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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ agentkit/
│ │ └── model-context-protocol/
│ └── examples/
│ ├── langchain-cdp-chatbot/
│ ├── langchain-cdp-v2-chatbot/
│ ├── langchain-farcaster-chatbot/
│ ├── langchain-privy-chatbot/
│ ├── langchain-solana-chatbot/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ agentkit/
│ │ └── model-context-protocol/
│ └── examples/
│ ├── langchain-cdp-chatbot/
│ ├── langchain-cdp-v2-chatbot/
│ ├── langchain-farcaster-chatbot/
│ ├── langchain-privy-chatbot/
│ ├── langchain-solana-chatbot/
Expand Down
5 changes: 5 additions & 0 deletions typescript/.changeset/metal-ads-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase/agentkit": minor
---

Added CdpV2EvmWalletProvider, CdpV2SolanaWalletProvider, and a unified CdpV2WalletProvider entrypoint
142 changes: 142 additions & 0 deletions typescript/agentkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
- [Adding Actions to your Action Provider that use a Wallet Provider](#adding-actions-to-your-action-provider-that-use-a-wallet-provider)
- [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
- [EVM Wallet Providers](#evm-wallet-providers)
- [CdpV2EvmWalletProvider](#cdpv2evmwalletprovider)
- [CdpWalletProvider](#cdpwalletprovider)
- [Network Configuration](#network-configuration)
- [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
Expand All @@ -36,6 +37,7 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
- [Configuring from PrivyWalletProvider](#configuring-from-privywalletprovider)
- [Configuring from ViemWalletProvider](#configuring-from-viemwalletprovider)
- [SVM Wallet Providers](#svm-wallet-providers)
- [CdpV2SolanaWalletProvider](#cdpv2solanawalletprovider)
- [SolanaKeypairWalletProvider](#solanakeypairwalletprovider)
- [Network Configuration](#solana-network-configuration)
- [RPC URL Configuration](#rpc-url-configuration)
Expand Down Expand Up @@ -537,11 +539,76 @@ const agentKit = new AgentKit({
Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:

EVM:
- [CdpV2EvmWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpV2EvmWalletProvider.ts)
- [CdpWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpWalletProvider.ts)
- [ViemWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/viemWalletProvider.ts)
- [PrivyWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/privyWalletProvider.ts)
- [ZeroDevWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/zeroDevWalletProvider.ts)

### CdpV2EvmWalletProvider

The `CdpV2EvmWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) V2 API. It provides a more modern and streamlined interface for interacting with CDP wallets.

#### Basic Configuration

```typescript
import { CdpV2EvmWalletProvider } from "@coinbase/agentkit";

const walletProvider = await CdpV2EvmWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
networkId: "base-sepolia", // Optional, defaults to "base-sepolia"
});
```

#### Using an Existing Wallet

You can configure the provider with an existing wallet by providing the wallet's address:

```typescript
import { CdpV2EvmWalletProvider } from "@coinbase/agentkit";

const walletProvider = await CdpV2EvmWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
address: "0x...", // The address of an existing wallet
networkId: "base-sepolia",
});
```

#### Creating a New Wallet

To create a new wallet, you can provide an idempotency key. The same idempotency key will always generate the same wallet address, and these keys are valid for 24 hours:

```typescript
import { CdpV2EvmWalletProvider } from "@coinbase/agentkit";

const walletProvider = await CdpV2EvmWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
idempotencyKey: "unique-key-123", // Optional, if not provided a new wallet will be created
networkId: "base-sepolia",
});
```

#### Environment Variables

The provider can also be configured using environment variables:

```typescript
// Environment variables:
// CDP_API_KEY_ID=your_api_key_id
// CDP_API_KEY_SECRET=your_api_key_secret
// CDP_WALLET_SECRET=your_wallet_secret
// NETWORK_ID=base-sepolia (optional)
// IDEMPOTENCY_KEY=unique-key-123 (optional)

const walletProvider = await CdpV2EvmWalletProvider.configureWithWallet();
```

### CdpWalletProvider

The `CdpWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) [API Wallet](https://docs.cdp.coinbase.com/wallet-api/docs/welcome).
Expand Down Expand Up @@ -877,10 +944,84 @@ const walletProvider = await ZeroDevWalletProvider.configureWithWallet({

## SVM Wallet Providers

Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:

SVM:
- [CdpV2SolanaWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpV2SolanaWalletProvider.ts)
- [SolanaKeypairWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/solanaKeypairWalletProvider.ts)
- [PrivyWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/privySvmWalletProvider.ts)

### CdpV2SolanaWalletProvider

The `CdpV2SolanaWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) V2 API for Solana. It provides a more modern and streamlined interface for interacting with CDP wallets on the Solana network.

#### Basic Configuration

```typescript
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";

const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
networkId: "solana-devnet", // Optional, defaults to "solana-devnet"
});
```

#### Using an Existing Wallet

You can configure the provider with an existing wallet by providing the wallet's address:

```typescript
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";

const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
address: "your-solana-address", // The address of an existing wallet
networkId: "solana-devnet",
});
```

#### Creating a New Wallet

To create a new wallet, you can provide an idempotency key. The same idempotency key will always generate the same wallet address, and these keys are valid for 24 hours:

```typescript
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";

const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
apiKeyId: "CDP_API_KEY_ID",
apiKeySecret: "CDP_API_KEY_SECRET",
walletSecret: "CDP_WALLET_SECRET",
idempotencyKey: "unique-key-123", // Optional, if not provided a new wallet will be created
networkId: "solana-devnet",
});
```

#### Environment Variables

The provider can also be configured using environment variables:

```typescript
// Environment variables:
// CDP_API_KEY_ID=your_api_key_id
// CDP_API_KEY_SECRET=your_api_key_secret
// CDP_WALLET_SECRET=your_wallet_secret
// NETWORK_ID=solana-devnet (optional)
// IDEMPOTENCY_KEY=unique-key-123 (optional)

const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet();
```

#### Supported Networks

The `CdpV2SolanaWalletProvider` supports the following Solana networks:
- `solana-mainnet`
- `solana-devnet`
- `solana-testnet`

### SolanaKeypairWalletProvider

The `SolanaKeypairWalletProvider` is a wallet provider that uses the API [Solana web3.js](https://solana-labs.github.io/solana-web3.js/).
Expand Down Expand Up @@ -931,6 +1072,7 @@ import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
const config: PrivyWalletConfig = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
connection,
chainType: "solana", // optional, defaults to "evm". Make sure to set this to "solana" if you want to use Solana!
networkId: "solana-devnet", // optional, defaults to "solana-devnet"
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
Expand Down
1 change: 1 addition & 0 deletions typescript/agentkit/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const baseConfig = require("../jest.config.base.cjs");

module.exports = {
...baseConfig,
setupFilesAfterEnv: ["<rootDir>/setup-jest.js"],
coveragePathIgnorePatterns: ["node_modules", "dist", "docs", "index.ts"],
coverageThreshold: {},
};
1 change: 1 addition & 0 deletions typescript/agentkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@across-protocol/app-sdk": "^0.2.0",
"@alloralabs/allora-sdk": "^0.1.0",
"@coinbase/cdp-sdk": "^1.3.0",
"@coinbase/coinbase-sdk": "^0.20.0",
"@jup-ag/api": "^6.0.39",
"@privy-io/public-api": "^2.18.5",
Expand Down
1 change: 1 addition & 0 deletions typescript/agentkit/setup-jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.mock("jose", () => ({}));
45 changes: 45 additions & 0 deletions typescript/agentkit/src/action-providers/cdp-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# CDP (Coinbase Developer Platform) V2 Action Provider

This directory contains the **CdpV2ActionProvider** implementation, which provides actions to interact with the **Coinbase Developer Platform (CDP)** API and wallet services.

## Directory Structure

```
cdp/
├── cdpApiV2ActionProvider.ts # Provider for CDP API interactions
├── cdpApiV2ActionProvider.test.ts # Tests for CDP API provider
├── schemas.ts # Action schemas for CDP operations
├── index.ts # Main exports
└── README.md # This file
```

## Actions

### CDP API Actions

- `request_faucet_funds`: Request testnet funds from CDP faucet

- Available only on Base Sepolia, Ethereum Sepolia or Solana Devnet

## Adding New Actions

To add new CDP actions:

1. Define your action schema in `schemas.ts`
2. Implement the action in the appropriate provider file:
- CDP API actions in `cdpApiActionProvider.ts`
3. Add corresponding tests

## Network Support

The CDP providers support all networks available on the Coinbase Developer Platform, including:

- Base (Mainnet & Testnet)
- Ethereum (Mainnet & Testnet)
- Other EVM-compatible networks

## Notes

- Requires CDP API credentials (API Key ID and Secret). Visit the [CDP Portal](https://portal.cdp.coinbase.com/) to get your credentials.

For more information on the **Coinbase Developer Platform**, visit [CDP Documentation](https://docs.cdp.coinbase.com/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { z } from "zod";
import { Network } from "../../network";
import { WalletProvider } from "../../wallet-providers";
import { WalletProviderWithClient } from "../../wallet-providers/cdpV2Shared";
import { CreateAction } from "../actionDecorator";
import { ActionProvider } from "../actionProvider";
import { RequestFaucetFundsV2Schema } from "./schemas";

type CdpV2WalletProviderWithClient = WalletProvider & WalletProviderWithClient;

/**
* CdpApiActionProvider is an action provider for CDP API.
*
* This provider is used for any action that uses the CDP API, but does not require a CDP Wallet.
*/
export class CdpApiV2ActionProvider extends ActionProvider<CdpV2WalletProviderWithClient> {
/**
* Constructor for the CdpApiActionProvider class.
*/
constructor() {
super("cdp_api_v2", []);
}

/**
* Requests test tokens from the faucet for the default address in the wallet.
*
* @param walletProvider - The wallet provider to request funds from.
* @param args - The input arguments for the action.
* @returns A confirmation message with transaction details.
*/
@CreateAction({
name: "request_faucet_funds",
description: `This tool will request test tokens from the faucet for the default address in the wallet. It takes the wallet and asset ID as input.
Faucet is only allowed on 'base-sepolia' or 'solana-devnet'.
If fauceting on 'base-sepolia', user can only provide asset ID 'eth', 'usdc', 'eurc' or 'cbbtc', if no asset ID is provided, the faucet will default to 'eth'.
If fauceting on 'solana-devnet', user can only provide asset ID 'sol' or 'usdc', if no asset ID is provided, the faucet will default to 'sol'.
You are not allowed to faucet with any other network or asset ID. If you are on another network, suggest that the user sends you some ETH
from another wallet and provide the user with your wallet details.`,
schema: RequestFaucetFundsV2Schema,
})
async faucet(
walletProvider: CdpV2WalletProviderWithClient,
args: z.infer<typeof RequestFaucetFundsV2Schema>,
): Promise<string> {
const network = walletProvider.getNetwork();
const networkId = network.networkId!;

if (network.protocolFamily === "evm") {
if (networkId !== "base-sepolia" && networkId !== "ethereum-sepolia") {
throw new Error(
"Faucet is only supported on 'base-sepolia' or 'ethereum-sepolia' evm networks.",
);
}

const faucetTx = await walletProvider.getClient().evm.requestFaucet({
address: walletProvider.getAddress(),
token: (args.assetId || "eth") as "eth" | "usdc" | "eurc" | "cbbtc",
network: networkId,
});

return `Received ${
args.assetId || "ETH"
} from the faucet. Transaction hash: ${faucetTx.transactionHash}`;
} else if (network.protocolFamily === "svm") {
if (networkId !== "solana-devnet") {
throw new Error("Faucet is only supported on 'solana-devnet' solana networks.");
}

const faucetTx = await walletProvider.getClient().solana.requestFaucet({
address: walletProvider.getAddress(),
token: (args.assetId || "sol") as "sol" | "usdc",
});

return `Received ${
args.assetId || "SOL"
} from the faucet. Transaction signature hash: ${faucetTx.signature}`;
} else {
throw new Error("Faucet is only supported on Ethereum and Solana protocol families.");
}
}

/**
* Checks if the Cdp action provider supports the given network.
*
* NOTE: Network scoping is done at the action implementation level
*
* @param _ - The network to check.
* @returns True if the Cdp action provider supports the network, false otherwise.
*/
supportsNetwork = (_: Network) => true;
}

export const cdpApiV2ActionProvider = () => new CdpApiV2ActionProvider();
2 changes: 2 additions & 0 deletions typescript/agentkit/src/action-providers/cdp-v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./schemas";
export * from "./cdpApiV2ActionProvider";
11 changes: 11 additions & 0 deletions typescript/agentkit/src/action-providers/cdp-v2/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

/**
* Input schema for request faucet funds action.
*/
export const RequestFaucetFundsV2Schema = z
.object({
assetId: z.string().optional().describe("The optional asset ID to request from faucet"),
})
.strip()
.describe("Instructions for requesting faucet funds");
1 change: 1 addition & 0 deletions typescript/agentkit/src/action-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./across";
export * from "./alchemy";
export * from "./basename";
export * from "./cdp";
export * from "./cdp-v2";
export * from "./compound";
export * from "./defillama";
export * from "./erc20";
Expand Down
Loading
Loading