@instadapp/avocado-base 0.0.13 → 0.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.13",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
@@ -1,11 +1,14 @@
1
1
  export function formatPercent(
2
- value: number,
2
+ value?: number | string,
3
3
  fractionDigits = 2,
4
4
  maxValue = null
5
5
  ) {
6
- if (isZero(value)) return "0.00%";
6
+ if (!value || isZero(value)) return "0.00%";
7
7
 
8
- if (maxValue && gt(times(value, "100"), maxValue)) return `>${maxValue}%`;
8
+ const valueAsNumber = toBN(value).toNumber();
9
+
10
+ if (maxValue && gt(times(valueAsNumber, "100"), maxValue))
11
+ return `>${maxValue}%`;
9
12
 
10
13
  const formatter = new Intl.NumberFormat("en-US", {
11
14
  style: "percent",
@@ -13,7 +16,7 @@ export function formatPercent(
13
16
  maximumFractionDigits: fractionDigits,
14
17
  });
15
18
 
16
- return formatter.format(value);
19
+ return formatter.format(valueAsNumber);
17
20
  }
18
21
 
19
22
  export function shortenHash(hash: string, length: number = 4) {
@@ -42,10 +45,41 @@ export function signedNumber(numb: string | number) {
42
45
  }).format(toBN(numb).toNumber());
43
46
  }
44
47
 
45
- export function formatDecimal(value: string | number, decimalPlaces = 5) {
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(
65
+ value: string | number,
66
+ fractionDigits = getFractionDigits(value)
67
+ ) {
46
68
  if (!value) {
47
69
  value = "0";
48
70
  }
71
+ let formatter;
72
+ if (lt(value, "0.0001") && gt(value, "0")) {
73
+ return "< 0.0001";
74
+ } else {
75
+ formatter = new Intl.NumberFormat("en-US", {
76
+ style: "decimal",
77
+ minimumFractionDigits: fractionDigits,
78
+ maximumFractionDigits: fractionDigits,
79
+ });
80
+ }
81
+
82
+ const valueAsNumber = toBN(value).toNumber();
49
83
 
50
- return toBN(value).decimalPlaces(decimalPlaces).toFormat();
84
+ return formatter.format(valueAsNumber);
51
85
  }
package/utils/network.ts CHANGED
@@ -7,6 +7,7 @@ export const networks: Network[] = [
7
7
  name: "Mainnet",
8
8
  debankName: "eth",
9
9
  ankrName: "eth",
10
+ zerionName: "ethereum",
10
11
  chainId: 1,
11
12
  explorerUrl: "https://etherscan.io",
12
13
  get serverRpcUrl() {
@@ -27,6 +28,7 @@ export const networks: Network[] = [
27
28
  name: "Polygon",
28
29
  debankName: "matic",
29
30
  ankrName: "polygon",
31
+ zerionName: "polygon",
30
32
  chainId: 137,
31
33
  balanceResolverAddress: "0x58632D23120b20650262b8A629a14e4F4043E0D9",
32
34
  usdcAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
@@ -48,6 +50,7 @@ export const networks: Network[] = [
48
50
  name: "Arbitrum",
49
51
  debankName: "arb",
50
52
  ankrName: "arbitrum",
53
+ zerionName: "arbitrum",
51
54
  chainId: 42161,
52
55
  usdcAddress: "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
53
56
  balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
@@ -69,6 +72,7 @@ export const networks: Network[] = [
69
72
  name: "Optimism",
70
73
  debankName: "op",
71
74
  ankrName: "optimism",
75
+ zerionName: "optimism",
72
76
  chainId: 10,
73
77
  usdcAddress: "0x7f5c764cbc14f9669b88837ca1490cca17c31607",
74
78
  balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
@@ -90,6 +94,7 @@ export const networks: Network[] = [
90
94
  name: "Avalanche",
91
95
  debankName: "avax",
92
96
  ankrName: "avalanche",
97
+ zerionName: "avalanche",
93
98
  chainId: 43114,
94
99
  usdcAddress: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
95
100
  balanceResolverAddress: "0x63009f31D054E0ac9F321Cf0D642375236A4Bf1E",
@@ -111,6 +116,7 @@ export const networks: Network[] = [
111
116
  name: "BSC",
112
117
  debankName: "bsc",
113
118
  ankrName: "bsc",
119
+ zerionName: "binance-smart-chain",
114
120
  chainId: 56,
115
121
  explorerUrl: "https://bscscan.com",
116
122
  usdcAddress: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
@@ -131,6 +137,7 @@ export const networks: Network[] = [
131
137
  {
132
138
  name: "Gnosis",
133
139
  debankName: "xdai",
140
+ zerionName: "xdai",
134
141
  chainId: 100,
135
142
  balanceResolverAddress: "0xfaa244e276b1597f663975ed007ee4ff70d27849",
136
143
  explorerUrl: "https://gnosisscan.io",
@@ -171,6 +178,7 @@ export const networks: Network[] = [
171
178
  // {
172
179
  // name: "Aurora",
173
180
  // chainId: 1313161554,
181
+ // zerionName: "aurora",
174
182
  // explorerUrl: "https://explorer.mainnet.aurora.dev",
175
183
  // get serverRpcUrl() {
176
184
  // return process.env?.AURORA_RPC_URL || this.params.rpcUrls[0];
@@ -190,6 +198,7 @@ export const networks: Network[] = [
190
198
  {
191
199
  name: "Fantom",
192
200
  chainId: 250,
201
+ zerionName: "fantom",
193
202
  explorerUrl: "https://ftmscan.com",
194
203
  ankrName: "fantom",
195
204
  get serverRpcUrl() {
package/utils/utils.d.ts CHANGED
@@ -18,6 +18,7 @@ interface Network {
18
18
  name: string;
19
19
  debankName?: string;
20
20
  ankrName?: string;
21
+ zerionName?: string;
21
22
  chainId: ChainId;
22
23
  isAvocado?: boolean;
23
24
  serverRpcUrl: string | undefined;