@instadapp/avocado-base 0.0.0-dev.0e37fd2 → 0.0.0-dev.17ef354
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/components/ChainLogo.vue +1 -1
- package/package.json +1 -1
- package/utils/formatter.ts +49 -6
- package/utils/metadata.ts +44 -0
- package/utils/network.ts +39 -27
- package/utils/utils.d.ts +11 -1
package/components/ChainLogo.vue
CHANGED
package/package.json
CHANGED
package/utils/formatter.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export function formatPercent(
|
|
2
|
-
value
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
90
|
+
const formattedNumber = num.toFixed(fractionDigits || decimals);
|
|
91
|
+
|
|
92
|
+
return toBN(formattedNumber).toFormat();
|
|
93
|
+
}
|
|
51
94
|
}
|
package/utils/metadata.ts
CHANGED
|
@@ -7,6 +7,13 @@ 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 toChainId",
|
|
14
|
+
"uint256 amount",
|
|
15
|
+
"address receiver",
|
|
16
|
+
],
|
|
10
17
|
bridge: [
|
|
11
18
|
"uint256 amount",
|
|
12
19
|
"address receiver",
|
|
@@ -78,6 +85,29 @@ export const encodeTransferMetadata = (
|
|
|
78
85
|
return single ? encodeMultipleActions(data) : data;
|
|
79
86
|
};
|
|
80
87
|
|
|
88
|
+
export const encodeCrossTransferMetadata = (
|
|
89
|
+
params: CrossSendMetadataProps,
|
|
90
|
+
single = true
|
|
91
|
+
) => {
|
|
92
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
93
|
+
actionMetadataTypes["cross-transfer"],
|
|
94
|
+
[
|
|
95
|
+
params.fromToken,
|
|
96
|
+
params.toToken,
|
|
97
|
+
params.toChainId,
|
|
98
|
+
params.amount,
|
|
99
|
+
params.receiver,
|
|
100
|
+
]
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const data = encodeMetadata({
|
|
104
|
+
type: "cross-transfer",
|
|
105
|
+
encodedData,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return single ? encodeMultipleActions(data) : data;
|
|
109
|
+
};
|
|
110
|
+
|
|
81
111
|
export const encodeDeployMetadata = (single = true) => {
|
|
82
112
|
const data = encodeMetadata({
|
|
83
113
|
type: "deploy",
|
|
@@ -302,6 +332,7 @@ export const decodeMetadata = (data: string) => {
|
|
|
302
332
|
payload = {
|
|
303
333
|
type,
|
|
304
334
|
};
|
|
335
|
+
break;
|
|
305
336
|
|
|
306
337
|
case "permit2":
|
|
307
338
|
payload = {
|
|
@@ -311,6 +342,19 @@ export const decodeMetadata = (data: string) => {
|
|
|
311
342
|
amount: toBN(decodedData.amount).toFixed(),
|
|
312
343
|
expiration: decodedData.expiration,
|
|
313
344
|
};
|
|
345
|
+
break;
|
|
346
|
+
|
|
347
|
+
case "cross-transfer":
|
|
348
|
+
payload = {
|
|
349
|
+
type,
|
|
350
|
+
fromToken: decodedData.fromToken,
|
|
351
|
+
toToken: decodedData.toToken,
|
|
352
|
+
toChainId: decodedData.toChainId
|
|
353
|
+
? decodedData.toChainId.toString()
|
|
354
|
+
: null,
|
|
355
|
+
amount: toBN(decodedData.amount).toFixed(),
|
|
356
|
+
receiver: decodedData.receiver,
|
|
357
|
+
};
|
|
314
358
|
|
|
315
359
|
break;
|
|
316
360
|
}
|
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",
|
|
@@ -83,13 +87,14 @@ export const networks: Network[] = [
|
|
|
83
87
|
symbol: "ETH",
|
|
84
88
|
decimals: 18,
|
|
85
89
|
},
|
|
86
|
-
rpcUrls: ["https://
|
|
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,
|
|
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
|
-
|
|
140
|
+
zerionName: "xdai",
|
|
135
141
|
chainId: 100,
|
|
136
142
|
balanceResolverAddress: "0xfaa244e276b1597f663975ed007ee4ff70d27849",
|
|
137
143
|
explorerUrl: "https://gnosisscan.io",
|
|
@@ -169,29 +175,32 @@ export const networks: Network[] = [
|
|
|
169
175
|
},
|
|
170
176
|
},
|
|
171
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
|
+
// },
|
|
172
198
|
{
|
|
173
|
-
name: "
|
|
174
|
-
chainId: 1313161554,
|
|
175
|
-
explorerUrl: "https://explorer.mainnet.aurora.dev",
|
|
176
|
-
get serverRpcUrl() {
|
|
177
|
-
return process.env?.AURORA_RPC_URL || this.params.rpcUrls[0];
|
|
178
|
-
},
|
|
179
|
-
usdcAddress: "0xB12BFcA5A55806AaF64E99521918A4bf0fC40802",
|
|
180
|
-
balanceResolverAddress: "0xdF19Da523DA64bBE82eE0E4DFf00d676A8386474",
|
|
181
|
-
params: {
|
|
182
|
-
rpcUrls: ["https://mainnet.aurora.dev"],
|
|
183
|
-
chainName: "Aurora",
|
|
184
|
-
nativeCurrency: {
|
|
185
|
-
decimals: 18,
|
|
186
|
-
name: "Aurora ETH",
|
|
187
|
-
symbol: "AETH",
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: "Fantom Opera",
|
|
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
|
},
|
|
@@ -199,7 +208,7 @@ export const networks: Network[] = [
|
|
|
199
208
|
balanceResolverAddress: "0x929376c77a2fb8152375a089a4fccf84ff481479",
|
|
200
209
|
params: {
|
|
201
210
|
rpcUrls: ["https://rpc.ankr.com/fantom"],
|
|
202
|
-
chainName: "Fantom
|
|
211
|
+
chainName: "Fantom",
|
|
203
212
|
nativeCurrency: {
|
|
204
213
|
name: "Fantom",
|
|
205
214
|
symbol: "FTM",
|
|
@@ -274,13 +283,16 @@ export const RPCMap = networks.reduce((acc, network) => {
|
|
|
274
283
|
|
|
275
284
|
export const networkIds = networks.map((network) => network.chainId);
|
|
276
285
|
|
|
277
|
-
const rpcInstances: Record<string, ethers.providers.
|
|
278
|
-
const serverRpcInstances: Record<
|
|
286
|
+
const rpcInstances: Record<string, ethers.providers.StaticJsonRpcProvider> = {};
|
|
287
|
+
const serverRpcInstances: Record<
|
|
288
|
+
string,
|
|
289
|
+
ethers.providers.StaticJsonRpcProvider
|
|
290
|
+
> = {};
|
|
279
291
|
|
|
280
292
|
export const getServerRpcProvider = (chainId: number | string) => {
|
|
281
293
|
if (!rpcInstances[chainId]) {
|
|
282
294
|
const network = networks.find((n) => n.chainId == chainId);
|
|
283
|
-
serverRpcInstances[chainId] = new ethers.providers.
|
|
295
|
+
serverRpcInstances[chainId] = new ethers.providers.StaticJsonRpcProvider(
|
|
284
296
|
network?.serverRpcUrl
|
|
285
297
|
);
|
|
286
298
|
}
|
|
@@ -290,7 +302,7 @@ export const getServerRpcProvider = (chainId: number | string) => {
|
|
|
290
302
|
|
|
291
303
|
export const getRpcProvider = (chainId: number | string) => {
|
|
292
304
|
if (!rpcInstances[chainId]) {
|
|
293
|
-
rpcInstances[chainId] = new ethers.providers.
|
|
305
|
+
rpcInstances[chainId] = new ethers.providers.StaticJsonRpcProvider(
|
|
294
306
|
getRpcURLByChainId(Number(chainId))
|
|
295
307
|
);
|
|
296
308
|
}
|
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,14 @@ type SendMetadataProps = {
|
|
|
54
55
|
receiver: string;
|
|
55
56
|
};
|
|
56
57
|
|
|
58
|
+
type CrossSendMetadataProps = {
|
|
59
|
+
fromToken: string;
|
|
60
|
+
toToken: string;
|
|
61
|
+
toChainId: string;
|
|
62
|
+
amount: string;
|
|
63
|
+
receiver: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
57
66
|
type UpgradeMetadataProps = {
|
|
58
67
|
version: string;
|
|
59
68
|
walletImpl: string;
|
|
@@ -94,7 +103,8 @@ type MetadataProps = {
|
|
|
94
103
|
| "upgrade"
|
|
95
104
|
| "dapp"
|
|
96
105
|
| "deploy"
|
|
97
|
-
| "permit2"
|
|
106
|
+
| "permit2"
|
|
107
|
+
| "cross-transfer";
|
|
98
108
|
encodedData: string;
|
|
99
109
|
version?: string;
|
|
100
110
|
};
|