Skip to Content

Uniswap v3 Key Concepts

Uniswap v3 introduced several important innovations, with concentrated liquidity being the most significant. To understand how it works, we need to learn about ticks, sqrtPrice, and other key concepts.

Ticks and Price Ranges

In Uniswap v3, the price space is divided into discrete ā€œticks.ā€ Each tick represents a specific price point, and liquidity can be provided within a range of ticks.

What is a Tick?

A tick is a logarithmic representation of price. The price at a given tick i is calculated as:

price = 1.0001^i

This means:

  • Tick 0 corresponds to a price of 1.0
  • Each increment of 1 tick increases the price by 0.01%
  • Moving 100 ticks changes the price by approximately 1%

Ticks allow Uniswap to represent the entire price range from 0 to infinity in a manageable way.

The Mystery of sqrtPriceX96

One of the most confusing aspects of Uniswap v3 is the sqrtPriceX96 value. Let’s break it down:

Why Square Root of Price?

Uniswap v3 uses the square root of price (√P) instead of the actual price (P) for several reasons:

  1. It simplifies the math for calculating liquidity and price movements
  2. It makes liquidity calculations more efficient
  3. It allows for more precise price tracking between ticks

What is X96?

The X96 part means the value is scaled by 2^96 (a very large number). This is done to maintain precision when working with fixed-point arithmetic in Solidity, which doesn’t support floating-point numbers.

So sqrtPriceX96 is:

sqrtPriceX96 = √P Ɨ 2^96

Converting Between Price and sqrtPriceX96

To convert a price to sqrtPriceX96:

uint160 sqrtPriceX96 = uint160(sqrt(price) * 2**96);

To convert sqrtPriceX96 back to price:

uint256 price = uint256(sqrtPriceX96) * uint256(sqrtPriceX96) / (2**192);

Liquidity Concentration

In Uniswap v3, liquidity providers specify a price range (lower tick and upper tick) for their liquidity. This creates ā€œvirtualā€ liquidity that’s only active when the price is within that range.

Benefits of Concentrated Liquidity

  1. Capital Efficiency: LPs can concentrate their capital where it’s most likely to be used
  2. Custom Risk Profiles: Different price ranges can be chosen based on market expectations
  3. Higher Returns: Concentrated liquidity can earn more fees with the same amount of capital

Example

If you believe ETH will trade between $1,800 and $2,200:

  • You can provide liquidity just within that range
  • Your capital is used much more efficiently than in v2
  • You earn more fees per dollar of liquidity provided
  • But if the price moves outside your range, your liquidity becomes inactive

Position Management

In Uniswap v3, each liquidity position is represented as an NFT (ERC-721 token). This is because each position is unique, defined by:

  1. The token pair
  2. The fee tier
  3. The price range (lower and upper ticks)
  4. The amount of liquidity

In the next section, we’ll look at how to initialize a Uniswap v3 pool and provide liquidity with code examples.

Last updated on