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

getSqrtRatioAtTick function returns incorrect result #9

Closed
Code0x2 opened this issue Dec 18, 2022 · 2 comments
Closed

getSqrtRatioAtTick function returns incorrect result #9

Code0x2 opened this issue Dec 18, 2022 · 2 comments

Comments

@Code0x2
Copy link
Contributor

Code0x2 commented Dec 18, 2022

The function in tick_math.rs returns incorrect result here

if (ratio.shr(32) + (ratio % (U256::one().shl(32)))).is_zero() {
    Ok(U256::zero())
} else {
    Ok(U256::one())
}

Function can only return one or zero, which is wrong. UniswapV3 code is ratio >> 32 and adding the value instead
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));

@0xKitsune
Copy link
Owner

Thanks for catching this! The lib still needs to be tested, feel free to make a PR fixing this if you would like, otherwise, Ill patch it in the interim.

@Code0x2
Copy link
Contributor Author

Code0x2 commented Dec 18, 2022

Sure, fixed it for myself anyways so might as well

@Code0x2 Code0x2 closed this as completed Dec 18, 2022
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