Crypto Trading · lesson 19 of 29
DeFi: Swaps and Liquidity Pools Explained
Learn this in a 5-minute interactive lesson
Real charts and practice questions. Free, no sign-up needed.
A swap without a company
On a decentralised exchange (DEX), you connect your own wallet, choose what to swap, approve the token, and confirm. The swap happens through a smart contract, and the new tokens land straight in your wallet.

Pools instead of order books
Most DEXs don't have an order book. Instead, they use liquidity pools: smart contracts holding two tokens, such as ETH and USDC. When you buy ETH, you put USDC into the pool and take ETH out. The price is set by a simple rule, used by an automated market maker (AMM):
amount of token A × amount of token B = a fixed number
So the more ETH you take out, the more expensive the next ETH becomes.
A pool holds 1,000 ETH and 2,400,000 USDC, so the price is 2,400,000 ÷ 1,000 = $2,400 per ETH. The fixed number is 1,000 × 2,400,000 = 2.4 billion.
You buy 10 ETH. The pool will have 990 ETH left, so it must hold 2,400,000,000 ÷ 990 = 2,424,242.42 USDC.
You pay 2,424,242.42 − 2,400,000 = $24,242.42, an average of $2,424.24 per ETH, about 1 percent above the starting price. That 1 percent is the price impact. The pool's new price is 2,424,242.42 ÷ 990 = $2,448.73. Most pools also charge a fee, often around 0.3 percent, which goes to the people who supplied the tokens.
Now imagine the pool only held 100 ETH. The same 10 ETH would cost you more than 11 percent above the starting price. Small pools punish big trades.
Slippage and sandwiches
Slippage tolerance is the most your price is allowed to move between clicking "swap" and the transaction actually happening. If you set it to 0.5 percent and the price moves more, the swap fails and you only lose the network fee.
Set it too high and you invite trouble. Bots watch the queue of waiting transactions, and if they see a big swap with a high slippage tolerance, they can buy just before you and sell just after, pocketing the difference. That's called a sandwich attack, and you're the filling. Keep slippage low, usually 0.5 to 1 percent for major tokens, and avoid big swaps in small pools.
- 1.Open the DEX by typing its address or using a bookmark. Fake DEX sites are common.
- 2.Check you're on the right network in your wallet.
- 3.Choose the tokens. For anything except the biggest tokens, paste the token's contract address from a trusted source instead of searching by name, because scammers create fake tokens with the same names.
- 4.Check the price impact, the minimum received, and the network fee.
- 5.Set slippage to 0.5 to 1 percent for major tokens.
- 6.Approve only the amount you need, then swap, and check the result on a block explorer.
Supplying liquidity
Anyone can deposit both tokens into a pool and become a liquidity provider (LP). In return, LPs share the trading fees. It sounds like free money, but there's a catch called impermanent loss.
When the price of one token changes, the pool automatically rebalances: as ETH rises, traders buy ETH from the pool, so the pool ends up holding less ETH and more USDC. You end up with less of the thing that went up.
Alex deposits 1 ETH and 2,400 USDC when ETH is $2,400, so the deposit is worth $4,800.
ETH doubles to $4,800.
If Alex had just held: 1 × 4,800 + 2,400 = $7,200. In the pool: it now holds about 0.707 ETH and 3,394 USDC, worth about $6,788.
Alex is about $412, or 5.7%, behind simply holding. Trading fees earned along the way may make up for it, or may not. It's called "impermanent" because the gap disappears if the price goes back to where it started, but if Alex withdraws at $4,800, the loss is very permanent.
Key terms from this lesson
- DeFi (decentralised finance)
- financial services run by smart contracts instead of companies.
- Liquidity pool
- a smart contract holding two tokens that people can swap between.
- Automated market maker (AMM)
- a pricing rule that sets swap prices from the amounts in a pool.
- Price impact
- how much your own trade moves the price.
- Slippage tolerance
- the maximum price change you'll accept before a swap fails.
- Sandwich attack
- a bot trading just before and after your swap to profit from your price impact.
- Liquidity provider (LP)
- someone who deposits tokens into a pool to earn fees.
- Impermanent loss
- how much worse a pool position does than holding, when prices move.
Learn this in a 5-minute interactive lesson
Real charts and practice questions. Free, no sign-up needed.
Related guides
Pajama Markets provides education, not financial advice. Trading forex, crypto and leveraged products carries a high risk of losing money. Practise on a demo account first.