@coinbase/agentkit 0.0.0-nightly-20250501210425 → 0.0.0-nightly-20250612210418

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 (27) hide show
  1. package/README.md +20 -20
  2. package/dist/action-providers/cdp/cdpApiActionProvider.js +3 -3
  3. package/dist/action-providers/cdp/cdpWalletActionProvider.js +3 -3
  4. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +2 -5
  5. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +27 -20
  6. package/dist/action-providers/vaultsfyi/api/historicalData.d.ts +31 -0
  7. package/dist/action-providers/vaultsfyi/api/historicalData.js +44 -0
  8. package/dist/action-providers/vaultsfyi/api/vaults.d.ts +38 -10
  9. package/dist/action-providers/vaultsfyi/api/vaults.js +19 -1
  10. package/dist/action-providers/vaultsfyi/schemas.d.ts +38 -3
  11. package/dist/action-providers/vaultsfyi/schemas.js +35 -3
  12. package/dist/action-providers/vaultsfyi/utils.d.ts +64 -0
  13. package/dist/action-providers/vaultsfyi/utils.js +53 -0
  14. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +18 -2
  15. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +87 -20
  16. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +165 -0
  17. package/dist/agentkit.d.ts +2 -2
  18. package/dist/agentkit.js +4 -4
  19. package/dist/wallet-providers/cdpV2EvmWalletProvider.js +21 -1
  20. package/dist/wallet-providers/cdpV2Shared.d.ts +7 -0
  21. package/dist/wallet-providers/cdpV2Shared.js +13 -0
  22. package/dist/wallet-providers/cdpWalletProvider.d.ts +2 -2
  23. package/dist/wallet-providers/cdpWalletProvider.js +3 -3
  24. package/dist/wallet-providers/cdpWalletProvider.test.js +6 -6
  25. package/dist/wallet-providers/smartWalletProvider.d.ts +4 -4
  26. package/dist/wallet-providers/smartWalletProvider.js +7 -7
  27. package/package.json +4 -4
@@ -4,6 +4,8 @@ exports.getVaultsLink = getVaultsLink;
4
4
  exports.executeActions = executeActions;
5
5
  exports.createSearchParams = createSearchParams;
6
6
  exports.parseAssetAmount = parseAssetAmount;
7
+ exports.transformVault = transformVault;
8
+ exports.transformDetailedVault = transformDetailedVault;
7
9
  const viem_1 = require("viem");
8
10
  /**
9
11
  * Get the link to the vaults.fyi page for a vault
@@ -67,3 +69,54 @@ async function parseAssetAmount(wallet, assetAddress, amount) {
67
69
  });
68
70
  return Math.floor(amount * 10 ** decimals);
69
71
  }
72
+ /**
73
+ * Transform a vault from the API to a format that can be used by the agent
74
+ *
75
+ * @param vault - The vault to transform
76
+ * @param apyRange - The APY range to use
77
+ * @returns The transformed vault
78
+ */
79
+ function transformVault(vault, apyRange) {
80
+ return {
81
+ name: vault.name,
82
+ address: vault.address,
83
+ network: vault.network,
84
+ protocol: vault.protocol,
85
+ tvlInUsd: Number(vault.tvlDetails.tvlUsd),
86
+ numberOfHolders: vault.numberOfHolders,
87
+ apy: {
88
+ base: vault.apy.base[apyRange] / 100,
89
+ rewards: vault.apy.rewards?.[apyRange] ? vault.apy.rewards[apyRange] / 100 : undefined,
90
+ total: vault.apy.total[apyRange] / 100,
91
+ },
92
+ token: {
93
+ address: vault.token.assetAddress,
94
+ name: vault.token.name,
95
+ symbol: vault.token.symbol,
96
+ },
97
+ vaultsFyiScore: vault.score.vaultScore,
98
+ link: getVaultsLink(vault),
99
+ };
100
+ }
101
+ /**
102
+ * Transform a detailed vault from the API to a format that can be used by the agent
103
+ *
104
+ * @param vault - The vault to transform
105
+ * @param apyRange - The APY range to use
106
+ * @returns The transformed vault
107
+ */
108
+ function transformDetailedVault(vault, apyRange) {
109
+ return {
110
+ ...transformVault(vault, apyRange),
111
+ rewards: vault.rewards.map(reward => ({
112
+ apy: reward.apy[apyRange] / 100,
113
+ asset: {
114
+ address: reward.asset.assetAddress,
115
+ name: reward.asset.name,
116
+ symbol: reward.asset.symbol,
117
+ },
118
+ })),
119
+ description: vault.description,
120
+ additionalIncentives: vault.additionalIncentives,
121
+ };
122
+ }
@@ -10,7 +10,7 @@ import { z } from "zod";
10
10
  import { ActionProvider } from "../actionProvider";
