OKX’s Moon Grid trading bot — automatically buy low and sell high
What is impermanent loss in DeFi? An overview of AMMs and the risks of liquidity mining
An explanation of impermanent loss and how it works when providing liquidity to DeFi protocols
DeFi, or decentralized finance, has been a buzzword in crypto since 2019, but it became a major topic in 2020 as DeFi protocols and platforms surged in popularity. The ecosystem, driven by the Ethereum blockchain, has also played a crucial role in reviving retail interest in the larger crypto space. In fact, even traditional banking institutions are now acknowledging the potential of DeFi, while we’ve seen the value of assets committed to DeFi protocols go from $1.2 billion to more than $60 billion in the last 12 months.
People even mildly familiar with the DeFi space may be aware of the concept of providing liquidity to earn passive income, or yield, via DeFi protocols. So-called yield farming — also called liquidity mining — in DeFi has been at the heart of the market’s explosion, led by automated-market-making protocols. Projects like Uniswap, SushiSwap and Balancer are what are known as decentralized exchanges, and they rely on such AMM protocols. Their platforms allow traders to easily swap tokens in a completely decentralized and seamless manner.
This is made possible by what are known as liquidity providers — i.e., users who deposit particular crypto assets to the platform, thereby providing liquidity for other assets to be exchanged. The LPs are incentivized to deposit, or lock in, their assets because they earn transaction fees generated by the traders swapping tokens on the given platform. From the point of view of the LPs — those locking their tokens into the DeFi protocol — the transaction fees they earn are like a yield. The value of the yield fluctuates, as it depends on the protocol’s usage and volume.
In this article, we are not going to delve into how providing liquidity works in detail, but to learn more, please refer to our guide on earning passive income with OKX Earn. Here, we will be explaining the concept of impermanent loss, which is important to grasp for users already providing liquidity to AMMs, or considering doing so.
In order to understand this concept, however, we need to have an overview of how liquidity pools in AMM protocols work.
How AMM liquidity pools work
In order for users of an AMM-powered protocol to swap tokens, there need to be pools of liquidity available to them. For example, if a trader wants to sell 1 ETH for USDT, there needs to be a liquidity pool that can take the 1 ETH and give 1,000 USDT (and, for simplicity’s sake, let’s say 1 ETH is trading for 1,000 USDT and we don’t consider fees) and vice versa. As trading volumes surge, so does the need for such liquidity, and that is where those who are looking to be LPs come in. These users can deposit the two digital currencies of a pair — in this case, ETH and USDT— to the protocol’s relevant pool(s) in a predetermined ratio, which is often 50/50.
For example, if an LP with 10 ETH wishes to add liquidity to an ETH/USDT pool with a 50/50 ratio, they will need to deposit 10 ETH and 10,000 USDT (still assuming 1 ETH = 1,000 USDT). If the pool they commit to has a total of 100,000 USDT worth of assets (50 ETH and 50,000 USDT), their share will be equal to 20,000 USDT / 100,000 USDT x 100 = 20%.
The percentage of the LP’s share in a given pool is important to note because when the LP commits, or deposits, their assets to the pool via a smart contract, they will automatically be issued LP tokens. These tokens entitle the LP to withdraw their share of the pool at any time — 20% of the pool in our above example.
This is where the concept of impermanent loss comes into play. Since LPs are entitled to their share of the pool and not a specific number of tokens, they are exposed to another layer of risk — impermanent loss — if the price of their deposited assets grows significantly.
Calculating impermanent loss
In our example, the price of 1 ETH was 1,000 USDT at the time, but let’s say the price doubles and 1 ETH starts trading for 2,000 USDT. Since the pool is adjusted algorithmically, it uses a formula to manage assets. The most basic and widely used one is the constant product formula, popularized by DEX platform Uniswap.
In simple terms, the formula is as follows: ETH liquidity x token liquidity = constant product
Using figures from our example above (50 ETH and 50,000 USDT) gets us: 50 x 50,000 = 2,500,000
Similarly, the price of ETH in the pool can be obtained with this formula: token liquidity / ETH liquidity = ETH price
Applying our example figures gets us: 50,000 / 50 = 1,000 USDT (i.e., the price of 1 ETH).
Now, when the price of ETH changes to 2,000 USDT, we can use these formulas to ascertain the ratio of ETH and USDT held in the pool:
- ETH liquidity = square root (constant product / ETH price)
- Token liquidity = square root (constant product x ETH price)
Applying data from our example here along with the new price of 2,000 USDT per ETH gets us:
- ETH liquidity = square root (2,500,000 / 2,000) = ~35.355 ETH
- Token liquidity = square root (2,500,000 x 2,000) = ~70,710.6 USDT
We can confirm the accuracy of this by using the very first equation (ETH liquidity x token liquidity = constant product) to arrive at the same constant product of 2,500,000: 35.355 x 70,710.6 = ~2,500,000 (i.e., the same as our original constant product above).
Hence, after the price change, assuming all other factors remain constant, the pool will have roughly 35 ETH and 70,710 USDT, compared to the original 50 ETH and 50,000 USDT.
If at this time, the LP wishes to withdraw their assets from the pool, they will exchange their LP tokens for the 20% share they own. Taking their share from the updated amounts of each asset in the pool, they will get 7 ETH (i.e., 20% of 35 ETH) and 14,142 USDT (i.e., 20% of 70,710 USDT).
Now, the total value of the assets withdrawn equals: (7 ETH x 2,000 USDT) + 14,142 USDT = 28,124 USDT.
However, had the user simply held their 10 ETH and 10,000 USDT, instead of depositing these assets into a DeFi protocol, they actually would have gained more. Assuming ETH doubled in price from 1,000 USDT to 2,000 USDT, the user’s non-deposited assets would have been valued at 30,000 USDT: (10 ETH x 2,000 USDT) + 10,000 USDT = 30,000 USDT.
That difference of 1,876 USDT— which can occur because of the way AMM platforms manage asset ratios — is what is known as impermanent loss.
In our example, the LP stands to lose nearly 2,000 USDT in the process of providing liquidity to a DeFi protocol. Though this process is called impermanent loss, the term is slightly misleading. The meaning of impermanent loss is actually very similar to the concept of unrealized loss. The loss could reverse in theory (if the LP doesn’t withdraw their assets and the ETH price returns to original levels), but there is no guarantee of that happening.
Moreover, once an LP withdraws liquidity from a protocol, the impermanent loss indeed becomes permanent. In a case where an LP experiences impermanent loss and then withdraws their assets, the only upside to having provided liquidity to the protocols remains the trading fees that the LP collected while their assets were deposited there. In volatile conditions, however, especially during a bull run, the fees alone are unlikely to cover the difference.
On the flip side, however, a reduction in the price of ETH from the time it was deposited in the pool would yield additional ETH, thereby increasing the liquidity provider’s ETH holding. Given how impermanent loss works, providing liquidity during a bear market and simply holding volatile assets during a bull market are both strategies that merit consideration.
If you’re interested in using a decentralized exchange or providing liquidity, you can start by exploring OKX Swap and Farm DApps on OKC.
OKX Insights presents market analyses, in-depth features, original research & curated news from crypto professionals.