@coinbase/agentkit 0.10.3 → 0.10.4

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 (55) hide show
  1. package/README.md +47 -10
  2. package/dist/action-providers/across/acrossActionProvider.js +2 -4
  3. package/dist/action-providers/across/acrossActionProvider.test.js +10 -5
  4. package/dist/action-providers/baseAccount/baseAccountActionProvider.js +5 -7
  5. package/dist/action-providers/clanker/utils.d.ts +2 -1
  6. package/dist/action-providers/clanker/utils.js +2 -2
  7. package/dist/action-providers/index.d.ts +1 -0
  8. package/dist/action-providers/index.js +1 -0
  9. package/dist/action-providers/jupiter/jupiterActionProvider.js +2 -2
  10. package/dist/action-providers/spl/splActionProvider.js +12 -13
  11. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +2 -2
  12. package/dist/action-providers/sushi/constants.d.ts +35 -0
  13. package/dist/action-providers/sushi/constants.js +7 -0
  14. package/dist/action-providers/sushi/index.d.ts +4 -0
  15. package/dist/action-providers/sushi/index.js +20 -0
  16. package/dist/action-providers/sushi/sushiDataActionProvider.d.ts +32 -0
  17. package/dist/action-providers/sushi/sushiDataActionProvider.js +113 -0
  18. package/dist/action-providers/sushi/sushiDataSchemas.d.ts +11 -0
  19. package/dist/action-providers/sushi/sushiDataSchemas.js +16 -0
  20. package/dist/action-providers/sushi/sushiRouterActionProvider.d.ts +40 -0
  21. package/dist/action-providers/sushi/sushiRouterActionProvider.js +386 -0
  22. package/dist/action-providers/sushi/sushiRouterActionProvider.test.d.ts +1 -0
  23. package/dist/action-providers/sushi/sushiRouterActionProvider.test.js +392 -0
  24. package/dist/action-providers/sushi/sushiRouterSchemas.d.ts +36 -0
  25. package/dist/action-providers/sushi/sushiRouterSchemas.js +55 -0
  26. package/dist/action-providers/vaultsfyi/constants.d.ts +8 -12
  27. package/dist/action-providers/vaultsfyi/constants.js +47 -13
  28. package/dist/action-providers/vaultsfyi/schemas.d.ts +120 -65
  29. package/dist/action-providers/vaultsfyi/schemas.js +72 -38
  30. package/dist/action-providers/vaultsfyi/sdk.d.ts +8 -0
  31. package/dist/action-providers/vaultsfyi/sdk.js +15 -0
  32. package/dist/action-providers/vaultsfyi/utils.d.ts +151 -55
  33. package/dist/action-providers/vaultsfyi/utils.js +29 -75
  34. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +55 -16
  35. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +413 -217
  36. package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +509 -316
  37. package/dist/action-providers/x402/constants.d.ts +67 -0
  38. package/dist/action-providers/x402/constants.js +37 -0
  39. package/dist/action-providers/x402/schemas.d.ts +45 -5
  40. package/dist/action-providers/x402/schemas.js +81 -11
  41. package/dist/action-providers/x402/utils.d.ts +85 -10
  42. package/dist/action-providers/x402/utils.js +302 -35
  43. package/dist/action-providers/x402/x402ActionProvider.d.ts +15 -1
  44. package/dist/action-providers/x402/x402ActionProvider.js +230 -179
  45. package/dist/action-providers/x402/x402ActionProvider.test.js +222 -262
  46. package/dist/action-providers/zora/zoraActionProvider.js +4 -5
  47. package/package.json +10 -7
  48. package/dist/action-providers/vaultsfyi/api/actions.d.ts +0 -41
  49. package/dist/action-providers/vaultsfyi/api/actions.js +0 -28
  50. package/dist/action-providers/vaultsfyi/api/historicalData.d.ts +0 -31
  51. package/dist/action-providers/vaultsfyi/api/historicalData.js +0 -44
  52. package/dist/action-providers/vaultsfyi/api/types.d.ts +0 -34
  53. package/dist/action-providers/vaultsfyi/api/types.js +0 -2
  54. package/dist/action-providers/vaultsfyi/api/vaults.d.ts +0 -66
  55. package/dist/action-providers/vaultsfyi/api/vaults.js +0 -57
@@ -25,9 +25,7 @@ const wallet_providers_1 = require("../../wallet-providers");
25
25
  const schemas_1 = require("./schemas");
26
26
  const utils_1 = require("./utils");
27
27
  const constants_1 = require("./constants");
