In order to calculate how much shares should be minted per user deposit, we need to get the net value of the position and calculate shares proportional of the user deposit (actual increase of position). Removing the position fee in the calculation of net value is not correct and will lead to unfair shares distribution.
Shares for user deposit are calculated in PerpetualVault::_mint():
_shares = amount * totalShares / totalAmountBefore;
where totalAmountBefore is calculated as:
totalAmountBefore = _totalAmount(prices) - amount;
In VaultReader::getPositionInfo() we have the following to get the netValue:
We have already adjusted user's actual increase of position in afterOrderExecution():
Removing the position fee from the netValue of a position would result in better shares allocation for late depositors. Position fee should not be accounted in the net value as it is taken from increase/decrease amounts in GMX and fee is static percent of the position size.
Consider the following example (for the purpose of example, we can consider that there is not a borrowing/funding fee and price of index token between to increase operations is the same):
We have a position with $1000 collateral and $3000 position size in USD. Lets say position fee is 0.33% (it is calculated based on position size) and we have 1000e14 total shares (1000e6 * 1e8)
Alice deposits $1000 worth of collateral and gets 1000e6 * totalShares / 1000e6 - (positionFee) shares which is equal to 1000e6 * 1000e14 / 1000e6 - 10e6 which makes 99999999990000000 shares
Bob deposits $1000 shares right after Alice and since price of index token is the same and there are no funding/borrowing fees, Bob is expected to get the same amount of shares.
Calculating Bob's shares we got 1000e6 * (1000e14 + Alice's shares)/ (1000e6 + Alice's increase - positionFee) which is equal to 1000e6 * (1000e14 + 99999999990000000) / uint(1990e6 - 20e6) which makes 101522842634517766
Every consecutive depositor will be getting more and more shares than what is fair.
Incorrect shares allocation.
Manual review.
Do not use positionFee when calculating netValue of a position.
Likelihood: High, every new deposit, more shares are mint for the same amount Impact: High, dilution of previous shares.
Likelihood: High, every new deposit, more shares are mint for the same amount Impact: High, dilution of previous shares.
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.