What is an automated market maker?
An automated market maker, or AMM, is a smart contract that holds a pool of two tokens and quotes prices from a formula instead of matching buyers with sellers. You swap against the pool, and every trade moves its price. The people who supply the tokens earn fees and carry a risk called impermanent loss.

On an exchange with an order book, your trade needs someone on the other side at a price you accept. If nobody is there, you wait.
An automated market maker, or AMM, replaces that person with a pool of tokens and a formula written into a smart contract. As long as the pool holds tokens, it will quote you a price.
Why order books are hard on a blockchain
An order book is a list of buy and sell orders that traders and market makers keep updating. On a blockchain, every new order, change and cancellation is a transaction that pays a fee and waits for a block.
An AMM needs no stream of orders. Liquidity providers deposit tokens into a pool, and the contract prices every trade from the pool's balances. Many decentralized exchanges in DeFi work this way.
The constant product formula
The best-known design keeps one number fixed. Multiply the amounts of the two tokens in the pool, and the result must stay the same after each trade, before fees. It is written x × y = k.
Take an illustrative pool of 100 ETH and 200,000 USDC. Then k = 100 × 200,000 = 20,000,000. The pool's price is the ratio of the two balances: 200,000 ÷ 100 = 2,000 USDC per ETH.
When you add one token, the formula decides how much of the other you get back, so the product stays at 20,000,000. Each ETH you take out leaves fewer behind, so the next one costs more.
Worked example: a 10,000 USDC swap
The numbers are illustrative, and the pool fee is left out for now.
- You put in 10,000 USDC. The pool now holds 200,000 + 10,000 = 210,000 USDC.
- To keep k, the pool's ETH must fall to 20,000,000 ÷ 210,000 = 95.238 ETH.
- You receive 100 minus 95.238 = 4.762 ETH.
- Your average price is 10,000 ÷ 4.762 = 2,100 USDC per ETH, 5% above where the pool started.
- The pool's new price is 210,000 ÷ 95.238 = 2,205 USDC per ETH.
The gap between 2,000 and your 2,100 is price impact, the cost of moving the pool with your own trade.
In this design it follows a simple rule: the extra you pay, in percent, equals your trade as a share of the pool's USDC. 10,000 is 5% of 200,000.
| You pay in | ETH out | Average price | Above 2,000 |
|---|---|---|---|
| 1,000 USDC | 0.4975 | 2,010 | 0.5% |
| 10,000 USDC | 4.7619 | 2,100 | 5% |
| 50,000 USDC | 20.0000 | 2,500 | 25% |
A deeper pool moves less for the same trade, which is what good liquidity means here. In a pool of 200 ETH and 400,000 USDC, the same 10,000 USDC pays 2.5% above 2,000 instead of 5%.
Real pools also charge a fee, such as 0.3%. In this design it comes off your 10,000 USDC first: 30 USDC.
The other 9,970 USDC goes through the formula and buys 4.748 ETH, an average of 2,106 USDC per ETH. The 30 USDC stays in the pool, and that is how the liquidity providers get paid.
How the pool price follows the market
After your swap the pool says 2,205, while other markets still say 2,000. An arbitrage trader buys ETH elsewhere at 2,000 and sells it into the pool.
Selling 4.762 ETH brings the pool back to 100 ETH and 200,000 USDC, and its price back to 2,000. The trader receives 10,000 USDC for ETH that cost about 9,524 USDC elsewhere, a profit of about 476 USDC before fees.
That profit came from your trade: you paid 10,000 USDC for ETH worth 9,524 USDC at the market price. Arbitrage keeps the pool in line with other markets, and your price impact is what the arbitrage trader earns.
Liquidity providers and impermanent loss
The tokens in a pool come from liquidity providers. Each deposits both tokens in equal value, receives a share of the pool recorded as LP tokens, and earns trading fees in proportion to that share.
In return, they carry impermanent loss. When the price moves, arbitrage leaves the pool holding more of the token that fell and less of the one that rose, compared with simply keeping both.
The numbers below are illustrative, and fees are left out.
- You deposit 10 ETH and 20,000 USDC, worth 40,000 USDC at 2,000. With your deposit, the pool holds 100 ETH and 200,000 USDC, so your share is 10%.
- The ETH price elsewhere rises to 8,000. Arbitrage traders buy ETH from the pool until its price is 8,000 too.
- With k = 20,000,000 and a price of 8,000, the pool holds 50 ETH and 400,000 USDC. Check: 50 × 400,000 = 20,000,000, and 400,000 ÷ 50 = 8,000.
- Your 10% is 5 ETH and 40,000 USDC, worth 5 × 8,000 + 40,000 = 80,000 USDC.
- Had you kept the tokens in your wallet, they would be worth 10 × 8,000 + 20,000 = 100,000 USDC.
Your pool share grew from 40,000 to 80,000 USDC, yet it trails holding by 20%. A fall to 500 USDC per ETH gives the same 20% gap, and a doubling of the price gives about 5.7%.
The loss is called impermanent because it shrinks back to zero if the price returns to 2,000 before you withdraw. Withdraw at any other price and it becomes permanent.
Trading fees earned while you wait can cover part or all of the gap, depending on how much trading the pool sees.
Questions
Who sets the price in an automated market maker?
The formula sets it from the pool's balances, and arbitrage traders keep those balances in line with other markets. Nobody posts a quote.
What does x × y = k mean?
The amounts of the two tokens in the pool, multiplied together, must stay the same after each trade, before fees. That rule makes each unit you take out cost more than the last.
Can impermanent loss be avoided?
Not in a pool of two tokens whose prices can drift apart. It is smallest in pools of two tokens that track each other, such as two dollar stablecoins.
Why did I get fewer tokens than the quoted price suggested?
Your own trade moved the pool's price, the pool took its fee, and other trades may have landed just before yours. Your slippage tolerance sets how much of that you accept before the swap fails.
Keep learning
Chapter 3What is DeFi?DeFi, short for decentralized finance, is trading and lending run by smart contracts on a public blockchain instead of by a company. You use it straight from your own wallet, with no account to open, at any hour. The same code that makes it open to anyone also makes its mistakes and losses final.
Chapter 3DeFi lending and yield: where the risk sits.In DeFi lending you lock more crypto than you borrow, and a contract sells part of your collateral if its value falls too far. Lenders earn the interest borrowers pay, minus a cut for the protocol. The risk sits in the collateral price, the code, the price feeds it trusts, and yields paid in new tokens.