Skip to main content
Ticks discretize the price curve. The main program contains the canonical conversion functions used by pool creation, swaps, liquidity operations, and tests.

Tick to square-root price

get_sqrt_price_at_tick starts from the fixed-point unit and conditionally multiplies precomputed constants according to the absolute tick’s bits. Positive and negative ticks use reciprocal directions. The function supports the configured domain from -400000 through 400000. Sentinel ticks lie outside the position domain and are list anchors, not price boundaries for user positions.

Square-root price to tick

get_tick_at_sqrt_price:
  1. Finds the most significant bit.
  2. Normalizes the value into the expected fixed-point interval.
  3. Computes fractional logarithm bits.
  4. Divides by the logarithm of the tick base.
  5. Checks the next tick boundary.
  6. Corrects a possible one-tick high estimate.
The returned value is intended to satisfy:

Pool creation interval

Pool creation does not accept an arbitrary tick and price pair. For initial_tick = t, it requires:
It also requires tick alignment and an exclusive upper bound below MAX_TICK.

Directional limits

For a token0-to-token1 swap, price moves downward and the limit must be below the current price. For token1-to-token0, price moves upward and the limit must be above. A limit can fall before the next initialized tick or exactly at it. Exact equality completes the crossing bookkeeping. The next iteration cannot trade beyond the limit.

Client conversion

For acceptance-critical inputs, port the integer algorithm and constants. Floating-point logarithms can produce an adjacent tick near boundaries. If a UI uses a decimal price, convert it to a conservative integer square-root price, verify direction, and simulate the contract interval before submission. Always state the quote convention, canonical token order, and display decimals alongside a displayed price.