degenbot.curve.types¶

Curve-specific type definitions (swap style, metapool enums).

Module Contents¶

class degenbot.curve.types.DVariant(*args, **kwds)¶

Bases: enum.Enum

Which D-calculation formula to use in _get_d.

The original code had 5 address groups selecting different d_func and dp_func pairs. Groups 1 and 3 both use variant_alpha dp but differ on d_func: - Group 1: variant_alpha d + variant_alpha dp - Group 3: standard d + variant_alpha dp

STANDARD¶
VARIANT_ALPHA¶
VARIANT_ALPHA_DP_ALPHA¶
VARIANT_DP_ALPHA¶
VARIANT_BETA_DP¶
VARIANT_GAMMA_DP¶
class degenbot.curve.types.YVariant(*args, **kwds)¶

Bases: enum.Enum

Which Y-calculation formula to use in _get_y.

The original code had two overlapping address sets controlling independent behaviours: Y_VARIANT_GROUP_0 (amp divisor) and Y_VARIANT_GROUP_1 (c/b formula). Since Y_VARIANT_GROUP_0 ⊂ Y_VARIANT_GROUP_1, there are exactly 3 observed combinations, yielding these variants:

STANDARD¶
VARIANT_0¶
VARIANT_1¶
class degenbot.curve.types.YDVariant(*args, **kwds)¶

Bases: enum.Enum

Which Y_D-calculation formula to use in _get_y_d.

STANDARD¶
VARIANT_0¶
class degenbot.curve.types.SwapStyle(*args, **kwds)¶

Bases: enum.Enum

Which computation path to use in get_dy.

Each value identifies a complete swap calculation path differing in rate source, balance source, fee application, and rate conversion. These are not independent axes — each path is a coherent unit.

The variants capture differences in: - How dy is computed (with or without the - 1 subtraction) - When fee is applied (before or after rate conversion) - How rate conversion is applied - What balances are used (pool state, live minus admin, raw)

STANDARD¶
RATE_ADJUSTED¶
RAW_BALANCE¶
CRYPTO¶
LIVE_ADMIN¶
LIVE_ADMIN_DYNAMIC¶
LIVE_ADMIN_DYNAMIC_PRECISION¶
LIVE_ADMIN_ORACLE¶
NO_ONE_FEE_RATE¶
CYTOKEN¶
RATE_ADJUSTED_NO_ONE¶
class degenbot.curve.types.MetapoolRateStyle(*args, **kwds)¶

Bases: enum.Enum

Which rates to use for the metapool branch in get_dy.

STANDARD¶
PRECISION_VP¶
REDEMPTION_VP¶
class degenbot.curve.types.MetapoolUnderlyingStyle(*args, **kwds)¶

Bases: enum.Enum

Which computation path to use in _get_dy_underlying.

STANDARD¶
REDEMPTION¶
PRECISION_VP¶
class degenbot.curve.types.LendingRateStyle(*args, **kwds)¶

Bases: enum.Enum

Which rate-fetching method to use for lending tokens.

Used by get_dy() to select which stored-rate resolution path to call via CurveDataProvider.lending_rates().

NONE¶
CTOKEN¶
YTOKEN¶
CYTOKEN¶
AETH¶
RETH¶
ORACLE¶
class degenbot.curve.types.BasePoolPort¶

Bases: Protocol

The slice of the base-pool surface the metapool DyCalculator needs.

Names the real interface behind the lazy go-between (ADR-005): a metapool’s calc paths call exactly these six members on its base pool — tokens / balances / fee for metadata, and calc_token_amount / get_dy / calc_withdraw_one_coin for delegated computation. Two adapters satisfy it: the production _LazyBasePool (handle → base companion, memoised) and a canned StubBasePool for calculator unit tests (which previously couldn’t exercise .calculate() without standing up a full pool).

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

Base-pool coin companions.

property balances: tuple[int, ...]¶

Base-pool balances.

property fee: int¶

Base-pool swap fee (FEE_DENOMINATOR units).

