简体   繁体   中英

How to calculate Deposit Amounts for Adding Liquidity within Uniswap V3

为 Uniswap V3 增加流动性

Whilst adding liquidity to a new pool within Uniswap V3, I am trying to calculate the formula for the 'Deposit Amounts' on any given pair.

For example, let's take the pair ETH/USDC

Current Price: 2172.05 Set price Rangle -20% & +20%

Min Price: 1747.7 Max Price: 2612.4

ETH: 0.394064 ($854.888) USDC: 1000 ($1000)

How is the ETH dollar amount calculated and what is the formula? ( How did Uniswap get ETH to $854.888??? )

ps: I have looked at the Uniswap V3 white paper https://uniswap.org/whitepaper-v3.pdf but need a step by step layman explanation. Cheers!

Additional

I have been reading the following article and the answer lies within the formulas below: uniswap-deep-dive-into-v3-technical-white-paper Source: uniswap-deep-dive-into-v3-technical-white-paper

This question might be a bit off-topic for SO, but I believe it will be useful for people anyway. Here is my answer...

Uniswap gave you the USD value of ETH amount you entered, just for convenience, using an oracle price. It's not a parameter of this deposit operation.

There are only 3 parameters here:

  • Asset A amount
  • Asset B amount
  • Price range

Asset A (ETH in your instance) ratio to Asset B (USDC in your instance) determines the equilibrium point. For example, if you deposit 1 Ether and 1000 USDC, then the equilibrium point will be ETH = 1000 USDC . Lastly, you define a price range to specify the range you want your deposit to be functional. By limiting the price range of your deposit, you increase the efficiency of the capital (deposit) in a given range. This involves quite a bit of math to explain but let me try to explain in a nutshell: Basically, automated market makers work on this equation: a * b = k . This implies when a goes to infinity b goes to zero and vice-versa. Because of this 'liquidity' is distributed over 0 to infinity, uniformly. When you put price ranges instead, you 'concentrate' liquidity inside the range, at expense of outside-range liquidity. Thus you increase the efficiency of capital.

计算证明

The complete solution has been added to an excel sheet at:

Uniswap Add Liquidity Token Calculations

Whilst adding liquidity to a new pool within Uniswap V3, I am trying to calculate the formula for the 'Deposit Amounts' on any given pair.

Adding liquidity to a pool has no effect on the price. This is the constraint to adding liquidity. Let's say we have A and B token, their amounts are x and y, respectively. since we want to add liquidity, we add "dx" and "dy". These "dx" and "dy" amounts cannot effect on the price. Otherwise for any adding liquidity would have price impact on the pool

Calculate dy given dx

If you want add "dx" amount of A token to the pool, how do we calculate "dy" amount of B token. Before adding liquidity, we assume we had "x" and "y" amounts so the price of x in terms of y is

x / y

Since adding liquidity will have no impact on the price, after adding liquidity, the price should be equal to x/y

x / y = (x+dx) / (y+dy)

then

xy + xdy = xy + ydx   // xy cancels out
x * dy = y * dx

we are looking for "dy"

dy = (y * dx) / x
 

Similary you can calculate the "dx" given "dy"

From this equation

x * dy = y * dx

we can also get this

dx / dy = x / y

the ratio of the deposit amount should be equal to the ratio of the token amounts before the adding liquidity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM