The Physics of Liquidity Pools: x*y=k and LVR

Why 'Impermanent Loss' is actually 'Permanent Arbitrage'. The Conservation Law of AMMs, Convexity, and why Uniswap V3 is a leveraged bet.

Intermediate 45 min read Expert Version →

🎯 What You'll Learn

  • Derive the Constant Product Formula ($x \cdot y = k$)
  • Calculate LVR (Loss-Versus-Rebalancing) mathematically
  • Visualize Uniswap V3 Concentrated Liquidity as a Limit Order
  • Analyze the Arbitrageur's role in price discovery
  • Trace a Swap's impact on Pool Reserves

📚 Prerequisites

Before this lesson, you should understand:

Introduction

An Automated Market Maker (AMM) is not a “Market Maker” in the traditional sense. It is a Robot that enforces a Conservation Law. It does not “know” the price of ETH. It only knows that it must preserve the constant kk.

When the price of ETH moves on Binance, the AMM does not move. It waits for an Arbitrageur to come and “correct” its reserves, paying them a profit to do so. This payment is what we call Impermanent Loss.


The Physics: Conservation Law (xy=kx \cdot y = k)

Consider a pool with two assets, XX and YY. The invariant is: xy=kx \cdot y = k

If a trader wants to buy Δx\Delta x amount of Token X, they must deposit Δy\Delta y amount of Token Y such that the new new total multiplies to kk.

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

Physics: This curve is a Hyperbola. As reserves of XX approach 0, the price of XX (in terms of YY) approaches Infinity. This ensures the pool can never run out of liquidity completely.


Deep Dive: Impermanent Loss is LVR

“Impermanent Loss” is a marketing term. The academic term is LVR (Loss-Versus-Rebalancing).

The Mechanism:

  1. ETH is $1000. Pool has correct ratio.
  2. ETH pumps to $1100 on Binance.
  3. Pool still offers ETH at $1000.
  4. Arbitrageur buys “Cheap ETH” from pool until price matches $1100.
  5. Result: The Pool sold ETH too cheap. You (the LP) subsidized the Arbitrageur’s profit.

Physics: You are effectively shorting Gamma (Volatility). You profit when price is stable (Fees > LVR). You lose when price is volatile (LVR > Fees).


Advanced: Concentrated Liquidity (Uniswap V3)

In V2, your liquidity covers 00 to \infty. In V3, you pick a range: [Pmin,Pmax][P_{min}, P_{max}].

Physics: This acts like a leveraged position.

  • If Price < PminP_{min}: You hold 100% Token X.
  • If Price > PmaxP_{max}: You hold 100% Token Y.
  • Inside Range: You earn massively amplified fees.

Risk: If price exits your range, you earn 0 fees, but you still suffered the IL/LVR of the move.


Code: Simulating a Swap

How does the contract actually calculate amountOut?

def get_amount_out(amount_in, reserve_in, reserve_out):
    # x * y = k
    # new_in * new_out = k
    # (reserve_in + amount_in) * (reserve_out - amount_out) = reserve_in * reserve_out
    
    amount_in_with_fee = amount_in * 997 # 0.3% Fee
    numerator = amount_in_with_fee * reserve_out
    denominator = (reserve_in * 1000) + amount_in_with_fee
    
    amount_out = numerator / denominator
    return amount_out

# Example
# Reserve: 10 ETH (In), 20,000 USDC (Out). Price 2000.
# Input: 1 ETH.
# Calculation (Simplified):
# New Reserve In ~ 11 ETH.
# New Reserve Out ~ 18,181 USDC.
# User receives: 20,000 - 18,181 = 1,819 USDC.
# Effective Price: $1,819 (Slippage due to depth).

Practice Exercises

Exercise 1: The Arb (Beginner)

Scenario: Pool Price 1000.ExternalPrice1000. External Price 1010. Task: Calculate how much ETH an arb can buy before the pool price hits 1010.(Hint:Usetheinvariant1010. (Hint: Use the invariant k$).

Exercise 2: Leverage Calculation (Intermediate)

Scenario: V3 Position with range 19901990 - 2010. Task: Compare the capital efficiency vs a V2 position. (Efficiency is 1Reflected Range\approx \frac{1}{\text{Reflected Range}}).

Exercise 3: Rekt Check (Advanced)

Scenario: You LP’d a memecoin that rugged (-99%). Task: Calculate your generic IL. (It approaches 100%, meaning you hold 100% of the worthless token and 0% of the valuable token).


Knowledge Check

  1. What does “Constant Product” preserve?
  2. Why do LPs lose money during volatility?
  3. What happens to a V3 LP position when price goes out of range?
  4. Who sets the price in an AMM?
  5. Why is the fee typically 0.3%?
Answers
  1. The multiplication of reserves (kk).
  2. LVR. They are constantly selling winners and buying losers against arbitrageurs.
  3. Dormancy. It stops earning fees and consists entirely of the less valuable asset.
  4. Arbitrageurs. They trade until the pool price matches the external market price.
  5. Standard convention. It creates a bid-ask spread that compensates LPs for volatility risk.

Summary

  • AMM: A dumb robot following a math law.
  • LVR: The tax LPs pay to Arbitrageurs.
  • V3: Leveraged liquidity provision.

Questions about this lesson? Working on related infrastructure?

Let's discuss