Unlike order and settlement fees, unrealized PnL is not considered for margin validation during settlements (SettlementBranch._fillOrder()
). As a result, some orders that should not be settled will succeed, while some orders that should be settled will be reverted.
During settlements, the resulting margin is checked, but only settlement and order fees are considered. Unrealized PnL is added or subtracted from the account's collateral later. Consequently, the margin validated after settlement is incorrect, as it does not include unrealized PnL. This leads to scenarios where:
Increasing orders that should not be settled (because they would bring the account below the initial margin) will succeed.
Orders that should be settled (because they would not bring the account below the initial margin) will revert.
Consider the following scenarios:
Alice's current collateral is above the initial margin, but she has unrealized negative PnL that would bring her collateral below the initial margin. Since this unrealized PnL is not considered during the settlement margin validation, she can increase her position even though it would bring her below the initial margin after settlement.
Alice's current collateral is below the initial margin, but she has unrealized positive PnL that would bring her collateral above the initial margin, even with an increasing order. However, since this positive unrealized PnL is not considered, her order will revert, even though her account would be above the initial margin after order settlement.
Some orders that should not be settled will be settled, leaving accounts below the initial margin. Conversely, other orders that should be settled will revert.
Manual Review.
Include unrealized PnL (both negative and positive) in margin validation, as is done for settlement and order fees.
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.