Utility functions for handling price, sqrt price, and tick index
This document provides an overview of commonly used utility methods and helper functions in the Cetus SDK.
Core Concepts
Price, Tick Index, and Sqrt Price
Price
Token exchange ratio (e.g., token1/token0)
Continuous value, updates in real-time
Directly determines trading rates
Tick Index
Discretized price interval index
Spacing determined by fee tiers
Manages liquidity distribution ranges
Sqrt Price
Square root of price
Stored as fixed-point numbers (e.g., sqrtPriceX64)
Simplifies on-chain calculations, improves efficiency
Notes:
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 don't know how to set your tick_lower and tick_upper.
2. Price to tick index
3. Tick index to sqrt price x64
4. Sqrt price x64 to tick index
5. Price to sqrt price
6. Sqrt price to price
7. Convert the tick index from i32 to u32
Last updated