An in-depth discussion of Uniswap’s constant formula

Uniswap V2 is the most popular and successful DEX.

Price the paired assets through the curve, and the result becomes this:

An in-depth discussion of Uniswap's constant formula

Where x and y are the balances of assets in the fund pool.

Given Δx, in order to exchange Δx for Δy, Uniswap V2 will perform the following calculations:

An in-depth discussion of Uniswap's constant formula

In this way, the invariant xy=k is still satisfied after the exchange, and the price is:

An in-depth discussion of Uniswap's constant formula

A major feature of Uniswap V2 is that no permission is required. Anyone can create a trading pair of two assets by providing tokens.

For example, by providing x = 1 ETH and y = 3000 USDT in the fund pool , the liquidity provider can create a trading pair, and ETH is initially priced at 3000 USDT/ETH.

Although Uniswap V2 has been widely adopted, the key problem of Uniswap V2 is its low capital efficiency, because the liquidity is distributed on the price [0, +∞].

This means that if the prices of two assets are concentrated in a relatively small range (such as stable currency swaps), most of the assets in the fund pool do not effectively contribute to the swap, resulting in higher Slippage and LP charge lower fees.

Concentrated liquidity of Uniswap V3

Uniswap V3 solves the problem of capital inefficiency by using a technique called concentrated liquidity, which uses the following curve:

An in-depth discussion of Uniswap's constant formula

The actual price of the transaction is in [p_a, p_b], p_a <p_b.

By setting p_a = 0 and p_b = +∞, V2 is essentially a special case of V3.

When providing liquidity, Uniswap V3 will ask LP for the price range of liquidity (see the figure below).

An in-depth discussion of Uniswap's constant formula

This allows LPs to focus their liquidity within the target price range, thereby achieving higher capital efficiency.

Taking stable currency trading ( USDC /USDT) as an example, from the figure below, 95% of the liquidity is concentrated in the price range [0.999, 1.001], achieving a capital efficiency about 2000 times that of Uniswap V2.

Due to the concentration of liquidity, the slippage of trading USDC/USDT is much lower than V2. Therefore, LP can charge more than V2 for the same amount of assets provided in the liquidity pool.

An in-depth discussion of Uniswap's constant formula

Due to the characteristics of concentrated liquidity, Uniswap V3’s TVL is progressing very smoothly, reaching 2.5 billion in about 3 months.

An in-depth discussion of Uniswap's constant formula

Concentrated liquidity of multiple pooled assets

Uniswap V3 is only a concentrated liquidity of paired assets. A natural question is:

  • What is the concentrated liquidity of multiple assets in the fund pool?

By concentrating liquidity for multiple assets, we can achieve higher capital efficiency because assets can share liquidity in the pool of funds. In contrast, in V3, due to insufficient liquidity of direct transactions, transactions may be routed to multiple trading pairs. For example, an exchange TUSD -> BUSD may be routed to TUSD -> USDT -> BUSD, which means that the trader will pay more fees and the higher the slippage.

So the core question is:

  • What should the aggregate liquidity curve of multiple assets look like?

Unfortunately, the answer is not simple, it is even more complicated. Let’s start with stablecoin transactions that benefit the most from centralized liquidity.

Assuming that the prices of two stablecoins are between [p, 1/p] (for example, p = 0.999), we can simplify the V3 curve to:

An in-depth discussion of Uniswap's constant formula

Where [p, 1/p] = [p_a, p_b].

The advantage of the simplified curve is that it is a bit symmetrical. The intuitive extension is to add a third term to another stablecoin to get the following equation:

An in-depth discussion of Uniswap's constant formula

Please note the slight changes between the 3 asset equations and the 2 asset equations:

  • On the right hand side is L³ instead of L²
  • Instead of using the square root of p on the left, we use the cube root of p.

Given this equation, we have a key result:

An in-depth discussion of Uniswap's constant formula

example

Balanced Pool

  • 3 stablecoins with 6 decimal places
  • x, y, z = [1000,000e6, 1000,000e6, 1000,000e6], that is, there is 1M in each fund pool
  • p = 0.999, that is, the price range is [0.999, 1.001]

Since these three terms are the same, we have:

L = x / (1 — ∛0.999) = 2998.99977x

Note that compared to the xy = k curve, where L = x, our capital efficiency is about 2000 times.

Exchange 10,000e6 (ie 10k USD) T0 for T1 will return 9999.96e6 T1 @ 0.999996 T0/T1. As a comparison, the xy=k curve will return 9375e6 T1 @ 0.9375 T0/T1, which has a much higher slippage.

Extremely unbalanced fund pool

  • 3 stablecoins with 6 decimal places
  • x, y, z = [0, 0, 1000,000e6], that is, there are 1M in each asset pool
  • p = 0.999, that is, the price range is [0.999, 1.001]

Since there is only one asset T2 in the fund pool, we expect the price of T2 to be close to the price limit, which is 0.999, or equivalently, the price of the remaining assets (T0/T1) and the price of T2 should be 1.001.

According to the curve, we can solve for L = 999.333z. Therefore, swapping 10,000e6 T0 for T2 will return 10009.90e6 T2 @ 1.00099 T0/T2, which is almost the same as the price limit (1/0.999).

Current state

We are implementing exchange algorithms for stablecoin transactions:

  • High-resolution fixed-point solver • n = 3 assets (but can be extended to more)
  • Adjustable price range [p, 1/p]
  • Uniswap V2 style interface (forge/destroy/exchange)
  • Gas cost optimization

Once the implementation of the algorithm is well verified, we will use it as a candidate for the next version of Smoothy.finance (SMTY).

Future topics

In the field of centralized liquidity of pooled assets, several interesting topics can be further developed:

More assets {x_0, x_1,…,x_n}, where the curve is as follows:

An in-depth discussion of Uniswap's constant formula

Multiple price ranges. For example, suppose we have p_0 <p_1 (for example, p_0 = 0.99, p_1 = 0.999), and LP can choose one of its liquidity price ranges.

Therefore, the algorithm will jointly solve the following equations for exchange.

An in-depth discussion of Uniswap's constant formula

For different price ranges of different assets, the equation is as follows:

An in-depth discussion of Uniswap's constant formula

Summarize

Centralized liquidity is one of the most popular topics in DEX, and has the following benefits:

  • Higher capital efficiency
  • Reduce slippage
  • More cost

Uniswap V3 is the first DEX to provide centralized liquidity for matching assets. For stable currency transactions, the capital efficiency can reach 2000 times.

We propose to centralize liquidity for multi-pool assets:

  • Share liquidity among multiple assets.
  • Very suitable for stable currency transactions.
  • It can become a competitive product in the same backing asset swap market (relative to the curve).
  • Robust smart contract implementation.

 

Posted by:CoinYuppie,Reprinted with attribution to:https://coinyuppie.com/an-in-depth-discussion-of-uniswaps-constant-formula/
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)
Donate Buy me a coffee Buy me a coffee
Previous 2021-08-31 14:10
Next 2021-08-31 14:14

Related articles