11
11
  import { Network } from "../../network";
12
12
  import { EvmWalletProvider } from "../../wallet-providers";
13
- import { claimActionSchema, depositActionSchema, redeemActionSchema, VaultsActionSchema } from "./schemas";
13
+ import { claimActionSchema, depositActionSchema, redeemActionSchema, VaultDetailsActionSchema, VaultHistoricalDataActionSchema, VaultsActionSchema } from "./schemas";
14
14
  /**
15
15
  * Configuration options for the OpenseaActionProvider.
16
16
  */
@@ -39,10 +39,26 @@ export declare class VaultsfyiActionProvider extends ActionProvider<EvmWalletPro
39
39
  * vaults action
40
40
  *
41
41
  * @param wallet - The wallet provider instance for blockchain interactions
42
- * @param args - Input arguments: token, network, transactionalOnly...
42
+ * @param args - Input arguments: token, network...
43
43
  * @returns A list of vaults.
44
44
  */
45
45
  vaults(wallet: EvmWalletProvider, args: z.infer<typeof VaultsActionSchema>): Promise<string>;
46
+ /**
47
+ * vault details action
48
+ *
49
+ * @param wallet - The wallet provider instance for blockchain interactions
50
+ * @param args - Input arguments: address, network, apyRange
51
+ * @returns A detailed view of a single vault.
52
+ */
53
+ vaultDetails(wallet: EvmWalletProvider, args: z.infer<typeof VaultDetailsActionSchema>): Promise<string>;
54
+ /**
55
+ * vault historical data action
56
+ *
57
+ * @param wallet - The wallet provider instance for blockchain interactions
58
+ * @param args - Input arguments: address, network, date, apyRange
59
+ * @returns A detailed view of a single vault.
60
+ */
61
+ vaultHistoricalData(wallet: EvmWalletProvider, args: z.infer<typeof VaultHistoricalDataActionSchema>): Promise<string>;
46
62
  /**
47
63
  * Deposit action
48
64
  *
@@ -27,6 +27,7 @@ const utils_1 = require("./utils");
27
27
  const constants_1 = require("./constants");
28
28
  const actions_1 = require("./api/actions");
29
29
  const vaults_1 = require("./api/vaults");
30
+ const historicalData_1 = require("./api/historicalData");
30
31
  /**
31
32
  * VaultsfyiActionProvider provides actions for vaultsfyi operations.
32
33
  *
@@ -52,10 +53,11 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
52
53
  * vaults action
53
54
  *
54
55
  * @param wallet - The wallet provider instance for blockchain interactions
55
- * @param args - Input arguments: token, network, transactionalOnly...
56
+ * @param args - Input arguments: token, network...
56
57
  * @returns A list of vaults.
57
58
  */
