@instadapp/avocado-base 0.0.0-dev.c071c45 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.c071c45",
3
+ "version": "0.0.0-dev.e144f0f",
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,50 @@ 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(value: string | number, fractionDigits?: number) {
46
65
  if (!value) {
47
66
  value = "0";
48
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
+ }
49
89
 
50
- return toBN(value).decimalPlaces(decimalPlaces).toFormat();
90
+ const formattedNumber = num.toFixed(fractionDigits || decimals);
91
+
92
+ return toBN(formattedNumber).toFormat();
93
+ }
51
94
  }
package/utils/metadata.ts CHANGED
@@ -7,6 +7,12 @@ const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
7
7
 
8
8
  const actionMetadataTypes = {
9
9
  transfer: ["address token", "uint256 amount", "address receiver"],
10
+ "cross-transfer": [
11
+ "address fromToken",
12
+ "address toToken",
13
+ "uint256 amount",
14
+ "address receiver",
15
+ ],
10
16
  bridge: [
11
17
  "uint256 amount",
12
18
  "address receiver",
@@ -78,6 +84,23 @@ export const encodeTransferMetadata = (
78
84
  return single ? encodeMultipleActions(data) : data;
79
85
  };
80
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
+
81
104
  export const encodeDeployMetadata = (single = true) => {
82
105
  const data = encodeMetadata({
83
106
  type: "deploy",
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,7 +137,7 @@ export const networks: Network[] = [
131
137
  {
132
138
  name: "Gnosis",
133
139
  debankName: "xdai",
134
- ankrName: "gnosis",
140
+ zerionName: "xdai",
135
141
  chainId: 100,
136
142
  balanceResolverAddress: "0xfaa244e276b1597f663975ed007ee4ff70d27849",
137
143
  explorerUrl: "https://gnosisscan.io",
@@ -172,6 +178,7 @@ export const networks: Network[] = [
172
178
  // {
173
179
  // name: "Aurora",
174
180
  // chainId: 1313161554,
181
+ // zerionName: "aurora",
175
182
  // explorerUrl: "https://explorer.mainnet.aurora.dev",
176
183
  // get serverRpcUrl() {
177
184
  // return process.env?.AURORA_RPC_URL || this.params.rpcUrls[0];
@@ -191,7 +198,9 @@ export const networks: Network[] = [
191
198
  {
192
199
  name: "Fantom",
193
200
  chainId: 250,
201
+ zerionName: "fantom",
194
202
  explorerUrl: "https://ftmscan.com",
203
+ ankrName: "fantom",
195
204
  get serverRpcUrl() {
196
205
  return process.env?.FANTOM_RPC_URL || this.params.rpcUrls[0];
197
206
  },
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;
@@ -54,6 +55,13 @@ type SendMetadataProps = {
54
55
  receiver: string;
55
56
  };
56
57
 
58
+ type CrossSendMetadatProps = {
59
+ fromToken: string;
60
+ toToken: string;
61
+ amount: string;
62
+ receiver: string;
63
+ };
64
+
57
65
  type UpgradeMetadataProps = {
58
66
  version: string;
59
67
  walletImpl: string;
@@ -94,7 +102,8 @@ type MetadataProps = {
94
102
  | "upgrade"
95
103
  | "dapp"
96
104
  | "deploy"
97
- | "permit2";
105
+ | "permit2"
106
+ | "cross-transfer";
98
107
  encodedData: string;
99
108
  version?: string;
100
109
  };