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.

๐ The Constant Product Formula
The fundamental equation governing early AMMs (like Uniswap V2) is:
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: 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
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.
Last updated