Skip to content
72lab
Crypto Basics· Lesson 7 of 10· 7 min

Decentralized Exchanges and Liquidity Pools

A decentralized exchange has no order book: the price comes from the ratio of the two coins in a pool. The more you buy, the bigger the price impact; providing liquidity earns fees but exposes you to impermanent loss.

Risk warning: forex, CFDs, options, futures and crypto assets usually involve leverage or high volatility, and you can lose more than you put in. This lesson only teaches the concepts; all numbers are for illustration and are not investment advice.

This lesson is free: sign up for an account to use the interactive simulation

Every lesson has an interactive simulation you can drag and play, plus a quick quiz. Sign up free to use them and save your progress automatically. Here is the text version of this lesson.

Not sure yet? Try the first lesson (no sign-up needed)「What Is a Blockchain?」。

Text version · Crypto Basics, lesson 7: “Decentralized Exchanges and Liquidity Pools”

A decentralized exchange has no order book: the price comes from the ratio of the two coins in a pool. The more you buy, the bigger the price impact; providing liquidity earns fees but exposes you to impermanent loss.

No order book: the pool's ratio is the price

On a decentralized exchange (DEX), there's no one quoting on the other side: you trade directly with a liquidity pool. The pool holds two coins, and price = amount of USDT ÷ amount of ETH. Put USDT in and take ETH out, and the ETH shrinks while the USDT grows, so the price rises. A common rule keeps the two amounts multiplied together constant, known as the constant product rule.

The more you buy, the higher your average price

Your price impact is roughly your order's share of that side of the pool: spend 1% of the pool's USDT and your average price is about 1% higher. The smaller the pool, the bigger the impact of the same money. Set a slippage tolerance before you trade: if the actual fill comes in too far from the quote, the transaction reverts automatically.

Providing liquidity: earn fees, take on impermanent loss

Put equal values of the two coins into the pool and you earn a share of the trading fees (illustrative; 0.3% is common). The cost is impermanent loss: whether the price rises or falls, the pool sells what's rising and buys what's falling, so you end up with less than if you'd just held. If the price doubles you're about 5.7% behind, and if it returns to where you deposited, the gap disappears.

Look before you approve: one signature can let your coins be taken

The first time you trade a coin, your wallet asks you to sign an "approval" that lets a contract spend that coin. Phishing sites often trick you into signing an unlimited approval, after which they can move your coins without asking you again. Only use sites you recognize, approve just the amount you need, and revoke approvals you no longer use.

Key takeaways

  • A decentralized exchange has no order book; you trade directly with a liquidity pool. Price = the ratio of the two coins in the pool, and the usual rule keeps the two amounts multiplied together constant.
  • Price impact is roughly your order's share of that side of the pool: the shallower the pool and the bigger the order, the higher your average price. Slippage tolerance limits how far the fill can be from the quote; beyond that, the whole trade reverts.
  • Providing liquidity earns a share of the fees, but any price change brings impermanent loss: up or down, you end up with less than just holding, the bigger the move the bigger the gap, and it only disappears when the price returns to where you deposited.
  • An approval lets a contract spend your coins: only use sites you recognize, approve just the amount you need, and revoke approvals you no longer use.

Try it yourself

You can do these exercises in this lesson's interactive simulation:

  1. Keep the default $150,000: how far above the pool's current price is your average price? What does the pool quote after the trade?
  2. Drag the amount to $300,000 (10% of the pool): how far above $3,000 is the pool's quote after the trade? Is that rise bigger or smaller than the rise in your average price?
  3. Pick "$20k buy ahead": does the trade go through at 0.5% tolerance? What's the lowest tolerance that lets it fill?
  4. Switch to "Provide liquidity" and drag the ETH price to $12,000, then to $1,500: how much less than holding do you have each time? Then raise fee income to $500: in which case do you end up with more than holding?

Quiz and explanations

1. A pool holds 100 ETH and 200,000 USDT. What price does it quote?
2. A pool holds 1,000,000 USDT and you buy with 50,000 USDT (ignoring fees). Roughly how far above the pool's current price is your average price?
3. At an ETH price of $1,000, you put $2,000 into an ETH / USDT pool, half in each coin. ETH later falls to $500. Ignoring fees, how do you compare with just holding?
4. You set a 0.5% slippage tolerance, and the quote says you'll get 10 coins. Before your transaction lands on-chain, someone else pushes the price up and you'd only get 9.9. What happens?
4 questions left to answer. Answers and explanations appear after you submit.

Terms in this lesson

  • decentralized exchange (DEX) (DEX): An exchange where swaps are carried out by smart contracts on a blockchain: there's no account to open, you trade straight from your own wallet, and your coins stay in your hands. Prices usually come from a liquidity pool's formula.
  • impermanent loss (Impermanent Loss): How much less you have after putting two tokens into a liquidity pool than if you'd simply held them, because their price changed. It disappears if the price returns to where it was when you deposited; at 2× the price it's about 5.7%.
  • liquidity pool (Liquidity Pool): Two tokens locked in a smart contract that anyone can swap for one another. A common constant-product pool keeps the product of the two amounts unchanged, and price = the amount on one side ÷ the amount on the other.
  • price impact (Price Impact): How far your own trade moves the price. In a liquidity pool, the bigger your purchase relative to that side of the pool, the further your average fill price ends up above the current price.
  • slippage tolerance (Slippage Tolerance): The largest deviation you'll accept when trading on a decentralized exchange: if the trade would execute worse than the quote by more than this percentage, it fails and is reverted.