@instadapp/avocado-base 0.0.0-dev.c8c43bc → 0.0.0-dev.e144f0f
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/app.vue +20 -0
- package/components/ChainLogo.vue +140 -0
- package/nuxt.config.ts +2 -2
- package/package.json +2 -1
- package/server/utils/index.ts +2 -0
- package/utils/bignumber.ts +31 -0
- package/utils/formatter.ts +94 -0
- package/utils/helper.ts +26 -0
- package/utils/metadata.ts +23 -1
- package/utils/network.ts +115 -64
- package/utils/utils.d.ts +28 -7
- package/utils/index.ts +0 -93
package/app.vue
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="container mx-auto">
|
|
3
|
+
Networks:
|
|
4
|
+
<ul class="grid grid-cols-5 gap-5">
|
|
5
|
+
<li class="w-fit" v-for="network in networks">
|
|
6
|
+
<p>
|
|
7
|
+
{{ network.name }}
|
|
8
|
+
</p>
|
|
9
|
+
<p>
|
|
10
|
+
{{ network.chainId }}
|
|
11
|
+
</p>
|
|
12
|
+
<div class="flex items-center gap-2">
|
|
13
|
+
<ChainLogo class="w-8 h-8" :chain="network.chainId" />
|
|
14
|
+
<ChainLogo stroke class="w-8 h-8" :chain="network.chainId" />
|
|
15
|
+
</div>
|
|
16
|
+
</li>
|
|
17
|
+
</ul>
|
|
18
|
+
</div>
|
|
19
|
+
<ul></ul>
|
|
20
|
+
</template>
|
package/components/ChainLogo.vue
CHANGED
|
@@ -380,6 +380,146 @@
|
|
|
380
380
|
</defs>
|
|
381
381
|
</svg>
|
|
382
382
|
|
|
383
|
+
<svg
|
|
384
|
+
v-else-if="chain == 1313161554"
|
|
385
|
+
width="24"
|
|
386
|
+
height="24"
|
|
387
|
+
viewBox="0 0 24 24"
|
|
388
|
+
fill="none"
|
|
389
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
390
|
+
>
|
|
391
|
+
<rect
|
|
392
|
+
x="1"
|
|
393
|
+
y="1"
|
|
394
|
+
width="22"
|
|
395
|
+
height="22"
|
|
396
|
+
rx="11"
|
|
397
|
+
:fill="generateID('aurora', true)"
|
|
398
|
+
/>
|
|
399
|
+
<path
|
|
400
|
+
d="M11.9961 7.26624C12.4182 7.26624 12.8014 7.505 12.9902 7.88257L16.1114 14.1291C16.3835 14.6788 16.1614 15.3451 15.6116 15.6172C15.4561 15.6949 15.2894 15.7338 15.1173 15.7338H8.87486C8.26395 15.7338 7.76411 15.234 7.76411 14.6233C7.76411 14.4511 7.80299 14.279 7.88074 14.1291L11.0019 7.88257C11.1908 7.49944 11.574 7.26069 11.9961 7.26624ZM11.9961 6.5C11.2852 6.5 10.6354 6.89978 10.3188 7.53831L7.19763 13.7848C6.73667 14.7121 7.10877 15.8337 8.03624 16.3001C8.29727 16.4278 8.58607 16.5 8.87486 16.5H15.1228C16.1558 16.5 17 15.6616 17 14.6288C17 14.3401 16.9334 14.0514 16.8001 13.7904L13.6733 7.53831C13.3567 6.89978 12.707 6.5 11.9961 6.5Z"
|
|
401
|
+
fill="white"
|
|
402
|
+
/>
|
|
403
|
+
<rect
|
|
404
|
+
x="1"
|
|
405
|
+
y="1"
|
|
406
|
+
width="22"
|
|
407
|
+
height="22"
|
|
408
|
+
rx="11"
|
|
409
|
+
stroke="black"
|
|
410
|
+
stroke-width="2"
|
|
411
|
+
v-if="stroke"
|
|
412
|
+
:class="strokeClass"
|
|
413
|
+
/>
|
|
414
|
+
<defs>
|
|
415
|
+
<linearGradient
|
|
416
|
+
:id="generateID('aurora')"
|
|
417
|
+
x1="12"
|
|
418
|
+
y1="2"
|
|
419
|
+
x2="12"
|
|
420
|
+
y2="22"
|
|
421
|
+
gradientUnits="userSpaceOnUse"
|
|
422
|
+
>
|
|
423
|
+
<stop stop-color="#8EEF6B" />
|
|
424
|
+
<stop offset="1" stop-color="#70D44B" />
|
|
425
|
+
</linearGradient>
|
|
426
|
+
</defs>
|
|
427
|
+
</svg>
|
|
428
|
+
|
|
429
|
+
<svg
|
|
430
|
+
v-else-if="chain == 250"
|
|
431
|
+
width="24"
|
|
432
|
+
height="24"
|
|
433
|
+
viewBox="0 0 24 24"
|
|
434
|
+
fill="none"
|
|
435
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
436
|
+
>
|
|
437
|
+
<rect
|
|
438
|
+
x="1"
|
|
439
|
+
y="1"
|
|
440
|
+
width="22"
|
|
441
|
+
height="22"
|
|
442
|
+
rx="11"
|
|
443
|
+
:fill="generateID('fantom', true)"
|
|
444
|
+
/>
|
|
445
|
+
<path
|
|
446
|
+
fill-rule="evenodd"
|
|
447
|
+
clip-rule="evenodd"
|
|
448
|
+
d="M12.75 10.0625L15 8.75V11.375L12.75 10.0625ZM15 15.6875L12 17.4375L9 15.6875V12.625L12 14.375L15 12.625V15.6875ZM9 8.75L11.25 10.0625L9 11.375V8.75ZM12.375 10.6875L14.625 12L12.375 13.3125V10.6875ZM11.625 13.3125L9.375 12L11.625 10.6875V13.3125ZM14.625 8.125L12 9.625L9.375 8.125L12 6.5625L14.625 8.125ZM8.25 7.875V16.0625L12 18.1875L15.75 16.0625V7.875L12 5.75L8.25 7.875Z"
|
|
449
|
+
fill="white"
|
|
450
|
+
/>
|
|
451
|
+
<rect
|
|
452
|
+
x="1"
|
|
453
|
+
y="1"
|
|
454
|
+
width="22"
|
|
455
|
+
height="22"
|
|
456
|
+
rx="11"
|
|
457
|
+
stroke="black"
|
|
458
|
+
stroke-width="2"
|
|
459
|
+
v-if="stroke"
|
|
460
|
+
:class="strokeClass"
|
|
461
|
+
/>
|
|
462
|
+
<defs>
|
|
463
|
+
<linearGradient
|
|
464
|
+
:id="generateID('fantom')"
|
|
465
|
+
x1="12"
|
|
466
|
+
y1="2"
|
|
467
|
+
x2="12"
|
|
468
|
+
y2="22"
|
|
469
|
+
gradientUnits="userSpaceOnUse"
|
|
470
|
+
>
|
|
471
|
+
<stop stop-color="#51D3FF" />
|
|
472
|
+
<stop offset="1" stop-color="#13B5EC" />
|
|
473
|
+
</linearGradient>
|
|
474
|
+
</defs>
|
|
475
|
+
</svg>
|
|
476
|
+
|
|
477
|
+
<svg
|
|
478
|
+
v-else-if="chain == 634 || chain == 63400"
|
|
479
|
+
width="24"
|
|
480
|
+
height="24"
|
|
481
|
+
viewBox="0 0 24 24"
|
|
482
|
+
fill="none"
|
|
483
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
484
|
+
>
|
|
485
|
+
<rect
|
|
486
|
+
x="1"
|
|
487
|
+
y="1"
|
|
488
|
+
width="22"
|
|
489
|
+
height="22"
|
|
490
|
+
rx="11"
|
|
491
|
+
:fill="generateID('avo', true)"
|
|
492
|
+
/>
|
|
493
|
+
<path
|
|
494
|
+
d="M11.9999 17.4052C11.9999 17.7497 12.2787 18.0322 12.6197 17.997C15.6422 17.6854 18 15.1194 18 12C18 8.88061 15.6422 6.31462 12.6197 6.00299C12.2787 5.96765 11.9999 6.25038 11.9999 6.59486V8.25799C11.9999 8.60246 12.2806 8.87521 12.6167 8.94319C14.0353 9.2307 15.1035 10.4899 15.1035 12C15.1035 13.5101 14.0353 14.7693 12.6167 15.0569C12.2806 15.1248 11.9999 15.3978 11.9999 15.7421V17.4052ZM10.1378 7.12664C10.1378 6.70254 9.7247 6.4036 9.34642 6.59132C7.36369 7.57527 6 9.62756 6 12C6 14.3725 7.36369 16.4248 9.34642 17.4087C9.7247 17.5964 10.1378 17.2975 10.1378 16.8734V7.12685V7.12664Z"
|
|
495
|
+
fill="white"
|
|
496
|
+
/>
|
|
497
|
+
<rect
|
|
498
|
+
x="1"
|
|
499
|
+
y="1"
|
|
500
|
+
width="22"
|
|
501
|
+
height="22"
|
|
502
|
+
rx="11"
|
|
503
|
+
stroke="black"
|
|
504
|
+
stroke-width="2"
|
|
505
|
+
v-if="stroke"
|
|
506
|
+
:class="strokeClass"
|
|
507
|
+
/>
|
|
508
|
+
<defs>
|
|
509
|
+
<linearGradient
|
|
510
|
+
:id="generateID('avo')"
|
|
511
|
+
x1="12"
|
|
512
|
+
y1="2"
|
|
513
|
+
x2="12"
|
|
514
|
+
y2="22"
|
|
515
|
+
gradientUnits="userSpaceOnUse"
|
|
516
|
+
>
|
|
517
|
+
<stop stop-color="#6ED578" />
|
|
518
|
+
<stop offset="1" stop-color="#4CA054" />
|
|
519
|
+
</linearGradient>
|
|
520
|
+
</defs>
|
|
521
|
+
</svg>
|
|
522
|
+
|
|
383
523
|
<template v-else>
|
|
384
524
|
<svg
|
|
385
525
|
v-bind="$attrs"
|
package/nuxt.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instadapp/avocado-base",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.e144f0f",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"types": "global.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@instadapp/avocado": "^0.1.10",
|
|
16
16
|
"@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
|
|
17
|
+
"@nuxtjs/tailwindcss": "^6.6.5",
|
|
17
18
|
"@typechain/ethers-v5": "^10.2.0",
|
|
18
19
|
"nuxt": "^3.3.3",
|
|
19
20
|
"rimraf": "^3.0.2",
|
package/server/utils/index.ts
CHANGED
|
@@ -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,94 @@
|
|
|
1
|
+
export function formatPercent(
|
|
2
|
+
value?: number | string,
|
|
3
|
+
fractionDigits = 2,
|
|
4
|
+
maxValue = null
|
|
5
|
+
) {
|
|
6
|
+
if (!value || isZero(value)) return "0.00%";
|
|
7
|
+
|
|
8
|
+
const valueAsNumber = toBN(value).toNumber();
|
|
9
|
+
|
|
10
|
+
if (maxValue && gt(times(valueAsNumber, "100"), maxValue))
|
|
11
|
+
return `>${maxValue}%`;
|
|
12
|
+
|
|
13
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
14
|
+
style: "percent",
|
|
15
|
+
minimumFractionDigits: fractionDigits,
|
|
16
|
+
maximumFractionDigits: fractionDigits,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return formatter.format(valueAsNumber);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function shortenHash(hash: string, length: number = 4) {
|
|
23
|
+
if (!hash) return;
|
|
24
|
+
if (hash.length < 12) return hash;
|
|
25
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
|
26
|
+
const shortened =
|
|
27
|
+
hash.substr(0, beginningChars) + "..." + hash.substr(-length);
|
|
28
|
+
return shortened;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formatUsd(value: any, fractionDigits = 2) {
|
|
32
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
33
|
+
style: "currency",
|
|
34
|
+
currency: "USD",
|
|
35
|
+
minimumFractionDigits: fractionDigits,
|
|
36
|
+
maximumFractionDigits: fractionDigits,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return formatter.format(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function signedNumber(numb: string | number) {
|
|
43
|
+
return new Intl.NumberFormat("en-US", {
|
|
44
|
+
signDisplay: "exceptZero",
|
|
45
|
+
}).format(toBN(numb).toNumber());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getFractionDigits(value: string | number) {
|
|
49
|
+
const absoluteValue = toBN(value).abs();
|
|
50
|
+
|
|
51
|
+
if (isZero(absoluteValue)) {
|
|
52
|
+
return 2;
|
|
53
|
+
} else if (lt(absoluteValue, 0.01)) {
|
|
54
|
+
return 6;
|
|
55
|
+
} else if (lt(absoluteValue, 1)) {
|
|
56
|
+
return 4;
|
|
57
|
+
} else if (lt(absoluteValue, 10000)) {
|
|
58
|
+
return 2;
|
|
59
|
+
} else {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function formatDecimal(value: string | number, fractionDigits?: number) {
|
|
65
|
+
if (!value) {
|
|
66
|
+
value = "0";
|
|
67
|
+
}
|
|
68
|
+
if (lt(value, "0.0001") && gt(value, "0")) {
|
|
69
|
+
return "< 0.0001";
|
|
70
|
+
} else {
|
|
71
|
+
const num = toBN(value);
|
|
72
|
+
let decimals;
|
|
73
|
+
|
|
74
|
+
if (num.lt(1)) {
|
|
75
|
+
decimals = 8;
|
|
76
|
+
} else if (num.lt(10)) {
|
|
77
|
+
decimals = 6;
|
|
78
|
+
} else if (num.lt(100)) {
|
|
79
|
+
decimals = 4;
|
|
80
|
+
} else if (num.lt(1000)) {
|
|
81
|
+
decimals = 3;
|
|
82
|
+
} else if (num.lt(10000)) {
|
|
83
|
+
decimals = 2;
|
|
84
|
+
} else if (num.lt(100000)) {
|
|
85
|
+
decimals = 1;
|
|
86
|
+
} else {
|
|
87
|
+
decimals = 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const formattedNumber = num.toFixed(fractionDigits || decimals);
|
|
91
|
+
|
|
92
|
+
return toBN(formattedNumber).toFormat();
|
|
93
|
+
}
|
|
94
|
+
}
|
package/utils/helper.ts
CHANGED
|
@@ -26,3 +26,29 @@ export function sortByMany<T>(
|
|
|
26
26
|
return result;
|
|
27
27
|
});
|
|
28
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
|
+
}
|
package/utils/metadata.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
2
|
import { Forwarder__factory } from "@/contracts";
|
|
3
|
-
import { toBN } from "./index";
|
|
4
3
|
|
|
5
4
|
const multiMetadataTypes = ["bytes[]"];
|
|
6
5
|
|
|
@@ -8,6 +7,12 @@ const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
|
8
7
|
|
|
9
8
|
const actionMetadataTypes = {
|
|
10
9
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
10
|
+
"cross-transfer": [
|
|
11
|
+
"address fromToken",
|
|
12
|
+
"address toToken",
|
|
13
|
+
"uint256 amount",
|
|
14
|
+
"address receiver",
|
|
15
|
+
],
|
|
11
16
|
bridge: [
|
|
12
17
|
"uint256 amount",
|
|
13
18
|
"address receiver",
|
|
@@ -79,6 +84,23 @@ export const encodeTransferMetadata = (
|
|
|
79
84
|
return single ? encodeMultipleActions(data) : data;
|
|
80
85
|
};
|
|
81
86
|
|
|
87
|
+
export const encodeCrossTransferMetadata = (
|
|
88
|
+
params: CrossSendMetadatProps,
|
|
89
|
+
single = true
|
|
90
|
+
) => {
|
|
91
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
92
|
+
actionMetadataTypes["cross-transfer"],
|
|
93
|
+
[params.fromToken, params.toToken, params.amount, params.receiver]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const data = encodeMetadata({
|
|
97
|
+
type: "cross-transfer",
|
|
98
|
+
encodedData,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return single ? encodeMultipleActions(data) : data;
|
|
102
|
+
};
|
|
103
|
+
|
|
82
104
|
export const encodeDeployMetadata = (single = true) => {
|
|
83
105
|
const data = encodeMetadata({
|
|
84
106
|
type: "deploy",
|
package/utils/network.ts
CHANGED
|
@@ -7,15 +7,16 @@ export const networks: Network[] = [
|
|
|
7
7
|
name: "Mainnet",
|
|
8
8
|
debankName: "eth",
|
|
9
9
|
ankrName: "eth",
|
|
10
|
+
zerionName: "ethereum",
|
|
10
11
|
chainId: 1,
|
|
12
|
+
explorerUrl: "https://etherscan.io",
|
|
13
|
+
get serverRpcUrl() {
|
|
14
|
+
return process.env?.MAINNET_RPC_URL || this.params.rpcUrls[0];
|
|
15
|
+
},
|
|
16
|
+
balanceResolverAddress: "0x5b7D61b389D12e1f5873d0cCEe7E675915AB5F43",
|
|
17
|
+
usdcAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
11
18
|
params: {
|
|
12
19
|
rpcUrls: ["https://rpc.ankr.com/eth"],
|
|
13
|
-
explorerUrl: "https://etherscan.io",
|
|
14
|
-
get serverRpcUrl() {
|
|
15
|
-
return process.env?.MAINNET_RPC_URL || this.rpcUrls[0];
|
|
16
|
-
},
|
|
17
|
-
balanceResolverAddress: "0x5b7D61b389D12e1f5873d0cCEe7E675915AB5F43",
|
|
18
|
-
usdcAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
19
20
|
nativeCurrency: {
|
|
20
21
|
name: "Ethereum",
|
|
21
22
|
symbol: "ETH",
|
|
@@ -27,7 +28,14 @@ export const networks: Network[] = [
|
|
|
27
28
|
name: "Polygon",
|
|
28
29
|
debankName: "matic",
|
|
29
30
|
ankrName: "polygon",
|
|
31
|
+
zerionName: "polygon",
|
|
30
32
|
chainId: 137,
|
|
33
|
+
balanceResolverAddress: "0x58632D23120b20650262b8A629a14e4F4043E0D9",
|
|
34
|
+
usdcAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
35
|
+
explorerUrl: "https://polygonscan.com",
|
|
36
|
+
get serverRpcUrl() {
|
|
37
|
+
return process.env?.POLYGON_RPC_URL || this.params.rpcUrls[0];
|
|
38
|
+
},
|
|
31
39
|
params: {
|
|
32
40
|
chainName: "Matic(Polygon) Mainnet",
|
|
33
41
|
nativeCurrency: {
|
|
@@ -35,20 +43,21 @@ export const networks: Network[] = [
|
|
|
35
43
|
symbol: "MATIC",
|
|
36
44
|
decimals: 18,
|
|
37
45
|
},
|
|
38
|
-
balanceResolverAddress: "0x58632D23120b20650262b8A629a14e4F4043E0D9",
|
|
39
|
-
usdcAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
40
46
|
rpcUrls: ["https://polygon-rpc.com"],
|
|
41
|
-
get serverRpcUrl() {
|
|
42
|
-
return process.env?.POLYGON_RPC_URL || this.rpcUrls[0];
|
|
43
|
-
},
|
|
44
|
-
explorerUrl: "https://polygonscan.com",
|
|
45
47
|
},
|
|
46
48
|
},
|
|
47
49
|
{
|
|
48
50
|
name: "Arbitrum",
|
|
49
51
|
debankName: "arb",
|
|
50
52
|
ankrName: "arbitrum",
|
|
53
|
+
zerionName: "arbitrum",
|
|
51
54
|
chainId: 42161,
|
|
55
|
+
usdcAddress: "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
|
|
56
|
+
balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
|
|
57
|
+
explorerUrl: "https://arbiscan.io",
|
|
58
|
+
get serverRpcUrl() {
|
|
59
|
+
return process.env?.ARBITRUM_RPC_URL || this.params.rpcUrls[0];
|
|
60
|
+
},
|
|
52
61
|
params: {
|
|
53
62
|
chainName: "Arbitrum One",
|
|
54
63
|
nativeCurrency: {
|
|
@@ -56,20 +65,21 @@ export const networks: Network[] = [
|
|
|
56
65
|
symbol: "ETH",
|
|
57
66
|
decimals: 18,
|
|
58
67
|
},
|
|
59
|
-
usdcAddress: "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
|
|
60
|
-
balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
|
|
61
|
-
get serverRpcUrl() {
|
|
62
|
-
return process.env?.ARBITRUM_RPC_URL || this.rpcUrls[0];
|
|
63
|
-
},
|
|
64
68
|
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
65
|
-
explorerUrl: "https://arbiscan.io",
|
|
66
69
|
},
|
|
67
70
|
},
|
|
68
71
|
{
|
|
69
72
|
name: "Optimism",
|
|
70
73
|
debankName: "op",
|
|
71
74
|
ankrName: "optimism",
|
|
75
|
+
zerionName: "optimism",
|
|
72
76
|
chainId: 10,
|
|
77
|
+
usdcAddress: "0x7f5c764cbc14f9669b88837ca1490cca17c31607",
|
|
78
|
+
balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
|
|
79
|
+
explorerUrl: "https://optimistic.etherscan.io",
|
|
80
|
+
get serverRpcUrl() {
|
|
81
|
+
return process.env?.OPTIMISM_RPC_URL || this.params.rpcUrls[0];
|
|
82
|
+
},
|
|
73
83
|
params: {
|
|
74
84
|
chainName: "Optimistic Ethereum",
|
|
75
85
|
nativeCurrency: {
|
|
@@ -77,50 +87,46 @@ export const networks: Network[] = [
|
|
|
77
87
|
symbol: "ETH",
|
|
78
88
|
decimals: 18,
|
|
79
89
|
},
|
|
80
|
-
|
|
81
|
-
balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
|
|
82
|
-
get serverRpcUrl() {
|
|
83
|
-
return process.env?.OPTIMISM_RPC_URL || this.rpcUrls[0];
|
|
84
|
-
},
|
|
85
|
-
rpcUrls: ["https://mainnet.optimism.io"],
|
|
86
|
-
explorerUrl: "https://optimistic.etherscan.io",
|
|
90
|
+
rpcUrls: ["https://rpc.ankr.com/optimism"],
|
|
87
91
|
},
|
|
88
92
|
},
|
|
89
93
|
{
|
|
90
94
|
name: "Avalanche",
|
|
91
95
|
debankName: "avax",
|
|
92
96
|
ankrName: "avalanche",
|
|
97
|
+
zerionName: "avalanche",
|
|
93
98
|
chainId: 43114,
|
|
99
|
+
usdcAddress: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
100
|
+
balanceResolverAddress: "0x63009f31D054E0ac9F321Cf0D642375236A4Bf1E",
|
|
101
|
+
explorerUrl: "https://snowtrace.io",
|
|
102
|
+
get serverRpcUrl() {
|
|
103
|
+
return process.env?.AVALANCHE_RPC_URL || this.params.rpcUrls[0];
|
|
104
|
+
},
|
|
94
105
|
params: {
|
|
95
106
|
chainName: "Avalanche Network",
|
|
96
|
-
get serverRpcUrl() {
|
|
97
|
-
return process.env?.AVALANCHE_RPC_URL || this.rpcUrls[0];
|
|
98
|
-
},
|
|
99
107
|
nativeCurrency: {
|
|
100
108
|
name: "Avalanche",
|
|
101
109
|
symbol: "AVAX",
|
|
102
110
|
decimals: 18,
|
|
103
111
|
},
|
|
104
|
-
usdcAddress: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
105
|
-
balanceResolverAddress: "0x63009f31D054E0ac9F321Cf0D642375236A4Bf1E",
|
|
106
112
|
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
107
|
-
explorerUrl: "https://snowtrace.io",
|
|
108
113
|
},
|
|
109
114
|
},
|
|
110
115
|
{
|
|
111
116
|
name: "BSC",
|
|
112
117
|
debankName: "bsc",
|
|
113
118
|
ankrName: "bsc",
|
|
119
|
+
zerionName: "binance-smart-chain",
|
|
114
120
|
chainId: 56,
|
|
121
|
+
explorerUrl: "https://bscscan.com",
|
|
122
|
+
usdcAddress: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
123
|
+
balanceResolverAddress: "0xb808cff38706e267067b0af427726aa099f69f89",
|
|
124
|
+
get serverRpcUrl() {
|
|
125
|
+
return process.env?.BSC_RPC_URL || this.params.rpcUrls[0];
|
|
126
|
+
},
|
|
115
127
|
params: {
|
|
116
128
|
chainName: "Binance Smart Chain",
|
|
117
|
-
explorerUrl: "https://bscscan.com",
|
|
118
129
|
rpcUrls: ["https://rpc.ankr.com/bsc"],
|
|
119
|
-
get serverRpcUrl() {
|
|
120
|
-
return process.env?.BSC_RPC_URL || this.rpcUrls[0];
|
|
121
|
-
},
|
|
122
|
-
usdcAddress: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
123
|
-
balanceResolverAddress: "0xb808cff38706e267067b0af427726aa099f69f89",
|
|
124
130
|
nativeCurrency: {
|
|
125
131
|
name: "Binance Coin",
|
|
126
132
|
symbol: "BNB",
|
|
@@ -131,17 +137,17 @@ export const networks: Network[] = [
|
|
|
131
137
|
{
|
|
132
138
|
name: "Gnosis",
|
|
133
139
|
debankName: "xdai",
|
|
134
|
-
|
|
140
|
+
zerionName: "xdai",
|
|
135
141
|
chainId: 100,
|
|
142
|
+
balanceResolverAddress: "0xfaa244e276b1597f663975ed007ee4ff70d27849",
|
|
143
|
+
explorerUrl: "https://gnosisscan.io",
|
|
144
|
+
usdcAddress: "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83",
|
|
145
|
+
get serverRpcUrl() {
|
|
146
|
+
return process.env?.GNOSIS_RPC_URL || this.params.rpcUrls[0];
|
|
147
|
+
},
|
|
136
148
|
params: {
|
|
137
149
|
chainName: "Gnosis Safe",
|
|
138
|
-
explorerUrl: "https://gnosisscan.io",
|
|
139
150
|
rpcUrls: ["https://rpc.ankr.com/gnosis"],
|
|
140
|
-
get serverRpcUrl() {
|
|
141
|
-
return process.env?.GNOSIS_RPC_URL || this.rpcUrls[0];
|
|
142
|
-
},
|
|
143
|
-
balanceResolverAddress: "0xfaa244e276b1597f663975ed007ee4ff70d27849",
|
|
144
|
-
usdcAddress: "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83",
|
|
145
151
|
nativeCurrency: {
|
|
146
152
|
name: "xdaistable",
|
|
147
153
|
symbol: "xDAI",
|
|
@@ -152,15 +158,16 @@ export const networks: Network[] = [
|
|
|
152
158
|
{
|
|
153
159
|
name: "Polygon zkEVM",
|
|
154
160
|
chainId: 1101,
|
|
161
|
+
explorerUrl: "https://zkevm.polygonscan.com",
|
|
162
|
+
balanceResolverAddress: "0x48D1Fa5Ee6691a1E0B45d2B515650997BEA27a01",
|
|
163
|
+
usdcAddress: "0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035",
|
|
164
|
+
get serverRpcUrl() {
|
|
165
|
+
return process.env?.POLYGON_ZKEVM_RPC_URL || this.params.rpcUrls[0];
|
|
166
|
+
},
|
|
155
167
|
params: {
|
|
156
168
|
chainName: "polygon zkEVM",
|
|
157
|
-
explorerUrl: "https://zkevm.polygonscan.com",
|
|
158
169
|
rpcUrls: ["https://rpc.ankr.com/polygon_zkevm"],
|
|
159
|
-
|
|
160
|
-
return process.env?.POLYGON_ZKEVM_RPC_URL || this.rpcUrls[0];
|
|
161
|
-
},
|
|
162
|
-
balanceResolverAddress: "0x48D1Fa5Ee6691a1E0B45d2B515650997BEA27a01",
|
|
163
|
-
usdcAddress: "0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035",
|
|
170
|
+
|
|
164
171
|
nativeCurrency: {
|
|
165
172
|
name: "Ethereum",
|
|
166
173
|
symbol: "ETH",
|
|
@@ -168,10 +175,55 @@ export const networks: Network[] = [
|
|
|
168
175
|
},
|
|
169
176
|
},
|
|
170
177
|
},
|
|
178
|
+
// {
|
|
179
|
+
// name: "Aurora",
|
|
180
|
+
// chainId: 1313161554,
|
|
181
|
+
// zerionName: "aurora",
|
|
182
|
+
// explorerUrl: "https://explorer.mainnet.aurora.dev",
|
|
183
|
+
// get serverRpcUrl() {
|
|
184
|
+
// return process.env?.AURORA_RPC_URL || this.params.rpcUrls[0];
|
|
185
|
+
// },
|
|
186
|
+
// usdcAddress: "0xB12BFcA5A55806AaF64E99521918A4bf0fC40802",
|
|
187
|
+
// balanceResolverAddress: "0xdF19Da523DA64bBE82eE0E4DFf00d676A8386474",
|
|
188
|
+
// params: {
|
|
189
|
+
// rpcUrls: ["https://mainnet.aurora.dev"],
|
|
190
|
+
// chainName: "Aurora",
|
|
191
|
+
// nativeCurrency: {
|
|
192
|
+
// decimals: 18,
|
|
193
|
+
// name: "Aurora ETH",
|
|
194
|
+
// symbol: "AETH",
|
|
195
|
+
// },
|
|
196
|
+
// },
|
|
197
|
+
// },
|
|
198
|
+
{
|
|
199
|
+
name: "Fantom",
|
|
200
|
+
chainId: 250,
|
|
201
|
+
zerionName: "fantom",
|
|
202
|
+
explorerUrl: "https://ftmscan.com",
|
|
203
|
+
ankrName: "fantom",
|
|
204
|
+
get serverRpcUrl() {
|
|
205
|
+
return process.env?.FANTOM_RPC_URL || this.params.rpcUrls[0];
|
|
206
|
+
},
|
|
207
|
+
usdcAddress: "0x04068da6c83afcfa0e13ba15a6696662335d5b75",
|
|
208
|
+
balanceResolverAddress: "0x929376c77a2fb8152375a089a4fccf84ff481479",
|
|
209
|
+
params: {
|
|
210
|
+
rpcUrls: ["https://rpc.ankr.com/fantom"],
|
|
211
|
+
chainName: "Fantom",
|
|
212
|
+
nativeCurrency: {
|
|
213
|
+
name: "Fantom",
|
|
214
|
+
symbol: "FTM",
|
|
215
|
+
decimals: 18,
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
171
219
|
{
|
|
172
220
|
name: AVO_PROD_CHAIN_NAME,
|
|
173
221
|
chainId: AVO_PROD_CHAIN_ID,
|
|
174
222
|
isAvocado: true,
|
|
223
|
+
balanceResolverAddress: "",
|
|
224
|
+
usdcAddress: "",
|
|
225
|
+
serverRpcUrl: AVO_PROD_RPC_URL,
|
|
226
|
+
explorerUrl: AVO_PROD_EXPLORER_URL,
|
|
175
227
|
params: {
|
|
176
228
|
chainName: AVO_PROD_CHAIN_NAME,
|
|
177
229
|
nativeCurrency: {
|
|
@@ -180,17 +232,17 @@ export const networks: Network[] = [
|
|
|
180
232
|
decimals: 18,
|
|
181
233
|
},
|
|
182
234
|
iconUrls: ["https://avocado.instadapp.io/logo.svg"],
|
|
183
|
-
balanceResolverAddress: "",
|
|
184
|
-
usdcAddress: "",
|
|
185
|
-
serverRpcUrl: AVO_PROD_RPC_URL,
|
|
186
235
|
rpcUrls: [AVO_PROD_RPC_URL],
|
|
187
|
-
explorerUrl: AVO_PROD_EXPLORER_URL,
|
|
188
236
|
},
|
|
189
237
|
},
|
|
190
238
|
{
|
|
191
239
|
name: AVO_STAGING_CHAIN_NAME,
|
|
192
240
|
chainId: AVO_STAGING_CHAIN_ID,
|
|
241
|
+
serverRpcUrl: AVO_STAGING_RPC_URL,
|
|
242
|
+
explorerUrl: AVO_STAGING_EXPLORER_URL,
|
|
193
243
|
isAvocado: true,
|
|
244
|
+
balanceResolverAddress: "",
|
|
245
|
+
usdcAddress: "",
|
|
194
246
|
params: {
|
|
195
247
|
chainName: AVO_STAGING_CHAIN_NAME,
|
|
196
248
|
nativeCurrency: {
|
|
@@ -198,12 +250,8 @@ export const networks: Network[] = [
|
|
|
198
250
|
symbol: "USDC",
|
|
199
251
|
decimals: 18,
|
|
200
252
|
},
|
|
201
|
-
serverRpcUrl: AVO_STAGING_RPC_URL,
|
|
202
|
-
balanceResolverAddress: "",
|
|
203
|
-
usdcAddress: "",
|
|
204
253
|
iconUrls: ["https://avocado.instadapp.io/logo.svg"],
|
|
205
254
|
rpcUrls: [AVO_STAGING_RPC_URL],
|
|
206
|
-
explorerUrl: AVO_STAGING_EXPLORER_URL,
|
|
207
255
|
},
|
|
208
256
|
},
|
|
209
257
|
];
|
|
@@ -235,14 +283,17 @@ export const RPCMap = networks.reduce((acc, network) => {
|
|
|
235
283
|
|
|
236
284
|
export const networkIds = networks.map((network) => network.chainId);
|
|
237
285
|
|
|
238
|
-
const rpcInstances: Record<string, ethers.providers.
|
|
239
|
-
const serverRpcInstances: Record<
|
|
286
|
+
const rpcInstances: Record<string, ethers.providers.StaticJsonRpcProvider> = {};
|
|
287
|
+
const serverRpcInstances: Record<
|
|
288
|
+
string,
|
|
289
|
+
ethers.providers.StaticJsonRpcProvider
|
|
290
|
+
> = {};
|
|
240
291
|
|
|
241
292
|
export const getServerRpcProvider = (chainId: number | string) => {
|
|
242
293
|
if (!rpcInstances[chainId]) {
|
|
243
294
|
const network = networks.find((n) => n.chainId == chainId);
|
|
244
|
-
serverRpcInstances[chainId] = new ethers.providers.
|
|
245
|
-
network?.
|
|
295
|
+
serverRpcInstances[chainId] = new ethers.providers.StaticJsonRpcProvider(
|
|
296
|
+
network?.serverRpcUrl
|
|
246
297
|
);
|
|
247
298
|
}
|
|
248
299
|
|
|
@@ -251,7 +302,7 @@ export const getServerRpcProvider = (chainId: number | string) => {
|
|
|
251
302
|
|
|
252
303
|
export const getRpcProvider = (chainId: number | string) => {
|
|
253
304
|
if (!rpcInstances[chainId]) {
|
|
254
|
-
rpcInstances[chainId] = new ethers.providers.
|
|
305
|
+
rpcInstances[chainId] = new ethers.providers.StaticJsonRpcProvider(
|
|
255
306
|
getRpcURLByChainId(Number(chainId))
|
|
256
307
|
);
|
|
257
308
|
}
|
|
@@ -264,5 +315,5 @@ export const getExplorerUrl = (
|
|
|
264
315
|
suffix: `/${string}` = "/"
|
|
265
316
|
) => {
|
|
266
317
|
const network = getNetworkByChainId(chainId);
|
|
267
|
-
return `${network.
|
|
318
|
+
return `${network.explorerUrl}${suffix}`;
|
|
268
319
|
};
|
package/utils/utils.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
type ChainId =
|
|
1
|
+
type ChainId =
|
|
2
|
+
| 1
|
|
3
|
+
| 137
|
|
4
|
+
| 42161
|
|
5
|
+
| 10
|
|
6
|
+
| 56
|
|
7
|
+
| 43114
|
|
8
|
+
| 100
|
|
9
|
+
| 1101
|
|
10
|
+
| 250
|
|
11
|
+
| 634
|
|
12
|
+
| 1313161554
|
|
13
|
+
| 63400;
|
|
2
14
|
|
|
3
15
|
type ISlackMessageType = "danger" | "error" | "success" | "banner";
|
|
4
16
|
|
|
@@ -6,16 +18,17 @@ interface Network {
|
|
|
6
18
|
name: string;
|
|
7
19
|
debankName?: string;
|
|
8
20
|
ankrName?: string;
|
|
21
|
+
zerionName?: string;
|
|
9
22
|
chainId: ChainId;
|
|
10
23
|
isAvocado?: boolean;
|
|
24
|
+
serverRpcUrl: string | undefined;
|
|
25
|
+
balanceResolverAddress?: string;
|
|
26
|
+
usdcAddress: string;
|
|
27
|
+
explorerUrl: string;
|
|
11
28
|
params: {
|
|
12
29
|
chainName?: string;
|
|
13
|
-
rpcUrls: string[];
|
|
14
|
-
serverRpcUrl: string | undefined;
|
|
15
|
-
balanceResolverAddress?: string;
|
|
16
|
-
usdcAddress: string;
|
|
17
|
-
explorerUrl: string;
|
|
18
30
|
iconUrls?: string[];
|
|
31
|
+
rpcUrls: string[];
|
|
19
32
|
nativeCurrency?: {
|
|
20
33
|
name: string;
|
|
21
34
|
symbol: string;
|
|
@@ -42,6 +55,13 @@ type SendMetadataProps = {
|
|
|
42
55
|
receiver: string;
|
|
43
56
|
};
|
|
44
57
|
|
|
58
|
+
type CrossSendMetadatProps = {
|
|
59
|
+
fromToken: string;
|
|
60
|
+
toToken: string;
|
|
61
|
+
amount: string;
|
|
62
|
+
receiver: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
45
65
|
type UpgradeMetadataProps = {
|
|
46
66
|
version: string;
|
|
47
67
|
walletImpl: string;
|
|
@@ -82,7 +102,8 @@ type MetadataProps = {
|
|
|
82
102
|
| "upgrade"
|
|
83
103
|
| "dapp"
|
|
84
104
|
| "deploy"
|
|
85
|
-
| "permit2"
|
|
105
|
+
| "permit2"
|
|
106
|
+
| "cross-transfer";
|
|
86
107
|
encodedData: string;
|
|
87
108
|
version?: string;
|
|
88
109
|
};
|
package/utils/index.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
}
|