Withdrawers are paying position fee and negative PnL once when calculating the collateral delta to create a decrease position and once again when getting the output from the decrease order.
Consider the following scenario:
There is an opened position with collateral $1000 and position size $3000
User has 1/10 of vault shares and initiates a withdraw
He has to be eligible of 1/10 of the whole position - minus fees and PnL related to his part
When he tries to withdraw, the collateral delta for the corresponding decrease position will be lowered by those fees and PnL
Instead of requesting $100 from the collateral, collateral delta would be a smaller number, lets say $80
The problem comes from the GMX implementation, which will also calculate fees and PnL and substract them from those $80
This will make withdrawer double paying and getting less than what he deserve.
The following logic is handling withdrawal process in Gamma and account for the fees and pnl:
We see that fee and pnl are once substracted from the collateralDeltaAmount.
Taking a look how order decrease is handled in GMX code:
Inside DecreasePositionUtils::decreasePosition() we have the following snippet to account for fees and collateral. It uses processCollateral(). Taking a look at how fees and PnL are accounted in processCollateral():
totalCostAmountExcludingFunding includes position fee.
And if we check how payForCost() is implemented, we see that fees and negative pnl will be first subtracted from the output amount (which is the actual amount user will get) and only if it is unsufficient, it will be subtracted from the remaining collateral.
Loss of funds for withdrawers.
Manual review.
Consider implementing a similar approach to the deposit functionality, where fees and pnl are accounted after decreasing order. I think the problem here is mainly that collateralDeltaAmount is subtracted before the actual decrease.
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.