LiquidationBranch::liquidateAccounts add accountTotalUnrealizedPnlUsdX18 to marginBalance only for working data which used for checking isLiquidatable, and when later deductAccountMargin is called it deduct required margin and fees from old margin without considering the unrealized PnL.
In the liquidateAccounts function, the margin balance is augmented(for working data only) by accountTotalUnrealizedPnlUsdX18 to determine if the account is liquidatable. However, this augmented balance is not used consistently during the actual liquidation process. Specifically:
The augmented balance is used to check if the account meets the liquidation criteria.
During the deduction of margin and fees in the deductAccountMargin call, the deduction is performed on the old margin balance, ignoring the unrealized PnL.
High
Manual
Update account margin balance before calling deductAccountMargin.
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.