degenbot.types.pool_protocols¶

Pool simulation protocols.

Define structural interfaces for pool behavior. Pools satisfy these protocols by implementing the required methods — no inheritance needed.

Three pool-shape protocols: - ConstantProductPool — V2-family pools - ConcentratedLiquidityPool — V3/V4-family pools - StableswapPool — Curve-family pools

Module Contents¶

class degenbot.types.pool_protocols.ConstantProductPool¶

Bases: Protocol

Any pool using the x*y=k invariant (V2-style, Aerodrome volatile/stable).

Replaces AbstractUniswapV2Pool and AbstractAerodromeV2Pool for isinstance dispatch. Aerodrome pools satisfy this protocol too — they have the same structural shape (directional fees, reserves). The stable flag is accessed separately when needed.

property address: degenbot.types.chain.ChecksummedAddress¶

Pool contract address.

property name: str¶

Human-readable pool name.

property token0: degenbot.erc20.erc20.Erc20Token¶

The lower-addressed token in the pair.

property token1: degenbot.erc20.erc20.Erc20Token¶

The higher-addressed token in the pair.

property fee_token0: fractions.Fraction¶

Fee ratio for token0 swaps.

property fee_token1: fractions.Fraction¶

Fee ratio for token1 swaps.

property reserves_token0: int¶

Raw reserve amount for token0.

property reserves_token1: int¶

Raw reserve amount for token1.

class degenbot.types.pool_protocols.ConcentratedLiquidityPool¶

Bases: Protocol

Any pool using concentrated liquidity (tick-based: V3, V4).

Replaces AbstractConcentratedLiquidityPool for isinstance dispatch.

property address: degenbot.types.chain.ChecksummedAddress¶

Pool contract address.

property name: str¶

Human-readable pool name.

property token0: degenbot.erc20.erc20.Erc20Token¶

The lower-addressed token in the pair.

property token1: degenbot.erc20.erc20.Erc20Token¶

The higher-addressed token in the pair.

property fee: int¶

Pool fee in hundredths of a bip.

property liquidity: int¶

Active liquidity in the current tick range.

property sqrt_price_x96: int¶

Current sqrt price as a Q64.96 value.

property tick: int¶

Current tick.

property tick_spacing: int¶

Minimum spacing between initialized ticks.

class degenbot.types.pool_protocols.StableswapPool¶

Bases: Protocol

Any pool using the Curve StableSwap invariant.

Structural check for multi-token stable pools. Used sparingly since Curve pools are typically dispatched by concrete type in the builder registry.

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

Tuple of all pool tokens.

class degenbot.types.pool_protocols.PoolSimulation¶

Bases: Protocol

Required interface for all pools.

Supports exact-input swap simulation.

property address: degenbot.types.chain.ChecksummedAddress¶

Pool contract address.

class degenbot.types.pool_protocols.StateManageablePool¶

Bases: Protocol

Optional interface for pools with on-chain state management.

Curve and Balancer pools typically don’t implement this.

external_update(update: object) → None¶

Apply an external state update to the pool.

discard_states_before_block(block: int) → None¶

Remove cached states before the given block.

restore_state_before_block(block: int) → None¶

Restore the most recent state before the given block.

class degenbot.types.pool_protocols.TwoTokenSwapCalculation¶

Bases: Protocol

A 2-token pool that can calculate output from input.

token_out is implied by token_in since there are exactly two tokens.

calculate_tokens_out_from_tokens_in(token_in: degenbot.erc20.erc20.Erc20Token, token_in_quantity: int, override_state: degenbot.types.abstract.AbstractPoolState | None = None) → int¶

Calculate output token amount for a given input.

class degenbot.types.pool_protocols.MultiTokenSwapCalculation¶

Bases: Protocol

An N-token pool requiring explicit token_out for swap calculation.

Curve and Balancer pools need token_out specified because they have more than two tokens.

calculate_tokens_out_from_tokens_in(token_in: degenbot.erc20.erc20.Erc20Token, token_out: degenbot.erc20.erc20.Erc20Token, token_in_quantity: int, override_state: degenbot.types.abstract.AbstractPoolState | None = None) → int¶

Calculate output token amount for a given input with explicit token_out.