Introduction

Every time you engage in a trade on a decentralized exchange, you're interacting with a pool of tokens. These pools don't magically appear; they exist because individuals, known as liquidity providers, deposit tokens into them to facilitate your trades. Liquidity providers do this to earn fees from your trades and make a profit. Now, let's focus on something called "Impermanent Loss" that occurs during these trades. We'll explore what it is and how to calculate it for a liquidity provider dealing with a specific pair of tokens. Let's dive right in!

What is Impermanent Loss?

Impermanent loss refers to the temporary loss that can occur when providing liquidity to a decentralized exchange (DEX). It happens when the price of the tokens a liquidity provider has provided as liquidity deviates from the price at which he/she deposited them.

info
💡 For example, say you as a liquidity provider deposited $50 worth of token A and $50 worth of token B into a liquidity pool when the price ratio was 1:1. If the price of token A increases to $100 while token B stays at $50, your pool now has assets worth $100 of token A and $50 of token B. However, if you withdrew your liquidity at this point, you would only get back around $75 worth of each token due to how the pool works. So you have an "impermanent" loss of around $25.

This impermanent loss occurs because your liquidity provides price support for the pool, allowing others to trade at divergent prices. You can regain this loss if the prices converge back to 1:1 in the future, which is why it is impermanent.

Impermanent loss is a natural part of being a liquidity provider in a DEX. It doesn't automatically lead to a financial loss because you still earn trading fees from the pool. It's something to keep in mind when you provide liquidity, and it encourages providers to select pairs of tokens they believe will increase in value over time.

Why Does Impermanent Loss Occur?

Impermanent loss can occur for several reasons, which we will look into. The first thing to keep in mind is that for a certain pool, there are a lot of liquidity providers. Your liquidity determines your percentage of ownership of the pool, except the pool (a pair of tokens) is just being created for the first time. Now, we have people who are called arbitrageurs, who are investors who exploit market inefficiencies by buying an asset in one market and simultaneously selling it in another market at a higher price.

info
💡 Let's say that CQT tokens are trading at $5 on Exchange A and $5.10 on Exchange B. An arbitrageur sees the token trading at $5 per token on Exchange A and $5.10 on Exchange B. The arbitrageur buys the tokens on Exchange A and sells them on Exchange B, locking in a profit of $0.10 per token. The arbitrageur repeats this process until the price difference between the two exchanges disappears.

Arbitrage opportunities can arise due to a variety of factors, such as differences in exchange rates, liquidity, and transaction fees.

The Impact of Impermanent Loss on Liquidity Providers

Impermanent loss mainly affects liquidity providers by making them miss out on potential earnings compared to just holding the tokens. Let’s take a closer look:

  • If the token's price goes up a lot, you won't benefit as much because the pool tries to keep the balance.

  • If the token's price crashes, your pooled tokens lose more value than if you held them separately.

  • Impermanent loss makes providing liquidity riskier, so providers may add less liquidity or require higher trading fees.

  • Providers might need to commit capital for a long time to wait for prices to get closer and reduce their losses.

The loss only happens if you withdraw when prices are different. If prices get closer again, the impermanent loss goes away. Additionally, trading fees earned for liquidity can compensate for impermanent loss, reducing risk.

Still, impermanent loss adds extra risks for liquidity providers compared to holding tokens directly. But they take these risks because they earn trading fees from the pool. Handling impermanent loss well is important for keeping liquidity provision sustainable.

Calculating Impermanent Loss

Before we dive into calculating impermanent loss, keep in mind that most DEXs use the Automated Market Maker (AMM) model, which follows the constant product formula. This formula defines how the pools work, where:

  • x is the quantity of the base token (e.g., $CQT tokens),

  • y is the quantity of the quote token (e.g., $ETH),

  • k is the constant product or invariant.

The value of k remains constant regardless of the size of a trade. This constant can be calculated by multiplying the initial amounts of $CQT and $ETH when the pool is created. When a trade occurs, the amounts of $CQT and $ETH change, but the product of the two quantities must always equal k.

