How Crypto Actually Trades
AMMs, Liquidity & Slippage
The constant-product formula is simple math with non-obvious consequences, and understanding it tells you exactly where your money leaks when you trade on-chain.
Most DEX volume runs through automated market makers. There is no order book, no counterparty placing a limit order. Instead, a pool of two assets rebalances mechanically according to a formula. The elegance of the design also produces several ways to lose money that are worth understanding precisely.
x times y equals k
The Uniswap v2 constant product formula is x * y = k. If a pool holds 100 ETH and 200,000 USDC, k = 20,000,000. If you buy 10 ETH, the pool must still satisfy k after the trade. The new ETH reserve is 90. Solve: 90 * y = 20,000,000, so y = 222,222 USDC. You paid 22,222 USDC for 10 ETH. The implied price was 2,000 before; you paid 2,222 per ETH. That difference is price impact.
x * y = k
the constant product invariant; trade size relative to pool depth determines price impact, not a flat fee schedule
Price impact and slippage
Price impact is the change in pool price caused by your trade. Slippage is the difference between the expected price when you submit and the actual execution price. Slippage tolerance in a DEX interface is a cap: if the price moves more than X percent by the time the transaction confirms, it reverts. Setting tolerance too low causes frequent reverts on volatile pairs. Setting it too high is how MEV bots (sandwich attacks) extract value from you.
- You submit swapexpected price at submission
- Bot sees pending txfront-runs with buy order in same block
- Your tx executesat worse price; within your tolerance
- Bot sells immediatelyextracts the difference
Impermanent loss explained without euphemism
If you provide liquidity to a pool, you deposit both assets in the current ratio. As price moves, the pool rebalances, and your holdings drift toward the asset that is declining in relative value. When you withdraw, you receive a ratio that reflects the new price. Impermanent loss is the difference between what you received and what you would have held if you had done nothing. It is not a fee or a penalty; it is the opportunity cost of providing liquidity versus simply holding.
It becomes realized the moment you withdraw after a price divergence. If the price returns to the original level before you exit, impermanent loss is zero. The name is misleading: the loss is only "impermanent" in the sense that it could reverse if prices reconverge, which is not guaranteed. Trading fees earned by the pool offset it partly. Whether they offset it fully depends on fee tier, volume, and volatility.
Key takeaways
Educational content only, not financial advice. Trading and investing carry real risk of loss, including your entire capital. Do your own research and consult a licensed professional before making financial decisions.
This is one lesson of 541.
The whole Foundation is free — 16 subjects, beginner to advanced. Sign in to track what you have read, take the end-of-module quizzes, and use the terminal.