Skip to content
LogoLogo

TickPrice

Git Source

Book levels on Uniswap v4 ticks: an order sits at the floor tick (spacing 1, 0.01% steps) of its exact currency1/currency0 limit. Levels are a fixed relative width at any price and for any token decimals; the exact limit still decides crossing within a level.

Functions

key

Radix key of an order's level, ordered by numeraire per asset. Monotone in the exact price, so distinct keys order prices strictly. Keys run from 1 to 2 * MAX_TICK + 1; ratios beyond the v4 price range share the end keys.

function key(bool isBuy, bool zeroForOne, uint256 amountIn, uint256 amountOut) public pure returns (uint128);

Parameters

NameTypeDescription
isBuybool
zeroForOnebool
amountInuint256
amountOutuint256

Returns

NameTypeDescription
<none>uint128

poolBeatsLevel

Whether the pool has active liquidity and its current price is strictly better for an incoming order than the best opposite level levelKey (below the best ask for a buy, above the best bid for a sell), compared as keys; if so, also the limit a pool-first swap may not cross. quote1: the numeraire is currency1, so the tick's price is already numeraire per asset; otherwise it is flipped.

Inside the dynamic-fee window (refTick, refBlock; see DynamicFeeOrdering) a fill back toward the reference pays about half the price gap it closes, so the pool's price counts that much worse: half the gap, in ticks. The limit is the level's tick, one tick higher for a swap that lowers the tick (the key is a floor tick, so the floor would trade past the level's exact price), kept inside the range v4 accepts.

function poolBeatsLevel(
        IPoolManager manager,
        PoolId poolId,
        bool quote1,
        bool isBuy,
        uint128 levelKey,
        int24 refTick,
        uint64 refBlock
    ) public view returns (bool, uint160);

Parameters

NameTypeDescription
managerIPoolManager
poolIdPoolId
quote1bool
isBuybool
levelKeyuint128
refTickint24
refBlockuint64

Returns

NameTypeDescription
<none>bool
<none>uint160

floorTick

Largest tick whose price is at most num/den, clamped to the v4 tick range. Monotone in num/den. Two regimes keep sqrt(num/den) * 2^96 well inside one tick of exact.

function floorTick(uint256 num, uint256 den) internal pure returns (int24);

Parameters

NameTypeDescription
numuint256
denuint256

Returns

NameTypeDescription
<none>int24