Lesson 7: Decentralized Exchanges
🎯 Core Concept: Automated Market Makers (AMMs)
TradFi and Centralized Exchanges utilize Central Limit Order Books (CLOBs), where buyers and sellers list prices. DeFi introduced a novel primitive: the Automated Market Maker (AMM), which uses mathematical formulas instead of order books to determine prices.

📚 The Constant Product Formula
The fundamental equation governing early AMMs (like Uniswap V2) is:
$$x \times y = k$$
Where:
- x: The quantity of Token A in the pool
- y: The quantity of Token B in the pool
- k: A constant (must remain the same after every trade)
How It Works: When a trader buys Token A from the pool, the supply of x decreases. To keep k constant, the supply of y must increase. This algorithmic relationship automatically adjusts the price based on supply and demand.

📚 Liquidity Pools
Instead of matching a buyer with a seller, the AMM matches a trader against a "pool" of assets (smart contract) provided by Liquidity Providers (LPs).
Key Concepts:
- Liquidity Providers: Users who deposit tokens into pools to earn fees
- Price Discovery: Prices adjust automatically based on trades
- Impermanent Loss: LPs face risk if token prices diverge significantly

Interactive DeFi Protocol Explorer
Use this interactive tool to explore and compare different DeFi protocols:
Launch DeFi Protocol Explorer →
Interactive Yield Farming Calculator
Use this interactive tool to calculate potential yields from liquidity provision:
Launch Yield Farming Calculator →
Interactive Gas Fee Estimator
Use this interactive tool to estimate gas fees for DEX transactions:
🔑 Key Takeaways
- AMMs Replace Order Books: Mathematical formulas determine prices automatically
- Liquidity Pools: Traders swap against pools, not individual orders
- Constant Product Formula: x × y = k ensures liquidity always exists
- Price Impact: Larger trades move prices more (slippage)
- LP Risks: Providing liquidity has risks (impermanent loss)
Next Lesson: In Lesson 8, we'll explore DeFi lending and borrowing protocols.

