AMMs and the constant product formula
Explain how an automated market maker prices trades using x * y = k, and why that matters for every swap.
Lesson path
Crypto and DeFi
DeFi Primer
Pass the check before saving this lesson.
Pass the check to unlock nextOpen track mapChange starting pointToday's tiny win: make one idea click.
Explain how an automated market maker prices trades using x * y = k, and why that matters for every swap.
How a swap pool prices a trade
On a normal exchange, when you buy, someone else has to be selling. The exchange matches you up. An AMM — automated market maker — works completely differently. There is a pool with two tokens in it. Say it holds 10 ETH and 30,000 USDC. When you want to swap, you trade with the pool itself. The pool decides the price using one rule, and that rule never changes: x times y equals k. Reserve of token X, times reserve of token Y, has to stay the same.
Here is what that means in practice. The starting pool has 10 ETH and 30,000 USDC. So k = 10 * 30,000 = 300,000. The implied price of 1 ETH is 30,000 / 10 = 3,000 USDC. Now you buy 1 ETH. After the trade the pool must still satisfy k = 300,000. You took 1 ETH out, so the pool has 9 ETH left. To keep k constant, the USDC side has to rise to 300,000 / 9 = 33,333 USDC. That means you had to put in 3,333 USDC to take out 1 ETH. The new implied price is 33,333 / 9 = 3,704. Your single trade moved the price.
This is why pool depth matters. A small pool moves a lot on a modest trade. A deep pool barely flinches. If you are swapping $500 worth of a small-cap token, the slippage can easily eat 5-15% of your trade. The same $500 in a deep ETH/USDC pool might cost you a fraction of a percent. Most swap interfaces show you the expected slippage before you click — read that number every single time.
On top of the price math, each swap pays a small fee — typically 0.3% in classic AMM pools. That fee is the entire revenue model of the people who deposited the tokens into the pool in the first place. We will dig into who those people are, and why their position can lose money even when the fees look good, in the next lesson.
Recap: AMM swaps are priced by x * y = k. Reserves shift, prices move, slippage is the cost. Deep pools = small slippage; thin pools = expensive trades. Always check the expected output before you confirm.
Knowledge check
Answer before moving on.
1. A pool holds 100 ETH and 300,000 USDC (k = 30,000,000). You swap 1 ETH for USDC, ignoring fees. Roughly how much USDC do you get out?
2. Why is pool depth (total reserves) so important for an AMM trade?
Pass the check before saving.
Use the knowledge check first. After you pass it, this card turns into the save-and-continue handoff.