Lesson 7: Decentralized Exchanges

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.

AMM vs Order Book Comparison

๐Ÿ“š The Constant Product Formula

The fundamental equation governing early AMMs (like Uniswap V2) is:

xร—y=kx \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.

Constant Product Formula Visualization

๐Ÿ“š 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

Liquidity Pool Components Diagram

๐ŸŽฎ Interactive: DEX Swap Simulator

Experience how AMM swaps work with this interactive simulator. See how trades affect pool reserves and cause slippage:

Interactive DeFi Protocol Explorer

Use this interactive tool to explore and compare different DeFi protocols:

Interactive Yield Farming Calculator

Use this interactive tool to calculate potential yields from liquidity provision:

Interactive Gas Fee Estimator

Use this interactive tool to estimate gas fees for DEX transactions:

๐Ÿ”‘ Key Takeaways

  1. AMMs Replace Order Books: Mathematical formulas determine prices automatically

  2. Liquidity Pools: Traders swap against pools, not individual orders

  3. Constant Product Formula: x ร— y = k ensures liquidity always exists

  4. Price Impact: Larger trades move prices more (slippage)

  5. LP Risks: Providing liquidity has risks (impermanent loss)


Next Lesson: In Lesson 8, we'll explore DeFi lending and borrowing protocols.

Last updated