degenbot.curve.types ==================== .. py:module:: degenbot.curve.types .. autoapi-nested-parse:: Curve-specific type definitions (swap style, metapool enums). Module Contents --------------- .. py:class:: DVariant(*args, **kwds) Bases: :py:obj:`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 .. py:attribute:: STANDARD .. py:attribute:: VARIANT_ALPHA .. py:attribute:: VARIANT_ALPHA_DP_ALPHA .. py:attribute:: VARIANT_DP_ALPHA .. py:attribute:: VARIANT_BETA_DP .. py:attribute:: VARIANT_GAMMA_DP .. py:class:: YVariant(*args, **kwds) Bases: :py:obj:`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: .. py:attribute:: STANDARD .. py:attribute:: VARIANT_0 .. py:attribute:: VARIANT_1 .. py:class:: YDVariant(*args, **kwds) Bases: :py:obj:`enum.Enum` Which Y_D-calculation formula to use in _get_y_d. .. py:attribute:: STANDARD .. py:attribute:: VARIANT_0 .. py:class:: SwapStyle(*args, **kwds) Bases: :py:obj:`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) .. py:attribute:: STANDARD .. py:attribute:: RATE_ADJUSTED .. py:attribute:: RAW_BALANCE .. py:attribute:: CRYPTO .. py:attribute:: LIVE_ADMIN .. py:attribute:: LIVE_ADMIN_DYNAMIC .. py:attribute:: LIVE_ADMIN_DYNAMIC_PRECISION .. py:attribute:: LIVE_ADMIN_ORACLE .. py:attribute:: NO_ONE_FEE_RATE .. py:attribute:: CYTOKEN .. py:attribute:: RATE_ADJUSTED_NO_ONE .. py:class:: MetapoolRateStyle(*args, **kwds) Bases: :py:obj:`enum.Enum` Which rates to use for the metapool branch in get_dy. .. py:attribute:: STANDARD .. py:attribute:: PRECISION_VP .. py:attribute:: REDEMPTION_VP .. py:class:: MetapoolUnderlyingStyle(*args, **kwds) Bases: :py:obj:`enum.Enum` Which computation path to use in _get_dy_underlying. .. py:attribute:: STANDARD .. py:attribute:: REDEMPTION .. py:attribute:: PRECISION_VP .. py:class:: LendingRateStyle(*args, **kwds) Bases: :py:obj:`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(). .. py:attribute:: NONE .. py:attribute:: CTOKEN .. py:attribute:: YTOKEN .. py:attribute:: CYTOKEN .. py:attribute:: AETH .. py:attribute:: RETH .. py:attribute:: ORACLE .. py:class:: BasePoolPort Bases: :py:obj:`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). .. py:property:: tokens :type: tuple[degenbot.erc20.Erc20Token, ...] Base-pool coin companions. .. py:property:: balances :type: tuple[int, ...] Base-pool balances. .. py:property:: fee :type: int Base-pool swap fee (``FEE_DENOMINATOR`` units). .. py:method:: 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). .. py:method:: 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``. .. py:method:: 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. .. py:class:: 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. .. py:attribute:: PRECISION :type: int .. py:attribute:: FEE_DENOMINATOR :type: int .. py:attribute:: fee :type: int .. py:attribute:: n_coins :type: int .. py:attribute:: balances :type: tuple[int, ...] .. py:attribute:: rate_multipliers :type: tuple[int, ...] .. py:attribute:: precision_multipliers :type: tuple[int, ...] .. py:attribute:: offpeg_fee_multiplier :type: int .. py:attribute:: fee_gamma :type: int .. py:attribute:: mid_fee :type: int .. py:attribute:: out_fee :type: int .. py:attribute:: address :type: degenbot.types.chain.ChecksummedAddress .. py:attribute:: resolved_rates :type: tuple[int, ...] .. py:attribute:: xp :type: tuple[int, ...] .. py:attribute:: block_number :type: int .. py:attribute:: block_timestamp :type: int .. py:attribute:: amp :type: int .. py:attribute:: d :type: int | None :value: None .. py:attribute:: gamma :type: int | None :value: None .. py:attribute:: price_scale :type: tuple[int, ...] | None :value: None .. py:attribute:: live_balances :type: tuple[int, ...] | None :value: None .. py:attribute:: admin_balances :type: tuple[int, ...] | None :value: None .. py:attribute:: effective_balances :type: tuple[int, ...] | None :value: None .. py:attribute:: virtual_price :type: int | None :value: None .. py:attribute:: scaled_redemption_price :type: int | None :value: None .. py:attribute:: base_pool :type: BasePoolPort | None :value: None .. py:attribute:: d_variant :type: DVariant .. py:attribute:: y_variant :type: YVariant .. py:attribute:: yd_variant :type: YDVariant .. py:attribute:: a_precision :type: int :value: 100 .. py:class:: CurveDataProvider Bases: :py:obj:`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. .. py:method:: virtual_price(block_number: int) -> int Return virtual price. .. py:method:: base_virtual_price(block_number: int) -> int Return base virtual price. .. py:method:: base_cache_updated(block_number: int) -> int Return base cache updated. .. py:method:: admin_balances(block_number: int) -> tuple[int, ...] Return admin balances. .. py:method:: d(block_number: int) -> int Return the D invariant value. .. py:method:: gamma(block_number: int) -> int Return the gamma parameter. .. py:method:: price_scale(block_number: int) -> tuple[int, ...] Return the price scale values. .. py:method:: block_timestamp(block_number: int) -> int Return the block timestamp. .. py:method:: block_number() -> int Return block number. .. py:method:: token_balance(token_address: str, holder_address: str, block_number: int) -> int Return token balance. .. py:method:: token_total_supply(token_address: str, block_number: int) -> int Return token total supply. .. py:method:: lending_rates(block_number: int) -> tuple[int, ...] Return lending rates. .. py:method:: redemption_price(block_number: int) -> int Return redemption price. .. py:class:: CurveStableswapPoolState Bases: :py:obj:`degenbot.types.abstract.AbstractPoolState` CurveStableswapPoolState class. .. py:attribute:: balances :type: tuple[int, ...] .. py:attribute:: base :type: CurveStableswapPoolState | None :value: None .. py:class:: CurveStableswapPoolExternalUpdate CurveStableswapPoolExternalUpdate class. .. py:attribute:: block_number :type: degenbot.types.aliases.BlockNumber .. py:attribute:: balances :type: tuple[int, ...] .. py:class:: CurveStableswapPoolSimulationResult CurveStableswapPoolSimulationResult class. .. py:attribute:: amount0_delta :type: int .. py:attribute:: amount1_delta :type: int .. py:attribute:: current_state :type: CurveStableswapPoolState