Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

univ3prices.getAmountsForCurrentLiquidity with different decimals #6

Closed
sydneyhenrard opened this issue Aug 22, 2021 · 1 comment
Closed

Comments

@sydneyhenrard
Copy link

I tried to use the getAmountsForCurrentLiquidity for the UNI/USDC pair
https://etherscan.io/address/0xd0fc8ba7e267f2bc56044a7715a489d851dc6d78#readContract

    const [token0Reserves, token1Reserves] = univ3prices.getAmountsForCurrentLiquidity(
        '18', // decimals of UNI
        '6', // decimals of USDC
        '647424456336700945', // Current liquidity value of the pool
        '424427182250808799309705', // Current sqrt price value of the pool
        '60', // the tickSpacing value from the pool
        0
    );
    console.log(token0Reserves) // 326.9
    console.log(token1Reserves) // 1009.9

Does it mean that there is 326.9 UNI and 1009.9 USDC in the pool? The number of USDC seems low.

@thanpolas
Copy link
Owner

Does it mean that there is 326.9 UNI and 1009.9 USDC in the pool? The number of USDC seems low.

Yes, that's exactly what it means. Remember, this is the very, very narrow range of a single tick space, in this case 60 ticks. Widen your range using the tickStep argument:

const tokenDecimals = [
        '18', // decimals of UNI
        '6', // decimals of USDC
];
const [token0Reserves, token1Reserves] = univ3prices.getAmountsForCurrentLiquidity(
    tokenDecimals,
    '647424456336700945', // Current liquidity value of the pool
    '424427182250808799309705', // Current sqrt price value of the pool
    '60', // the tickSpacing value from the pool
    {tickStep: 10} // RAISE THE TICK STEP
);
console.log(token0Reserves) // 116596.9
console.log(token1Reserves) // 1755.4

Thanks for opening the issue @sydneyhenrard, it helped me find a bug in the tickSpace which has been fixed in v3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants