The function is using the initialMarginUsdX18
to calculate the available margin, when it should be using the maintenanceMarginUsdX18
. This is incorrect.
The getAccountMarginBreakdown function is using the initialMarginUsdX18
to calculate the available margin, when it should be using the maintenanceMarginUsdX18
. This is incorrect because:
Available margin is typically calculated as the difference between the total margin balance and the maintenance margin, not the initial margin.
Using initial margin for this calculation can lead to an underestimation of the available margin, as initial margin requirements are generally higher than maintenance margin requirements.
This error could potentially prevent users from withdrawing funds that should be available to them, as it's using a more conservative (higher) margin requirement for the calculation.
The @dev comment mentions that "If the account's maintenance margin rate rises to 100% or above (MMR >= 1e18), the liquidation engine will be triggered." This is correct, but the available balance calculation doesn't align with this liquidation threshold, creating a disconnect between the user's perceived available funds and the actual risk of liquidation.
Users might see less available margin than they should, potentially leading to unnecessary margin calls or preventing them from opening new positions when they actually have sufficient funds.
Manual Review
availableMarginUsdX18 = marginBalanceUsdX18.sub((maintenanceMarginUsdX18).intoSD59x18());
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.