Foundations, guide 4 of 14

Automated Market Makers Explained: How an AMM Actually Works

How an AMM quotes a price from its own reserves, what three generations of design changed, where your execution cost really comes from, and what to check first.

On a normal exchange, your buy order waits until somebody posts a matching sell. An automated market maker, or AMM, removes the waiting. It always has a price, because it works one out from what it is holding right now.

That is the whole trick, and it is also the whole problem. The contract has no idea what your token is worth anywhere else. It quotes from its own shelves, and it keeps quoting the old number until someone trades against it.

By the end you should be able to tell which kind of pool you are looking at, estimate what a trade through it will really cost, and know what to check before you trade or deposit.

An automated market mechanism moves token inventory along a pricing curve.
An automated market maker operates as an inventory rule governed by an invariant curve. Original editorial illustration by LiquidityPools.app.

Key point: People read the pool rule as a price formula. It is better read as a boundary the contract is not allowed to cross. The price is a by-product: whatever rate keeps the contract on the right side of that boundary for your trade. Nothing in the rule knows the market price, so traders from outside are what pull the pool back in line.

An AMM is a shelf, not a price feed

Picture a shop with two shelves. One holds ETH, the other holds USDC. The rule says the two shelf counts multiplied together must never fall[1].

Take ETH off the first shelf and you have to put enough USDC on the second to keep that number level. Take more and you have to put on proportionally more still. That is where the price comes from, and it is why the rate gets worse as your order gets bigger.

Order books are expensive to run on a blockchain, because every new order and every cancellation is a paid transaction. Decentralised exchanges adopted this shelf rule largely to avoid that cost[9].

The pool never checks anywhere else. It does not know ETH just moved on Binance. It keeps offering the old rate until someone walks in and takes the good side, which is exactly what arbitrage traders do all day. That trading is what keeps a constant-product pool’s price close to the wider market[10]. The formal treatment is in Constant Product Formula. If the pool itself is new to you, start with What Is a Liquidity Pool?.

The one relationship the pool refuses to break is called its invariant — the rule holding the shelves in line. Different pools use different ones, and that choice decides how the price behaves[10].

How AMM design changed over three generations

Generation What it looked like Where money sat Fee The catch
First, Uniswap v1 and v2 One contract per pair Spread across every price 0.30% on every pool[4] Tokens moved on every hop, so routing was expensive
Second, Uniswap v3 One contract per pair, money in bands Only in the band you chose A few fixed tiers, from 0.01% to 1%[4] Money outside the live band does nothing
Third, Uniswap v4 Every pool in one contract Bands, plus custom code Any level, or set by a hook as conditions change[4] Hooks are code, and code can be written badly

First generation: one contract per pair

Every pair got its own contract. Every swap moved real tokens in and real tokens out[1]. A trade routed through three pools paid for every one of those transfers, which made multi-hop routing costly[3].

Second generation: money in a chosen band

Uniswap v3 let you put money into a price band instead of across the whole range[2]. The same deposit could absorb far more trading, so it earned far more while the price stayed inside. But depth became patchy: money outside the live band earns nothing and fills nothing[2].

Third generation: one contract for everything

Uniswap v4 puts every pool inside a single contract — a pattern called a singleton, because one contract holds them all[3]. Three things follow:

  • The tokens stay put during a trade. The contract keeps a running tally and settles once at the end. This is flash accounting — bookkeeping in temporary memory rather than a real transfer at every step — and it cuts the gas cost of trades that cross several pools[3].
  • Balances can live inside the contract. Routers and depositors can hold internal claims rather than moving tokens back and forth[3].
  • Pools can run their own code. Hooks are separate contracts that fire at set moments: before and after a swap, before and after liquidity moves, and so on[3].

Hooks are what make modern pools interesting and what make them worth checking. The v4 design lists uses such as fees that shift with volatility and limit orders that fill inside the pool[3]. A hook can also do things you would not want, such as charging a fee on withdrawals. Read what a hook does before you deposit behind it.

Where your trading cost actually comes from

Most people look at the fee tier and stop. The fee is often the small part.

Two things decide what you pay. The fee is the advertised one. The other is price impact — how far your own order moves the rate while it executes. The pool takes its fee from your input first, then hands back whatever keeps the product of its balances level[1].

Δy=y−kx+(1−f)⋅Δx\Delta y = y - \frac{k}{x + (1 - f) \cdot \Delta x}

Where:

  • Δx\Delta x is what you put in.
  • Δy\Delta y is what you get out.
  • xx and yy are the two pool balances before your trade.
  • ff is the fee rate, so a 0.30% pool has f=0.003f = 0.003.
  • kk is the number the pool holds level, x⋅yx \cdot y.

The thing to take from it is the denominator. Your input sits at the bottom of a fraction, so the more you send, the less each extra unit gets back. Small trades barely notice. Large ones pay for the whole curve.

Three practical consequences:

  • The quoted price is not your price. The headline rate is for an infinitely small trade. Yours is worse, and how much worse depends on your size against the money actually working near that price. A pool’s total size counts idle money too.
  • A cheap fee tier can be the expensive choice. Send $50,000 into a 0.05% pool with $1M on the side you are paying into, and fee plus impact cost about 4.8%. The same order into a 0.30% pool with $10M costs about 0.8%.
  • Your tolerance setting is a backstop, not a plan. It caps slippage — the gap between the quote you saw and the fill you got, usually because somebody traded in front of you. Set it wide on a public transaction and a bot can push your fill right down to that limit[8][9].

