degenbot.curve¶
Curve StableSwap pools, trackers, and simulation types.
Submodules¶
Package Contents¶
- class degenbot.curve.CurveStableswapPool(*args: Any, **kwargs: Any)¶
Bases:
degenbot.curve.stableswap_pool_state.StableswapPoolState,degenbot.types.abstract.AbstractLiquidityPoolCurveStableswapPool class.
- type PoolState = CurveStableswapPoolState¶
- classmethod from_handle(py_pool: degenbot.types.Pool) Self¶
Wrap a Rust-owned
Poolhandle 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 sharedBotState, no Python registry), wrapped in a_LazyBasePoolthat 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
Poolhandle (ADR-005 slice 11b). RustBotStateis the single source of truth for the mutablebalancesslot; 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’ssnapshot_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_blockatomically (ADR-005 slice 11b). TheStateCachetemporal-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:
DegenbotValueError – See function documentation.
InvalidSwapInputAmount – See function documentation.
NoLiquidity – See function documentation.
- class degenbot.curve.CurveStableswapPoolTracker(*, bot: degenbot.bot.Bot, chain_id: degenbot.types.aliases.ChainId | None = None)¶
Bases:
degenbot.types.abstract.AbstractPoolTracker[degenbot.curve.curve_stableswap_liquidity_pool.CurveStableswapPool]Manages Curve StableSwap pool instances.
Tracks Curve pools by address, delegates construction to Bot.build_pool(), and supports registry-based discovery.
- get_pool(pool_address: degenbot.types.chain.ChecksummedAddress | str, *, silent: bool = False) degenbot.curve.curve_stableswap_liquidity_pool.CurveStableswapPool¶
Get a Curve pool from its address.
If the pool is already tracked, that instance is returned. If the pool is in the bot’s pool registry, it is tracked and returned. Otherwise, a new pool is built via Bot.build_pool().
- Returns:
The computed value.
- Raises:
PoolCreationFailed – See function documentation.
PoolNotAssociated – See function documentation.
- get_pools_for_token(token_address: degenbot.types.chain.ChecksummedAddress | str) list[degenbot.curve.curve_stableswap_liquidity_pool.CurveStableswapPool]¶
Return all tracked pools that contain the given token.
- Returns:
A list of results.
- class degenbot.curve.CurveStableswapPoolSimulationResult¶
CurveStableswapPoolSimulationResult class.
- current_state: CurveStableswapPoolState¶
- class degenbot.curve.CurveStableswapPoolState¶
Bases:
degenbot.types.abstract.AbstractPoolStateCurveStableswapPoolState class.
- base: CurveStableswapPoolState | None = None¶