Automated Market Maker
Swap tokens, add liquidity, and watch the constant product curve respond to every trade.
The Constant Product Formula
An AMM holds two token reserves and enforces one rule: x · y = k. The reserves sit on a hyperbola. When you buy token B, you push reserve A up and reserve B down, sliding along the curve. The pool never runs dry because the hyperbola never hits zero.
Compare this to an order book, where discrete limit orders set the price. An AMM has no order book. The price is just the ratio of the two reserves, and every trade shifts it.
Price and Slippage
The spot price is reserveB / reserveA. But that's the price for an infinitely small trade. A real trade moves along the curve, and the average execution price is worse than the spot price. Bigger trades move further along the curve and get worse execution. This is slippage, and it's visible as the gap between the tangent line (spot price) and the actual path along the curve.
Fees and k Growth
In a real AMM, a fee (typically 0.3%) is taken from every swap and stays in the pool. This means k grows over time. Liquidity providers earn returns because the pool gets bigger with every trade. You can see this in auto mode: the curve slowly drifts outward as fees accumulate.
Impermanent Loss
If you deposit tokens at one price ratio and the price moves, you'd have been better off just holding. The formula is 2·√r / (1+r) - 1 where r is the price ratio. At 2x price change, you lose about 5.7% compared to holding. It reverses if the price returns. The word "impermanent" is optimistic. Fees can offset it if trading volume is high enough.
Where AMMs Show Up
Uniswap v2 uses this exact constant product formula. Curve (StableSwap) blends constant product with constant sum for stablecoins, giving near-zero slippage around the peg. Balancer generalizes to multiple tokens with configurable weights. Uniswap v3 introduced concentrated liquidity, where LPs choose a price range, dramatically improving capital efficiency.