Automated Market Makers (AMMs) are the formulas that power liquidity-pools. They’re what decide the exchange rate when you trade on a decentralized exchange.
The Formula
The most common AMM formula is dead simple:
Where:
x= amount of token A in the pooly= amount of token B in the poolk= a constant that never changes
That’s it. This one equation runs billions of dollars in trading volume.
The Mango-Banana Market
Let me show you exactly how this works.
You and your friends create a fruit exchange pool with 50,000 mangoes and 50,000 bananas. The constant k = 50,000 x 50,000 = 2.5 billion.
Right now, 1 mango = 1 banana (equal amounts in the pool).
graph LR subgraph before["Pool Before Trade"] M1["🥭 50,000 mangoes"] --- B1["🍌 50,000 bananas"] end
Now Ravi shows up with 7,000 bananas and wants mangoes.
After adding his bananas, the pool has 57,000 bananas. How many mangoes should he get?
The formula says: mangoes x 57,000 = 2,500,000,000
So: mangoes = 2,500,000,000 / 57,000 = 43,860
The pool needs to keep 43,860 mangoes. It had 50,000. So Ravi gets 6,140 mangoes (not 7,000!).
graph LR subgraph after["Pool After Trade"] M2["🥭 43,860 mangoes"] --- B2["🍌 57,000 bananas"] end
What happened to the prices?
- Mangoes: 50,000 / 43,860 = ₹1.14 per mango (was ₹1.00) — price went up because supply went down
- Bananas: 50,000 / 57,000 = ₹0.88 per banana (was ₹1.00) — price went down because supply went up
The price adjusted automatically based on supply and demand. No human set the price. No order book. Just math.
Slippage — Why Big Trades Get Worse Rates
Notice Ravi put in 7,000 bananas but only got 6,140 mangoes — not 7,000. That difference is called slippage.
The bigger your trade relative to the pool, the worse your rate:
| Trade size (bananas in) | Mangoes out | Effective rate |
|---|---|---|
| 100 | ~99.8 | ~1:1 (barely any slippage) |
| 7,000 | ~6,140 | ~1:0.88 (noticeable) |
| 25,000 | ~16,667 | ~1:0.67 (terrible) |
Bigger pools = less slippage. If the pool had 20 million mangoes and 20 million bananas instead of 50,000, even a 10,000 banana trade would barely move the price. This is why protocols fight to attract liquidity — bigger pools = better trading experience.
Liquidity Providers and Rewards
Every trade charges a small fee (usually 0.3%). This fee is added to the pool, growing k over time. Liquidity providers (the people who deposited into the pool) get their proportional share of these fees when they withdraw.
flowchart TD T["Ravi trades:<br/>7,000 bananas → 6,140 mangoes<br/>+ 0.3% fee (21 bananas)"] --> P["Pool grows slightly<br/>Fees accumulate"] P --> LP["Liquidity providers<br/>earn a share of fees 💰"]
It’s small per trade, but with thousands of trades per day, it adds up. This is the whole incentive for providing liquidity.
Beyond x * y = k
The constant product formula is the simplest AMM, but there are variations:
- Curve uses a different formula optimized for tokens that should be nearly equal (stablecoins). Much less slippage for USDC/USDT trades
- Balancer allows pools with more than 2 tokens and custom weight ratios (like 80/20 instead of 50/50)
- Uniswap v3 introduced “concentrated liquidity” — LPs can choose a price range to provide liquidity in, making capital more efficient
The fundamentals are the same though. Math replaces humans in setting prices.
What’s Next?
Now that you understand how AMMs work, read about impermanent-loss — the main risk of being a liquidity provider. It’s the gotcha that catches most beginners off guard.