58
59
  async vaults(wallet, args) {
60
+ const apyRange = args.apyRange ?? "7day";
59
61
  const vaults = await (0, vaults_1.fetchVaults)(args, this.apiKey);
60
62
  if ("error" in vaults) {
61
63
  return `Failed to fetch vaults: ${vaults.error}, ${vaults.message}`;
@@ -66,24 +68,7 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
66
68
  .filter((value, index, self) => self.indexOf(value) === index);
67
69
  return `Protocol ${args.protocol} is not supported. Supported protocols are: ${supportedProtocols.join(", ")}`;
68
70
  }
69
- const transformedVaults = vaults.map(vault => ({
70
- name: vault.name,
71
- address: vault.address,
72
- network: vault.network,
73
- protocol: vault.protocol,
74
- tvlInUsd: Number(vault.tvlDetails.tvlUsd),
75
- apy: {
76
- base: vault.apy.base["7day"] / 100,
77
- rewards: vault.apy.rewards?.["7day"] ? vault.apy.rewards["7day"] / 100 : undefined,
78
- total: vault.apy.total["7day"] / 100,
79
- },
80
- token: {
81
- address: vault.token.assetAddress,
82
- name: vault.token.name,
83
- symbol: vault.token.symbol,
84
- },
85
- link: (0, utils_1.getVaultsLink)(vault),
86
- }));
71
+ const transformedVaults = vaults.map(vault => (0, utils_1.transformVault)(vault, apyRange));
87
72
  const filteredVaults = transformedVaults.filter(vault => args.protocol ? vault.protocol === args.protocol : true);
88
73
  const sortedVaults = filteredVaults.sort((a, b) => {
89
74
  if (args.sort?.field === "tvl") {
@@ -107,6 +92,49 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
107
92
  results,
108
93
  });
109
94
  }
95
+ /**
96
+ * vault details action
97
+ *
98
+ * @param wallet - The wallet provider instance for blockchain interactions
99
+ * @param args - Input arguments: address, network, apyRange
100
+ * @returns A detailed view of a single vault.
101
+ */
102
+ async vaultDetails(wallet, args) {
103
+ const vault = await (0, vaults_1.fetchVault)(args, this.apiKey);
104
+ if ("error" in vault) {
105
+ return `Failed to fetch vault: ${vault.error}, ${vault.message}`;
106
+ }
107
+ return JSON.stringify((0, utils_1.transformDetailedVault)(vault, args.apyRange ?? "7day"));
108
+ }
109
+ /**
110
+ * vault historical data action
111
+ *
112
+ * @param wallet - The wallet provider instance for blockchain interactions
113
+ * @param args - Input arguments: address, network, date, apyRange
114
+ * @returns A detailed view of a single vault.
115
+ */
116
+ async vaultHistoricalData(wallet, args) {
117
+ const data = await (0, historicalData_1.fetchVaultHistoricalData)(args, this.apiKey);
118
+ if ("error" in data) {
119
+ return `Failed to fetch vault: ${data.error}, ${data.message}`;
120
+ }
121
+ return JSON.stringify({
122
+ apy: {
123
+ apy: {
124
+ base: data.apy.apy.base / 100,
125
+ rewards: data.apy.apy.rewards ? data.apy.apy.rewards / 100 : undefined,
126
+ total: data.apy.apy.total / 100,
127
+ },
128
+ date: new Date(data.apy.timestamp * 1000).toISOString(),
129
+ blockNumber: data.apy.blockNumber,
130
+ },
131
+ tvl: {
132
+ tvlInUsd: data.tvl.tvlDetails.tvlUsd,
133
+ date: new Date(data.tvl.timestamp * 1000).toISOString(),
134
+ blockNumber: data.tvl.blockNumber,
135
+ },
136
+ });
137
+ }
110
138
  /**
111
139
  * Deposit action
112
140
  *
@@ -260,7 +288,7 @@ __decorate([
260
288
  This action returns a list of available vaults.
261
289
  Small vaults (under 100k TVL) are probably best avoided as they may be more risky. Unless the user is looking for high-risk, high-reward opportunities, don't include them.
262
290
  When the user asks for best vaults, optimize for apy, and if the user asks for safest/reliable vaults, optimize for TVL.
263
- Try to take a reasonable number of results so its easier to analyze the data.
291
+ Try to take a reasonable number of results so its easier to analyze the data. Include vaults.fyi links for each vault.
264
292
  Format result apys as: x% (base: x%, rewards: x%) if rewards apy is available, otherwise: x%
265
293
  Examples:
266
294
  User: "Show me the best vaults"
@@ -275,6 +303,7 @@ __decorate([
275
303
  args: { network: 'polygon', sort: { field: 'apy', direction: 'desc' }, take: 5, minTvl: 0 }
276
304
  User: "Show me some more of those"
277
305
  args: { network: 'polygon', sort: { field: 'apy', direction: 'desc' }, take: 5, minTvl: 0, page: 2 }
306
+ All optional fields should be null if not specified.
278
307
  `,
279
308
  schema: schemas_1.VaultsActionSchema,
280
309
  }),
@@ -282,6 +311,44 @@ __decorate([
282
311
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
283
312
  __metadata("design:returntype", Promise)
284
313
  ], VaultsfyiActionProvider.prototype, "vaults", null);
314
+ __decorate([
315
+ (0, actionDecorator_1.CreateAction)({
316
+ name: "vault_details",
317
+ description: `
318
+ This action returns a more detailed view of a single vault. Additional details include:
319
+ - Description
320
+ - Additional incentives (points etc)
321
+ - Rewards breakdown
322
+ Params:
323
+ - vaultAddress: The address of the vault to fetch details for
324
+ - network: The network of the vault
325
+ - apyRange: The APY moving average range (default: 7day)
326
+ `,
327
+ schema: schemas_1.VaultDetailsActionSchema,
328
+ }),
329
+ __metadata("design:type", Function),
330
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
331
+ __metadata("design:returntype", Promise)
332
+ ], VaultsfyiActionProvider.prototype, "vaultDetails", null);
333
+ __decorate([
334
+ (0, actionDecorator_1.CreateAction)({
335
+ name: "vault_historical_data",
336
+ description: `
337
+ This action returns a historical data of a vault. It returns the APY and TVL data closest to the given date.
338
+ Always check if the results date is close to the requested date, as the data may not be available for the exact date.
339
+ If there is a more than 7 day difference between the requested date and the resulting date, don't provide the data, but rather with a message explaining the missing data.
340
+ If the resulting date is a lot later than the requested date, the reason for missing data might be that the vault has not been deployed yet.
341
+ Example queries:
342
+ params: { vaultAddress: "0x1234567890abcdef1234567890abcdef12345678", network: "arbitrum", date: "2025-01-01T00:00:00Z" }
343
+ result: { ..., date: "2025-02-16T14:59:59.000Z" }
344
+ response: "The requested date was 2025-01-01T00:00:00Z, but the closest data available is from 2025-02-16T14:59:59.000Z. This may indicate that the vault was not deployed at the requested date."
345
+ `,
346
+ schema: schemas_1.VaultHistoricalDataActionSchema,
347
+ }),
348
+ __metadata("design:type", Function),
349
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
350
+ __metadata("design:returntype", Promise)
351
+ ], VaultsfyiActionProvider.prototype, "vaultHistoricalData", null);
285
352
  __decorate([
286
353
  (0, actionDecorator_1.CreateAction)({
287
354
  name: "deposit",
@@ -35,6 +35,30 @@ const mockVault = (num) => ({
35
35
  "7day": num * 100,
36
36
  },
37
37
  },
38
+ numberOfHolders: num,
39
+ rewards: [
40
+ {
41
+ apy: {
42
+ "7day": num * 100,
43
+ },
44
+ asset: {
45
+ name: `reward-token-${num}`,
46
+ symbol: `RT${num}`,
47
+ assetAddress: `0x${num.toString(16).padStart(40, "0")}`,
48
+ decimals: 18,
49
+ },
50
+ },
51
+ ],
52
+ description: `Description for vault-${num}`,
53
+ additionalIncentives: `Incentives for vault-${num}`,
54
+ score: {
55
+ vaultScore: num,
56
+ vaultTvlScore: num,
57
+ protocolTvlScore: num,
58
+ holderScore: num,
59
+ networkScore: num,
60
+ assetScore: num,
61
+ },
38
62
  isTransactional: true,
39
63
  },
40
64
  transformedResult: {
@@ -53,6 +77,8 @@ const mockVault = (num) => ({
53
77
  rewards: num,
54
78
  total: num,
55
79
  },
80
+ vaultsFyiScore: num,
81
+ numberOfHolders: num,
56
82
  link: `https://app.vaults.fyi/opportunity/network-${num}/0x${num.toString(16).padStart(40, "0")}`,
57
83
  },
58
84
  });
@@ -435,4 +461,143 @@ describe("VaultsfyiActionProvider", () => {
435
461
  expect(await provider.positions(mockWalletProvider)).toBe("Failed to fetch positions: Internal Server Error, some more info");
436
462
  });
437
463
  });
464
+ describe("vault_details action", () => {
465
+ it("should transform vault details correctly", async () => {
466
+ const detailedVault = mockVault(1);
467
+ mockedFetch.mockResolvedValue(mockFetchResult(200, detailedVault.apiResult));
468
+ const args = {
469
+ vaultAddress: "0x123456",
470
+ network: "mainnet",
471
+ };
472
+ const result = await provider.vaultDetails(mockWalletProvider, args);
473
+ const parsedResult = JSON.parse(result);
474
+ expect(parsedResult).toStrictEqual({
475
+ ...detailedVault.transformedResult,
476
+ description: detailedVault.apiResult.description,
477
+ additionalIncentives: detailedVault.apiResult.additionalIncentives,
478
+ rewards: [
479
+ {
480
+ apy: detailedVault.apiResult.rewards[0].apy["7day"] / 100,
481
+ asset: {
482
+ name: detailedVault.apiResult.rewards[0].asset.name,
483
+ symbol: detailedVault.apiResult.rewards[0].asset.symbol,
484
+ address: detailedVault.apiResult.rewards[0].asset.assetAddress,
485
+ },
486
+ },
487
+ ],
488
+ });
489
+ });
490
+ it("should return an error if the API request fails", async () => {
491
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
492
+ const args = {
493
+ vaultAddress: "0x123456",
494
+ network: "mainnet",
495
+ };
496
+ expect(await provider.vaultDetails(mockWalletProvider, args)).toBe("Failed to fetch vault: Internal Server Error, some more info");
497
+ });
498
+ });
499
+ describe("vault_historical_data action", () => {
500
+ it("should fetch and transform historical data correctly", async () => {
501
+ // Mock API responses for both TVL and APY data
502
+ const mockApyData = {
503
+ timestamp: 1704067200, // Jan 1, 2024
504
+ blockNumber: 12345678,
505
+ apy: {
506
+ base: 500,
507
+ rewards: 300,
508
+ total: 800,
509
+ },
510
+ };
511
+ const mockTvlData = {
512
+ timestamp: 1704067200, // Jan 1, 2024
513
+ blockNumber: 12345678,
514
+ tvlDetails: {
515
+ tvlUsd: 1000000,
516
+ },
517
+ };
518
+ // Set up the mock to return appropriate data for each call
519
+ mockedFetch.mockImplementation(url => {
520
+ if (url.includes("/historical-apy/")) {
521
+ return Promise.resolve(mockFetchResult(200, mockApyData));
522
+ }
523
+ else if (url.includes("/historical-tvl/")) {
524
+ return Promise.resolve(mockFetchResult(200, mockTvlData));
525
+ }
526
+ return Promise.resolve(mockFetchResult(500, { error: "Unexpected URL" }));
527
+ });
528
+ const args = {
529
+ vaultAddress: "0x123456",
530
+ network: "mainnet",
531
+ date: "2024-01-01T00:00:00Z",
532
+ };
533
+ const result = await provider.vaultHistoricalData(mockWalletProvider, args);
534
+ const parsedResult = JSON.parse(result);
535
+ expect(parsedResult).toEqual({
536
+ apy: {
537
+ apy: {
538
+ base: 5,
539
+ rewards: 3,
540
+ total: 8,
541
+ },
542
+ date: "2024-01-01T00:00:00.000Z",
543
+ blockNumber: 12345678,
544
+ },
545
+ tvl: {
546
+ tvlInUsd: 1000000,
547
+ date: "2024-01-01T00:00:00.000Z",
548
+ blockNumber: 12345678,
549
+ },
550
+ });
551
+ });
552
+ it("should return an error if the APY API request fails", async () => {
553
+ // Set up the mock to fail for APY but succeed for TVL
554
+ mockedFetch.mockImplementation(url => {
555
+ if (url.includes("/historical-apy/")) {
556
+ return Promise.resolve(mockFetchResult(500, {
557
+ error: "Internal Server Error",
558
+ message: "Failed to get historical APY data",
559
+ }));
560
+ }
561
+ else if (url.includes("/historical-tvl/")) {
562
+ return Promise.resolve(mockFetchResult(200, {
563
+ timestamp: 1704067200,
564
+ blockNumber: 12345678,
565
+ tvlDetails: { tvlUsd: 1000000 },
566
+ }));
567
+ }
568
+ return Promise.resolve(mockFetchResult(500, { error: "Unexpected URL" }));
569
+ });
570
+ const args = {
571
+ vaultAddress: "0x123456",
572
+ network: "mainnet",
573
+ date: "2024-01-01T00:00:00Z",
574
+ };
575
+ expect(await provider.vaultHistoricalData(mockWalletProvider, args)).toBe("Failed to fetch vault: Internal Server Error, Failed to get historical APY data");
576
+ });
577
+ it("should return an error if the TVL API request fails", async () => {
578
+ // Set up the mock to succeed for APY but fail for TVL
579
+ mockedFetch.mockImplementation(url => {
580
+ if (url.includes("/historical-apy/")) {
581
+ return Promise.resolve(mockFetchResult(200, {
582
+ timestamp: 1704067200,
583
+ blockNumber: 12345678,
584
+ apy: { base: 500, rewards: 300, total: 800 },
585
+ }));
586
+ }
587
+ else if (url.includes("/historical-tvl/")) {
588
+ return Promise.resolve(mockFetchResult(500, {
589
+ error: "Internal Server Error",
590
+ message: "Failed to get historical TVL data",
591
+ }));
592
+ }
593
+ return Promise.resolve(mockFetchResult(500, { error: "Unexpected URL" }));
594
+ });
595
+ const args = {
596
+ vaultAddress: "0x123456",
597
+ network: "mainnet",
598
+ date: "2024-01-01T00:00:00Z",
599
+ };
600
+ expect(await provider.vaultHistoricalData(mockWalletProvider, args)).toBe("Failed to fetch vault: Internal Server Error, Failed to get historical TVL data");
601
+ });
602
+ });
438
603
  });
@@ -4,8 +4,8 @@ import { Action, ActionProvider } from "./action-providers";
4
4
  * Configuration options for AgentKit
5
5
  */
6
6
  export type AgentKitOptions = {
7
- cdpApiKeyName?: string;
8
- cdpApiKeyPrivateKey?: string;
7
+ cdpApiKeyId?: string;
8
+ cdpApiKeySecret?: string;
9
9
  walletProvider?: WalletProvider;
10
10
  actionProviders?: ActionProvider[];
11
11
  };
package/dist/agentkit.js CHANGED
@@ -32,12 +32,12 @@ class AgentKit {
32
32
  static async from(config = { actionProviders: [(0, action_providers_1.walletActionProvider)()] }) {
33
33
  let walletProvider = config.walletProvider;
34
34
  if (!config.walletProvider) {
35
- if (!config.cdpApiKeyName || !config.cdpApiKeyPrivateKey) {
36
- throw new Error("cdpApiKeyName and cdpApiKeyPrivateKey are required if not providing a walletProvider");
35
+ if (!config.cdpApiKeyId || !config.cdpApiKeySecret) {
36
+ throw new Error("cdpApiKeyId and cdpApiKeySecret are required if not providing a walletProvider");
37
37
  }
38
38
  walletProvider = await wallet_providers_1.CdpWalletProvider.configureWithWallet({
39
- apiKeyName: config.cdpApiKeyName,
40
- apiKeyPrivateKey: config.cdpApiKeyPrivateKey,
39
+ apiKeyId: config.cdpApiKeyId,
40
+ apiKeySecret: config.cdpApiKeySecret,
41
41
  });
42
42
  }
43
43
  return new AgentKit({ ...config, walletProvider: walletProvider });
@@ -118,9 +118,29 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
118
118
  * @returns The hash of the transaction.
119
119
  */
120
120
  async sendTransaction(transaction) {
121
+ const txWithGasParams = {
122
+ ...transaction,
123
+ chainId: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_network, "f").chainId,
124
+ };
125
+ if (!txWithGasParams.maxFeePerGas && !txWithGasParams.gasPrice) {
126
+ const feeData = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").estimateFeesPerGas();
127
+ txWithGasParams.maxFeePerGas = feeData.maxFeePerGas;
128
+ txWithGasParams.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
129
+ }
130
+ if (!txWithGasParams.gas) {
131
+ try {
132
+ txWithGasParams.gas = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").estimateGas({
133
+ account: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address,
134
+ ...txWithGasParams,
135
+ });
136
+ }
137
+ catch (error) {
138
+ console.warn("Failed to estimate gas, continuing without gas estimation", error);
139
+ }
140
+ }
121
141
  const result = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_cdp, "f").evm.sendTransaction({
122
142
  address: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address,
123
- transaction: (0, viem_1.serializeTransaction)(transaction),
143
+ transaction: (0, viem_1.serializeTransaction)(txWithGasParams),
124
144
  network: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_instances, "m", _CdpV2EvmWalletProvider_getCdpSdkNetwork).call(this),
125
145
  });
