In Uniswap V2, all liquidity provider (LP) positions fall in the price range [pa, pb] = [0, Infinity]
. The value for liquidity is fungible across all positions and is calculated as follows:
This means that the value of liquidity is directly proportional to the values of x
and y
tokens provided, and the only way to get the same exact value of liquidity is to provide an amount of underlying tokens that falls on the curve described by the formula above.
In Uniswap V3, LP positions are more fine-tuned and have an additional level of depth. Uniswap V3 introduces the concept of concentrated liquidity, where positions are not only described by the amount of liquidity provided but also the price range [pa, pb]
over which that liquidity is provided. Liquidity is described by the following formulas:
By examining the Uniswap V3 formulas, we see that the value of liquidity is directly proportional to the values of x
and y
and inversely proportional to the width of the price range. If we calculate the amount of liquidity that results from providing an amount of tokens x1
and y1
across a price range [pa, pb]
, it should be possible to get the same exact value of liquidity by providing a smaller amount of both tokens x2
and y2
across a narrower price range [pc, pd]
.
Therefore, in Uniswap V3, the liquidity units are not fungible across positions with different price ranges and are only locally fungible within positions that lie within the same price range.
In Uniswap V3, the formula for calculating the price from a given tick is the following:
By looking up Uniswap V3's codebase, we find that the price is represented by the variable sqrtPriceX96
of type uint160
. Where:
And:
By using both formulas above and plugging in the maximum tick value of 887272
, we find the following:
We know that in Solidity, the conventional way of representing the value of ∞ would be to use the maximum integer value allowed by a type. The max number we could obtain with a uint160
(i.e. the type of sqrtPriceX96
) is:
Therefore, we conclude that the chosen maximum tick of 887272
is just enough to produce a sqrtPriceX96
that is still lower than the maximum value allowed by the type uint160
. And most likely, the minimum tick value of -887272
was chosen to represent a price of zero for symmetry.
Best Answer
sqrtPricesX96 for a evetn swaap is the price of the pool after swap
Here a screenshot from uniswap doc:
See docs from Uniswap https://docs.uniswap.org/contracts/v3/reference/core/interfaces/pool/IUniswapV3PoolEvents#swap