@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
@@ -11,46 +11,109 @@ const mockFetchResult = (status, data) => {
11
11
  };
12
12
  const mockVault = (num) => ({
13
13
  apiResult: {
14
- address: `0x${num.toString(16).padStart(40, "0")}`,
15
- network: `network-${num}`,
14
+ address: "0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
15
+ network: {
16
+ name: "base",
17
+ chainId: 8453,
18
+ networkCaip: "eip155:8453",
19
+ },
20
+ asset: {
21
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
22
+ assetCaip: "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
23
+ name: "USD Coin",
24
+ symbol: "USDC",
25
+ decimals: 6,
26
+ assetLogo: "https://images.vaults.fyi/tokens/usdc.png",
27
+ assetPriceInUsd: "0.99983592",
28
+ assetGroup: "USD",
29
+ },
30
+ isTransactional: true,
31
+ isAppFeatured: true,
16
32
  name: `vault-${num}`,
17
- protocol: `protocol-${num}`,
18
- token: {
19
- name: `token-${num}`,
20
- assetAddress: `0x${num.toString(16).padStart(40, "0")}`,
21
- symbol: `T${num}`,
22
- decimals: 18,
33
+ protocol: {
34
+ name: "40acres",
35
+ product: "",
36
+ version: "",
37
+ protocolLogo: "https://images.vaults.fyi/protocols/40acres.png",
23
38
  },
24
- tvlDetails: {
25
- tvlUsd: num.toString(),
39
+ lendUrl: "https://app.vaults.fyi/opportunity/base/0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
40
+ description: `Description for vault-${num}`,
41
+ protocolVaultUrl: "https://www.40acres.finance/",
42
+ tags: ["Lending"],
43
+ holdersData: {
44
+ totalCount: num,
45
+ totalBalance: (num * 1000000).toString(),
46
+ topHolders: [
47
+ {
48
+ address: "0x1d59868D7767d703929393bDaB313302840f533c",
49
+ lpTokenBalance: (num * 1000000).toString(),
50
+ },
51
+ {
52
+ address: "0x1c6586f4895A569d9EFac5ABd231b79E0D47cAAD",
53
+ lpTokenBalance: (num * 1000000).toString(),
54
+ },
55
+ {
56
+ address: "0x011b0a055E02425461A1ae95B30F483c4fF05bE7",
57
+ lpTokenBalance: (num * 1000000).toString(),
58
+ },
59
+ {
60
+ address: "0x9551EeC2a31025D582Be358E05D88a9c95cAD86E",
61
+ lpTokenBalance: (num * 1000000).toString(),
62
+ },
63
+ {
64
+ address: "0x10076ed296571cE4Fde5b1FDF0eB9014a880e47B",
65
+ lpTokenBalance: (num * 1000000).toString(),
66
+ },
67
+ {
68
+ address: "0x9e33Fef28A75303B4FEB7b4c713c27Fed2AC78DD",
69
+ lpTokenBalance: (num * 1000000).toString(),
70
+ },
71
+ {
72
+ address: "0x166B9a0390474C455115dFb64579D1D79286588F",
73
+ lpTokenBalance: (num * 1000000).toString(),
74
+ },
75
+ {
76
+ address: "0x318962D28813fe14B9b6265fE2dAFB241C7F7777",
77
+ lpTokenBalance: (num * 1000000).toString(),
78
+ },
79
+ {
80
+ address: "0x22e4bB70905c7Ad93B65BC9Bd5B1b06e67378124",
81
+ lpTokenBalance: (num * 1000000).toString(),
82
+ },
83
+ {
84
+ address: "0x57609a91CC6eA77D9805137656A9308F5bF52f23",
85
+ lpTokenBalance: (num * 1000000).toString(),
86
+ },
87
+ ],
26
88
  },
27
89
  apy: {
28
- base: {
29
- "7day": num * 100,
90
+ "1day": {
91
+ base: num,
92
+ reward: num,
93
+ total: num,
30
94
  },
31
- rewards: {
32
- "7day": num * 100,
95
+ "7day": {
96
+ base: num,
97
+ reward: num,
98
+ total: num,
33
99
  },
34
- total: {
35
- "7day": num * 100,
100
+ "30day": {
101
+ base: num,
102
+ reward: num,
103
+ total: num,
36
104
  },
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
- },
105
+ "1hour": {
106
+ base: num,
107
+ reward: num,
108
+ total: num,
50
109
  },
51
- ],
52
- description: `Description for vault-${num}`,
53
- additionalIncentives: `Incentives for vault-${num}`,
110
+ },
111
+ tvl: {
112
+ usd: num.toString(),
113
+ native: (num * 1000000).toString(),
114
+ },
115
+ lastUpdateTimestamp: 1764259200,
116
+ rewards: [],
54
117
  score: {
55
118
  vaultScore: num,
56
119
  vaultTvlScore: num,
@@ -59,27 +122,146 @@ const mockVault = (num) => ({
59
122
  networkScore: num,
60
123
  assetScore: num,
61
124
  },
62
- isTransactional: true,
125
+ lpToken: {
126
+ address: "0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
127
+ tokenCaip: "eip155:8453/erc20:0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
128
+ name: `Vault-${num}`,
129
+ symbol: `VAULT-${num}`,
130
+ decimals: 6,
131
+ },
132
+ transactionalProperties: {
133
+ depositStepsType: "instant",
134
+ redeemStepsType: "instant",
135
+ rewardsSupported: false,
136
+ },
137
+ warnings: [],
63
138
  },
64
139
  transformedResult: {
140
+ address: "0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
141
+ network: {
142
+ name: "base",
143
+ chainId: 8453,
144
+ networkCaip: "eip155:8453",
145
+ },
146
+ asset: {
147
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
148
+ assetCaip: "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
149
+ name: "USD Coin",
150
+ symbol: "USDC",
151
+ decimals: 6,
152
+ assetLogo: "https://images.vaults.fyi/tokens/usdc.png",
153
+ assetPriceInUsd: "0.99983592",
154
+ assetGroup: "USD",
155
+ },
156
+ isTransactional: true,
157
+ isAppFeatured: true,
65
158
  name: `vault-${num}`,
66
- address: `0x${num.toString(16).padStart(40, "0")}`,
67
- network: `network-${num}`,
68
- protocol: `protocol-${num}`,
69
- tvlInUsd: num,
70
- token: {
71
- name: `token-${num}`,
72
- address: `0x${num.toString(16).padStart(40, "0")}`,
73
- symbol: `T${num}`,
159
+ protocol: {
160
+ name: "40acres",
161
+ product: "",
162
+ version: "",
163
+ protocolLogo: "https://images.vaults.fyi/protocols/40acres.png",
164
+ },
165
+ lendUrl: "https://app.vaults.fyi/opportunity/base/0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
166
+ description: `Description for vault-${num}`,
167
+ protocolVaultUrl: "https://www.40acres.finance/",
168
+ tags: ["Lending"],
169
+ holdersData: {
170
+ totalCount: num,
171
+ totalBalance: (num * 1000000).toString(),
172
+ topHolders: [
173
+ {
174
+ address: "0x1d59868D7767d703929393bDaB313302840f533c",
175
+ lpTokenBalance: (num * 1000000).toString(),
176
+ },
177
+ {
178
+ address: "0x1c6586f4895A569d9EFac5ABd231b79E0D47cAAD",
179
+ lpTokenBalance: (num * 1000000).toString(),
180
+ },
181
+ {
182
+ address: "0x011b0a055E02425461A1ae95B30F483c4fF05bE7",
183
+ lpTokenBalance: (num * 1000000).toString(),
184
+ },
185
+ {
186
+ address: "0x9551EeC2a31025D582Be358E05D88a9c95cAD86E",
187
+ lpTokenBalance: (num * 1000000).toString(),
188
+ },
189
+ {
190
+ address: "0x10076ed296571cE4Fde5b1FDF0eB9014a880e47B",
191
+ lpTokenBalance: (num * 1000000).toString(),
192
+ },
193
+ {
194
+ address: "0x9e33Fef28A75303B4FEB7b4c713c27Fed2AC78DD",
195
+ lpTokenBalance: (num * 1000000).toString(),
196
+ },
197
+ {
198
+ address: "0x166B9a0390474C455115dFb64579D1D79286588F",
199
+ lpTokenBalance: (num * 1000000).toString(),
200
+ },
201
+ {
202
+ address: "0x318962D28813fe14B9b6265fE2dAFB241C7F7777",
203
+ lpTokenBalance: (num * 1000000).toString(),
204
+ },
205
+ {
206
+ address: "0x22e4bB70905c7Ad93B65BC9Bd5B1b06e67378124",
207
+ lpTokenBalance: (num * 1000000).toString(),
208
+ },
209
+ {
210
+ address: "0x57609a91CC6eA77D9805137656A9308F5bF52f23",
211
+ lpTokenBalance: (num * 1000000).toString(),
212
+ },
213
+ ],
74
214
  },
75
215
  apy: {
76
- base: num,
77
- rewards: num,
78
- total: num,
216
+ "1day": {
217
+ base: `${(num * 100).toFixed(2)}%`,
218
+ reward: `${(num * 100).toFixed(2)}%`,
219
+ total: `${(num * 100).toFixed(2)}%`,
220
+ },
221
+ "7day": {
222
+ base: `${(num * 100).toFixed(2)}%`,
223
+ reward: `${(num * 100).toFixed(2)}%`,
224
+ total: `${(num * 100).toFixed(2)}%`,
225
+ },
226
+ "30day": {
227
+ base: `${(num * 100).toFixed(2)}%`,
228
+ reward: `${(num * 100).toFixed(2)}%`,
229
+ total: `${(num * 100).toFixed(2)}%`,
230
+ },
231
+ "1hour": {
232
+ base: `${(num * 100).toFixed(2)}%`,
233
+ reward: `${(num * 100).toFixed(2)}%`,
234
+ total: `${(num * 100).toFixed(2)}%`,
235
+ },
236
+ },
237
+ tvl: {
238
+ usd: num.toString(),
239
+ native: (num * 1000000).toString(),
79
240
  },
80
- vaultsFyiScore: num,
81
- numberOfHolders: num,
82
- link: `https://app.vaults.fyi/opportunity/network-${num}/0x${num.toString(16).padStart(40, "0")}`,
241
+ lastUpdateTimestamp: new Date(1764259200 * 1000).toISOString(),
242
+ rewards: [],
243
+ score: {
244
+ vaultScore: num,
245
+ vaultTvlScore: num,
246
+ protocolTvlScore: num,
247
+ holderScore: num,
248
+ networkScore: num,
249
+ assetScore: num,
250
+ },
251
+ lpToken: {
252
+ address: "0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
253
+ tokenCaip: "eip155:8453/erc20:0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5",
254
+ name: `Vault-${num}`,
255
+ symbol: `VAULT-${num}`,
256
+ decimals: 6,
257
+ },
258
+ transactionalProperties: {
259
+ depositStepsType: "instant",
260
+ redeemStepsType: "instant",
261
+ rewardsSupported: false,
262
+ },
263
+ warnings: [],
264
+ link: `https://app.vaults.fyi/opportunity/base/0xB99B6dF96d4d5448cC0a5B3e0ef7896df9507Cf5`,
83
265
  },
84
266
  });
85
267
  const MOCK_TX_HASH = "0xmock-hash";
@@ -111,10 +293,10 @@ describe("VaultsfyiActionProvider", () => {
111
293
  });
112
294
  describe("network support", () => {
113
295
  it("should support all vaultsfyi networks", () => {
114
- Object.keys(constants_1.VAULTSFYI_SUPPORTED_CHAINS).forEach(network => {
296
+ constants_1.SUPPORTED_CHAIN_IDS.forEach(chainId => {
115
297
  expect(provider.supportsNetwork({
116
298
  protocolFamily: "evm",
117
- chainId: network,
299
+ chainId: chainId,
118
300
  })).toBe(true);
119
301
  });
120
302
  });
@@ -135,75 +317,16 @@ describe("VaultsfyiActionProvider", () => {
135
317
  const args = {};
136
318
  const result = await provider.vaults(mockWalletProvider, args);
137
319
  expect(JSON.parse(result)).toStrictEqual({
138
- totalResults: 1,
139
- nextPage: false,
140
- results: [mockedVault.transformedResult],
141
- });
142
- });
143
- it("should filter by protocol", async () => {
144
- const mockedVaults = [mockVault(1), mockVault(2)];
145
- mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
146
- const args = { protocol: "protocol-1" };
147
- const result = await provider.vaults(mockWalletProvider, args);
148
- expect(JSON.parse(result)).toStrictEqual({
149
- totalResults: 1,
150
- nextPage: false,
151
- results: [mockedVaults[0].transformedResult],
152
- });
153
- });
154
- it("should take a limit", async () => {
155
- const mockedVaults = [mockVault(1), mockVault(2)];
156
- mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
157
- const args = { take: 1 };
158
- const result = await provider.vaults(mockWalletProvider, args);
159
- expect(JSON.parse(result)).toStrictEqual({
160
- totalResults: 2,
161
- nextPage: true,
162
- results: [mockedVaults[0].transformedResult],
163
- });
164
- });
165
- describe("sorting", () => {
166
- it("should sort by TVL", async () => {
167
- const mockedVaults = [mockVault(2), mockVault(1)];
168
- mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
169
- const args = { sort: { field: "tvl", direction: "asc" } };
170
- const result = await provider.vaults(mockWalletProvider, args);
171
- expect(JSON.parse(result)).toStrictEqual({
172
- totalResults: 2,
173
- nextPage: false,
174
- results: [mockedVaults[1].transformedResult, mockedVaults[0].transformedResult],
175
- });
176
- });
177
- it("should sort by APY", async () => {
178
- const mockedVaults = [mockVault(2), mockVault(1)];
179
- mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
180
- const args = { sort: { field: "apy", direction: "asc" } };
181
- const result = await provider.vaults(mockWalletProvider, args);
182
- expect(JSON.parse(result)).toStrictEqual({
183
- totalResults: 2,
184
- nextPage: false,
185
- results: [mockedVaults[1].transformedResult, mockedVaults[0].transformedResult],
186
- });
187
- });
188
- it("should sort by name by default", async () => {
189
- const mockedVaults = [mockVault(2), mockVault(1)];
190
- mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
191
- const args = {};
192
- const result = await provider.vaults(mockWalletProvider, args);
193
- expect(JSON.parse(result)).toStrictEqual({
194
- totalResults: 2,
195
- nextPage: false,
196
- results: [mockedVaults[1].transformedResult, mockedVaults[0].transformedResult],
197
- });
320
+ data: [mockedVault.transformedResult],
198
321
  });
199
322
  });
200
323
  it("should return an error if the API request fails", async () => {
201
324
  mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
202
325
  const args = {};
203
- expect(await provider.vaults(mockWalletProvider, args)).toBe("Failed to fetch vaults: Internal Server Error, some more info");
326
+ expect(await provider.vaults(mockWalletProvider, args)).toBe("Failed to fetch vaults: some more info");
204
327
  });
205
328
  });
206
- describe("deposit action", () => {
329
+ describe("execute_step action", () => {
207
330
  it("should execute deposit", async () => {
208
331
  mockedFetch.mockResolvedValue(mockFetchResult(200, {
209
332
  currentActionIndex: 0,
@@ -223,15 +346,15 @@ describe("VaultsfyiActionProvider", () => {
223
346
  vaultAddress: "0x123",
224
347
  assetAddress: "0x456",
225
348
  network: "mainnet",
226
- amount: 1,
349
+ amount: 1n,
350
+ action: "deposit",
227
351
  };
228
- const response = await provider.deposit(mockWalletProvider, args);
229
- expect(response).toBe("Deposit successful");
352
+ const response = await provider.executeStep(mockWalletProvider, args);
353
+ expect(response).toBe("Successfully executed deposit step");
230
354
  expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
231
355
  to: "0x123",
232
356
  data: "0x456",
233
357
  value: 1n,
234
- chainId: 1,
235
358
  });
236
359
  expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
237
360
  });
@@ -263,21 +386,20 @@ describe("VaultsfyiActionProvider", () => {
263
386
  vaultAddress: "0x123",
264
387
  assetAddress: "0x456",
265
388
  network: "mainnet",
266
- amount: 1,
389
+ amount: 1n,
390
+ action: "deposit",
267
391
  };
268
- const response = await provider.deposit(mockWalletProvider, args);
269
- expect(response).toBe("Deposit successful");
392
+ const response = await provider.executeStep(mockWalletProvider, args);
393
+ expect(response).toBe("Successfully executed deposit step");
270
394
  expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
271
395
  to: "0x123",
272
396
  data: "0x456",
273
397
  value: 1n,
274
- chainId: 1,
275
398
  });
276
399
  expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
277
400
  to: "0x789",
278
401
  data: "0xabc",
279
402
  value: 2n,
280
- chainId: 1,
281
403
  });
282
404
  expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
283
405
  });
@@ -287,99 +409,14 @@ describe("VaultsfyiActionProvider", () => {
287
409
  vaultAddress: "0x123",
288
410
  assetAddress: "0x456",
289
411
  network: "mainnet",
290
- amount: 1,
412
+ amount: 1n,
413
+ action: "deposit",
291
414
  };
292
- expect(await provider.deposit(mockWalletProvider, args)).toBe("Failed to fetch deposit transactions: Internal Server Error, some more info");
415
+ expect(await provider.executeStep(mockWalletProvider, args)).toBe("Failed to execute step: some more info");
293
416
  });
294
417
  });
295
- describe("redeem action", () => {
296
- it("should execute redeem", async () => {
297
- mockedFetch.mockResolvedValue(mockFetchResult(200, {
298
- currentActionIndex: 0,
299
- actions: [
300
- {
301
- tx: {
302
- to: "0x123",
303
- data: "0x456",
304
- value: "1",
305
- chainId: 1,
306
- },
307
- description: "Redeem from vault",
308
- },
309
- ],
310
- }));
311
- const args = {
312
- vaultAddress: "0x123",
313
- assetAddress: "0x456",
314
- network: "mainnet",
315
- amount: 1,
316
- };
317
- const response = await provider.redeem(mockWalletProvider, args);
318
- expect(response).toBe("Redeem successful");
319
- expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
320
- to: "0x123",
321
- data: "0x456",
322
- value: 1n,
323
- chainId: 1,
324
- });
325
- expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
326
- });
327
- it("should return an error if the API request fails", async () => {
328
- mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
329
- const args = {
330
- vaultAddress: "0x123",
331
- assetAddress: "0x456",
332
- network: "mainnet",
333
- amount: 1,
334
- };
335
- expect(await provider.redeem(mockWalletProvider, args)).toBe("Failed to fetch redeem transactions: Internal Server Error, some more info");
336
- });
337
- });
338
- describe("claim rewards action", () => {
339
- it("should execute claim rewards", async () => {
340
- mockedFetch.mockResolvedValue(mockFetchResult(200, {
341
- currentActionIndex: 0,
342
- actions: [
343
- {
344
- tx: {
345
- to: "0x123",
346
- data: "0x456",
347
- value: "1",
348
- chainId: 1,
349
- },
350
- description: "Claim rewards from vault",
351
- },
352
- ],
353
- }));
354
- const args = {
355
- vaultAddress: "0x123",
356
- assetAddress: "0x456",
357
- network: "mainnet",
358
- amount: 1,
359
- };
360
- const response = await provider.claim(mockWalletProvider, args);
361
- expect(response).toBe("Claim successful");
362
- expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
363
- to: "0x123",
364
- data: "0x456",
365
- value: 1n,
366
- chainId: 1,
367
- });
368
- expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
369
- });
370
- it("should return an error if the API request fails", async () => {
371
- mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
372
- const args = {
373
- vaultAddress: "0x123",
374
- assetAddress: "0x456",
375
- network: "mainnet",
376
- amount: 1,
377
- };
378
- expect(await provider.claim(mockWalletProvider, args)).toBe("Failed to fetch claim transactions: Internal Server Error, some more info");
379
- });
380
- });
381
- describe("wallet balances action", () => {
382
- it("should strip and transform balances correctly", async () => {
418
+ describe("user_idle_assets action", () => {
419
+ it("should return the response", async () => {
383
420
  mockedFetch.mockResolvedValue(mockFetchResult(200, {
384
421
  mainnet: [
385
422
  {
@@ -388,31 +425,31 @@ describe("VaultsfyiActionProvider", () => {
388
425
  symbol: "T1",
389
426
  balance: (10 ** 18).toString(),
390
427
  decimals: 18,
391
- somethingElse: "should be stripped",
392
428
  },
393
429
  ],
394
430
  }));
395
- const response = await provider.balances(mockWalletProvider);
431
+ const response = await provider.idleAssets(mockWalletProvider);
396
432
  expect(JSON.parse(response)).toStrictEqual({
397
433
  mainnet: [
398
434
  {
399
435
  address: "0x123",
400
436
  name: "token-1",
401
437
  symbol: "T1",
402
- balance: 1,
438
+ balance: (10 ** 18).toString(),
439
+ decimals: 18,
403
440
  },
404
441
  ],
405
442
  });
406
443
  });
407
444
  it("should return an error if the API request fails", async () => {
408
445
  mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
409
- expect(await provider.balances(mockWalletProvider)).toBe("Failed to fetch wallet balances: Internal Server Error, some more info");
446
+ expect(await provider.idleAssets(mockWalletProvider)).toBe("Failed to fetch idle assets: some more info");
410
447
  });
411
448
  });
412
449
  describe("wallet positions action", () => {
413
- it("should strip and transform positions correctly", async () => {
450
+ it("should transform the response correctly", async () => {
414
451
  mockedFetch.mockResolvedValue(mockFetchResult(200, {
415
- mainnet: [
452
+ data: [
416
453
  {
417
454
  vaultName: "vault-1",
418
455
  vaultAddress: "0x123",
@@ -426,31 +463,32 @@ describe("VaultsfyiActionProvider", () => {
426
463
  balanceLp: (10 ** 18).toString(),
427
464
  unclaimedUsd: "100",
428
465
  apy: {
429
- base: 100,
430
- rewards: 100,
431
- total: 100,
466
+ base: 0.1,
467
+ reward: 0.1,
468
+ total: 0.1,
432
469
  },
433
470
  },
434
471
  ],
435
472
  }));
436
473
  const response = await provider.positions(mockWalletProvider);
437
474
  expect(JSON.parse(response)).toStrictEqual({
438
- mainnet: [
475
+ data: [
439
476
  {
440
- name: "vault-1",
477
+ vaultName: "vault-1",
441
478
  vaultAddress: "0x123",
442
479
  asset: {
443
- address: "0x456",
480
+ assetAddress: "0x456",
444
481
  name: "token-1",
445
482
  symbol: "T1",
483
+ decimals: 18,
446
484
  },
447
- underlyingTokenBalance: 1,
448
- lpTokenBalance: 1,
449
- unclaimedRewards: true,
485
+ balanceNative: (10 ** 18).toString(),
486
+ balanceLp: (10 ** 18).toString(),
487
+ unclaimedUsd: "100",
450
488
  apy: {
451
- base: 1,
452
- rewards: 1,
453
- total: 1,
489
+ base: "10.00%",
490
+ reward: "10.00%",
491
+ total: "10.00%",
454
492
  },
455
493
  },
456
494
  ],
@@ -458,11 +496,11 @@ describe("VaultsfyiActionProvider", () => {
458
496
  });
459
497
  it("should return an error if the API request fails", async () => {
460
498
  mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
461
- expect(await provider.positions(mockWalletProvider)).toBe("Failed to fetch positions: Internal Server Error, some more info");
499
+ expect(await provider.positions(mockWalletProvider)).toBe("Failed to fetch positions: some more info");
462
500
  });
463
501
  });
464
- describe("vault_details action", () => {
465
- it("should transform vault details correctly", async () => {
502
+ describe("detailed_vault action", () => {
503
+ it("should return the response", async () => {
466
504
  const detailedVault = mockVault(1);
467
505
  mockedFetch.mockResolvedValue(mockFetchResult(200, detailedVault.apiResult));
468
506
  const args = {
@@ -473,15 +511,59 @@ describe("VaultsfyiActionProvider", () => {
473
511
  const parsedResult = JSON.parse(result);
474
512
  expect(parsedResult).toStrictEqual({
475
513
  ...detailedVault.transformedResult,
476
- description: detailedVault.apiResult.description,
477
- additionalIncentives: detailedVault.apiResult.additionalIncentives,
478
- rewards: [
514
+ });
515
+ });
516
+ it("should return an error if the API request fails", async () => {
517
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
518
+ const args = {
519
+ vaultAddress: "0x123456",
520
+ network: "mainnet",
521
+ };
522
+ expect(await provider.vaultDetails(mockWalletProvider, args)).toBe("Failed to fetch vault: some more info");
523
+ });
524
+ });
525
+ describe("vault_historical_data action", () => {
526
+ it("transforms the response correctly", async () => {
527
+ mockedFetch.mockResolvedValue(mockFetchResult(200, {
528
+ data: [
479
529
  {
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,
530
+ timestamp: 1704067200,
531
+ blockNumber: 12345678,
532
+ apy: {
533
+ base: 0.5,
534
+ reward: 0.3,
535
+ total: 0.8,
536
+ },
537
+ tvl: {
538
+ usd: 1000000,
539
+ native: 1000000,
540
+ },
541
+ },
542
+ ],
543
+ }));
544
+ const args = {
545
+ vaultAddress: "0x123456",
546
+ network: "mainnet",
547
+ fromDate: "2024-01-01T00:00:00Z",
548
+ toDate: "2024-01-02T00:00:00Z",
549
+ granularity: "1hour",
550
+ apyInterval: "1day",
551
+ };
552
+ const result = await provider.vaultHistoricalData(mockWalletProvider, args);
553
+ const parsedResult = JSON.parse(result);
554
+ expect(parsedResult).toEqual({
555
+ data: [
556
+ {
557
+ timestamp: "2024-01-01T00:00:00.000Z",
558
+ blockNumber: 12345678,
559
+ apy: {
560
+ base: "50.00%",
561
+ reward: "30.00%",
562
+ total: "80.00%",
563
+ },
564
+ tvl: {
565
+ usd: 1000000,
566
+ native: 1000000,
485
567
  },
486
568
  },
487
569
  ],
@@ -492,112 +574,223 @@ describe("VaultsfyiActionProvider", () => {
492
574
  const args = {
493
575
  vaultAddress: "0x123456",
494
576
  network: "mainnet",
577
+ fromDate: "2024-01-01T00:00:00Z",
578
+ toDate: "2024-01-02T00:00:00Z",
579
+ granularity: "1hour",
580
+ apyInterval: "1day",
495
581
  };
496
- expect(await provider.vaultDetails(mockWalletProvider, args)).toBe("Failed to fetch vault: Internal Server Error, some more info");
582
+ expect(await provider.vaultHistoricalData(mockWalletProvider, args)).toBe("Failed to fetch vault historical data: some more info");
497
583
  });
498
584
  });
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,
585
+ describe("rewards_context action", () => {
586
+ it("should return the response", async () => {
587
+ mockedFetch.mockResolvedValue(mockFetchResult(200, {
588
+ data: [
589
+ {
590
+ some: "data",
591
+ },
592
+ ],
593
+ }));
594
+ const response = await provider.rewardsContext(mockWalletProvider);
595
+ expect(JSON.parse(response)).toStrictEqual({ data: [{ some: "data" }] });
596
+ });
597
+ it("should return an error if the API request fails", async () => {
598
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
599
+ expect(await provider.rewardsContext(mockWalletProvider)).toBe("Failed to fetch rewards context: some more info");
600
+ });
601
+ });
602
+ describe("get_benchmark_apy action", () => {
603
+ it("should transform the response correctly", async () => {
604
+ mockedFetch.mockResolvedValue(mockFetchResult(200, {
505
605
  apy: {
506
- base: 500,
507
- rewards: 300,
508
- total: 800,
606
+ "1day": {
607
+ base: 0.5,
608
+ reward: 0.3,
609
+ total: 0.8,
610
+ },
611
+ "7day": {
612
+ base: 0.5,
613
+ reward: 0.3,
614
+ total: 0.8,
615
+ },
616
+ "30day": {
617
+ base: 0.5,
618
+ reward: 0.3,
619
+ total: 0.8,
620
+ },
509
621
  },
622
+ timestamp: 1704067200,
623
+ }));
624
+ const args = {
625
+ network: "mainnet",
626
+ benchmarkCode: "eth",
510
627
  };
511
- const mockTvlData = {
512
- timestamp: 1704067200, // Jan 1, 2024
513
- blockNumber: 12345678,
514
- tvlDetails: {
515
- tvlUsd: 1000000,
628
+ const result = await provider.benchmarkApy(mockWalletProvider, args);
629
+ const parsedResult = JSON.parse(result);
630
+ expect(parsedResult).toEqual({
631
+ apy: {
632
+ "1day": {
633
+ base: "50.00%",
634
+ reward: "30.00%",
635
+ total: "80.00%",
636
+ },
637
+ "7day": {
638
+ base: "50.00%",
639
+ reward: "30.00%",
640
+ total: "80.00%",
641
+ },
642
+ "30day": {
643
+ base: "50.00%",
644
+ reward: "30.00%",
645
+ total: "80.00%",
646
+ },
516
647
  },
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" }));
648
+ timestamp: new Date(1704067200 * 1000).toISOString(),
527
649
  });
650
+ });
651
+ it("should return an error if the API request fails", async () => {
652
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
528
653
  const args = {
529
- vaultAddress: "0x123456",
530
654
  network: "mainnet",
531
- date: "2024-01-01T00:00:00Z",
655
+ benchmarkCode: "eth",
532
656
  };
533
- const result = await provider.vaultHistoricalData(mockWalletProvider, args);
657
+ expect(await provider.benchmarkApy(mockWalletProvider, args)).toBe("Failed to fetch benchmark: some more info");
658
+ });
659
+ });
660
+ describe("historical_benchmark_apy action", () => {
661
+ it("should transform the response correctly", async () => {
662
+ mockedFetch.mockResolvedValue(mockFetchResult(200, {
663
+ data: [
664
+ {
665
+ timestamp: 1704067200,
666
+ apy: {
667
+ "1day": {
668
+ base: 0.5,
669
+ reward: 0.3,
670
+ total: 0.8,
671
+ },
672
+ "7day": {
673
+ base: 0.5,
674
+ reward: 0.3,
675
+ total: 0.8,
676
+ },
677
+ "30day": {
678
+ base: 0.5,
679
+ reward: 0.3,
680
+ total: 0.8,
681
+ },
682
+ },
683
+ },
684
+ ],
685
+ }));
686
+ const args = {
687
+ network: "mainnet",
688
+ benchmarkCode: "eth",
689
+ fromDate: "2024-01-01T00:00:00Z",
690
+ toDate: "2024-01-02T00:00:00Z",
691
+ page: 1,
692
+ perPage: 10,
693
+ };
694
+ const result = await provider.historicalBenchmarkApy(mockWalletProvider, args);
534
695
  const parsedResult = JSON.parse(result);
535
696
  expect(parsedResult).toEqual({
536
- apy: {
537
- apy: {
538
- base: 5,
539
- rewards: 3,
540
- total: 8,
697
+ data: [
698
+ {
699
+ timestamp: "2024-01-01T00:00:00.000Z",
700
+ apy: {
701
+ "1day": {
702
+ base: "50.00%",
703
+ reward: "30.00%",
704
+ total: "80.00%",
705
+ },
706
+ "7day": {
707
+ base: "50.00%",
708
+ reward: "30.00%",
709
+ total: "80.00%",
710
+ },
711
+ "30day": {
712
+ base: "50.00%",
713
+ reward: "30.00%",
714
+ total: "80.00%",
715
+ },
716
+ },
541
717
  },
542
- date: "2024-01-01T00:00:00.000Z",
543
- blockNumber: 12345678,
718
+ ],
719
+ });
720
+ });
721
+ it("should return an error if the API request fails", async () => {
722
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
723
+ const args = {
724
+ network: "mainnet",
725
+ benchmarkCode: "eth",
726
+ fromDate: "2024-01-01T00:00:00Z",
727
+ toDate: "2024-01-02T00:00:00Z",
728
+ page: 1,
729
+ perPage: 10,
730
+ };
731
+ expect(await provider.historicalBenchmarkApy(mockWalletProvider, args)).toBe("Failed to fetch historical benchmark: some more info");
732
+ });
733
+ });
734
+ describe("total_vault_returns action", () => {
735
+ it("should return the response", async () => {
736
+ mockedFetch.mockResolvedValue(mockFetchResult(200, {
737
+ data: {
738
+ totalReturns: 1000000,
544
739
  },
545
- tvl: {
546
- tvlInUsd: 1000000,
547
- date: "2024-01-01T00:00:00.000Z",
548
- blockNumber: 12345678,
740
+ }));
741
+ const args = {
742
+ vaultAddress: "0x123456",
743
+ network: "mainnet",
744
+ };
745
+ const result = await provider.totalVaultReturns(mockWalletProvider, args);
746
+ expect(JSON.parse(result)).toEqual({
747
+ data: {
748
+ totalReturns: 1000000,
549
749
  },
550
750
  });
551
751
  });
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
- });
752
+ it("should return an error if the API request fails", async () => {
753
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
570
754
  const args = {
571
755
  vaultAddress: "0x123456",
572
756
  network: "mainnet",
573
- date: "2024-01-01T00:00:00Z",
574
757
  };
575
- expect(await provider.vaultHistoricalData(mockWalletProvider, args)).toBe("Failed to fetch vault: Internal Server Error, Failed to get historical APY data");
758
+ expect(await provider.totalVaultReturns(mockWalletProvider, args)).toBe("Failed to fetch total vault returns: some more info");
576
759
  });
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, {
760
+ });
761
+ describe("user_events action", () => {
762
+ it("should transform the response correctly", async () => {
763
+ mockedFetch.mockResolvedValue(mockFetchResult(200, {
764
+ data: [
765
+ {
582
766
  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" }));
767
+ action: "deposit",
768
+ amount: 1000000,
769
+ },
770
+ ],
771
+ }));
772
+ const args = {
773
+ vaultAddress: "0x123456",
774
+ network: "mainnet",
775
+ };
776
+ const result = await provider.userEvents(mockWalletProvider, args);
777
+ expect(JSON.parse(result)).toEqual({
778
+ data: [
779
+ {
780
+ timestamp: "2024-01-01T00:00:00.000Z",
781
+ action: "deposit",
782
+ amount: 1000000,
783
+ },
784
+ ],
594
785
  });
786
+ });
787
+ it("should return an error if the API request fails", async () => {
788
+ mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
595
789
  const args = {
596
790
  vaultAddress: "0x123456",
597
791
  network: "mainnet",
598
- date: "2024-01-01T00:00:00Z",
599
792
  };
600
- expect(await provider.vaultHistoricalData(mockWalletProvider, args)).toBe("Failed to fetch vault: Internal Server Error, Failed to get historical TVL data");
793
+ expect(await provider.userEvents(mockWalletProvider, args)).toBe("Failed to fetch user events: some more info");
601
794
  });
602
795
  });
603
796
  });