126
146
  return result.transactionHash;
@@ -39,3 +39,10 @@ export interface WalletProviderWithClient {
39
39
  */
40
40
  getClient(): CdpClient;
41
41
  }
42
+ /**
43
+ * Type guard to check if a wallet provider implements WalletProviderWithClient interface.
44
+ *
45
+ * @param provider - The provider to check
46
+ * @returns True if the provider implements WalletProviderWithClient
47
+ */
48
+ export declare function isWalletProviderWithClient(provider: unknown): provider is WalletProviderWithClient;
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWalletProviderWithClient = isWalletProviderWithClient;
4
+ /**
5
+ * Type guard to check if a wallet provider implements WalletProviderWithClient interface.
6
+ *
7
+ * @param provider - The provider to check
8
+ * @returns True if the provider implements WalletProviderWithClient
9
+ */
10
+ function isWalletProviderWithClient(provider) {
11
+ return (provider !== null &&
12
+ typeof provider === "object" &&
13
+ "getClient" in provider &&
14
+ typeof provider.getClient === "function");
15
+ }
@@ -9,11 +9,11 @@ export interface CdpProviderConfig {
9
9
  /**
10
10
  * The CDP API Key Name.
11
11
  */
12
- apiKeyName?: string;
12
+ apiKeyId?: string;
13
13
  /**
14
14
  * The CDP API Key Private Key.
15
15
  */
16
- apiKeyPrivateKey?: string;
16
+ apiKeySecret?: string;
17
17
  }