Let's say you want to create a liquidity pool for $CQT and $ETH on an AMM exchange. You decide to deposit 10,000 $CQT tokens and 100 $ETH into the pool.

Initially:

  • x (amount of $CQT) = 10,000

  • y (amount of $ETH) = 100

Now you calculate the invariant k:

  • k = x * y = 10,000 $CQT * 100 $ETH = 1,000,000

This means no matter how the quantities of $CQT and $ETH in the pool change, their product must always be equal to 1,000,000 to maintain the invariant.

When someone buys $CQT using $ETH, they add $ETH to the pool, which increases the $ETH quantity and decreases the $CQT quantity to maintain the invariant k.

Calculating the Trade Without Fees

Let's imagine someone wants to buy 1,000 $CQT tokens from the pool. They will need to add a certain amount of $ETH to the pool to keep the invariant the same.

Let's denote the new quantities of $CQT and $ETH in the pool as x'  and y', respectively. After the trade:

  • x' = 10,000 - 1,000 = 9,000 $CQT (since 1,000 $CQT are taken out)

  • The invariant k is still = 1,000,000

We can find out how much $ETH needs to be added to the pool by rearranging the constant product formula to solve for y':

This means the new amount of $ETH in the pool must be about 111.11. Since there was initially 100 $ETH, the trader must add approximately 11.11 $ETH to the pool to purchase 1,000 $CQT tokens.

Through this transaction, the price of $CQT in terms of $ETH has changed. Before the transaction, the price was:

100 $ETH / 10,000 $CQT = 0.01 $ETH per $CQT.

After the transaction, the price is now:

111.11 $ETH / 9,000 $CQT ≈ 0.0123 $ETH per $CQT.

The price increases with the purchase, which is characteristic of the AMM model due to the sliding price scale.

So, the balance of $CQT decreases because the trader takes out $CQT, and the $ETH balance increases because the trader adds $ETH. The price of $CQT relative to $ETH has increased because there is less $CQT in the pool after the trade, and each $CQT now costs more $ETH. This is a direct result of supply and demand: as the supply of $CQT decreases due to the trade, its price increases.

The question now is how does that affect the invariant? (Before and after trade)

Before the trade:

k = 10,000 * 100 = 1,000,000

After the trade:

k = (10,000 - 1,000) * (100 + 11.11) = 9,000 * 111.11 = 1,000,000

The invariant k still remains the same, as the increase in $ETH compensates for the decrease in $CQT.

info
💡 This is just a simplified representation to illustrate how the constant product formula works and the concept of the invariant k. Take note that in real AMM protocols, fees are also a factor and can slightly adjust how the invariant is maintained.

Now that we understand how trade happens in the pool let’s now move to how to calculate the impermanent loss for liquidity providers.

The Basic Formula to Calculate Impermanent Loss

The formula below is a way to calculate impermanent loss that is commonly used in the context of AMMs like UniswapV2. It is based on the change in price ratio (k) of the two assets in the liquidity pool. This formula provides a more direct calculation, where:

  • k is the price ratio of the two assets after the price change, divided by the price ratio before the price change.

A Simple Step-by-Step Example of Impermanent Loss

Let's use our previous example with the $CQT and $ETH liquidity pool to calculate the impermanent loss.

Initial Conditions:

  • Suppose you, as a liquidity provider, deposit 10,000 $CQT and 100 $ETH into the pool.

  • The initial price ratio when you deposited was 1 $ETH = 100 $CQT (or 0.01 $ETH per $CQT).

Scenario:

Let's say the price of $CQT doubles with respect to $ETH outside the pool (maybe due to market movements), which means 1 $ETH now equals 50 $CQT or 0.02 $ETH per $CQT.

After the Price Change:

  • After $CQT doubles in value, the new price ratio is 0.02 $ETH per $CQT.

