Foundations · Exchanges, DEX & DeFi

AMMs & Liquidity Pools

An automated market maker (AMM) prices trades with a formula applied to a pool of two tokens, instead of matching buyers and sellers in an order book.

  • Intermediate
  • 5 min read
  • Updated

Why it matters

Most trading on decentralized exchanges does not match a buyer with a seller. It runs through pools of tokens priced by a formula. That design decides what price a trader receives, why large trades cost more, and where the risks of supplying a pool come from.

How it works

A constant-product liquidity pool
020405101520Before swapAfter swapToken A in the poolToken B in the pool
In a simple AMM, the product of the two token balances stays constant. Every swap moves the pool along this curve, which is what changes the price.

A liquidity pool is a smart contract that holds reserves of two tokens. An automated market maker (AMM) is the rule the contract uses to set the exchange rate between them. Traders do not trade with each other. They trade with the pool.

The best-known rule is the constant product formula, popularized by Uniswap:

x × y = kx and y are the pool's balances of the two tokens. A swap changes x and y but must leave their product, k, unchanged (apart from the fee, which is added to the pool).

The pool’s price is the ratio of the two balances: y divided by x gives the price of one unit of the first token, measured in the second.

The figure shows a tiny pool with 5 A and 20 B, so k = 5 × 20 = 100 and A is priced at 20 / 5 = 4 B. A trader sends in 5 A:

  • the pool now holds 10 A, so it must hold 100 / 10 = 10 B;
  • the trader receives the other 10 B;
  • the trader’s average price was 10 / 5 = 2 B per A;
  • the pool’s new price is 10 / 10 = 1 B per A.

One trade doubled the pool’s A balance and cut its price by three quarters. That is an extreme case, chosen to make the movement visible.

In plain words

Imagine a market stall with two baskets, apples and oranges, and one rule: the fuller the apple basket gets, the fewer oranges each new apple earns. Nobody haggles. Every swap changes the baskets, and the baskets set the next price.

Price impact

One pool, three trade sizes
Swap in 1,000 B (1% of the pool's B)about 1% worse

Average price 101 B per A.

Swap in 5,000 B (5%)about 5% worse

Average price 105 B per A.

Swap in 10,000 B (10%)about 10% worse

Average price 110 B per A.

The pool holds 1,000 A and 100,000 B, so it starts at 100 B per A. The larger the trade relative to the pool, the further the average price moves from that starting price. Hypothetical: ignores the swap fee.

Because every swap moves the pool along its curve, the trader’s own order changes the price it receives. The difference between the pool’s starting price and the average price of the trade is called price impact.

What matters is the size of the trade relative to the pool. A trade equal to 1% of a reserve moves the average price by about 1%. The same trade in a pool ten times larger would move it by about 0.1%. Deep pools behave like markets with good liquidity, and shallow pools do not.

Why the pool price follows the market

A pool does not know what a token is worth elsewhere. It knows only its two balances. When the price on other venues moves, the pool’s price is briefly out of date.

Traders then buy the token that is too cheap in the pool and sell it where it is dearer, until the gap is smaller than the fee. This is arbitrage, and it is what keeps pool prices close to the wider market. The profit those traders collect is taken from the pool, which is the origin of impermanent loss.

Going deeper

Fees. Each swap pays a small percentage that stays in the pool and belongs to the liquidity providers who supplied the tokens. What providers earn this way is variable and is not guaranteed. Extra rewards are often paid in a token whose price can fall, and the whole amount comes with the risks of the pool.

Who sets the first price. The first depositor chooses the starting ratio. If it is wrong, arbitrage corrects it at that depositor’s expense.

Other formulas. Constant product is one design among several. Some pools use curves built for assets that are meant to trade at nearly the same price, which gives less price impact near that price. Others let providers place their tokens within a chosen price range, or hold more than two tokens at unequal weights. The reasoning on this page applies to all of them, but the numbers do not.

No order book. There are no bids or offers to read. The equivalent of market depth is the size of the reserves. The comparison with quoted markets is covered in market makers.

Three trades against one hypothetical poolHypothetical illustration

Made-up numbers, ignoring the swap fee. A pool holds 1,000 A and 100,000 B. The price is 100,000 / 1,000 = 100 B per A, and k = 1,000 × 100,000 = 100,000,000.

A trader swaps in 10,000 B:

  • new B balance: 100,000 + 10,000 = 110,000;
  • required A balance: 100,000,000 / 110,000 = 909.09;
  • A paid out: 1,000 - 909.09 = 90.91;
  • average price: 10,000 / 90.91 = 110 B per A, which is 10% above the starting price.
B swapped in A received Average price New pool price
1,000 9.90 101.00 102.01
5,000 47.62 105.00 110.25
10,000 90.91 110.00 121.00

After the largest trade the pool quotes 110,000 / 909.09 = 121 B per A. If the wider market is still at 100, an arbitrageur can sell A into the pool until its price returns there.

What it does NOT mean

  • The pool’s price is not “the” market price. It is the ratio of two balances, and one large trade can move it.
  • No order book does not mean no trading cost. Price impact and the swap fee take the place of the spread.
  • A pool that cannot run dry is not a pool that trades at a fair price. Under constant product the reserve never reaches zero because the price climbs without limit as it shrinks.
  • A pool existing says nothing about the token in it. Anyone can create a pool for any token.
  • Constant product is not how every AMM works. Other designs follow different curves.

Common misunderstandings

  1. Reading the displayed price as the trade price. The displayed price is for an infinitely small trade. Real trades get the average along the curve.
  2. Ignoring pool size. The same order can cost 0.1% in one pool and 10% in another.
  3. Assuming the pool sets the price. Arbitrage drags the pool toward prices set elsewhere.
  4. Using a small pool’s price as a reference. A thin pool is cheap to push around, a weakness described in smart contract risk.

Risks and limits

  • Thin pools give poor prices and are easy to manipulate.
  • The pool contract can contain bugs, and a flawed token inside a pool can drain the other side of it.
  • Prices in a pool lag fast markets until arbitrage catches up.
  • Published formulas describe the design. Fees, upgrades and special token behavior can change the outcome in practice.

Key takeaway

An AMM replaces the order book with a pool and a formula. Under constant product, every swap moves the price, and the bigger the trade is relative to the pool, the worse the average price becomes.

Sources and further reading