Skip to content

liquidity parameter in uniswapv3 Swap() #61

@tobinchodos

Description

@tobinchodos

When swapping on a uniswap v3 exchange, the cache variable is initialized with total_supply, i.e. total liquidity in the pool across all positions. This value, via SwapState, is then used to calculate swap amounts in/out.

Shouldn't this be liquidity-at-tick? (i.e. the value stored as self.liquidity , not self.total_supply).

We encountered this trying to replicate historical data. Replacing total_supply with liquidity-at-tick (calculated as the liquidity at the largest tick to the left of current price, by way of a cumulative sum of net liquidity) leads to successful replication of historical data.

Also, self.liquidity is not defined on initialization of uniswap v3 exchanges. It seems to be defined only after the first swap() call, so you can't actually replace self.total_supply with self.liquidity in the line referenced above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions