In the `SettlementBranch.sol` the deleverage amount is accounted incorrectly.
In the _fillOrder
function the getAdjustedProfitForMarketId
is used to preview the marginToAddX18
with the applied deleveraging:
However we can see that the getAdjustedProfitForMarketId
does not call recalculateVaultsCreditCapacity
to update the vault's capacity which has a direct effect on the total deleged credit. As a result it will use an outdated value for the creditCapacityUsdX18
:
This will result in wrong adjustedProfitUsdX18
being used in the deposit for the trading account.
The getAdjustedProfitForMarketId
uses outdated creditCapacityUsdX18
creating a discrepancy between the actual amount that will be withdrawn in the withdrawUsdTokenFromMarket
and the amount previewed in getAdjustedProfitForMarketId
The discrepancy will cause incorrect internal accounting which may even lead to insolvency
Manual Review
Should call recalculateVaultsCreditCapacity
prior to previewing the adjustedProfitUsdX18
in _fillOrder
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.