@instadapp/avocado-base 0.0.1 → 0.0.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.
@@ -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/package.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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
+ "@typechain/ethers-v5": "^10.2.0",
13
18
  "nuxt": "^3.3.3",
14
- "@instadapp/avocado": "^0.1.9",
15
- "@instadapp/avocado-dev": "npm:@instadapp/avocado@dev"
19
+ "rimraf": "^3.0.2",
20
+ "typechain": "^8.1.1"
16
21
  },
17
22
  "dependencies": {
23
+ "bignumber.js": "^9.1.1",
18
24
  "ethers": "^5.7.2"
19
25
  }
20
26
  }
@@ -0,0 +1,28 @@
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
+ }
package/utils/index.ts ADDED
@@ -0,0 +1,93 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { BigNumber as BN } from "ethers";
3
+
4
+ export function shortenHash(hash: string, length: number = 4) {
5
+ if (!hash) return;
6
+ if (hash.length < 12) return hash;
7
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
8
+ const shortened =
9
+ hash.substr(0, beginningChars) + "..." + hash.substr(-length);
10
+ return shortened;
11
+ }
12
+
13
+ export const toBN = (value: BigNumber.Value | BN) =>
14
+ new BigNumber(BN.isBigNumber(value) ? value.toString() : value);
15
+ export const isZero = (value: BigNumber.Value | BN) => toBN(value).isZero();
16
+ export const times = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
17
+ toBN(a).times(toBN(b));
18
+ export const minus = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
19
+ toBN(a).minus(toBN(b));
20
+ export const plus = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
21
+ toBN(a).plus(toBN(b));
22
+ export const lte = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
23
+ toBN(a).lte(toBN(b));
24
+ export const gte = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
25
+ toBN(a).gte(toBN(b));
26
+ export const div = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
27
+ toBN(a).div(toBN(b));
28
+ export const lt = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
29
+ toBN(a).lt(toBN(b));
30
+ export const gt = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
31
+ toBN(a).gt(toBN(b));
32
+ export const ensureValue = (value: any) => {
33
+ if (!value) return toBN("0");
34
+ if (toBN(value).isNaN()) return toBN("0");
35
+
36
+ return toBN(value);
37
+ };
38
+ export const max = (...args: BigNumber.Value[]) => {
39
+ return BigNumber.max(...args);
40
+ };
41
+
42
+ export function onImageError(this: HTMLImageElement) {
43
+ const parentElement = this.parentElement;
44
+ this.onerror = null;
45
+ this.remove();
46
+
47
+ if (parentElement) {
48
+ parentElement.classList.add("bg-gray-300");
49
+ }
50
+ }
51
+
52
+ const locale = "en-US";
53
+
54
+ export function formatUsd(value: any, fractionDigits = 2) {
55
+ const formatter = new Intl.NumberFormat(locale, {
56
+ style: "currency",
57
+ currency: "USD",
58
+ minimumFractionDigits: fractionDigits,
59
+ maximumFractionDigits: fractionDigits,
60
+ });
61
+
62
+ return formatter.format(value);
63
+ }
64
+
65
+ export function cloneDeep<T>(value: T): T {
66
+ return JSON.parse(JSON.stringify(value));
67
+ }
68
+
69
+ export function signedNumber(numb: string | number) {
70
+ return new Intl.NumberFormat("en-US", {
71
+ signDisplay: "exceptZero",
72
+ }).format(toBN(numb).toNumber());
73
+ }
74
+
75
+ export function formatDecimal(value: string | number, decimalPlaces = 5) {
76
+ if (!value) {
77
+ value = "0";
78
+ }
79
+
80
+ return toBN(value).decimalPlaces(decimalPlaces).toFormat();
81
+ }
82
+
83
+ export function filterArray(array: any, filters: any) {
84
+ const filterKeys = Object.keys(filters);
85
+ return array.filter((item: any) => {
86
+ // validates all filter criteria
87
+ return filterKeys.every((key) => {
88
+ // ignores non-function predicates
89
+ if (typeof filters[key] !== "function") return true;
90
+ return filters[key](item[key], item);
91
+ });
92
+ });
93
+ }