@coinbase/agentkit 0.6.0 → 0.6.2
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.
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/vaultsfyi/api/actions.d.ts +41 -0
- package/dist/action-providers/vaultsfyi/api/actions.js +28 -0
- package/dist/action-providers/vaultsfyi/api/types.d.ts +34 -0
- package/dist/action-providers/vaultsfyi/api/types.js +2 -0
- package/dist/action-providers/vaultsfyi/api/vaults.d.ts +38 -0
- package/dist/action-providers/vaultsfyi/api/vaults.js +39 -0
- package/dist/action-providers/vaultsfyi/constants.d.ts +12 -0
- package/dist/action-providers/vaultsfyi/constants.js +15 -0
- package/dist/action-providers/vaultsfyi/index.d.ts +7 -0
- package/dist/action-providers/vaultsfyi/index.js +23 -0
- package/dist/action-providers/vaultsfyi/schemas.d.ts +94 -0
- package/dist/action-providers/vaultsfyi/schemas.js +49 -0
- package/dist/action-providers/vaultsfyi/utils.d.ts +34 -0
- package/dist/action-providers/vaultsfyi/utils.js +69 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +98 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +383 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +438 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -0
- package/dist/wallet-providers/privyShared.d.ts +3 -5
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +4 -1
- package/dist/wallet-providers/privySvmWalletProvider.test.js +1 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +6 -5
- package/dist/wallet-providers/privyWalletProvider.test.js +30 -0
- package/package.json +2 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vaultsfyiActionProvider_1 = require("./vaultsfyiActionProvider");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const mockFetchResult = (status, data) => {
|
|
6
|
+
return {
|
|
7
|
+
json: async () => data,
|
|
8
|
+
status,
|
|
9
|
+
ok: status >= 200 && status < 300,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const mockVault = (num) => ({
|
|
13
|
+
apiResult: {
|
|
14
|
+
address: `0x${num.toString(16).padStart(40, "0")}`,
|
|
15
|
+
network: `network-${num}`,
|
|
16
|
+
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,
|
|
23
|
+
},
|
|
24
|
+
tvlDetails: {
|
|
25
|
+
tvlUsd: num.toString(),
|
|
26
|
+
},
|
|
27
|
+
apy: {
|
|
28
|
+
base: {
|
|
29
|
+
"7day": num * 100,
|
|
30
|
+
},
|
|
31
|
+
rewards: {
|
|
32
|
+
"7day": num * 100,
|
|
33
|
+
},
|
|
34
|
+
total: {
|
|
35
|
+
"7day": num * 100,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
isTransactional: true,
|
|
39
|
+
},
|
|
40
|
+
transformedResult: {
|
|
41
|
+
name: `vault-${num}`,
|
|
42
|
+
address: `0x${num.toString(16).padStart(40, "0")}`,
|
|
43
|
+
network: `network-${num}`,
|
|
44
|
+
protocol: `protocol-${num}`,
|
|
45
|
+
tvlInUsd: num,
|
|
46
|
+
token: {
|
|
47
|
+
name: `token-${num}`,
|
|
48
|
+
address: `0x${num.toString(16).padStart(40, "0")}`,
|
|
49
|
+
symbol: `T${num}`,
|
|
50
|
+
},
|
|
51
|
+
apy: {
|
|
52
|
+
base: num,
|
|
53
|
+
rewards: num,
|
|
54
|
+
total: num,
|
|
55
|
+
},
|
|
56
|
+
link: `https://app.vaults.fyi/opportunity/network-${num}/0x${num.toString(16).padStart(40, "0")}`,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const MOCK_TX_HASH = "0xmock-hash";
|
|
60
|
+
describe("VaultsfyiActionProvider", () => {
|
|
61
|
+
const provider = new vaultsfyiActionProvider_1.VaultsfyiActionProvider({ apiKey: "test-api-key" });
|
|
62
|
+
let mockWalletProvider;
|
|
63
|
+
let mockedFetch;
|
|
64
|
+
const originalFetch = global.fetch;
|
|
65
|
+
beforeAll(() => {
|
|
66
|
+
global.fetch = mockedFetch = jest.fn();
|
|
67
|
+
});
|
|
68
|
+
afterAll(() => {
|
|
69
|
+
global.fetch = originalFetch;
|
|
70
|
+
});
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
mockWalletProvider = {
|
|
73
|
+
getAddress: jest.fn(),
|
|
74
|
+
getBalance: jest.fn(),
|
|
75
|
+
getName: jest.fn(),
|
|
76
|
+
getNetwork: jest.fn().mockReturnValue({
|
|
77
|
+
protocolFamily: "evm",
|
|
78
|
+
networkId: "test-network",
|
|
79
|
+
}),
|
|
80
|
+
nativeTransfer: jest.fn(),
|
|
81
|
+
readContract: jest.fn(() => Promise.resolve(18)), // token decimals
|
|
82
|
+
sendTransaction: jest.fn(() => Promise.resolve(MOCK_TX_HASH)),
|
|
83
|
+
waitForTransactionReceipt: jest.fn(),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
describe("network support", () => {
|
|
87
|
+
it("should support all vaultsfyi networks", () => {
|
|
88
|
+
Object.keys(constants_1.VAULTSFYI_SUPPORTED_CHAINS).forEach(network => {
|
|
89
|
+
expect(provider.supportsNetwork({
|
|
90
|
+
protocolFamily: "evm",
|
|
91
|
+
chainId: network,
|
|
92
|
+
})).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it("should not support other protocol families", () => {
|
|
96
|
+
expect(provider.supportsNetwork({
|
|
97
|
+
protocolFamily: "evm",
|
|
98
|
+
chainId: "some-other-chain",
|
|
99
|
+
})).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
it("should handle invalid network objects", () => {
|
|
102
|
+
expect(provider.supportsNetwork({})).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("vaults action", () => {
|
|
106
|
+
it("should return a transformed vault", async () => {
|
|
107
|
+
const mockedVault = mockVault(1);
|
|
108
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, { data: [mockedVault.apiResult] }));
|
|
109
|
+
const args = {};
|
|
110
|
+
const result = await provider.vaults(mockWalletProvider, args);
|
|
111
|
+
expect(JSON.parse(result)).toStrictEqual({
|
|
112
|
+
totalResults: 1,
|
|
113
|
+
nextPage: false,
|
|
114
|
+
results: [mockedVault.transformedResult],
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it("should filter by protocol", async () => {
|
|
118
|
+
const mockedVaults = [mockVault(1), mockVault(2)];
|
|
119
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
|
|
120
|
+
const args = { protocol: "protocol-1" };
|
|
121
|
+
const result = await provider.vaults(mockWalletProvider, args);
|
|
122
|
+
expect(JSON.parse(result)).toStrictEqual({
|
|
123
|
+
totalResults: 1,
|
|
124
|
+
nextPage: false,
|
|
125
|
+
results: [mockedVaults[0].transformedResult],
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
it("should take a limit", async () => {
|
|
129
|
+
const mockedVaults = [mockVault(1), mockVault(2)];
|
|
130
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
|
|
131
|
+
const args = { take: 1 };
|
|
132
|
+
const result = await provider.vaults(mockWalletProvider, args);
|
|
133
|
+
expect(JSON.parse(result)).toStrictEqual({
|
|
134
|
+
totalResults: 2,
|
|
135
|
+
nextPage: true,
|
|
136
|
+
results: [mockedVaults[0].transformedResult],
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("sorting", () => {
|
|
140
|
+
it("should sort by TVL", async () => {
|
|
141
|
+
const mockedVaults = [mockVault(2), mockVault(1)];
|
|
142
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
|
|
143
|
+
const args = { sort: { field: "tvl", direction: "asc" } };
|
|
144
|
+
const result = await provider.vaults(mockWalletProvider, args);
|
|
145
|
+
expect(JSON.parse(result)).toStrictEqual({
|
|
146
|
+
totalResults: 2,
|
|
147
|
+
nextPage: false,
|
|
148
|
+
results: [mockedVaults[1].transformedResult, mockedVaults[0].transformedResult],
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
it("should sort by APY", async () => {
|
|
152
|
+
const mockedVaults = [mockVault(2), mockVault(1)];
|
|
153
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
|
|
154
|
+
const args = { sort: { field: "apy", direction: "asc" } };
|
|
155
|
+
const result = await provider.vaults(mockWalletProvider, args);
|
|
156
|
+
expect(JSON.parse(result)).toStrictEqual({
|
|
157
|
+
totalResults: 2,
|
|
158
|
+
nextPage: false,
|
|
159
|
+
results: [mockedVaults[1].transformedResult, mockedVaults[0].transformedResult],
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
it("should sort by name by default", async () => {
|
|
163
|
+
const mockedVaults = [mockVault(2), mockVault(1)];
|
|
164
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, { data: mockedVaults.map(v => v.apiResult) }));
|
|
165
|
+
const args = {};
|
|
166
|
+
const result = await provider.vaults(mockWalletProvider, args);
|
|
167
|
+
expect(JSON.parse(result)).toStrictEqual({
|
|
168
|
+
totalResults: 2,
|
|
169
|
+
nextPage: false,
|
|
170
|
+
results: [mockedVaults[1].transformedResult, mockedVaults[0].transformedResult],
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it("should return an error if the API request fails", async () => {
|
|
175
|
+
mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
|
|
176
|
+
const args = {};
|
|
177
|
+
expect(await provider.vaults(mockWalletProvider, args)).toBe("Failed to fetch vaults: Internal Server Error, some more info");
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe("deposit action", () => {
|
|
181
|
+
it("should execute deposit", async () => {
|
|
182
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, {
|
|
183
|
+
currentActionIndex: 0,
|
|
184
|
+
actions: [
|
|
185
|
+
{
|
|
186
|
+
tx: {
|
|
187
|
+
to: "0x123",
|
|
188
|
+
data: "0x456",
|
|
189
|
+
value: "1",
|
|
190
|
+
chainId: 1,
|
|
191
|
+
},
|
|
192
|
+
description: "Deposit to vault",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
}));
|
|
196
|
+
const args = {
|
|
197
|
+
vaultAddress: "0x123",
|
|
198
|
+
assetAddress: "0x456",
|
|
199
|
+
network: "mainnet",
|
|
200
|
+
amount: 1,
|
|
201
|
+
};
|
|
202
|
+
const response = await provider.deposit(mockWalletProvider, args);
|
|
203
|
+
expect(response).toBe("Deposit successful");
|
|
204
|
+
expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
|
|
205
|
+
to: "0x123",
|
|
206
|
+
data: "0x456",
|
|
207
|
+
value: 1n,
|
|
208
|
+
chainId: 1,
|
|
209
|
+
});
|
|
210
|
+
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
|
|
211
|
+
});
|
|
212
|
+
it("should execute multiple transactions", async () => {
|
|
213
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, {
|
|
214
|
+
currentActionIndex: 0,
|
|
215
|
+
actions: [
|
|
216
|
+
{
|
|
217
|
+
tx: {
|
|
218
|
+
to: "0x123",
|
|
219
|
+
data: "0x456",
|
|
220
|
+
value: "1",
|
|
221
|
+
chainId: 1,
|
|
222
|
+
},
|
|
223
|
+
description: "Deposit to vault",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
tx: {
|
|
227
|
+
to: "0x789",
|
|
228
|
+
data: "0xabc",
|
|
229
|
+
value: "2",
|
|
230
|
+
chainId: 1,
|
|
231
|
+
},
|
|
232
|
+
description: "Deposit to vault",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
}));
|
|
236
|
+
const args = {
|
|
237
|
+
vaultAddress: "0x123",
|
|
238
|
+
assetAddress: "0x456",
|
|
239
|
+
network: "mainnet",
|
|
240
|
+
amount: 1,
|
|
241
|
+
};
|
|
242
|
+
const response = await provider.deposit(mockWalletProvider, args);
|
|
243
|
+
expect(response).toBe("Deposit successful");
|
|
244
|
+
expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
|
|
245
|
+
to: "0x123",
|
|
246
|
+
data: "0x456",
|
|
247
|
+
value: 1n,
|
|
248
|
+
chainId: 1,
|
|
249
|
+
});
|
|
250
|
+
expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
|
|
251
|
+
to: "0x789",
|
|
252
|
+
data: "0xabc",
|
|
253
|
+
value: 2n,
|
|
254
|
+
chainId: 1,
|
|
255
|
+
});
|
|
256
|
+
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
|
|
257
|
+
});
|
|
258
|
+
it("should return an error if the API request fails", async () => {
|
|
259
|
+
mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
|
|
260
|
+
const args = {
|
|
261
|
+
vaultAddress: "0x123",
|
|
262
|
+
assetAddress: "0x456",
|
|
263
|
+
network: "mainnet",
|
|
264
|
+
amount: 1,
|
|
265
|
+
};
|
|
266
|
+
expect(await provider.deposit(mockWalletProvider, args)).toBe("Failed to fetch deposit transactions: Internal Server Error, some more info");
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
describe("redeem action", () => {
|
|
270
|
+
it("should execute redeem", async () => {
|
|
271
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, {
|
|
272
|
+
currentActionIndex: 0,
|
|
273
|
+
actions: [
|
|
274
|
+
{
|
|
275
|
+
tx: {
|
|
276
|
+
to: "0x123",
|
|
277
|
+
data: "0x456",
|
|
278
|
+
value: "1",
|
|
279
|
+
chainId: 1,
|
|
280
|
+
},
|
|
281
|
+
description: "Redeem from vault",
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
}));
|
|
285
|
+
const args = {
|
|
286
|
+
vaultAddress: "0x123",
|
|
287
|
+
assetAddress: "0x456",
|
|
288
|
+
network: "mainnet",
|
|
289
|
+
amount: 1,
|
|
290
|
+
};
|
|
291
|
+
const response = await provider.redeem(mockWalletProvider, args);
|
|
292
|
+
expect(response).toBe("Redeem successful");
|
|
293
|
+
expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
|
|
294
|
+
to: "0x123",
|
|
295
|
+
data: "0x456",
|
|
296
|
+
value: 1n,
|
|
297
|
+
chainId: 1,
|
|
298
|
+
});
|
|
299
|
+
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
|
|
300
|
+
});
|
|
301
|
+
it("should return an error if the API request fails", async () => {
|
|
302
|
+
mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
|
|
303
|
+
const args = {
|
|
304
|
+
vaultAddress: "0x123",
|
|
305
|
+
assetAddress: "0x456",
|
|
306
|
+
network: "mainnet",
|
|
307
|
+
amount: 1,
|
|
308
|
+
};
|
|
309
|
+
expect(await provider.redeem(mockWalletProvider, args)).toBe("Failed to fetch redeem transactions: Internal Server Error, some more info");
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
describe("claim rewards action", () => {
|
|
313
|
+
it("should execute claim rewards", async () => {
|
|
314
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, {
|
|
315
|
+
currentActionIndex: 0,
|
|
316
|
+
actions: [
|
|
317
|
+
{
|
|
318
|
+
tx: {
|
|
319
|
+
to: "0x123",
|
|
320
|
+
data: "0x456",
|
|
321
|
+
value: "1",
|
|
322
|
+
chainId: 1,
|
|
323
|
+
},
|
|
324
|
+
description: "Claim rewards from vault",
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
}));
|
|
328
|
+
const args = {
|
|
329
|
+
vaultAddress: "0x123",
|
|
330
|
+
assetAddress: "0x456",
|
|
331
|
+
network: "mainnet",
|
|
332
|
+
amount: 1,
|
|
333
|
+
};
|
|
334
|
+
const response = await provider.claim(mockWalletProvider, args);
|
|
335
|
+
expect(response).toBe("Claim successful");
|
|
336
|
+
expect(mockWalletProvider.sendTransaction).toHaveBeenCalledWith({
|
|
337
|
+
to: "0x123",
|
|
338
|
+
data: "0x456",
|
|
339
|
+
value: 1n,
|
|
340
|
+
chainId: 1,
|
|
341
|
+
});
|
|
342
|
+
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
|
|
343
|
+
});
|
|
344
|
+
it("should return an error if the API request fails", async () => {
|
|
345
|
+
mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
|
|
346
|
+
const args = {
|
|
347
|
+
vaultAddress: "0x123",
|
|
348
|
+
assetAddress: "0x456",
|
|
349
|
+
network: "mainnet",
|
|
350
|
+
amount: 1,
|
|
351
|
+
};
|
|
352
|
+
expect(await provider.claim(mockWalletProvider, args)).toBe("Failed to fetch claim transactions: Internal Server Error, some more info");
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
describe("wallet balances action", () => {
|
|
356
|
+
it("should strip and transform balances correctly", async () => {
|
|
357
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, {
|
|
358
|
+
mainnet: [
|
|
359
|
+
{
|
|
360
|
+
address: "0x123",
|
|
361
|
+
name: "token-1",
|
|
362
|
+
symbol: "T1",
|
|
363
|
+
balance: (10 ** 18).toString(),
|
|
364
|
+
decimals: 18,
|
|
365
|
+
somethingElse: "should be stripped",
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
}));
|
|
369
|
+
const response = await provider.balances(mockWalletProvider);
|
|
370
|
+
expect(JSON.parse(response)).toStrictEqual({
|
|
371
|
+
mainnet: [
|
|
372
|
+
{
|
|
373
|
+
address: "0x123",
|
|
374
|
+
name: "token-1",
|
|
375
|
+
symbol: "T1",
|
|
376
|
+
balance: 1,
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
it("should return an error if the API request fails", async () => {
|
|
382
|
+
mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
|
|
383
|
+
expect(await provider.balances(mockWalletProvider)).toBe("Failed to fetch wallet balances: Internal Server Error, some more info");
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
describe("wallet positions action", () => {
|
|
387
|
+
it("should strip and transform positions correctly", async () => {
|
|
388
|
+
mockedFetch.mockResolvedValue(mockFetchResult(200, {
|
|
389
|
+
mainnet: [
|
|
390
|
+
{
|
|
391
|
+
vaultName: "vault-1",
|
|
392
|
+
vaultAddress: "0x123",
|
|
393
|
+
asset: {
|
|
394
|
+
assetAddress: "0x456",
|
|
395
|
+
name: "token-1",
|
|
396
|
+
symbol: "T1",
|
|
397
|
+
decimals: 18,
|
|
398
|
+
},
|
|
399
|
+
balanceNative: (10 ** 18).toString(),
|
|
400
|
+
balanceLp: (10 ** 18).toString(),
|
|
401
|
+
unclaimedUsd: "100",
|
|
402
|
+
apy: {
|
|
403
|
+
base: 100,
|
|
404
|
+
rewards: 100,
|
|
405
|
+
total: 100,
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
}));
|
|
410
|
+
const response = await provider.positions(mockWalletProvider);
|
|
411
|
+
expect(JSON.parse(response)).toStrictEqual({
|
|
412
|
+
mainnet: [
|
|
413
|
+
{
|
|
414
|
+
name: "vault-1",
|
|
415
|
+
vaultAddress: "0x123",
|
|
416
|
+
asset: {
|
|
417
|
+
address: "0x456",
|
|
418
|
+
name: "token-1",
|
|
419
|
+
symbol: "T1",
|
|
420
|
+
},
|
|
421
|
+
underlyingTokenBalance: 1,
|
|
422
|
+
lpTokenBalance: 1,
|
|
423
|
+
unclaimedRewards: true,
|
|
424
|
+
apy: {
|
|
425
|
+
base: 1,
|
|
426
|
+
rewards: 1,
|
|
427
|
+
total: 1,
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
],
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
it("should return an error if the API request fails", async () => {
|
|
434
|
+
mockedFetch.mockResolvedValue(mockFetchResult(500, { error: "Internal Server Error", message: "some more info" }));
|
|
435
|
+
expect(await provider.positions(mockWalletProvider)).toBe("Failed to fetch positions: Internal Server Error, some more info");
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|
|
@@ -12,6 +12,8 @@ export interface PrivyEvmDelegatedEmbeddedWalletConfig extends PrivyWalletConfig
|
|
|
12
12
|
networkId?: string;
|
|
13
13
|
/** The chain ID to connect to */
|
|
14
14
|
chainId?: string;
|
|
15
|
+
/** The wallet type to use */
|
|
16
|
+
walletType: "embedded";
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* A wallet provider that uses Privy's embedded wallets with delegation.
|
|
@@ -123,6 +123,7 @@ describe("PrivyEvmDelegatedEmbeddedWalletProvider", () => {
|
|
|
123
123
|
authorizationPrivateKey: "wallet-auth:test-auth-key",
|
|
124
124
|
walletId: MOCK_WALLET_ID,
|
|
125
125
|
networkId: "base-sepolia",
|
|
126
|
+
walletType: "embedded",
|
|
126
127
|
};
|
|
127
128
|
beforeEach(() => {
|
|
128
129
|
jest.clearAllMocks();
|
|
@@ -15,10 +15,6 @@ export interface PrivyWalletConfig {
|
|
|
15
15
|
authorizationPrivateKey?: string;
|
|
16
16
|
/** Optional authorization key ID for creating new wallets */
|
|
17
17
|
authorizationKeyId?: string;
|
|
18
|
-
/** The chain type to create the wallet on */
|
|
19
|
-
chainType?: "ethereum" | "solana";
|
|
20
|
-
/** The type of wallet to use */
|
|
21
|
-
walletType?: "server" | "embedded";
|
|
22
18
|
}
|
|
23
19
|
export type PrivyWalletExport = {
|
|
24
20
|
walletId: string;
|
|
@@ -45,5 +41,7 @@ export declare const createPrivyClient: (config: PrivyWalletConfig) => PrivyClie
|
|
|
45
41
|
* @param config - The configuration options for the Privy wallet
|
|
46
42
|
* @returns The created Privy wallet
|
|
47
43
|
*/
|
|
48
|
-
export declare function createPrivyWallet(config: PrivyWalletConfig
|
|
44
|
+
export declare function createPrivyWallet(config: PrivyWalletConfig & {
|
|
45
|
+
chainType: "ethereum" | "solana";
|
|
46
|
+
}): Promise<CreatePrivyWalletReturnType>;
|
|
49
47
|
export {};
|
|
@@ -10,6 +10,8 @@ export interface PrivySvmWalletConfig extends PrivyWalletConfig {
|
|
|
10
10
|
networkId?: string;
|
|
11
11
|
/** The connection to use for the wallet */
|
|
12
12
|
connection?: Connection;
|
|
13
|
+
/** The wallet type to use */
|
|
14
|
+
walletType: "server";
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* A wallet provider that uses Privy's server wallet API.
|
|
@@ -59,7 +59,10 @@ class PrivySvmWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
61
|
static async configureWithWallet(config) {
|
|
62
|
-
const { wallet, privy } = await (0, privyShared_1.createPrivyWallet)(
|
|
62
|
+
const { wallet, privy } = await (0, privyShared_1.createPrivyWallet)({
|
|
63
|
+
...config,
|
|
64
|
+
chainType: "solana",
|
|
65
|
+
});
|
|
63
66
|
const connection = config.connection ??
|
|
64
67
|
new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)(svm_1.SOLANA_CLUSTER_ID_BY_NETWORK_ID[config.networkId ?? ""]));
|
|
65
68
|
return new PrivySvmWalletProvider({
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { PrivyEvmWalletProvider, PrivyEvmWalletConfig } from "./privyEvmWalletProvider";
|
|
2
2
|
import { PrivySvmWalletProvider, PrivySvmWalletConfig } from "./privySvmWalletProvider";
|
|
3
3
|
import { PrivyEvmDelegatedEmbeddedWalletProvider, PrivyEvmDelegatedEmbeddedWalletConfig } from "./privyEvmDelegatedEmbeddedWalletProvider";
|
|
4
|
-
|
|
4
|
+
type PrivyWalletConfig = (PrivyEvmWalletConfig | PrivySvmWalletConfig | PrivyEvmDelegatedEmbeddedWalletConfig) & {
|
|
5
|
+
chainType?: "ethereum" | "solana";
|
|
6
|
+
walletType?: "server" | "embedded";
|
|
7
|
+
};
|
|
5
8
|
export type PrivyWalletProviderVariant<T> = T extends {
|
|
6
9
|
walletType: "embedded";
|
|
7
10
|
} ? PrivyEvmDelegatedEmbeddedWalletProvider : T extends {
|
|
@@ -41,8 +44,6 @@ export declare class PrivyWalletProvider {
|
|
|
41
44
|
* });
|
|
42
45
|
* ```
|
|
43
46
|
*/
|
|
44
|
-
static configureWithWallet<T extends PrivyWalletConfig>(config: T
|
|
45
|
-
chainType?: "ethereum" | "solana";
|
|
46
|
-
walletType?: "server" | "embedded";
|
|
47
|
-
}): Promise<PrivyWalletProviderVariant<T>>;
|
|
47
|
+
static configureWithWallet<T extends PrivyWalletConfig>(config: T): Promise<PrivyWalletProviderVariant<T>>;
|
|
48
48
|
}
|
|
49
|
+
export {};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const privyWalletProvider_1 = require("./privyWalletProvider");
|
|
4
4
|
const privyEvmWalletProvider_1 = require("./privyEvmWalletProvider");
|
|
5
5
|
const privySvmWalletProvider_1 = require("./privySvmWalletProvider");
|
|
6
|
+
const privyEvmDelegatedEmbeddedWalletProvider_1 = require("./privyEvmDelegatedEmbeddedWalletProvider");
|
|
6
7
|
global.fetch = jest.fn(() => Promise.resolve({
|
|
7
8
|
ok: true,
|
|
8
9
|
json: () => Promise.resolve({}),
|
|
@@ -34,6 +35,18 @@ jest.mock("./privySvmWalletProvider", () => ({
|
|
|
34
35
|
}),
|
|
35
36
|
},
|
|
36
37
|
}));
|
|
38
|
+
jest.mock("./privyEvmDelegatedEmbeddedWalletProvider", () => ({
|
|
39
|
+
PrivyEvmDelegatedEmbeddedWalletProvider: {
|
|
40
|
+
configureWithWallet: jest.fn().mockResolvedValue({
|
|
41
|
+
getAddress: jest.fn().mockReturnValue("0x324335Cc6634C0532925a3b844Bc454e4438d22g"),
|
|
42
|
+
getNetwork: jest.fn().mockReturnValue({
|
|
43
|
+
protocolFamily: "evm",
|
|
44
|
+
chainId: "1",
|
|
45
|
+
networkId: "mainnet",
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
37
50
|
describe("PrivyWalletProvider", () => {
|
|
38
51
|
const MOCK_EVM_CONFIG = {
|
|
39
52
|
appId: "test-app-id",
|
|
@@ -44,6 +57,12 @@ describe("PrivyWalletProvider", () => {
|
|
|
44
57
|
appSecret: "test-app-secret",
|
|
45
58
|
chainType: "solana",
|
|
46
59
|
};
|
|
60
|
+
const MOCK_EVM_EMBEDDED_WALLET_CONFIG = {
|
|
61
|
+
...MOCK_EVM_CONFIG,
|
|
62
|
+
authorizationPrivateKey: "test-auth-key",
|
|
63
|
+
walletId: "test-wallet-id",
|
|
64
|
+
walletType: "embedded",
|
|
65
|
+
};
|
|
47
66
|
beforeEach(() => {
|
|
48
67
|
jest.clearAllMocks();
|
|
49
68
|
});
|
|
@@ -51,6 +70,7 @@ describe("PrivyWalletProvider", () => {
|
|
|
51
70
|
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(MOCK_EVM_CONFIG);
|
|
52
71
|
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(MOCK_EVM_CONFIG);
|
|
53
72
|
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
73
|
+
expect(privyEvmDelegatedEmbeddedWalletProvider_1.PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
54
74
|
expect(provider.getAddress()).toBe("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");
|
|
55
75
|
expect(provider.getNetwork().protocolFamily).toBe("evm");
|
|
56
76
|
});
|
|
@@ -62,6 +82,7 @@ describe("PrivyWalletProvider", () => {
|
|
|
62
82
|
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(config);
|
|
63
83
|
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(config);
|
|
64
84
|
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
85
|
+
expect(privyEvmDelegatedEmbeddedWalletProvider_1.PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
65
86
|
expect(provider.getAddress()).toBe("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");
|
|
66
87
|
expect(provider.getNetwork().protocolFamily).toBe("evm");
|
|
67
88
|
});
|
|
@@ -69,9 +90,18 @@ describe("PrivyWalletProvider", () => {
|
|
|
69
90
|
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(MOCK_SVM_CONFIG);
|
|
70
91
|
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(MOCK_SVM_CONFIG);
|
|
71
92
|
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
93
|
+
expect(privyEvmDelegatedEmbeddedWalletProvider_1.PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
72
94
|
expect(provider.getAddress()).toBe("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM");
|
|
73
95
|
expect(provider.getNetwork().protocolFamily).toBe("solana");
|
|
74
96
|
});
|
|
97
|
+
it("should create an EVM embedded wallet provider when embedded is specified", async () => {
|
|
98
|
+
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(MOCK_EVM_EMBEDDED_WALLET_CONFIG);
|
|
99
|
+
expect(privyEvmDelegatedEmbeddedWalletProvider_1.PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet).toHaveBeenCalledWith(MOCK_EVM_EMBEDDED_WALLET_CONFIG);
|
|
100
|
+
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
101
|
+
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
102
|
+
expect(provider.getAddress()).toBe("0x324335Cc6634C0532925a3b844Bc454e4438d22g");
|
|
103
|
+
expect(provider.getNetwork().protocolFamily).toBe("evm");
|
|
104
|
+
});
|
|
75
105
|
it("should pass through all config properties", async () => {
|
|
76
106
|
const fullConfig = {
|
|
77
107
|
...MOCK_EVM_CONFIG,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@coinbase/agentkit",
|
|
3
3
|
"description": "Coinbase AgentKit core primitives",
|
|
4
4
|
"repository": "https://github.com/coinbase/agentkit",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.2",
|
|
6
6
|
"author": "Coinbase Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@alloralabs/allora-sdk": "^0.1.0",
|
|
27
27
|
"@coinbase/coinbase-sdk": "^0.20.0",
|
|
28
28
|
"@jup-ag/api": "^6.0.39",
|
|
29
|
+
"@privy-io/public-api": "^2.18.5",
|
|
29
30
|
"@privy-io/server-auth": "^1.18.4",
|
|
30
31
|
"@solana/spl-token": "^0.4.12",
|
|
31
32
|
"@solana/web3.js": "^1.98.0",
|