Understanding Constant Product Market Makers: The Uniswap Model
The Elegance of xy = k
In 5.1, we explored why automated market makers (AMMs) emerged as the solution to decentralized exchange. Now we'll dissect the mathematical engine powering the most successful AMM design: the constant product formula. This deceptively simple equation—xy = k—revolutionized decentralized trading and manages billions of dollars in liquidity today.
Understanding this formula is essential for anyone who wants to:
- Trade effectively on AMMs
- Provide liquidity profitably
- Build on top of DeFi protocols
- Understand the mechanics of modern decentralized finance
We'll start with intuition, progress to rigorous mathematics, and conclude with practical examples that demonstrate real trading scenarios.
The Constant Product Invariant: Core Concept
The Formula
A constant product market maker maintains a liquidity pool with reserves of two tokens (we'll call them token X and token Y). The fundamental rule is:
x × y = k
Where:
- x = quantity of token X in the pool
- y = quantity of token Y in the pool
- k = the constant product (invariant)
The invariant property: Any trade that swaps token X for token Y (or vice versa) must preserve this product. The pool will only accept trades that maintain k constant (ignoring fees for now).
Visual Intuition
Imagine the pool as a rectangular area with dimensions x by y. The area (product) must always equal k. When you add token X to the pool, the rectangle gets wider, so it must get shorter (less token Y) to maintain the same area.
Before trade: x = 100, y = 1000, k = 100,000
┌──────────────────────┐
│ │ Height: y = 1000
│ k = 100k │
└──────────────────────┘
Width: x = 100
After buying X: x = 110, y = 909.09, k = 100,000
┌─────────────────────────┐
│ │ Height: y = 909.09
│ k = 100k │
└─────────────────────────┘
Width: x = 110
The visual representation helps build intuition: as one dimension grows, the other must shrink proportionally to maintain constant area.
Why This Formula?
The constant product formula has several elegant properties:
1. Always Liquid: You can always trade any amount—the pool never runs out. Even trading 99% of one token is mathematically possible (though extremely expensive).
2. Price Discovery: The ratio of reserves automatically determines the price. No external oracle or order book needed.
3. Bounded: As you buy more of a token, its price increases asymptotically. The curve approaches infinity but never reaches it, naturally limiting extreme trades.
4. Simple to Compute: Calculating trade amounts requires only basic arithmetic—critical for gas efficiency on-chain.
5. Symmetrical: The formula treats both tokens equally. It works the same regardless of which direction you trade.
Deriving Trade Amounts: The Mathematics
Setting Up the Problem
Let's derive exactly how much of token Y you receive when trading Δx amount of token X into the pool.
Initial state:
- Pool contains: x₀ and y₀
- Constant product: k = x₀ × y₀
After your trade:
- You add: Δx to the pool
- Pool takes out: Δy for you
- New reserves: x₁ = x₀ + Δx and y₁ = y₀ - Δy
- Constant product must hold: x₁ × y₁ = k
The Core Equation
Since the product must remain constant:
(x₀ + Δx) × (y₀ - Δy) = x₀ × y₀
Expanding:
x₀y₀ - x₀Δy + y₀Δx - ΔxΔy = x₀y₀
Simplifying:
-x₀Δy + y₀Δx - ΔxΔy = 0
Solving for Δy:
Δy = (y₀Δx) / (x₀ + Δx)
This is the fundamental equation for AMM trades.
Understanding the Formula
Let's examine what this equation tells us:
Numerator (y₀Δx): How much you'd receive if the price didn't change Denominator (x₀ + Δx): Adjustment factor accounting for price movement
Notice that:
- As Δx approaches 0, Δy approaches (y₀/x₀)Δx—the spot price
- As Δx increases, you get less than proportional returns—this is slippage
Including Fees
Real AMMs charge trading fees. Uniswap V2 charges 0.3% (0.997 fee multiplier). The equation becomes:
Δy = (y₀ × γΔx) / (x₀ + γΔx)
Where γ = 0.997 (or 1 - fee percentage)
The fee effectively reduces your input, so you receive less output. These fees accrue to liquidity providers as compensation for supplying capital.
Numerical Example 1: Small Trade
Setup:
- Pool: 100 ETH and 200,000 USDC (k = 20,000,000)
- Implied price: 200,000 / 100 = 2,000 USDC per ETH
- Fee: 0.3%
You want to buy 1 ETH:
Δy = (200,000 × 0.997 × 1) / (100 + 0.997 × 1)
Δy = 199,400 / 100.997
Δy ≈ 1,974.09 USDC
Analysis:
- You pay 1,974.09 USDC for 1 ETH
- Effective price: 1,974.09 USDC per ETH
- Spot price was 2,000 USDC per ETH
- You got a slightly better price due to buying
Wait—better price? Let's reconsider. You're buying ETH, so you ADD USDC and receive ETH:
Corrected calculation (you're buying ETH, selling USDC):
Input: Δx = 1,974.09 USDC
Output: Δy = (100 × 0.997 × 1,974.09) / (200,000 + 0.997 × 1,974.09)
Δy = 196,921.17 / 201,968.21
Δy ≈ 0.975 ETH
Actually, let me recalculate more carefully. Let's be precise about direction.
You want to buy 1 ETH (receive 1 ETH):
- You must add USDC (Δx USDC)
- Pool will remove 1 ETH (Δy = 1 ETH)
- After trade: (x₀ + Δx) × (y₀ - 1) = k
(200,000 + Δx) × (100 - 1) = 20,000,000
(200,000 + Δx) × 99 = 20,000,000
200,000 + Δx = 202,020.20
Δx = 2,020.20 USDC
With 0.3% fee:
Δx_with_fee = 2,020.20 / 0.997 ≈ 2,026.31 USDC
Result:
- You pay 2,026.31 USDC for 1 ETH
- Effective price: 2,026.31 USDC/ETH
- Spot price: 2,000 USDC/ETH
- Price impact: +1.3%
Numerical Example 2: Large Trade
Same pool, but you want to buy 10 ETH:
(200,000 + Δx) × (100 - 10) = 20,000,000
(200,000 + Δx) × 90 = 20,000,000
Δx = 22,222.22 USDC
With fee:
Δx_with_fee = 22,222.22 / 0.997 ≈ 22,289.49 USDC
Result:
- You pay 22,289.49 USDC for 10 ETH
- Effective price: 2,228.95 USDC/ETH
- Spot price: 2,000 USDC/ETH
- Price impact: +11.4%
Key insight: The larger your trade relative to pool size, the worse your effective price. This is fundamental to AMM design.
Marginal Price vs. Execution Price
Understanding the difference between marginal and execution price is crucial for AMM trading.
Marginal Price (Spot Price)
The marginal price is the instantaneous price for an infinitesimally small trade. It's the derivative of the bonding curve at the current point.
For our constant product formula, at any reserve state (x, y):
Marginal price of X (in terms of Y) = y / x
This is simply the ratio of reserves. For example:
- Pool: 100 ETH, 200,000 USDC
- Marginal price: 200,000 / 100 = 2,000 USDC per ETH
Mathematical derivation:
Starting from xy = k, take the differential:
x·dy + y·dx = 0
dy/dx = -y/x
The negative sign indicates that as x increases, y decreases. The marginal price is the absolute value: y/x.
Execution Price (Average Price)
The execution price is the actual price you pay for a finite trade:
Execution price = Total input / Total output
Using our earlier example:
- Paid 22,289.49 USDC for 10 ETH
- Execution price = 22,289.49 / 10 = 2,228.95 USDC/ETH
The Gap: Why They Differ
The execution price differs from the marginal price because your trade itself moves the price. Let's visualize this:
Price (USDC/ETH)
│
2500├ ┌─── Your trade moves the price along curve
│ /
2200├ /⟍ Execution price (average)
│ / │
2000├─●───┴─── Marginal price (start)
│
└────────────────────> ETH reserves
100 90
Your trade "walks up" the bonding curve. The execution price is the average of all the infinitesimal prices along your path.
Calculating Execution Price from Formula
For a trade Δx → Δy:
Marginal price (start) = y₀ / x₀
Execution price = Δx / Δy = Δx × (x₀ + Δx) / (y₀Δx) = (x₀ + Δx) / y₀
Notice: Execution price = (x₀ + Δx) / y₀ > x₀ / y₀ = Marginal price
The execution price always exceeds the starting marginal price when buying. Symmetrically, when selling, you receive less than the marginal price suggests.
Numerical Comparison
| Trade Size | Marginal Price | Execution Price | Difference |
|---|---|---|---|
| 0.1 ETH | 2,000 USDC | 2,002.03 USDC | +0.10% |
| 1 ETH | 2,000 USDC | 2,026.31 USDC | +1.32% |
| 5 ETH | 2,000 USDC | 2,105.26 USDC | +5.26% |
| 10 ETH | 2,000 USDC | 2,228.95 USDC | +11.45% |
| 20 ETH | 2,000 USDC | 2,525.32 USDC | +26.27% |
The difference grows non-linearly with trade size. This is slippage.
Slippage: The Cost of Trading on AMMs
Defining Slippage
Slippage is the difference between expected and actual execution price:
Slippage = (Execution price - Marginal price) / Marginal price
Or equivalently:
Slippage = (Execution price / Marginal price) - 1
Deriving the Slippage Formula
From our earlier work:
Execution price = (x₀ + Δx) / y₀
Marginal price = x₀ / y₀
Slippage = [(x₀ + Δx) / y₀] / [x₀ / y₀] - 1
= (x₀ + Δx) / x₀ - 1
= Δx / x₀
This is remarkably simple! Slippage equals your trade size as a fraction of the pool reserve.
Key formula:
Slippage ≈ Δx / x₀
(This is approximate because it ignores fees and second-order effects, but it's accurate for small trades.)
Understanding Slippage Intuitively
Slippage depends on two factors:
1. Absolute trade size (Δx): Larger trades → more slippage 2. Pool depth (x₀): Deeper pools → less slippage
The ratio Δx/x₀ captures both. Trading 1 ETH against:
- 100 ETH pool: 1% slippage
- 1,000 ETH pool: 0.1% slippage
- 10,000 ETH pool: 0.01% slippage
This is why liquidity matters so much in DeFi.
Slippage with Fees
Including the fee γ, the exact slippage formula is:
Slippage = Δx / x₀ + (1-γ)
For Uniswap's 0.3% fee:
Slippage = Δx / x₀ + 0.003
So even a zero-size trade has 0.3% "slippage" from fees.
Example Calculations
Pool: 100 ETH, 200,000 USDC (k = 20M)
| Trade | Δx/x₀ | Slippage (no fee) | Slippage (0.3% fee) | Total Cost |
|---|---|---|---|---|
| 1 ETH | 1% | 1.0% | 1.3% | 2,026 USDC |
| 5 ETH | 5% | 5.0% | 5.3% | 10,526 USDC |
| 10 ETH | 10% | 10.0% | 10.3% | 22,289 USDC |
| 50 ETH | 50% | 50.0% | 50.3% | 200,600 USDC |
Notice how slippage becomes punishing for large trades. A 50 ETH trade pays an average of 4,012 USDC per ETH when the marginal price is only 2,000!
Slippage Tolerance
To protect against front-running and price manipulation, AMM interfaces let you set a slippage tolerance:
- "Execute this trade only if my execution price is within X% of the current marginal price"
- Transaction reverts if slippage exceeds your tolerance
- Protects against sandwich attacks (we'll cover in Lesson 9)
Typical settings:
- 0.1-0.5%: Stablecoin swaps or large liquidity pairs
- 0.5-1%: Standard token swaps
- 1-5%: Low liquidity pairs or volatile markets
Setting too low = frequent transaction failures Setting too high = vulnerability to front-running
The Slippage Curve
Let's visualize how slippage grows with trade size:
Slippage %
│
50%├ ●
│ ●
30%├ ●
│ ●
20%├ ●
│ ●
10%├ ●
│ ●
5%├ ●
│ ●
1%├●
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──> Trade size / Pool size
0 1% 5% 10%15%20%30%40%50%
The relationship is approximately linear for small trades but curves upward as you approach depleting the pool.
Liquidity Provision: Becoming a Market Maker
Now that we understand how trading works, let's examine the other side: providing liquidity.
Why Provide Liquidity?
Liquidity providers (LPs) earn trading fees in exchange for depositing assets. Every trade pays a fee (typically 0.3%), which accrues to the pool. Your share of fees is proportional to your share of the pool.
Incentives:
- Passive income from trading fees
- Potential additional rewards (liquidity mining)
- Exposure to both tokens in the pool
Risks:
- Impermanent loss (covered in 5.3)
- Smart contract risk
- Token price volatility
Adding Liquidity: The Process
When you provide liquidity, you must deposit both tokens in the current pool ratio.
Example:
- Current pool: 100 ETH and 200,000 USDC
- Current ratio: 1 ETH : 2,000 USDC
- You want to add liquidity worth 10 ETH
You must deposit:
- 10 ETH
- 20,000 USDC (matching the 1:2000 ratio)
Why the ratio requirement?
If you could deposit at any ratio, you'd be essentially trading with the pool at a non-market rate. The protocol enforces the current ratio to prevent this arbitrage.
After your deposit:
- Pool: 110 ETH and 220,000 USDC
- New k: 110 × 220,000 = 24,200,000
- Price unchanged: 220,000 / 110 = 2,000 USDC/ETH
Notice that k increased, but the price (ratio) stayed constant. This is the key property of liquidity provision.
Pool Shares (LP Tokens)
When you provide liquidity, the protocol mints LP tokens representing your share of the pool. These are fungible ERC-20 tokens you can hold, transfer, or redeem.
Calculating your share:
If this is the first liquidity provision (new pool):
LP_tokens = √(x × y) = √k
For subsequent provisions:
LP_tokens = (Δx / x) × existing_LP_supply = (Δy / y) × existing_LP_supply
Why the square root for initial provision?
Using √k ensures that LP tokens have reasonable magnitude and treats both tokens symmetrically. The exact number doesn't matter; what matters is your percentage of total LP tokens.
Example: LP Token Calculation
Initial pool creation:
- Alice deposits 100 ETH and 200,000 USDC
- k = 100 × 200,000 = 20,000,000
- LP tokens minted: √20,000,000 ≈ 4,472.14
- Alice receives 4,472.14 LP tokens (100% of supply)
Bob adds liquidity:
- Current pool: 100 ETH and 200,000 USDC
- Bob deposits 10 ETH and 20,000 USDC (10% of pool)
- Existing LP supply: 4,472.14
- Bob's LP tokens: 0.10 × 4,472.14 = 447.21
- New total supply: 4,919.35 LP tokens
Ownership:
- Alice: 4,472.14 / 4,919.35 = 90.91%
- Bob: 447.21 / 4,919.35 = 9.09%
Removing Liquidity
To withdraw, you burn your LP tokens and receive a proportional share of the current pool.
Bob removes his liquidity:
Current pool has grown to 120 ETH and 240,000 USDC (from trading fees)
Bob's share: 447.21 / 4,919.35 = 9.09%
Bob receives:
- 0.0909 × 120 = 10.91 ETH
- 0.0909 × 240,000 = 21,816 USDC
Notice Bob deposited 10 ETH and 20,000 USDC but withdrew 10.91 ETH and 21,816 USDC. The extra comes from accumulated trading fees.
The Value of LP Tokens
LP tokens represent a claim on pool assets. Their value equals:
LP_token_value = (x × price_x + y × price_y) / LP_supply
Using ETH as the unit of account (price_x = 1):
LP_token_value = (x + y/price_ratio) / LP_supply
Example:
- Pool: 120 ETH, 240,000 USDC
- Price: 2,000 USDC/ETH
- LP supply: 4,919.35
LP_value = (120 + 240,000/2,000) / 4,919.35
= (120 + 120) / 4,919.35
= 240 / 4,919.35
= 0.0488 ETH per LP token
Or in USDC: 0.0488 × 2,000 = 97.6 USDC per LP token
Bob's holdings: 447.21 × 97.6 = 43,648 USDC worth
How Fees Accrue to LPs
When traders pay fees, the fees remain in the pool, increasing k. Let's see how this works:
Before trade:
- Pool: 100 ETH, 200,000 USDC
- k = 20,000,000
- LP supply: 4,472.14
Large trade: Buy 10 ETH for 22,289.49 USDC (with 0.3% fee)
The fee is kept in the pool, so:
Fee = 22,289.49 × 0.003 = 66.87 USDC
Amount actually used for swap = 22,289.49 × 0.997 = 22,222.62 USDC
After trade:
- Reserves: 90 ETH, 222,289.49 USDC
- New k: 90 × 222,289.49 = 20,006,054.1
Notice k increased! This means each LP token now represents a larger claim on the pool.
LP value before trade:
240,000 / 4,472.14 = 53.67 USDC per LP
LP value after trade:
(90 × 2,469.88 + 222,289.49) / 4,472.14 = (222,289.49 + 222,289.49) / 4,472.14 ≈ 99.37 USDC per LP
Wait, that doesn't look right. Let me recalculate using consistent pricing.
Actually, the better way to see fee accrual is that k increases:
k growth = fee accumulation for LPs
The new k of 20,006,054 compared to 20,000,000 represents the value accrued to LPs. This is distributed proportionally to all LP token holders.
Complete Example: Alice's LP Journey
Let's trace Alice's complete experience as an LP over time:
Day 1: Add Liquidity
- Alice deposits: 100 ETH + 200,000 USDC
- Price: 2,000 USDC/ETH
- Total value: 400,000 USDC
- LP tokens received: 4,472.14
- Alice owns: 100% of pool
Day 30: After Trading Activity
- Pool has grown: 102 ETH, 196,078 USDC
- From fees: k = 19,999,956 (approx. same, slight rounding)
- But wait, let's say trading volume generated fees
- Actual pool: 102 ETH, 196,078 USDC with k ≈ 20,000,000
Let me construct a clearer example.
Day 1:
- Pool: 100 ETH, 200,000 USDC
- k = 20,000,000
- Alice's LP: 4,472.14 tokens (100% of supply)
Day 30: After $10M in trading volume at 0.3% fee
- Fees collected: $10M × 0.003 = $30,000
- These fees were retained in the pool
- Let's say price hasn't changed much, still ~2,000 USDC/ETH
- The pool now has: 100 ETH, 230,000 USDC (simplified)
- New k: 100 × 230,000 = 23,000,000
Alice withdraws:
- She owns 100% of LP supply
- Receives: 100 ETH, 230,000 USDC
- Total value: 400,000 USDC (from initial) + 30,000 USDC (from fees) = 430,000 USDC
- Return: 7.5% in one month (assumes price didn't change)
Key insight: Even if prices are unchanged, LPs profit from fees when there's trading volume.
The Bonding Curve Visualized
Let's visualize the xy = k curve to build geometric intuition:
USDC (y)
│
4M│●
│ ╲
│ ╲
2M│ ●╲___Current state: 100 ETH, 200k USDC
│ ╲___
│ ╲___
1M│ ╲●___
│ ╲___
│ ╲___●
│ ╲___
└──────┴────┴────┴────┴────┴─────┴─●────> ETH (x)
50 100 150 200 250
Key properties of this curve:
1. Hyperbolic shape: As x increases, y decreases non-linearly
2. Asymptotic: The curve approaches but never touches the axes. You can never fully deplete the pool.
3. Slope = Price: The slope of the tangent line at any point is the marginal price
4. Convex: The curve bows outward, causing slippage
Trading on the Curve
When you trade, you move along this curve:
USDC (y)
│
│●─────────● Your trade: add 10 ETH, receive USDC
│ ╲ ↑
│ ╲ │ This vertical distance is Δy
│ ╲ │
│ ●─────┘
│ ╲ ← Price got worse as you moved along curve
│ ╲
│ ╲
│ ╲
└─────────┴─────┴────> ETH (x)
100 110
↑_____↑
This horizontal distance is Δx
The curved shape means you get diminishing returns. The first ETH you buy is cheaper than the last.
Liquidity Provision on the Curve
When you add liquidity, the entire curve shifts outward:
Before liquidity addition: xy = 20,000,000
After liquidity addition: xy = 24,200,000
USDC (y)
│
│ ● New curve (bigger k)
│ ╱
│ ● ╱ Original curve
│ ╱ ╱
│╱ ╱
│ ╱
│╱
│
└──────────────> ETH (x)
The new curve is a scaled version of the original, maintaining the same shape but enclosing more area (larger k).
Advanced Considerations
The Square Root Formula for LP Tokens
Why do we use √(xy) = √k for initial LP token minting?
Properties we want:
- LP value should scale with pool size
- Should be symmetric in x and y
- Should be scale-invariant (doubling both reserves doubles LP value)
The square root satisfies all three:
- √(ax × ay) = a√(xy) - scales linearly with a
- √(xy) = √(yx) - symmetric
- Has reasonable magnitude
Alternative formulas (x + y, xy, etc.) fail at least one property.
Minimum Liquidity Lock
Uniswap V2 implements a clever trick: the first LP to create a pool has 1000 LP tokens (10^-15) permanently locked by sending them to the zero address.
Why?
Without this, an attacker could:
- Create a pool with tiny amounts (1 wei each)
- Receive all LP tokens
- Donate large amounts to manipulate price
- Profit from price manipulation
Locking minimum liquidity prevents this by ensuring the attacker can't redeem all liquidity.
Price Impact Function
We can derive a general formula for price impact as a function of trade size:
Price impact = (x₀ + Δx) / x₀ - 1 = Δx / x₀
But we can also express it as a function of the final price:
Price_new = y₁ / x₁ = y₁ / (x₀ + Δx)
Price_old = y₀ / x₀
Price_impact = (Price_new / Price_old) - 1
Through substitution:
Price_impact = (y₁x₀) / (y₀x₁) - 1 = (y₁x₀) / (y₀(x₀ + Δx)) - 1
Since y₀y₁ = k / x₁ = k / (x₀ + Δx):
Price_impact = (k/x₁ × x₀) / (k/x₀) - 1 = (x₀/x₁)² - 1
This shows price impact grows with the square of the reserve ratio change.
Practical Trading Strategies
1. Splitting Large Trades
Because slippage is non-linear, splitting large trades can reduce total slippage:
Example: Buying 20 ETH from 100 ETH pool
Option A: Single trade
- Slippage: 20% + fees
- Pay: ~50,505 USDC
- Average price: 2,525 USDC/ETH
Option B: Four trades of 5 ETH each
- First trade: 5.0% slippage, pay 10,526 USDC
- Wait for arbitrageurs to rebalance pool
- Second trade: 5.0% slippage, pay 10,526 USDC
- (Repeat)
- Total: ~42,104 USDC
- Average price: 2,105 USDC/ETH
Savings: 8,401 USDC (16.6%)
The catch? You need arbitrageurs to rebalance the pool between your trades. In practice, this happens automatically if you wait a few blocks.
2. Routing Through Multiple Pools
Sometimes trading A→B→C gives better execution than A→C directly:
Direct: ETH → obscure_token (low liquidity, high slippage) Routed: ETH → USDC → obscure_token (two liquid pools, lower total slippage)
DEX aggregators like 1inch automatically find optimal routes.
3. Timing Matters for LPs
The best time to add liquidity is when:
- Volatility is low (reduces impermanent loss risk)
- Trading volume is high (maximizes fee earnings)
- Price is near your expected fair value
Avoid adding liquidity:
- Right before expected volatility (protocol launches, announcements)
- When pool is very imbalanced (you'll add at poor prices)
4. Calculating Break-Even Fees
As an LP, you can calculate minimum fee income needed to offset impermanent loss:
Required_fees > Impermanent_loss
Required_fees = Trading_volume × Fee_rate × Your_share
If you expect 20% price divergence (3.8% IL, from 5.3), you need:
Trading_volume × 0.003 × Your_share > 0.038 × Your_position
Trading_volume > 12.67 × Your_position
The pool needs to trade >12.67x your position to break even. For a $100k position, that's $1.27M in volume.
Common Misconceptions
Misconception 1: "LPs lose money on every trade"
Reality: LPs lose value when prices diverge (impermanent loss), but gain from fees on every trade. Net outcome depends on volume vs. volatility.
Misconception 2: "The pool sets prices"
Reality: Arbitrageurs set prices by trading when the pool diverges from external markets. The pool passively reflects those trades.
Misconception 3: "More liquidity always means better prices"
Reality: More liquidity reduces slippage percentage, but your absolute price still depends on trade size and current ratio.
Misconception 4: "LP tokens are like holding both tokens"
Reality: LP tokens behave differently than simply holding. Your ratio rebalances automatically, creating impermanent loss risk but also fee income.
Summary and Key Formulas
Essential Formulas
Constant Product:
x × y = k
Trade Output (no fees):
Δy = (y₀ × Δx) / (x₀ + Δx)
Trade Output (with fees):
Δy = (y₀ × γΔx) / (x₀ + γΔx)
where γ = 1 - fee_rate
Marginal Price:
p = y / x
Execution Price:
p_exec = Δx / Δy
Slippage:
Slippage ≈ Δx / x₀ (plus fees)
LP Token Value:
value = (x × price_x + y × price_y) / LP_supply
Key Takeaways
-
The constant product formula creates a simple, always-liquid market with automatic price discovery
-
Slippage is unavoidable and scales with trade size relative to liquidity—large trades need deep pools
-
Execution price differs from marginal price because your trade moves the market
-
Liquidity providers earn fees proportional to their share and benefit from high trading volume
-
LP tokens represent proportional pool ownership and accrue value from trading fees
-
The bonding curve shape (hyperbola) creates natural price movement and prevents pool depletion
-
Understanding these mechanics is essential for efficient trading and profitable liquidity provision
Looking Ahead
We've now mastered the mathematical foundation of constant product market makers. In 5.3, we'll tackle the most important concept for liquidity providers: impermanent loss. We'll derive exactly how much value LPs lose when prices diverge, when fee income overcomes these losses, and optimal strategies for liquidity provision.
Coming in 5.3:
- Mathematical derivation of impermanent loss
- Why it's "impermanent" and when it becomes permanent
- Calculating break-even points
- Risk/return analysis for LPs
- Hedging strategies
Prerequisites for Next Lesson: Understanding from this lesson, basic calculus helpful but not required
Practice Problems:
-
A pool has 50 ETH and 100,000 USDC. You want to buy 5 ETH. How much USDC will you pay (with 0.3% fee)? What's your slippage?
-
You provide 10 ETH and 20,000 USDC to the pool above, receiving LP tokens. After trading, the pool has 55 ETH and 90,909 USDC. How much do you receive when withdrawing?
-
What trade size creates 5% slippage in a pool with 200 ETH and 400,000 USDC?
-
If a pool generates $1M daily volume with 0.3% fees and you own 1% of the pool, how much do you earn daily?
(Answers available in the appendix or online resource)