@instadapp/avocado-base 0.0.1 → 0.0.3
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/abi/avoFactoryProxy.json +109 -0
- package/abi/balanceResolver.json +110 -0
- package/abi/erc20.json +350 -0
- package/abi/forwarder.json +331 -0
- package/abi/gaslessWallet.json +289 -0
- package/app.vue +20 -0
- package/contracts/AvoFactoryProxy.ts +302 -0
- package/contracts/BalanceResolver.ts +321 -0
- package/contracts/Erc20.ts +526 -0
- package/contracts/Forwarder.ts +790 -0
- package/contracts/GaslessWallet.ts +660 -0
- package/contracts/common.ts +46 -0
- package/contracts/factories/AvoFactoryProxy__factory.ts +181 -0
- package/contracts/factories/BalanceResolver__factory.ts +212 -0
- package/contracts/factories/Erc20__factory.ts +368 -0
- package/contracts/factories/Forwarder__factory.ts +656 -0
- package/contracts/factories/GaslessWallet__factory.ts +499 -0
- package/contracts/factories/index.ts +8 -0
- package/contracts/index.ts +14 -0
- package/nuxt.config.ts +2 -2
- package/package.json +11 -4
- package/utils/bignumber.ts +31 -0
- package/utils/formatter.ts +51 -0
- package/utils/helper.ts +54 -0
- package/utils/metadata.ts +326 -0
- package/utils/network.ts +96 -20
- package/utils/utils.d.ts +72 -1
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
|
|
5
|
+
import { Contract, Signer, utils } from "ethers";
|
|
6
|
+
import type { Provider } from "@ethersproject/providers";
|
|
7
|
+
import type { GaslessWallet, GaslessWalletInterface } from "../GaslessWallet";
|
|
8
|
+
|
|
9
|
+
const _abi = [
|
|
10
|
+
{
|
|
11
|
+
inputs: [
|
|
12
|
+
{
|
|
13
|
+
internalType: "contract IGSWVersionsRegistry",
|
|
14
|
+
name: "gswVersionsRegistry_",
|
|
15
|
+
type: "address",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
internalType: "address",
|
|
19
|
+
name: "gswForwarder_",
|
|
20
|
+
type: "address",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
stateMutability: "nonpayable",
|
|
24
|
+
type: "constructor",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
inputs: [],
|
|
28
|
+
name: "GaslessSmartWallet__Expired",
|
|
29
|
+
type: "error",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
inputs: [],
|
|
33
|
+
name: "GaslessSmartWallet__InvalidParams",
|
|
34
|
+
type: "error",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
inputs: [],
|
|
38
|
+
name: "GaslessSmartWallet__InvalidSignature",
|
|
39
|
+
type: "error",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
inputs: [],
|
|
43
|
+
name: "GaslessSmartWallet__Unauthorized",
|
|
44
|
+
type: "error",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
inputs: [],
|
|
48
|
+
name: "SelfUpgradeable__Unauthorized",
|
|
49
|
+
type: "error",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
anonymous: false,
|
|
53
|
+
inputs: [
|
|
54
|
+
{
|
|
55
|
+
indexed: true,
|
|
56
|
+
internalType: "address",
|
|
57
|
+
name: "source",
|
|
58
|
+
type: "address",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
indexed: true,
|
|
62
|
+
internalType: "address",
|
|
63
|
+
name: "caller",
|
|
64
|
+
type: "address",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
indexed: false,
|
|
68
|
+
internalType: "bytes",
|
|
69
|
+
name: "metadata",
|
|
70
|
+
type: "bytes",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
name: "CastExecuted",
|
|
74
|
+
type: "event",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
anonymous: false,
|
|
78
|
+
inputs: [
|
|
79
|
+
{
|
|
80
|
+
indexed: true,
|
|
81
|
+
internalType: "address",
|
|
82
|
+
name: "source",
|
|
83
|
+
type: "address",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
indexed: true,
|
|
87
|
+
internalType: "address",
|
|
88
|
+
name: "caller",
|
|
89
|
+
type: "address",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
indexed: false,
|
|
93
|
+
internalType: "string",
|
|
94
|
+
name: "reason",
|
|
95
|
+
type: "string",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
indexed: false,
|
|
99
|
+
internalType: "bytes",
|
|
100
|
+
name: "metadata",
|
|
101
|
+
type: "bytes",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
name: "CastFailed",
|
|
105
|
+
type: "event",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
anonymous: false,
|
|
109
|
+
inputs: [
|
|
110
|
+
{
|
|
111
|
+
indexed: false,
|
|
112
|
+
internalType: "uint8",
|
|
113
|
+
name: "version",
|
|
114
|
+
type: "uint8",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
name: "Initialized",
|
|
118
|
+
type: "event",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
anonymous: false,
|
|
122
|
+
inputs: [
|
|
123
|
+
{
|
|
124
|
+
indexed: true,
|
|
125
|
+
internalType: "address",
|
|
126
|
+
name: "gswImpl",
|
|
127
|
+
type: "address",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
name: "Upgraded",
|
|
131
|
+
type: "event",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
inputs: [],
|
|
135
|
+
name: "ACTION_TYPE_HASH",
|
|
136
|
+
outputs: [
|
|
137
|
+
{
|
|
138
|
+
internalType: "bytes32",
|
|
139
|
+
name: "",
|
|
140
|
+
type: "bytes32",
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
stateMutability: "view",
|
|
144
|
+
type: "function",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
inputs: [],
|
|
148
|
+
name: "CAST_TYPE_HASH",
|
|
149
|
+
outputs: [
|
|
150
|
+
{
|
|
151
|
+
internalType: "bytes32",
|
|
152
|
+
name: "",
|
|
153
|
+
type: "bytes32",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
stateMutability: "view",
|
|
157
|
+
type: "function",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
inputs: [],
|
|
161
|
+
name: "DEFAULT_CHAIN_ID",
|
|
162
|
+
outputs: [
|
|
163
|
+
{
|
|
164
|
+
internalType: "uint256",
|
|
165
|
+
name: "",
|
|
166
|
+
type: "uint256",
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
stateMutability: "view",
|
|
170
|
+
type: "function",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
inputs: [],
|
|
174
|
+
name: "DOMAIN_SEPARATOR_NAME",
|
|
175
|
+
outputs: [
|
|
176
|
+
{
|
|
177
|
+
internalType: "string",
|
|
178
|
+
name: "",
|
|
179
|
+
type: "string",
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
stateMutability: "view",
|
|
183
|
+
type: "function",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
inputs: [],
|
|
187
|
+
name: "DOMAIN_SEPARATOR_VERSION",
|
|
188
|
+
outputs: [
|
|
189
|
+
{
|
|
190
|
+
internalType: "string",
|
|
191
|
+
name: "",
|
|
192
|
+
type: "string",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
stateMutability: "view",
|
|
196
|
+
type: "function",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
inputs: [],
|
|
200
|
+
name: "TYPE_HASH",
|
|
201
|
+
outputs: [
|
|
202
|
+
{
|
|
203
|
+
internalType: "bytes32",
|
|
204
|
+
name: "",
|
|
205
|
+
type: "bytes32",
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
stateMutability: "view",
|
|
209
|
+
type: "function",
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
inputs: [
|
|
213
|
+
{
|
|
214
|
+
components: [
|
|
215
|
+
{
|
|
216
|
+
internalType: "address",
|
|
217
|
+
name: "target",
|
|
218
|
+
type: "address",
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
internalType: "bytes",
|
|
222
|
+
name: "data",
|
|
223
|
+
type: "bytes",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
internalType: "uint256",
|
|
227
|
+
name: "value",
|
|
228
|
+
type: "uint256",
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
internalType: "struct IGaslessSmartWallet.Action[]",
|
|
232
|
+
name: "actions_",
|
|
233
|
+
type: "tuple[]",
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
name: "_callTargets",
|
|
237
|
+
outputs: [],
|
|
238
|
+
stateMutability: "payable",
|
|
239
|
+
type: "function",
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
inputs: [
|
|
243
|
+
{
|
|
244
|
+
components: [
|
|
245
|
+
{
|
|
246
|
+
internalType: "address",
|
|
247
|
+
name: "target",
|
|
248
|
+
type: "address",
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
internalType: "bytes",
|
|
252
|
+
name: "data",
|
|
253
|
+
type: "bytes",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
internalType: "uint256",
|
|
257
|
+
name: "value",
|
|
258
|
+
type: "uint256",
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
internalType: "struct IGaslessSmartWallet.Action[]",
|
|
262
|
+
name: "actions_",
|
|
263
|
+
type: "tuple[]",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
internalType: "uint256",
|
|
267
|
+
name: "validUntil_",
|
|
268
|
+
type: "uint256",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
internalType: "uint256",
|
|
272
|
+
name: "gas_",
|
|
273
|
+
type: "uint256",
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
internalType: "address",
|
|
277
|
+
name: "source_",
|
|
278
|
+
type: "address",
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
internalType: "bytes",
|
|
282
|
+
name: "metadata_",
|
|
283
|
+
type: "bytes",
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
internalType: "bytes",
|
|
287
|
+
name: "signature_",
|
|
288
|
+
type: "bytes",
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
name: "cast",
|
|
292
|
+
outputs: [
|
|
293
|
+
{
|
|
294
|
+
internalType: "bool",
|
|
295
|
+
name: "success_",
|
|
296
|
+
type: "bool",
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
internalType: "string",
|
|
300
|
+
name: "revertReason_",
|
|
301
|
+
type: "string",
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
stateMutability: "payable",
|
|
305
|
+
type: "function",
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
inputs: [],
|
|
309
|
+
name: "domainSeparatorV4",
|
|
310
|
+
outputs: [
|
|
311
|
+
{
|
|
312
|
+
internalType: "bytes32",
|
|
313
|
+
name: "",
|
|
314
|
+
type: "bytes32",
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
stateMutability: "view",
|
|
318
|
+
type: "function",
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
inputs: [],
|
|
322
|
+
name: "gswForwarder",
|
|
323
|
+
outputs: [
|
|
324
|
+
{
|
|
325
|
+
internalType: "address",
|
|
326
|
+
name: "",
|
|
327
|
+
type: "address",
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
stateMutability: "view",
|
|
331
|
+
type: "function",
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
inputs: [],
|
|
335
|
+
name: "gswNonce",
|
|
336
|
+
outputs: [
|
|
337
|
+
{
|
|
338
|
+
internalType: "uint256",
|
|
339
|
+
name: "",
|
|
340
|
+
type: "uint256",
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
stateMutability: "view",
|
|
344
|
+
type: "function",
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
inputs: [],
|
|
348
|
+
name: "gswVersionsRegistry",
|
|
349
|
+
outputs: [
|
|
350
|
+
{
|
|
351
|
+
internalType: "contract IGSWVersionsRegistry",
|
|
352
|
+
name: "",
|
|
353
|
+
type: "address",
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
stateMutability: "view",
|
|
357
|
+
type: "function",
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
inputs: [
|
|
361
|
+
{
|
|
362
|
+
internalType: "address",
|
|
363
|
+
name: "owner_",
|
|
364
|
+
type: "address",
|
|
365
|
+
},
|
|
366
|
+
],
|
|
367
|
+
name: "initialize",
|
|
368
|
+
outputs: [],
|
|
369
|
+
stateMutability: "nonpayable",
|
|
370
|
+
type: "function",
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
inputs: [],
|
|
374
|
+
name: "owner",
|
|
375
|
+
outputs: [
|
|
376
|
+
{
|
|
377
|
+
internalType: "address",
|
|
378
|
+
name: "",
|
|
379
|
+
type: "address",
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
stateMutability: "view",
|
|
383
|
+
type: "function",
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
inputs: [
|
|
387
|
+
{
|
|
388
|
+
internalType: "address",
|
|
389
|
+
name: "gswImpl_",
|
|
390
|
+
type: "address",
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
name: "upgradeTo",
|
|
394
|
+
outputs: [],
|
|
395
|
+
stateMutability: "nonpayable",
|
|
396
|
+
type: "function",
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
inputs: [
|
|
400
|
+
{
|
|
401
|
+
internalType: "address",
|
|
402
|
+
name: "gswImpl_",
|
|
403
|
+
type: "address",
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
internalType: "bytes",
|
|
407
|
+
name: "data_",
|
|
408
|
+
type: "bytes",
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
internalType: "bool",
|
|
412
|
+
name: "forceCall_",
|
|
413
|
+
type: "bool",
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
name: "upgradeToAndCall",
|
|
417
|
+
outputs: [],
|
|
418
|
+
stateMutability: "payable",
|
|
419
|
+
type: "function",
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
inputs: [
|
|
423
|
+
{
|
|
424
|
+
components: [
|
|
425
|
+
{
|
|
426
|
+
internalType: "address",
|
|
427
|
+
name: "target",
|
|
428
|
+
type: "address",
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
internalType: "bytes",
|
|
432
|
+
name: "data",
|
|
433
|
+
type: "bytes",
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
internalType: "uint256",
|
|
437
|
+
name: "value",
|
|
438
|
+
type: "uint256",
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
internalType: "struct IGaslessSmartWallet.Action[]",
|
|
442
|
+
name: "actions_",
|
|
443
|
+
type: "tuple[]",
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
internalType: "uint256",
|
|
447
|
+
name: "validUntil_",
|
|
448
|
+
type: "uint256",
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
internalType: "uint256",
|
|
452
|
+
name: "gas_",
|
|
453
|
+
type: "uint256",
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
internalType: "address",
|
|
457
|
+
name: "source_",
|
|
458
|
+
type: "address",
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
internalType: "bytes",
|
|
462
|
+
name: "metadata_",
|
|
463
|
+
type: "bytes",
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
internalType: "bytes",
|
|
467
|
+
name: "signature_",
|
|
468
|
+
type: "bytes",
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
name: "verify",
|
|
472
|
+
outputs: [
|
|
473
|
+
{
|
|
474
|
+
internalType: "bool",
|
|
475
|
+
name: "",
|
|
476
|
+
type: "bool",
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
stateMutability: "view",
|
|
480
|
+
type: "function",
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
stateMutability: "payable",
|
|
484
|
+
type: "receive",
|
|
485
|
+
},
|
|
486
|
+
] as const;
|
|
487
|
+
|
|
488
|
+
export class GaslessWallet__factory {
|
|
489
|
+
static readonly abi = _abi;
|
|
490
|
+
static createInterface(): GaslessWalletInterface {
|
|
491
|
+
return new utils.Interface(_abi) as GaslessWalletInterface;
|
|
492
|
+
}
|
|
493
|
+
static connect(
|
|
494
|
+
address: string,
|
|
495
|
+
signerOrProvider: Signer | Provider
|
|
496
|
+
): GaslessWallet {
|
|
497
|
+
return new Contract(address, _abi, signerOrProvider) as GaslessWallet;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
export { AvoFactoryProxy__factory } from "./AvoFactoryProxy__factory";
|
|
5
|
+
export { BalanceResolver__factory } from "./BalanceResolver__factory";
|
|
6
|
+
export { Erc20__factory } from "./Erc20__factory";
|
|
7
|
+
export { Forwarder__factory } from "./Forwarder__factory";
|
|
8
|
+
export { GaslessWallet__factory } from "./GaslessWallet__factory";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
export type { AvoFactoryProxy } from "./AvoFactoryProxy";
|
|
5
|
+
export type { BalanceResolver } from "./BalanceResolver";
|
|
6
|
+
export type { Erc20 } from "./Erc20";
|
|
7
|
+
export type { Forwarder } from "./Forwarder";
|
|
8
|
+
export type { GaslessWallet } from "./GaslessWallet";
|
|
9
|
+
export * as factories from "./factories";
|
|
10
|
+
export { AvoFactoryProxy__factory } from "./factories/AvoFactoryProxy__factory";
|
|
11
|
+
export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
|
|
12
|
+
export { Erc20__factory } from "./factories/Erc20__factory";
|
|
13
|
+
export { Forwarder__factory } from "./factories/Forwarder__factory";
|
|
14
|
+
export { GaslessWallet__factory } from "./factories/GaslessWallet__factory";
|
package/nuxt.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instadapp/avocado-base",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
|
+
"types": "global.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "nuxt build",
|
|
8
9
|
"dev": "nuxt dev",
|
|
9
10
|
"generate": "nuxt generate",
|
|
10
|
-
"preview": "nuxt preview"
|
|
11
|
+
"preview": "nuxt preview",
|
|
12
|
+
"generate:contracts": "rimraf contracts && typechain --target=ethers-v5 'abi/*.json' --out-dir 'contracts'"
|
|
11
13
|
},
|
|
12
14
|
"devDependencies": {
|
|
15
|
+
"@instadapp/avocado": "^0.1.10",
|
|
16
|
+
"@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
|
|
17
|
+
"@nuxtjs/tailwindcss": "^6.6.5",
|
|
18
|
+
"@typechain/ethers-v5": "^10.2.0",
|
|
13
19
|
"nuxt": "^3.3.3",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
20
|
+
"rimraf": "^3.0.2",
|
|
21
|
+
"typechain": "^8.1.1"
|
|
16
22
|
},
|
|
17
23
|
"dependencies": {
|
|
24
|
+
"bignumber.js": "^9.1.1",
|
|
18
25
|
"ethers": "^5.7.2"
|
|
19
26
|
}
|
|
20
27
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { BigNumber as BN } from "ethers";
|
|
3
|
+
|
|
4
|
+
export const toBN = (value: BigNumber.Value | BN) =>
|
|
5
|
+
new BigNumber(BN.isBigNumber(value) ? value.toString() : value);
|
|
6
|
+
export const isZero = (value: BigNumber.Value | BN) => toBN(value).isZero();
|
|
7
|
+
export const times = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
8
|
+
toBN(a).times(toBN(b));
|
|
9
|
+
export const minus = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
10
|
+
toBN(a).minus(toBN(b));
|
|
11
|
+
export const plus = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
12
|
+
toBN(a).plus(toBN(b));
|
|
13
|
+
export const lte = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
14
|
+
toBN(a).lte(toBN(b));
|
|
15
|
+
export const gte = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
16
|
+
toBN(a).gte(toBN(b));
|
|
17
|
+
export const div = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
18
|
+
toBN(a).div(toBN(b));
|
|
19
|
+
export const lt = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
20
|
+
toBN(a).lt(toBN(b));
|
|
21
|
+
export const gt = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
22
|
+
toBN(a).gt(toBN(b));
|
|
23
|
+
export const ensureValue = (value: any) => {
|
|
24
|
+
if (!value) return toBN("0");
|
|
25
|
+
if (toBN(value).isNaN()) return toBN("0");
|
|
26
|
+
|
|
27
|
+
return toBN(value);
|
|
28
|
+
};
|
|
29
|
+
export const max = (...args: BigNumber.Value[]) => {
|
|
30
|
+
return BigNumber.max(...args);
|
|
31
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function formatPercent(
|
|
2
|
+
value: number,
|
|
3
|
+
fractionDigits = 2,
|
|
4
|
+
maxValue = null
|
|
5
|
+
) {
|
|
6
|
+
if (isZero(value)) return "0.00%";
|
|
7
|
+
|
|
8
|
+
if (maxValue && gt(times(value, "100"), maxValue)) return `>${maxValue}%`;
|
|
9
|
+
|
|
10
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
11
|
+
style: "percent",
|
|
12
|
+
minimumFractionDigits: fractionDigits,
|
|
13
|
+
maximumFractionDigits: fractionDigits,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return formatter.format(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function shortenHash(hash: string, length: number = 4) {
|
|
20
|
+
if (!hash) return;
|
|
21
|
+
if (hash.length < 12) return hash;
|
|
22
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
|
23
|
+
const shortened =
|
|
24
|
+
hash.substr(0, beginningChars) + "..." + hash.substr(-length);
|
|
25
|
+
return shortened;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function formatUsd(value: any, fractionDigits = 2) {
|
|
29
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
30
|
+
style: "currency",
|
|
31
|
+
currency: "USD",
|
|
32
|
+
minimumFractionDigits: fractionDigits,
|
|
33
|
+
maximumFractionDigits: fractionDigits,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return formatter.format(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function signedNumber(numb: string | number) {
|
|
40
|
+
return new Intl.NumberFormat("en-US", {
|
|
41
|
+
signDisplay: "exceptZero",
|
|
42
|
+
}).format(toBN(numb).toNumber());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function formatDecimal(value: string | number, decimalPlaces = 5) {
|
|
46
|
+
if (!value) {
|
|
47
|
+
value = "0";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return toBN(value).decimalPlaces(decimalPlaces).toFormat();
|
|
51
|
+
}
|
package/utils/helper.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const indexSorter = (aIndex: number, bIndex: number) => {
|
|
2
|
+
if (aIndex === -1 && bIndex === -1) {
|
|
3
|
+
return 0; // fallback to other sorting criteria
|
|
4
|
+
} else if (aIndex === -1) {
|
|
5
|
+
return 1; // b comes first if a is not in the priority list
|
|
6
|
+
} else if (bIndex === -1) {
|
|
7
|
+
return -1; // a comes first if b is not in the priority list
|
|
8
|
+
} else {
|
|
9
|
+
return aIndex - bIndex; // sort by the index in the priority list
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function sortByMany<T>(
|
|
14
|
+
items: T[],
|
|
15
|
+
callback: ((a: T, b: T) => number)[]
|
|
16
|
+
) {
|
|
17
|
+
return items.sort(function (a, b) {
|
|
18
|
+
var result = 0;
|
|
19
|
+
for (var i = 0; i < callback.length; i++) {
|
|
20
|
+
var func = callback[i];
|
|
21
|
+
result = func(a, b);
|
|
22
|
+
if (result !== 0) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function cloneDeep<T>(value: T): T {
|
|
31
|
+
return JSON.parse(JSON.stringify(value));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function filterArray(array: any, filters: any) {
|
|
35
|
+
const filterKeys = Object.keys(filters);
|
|
36
|
+
return array.filter((item: any) => {
|
|
37
|
+
// validates all filter criteria
|
|
38
|
+
return filterKeys.every((key) => {
|
|
39
|
+
// ignores non-function predicates
|
|
40
|
+
if (typeof filters[key] !== "function") return true;
|
|
41
|
+
return filters[key](item[key], item);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function onImageError(this: HTMLImageElement) {
|
|
47
|
+
const parentElement = this.parentElement;
|
|
48
|
+
this.onerror = null;
|
|
49
|
+
this.remove();
|
|
50
|
+
|
|
51
|
+
if (parentElement) {
|
|
52
|
+
parentElement.classList.add("bg-gray-300");
|
|
53
|
+
}
|
|
54
|
+
}
|