When an order is filled through _fillOrder, if the trader has a positive pnl they receive credit and receive settlement tokens from the market making engine. The problem is the margin to add is deducted by the delevergaing factor twice leading to less settlement tokens minted to the trader than intended. Once through getAdjustedProfitForMarketId and again through withdrawUsdTokenFromMarket
A market order keeper intends to fill an order. When _fillOrder is called it checks if the trader's pnl is currently positive. If it is they are credited settlement tokens through the market making engine. The margin to add needs to be adjusted based on the deleveraging factor. That is done through the call to getAdjustedProfitForMarketId
. The amount returned is then passed into withdrawUsdTokenFromMarket
to mint the corresponding amount of settlement tokens.
The problem is that both of these functions are reducing the amount by the deleveraging factor.
https://github.com/Cyfrin/2025-01-zaros-part-2/blob/35deb3e92b2a32cd304bf61d27e6071ef36e446d/src/market-making/branches/CreditDelegationBranch.sol#L154C9-L160C10
https://github.com/Cyfrin/2025-01-zaros-part-2/blob/35deb3e92b2a32cd304bf61d27e6071ef36e446d/src/market-making/branches/CreditDelegationBranch.sol#L283C9-L292C64
This greatly reduces the intended amount of credit dedicated to this user.
Loss of user credit
Manual Review
There is no need to check the deleveraging factor when we mint the tokens in withdrawUsdTokenFromMarket
as it is already accounted for.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.