@instadapp/avocado-base 0.0.0-dev.9e8d2fb → 0.0.0-dev.a1a59bd
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/abi/forwarder.json +1253 -149
- package/app.vue +20 -0
- package/assets/images/icons/arrow-left.svg +5 -0
- package/assets/images/icons/arrow-right.svg +5 -0
- package/assets/images/icons/avocado.svg +4 -0
- package/assets/images/icons/bridge-2.svg +3 -0
- package/assets/images/icons/bridge.svg +7 -0
- package/assets/images/icons/calendar.svg +8 -0
- package/assets/images/icons/check-circle.svg +4 -0
- package/assets/images/icons/chevron-down.svg +4 -0
- package/assets/images/icons/clipboard.svg +7 -0
- package/assets/images/icons/clock-circle.svg +5 -0
- package/assets/images/icons/copy.svg +5 -0
- package/assets/images/icons/error-circle.svg +6 -0
- package/assets/images/icons/exclamation-circle.svg +13 -0
- package/assets/images/icons/exclamation-octagon.svg +13 -0
- package/assets/images/icons/exclamation-triangle.svg +5 -0
- package/assets/images/icons/external-link.svg +6 -0
- package/assets/images/icons/eye.svg +4 -0
- package/assets/images/icons/flowers.svg +8 -0
- package/assets/images/icons/gas-emoji.svg +193 -0
- package/assets/images/icons/gas.svg +7 -0
- package/assets/images/icons/gift.svg +153 -0
- package/assets/images/icons/globe.svg +110 -0
- package/assets/images/icons/hamburger.svg +6 -0
- package/assets/images/icons/logout.svg +3 -0
- package/assets/images/icons/moon.svg +3 -0
- package/assets/images/icons/network.svg +13 -0
- package/assets/images/icons/options.svg +5 -0
- package/assets/images/icons/plus.svg +5 -0
- package/assets/images/icons/power-off-bg.svg +24 -0
- package/assets/images/icons/power-off.svg +19 -0
- package/assets/images/icons/power-on.svg +19 -0
- package/assets/images/icons/qr.svg +20 -0
- package/assets/images/icons/question-circle.svg +14 -0
- package/assets/images/icons/refresh.svg +6 -0
- package/assets/images/icons/search.svg +12 -0
- package/assets/images/icons/sun.svg +3 -0
- package/assets/images/icons/wave.svg +214 -0
- package/assets/images/icons/x.svg +5 -0
- package/components/ActionMetadata.vue +53 -0
- package/components/ChainLogo.vue +141 -1
- package/components/metadata/Bridge.vue +39 -0
- package/components/metadata/CrossTransfer.vue +67 -0
- package/components/metadata/GasTopup.vue +33 -0
- package/components/metadata/Permit2.vue +37 -0
- package/components/metadata/Swap.vue +67 -0
- package/components/metadata/Transfer.vue +46 -0
- package/components.d.ts +13 -0
- package/contracts/Forwarder.ts +856 -2
- package/contracts/factories/Forwarder__factory.ts +816 -16
- package/nuxt.config.ts +18 -2
- package/package.json +7 -3
- package/server/utils/index.ts +2 -0
- package/utils/avocado.ts +2 -0
- package/utils/bignumber.ts +51 -0
- package/utils/formatter.ts +94 -0
- package/utils/helper.ts +26 -0
- package/utils/metadata.ts +278 -125
- package/utils/network.ts +130 -67
- package/utils/services.ts +14 -0
- package/utils/utils.d.ts +50 -7
- package/utils/index.ts +0 -93
package/nuxt.config.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
|
-
|
|
2
|
+
import ViteComponents from "unplugin-vue-components/vite";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export default defineNuxtConfig({
|
|
5
|
+
modules: ["@nuxtjs/tailwindcss", "nuxt-svgo", "@vueuse/nuxt"],
|
|
6
|
+
svgo: {
|
|
7
|
+
defaultImport: "component",
|
|
8
|
+
autoImportPath: "./assets/images/icons",
|
|
9
|
+
svgoConfig: {
|
|
10
|
+
plugins: ["prefixIds"],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
vite: {
|
|
14
|
+
plugins: [
|
|
15
|
+
ViteComponents({
|
|
16
|
+
dts: true,
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instadapp/avocado-base",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.a1a59bd",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"types": "global.d.ts",
|
|
@@ -14,12 +14,16 @@
|
|
|
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
|
-
"nuxt": "^3.
|
|
19
|
+
"nuxt": "^3.6.1",
|
|
20
|
+
"nuxt-svgo": "^3.1.0",
|
|
19
21
|
"rimraf": "^3.0.2",
|
|
20
|
-
"typechain": "^8.1.1"
|
|
22
|
+
"typechain": "^8.1.1",
|
|
23
|
+
"unplugin-vue-components": "^0.25.1"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
26
|
+
"@vueuse/nuxt": "^10.2.0",
|
|
23
27
|
"bignumber.js": "^9.1.1",
|
|
24
28
|
"ethers": "^5.7.2"
|
|
25
29
|
}
|
package/server/utils/index.ts
CHANGED
package/utils/avocado.ts
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { BigNumber as BN } from "ethers";
|
|
3
|
+
|
|
4
|
+
type CombinedBigNumber = BigNumber | string | number;
|
|
5
|
+
|
|
6
|
+
export const toBN = (value: BigNumber.Value | BN) =>
|
|
7
|
+
new BigNumber(BN.isBigNumber(value) ? value.toString() : value);
|
|
8
|
+
export const isZero = (value: BigNumber.Value | BN) => toBN(value).isZero();
|
|
9
|
+
export const times = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
10
|
+
toBN(a).times(toBN(b));
|
|
11
|
+
export const minus = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
12
|
+
toBN(a).minus(toBN(b));
|
|
13
|
+
export const plus = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
14
|
+
toBN(a).plus(toBN(b));
|
|
15
|
+
export const lte = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
16
|
+
toBN(a).lte(toBN(b));
|
|
17
|
+
export const gte = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
18
|
+
toBN(a).gte(toBN(b));
|
|
19
|
+
export const div = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
20
|
+
toBN(a).div(toBN(b));
|
|
21
|
+
export const lt = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
22
|
+
toBN(a).lt(toBN(b));
|
|
23
|
+
export const gt = (a: BigNumber.Value | BN, b: BigNumber.Value | BN) =>
|
|
24
|
+
toBN(a).gt(toBN(b));
|
|
25
|
+
export const ensureValue = (value: any) => {
|
|
26
|
+
if (!value) return toBN("0");
|
|
27
|
+
if (toBN(value).isNaN()) return toBN("0");
|
|
28
|
+
|
|
29
|
+
return toBN(value);
|
|
30
|
+
};
|
|
31
|
+
export const max = (...args: BigNumber.Value[]) => {
|
|
32
|
+
return BigNumber.max(...args);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function pow(value: CombinedBigNumber, exponent: string | number) {
|
|
36
|
+
return toBN(value).pow(toBN(exponent));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function toWei(val: CombinedBigNumber, decimals: number): string {
|
|
40
|
+
const num = toBN(val);
|
|
41
|
+
const multiplier = pow(10, decimals);
|
|
42
|
+
return times(num, multiplier).toFixed(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function fromWei(val: CombinedBigNumber, decimal = 18) {
|
|
46
|
+
return toBN(val).div(new BigNumber(10).pow(decimal));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function abs(value: CombinedBigNumber) {
|
|
50
|
+
return toBN(value).abs();
|
|
51
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export function formatPercent(
|
|
2
|
+
value?: number | string,
|
|
3
|
+
fractionDigits = 2,
|
|
4
|
+
maxValue = null
|
|
5
|
+
) {
|
|
6
|
+
if (!value || isZero(value)) return "0.00%";
|
|
7
|
+
|
|
8
|
+
const valueAsNumber = toBN(value).toNumber();
|
|
9
|
+
|
|
10
|
+
if (maxValue && gt(times(valueAsNumber, "100"), maxValue))
|
|
11
|
+
return `>${maxValue}%`;
|
|
12
|
+
|
|
13
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
14
|
+
style: "percent",
|
|
15
|
+
minimumFractionDigits: fractionDigits,
|
|
16
|
+
maximumFractionDigits: fractionDigits,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return formatter.format(valueAsNumber);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function shortenHash(hash: string, length: number = 4) {
|
|
23
|
+
if (!hash) return;
|
|
24
|
+
if (hash.length < 12) return hash;
|
|
25
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
|
26
|
+
const shortened =
|
|
27
|
+
hash.substr(0, beginningChars) + "..." + hash.substr(-length);
|
|
28
|
+
return shortened;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formatUsd(value: any, fractionDigits = 2) {
|
|
32
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
33
|
+
style: "currency",
|
|
34
|
+
currency: "USD",
|
|
35
|
+
minimumFractionDigits: fractionDigits,
|
|
36
|
+
maximumFractionDigits: fractionDigits,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return formatter.format(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function signedNumber(numb: string | number) {
|
|
43
|
+
return new Intl.NumberFormat("en-US", {
|
|
44
|
+
signDisplay: "exceptZero",
|
|
45
|
+
}).format(toBN(numb).toNumber());
|
|
46
|
+
}
|
|
47
|
+
|
|
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) {
|
|
65
|
+
if (!value) {
|
|
66
|
+
value = "0";
|
|
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
|
+
}
|
|
89
|
+
|
|
90
|
+
const formattedNumber = num.toFixed(fractionDigits || decimals);
|
|
91
|
+
|
|
92
|
+
return toBN(formattedNumber).toFormat();
|
|
93
|
+
}
|
|
94
|
+
}
|
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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
|
-
import { Forwarder__factory } from "
|
|
3
|
-
import { toBN } from "./index";
|
|
2
|
+
import { Forwarder__factory } from "../contracts";
|
|
4
3
|
|
|
5
4
|
const multiMetadataTypes = ["bytes[]"];
|
|
6
5
|
|
|
@@ -8,6 +7,13 @@ const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
|
8
7
|
|
|
9
8
|
const actionMetadataTypes = {
|
|
10
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
|
+
],
|
|
11
17
|
bridge: [
|
|
12
18
|
"uint256 amount",
|
|
13
19
|
"address receiver",
|
|
@@ -28,6 +34,7 @@ const actionMetadataTypes = {
|
|
|
28
34
|
"gas-topup": ["uint256 amount", "address token", "address onBehalf"],
|
|
29
35
|
upgrade: ["bytes32 version", "address walletImpl"],
|
|
30
36
|
dapp: ["string name", "string url"],
|
|
37
|
+
auth: ["address address", "uint256 chainId", "bool remove"],
|
|
31
38
|
deploy: [],
|
|
32
39
|
permit2: [
|
|
33
40
|
"address token",
|
|
@@ -35,6 +42,8 @@ const actionMetadataTypes = {
|
|
|
35
42
|
"uint160 amount",
|
|
36
43
|
"uint48 expiration",
|
|
37
44
|
],
|
|
45
|
+
"instadapp-pro": ["string castDetails"],
|
|
46
|
+
reject: ["string reason"],
|
|
38
47
|
};
|
|
39
48
|
|
|
40
49
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -79,6 +88,60 @@ export const encodeTransferMetadata = (
|
|
|
79
88
|
return single ? encodeMultipleActions(data) : data;
|
|
80
89
|
};
|
|
81
90
|
|
|
91
|
+
export const encodeRejectMetadata = (reason: string, single = true) => {
|
|
92
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
93
|
+
actionMetadataTypes.reject,
|
|
94
|
+
[reason]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const data = encodeMetadata({
|
|
98
|
+
type: "reject",
|
|
99
|
+
encodedData,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return single ? encodeMultipleActions(data) : data;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const encodeCrossTransferMetadata = (
|
|
106
|
+
params: CrossSendMetadataProps,
|
|
107
|
+
single = true
|
|
108
|
+
) => {
|
|
109
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
110
|
+
actionMetadataTypes["cross-transfer"],
|
|
111
|
+
[
|
|
112
|
+
params.fromToken,
|
|
113
|
+
params.toToken,
|
|
114
|
+
params.toChainId,
|
|
115
|
+
params.amount,
|
|
116
|
+
params.receiver,
|
|
117
|
+
]
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const data = encodeMetadata({
|
|
121
|
+
type: "cross-transfer",
|
|
122
|
+
encodedData,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return single ? encodeMultipleActions(data) : data;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const encodeAuthMetadata = (
|
|
129
|
+
params: AuthMetadataProps,
|
|
130
|
+
single = true
|
|
131
|
+
) => {
|
|
132
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
133
|
+
actionMetadataTypes["auth"],
|
|
134
|
+
[params.address, params.chainId, params.remove]
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const data = encodeMetadata({
|
|
138
|
+
type: "auth",
|
|
139
|
+
encodedData,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return single ? encodeMultipleActions(data) : data;
|
|
143
|
+
};
|
|
144
|
+
|
|
82
145
|
export const encodeDeployMetadata = (single = true) => {
|
|
83
146
|
const data = encodeMetadata({
|
|
84
147
|
type: "deploy",
|
|
@@ -194,134 +257,224 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
194
257
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
195
258
|
};
|
|
196
259
|
|
|
197
|
-
export const
|
|
260
|
+
export const decodeData = (data: string) => {
|
|
198
261
|
try {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
262
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
263
|
+
|
|
264
|
+
return parseMetadata(metadata);
|
|
265
|
+
} catch (e) {
|
|
266
|
+
// console.log(e);
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export const decodeMetadata = (metadata: string) => {
|
|
272
|
+
try {
|
|
273
|
+
return parseMetadata(metadata);
|
|
274
|
+
} catch (e) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const getMetadataFromData = (data: string) => {
|
|
280
|
+
const iface = Forwarder__factory.createInterface();
|
|
281
|
+
let metadata = "0x";
|
|
282
|
+
|
|
283
|
+
if (data.startsWith("0x18e7f485")) {
|
|
284
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
285
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
286
|
+
return null;
|
|
287
|
+
} else {
|
|
288
|
+
metadata = executeData.metadata_;
|
|
289
|
+
}
|
|
290
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
291
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
292
|
+
if (
|
|
293
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
294
|
+
!executeDataV2.params_.metadata
|
|
295
|
+
) {
|
|
296
|
+
return null;
|
|
297
|
+
} else {
|
|
298
|
+
metadata = executeDataV2.params_.metadata;
|
|
299
|
+
}
|
|
300
|
+
} else if (data.startsWith("0x85114d53")) {
|
|
301
|
+
const executeDataV3 = iface.decodeFunctionData("executeV3", data);
|
|
302
|
+
if (
|
|
303
|
+
executeDataV3.params_.metadata === "0x" ||
|
|
304
|
+
!executeDataV3.params_.metadata
|
|
305
|
+
) {
|
|
306
|
+
return null;
|
|
307
|
+
} else {
|
|
308
|
+
metadata = executeDataV3.params_.metadata;
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
const executeDataMultisigV3 = iface.decodeFunctionData(
|
|
312
|
+
"executeMultisigV3",
|
|
313
|
+
data
|
|
314
|
+
);
|
|
315
|
+
if (
|
|
316
|
+
executeDataMultisigV3.params_.metadata === "0x" ||
|
|
317
|
+
!executeDataMultisigV3.params_.metadata
|
|
318
|
+
) {
|
|
319
|
+
return null;
|
|
212
320
|
} else {
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
executeDataV2.params_.metadata === "0x" ||
|
|
216
|
-
!executeDataV2.params_.metadata
|
|
217
|
-
) {
|
|
218
|
-
return null;
|
|
219
|
-
} else {
|
|
220
|
-
metadata = executeDataV2.params_.metadata;
|
|
221
|
-
}
|
|
321
|
+
metadata = executeDataMultisigV3.params_.metadata;
|
|
222
322
|
}
|
|
323
|
+
}
|
|
223
324
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
325
|
+
return metadata;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const parseMetadata = (metadata: string) => {
|
|
329
|
+
const metadataArr = [];
|
|
330
|
+
let payload = {};
|
|
331
|
+
|
|
332
|
+
const [decodedMultiMetadata = []] =
|
|
333
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
334
|
+
multiMetadataTypes,
|
|
335
|
+
metadata
|
|
336
|
+
) as string[]) || [];
|
|
337
|
+
|
|
338
|
+
for (let metadata of decodedMultiMetadata) {
|
|
339
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
340
|
+
metadataTypes,
|
|
341
|
+
metadata
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
const type = ethers.utils.parseBytes32String(
|
|
345
|
+
decodedMetadata.type
|
|
346
|
+
) as keyof typeof actionMetadataTypes;
|
|
347
|
+
|
|
348
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
349
|
+
actionMetadataTypes[type],
|
|
350
|
+
decodedMetadata.data
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
switch (type) {
|
|
354
|
+
case "transfer":
|
|
355
|
+
payload = {
|
|
356
|
+
type,
|
|
357
|
+
token: decodedData.token,
|
|
358
|
+
amount: toBN(decodedData.amount).toFixed(),
|
|
359
|
+
receiver: decodedData.receiver,
|
|
360
|
+
};
|
|
361
|
+
break;
|
|
362
|
+
case "bridge":
|
|
363
|
+
payload = {
|
|
364
|
+
type,
|
|
365
|
+
amount: toBN(decodedData.amount).toFixed(),
|
|
366
|
+
receiver: decodedData.receiver,
|
|
367
|
+
toToken: decodedData.toToken,
|
|
368
|
+
fromToken: decodedData.fromToken,
|
|
369
|
+
toChainId: decodedData.toChainId
|
|
370
|
+
? decodedData.toChainId.toString()
|
|
371
|
+
: null,
|
|
372
|
+
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
373
|
+
};
|
|
374
|
+
break;
|
|
375
|
+
case "swap":
|
|
376
|
+
payload = {
|
|
377
|
+
type,
|
|
378
|
+
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
379
|
+
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
380
|
+
buyToken: decodedData.buyToken,
|
|
381
|
+
sellToken: decodedData.sellToken,
|
|
382
|
+
receiver: decodedData.receiver,
|
|
383
|
+
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
384
|
+
};
|
|
385
|
+
break;
|
|
386
|
+
case "upgrade":
|
|
387
|
+
payload = {
|
|
388
|
+
type,
|
|
389
|
+
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
390
|
+
walletImpl: decodedData?.walletImpl,
|
|
391
|
+
};
|
|
392
|
+
break;
|
|
393
|
+
case "gas-topup":
|
|
394
|
+
payload = {
|
|
395
|
+
type,
|
|
396
|
+
amount: toBN(decodedData.amount).toFixed(),
|
|
397
|
+
token: decodedData.token,
|
|
398
|
+
onBehalf: decodedData.onBehalf,
|
|
399
|
+
};
|
|
400
|
+
break;
|
|
401
|
+
case "dapp":
|
|
402
|
+
payload = {
|
|
403
|
+
type,
|
|
404
|
+
name: decodedData?.name,
|
|
405
|
+
url: decodedData?.url,
|
|
406
|
+
};
|
|
407
|
+
break;
|
|
408
|
+
case "deploy":
|
|
409
|
+
payload = {
|
|
410
|
+
type,
|
|
411
|
+
};
|
|
412
|
+
break;
|
|
413
|
+
|
|
414
|
+
case "permit2":
|
|
415
|
+
payload = {
|
|
416
|
+
type,
|
|
417
|
+
token: decodedData.token,
|
|
418
|
+
spender: decodedData.spender,
|
|
419
|
+
amount: toBN(decodedData.amount).toFixed(),
|
|
420
|
+
expiration: decodedData.expiration,
|
|
421
|
+
};
|
|
422
|
+
break;
|
|
423
|
+
|
|
424
|
+
case "cross-transfer":
|
|
425
|
+
payload = {
|
|
426
|
+
type,
|
|
427
|
+
fromToken: decodedData.fromToken,
|
|
428
|
+
toToken: decodedData.toToken,
|
|
429
|
+
toChainId: decodedData.toChainId
|
|
430
|
+
? decodedData.toChainId.toString()
|
|
431
|
+
: null,
|
|
432
|
+
amount: toBN(decodedData.amount).toFixed(),
|
|
433
|
+
receiver: decodedData.receiver,
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
break;
|
|
437
|
+
case "auth":
|
|
438
|
+
payload = {
|
|
439
|
+
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
440
|
+
address: decodedData.address,
|
|
441
|
+
chainId: decodedData.chainId ? decodedData.chainId.toString() : null,
|
|
442
|
+
remove: decodedData.remove,
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
break;
|
|
446
|
+
case "instadapp-pro":
|
|
447
|
+
payload = {
|
|
448
|
+
type,
|
|
449
|
+
castDetails: decodedData.castDetails,
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
break;
|
|
453
|
+
|
|
454
|
+
case "reject":
|
|
455
|
+
payload = {
|
|
456
|
+
type,
|
|
457
|
+
reason: decodedData.reason,
|
|
458
|
+
};
|
|
459
|
+
break;
|
|
320
460
|
}
|
|
321
461
|
|
|
322
|
-
|
|
323
|
-
} catch (e) {
|
|
324
|
-
console.log(e);
|
|
325
|
-
return null;
|
|
462
|
+
metadataArr.push(payload);
|
|
326
463
|
}
|
|
464
|
+
|
|
465
|
+
return metadataArr;
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
470
|
+
* @param {string} txType - The input sentence to modify
|
|
471
|
+
*
|
|
472
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
473
|
+
*/
|
|
474
|
+
export const formatTxType = (txType: string) => {
|
|
475
|
+
const finalSentence = txType
|
|
476
|
+
.replace("-", " ")
|
|
477
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
478
|
+
|
|
479
|
+
return finalSentence;
|
|
327
480
|
};
|