Function: snapPriceToTick()
snapPriceToTick(
price,tickType,rounding):number
Snap a price onto the tick grid for the given tick type.
This is what a UI should call when a user types an arbitrary price, and what an integrator should call before creating a pool so its bounds land on canonical ticks shared across the whole ecosystem.
Parameters
price
number
Arbitrary price to snap.
tickType
Desired tick width.
rounding
TickRounding = 'nearest'
nearest (default), down, or up.
Returns
number
The snapped price (never negative), rounded to the tick's decimals to avoid floating point noise.
Example
snapPriceToTick(0.94, 'wide'); // 0.9
snapPriceToTick(0.96, 'wide'); // 1
snapPriceToTick(10123, 'normal', 'up'); // 10200