Tick Arrays Mechanics

Drawing

A sequence of ticks are stored in individual tick-array accounts on chain. Each whirlpool has a sequence of tick-array accounts to host the entire tick range.

A tick-array is keyed by the start-index of its hosted ticks and can hold 88 physical ticks in an array. It only hosts the tick objects for the initializable tick indices based on the Whirlpool's tick-spacing. The total range for a tick-array is therefore 88 * tick-spacing.

Tick Array Account Info

  • Number of physical tick slots - 88

  • Account Size - 10kb

Usage in Instructions

When you interact with ticks on Whirlpool instructions, often you will need to derive the correct tick-array so the program can get access to the designated tick object. This tick-array is a PDA derived using the Whirlpool pool’s public key and the start tick index of the tick array, which defines the beginning of a specific range of ticks.

For example, if the current tick is 200, the tick spacing is 2, and each tick-array contains 88 ticks, you can compute the start tick index by first finding the closest multiple of tick_spacing * ticks_per_array that is less than or equal to the current tick. Here, the start tick index would be 176, calculated as (200/(288))(288)(\lfloor200 / (2 * 88)\rfloor) * (2 * 88).

Open Position

When a position opens up in a new tick or price range, the tick-array must be initialized before the position can be created. This means the user invoking the position will need to cover the rent-exempt cost for the tick-array account.

Once a tick-array account is set up, it cannot be closed and will never need to be reinitialized. For this reason, Fusion AMM owners may consider preemptively initializing tick-array ranges to prevent unexpected costs for users.

Adjust Liquidity (increase / decrease liquidity)

Users of these instructions must provide the tick-arrays that contain the specified tick indexes. For each instruction, two tick-arrays need to be passed in—these may be the same array if the range is small. The instruction requires access to these accounts to read the appropriate Tick objects effectively.

Swap

Swap users must specify a series of tick arrays across which the swap will traverse.

The first tick array in the sequence typically contains the FusionPool’s current tick index, though this is not strictly required. Before processing the swap, the Fusion AMM program will order the tick arrays automatically.

The second and third tick arrays are those immediately following in the swap direction. If the user knows the swap will not move into the next tick array, or if it's not possible at either end of the price range, they can provide any tick array public key instead.

SparseSwap: crossing unitialized tick arrays during swap

It is not necessary for all tick array accounts to be initialized. As long as there is sufficient active liquidity at the current tick (a property defined in the FusionPool state), the Fusion AMM program can execute a swap.

Limit Order

Increasing or decreasing a Limit Orders liquidity requires a single Tick Array that tracks the Tick specified by the Limit Order. Fulfilling Limit Orders affects the movement of the price through the ticks in a Tick Array slightly differently. When a swap moves the FusionPool’s price to a Tick with a Limit Order, the price stalls until the order is fulfilled, as it consumes available limit order liquidity. This reduces slippage for swaps by providing additional liquidity at that Tick. We explore this further in Limit Orders.

Last updated