DeFi

How DEXs Work: AMMs and Liquidity Pools

Constant-product AMMs, pools, and how a swap executes without an order book.

6 min readReviewed by Pim Feltkamp · Aug 11, 2026, 09:42 PM

Before this guide, read What Is DeFi?.

A decentralized exchange (DEX) lets you swap one token for another directly from your wallet, with no company holding your funds and no order book matching buyers to sellers. Most DEXs use an automated market maker (AMM): a smart contract holding a pool of two tokens, which prices every trade with a simple formula. Understanding that formula — and what it costs you as trade size grows — is the core skill for using DEXs well.

Why DEXs Abandoned the Order Book

Traditional exchanges run order books: lists of bids and asks that a matching engine pairs up. Order books work well when professional market makers constantly post and update thousands of quotes. On a blockchain, every update is a transaction that costs gas, so continuously refreshed quotes were impractical on early Ethereum.

The AMM was the workaround. Instead of matching your order against another trader, you trade against a pool of tokens locked in a smart contract. The pool always quotes a price, for any size, at any hour, with no counterparty needed. This is why an AMM can offer instant liquidity for thousands of obscure tokens that no professional market maker would touch — and also why trading against one has costs an order book doesn't.

The Constant Product Formula

The classic AMM design, popularized by Uniswap, is the constant product market maker. The rule: the product of the two token reserves must stay the same across a trade.

If a pool holds x units of token A and y units of token B, the contract enforces:

x * y = k

Suppose a pool holds 100 ETH and 300,000 USDC. Then k = 30,000,000, and the implied price is 300,000 / 100 = 3,000 USDC per ETH.

Now you swap 30,000 USDC for ETH. The pool's USDC balance rises to 330,000. To keep k constant, the ETH balance must fall to 30,000,000 / 330,000 ≈ 90.91 ETH. The pool releases the difference: 100 − 90.91 = 9.09 ETH.

Notice what happened. At the quoted price of 3,000, your 30,000 USDC "should" have bought 10 ETH. You received 9.09 — an effective price of about 3,300 USDC per ETH, roughly 10% worse than the quote. That gap is price impact, and it is the defining property of AMMs: the formula makes each additional unit you buy more expensive, smoothly and automatically. A trade of 300 USDC in the same pool would have had a price impact of about 0.1% — barely noticeable. Trade size relative to pool size is everything.

This is also how the pool's price tracks the wider market. If ETH rises to 3,500 elsewhere, arbitrage traders buy the pool's now-cheap ETH until the ratio of reserves implies 3,500 too. AMM prices are kept honest not by the contract but by arbitrageurs profiting from any gap.

Where the Liquidity Comes From

The tokens in the pool belong to liquidity providers (LPs) — users who deposit both assets, typically in equal value, in exchange for a share of the pool.

Their incentive is fees. Each swap pays a fee — commonly around 0.3% on classic pools, with newer designs offering tiers from 0.01% for stablecoin pairs up to 1% for volatile ones — which is added to the pool and accrues to LPs in proportion to their share. In a busy pool, this fee stream can be substantial; in a quiet one, it is negligible.

Providing liquidity is not passive interest, though. Because the formula always sells the rising asset and accumulates the falling one, LPs systematically end up with less of whatever appreciated. This cost — impermanent loss — is significant enough that it gets its own guide later in this path. For now, the essential point: LP returns are fees earned minus that rebalancing cost, and the net result is frequently worse than simply holding the two tokens.

Newer AMM designs refine the basic formula. Concentrated liquidity (introduced by Uniswap v3) lets LPs commit their capital to a chosen price range instead of spreading it from zero to infinity, which deepens liquidity around the current price. Stableswap curves (Curve's design) flatten the pricing formula for assets that should trade near parity, such as two dollar stablecoins, so large swaps execute with minimal impact.

Anatomy of a Swap, Step by Step

Here is what actually happens when you swap tokens through a DEX interface:

  1. Approval. For a token you have never traded there, you first sign an approval transaction letting the DEX's router contract move that token from your wallet. This is a separate transaction with its own gas cost, and approvals persist until revoked.
  2. Quote and routing. The interface computes the best path. Your trade may route through multiple pools — for example token A to ETH to token B — if that produces a better net price than a direct pool.
  3. Slippage tolerance. You set the worst execution you will accept, commonly 0.1–1%. Prices can move between the moment you sign and the moment your transaction is processed; if the final execution would breach your tolerance, the whole transaction reverts (you still pay gas).
  4. Execution. You sign the swap. The contract takes your input token, applies the formula, deducts the fee, and sends the output token to your wallet — all atomically, in one transaction. There is no settlement delay and no counterparty holding your funds.

A caution attached to step 3: on public blockchains, pending transactions are visible before they confirm, and automated bots can exploit generous slippage settings by trading ahead of you and selling back after — a "sandwich" that pockets your tolerance as their profit. Keeping slippage tight and trade sizes moderate limits this.

What DEXs Are Good and Bad At

DEXs are strong where their design shines: self-custodial trading with atomic settlement, access to new and long-tail tokens, transparent on-chain pricing, and availability to anyone at any time. There is no account, no listing committee, and no exchange holding your assets that can fail with them inside.

They are weak in mirror-image ways. Every trade costs gas, which makes small trades on busy networks disproportionately expensive (layer 2 networks reduce this substantially). Price impact punishes size in shallow pools. Open, permissionless listing means anyone can create a pool for a worthless or malicious token — a token being tradable on a DEX signals nothing about its quality. And the pools themselves are smart contracts, carrying the code risk that applies to everything in DeFi.

A practical habit: before any meaningful swap, check the pool's liquidity and simulate the trade in the interface to see the quoted price impact. If a $2,000 swap shows 4% impact, the pool is too shallow for your size — split the trade, use an aggregator that routes across venues, or reconsider.

Key Takeaways

  • Most DEXs are automated market makers: you trade against a token pool priced by a formula, not against another trader's order.
  • The constant product rule x * y = k means price worsens smoothly as your trade grows; price impact depends on your size relative to the pool.
  • Arbitrage traders, not the contract, keep AMM prices aligned with the wider market.
  • Liquidity providers fund the pools and earn swap fees, but their returns are reduced by a structural rebalancing cost covered in the impermanent loss guide.
  • Set slippage tolerance tightly, expect gas plus fees plus impact as your true cost, and remember that being tradable on a DEX says nothing about a token's legitimacy.

Educational content, not financial advice. Read the full disclaimer.

Next in DeFi

Impermanent Loss Explained