degenbot.types ============== .. py:module:: degenbot.types .. autoapi-nested-parse:: Shared types: AddressComparable, state caches, pool enums, and aliases. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/degenbot/types/abstract/index /autoapi/degenbot/types/address_comparable/index /autoapi/degenbot/types/aliases/index /autoapi/degenbot/types/chain/index /autoapi/degenbot/types/concrete/index /autoapi/degenbot/types/pool_protocols/index /autoapi/degenbot/types/pool_type/index /autoapi/degenbot/types/rpc_types/index Package Contents ---------------- .. py:class:: AddressComparable Mixin providing address-based comparison, ordering, and hashing. Any on-chain entity identified by a ChecksummedAddress can inherit from this to get consistent equality, ordering, and hashing by address. .. py:attribute:: address :type: degenbot._ffi.ChecksummedAddress .. py:class:: BoundedCache[KT, VT](max_items: int) Bases: :py:obj:`collections.OrderedDict`\ [\ :py:obj:`KT`\ , :py:obj:`VT`\ ] A cache holding key-value pairs, tracked by entry order. The cache automatically removes old. items if the number of items would exceed the maximum number of entries set by `max_items`. Setting a value at an existing key will overwrite that value without affecting ordering. .. py:attribute:: max_items .. py:method:: copy() -> Self Copy. :returns: The computed value. .. py:class:: KeyedDefaultDict[KT, VT](default_factory: collections.abc.Callable[[KT], VT]) Bases: :py:obj:`collections.defaultdict`\ [\ :py:obj:`KT`\ , :py:obj:`VT`\ ] A modified defaultdict that passes the key to default_factory at runtime and records it. This differs from the defaultdict behavior, which calls default_factory with no arguments. .. py:class:: MultiTokenSwapCalculation Bases: :py:obj:`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. .. py:method:: 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. .. py:class:: PoolSimulation Bases: :py:obj:`Protocol` Required interface for all pools. Supports exact-input swap simulation. .. py:property:: address :type: degenbot.types.chain.ChecksummedAddress Pool contract address. .. py:class:: StateManageablePool Bases: :py:obj:`Protocol` Optional interface for pools with on-chain state management. Curve and Balancer pools typically don't implement this. .. py:method:: external_update(update: object) -> None Apply an external state update to the pool. .. py:method:: discard_states_before_block(block: int) -> None Remove cached states before the given block. .. py:method:: restore_state_before_block(block: int) -> None Restore the most recent state before the given block. .. py:class:: TwoTokenSwapCalculation Bases: :py:obj:`Protocol` A 2-token pool that can calculate output from input. token_out is implied by token_in since there are exactly two tokens. .. py:method:: 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.