@coinbase/agentkit 0.9.0 → 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 (74) hide show
  1. package/README.md +137 -55
  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/farcaster/farcasterActionProvider.js +2 -0
  18. package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
  19. package/dist/action-providers/farcaster/schemas.d.ts +13 -0
  20. package/dist/action-providers/farcaster/schemas.js +6 -0
  21. package/dist/action-providers/index.d.ts +3 -0
  22. package/dist/action-providers/index.js +3 -0
  23. package/dist/action-providers/truemarkets/constants.d.ts +179 -0
  24. package/dist/action-providers/truemarkets/constants.js +46 -0
  25. package/dist/action-providers/truemarkets/index.d.ts +1 -0
  26. package/dist/action-providers/truemarkets/index.js +17 -0
  27. package/dist/action-providers/truemarkets/schemas.d.ts +21 -0
  28. package/dist/action-providers/truemarkets/schemas.js +29 -0
  29. package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +51 -0
  30. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +469 -0
  31. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.d.ts +1 -0
  32. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +217 -0
  33. package/dist/action-providers/truemarkets/utils.d.ts +10 -0
  34. package/dist/action-providers/truemarkets/utils.js +9 -0
  35. package/dist/action-providers/twitter/schemas.d.ts +16 -0
  36. package/dist/action-providers/twitter/schemas.js +23 -1
  37. package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
  38. package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
  39. package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
  40. package/dist/action-providers/weth/constants.d.ts +9 -0
  41. package/dist/action-providers/weth/constants.js +12 -0
  42. package/dist/action-providers/weth/schemas.d.ts +7 -0
  43. package/dist/action-providers/weth/schemas.js +7 -1
  44. package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
  45. package/dist/action-providers/weth/wethActionProvider.js +50 -1
  46. package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
  47. package/dist/action-providers/zerion/constants.d.ts +1 -0
  48. package/dist/action-providers/zerion/constants.js +4 -0
  49. package/dist/action-providers/zerion/index.d.ts +2 -0
  50. package/dist/action-providers/zerion/index.js +18 -0
  51. package/dist/action-providers/zerion/schemas.d.ts +11 -0
  52. package/dist/action-providers/zerion/schemas.js +15 -0
  53. package/dist/action-providers/zerion/types.d.ts +125 -0
  54. package/dist/action-providers/zerion/types.js +16 -0
  55. package/dist/action-providers/zerion/utils.d.ts +3 -0
  56. package/dist/action-providers/zerion/utils.js +45 -0
  57. package/dist/action-providers/zerion/zerionActionProvider.d.ts +57 -0
  58. package/dist/action-providers/zerion/zerionActionProvider.js +159 -0
  59. package/dist/action-providers/zerion/zerionActionProvider.test.d.ts +1 -0
  60. package/dist/action-providers/zerion/zerionActionProvider.test.js +213 -0
  61. package/dist/action-providers/zora/index.d.ts +3 -0
  62. package/dist/action-providers/zora/index.js +19 -0
  63. package/dist/action-providers/zora/schemas.d.ts +29 -0
  64. package/dist/action-providers/zora/schemas.js +31 -0
  65. package/dist/action-providers/zora/utils.d.ts +28 -0
  66. package/dist/action-providers/zora/utils.js +200 -0
  67. package/dist/action-providers/zora/zoraActionProvider.d.ts +36 -0
  68. package/dist/action-providers/zora/zoraActionProvider.js +151 -0
  69. package/dist/action-providers/zora/zoraActionProvider.test.d.ts +1 -0
  70. package/dist/action-providers/zora/zoraActionProvider.test.js +205 -0
  71. package/dist/wallet-providers/cdpShared.d.ts +4 -0
  72. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +8 -1
  73. package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -11
  74. package/package.json +3 -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%">
@@ -261,7 +300,7 @@ const agent = createReactAgent({
261
300
  </tr>
262
301
  <tr>
263
302
  <td width="200"><code>post_cast</code></td>
264
- <td width="768">Creates a new cast (message) on Farcaster with up to 280 characters.</td>
303
+ <td width="768">Creates a new cast (message) on Farcaster with up to 280 characters and support for up to 2 embedded URLs.</td>
265
304
  </tr>
266
305
  </table>
267
306
  </details>
@@ -362,6 +401,23 @@ const agent = createReactAgent({
362
401
  <td width="200"><code>post_tweet_reply</code></td>
363
402
  <td width="768">Creates a reply to an existing tweet using the tweet's unique identifier.</td>
364
403
  </tr>
404
+ <tr>
405
+ <td width="200"><code>upload_media</code></td>
406
+ <td width="768">Uploads media (images, videos) to Twitter that can be attached to tweets.</td>
407
+ </tr>
408
+ </table>
409
+ </details>
410
+ <details>
411
+ <summary><strong>TrueMarkets</strong></summary>
412
+ <table width="100%">
413
+ <tr>
414
+ <td width="200"><code>get_active_markets</code></td>
415
+ <td width="768">Retrieves active prediction markets from Truemarkets with pagination and sorting options.</td>
416
+ </tr>
417
+ <tr>
418
+ <td width="200"><code>get_market_details</code></td>
419
+ <td width="768">Fetches comprehensive details for a specific Truemarkets prediction market including question, status, prices, and liquidity.</td>
420
+ </tr>
365
421
  </table>
366
422
  </details>
367
423
  <details>
@@ -384,6 +440,10 @@ const agent = createReactAgent({
384
440
  <td width="200"><code>wrap_eth</code></td>
385
441
  <td width="768">Converts native ETH to Wrapped ETH (WETH) on Base Sepolia or Base Mainnet.</td>
386
442
  </tr>
443
+ <tr>
444
+ <td width="200"><code>unwrap_eth</code></td>
445
+ <td width="768">Converts Wrapped ETH (WETH) to Native ETH on Base Sepolia or Base Mainnet.</td>
446
+ </tr>
387
447
  </table>
388
448
  </details>
389
449
  <details>
@@ -431,6 +491,19 @@ it will return payment details that can be used on retry.</td>
431
491
  </table>
432
492
  </details>
433
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>
434
507
  <summary><strong>ZeroDev Wallet</strong></summary>
435
508
  <table width="100%">
436
509
  <tr>
@@ -439,6 +512,15 @@ it will return payment details that can be used on retry.</td>
439
512
  </tr>
440
513
  </table>
441
514
  </details>
515
+ <details>
516
+ <summary><strong>Zora</strong></summary>
517
+ <table width="100%">
518
+ <tr>
519
+ <td width="200"><code>coinIt</code></td>
520
+ <td width="768">Creates a new Zora coin with customizable name, symbol, description, and image.</td>
521
+ </tr>
522
+ </table>
523
+ </details>
442
524
 
443
525
  ## Creating an Action Provider
444
526
 
@@ -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;