A6: How AMMs Set Prices — The Constant Product Formula

L06 Market Microstructure — 45 min analysis + 10 min presentation
Assignment Brief

Introduction

An AMM (Automated Market Maker) is a piece of software that lets people trade one cryptocurrency for another without needing a human broker or traditional exchange. AMMs use the constant product formula x * y = k where:

When you buy token A, you add token B to the pool and remove token A. This changes the ratio y/x, which automatically changes the price. Slippage (the difference between the expected price and the actual price you pay) increases with trade size because larger trades move the ratio more.

Your Task

You will explore how different pool parameters affect slippage by modifying the baseline constant product AMM model. Create a 7-slide Marp presentation analyzing three variations and one open extension.

Baseline Model

Variations to Analyze

Variation 1: Increase pool depth

Variation 2: Imbalanced pool

Variation 3: Add 0.3% swap fee

Open Extension: Pool Depth Comparison


Deliverables

  1. 7-slide Marp presentation (model-answer-presentation.md):
    • Slide 1: Title + citation (Adams et al. 2021 — Uniswap v3 Core)
    • Slide 2: The Model — formula explanation
    • Slide 3: Baseline results with baseline chart
    • Slide 4: Variation 1 results with variation chart
    • Slide 5: Variation 2 results
    • Slide 6: Variation 3 results with fee comparison
    • Slide 7: Key insights — why pool depth matters
  2. Python chart (chart_varied.py):
    • 2×2 subplot grid (16×12 inches)
    • Panel 1: Baseline — constant product curve with trade arrows for 100 and 500 token trades
    • Panel 2: Variation 1 — k = 10M, same trades, show reduced slippage
    • Panel 3: Variation 2 — x₀ = 500, y₀ = 2000, show asymmetric curve
    • Panel 4: Variation 3 — bar chart comparing slippage with and without 0.3% fee for trade sizes [10, 50, 100, 200, 500]
    • Use np.random.seed(42) for reproducibility
    • Save to chart_varied.pdf and chart_varied.png

How to Run

Use Google Colab (free, no installation required):

  1. Go to colab.research.google.com
  2. Upload chart_varied.py
  3. Run the script (Runtime → Run all)
  4. Download generated PNG/PDF from the Files panel (left sidebar)

For the Marp presentation:

  1. Install the Marp extension in VS Code, or
  2. Use the online Marp editor at marp.app

Time Allocation


Learning Objectives

By completing this assignment, you will:


Grading Rubric (100 points)

ComponentPointsCriteria
Variation 1 analysis20Correct k = 10M calculation, slippage comparison
Variation 2 analysis20Correct imbalanced pool, asymmetric curve explanation
Variation 3 analysis20Fee calculation correct, slippage comparison table
Chart quality20All 4 panels correct, annotations clear, professional
Presentation clarity15Logic flow, key insights highlighted, visuals support text
Open extension5Thoughtful comparison, actionable insight

References

Adams, H., Zinsmeister, N., Salem, M., Keefer, R., & Robinson, D. (2021). Uniswap v3 Core. Retrieved from https://uniswap.org/whitepaper-v3.pdf

Model Answer
Show Model Answer Presentation (7 slides)

Slide 1 — Title

How AMMs Set Prices: The Constant Product Formula

Assignment A6 — L06 Market Microstructure

Reference: Adams, H., Zinsmeister, N., Salem, M., Keefer, R., & Robinson, D. (2021). Uniswap v3 Core

Slide 2 — The Model

The Model: x * y = k (Constant Product)

Concept: An AMM maintains a liquidity pool with two tokens (X, Y) where the product of reserves is constant:

$$x \cdot y = k \quad \text{(invariant)}$$

Spot Price: The marginal exchange rate is:

$$P = \frac{y}{x}$$

Trade Mechanics: To buy Δx of token X, you must pay Δy of token Y such that:

$$(x - \Delta x) \cdot (y + \Delta y) = k$$

Solving: $\Delta y = \frac{k}{x - \Delta x} - y$

Slippage: Effective price $P_{eff} = \Delta y / \Delta x$ exceeds spot price P due to convex curve (not linear).

Slide 3 — Baseline Results

Baseline Results (k = 1M, x₀ = y₀ = 1000)

Observations:

  • Trade 100 X: Costs 111 Y → effective price 1.111 Y/X → 11.1% slippage
  • Trade 500 X: Costs 1000 Y → effective price 2.0 Y/X → 100% slippage
  • Slippage grows nonlinearly (convex function)

Slide 4 — Variation 1

Variation 1: Deeper Pool (k = 10M)

(Panel 2: k = 10M — note reduced slippage)

Results:

  • Same 100 X trade now costs ~103.8 Y → ~3.8% slippage (down from 11.1%)
  • Slippage reduction: ~66% improvement with 10x deeper liquidity
  • Why?: Larger k means flatter curve → smaller percentage change in y/x ratio

Key Insight: This is why liquidity mining exists — deeper pools attract traders with better prices.

Slide 5 — Variation 2

Variation 2: Imbalanced Pool (x₀ = 500, y₀ = 2000)

(Panel 3: Asymmetric curve with initial price P = 4.0)

Results:

  • Initial price P = y/x = 2000/500 = 4.0 Y/X (not 1.0)
  • Curve is steeper on the X-side (buying X is expensive)
  • Curve is flatter on the Y-side (buying Y is cheaper)
  • Asymmetry: Traders pay more slippage when buying the scarce asset (X)

Implication: Arbitrageurs will rebalance the pool toward x₀ = y₀ if external price differs.

Slide 6 — Variation 3

Variation 3: Adding 0.3% Swap Fee

(Panel 4: Slippage comparison with and without fee)

Fee Model: Effective output = amount_out × 0.997

Trade Size (X)Slippage (no fee)Slippage (with 0.3% fee)Fee Impact
101.0%1.3%+0.3 pp
505.3%5.6%+0.3 pp
10011.1%11.4%+0.3 pp
20025.0%25.4%+0.4 pp
500100.0%100.6%+0.6 pp

Observation: Fee adds constant ~0.3 percentage points. For large trades, slippage dominates fees.

Slide 7 — Key Insights

Key Insights: Why Pool Depth Is Everything

  1. Nonlinear Slippage: x * y = k creates convex curve → slippage grows faster than trade size
  2. Liquidity Is King: 10x deeper pool (k = 10M) cuts slippage by ~70% for same trade
    • This is why protocols offer liquidity mining rewards (LP tokens, governance tokens)
    • Traders prefer deep pools → more volume → more fees for LPs → positive feedback loop
  3. Balance Matters: Imbalanced pools punish trades in the scarce direction
    • Arbitrage naturally rebalances pools toward 50/50 split
  4. Fees Are Secondary: For large trades, slippage (11%) >> fees (0.3%)
    • Protocol revenue comes from volume, not high fees
  5. Design Trade-off: Constant product is simple but capital inefficient
    • Uniswap v3 uses concentrated liquidity to improve this
← A5: Winner-Take-All A7: Regulatory Game Theory →