Subscribe to SeanChao
Subscribe to SeanChao
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers
In a decentralized world, people need to swap tokens. However, money does not exist at first and nobody behaves as a market maker.
Where does the money come from? People put tokens into a liquidity pool to that others could swap tokens they supplied. They are called liquidity providers.
Who is the market maker? Code. The immutable smart contract permanently stored on the blockchain does the job. The contract determines the exchange rate of a token pair. The contract (or protocol) is called automated market makers(AMM).
The most widely used automated market maker mechanism is called constant product automated market maker, adopted by renowned DeFi protocols Uniswap and Sushiswap, where the product of the number of tokens A and B is a constant $k$:
For example, assume we have 1 $ETH and 1000 $USDX, and 1 $ETH = 1000 $USDX. We provide both of them to the liquidity pool. The constant $k = 1 \times 4000 = 4000$. If the price of $ETH 🚀 to 4000 $USDX, our decentralized code has no idea about that, and people keep swapping $USDX to $ETH in our decentralized exchange (DEX) to arbitrage. As a result, the number of $ETH keeps decreasing. To make $k$ constant, we need more $USDX! Therefore, the number of $USDX required to swap for a $ETH keeps increasing, until finally, 1 $ETH is 4000 $USDX in our DEX.
Now, we have $1000 = k = \bold{0.5} \times \bold{2000}$ in our pool (0.5 $ETH and 2000 $USDX, corresponding to 1 $ETH = 4000 $USDX). If we decide to take our money back, we will receive 0.5 $ETH and 2000 $USDX.
When people swap tokens in DeFi, they pay a small number of transaction fees to the liquidity pool, which goes to the liquidity providers in the end. If that is the whole story, liquidity providers never lose money, do they?
Sadly, the answer is: liquidity providers can lose money. What are we missing? The change of price.
Recall the example above, after we take out money from the liquidity pool, we have 0.5 $ETH and 2000 $USDX. If 1 $USDX = $1, we have $4000 in total.
What if we never provide liquidity and just HODL the tokens in the first place? We have 1 $ETH(=4000 $USDX) and $1000 USDX, which is now worth $5000! We lost a potential $1000 profit! The $1000 loss is called impermanent loss, originated from the change in asset value.
Let’s consider the impermanent loss as the ratio between the value of assets if we provide liquidity and the value of assets if we simply hold them. We define the exchange rate between tokens as $r$. If token A trades r token B, the price of A is r times the price of B. In the liquidity pool, each token composes of 50% of the pool. Therefore the number of token B in the pool is r times of A.
We denote the number of token A and B in the pool at the begnning as $a_{t1}$, $b_{t1}$ respectively. The initial exchange rate is $r_1$. Now we have $b_{t1}=r_1a_{t1}$. Note that $a_{t1} \times b_{t1} = k$. We get:
After the price changes, the number of token A and B becomes $a_{t2}$, $b_{t2}$ respectively, with the new exchange rate to be $r_2$. Again, $a_{t2} \times b_{t2} = k$. Now,
Let’s calculate our profit. $\text{V}\text{hodl}$ denotes the total value if we hodls tokens and $\text{V}\text{lp}$ denotes the value if we provide liquidity.
$$ \begin{align} \text{V}\text{lp} & = r_2a{t_\bold{2}}+b_{t_\bold{2}} \ \text{V}\text{hodl} & = r_2a{t_\bold{1}}+b_{t_\bold{1}} \end{align} $$
Finally, The impermanent loss, the loss in total value (relative to the HODL value), is:
$$ \begin{align*} \text{IL%} & = 1- \dfrac{\text{P}\text{lp}}{\text{P}\text{hodl}} \ & = 1 - \dfrac{r_2a_{t_\bold{2}}+b_{t_\bold{2}}}{r_2a_{t_\bold{1}}+b_{t_\bold{1}}} \ & = 1 - \dfrac{r_2\sqrt{\dfrac{k}{r_2}}+ \sqrt{kr_2}} {r_2\sqrt{\dfrac{k}{r_1}}+ \sqrt{kr_1}} \ & = 1 - \dfrac{2}{\sqrt{\dfrac{r_2}{r_1}}+ \sqrt{\dfrac{r_1}{r_2}}} \end{align*} $$
Let’s simply it bit. $\Delta = \frac{r_2}{r_1}$ is simply how much token A increases or decrease relative to token B. A and B is also interchangeable! Now we can consider the impermanent loss simply in terms of the price change:
$\text{IL%} = 1 - \dfrac{2\sqrt{\Delta}}{\Delta + 1}$
The table and plot are shown below. For example, if $ETH doubles (Delta=2), we suffer from an impermanent loss of 5.72%.
Price change | IL% |
|---|---|
± 1% | 0.00109% |
± 3% | 0.0109% |
± 5% | 0.0297% |
± 10% | 0.113% |
± 100% | 5.72% |

