CetusProtocol / cetus-clmm-sui-sdk

The clmm sdk on Sui.
Apache License 2.0
36 stars 25 forks source link

bug: getInitializableTickIndex return error if tickIndex is negative #5

Closed GuihaiHU closed 1 week ago

GuihaiHU commented 6 months ago

TickMath.getInitializableTickIndex run well when tickIndex is Positive number,However, When tickindex is negative, It return error.

For example: symbols: WBTC-USDC, tickIndex: -64361, tickSpacing: 60. after run TickMath.getInitializableTickIndex, it return -64320 which is larger than tickIndex. The correct value should be -64380

Here is the sugguest code

static getInitializableTickIndex(tickIndex, tickSpacing) {
    const remainder = Math.abs(tickIndex) % Math.abs(tickSpacing);
    return (tickIndex < 0) ? tickIndex - remainder : tickIndex + remainder;
}