Ultimate magazine theme for WordPress.

Concentrated liquidity and security issues | by ChainLight | ChainLight BLOG

The DeFi ecosystem has consistently made efforts to create an efficient exchange where both makers and takers can share profits in smart contracts. While the order book model widely used in traditional financial markets could easily solve this problem, it was not easy to adopt due to the unique properties of the blockchain. With order book exchanges, when a maker sets the price and amount, takers can execute the final transaction as many times as they like. The order book model, which requires manufacturers to place and cancel orders tens to hundreds of times per second, is difficult to implement on a blockchain with long block generation times.

Automated Market Maker (AMM) simplified the maker’s actions. If the manufacturer provides multiple tokens to a single liquidity pool, the current value and exchange rate of the tokens are automatically calculated based on the current account balance. Buyers can complete the transaction at the current exchange rate without interacting with the manufacturer. When comparing the order book and AMM, the following can be observed:

The AMM method has two major disadvantages: slippage and impermanent loss (IL). For most AMMs, the expected value and exchange ratio will change automatically based on the remaining amount of reserve tokens. Therefore, if a taker makes a large trade at once, the exchange ratio will be less favorable than initially expected, resulting in losses. This is referred to as increased slip.

A temporary loss arises because the makers, without separate orders, take actions that oppose the takers. After the makers provide liquidity to the pool, the composition ratio of the tokens fluctuates depending on the orders from the takers. As a result, they end up owning a larger portion of the asset that is going down in price and a smaller portion of the asset that is going up in price. Therefore, they are more vulnerable to price fluctuations than if they had not provided liquidity.

AMMs are categorized based on their invariant formula. We will first discuss the simple ones.

Constant Sum Market Maker (CSMM)

CSMM maintains a constant sum of token amounts. This can be expressed as “x + y = k”. The exchange ratio of the two tokens remains the same; Therefore, if price equilibrium is not maintained, one of the assets will eventually be lost.

Constant Product Market Maker (CPMM)

CPMM maintains a constant product of token sets. This can be expressed as “x * y = k”. As the quantity of a page decreases, the relative value increases rapidly and the price diverges to infinity. Although it was widely used in early AMMs because takers could always obtain a rational two-way exchange ratio, it carries the risks of slippage and IL mentioned above.

Stable swap from Curve Finance

CPMM is simple and powerful, but has the disadvantage of wasting liquidity in order to ensure that the exchange can take place until the asset exchange ratio becomes infinity. This is evident when exchanging stable coins aimed at maintaining a specific value.

There are several trade-offs to solve this problem and one of them is shown by Curve Finance’s stable swap. If the difference in the amount of assets is not large, it works closer to the CSMM to minimize slippage; If there’s a big price difference, they’ll switch to something similar to CPMM to avoid an outflow of assets.

Uniswap V3

Concentrated liquidity is a liquidity supply method that concentrates liquidity in a specific price range. It was introduced by Uniswap Labs two years ago. When providing liquidity, you can set the price range. However, you will only receive fees for swaps that take place within this price range.

Chart of the CPMM divided into ticks

With CPMM, the liquidity provided by the manufacturer influences the current price, regardless of the relationship between the two assets. However, since liquidity is only provided within a certain price range, the size of the available liquidity varies for each of the fixed intervals that the price range is divided into, also called ticks. Makers focus their liquidity on the areas where it is expected that there will be many transactions from takers mainly near the current price in order to receive the fees generated by trading in that area. This benefits takers trading at the current price, as slippage is less likely to occur in areas with ample liquidity.

Uniswap V3, Trident Concentrated Liquidity Pool and other platforms have implemented concentrated liquidity.

Uniswap info

The image above shows that liquidity for the DAI and USDC stablecoins is almost entirely concentrated around the exchange rate of 1.

Uniswap info

In the case of USDC-ETH, liquidity is much more evenly distributed, although most of the liquidity supply is distributed around the current price.

