During liquidation, the required Maintenance Margin(MM) is deducted from the trader's collateral regardless of how much the trade lost. There could be scenarios where MM does not cover the loss and bad debt is incurred.
In liquidateAccounts(), MM is deducted from the account's collateral:
This assumes that MM is sufficient to cover potential losses but there could be scenarios where losses exceed MM due to:
Sharp drawdown in price during black swan events, and keepers cannot liquidate fast enough
Arbitrum sequencer downtime (see https://dedaub.com/blog/arbitrum-sequencer-outage/) such that liquidations cannot be performed temporarily
If losses exceed MM but only MM is deducted, then the trader benefits by being able to withdraw remaining collateral and avoid paying for his full losses. Consider this example:
Bob deposits $2,000 of collateral
Bob opens a $10,000 position which requires a 10% MM of $1,000
Due to a sharp price drawdown, Bob's position is in a loss of $1,100
Bob is liquidated but only $1,000 is taken from him
Bob withdraws the remaining $1,000 of collateral and avoids a $100 loss
On the other hand, there may be scenarios where the trader does not have any losses but due to collateral value decreasing, he is liquidated and has all collateral taken unfairly. Consider this example
Bob deposits $2,000 of ETH collateral
Required MM of $1,000
PnL of $0
Due to ETH price decrease, his collateral is worth $999
Bob is liquidated and loses all $999
Traders may be able to avoid the full extent of their losses and the counterparty to their trade (protocol / LPs) are deprived of potential profit.
Consider deducting only trading losses and fees, and return any remaining collateral.
https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/branches/LiquidationBranch.sol#L158
Manual Review
Deduct the higher of either MM or accountTotalUnrealizedPnlUsdX18 from the trader's collateral, and if the amount to be deducted exceeds the trader's collateral, take all the collateral.
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.