Get DEX Tick Level
dex.getTickLevel
Gets the order queue and liquidity at a tick level.
Usage
import { } from './viem.config'
const = await ..({
: '0x20c0000000000000000000000000000000000001',
: true,
: 100,
})
.('Tick level:', )
Tick level: { head: 123n, tail: 124n, totalLiquidity: 200000000n }import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Recipes
Check Liquidity at a Target Price
Use Tick.fromPrice to address a level by its human-readable price and read totalLiquidity before resting an order there: orders already at the tick fill ahead of yours.
import { } from 'viem/tempo'
import { } from './viem.config'
const = await ..({
: '0x20c0000000000000000000000000000000000001',
: true,
: .('0.999'),
})
.('Liquidity ahead:', .)
Liquidity ahead: 250000000nimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Walk the Order Queue at a Tick
Combine dex.getTickLevel with dex.getOrder to enumerate resting orders front to back, for example to find your queue position at a price level.
import { } from './viem.config'
const = await ..({
: '0x20c0000000000000000000000000000000000001',
: true,
: -100,
})
let = .
while ( !== 0n) {
const = await ..({ })
.(, ., .)
= .
}import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnType = {
/** Order ID of the first order at this tick (0 if empty). */
head: bigint
/** Order ID of the last order at this tick (0 if empty). */
tail: bigint
/** Total liquidity available at this tick level. */
totalLiquidity: bigint
}The first and last order IDs at the tick, plus total liquidity available.
Parameters
base
- Type:
Address | bigint
Base token to query: a TIP-20 token id or a contract address.
isBid
- Type:
boolean
Whether to query the bid side (true) or ask side (false).
tick
- Type:
number
Price tick to query. A tick of 100 is approximately price 1.001.
blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.