Skip to content
This repository was archived by the owner on Oct 3, 2026. It is now read-only.
This repository was archived by the owner on Oct 3, 2026. It is now read-only.

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

Open

Description

@Autoparallel

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.

Activity

  1. self-assigned this
    on Feb 20, 2024
  2. added
    🪲 bug
    on Feb 20, 2024
  3. added
    📃 contracts
    on Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

📃 contracts🪲 bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions