Losses when leverage is zero or negative which protocol does not account for
This is an edge case which the code does not consider:
The getAccountLeverage function doesn't handle the case where there might be open positions but zero or negative margin balance, which could lead to incorrect leverage calculations or potential division by zero errors.
Zero Margin Balance:
Liquidation: When the margin balance reaches zero, the position is at risk of liquidation. If the value of the collateral drops to the maintenance margin level, the exchange will liquidate the position to cover the losses.
Profit and Loss: If there are unrealized profits in the position but have withdrawn all available margin, the margin balance could be zero. The open positions remain, but any adverse price movement could quickly lead to liquidation.
Negative Margin Balance:
Extreme Market Movements: In cases of extreme market volatility, the position might incur losses faster than the exchange can liquidate it, leading to a negative margin balance. This means traders owe the exchange more than their collateral value.
Fee Accumulation: If fees such as funding rates or trading fees are not covered by the available margin, they can push the balance into the negative.
There will be further losses for the protocol when this happens. There will be liquidations for traders as they may not receive any alerts to add more collateral or risk liquidations. There will be losses during this systemic risk scenario.
Manual Review
Account for these edge cases in the code.
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.