During liquidation, the protocol deducts account margin without awarding any positive PnL to user. This can result an unfair over-liquidation of collateral asset.
LiquidationBranch.liquidateAccounts
can be summarized as the following steps:
Calculate requiredMaintenanceMarginUsd
and accountTotalUnrealizedPnlUsd
for given account
Calculate marginBalanceUsd
for the account
Check if marginBalanceUsd < requiredMaintenanceMarginUsd + liquidationFeeUsd
For all active markets, close the position and update funding rate and skews
Deduct accountTotalUnrealizedPnlUsd.abs() + requiredMaintenanceUsd
from account's margin
where
To make things simpler, let's assume an account has only one collateral type and liquidationFeeUsd = 0
Consider the following scenario:
accountTotalUnrealizedPnlUsd = 50
collateralInUsd = 1000
requiredMaintenanceMarginUsd = 900
loanToValue = 0.8
The account is liquidable because:
The amount to deduct from account is:
So, after liquidation, the account is left with
worth of collateral and no position. Since all position is lost, the user cannot claim 50 USD worth of accountTotalUnrealizedPnlUsd
anymore.
Thus, the user lost 50 USD worth of accountTotalUnrealizedPnlUsd
during liquidation.
Because taking positive PnL into account, remaining asset after liquidation should be:
User's positive PnL is not realized during liquidation, and user gets their collateral liquidated more than needed.
Manual Review
Introduce the same postive PnL logic as in SettlementBranch._fillOrder
An alternative approach is not to withdraw positive PnL from trade account:
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.