Decentralized Exchanges and Automated Market Makers
Liquidity Pools, the Constant Product Formula, and Impermanent Loss — A TLDR Primer
If you've heard terms like "liquidity pool," "AMM," or "impermanent loss" and had no idea what they meant — or if you're taking a course on blockchain technology and need the math to click fast — this guide is for you.
Decentralized exchanges (DEXs) like Uniswap have replaced traditional order books with a simple but powerful formula: *x × y = k*. Understanding that one equation unlocks how prices are set, how trades get executed, and why providing liquidity can be profitable — or costly. This primer walks you through all of it, step by step, with real numbers.
**What's inside:** - Why blockchains can't run traditional order books, and what automated market makers do instead - How the constant product formula prices every trade, with worked examples - How liquidity providers earn fees — and what LP tokens actually represent - The math of impermanent loss, explained with a concrete numerical walkthrough - Real risks: slippage, price impact, MEV bots, sandwich attacks, and smart contract failures - A clear-eyed look at Uniswap v3 concentrated liquidity and Curve's stableswap, so you know where the field is heading
This is not a get-rich-quick crypto pitch. It's a focused, honest explanation of how decentralized exchanges work — written for students who want to understand the mechanics, not just the hype. If you've been searching for an automated market maker explained simply, with actual math and no filler, this is the guide.
Pick it up, read it in an afternoon, and walk into your next class or project with confidence.
- Explain how a decentralized exchange (DEX) differs from a centralized exchange and from a traditional order book
- Derive prices and trade outputs from the constant product formula x*y=k
- Describe how liquidity providers earn fees and how LP tokens represent pool shares
- Calculate and reason about impermanent loss, slippage, and price impact
- Identify real risks: MEV, sandwich attacks, smart contract bugs, and rug pulls
- 1. From Order Books to On-Chain TradingExplains what a DEX is, why centralized exchanges and traditional order books don't translate well to blockchains, and what problem AMMs were invented to solve.
- 2. How an Automated Market Maker WorksIntroduces liquidity pools, the constant product formula x*y=k, and walks through trade pricing with concrete numbers using Uniswap v2 as the model.
- 3. Liquidity Providers, LP Tokens, and FeesShows how anyone can deposit a pair of tokens to become a liquidity provider, what LP tokens represent, and how the 0.3% fee accrues to providers.
- 4. Impermanent Loss, Slippage, and Price ImpactWorks through the math of impermanent loss with a numerical example, distinguishes slippage from price impact, and explains when LPing is actually profitable.
- 5. Risks: MEV, Sandwich Attacks, and Smart Contract FailureSurveys the real-world hazards traders and LPs face, from front-running bots to buggy or malicious contracts, with named historical examples.
- 6. Beyond Uniswap v2: Concentrated Liquidity and What Comes NextBriefly covers Curve's stableswap, Uniswap v3 concentrated liquidity, and how DEX design is still evolving — enough to orient a reader for further reading.