degenbot.builders.balancer_builder_base ======================================= .. py:module:: degenbot.builders.balancer_builder_base .. autoapi-nested-parse:: Balancer builder base class and shared data types. Module Contents --------------- .. py:class:: DecodedPoolId Result of decoding a 32-byte Balancer pool ID. .. py:attribute:: pool_address :type: str .. py:attribute:: specialization :type: int .. py:attribute:: nonce :type: int .. py:class:: VaultTokensResult Result of decoding Vault.getPoolTokens() response. .. py:attribute:: tokens :type: list[str] .. py:attribute:: balances :type: list[int] .. py:attribute:: last_change_block :type: int .. py:class:: BalancerBuilderBase Shared helpers for Balancer pool builders. Sync and async builders call these @staticmethod helpers without duplicating decode/extract logic. I/O helpers take a BotIo parameter — callers pass the io they receive. .. py:attribute:: INVARIANT_V1 :value: 1 .. py:attribute:: INVARIANT_V2 :value: 2 .. py:method:: pow_version_to_rust(pow_version: degenbot.balancer.libraries.constants.PowVersion | int) -> int :staticmethod: Map a ``PowVersion`` enum (or raw int) → the ``u8`` discriminant Rust stores. The Rust core (``register_balancer_weighted_pool``, ADR-005 slice 12a) carries ``PowVersion`` as an opaque ``u8`` (V1=1 / V2=2) for the future Rust ``WeightedMath`` port (ADR-005 slice 12e). Not consumed by slice 12b's companion — the Python companion keeps its own ``PowVersion`` for legacy builder compatibility. :returns: The computed value. .. py:method:: decode_pool_id(raw: bytes) -> DecodedPoolId :staticmethod: Decode a 32-byte pool ID into typed components. :returns: The computed value. .. py:method:: decode_vault_tokens(raw: bytes) -> VaultTokensResult :staticmethod: Decode getPoolTokens() response. :returns: The computed value. .. py:method:: detect_bpt_index(token_addresses: list[str] | tuple[str, ...], pool_address: str) -> int | None :staticmethod: Detect the BPT index for ComposableStablePools. Heuristic: the token whose address matches the pool address is BPT. Returns None for MetaStablePools (no BPT in token list). :returns: The computed value. .. py:method:: resolve_invariant_version(*, specialization: int, override: int | None = None) -> int :staticmethod: Determine which StableMath invariant version to use. specialization comes from the decoded pool ID: - 0 (General): most likely ComposableStablePool → INVARIANT_V1 - 1 (MinimalSwapInfo): most likely MetaStablePool → INVARIANT_V2 - 2 (TwoToken): older WeightedPool2Tokens → not a stable pool The override parameter from BuildPoolRequest.invariant_version takes precedence over heuristics. :returns: The computed value.