@gearbox-protocol/sdk 9.15.3 → 9.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,517 @@
1
+ const balancerV3WrapperWorkerAbi = [
2
+ {
3
+ type: "constructor",
4
+ inputs: [{ name: "_router", type: "address", internalType: "address" }],
5
+ stateMutability: "nonpayable"
6
+ },
7
+ {
8
+ type: "function",
9
+ name: "buildEdges",
10
+ inputs: [
11
+ {
12
+ name: "graph",
13
+ type: "tuple",
14
+ internalType: "struct Graph",
15
+ components: [
16
+ {
17
+ name: "vertices",
18
+ type: "tuple[]",
19
+ internalType: "struct Vertex[]",
20
+ components: [
21
+ { name: "token", type: "address", internalType: "address" },
22
+ { name: "balance", type: "uint256", internalType: "uint256" },
23
+ {
24
+ name: "leftoverBalance",
25
+ type: "uint256",
26
+ internalType: "uint256"
27
+ },
28
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
29
+ {
30
+ name: "currentOptimalEdge",
31
+ type: "uint256",
32
+ internalType: "uint256"
33
+ }
34
+ ]
35
+ },
36
+ {
37
+ name: "edges",
38
+ type: "tuple[]",
39
+ internalType: "struct Edge[]",
40
+ components: [
41
+ { name: "id", type: "uint256", internalType: "uint256" },
42
+ { name: "tokenIn", type: "address", internalType: "address" },
43
+ { name: "tokenOut", type: "address", internalType: "address" },
44
+ { name: "adapter", type: "address", internalType: "address" },
45
+ { name: "worker", type: "address", internalType: "address" },
46
+ { name: "extraData", type: "bytes", internalType: "bytes" },
47
+ {
48
+ name: "amountInTotal",
49
+ type: "uint256",
50
+ internalType: "uint256"
51
+ },
52
+ {
53
+ name: "amountOutTotal",
54
+ type: "uint256",
55
+ internalType: "uint256"
56
+ },
57
+ {
58
+ name: "amountInCurrent",
59
+ type: "uint256",
60
+ internalType: "uint256"
61
+ },
62
+ {
63
+ name: "amountOutCurrent",
64
+ type: "uint256",
65
+ internalType: "uint256"
66
+ }
67
+ ]
68
+ }
69
+ ]
70
+ },
71
+ { name: "adapter", type: "address", internalType: "address" }
72
+ ],
73
+ outputs: [
74
+ {
75
+ name: "",
76
+ type: "tuple",
77
+ internalType: "struct Graph",
78
+ components: [
79
+ {
80
+ name: "vertices",
81
+ type: "tuple[]",
82
+ internalType: "struct Vertex[]",
83
+ components: [
84
+ { name: "token", type: "address", internalType: "address" },
85
+ { name: "balance", type: "uint256", internalType: "uint256" },
86
+ {
87
+ name: "leftoverBalance",
88
+ type: "uint256",
89
+ internalType: "uint256"
90
+ },
91
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
92
+ {
93
+ name: "currentOptimalEdge",
94
+ type: "uint256",
95
+ internalType: "uint256"
96
+ }
97
+ ]
98
+ },
99
+ {
100
+ name: "edges",
101
+ type: "tuple[]",
102
+ internalType: "struct Edge[]",
103
+ components: [
104
+ { name: "id", type: "uint256", internalType: "uint256" },
105
+ { name: "tokenIn", type: "address", internalType: "address" },
106
+ { name: "tokenOut", type: "address", internalType: "address" },
107
+ { name: "adapter", type: "address", internalType: "address" },
108
+ { name: "worker", type: "address", internalType: "address" },
109
+ { name: "extraData", type: "bytes", internalType: "bytes" },
110
+ {
111
+ name: "amountInTotal",
112
+ type: "uint256",
113
+ internalType: "uint256"
114
+ },
115
+ {
116
+ name: "amountOutTotal",
117
+ type: "uint256",
118
+ internalType: "uint256"
119
+ },
120
+ {
121
+ name: "amountInCurrent",
122
+ type: "uint256",
123
+ internalType: "uint256"
124
+ },
125
+ {
126
+ name: "amountOutCurrent",
127
+ type: "uint256",
128
+ internalType: "uint256"
129
+ }
130
+ ]
131
+ }
132
+ ]
133
+ }
134
+ ],
135
+ stateMutability: "view"
136
+ },
137
+ {
138
+ type: "function",
139
+ name: "contractType",
140
+ inputs: [],
141
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
142
+ stateMutability: "view"
143
+ },
144
+ {
145
+ type: "function",
146
+ name: "getEdgeAmountOutCurrent",
147
+ inputs: [
148
+ {
149
+ name: "edge",
150
+ type: "tuple",
151
+ internalType: "struct Edge",
152
+ components: [
153
+ { name: "id", type: "uint256", internalType: "uint256" },
154
+ { name: "tokenIn", type: "address", internalType: "address" },
155
+ { name: "tokenOut", type: "address", internalType: "address" },
156
+ { name: "adapter", type: "address", internalType: "address" },
157
+ { name: "worker", type: "address", internalType: "address" },
158
+ { name: "extraData", type: "bytes", internalType: "bytes" },
159
+ { name: "amountInTotal", type: "uint256", internalType: "uint256" },
160
+ { name: "amountOutTotal", type: "uint256", internalType: "uint256" },
161
+ { name: "amountInCurrent", type: "uint256", internalType: "uint256" },
162
+ {
163
+ name: "amountOutCurrent",
164
+ type: "uint256",
165
+ internalType: "uint256"
166
+ }
167
+ ]
168
+ }
169
+ ],
170
+ outputs: [
171
+ { name: "amountOutCurrent", type: "uint256", internalType: "uint256" }
172
+ ],
173
+ stateMutability: "pure"
174
+ },
175
+ {
176
+ type: "function",
177
+ name: "getMulticalls",
178
+ inputs: [
179
+ {
180
+ name: "edge",
181
+ type: "tuple",
182
+ internalType: "struct Edge",
183
+ components: [
184
+ { name: "id", type: "uint256", internalType: "uint256" },
185
+ { name: "tokenIn", type: "address", internalType: "address" },
186
+ { name: "tokenOut", type: "address", internalType: "address" },
187
+ { name: "adapter", type: "address", internalType: "address" },
188
+ { name: "worker", type: "address", internalType: "address" },
189
+ { name: "extraData", type: "bytes", internalType: "bytes" },
190
+ { name: "amountInTotal", type: "uint256", internalType: "uint256" },
191
+ { name: "amountOutTotal", type: "uint256", internalType: "uint256" },
192
+ { name: "amountInCurrent", type: "uint256", internalType: "uint256" },
193
+ {
194
+ name: "amountOutCurrent",
195
+ type: "uint256",
196
+ internalType: "uint256"
197
+ }
198
+ ]
199
+ },
200
+ { name: "currentBalance", type: "uint256", internalType: "uint256" }
201
+ ],
202
+ outputs: [
203
+ {
204
+ name: "calls",
205
+ type: "tuple[]",
206
+ internalType: "struct MultiCall[]",
207
+ components: [
208
+ { name: "target", type: "address", internalType: "address" },
209
+ { name: "callData", type: "bytes", internalType: "bytes" }
210
+ ]
211
+ }
212
+ ],
213
+ stateMutability: "pure"
214
+ },
215
+ {
216
+ type: "function",
217
+ name: "isNonLinear",
218
+ inputs: [],
219
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
220
+ stateMutability: "view"
221
+ },
222
+ {
223
+ type: "function",
224
+ name: "migrate",
225
+ inputs: [],
226
+ outputs: [],
227
+ stateMutability: "nonpayable"
228
+ },
229
+ {
230
+ type: "function",
231
+ name: "processClaims",
232
+ inputs: [
233
+ {
234
+ name: "",
235
+ type: "tuple",
236
+ internalType: "struct Edge",
237
+ components: [
238
+ { name: "id", type: "uint256", internalType: "uint256" },
239
+ { name: "tokenIn", type: "address", internalType: "address" },
240
+ { name: "tokenOut", type: "address", internalType: "address" },
241
+ { name: "adapter", type: "address", internalType: "address" },
242
+ { name: "worker", type: "address", internalType: "address" },
243
+ { name: "extraData", type: "bytes", internalType: "bytes" },
244
+ { name: "amountInTotal", type: "uint256", internalType: "uint256" },
245
+ { name: "amountOutTotal", type: "uint256", internalType: "uint256" },
246
+ { name: "amountInCurrent", type: "uint256", internalType: "uint256" },
247
+ {
248
+ name: "amountOutCurrent",
249
+ type: "uint256",
250
+ internalType: "uint256"
251
+ }
252
+ ]
253
+ },
254
+ {
255
+ name: "graph",
256
+ type: "tuple",
257
+ internalType: "struct Graph",
258
+ components: [
259
+ {
260
+ name: "vertices",
261
+ type: "tuple[]",
262
+ internalType: "struct Vertex[]",
263
+ components: [
264
+ { name: "token", type: "address", internalType: "address" },
265
+ { name: "balance", type: "uint256", internalType: "uint256" },
266
+ {
267
+ name: "leftoverBalance",
268
+ type: "uint256",
269
+ internalType: "uint256"
270
+ },
271
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
272
+ {
273
+ name: "currentOptimalEdge",
274
+ type: "uint256",
275
+ internalType: "uint256"
276
+ }
277
+ ]
278
+ },
279
+ {
280
+ name: "edges",
281
+ type: "tuple[]",
282
+ internalType: "struct Edge[]",
283
+ components: [
284
+ { name: "id", type: "uint256", internalType: "uint256" },
285
+ { name: "tokenIn", type: "address", internalType: "address" },
286
+ { name: "tokenOut", type: "address", internalType: "address" },
287
+ { name: "adapter", type: "address", internalType: "address" },
288
+ { name: "worker", type: "address", internalType: "address" },
289
+ { name: "extraData", type: "bytes", internalType: "bytes" },
290
+ {
291
+ name: "amountInTotal",
292
+ type: "uint256",
293
+ internalType: "uint256"
294
+ },
295
+ {
296
+ name: "amountOutTotal",
297
+ type: "uint256",
298
+ internalType: "uint256"
299
+ },
300
+ {
301
+ name: "amountInCurrent",
302
+ type: "uint256",
303
+ internalType: "uint256"
304
+ },
305
+ {
306
+ name: "amountOutCurrent",
307
+ type: "uint256",
308
+ internalType: "uint256"
309
+ }
310
+ ]
311
+ }
312
+ ]
313
+ },
314
+ { name: "", type: "address", internalType: "address" }
315
+ ],
316
+ outputs: [
317
+ {
318
+ name: "",
319
+ type: "tuple",
320
+ internalType: "struct Graph",
321
+ components: [
322
+ {
323
+ name: "vertices",
324
+ type: "tuple[]",
325
+ internalType: "struct Vertex[]",
326
+ components: [
327
+ { name: "token", type: "address", internalType: "address" },
328
+ { name: "balance", type: "uint256", internalType: "uint256" },
329
+ {
330
+ name: "leftoverBalance",
331
+ type: "uint256",
332
+ internalType: "uint256"
333
+ },
334
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
335
+ {
336
+ name: "currentOptimalEdge",
337
+ type: "uint256",
338
+ internalType: "uint256"
339
+ }
340
+ ]
341
+ },
342
+ {
343
+ name: "edges",
344
+ type: "tuple[]",
345
+ internalType: "struct Edge[]",
346
+ components: [
347
+ { name: "id", type: "uint256", internalType: "uint256" },
348
+ { name: "tokenIn", type: "address", internalType: "address" },
349
+ { name: "tokenOut", type: "address", internalType: "address" },
350
+ { name: "adapter", type: "address", internalType: "address" },
351
+ { name: "worker", type: "address", internalType: "address" },
352
+ { name: "extraData", type: "bytes", internalType: "bytes" },
353
+ {
354
+ name: "amountInTotal",
355
+ type: "uint256",
356
+ internalType: "uint256"
357
+ },
358
+ {
359
+ name: "amountOutTotal",
360
+ type: "uint256",
361
+ internalType: "uint256"
362
+ },
363
+ {
364
+ name: "amountInCurrent",
365
+ type: "uint256",
366
+ internalType: "uint256"
367
+ },
368
+ {
369
+ name: "amountOutCurrent",
370
+ type: "uint256",
371
+ internalType: "uint256"
372
+ }
373
+ ]
374
+ }
375
+ ]
376
+ },
377
+ {
378
+ name: "",
379
+ type: "tuple[]",
380
+ internalType: "struct MultiCall[]",
381
+ components: [
382
+ { name: "target", type: "address", internalType: "address" },
383
+ { name: "callData", type: "bytes", internalType: "bytes" }
384
+ ]
385
+ }
386
+ ],
387
+ stateMutability: "pure"
388
+ },
389
+ {
390
+ type: "function",
391
+ name: "router",
392
+ inputs: [],
393
+ outputs: [
394
+ { name: "", type: "address", internalType: "contract IGearboxRouter" }
395
+ ],
396
+ stateMutability: "view"
397
+ },
398
+ {
399
+ type: "function",
400
+ name: "trimSpecialVertex",
401
+ inputs: [
402
+ {
403
+ name: "",
404
+ type: "tuple",
405
+ internalType: "struct Edge",
406
+ components: [
407
+ { name: "id", type: "uint256", internalType: "uint256" },
408
+ { name: "tokenIn", type: "address", internalType: "address" },
409
+ { name: "tokenOut", type: "address", internalType: "address" },
410
+ { name: "adapter", type: "address", internalType: "address" },
411
+ { name: "worker", type: "address", internalType: "address" },
412
+ { name: "extraData", type: "bytes", internalType: "bytes" },
413
+ { name: "amountInTotal", type: "uint256", internalType: "uint256" },
414
+ { name: "amountOutTotal", type: "uint256", internalType: "uint256" },
415
+ { name: "amountInCurrent", type: "uint256", internalType: "uint256" },
416
+ {
417
+ name: "amountOutCurrent",
418
+ type: "uint256",
419
+ internalType: "uint256"
420
+ }
421
+ ]
422
+ },
423
+ {
424
+ name: "",
425
+ type: "tuple",
426
+ internalType: "struct Graph",
427
+ components: [
428
+ {
429
+ name: "vertices",
430
+ type: "tuple[]",
431
+ internalType: "struct Vertex[]",
432
+ components: [
433
+ { name: "token", type: "address", internalType: "address" },
434
+ { name: "balance", type: "uint256", internalType: "uint256" },
435
+ {
436
+ name: "leftoverBalance",
437
+ type: "uint256",
438
+ internalType: "uint256"
439
+ },
440
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
441
+ {
442
+ name: "currentOptimalEdge",
443
+ type: "uint256",
444
+ internalType: "uint256"
445
+ }
446
+ ]
447
+ },
448
+ {
449
+ name: "edges",
450
+ type: "tuple[]",
451
+ internalType: "struct Edge[]",
452
+ components: [
453
+ { name: "id", type: "uint256", internalType: "uint256" },
454
+ { name: "tokenIn", type: "address", internalType: "address" },
455
+ { name: "tokenOut", type: "address", internalType: "address" },
456
+ { name: "adapter", type: "address", internalType: "address" },
457
+ { name: "worker", type: "address", internalType: "address" },
458
+ { name: "extraData", type: "bytes", internalType: "bytes" },
459
+ {
460
+ name: "amountInTotal",
461
+ type: "uint256",
462
+ internalType: "uint256"
463
+ },
464
+ {
465
+ name: "amountOutTotal",
466
+ type: "uint256",
467
+ internalType: "uint256"
468
+ },
469
+ {
470
+ name: "amountInCurrent",
471
+ type: "uint256",
472
+ internalType: "uint256"
473
+ },
474
+ {
475
+ name: "amountOutCurrent",
476
+ type: "uint256",
477
+ internalType: "uint256"
478
+ }
479
+ ]
480
+ }
481
+ ]
482
+ },
483
+ { name: "", type: "address", internalType: "address" }
484
+ ],
485
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
486
+ stateMutability: "pure"
487
+ },
488
+ {
489
+ type: "function",
490
+ name: "updateRouter",
491
+ inputs: [{ name: "newRouter", type: "address", internalType: "address" }],
492
+ outputs: [],
493
+ stateMutability: "nonpayable"
494
+ },
495
+ {
496
+ type: "function",
497
+ name: "version",
498
+ inputs: [],
499
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
500
+ stateMutability: "view"
501
+ },
502
+ {
503
+ type: "event",
504
+ name: "NewRouter",
505
+ inputs: [
506
+ { name: "", type: "address", indexed: true, internalType: "address" }
507
+ ],
508
+ anonymous: false
509
+ },
510
+ { type: "error", name: "FutureRouterOnlyException", inputs: [] },
511
+ { type: "error", name: "MigrationErrorException", inputs: [] },
512
+ { type: "error", name: "RouterOnlyException", inputs: [] },
513
+ { type: "error", name: "RouterOwnerOnlyException", inputs: [] }
514
+ ];
515
+ export {
516
+ balancerV3WrapperWorkerAbi
517
+ };
@@ -1,8 +1,8 @@
1
- import { createPublicClient, parseEventLogs } from "viem";
1
+ import { parseEventLogs } from "viem";
2
2
  import { TokensMeta } from "./base/index.js";
