The Gamma protocol calculates position fees using vaultReader.getPositionFeeUsd with a hardcoded false value for the _hasPositiveImpact parameter. This ignores the actual price impact of the trade, leading to incorrect fee calculations. Fees are either overestimated or underestimated, depending on the direction of the price impact, resulting in financial losses for users or the protocol.
Hardcoded _hasPositiveImpact Parameter
The function vaultReader.getPositionFeeUsd uses a boolean parameter _hasPositiveImpact to determine whether the trade has a positive or negative price impact. This affects the fee calculation logic.
Current Code Issue:
The parameter is hardcoded to false, assuming all trades have a negative price impact. This is incorrect because price impact can be positive or negative depending on the trade direction and market conditions.
Price Impact Not Factored into Fee Calculation
The protocol fetches the price impact separately using vaultReader.getPriceImpactInCollateral but does not use it to determine the correct value for _hasPositiveImpact. This creates a disconnect between the fee calculation and the actual market impact of the trade.
Wrong computation of fees and users are charged the wrong fee.
Determine Price Impact Direction
Use the priceImpact value returned by vaultReader.getPriceImpactInCollateral to determine whether the impact is positive or negative:
Pass Correct Parameter to Fee Calculation
Update the fee calculation to use the dynamically determined hasPositiveImpact value:
Update Fee Calculation Logic
Modify the existing code to incorporate the price impact direction:
Guardians audit L-02.
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.