Uniswap V3 – Why Ticks [-887272, 887272] Represent the Price Range [0, ?]

liquidity-providermathuniswapv3

When providing liquidity to an already-created Uniswap V3 pool, you are offered the option to provide liquidity across the price range [0,∞] (effectively performing as a Uniswap V2 LP position). My question is why is the created LP position assigned a tickLower of -887272 and tickUpper of 887272? I'm interested in why those specific tick values were chosen to represent the price range [0,∞].

Best Answer

In Uniswap V3, the formula for calculating the price from a given tick is the following:

enter image description here

By looking up Uniswap V3's codebase, we find that the price is represented by the variable sqrtPriceX96 of type uint160. Where:

enter image description here

And:

enter image description here

By using both formulas above and plugging in the maximum tick value of 887272, we find the following:

enter image description here

enter image description here

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:

enter image description here

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.

Related Topic