precision loss in UpliftOnlyExample::onAfterSwap() fee calculation mechanism that leads to very high QuantAdmin fees percentage from hookFee.
The fee calculation in onAfterSwap() performs division operations in a bad order:
The issue arises from dividing 1e18 by quantAMMFeeTake first, which creates truncation that gets magnified in subsequent calculations.
Examples:
For quantAMMFeeTake = 0.3e18 (30%)
1e18 / 0.3e18 = 3.333... truncates to 3
With hookFee = 100e18:
Calculated: adminFee = 100e18/3 = 33e18
Expected: 100e18 * 0.3 = 30e18
Difference: +10% overcharge
Another Example That will eat all the swap Fees (Works with any thing above 0.5e18 as quantAMMFeeTake):
For quantAMMFeeTake = 0.7e18 (70%)
1e18 / 0.7e18 = 1.428... truncates to 1
With hookFee = 100e18:
Calculated: adminFee = 100e18/1 = 100e18
Expected: 100 * 0.7 = 70e18
Difference: +42.8% overcharge
NOTE!: The issues doesn't assume the admin to be behaving maliciously, but its just a valid fee % that is <= 1e18 as checked here
Fees overcharged % from hookFee during onAfterSwap() Hook
Manual code
Implement the following fix to maintain precision:
Likelyhood: High, quantAMMFeeTake is a percentage on calculated fees. Being between 30-70% is very likely. Impact: High, fees for LP providers will be lower than expected and 0 if the admin fees is above 50%.
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.