Mechanics of Impermanent Loss

Introduction and Background

Impermanent loss is a new concept born in the world of DeFi. Impermanent loss is the idea that liquidity providers can end up with less wealth (measured in US dollar terms) providing liquidity compared to holding assets. This happens because of the mechanics of liquidity pools which will be explained below.

Many (most?) liquidity pools today are constant product pools (defined more technically below) which is what this article will cover. Uniswap v3 has moved to concentrated liquidity) which will not be covered in this article. This article will not cover how slippage or fees charged by pools (0.30% for Uniswap) affect impermanent loss.

Liquidity pools pair two assets into a “pool” to enable asset trading. Users are incentivized to provide assets into these pools to earn fees which are charged to asset traders. For example, suppose there’s market demand to swap between WBTC (wrapped bitcoin) and ETH (ether). Because of this demand, a liquidity pool for WBTC and ETH will be created and holders of these assets will provide liquidity to this pool in order to earn fees from other users who want to swap between these two assets. These asset “pools” are governed by smart contracts and the concept of “providing liquidity” means that users deposit assets into smart contracts. When a user provides liquidity to a pool, they are given LP tokens in exchange which represent ownership of a fraction of the assets in that pool.

When a user provides liquidity to a pool they must provide both assets (remember that pools operate in asset pairs) and rational participants will provide equal dollar values of both assets. If unequal dollar values are provided, arbitrageurs will be able to extract profit from the imbalance - this will become clear below when we work through the math. Constant product liquidity pools, like in Uniswap V2, require the following formula to always be satisfied when executing a trade:

Where x is the quantity of one asset and y is the quantity of another asset. Remember that k (the “constant product”) is preserved when executing trades but that k changes when users add and remove liquidity.

Since we’re going to be doing some basic algebra later in this article, lets rewrite the above formula as:

Price Drop Example

Setup

Lets suppose that a WBTC:ETH liquidity pool is described by the following table:

Note that the dollar values are equal. Let’s assume that there currently exist 10 LP tokens for this pool.

Now you as a user decide it will be worthwhile to add liquidity to this pool. You know that for every 1 WBTC you add you also need to add 5 ETH. Let’s say you add 1 WBTC and 5 ETH. The new description of the pool is as follows:

LP tokens and Pool Ownership

There used to be $2000 of liquidity and there’s now $2200 of liquidity. You provided $200 of liquidity to the pool which means you own 9.090909% of the pool, as explained below:

From this we can calculate how many LP tokens you will be issued. There used to be 10 LP tokens, there are now y LP tokens in total and you own 9.090909% of the y LP tokens.

Which means that you will be issued 0.99999999 LP tokens which represent 9.090909% of all LP tokens and the same percentage ownership of the pool.

We also know that

ETH Price Drop

Now, suppose that the price of ETH drops to $15.

Given the imbalance in the USD value of the assets in this pool, arbitrageurs can sell ETH into the pool and buy WBTC at a relative discount. This will be clear after we rebalance the pool below.

We can rewrite the constant product formula using the USD price and USD value of the assets (quantity = value / price). The quantity of WBTC is equal to the value of all WBTC in the pool divided by the price of WBTC. This is also true for ETH.

Rebalancing the pool

Whenever a pool is imbalanced market forces will rebalance it because arbitrageurs can extract profit while simultaneously rebalancing it. This will become clear soon.

In order for the pool to normalize, the USD value of each asset must be equal (hence why they both have a value of x in the following table) and the new quantities of each asset must be determined:

We can solve for x as follows

which means there should be $952.63 of each asset after rebalancing. We can now solve for the quantity of each asset:

which means the final tables looks like

Profit Extraction By Arbitrageurs

This means an arbitrageur could have bought 11-9.5263=1.4737 WBTC worth 1.4737*$100=$147.37 in exchange for 63.51-55=8.51 ETH worth 8.51*$15=$127.65 earning a profit of $147.37-$127.65=$19.72.

This is how the pool will be rebalanced by market forces - arbitrageurs will see an opportunity to profit from the imbalance. They will try to extract this profit and in the process will rebalance the pool. Note that most arbitraging activity will be done by bots which constantly monitor the blockchain and take action as soon as they realize there’s a profit opportunity - this is done much faster and more frequently than any human can do manually.

