Key Takeaways: Decentralized Exchanges and Automated Market Makers
Core Concepts
-
AMMs replace order books with math. Instead of matching discrete buy and sell orders, automated market makers use a mathematical invariant (most commonly x * y = k) to determine prices algorithmically based on the ratio of tokens in a liquidity pool. This eliminates the need for professional market makers, real-time order management, and centralized matching engines.
-
The constant product formula is derived, not arbitrary. The invariant x * y = k is the simplest function that satisfies three essential properties: (a) the price reflects supply and demand (as a token becomes scarcer in the pool, its price increases), (b) the pool can never be fully drained (the price asymptotically approaches infinity as reserves approach zero), and (c) the computation is cheap enough to execute on-chain (a single multiplication).
-
Impermanent loss is the cost of providing liquidity. When prices change, an LP's pool position is always worth less than holding the same tokens. The loss follows the formula IL = 2*sqrt(r)/(1+r) - 1, where r is the price ratio. Key benchmarks: a 2x price change produces 5.72% IL; a 5x price change produces 25.46% IL. The loss is symmetric — it depends on the magnitude of price change, not the direction.
-
Concentrated liquidity is a paradigm shift. Uniswap V3 allows LPs to concentrate their capital within a specific price range, dramatically increasing capital efficiency (up to 4,000x for tight ranges). The trade-off: positions require active management, impermanent loss is amplified, and LP positions become non-fungible NFTs rather than fungible tokens.
-
MEV and sandwich attacks are structural, not incidental. The transparent mempool that makes Ethereum censorship-resistant also allows searchers to see pending transactions and profit by manipulating transaction ordering. Sandwich attacks (front-running and back-running a victim's swap) are the most common form of DEX-targeted MEV, extracting billions of dollars annually from traders.
Formulas to Remember
| Formula | What It Computes |
|---|---|
| x * y = k | Constant product invariant — the core AMM rule |
| delta_x = x * delta_y / (y + delta_y) | Amount of Token X received for depositing delta_y of Token Y |
| P = y / x | Marginal (spot) price of Token X in terms of Token Y |
| IL = 2*sqrt(r) / (1+r) - 1 | Impermanent loss as a function of price ratio r |
| P(i) = 1.0001^i | Price at tick i in Uniswap V3 |
Key Distinctions
-
DEX vs. CEX: DEXs offer self-custody, permissionless access, and censorship resistance. CEXs offer lower latency, deeper liquidity, tighter spreads, and fiat on/off ramps. Neither is universally superior; each makes different trade-offs.
-
Price impact vs. slippage: Price impact is the deterministic price movement caused by a trade's size relative to pool liquidity. Slippage is the difference between the expected price and the executed price, which includes price impact plus any price movement during transaction confirmation.
-
Impermanent vs. permanent loss: Impermanent loss reverses if the price returns to its starting value. It becomes permanent when the LP withdraws at a different price. The term "impermanent" is misleading — "divergence loss" is more accurate.
-
Maker vs. taker in an AMM context: In traditional order books, makers provide orders and takers consume them. In an AMM, liquidity providers are analogous to makers (they provide liquidity and earn fees), and traders are analogous to takers (they consume liquidity and pay fees).
Common Pitfalls
-
Assuming IL is small. For volatile assets, IL can be devastating. A 10x price movement produces 42.5% IL. Most retail LPs underestimate this risk because they focus on fee APR without accounting for divergence loss.
-
Ignoring fees in IL calculations. IL alone does not determine LP profitability. An LP with 5% IL but 12% fee income is profitable. Always compare IL to accumulated fees when evaluating an LP position.
-
Setting high slippage tolerance. A high slippage tolerance (e.g., 2-5%) is an invitation for sandwich attackers. Use the lowest tolerance that still allows your trade to execute, and consider private transaction submission.
-
Treating concentrated liquidity as passive. Unlike V2, a V3 concentrated position requires active monitoring. If the price moves out of range, the position earns zero fees and holds 100% of the lower-valued token.
-
Assuming DEX prices are independent. AMM prices are set by arbitrageurs who align them with external (usually CEX) prices. The AMM is a passive price-taker, not a price-setter. This is why AMMs cannot function in isolation — they require external price sources and arbitrage activity.
Bridge to Next Chapter
DEXs provide the exchange infrastructure for DeFi. Chapter 23 examines the next critical primitive: lending and borrowing protocols. Protocols like Aave, Compound, and MakerDAO allow users to lend tokens to earn interest or borrow tokens against collateral. These protocols are the largest consumers of DEX liquidity — when borrower positions become undercollateralized, liquidators use DEXs to sell the collateral. Understanding AMMs is therefore prerequisite to understanding the liquidation mechanics that keep lending protocols solvent.