Skip to content

fix: use resolve_supported_network() for consistent CDP network alias mapping#973

Open
octo-patch wants to merge 1 commit intocrestalnetwork:mainfrom
octo-patch:fix/issue-723-cdp-network-alias-mapping
Open

fix: use resolve_supported_network() for consistent CDP network alias mapping#973
octo-patch wants to merge 1 commit intocrestalnetwork:mainfrom
octo-patch:fix/issue-723-cdp-network-alias-mapping

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #723

Problem

get_cdp_network() in intentkit/wallets/cdp.py used a hardcoded string mapping that only accepted canonical network identifiers (e.g., "base-mainnet", "ethereum-mainnet"). However, AGENT_NETWORK_TO_SUPPORTED_NETWORK in intentkit/utils/chain.py supports several additional aliases:

Alias Resolves to
"ethereum" ethereum-mainnet
"polygon" polygon-mainnet
"matic" / "matic-mainnet" polygon-mainnet
"bsc-mainnet" / "binance-mainnet" bnb-mainnet

When an agent's network_id was set to any of these aliases, get_cdp_network() silently fell through to a 400 BadNetworkID error, 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 a SupportedNetwork-keyed dict. This means any alias recognized by chain.py is automatically supported—no separate maintenance required.

Changes

  • intentkit/wallets/cdp.py: refactor get_cdp_network() to normalize via resolve_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.

… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CDP ERC20 Transfers failing due to incomplete network mapping.

1 participant