28
- const actions_1 = require("./api/actions");
29
- const vaults_1 = require("./api/vaults");
30
- const historicalData_1 = require("./api/historicalData");
28
+ const sdk_1 = require("./sdk");
31
29
  /**
32
30
  * VaultsfyiActionProvider provides actions for vaultsfyi operations.
33
31
  *
@@ -57,40 +55,30 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
57
55
  * @returns A list of vaults.
58
56
  */
59
57
  async vaults(wallet, args) {
60
- const apyRange = args.apyRange ?? "7day";
61
- const vaults = await (0, vaults_1.fetchVaults)(args, this.apiKey);
62
- if ("error" in vaults) {
63
- return `Failed to fetch vaults: ${vaults.error}, ${vaults.message}`;
58
+ try {
59
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
60
+ const vaults = await sdk.getAllVaults({
61
+ query: {
62
+ page: args.page || 1,
63
+ perPage: args.perPage || 5,
64
+ allowedAssets: args.allowedAssets ? args.allowedAssets : undefined,
65
+ allowedNetworks: args.allowedNetworks ? args.allowedNetworks : undefined,
66
+ allowedProtocols: args.allowedProtocols ? args.allowedProtocols : undefined,
67
+ minTvl: args.minTvl ?? 100000,
68
+ onlyTransactional: true,
69
+ sortBy: args.sort?.field,
70
+ sortOrder: args.sort?.direction,
71
+ },
72
+ });
73
+ const transformedVaults = vaults.data.map(utils_1.transformVault);
74
+ return JSON.stringify({
75
+ ...vaults,
76
+ data: transformedVaults,
77
+ });
64
78
  }
65
- if (args.protocol && !vaults.find(vault => vault.protocol === args.protocol)) {
66
- const supportedProtocols = vaults
67
- .map(vault => vault.protocol)
68
- .filter((value, index, self) => self.indexOf(value) === index);
69
- return `Protocol ${args.protocol} is not supported. Supported protocols are: ${supportedProtocols.join(", ")}`;
79
+ catch (error) {
80
+ return `Failed to fetch vaults: ${error instanceof Error ? error.message : String(error)}`;
70
81
  }
71
- const transformedVaults = vaults.map(vault => (0, utils_1.transformVault)(vault, apyRange));
72
- const filteredVaults = transformedVaults.filter(vault => args.protocol ? vault.protocol === args.protocol : true);
73
- const sortedVaults = filteredVaults.sort((a, b) => {
74
- if (args.sort?.field === "tvl") {
75
- return args.sort.direction === "asc" ? a.tvlInUsd - b.tvlInUsd : b.tvlInUsd - a.tvlInUsd;
76
- }
77
- else if (args.sort?.field === "apy") {
78
- return args.sort.direction === "asc"
79
- ? a.apy.total - b.apy.total
80
- : b.apy.total - a.apy.total;
81
- }
82
- return a.name.localeCompare(b.name);
83
- });
84
- const take = args.take || 10;
85
- const page = args.page || 1;
86
- const start = (page - 1) * take;
87
- const end = start + take;
88
- const results = sortedVaults.slice(start, end);
89
- return JSON.stringify({
90
- totalResults: sortedVaults.length,
91
- nextPage: end < sortedVaults.length,
92
- results,
93
- });
94
82
  }
95
83
  /**
96
84
  * vault details action
@@ -100,11 +88,19 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
100
88
  * @returns A detailed view of a single vault.
101
89
  */
102
90
  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}`;
91
+ try {
92
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
93
+ const vault = await sdk.getVault({
94
+ path: {
95
+ vaultAddress: args.vaultAddress,
96
+ network: args.network,
97
+ },
98
+ });
99
+ return JSON.stringify((0, utils_1.transformVault)(vault));
100
+ }
101
+ catch (error) {
102
+ return `Failed to fetch vault: ${error instanceof Error ? error.message : String(error)}`;
106
103
  }
107
- return JSON.stringify((0, utils_1.transformDetailedVault)(vault, args.apyRange ?? "7day"));
108
104
  }
109
105
  /**
110
106
  * vault historical data action
@@ -114,160 +110,304 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
114
110
  * @returns A detailed view of a single vault.
115
111
  */
116
112
  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,
113
+ try {
114
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
115
+ const data = await sdk.getVaultHistoricalData({
116
+ path: {
117
+ vaultAddress: args.vaultAddress,
118
+ network: args.network,
119
+ },
120
+ query: {
121
+ granularity: args.granularity,
122
+ fromTimestamp: Math.floor(new Date(args.fromDate).getTime() / 1000),
123
+ toTimestamp: Math.floor(new Date(args.toDate).getTime() / 1000),
124
+ apyInterval: args.apyInterval,
125
+ page: args.page,
126
+ perPage: args.perPage,
127
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
- });
128
+ });
129
+ return JSON.stringify({
130
+ ...data,
131
+ data: data.data.map(d => ({
132
+ ...d,
133
+ timestamp: new Date(d.timestamp * 1000).toISOString(),
134
+ apy: (0, utils_1.transformApy)(d.apy),
135
+ })),
136
+ });
137
+ }
138
+ catch (error) {
139
+ return `Failed to fetch vault historical data: ${error instanceof Error ? error.message : String(error)}`;
140
+ }
137
141
  }
138
142
  /**
139
- * Deposit action
143
+ * Transaction context action
140
144
  *
141
145
  * @param wallet - The wallet provider instance for blockchain interactions
142
146
  * @param args - Input arguments
143
147
  * @returns A result message
144
148
  */
145
- async deposit(wallet, args) {
146
- const actions = await (0, actions_1.fetchVaultActions)({
147
- action: "deposit",
148
- args: { ...args, amount: await (0, utils_1.parseAssetAmount)(wallet, args.assetAddress, args.amount) },
149
- sender: wallet.getAddress(),
150
- apiKey: this.apiKey,
151
- });
152
- if ("error" in actions) {
153
- return `Failed to fetch deposit transactions: ${actions.error}, ${actions.message}`;
149
+ async transactionContext(wallet, args) {
150
+ try {
151
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
152
+ const context = await sdk.getTransactionsContext({
153
+ path: {
154
+ userAddress: wallet.getAddress(),
155
+ vaultAddress: args.vaultAddress,
156
+ network: args.network,
157
+ },
158
+ });
159
+ return JSON.stringify(context);
160
+ }
161
+ catch (error) {
162
+ return `Failed to fetch transaction context: ${error instanceof Error ? error.message : String(error)}`;
154
163
  }
155
- await (0, utils_1.executeActions)(wallet, actions);
156
- return "Deposit successful";
157
164
  }
158
165
  /**
159
- * Redeem action
166
+ * Deposit action
160
167
  *
161
168
  * @param wallet - The wallet provider instance for blockchain interactions
162
169
  * @param args - Input arguments
163
170
  * @returns A result message
164
171
  */
165
- async redeem(wallet, args) {
166
- const actions = await (0, actions_1.fetchVaultActions)({
167
- action: "redeem",
168
- args: { ...args, amount: await (0, utils_1.parseAssetAmount)(wallet, args.assetAddress, args.amount) },
169
- sender: wallet.getAddress(),
170
- apiKey: this.apiKey,
171
- });
172
- if ("error" in actions) {
173
- return `Failed to fetch redeem transactions: ${actions.error}, ${actions.message}`;
172
+ async executeStep(wallet, args) {
173
+ try {
174
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
175
+ const amount = args.amount === "all" ? 0 : args.amount;
176
+ const actions = await sdk.getActions({
177
+ path: {
178
+ action: args.action,
179
+ userAddress: wallet.getAddress(),
180
+ vaultAddress: args.vaultAddress,
181
+ network: args.network,
182
+ },
183
+ query: {
184
+ assetAddress: args.assetAddress,
185
+ amount: amount ? amount.toString() : undefined,
186
+ all: args.amount === "all",
187
+ },
188
+ });
189
+ await (0, utils_1.executeActions)(wallet, actions);
190
+ return `Successfully executed ${args.action} step`;
191
+ }
192
+ catch (error) {
193
+ return `Failed to execute step: ${error instanceof Error ? error.message : String(error)}`;
194
+ }
195
+ }
196
+ /**
197
+ * Returns the users wallet token balances.
198
+ *
199
+ * @param wallet - The wallet provider instance for blockchain interactions
200
+ * @returns A record of the users balances
201
+ */
202
+ async idleAssets(wallet) {
203
+ try {
204
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
205
+ const idleAssets = await sdk.getIdleAssets({
206
+ path: {
207
+ userAddress: wallet.getAddress(),
208
+ },
209
+ });
210
+ return JSON.stringify(idleAssets);
211
+ }
212
+ catch (error) {
213
+ return `Failed to fetch idle assets: ${error instanceof Error ? error.message : String(error)}`;
214
+ }
215
+ }
216
+ /**
217
+ * Returns the users positions.
218
+ *
219
+ * @param wallet - The wallet provider instance for blockchain interactions
220
+ * @returns A record of the users positions
221
+ */
222
+ async positions(wallet) {
223
+ try {
224
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
225
+ const positions = await sdk.getPositions({
226
+ path: {
227
+ userAddress: wallet.getAddress(),
228
+ },
229
+ });
230
+ return JSON.stringify({
231
+ ...positions,
232
+ data: positions.data.map(p => ({
233
+ ...p,
234
+ apy: (0, utils_1.transformApy)(p.apy),
235
+ })),
236
+ });
237
+ }
238
+ catch (error) {
239
+ return `Failed to fetch positions: ${error instanceof Error ? error.message : String(error)}`;
240
+ }
241
+ }
242
+ /**
243
+ * Rewards context action
244
+ *
245
+ * @param wallet - The wallet provider instance for blockchain interactions
246
+ * @returns A record of rewards that are available to the user each with a unique claim id
247
+ */
248
+ async rewardsContext(wallet) {
249
+ try {
250
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
251
+ const context = await sdk.getRewardsTransactionsContext({
252
+ path: {
253
+ userAddress: wallet.getAddress(),
254
+ },
255
+ });
256
+ return JSON.stringify(context);
257
+ }
258
+ catch (error) {
259
+ return `Failed to fetch rewards context: ${error instanceof Error ? error.message : String(error)}`;
174
260
  }
175
- await (0, utils_1.executeActions)(wallet, actions);
176
- return "Redeem successful";
177
261
  }
178
262
  /**
179
263
  * Claim rewards action
180
264
  *
181
265
  * @param wallet - The wallet provider instance for blockchain interactions
182
- * @param args - Input arguments
183
- * @returns A result message
266
+ * @param args - Input arguments: claimIds
267
+ * @returns A message indicating the success of the claim
184
268
  */
185
- async claim(wallet, args) {
186
- const actions = await (0, actions_1.fetchVaultActions)({
187
- action: "claim-rewards",
188
- args,
189
- sender: wallet.getAddress(),
190
- apiKey: this.apiKey,
191
- });
192
- if ("error" in actions) {
193
- return `Failed to fetch claim transactions: ${actions.error}, ${actions.message}`;
269
+ async claimRewards(wallet, args) {
270
+ const chainId = wallet.getNetwork().chainId;
271
+ if (!chainId)
272
+ return "Invalid network";
273
+ const networkName = (0, constants_1.getNetworkNameFromChainId)(chainId);
274
+ if (!networkName)
275
+ return "Invalid network";
276
+ try {
277
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
278
+ const actions = await sdk.getRewardsClaimActions({
279
+ path: {
280
+ userAddress: wallet.getAddress(),
281
+ },
282
+ query: {
283
+ claimIds: args.claimIds,
284
+ },
285
+ });
286
+ if (Object.keys(actions).some(network => network !== networkName)) {
287
+ return `Error: You're trying to claim rewards from a different network. Agent network is ${networkName}.`;
288
+ }
289
+ if (!actions[networkName])
290
+ return "No actions found";
291
+ await (0, utils_1.executeActions)(wallet, actions[networkName]);
292
+ return `Successfully claimed rewards for ${args.claimIds.length} rewards`;
293
+ }
294
+ catch (error) {
295
+ return `Failed to claim rewards: ${error instanceof Error ? error.message : String(error)}`;
194
296
  }
