Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/coinbase-agentkit/changelog.d/+2769d1c2.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed network support in CDP wallet providers
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def _send_transaction():
to=to,
value=value_wei,
),
network=self._network.network_id,
network=self._get_cdp_sdk_network(),
)

return self._run_async(_send_transaction())
Expand Down Expand Up @@ -200,7 +200,7 @@ async def _send_transaction():
value=transaction.get("value", 0),
data=transaction.get("data", "0x"),
),
network=self._network.network_id,
network=self._get_cdp_sdk_network(),
)

return self._run_async(_send_transaction())
Expand Down Expand Up @@ -298,7 +298,7 @@ async def _sign_transaction():
value=transaction.get("value", 0),
data=transaction.get("data", "0x"),
),
network=self._network.network_id,
network=self._get_cdp_sdk_network(),
)

return self._run_async(_sign_transaction())
Expand Down Expand Up @@ -330,6 +330,31 @@ async def _create_account(self, client: CdpClient):
async with client as cdp:
return await cdp.evm.create_account(idempotency_key=self._idempotency_key)

def _get_cdp_sdk_network(self) -> str:
"""Convert the internal network ID to the format expected by the CDP SDK.

Returns:
str: The network ID in CDP SDK format

Raises:
ValueError: If the network is not supported by CDP SDK

"""
network_mapping = {
"base-sepolia": "base-sepolia",
"base-mainnet": "base",
"ethereum-mainnet": "ethereum",
"ethereum-sepolia": "ethereum-sepolia",
"polygon-mainnet": "polygon",
"arbitrum-mainnet": "arbitrum",
"optimism-mainnet": "optimism",
}

if self._network.network_id not in network_mapping:
raise ValueError(f"Unsupported network for CDP SDK: {self._network.network_id}")

return network_mapping[self._network.network_id]

def _run_async(self, coroutine):
"""Run an async coroutine synchronously.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ def get_client(self) -> CdpClient:
wallet_secret=self._wallet_secret,
)

def _get_cdp_sdk_network(self) -> str:
"""Convert the internal network ID to the format expected by the CDP SDK.

Returns:
str: The network ID in CDP SDK format

Raises:
ValueError: If the network is not supported by CDP SDK

"""
network_mapping = {
"base-sepolia": "base-sepolia",
"base-mainnet": "base",
"ethereum-mainnet": "ethereum",
"ethereum-sepolia": "ethereum-sepolia",
"polygon-mainnet": "polygon",
"arbitrum-mainnet": "arbitrum",
"optimism-mainnet": "optimism",
}

if self._network.network_id not in network_mapping:
raise ValueError(f"Unsupported network for smart wallets: {self._network.network_id}")

return network_mapping[self._network.network_id]

def _run_async(self, coroutine):
"""Run an async coroutine synchronously.

Expand Down Expand Up @@ -231,7 +256,7 @@ async def _send_user_operation():

user_operation = await cdp.evm.send_user_operation(
smart_account=smart_account,
network=self._network.network_id,
network=self._get_cdp_sdk_network(),
calls=[EncodedCall(to=to, value=value_wei, data="0x")],
paymaster_url=self._paymaster_url,
)
Expand Down Expand Up @@ -289,7 +314,7 @@ async def _send_user_operation():
smart_account = await self._get_smart_account(cdp)
user_operation = await cdp.evm.send_user_operation(
smart_account=smart_account,
network=self._network.network_id,
network=self._get_cdp_sdk_network(),
calls=[
EncodedCall(
to=transaction["to"],
Expand Down Expand Up @@ -376,9 +401,7 @@ async def _sign_typed_data():
types=types,
primary_type=primary_type,
message=message,
network="base"
if self.get_network().network_id == "base-mainnet"
else self.get_network().network_id,
network=self._get_cdp_sdk_network(),
)

try:
Expand Down Expand Up @@ -420,7 +443,7 @@ async def _send_user_operation():
smart_account = await self._get_smart_account(cdp)
user_operation = await cdp.evm.send_user_operation(
smart_account=smart_account,
network=self._network.network_id,
network=self._get_cdp_sdk_network(),
calls=calls,
paymaster_url=self._paymaster_url,
)
Expand Down
5 changes: 5 additions & 0 deletions typescript/.changeset/silly-bees-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase/agentkit": patch
---

Expanded network support for CDP wallet providers
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ import { Network, NETWORK_ID_TO_CHAIN_ID, NETWORK_ID_TO_VIEM_CHAIN } from "../ne
import { EvmWalletProvider } from "./evmWalletProvider";
import { WalletProviderWithClient, CdpWalletProviderConfig } from "./cdpShared";

/**
* Supported network types for CDP SDK EVM transactions
*/
type CdpEvmNetwork =
| "base"
| "base-sepolia"
| "ethereum"
| "ethereum-sepolia"
| "polygon"
| "arbitrum"
| "optimism";

interface ConfigureCdpEvmWalletProviderWithWalletOptions {
/**
* The CDP client of the wallet.
Expand Down Expand Up @@ -299,17 +311,27 @@ export class CdpEvmWalletProvider extends EvmWalletProvider implements WalletPro
/**
* Converts the internal network ID to the format expected by the CDP SDK.
*
* @returns The network ID in CDP SDK format ("base-sepolia" or "base")
* @returns The network ID in CDP SDK format
* @throws Error if the network is not supported
*/
#getCdpSdkNetwork(): "base-sepolia" | "base" {
#getCdpSdkNetwork(): CdpEvmNetwork {
switch (this.#network.networkId) {
case "base-sepolia":
return "base-sepolia";
case "base-mainnet":
return "base";
case "ethereum-mainnet":
return "ethereum";
case "ethereum-sepolia":
return "ethereum-sepolia";
case "polygon-mainnet":
return "polygon";
case "arbitrum-mainnet":
return "arbitrum";
case "optimism-mainnet":
return "optimism";
default:
throw new Error(`Unsupported network: ${this.#network.networkId}`);
throw new Error(`Unsupported network for CDP SDK: ${this.#network.networkId}`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import { Network, NETWORK_ID_TO_CHAIN_ID, NETWORK_ID_TO_VIEM_CHAIN } from "../ne
import { EvmWalletProvider } from "./evmWalletProvider";
import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpShared";

/**
* Supported network types for CDP SDK smart wallet operations
*/
type CdpSmartWalletNetwork =
| "base"
| "base-sepolia"
| "ethereum"
| "ethereum-sepolia"
| "polygon"
| "arbitrum"
| "optimism";

interface ConfigureCdpSmartWalletProviderWithWalletOptions {
/**
* The CDP client of the wallet.
Expand Down Expand Up @@ -356,15 +368,25 @@ export class CdpSmartWalletProvider extends EvmWalletProvider implements WalletP
/**
* Converts the internal network ID to the format expected by the CDP SDK.
*
* @returns The network ID in CDP SDK format ("base-sepolia" or "base")
* @returns The network ID in CDP SDK format
* @throws Error if the network is not supported
*/
#getCdpSdkNetwork(): "base-sepolia" | "base" {
#getCdpSdkNetwork(): CdpSmartWalletNetwork {
switch (this.#network.networkId) {
case "base-sepolia":
return "base-sepolia";
case "base-mainnet":
return "base";
case "ethereum-mainnet":
return "ethereum";
case "ethereum-sepolia":
return "ethereum-sepolia";
case "polygon-mainnet":
return "polygon";
case "arbitrum-mainnet":
return "arbitrum";
case "optimism-mainnet":
return "optimism";
default:
throw new Error(`Unsupported network for smart wallets: ${this.#network.networkId}`);
}
Expand Down
Loading