degenbot.provider.factory¶
Provider construction over a cascade-resolved endpoint (ADR-062 D8).
The canonical chain-bound URL-to-provider factory. The endpoint and the chain
both come from the installed typed config, and the chain binding itself is the
Rust core’s: the factory hands the resolved chain_id to the provider and the
core reads eth_chainId once at construction, refusing a misconfigured
endpoint before any pool/token I/O runs. A Rust consumer that constructs a
provider directly gets the same refusal (see
degenbot_rpc::provider::AlloyProvider::for_chain). What is left here is
translating the core’s refusal into this package’s error hierarchy.
Lives in degenbot.provider (the lib layer) so both Bot.__init__ and the
CLI can reach it without a lib->cli reverse dependency.
Module Contents¶
- exception degenbot.provider.factory.ChainIdentityMismatchError¶
Bases:
degenbot.exceptions.base.DegenbotValueError,ValueErrorThe core’s chain-binding refusal, re-homed into this package’s hierarchy.
The check is the core’s invariant; only the error class is re-homed here. It stays a
ValueErroras well as aDegenbotValueError, so a caller that already handled a misconfigured endpoint keeps catching it exactly as it caught the core’s own refusal.
- degenbot.provider.factory.get_provider_from_config(*, chain_id: int | str | None = None, node: str | None = None, resolve_uri: collections.abc.Callable[..., str] = resolve_http_rpc_uri, provider_factory: collections.abc.Callable[..., degenbot.provider.sync.AlloyProvider] | None = None, chain_mismatch_error: type[degenbot.provider.ChainMismatchError] = ChainMismatchError) degenbot.provider.sync.AlloyProvider¶
Build a chain-bound
AlloyProviderfor the session chain.The endpoint resolves through the request scope of the four-layer cascade and the chain through the chain-id cascade, both from the installed typed config;
chain_id/nodeare the explicit override layer when given.The constructed provider is BOUND to that chain: the Rust core verifies the endpoint’s
eth_chainIdonce, and its refusal is translated into aDegenbotValueErrorhere.resolve_uri/provider_factory/chain_mismatch_errorare the DI seams (tests inject a recording resolver, a stand-in constructor, and a constructible stand-in for the PyO3 refusal class); omitted kwargs keep the production bindings.- Parameters:
chain_id – The explicit chain override; resolved from the config layers when absent.
node – The explicit endpoint override, classified by its own value.
resolve_uri – The endpoint resolver called as
resolve_uri(session_chain_id, node=node).provider_factory – The provider constructor called as
provider_factory(endpoint, chain_id=session_chain_id).chain_mismatch_error – The exception class the core’s refusal is caught as before re-homing.
- Returns:
A chain-bound AlloyProvider over the resolved RPC endpoint.
- Raises:
ChainIdentityMismatchError – When the endpoint serves another chain than the session targets. It is both a
DegenbotValueErrorand aValueError.
- async degenbot.provider.factory.get_async_provider_from_config(*, chain_id: int | str | None = None, node: str | None = None, resolve_uri: collections.abc.Callable[..., str] = resolve_http_rpc_uri, provider_factory: collections.abc.Callable[..., Any] | None = None, chain_mismatch_error: type[degenbot.provider.ChainMismatchError] = ChainMismatchError) degenbot.provider.async_provider.AsyncAlloyProvider¶
Build a chain-bound
AsyncAlloyProviderfor the session chain.Async counterpart of
get_provider_from_config(): the same resolution, the same core check, awaited on the caller’s event loop. The DI seams are the sync factory’s; an omittedprovider_factoryresolves toAsyncAlloyProvider.create.- Parameters:
chain_id – The explicit chain override; resolved from the config layers when absent.
node – The explicit endpoint override, classified by its own value.
resolve_uri – The endpoint resolver called as
resolve_uri(session_chain_id, node=node).provider_factory – The awaited provider constructor called as
provider_factory(endpoint, chain_id=session_chain_id).chain_mismatch_error – The exception class the core’s refusal is caught as before re-homing.
- Returns:
A chain-bound AsyncAlloyProvider over the resolved RPC endpoint.
- Raises:
ChainIdentityMismatchError – When the endpoint serves another chain than the session targets. It is both a
DegenbotValueErrorand aValueError.