1

I want to be extract the amounts of t0 and t1 from a Uniswap v3 Pool.

I was trying with some method which I found on other post, but I think is not working, or I am doing something wrong.

This is the method tried by me:

function extractAmounts(){
            
    const tick = -282260;
    const liquidity = 31494343572914561514 //liquidityNet
    const sqrtPriceCurrent = 58884551862568005367467
                
    const sqrtPriceLow = Math.pow(1.0001, -282260);
    const sqrtPriceHigh = Math.pow(1.0001, -282250);
                
    const sp = Math.max(Math.min(sqrtPriceCurrent, sqrtPriceHigh), sqrtPriceLow)
                
    const amount0 = liquidity * (sqrtPriceHigh - sp) / (sp * sqrtPriceHigh)
    const amount1 = liquidity * (sp - sqrtPriceLow)
                
    console.log(amount0, amount1)
                
}
extractAmounts();

The values printed in console for the tick(wrote manually by me) are not matching with the chart from Uniswap page (USDC locked value, in the image):

https://info.uniswap.org/#/polygon/pools/0xa374094527e1673a86de625aa59517c5de346d32 enter image description here The values from the image is for example, and is not matching the values from code.

Someone can explain to me how to calculate the amounts for a tick(current/specific one)?

A pool example(polygon): https://polygonscan.com/address/0xa374094527e1673a86de625aa59517c5de346d32#readContract

1

1 Answer 1

2

There is an NPM library that does all these calculations. It's called univ3prices: https://www.npmjs.com/package/@thanpolas/univ3prices/v/3.0.2

Specifically, check univ3prices.getAmountsForCurrentLiquidity (gets amounts for the current tick space) and univ3prices.getAmountsForLiquidityRange (gets amounts for an arbitrary range)

If you are looking for the exact math, it could be found here: see section 3.3.3 in this whitepaper: atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf

4
  • The idea is that I am coding in different language(java), and I don't find any SDK for java from Uniswap. So, I need to implement it by myself, but I can't understand how the calculations are made.
    – KunLun
    Commented Aug 28, 2023 at 14:52
  • 1
    check section 3.3.3 in this whitepaper: atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf . It has all the math
    – Vas Treck
    Commented Aug 29, 2023 at 3:07
  • Can you add the comment into the answer? To accept it as solution?
    – KunLun
    Commented Aug 29, 2023 at 17:14
  • done. thank you
    – Vas Treck
    Commented Aug 29, 2023 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.