
Written by: Ricky Li, Siddharth Lalwani, Hongxu Yan at Altonomy Ventures
secondary title
Pricing Models and Invariants
People participating in the automatic market maker mechanism include two different roles: liquidity providers (LP) and traders. Liquidity providers deposit funds into the pool, and traders exchange one currency from the pool for another token. The first problem that the AMM protocol needs to solve is how to set the price. Take a two-currency pool as an example, that is, how to use the quantity of token 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 Δ2 quantity t2 to buy Δ1 quantity t1 in a transaction. We can use a transaction function ψ to describe an AMM protocol, which must satisfy the function value before and after the transaction. The invariant is expressed as:
According to this equation, we can deduce Δ2 from Δ1 (or vice versa). And this transaction will also affect the price at the same time, 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 smart pool and the price of the external reference market, arbitrageurs will continue to trade until the price difference returns. AMM uses this mechanism to correct the transaction price in the pool. The average price per transaction is defined as:
image description
Table 1 Marginal Price
Uniswap V3
The transaction function of Uniswap 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,
In the new version V3, since the liquidity density in different price ranges is different, it needs to be calculated separately for each small area with the same liquidity density. When the interval boundary is crossed, similar calculations are required for the next interval.
Balancer V2
Balancer's transaction function 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 weight ω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 tokens. When there are more than two types of tokens, its transaction function is expanded to:
Other derivation steps can be similarly extended to multi-coin situations, 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:
secondary title
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 change of marginal price before and after a single transaction. Comparing the price impact of the three protocols, we can draw the following conclusions: Assuming the same amount of tokens 1 are traded, the Balancer pool with a higher ω1 is set to have a greater price impact. If ω1>1/2, then the price impact is greater than The effect of the same transaction in the Uniswap pool and vice versa. And near the equilibrium point (that is, the price deviation is not severe) 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, the initial price is 1.5
A Curve V2 pool, α=1, β=3, initial price is 1
image description
Figure 1 Price Impact Curve
Obviously, for token 1 with the same amount Δ1 traded, the order of impact on price is as follows: Balancer V2 w1=0.6 > Uniswap V3 > Balancer V2 w1=0.4 > Curve V2.
image description
impermanent loss
Table 2 impermanence loss
For Uniswap V3, the liquidity from a single provider is placed in a closed range. When the price of a token drops, LP’s risk exposure to that token gradually increases until the price Come to the interval boundary. At this time, the LP only has risk exposure to this token, and 0 exposure to another token. If the price continues to move in the same direction, the exposure remains unchanged.
image description
Figure 2 The impact of the relative price change of the Balancer pool under different weight configurations on the impermanent loss
secondary title
Withdrawal and deposit
image description
Table 3 Withdrawal and deposit
The specific calculation method is as follows:
The specific calculation method is as follows:
When withdrawing funds, the principal withdrawal amount of the two tokens can be calculated similarly. The portion of the commission that has been earned is charged and withdrawn in the token type at the time of the transaction.
For Balancer V2, LP always needs to provide all types of tokens in the pool when depositing money, and its matching ratio determines the weight setting of the pool
For Curve, when depositing, LPs can deposit tokens in any proportion, or only deposit a single type of token. However, if the deposit ratio does not match the total token ratio in the current pool, 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:
liquidity aggregation
liquidity aggregation
image description
Table 4 Liquidity Aggregation Methods
Uniswap V3 allows each LP to set an arbitrary liquidity range, in order to expect the overall liquidity to gather in the most active range. However, in theory, liquidity can be shaped into an arbitrary distribution according to the autonomous decision of each LP.
image description
Figure 3 Liquidity Distribution Uniswap V2
This means that if all LPs set the liquidity range to the maximum possible range, then the Uniswap V3 pool will be equivalent to V2.
image description
Figure 4 Liquidity Distribution Curve
However, the above figure is only an approximation of Curve V3, which is actually more complex. As market conditions change and the most active price range deviates too much from the original balance point, Curve V3 will readjust the balance point and price curve according to the built-in Oracle.
image description
Figure 5 Liquidity Distribution Balancer V2
image description
image description
transaction fee
Table 5 Transaction Fees
Uniswap V3
Each trading pair has three fee gradient pools for LP to choose from: 0.05%, 0.3%, and 1%. Intuitively, LPs are more inclined to high-fee pools, but when the transaction activity of high-fee pools is much lower than that of low-fee pools, LPs have to participate in low-fee pools. Traders prefer low-fee pools, but when the liquidity of low-fee pools is too thin and the slippage is too high, traders are forced to trade from high-fee pools.
According to actual observation, for stablecoin trading pairs, the pool with 0.05% fee is the most active. For other trading pairs, high-fee pools become more active when market volatility is high, and low-fee pools become more active when volatility is low.
Balancer V2
The Balancer protocol charges two fees: (1) transaction fee, which is charged to the trader as a certain percentage of the transaction amount (2) withdrawal fee, which is 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 protocol according to multiple factors. Factors include: volatility, transaction volume, impermanent loss, total liquidity, liquidity Sexual mining rewards, etc.
Withdrawal fees can be set by the protocol, but have not been adopted so far.
Curve V2
in conclusion
in conclusion
Through various comparisons, it can be seen that each protocol 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 did not add more auxiliary features to keep the protocol simple. LPs, on the other hand, need to manage their own risks.
Curve has historically focused on stablecoin trading pairs, and this new version, V2, aims to expand the variety of coins covered. Unlike stablecoins, the market mid-price of non-stablecoin trading pairs may shift to a new active range, so this protocol can adjust the liquidity aggregation range according to 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 types of tokens in the same liquidity pool, and gives them different weights, which meets the needs of some LPs to treat different types of token risk exposures differently. By increasing the risk volatility on one side, the risk on the other side is reduced.
Citation
[1] G. Angeris, A. Evans, T. Chitra; When does the tail wag the dog? Curvature and market making, 2020.
[2] Hayden Adams, Noah Zinsmeister, Moody Salem, River Keefer, and Dan Robinson. Uniswap v3 Core. (2021).
[3] Michael Egorov, Curve Finance (Swiss Stake GmbH). Automatic market-making with dynamic peg (2021)
[4] Fernando Martinelli, Nikolai Mushegian. Balancer Whitepaper (2019)