An alternative to the central provision of liquidity mentioned above is just-in-time liquidity (JIT).

Just-In-Time (JIT) Liquidity.

Just-in-time (JIT) liquidity is one of the strategies to increase miner extractable value (MEV) and achieve maximum profit efficiency. This can result in the cost of price manipulation increasing through the efficient provision of liquidity.

“JIT liquidity is equal to miner extractable value (MEV), where MEV is the maximum profit a miner can make by looking ahead and rearranging transactions.”

JIT liquidity is a strategy in which liquidity is provided just before orders are accepted and withdrawn immediately thereafter. Liquidity is provided within a very small price range. In general, existing LPs provide liquidity over a wide range based on the current price. So if we only consider the price at which the current transaction is taking place, they provided relatively little liquidity in the price interval. Therefore, JIT liquidity providers have a large share of the fees generated by the taker orders targeted by the attack.

Unlike most MEV-based front-running attacks that harm users making the target transaction, JIT liquidity does not harm the takers and can even benefit them. This is because takers can trade with more liquidity than expected, reducing slippage. However, existing LPs will see a drop in revenue as some of the expected fees are reallocated to JIT LPs.

In cases like Uniswap V3, where liquidity is provided around the current market price, takers can benefit from reduced slippage. But what are the benefits of LPs?

First, LPs can provide maximum liquidity with the same amount of funds, thus reducing wastage of liquidity. The more liquidity provided, the greater the proportion of transaction fees, resulting in higher revenue. This drives competition for the optimal range of liquidity supplies. Another advantage is that the liquidity provision allows the use of limit orders in AMMs.

For example, if a route from Seoul to Austin has high passenger demand, airlines increase the number of flights on that route. The airlines serving the high-demand route will benefit and generate more revenue as they gain a larger market share.

The disadvantage of implementing concentrated liquidity is that manufacturers suffer more losses due to the impermanent loss (IL). If the current price goes beyond the range where liquidity is provided, LPs only hold assets from the side of the token that have fallen in value. This means that LPs suffer the effects of IL more quickly compared to CPMM. By setting a tight price range, LPs are subject to greater token price volatility.

CPMM liquidity range

If the liquidity supply spread does not include the current price, the liquidity provider’s assets for the spread consist of only one token. In this case, providing liquidity in a very short range with minimal price range will result in the assets fully converting to the other token when crossing this range. Unlike limit orders on centralized exchanges, the assets naturally convert back to the original token when the price recovers, requiring liquidity providers to withdraw liquidity after the liquidity has been converted to the desired token.

This opportunity demonstrates the advantage of AMMs while also allowing traditional financial products to be ported to the DeFi world.

Can we defend ourselves effectively against price manipulation?

When price manipulation occurs in an AMM, the on-chain price oracles that depend on it can return incorrect values. This can cause problems for DApps that rely on this value and lead to cascading errors. Common ways to minimize this risk include using the Time Weighted Average Price (TWAP) or external oracles like Chainlink.

However, assuming the same Total Value Locked (TVL), CPMM-based exchanges with concentrated liquidity are more vulnerable to price manipulation attacks than those without.

When liquidity is concentrated around the current price, market manipulation requires greater funds to execute

However, once the concentrated liquidity dries up, the exchange moves into a less liquid zone where greater price manipulation is possible with fewer funds, impacting the usefulness of TWAP. This can be more pronounced in low TVL liquidity pools, and a well-funded attacker can exploit the vulnerability of concentrated liquidity to generate large profits through price manipulation.

Many market makers choose to provide liquidity around the current price to reap the benefits of concentrated liquidity. Therefore, liquidity pool builders must defend against liquidity leaks in the outer regions by providing a certain amount of liquidity across the region.

Learn Crypto Trading, Yield Farms, Income strategies and more at CrytoAnswers
https://nov.link/cryptoanswers

Comments are closed.

%d bloggers like this: