degenbot.curve.curve_stableswap_liquidity_pool¶

Curve StableSwap liquidity pool implementation.

Implements the Curve StableSwap invariant for V1-style pools including plain pools, metapools, lending pools, and crypto pools.

Module Contents¶

class degenbot.curve.curve_stableswap_liquidity_pool.CurveStableswapPool(*args: Any, **kwargs: Any)¶

Bases: degenbot.curve.stableswap_pool_state.StableswapPoolState, degenbot.types.abstract.AbstractLiquidityPool

CurveStableswapPool class.

type PoolState = CurveStableswapPoolState¶
PRECISION_DECIMALS: int = 18¶
PRECISION: int = 1000000000000000000¶
address: degenbot.types.chain.ChecksummedAddress¶
FEE_DENOMINATOR: int = 10000000000¶
A_PRECISION: int = 100¶
classmethod from_handle(py_pool: degenbot.types.Pool) → Self¶

Wrap a Rust-owned Pool handle as a Python companion.

Single-arg seam (ADR-005): reads every identity field + the stored data-provider trait object off the handle. The cross-pool references (base pool companion + underlying/LP tokens) are recovered from the handle too — the base pool via the Rust go-between curve_base_pool() (same shared BotState, no Python registry), wrapped in a _LazyBasePool that memoises construction.

Returns:

The companion wrapping the handle.

Raises:

DegenbotValueError – If the handle is not a Curve stableswap pool, or its tokens are not registered in the handle’s Bot.

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

Balances.

Read from the Rust core via the Pool handle (ADR-005 slice 11b). Rust BotState is the single source of truth for the mutable balances slot; this getter returns the live tuple.

property state: degenbot.curve.types.CurveStableswapPoolState¶

State.

Built from one atomic Rust snapshot (snapshot_curve() — (balances, block)) so callers see a coherent tuple (no torn read mid-external_update). Mirrors V3/V4’s snapshot_v3() contract.

Raises:

DegenbotValueError – If the Rust snapshot is absent (the pool is not registered in Rust as a Curve pool — unreachable for a companion built over a registered handle).

property update_block: degenbot.types.aliases.BlockNumber¶

Update block (from Rust via the handle).

property requires_io_at_calculation_time: bool¶

Whether this pool may call data_provider during swap calculations.

Returns True for pools that need per-block on-chain data (D, gamma, price_scale, lending rates, admin balances, virtual price for metapools, block timestamps for A ramping). Returns False only for plain pools with static rate multipliers and no A ramping.

external_update(update: degenbot.curve.types.CurveStableswapPoolExternalUpdate) → None¶

Apply an external state update with new balances.

Delegates to the Rust core (Pool.apply_curve_balance_update) which journals the prior balances (genesis-anchor V2-style discipline) and lands the new balances + update_block atomically (ADR-005 slice 11b). The StateCache temporal-navigation layer it used to write is gone — the Rust reorg journal handles rollback now.

Raises:

DegenbotValueError – If the Rust core rejects the update (the pool is not registered as a Curve pool — unreachable for a companion built over a registered handle).

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

Simplified method to calculate addition or reduction in token supply at.

deposit or withdrawal without taking fees into account (but looking at slippage). Needed to prevent front-running, not for precise calculations!

Returns:

The computed integer value.

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

Calc withdraw one coin.

Returns:

The computed value.

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

@notice Calculate the current output dy given input dx.

@dev Index values can be found via the coins public getter method @param i Index value for the coin to send @param j Index value of the coin to recieve @param dx Amount of i being exchanged @return Amount of j predicted.

Reference: https://github.com/curveresearch/notes/blob/main/stableswap.pdf

Delegates to the Rust-owned Pool.curve_get_dy: the I/O orchestration (amp/rates/xp + provider fetches) and the pure dy math both run in the Rust core, so this is a single handle call with no Python provider / cache / calculator on the swap path.

Returns:

The computed integer value.

Raises:

EVMRevertError – See function documentation.

calculate_tokens_out_from_tokens_in(token_in: degenbot.erc20.Erc20Token, token_out: degenbot.erc20.Erc20Token, token_in_quantity: int, override_state: degenbot.curve.types.CurveStableswapPoolState | None = None, block_identifier: degenbot.types.rpc_types.BlockIdentifier | None = None) → int¶

Calculate the expected token OUTPUT for a target INPUT at current pool reserves.

Returns:

The computed integer value.

Raises: