@coinbase/agentkit 0.10.0 → 0.10.1

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 (131) hide show
  1. package/README.md +75 -0
  2. package/dist/action-providers/across/acrossActionProvider.js +3 -3
  3. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
  4. package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
  5. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
  6. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
  7. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +223 -23
  8. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +278 -0
  9. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
  10. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +223 -18
  11. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +265 -1
  12. package/dist/action-providers/cdp/schemas.d.ts +12 -12
  13. package/dist/action-providers/cdp/schemas.js +17 -5
  14. package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
  15. package/dist/action-providers/cdp/swapUtils.js +142 -0
  16. package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
  17. package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
  18. package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
  19. package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
  20. package/dist/action-providers/clanker/index.d.ts +2 -0
  21. package/dist/action-providers/clanker/index.js +18 -0
  22. package/dist/action-providers/clanker/schemas.d.ts +56 -0
  23. package/dist/action-providers/clanker/schemas.js +47 -0
  24. package/dist/action-providers/clanker/utils.d.ts +9 -0
  25. package/dist/action-providers/clanker/utils.js +23 -0
  26. package/dist/action-providers/compound/constants.d.ts +1 -1
  27. package/dist/action-providers/compound/constants.js +2 -2
  28. package/dist/action-providers/erc20/constants.d.ts +35 -135
  29. package/dist/action-providers/erc20/constants.js +37 -189
  30. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
  31. package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
  32. package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
  33. package/dist/action-providers/erc20/schemas.d.ts +25 -12
  34. package/dist/action-providers/erc20/schemas.js +34 -6
  35. package/dist/action-providers/erc20/utils.d.ts +19 -0
  36. package/dist/action-providers/erc20/utils.js +54 -0
  37. package/dist/action-providers/flaunch/constants.d.ts +1 -1
  38. package/dist/action-providers/flaunch/constants.js +2 -2
  39. package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
  40. package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
  41. package/dist/action-providers/index.d.ts +3 -0
  42. package/dist/action-providers/index.js +3 -0
  43. package/dist/action-providers/jupiter/schemas.d.ts +1 -1
  44. package/dist/action-providers/moonwell/schemas.d.ts +2 -2
  45. package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
  46. package/dist/action-providers/morpho/schemas.d.ts +2 -2
  47. package/dist/action-providers/pyth/pythActionProvider.js +5 -0
  48. package/dist/action-providers/pyth/pythActionProvider.test.js +5 -1
  49. package/dist/action-providers/superfluid/constants.d.ts +814 -0
  50. package/dist/action-providers/superfluid/constants.js +2826 -0
  51. package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
  52. package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
  53. package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
  54. package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
  55. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
  56. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
  57. package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
  58. package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
  59. package/dist/action-providers/superfluid/index.d.ts +7 -0
  60. package/dist/action-providers/superfluid/index.js +23 -0
  61. package/dist/action-providers/superfluid/schemas.d.ts +86 -0
  62. package/dist/action-providers/superfluid/schemas.js +103 -0
  63. package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
  64. package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
  65. package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
  66. package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
  67. package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
  68. package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
  69. package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
  70. package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
  71. package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
  72. package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
  73. package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
  74. package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
  75. package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
  76. package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
  77. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
  78. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
  79. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
  80. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
  81. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
  82. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
  83. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
  84. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
  85. package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
  86. package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
  87. package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
  88. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
  89. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
  90. package/dist/action-providers/wallet/walletActionProvider.js +21 -10
  91. package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
  92. package/dist/action-providers/zeroX/index.d.ts +1 -0
  93. package/dist/action-providers/zeroX/index.js +17 -0
  94. package/dist/action-providers/zeroX/schemas.d.ts +51 -0
  95. package/dist/action-providers/zeroX/schemas.js +82 -0
  96. package/dist/action-providers/zeroX/utils.d.ts +23 -0
  97. package/dist/action-providers/zeroX/utils.js +106 -0
  98. package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
  99. package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
  100. package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
  101. package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
  102. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +20 -2
  103. package/dist/wallet-providers/cdpEvmWalletProvider.js +40 -15
  104. package/dist/wallet-providers/cdpShared.d.ts +5 -0
  105. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +22 -3
  106. package/dist/wallet-providers/cdpSmartWalletProvider.js +43 -19
  107. package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
  108. package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
  109. package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
  110. package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
  111. package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -2
  112. package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +12 -2
  113. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +12 -2
  114. package/dist/wallet-providers/legacyCdpWalletProvider.js +11 -2
  115. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +10 -2
  116. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +12 -3
  117. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
  118. package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
  119. package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
  120. package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
  121. package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
  122. package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
  123. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
  124. package/dist/wallet-providers/viemWalletProvider.d.ts +12 -2
  125. package/dist/wallet-providers/viemWalletProvider.js +12 -3
  126. package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
  127. package/dist/wallet-providers/walletProvider.d.ts +1 -1
  128. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +10 -2
  129. package/dist/wallet-providers/zeroDevWalletProvider.js +14 -5
  130. package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
  131. package/package.json +4 -2