calc_token_amount(*, amounts: collections.abc.Sequence[int], deposit: bool, block_identifier: degenbot.types.rpc_types.BlockIdentifier | None = None, override_state: CurveStableswapPoolState | None = None) → int¶

Deposit/withdraw token amount (slippage-adjusted).

get_dy(i: int, j: int, dx: int, block_identifier: degenbot.types.rpc_types.BlockIdentifier | None = None, override_state: CurveStableswapPoolState | None = None) → int¶

Output dy for swapping dx of coin i → coin j.

calc_withdraw_one_coin(_token_amount: int, i: int, block_identifier: degenbot.types.rpc_types.BlockIdentifier | None = None) → tuple[int, ...]¶

Withdraw a single coin from a deposit.

class degenbot.curve.types.DyCalculationInputs¶

Pre-resolved data for a single dy calculation.

Constructed by CurveStableswapPool.get_dy() before delegating to the injected DyCalculator. The calculator reads only from this object — never from the pool directly. All I/O, cache lookups, and rate resolution happen before this object is created.

PRECISION: int¶
FEE_DENOMINATOR: int¶
fee: int¶
n_coins: int¶
balances: tuple[int, ...]¶
rate_multipliers: tuple[int, ...]¶
precision_multipliers: tuple[int, ...]¶
offpeg_fee_multiplier: int¶
fee_gamma: int¶
mid_fee: int¶
out_fee: int¶
address: degenbot.types.chain.ChecksummedAddress¶
resolved_rates: tuple[int, ...]¶
xp: tuple[int, ...]¶
block_number: int¶
block_timestamp: int¶
amp: int¶
d: int | None = None¶
gamma: int | None = None¶
price_scale: tuple[int, ...] | None = None¶
live_balances: tuple[int, ...] | None = None¶
admin_balances: tuple[int, ...] | None = None¶
effective_balances: tuple[int, ...] | None = None¶
virtual_price: int | None = None¶
scaled_redemption_price: int | None = None¶
base_pool: BasePoolPort | None = None¶
d_variant: DVariant¶
y_variant: YVariant¶
yd_variant: YDVariant¶
a_precision: int = 100¶
class degenbot.curve.types.CurveDataProvider¶

Bases: Protocol

On-chain data access for a Curve StableSwap pool.

Consolidates the 13 individual fetcher callbacks into a single interface. The pool checks provider availability before calling; a provider that doesn’t support a method should raise MissingCurveData.

All methods accepting block_number may use block-specific data.

virtual_price(block_number: int) → int¶

Return virtual price.

base_virtual_price(block_number: int) → int¶

Return base virtual price.

base_cache_updated(block_number: int) → int¶

Return base cache updated.

admin_balances(block_number: int) → tuple[int, ...]¶

Return admin balances.

d(block_number: int) → int¶

Return the D invariant value.

gamma(block_number: int) → int¶

Return the gamma parameter.

price_scale(block_number: int) → tuple[int, ...]¶

Return the price scale values.

block_timestamp(block_number: int) → int¶

Return the block timestamp.

block_number() → int¶

Return block number.

token_balance(token_address: str, holder_address: str, block_number: int) → int¶

Return token balance.

token_total_supply(token_address: str, block_number: int) → int¶

Return token total supply.

lending_rates(block_number: int) → tuple[int, ...]¶

Return lending rates.

redemption_price(block_number: int) → int¶

Return redemption price.

class degenbot.curve.types.CurveStableswapPoolState¶

Bases: degenbot.types.abstract.AbstractPoolState

CurveStableswapPoolState class.

balances: tuple[int, ...]¶
base: CurveStableswapPoolState | None = None¶
class degenbot.curve.types.CurveStableswapPoolExternalUpdate¶

CurveStableswapPoolExternalUpdate class.

block_number: degenbot.types.aliases.BlockNumber¶
balances: tuple[int, ...]¶
class degenbot.curve.types.CurveStableswapPoolSimulationResult¶

CurveStableswapPoolSimulationResult class.

amount0_delta: int¶
amount1_delta: int¶
current_state: CurveStableswapPoolState¶