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.

Example

Local

1
WITH step AS (
2
SELECT clmm_swap_step_x96(
3
79228162514264337593543950336::UINT256,
4
79623317895830914510639640423::UINT256,
5
2000000000000000000::UINT256,
6
-1000000000000000000::INT256,
7
600::UBIGINT
8
) AS value
9
)
10
SELECT
11
(value).sqrt_price_next_x96::VARCHAR AS sqrt_price_next_x96,
12
(value).amount_in::VARCHAR AS amount_in,
13
(value).amount_out::VARCHAR AS amount_out,
14
(value).fee_amount::VARCHAR AS fee_amount,
15
(value).zero_for_one::VARCHAR AS zero_for_one,
16
(value).reached_target::VARCHAR AS reached_target
17
FROM step;
18
-- => [{"sqrt_price_next_x96":"79623317895830914510639640423","amount_in":"9975124224178055","amount_out":"9925619580021728","fee_amount":"5988667735148","zero_for_one":"false","reached_target":"true"}]
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

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.

Inputs

Name Type Use
sqrt_price_current_x96 UINT256

UINT256 sqrt(currency1/currency0) * 2^96 within the inclusive TickMath bounds.

required positional
sqrt_price_target_x96 UINT256

UINT256 price boundary for this single range. Direction is inferred: current >= target means zero-for-one.

required positional
liquidity UINT256

UINT256 SQL value restricted to [1, 2^128 - 1].

required positional
amount_remaining INT256

INT256: negative means exact input and its magnitude includes fees; non-negative means exact output.

required positional
fee_pips UBIGINT

UBIGINT fee numerator no greater than the denominator; exact output requires it to be strictly smaller.

required positional

Returns

Name Type
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.

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.

Local SQL

1
WITH bounds AS (
2
SELECT
3
clmm_tick_to_sqrt_price_x96(-60) AS sqrt_price_a_x96,
4
clmm_tick_to_sqrt_price_x96(60) AS sqrt_price_b_x96
5
)
6
SELECT clmm_amount0_delta_x96(
7
sqrt_price_a_x96,
8
sqrt_price_b_x96,
9
1000000::UINT256,
10
false
11
) AS amount0
12
FROM bounds;
Notebook ready in readonly mode.

Additional overloads

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.

Inputs

NameTypeUse
sqrt_price_current_x96UINT256

UINT256 sqrt(currency1/currency0) * 2^96 within the inclusive TickMath bounds.

requiredpositional
sqrt_price_target_x96UINT256

UINT256 price boundary for this single range. Direction is inferred: current >= target means zero-for-one.

requiredpositional
liquidityUINT256

UINT256 SQL value restricted to [1, 2^128 - 1].

requiredpositional
amount_remainingINT256

INT256: negative means exact input and its magnitude includes fees; non-negative means exact output.

requiredpositional
fee_pipsUBIGINT

UBIGINT fee numerator no greater than the denominator; exact output requires it to be strictly smaller.

requiredpositional
Showing fewer

Returns

Name Type
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.

Overload examples

Local SQL

1
WITH step AS (
2
SELECT clmm_swap_step_x96(
3
79228162514264337593543950336::UINT256,
4
79623317895830914510639640423::UINT256,
5
2000000000000000000::UINT256,
6
1000000000000000000::INT256,
7
6::UBIGINT,
8
10000::UBIGINT
9
) AS value
10
)
11
SELECT
12
(value).sqrt_price_next_x96::VARCHAR AS sqrt_price_next_x96,
13
(value).amount_in::VARCHAR AS amount_in,
14
(value).amount_out::VARCHAR AS amount_out,
15
(value).fee_amount::VARCHAR AS fee_amount,
16
(value).zero_for_one::VARCHAR AS zero_for_one,
17
(value).reached_target::VARCHAR AS reached_target
18
FROM step;
19
-- => [{"sqrt_price_next_x96":"79623317895830914510639640423","amount_in":"9975124224178055","amount_out":"9925619580021728","fee_amount":"5988667735148","zero_for_one":"false","reached_target":"true"}]

Related functions

Category and tags

Tag
Clmm Math
Tag
Offline
Tag
Types