See AMM vs Order Book for how this compares to matching buyers and sellers directly.

How fees actually reach you

A swap fee is what you are paid for standing in the middle. In the older design it is simply added back to the pool, so your share is worth a little more each time[4]. In band-based pools it goes only to the money that was live for that particular trade[2][4].

Not all of it always reaches providers. On Uniswap, governance switched on a protocol fee in December 2025: v2 pools now pay providers 0.25% of the 0.30%, and enabled v3 pools pay providers between three-quarters and five-sixths of their tier, depending on the tier[4].

Newer pools let the fee move rather than sit fixed:

  • Fees that track volatility. LFJ’s Liquidity Book adds a variable fee that rises with recent price movement[7]. Uniswap v4 pools can do the same through a hook[4]. That charges more to the traders picking off stale quotes.
  • Fees that track imbalance. Curve’s newer stable pools raise the fee when a trade pushes the pool further out of balance[6].

Two rules fall out of this. If you are trading, a low headline fee guarantees nothing about your total cost. If you are depositing, your fees stop the instant the price leaves your band, and they stop completely, not partially[4]. To turn a pool’s routed volume, your share of the active liquidity and your time in range into a fee APR, use the liquidity pool fee and APR calculator.

What happens when the price leaves your band

Where the price is What you are holding What you earn
Above your band All of the quote token, having sold the whole way up Nothing
Inside your band A mix, shifting as the price moves Fees on every swap that crosses you
Below your band All of the risky token, having bought the whole way down Nothing

A narrower band earns more per dollar while the price stays inside it, and pushes you outside it more often[2]. That is the entire trade-off, and no setting removes it. A band position therefore needs watching: out of range, you earn nothing and hold the weaker token.

What to check before you trade or deposit

  1. Which rule is the pool using? Full range, chosen band, stepped bins, or a stable-pair curve. Each behaves differently under stress.
  2. Does the pool have hooks, and what do they do? Check whether they can change fees, limit withdrawals, or pause trading[3].
  3. How much money sits near the price? Look within 1% and 2% of the current rate, and compare that to your order size.
  4. Is the pool balanced? For pegged pairs, a stable curve behaves like a flat line near balance and like a constant-product curve when lopsided. A skewed pool is already near the steep part[5].
  5. How are you sending the order? Anything large should go through a private relay or a batch auction rather than the open queue, where pending trades are visible to bots[8].

For how the fee side adds up, see Liquidity Provider Fees.

Where to watch the numbers

  • Simulate a trade before sending it: Tenderly replays swaps against the real contract.
  • Volume against pool size across protocols: DeFiLlama Yields.
  • Your own position and fees earned: Revert Finance.

When something goes wrong

  • A swap keeps reverting with a K error. If you are building on a pool, the check on its rule failed, usually because fees were taken in the wrong order or a rounding step went the wrong way. Deduct fees before the check, and round in the pool’s favour: up for what a trader pays in, down for what they take out.
  • The pool’s price has drifted from everywhere else. If the gap is smaller than the fees an arbitrage trader would pay to close it, nobody profits by closing it, and that is normal. If it is larger, check whether a transfer tax or a pause is blocking arbitrage.
  • Your position is losing money fast. Faster traders are picking off a stale quote. Compare the fee tier against how much the pair has actually been moving.

Where to go next

What a trader pays is broken down in Slippage and Price Impact. What the same curve hands to arbitrage — the cost of a quote that always trails the market by a block — is measured in Loss-Versus-Rebalancing. For the next layer of detail, compare versions in Uniswap v3 vs v4, curve families in Bonding Curves and AMM Invariants, and fee designs in Dynamic Fees in AMMs.

References

  1. Uniswap v2 Core Whitepaper (Adams et al., 2020)
  2. Uniswap v3 Core Whitepaper (Adams et al., 2021)
  3. Uniswap v4 Core Whitepaper (Adams et al., 2024)
  4. Fees (Uniswap Developer Documentation)
  5. Curve StableSwap Exchange: Overview (Curve Knowledge Hub)
  6. Stableswap-NG: Overview (Curve Knowledge Hub)
  7. Fees (LFJ Developer Docs)
  8. Maximal extractable value (MEV) (ethereum.org)
  9. DeFi risks and the decentralisation illusion (BIS Quarterly Review, December 2021)
  10. An Analysis of Uniswap Markets (Angeris et al., 2019)

Frequently asked questions

How does an AMM work?

An automated market maker prices trades from a formula applied to its reserves rather than from an order book. Traders deposit one asset and withdraw another, the reserves change, and the formula returns a new price. Arbitrage keeps that price aligned with external markets.

What is the difference between an AMM and a DEX?

A decentralised exchange is the venue; an automated market maker is one mechanism a venue can use to price trades. Some decentralised exchanges run order books instead, and intent-based systems settle through solvers rather than either.

How does a liquidity pool set price?

By the invariant. In a constant-product pool the marginal price is the ratio of the two reserves, so buying an asset reduces its reserve and raises its price for the next trade. Other curve designs change how quickly that happens.

Does an AMM need an order book to set a price?

No. The pool computes a price from its reserves and the curve rule. Traders do not post bids and asks; each swap moves along the curve, and arbitrage brings the quote back in line with other venues.

Continue in this track

This is guide 4 of 14 in Foundations.

Next: AMM vs. Order Book: Three Ways to Get a Trade Done →

Previous: ← What Is a Liquidity Provider? The LP Role, Explained

See the full track sequence, or browse all 59 guides.