fix: use resolve_supported_network() for consistent CDP network alias mapping#973
Open
octo-patch wants to merge 1 commit intocrestalnetwork:mainfrom
Open
Conversation
… mapping (fixes crestalnetwork#723) The previous get_cdp_network() used a hardcoded string mapping that only accepted canonical network IDs (e.g., "base-mainnet", "ethereum-mainnet"). This diverged from AGENT_NETWORK_TO_SUPPORTED_NETWORK in chain.py, which supports additional aliases like "ethereum", "polygon", "matic", "bsc-mainnet", and "binance-mainnet". Now get_cdp_network() calls resolve_supported_network() first to normalize the input, then looks up the CDP network name via SupportedNetwork enum. This ensures any alias supported by the chain utility is automatically honoured, preventing 400 BadNetworkID errors for valid but non-canonical network identifiers. Add tests covering canonical names, all recognized aliases, and error cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #723
Problem
get_cdp_network()inintentkit/wallets/cdp.pyused a hardcoded string mapping that only accepted canonical network identifiers (e.g.,"base-mainnet","ethereum-mainnet"). However,AGENT_NETWORK_TO_SUPPORTED_NETWORKinintentkit/utils/chain.pysupports several additional aliases:"ethereum"ethereum-mainnet"polygon"polygon-mainnet"matic"/"matic-mainnet"polygon-mainnet"bsc-mainnet"/"binance-mainnet"bnb-mainnetWhen an agent's
network_idwas set to any of these aliases,get_cdp_network()silently fell through to a400 BadNetworkIDerror, even though the same value was handled correctly everywhere else in the stack.Solution
Replace the hardcoded string map with a call to
resolve_supported_network()(the same normalization function used throughout the codebase), then look up the CDP network name using aSupportedNetwork-keyed dict. This means any alias recognized bychain.pyis automatically supported—no separate maintenance required.Changes
intentkit/wallets/cdp.py: refactorget_cdp_network()to normalize viaresolve_supported_network()before mapping to the CDP network string.tests/wallets/test_cdp_network.py: add unit tests covering all canonical names, all recognized aliases, and error cases (missing network, solana, unknown network).Testing
The new test file covers all cases without requiring a live database or CDP credentials.