195
- await (0, utils_1.executeActions)(wallet, actions);
196
- return "Claim successful";
197
297
  }
198
298
  /**
199
- * Returns the users wallet token balances.
299
+ * Benchmark APY action
200
300
  *
201
301
  * @param wallet - The wallet provider instance for blockchain interactions
202
- * @returns A record of the users balances
302
+ * @param args - Input arguments: network, benchmarkCode
303
+ * @returns benchmark APY data
203
304
  */
204
- async balances(wallet) {
205
- const params = new URLSearchParams({
206
- account: wallet.getAddress(),
207
- });
208
- const result = await fetch(`${constants_1.VAULTS_API_URL}/portfolio/wallet-balances?${params.toString()}`, {
209
- method: "GET",
210
- headers: {
211
- "x-api-key": this.apiKey,
212
- },
213
- });
214
- const balances = (await result.json());
215
- if ("error" in balances) {
216
- return `Failed to fetch wallet balances: ${balances.error}, ${balances.message}`;
305
+ async benchmarkApy(wallet, args) {
306
+ try {
307
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
308
+ const benchmark = await sdk.getBenchmarks({
309
+ path: {
310
+ network: args.network,
311
+ },
312
+ query: {
313
+ code: args.benchmarkCode,
314
+ },
315
+ });
316
+ return JSON.stringify({
317
+ ...benchmark,
318
+ apy: benchmark.apy ? (0, utils_1.transformApyObject)(benchmark.apy) : null,
319
+ timestamp: new Date(benchmark.timestamp * 1000).toISOString(),
320
+ });
217
321
  }
218
- const entries = Object.entries(balances).map(([network, balances]) => {
219
- return [
220
- network,
221
- balances.map(balance => ({
222
- address: balance.address,
223
- name: balance.name,
224
- symbol: balance.symbol,
225
- balance: Number(balance.balance) / 10 ** balance.decimals,
322
+ catch (error) {
323
+ return `Failed to fetch benchmark: ${error instanceof Error ? error.message : String(error)}`;
324
+ }
325
+ }
326
+ /**
327
+ * Historical benchmark APY action
328
+ *
329
+ * @param wallet - The wallet provider instance for blockchain interactions
330
+ * @param args - Input arguments: network, benchmarkCode, fromDate, toDate, page, perPage
331
+ * @returns A list of historical benchmark APY data
332
+ */
333
+ async historicalBenchmarkApy(wallet, args) {
334
+ try {
335
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
336
+ const historicalBenchmarks = await sdk.getHistoricalBenchmarks({
337
+ path: {
338
+ network: args.network,
339
+ },
340
+ query: {
341
+ code: args.benchmarkCode,
342
+ fromTimestamp: Math.floor(new Date(args.fromDate).getTime() / 1000),
343
+ toTimestamp: Math.floor(new Date(args.toDate).getTime() / 1000),
344
+ page: args.page,
345
+ perPage: args.perPage,
346
+ },
347
+ });
348
+ return JSON.stringify({
349
+ ...historicalBenchmarks,
350
+ data: historicalBenchmarks.data.map(d => ({
351
+ timestamp: new Date(d.timestamp * 1000).toISOString(),
352
+ apy: d.apy ? (0, utils_1.transformApyObject)(d.apy) : null,
226
353
  })),
227
- ];
228
- });
229
- return JSON.stringify(Object.fromEntries(entries));
354
+ });
355
+ }
356
+ catch (error) {
357
+ return `Failed to fetch historical benchmark: ${error instanceof Error ? error.message : String(error)}`;
358
+ }
230
359
  }
231
360
  /**
232
- * Returns the users positions.
361
+ * Total vault returns action
233
362
  *
234
363
  * @param wallet - The wallet provider instance for blockchain interactions
235
- * @returns A record of the users positions
364
+ * @param args - Input arguments: vaultAddress, network, userAddress
365
+ * @returns An amount of the users total returns
236
366
  */
237
- async positions(wallet) {
238
- const result = await fetch(`${constants_1.VAULTS_API_URL}/portfolio/positions/${wallet.getAddress()}`, {
239
- method: "GET",
240
- headers: {
241
- "x-api-key": this.apiKey,
242
- },
243
- });
244
- const positions = (await result.json());
245
- if ("error" in positions) {
246
- return `Failed to fetch positions: ${positions.error}, ${positions.message}`;
367
+ async totalVaultReturns(wallet, args) {
368
+ try {
369
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
370
+ const totalReturns = await sdk.getUserVaultTotalReturns({
371
+ path: {
372
+ vaultAddress: args.vaultAddress,
373
+ network: args.network,
374
+ userAddress: args.userAddress || wallet.getAddress(),
375
+ },
376
+ });
377
+ return JSON.stringify(totalReturns);
378
+ }
379
+ catch (error) {
380
+ return `Failed to fetch total vault returns: ${error instanceof Error ? error.message : String(error)}`;
247
381
  }
248
- const entries = Object.entries(positions).map(([network, positions]) => {
249
- return [
250
- network,
251
- positions.map(position => ({
252
- name: position.vaultName,
253
- vaultAddress: position.vaultAddress,
254
- asset: {
255
- address: position.asset.assetAddress,
256
- name: position.asset.name,
257
- symbol: position.asset.symbol,
258
- },
259
- underlyingTokenBalance: Number(position.balanceNative) / 10 ** position.asset.decimals,
260
- lpTokenBalance: Number(position.balanceLp) / 10 ** position.asset.decimals,
261
- unclaimedRewards: Number(position.unclaimedUsd) > 0,
262
- apy: {
263
- base: position.apy.base / 100,
264
- rewards: position.apy.rewards / 100,
265
- total: position.apy.total / 100,
266
- },
382
+ }
383
+ /**
384
+ * User events action
385
+ *
386
+ * @param wallet - The wallet provider instance for blockchain interactions
387
+ * @param args - Input arguments: vaultAddress, network, userAddress
388
+ * @returns A list of the users actions on a vault
389
+ */
390
+ async userEvents(wallet, args) {
391
+ try {
392
+ const sdk = (0, sdk_1.getVaultsSdk)(this.apiKey);
393
+ const userEvents = await sdk.getUserVaultEvents({
394
+ path: {
395
+ vaultAddress: args.vaultAddress,
396
+ network: args.network,
397
+ userAddress: args.userAddress || wallet.getAddress(),
398
+ },
399
+ });
400
+ return JSON.stringify({
401
+ ...userEvents,
402
+ data: userEvents.data.map(d => ({
403
+ ...d,
404
+ timestamp: new Date(d.timestamp * 1000).toISOString(),
267
405
  })),
268
- ];
269
- });
270
- return JSON.stringify(Object.fromEntries(entries));
406
+ });
407
+ }
408
+ catch (error) {
409
+ return `Failed to fetch user events: ${error instanceof Error ? error.message : String(error)}`;
410
+ }
271
411
  }
272
412
  /**
273
413
  * Checks if this provider supports the given network.
@@ -276,8 +416,8 @@ class VaultsfyiActionProvider extends actionProvider_1.ActionProvider {
276
416
  * @returns True if the network is supported
277
417
  */
278
418
  supportsNetwork(network) {
279
- return (network.protocolFamily == "evm" &&
280
- (network.chainId ? Object.keys(constants_1.VAULTSFYI_SUPPORTED_CHAINS).includes(network.chainId) : false));
419
+ return (network.protocolFamily === "evm" &&
420
+ (network.chainId ? constants_1.SUPPORTED_CHAIN_IDS.includes(network.chainId) : false));
281
421
  }
282
422
  }
283
423
  exports.VaultsfyiActionProvider = VaultsfyiActionProvider;
@@ -285,24 +425,24 @@ __decorate([
285
425
  (0, actionDecorator_1.CreateAction)({
286
426
  name: "vaults",
287
427
  description: `
288
- This action returns a list of available vaults.
428
+ This action returns a list of available vaults. All asset/lp token amounts returned are in the smallest unit of the token.
289
429
  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.
290
430
  When the user asks for best vaults, optimize for apy, and if the user asks for safest/reliable vaults, optimize for TVL.
291
- Try to take a reasonable number of results so its easier to analyze the data. Include vaults.fyi links for each vault.
292
- Format result apys as: x% (base: x%, rewards: x%) if rewards apy is available, otherwise: x%
431
+ Include vaults.fyi links for each vault.
432
+ By default, it's best to check only the vaults for the users network (check with another action if you're not sure).
293
433
  Examples:
294
434
  User: "Show me the best vaults"
295
- args: { sort: { field: 'apy', direction: 'desc' }, take: 5 }
435
+ args: { sort: { field: 'apy7day', direction: 'desc' }, perPage: 5 }
296
436
  User: "Show me the safest vaults"
297
- args: { sort: { field: 'tvl', direction: 'desc' }, take: 5 }
437
+ args: { sort: { field: 'tvl', direction: 'desc' }, perPage: 5 }
298
438
  User: "Show me the best vaults on Arbitrum"
299
- args: { network: 'arbitrum', sort: { field: 'apy', direction: 'desc' }, take: 5 }
439
+ args: { allowedNetworks: ['arbitrum'], sort: { field: 'apy7day', direction: 'desc' }, perPage: 5 }
300
440
  User: "I want to earn yield on my usdc on base!"
301
- args: { token: 'usdc', network: 'base', sort: { field: 'apy', direction: 'desc' }, take: 5 }
441
+ args: { allowedAssets: ['usdc'], allowedNetworks: ['base'], sort: { field: 'apy7day', direction: 'desc' }, perPage: 5 }
302
442
  User: "What are some of the most profitable degen vaults on polygon"
303
- args: { network: 'polygon', sort: { field: 'apy', direction: 'desc' }, take: 5, minTvl: 0 }
443
+ args: { allowedNetworks: ['polygon'], sort: { field: 'apy7day', direction: 'desc' }, perPage: 5, minTvl: 0 }
304
444
  User: "Show me some more of those"
305
- args: { network: 'polygon', sort: { field: 'apy', direction: 'desc' }, take: 5, minTvl: 0, page: 2 }
445
+ args: { allowedNetworks: ['polygon'], sort: { field: 'apy7day', direction: 'desc' }, perPage: 5, minTvl: 0, page: 2 }
306
446
  All optional fields should be null if not specified.
307
447
  `,
308
448
  schema: schemas_1.VaultsActionSchema,
@@ -313,16 +453,9 @@ __decorate([
313
453
  ], VaultsfyiActionProvider.prototype, "vaults", null);
314
454
  __decorate([
315
455
  (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)
456
+ name: "detailed_vault",
457
+ description: `This action returns single vault details.
458
+ All asset/lp token amounts returned are in the smallest unit of the token.
326
459
  `,
327
460
  schema: schemas_1.VaultDetailsActionSchema,
328
461
  }),
@@ -334,15 +467,12 @@ __decorate([
334
467
  (0, actionDecorator_1.CreateAction)({
335
468
  name: "vault_historical_data",
336
469
  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
- `,
470
+ This action returns a historical APY, TVL and share price of a vault.
471
+ It returns an array of data points with the requested granularity. (hourly, daily weekly),
472
+ The pricing is 3 credits base and 3 credits for each datapoint.
473
+ Estimate the credits usage and warn the user before executing the action.
474
+ All asset/lp token amounts returned are in the smallest unit of the token.
475
+ `,
346
476
  schema: schemas_1.VaultHistoricalDataActionSchema,
347
477
  }),
348
478
  __metadata("design:type", Function),
@@ -351,15 +481,18 @@ __decorate([
351
481
  ], VaultsfyiActionProvider.prototype, "vaultHistoricalData", null);
352
482
  __decorate([
353
483
  (0, actionDecorator_1.CreateAction)({
354
- name: "deposit",
484
+ name: "transaction_context",
355
485
  description: `
356
- 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.
357
- Even if you received the balance from some other source, double-check the user balance.
358
- Use examples:
486
+ This action returns the transaction context for a given vault. It returns a list of steps for a deposit/redeem from a vault.
487
+ These steps can be executed using the execute_step action. Check the "redeemStepsType"/"depositStepsType" to see if it's "instant" or "complex".
488
+ Complex steps might require delay between steps like request and claim flows. Status of these can usually be found in the "vaultSpecificData" field of the context.
489
+ All asset/lp token amounts returned are in the smallest unit of the token. For example, USDC has 6 decimals, so 1000 USDC is 1000000000. Use smallest unit for the amount field in the execute_step action.
490
+ Usage examples:
359
491
  User: "Deposit 1000 USDC into the vault"
360
492
  actions:
361
- - check wallet balance for USDC
362
- - deposit USDC into the vault if balance is sufficient
493
+ - check if the wallet has 1000 USDC
494
+ - check vault context to see the deposit steps
495
+ - execute the deposit steps sequentially
363
496
  User: "I want more yield on my DAI"
364
497
  actions:
365
498
  - check positions that the user already has for dai
@@ -373,45 +506,32 @@ __decorate([
373
506
  - create a diversified strategy using the users assets
374
507
  - propose the strategy to the user before executing
375
508
  `,
376
- schema: schemas_1.depositActionSchema,
377
- }),
378
- __metadata("design:type", Function),
379
- __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
380
- __metadata("design:returntype", Promise)
381
- ], VaultsfyiActionProvider.prototype, "deposit", null);
382
- __decorate([
383
- (0, actionDecorator_1.CreateAction)({
384
- name: "redeem",
385
- description: `
386
- 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.
387
- Even if you received the lp tokens from some other source, double-check the amount before redeeming.
388
- 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.
389
- `,
390
- schema: schemas_1.redeemActionSchema,
509
+ schema: schemas_1.transactionContextActionSchema,
391
510
  }),
392
511
  __metadata("design:type", Function),
393
512
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
394
513
  __metadata("design:returntype", Promise)
395
- ], VaultsfyiActionProvider.prototype, "redeem", null);
514
+ ], VaultsfyiActionProvider.prototype, "transactionContext", null);
396
515
  __decorate([
397
516
  (0, actionDecorator_1.CreateAction)({
398
- name: "claim_rewards",
517
+ name: "execute_step",
399
518
  description: `
400
- This action claims rewards from a selected vault.
401
- assetAddress is the address of the vaults underlying token.
402
- If you're not sure what vaults have rewards claimable, use the positions action.
403
- `,
404
- schema: schemas_1.claimActionSchema,
519
+ This action executes a given step on a vault. If you're not sure what steps are available, use the transaction context to get more information.
520
+ The amount should be a in smallest unit of the token (f.e. 1000000 for 1 USDC) and for redeeming should be the amount of lpTokens in smallest units.
521
+ If you want to redeem all shares, use {"amount":"all"}.
522
+ Even if you received the balance from some other source, double-check the user balance with idle_assets/positions/context actions before deposit/redeem.`,
523
+ schema: schemas_1.executeStepActionSchema,
405
524
  }),
406
525
  __metadata("design:type", Function),
407
526
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
408
527
  __metadata("design:returntype", Promise)
409
- ], VaultsfyiActionProvider.prototype, "claim", null);
528
+ ], VaultsfyiActionProvider.prototype, "executeStep", null);
410
529
  __decorate([
411
530
  (0, actionDecorator_1.CreateAction)({
412
- name: "user_wallet_balances",
531
+ name: "user_idle_assets",
413
532
  description: `
414
533
  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.
534
+ All asset/lp token amounts returned are in the smallest unit of the token.
415
535
  Example queries:
416
536
  User: "What tokens do I have?"
417
537
  User: "What tokens do I have on Arbitrum?"
@@ -422,12 +542,13 @@ __decorate([
422
542
  __metadata("design:type", Function),
423
543
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider]),
424
544
  __metadata("design:returntype", Promise)
425
- ], VaultsfyiActionProvider.prototype, "balances", null);
545
+ ], VaultsfyiActionProvider.prototype, "idleAssets", null);
426
546
  __decorate([
427
547
  (0, actionDecorator_1.CreateAction)({
428
548
  name: "positions",
429
549
  description: `
430
550
  This action returns the users positions in vaults.
551
+ All asset/lp token amounts returned are in the smallest unit of the token.
431
552
  Example queries:
432
553
  User: "Show me my positions"
433
554
  User: "What vaults am i invested in?"
@@ -440,11 +561,86 @@ __decorate([
440
561
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider]),
441
562
  __metadata("design:returntype", Promise)
442
563
  ], VaultsfyiActionProvider.prototype, "positions", null);
564
+ __decorate([
565
+ (0, actionDecorator_1.CreateAction)({
566
+ name: "rewards_context",
567
+ description: `
568
+ This action returns a record of rewards that are available to the user each with a unique claim id. You can use these ids in the claim_rewards action to claim specific rewards.
569
+ All asset/lp token amounts returned are in the smallest unit of the token.
570
+ `,
571
+ schema: zod_1.z.object({}),
572
+ }),
573
+ __metadata("design:type", Function),
574
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider]),
575
+ __metadata("design:returntype", Promise)
576
+ ], VaultsfyiActionProvider.prototype, "rewardsContext", null);
577
+ __decorate([
578
+ (0, actionDecorator_1.CreateAction)({
579
+ name: "claim_rewards",
580
+ description: `
581
+ This action claims rewards for a given reward id.
582
+ `,
583
+ schema: schemas_1.claimRewardsActionSchema,
584
+ }),
585
+ __metadata("design:type", Function),
586
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
587
+ __metadata("design:returntype", Promise)
588
+ ], VaultsfyiActionProvider.prototype, "claimRewards", null);
589
+ __decorate([
590
+ (0, actionDecorator_1.CreateAction)({
591
+ name: "benchmark_apy",
592
+ description: `
593
+ This action retrieves benchmark APY data for the specified network and benchmark code. It's a weighted average of top yields for the network and asset. Can be used to benchmark vaults against.
594
+ `,
595
+ schema: schemas_1.benchmarkActionSchema,
596
+ }),
597
+ __metadata("design:type", Function),
598
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
599
+ __metadata("design:returntype", Promise)
600
+ ], VaultsfyiActionProvider.prototype, "benchmarkApy", null);
601
+ __decorate([
602
+ (0, actionDecorator_1.CreateAction)({
603
+ name: "historical_benchmark_apy",
604
+ description: `
605
+ This action retrieves historical benchmark APY data for the specified network and benchmark code. It's a weighted average of top yields for the network and asset. Can be used to benchmark vaults against.
606
+ `,
607
+ schema: schemas_1.historicalBenchmarkActionSchema,
608
+ }),
609
+ __metadata("design:type", Function),
610
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
611
+ __metadata("design:returntype", Promise)
612
+ ], VaultsfyiActionProvider.prototype, "historicalBenchmarkApy", null);
613
+ __decorate([
614
+ (0, actionDecorator_1.CreateAction)({
615
+ name: "total_vault_returns",
616
+ description: `
617
+ This action retrieves the total returns earned by a given user for a given vault. Uses your address if userAddress not specified.
618
+ "returnsNative" amounts returned are in the smallest unit of the token.
619
+ `,
620
+ schema: schemas_1.totalVaultReturnsActionSchema,
621
+ }),
622
+ __metadata("design:type", Function),
623
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
624
+ __metadata("design:returntype", Promise)
625
+ ], VaultsfyiActionProvider.prototype, "totalVaultReturns", null);
626
+ __decorate([
627
+ (0, actionDecorator_1.CreateAction)({
628
+ name: "user_events",
629
+ description: `
630
+ This action retrieves historical actions performed by a given user on a given vault.
631
+ All asset/lp token amounts returned are in the smallest unit of the token.
632
+ `,
633
+ schema: schemas_1.userEventsActionSchema,
634
+ }),
635
+ __metadata("design:type", Function),
636
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
637
+ __metadata("design:returntype", Promise)
638
+ ], VaultsfyiActionProvider.prototype, "userEvents", null);
443
639
  /**
444
640
  * Factory function to create a new VaultsfyiActionProvider instance.
445
641
  *
446
642
  * @param config - Configuration options for the provider
447
643
  * @returns A new VaultsfyiActionProvider instance
448
644
  */
449
- const vaultsfyiActionProvider = (config) => new VaultsfyiActionProvider(config);
645
+ const vaultsfyiActionProvider = (config = {}) => new VaultsfyiActionProvider(config);
450
646
  exports.vaultsfyiActionProvider = vaultsfyiActionProvider;