Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(low-severity): fee calculation on GeometricMean #3

Open
Autoparallel opened this issue Feb 20, 2024 · 2 comments · May be fixed by #6
Open

bug(low-severity): fee calculation on GeometricMean #3

Autoparallel opened this issue Feb 20, 2024 · 2 comments · May be fixed by #6
Assignees
Labels
🪲 bug Something isn't working 📃 contracts Anything related to the DFMM contracts (or strategies)

Comments

@Autoparallel
Copy link
Contributor

Description

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.

@Autoparallel Autoparallel self-assigned this Feb 20, 2024
@Autoparallel Autoparallel added the 🪲 bug Something isn't working label Feb 20, 2024
@Autoparallel Autoparallel linked a pull request Feb 21, 2024 that will close this issue
1 task
@0xJepsen
Copy link
Contributor

Do we want to document these bugs in the report actually?

@Autoparallel
Copy link
Contributor Author

Do we want to document these bugs in the report actually?

This wasn't found with arbiter, just fyi

@clemlak clemlak added the 📃 contracts Anything related to the DFMM contracts (or strategies) label Feb 28, 2024
@clemlak clemlak added this to the ❄️ Contracts Freeze milestone Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working 📃 contracts Anything related to the DFMM contracts (or strategies)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants