The Perpetuals::Liquidate function liquidates all of an account positions and seizes their collateral.I have found that this is not necessary and some positions can be spared and still laeve the account in a healty position.
The Perpetuals::Liquidate function liquidates all of an account positions and seizes their collateral:
The problem is that this is not necessary since its possible to only close some positions and still leave the account healty. Consider a case where a trading account has 2 positions- a small position and a large position. Instead of closing the 2 positions, it is possible to only close 1 position and still leave the account healty.
For a POC, add this comment to src/perpetuals/branches/LiquidationBranch.sol::Ln177 at the start of the activeMarketsIds loop:
Add this test to test/integration/perpetuals/liquidation-branch/liquidateAccounts/liquidateAccounts.t.sol:
Run the test as:
forge test --match-test testLiquidateOneOff -vvv
The test shows that after the first position is liquidated, the account returns to a healthy state and should not be liquidated. Thi could have spared the second position.
Closing all an acccount positions unfairly seizes all their collateral and denies traders opportunity to rescue their accounts.
Manual review
Consider checking the accounts liquidation status before closing a position in order to avoid undue loss.
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.