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.
🎯 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 .
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 ()
Consider a pool with two assets, and . The invariant is:
If a trader wants to buy amount of Token X, they must deposit amount of Token Y such that the new new total multiplies to .
Physics: This curve is a Hyperbola. As reserves of approach 0, the price of (in terms of ) 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:
- ETH is $1000. Pool has correct ratio.
- ETH pumps to $1100 on Binance.
- Pool still offers ETH at $1000.
- Arbitrageur buys “Cheap ETH” from pool until price matches $1100.
- 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 to . In V3, you pick a range: .
Physics: This acts like a leveraged position.
- If Price < : You hold 100% Token X.
- If Price > : 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 1010. Task: Calculate how much ETH an arb can buy before the pool price hits k$).
Exercise 2: Leverage Calculation (Intermediate)
Scenario: V3 Position with range 2010. Task: Compare the capital efficiency vs a V2 position. (Efficiency is ).
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
- What does “Constant Product” preserve?
- Why do LPs lose money during volatility?
- What happens to a V3 LP position when price goes out of range?
- Who sets the price in an AMM?
- Why is the fee typically 0.3%?
Answers
- The multiplication of reserves ().
- LVR. They are constantly selling winners and buying losers against arbitrageurs.
- Dormancy. It stops earning fees and consists entirely of the less valuable asset.
- Arbitrageurs. They trade until the pool price matches the external market price.
- 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