Skip to main content
CLMM prices live in three representations: All raw prices are token1 per token0 in sorted order. The base/quote helpers below handle UI pairs in either orientation.

Tick ↔ sqrtPriceX96

getSqrtRatioAtTick(tick)

Exact port of the on-chain tick math. Throws TickOutOfBounds if |tick| > MAX_TICK (887272).

getTickAtSqrtRatio(sqrtPriceX96)

The greatest tick whose sqrt ratio is ≤ the input. Throws SqrtPriceX96OutOfBounds outside [MIN_SQRT_RATIO, MAX_SQRT_RATIO).

Price ↔ sqrtPriceX96

priceToSqrtPriceX96(price, token0Decimals, token1Decimals)

price is the human price of token0 in token1. Throws on non-finite or non-positive prices.

sqrtPriceX96ToPrice(sqrtPriceX96, token0Decimals, token1Decimals)

Aligning to tick spacing

Position bounds must be multiples of the fee tier’s tickSpacing.

getAlignedTick(price, token0Decimals, token1Decimals, tickSpacing)

Converts a human price to the nearest valid tick (rounded up to a multiple of tickSpacing).

Base/quote helpers for UIs

These take the tokens as the user sees them (tokenBase, tokenQuote) plus baseIn, and flip to sorted order internally. With baseIn = true the price is quoted as “1 base = X quote”.

Swap math

Constants

Exported from the package root: MIN_TICK = -887272n, MAX_TICK = 887272n, U256_MAX, UNLIMITED_AMOUNT, and MAX_PIPS. The package root does not export MIN_SQRT_RATIO (4295128739n), MAX_SQRT_RATIO, or Q96 (2n ** 96n). Define them locally if you need them.