Skip to content
STAGING — not production

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

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 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 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 product stays at kk.

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

This curve is a hyperbola. As reserves of XX approach 0, the price of XX (in terms of YY) approaches infinity. The pool can never run out of liquidity completely.


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.

You are effectively shorting gamma (volatility). You profit when price is stable (Fees > LVR). You lose when price is volatile (LVR > Fees).


Concentrated Liquidity (Uniswap V3)

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

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

Risk: If price exits your range, you earn 0 fees, but you already suffered the LVR of the move that took it out of range.


Code: Simulating a Swap

How does the contract actually calculate amountOut?

def get_amount_out(amount_in, reserve_in, reserve_out):
    # x * y = 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.
# 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 pool 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 over the same range. Tighter ranges amplify fee earnings but also amplify LVR.

Exercise 3: Rekt Check (Advanced)

Scenario: You LP’d a memecoin that rugged (-99%). Task: Calculate your approximate IL. (Approaches 100% — you end up holding mostly the worthless 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: Concentrated liquidity with amplified fees and amplified risk.

Want to go deeper?

Weekly infrastructure insights for engineers who build trading systems.

Free forever. Unsubscribe anytime.

You're in. Check your inbox.

Questions about this lesson? Working on related infrastructure?

Let's discuss