clmm_amounts_for_liquidity_x96

Position token amounts at a price from liquidity and range, as Uniswap v3-periphery LiquidityAmounts.getAmountsForLiquidity. Integer math only; NULL propagates.

Example

Runs locally

-- Token amounts of a position (liquidity 1576006373580496, ticks 197940..198960) at a pool price
SELECT (a).amount0::VARCHAR AS amount0, (a).amount1::VARCHAR AS amount1
FROM (SELECT clmm_amounts_for_liquidity_x96('1615992376167869037152219662794366'::UINT256,
  clmm_tick_to_sqrt_price_x96(197940), clmm_tick_to_sqrt_price_x96(198960), 1576006373580496::UINT256) AS a);
-- => [{"amount0":"1860606774","amount1":"844506684178188026"}]

API reference

clmm_amounts_for_liquidity_x96(UINT256, UINT256, UINT256, UINT256) #

Position token amounts at a price from liquidity and range, as Uniswap v3-periphery LiquidityAmounts.getAmountsForLiquidity. Integer math only; NULL propagates.

Inputs

Name Type Use
sqrt_price_x96 UINT256

UINT256 inside inclusive TickMath bounds.

required positional
sqrt_price_a_x96 UINT256

UINT256 Q64.96 price; boundary order free.

required positional
sqrt_price_b_x96 UINT256

UINT256 Q64.96 price, not equal to first.

required positional
liquidity UINT256

UINT256, at most 2^128 - 1; 0 gives zero amounts.

required positional

Returns

Name Type
amounts STRUCT(amount0 UINT256, amount1 UINT256)

Position token amounts. STRUCT(amount0 UINT256, amount1 UINT256), raw, rounded down: only currency0 below range, only currency1 above, both inside. NULL input returns NULL; empty range errors.

Guidance

Uniswap v4-compatible local math boundary

These generic helpers follow Uniswap v4 core TickMath, SqrtPriceMath, SwapMath, and TickBitmap conventions. Q64.96 square-root price means sqrt(currency1 / currency0) * 2^96, using raw token units.

  • Use them as deterministic evidence about one hydrated pool state, price range, bitmap word, or swap step.
  • They do not fetch state or bitmap words, resolve dynamic fees or hooks, apply slippage policy, select routes, produce calldata, or return an executable quote. clmm_swap_x96 crosses only the initialized ticks the caller lists.
  • Pin onchain reads before use. The six-argument swap-step fee denominator and the bitmap result diagnostics are Determica extensions, not Uniswap v4 interfaces.

Runs locally

WITH bounds AS (
  SELECT
    clmm_tick_to_sqrt_price_x96(-60) AS sqrt_price_a_x96,
    clmm_tick_to_sqrt_price_x96(60) AS sqrt_price_b_x96
)
SELECT clmm_amount0_delta_x96(
  sqrt_price_a_x96,
  sqrt_price_b_x96,
  1000000::UINT256,
  false
) AS amount0
FROM bounds;