@coinbase/agentkit 0.6.1 → 0.7.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 (62) hide show
  1. package/README.md +234 -0
  2. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +37 -0
  3. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +91 -0
  4. package/dist/action-providers/cdp-v2/index.d.ts +2 -0
  5. package/dist/action-providers/cdp-v2/index.js +18 -0
  6. package/dist/action-providers/cdp-v2/schemas.d.ts +11 -0
  7. package/dist/action-providers/cdp-v2/schemas.js +13 -0
  8. package/dist/action-providers/compound/schemas.d.ts +8 -8
  9. package/dist/action-providers/index.d.ts +3 -0
  10. package/dist/action-providers/index.js +3 -0
  11. package/dist/action-providers/vaultsfyi/api/actions.d.ts +41 -0
  12. package/dist/action-providers/vaultsfyi/api/actions.js +28 -0
  13. package/dist/action-providers/vaultsfyi/api/types.d.ts +34 -0
  14. package/dist/action-providers/vaultsfyi/api/types.js +2 -0
  15. package/dist/action-providers/vaultsfyi/api/vaults.d.ts +38 -0
  16. package/dist/action-providers/vaultsfyi/api/vaults.js +39 -0
  17. package/dist/action-providers/vaultsfyi/constants.d.ts +12 -0
  18. package/dist/action-providers/vaultsfyi/constants.js +15 -0
  19. package/dist/action-providers/vaultsfyi/index.d.ts +7 -0
  20. package/dist/action-providers/vaultsfyi/index.js +23 -0
  21. package/dist/action-providers/vaultsfyi/schemas.d.ts +94 -0
  22. package/dist/action-providers/vaultsfyi/schemas.js +49 -0
  23. package/dist/action-providers/vaultsfyi/utils.d.ts +34 -0
  24. package/dist/action-providers/vaultsfyi/utils.js +69 -0
  25. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +98 -0
  26. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +383 -0
  27. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.d.ts +1 -0
  28. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +438 -0
  29. package/dist/action-providers/zerodev/index.d.ts +1 -0
  30. package/dist/action-providers/zerodev/index.js +17 -0
  31. package/dist/action-providers/zerodev/schemas.d.ts +29 -0
  32. package/dist/action-providers/zerodev/schemas.js +21 -0
  33. package/dist/action-providers/zerodev/zeroDevWalletActionProvider.d.ts +32 -0
  34. package/dist/action-providers/zerodev/zeroDevWalletActionProvider.js +66 -0
  35. package/dist/action-providers/zerodev/zeroDevWalletActionProvider.test.d.ts +1 -0
  36. package/dist/action-providers/zerodev/zeroDevWalletActionProvider.test.js +112 -0
  37. package/dist/network/svm.d.ts +1 -0
  38. package/dist/network/svm.js +6 -1
  39. package/dist/wallet-providers/cdpV2EvmWalletProvider.d.ts +105 -0
  40. package/dist/wallet-providers/cdpV2EvmWalletProvider.js +212 -0
  41. package/dist/wallet-providers/cdpV2EvmWalletProvider.test.d.ts +1 -0
  42. package/dist/wallet-providers/cdpV2EvmWalletProvider.test.js +343 -0
  43. package/dist/wallet-providers/cdpV2Shared.d.ts +41 -0
  44. package/dist/wallet-providers/cdpV2Shared.js +2 -0
  45. package/dist/wallet-providers/cdpV2SolanaWalletProvider.d.ts +111 -0
  46. package/dist/wallet-providers/cdpV2SolanaWalletProvider.js +247 -0
  47. package/dist/wallet-providers/cdpV2SolanaWalletProvider.test.d.ts +1 -0
  48. package/dist/wallet-providers/cdpV2SolanaWalletProvider.test.js +307 -0
  49. package/dist/wallet-providers/cdpV2WalletProvider.d.ts +35 -0
  50. package/dist/wallet-providers/cdpV2WalletProvider.js +42 -0
  51. package/dist/wallet-providers/cdpWalletProvider.js +1 -1
  52. package/dist/wallet-providers/cdpWalletProvider.test.js +1 -0
  53. package/dist/wallet-providers/evmWalletProvider.d.ts +7 -1
  54. package/dist/wallet-providers/evmWalletProvider.js +20 -0
  55. package/dist/wallet-providers/index.d.ts +5 -0
  56. package/dist/wallet-providers/index.js +5 -0
  57. package/dist/wallet-providers/walletProvider.test.js +22 -0
  58. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +147 -0
  59. package/dist/wallet-providers/zeroDevWalletProvider.js +301 -0
  60. package/dist/wallet-providers/zeroDevWalletProvider.test.d.ts +1 -0
  61. package/dist/wallet-providers/zeroDevWalletProvider.test.js +435 -0
  62. package/package.json +5 -1
