Candleread
Crypto and DeFi · DeFi Primer

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.

3 min read+25 XPLesson 51 of 79
Start reading

Lesson path

Crypto and DeFi

DeFi Primer

Lesson 51 of 7965%
Lesson 51 of 79Crypto and DeFiDeFi Primer

Today'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.

Learn itSpot itPass the check

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.

Wick points at a chalkboard working the pool math: 10 ETH times 30,000 is 300,000, buy 1 ETH and 9 are left, so the price moves from 3,000 to 3,704.x × y = k10 ETH × 30,000 = 300,000Buy 1 ETH, 9 ETH leftPrice 3,000 → 3,704
Wick saysBuying 1 ETH from a 10 ETH pool moved the price from 3,000 to about 3,704.

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.

Wick watches a scale where the thin pool side with 5 to 15% slippage sinks below the deep pool side with tiny slippage, showing why pool depth matters.Deep poolTiny slippageThin pool5 to 15% slip?
Wick saysThe same $500 swap barely moves a deep pool but can lose 5 to 15% in a thin one.

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.

Wick pays a coin marked 0.3% fee at a swap pool gate, with a note that the fee goes to liquidity providers, showing how pools earn from every trade.Swap poolFee goes to liquidityproviders0.3% fee$
Wick saysEach swap in a classic pool pays about 0.3%, and that fee goes to the people who fund it.

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.

0 / 2 answered

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?

Lesson handoff

Pass the check before saving.

Use the knowledge check first. After you pass it, this card turns into the save-and-continue handoff.