Price: Represents the real-time ratio between two tokens (e.g., ETH/USDC).
Tick Index:
Derived from P = 1.0001^i, where i is the Tick Index.
Liquidity can only be provided at discrete Ticks (e.g., multiples of 10).
Sqrt Price:
Used for computational efficiency (avoids floating-point operations).
In Uniswap V3, stored as sqrtPriceX64 (Q64 fixed-point format).
1. Tick index to price
when you want to open position, you dont know how to set your tick_lower and tick_upper.
use /src/math/tick.ts TickMath.tickIndexToPrice()
import{ TickMath }from'@cetusprotocol/cetus-sui-clmm-sdk'// decimalsA and decimalsB means the decimal of coinA and coinBconstprice=TickMath.tickIndexToPrice(tickIndex, decimalsA, decimalsB)
2.Price to tick index
use /src/math/tick.ts TickMath.priceToTickIndex()
3. Tick index to sqrt price x64
use /src/math/tick.ts TickMath.tickIndexToSqrtPriceX64()
4. Sqrt price x64 to tick index
use /src/math/tick.ts TickMath.sqrtPriceToTickIndex()
5. Price to sqrt price
use /src/math/tick.ts TickMath.priceToSqrtPriceX64()
6. Sqrt price to price
use /src/math/tick.ts TickMath.sqrtPriceX64ToPrice()
7. Convert the tick index from i32 to u32
In the TS SDK, for easier display, we will convert u32 to i32. If you need to call the contract directly, you can also use the method below to convert i32 to u32.
import { TickMath } from '@cetusprotocol/cetus-sui-clmm-sdk'
// decimalsA and decimalsB means the decimal of coinA and coinB
const tickIndex = TickMath.priceToTickIndex(price, decimalsA, decimalsB)
import { TickMath } from '@cetusprotocol/cetus-sui-clmm-sdk'
const sqrtPriceX64 = TickMath.tickIndexToSqrtPriceX64(tickIndex)
import { TickMath } from '@cetusprotocol/cetus-sui-clmm-sdk'
const tickIndex = TickMath.sqrtPriceX64ToTickIndex(sqrtPriceX64)
import { TickMath } from '@cetusprotocol/cetus-sui-clmm-sdk'
// decimalsA and decimalsB means the decimal of coinA and coinB
const sqrtPriceX64 = TickMath.priceToSqrtPriceX64(price, decimalsA, decimalsB)
import { TickMath } from '@cetusprotocol/cetus-sui-clmm-sdk'
// decimalsA and decimalsB means the decimal of coinA and coinB
const price = TickMath.sqrtPriceX64ToPrice(sqrtPriceX64, decimalsA, decimalsB)