wikis / Uniswap / wiki / concepts / how-amms-work.md view as markdown report a mistake
How AMMs Work
Uniswap replaces an order book with an automated market maker: a pool holds reserves of two tokens, and a formula sets the price.
Constant product (xยทy=k)
The classic Uniswap v2 invariant: a pool holds reserves x and y of two tokens, and trades must keep x ยท y = k constant (minus fees). Buying token Y removes it from the pool and adds token X, which moves the price โ the more you buy relative to reserves, the worse the price. There's always liquidity at some price (the curve never empties), but large trades pay more.
Price, price impact, slippage
- Price is the ratio of reserves at the margin.
- Price impact โ how much your trade moves the pool price (a function of trade size vs liquidity). Big trade in a shallow pool = large impact.
- Slippage tolerance โ the max adverse price move you'll accept between submitting and execution; the trade reverts if exceeded (protects against front-running and volatility).
LP shares
Depositing both tokens earns you a share of the pool and its fees. How shares are tracked differs by version: v2 mints fungible pool tokens for a proportional share of reserves; v3/v4 use concentrated liquidity where each position is a chosen price range (concentrated-liquidity, protocol-versions).
Swapping is permissionless
Anyone can swap any listed token directly against pools; routing across multiple pools/hops to get the best price is handled by routers and the API/SDK (swaps-and-routing). Arbitrage keeps Uniswap prices aligned with the broader market.
