@instadapp/avocado-base 0.0.2 → 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/app.vue +20 -0
- package/nuxt.config.ts +2 -2
- package/package.json +3 -2
- package/utils/bignumber.ts +31 -0
- package/utils/formatter.ts +51 -0
- package/utils/helper.ts +26 -0
- package/utils/metadata.ts +0 -1
- 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/nuxt.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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
|
-
|
|
6
|
+
"types": "global.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "nuxt build",
|
|
9
9
|
"dev": "nuxt dev",
|
|
@@ -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",
|
|
@@ -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
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
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
|
-
}
|