DeFiGrail
LOADING CONTENT INDEX…
LIVE
BTC$71,240+2.1%ETH$3,905+3.4%DeFi TVL$112.4B-0.8%
DATA AS OF 14:00 UTC
Foundational · v0

Uniswap v2

Constant-product AMM (x·y=k) — the passive market maker every DEX descends from.
TradFi →Continuous-quote market maker

01 · Concept — what problem does it solve?

Order books need active market makers posting quotes. On-chain, every quote update costs , so order books were economically dead on Ethereum L1. Uniswap v2 replaces the market maker with a formula: a passive pool of two tokens whose product must stay constant. Anyone can trade against the pool 24/7; anyone can become the "market maker" by depositing both tokens.

Unlike a TradFi market maker, the never withdraws quotes, never widens spreads in panic, and never refuses a trade — the price impact curve is the .

02 · Mechanics

  • Pool: reserves x (token A) and y (token B). Every swap must preserve x · y = k (after the 0.30% fee is added to reserves).
  • Price: the marginal price is just the reserve ratio y/x. Big trades move along the hyperbola → price impact grows with trade size.
  • tokens: depositors receive pro-rata pool shares; fees accrue into reserves, so LP tokens appreciate against the pool.
  • : cumulative price accumulators allow manipulation-resistant time-weighted average prices.

03 · Formulas

// invariant
x · y = k

// swap output with 0.30% fee (997/1000)
Δy = ( y · Δx · 997 ) / ( x · 1000 + Δx · 997 )

// spot price & price impact
P = y / x          execution price < P for buys

// LP share minted (initial / subsequent)
s₀ = √(Δx·Δy) − 1000        MINIMUM_LIQUIDITY lock
s  = min( Δx/x , Δy/y ) · S

04 · Edge cases & risks

  • — LPs lose vs. holding when price diverges. See Impermanent Loss for full treatment.
  • Sandwich exposure — deterministic price impact makes every pending swap a target. See MEV.
  • Fee-on-transfer tokens break the invariant math; v2 added swapExactTokensForTokensSupportingFeeOnTransferTokens as a workaround.
  • 1000-wei liquidity burn — the first LP mints to address(0) to prevent share-price inflation attacks on tiny pools.
Next: MakerDAO