clmm_liquidity_for_amounts_x96

Liquidity two token amounts buy in a price range, as Uniswap v3-periphery LiquidityAmounts.getLiquidityForAmounts. Integer math only; NULL propagates.

Example

Runs locally

-- Liquidity of 1860.606774 USDC and 0.844506684178188026 WETH in ticks 197940..198960
SELECT clmm_liquidity_for_amounts_x96('1615992376167869037152219662794366'::UINT256,
  clmm_tick_to_sqrt_price_x96(197940), clmm_tick_to_sqrt_price_x96(198960),
  1860606774::UINT256, 844506684178188026::UINT256)::VARCHAR AS liquidity;
-- => [{"liquidity":"1576006372865616"}]

API reference

clmm_liquidity_for_amounts_x96(UINT256, UINT256, UINT256, UINT256, UINT256) #

Liquidity two token amounts buy in a price range, as Uniswap v3-periphery LiquidityAmounts.getLiquidityForAmounts. 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
amount0 UINT256

UINT256 raw currency0 available.

required positional
amount1 UINT256

UINT256 raw currency1 available.

required positional

Returns

Name Type
liquidity UINT256

Position liquidity. UINT256 liquidity, rounded down: amount0 below range, amount1 above, smaller of both inside. Each side exact before the min, so an unbounded side lets the other bind. NULL input returns NULL; result above 2^128 - 1 or 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;