18
18
  /**
19
19
  * Configuration options for the CdpActionProvider.
@@ -56,10 +56,10 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
56
56
  * @throws Error if required environment variables are missing or wallet initialization fails
57
57
  */
58
58
  static async configureWithWallet(config = {}) {
59
- if (config.apiKeyName && config.apiKeyPrivateKey) {
59
+ if (config.apiKeyId && config.apiKeySecret) {
60
60
  coinbase_sdk_1.Coinbase.configure({
61
- apiKeyName: config.apiKeyName,
62
- privateKey: config.apiKeyPrivateKey?.replace(/\\n/g, "\n"),
61
+ apiKeyName: config.apiKeyId,
62
+ privateKey: config.apiKeySecret?.replace(/\\n/g, "\n"),
63
63
  source: "agentkit",
64
64
  sourceVersion: package_json_1.version,
65
65
  });
@@ -199,16 +199,16 @@ describe("CdpWalletProvider", () => {
199
199
  expect(provider.getNetwork()).toEqual(MOCK_NETWORK);
200
200
  });
201
201
  it("should initialize with API keys", async () => {
202
- const apiKeyName = "test-key";
203
- const apiKeyPrivateKey = "private-key";
202
+ const apiKeyId = "test-key";
203
+ const apiKeySecret = "private-key";
204
204
  const provider = await cdpWalletProvider_1.CdpWalletProvider.configureWithWallet({
205
- apiKeyName,
206
- apiKeyPrivateKey,
205
+ apiKeyId,
206
+ apiKeySecret,
207
207
  networkId: MOCK_NETWORK_ID,
208
208
  });
209
209
  expect(coinbase_sdk_1.Coinbase.configure).toHaveBeenCalledWith({
210
- apiKeyName,
211
- privateKey: apiKeyPrivateKey,
210
+ apiKeyName: apiKeyId,
211
+ privateKey: apiKeySecret,
212
212
  source: "agentkit",
213
213
  sourceVersion: "1.0.0",
214
214
  });
@@ -3,8 +3,8 @@ import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadCont
3
3
  import { Network } from "../network";
4
4
  import { EvmWalletProvider } from "./evmWalletProvider";
5
5
  export interface ConfigureSmartWalletOptions {
6
- cdpApiKeyName?: string;
7
- cdpApiKeyPrivateKey?: string;
6
+ cdpApiKeyId?: string;
7
+ cdpApiKeySecret?: string;
8
8
  networkId?: string;
9
9
  smartWalletAddress?: Hex;
10
10
  paymasterUrl?: string;
@@ -39,8 +39,8 @@ export declare class SmartWalletProvider extends EvmWalletProvider {
39
39
  * const smartWalletProvider = await SmartWalletProvider.configureWithWallet({
40
40
  * networkId: "base-sepolia",
41
41
  * signer: privateKeyToAccount("0xethprivatekey"),
42
- * cdpApiKeyName: "my-api-key",
43
- * cdpApiKeyPrivateKey: "my-private-key",
42
+ * cdpApiKeyId: "my-api-key",
43
+ * cdpApiKeySecret: "my-private-key",
44
44
  * smartWalletAddress: "0x123456...",
45
45
  * });
46
46
  * ```
@@ -57,8 +57,8 @@ class SmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
57
57
  * const smartWalletProvider = await SmartWalletProvider.configureWithWallet({
58
58
  * networkId: "base-sepolia",
59
59
  * signer: privateKeyToAccount("0xethprivatekey"),
60
- * cdpApiKeyName: "my-api-key",
61
- * cdpApiKeyPrivateKey: "my-private-key",
60
+ * cdpApiKeyId: "my-api-key",
61
+ * cdpApiKeySecret: "my-private-key",
62
62
  * smartWalletAddress: "0x123456...",
63
63
  * });
64
64
  * ```
@@ -77,12 +77,12 @@ class SmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
77
77
  if (!supportedChainIds.includes(network.chainId)) {
78
78
  throw new Error(`Invalid chain id ${network.chainId}. Chain id must be one of ${supportedChainIds.join(", ")}`);
79
79
  }
80
- const cdpApiKeyName = config.cdpApiKeyName || process.env.CDP_API_KEY_NAME;
81
- const cdpApiKeyPrivateKey = config.cdpApiKeyPrivateKey || process.env.CDP_API_KEY_PRIVATE_KEY;
82
- if (cdpApiKeyName && cdpApiKeyPrivateKey) {
80
+ const cdpApiKeyId = config.cdpApiKeyId || process.env.CDP_API_KEY_ID;
81
+ const cdpApiKeySecret = config.cdpApiKeySecret || process.env.CDP_API_KEY_SECRET;
82
+ if (cdpApiKeyId && cdpApiKeySecret) {
83
83
  coinbase_sdk_1.Coinbase.configure({
84
- apiKeyName: cdpApiKeyName,
85
- privateKey: cdpApiKeyPrivateKey?.replace(/\\n/g, "\n"),
84
+ apiKeyName: cdpApiKeyId,
85
+ privateKey: cdpApiKeySecret?.replace(/\\n/g, "\n"),
86
86
  source: "agentkit",
87
87
  sourceVersion: package_json_1.version,
88
88
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@coinbase/agentkit",
3
3
  "description": "Coinbase AgentKit core primitives",
4
4
  "repository": "https://github.com/coinbase/agentkit",
5
- "version": "0.0.0-nightly-20250501210425",
5
+ "version": "0.0.0-nightly-20250612210418",
6
6
  "author": "Coinbase Inc.",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/index.js",
@@ -27,10 +27,10 @@
27
27
  "@coinbase/cdp-sdk": "^1.3.0",
28
28
  "@coinbase/coinbase-sdk": "^0.20.0",
29
29
  "@jup-ag/api": "^6.0.39",
30
- "@privy-io/public-api": "^2.18.5",
31
- "@privy-io/server-auth": "^1.18.4",
30
+ "@privy-io/public-api": "2.18.5",
31
+ "@privy-io/server-auth": "1.18.4",
32
32
  "@solana/spl-token": "^0.4.12",
33
- "@solana/web3.js": "^1.98.0",
33
+ "@solana/web3.js": "^1.98.1",
34
34
  "bs58": "^4.0.1",
35
35
  "canonicalize": "^2.1.0",
36
36
  "decimal.js": "^10.5.0",