Skip to content

Commit c6dea84

Browse files
authored
feat: upgrade cdp-sdk (#777)
1 parent 38d763c commit c6dea84

File tree

41 files changed

+6388
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6388
-140
lines changed

python/coinbase-agentkit/README.md

Lines changed: 136 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,36 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
77
- [Getting Started](#getting-started)
88
- [Installation](#installation)
99
- [Usage](#usage)
10-
- [Create an AgentKit instance](#create-an-agentkit-instance)
11-
- [Create an AgentKit instance with a specified wallet provider](#create-an-agentkit-instance-with-a-specified-wallet-provider)
12-
- [Create an AgentKit instance with specified action providers](#create-an-agentkit-instance-with-specified-action-providers)
13-
- [Use with a framework extension (e.g., LangChain + OpenAI)](#use-with-a-framework-extension)
10+
- [Create an AgentKit instance](#create-an-agentkit-instance)
11+
- [Create an AgentKit instance with a specified wallet provider](#create-an-agentkit-instance-with-a-specified-wallet-provider)
12+
- [Create an AgentKit instance with specified action providers](#create-an-agentkit-instance-with-specified-action-providers)
13+
- [Use with a framework extension (e.g., LangChain + OpenAI)](#use-with-a-framework-extension)
1414
- [Creating an Action Provider](#creating-an-action-provider)
15-
- [Adding Actions to your Action Provider](#adding-actions-to-your-action-provider)
16-
- [Adding Actions that use a Wallet Provider](#adding-actions-that-use-a-wallet-provider)
17-
- [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
15+
- [Adding Actions to your Action Provider](#adding-actions-to-your-action-provider)
16+
- [Adding Actions that use a Wallet Provider](#adding-actions-that-use-a-wallet-provider)
17+
- [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
1818
- [Action Providers](#action-providers)
1919
- [Wallet Providers](#wallet-providers)
20-
- [CdpEvmServerWalletProvider](#cdpevmserverwalletprovider)
21-
- [Network Configuration](#network-configuration)
22-
- [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
23-
- [Creating a new wallet](#creating-a-new-wallet)
24-
- [Example Usage with AgentKit](#example-usage-with-agentkit)
25-
- [CdpEvmSmartWalletProvider](#cdpevmsmartwalletprovider)
26-
- [Network Configuration](#network-configuration)
27-
- [Configuring with a Private Key Owner](#configuring-with-a-private-key-owner)
28-
- [Configuring with a Server Wallet Owner](#configuring-with-a-server-wallet-owner)
29-
- [Creating a New Smart Wallet](#creating-a-new-smart-wallet)
30-
- [Gasless Transactions with Paymaster](#gasless-transactions-with-paymaster)
31-
- [Example Usage with AgentKit](#example-usage-with-agentkit)
32-
- [EthAccountWalletProvider](#ethaccountwalletprovider)
33-
- [Configuring gas parameters](#configuring-ethaccountwalletprovider-gas-parameters)
34-
- [SmartWalletProvider](#smartwalletprovider)
20+
- [CdpEvmServerWalletProvider](#cdpevmserverwalletprovider)
21+
- [Network Configuration](#network-configuration)
22+
- [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
23+
- [Creating a new wallet](#creating-a-new-wallet)
24+
- [Example Usage with AgentKit](#example-usage-with-agentkit)
25+
- [CdpEvmSmartWalletProvider](#cdpevmsmartwalletprovider)
26+
- [Network Configuration](#network-configuration)
27+
- [Configuring with a Private Key Owner](#configuring-with-a-private-key-owner)
28+
- [Configuring with a Server Wallet Owner](#configuring-with-a-server-wallet-owner)
29+
- [Creating a New Smart Wallet](#creating-a-new-smart-wallet)
30+
- [Gasless Transactions with Paymaster](#gasless-transactions-with-paymaster)
31+
- [Example Usage with AgentKit](#example-usage-with-agentkit)
32+
- [EthAccountWalletProvider](#ethaccountwalletprovider)
33+
- [Configuring gas parameters](#configuring-ethaccountwalletprovider-gas-parameters)
34+
- [Configuring `EthAccountWalletProvider` rpc url](#configuring-ethaccountwalletprovider-rpc-url)
35+
- [SmartWalletProvider](#smartwalletprovider)
36+
- [CdpSolanaWalletProvider](#cdpsolanawalletprovider)
37+
- [Configuring with API credentials](#configuring-with-api-credentials)
38+
- [Using environment variables](#using-environment-variables)
39+
- [Example Usage with AgentKit](#example-usage-with-agentkit)
3540
- [Contributing](#contributing)
3641

3742
## Getting Started
@@ -888,9 +893,9 @@ import os
888893
from eth_account import Account
889894

890895
from coinbase_agentkit import (
891-
AgentKit,
892-
AgentKitConfig,
893-
SmartWalletProvider,
896+
AgentKit,
897+
AgentKitConfig,
898+
SmartWalletProvider,
894899
SmartWalletProviderConfig
895900
)
896901

@@ -916,6 +921,112 @@ agent_kit = AgentKit(AgentKitConfig(
916921
))
917922
```
918923

924+
### CdpSolanaWalletProvider
925+
926+
The `CdpSolanaWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) API for Solana networks. It supports SOL transfers and message signing on Solana mainnet, devnet, and testnet.
927+
928+
#### Network Configuration
929+
930+
The `CdpSolanaWalletProvider` can be configured to use different Solana networks by setting the `network_id` parameter:
931+
932+
- `solana-mainnet` - Solana Mainnet
933+
- `solana-devnet` - Solana Devnet (default)
934+
- `solana-testnet` - Solana Testnet
935+
936+
```python
937+
from coinbase_agentkit import CdpSolanaWalletProvider, CdpSolanaWalletProviderConfig
938+
939+
wallet_provider = CdpSolanaWalletProvider(CdpSolanaWalletProviderConfig(
940+
api_key_id="CDP API KEY ID",
941+
api_key_secret="CDP API KEY SECRET",
942+
wallet_secret="CDP WALLET SECRET",
943+
network_id="solana-devnet",
944+
))
945+
```
946+
947+
#### Configuring with API credentials
948+
949+
You can configure the provider by passing CDP API credentials directly:
950+
951+
```python
952+
from coinbase_agentkit import CdpSolanaWalletProvider, CdpSolanaWalletProviderConfig
953+
954+
wallet_provider = CdpSolanaWalletProvider(CdpSolanaWalletProviderConfig(
955+
api_key_id="CDP API KEY ID",
956+
api_key_secret="CDP API KEY SECRET",
957+
wallet_secret="CDP WALLET SECRET",
958+
network_id="solana-mainnet",
959+
))
960+
```
961+
962+
#### Using environment variables
963+
964+
The provider can also read configuration from environment variables:
965+
966+
```python
967+
from coinbase_agentkit import CdpSolanaWalletProvider, CdpSolanaWalletProviderConfig
968+
969+
# Set environment variables:
970+
# CDP_API_KEY_ID="your-api-key-id"
971+
# CDP_API_KEY_SECRET="your-api-key-secret"
972+
# CDP_WALLET_SECRET="your-wallet-secret"
973+
# NETWORK_ID="solana-devnet"
974+
975+
wallet_provider = CdpSolanaWalletProvider(CdpSolanaWalletProviderConfig())
976+
```
977+
978+
#### Using an existing wallet
979+
980+
If you have an existing CDP Solana wallet, you can specify its address:
981+
982+
```python
983+
from coinbase_agentkit import CdpSolanaWalletProvider, CdpSolanaWalletProviderConfig
984+
985+
wallet_provider = CdpSolanaWalletProvider(CdpSolanaWalletProviderConfig(
986+
api_key_id="CDP API KEY ID",
987+
api_key_secret="CDP API KEY SECRET",
988+
wallet_secret="CDP WALLET SECRET",
989+
address="YOUR_EXISTING_SOLANA_ADDRESS",
990+
network_id="solana-mainnet",
991+
))
992+
```
993+
994+
#### Example Usage with AgentKit
995+
996+
Here's a complete example of using `CdpSolanaWalletProvider` with AgentKit:
997+
998+
```python
999+
from coinbase_agentkit import (
1000+
AgentKit,
1001+
AgentKitConfig,
1002+
CdpSolanaWalletProvider,
1003+
CdpSolanaWalletProviderConfig,
1004+
wallet_action_provider,
1005+
)
1006+
1007+
# Initialize the wallet provider
1008+
wallet_provider = CdpSolanaWalletProvider(CdpSolanaWalletProviderConfig(
1009+
api_key_id="CDP API KEY ID",
1010+
api_key_secret="CDP API KEY SECRET",
1011+
wallet_secret="CDP WALLET SECRET",
1012+
network_id="solana-devnet",
1013+
))
1014+
1015+
# Create AgentKit instance with wallet and action providers
1016+
agentkit = AgentKit(AgentKitConfig(
1017+
wallet_provider=wallet_provider,
1018+
action_providers=[
1019+
wallet_action_provider(), # Provides basic wallet operations for Solana
1020+
],
1021+
))
1022+
1023+
# The wallet provider supports:
1024+
# - Getting wallet address: wallet_provider.get_address()
1025+
# - Getting SOL balance: wallet_provider.get_balance()
1026+
# - Transferring SOL: wallet_provider.native_transfer(to, amount)
1027+
# - Signing messages: wallet_provider.sign_message(message)
1028+
```
1029+
9191030
## Contributing
9201031

9211032
See [CONTRIBUTING.md](https://github.com/coinbase/agentkit/blob/main/CONTRIBUTING.md) for more information.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgraded cdp-sdk to latest and added CdpSolanaWalletProvider

python/coinbase-agentkit/coinbase_agentkit/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
CdpEvmServerWalletProviderConfig,
3030
CdpEvmSmartWalletProvider,
3131
CdpEvmSmartWalletProviderConfig,
32+
CdpSolanaWalletProvider,
33+
CdpSolanaWalletProviderConfig,
3234
EthAccountWalletProvider,
3335
EthAccountWalletProviderConfig,
3436
EvmWalletProvider,
@@ -47,6 +49,8 @@
4749
"CdpEvmServerWalletProviderConfig",
4850
"CdpEvmSmartWalletProvider",
4951
"CdpEvmSmartWalletProviderConfig",
52+
"CdpSolanaWalletProvider",
53+
"CdpSolanaWalletProviderConfig",
5054
"EvmWalletProvider",
5155
"EthAccountWalletProvider",
5256
"EthAccountWalletProviderConfig",

python/coinbase-agentkit/coinbase_agentkit/action_providers/cdp/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ tests/action_providers/cdp/
2727
- `address_reputation`: Returns onchain activity metrics
2828
- `request_faucet_funds`: Request testnet funds from CDP faucet
2929

30-
- Available only on Base Sepolia
30+
- Available on Base Sepolia, Ethereum Sepolia, and Solana Devnet
31+
- Supported assets:
32+
- Base Sepolia / Ethereum Sepolia: ETH (default), USDC, EURC, CBBTC
33+
- Solana Devnet: SOL (default), USDC
3134

3235
### CDP Wallet Actions
3336

python/coinbase-agentkit/coinbase_agentkit/action_providers/cdp/cdp_api_action_provider.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ...wallet_providers.evm_wallet_provider import EvmWalletProvider
1010
from ..action_decorator import create_action
1111
from ..action_provider import ActionProvider
12-
from .schemas import RequestFaucetFundsSchema
12+
from .schemas import RequestFaucetFundsSchema, SwapSchema
1313

1414
TWalletProvider = TypeVar("TWalletProvider", bound=EvmWalletProvider)
1515

@@ -116,6 +116,58 @@ async def _request_faucet():
116116
else:
117117
return "Error: Faucet is only supported on Ethereum and Solana protocol families."
118118

119+
@create_action(
120+
name="swap",
121+
description="""
122+
This tool can be used to swap tokens on EVM networks (Ethereum and Base).
123+
It takes the from asset ID, to asset ID, amount, and network as input.
124+
Only supported on mainnet EVM networks.
125+
Amount should be specified in the smallest denomination (e.g., wei for ETH).""",
126+
schema=SwapSchema,
127+
)
128+
def swap(self, wallet_provider: TWalletProvider, args: dict[str, Any]) -> str:
129+
"""Swap tokens using CDP API.
130+
131+
Args:
132+
wallet_provider: The wallet provider instance.
133+
args: Input arguments for the action.
134+
135+
Returns:
136+
str: A message containing the action response or error details.
137+
138+
"""
139+
validated_args = SwapSchema(**args)
140+
network = wallet_provider.get_network()
141+
142+
if network.protocol_family != "evm":
143+
return "Error: Swap is only supported on EVM networks."
144+
145+
if "sepolia" in network.network_id or "testnet" in network.network_id:
146+
return "Error: Swap is only supported on mainnet networks."
147+
148+
client = self._get_client(wallet_provider)
149+
try:
150+
loop = asyncio.get_event_loop()
151+
except RuntimeError:
152+
loop = asyncio.new_event_loop()
153+
asyncio.set_event_loop(loop)
154+
155+
async def _swap():
156+
async with client as cdp:
157+
return await cdp.evm.swap(
158+
address=wallet_provider.get_address(),
159+
amount=validated_args.amount,
160+
from_asset_id=validated_args.from_asset_id,
161+
to_asset_id=validated_args.to_asset_id,
162+
network=validated_args.network,
163+
)
164+
165+
try:
166+
swap_result = loop.run_until_complete(_swap())
167+
return f"Successfully swapped {validated_args.amount} {validated_args.from_asset_id} to {validated_args.to_asset_id}. Transaction hash: {swap_result.transaction_hash}"
168+
except Exception as e:
169+
return f"Error performing swap: {e!s}"
170+
119171
def supports_network(self, network: Network) -> bool:
120172
"""Check if the network is supported by this action provider.
121173
@@ -127,7 +179,13 @@ def supports_network(self, network: Network) -> bool:
127179
128180
"""
129181
if network.protocol_family == "evm":
130-
return network.network_id in ["base-sepolia", "ethereum-sepolia"]
182+
# Support both testnet (for faucet) and mainnet (for swap)
183+
return network.network_id in [
184+
"base-sepolia",
185+
"ethereum-sepolia", # testnet for faucet
186+
"base-mainnet",
187+
"ethereum-mainnet", # mainnet for swap
188+
]
131189
elif network.protocol_family == "svm":
132190
return network.network_id == "solana-devnet"
133191
return False

python/coinbase-agentkit/coinbase_agentkit/action_providers/cdp/schemas.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ class RequestFaucetFundsSchema(BaseModel):
1010
None,
1111
description="The optional asset ID to request from faucet",
1212
)
13+
14+
15+
class SwapSchema(BaseModel):
16+
"""Input schema for token swapping."""
17+
18+
amount: str = Field(description="The amount of the from asset to swap")
19+
from_asset_id: str = Field(description="The from asset ID to swap")
20+
to_asset_id: str = Field(description="The to asset ID to receive from the swap")
21+
network: str = Field(description="The network on which to perform the swap")

python/coinbase-agentkit/coinbase_agentkit/wallet_providers/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
CdpEvmSmartWalletProvider,
99
CdpEvmSmartWalletProviderConfig,
1010
)
11+
from .cdp_solana_wallet_provider import (
12+
CdpSolanaWalletProvider,
13+
CdpSolanaWalletProviderConfig,
14+
)
1115
from .eth_account_wallet_provider import EthAccountWalletProvider, EthAccountWalletProviderConfig
1216
from .evm_wallet_provider import EvmWalletProvider
1317
from .wallet_provider import WalletProvider
@@ -18,6 +22,8 @@
1822
"CdpEvmServerWalletProviderConfig",
1923
"CdpEvmSmartWalletProvider",
2024
"CdpEvmSmartWalletProviderConfig",
25+
"CdpSolanaWalletProvider",
26+
"CdpSolanaWalletProviderConfig",
2127
"EvmWalletProvider",
2228
"EthAccountWalletProvider",
2329
"EthAccountWalletProviderConfig",

0 commit comments

Comments
 (0)