Original article: https://frogsanon.neworder.network/articles/lp-diving-how-to-hack-impermanent-loss
There is no shortage of DeFi protocols in the market today, and there are plenty of opportunities to earn yield by providing liquidity to them. UniSwap, Balancer, and Curve protocols pioneered the Constant Product Market Maker formula and StableSwap invariants that are now used by almost all AMM protocols. Their proposition is simple: users provide liquidity, and when pools are used for transactions, each protocol according to these The formula allocates fees.
However, LPs using these invariants will note a key problem: changes in price lead to losses, and fees are often irrecoverable. This loss of profit—intangible, but measurable—is known as impermanent loss. So why provide liquidity when you can earn more by simply holding and selling?
So what if we could change the idea of profiting from the initial loss? What if we could exploit this phenomenon as a profitable hedge within a broader long/short strategy?
This is all possible with a technique I call "LP Diving", which I would like to explain. To better understand this concept, let's first review the basics of impermanent loss.
impermanent loss
The impermanent loss is a fairly simple concept, but the implications are dire: it is more profitable to buy and hold an asset than to deploy it in a liquidity pool and collect fees. This is because the mechanics of the liquidity pool create losses when the prices of the two assets diverge. Therefore, impermanence loss is more accurately described as divergence loss. [1]
Take two assets in LP pool K as an example, their variable price appreciation has nothing to do with AMM/LP itself. Imagine you pooled:
- 500 Token A, $1
- 500 B Tokens, $1
- Deposit 1,000 tokens for $1,000
Now, consider a situation:
- Token A increases from $1 to $5 (500% increase)
- Token B increases from $1 to $2 (200% increase)
- Final value of $3,500
A reasonable assumption is that depositors can later withdraw their deposits at a 1:1 ratio after a price appreciation or depreciation, just like buying and holding. Token A 500, Token B 500.
However, this doesn't happen. The pool makes a market based on the oracle price whenever a trade passes through them. Hence its name - Constant Product Market Maker.
Unless the two assets are correlated enough that the price deltas of each are equal, savers will withdraw irregular amounts whenever prices deviate. In effect, depositors will withdraw:
- 316.23 of Token A, worth $1,581.14
- 790.57 of Token B, worth $1,581.14
- If deposited, the final value is $3,162.28
Depositors suffer an impermanent loss of 9.65% (or $337.72 less than holders)
This profit is significantly lower than the profit earned by providing no liquidity at all, which tends to keep pool depositors from depositing in the first place. Many protocols attempt to incentivize liquidity through releases as a way to pay depositors fees, but almost always, these fees do not cover losses from price differences.
Consider this: Does a protocol have the ability to pay each depositor the difference — $337.72 in the example above. Typically, tokens paid as fees are compensated by allocating an inflated low-cost supply, often forcing depositors to simply regroup the marginal profits earned. A little consolation to the victims of impermanence loss!
Subvert ideas
This is the core reason why pooling more than one asset together is discouraged - it adds complexity to market making. Additionally, the constant reallocation of assets based on profits makes it difficult for depositors to predict whether they will get their money back by claiming LP tokens.
However, a unique record of value can be seen when looking at AMM behavior. Check the results of our above example again:
- 316.23 A tokens for $1,581.14
- 790.57 B tokens for $1,581.14
Note that while A and B have the same value, the amount of tokens withdrawn is different. When we started we had 500 Token B, now we have 790.57. The effect of an automated market maker is that depositors trade shares of A for shares of B, and the prices of both assets rise over time. As prices diverge between them, we use our allocation to A to allocate more shares to B.
Those working with liquidity pools can apply a more sophisticated approach to profiting from CPMM-based LPs by leveraging redistribution mechanisms in an interaction I call an "LP Dive".
Advanced mobility for newcomers
The concept is fairly simple: deposit into a liquidity pool, then withdraw assets as the price deviates. Then, open long positions for assets with larger volumes.
Profitable dives arise from exploiting the phenomenon of divergence loss. The core bet is that after the divergence, the rate at which the long asset position appreciates makes the return greater than holding or depositing. Two examples are provided for common token LP setups: Compression Dive for Token-Stable pools and Twin Dive for Token-Token pools.
Example 1: Token-Stable Pool
Token-Stable Pool works like a native dollar cost averaging mechanism in either direction. This is the core of hedging - depositing Token-Stable LP allows users to perform DCA with lower returns during the up or down process, while earning some fees. This will be called a Compression Dive.
Let's take a look at this example. Assume the investor LP has:
- 500 A Tokens and 500 Stable B Tokens, each purchased for $1 (with a deposit of $1,000)
- Investors are using flexible long/short strategies
- Investors are long A and short B flexibly
Then, suppose the following happens:
- The price of Token A drops to $0.01
- Stable B price remains at $1
Since investors want to take a long position on A, they can simply withdraw their liquidity pool token K if the price depreciates. In this example, when Token A hits the $0.01 price point, the investor exits, leaving 5,000 Token A and 50 Stable B.
The result is increased depositor losses! The LP left them a total of $100, and if they had just held, they would have $505. This appears to be a very bad case for depositors of liquidity pools, as it is, and accruals cannot cover such a large loss.
In this example, the impermanent loss is calculated to be 80.2%, and if depositors do not monitor their positions, the net loss is surprisingly high! Depositors have lost so much they may be tempted to cut their deposits.
This is where we "dive" in this liquidity pool. Even if the price of the pool (withdrawable deposits) falls, the number of A will grow exponentially. Whether they know it or not, savers use their Stable B to buy more A as the price falls.
Here we have the central premise of the LP dive: redefining impermanent loss as a redistribution of tokens in the belief that they will return to their initial price. Investors do not abandon their positions in Token A, but exit their long positions. By holding this long position, investors effectively lower their breakeven price!
- Depositor owns 5,000 Token A
- Depositor has an impermanent loss of $850 ($900 loss – remaining $50 from Stable B)
- IL divided by the amount of Token A (850 / 5,000)
- Depositors break even when Token A = $0.17
This is where exponential growth happens. In this example, when Token A appreciates above $0.17, the risk-reward ratio of the long position also increases exponentially.
Now, astute observers might consider this strategy without a liquidity pool: instead of depositing $1,000, they simply use half or all of their initial $1,000 to buy 10 A of 10,000 tokens. This strategy works better without LPs as traders make the market without additional tools.
This begs the question: why use a diving strategy when micro bottoms are most profitable? The idea is that using a diving strategy allows investors to functionally use LPs as a hedging tool. Downside risk is naturally protected through the mechanism of AMMs, as timing micro-bottoms is easier said than done.
Consolidation to compress token price for yield
We can rebalance risk allocation by borrowing ideas from underlying market makers and implementing them in diving strategies. Compression, then, is exercising a flexible short position.
Divers have the option to consolidate their Stable B position by using the Stable B position to purchase Token A at the spot price after their immediate exit. On the premise of returning to the initial price, this further magnifies the profit of the diving strategy. Coincidentally, this also lowers the threshold for the price of token A to grow exponentially after the deposit breakeven point.
Summarize:
- Increase position with 5,000 A tokens using 50 Stable B
- Depositors now have 10,000 A tokens
We still assume this is an LP that does not use a centralized liquidity position
This is the most fascinating aspect of C-Dive: the final total position is $10,000 - a profit of $9,000 after the initial deposit. Using a squeeze dive strategy on a liquidity pool allows for hedging Token A positions and collecting profits similar to timed locals or micro bottoms.
Example 2: Token-Token Pool Dive
The real magic is when you start with two volatile coins. When used correctly, LPs are your favorite hedging tool right now. Use Token-Token Pool to start introducing the leveraged diving strategy, by compressing one asset with another to obtain multiplied returns.
Let's assume an investor has the same input as before:
- 500 Token A, 500 Token B - $1 each
- $1,000 initial deposit
- Investors are using flexible long/short strategies
- Investors are long A and short B flexibly
Then, suppose the following happens:
- The price of Token A drops to $0.01
- The price of token B rises to $2
Dive withdrawal summary:
- 7071.07 Token A
- 35.36 Token B
- Hold $1,005
- $141.42 if deposited into LP
In this case, the impermanence loss is calculated to be 85.93% - 5.73% higher than the IL of the Token-Stable pool! From this vantage point, divergence loss looks downright scary.
Let's evaluate the break-even point:
- 7,071.07 of Token A needs to compensate -$858.58 of initial deposit loss
- The depositor owns 35.36 Token B, or $70.72
- We want to compensate token B for quantified IL loss (i.e. in tokens) to calculate breakeven
- We subtract token B holdings from the deposit value (1,000 - 70.72)
- Divide this IL compensation value by the amount of Token A (929.28 / 7,071.07)
- Depositor breakeven when token A = ~$0.13142
Additionally, depositors can choose whether they would like to exercise short positions by buying immediately after withdrawal. We can take the value of B at withdrawal time and use it to exploit it as we did in the original compression dive method. This doubled our token holdings to 14,143.07.
As one begins to see, using a Twin Dive is a form of utilizing a Compression Dive based on B's leveraged buying power. This is the strict benefit of using the dive method over Token-Token pools. The easiest way to calculate the base leverage available for a Token-Token Double Hop strategy is to divide the leveraged token or Token B, in this case by the price of Token A.
For example:
- Token B is priced at $2 at the time of withdrawal
- Withdrawal price for Token A is $0.01
- Base leverage is 200 - or simply 2.00 times - based on total price difference
This strategy is often referred to as a liquidity "vampire". This is because liquidity is effectively taken from depositors by token volume and transferred to divers based on leverage. Generally speaking, this liquidity is simply extracted based on its MEV, which means it is an effective shorting tool.
The Positives and Negatives of LP Dive
Assuming the price forecast favors the long/short investor approach and the fee yield token has value, the Dive approach can be used to mitigate impermanent losses and increase profits for savers. Any investor can use this strategy on any LP that utilizes CPMM invariants or some of its derivatives (including StableSwap). There are additional nuances to using this approach on concentrated LP positions, and general effects vary by individual agreement.
Compared to simple buy, hold and sell, LP Dive will naturally generate exponential profits relative to the standard operations allowed by the protocol functions. Smaller depositors can make more profits this way, and it is easier to test on cheaper chains.
It's easier to think of AMMs and associated LPs as local hedging vehicles rather than vehicles for depositing to earn yield. What this tool provides as a benefit is the process of locally shorting one asset against another, all the way down to lower valuations, lowering yields, and automating long-short hedging strategies. Funds or investors using delta-based hedging strategies can view price changes as delta and LP price/volume changes as gamma.
The negative impact of this action is usually high for all other participants except divers. In the broader market context, doing this on an ongoing basis results in price compression or temporary price parity, and more tokens allocated to divers as compensation for taking risk on whatever assets they dive. That is, all spot prices move towards the lowest equilibrium value of all assets in all pools. During this time, divers can take advantage of leverage using LP as a local hedging tool, which makes the TVL in the pool less viscous, or more prone to "vampire" (MEV extraction).
For investors without diving deposits, generally speaking, the pool APR will generate a certain amount of fees in the tokens of the agreement. Although it is not the maximum profit, it takes less risk than diving. If the LP diving method is used to increase, it becomes more profitable for depositors to consolidate their capital through deep liquidity to earn fees.
Linking risk to price action between the two means that when an asset is paired with an AMM, it is less volatile. Consistent use of dive strategies, especially leveraged C or T dives, can further reduce the volatility that makes leveraged dives less effective.
in conclusion
The assumption that liquidity mining is unprofitable is correct - divers take on long/short risk and make more money than depositors in the short term. Current LPs using CPMM-based invariants run the risk of divers exploiting these soft holes, a by-product of the mechanism used by invariants. On the other hand, this opens up new areas of implementation and research for AMMs and LPs, especially related to automated DEXs. By gathering knowledge about these concepts, on-chain liquidity can be deepened in these protocols, and more robust functionality can be developed around liquidity pools.