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(high-severity): fee calculation for LogNormal #2

Open
Autoparallel opened this issue Feb 20, 2024 · 0 comments
Open

bug(high-severity): fee calculation for LogNormal #2

Autoparallel opened this issue Feb 20, 2024 · 0 comments
Assignees
Labels
🪲 bug Something isn't working 📃 contracts Anything related to the DFMM contracts (or strategies)

Comments

@Autoparallel
Copy link
Contributor

Description

The LogNormal strategy uses an incorrect fee calculation for the increase in L that will result in fees that are dependent on the current price of the pool.

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.

In the case where the pool is priced such that R is much less than L``, can see that we then require a substantial growth in L` for the swap to be accepted. This can lead to worse execution prices and could lead to a pool becoming stale/bricked if the reported price falls too far from the "strike" price of the pool (also depends on the sigma parameter).

Fix

To fix the issue, we just calculate the fees and deltaL slightly differently.

If X is being tendered:

deltaL = amountIn * swapFee

else if Y is being tendered:

deltaL = amountIn * swapFee / params.strikePrice

Testing in Mathematica notebooks seems to show this change fixes the fee problem and as the pool depth increases, this choice of fee calculation leads to what we expect to see from a ConstantSum CFMM.

@Autoparallel Autoparallel self-assigned this Feb 20, 2024
@Autoparallel Autoparallel added the 🪲 bug Something isn't working label Feb 20, 2024
@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

No branches or pull requests

2 participants