In the liquidateAccounts
function of LiquidationBranch.sol
contract all positions can be fully liquidated at once. This can be a problem in illiquid markets, where large-scale liquidations could cause significant slippage. Such behavior can negatively affect both the users involved in the liquidation and the market itself. Implementing partial liquidation based on market liquidity could help mitigate these risks.
In the LiquidationBranch.sol
contract, the code sets ctx.liquidationSizeX18 = -ctx.oldPositionSizeX18;
, assuming that the entire position can be liquidated in a single transaction.
However, in illiquid markets, attempting to liquidate large positions in a single transaction may lead to significant slippage. Large-scale liquidations can severely impact market prices, making the liquidation price significantly worse than the market price, resulting in unfair liquidation outcomes for users. Major price fluctuations due to large liquidations could lead to a cascade effect, triggering liquidations of other positions and potentially causing a liquidation "cascade."
src/perpetuals/branches/LiquidationBranch.sol:liquidateAccounts#L189
Significant Slippage: In markets with low liquidity, large position liquidations could cause substantial price slippage, resulting in users being liquidated at much worse prices than expected.
Unfair Liquidations: Users with positions being liquidated might experience unfair losses due to the price impact of large-scale liquidations in illiquid markets.
Market Instability: A lack of partial liquidation mechanisms could lead to a cascade of liquidations, further destabilizing the market and possibly triggering a domino effect of additional liquidations.
Manual Code Review
It is recommended to implement partial liquidation and add logic to limit the liquidation size based on the market liquidity. For large positions, split the liquidation into multiple smaller transactions to avoid overwhelming the market and causing significant price movements. And set a limit on the size of any single liquidation transaction to prevent excessive market impact. For example:
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.