Skip to main content

Uniswap: How to calculate Impermanent Loss?

Impermanent Loss is a popular concept when it comes to automated market makers and decentralized exchanges like Uniswap. This term is often defined as the percentage loss a liquidity provider would experience for a given price movement. This means that, as an LP, your position may fall in value due to volatility, causing a loss compared to holding these assets outside of the pool. 

This article will spell out the concept in mathematical logic and explain all the assumptions involved. 

We consider a market with liquidity L and amounts x and y of assets X and Y respectively. We also have P as the price of X in terms of Y, and a price movement P1 = P.d where d >0

According to the definition of IL touched upon, we establish a generic formula for IL:

where:
  • V1 is the value of your position in the pool at the price P1 (x,y move with price)
  • Vh is the value of your assets at the price P1 if you keep them outside of the pool 
  • We also consider V0 as the initial value of your holding (at the price P)

Impermanent Loss on Uniswap V2

On Uniswap V2, we have constant product formula and the price between X and Y:


It follows then that:



When the price move to P1, we have V1 in terms of L and P1:

and also have Vh in terms of L and P1:


By combining (3) and (4), we can easily derive the formula for IL:


Impermanent Loss on Uniswap V3

On the Uniswap V3, reserves for a concentrated position are described by the curve:


We will use the same approach to calculate IL for V3 based on the above V2 section, and also define Pa, Pb to be the price interval for our concentrated position. Both P and P1 are assumed to be inside this range. 

On the other hand, we can also determine the amounts x and y in terms of real and virtual reserves. And note that the amounts of reserves of your position are now x_r and y_r:

Now, we combine (1), (2) with the V3 curve, then the real reserves are described like this:


The initial value V0 of your holding:


When the price move to P1, the real reserves x_r and y_r also change and V1 is just V0 with P1 substituted for P:

Next up is Vh:

Finally, we calculate IL on V3 as a percentage change:

We also can described IL(V3) in terms of IL(V2): 


Note that we don't use this equation if the price falls outside the liquidity range [Pa, Pb].


Comments

Popular posts from this blog

Understanding Automated Market-Makers (AMM): Price Impact

Every day, thousands of people use a decentralized exchange (DEX) for the first time. However, the idiosyncrasies of a public blockchain routinely catch newcomers off-guard, even those familiar with trading on more traditional venues. As a result, traders bleed money to arbitrageurs and frontrunners, leading to worse-than-necessary execution. At a high level, we can break down the costs of each trade into several parts: 1. Price impact 2. Broker or trading fees 3. Slippage 4. Transaction fees of the underlying blockchain This article on automated market-makers (AMMs) will serve as an intro to the series and discuss the first and most crucial cost: price impact. You will learn: how AMMs like Uniswap V2, Sushiswap, and Balancer determine the prices they quote and how to minimize the price impact of your trade using a few simple strategies. What are liquidity pools? Most DEXs consist of many liquidity pools that represent different trading pairs, like ETH/WBTC. Instead of matching buyers ...

Weekly Report: 7th November 2022

Fund Flows  Mixed sentiment following the FOMC announcement last week  TD; LR: 1. Digital asset investment products saw minor outflows totaling US$15.6m last week and a bad start to the month with outflows totaling US$19m. 2. Bitcoin saw outflows totaling US$13m for the week. This follows a 7-week run of inflows and comes after FOMC raised interest rates by a further 75 basis points. 3. Short-Bitcoin investment products also saw outflows for the 3rd consecutive week totaling US$7.1m, bringing total outflows to US$28m. 4. XRP saw inflows for the 3rd week totaling US$1.1m implying improving investor confidence as the SEC case against Ripple looks increasingly fragile.  Digital asset investment products saw minor outflows totaling US$15.6m last week and a bad start to the month with outflows totaling US$19m. However, the flow activity remains very low relative to history, with this doldrum period lasting 8 weeks now. Regionally, the negative activity focussed on the Americas...