Jeiwan / uniswapv3-book

Uniswap V3 Development Book

Home Page:https://uniswapv3book.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong Calculation in Q64.96 number of sqrt Price

OoXooOx opened this issue · comments

In book you use lower price 4545$, so sqrt from P * 2 * * 96 will be 5341294542274603406682713227264 (in book it is 5314786713428871004159001755648)
import math
q96 = 2**96
def price_to_sqrtp(p):
return int(math.sqrt(p) * q96)
print (price_to_sqrtp(4545))

5341294542274603406682713227264

I don't know, mb error in define lower price. If you want assign it to 4500, then it will be correct.
import math
q96 = 2**96
def price_to_sqrtp(p):
return int(math.sqrt(p) * q96)
print (price_to_sqrtp(4500))

5314786713428871004159001755648