Limits
To optimise gas efficiency, prices on Haiko are partitioned into price intervals called limits. Limits define valid price points at which liquidity positions and limit orders can be placed.
Limits work in the same way as Uniswap's ticks, except they have a minimum increment of 1.00001 (rather than 1.0001) to allow for more precise price points.
Converting limits to prices
Limits are stored as (positive or negative) integers that must be exponentiated to convert them to a regular price. Specifically:
For instance:
where
where
where
Limit width
The interval of valid limits can be configured through a width parameter, on a per-market basis. Valid limits must be a multiple of width. For example:
a market with
widthof 1 has limits of 25, 26, 27, 28 etc (the minimum width)a market with
widthof 10 has limits of 10, 20, 30, 40 etca market with
widthof 2500 has limits of -2500, 0, 2500, 5000 etc.
Valid range of limits
The range of valid price limits spans from -7,906,625 to 7,906,625 for markets of width 1. This is a total of 15,813,251 (251 ** 3) limits.
At the smart contract level, limits are shifted to range from 0 to 15,813,250, avoiding the need for signed integers which are not currently natively supported in Cairo. This allows them to fit inside a single u32 slot.
For markets of other widths, the range of valid limits becomes -R to R, where R is the greatest multiple of width such that R ≤ 7,906,625.
For example:
markets with
width10 range from-7,906,620to7,906,620markets with
width50 range from-7,906,600to7,906,600markets with
width500 range from-7,906,500to7,906,500
Last updated