package/README.md CHANGED
@@ -182,6 +182,14 @@ const agent = createReactAgent({
182
182
  <td width="200"><code>use_spend_permission</code></td>
183
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
184
  </tr>
185
+ <tr>
186
+ <td width="200"><code>get_swap_price</code></td>
187
+ <td width="768">Fetches a price quote for swapping between two tokens using the CDP Swap API (does not execute swap).</td>
188
+ </tr>
189
+ <tr>
190
+ <td width="200"><code>swap</code></td>
191
+ <td width="768">Executes a token swap using the CDP Swap API with automatic token approvals.</td>
192
+ </tr>
185
193
  </table>
186
194
  </details>
187
195
  <details>
@@ -195,6 +203,14 @@ const agent = createReactAgent({
195
203
  <td width="200"><code>use_spend_permission</code></td>
196
204
  <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
205
  </tr>
206
+ <tr>
207
+ <td width="200"><code>get_swap_price</code></td>
208
+ <td width="768">Fetches a price quote for swapping between two tokens using the CDP Swap API (does not execute swap).</td>
209
+ </tr>
210
+ <tr>
211
+ <td width="200"><code>swap</code></td>
212
+ <td width="768">Executes a token swap using the CDP Swap API with automatic token approvals.</td>
213
+ </tr>
198
214
  </table>
199
215
  </details>
200
216
  <details>
@@ -220,6 +236,15 @@ const agent = createReactAgent({
220
236
  </table>
221
237
  </details>
222
238
  <details>
239
+ <summary><strong>Clanker</strong></summary>
240
+ <table width="100%">
241
+ <tr>
242
+ <td width="200"><code>clank_token</code></td>
243
+ <td width="768">Deploys an ERC20 Clanker token based on the supplied config.</td>
244
+ </tr>
245
+ </table>
246
+ </details>
247
+ <details>
223
248
  <summary><strong>Compound</strong></summary>
224
249
  <table width="100%">
225
250
  <tr>
@@ -272,6 +297,10 @@ const agent = createReactAgent({
272
297
  <td width="200"><code>transfer</code></td>
273
298
  <td width="768">Transfers a specified amount of ERC-20 tokens to a destination address.</td>
274
299
  </tr>
300
+ <tr>
301
+ <td width="200"><code>get_erc20_token_address</code></td>
302
+ <td width="768">Gets the contract address for frequently used ERC20 tokens on different networks by token symbol.</td>
303
+ </tr>
275
304
  </table>
276
305
  </details>
277
306
  <details>
@@ -383,6 +412,43 @@ const agent = createReactAgent({
383
412
  </table>
384
413
  </details>
385
414
  <details>
415
+ <summary><strong>Superfluid</strong></summary>
416
+ <table width="100%">
417
+ <tr>
418
+ <td width="200"><code>create_pool</code></td>
419
+ <td width="768">Creates a new Superfluid pool for a Supertoken.</td>
420
+ </tr>
421
+ <tr>
422
+ <td width="200"><code>update_pool</code></td>
423
+ <td width="768">Updates an existing Superfluid pool with recipients and flow rates.</td>
424
+ </tr>
425
+ <tr>
426
+ <td width="200"><code>query_streams</code></td>
427
+ <td width="768">Queries existing Superfluid streams using Graphql.</td>
428
+ </tr>
429
+ <tr>
430
+ <td width="200"><code>create_stream</code></td>
431
+ <td width="768">Creates a new Superfluid stream to an address with a given flow rate.</td>
432
+ </tr>
433
+ <tr>
434
+ <td width="200"><code>update_stream</code></td>
435
+ <td width="768">Updates an existing Superfluid stream with a new flow rate.</td>
436
+ </tr>
437
+ <tr>
438
+ <td width="200"><code>delete_stream</code></td>
439
+ <td width="768">Stops an existing Superfluid stream.</td>
440
+ </tr>
441
+ <tr>
442
+ <td width="200"><code>create_super_token</code></td>
443
+ <td width="768">Creates a new Supertoken implementation for an existing ERC20 token.</td>
444
+ </tr>
445
+ <tr>
446
+ <td width="200"><code>wrap_superfluid_token</code></td>
447
+ <td width="768">Wraps an ERC20 token into its Superfluid Super token implementation.</td>
448
+ </tr>
449
+ </table>
450
+ </details>
451
+ <details>
386
452
  <summary><strong>Twitter</strong></summary>
387
453
  <table width="100%">
388
454
  <tr>
@@ -487,6 +553,15 @@ it will return payment details that can be used on retry.</td>
487
553
  <tr>
488
554
  <td width="200"><code>make_http_request_with_x402</code></td>
489
555
  <td width="768">Combines make_http_request and retry_http_request_with_x402 into a single step.</td>
556
+ <summary><strong>ZeroX</strong></summary>
557
+ <table width="100%">
558
+ <tr>
559
+ <td width="200"><code>get_swap_price_quote_from_0x</code></td>
560
+ <td width="768">Fetches a price quote for swapping between two tokens using the 0x API.</td>
561
+ </tr>
562
+ <tr>
563
+ <td width="200"><code>execute_swap_on_0x</code></td>
564
+ <td width="768">Executes a token swap between two tokens using the 0x API.</td>
490
565
  </tr>
491
566
  </table>
492
567
  </details>
@@ -31,7 +31,7 @@ const schemas_1 = require("./schemas");
31
31
  const wallet_providers_1 = require("../../wallet-providers");
32
32
  const utils_1 = require("./utils");
33
33
  const accounts_1 = require("viem/accounts");
34
- const constants_1 = require("../erc20/constants");
34
+ const viem_2 = require("viem");
35
35
  /**
36
36
  * AcrossActionProvider provides actions for cross-chain bridging via Across Protocol.
37
37
  */
@@ -141,7 +141,7 @@ class AcrossActionProvider extends actionProvider_1.ActionProvider {
141
141
  // Check ERC20 token balance
142
142
  const tokenBalance = (await walletProvider.readContract({
143
143
  address: inputToken,
144
- abi: constants_1.abi,
144
+ abi: viem_2.erc20Abi,
145
145
  functionName: "balanceOf",
146
146
  args: [address],
147
147
  }));
@@ -194,7 +194,7 @@ class AcrossActionProvider extends actionProvider_1.ActionProvider {
194
194
  approvalTxHash = await walletProvider.sendTransaction({
195
195
  to: inputToken,
196
196
  data: (0, viem_1.encodeFunctionData)({
197
- abi: constants_1.abi,
197
+ abi: viem_2.erc20Abi,
198
198
  functionName: "approve",
199
199
  args: [quote.deposit.spokePoolAddress, quote.deposit.inputAmount],
200
200
  }),
@@ -2,14 +2,13 @@ import { z } from "zod";
2
2
  import { Network } from "../../network";
3
3
  import { WalletProvider } from "../../wallet-providers";
4
4
  import { ActionProvider } from "../actionProvider";
5
- import { RequestFaucetFundsV2Schema, SwapSchema } from "./schemas";
5
+ import { RequestFaucetFundsV2Schema } from "./schemas";
6
6
  /**
7
7
  * CdpApiActionProvider is an action provider for CDP API.
8
8
  *
9
9
  * This provider is used for any action that uses the CDP API, but does not require a CDP Wallet.
10
10
  */
11
11
  export declare class CdpApiActionProvider extends ActionProvider<WalletProvider> {
12
- #private;
13
12
  /**
14
13
  * Constructor for the CdpApiActionProvider class.
15
14
  */
@@ -23,20 +22,12 @@ export declare class CdpApiActionProvider extends ActionProvider<WalletProvider>
23
22
  */
24
23
  faucet(walletProvider: WalletProvider, args: z.infer<typeof RequestFaucetFundsV2Schema>): Promise<string>;
25
24
  /**
26
- * Swaps tokens using the CDP client.
27
- *
28
- * @param walletProvider - The wallet provider to perform the swap with.
29
- * @param args - The input arguments for the swap action.
30
- * @returns A confirmation message with transaction details.
31
- */
32
- swap(walletProvider: WalletProvider, args: z.infer<typeof SwapSchema>): Promise<string>;
33
- /**
34
- * Checks if the Cdp action provider supports the given network.
25
+ * Checks if the CDP action provider supports the given network.
35
26
  *
36
27
  * NOTE: Network scoping is done at the action implementation level
37
28
  *
38
29
  * @param _ - The network to check.
39
- * @returns True if the Cdp action provider supports the network, false otherwise.
30
+ * @returns True if the CDP action provider supports the network, false otherwise.
40
31
  */
41
32
  supportsNetwork: (_: Network) => boolean;
42
33
  }
@@ -8,12 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
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 _CdpApiActionProvider_instances, _CdpApiActionProvider_getCdpSdkNetwork;
17
11
  Object.defineProperty(exports, "__esModule", { value: true });
18
12
  exports.cdpApiActionProvider = exports.CdpApiActionProvider = void 0;
19
13
  const zod_1 = require("zod");
@@ -33,14 +27,13 @@ class CdpApiActionProvider extends actionProvider_1.ActionProvider {
33
27
  */
34
28
  constructor() {
35
29
  super("cdp_api", []);
36
- _CdpApiActionProvider_instances.add(this);
37
30
  /**
38
- * Checks if the Cdp action provider supports the given network.
31
+ * Checks if the CDP action provider supports the given network.
39
32
  *
40
33
  * NOTE: Network scoping is done at the action implementation level
41
34
  *
42
35
  * @param _ - The network to check.
43
- * @returns True if the Cdp action provider supports the network, false otherwise.
36
+ * @returns True if the CDP action provider supports the network, false otherwise.
44
37
  */
45
38
  this.supportsNetwork = (_) => true;
46
39
  }
@@ -84,66 +77,8 @@ class CdpApiActionProvider extends actionProvider_1.ActionProvider {
84
77
  throw new Error("Wallet provider is not a CDP Wallet Provider.");
85
78
  }
86
79
  }
87
- /**
88
- * Swaps tokens using the CDP client.
89
- *
90
- * @param walletProvider - The wallet provider to perform the swap with.
91
- * @param args - The input arguments for the swap action.
92
- * @returns A confirmation message with transaction details.
93
- */
94
- async swap(walletProvider, args) {
95
- const network = walletProvider.getNetwork();
96
- const networkId = network.networkId;
97
- if ((0, cdpShared_1.isWalletProviderWithClient)(walletProvider)) {
98
- if (network.protocolFamily === "evm") {
99
- try {
100
- const cdpNetwork = __classPrivateFieldGet(this, _CdpApiActionProvider_instances, "m", _CdpApiActionProvider_getCdpSdkNetwork).call(this, networkId);
101
- // Get the account for the wallet address
102
- const account = await walletProvider.getClient().evm.getAccount({
103
- address: walletProvider.getAddress(),
104
- });
105
- // Execute swap using the all-in-one pattern
106
- const swapResult = await account.swap({
107
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
- network: cdpNetwork,
109
- from: args.fromAssetId,
110
- to: args.toAssetId,
111
- amount: args.amount,
112
- slippageBps: 100, // 1% slippage tolerance
113
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
- paymasterUrl: walletProvider.getPaymasterUrl?.(),
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- });
117
- return `Successfully swapped ${args.amount} ${args.fromAssetId.toUpperCase()} to ${args.toAssetId.toUpperCase()}. Transaction hash: ${swapResult.transactionHash}`;
118
- }
119
- catch (error) {
120
- throw new Error(`Swap failed: ${error}`);
121
- }
122
- }
123
- else {
124
- throw new Error("Swap is currently only supported on EVM networks.");
125
- }
126
- }
127
- else {
128
- throw new Error("Wallet provider is not a CDP Wallet Provider.");
129
- }
130
- }
131
80
  }
132
81
  exports.CdpApiActionProvider = CdpApiActionProvider;
133
- _CdpApiActionProvider_instances = new WeakSet(), _CdpApiActionProvider_getCdpSdkNetwork = function _CdpApiActionProvider_getCdpSdkNetwork(networkId) {
134
- switch (networkId) {
135
- case "base-sepolia":
136
- return "base-sepolia";
137
- case "base-mainnet":
138
- return "base";
139
- case "ethereum-sepolia":
140
- return "ethereum-sepolia";
141
- case "ethereum-mainnet":
142
- return "ethereum";
143
- default:
144
- return networkId; // For other networks, use as-is
145
- }
146
- };
147
82
  __decorate([
148
83
  (0, actionDecorator_1.CreateAction)({
149
84
  name: "request_faucet_funds",
@@ -159,19 +94,5 @@ from another wallet and provide the user with your wallet details.`,
159
94
  __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
160
95
  __metadata("design:returntype", Promise)
161
96
  ], CdpApiActionProvider.prototype, "faucet", null);
162
- __decorate([
163
- (0, actionDecorator_1.CreateAction)({
164
- name: "swap",
165
- description: `This tool swaps tokens using the CDP API. It takes the wallet, from asset ID, to asset ID, and amount as input.
166
- Swaps are currently supported on EVM networks like Base and Ethereum.
167
- Example usage:
168
- - Swap 0.1 ETH to USDC: { fromAssetId: "eth", toAssetId: "usdc", amount: "0.1" }
169
- - Swap 100 USDC to ETH: { fromAssetId: "usdc", toAssetId: "eth", amount: "100" }`,
170
- schema: schemas_1.SwapSchema,
171
- }),
172
- __metadata("design:type", Function),
173
- __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
174
- __metadata("design:returntype", Promise)
175
- ], CdpApiActionProvider.prototype, "swap", null);
176
97
  const cdpApiActionProvider = () => new CdpApiActionProvider();
177
98
  exports.cdpApiActionProvider = cdpApiActionProvider;
@@ -10,20 +10,14 @@ describe("CDP API Action Provider", () => {
10
10
  let mockCdpClient;
11
11
  beforeEach(() => {
12
12
  jest.clearAllMocks();
13
- const mockAccount = {
14
- swap: jest.fn(),
15
- };
16
13
  mockCdpClient = {
17
14
  evm: {
18
15
  requestFaucet: jest.fn(),
19
- getAccount: jest.fn(),
20
16
  },
21
17
  solana: {
22
18
  requestFaucet: jest.fn(),
23
19
  },
24
20
  };
25
- // Set up default mock behavior
26
- mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
27
21
  mockWalletProvider = {
28
22
  getNetwork: jest.fn(),
29
23
  getAddress: jest.fn(),
@@ -93,94 +87,6 @@ describe("CDP API Action Provider", () => {
93
87
  await expect(actionProvider.faucet(mockWalletWithoutClient, { assetId: "eth" })).rejects.toThrow("Wallet provider is not a CDP Wallet Provider");
94
88
  });
95
89
  });
96
- describe("swap", () => {
97
- it("should perform swap on base-sepolia", async () => {
98
- const mockNetwork = { protocolFamily: "evm", networkId: "base-sepolia" };
99
- mockWalletProvider.getNetwork.mockReturnValue(mockNetwork);
100
- mockWalletProvider.getAddress.mockReturnValue("0x123456789");
101
- mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
102
- const mockAccount = { swap: jest.fn() };
103
- mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
104
- mockAccount.swap.mockResolvedValue({
105
- transactionHash: "0xswap123456",
106
- });
107
- const result = await actionProvider.swap(mockWalletProvider, {
108
- fromAssetId: "eth",
109
- toAssetId: "usdc",
110
- amount: "0.1",
111
- });
112
- expect(mockCdpClient.evm.getAccount).toHaveBeenCalledWith({
113
- address: "0x123456789",
114
- });
115
- expect(mockAccount.swap).toHaveBeenCalledWith({
116
- network: "base-sepolia",
117
- from: "eth",
118
- to: "usdc",
119
- amount: "0.1",
120
- slippageBps: 100,
121
- });
122
- expect(result).toContain("Successfully swapped 0.1 ETH to USDC");
123
- expect(result).toContain("0xswap123456");
124
- });
125
- it("should perform swap on base-mainnet", async () => {
126
- const mockNetwork = { protocolFamily: "evm", networkId: "base-mainnet" };
127
- mockWalletProvider.getNetwork.mockReturnValue(mockNetwork);
128
- mockWalletProvider.getAddress.mockReturnValue("0x123456789");
129
- mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
130
- const mockAccount = { swap: jest.fn() };
131
- mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
132
- mockAccount.swap.mockResolvedValue({
133
- transactionHash: "0xswap789",
134
- });
135
- const result = await actionProvider.swap(mockWalletProvider, {
136
- fromAssetId: "usdc",
137
- toAssetId: "eth",
138
- amount: "100",
139
- });
140
- expect(mockAccount.swap).toHaveBeenCalledWith({
141
- network: "base", // Should convert base-mainnet to base
142
- from: "usdc",
143
- to: "eth",
144
- amount: "100",
145
- slippageBps: 100,
146
- });
147
- expect(result).toContain("Successfully swapped 100 USDC to ETH");
148
- });
149
- it("should throw error for non-EVM networks", async () => {
150
- const mockNetwork = { protocolFamily: "svm", networkId: "solana-devnet" };
151
- mockWalletProvider.getNetwork.mockReturnValue(mockNetwork);
152
- mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
153
- await expect(actionProvider.swap(mockWalletProvider, {
154
- fromAssetId: "sol",
155
- toAssetId: "usdc",
156
- amount: "1",
157
- })).rejects.toThrow("Swap is currently only supported on EVM networks");
158
- });
159
- it("should throw error for wallet provider without client", async () => {
160
- const mockWalletWithoutClient = {
161
- getNetwork: jest.fn().mockReturnValue({ protocolFamily: "evm", networkId: "base-sepolia" }),
162
- };
163
- await expect(actionProvider.swap(mockWalletWithoutClient, {
164
- fromAssetId: "eth",
165
- toAssetId: "usdc",
166
- amount: "0.1",
167
- })).rejects.toThrow("Wallet provider is not a CDP Wallet Provider");
168
- });
169
- it("should handle swap errors", async () => {
170
- const mockNetwork = { protocolFamily: "evm", networkId: "base-sepolia" };
171
- mockWalletProvider.getNetwork.mockReturnValue(mockNetwork);
172
- mockWalletProvider.getAddress.mockReturnValue("0x123456789");
173
- mockWalletProvider.getClient.mockReturnValue(mockCdpClient);
174
- const mockAccount = { swap: jest.fn() };
175
- mockCdpClient.evm.getAccount.mockResolvedValue(mockAccount);
176
- mockAccount.swap.mockRejectedValue(new Error("Insufficient liquidity"));
177
- await expect(actionProvider.swap(mockWalletProvider, {
178
- fromAssetId: "eth",
179
- toAssetId: "usdc",
180
- amount: "1000",
181
- })).rejects.toThrow("Swap failed: Error: Insufficient liquidity");
182
- });
183
- });
184
90
  describe("RequestFaucetFundsV2Schema", () => {
185
91
  it("should validate correct input", () => {
186
92
  const validInput = { assetId: "eth" };
@@ -193,35 +99,4 @@ describe("CDP API Action Provider", () => {
193
99
  expect(result.success).toBe(true);
194
100
  });
195
101
  });
196
- describe("SwapSchema", () => {
197
- it("should validate correct swap input", () => {
198
- const validInput = {
199
- fromAssetId: "eth",
200
- toAssetId: "usdc",
201
- amount: "0.1",
202
- };
203
- const result = schemas_1.SwapSchema.safeParse(validInput);
204
- expect(result.success).toBe(true);
205
- expect(result.data).toEqual(validInput);
206
- });
207
- it("should validate swap input with network", () => {
208
- const validInput = {
209
- fromAssetId: "usdc",
210
- toAssetId: "eth",
211
- amount: "100",
212
- network: "base-sepolia",
213
- };
214
- const result = schemas_1.SwapSchema.safeParse(validInput);
215
- expect(result.success).toBe(true);
216
- expect(result.data).toEqual(validInput);
217
- });
218
- it("should fail validation when missing required fields", () => {
219
- const invalidInput = {
220
- fromAssetId: "eth",
221
- // missing toAssetId and amount
222
- };
223
- const result = schemas_1.SwapSchema.safeParse(invalidInput);
224
- expect(result.success).toBe(false);
225
- });
226
- });
227
102
  });
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { WalletProvider } from "../../wallet-providers";
3
3
  import { CdpEvmWalletProvider } from "../../wallet-providers/cdpEvmWalletProvider";
4
4
  import { ActionProvider } from "../actionProvider";
5
- import { UseSpendPermissionSchema, ListSpendPermissionsSchema } from "./schemas";
5
+ import { UseSpendPermissionSchema, ListSpendPermissionsSchema, SwapSchema } from "./schemas";
6
6
  import type { Network } from "../../network";
7
7
  /**
8
8
  * CdpEvmWalletActionProvider is an action provider for CDP EVM Wallet specific actions.
@@ -11,7 +11,6 @@ import type { Network } from "../../network";
11
11
  * that are optimized for EVM functionality, including spend permission usage.
12
12
  */
13
13
  export declare class CdpEvmWalletActionProvider extends ActionProvider<CdpEvmWalletProvider> {
14
- #private;
15
14
  /**
16
15
  * Constructor for the CdpEvmWalletActionProvider class.
17
16
  */
@@ -31,7 +30,23 @@ export declare class CdpEvmWalletActionProvider extends ActionProvider<CdpEvmWal
31
30
  * @param args - The input arguments for using the spend permission.
32
31
  * @returns A confirmation message with transaction details.
33
32
  */
34
- useSpendPermission(walletProvider: WalletProvider, args: z.infer<typeof UseSpendPermissionSchema>): Promise<string>;
33
+ useSpendPermission(walletProvider: CdpEvmWalletProvider, args: z.infer<typeof UseSpendPermissionSchema>): Promise<string>;
34
+ /**
35
+ * Gets a price quote for swapping tokens using the CDP Swap API.
36
+ *
37
+ * @param walletProvider - The EVM wallet provider to get the quote for.
38
+ * @param args - The input arguments for the swap price action.
39
+ * @returns A JSON string with detailed swap price quote information.
40
+ */
41
+ getSwapPrice(walletProvider: CdpEvmWalletProvider, args: z.infer<typeof SwapSchema>): Promise<string>;
42
+ /**
43
+ * Swaps tokens using the CDP client.
44
+ *
45
+ * @param walletProvider - The EVM wallet provider to perform the swap with.
46
+ * @param args - The input arguments for the swap action.
47
+ * @returns A JSON string with detailed swap execution information.
48
+ */
49
+ swap(walletProvider: CdpEvmWalletProvider, args: z.infer<typeof SwapSchema>): Promise<string>;
35
50
  /**
36
51
  * Checks if the EVM wallet action provider supports the given network.
37
52
  *