BR Academy
0%
Module 3: Swaps and Slippage·Lesson 10 of 30·11 min

How Decentralized Exchanges Work

With your wallet set up and approvals understood, you're ready to look at the first real DeFi action most users take: swapping one token for another on a decentralized exchange (DEX). Unlike a traditional stock exchange or a centralized crypto exchange, where buy and sell orders are matched against each other in an order book, most DEXs — Uniswap being the best-known example — use a fundamentally different mechanism called an automated market maker, or AMM.

Instead of waiting for your order to match a counterparty's order, you trade directly against a shared pool of two tokens (for example, an ETH/USDC pool) that other users have deposited. A simple mathematical formula — the most common being the "constant product" formula, x·y=k, where x and y are the quantities of the two tokens in the pool and k is a constant — determines the price based purely on the current ratio of the two tokens in that pool. When you swap, you add one token to the pool and remove the other, which shifts the ratio, which in turn shifts the price for the next trader. This is why larger trades, relative to the pool's size, move the price more than smaller ones — you're not just executing at "the" price, you're changing the price as you trade.

This design has an elegant consequence: there is no need for a human market maker, an order book, or matching engine. Liquidity exists continuously, for any trade size the pool can support, 24/7, set entirely by the formula and the pool's current reserves — which is also precisely why pool depth (covered more in the slippage lessons ahead) matters so much to how good a price you get.

Worked Example

Imagine an ETH/USDC pool holding 100 ETH and 300,000 USDC. Using the constant product formula, the implied price is simply the ratio of the two reserves: 300,000 USDC ÷ 100 ETH = 3,000 USDC per ETH. If you swap 10,000 USDC into the pool to receive ETH, the pool's USDC reserve rises to 310,000 and, to keep the product constant (100 × 300,000 = 30,000,000), the ETH reserve must fall to 30,000,000 ÷ 310,000 ≈ 96.77 ETH — meaning you receive approximately 3.23 ETH for your 10,000 USDC, an effective price of about 3,096 USDC per ETH, noticeably higher than the pre-trade price of 3,000 because your own trade moved the ratio. This gap between the price before your trade and the effective price you actually paid is the mechanical origin of slippage, which the next lessons in this module explore in depth.

Note also that after your trade, the pool's new implied price (96.77 ETH to 310,000 USDC, or roughly 3,204 USDC per ETH) is now the new starting point for the next trader — the AMM has no memory of "yesterday's price" beyond what the current reserves imply, which is also why external arbitrageurs constantly trade against AMM pools to keep their implied price in line with prices on other exchanges.

It's also worth understanding what AMMs give up relative to an order book, so you know when to expect the trade-offs covered later in this module. Because the price is entirely a function of the current reserves, an AMM pool cannot "remember" that a large seller is about to arrive, cannot offer price improvement the way a matched order book sometimes can, and will always show some degree of price impact for any trade large enough relative to its depth — there's no way around this mechanically, only pools deep enough that it becomes negligible for your particular trade size. This is precisely why "pool depth" (also called total value locked, or TVL) is one of the first numbers experienced DeFi users check before trading any pair they're not already familiar with.

Why This Design Won

AMMs became the dominant DEX design for a simple reason: they require no order-book infrastructure, no matching engine, and no need for a counterparty to be actively placing an opposing order at the same moment you want to trade. Anyone can become a liquidity provider (covered in Module 4) simply by depositing tokens into the pool's smart contract, and the formula handles pricing automatically for every trade, at any hour, without needing active market makers to show up and quote prices the way a traditional exchange requires. This is also why AMMs scale so well to the long tail of smaller, less-traded tokens that would never attract a dedicated market maker on a traditional order-book exchange — the formula works identically whether the pool holds $50,000 or $500,000,000, just with correspondingly more or less price impact per trade.

Exercise

Look up a live ETH/USDC pool (or a comparable major pair) on a DEX's interface, or use a cached screenshot or example if live access isn't available, and note the pool's two reserve balances as displayed. Calculate the implied price yourself by dividing the USDC reserve by the ETH reserve, exactly as shown in the worked example above.

Then compare your calculated implied price to the price the interface quotes for a small trade (small relative to the pool's total size). They should be very close — confirming that the AMM formula, not a hidden order book, is what's setting the price you're quoted. Note any small difference and consider whether it might be due to trading fees (which are added on top of the raw formula) rather than the formula itself — fee mechanics are covered in Module 4.

Recap

  • DEXs typically use automated market makers (AMMs), pricing trades from a pool's token ratio via a formula like x·y=k, rather than matching buy and sell orders.
  • Your own trade size, relative to the pool's depth, mechanically shifts the price — larger trades move the ratio (and the price) more than smaller ones.
  • Verifying the implied price from raw reserves against the quoted swap price confirms how AMM pricing actually works before you execute a real trade.

Resources