degenbot.builders.balancer_builder_base¶

Balancer builder base class and shared data types.

Module Contents¶

class degenbot.builders.balancer_builder_base.DecodedPoolId¶

Result of decoding a 32-byte Balancer pool ID.

pool_address: str¶
specialization: int¶
nonce: int¶
class degenbot.builders.balancer_builder_base.VaultTokensResult¶

Result of decoding Vault.getPoolTokens() response.

tokens: list[str]¶
balances: list[int]¶
last_change_block: int¶
class degenbot.builders.balancer_builder_base.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.

INVARIANT_V1 = 1¶
INVARIANT_V2 = 2¶
static pow_version_to_rust(pow_version: degenbot.balancer.libraries.constants.PowVersion | int) → int¶

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.

static decode_pool_id(raw: bytes) → DecodedPoolId¶

Decode a 32-byte pool ID into typed components.

Returns:

The computed value.

static decode_vault_tokens(raw: bytes) → VaultTokensResult¶

Decode getPoolTokens() response.

Returns:

The computed value.

static detect_bpt_index(token_addresses: list[str] | tuple[str, ...], pool_address: str) → int | None¶

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.

static resolve_invariant_version(*, specialization: int, override: int | None = None) → int¶

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.