# 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.

Canonical HTML: <https://determica.com/docs/functions/clmm_amounts_for_liquidity_x96>

- Kind: scalar function
- Category: [Fixed-point and AMM math](/docs/category/fixed-point-and-amm-math.md)
- Tags: Clmm Math, Deterministic, Offline, Types

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

## Overload 1: clmm_amounts_for_liquidity_x96(UINT256, UINT256, UINT256, UINT256)

```sql
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.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `sqrt_price_x96` (UINT256; required; positional) — UINT256 inside inclusive TickMath bounds.
- `sqrt_price_a_x96` (UINT256; required; positional) — UINT256 Q64.96 price; boundary order free.
- `sqrt_price_b_x96` (UINT256; required; positional) — UINT256 Q64.96 price, not equal to first.
- `liquidity` (UINT256; required; positional) — UINT256, at most 2^128 - 1; 0 gives zero amounts.

### Returns

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.

- `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.

### Examples

_Local SQL · Local_

```sql
-- 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"}]
```

## 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.

```sql
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;
```

## Related functions

- [clmm_liquidity_for_amounts_x96](/docs/functions/clmm_liquidity_for_amounts_x96.md) — Alternative
- [clmm_tick_to_sqrt_price_x96](/docs/functions/clmm_tick_to_sqrt_price_x96.md) — Usually Before
- [format_units](/docs/functions/format_units.md) — Usually After
