The auto deleveraging mechanism is incorrectly applied twice when processing positive PnL in the _fillOrder() function.
In _fillOrder(), when processing positive PnL, the code first applies auto-deleveraging through getAdjustedProfitForMarketId() and then passes this already deleveraged amount to withdrawUsdTokenFromMarket() which applies deleveraging again:
The protocol becomes insolvent as positions record single deleveraged amounts while minted tokens reflect double deleveraged amounts.
Pass the original pnlUsdX18 amount to withdrawUsdTokenFromMarket() instead of the already deleveraged marginToAddX18.
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.