3
3
  import {
4
4
  chains,
5
- createTransport,
5
+ createTransportClient,
6
6
  detectNetwork,
7
7
  Provider
8
8
  } from "./chain/index.js";
@@ -87,8 +87,7 @@ class GearboxSDK {
87
87
  gasLimit
88
88
  } = options;
89
89
  let { networkType, addressProvider, chainId } = options;
90
- const transport = createTransport(options);
91
- const attachClient = createPublicClient({ transport });
90
+ const [transport, attachClient] = createTransportClient(options);
92
91
  if (!networkType) {
93
92
  networkType = await detectNetwork(attachClient);
94
93
  }
@@ -1,13 +1,24 @@
1
1
  import { createPublicClient, defineChain, fallback, http } from "viem";
2
2
  import { AddressLabeller } from "../base/AddressLabeller.js";
3
3
  import { chains } from "./chains.js";
4
- function createTransport(opts) {
4
+ function createTransportClient(opts, chain) {
5
5
  const { timeout = 12e4, retryCount } = opts;
6
+ let transport;
7
+ if ("client" in opts) {
8
+ transport = () => ({
9
+ config: opts.client.transport.config,
10
+ request: opts.client.transport.request,
11
+ value: opts.client.transport.value
12
+ });
13
+ return [transport, opts.client];
14
+ }
6
15
  if ("transport" in opts) {
7
- return opts.transport;
16
+ transport = opts.transport;
17
+ } else {
18
+ const rpcs = opts.rpcURLs.map((url) => http(url, { timeout, retryCount }));
19
+ transport = rpcs.length > 1 ? fallback(rpcs) : rpcs[0];
8
20
  }
9
- const rpcs = opts.rpcURLs.map((url) => http(url, { timeout, retryCount }));
10
- return rpcs.length > 1 ? fallback(rpcs) : rpcs[0];
21
+ return [transport, createPublicClient({ transport, chain })];
11
22
  }
12
23
  class Provider {
13
24
  chainId;
@@ -24,11 +35,10 @@ class Provider {
24
35
  ...chains[networkType],
25
36
  id: chainId
26
37
  });
27
- this.#transport = createTransport(opts);
28
- this.#publicClient = createPublicClient({
29
- chain: this.chain,
30
- transport: this.#transport
31
- });
38
+ [this.#transport, this.#publicClient] = createTransportClient(
39
+ opts,
40
+ this.chain
41
+ );
32
42
  this.addressLabels = new AddressLabeller();
33
43
  }
34
44
  get transport() {
@@ -47,5 +57,5 @@ class Provider {
47
57
  }
48
58
  export {
49
59
  Provider,
50
- createTransport
60
+ createTransportClient
51
61
  };