You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 3, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 3, 2026. It is now read-only.
bug(low-severity): fee calculation on GeometricMean #3
The GeometricMean strategy uses an incorrect fee calculation for the increase in L that is off by a factor of 2.
Details
The fee calculation roughly looks like
fees = amountIn * swapFee;
deltaL = fees * L / R
where R is either one of the two reserves, and specifically is the reserve that is being tendered in for a swap.
Replication of the issue
To see why this is off, take a pool with a swap fee of 0.003, initial price of 1, initial X of 10E9, and then perform a swap of 1 of X or Y in. This liquidity depth and swap size should make it such that the pool is close to being a ConstantSum pool. What you find is that instead of getting out 0.997 of the other token, you get back 0.994 indicating the fee was double counted.
Fix
To fix the issue, simply divide the above deltaL by 2.
Testing in Mathematica notebooks seems to show this change fixes the fee problem.
Activity
0xJepsen commentedon Feb 22, 2024
Do we want to document these bugs in the report actually?
Autoparallel commentedon Feb 22, 2024
This wasn't found with arbiter, just fyi