@coinbase/agentkit 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +106 -54
  2. package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -0
  3. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +43 -0
  4. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +151 -0
  5. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
  6. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +242 -0
  7. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +42 -0
  8. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +132 -0
  9. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
  10. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +199 -0
  11. package/dist/action-providers/cdp/index.d.ts +3 -0
  12. package/dist/action-providers/cdp/index.js +3 -0
  13. package/dist/action-providers/cdp/schemas.d.ts +29 -0
  14. package/dist/action-providers/cdp/schemas.js +32 -1
  15. package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
  16. package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
  17. package/dist/action-providers/index.d.ts +1 -0
  18. package/dist/action-providers/index.js +1 -0
  19. package/dist/action-providers/zerion/constants.d.ts +1 -0
  20. package/dist/action-providers/zerion/constants.js +4 -0
  21. package/dist/action-providers/zerion/index.d.ts +2 -0
  22. package/dist/action-providers/zerion/index.js +18 -0
  23. package/dist/action-providers/zerion/schemas.d.ts +11 -0
  24. package/dist/action-providers/zerion/schemas.js +15 -0
  25. package/dist/action-providers/zerion/types.d.ts +125 -0
  26. package/dist/action-providers/zerion/types.js +16 -0
  27. package/dist/action-providers/zerion/utils.d.ts +3 -0
  28. package/dist/action-providers/zerion/utils.js +45 -0
  29. package/dist/action-providers/zerion/zerionActionProvider.d.ts +57 -0
  30. package/dist/action-providers/zerion/zerionActionProvider.js +159 -0
  31. package/dist/action-providers/zerion/zerionActionProvider.test.d.ts +1 -0
  32. package/dist/action-providers/zerion/zerionActionProvider.test.js +213 -0
  33. package/dist/wallet-providers/cdpShared.d.ts +4 -0
  34. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +8 -1
  35. package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -11
  36. package/package.json +2 -2
package/README.md CHANGED
@@ -5,60 +5,73 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
5
5
  ## Table of Contents
6
6
 
