# clmm_swap_step_x96

Computes one Uniswap v4 SwapMath-compatible price-range step. Negative amount_remaining means exact input; non-negative means exact output. Direction is inferred from current versus target. Hooks, dynamic fee resolution, tick-crossing liquidity changes, multi-word iteration, slippage, routing, and calldata are outside this deterministic helper. The five-argument overload uses Uniswap v4's 1,000,000 fee denominator.

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

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

Computes one Uniswap v4 SwapMath-compatible price-range step. Negative amount_remaining means exact input; non-negative means exact output. Direction is inferred from current versus target. Hooks, dynamic fee resolution, tick-crossing liquidity changes, multi-word iteration, slippage, routing, and calldata are outside this deterministic helper. The five-argument overload uses Uniswap v4's 1,000,000 fee denominator.

## Overload 1: clmm_swap_step_x96(UINT256, UINT256, UINT256, INT256, UBIGINT)

```sql
clmm_swap_step_x96(UINT256, UINT256, UINT256, INT256, UBIGINT)
```

Computes one Uniswap v4 SwapMath-compatible price-range step. Negative amount_remaining means exact input; non-negative means exact output. Direction is inferred from current versus target. Hooks, dynamic fee resolution, tick-crossing liquidity changes, multi-word iteration, slippage, routing, and calldata are outside this deterministic helper. The five-argument overload uses Uniswap v4's 1,000,000 fee denominator.

- 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_current_x96` (UINT256; required; positional) — UINT256 sqrt(currency1/currency0) * 2^96 within the inclusive TickMath bounds.
- `sqrt_price_target_x96` (UINT256; required; positional) — UINT256 price boundary for this single range. Direction is inferred: current >= target means zero-for-one.
- `liquidity` (UINT256; required; positional) — UINT256 SQL value restricted to [1, 2^128 - 1].
- `amount_remaining` (INT256; required; positional) — INT256: negative means exact input and its magnitude includes fees; non-negative means exact output.
- `fee_pips` (UBIGINT; required; positional) — UBIGINT fee numerator no greater than the denominator; exact output requires it to be strictly smaller.

### Returns

Single-range swap step

STRUCT for one price range only: sqrt_price_next_x96 is the reached Q64.96 price; amount_in and amount_out are raw input/output token units excluding the fee; fee_amount is raw input-token fee; zero_for_one reports the direction inferred from current versus target; reached_target says whether this step ended at the supplied target. NULL input returns NULL. Invalid price or liquidity, invalid fee ratios, insufficient output, or arithmetic bounds raise errors. This result is never a complete route quote.

- `swap_step` (STRUCT(sqrt_price_next_x96 UINT256, amount_in UINT256, amount_out UINT256, fee_amount UINT256, zero_for_one BOOLEAN, reached_target BOOLEAN))

Single-range swap step. STRUCT for one price range only: sqrt_price_next_x96 is the reached Q64.96 price; amount_in and amount_out are raw input/output token units excluding the fee; fee_amount is raw input-token fee; zero_for_one reports the direction inferred from current versus target; reached_target says whether this step ended at the supplied target. NULL input returns NULL. Invalid price or liquidity, invalid fee ratios, insufficient output, or arithmetic bounds raise errors. This result is never a complete route quote.

### Examples

_Local SQL · Local_

```sql
WITH step AS (
  SELECT clmm_swap_step_x96(
    79228162514264337593543950336::UINT256,
    79623317895830914510639640423::UINT256,
    2000000000000000000::UINT256,
    -1000000000000000000::INT256,
    600::UBIGINT
  ) AS value
)
SELECT
  (value).sqrt_price_next_x96::VARCHAR AS sqrt_price_next_x96,
  (value).amount_in::VARCHAR AS amount_in,
  (value).amount_out::VARCHAR AS amount_out,
  (value).fee_amount::VARCHAR AS fee_amount,
  (value).zero_for_one::VARCHAR AS zero_for_one,
  (value).reached_target::VARCHAR AS reached_target
