I need help with math of UniSwap V3 virtual and real reserves. Need to find the true reserves of a pair (value of token0 = value of token1). Example:
Let's say we have this DAI/WETH pair: 0x60594a405d53811d3BC4766596EFD80fd545A270 balance of DAI was - 2591437269710515203595384 & balance of WETH was - 2838497576725882781612 As we can see here, reserve's of tokens in this pool disbalanced DAI value in pool - 2,594,028.706980225 $ - 43 % WETH value in pool - 3,461,888.414526421 $ - 57 %
If I'am not mistaken, because of concentrated liquidity we have a different virtual reserve's in every "concentrated" zone. Also, those virtual reserve's should be balanced (50/50 - value) by x*y=k. Does anyone know how to find those virtual and/or real reserve's?
I've succesfully calculated a price of both token's: token0Price= sqrtRatioX96 ** 2 / 2 ** 192 = 2267580935849786082246943435 **2 / 2 **192 = 5.141923300629392e+54 / 6.277101735386681e+57 = 0.0008191556417896165
token1Price = 2 ** 192 / sqrtRatioX96 ** 2 = 6.277101735386681e+57 / 2267580935849786082246943435 **2 = 6.277101735386681e+57 / 5.141923300629392e+54 = 1220.7692274636495 And price's are fine.
Also, I've got: Reserves token0 x = L / sqrt(P) x = 776218541774739337116335 / sqrt(0.0008191556417896165) x = 776218541774739337116335 / 0.02862089519 x = 2.7120694046143822e+25 x = 27120694046143822000000000
Reserves token1 y = L * sqrt(P) Suppose that sqrt(P) is sqrt(token1Price) then: y = 776218541774739337116335 * sqrt(1220.7692274636495) y = 776218541774739337116335 * 34.9395081171 y = 2.7120694040982028e+25 y = 27120694040982028000000000
x = 27120694046143822000000000 y = 27120694040982028000000000
Yeah, it's look like 50/50, but not by it's token reserves value. I'm not sure, that's my math is correct.
Thank you!
x
andy
are very rarely needed; liquidity is almost always what you want to calculate and use. Real reserves in a pool are complex to calculate because of the non-uniform liquidity. See my answer here stackoverflow.com/a/71815432/2435820