7
7
  - [Agentkit](#agentkit)
8
- - [Getting Started](#getting-started)
9
- - [Installation](#installation)
10
- - [Usage](#usage)
11
- - [Create an AgentKit instance](#create-an-agentkit-instance)
12
- - [Create an AgentKit instance with a specified wallet provider](#create-an-agentkit-instance-with-a-specified-wallet-provider)
13
- - [Create an AgentKit instance with a specified action providers](#create-an-agentkit-instance-with-a-specified-action-providers)
14
- - [Use the agent's actions with a framework extension. For example, using LangChain + OpenAI](#use-the-agents-actions-with-a-framework-extension-for-example-using-langchain--openai)
15
- - [Action Providers](#action-providers)
16
- - [Creating an Action Provider](#creating-an-action-provider)
17
- - [Adding Actions to your Action Provider](#adding-actions-to-your-action-provider)
18
- - [Adding Actions to your Action Provider that use a Wallet Provider](#adding-actions-to-your-action-provider-that-use-a-wallet-provider)
19
- - [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
20
- - [EVM Wallet Providers](#evm-wallet-providers)
21
- - [CdpEvmWalletProvider](#cdpevmwalletprovider)
22
- - [Basic Configuration](#basic-configuration)
23
- - [Using an existing wallet](#using-an-existing-wallet)
24
- - [Creating a new wallet](#creating-a-new-wallet)
25
- - [Environment Variables](#environment-variables)
26
- - [Exporting a wallet](#exporting-a-wallet)
27
- - [CdpSmartWalletProvider](#cdpsmartwalletprovider)
28
- - [Basic Configuration](#basic-configuration-1)
29
- - [Using an Existing Smart Wallet](#using-an-existing-smart-wallet)
30
- - [Specifying an Owner Account](#specifying-an-owner-account)
31
- - [Creating a New Smart Wallet](#creating-a-new-smart-wallet)
32
- - [Environment Variables](#environment-variables-1)
33
- - [Exporting Smart Wallet Information](#exporting-smart-wallet-information)
34
- - [Key Differences from Regular Wallets](#key-differences-from-regular-wallets)
35
- - [LegacyCdpWalletProvider](#legacycdpwalletprovider)
36
- - [Network Configuration](#network-configuration)
37
- - [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
38
- - [Configuring from a mnemonic phrase](#configuring-from-a-mnemonic-phrase)
39
- - [Exporting a wallet](#exporting-a-wallet)
40
- - [Importing a wallet from WalletData JSON string](#importing-a-wallet-from-walletdata-json-string)
41
- - [Configuring gas parameters](#configuring-legacycdpwalletprovider-gas-parameters)
42
- - [ViemWalletProvider](#viemwalletprovider)
43
- - [Configuring gas parameters](#configuring-viemwalletprovider-gas-parameters)
44
- - [PrivyWalletProvider](#privywalletprovider)
45
- - [Authorization Keys](#authorization-keys)
46
- - [Exporting Privy Wallet information](#exporting-privy-wallet-information)
47
- - [SmartWalletProvider](#smartwalletprovider)
48
- - [ZeroDevWalletProvider](#zerodevwalletprovider)
49
- - [Configuring from CdpWalletProvider](#configuring-from-cdpwalletprovider)
50
- - [Configuring from PrivyWalletProvider](#configuring-from-privywalletprovider)
51
- - [Configuring from ViemWalletProvider](#configuring-from-viemwalletprovider)
52
- - [SVM Wallet Providers](#svm-wallet-providers)
53
- - [CdpSolanaWalletProvider](#cdpsolanawalletprovider)
54
- - [SolanaKeypairWalletProvider](#solanakeypairwalletprovider)
55
- - [Network Configuration](#solana-network-configuration)
56
- - [RPC URL Configuration](#rpc-url-configuration)
57
- - [PrivyWalletProvider](#privywalletprovider-solana)
58
- - [Connection Configuration](#connection-configuration)
59
- - [Authorization Keys](#authorization-keys)
60
- - [Exporting Privy Wallet information](#exporting-privy-wallet-information)
61
- - [Contributing](#contributing)
8
+ - [Table of Contents](#table-of-contents)
9
+ - [Getting Started](#getting-started)
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Create an AgentKit instance. If no wallet or action providers are specified, the agent will use the `CdpWalletProvider` and `WalletProvider` action provider.](#create-an-agentkit-instance-if-no-wallet-or-action-providers-are-specified-the-agent-will-use-the-cdpwalletprovider-and-walletprovider-action-provider)
13
+ - [Create an AgentKit instance](#create-an-agentkit-instance)
14
+ - [Create an AgentKit instance with a specified wallet provider.](#create-an-agentkit-instance-with-a-specified-wallet-provider)
15
+ - [Create an AgentKit instance with a specified action providers.](#create-an-agentkit-instance-with-a-specified-action-providers)
16
+ - [Use the agent's actions with a framework extension. For example, using LangChain + OpenAI.](#use-the-agents-actions-with-a-framework-extension-for-example-using-langchain--openai)
17
+ - [Action Providers](#action-providers)
18
+ - [Creating an Action Provider](#creating-an-action-provider)
19
+ - [Adding Actions to your Action Provider](#adding-actions-to-your-action-provider)
20
+ - [Required Typescript Compiler Options](#required-typescript-compiler-options)
21
+ - [Steps to create an action](#steps-to-create-an-action)
22
+ - [Adding Actions to your Action Provider that use a Wallet Provider](#adding-actions-to-your-action-provider-that-use-a-wallet-provider)
23
+ - [Adding an Action Provider to your AgentKit instance.](#adding-an-action-provider-to-your-agentkit-instance)
24
+ - [EVM Wallet Providers](#evm-wallet-providers)
25
+ - [CdpEvmWalletProvider](#cdpevmwalletprovider)
26
+ - [Basic Configuration](#basic-configuration)
27
+ - [Using an Existing Wallet](#using-an-existing-wallet)
28
+ - [Creating a New Wallet](#creating-a-new-wallet)
29
+ - [Environment Variables](#environment-variables)
30
+ - [Exporting a wallet](#exporting-a-wallet)
31
+ - [CdpSmartWalletProvider](#cdpsmartwalletprovider)
32
+ - [Basic Configuration](#basic-configuration-1)
33
+ - [Using an Existing Smart Wallet](#using-an-existing-smart-wallet)
34
+ - [Specifying an Owner Account](#specifying-an-owner-account)
35
+ - [Creating a New Smart Wallet](#creating-a-new-smart-wallet)
36
+ - [Environment Variables](#environment-variables-1)
37
+ - [Exporting Smart Wallet Information](#exporting-smart-wallet-information)
38
+ - [Key Differences from Regular Wallets](#key-differences-from-regular-wallets)
39
+ - [LegacyCdpWalletProvider](#legacycdpwalletprovider)
40
+ - [Network Configuration](#network-configuration)
41
+ - [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
42
+ - [Configuring from a mnemonic phrase](#configuring-from-a-mnemonic-phrase)
43
+ - [Exporting a wallet](#exporting-a-wallet-1)
44
+ - [Importing a wallet from `WalletData` JSON string](#importing-a-wallet-from-walletdata-json-string)
45
+ - [Configuring LegacyCdpWalletProvider gas parameters](#configuring-legacycdpwalletprovider-gas-parameters)
46
+ - [ViemWalletProvider](#viemwalletprovider)
47
+ - [Configuring ViemWalletProvider gas parameters](#configuring-viemwalletprovider-gas-parameters)
48
+ - [PrivyWalletProvider](#privywalletprovider)
49
+ - [Server Wallet Configuration](#server-wallet-configuration)
50
+ - [Delegated Embedded Wallet Configuration](#delegated-embedded-wallet-configuration)
51
+ - [Prerequisites](#prerequisites)
52
+ - [Supported Operations](#supported-operations)
53
+ - [Authorization Keys](#authorization-keys)
54
+ - [Exporting Privy Wallet information](#exporting-privy-wallet-information)
55
+ - [SmartWalletProvider](#smartwalletprovider)
56
+ - [ZeroDevWalletProvider](#zerodevwalletprovider)
57
+ - [Configuring from CdpWalletProvider](#configuring-from-cdpwalletprovider)
58
+ - [Configuring from PrivyWalletProvider](#configuring-from-privywalletprovider)
59
+ - [Configuring from ViemWalletProvider](#configuring-from-viemwalletprovider)
60
+ - [SVM Wallet Providers](#svm-wallet-providers)
61
+ - [CdpV2SolanaWalletProvider](#cdpv2solanawalletprovider)
62
+ - [Basic Configuration](#basic-configuration-2)
63
+ - [Using an Existing Wallet](#using-an-existing-wallet-1)
64
+ - [Creating a New Wallet](#creating-a-new-wallet-1)
65
+ - [Environment Variables](#environment-variables-2)
66
+ - [Supported Networks](#supported-networks)
67
+ - [SolanaKeypairWalletProvider](#solanakeypairwalletprovider)
68
+ - [Solana Network Configuration](#solana-network-configuration)
69
+ - [RPC URL Configuration](#rpc-url-configuration)
70
+ - [PrivyWalletProvider (Solana)](#privywalletprovider-solana)
71
+ - [Connection Configuration](#connection-configuration)
72
+ - [Authorization Keys](#authorization-keys-1)
73
+ - [Exporting Privy Wallet information](#exporting-privy-wallet-information-1)
74
+ - [Contributing](#contributing)
62
75
 
63
76
  ## Getting Started
64
77
 
@@ -158,6 +171,32 @@ const agent = createReactAgent({
158
171
 
159
172
  ## Action Providers
160
173
 
174
+ <details>
175
+ <summary><strong>CDP EVM Wallet</strong></summary>
176
+ <table width="100%">
177
+ <tr>
178
+ <td width="200"><code>list_spend_permissions</code></td>
179
+ <td width="768">Lists spend permissions that have been granted to the current EVM wallet by a smart account.</td>
180
+ </tr>
181
+ <tr>
182
+ <td width="200"><code>use_spend_permission</code></td>
183
+ <td width="768">Uses a spend permission to spend tokens on behalf of a smart account that the current EVM wallet has permission to spend.</td>
184
+ </tr>
185
+ </table>
186
+ </details>
187
+ <details>
188
+ <summary><strong>CDP Smart Wallet</strong></summary>
189
+ <table width="100%">
190
+ <tr>
191
+ <td width="200"><code>list_spend_permissions</code></td>
192
+ <td width="768">Lists spend permissions that have been granted to the current smart wallet by a smart account.</td>
193
+ </tr>
194
+ <tr>
195
+ <td width="200"><code>use_spend_permission</code></td>
196
+ <td width="768">Uses a spend permission to spend tokens on behalf of a smart account that the current smart wallet has permission to spend.</td>
197
+ </tr>
198
+ </table>
199
+ </details>
161
200
  <details>
162
201
  <summary><strong>Across</strong></summary>
163
202
  <table width="100%">
@@ -452,6 +491,19 @@ it will return payment details that can be used on retry.</td>
452
491
  </table>
453
492
  </details>
454
493
  <details>
494
+ <summary><strong>Zerion</strong></summary>
495
+ <table width="100%">
496
+ <tr>
497
+ <td width="200"><code>getPortfolioOverview</code></td>
498
+ <td width="768">Fetches and summarizes a crypto wallet's portfolio in USD.</td>
499
+ </tr>
500
+ <tr>
501
+ <td width="200"><code>getFungiblePositions</code></td>
502
+ <td width="768">Retrieves and summarizes a wallet's fungible token holdings (including DeFi positions)</td>
503
+ </tr>
504
+ </table>
505
+ </details>
506
+ <details>
455
507
  <summary><strong>ZeroDev Wallet</strong></summary>
456
508
  <table width="100%">
457
509
  <tr>
@@ -111,6 +111,8 @@ class CdpApiActionProvider extends actionProvider_1.ActionProvider {
111
111
  amount: args.amount,
112
112
  slippageBps: 100, // 1% slippage tolerance
113
113
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
+ paymasterUrl: walletProvider.getPaymasterUrl?.(),
115
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
116
  });
115
117
  return `Successfully swapped ${args.amount} ${args.fromAssetId.toUpperCase()} to ${args.toAssetId.toUpperCase()}. Transaction hash: ${swapResult.transactionHash}`;
116
118
  }
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ import { WalletProvider } from "../../wallet-providers";
3
+ import { CdpEvmWalletProvider } from "../../wallet-providers/cdpEvmWalletProvider";
4
+ import { ActionProvider } from "../actionProvider";
5
+ import { UseSpendPermissionSchema, ListSpendPermissionsSchema } from "./schemas";
6
+ import type { Network } from "../../network";
7
+ /**
8
+ * CdpEvmWalletActionProvider is an action provider for CDP EVM Wallet specific actions.
9
+ *
10
+ * This provider is scoped specifically to EVM wallets and provides actions
11
+ * that are optimized for EVM functionality, including spend permission usage.
12
+ */
13
+ export declare class CdpEvmWalletActionProvider extends ActionProvider<CdpEvmWalletProvider> {
14
+ #private;
15
+ /**
16
+ * Constructor for the CdpEvmWalletActionProvider class.
17
+ */
18
+ constructor();
19
+ /**
20
+ * Lists spend permissions for a smart account.
21
+ *
22
+ * @param walletProvider - The server wallet provider to use for listing permissions.
23
+ * @param args - The input arguments for listing spend permissions.
24
+ * @returns A list of spend permissions available to the current wallet.
25
+ */
26
+ listSpendPermissions(walletProvider: WalletProvider, args: z.infer<typeof ListSpendPermissionsSchema>): Promise<string>;
27
+ /**
28
+ * Uses a spend permission to transfer tokens from a smart account to the current EVM wallet.
29
+ *
30
+ * @param walletProvider - The EVM wallet provider to use for the spend operation.
31
+ * @param args - The input arguments for using the spend permission.
32
+ * @returns A confirmation message with transaction details.
33
+ */
34
+ useSpendPermission(walletProvider: WalletProvider, args: z.infer<typeof UseSpendPermissionSchema>): Promise<string>;
35
+ /**
36
+ * Checks if the EVM wallet action provider supports the given network.
37
+ *
38
+ * @param network - The network to check.
39
+ * @returns True if the EVM wallet action provider supports the network, false otherwise.
40
+ */
41
+ supportsNetwork: (network: Network) => boolean;
42
+ }
43
+ export declare const cdpEvmWalletActionProvider: () => CdpEvmWalletActionProvider;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _CdpEvmWalletActionProvider_instances, _CdpEvmWalletActionProvider_getCdpSdkNetwork;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.cdpEvmWalletActionProvider = exports.CdpEvmWalletActionProvider = void 0;
19
+ const zod_1 = require("zod");
20
+ const wallet_providers_1 = require("../../wallet-providers");
21
+ const cdpShared_1 = require("../../wallet-providers/cdpShared");
22
+ const actionDecorator_1 = require("../actionDecorator");
23
+ const actionProvider_1 = require("../actionProvider");
24
+ const schemas_1 = require("./schemas");
25
+ const spendPermissionUtils_1 = require("./spendPermissionUtils");
26
+ /**
27
+ * CdpEvmWalletActionProvider is an action provider for CDP EVM Wallet specific actions.
28
+ *
29
+ * This provider is scoped specifically to EVM wallets and provides actions
30
+ * that are optimized for EVM functionality, including spend permission usage.
31
+ */
32
+ class CdpEvmWalletActionProvider extends actionProvider_1.ActionProvider {
33
+ /**
34
+ * Constructor for the CdpEvmWalletActionProvider class.
35
+ */
36
+ constructor() {
37
+ super("cdp_evm_wallet", []);
38
+ _CdpEvmWalletActionProvider_instances.add(this);
39
+ /**
40
+ * Checks if the EVM wallet action provider supports the given network.
41
+ *
42
+ * @param network - The network to check.
43
+ * @returns True if the EVM wallet action provider supports the network, false otherwise.
44
+ */
45
+ this.supportsNetwork = (network) => {
46
+ // EVM wallets support EVM networks in general
47
+ return network.protocolFamily === "evm";
48
+ };
49
+ }
50
+ /**
51
+ * Lists spend permissions for a smart account.
52
+ *
53
+ * @param walletProvider - The server wallet provider to use for listing permissions.
54
+ * @param args - The input arguments for listing spend permissions.
55
+ * @returns A list of spend permissions available to the current wallet.
56
+ */
57
+ async listSpendPermissions(walletProvider, args) {
58
+ const network = walletProvider.getNetwork();
59
+ if ((0, cdpShared_1.isWalletProviderWithClient)(walletProvider)) {
60
+ if (network.protocolFamily === "evm") {
61
+ return await (0, spendPermissionUtils_1.listSpendPermissionsForSpender)(walletProvider.getClient(), args.smartAccountAddress, walletProvider.getAddress());
62
+ }
63
+ else {
64
+ return "Spend permissions are currently only supported on EVM networks.";
65
+ }
66
+ }
67
+ else {
68
+ return "Wallet provider is not a CDP Wallet Provider.";
69
+ }
70
+ }
71
+ /**
72
+ * Uses a spend permission to transfer tokens from a smart account to the current EVM wallet.
73
+ *
74
+ * @param walletProvider - The EVM wallet provider to use for the spend operation.
75
+ * @param args - The input arguments for using the spend permission.
76
+ * @returns A confirmation message with transaction details.
77
+ */
78
+ async useSpendPermission(walletProvider, args) {
79
+ const network = walletProvider.getNetwork();
80
+ const cdpNetwork = __classPrivateFieldGet(this, _CdpEvmWalletActionProvider_instances, "m", _CdpEvmWalletActionProvider_getCdpSdkNetwork).call(this, network.networkId);
81
+ if ((0, cdpShared_1.isWalletProviderWithClient)(walletProvider)) {
82
+ if (network.protocolFamily === "evm") {
83
+ try {
84
+ const spenderAddress = walletProvider.getAddress();
85
+ const permission = await (0, spendPermissionUtils_1.findLatestSpendPermission)(walletProvider.getClient(), args.smartAccountAddress, spenderAddress);
86
+ const account = await walletProvider.getClient().evm.getAccount({
87
+ address: spenderAddress,
88
+ });
89
+ const spendResult = await account.useSpendPermission({
90
+ spendPermission: permission,
91
+ value: BigInt(args.value),
92
+ network: cdpNetwork,
93
+ });
94
+ return `Successfully spent ${args.value} tokens using spend permission. Transaction hash: ${spendResult.transactionHash}`;
95
+ }
96
+ catch (error) {
97
+ return `Failed to use spend permission: ${error}`;
98
+ }
99
+ }
100
+ else {
101
+ return "Spend permissions are currently only supported on EVM networks.";
102
+ }
103
+ }
104
+ else {
105
+ return "Wallet provider is not a CDP Wallet Provider.";
106
+ }
107
+ }
108
+ }
109
+ exports.CdpEvmWalletActionProvider = CdpEvmWalletActionProvider;
110
+ _CdpEvmWalletActionProvider_instances = new WeakSet(), _CdpEvmWalletActionProvider_getCdpSdkNetwork = function _CdpEvmWalletActionProvider_getCdpSdkNetwork(networkId) {
111
+ switch (networkId) {
112
+ case "base-sepolia":
113
+ return "base-sepolia";
114
+ case "base-mainnet":
115
+ return "base";
116
+ case "ethereum-sepolia":
117
+ return "ethereum-sepolia";
118
+ case "ethereum-mainnet":
119
+ return "ethereum";
120
+ default:
121
+ return networkId; // For other networks, use as-is
122
+ }
123
+ };
124
+ __decorate([
125
+ (0, actionDecorator_1.CreateAction)({
126
+ name: "list_spend_permissions",
127
+ description: `This tool lists spend permissions that have been granted to the current EVM wallet by a smart account.
128
+ It takes a smart account address and returns spend permissions where the current EVM wallet is the spender.
129
+ This is useful to see what spending allowances have been granted before using them.
130
+ This action is specifically designed for EVM wallets.`,
131
+ schema: schemas_1.ListSpendPermissionsSchema,
132
+ }),
133
+ __metadata("design:type", Function),
134
+ __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
135
+ __metadata("design:returntype", Promise)
136
+ ], CdpEvmWalletActionProvider.prototype, "listSpendPermissions", null);
137
+ __decorate([
138
+ (0, actionDecorator_1.CreateAction)({
139
+ name: "use_spend_permission",
140
+ description: `This tool uses a spend permission to spend tokens on behalf of a smart account that the current EVM wallet has permission to spend.
141
+ It automatically finds the latest valid spend permission granted by the smart account to the current EVM wallet and uses it to spend the specified amount.
142
+ The smart account must have previously granted a spend permission to the current EVM wallet using createSpendPermission.
143
+ This action is specifically designed for EVM wallets and uses the EVM wallet for spend permission execution.`,
144
+ schema: schemas_1.UseSpendPermissionSchema,
145
+ }),
146
+ __metadata("design:type", Function),
147
+ __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
148
+ __metadata("design:returntype", Promise)
149
+ ], CdpEvmWalletActionProvider.prototype, "useSpendPermission", null);
150
+ const cdpEvmWalletActionProvider = () => new CdpEvmWalletActionProvider();
151
+ exports.cdpEvmWalletActionProvider = cdpEvmWalletActionProvider;
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const cdpEvmWalletActionProvider_1 = require("./cdpEvmWalletActionProvider");
37
+ const schemas_1 = require("./schemas");
38
+ const spendPermissionUtils = __importStar(require("./spendPermissionUtils"));
39
+ // Mock the CDP SDK and utility functions
40
+ jest.mock("@coinbase/cdp-sdk");
41
+ jest.mock("./spendPermissionUtils");
42
+ describe("CDP EVM Wallet Action Provider", () => {
43
+ let actionProvider;
44
+ let mockWalletProvider;
45
+ let mockCdpClient;
46
+ let mockAccount;
47
+ beforeEach(() => {
48
+ jest.clearAllMocks();
49
+ mockAccount = {
50
+ useSpendPermission: jest.fn(),
51
+ address: "0x1234567890123456789012345678901234567890",
52
+ };
53
+ mockCdpClient = {
54
+ evm: {
55
+ listSpendPermissions: jest.fn(),
56
+ getAccount: jest.fn(),
57
+ },
58
+ };
59
+ mockWalletProvider = {
60
+ getNetwork: jest.fn(),
61
+ getAddress: jest.fn(),
62
+ getClient: jest.fn(),
63
+ };
64
+ actionProvider = new cdpEvmWalletActionProvider_1.CdpEvmWalletActionProvider();
65
+ });
66
+ describe("listSpendPermissions", () => {
67
+ const mockArgs = {
68
+ smartAccountAddress: "0xabcd1234567890123456789012345678901234567890",
69
+ };
70
+ beforeEach(() => {
71
+ mockWalletProvider.getNetwork.mockReturnValue({
72
+ protocolFamily: "evm",
73
+ networkId: "base-sepolia",
74
+ });
75
+ mockWalletProvider.getAddress.mockReturnValue("0x1234567890123456789012345678901234567890");
76
+ mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
77
+ });
78
+ it("should successfully list spend permissions for EVM wallets", async () => {
79
+ const expectedResult = "Found 2 spend permission(s):\n1. Token: USDC, Allowance: 500, Period: 1800 seconds, Start: 111111, End: 222222\n2. Token: ETH, Allowance: 1000, Period: 3600 seconds, Start: 123456, End: 234567";
80
+ spendPermissionUtils.listSpendPermissionsForSpender.mockResolvedValue(expectedResult);
81
+ const result = await actionProvider.listSpendPermissions(mockWalletProvider, mockArgs);
82
+ expect(spendPermissionUtils.listSpendPermissionsForSpender).toHaveBeenCalledWith(mockCdpClient, mockArgs.smartAccountAddress, "0x1234567890123456789012345678901234567890");
83
+ expect(result).toBe(expectedResult);
84
+ });
85
+ it("should return error message for non-EVM networks", async () => {
86
+ mockWalletProvider.getNetwork.mockReturnValue({
87
+ protocolFamily: "svm",
88
+ networkId: "solana-devnet",
89
+ });
90
+ const result = await actionProvider.listSpendPermissions(mockWalletProvider, mockArgs);
91
+ expect(result).toBe("Spend permissions are currently only supported on EVM networks.");
92
+ expect(spendPermissionUtils.listSpendPermissionsForSpender).not.toHaveBeenCalled();
93
+ });
94
+ it("should handle utility function errors gracefully", async () => {
95
+ spendPermissionUtils.listSpendPermissionsForSpender.mockResolvedValue("Failed to list spend permissions: Network error");
96
+ const result = await actionProvider.listSpendPermissions(mockWalletProvider, mockArgs);
97
+ expect(result).toBe("Failed to list spend permissions: Network error");
98
+ });
99
+ it("should validate input schema", () => {
100
+ const validInput = { smartAccountAddress: "0xabcd1234567890123456789012345678901234567890" };
101
+ const invalidInput = { wrongField: "0xabcd1234567890123456789012345678901234567890" };
102
+ expect(() => schemas_1.ListSpendPermissionsSchema.parse(validInput)).not.toThrow();
103
+ expect(() => schemas_1.ListSpendPermissionsSchema.parse(invalidInput)).toThrow();
104
+ });
105
+ });
106
+ describe("useSpendPermission", () => {
107
+ const mockArgs = {
108
+ smartAccountAddress: "0xabcd1234567890123456789012345678901234567890",
109
+ value: "2500",
110
+ };
111
+ beforeEach(() => {
112
+ mockWalletProvider.getNetwork.mockReturnValue({
113
+ protocolFamily: "evm",
114
+ networkId: "base-sepolia",
115
+ });
116
+ mockWalletProvider.getAddress.mockReturnValue("0x1234567890123456789012345678901234567890");
117
+ mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
118
+ mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
119
+ });
120
+ it("should successfully use spend permission for EVM wallets", async () => {
121
+ const mockPermission = {
122
+ spender: "0x1234567890123456789012345678901234567890",
123
+ token: "USDC",
124
+ allowance: "5000",
125
+ period: 7200,
126
+ start: 111111,
127
+ end: 333333,
128
+ };
129
+ const mockSpendResult = {
130
+ status: "completed",
131
+ transactionHash: "0xdef456789",
132
+ };
133
+ spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
134
+ mockAccount.useSpendPermission.mockResolvedValue(mockSpendResult);
135
+ const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
136
+ expect(spendPermissionUtils.findLatestSpendPermission).toHaveBeenCalledWith(mockCdpClient, mockArgs.smartAccountAddress, "0x1234567890123456789012345678901234567890");
137
+ expect(mockCdpClient.evm.getAccount).toHaveBeenCalledWith({
138
+ address: "0x1234567890123456789012345678901234567890",
139
+ });
140
+ expect(mockAccount.useSpendPermission).toHaveBeenCalledWith({
141
+ spendPermission: mockPermission,
142
+ value: BigInt(2500),
143
+ network: "base-sepolia",
144
+ });
145
+ expect(result).toBe("Successfully spent 2500 tokens using spend permission. Transaction hash: 0xdef456789");
146
+ });
147
+ it("should handle different network conversions", async () => {
148
+ const testCases = [
149
+ { networkId: "base-sepolia", expected: "base-sepolia" },
150
+ { networkId: "base-mainnet", expected: "base" },
151
+ { networkId: "ethereum-sepolia", expected: "ethereum-sepolia" },
152
+ { networkId: "ethereum-mainnet", expected: "ethereum" },
153
+ ];
154
+ const mockPermission = { spender: "0x1234", token: "ETH" };
155
+ const mockSpendResult = { status: "completed" };
156
+ spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
157
+ mockAccount.useSpendPermission.mockResolvedValue(mockSpendResult);
158
+ for (const testCase of testCases) {
159
+ jest.clearAllMocks();
160
+ mockWalletProvider.getNetwork.mockReturnValue({
161
+ protocolFamily: "evm",
162
+ networkId: testCase.networkId,
163
+ });
164
+ mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
165
+ mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
166
+ await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
167
+ expect(mockAccount.useSpendPermission).toHaveBeenCalledWith({
168
+ spendPermission: mockPermission,
169
+ value: BigInt(2500),
170
+ network: testCase.expected,
171
+ });
172
+ }
173
+ });
174
+ it("should handle unknown networks by passing them as-is", async () => {
175
+ mockWalletProvider.getNetwork.mockReturnValue({
176
+ protocolFamily: "evm",
177
+ networkId: "polygon-mainnet",
178
+ });
179
+ const mockPermission = { spender: "0x1234", token: "MATIC" };
180
+ const mockSpendResult = { status: "completed" };
181
+ spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
182
+ mockAccount.useSpendPermission.mockResolvedValue(mockSpendResult);
183
+ await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
184
+ expect(mockAccount.useSpendPermission).toHaveBeenCalledWith({
185
+ spendPermission: mockPermission,
186
+ value: BigInt(2500),
187
+ network: "polygon-mainnet",
188
+ });
189
+ });
190
+ it("should return error message for non-EVM networks", async () => {
191
+ mockWalletProvider.getNetwork.mockReturnValue({
192
+ protocolFamily: "svm",
193
+ networkId: "solana-devnet",
194
+ });
195
+ const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
196
+ expect(result).toBe("Spend permissions are currently only supported on EVM networks.");
197
+ });
198
+ it("should handle spend permission not found error", async () => {
199
+ spendPermissionUtils.findLatestSpendPermission.mockRejectedValue(new Error("No spend permissions found for spender"));
200
+ const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
201
+ expect(result).toBe("Failed to use spend permission: Error: No spend permissions found for spender");
202
+ });
203
+ it("should handle account creation failure", async () => {
204
+ spendPermissionUtils.findLatestSpendPermission.mockResolvedValue({
205
+ spender: "0x1234",
206
+ token: "ETH",
207
+ });
208
+ mockCdpClient.evm.getAccount.mockRejectedValue(new Error("Account not found"));
209
+ const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
210
+ expect(result).toBe("Failed to use spend permission: Error: Account not found");
211
+ });
212
+ it("should handle account use permission failure", async () => {
213
+ const mockPermission = { spender: "0x1234", token: "ETH" };
214
+ spendPermissionUtils.findLatestSpendPermission.mockResolvedValue(mockPermission);
215
+ mockAccount.useSpendPermission.mockRejectedValue(new Error("Insufficient allowance"));
216
+ const result = await actionProvider.useSpendPermission(mockWalletProvider, mockArgs);
217
+ expect(result).toBe("Failed to use spend permission: Error: Insufficient allowance");
218
+ });
219
+ it("should validate input schema", () => {
220
+ const validInput = {
221
+ smartAccountAddress: "0xabcd1234567890123456789012345678901234567890",
222
+ value: "1000",
223
+ };
224
+ const invalidInput = {
225
+ smartAccountAddress: "not-an-address",
226
+ value: -100,
227
+ };
228
+ expect(() => schemas_1.UseSpendPermissionSchema.parse(validInput)).not.toThrow();
229
+ expect(() => schemas_1.UseSpendPermissionSchema.parse(invalidInput)).toThrow();
230
+ });
231
+ });
232
+ describe("supportsNetwork", () => {
233
+ it("should return true for EVM networks", () => {
234
+ const evmNetwork = { protocolFamily: "evm", networkId: "base-sepolia" };
235
+ expect(actionProvider.supportsNetwork(evmNetwork)).toBe(true);
236
+ });
237
+ it("should return false for non-EVM networks", () => {
238
+ const svmNetwork = { protocolFamily: "svm", networkId: "solana-devnet" };
239
+ expect(actionProvider.supportsNetwork(svmNetwork)).toBe(false);
240
+ });
241
+ });
242
+ });