After entering the liquidation state, the user can still execute fillMarketOrder() to reduce the position and avoid liquidation.
in _fillOrder()
We will check if the order will go into liquidation after it is executed
The above code uses tradingAccount.getAccountMarginRequirementUsdAndUnrealizedPnlUsd(marketId, sizeDeltaX18);
to calculate the requiredMaintenanceMarginUsdX18
.
This assumes that :position.size = 1000, and that the user is already in liquidation.
But the user can still successfully close the postion
by passing in fillOrder(sizeDeltaX18 = -1000)
.
Because getAccountMarginRequirementUsdAndUnrealizedPnlUsd(sizeDeltaX18 = -1000)
inside will use the reduced position to calculate notionalValueX18 = sd59x18(position. size).add(sizeDeltaX18).abs().intoUD60x18().mul(markPrice);
The resulting requiredMarginUsdX18
will be small enough to close the position
properly.
It's already in liquidation, so it should only be able to be liquidated or have collateral added to prevent it from being liquidated, it shouldn't be able to just close the position
.
fillOrder()
should be executed by checking the current state first.
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.