Decentralized Exchanges and Automated Market Makers
Trading Without Intermediaries
Introduction
Traditional exchanges work through order books: buyers and sellers post prices, and trades execute when orders match. This model requires significant liquidity, market makers to provide it, and centralized infrastructure to maintain the order book. Decentralized exchanges took a fundamentally different approach.
Automated Market Makers (AMMs) revolutionized decentralized trading by replacing order books with liquidity pools and mathematical formulas. This innovation enabled trading without centralized order matching while creating new opportunities for liquidity provision.
This lesson explores how decentralized exchanges work, the mechanics of automated market makers, and the trade-offs involved in this new trading paradigm.
The Problem with Traditional DEXs
Early decentralized exchanges attempted to replicate traditional order book models on blockchain. This proved problematic:
On-Chain Order Books:
- Every order submission requires a blockchain transaction
- Every cancellation requires a transaction
- High fees for active trading
- Slow execution compared to centralized exchanges
Latency Issues:
- Block times create delays
- Front-running by miners/validators possible
- Can't compete with centralized exchange speed
Liquidity Fragmentation:
- Liquidity spread across many markets
- Hard to build sufficient depth
- Wide spreads and poor execution
These challenges led to the development of automated market makers—a fundamentally different approach.
How Automated Market Makers Work
AMMs replace order books with liquidity pools—smart contracts holding pairs of tokens.
The Basic Concept:
- A pool contains two tokens (e.g., ETH and USDC)
- Prices determined by mathematical formula
- Traders swap one token for another from the pool
- The formula adjusts prices based on pool ratios
Constant Product Formula (x × y = k):
Uniswap popularized this formula:
- x = quantity of token A
- y = quantity of token B
- k = constant product
Example:
Pool has 100 ETH and 100,000 USDC:
- k = 100 × 100,000 = 10,000,000
- Implied price: 100,000 / 100 = 1,000 USDC per ETH
To buy 10 ETH:
- New ETH in pool: 90
- New USDC must satisfy: 90 × y = 10,000,000
- y = 111,111 USDC
- Buyer pays: 111,111 - 100,000 = 11,111 USDC
- Effective price: ~1,111 USDC per ETH (higher than starting price due to slippage)
Key Insight:
As traders buy a token, its quantity in the pool decreases and its price increases automatically. No order matching needed.
Liquidity Provision
Anyone can become a liquidity provider (LP) by depositing tokens into pools.
How It Works:
- Deposit both tokens in equal value (e.g., $1000 ETH + $1000 USDC)
- Receive LP tokens representing your pool share
- When trades occur, fees distributed to LPs
- Withdraw by returning LP tokens for underlying assets
Earning Fees:
LPs earn fees on every trade:
- Uniswap V2: 0.3% per trade
- Fees distributed proportionally to LP share
- Provides passive income opportunity
Impermanent Loss:
The key risk for liquidity providers:
- When token prices diverge, LPs would have been better off just holding
- Called "impermanent" because it reverses if prices return to original ratio
- Becomes permanent if you withdraw while prices differ
Example:
You provide liquidity when ETH = $1000:
- Deposit: 1 ETH + 1000 USDC ($2000 total)
- ETH rises to $2000
- Due to pool rebalancing, you now have ~0.7 ETH + ~1414 USDC
- Value: ~$2828
- If you had just held: 1 ETH + 1000 USDC = $3000
- Impermanent loss: ~$172 (5.7%)
Fees may compensate for impermanent loss, but not always.
Major DEX Protocols
Uniswap:
The pioneer and largest DEX:
- V1 (2018): Simple ETH pairs
- V2 (2020): Any token pairs, improved oracle
- V3 (2021): Concentrated liquidity
- Deployed across multiple chains
Curve Finance:
Optimized for stablecoin and similar-asset trading:
- Specialized curve for assets that should trade near 1:1
- Much lower slippage for stablecoin swaps
- Important for stablecoin ecosystem
- Also handles wrapped/derivative assets
SushiSwap:
Uniswap fork with additional features:
- Launched via "vampire attack" on Uniswap liquidity
- Added governance token (SUSHI)
- Expanded to multiple chains early
Balancer:
Multi-token pools with custom weightings:
- Pools can have 2-8 tokens
- Custom weighting (not just 50/50)
- Enables index-fund-like products
Aggregators (1inch):
Route trades across multiple DEXs:
- Find best price across venues
- Split orders for better execution
- Reduce slippage on large trades
Trading Mechanics and Slippage
Slippage:
The difference between expected and actual execution price:
- Larger trades relative to pool size = more slippage
- AMMs inherently have slippage
- Users set slippage tolerance to protect against excessive slippage
Example:
Small trade on deep pool: 0.1% slippage Large trade on shallow pool: 10%+ slippage
Price Impact:
Your trade itself moves the price:
- Buying pushes price up
- Selling pushes price down
- Large trades significantly impact price
MEV (Maximal Extractable Value):
Miners/validators can profit by reordering transactions:
- Frontrunning: Place trade before victim's large trade
- Sandwich attacks: Trade before and after victim
- Users lose value to MEV extractors
Protection Strategies:
- Set tight slippage tolerances
- Use MEV protection services (Flashbots)
- Trade on L2s with different MEV dynamics
Concentrated Liquidity
Traditional AMMs spread liquidity across all prices from zero to infinity—capital inefficient since most trading occurs in narrow ranges.
Uniswap V3 Innovation:
LPs can concentrate liquidity in specific price ranges:
- Provide liquidity only between $1800-$2200 for ETH
- Earn more fees per dollar deposited
- More capital efficient (up to 4000x in theory)
Trade-offs:
Benefits:
- Higher fee earnings per dollar
- Better capital efficiency
- Tighter spreads for traders
Challenges:
- Requires active management
- Out-of-range positions earn nothing
- Greater impermanent loss risk if price moves outside range
Professional LPs:
Concentrated liquidity has led to more professional LP strategies:
- Active range management
- Algorithmic rebalancing
- Competition with passive LPs
Key Takeaways
- AMMs replaced order books with liquidity pools and mathematical formulas for price determination
- The constant product formula (x × y = k) is the most common AMM mechanism
- Liquidity providers earn fees but face impermanent loss risk when token prices diverge
- Major protocols include Uniswap, Curve, SushiSwap, and Balancer with different specializations
- Concentrated liquidity improves capital efficiency but requires active management
Summary
Automated Market Makers transformed decentralized trading by replacing traditional order books with algorithmic pricing and liquidity pools. This innovation enabled permissionless trading and created new opportunities for passive income through liquidity provision. While AMMs solve many problems of traditional DEXs, they introduce new considerations around slippage, impermanent loss, and MEV extraction.

