degenbot.registry.pool_type¶
Unified pool type registry.
Identity (family, variant, kind) is auto-derived from the class hierarchy and class attributes. Deployment data (chain_id, factory, deployer, init_hash) is carried by the registration call.
Module Contents¶
- class degenbot.registry.pool_type.PoolDeploymentData¶
Per-chain deployment data for a pool factory.
- factory_address: degenbot.types.chain.ChecksummedAddress¶
- class degenbot.registry.pool_type.PoolRegistration¶
Typed registration request for
PoolTypeRegistry.register().family/variantoverride the class-derived identity when the class shape misleads_derive_family()(Balancer) or a collapsed subclass hierarchy needs an explicit DBkind(ADR-005 slice 7 step 4b).dex_identitycarries the canonical DEX preset when one exists.implementation_addressis the EIP-1167 clone master for factories that use one.- chain_id: degenbot.types.aliases.ChainId¶
- family: degenbot.types.pool_type.PoolFamily | None = None¶
- class degenbot.registry.pool_type.PoolTypeRegistry¶
Unified registry mapping (chain_id, factory_address) → pool type identity.
Each DEX module registers its pool subclass at import time via register(). Builders consult this registry to select the concrete class and its deployment data.
Family, variant, and kind are auto-derived from the class hierarchy and the class’s variant attribute.
Public API for external callers¶
Library users who want to register a custom DEX pool class should:
Subclass a pool shape protocol (
ConstantProductPool,ConcentratedLiquidityPool, orStableswapPool). This is typically done by inheriting from an existing pool class that already satisfies the protocol (e.g.,UniswapV2Pool).Add a
variant: ClassVar[str | None] = "your_dex_name"class attribute. Use the bare DEX name without a_v2/_v3suffix — the suffix is derived automatically from the family.If the pool has a non-standard constructor (e.g. requires chain fetches for extra parameters), add a builder method (e.g.
_build_aerodrome_v2,_build_camelot) on the appropriate pool builder class. The builder will be dispatched viaissubclasschecks in thebuild()method.Call
pool_type_registry.register()with the class, chain ID, factory address, and optional deployment data.
Example:
from degenbot.registry import pool_type_registry from degenbot.uniswap.v2_liquidity_pool import UniswapV2Pool class MyCustomPool(UniswapV2Pool): variant: ClassVar[str | None] = "my_dex" pool_type_registry.register( PoolRegistration( pool_class=MyCustomPool, chain_id=1, factory_address="0x...", pool_init_hash="0x...", ) )
After registration,
Bot.build_pool()will automatically selectMyCustomPoolfor any pool whosefactory()returns the registered address on the given chain.- register(registration: PoolRegistration) None¶
Register a pool class for a specific (chain_id, factory) deployment.
Identity (family, variant, kind) is auto-derived from the class unless overridden on the request. Deployment data (chain_id, factory, deployer, init_hash) is stored alongside for lookup.
- Parameters:
registration – The typed registration request; see
PoolRegistrationfor field semantics.- Raises:
ValueError – If the factory is already registered for the given chain.
- unregister(*, chain_id: degenbot.types.aliases.ChainId, factory_address: str) None¶
Remove a previously-registered (chain_id, factory) entry.
Used by tests to clean up after calling
register()so the module-level singleton is not permanently polluted.- Raises:
KeyError – If no registration exists for the given key.
- set_default_v2_class(pool_class: type[degenbot.types.pool_protocols.ConstantProductPool]) None¶
Set the default V2 pool class when no factory-specific mapping exists.
- set_default_v3_class(pool_class: type[degenbot.types.pool_protocols.ConcentratedLiquidityPool]) None¶
Set the default V3 pool class when no factory-specific mapping exists.
- has_registration(chain_id: degenbot.types.aliases.ChainId, factory_address: str) bool¶
Whether a pool class is registered for (chain_id, factory).
- Returns:
True if a registration exists, False otherwise.
- get_class(chain_id: degenbot.types.aliases.ChainId, factory_address: str) type[degenbot.types.abstract.liquidity_pool.AbstractLiquidityPool] | None¶
Get the pool class for (chain_id, factory).
Returns None if no specific registration exists and no default is set.
- Returns:
The pool class, or None if not found.
- get_v2_class(chain_id: degenbot.types.aliases.ChainId, factory_address: str) type[degenbot.types.pool_protocols.ConstantProductPool] | None¶
Get the V2 pool class for (chain_id, factory), with default fallback.
- Returns:
The V2 pool class, or None if not found.
- get_v3_class(chain_id: degenbot.types.aliases.ChainId, factory_address: str) type[degenbot.types.pool_protocols.ConcentratedLiquidityPool] | None¶
Get the V3 pool class for (chain_id, factory), with default fallback.
- Returns:
The V3 pool class, or None if not found.
- get_descriptor(chain_id: degenbot.types.aliases.ChainId, factory_address: str) degenbot.types.pool_type.PoolTypeDescriptor | None¶
Get the PoolTypeDescriptor for (chain_id, factory).
- Returns:
The descriptor, or None if not found.
- get_v2_identity(chain_id: degenbot.types.aliases.ChainId, factory_address: str) degenbot.types.DexIdentity | None¶
Get the DexIdentity preset for (chain_id, factory), or None.
Returns None if no registration exists OR if the registration was made without a
dex_identity(e.g. Aerodrome V2 — deferred per TODO-e30504ed).- Returns:
The DexIdentity preset, or None if not found / not set.
- get_deployment(chain_id: degenbot.types.aliases.ChainId, factory_address: str) PoolDeploymentData | None¶
Get the deployment data for (chain_id, factory).
- Returns:
The deployment data, or None if not found.
- get_descriptor_by_kind(kind: str) degenbot.types.pool_type.PoolTypeDescriptor | None¶
Get a PoolTypeDescriptor by its kind string.
Used for DB lookups where the kind is known but the factory address is not. When multiple deployments share a kind, returns the descriptor from the last registration.
- Returns:
The descriptor, or None if not found.
- property registrations: dict[tuple[degenbot.types.aliases.ChainId, str], tuple[type[degenbot.types.abstract.liquidity_pool.AbstractLiquidityPool], degenbot.types.pool_type.PoolTypeDescriptor, PoolDeploymentData]]¶
A copy of all registrations.
- degenbot.registry.pool_type.pool_type_registry¶