In OrderBranch
, function simulateTrade
has incorrect liquidation.
function simulateTrade
is called by function createMarketOrder
. The function simulateTrade
has checks which ensure that the creation of market order will fail if tradingAccount
is liquidatable after the order
settlement. However, the condition being used is wrong.
The check is used to ensure that previousRequiredMaintenanceMarginUsdX18
(before order settlement) is less than marginBalanceUsdX18
to prevent liquidatable accounts from trading as mentioned in comments. However, marginBalanceUsdX18
is calculated considering the sizeDelta
once the order is settled. This is not correct way because it should calculate marginBalanceUsdX18
only considering current state of tradingAccount
and not based on sizeDelta
of created order.
marginBalanceUsdX18
calculated may not be accurate because it considers the sizeDelta
and not current state of account.
Manual
The correct code is as follows(added the comments where changes is made):
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.