course / defi  /  Lesson 04 of 05

Decentralized exchanges and AMMs

How a formula replaced the order book: constant-product markets, liquidity, slippage, impermanent loss.

14 min

Order books need market makers quoting both sides continuously, which is operationally heavy on-chain. Automated market makers replaced the book with a pool and a formula: anyone can trade against the pool, and the price is a function of its balances.

The constant product

The classic AMM invariant, introduced by Uniswap, is disarmingly small:

x * y = k

x  reserve of token A
y  reserve of token B
k  constant preserved by every trade

price of A  =  y / x

Buying token A removes some x from the pool, so y must rise to keep k constant: the price moves against you as your trade grows. That curvature is slippage, and it is the mechanism, not a bug.

Liquidity providers

Pools are funded by liquidity providers who earn trading fees but accept impermanent loss: when prices diverge, the pool rebalances against them, and holding the assets outright would sometimes have paid more.

Sign in to track progress