@@ -0,0 +1,383 @@
1
+ "use strict";
2
+ /**
3
+ * Vaultsfyi Action Provider
4
+ *
5
+ * This file contains the implementation of the VaultsfyiActionProvider,
6
+ * which provides actions for vaultsfyi operations.
7
+ *
8
+ * @module vaultsfyi
9
+ */
10
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ 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;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ };
16
+ var __metadata = (this && this.__metadata) || function (k, v) {
17
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.vaultsfyiActionProvider = exports.VaultsfyiActionProvider = void 0;
21
+ const zod_1 = require("zod");
22
+ const actionProvider_1 = require("../actionProvider");
23
+ const actionDecorator_1 = require("../actionDecorator");
24
+ const wallet_providers_1 = require("../../wallet-providers");
25
+ const schemas_1 = require("./schemas");
26
+ const utils_1 = require("./utils");
27
+ const constants_1 = require("./constants");
28
+ const actions_1 = require("./api/actions");
29
+ const vaults_1 = require("./api/vaults");
30
+ /**
31
+ * VaultsfyiActionProvider provides actions for vaultsfyi operations.
32
+ *
33
+ * @description
34
+ * This provider is designed to work with EvmWalletProvider for blockchain interactions.
35
+ * It supports all evm networks.
36
+ */
37
+ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
38
+ /**
39
+ * Constructor for the VaultsfyiActionProvider.
40
+ *
41
+ * @param config - Configuration options for the provider
42
+ */
43
+ constructor(config = {}) {
44
+ super("vaultsfyi", []);
45
+ const apiKey = config.apiKey || process.env.VAULTSFYI_API_KEY;
46
+ if (!apiKey) {
47
+ throw new Error("VAULTSFYI_API_KEY is not configured.");
48
+ }
49
+ this.apiKey = apiKey;
50
+ }
51
+ /**
52
+ * vaults action
53
+ *
54
+ * @param wallet - The wallet provider instance for blockchain interactions
55
+ * @param args - Input arguments: token, network, transactionalOnly...
56
+ * @returns A list of vaults.
57
+ */
58
+ async vaults(wallet, args) {
59
+ const vaults = await (0, vaults_1.fetchVaults)(args, this.apiKey);
60
+ if ("error" in vaults) {
61
+ return `Failed to fetch vaults: ${vaults.error}, ${vaults.message}`;
62
+ }
63
+ if (args.protocol && !vaults.find(vault => vault.protocol === args.protocol)) {
64
+ const supportedProtocols = vaults
65
+ .map(vault => vault.protocol)
66
+ .filter((value, index, self) => self.indexOf(value) === index);
67
+ return `Protocol ${args.protocol} is not supported. Supported protocols are: ${supportedProtocols.join(", ")}`;
68
+ }
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
+ }));
87
+ const filteredVaults = transformedVaults.filter(vault => args.protocol ? vault.protocol === args.protocol : true);
88
+ const sortedVaults = filteredVaults.sort((a, b) => {
89
+ if (args.sort?.field === "tvl") {
90
+ return args.sort.direction === "asc" ? a.tvlInUsd - b.tvlInUsd : b.tvlInUsd - a.tvlInUsd;
91
+ }
92
+ else if (args.sort?.field === "apy") {
93
+ return args.sort.direction === "asc"
94
+ ? a.apy.total - b.apy.total
95
+ : b.apy.total - a.apy.total;
96
+ }
97
+ return a.name.localeCompare(b.name);
98
+ });
99
+ const take = args.take || 10;
100
+ const page = args.page || 1;
101
+ const start = (page - 1) * take;
102
+ const end = start + take;
103
+ const results = sortedVaults.slice(start, end);
104
+ return JSON.stringify({
105
+ totalResults: sortedVaults.length,
106
+ nextPage: end < sortedVaults.length,
107
+ results,
108
+ });
109
+ }
110
+ /**
111
+ * Deposit action
112
+ *
113
+ * @param wallet - The wallet provider instance for blockchain interactions
114
+ * @param args - Input arguments
115
+ * @returns A result message
116
+ */
117
+ async deposit(wallet, args) {
118
+ const actions = await (0, actions_1.fetchVaultActions)({
119
+ action: "deposit",
120
+ args: { ...args, amount: await (0, utils_1.parseAssetAmount)(wallet, args.assetAddress, args.amount) },
121
+ sender: wallet.getAddress(),
122
+ apiKey: this.apiKey,
123
+ });
124
+ if ("error" in actions) {
125
+ return `Failed to fetch deposit transactions: ${actions.error}, ${actions.message}`;
126
+ }
127
+ await (0, utils_1.executeActions)(wallet, actions);
128
+ return "Deposit successful";
129
+ }
130
+ /**
131
+ * Redeem action
132
+ *
133
+ * @param wallet - The wallet provider instance for blockchain interactions
134
+ * @param args - Input arguments
135
+ * @returns A result message
136
+ */
137
+ async redeem(wallet, args) {
138
+ const actions = await (0, actions_1.fetchVaultActions)({
139
+ action: "redeem",
140
+ args: { ...args, amount: await (0, utils_1.parseAssetAmount)(wallet, args.assetAddress, args.amount) },
141
+ sender: wallet.getAddress(),
142
+ apiKey: this.apiKey,
143
+ });
144
+ if ("error" in actions) {
145
+ return `Failed to fetch redeem transactions: ${actions.error}, ${actions.message}`;
146
+ }
147
+ await (0, utils_1.executeActions)(wallet, actions);
148
+ return "Redeem successful";
149
+ }
150
+ /**
151
+ * Claim rewards action
152
+ *
153
+ * @param wallet - The wallet provider instance for blockchain interactions
154
+ * @param args - Input arguments
155
+ * @returns A result message
156
+ */
157
+ async claim(wallet, args) {
158
+ const actions = await (0, actions_1.fetchVaultActions)({
159
+ action: "claim-rewards",
160
+ args,
161
+ sender: wallet.getAddress(),
162
+ apiKey: this.apiKey,
163
+ });
164
+ if ("error" in actions) {
165
+ return `Failed to fetch claim transactions: ${actions.error}, ${actions.message}`;
166
+ }
167
+ await (0, utils_1.executeActions)(wallet, actions);
168
+ return "Claim successful";
169
+ }
170
+ /**
171
+ * Returns the users wallet token balances.
172
+ *
173
+ * @param wallet - The wallet provider instance for blockchain interactions
174
+ * @returns A record of the users balances
175
+ */
176
+ async balances(wallet) {
177
+ const params = new URLSearchParams({
178
+ account: wallet.getAddress(),
179
+ });
180
+ const result = await fetch(`${constants_1.VAULTS_API_URL}/portfolio/wallet-balances?${params.toString()}`, {
181
+ method: "GET",
182
+ headers: {
183
+ "x-api-key": this.apiKey,
184
+ },
185
+ });
186
+ const balances = (await result.json());
187
+ if ("error" in balances) {
188
+ return `Failed to fetch wallet balances: ${balances.error}, ${balances.message}`;
189
+ }
190
+ const entries = Object.entries(balances).map(([network, balances]) => {
191
+ return [
192
+ network,
193
+ balances.map(balance => ({
194
+ address: balance.address,
195
+ name: balance.name,
196
+ symbol: balance.symbol,
197
+ balance: Number(balance.balance) / 10 ** balance.decimals,
198
+ })),
199
+ ];
200
+ });
201
+ return JSON.stringify(Object.fromEntries(entries));
202
+ }
203
+ /**
204
+ * Returns the users positions.
205
+ *
206
+ * @param wallet - The wallet provider instance for blockchain interactions
207
+ * @returns A record of the users positions
208
+ */
209
+ async positions(wallet) {
210
+ const result = await fetch(`${constants_1.VAULTS_API_URL}/portfolio/positions/${wallet.getAddress()}`, {
211
+ method: "GET",
212
+ headers: {
213
+ "x-api-key": this.apiKey,
214
+ },
215
+ });
216
+ const positions = (await result.json());
217
+ if ("error" in positions) {
218
+ return `Failed to fetch positions: ${positions.error}, ${positions.message}`;
219
+ }
220
+ const entries = Object.entries(positions).map(([network, positions]) => {
221
+ return [
222
+ network,
223
+ positions.map(position => ({
224
+ name: position.vaultName,
225
+ vaultAddress: position.vaultAddress,
226
+ asset: {
227
+ address: position.asset.assetAddress,
228
+ name: position.asset.name,
229
+ symbol: position.asset.symbol,
230
+ },
231
+ underlyingTokenBalance: Number(position.balanceNative) / 10 ** position.asset.decimals,
232
+ lpTokenBalance: Number(position.balanceLp) / 10 ** position.asset.decimals,
233
+ unclaimedRewards: Number(position.unclaimedUsd) > 0,
234
+ apy: {
235
+ base: position.apy.base / 100,
236
+ rewards: position.apy.rewards / 100,
237
+ total: position.apy.total / 100,
238
+ },
239
+ })),
240
+ ];
241
+ });
242
+ return JSON.stringify(Object.fromEntries(entries));
243
+ }
244
+ /**
245
+ * Checks if this provider supports the given network.
246
+ *
247
+ * @param network - The network to check support for
248
+ * @returns True if the network is supported
249
+ */
250
+ supportsNetwork(network) {
251
+ return (network.protocolFamily == "evm" &&
252
+ (network.chainId ? Object.keys(constants_1.VAULTSFYI_SUPPORTED_CHAINS).includes(network.chainId) : false));
253
+ }
254
+ }
255
+ exports.VaultsfyiActionProvider = VaultsfyiActionProvider;
256
+ __decorate([
257
+ (0, actionDecorator_1.CreateAction)({
258
+ name: "vaults",
259
+ description: `
260
+ This action returns a list of available vaults.
261
+ 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
+ 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.
264
+ Format result apys as: x% (base: x%, rewards: x%) if rewards apy is available, otherwise: x%
265
+ Examples:
266
+ User: "Show me the best vaults"
267
+ args: { sort: { field: 'apy', direction: 'desc' }, take: 5 }
268
+ User: "Show me the safest vaults"
269
+ args: { sort: { field: 'tvl', direction: 'desc' }, take: 5 }
270
+ User: "Show me the best vaults on Arbitrum"
271
+ args: { network: 'arbitrum', sort: { field: 'apy', direction: 'desc' }, take: 5 }
272
+ User: "I want to earn yield on my usdc on base!"
273
+ args: { token: 'usdc', network: 'base', sort: { field: 'apy', direction: 'desc' }, take: 5 }
274
+ User: "What are some of the most profitable degen vaults on polygon"
275
+ args: { network: 'polygon', sort: { field: 'apy', direction: 'desc' }, take: 5, minTvl: 0 }
276
+ User: "Show me some more of those"
277
+ args: { network: 'polygon', sort: { field: 'apy', direction: 'desc' }, take: 5, minTvl: 0, page: 2 }
278
+ `,
279
+ schema: schemas_1.VaultsActionSchema,
280
+ }),
281
+ __metadata("design:type", Function),
282
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
283
+ __metadata("design:returntype", Promise)
284
+ ], VaultsfyiActionProvider.prototype, "vaults", null);
285
+ __decorate([
286
+ (0, actionDecorator_1.CreateAction)({
287
+ name: "deposit",
288
+ description: `
289
+ This action deposits assets into a selected vault. Before depositing make sure you have the required assets in your wallet using the wallet-balances action.
290
+ Even if you received the balance from some other source, double-check the user balance.
291
+ Use examples:
292
+ User: "Deposit 1000 USDC into the vault"
293
+ actions:
294
+ - check wallet balance for USDC
295
+ - deposit USDC into the vault if balance is sufficient
296
+ User: "I want more yield on my DAI"
297
+ actions:
298
+ - check positions that the user already has for dai
299
+ - find high yield vaults for dai
300
+ - if there is a vault with higher yield available, redeem from the current vault and deposit into the new vault
301
+ - if users dai wasn't in a vault to begin with, deposit into the new vault
302
+ User: "I want to create a diversified yield strategy"
303
+ actions:
304
+ - check wallet balances for all assets
305
+ - find a couple vaults for each asset, preferably from different protocols
306
+ - create a diversified strategy using the users assets
307
+ - propose the strategy to the user before executing
308
+ `,
309
+ schema: schemas_1.depositActionSchema,
310
+ }),
311
+ __metadata("design:type", Function),
312
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
313
+ __metadata("design:returntype", Promise)
314
+ ], VaultsfyiActionProvider.prototype, "deposit", null);
315
+ __decorate([
316
+ (0, actionDecorator_1.CreateAction)({
317
+ name: "redeem",
318
+ description: `
319
+ This action redeems assets from a selected vault. Before redeeming make sure you have the required lp tokens in your wallet using the positions action.
320
+ Even if you received the lp tokens from some other source, double-check the amount before redeeming.
321
+ lp tokens aren't always 1:1 with the underlying asset, so make sure to check the amount of lp tokens you have before redeeming even if you know the amount of the underlying asset you want to redeem.
322
+ `,
323
+ schema: schemas_1.redeemActionSchema,
324
+ }),
325
+ __metadata("design:type", Function),
326
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
327
+ __metadata("design:returntype", Promise)
328
+ ], VaultsfyiActionProvider.prototype, "redeem", null);
329
+ __decorate([
330
+ (0, actionDecorator_1.CreateAction)({
331
+ name: "claim_rewards",
332
+ description: `
333
+ This action claims rewards from a selected vault.
334
+ assetAddress is the address of the vaults underlying token.
335
+ If you're not sure what vaults have rewards claimable, use the positions action.
336
+ `,
337
+ schema: schemas_1.claimActionSchema,
338
+ }),
339
+ __metadata("design:type", Function),
340
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
341
+ __metadata("design:returntype", Promise)
342
+ ], VaultsfyiActionProvider.prototype, "claim", null);
343
+ __decorate([
344
+ (0, actionDecorator_1.CreateAction)({
345
+ name: "user_wallet_balances",
346
+ description: `
347
+ This action returns the users wallet balances of all tokens supported by vaults.fyi. Useful when you don't know token addresses but want to check if the user has an asset.
348
+ Example queries:
349
+ User: "What tokens do I have?"
350
+ User: "What tokens do I have on Arbitrum?"
351
+ User: "Whats my balance of USDC?"
352
+ `,
353
+ schema: zod_1.z.object({}),
354
+ }),
355
+ __metadata("design:type", Function),
356
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider]),
357
+ __metadata("design:returntype", Promise)
358
+ ], VaultsfyiActionProvider.prototype, "balances", null);
359
+ __decorate([
360
+ (0, actionDecorator_1.CreateAction)({
361
+ name: "positions",
362
+ description: `
363
+ This action returns the users positions in vaults.
364
+ Example queries:
365
+ User: "Show me my positions"
366
+ User: "What vaults am i invested in?"
367
+ User: "What's my average yield?"
368
+ User: "What vaults do I have rewards in?"
369
+ `,
370
+ schema: zod_1.z.object({}),
371
+ }),
372
+ __metadata("design:type", Function),
373
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider]),
374
+ __metadata("design:returntype", Promise)
375
+ ], VaultsfyiActionProvider.prototype, "positions", null);
376
+ /**
377
+ * Factory function to create a new VaultsfyiActionProvider instance.
378
+ *
379
+ * @param config - Configuration options for the provider
380
+ * @returns A new VaultsfyiActionProvider instance
381
+ */
382
+ const vaultsfyiActionProvider = (config) => new VaultsfyiActionProvider(config);
383
+ exports.vaultsfyiActionProvider = vaultsfyiActionProvider;