# Multi-dimensional analysis of head AMM: Uniswap V3, Curve V2 and Balancer V2

Written by: Ricky Li, Siddharth Lalwani, Hongxu Yan, working at Altonomy Ventures

The Automatic Market Maker Mechanism (AMM), with its advantage of occupying a constant level of time and space, has been adopted by many decentralized exchanges (DEX). So far, many such projects have achieved great success. Speaking of the best among them, we must mention Uniswap, Balancer and Curve, all of which have recently launched new versions to address various issues and risks that liquidity providers are concerned about. This article will compare the latest versions of these three protocols from many aspects.

## Pricing models and invariants

The people participating in the automatic market maker mechanism include two different roles: liquidity provider (LP) and trader. Liquidity providers deposit funds into the machine gun pool, and traders exchange one currency for another token from the pool. The first problem that the AMM protocol needs to solve is how to price. Take a two-currency pool as an example, that is, how to use the number of tokens 2 (t2) to represent the price of token 1 (t1).

Assuming that the quantities of two currencies in the pool are R1 and R2, respectively, a trader wants to use t2 of Δ2 to buy t1 of Δ1 in a transaction. We can use a transaction function ψ to describe an AMM protocol, which must satisfy that the value of the function does not change before and after the transaction. The invariant is expressed as:

According to this equation, we can deduce Δ2 from Δ1 (or vice versa). This transaction also affects the price, because the total amount of tokens in the pool changes after the transaction. In fact, because there is a gap between the transaction price of the machine gun pool and the price of the external reference market, arbitrageurs will continue to trade until the spread returns. AMM uses this mechanism to correct the transaction price in the pool. The average price of each transaction is defined as:

When dΔ1->0, we can calculate the marginal price. The marginal prices of the three agreements are summarized in the following table

Table 1 Marginal price

### Uniswap V3

Uniswap’s trading functions are defined as follows:

From this, the invariant can be obtained as:

The expression of Δ2 is derived as:

The marginal price is:

When Δ1->0,

In the new version V3, due to the different liquidity densities in different price ranges, it is necessary to calculate separately for each cell with the same liquidity density. When the interval boundary is crossed, the next interval required is similarly calculated.

### Balancer V2

The trading function of Balancer is defined as follows:

From this, the invariant can be obtained as:

The expression of Δ2 is derived as:

The marginal price is:

When Δ1->0,

The weights ω1 and ω2 also represent the proportion of the total market value of the two tokens. If ω1=ω2=1/2 is specified, then the pool is equivalent to the Uniswap pool.
In particular, Balancer allows a mixed pool of up to 8 types of tokens. When there are more than two types of tokens, the transaction function is expanded to:

Other derivation steps can be similarly extended to the multi-currency situation, and the derivation steps are skipped here.

### Curve V2

The transaction function of the Curve protocol is a linear combination of a constant sum function and a constant product function:

Similarly, we can deduce the marginal price, when Δ1->0,

## Price impact and slippage

According to the marginal price formula obtained in the previous step, we can define the price impact of this transaction by comparing the changes in the marginal price before and after a single transaction. Comparing the price effects of the three protocols, we can draw the following conclusion: assuming that the same number of tokens are traded 1, the Balancer pool with the higher ω1 is set, the greater the price impact will be. If ω1>1/2, the price impact will be greater than The impact of the same transaction in the Uniswap pool, and vice versa. And near the equilibrium point (that is, the price deviation is not serious) Curve V2 has the least price impact.

In the following example, we compare the impact of a single transaction price in four different pools, assuming that the total amount of tokens in the initial pool is R1=R2=10000:

• A Uniswap V3 pool with an initial price of 1
• A Balancer V2 pool, ω1=0.4, ω2=0.6, the initial price is 0.666
• A Balancer V2 pool, ω1=0.6, ω2=0.4, and the initial price is 1.5
• A Curve V2 pool, α=1, β=3, and the initial price is 1

The price impact curves of the four pools are shown in the figure below:

Figure 1 Price influence curve

Obviously, for the same number of Δ1 tokens 1, the order of the impact on the price is as follows: Balancer V2 w1=0.6> Uniswap V3> Balancer V2 w1=0.4> Curve V2.

For Curve, because it has the smallest price impact within a certain range, it is most suitable for stable currency trading pairs. Based on the experience of previous AMM agreements, the shape of the price influence curve is often related to the returns of liquidity providers. As shown in the figure above, because Curve’s price impact curve is the flattest, resulting in lower slippage, so that traders will trade more frequently (or a lot more) in this range, and eventually liquidity providers will earn more Transaction Fees.

## Impermanence loss

Table 2 impermanence loss

For Uniswap V3, the liquidity from a single provider is placed in a closed interval. When the price of a token drops, the LP’s risk exposure to the token gradually increases until the price Come to the boundary of the interval. At this time, the LP only has risk exposure to this token, and its exposure to another token is 0. If the price continues to move in the same direction, the exposure remains unchanged.

For Balancer V2 and Curve V2, liquidity is provided for the entire price range, so the exposure will gradually change throughout the range and will not reach the maximum/minimum value.

Figure 2 The impact of relative price changes of the Balancer pool under different weight configurations on impermanence losses

For the Balancer protocol, the smaller the weight ω1 of token 1, the smaller the impermanence loss under the same price fluctuation. This is intuitive because the amount of token 1 held by LP becomes smaller.

## Withdrawal and deposit

For liquidity providers who want to participate in these three agreements, they do not have absolute advantages and disadvantages in terms of the rules of withdrawal and deposit, but according to personal asset class and risk preference, each agreement is more suitable Situation:

Table 3 Withdrawal and Deposit

