CetusProtocol / cetus-clmm-sui-sdk

The clmm sdk on Sui.
Apache License 2.0
28 stars 20 forks source link

bug: getInitializableTickIndex return error if tickIndex is negative #5

Open GuihaiHU opened 5 months ago

GuihaiHU commented 5 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;
}