This is a cheatsheet of maths related to how concentrated liquidity works, which could be useful for doing analysis on how to provide liquidity on Muffin.

The following section assumes you have already had a good understanding on how concentrated liquidity technically works.

Add / Remove Liquidity

First of all, we define $P$ as the current pool price but being bounded in the price range $[P_\text{lower}, P_\text{upper}]$, i.e.:

$$ P = \text{max}\left\{P_{\text{lower}}, \text{min}\left\{ P_{\text{upper}}, P_{\text{now}}\right\}\right\} $$

What are the underlying token amounts $x$ and $y$ for a position with a liquidity level $L$ in the price range $[P_\text{lower}, P_\text{upper}]$?

$$ \begin{gather} x = L \left( \frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_\text{upper}}} \right) \newline y = L \left( \sqrt{P} - \sqrt{P_\text{lower}} \right) \end{gather} $$

Reversely, what is the liquidity level $L$ if I’m adding $x$ and $y$ tokens into the range $[P_\text{lower}, P_\text{upper}]$?

$$ L = \text{min} \left\{ \frac{x}{\frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_\text{upper}}}}, \frac{y}{\sqrt{P} - \sqrt{P_\text{lower}}} \right\} $$

Position Value

What is the cash value $V$ of a position with a liquidity level $L$ in the price range $[P_\text{lower}, P_\text{upper}]$? Let $c_x$ and $c_y$ are the USD-denominated prices of tokens X and Y respectively.

$$ V = c_x x + c_y y $$

$$ V = L \left[ c_x \left( \frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_\text{upper}}} \right) + c_y \left( \sqrt{P} - \sqrt{P_\text{lower}} \right) \right] $$

Reversely, the liquidity level $L$ if I’m adding liquidity of a value $V$ into the price range $[P_\text{lower}, P_\text{upper}]$:

$$ L = \frac{V}{c_x \left( \frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_\text{upper}}} \right) + c_y \left( \sqrt{P} - \sqrt{P_\text{lower}} \right)} $$

Capitial Efficiency

We quantify capitial efficiency by comparing the value of $L$ of a concentrated liquidity position to that of a full-range liquidity position with the same value $V$.

$$ CE = \frac{L_\text{conc}}{L_\text{full}} $$

where

$$ L_\text{conc} = \frac{V}{P_\text{now} \left( \frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_\text{upper}}} \right) + \left(\sqrt{P} - \sqrt{P_\text{lower}}\right)} $$

$$ L_\text{full} = \frac{V}{P_\text{now}\left(\frac{1}{\sqrt{P_\text{now}}}\right) + \sqrt{P_\text{now}}} = \frac{V}{2 \sqrt{P_\text{now}}} $$

For simplicity, let’s define the price range $[P_\text{lower}, P_\text{upper}] = [\frac{1}{a} P_\text{now}, b P_\text{now}]$ where $\frac{1}{a} < b$ and $a,b>0$.

Then, we simplify the capital efficency formula to:

$$ CE = \begin{cases} \frac{1}{1 - \frac{1}{2 \sqrt{a}} - \frac{1}{2 \sqrt{b}}} & a \ge 1\ \ \text{and}\ \ b \ge 1 & \text{(In range)} \\[4pt] \frac{2}{\sqrt{a}-\frac{1}{\sqrt{b}}} & a < 1\ \ \text{and}\ \ b > 1 & \text{(Below range)} \\[4pt] \frac{2}{\sqrt{b}-\frac{1}{\sqrt{a}}} & a > 1\ \ \text{and}\ \ b < 1 & \text{(Above range)} \end{cases} $$

So, if you create a position of which the current price is in the middle of the price range (i.e. $a = b$), then:

$$ CE = 1 + \frac{1}{\sqrt{a}-1} $$

For example, for a 1-tick position, $a=\sqrt{1.0001}$ and thus $CE=40002.5$. It means you need 40002x more capitial to construct a full-range position with the same liquidity level.

Divergence Loss

Let’s clarify some variables that we’re going to use:

$$ \begin{split} P_{t0} & = \text{Price when creating the position} \\[3pt] P_{t1} & = \text{Current price} \\[3pt] P_0 & = \text{max}\left\{P_{\text{lower}}, \text{min}\left\{ P_{\text{upper}}, P_{t0}\right\}\right\} \\[3pt] P_1 & = \text{max}\left\{P_{\text{lower}}, \text{min}\left\{ P_{\text{upper}}, P_{t1}\right\}\right\} \\[3pt] \newline x_0, y_0 &= \text{Token amounts used to create the position} \\[3pt] x_1, y_1 &= \text{Current token amounts in the position} \\[3pt] \end{split} $$

Divergence loss is the percentage decrease in the value of the position comparing to the value of simply hodling the tokens.

$$ V_\text{LP} = P_{t1} x_1 + y_1 $$

$$ V_\text{Hodl} = P_{t1} x_0+y_0 $$

$$ DL = \frac{V_\text{LP}}{V_\text{Hodl}} - 1 $$

$$ DL = \frac{ P_{t1} \left( \frac{1}{\sqrt{P_1}} - \frac{1}{\sqrt{P_\text{upper}}} \right) + \left(\sqrt{P_1} - \sqrt{P_\text{lower}}\right) }{ P_{t1} \left( \frac{1}{\sqrt{P_0}} - \frac{1}{\sqrt{P_\text{upper}}} \right) + \left(\sqrt{P_0} - \sqrt{P_\text{lower}}\right) } - 1 $$

Let’s assume the pool price was in the middle of the position’s price range when the position was created, i.e. $[P_\text{lower}, P_\text{upper}] = [\frac{1}{a} P_0, a P_0]$ where $a > 1$.

Let’s also define the current price $P_{t1} = u P_{t0}$. Then, we simplify the DL formula to:

$$ DL = \begin{cases} \frac{u \left( \sqrt{a}+1 \right)}{u+1} - 1 & u < \frac{1}{a} & \text{(Below range)} \\[6pt] \frac{\left( \sqrt{a}+1 \right)}{u+1} - 1 & u > a & \text{(Above range)} \\[6pt] \frac{\sqrt{a} \left(\sqrt{u}-1\right)^2} {\left(1-\sqrt{a}\right) (u+1)} & \text{otherwise} & \text{(In range)} \\[6pt] \end{cases} $$

Proportions of Underlying Tokens

Given a current price $P_\text{now}$ and a position’s price range $[P_\text{lower}, P_\text{upper}]$, what are the weights of token X and token Y in the position in terms of cash value?

$$ \begin{gather} w_x = \frac{V_x}{V_x + V_y} \\[2pt] w_x = \left( \frac{V_y}{V_x} + 1 \right)^{-1} \\[2pt] w_x = \left( \frac{y}{P_\text{now} x} + 1 \right)^{-1} \\[2pt] w_x = \left[ \frac {\sqrt{P} - \sqrt{P_\text{lower}}} {P_\text{now} \left( \frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_\text{upper}}} \right)} + 1 \right]^{-1} \end{gather} $$

$$ w_y = 1 - w_x $$

Tick Conversion

$$ P_i = 1.0001^i $$

$$ i = \log_{1.0001}P_i $$

  • $i$: Tick number
  • $P$: Price of token0 in terms of token1