How are token prices determined?
Last modified:
Every liquidity pool enforces a single invariant — the constant product — that fully determines prices from on-chain reserves alone:
x · y = k
x— reserve oftoken0y— reserve oftoken1k— invariant (constant product)
When a trader sells one token into the pool and withdraws the other, the contract adjusts both balances so that their product remains equal to k. That adjustment is the price.
The Constant Product Formula
The spot price of token0 in terms of token1 at any moment is the ratio of the reserves:
price_token0 = y / xBecause x * y = k, the price is fully determined by the reserves and the invariant.
Deriving the swap output
When you sell Δx of token0 into a pool with reserves (x, y), the pool must maintain k:
(x + Δx) * (y - Δy) = k = x * ySolving for Δy (the amount of token1 you receive):
Δy = y * Δx / (x + Δx)This is always less than Δx * (y / x) — the "ideal" output at the spot price — because your own trade moves the price against you. This difference is the price impact.
Worked example
A pool holds 50 CTN and 100,000 USDC, so k = 50 * 100,000 = 5,000,000.
| You sell | You receive | Effective price | Spot was | Price impact |
|---|---|---|---|---|
| 1 CTN | 100,000 × 1 / (50 + 1) = 1,960.78 USDC | 1,960.78 | 2,000 | 1.96% |
| 5 CTN | 100,000 × 5 / (50 + 5) = 9,090.91 USDC | 1,818.18 | 2,000 | 9.09% |
| 10 CTN | 100,000 × 10 / (50 + 10) = 16,666.67 USDC | 1,666.67 | 2,000 | 16.67% |
| 25 CTN | 100,000 × 25 / (50 + 25) = 33,333.33 USDC | 1,333.33 | 2,000 | 33.33% |
Notice how price impact accelerates as the trade size grows relative to the pool reserves. This is the fundamental tradeoff of AMMs: larger trades get progressively worse prices.
After the trade
After selling 5 CTN into the pool above:
New reserves: x = 55 CTN, y = 90,909.09 USDC
New k = 55 * 90,909.09 = 5,000,000 (unchanged)
New spot price = 90,909.09 / 55 = 1,652.89 USDC/CTNThe spot price dropped from 2,000 to 1,652.89 — the pool now offers less USDC per CTN because the CTN supply increased and the USDC supply decreased.
Adding Liquidity and k
When a liquidity provider deposits tokens, k increases. More liquidity means lower price impact for the same trade size:
Pool A: 50 CTN / 100,000 USDC (k = 5M) → 5 CTN trade → 9.09% impact
Pool B: 500 CTN / 1,000,000 USDC (k = 500M) → 5 CTN trade → 0.99% impactDeep liquidity therefore translates directly into better execution for traders.
From v2 to v3
In v2 every pool distributes liquidity across the full curve from price 0 to infinity. v3 lets providers concentrate capital within a chosen range, creating virtual reserves that behave as though the pool were far deeper. The mathematics change accordingly — see Concentrated Liquidity for the virtual-reserves formulas and Tick Math for on-chain price encoding.