ParaSpace
Search
⌃K

Uniswap V3 LP Token Analyzer

Uniswap V3 LP token is an NFT token that represents the liquidity provision position. Check Uniswap V3 Whitepaper for detail.
Specifically, the variable
LL
represents the liquidity given the relative price (
P0P_0
) of asset
XX
in the denomination of asset
YY
at the time the position is created/last changed, the lower bound (
PaP_a
) and upper bound (
PbP_b
) of price in which the user chooses to provide liquidity.
  1. 1.
    Define input parameters. On the page of adding liquidity in Uniswap V3, three factors have to be defined,
    PaP_a
    ,
    PbP_b
    , and either one of
    x0x_0
    and
    y0y_0
    , where
    x0x_0
    and
    y0y_0
    denote the number of
    XX
    and
    YY
    tokens that will be injected into the liquidity provision position.
  2. 2.
    Calculate
    LL
    and
    x0x_0
    or
    y0y_0
    . Depending on which one of
    x0x_0
    and
    y0y_0
    is defined in step 1), the other one will be calculated. The detailed calculation follows formula 2.2 on Uniswap V3 Whitepaper. For example, if
    x0x_0
    is defined, we will first solve
    LL
    based on (1) and then calculate
    y0y_0
    based on (2) below:
    x0=max(0,L(1P01Pb))x_0=\max\left(0,L*\left(\frac{1}{\sqrt{P_0}}-\frac{1}{\sqrt{P_b}}\right) \right)
    y0=max(0,L(P0Pa))y_0=\max\left(0,L*\left({\sqrt{P_0}}-{\sqrt{P_a}}\right)\right)
    Note here
    y0x0P0\frac{y_0}{x_0}\ne P_0
    in Uniswap V3.
  3. 3.
    Then given price fluctuating to any
    PP
    ,
    xx
    and
    yy
    that represent the number of
    XX
    and
    YY
    tokens redeemable from the liquidity provision position can be derived following eq. 6.29 and 6.30 in Uniswap V3 Whitepaper, which are copied and pasted below:
    y={0P<PaL(PPa)PaP<PbL(PbPa)PPb y=\begin{cases} 0 & P<P_a \\ L*\left(\sqrt{P}-\sqrt{P_a}\right) &P_a \le P < P_b \\ L*\left(\sqrt{P_b}-\sqrt{P_a}\right) & P\ge P_b \end{cases}
    x={L(1Pa1Pb)P<PaL(1P1Pb)PaP<Pb0PPb x=\begin{cases} L*\left(\frac{1}{\sqrt{P_a}}-\frac{1}{\sqrt{P_b}}\right) & P<P_a \\ L*\left(\frac{1}{\sqrt{P}}-\frac{1}{\sqrt{P_b}}\right) &P_a \le P < P_b \\ 0 & P\ge P_b \end{cases}
To get
xx
and
yy
in a given position as well as other information, function positions() can be called. See details here.