What is automated market maker (AMM)?
A smart contract that prices trades from the ratio of assets held in a pool instead of matching buyers and sellers on an order book.
Not yet verifiedHow we verify
3 min read
In this entry
A smart contract that prices trades from the ratio of assets held in a pool instead of matching buyers and sellers on an order book.
This is what lets a dex run without a central operator. There is no queue of resting orders and no matching engine, just a pool of two assets and a formula that says what one is worth in terms of the other given how much of each the pool holds.
The thing people get wrong is assuming the quoted price is the price they will get. On an order book, a small order fills at the top of the book. On an AMM, every trade moves the ratio, so the price worsens continuously as your order executes. Size, not luck, determines your fill.
How it works
The original design is the constant product formula. The pool holds x units of one asset and y of the other, and the contract enforces that x multiplied by y stays constant across a trade. Buying asset Y removes some from the pool, which raises the amount of X the formula demands, so each successive unit costs more.
Nobody sets that price. Arbitrageurs do, by trading against the pool whenever it drifts from the wider market, which is also how the pool tracks external prices without an oracle.
Liquidity providers deposit both assets in the current ratio and receive an lp token representing their share. They earn a cut of every trade, set by the pool's fee tier, and they carry impermanent loss, which is the gap between holding the pair in the pool and simply holding the two assets.
Concentrated liquidity designs let a provider place capital only within a chosen price range, which raises depth where trading actually happens and means the provider earns nothing when price leaves the range.
Example
Illustrative constant-product pool holding 10 ETH and 30,000 USDC, so the product is 300,000 and the spot rate is 3,000 USDC per ETH. You buy 1 ETH. The pool must keep the product constant, so USDC must rise to 300,000 divided by 9, which is 33,333.33. You pay 3,333.33 USDC for 1 ETH, an average of 3,333.33 against a starting rate of 3,000, which is 11.1% of price impact before any fee. In a pool ten times deeper the same trade costs about 1.1%. Figures are illustrative and ignore fees.
Why it matters when you buy
If you buy through a decentralized venue or an aggregator, pool depth is the whole story on price, and it varies enormously between assets. A thin pool turns a modest order into a bad fill regardless of what any chart says the asset is worth. Check depth before size at the liquidity pages, and compare with the order-book venues at the exchange directory.
Related terms
- liquidity pool — the reserves the formula prices against
- price impact — how far your own order moves the rate
- impermanent loss — the cost of providing liquidity
- lp token — the receipt for a pool deposit
- concentrated liquidity — depth placed within a price range
- sandwich attack — the attack a loose slippage setting enables
Questions
Why did my trade fill worse than the quote?
Either the pool moved between quote and execution, or your order was large relative to pool depth. Both show up as price impact, and both get worse as the pool gets thinner.
Is an AMM cheaper than an exchange?
Not reliably. Trading fees can be lower, but you also pay network fees and price impact. For small orders in deep pools it can be competitive; for large orders in thin ones it is usually far worse.
Who sets the price in a pool?
No one. The formula sets it from the current reserves, and arbitrage traders keep those reserves roughly in line with prices elsewhere by trading whenever a gap appears.