degenbot.uniswap.v3_pool_calc¶

Calculation mixin for Uniswap V3 concentrated-liquidity pools.

Provides calculation methods that operate on state held by V3PoolState. All methods are read-only with respect to pool state — they compute results based on current state but don’t modify it.

These methods match the Uniswap V3 contract’s math: - calculate_tokens_out_from_tokens_in / calculate_tokens_in_from_tokens_out:

degenbot interface (delegated to the Rust-routed simulate_exact_input_swap / simulate_exact_output_swap)

  • get_absolute_price / get_absolute_exchange_rate / get_nominal_price / get_nominal_rate: pricing

See: contract_reference/uniswap/V3/UniswapV3Factory.sol (UniswapV3Pool swap, Oracle, Tick, TickBitmap, SqrtPriceMath, SwapMath)

Module Contents¶

class degenbot.uniswap.v3_pool_calc.UniswapV3PoolCalc¶

Calculation methods matching the Uniswap V3 contract.

All methods operate on state held by the concrete class via V3PoolState.

Class variables that V3 subclasses may override: - FEE_DENOMINATOR - TICK_STRUCT_TYPES - SLOT0_STRUCT_TYPES

property tokens: tuple[degenbot.erc20.Erc20Token, degenbot.erc20.Erc20Token]¶
Abstractmethod:

Tokens.

Returns:

The token pair held by this pool.

property state: degenbot.uniswap.v3_types.UniswapV3PoolState¶
Abstractmethod:

State.

Returns:

The current pool state.

abstractmethod simulate_exact_input_swap(token_in: degenbot.erc20.Erc20Token, token_in_quantity: int, sqrt_price_limit_x96: int | None = None, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → degenbot.uniswap.v3_types.UniswapV3PoolSimulationResult¶

Exact-input swap simulation (routed to the Rust seam).

abstractmethod simulate_exact_output_swap(token_out: degenbot.erc20.Erc20Token, token_out_quantity: int, sqrt_price_limit_x96: int | None = None, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → degenbot.uniswap.v3_types.UniswapV3PoolSimulationResult¶

Exact-output swap simulation (routed to the Rust seam).

FEE_DENOMINATOR = 1000000¶
calculate_tokens_out_from_tokens_in(token_in: degenbot.erc20.Erc20Token, token_in_quantity: int, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → int¶

Calculate expected token OUTPUT for a given INPUT at current pool state.

Returns:

The expected output token amount.

Raises:
calculate_tokens_in_from_tokens_out(token_out: degenbot.erc20.Erc20Token, token_out_quantity: int, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → int¶

Calculate required token INPUT for a target OUTPUT at current pool state.

Returns:

The required input token amount.

Raises:
get_absolute_price(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → fractions.Fraction¶

Get the absolute price for the given token, expressed in units of the other.

Returns:

The absolute price as a Fraction.

get_absolute_exchange_rate(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → fractions.Fraction¶

Get the absolute exchange rate for the given token.

A V3 pool encodes the token1/token0 exchange rate in sqrt_price_x96, so it can be directly obtained.

Returns:

The absolute exchange rate as a Fraction.

Raises:

DegenbotValueError – If the token is not held by this pool.

get_nominal_price(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → fractions.Fraction¶

Get the nominal price, corrected for decimals.

Returns:

The nominal price as a Fraction.

get_nominal_rate(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v3_types.UniswapV3PoolState | None = None) → fractions.Fraction¶

Get the nominal rate of exchange, corrected for decimal place values.

Returns:

The nominal exchange rate as a Fraction.