0

I know how to get balances of each token from a pair, and if I'm not mistaken - those balances of tokens is indeed a real reserves. Also, L is stored in contract info, but I doubt one thing - this L is just an L or L^2 or a srqt(L). From sqrtRatioX96 price can be founded.

Found, that (x(real) + L / sqrt(Pb))*(y(real) + L * sqrt(Pa)) = L**2

As well as

(x(real) + x(virtual)) * (y(real) + y(virtual)) = L**2

So x(virtual) = L / sqrt(Pb) y(virtual) = L * sqrt(Pa) But what (Pa) & (Pb) is exactly? P(a) is a token0Price & (Pb) is a token1Price? Or (Pa) & (Pb) is a high & low price of this tick/ concentration zone. I have thoughts that (Pa) & (Pb) is a "price range" of current tick/position, but no clue how to find this (Pa) & (Pb). If Pa = token0Price (from sqrtRatioX96) & If Pb = token1Price (from sqrtRatioX96) I've got: x(virtual) = L / sqrt(token0Price) x(virtual) = 776218541774739337116335 / sqrt(0.0008191556417896165) x(virtual) = 776218541774739337116335 / 0.02862089519 x(virtual) = 2.7120694046143822e+25 x(virtual) = 27120694046143822000000000 (18 decimal)

y(virtual) = L * sqrt(P) y(virtual) = 776218541774739337116335 * sqrt(1220.7692274636495) y(virtual) = 776218541774739337116335 * 34.9395081171 y(virtual) = 2.7120694040982028e+25 y(virtual) = 27120694040982028000000000 (18 decimal)

x(virtual) (token0Price) = 27120694046143822000000000 = 27120694.046143822 y(virtual) (token1Price) = 27120694040982028000000000

Yeah, look's pretty 50/50, but what exactly those numbers is? That's a DAI/WETH pair (0,5 fee) and if that's a "USD valued" reserves - not possible, because real reserves of DAI at that moment was 2591437.269710515203595384 & 2838.497576725882781612 of WETH.

Is there anything that i missed?

Chenky
  • 11
  • 4

2 Answers2

1

From https://uniswap.org/whitepaper-v3.pdf

(x(real) + L / sqrt(Pb))*(y(real) + L * sqrt(Pa)) = L**2:
x_virtual = L / sqrt(Pb) & y_virtual = L * sqrt(Pa)

At the momment L = 629666507025852065455329 DAI Reserves (balanceOf) 1319679676310680369741279 WETH Reserves (balanceOf) 3660663192506322781740

x_virtual =(629666507025852065455329/sqrt(1128.50448824)) x_virtual = (629666507025852065455329/33.5932208673) x_virtual = 1.8743856372485445e+22 x_virtual = 18743856372485445000000 x_virtual = 18743.856372485445

y_virtual = 629666507025852065455329 * sqrt(0.0008861285)) y_virtual = (629666507025852065455329 * 0.02976791057) y_virtual = 1.8743856270069843e+22 y_virtual = 18743856270069843000000 y_virtual = 18743.856270069843

x_virtual = 18743856372485445000000 y_virtual = 18743856270069843000000

0x60594a405d53811d3BC4766596EFD80fd545A270 - just in case you need to see which pair I'm using

That's right?

Chenky
  • 11
  • 4
0

First of all, your second formula is not correct, meaning that the rest of the computation is probably wrong, too. P_a is the low price of the tick range (or of the position, depending on the context). P_b is the high price of the range (position).

If you have a tick range from tick_A to tick_B then:

P_a = 1.0001 ^ tick_A
P_b = 1.0001 ^ tick_B

Then once you know the P_a and P_b, you can compute the virtual amount of assets using Equation 2.2 from the Uniswap v3 whitepaper:

x_virtual = x_real + L / sqrt(P_b)
y_virtual = y_real + L * sqrt(P_a)
kfx
  • 1,501
  • 4
  • 18
  • Hi! {x_virtual = x_real + L / sqrt(P_b) y_virtual = y_real + L * sqrt(P_a)} seems to be incorrect – Chenky Nov 23 '22 at 15:07
  • About the Pa & Pb: slot(0) sqrtPriceX96 uint160 : 2358490336287291322714092334 tick int24 : -70290 observationIndex uint16 : 29 observationCardinality uint16 : 180 observationCardinalityNext uint16 : 180 feeProtocol uint8 : 0 unlocked bool : true – Chenky Nov 23 '22 at 15:09
  • tick_A = -70290 & tick_B = 70290 .
    Pa = 1.0001 ^ tick_A = 1.0001 ^ (-70290) = 0.0008861285

    Pb = 1.0001 ^ tick_B = 1.0001 ^ 70290 = 1128.50448824

    – Chenky Nov 23 '22 at 15:11