Uniswap / v3-sdk

🛠 An SDK for building applications on top of Uniswap V3
MIT License
547 stars 425 forks source link

A bug in tickList.ts(line 122) which will cause different rounds in swap and sqrtPriceX96 error #82

Closed kafeikui closed 2 years ago

kafeikui commented 2 years ago

Recently I'm trying to build a simulator with my team based on Uniswap V3 CorePool maths model as well as contract implementation. My teammate found the repo and your help is greatly appreciated.

I know the tickList.ts do the same thing as TickBitmap.sol do. It's wonderful work. However, I believe there is a small accident in https://github.com/Uniswap/v3-sdk/blob/b50b02238d4d4f04dbaa04d531e5ff8dd76d63d9/src/utils/tickList.ts#L122 and that will be correct if we adjust the subtraction to the proper position.

const maximum = (((wordPos + 1) << 8) - 1) * tickSpacing;

As fas as the test result I know, this error can result in less swap rounds under certain condition. Thus sqrtPriceX96 will be different and swap result like amount will be different from actual mainnet data bit by bit.

Please check if it is right. Thank you.

bampan commented 2 years ago

I think you're right. I had the same problem.

NoahZinsmeister commented 2 years ago

sorry about that! thanks for flagging, fixed in 3.8.1