For Uniswap V3, the ratio of the two tokens deposited when depositing is determined by two factors (1) the two boundaries of the interval (2) the current transaction price. Simply put, if the current transaction price is equal to the geometric mean of the two boundary prices, LP needs to deposit two tokens equal to 50:50. If the current price is more to one side, then the cheaper token will occupy a higher proportion of the tokens that LP needs to deposit. If the current price is outside the range, LP only needs to provide a cheaper token.

The specific calculation method is as follows:

When withdrawing gold, the principal withdrawal amount of the two tokens can be calculated similarly. The portion of the earned handling fee is collected and withdrawn in the type of token at the time of the transaction.
For Balancer V2, LP always needs to provide all types of tokens in the pool when depositing funds, and the ratio determines the weight setting of the pool

For Curve, when depositing gold, LP can deposit tokens in any proportion, or deposit only a single type of token. However, if the deposit ratio does not match the total token ratio in the current pool, the LP will suffer a certain degree of loss (or reward). Because when LP acquires LP tokens, the amount obtained is calculated by the following formula:

Where D is the total amount of tokens in the pool at the equilibrium point, its value is D0 before liquidity increases, and its value becomes D1 after liquidity increases. However, (assuming the same amount of tokens are invested) when the proportion of tokens in the pool is farther from the balance point, the value of D will be relatively smaller, resulting in a smaller amount of LP tokens obtained by LP, which means a loss. On the contrary, if the invested tokens make the proportion of tokens in the pool tend to return to the equilibrium point, then LP will get more LP tokens, that is, get rewards.

## Liquidity aggregation

In terms of liquidity aggregation, Uniswap V3 gives LPs the greatest degree of flexibility. LPs can aggregate any form of liquidity distribution curve according to their own wishes. In contrast, Balancer and Curve replace this flexibility with more fixed parameter settings.

Table 4 Liquidity aggregation method

Uniswap V3 allows each LP to set an arbitrary range of liquidity, hoping that the overall liquidity will be concentrated in a most active range. However, in theory, according to the autonomous decision of each LP, liquidity can be shaped into an arbitrary distribution.

For example, a liquidity distribution equivalent to Uniswap V2 is shown in the figure below:

Figure 3 Liquidity distribution Uniswap V2

This means that if all LPs set the liquidity interval to the maximum possible interval, then the Uniswap V3 pool will be equivalent to V2.

The following is a liquidity distribution similar to Curve. All liquidity is concentrated in a small area near the equilibrium point.

Figure 4 Liquidity Distribution Curve

However, the above figure is only an approximation of Curve V3, which is actually more complicated. As market conditions change, when the most active price range deviates too much from the original balance point, Curve V3 will re-adjust the balance point and price curve according to the built-in Orcale.

The following is a liquidity distribution equivalent to Balancer V2, which is clustered on the lower side of the more weighted tokens

Figure 5 Liquidity distribution Balancer V2

However, none of the above are actually observed common liquidity distributions in Uniswap V3 pools, and the common distributions are more similar to the following:

Figure 6 Actually observed liquidity distribution Uniswap V3

## transaction fee

Table 5 Transaction fees

### Uniswap V3

For each trading pair, there are three fee gradient pools for LP to choose: 0.05%, 0.3%, and 1%. Intuitively, LP is more inclined to the high-fee pool, but when the transaction activity of the high-fee pool is much lower than that of the low-fee pool, LP has to participate in the low-fee pool. Traders prefer low-fee pools, but when the liquidity of low-fee pools is too thin and the slippage is too high, traders will be forced to trade from high-fee pools.

According to actual observations, for stablecoin trading pairs, the 0.05% fee pool is the most active. For other trading pairs, when the market volatility is high, the high-fee pool becomes more active, and when the volatility is low, the low-fee pool becomes more active.

### Balancer V2

The Balancer agreement charges two types of fees: (1) Transaction fees, which are charged to traders as a certain percentage of the transaction amount (2) Withdrawal fees, which are charged according to the withdrawal amount when LP withdraws from the agreement

The transaction fee can be set between 0.05% and 1%. The initial value is set by the pool creator and dynamically adjusted by the agreement according to multiple factors. The factors include: volatility, transaction volume, impermanence loss, total liquidity, and liquidity Sexual mining rewards, etc.

The withdrawal fee can be set by agreement, but it has not been adopted so far.

### Curve V2

The fee can be set between 0.04% and 0.4%, and it can be dynamically adjusted according to the current token ratio in the pool. The farther the current ratio is from the balance point, the lower the fee rate:

## in conclusion

Through various comparisons, it can be seen that each agreement adopts different methods to meet the various needs of LPs and traders.

Uniswap V3 gives LP the greatest flexibility. Almost all parameters can be determined by LP independently, and the team has not added more auxiliary features to keep the protocol simple. The LP needs to manage its own risks.

Curve has historically focused on stable currency trading pairs, and this new version V2 is dedicated to expanding the types of tokens covered. Unlike stablecoins, the mid-market price of non-stablecoin trading pairs may shift to a new active range, so this protocol can adjust the liquidity concentration range based on the price feed of the built-in Oracle, without the need for LPs to redeploy the liquidity range themselves. This design is more friendly to individual investors, but limits the possibility of developing more complex customized market-making strategies.

Balancer V2 accommodates more than two tokens in the same liquidity pool and assigns different weights, which meets the needs of some LPs to treat different token risk exposures differently. By increasing the risk of one side, the risk on the other side is reduced.

Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Like (0)
Previous 2021-07-16 11:24
Next 2021-07-16 11:40

2021-12-20

2021-08-28

2021-06-03

2021-07-09

2021-09-23

2021-06-24