In PerpMarket
library, function checkOpenInterestLimits
is used to ensure that newly created or settled order doesn't increase open interest or skew when they are decreasing the position. However, in some circumstances, it's possible that reducing the position size reverts due to checks present in this function.
The function checkOpenInterestLimits
is used to ensure that created and settled market order doesn't increase open interest above maxOpenInterest
and skew above maxSkew
. In the case of open interest more than maxOpenInterest
, the checks ensure that the function doesn't revert if the order is decreasing open interest. Also, in the case of skew more than maxSkew
, the checks ensure that the function doesn't revert if the order is decreasing the skew. However, this checks shouldn't be present when the account
is decreasing their position size
. The checks may prevent certain trades from being executed. This could lead to situations where traders are unable to perform trades that would decrease their risk, potentially leading to liquidations. The comments says the following:
However, there can be the case that the order is reducing Open Interest
but increasing the skew
. In such cases, traders won't be able to reduce or close their position leading them subjected to liquidation.
Consider following example:
Initial State:
Long Positions: 130
Short Positions: -30
Old Open Interest: 160
Old Skew: 100
Old max Open Interest: 180
Old max skew: 120
Trader: -15(short position)
Owner Update:
New max skew: 100
New max Open Interest: 120
Trade Attempt by trader to close the short position by placing long order of 15
. Values after trade settlement:
Long Positions: 130
Short Positions: -15
New Open Interest: 145 (reduced)
New Skew: 115 (increased)
Since newOpenInterest
is greater than maxOpenInterest
and the order is reducing OpenInterest
, it should be allowed
.
But newSkew
is greater that maxSkew
and the order is not reducing maxSkew
, so this order is not allowed
.
This leads to revert of order of closing position of trader.
Occurences in codebase:
In SettlementBranch
In OrderBranch
Traders may be unable to execute trades that would reduce their overall open interest, potentially leading to forced liquidations.
Manual review
Modify Skew Handling Logic: Update the skew handling logic to allow trades that either reduce open interest or reduce skew. This ensures that trades aimed at reducing risk are not unnecessarily blocked.
By implementing following change, trades that reduce either open interest or skew will be allowed, ensuring that traders can effectively manage their risk and avoid forced liquidations.
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.