Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Queries a pool's liquidity distribution over a tick range, giving the liquidity and both token amounts per segment.

exchange.IO(k, poolId, tickLower, tickUpper)
exchange.IO(k, poolId, tickLower, tickUpper, step)

Examples

Look at the liquidity within 10 tick spacings on either side of the price.

javascript
function main() { var p = exchange.IO("lp.select", "ETH", 1000, {quote: "USDC"}) var pool = exchange.IO("lp.pool", p.id) var w = pool.tickSpacing * 10 var r = exchange.IO("lp.ticks", p.id, pool.tick - w, pool.tick + w, pool.tickSpacing * 2) r.segments.forEach(function (s) { Log(s.tickLower, s.tickUpper, s.current ? "<- price" : "", pool.token0.symbol, s.amount0, pool.token1.symbol, s.amount1) }) }

Returns

TypeDescription

object / null value

{pool, tick, token0, token1, segments}, where segments lists {tickLower, tickUpper, price0Lower, price0Upper, liquidity, amount0, amount1, current}; see the remarks. Null with an error when the range is too wide.

Arguments

NameTypeRequiredDescription

k

string

Yes

Set to lp.ticks to query the liquidity distribution.

poolId

string

Yes

Pool ID as in exchange.IO("lp.pool", ...); not applicable to basic pools, which have no ticks.

tickLower

number

Yes

Lower end of the range (tick).

tickUpper

number

Yes

Upper end of the range (tick).

step

number

No

Segment width in ticks; the pool's tick spacing by default.

See Also

Remarks

Each segment's liquidity is the liquidity inside it and amount0 and amount1 the amounts of both tokens in it (summed over the initialized ticks, in token units); price0Lower and price0Upper give token1 per token0 at the two ends; the segment with current true contains the current tick and is the only one holding both tokens. The token order is that of lp.pool.

The range is read through the tick bitmap; spans of more than 120 bitmap words (each covering 256 tick spacings) fail, so narrow the range or query it in parts.