FROM step;
-- => [{"sqrt_price_next_x96":"79623317895830914510639640423","amount_in":"9975124224178055","amount_out":"9925619580021728","fee_amount":"5988667735148","zero_for_one":"false","reached_target":"true"}]
```

## Overload 2: clmm_swap_step_x96(UINT256, UINT256, UINT256, INT256, UBIGINT, UBIGINT)

```sql
clmm_swap_step_x96(UINT256, UINT256, UINT256, INT256, UBIGINT, UBIGINT)
```

Computes one Uniswap v4 SwapMath-compatible price-range step. Negative amount_remaining means exact input; non-negative means exact output. Direction is inferred from current versus target. Hooks, dynamic fee resolution, tick-crossing liquidity changes, multi-word iteration, slippage, routing, and calldata are outside this deterministic helper. The six-argument fee denominator is a Determica extension; 6/10,000 equals 600/1,000,000.

- 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_current_x96` (UINT256; required; positional) — UINT256 sqrt(currency1/currency0) * 2^96 within the inclusive TickMath bounds.
- `sqrt_price_target_x96` (UINT256; required; positional) — UINT256 price boundary for this single range. Direction is inferred: current >= target means zero-for-one.
- `liquidity` (UINT256; required; positional) — UINT256 SQL value restricted to [1, 2^128 - 1].
- `amount_remaining` (INT256; required; positional) — INT256: negative means exact input and its magnitude includes fees; non-negative means exact output.
- `fee_pips` (UBIGINT; required; positional) — UBIGINT fee numerator no greater than the denominator; exact output requires it to be strictly smaller.
- `fee_denom` (UBIGINT; required; positional) — Non-zero UBIGINT denominator. This six-argument form is a Determica extension, not a Uniswap v4 interface.

### Returns

Single-range swap step

STRUCT for one price range only: sqrt_price_next_x96 is the reached Q64.96 price; amount_in and amount_out are raw input/output token units excluding the fee; fee_amount is raw input-token fee; zero_for_one reports the direction inferred from current versus target; reached_target says whether this step ended at the supplied target. NULL input returns NULL. Invalid price or liquidity, invalid fee ratios, insufficient output, or arithmetic bounds raise errors. This result is never a complete route quote.

- `swap_step` (STRUCT(sqrt_price_next_x96 UINT256, amount_in UINT256, amount_out UINT256, fee_amount UINT256, zero_for_one BOOLEAN, reached_target BOOLEAN))

Single-range swap step. STRUCT for one price range only: sqrt_price_next_x96 is the reached Q64.96 price; amount_in and amount_out are raw input/output token units excluding the fee; fee_amount is raw input-token fee; zero_for_one reports the direction inferred from current versus target; reached_target says whether this step ended at the supplied target. NULL input returns NULL. Invalid price or liquidity, invalid fee ratios, insufficient output, or arithmetic bounds raise errors. This result is never a complete route quote.

### Examples

_Local SQL · Local_

```sql
WITH step AS (
  SELECT clmm_swap_step_x96(
    79228162514264337593543950336::UINT256,
    79623317895830914510639640423::UINT256,
    2000000000000000000::UINT256,
    1000000000000000000::INT256,
    6::UBIGINT,
    10000::UBIGINT
  ) AS value
)
SELECT
  (value).sqrt_price_next_x96::VARCHAR AS sqrt_price_next_x96,
  (value).amount_in::VARCHAR AS amount_in,
  (value).amount_out::VARCHAR AS amount_out,
  (value).fee_amount::VARCHAR AS fee_amount,
  (value).zero_for_one::VARCHAR AS zero_for_one,
  (value).reached_target::VARCHAR AS reached_target
FROM step;
-- => [{"sqrt_price_next_x96":"79623317895830914510639640423","amount_in":"9975124224178055","amount_out":"9925619580021728","fee_amount":"5988667735148","zero_for_one":"false","reached_target":"true"}]
```

## 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, resolve dynamic fees or hooks, cross ticks and update liquidity, iterate bitmap words, apply slippage policy, select routes, produce calldata, or return a complete executable quote.
- 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_next_sqrt_price_from_input_x96](/docs/functions/clmm_next_sqrt_price_from_input_x96.md) — Usually After
- [clmm_next_sqrt_price_from_output_x96](/docs/functions/clmm_next_sqrt_price_from_output_x96.md) — Usually After
- [clmm_amount0_delta_x96](/docs/functions/clmm_amount0_delta_x96.md) — Usually After
- [clmm_amount1_delta_x96](/docs/functions/clmm_amount1_delta_x96.md) — Usually After
