The liquidation mechanism currently mandates the complete closure of a position rather than supporting partial liquidation. This all-or-nothing approach may force traders to liquidate their entire market exposure unnecessarily, potentially resulting in higher losses than if only a fraction of the position were closed to restore adequate margin levels.
The code forces full liquidation by computing the liquidation size as the negative of the entire open position:
Later, the entire position is cleared:
This indicates that the system does not support partial liquidation where only a portion of the position is closed to bring the account back in compliance with margin requirements. The absence of flexibility in liquidation size means that even when a small position reduction would suffice, the protocol liquidates the entire position, potentially exacerbating losses.
Excessive Losses for Traders: Forcing a full liquidation may lead to higher-than-necessary losses, as traders lose the benefit of retaining some exposure which might still be profitable.
Inefficient Risk Management: Traders lose the opportunity to adjust positions gradually and recover by partially closing positions, leading to more aggressive and costly liquidation outcomes.
Market Confidence Erosion: The inability to execute partial liquidations may deter market participants who value flexibility in managing risk, potentially affecting overall market liquidity.
Manual Code Review
Static Analysis Tools
Simulation Testing
Implement Partial Liquidation Logic: Modify the liquidation mechanism to allow for closing only a portion of a position when appropriate. This may involve:
Calculating the minimum liquidation size necessary to restore the margin above the maintenance threshold.
Adjusting the position size by the calculated amount instead of clearing it entirely.
Dynamic Liquidation Parameters: Introduce parameters that determine the optimal fraction of the position to liquidate based on the margin shortfall and current market conditions.
Update Event Logging: Enhance event emissions to include details of the partial liquidation, such as the portion liquidated and the remaining position size.
Comprehensive Testing: Develop unit and integration tests to cover various partial liquidation scenarios ensuring that the system behaves as expected under different market conditions.
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.