Making Impermanent Loss Permanent

Remember that you have 0.99999999 LP tokens and that there are a total of 10.99999999 LP tokens which entitles you to 9.090909% of the assets in the pool. If you decide to redeem your LP tokens you will get 9.5263*0.09090909=0.86602726 WBTC and 63.51*0.09090909=5.77363631 of ETH. Your 0.86602726 WBTC is worth $86.602726 and your 5.77363631 ETH is also worth $86.60454465. Summed together your assets are worth $173.2090893.

If you had not put your assets into the liquidity pool you would still have 1 WBTC and 5 ETH which would be worth 1*$100+5*$15=$175. This means that you lost $175-$173.2090893=$1.7909107 in impermanent loss. You have made your impermanent loss permanent by redeeming your LP tokens.

Price Rise Example

Setup

Let’s assume the exact same setup as before. You add 1 WBTC and 5 ETH and in exchange get 0.99999999 LP tokens which represent 9.090909% of the following pool:

ETH Price Rises

In the previous example, the price of ETH dropped to $15, in this example the price of ETH will rise to $25.

Rebalancing the Pool

I’ll leave working out the math as an exercise for the reader. Assuming I’ve done the calculations correctly, a properly balanced pool will have the following asset quantities:

Profit Extraction By Arbitrageurs

This means an arbitrageur could have sold 12.2984-11=1.2984 WBTC worth 1.2984*$100=$129.84 into the pool in exchange for 55-49.1936=5.8064 ETH worth 5.8064*$15=$145.16 earning a profit of $145.16-$129.84=$15.32.

Making Impermanent Loss Permanent

Redeeming your LP tokens will get you 1.11803635 WBTC worth $111.80 and 4.47214541 ETH worth $111.80. The total value of your assets is $223.6.

If you never adding liquidity to the pool you would have 1 WBTC and 5 ETH worth 1*$100 + 5*$25=$225 which means you suffered $225-$223.6=$1.40 of impermanent loss.

Both Assets Fall in Price

Setup

Let’s assume the exact same setup as before. You add 1 WBTC and 5 ETH and in exchange get 0.99999999 LP tokens which represent 9.090909% of the following pool:

ETH Drops in Price

Like before, let’s assume ETH drops from $20 to $15 which is a change of 25%. After the pool gets rebalanced it will look like this (copied from above):

If you were to redeem your LP tokens you would suffer impermanent loss. Instead let’s assume you hold your LP tokens and now the price of WBTC drops by 25% too.

WBTC Drops in Price

Now, WBTC drops by 25% to $75.

This is how the pool will be rebalanced by arbitrageurs, I will leave the math as an exercise for the reader (tip: remember that k=605):

Note that now the quantities of both assets are equal to the quantities prior to any price changes. If you redeem your LP tokens now, after both assets changed in price by an equal percentage amount, you will not suffer impermanent loss.

Conclusion

Impermanent loss is a new phenomenon that occurs as a result of the mechanics of constant product AMMs. The concept is called impermanent loss, somewhat disingenuously, since the liquidity provider only realizes the loss if they redeem their LP tokens for assets from the pool.

We’ve seen that impermanent loss happens when the price of one asset in the pool rises or falls relative to the price of the other asset in the pool. If the price of both assets rise or fall perfectly in tandem (in percentage terms) then there will be no impermanent loss since the dollar value of both assets will remain constant, rebalancing won’t need to occur and arbitrageurs won’t be able to make a profit through trades with the pool.

Tools like apy.vision can help liquidity providers determine if they will suffer impermanent loss when redeeming LP tokens. New projects are being built which offer impermanent loss protection (like Tokemak and Thorchain), while others aim to circumvent impermanent loss (like Olympus).

Recall that this article does not cover how fees charged by the liquidity pools affect impermanent loss. Uniswap V2 charges a 0.30% trading fee and this fee is used to compensate liquidity providers for taking the risk of providing assets. It’s possible that these fees will outweigh any impermanent loss. Average users will likely suffer more impermanent loss than they will recoup in trading fees.

Subscribe to Paymahn
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.