Automated Market Makers (AMMs) are the engines powering decentralized exchanges. Instead of matching buyers with sellers, AMMs use mathematical formulas and liquidity pools to enable trading 24/7 without intermediaries. This guide explains how AMMs work from first principles.
Traditional Exchanges vs AMMs
Traditional exchanges (NYSE, Binance, etc.) use order books:
- Buyers post bid prices
- Sellers post ask prices
- The exchange matches orders when prices align
- Requires market makers to provide liquidity
AMMs replace this with liquidity pools:
- Token pairs locked in smart contracts
- Mathematical formulas determine prices
- Anyone can be a liquidity provider
- Trade instantly against the pool
The Constant Product Formula
Most AMMs use the constant product formula: x × y = k
Where:
- x = Amount of Token A in pool
- y = Amount of Token B in pool
- k = A constant that must stay the same
How a Trade Works
Example: ETH/USDC pool with 10 ETH and 20,000 USDC (k = 200,000)
- Trader wants to buy 1 ETH
- Pool will have 9 ETH after
- To maintain k: 9 × y = 200,000
- y = 22,222.22 USDC needed in pool
- Trader pays: 22,222.22 – 20,000 = 2,222.22 USDC
- Price = 2,222.22 USDC per ETH (plus fees)
Types of AMMs
| Type | Formula | Best For | Examples |
|---|---|---|---|
| Constant Product | x × y = k | General trading | Uniswap V2 |
| Concentrated | Custom ranges | Capital efficiency | Uniswap V3 |
| StableSwap | Hybrid curve | Stablecoins | Curve |
| Weighted | Multi-asset | Index funds | Balancer |
Key Takeaways
- AMMs use math formulas instead of order books
- Liquidity pools enable 24/7 trading
- Anyone can provide liquidity and earn fees
- Different AMM types suit different use cases
- Slippage increases with trade size relative to pool