Comparison with v2
In v2, the formula:
is used to calculate the pool's liquidity, reserves, and price via the ratio of x and y. Liquidity is provided globally, meaning it covers the entire price range. No matter the market price, there's always liquidity available, avoiding token depletion.
In v3, users can concentrate liquidity within specific price ranges to improve capital efficiency. This requires major changes in liquidity calculation, as a single global k
constant no longer applies.
Providing Liquidity in a Specific Range
In v3, liquidity can be provided within specified ranges, called positions — stored as NFTs. As long as the market price is within the range, LPs collect fees.
When price moves out of range, the position becomes inactive and can't collect fees. If liquidity is withdrawn, it will be in a single token.
When price reaches a boundary (e.g. P2), the position's token B is exhausted — it can't provide market making beyond this point.
Price & Liquidity Calculations
v3 only stores:
- — square root of price ()
- — liquidity,
From :
Prices are expressed in ticks:
Liquidity
In v2, liquidity depends on reserves with a 50/50 value ratio.
In v3:
- Each position has price bounds.
- The pool’s total liquidity is a collection of these positions.
LP Use Case
From Figure 3:
- (f1)
- (f2)
Further:
Finally:
Example:
Result: — providing 1 y requires 16779 x.
Note: Solidity uses ticks and Q64.96 fixed-point (sqrtPriceX96). On-chain results may differ.
Price
Swap flow without crossing ticks:
- Specify input or output amount
- Use pool’s and token amount to compute
- Compute corresponding token change
From (f1) and (f2):
- (f4)
- (f5)
Example: Adding 10 y in a pool:
Then:
Result:
UI Example
Figure 5: USDT/ETH pool UI
Current price: 3632, range: 2195~6620. Fixing 1 ETH requires 3188 USDT.
Adjusting price range (Figure 6) increases required USDT as range widens.
Contract Architecture
Uniswap Overview
Universal Router manages both v2 and v3 swaps.
Universal Router
Acts like a multicall, bundling operations via bytes-encoded instructions. The frontend picks optimal paths and parameters.
V3 Core
Minimal contract architecture (production uses Universal Router).
PoolFactory
Creates pools and assigns ownership.
Pool
Handles:
mint
— add a position, mint NFTburn
— remove liquidity, burn NFTswap
— execute token swapscollect
— collect earned fees
Periphery
Helper contracts.
SwapRouter
Handles swap logic with exactInput / exactOutput.
NFTManager
ERC-721 implementation for position NFTs with functions like collect
, increaseLiquidity
, decreaseLiquidity
.