> ## Documentation Index
> Fetch the complete documentation index at: https://shield.fi/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tick and price conversion

> Convert between ticks and square-root prices within the contract domain.

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:

```text theme={"languages":{"custom":["/languages/leo.tmLanguage.json"]}}
sqrt_price_at_tick(tick) <= sqrt_price
sqrt_price < sqrt_price_at_tick(tick + 1)
```

## Pool creation interval

Pool creation does not accept an arbitrary tick and price pair. For `initial_tick = t`, it requires:

```text theme={"languages":{"custom":["/languages/leo.tmLanguage.json"]}}
sqrt_price_at_tick(t) <= initial_sqrt_price
initial_sqrt_price < sqrt_price_at_tick(t + 1)
```

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.