In a decentralized world, people need to swap tokens. However, money does not exist at first and nobody behaves as a market maker.
Where does the money come from? People put tokens into a liquidity pool to that others could swap tokens they supplied. They are called liquidity providers.
Who is the market maker? Code. The immutable smart contract permanently stored on the blockchain does the job. The contract determines the exchange rate of a token pair. The contract (or protocol) is called automated market makers(AMM).
The most widely used automated market maker mechanism is called constant product automated market maker, adopted by renowned DeFi protocols Uniswap and Sushiswap, where the product of the number of tokens A and B is a constant $k$:
For example, assume we have 1 $ETH and 1000 $USDX, and 1 $ETH = 1000 $USDX. We provide both of them to the liquidity pool. The constant $k = 1 \times 4000 = 4000$. If the price of $ETH 🚀 to 4000 $USDX, our decentralized code has no idea about that, and people keep swapping $USDX to $ETH in our decentralized exchange (DEX) to arbitrage. As a result, the number of $ETH keeps decreasing. To make $k$ constant, we need more $USDX! Therefore, the number of $USDX required to swap for a $ETH keeps increasing, until finally, 1 $ETH is 4000 $USDX in our DEX.
Now, we have $1000 = k = \bold{0.5} \times \bold{2000}$ in our pool (0.5 $ETH and 2000 $USDX, corresponding to 1 $ETH = 4000 $USDX). If we decide to take our money back, we will receive 0.5 $ETH and 2000 $USDX.
When people swap tokens in DeFi, they pay a small number of transaction fees to the liquidity pool, which goes to the liquidity providers in the end. If that is the whole story, liquidity providers never lose money, do they?
Sadly, the answer is: liquidity providers can lose money. What are we missing? The change of price.
Recall the example above, after we take out money from the liquidity pool, we have 0.5 $ETH and 2000 $USDX. If 1 $USDX = $1, we have $4000 in total.
What if we never provide liquidity and just HODL the tokens in the first place? We have 1 $ETH(=4000 $USDX) and $1000 USDX, which is now worth $5000! We lost a potential $1000 profit! The $1000 loss is called impermanent loss, originated from the change in asset value.
Let’s consider the impermanent loss as the ratio between the value of assets if we provide liquidity and the value of assets if we simply hold them. We define the exchange rate between tokens as $r$. If token A trades r token B, the price of A is r times the price of B. In the liquidity pool, each token composes of 50% of the pool. Therefore the number of token B in the pool is r times of A.
We denote the number of token A and B in the pool at the begnning as $a_{t1}$, $b_{t1}$ respectively. The initial exchange rate is $r_1$. Now we have $b_{t1}=r_1a_{t1}$. Note that $a_{t1} \times b_{t1} = k$. We get:
After the price changes, the number of token A and B becomes $a_{t2}$, $b_{t2}$ respectively, with the new exchange rate to be $r_2$. Again, $a_{t2} \times b_{t2} = k$. Now,
Let’s calculate our profit. $\text{V}\text{hodl}$ denotes the total value if we hodls tokens and $\text{V}\text{lp}$ denotes the value if we provide liquidity.
$$ \begin{align} \text{V}\text{lp} & = r_2a{t_\bold{2}}+b_{t_\bold{2}} \ \text{V}\text{hodl} & = r_2a{t_\bold{1}}+b_{t_\bold{1}} \end{align} $$
Finally, The impermanent loss, the loss in total value (relative to the HODL value), is:
$$ \begin{align*} \text{IL%} & = 1- \dfrac{\text{P}\text{lp}}{\text{P}\text{hodl}} \ & = 1 - \dfrac{r_2a_{t_\bold{2}}+b_{t_\bold{2}}}{r_2a_{t_\bold{1}}+b_{t_\bold{1}}} \ & = 1 - \dfrac{r_2\sqrt{\dfrac{k}{r_2}}+ \sqrt{kr_2}} {r_2\sqrt{\dfrac{k}{r_1}}+ \sqrt{kr_1}} \ & = 1 - \dfrac{2}{\sqrt{\dfrac{r_2}{r_1}}+ \sqrt{\dfrac{r_1}{r_2}}} \end{align*} $$
Let’s simply it bit. $\Delta = \frac{r_2}{r_1}$ is simply how much token A increases or decrease relative to token B. A and B is also interchangeable! Now we can consider the impermanent loss simply in terms of the price change:
$\text{IL%} = 1 - \dfrac{2\sqrt{\Delta}}{\Delta + 1}$
The table and plot are shown below. For example, if $ETH doubles (Delta=2), we suffer from an impermanent loss of 5.72%.
Price change | IL% |
|---|---|
± 1% | 0.00109% |
± 3% | 0.0109% |
± 5% | 0.0297% |
± 10% | 0.113% |
± 100% | 5.72% |

No activity yet