Uniswap v3 Liquidity Formula Explained

Β·

Understanding the mechanics behind decentralized exchanges (DEXs) like Uniswap is essential for both developers and liquidity providers. At the heart of Uniswap v3 lies a groundbreaking innovation: concentrated liquidity. This feature allows users to allocate capital within specific price ranges, significantly improving capital efficiency compared to earlier versions such as Uniswap v2.

One of the core mathematical components in this system is the formula that translates virtual reserves into real token amounts β€” known as Equation 2.2 in the Uniswap v3 whitepaper. While the document presents the equation, it leaves the derivation as an exercise for the reader. In this article, we break down how this formula emerges naturally from the geometric and algebraic structure of liquidity positioning.


The Two Coordinate Systems of Liquidity

To grasp how liquidity works in Uniswap v3, it's helpful to think in two different coordinate systems, each offering unique insights:

  1. Liquidity vs. Price

    • X-axis: logarithm of price (often denoted as √P)
    • Y-axis: liquidity (L)
    • Useful for analyzing fee accrual, slippage, and pool dynamics
  2. Token Amounts (X vs. Y)

    • X-axis: amount of token X
    • Y-axis: amount of token Y
    • Ideal for visualizing actual holdings and position management

πŸ‘‰ Discover how advanced trading tools can help you manage liquidity positions more effectively.

These perspectives are mathematically equivalent but serve different practical purposes.

In Uniswap v2, where liquidity is spread uniformly across all prices, the liquidity/price graph is a flat line, while in the token amount space, it forms a hyperbola defined by $ x \cdot y = k $. In contrast, Uniswap v3 introduces concentrated liquidity, meaning liquidity is only active within a specified price range $[P_a, P_b]$. This results in a piecewise constant function in the liquidity/price view β€” resembling a histogram β€” and a bounded curve segment in the token amount view.


Visualizing Liquidity Positions

In the token amount coordinate system, every constant price level corresponds to a straight line through the origin: $ y = P \cdot x $. The steeper the slope, the higher the price (by convention, price is expressed as units of Y per X).

Each point on this line represents a possible state of the pool. The distance from the origin along this line is determined by the liquidity value L. Higher liquidity means being farther from (0,0), indicating more tokens are committed at that price.

For a given liquidity position in Uniswap v3:

This hyperbolic segment is part of the invariant curve $ \sqrt{x \cdot y} = L $, adjusted for price bounds.

Crucially, the shape of this curve is independent of liquidity β€” it depends only on the price range. Therefore, any position within the same price bounds will follow the same curve shape; what changes is just its scale based on L.


From Virtual Reserves to Real Reserves

Uniswap v3 uses the concept of virtual reserves β€” theoretical token balances that maintain constant product behavior even when real balances hit zero. However, when managing actual positions (depositing or withdrawing), we need to compute real reserves: the tangible amounts of tokens currently held.

This transformation involves shifting the hyperbolic curve so that:

Let’s define:

We shift the curve left by $ x\_offset = b_x $ and down by $ y\_offset = a_y $, so that:

This shift converts virtual reserves into real ones.


Deriving Equation 2.2: The Real Reserves Formula

The standard constant product formula with liquidity L is:

$$ x \cdot y = L^2 $$

But under concentrated liquidity, we must account for price boundaries. Using coordinate transformations:

Given a price $ P $, we know:

Substituting:

$$ x \cdot (P \cdot x) = L^2 \Rightarrow x^2 P = L^2 \Rightarrow x = \frac{L}{\sqrt{P}} $$

$$ y = P \cdot x = P \cdot \frac{L}{\sqrt{P}} = L \cdot \sqrt{P} $$

So:

Now apply these offsets to translate virtual to real reserves:

$$ x_{real} = \frac{L}{\sqrt{P}} - \frac{L}{\sqrt{P_b}} = L \left( \frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_b}} \right) $$

$$ y_{real} = L \cdot \sqrt{P} - L \cdot \sqrt{P_a} = L \left( \sqrt{P} - \sqrt{P_a} \right) $$

πŸ‘‰ Learn how to apply these formulas in practice with precision tools for DeFi analytics.

These expressions match Equation 2.2 in the Uniswap v3 whitepaper β€” derived directly from geometric reasoning and algebraic substitution.


Why This Matters for Liquidity Providers

Understanding this derivation isn't just academic β€” it has real implications:

Developers building interfaces or analytics platforms must accurately model these shifts to display correct balances and profit/loss metrics.


Frequently Asked Questions

What is concentrated liquidity in Uniswap v3?

Concentrated liquidity allows users to allocate their funds within custom price ranges instead of across the entire price curve. This increases capital efficiency and enables higher fee returns relative to traditional AMMs.

How does virtual liquidity differ from real reserves?

Virtual liquidity refers to theoretical token amounts used internally by Uniswap v3 to maintain mathematical consistency. Real reserves are the actual token balances a position holds, which become zero outside the set price range.

What does Equation 2.2 calculate?

Equation 2.2 computes the real token balances (x and y) in a Uniswap v3 position at a given price P, based on liquidity L and price bounds $ P_a $ and $ P_b $. It adjusts virtual reserves by subtracting offset values derived from range limits.

Why use square roots of price in calculations?

Using $ \sqrt{P} $ simplifies the mathematics because Uniswap v3 internally tracks tick values as integers representing log-scaled price square roots. This enables efficient computation and precise boundary enforcement.

Can I visualize my liquidity position across price ranges?

Yes β€” several DeFi analytics platforms offer interactive charts showing how your token distribution changes with price. These tools use the same formulas discussed here to render accurate representations.

Is this formula used outside Uniswap v3?

While Uniswap v3 popularized it, similar models appear in other next-generation AMMs like PancakeSwap V3 and QuickSwap V3. The core math remains relevant across protocols adopting concentrated liquidity designs.


Final Thoughts

The elegance of Uniswap v3 lies in its fusion of financial innovation and mathematical rigor. By rethinking how liquidity is deployed, it sets a new standard for decentralized trading.

The derivation of Equation 2.2 demonstrates how powerful geometric intuition can be when applied to blockchain protocols. Whether you're a developer implementing a DEX interface or an investor optimizing yield strategies, understanding these fundamentals empowers better decision-making.

πŸ‘‰ Explore next-generation trading solutions built on deep protocol understanding.

By mastering concepts like coordinate transformations, virtual vs. real reserves, and liquidity scaling, you gain insight not just into Uniswap β€” but into the future of decentralized finance itself.


Core Keywords: Uniswap v3, concentrated liquidity, liquidity formula, real reserves, virtual reserves, DeFi, AMM, Equation 2.2