@instadapp/avocado-base 0.0.17 → 0.0.19
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 +1 -1
- package/utils/formatter.ts +22 -13
- package/utils/metadata.ts +44 -0
- package/utils/utils.d.ts +10 -1
package/package.json
CHANGED
package/utils/formatter.ts
CHANGED
|
@@ -61,25 +61,34 @@ function getFractionDigits(value: string | number) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function formatDecimal(
|
|
65
|
-
value: string | number,
|
|
66
|
-
fractionDigits = getFractionDigits(value)
|
|
67
|
-
) {
|
|
64
|
+
export function formatDecimal(value: string | number, fractionDigits?: number) {
|
|
68
65
|
if (!value) {
|
|
69
66
|
value = "0";
|
|
70
67
|
}
|
|
71
|
-
let formatter;
|
|
72
68
|
if (lt(value, "0.0001") && gt(value, "0")) {
|
|
73
69
|
return "< 0.0001";
|
|
74
70
|
} else {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
minimumFractionDigits: fractionDigits,
|
|
78
|
-
maximumFractionDigits: fractionDigits,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
71
|
+
const num = toBN(value);
|
|
72
|
+
let decimals;
|
|
81
73
|
|
|
82
|
-
|
|
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
|
+
}
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
const formattedNumber = num.toFixed(fractionDigits || decimals);
|
|
91
|
+
|
|
92
|
+
return toBN(formattedNumber).toFormat();
|
|
93
|
+
}
|
|
85
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/utils.d.ts
CHANGED
|
@@ -55,6 +55,14 @@ type SendMetadataProps = {
|
|
|
55
55
|
receiver: string;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
type CrossSendMetadataProps = {
|
|
59
|
+
fromToken: string;
|
|
60
|
+
toToken: string;
|
|
61
|
+
toChainId: string;
|
|
62
|
+
amount: string;
|
|
63
|
+
receiver: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
58
66
|
type UpgradeMetadataProps = {
|
|
59
67
|
version: string;
|
|
60
68
|
walletImpl: string;
|
|
@@ -95,7 +103,8 @@ type MetadataProps = {
|
|
|
95
103
|
| "upgrade"
|
|
96
104
|
| "dapp"
|
|
97
105
|
| "deploy"
|
|
98
|
-
| "permit2"
|
|
106
|
+
| "permit2"
|
|
107
|
+
| "cross-transfer";
|
|
99
108
|
encodedData: string;
|
|
100
109
|
version?: string;
|
|
101
110
|
};
|