LiquidationBranch.liquidateAccounts()
can handle multiple account liquidations at once. When liquidating accounts with multiple positions, the mark price should update after each position closes, reflecting the cumulative impact of all liquidations. However, the price only updates for the current position in the loop, ignoring the effect of previously liquidated positions."
Looking at the LiquidationBranch.liquidateAccounts() function, we will see that it iterates through all liquidatable account ids and start closing all account positions if an account is liquidatable.
The price impact calculation in the loop above only considers the current position being closed (ctx.liquidationSizeX18
which is -ctx.oldPositionSizeX18
), without factoring in how previous liquidations affected the price. The index price remains constant across all position closures, which is not realistic.
Consider a scenario where two liquidatable accounts have long positions of 20e18 and 10e18, with an index price of 100,000e18 (MOCK_BTC_USD_PRICE). When the 20e18 position is liquidated first, the price drops to 999,999e17. The second position's liquidation should then push the price to 999,9995e16, but because each calculation uses the original index price, this cumulative effect isn't captured.
The miscalculated markPrice
affects funding rate calculations. As more liquidations occur, the gap between the actual and expected markPrice grows wider, leading to inaccurate funding rates. This becomes particularly a problem when liquidating positions of varying sizes - if a large position is closed first followed by smaller ones, the funding rate for the smaller positions won't reflect the significant price impact from the earlier large liquidation."
Manual Review
Replace ctx.liquidationSizeX18 = -ctx.oldPositionSizeX18
with ctx.liquidationSizeX18 = ctx.liquidationSizeX18.sub(ctx.oldPositionSizeX18)
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.