DEXs and liquidity pools: how swapping works
On a decentralised exchange, or DEX, you do not trade with another person. You trade with a pool of tokens held by a smart contract. This lesson explains how the pool sets a price and what a swap really costs.
A pool instead of an order book
Lesson 12 described the order book: a list of buyers and sellers that a centralised exchange matches. Most DEXs work differently. They use an automated market maker.
A pool holds two tokens, for example ETH and USDC. Anyone can swap one for the other. The price comes from the ratio of the two tokens in the pool at that moment.
Who fills the pool
People called liquidity providers deposit both tokens, in equal value. In return they receive pool tokens that record their share. They can withdraw their share at any time.
Every swap pays a fee that is added to the pool. In the original Uniswap design the fee is 0.30% of each trade, and it belongs to the liquidity providers. Other pools charge different rates.
How the price moves
The classic rule is simple. Multiply the amounts of the two tokens in the pool. A swap must leave that number unchanged.
Take a pool with 10 ETH and 40,000 USDC. The price is 4,000 USDC per ETH, and the two amounts multiply to 400,000.
You want to buy 1 ETH. The pool will be left with 9 ETH, so it must hold 400,000 ÷ 9 = about 44,444 USDC. You pay about 4,444 USDC, before the fee, for an ETH that was priced at 4,000.
You paid 11% more than the starting price, because your own trade moved it. That is called price impact. It is large here because the trade is big compared with the pool. In a pool a thousand times larger, the same purchase would barely move it.
After a big swap the pool's price differs from the price elsewhere. Traders buy the cheaper side until the prices match again. That arbitrage is what keeps a pool in line with the wider market.
Slippage
Price impact is the change your trade causes. Slippage is the difference between the price you expected and the price you got, because other trades landed before yours.
A DEX lets you set a slippage tolerance. If the price moves against you by more than that, the swap fails instead of going through at a bad price. A failed swap still costs gas.
Set the tolerance too high and you accept a bad price. Pending swaps are visible to everyone, and automated traders look for large ones with loose settings. They buy just before the swap and sell just after it, at the swapper's expense.
Any token can be listed
Nobody approves listings. Anyone can create a token and a pool for it, and can give the token the same name and symbol as a famous one. The only reliable identifier is the token's contract address. Take it from the project's official site, not from a search result or a message.
Swapping without overpaying
- Check the price impact the DEX shows before you confirm.
- Prefer large pools. Thin pools mean bad prices.
- Keep the slippage tolerance low and raise it only when you understand why a swap failed.
- Confirm the token's contract address.
- Count the gas. On a small swap it can cost more than the fee. Lesson 32 explains gas.
- The first swap of a token asks for an approval. Lesson 37 explains what you are granting.
On a DEX, does a larger pool give a big trade a better price than a small pool?
A DEX prices tokens from the balance of a pool. A trade that is large for the pool pays a worse price, so check the price impact, keep slippage tight and verify the token's address.
Sources
- Uniswap docs: How Uniswap works
- Uniswap support: Price impact vs price slippage
- Uniswap docs: Understanding swaps
- ethereum.org: Maximal extractable value
Facts checked against these sources on 10 October 2026.
The course by email
Five short emails to get you started, then one a month about what is new. No price tips and no hype.
Free. Unsubscribe any time. See our privacy notice.
Want your progress saved too? Create a free account.