Calculating (k)

Calculating Impermanent Loss

Plug (k) into the formula:

So, the impermanent loss, in this case, would be -5.72%, which means that the liquidity provider's position is worth approximately 5.72% less than if they had just held the assets. This is typically presented as a positive percentage, so we would say there is a 5.72% impermanent loss.

If you try to use this calculator to calculate the loss, here’s what you have:

Which is the same with our calculation. Now, suppose you have $500 worth of Token A and $500 worth of Token B:

  • If you hold them directly, you have 5.00 Token A and 500.00 Token B. The total value of your holdings is $750.00.

  • If you provide these tokens as liquidity in a pool, you end up with 7.07 Token A and 353.55 Token B in the liquidity pool. The total value of your liquidity provision is $707.11.

When discussing impermanent loss and the associated calculations, it's important to use the specific formula that best fits the context of the AMM you're analyzing, as there are different formulas that can apply depending on the specifics of the AMM's mechanism.

Impermanent Loss in UniswapV3

UniswapV3 introduces the concept of concentrated liquidity, allowing liquidity providers (LPs) to allocate capital within a predetermined price range [a, b]. This can influence impermanent loss for pairs like $CQT/$ETH in complex ways:

Concentrated Liquidity and Leveraged Exposure

By providing liquidity in a fixed range, liquidity providers (LPs) can be thought of as offering liquidity on leverage. An LP’s reserves are used more effectively within the confines of [a, b], similar to 'virtual liquidity.’ However, if the price moves outside this range, LPs end up with only one asset and cease to earn trading fees until the price returns to within the range.

Increased Impermanent Loss with Concentrated Positions

Although LPs can enjoy a larger share of trading fees due to their concentrated position, the downside is an amplified impermanent loss, just as gains and losses are magnified with financial leverage. The exact extent of this increase in impermanent loss can be derived from the reserves and the price movement within the set range [p_a, p_b].

Caveats and Price Movement

The impermanent loss equations derived apply only within the active price range. If prices move outside [p_a, p_b], the LPs' asset holdings become static, and different considerations come into play. It's insightful to note that as the price range widens towards the whole price spectrum, the impermanent loss approaches that of the UniswapV2 model.

Analysis of Impermanent Loss in UniswapV3

The analysis shows that even when the price range is sufficiently large to accommodate a doubling or halving of prices, the impermanent loss can be nearly four times greater than providing liquidity across the entire price spectrum. This excludes any additional impermanent loss from prices exiting the targeted range.

Considerations for Liquidity Providers in UniswapV3

Given these dynamics, $CQT/$ETH liquidity providers and others in UniswapV3 must:

  • Understand Concentrated Liquidity Risks: Know the leveraged nature of concentrated liquidity and the implications for impermanent loss, especially when prices move out of the chosen range.

  • Actively Manage Risk Tolerance: Assess their willingness to actively manage their positions and risk tolerance against the potential of increased impermanent loss.

  • Set Strategic Investment Parameters: Align liquidity provision with their broader investment goals, considering the nuanced risks and rewards of a V3 position.

  • Stay Informed and Adapt: Maintain an informed outlook on market conditions to manage their positions proactively, mitigating the risks of impermanent loss where possible.

By understanding and leveraging UniswapV3’s mechanisms thoughtfully, liquidity providers can navigate the complexities of impermanent loss more effectively, particularly with volatile pairs like $CQT and $ETH.

Conclusion

Impermanent loss is common for liquidity providers in AMMs like Uniswap. However, new protocols and strategies are being developed to address this challenge. Over time, the fees earned from providing liquidity can offset impermanent losses. The DeFi community will likely adopt more advanced approaches to liquidity provision that balance returns and minimize impermanent loss through creative methods and careful capital deployment. While it may not be entirely eliminated, informed strategies can help reduce impermanent loss. Just like in any investment, managing risks is vital for sustaining participation in decentralized liquidity pools.

References & Further Reading