@instadapp/avocado-base 0.0.0-dev.d36b11d → 0.0.0-dev.d63c845
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 +7 -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/change-threshold.svg +4 -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/cross-transfer.svg +7 -0
- package/assets/images/icons/dapp.svg +4 -0
- package/assets/images/icons/deploy.svg +12 -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 +14 -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/instadapp-pro.svg +4 -0
- package/assets/images/icons/logout.svg +3 -0
- package/assets/images/icons/moon.svg +3 -0
- package/assets/images/icons/multi-send.svg +7 -0
- package/assets/images/icons/network.svg +13 -0
- package/assets/images/icons/options.svg +5 -0
- package/assets/images/icons/permit-sign.svg +11 -0
- package/assets/images/icons/plus-circle.svg +6 -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/reject-proposal.svg +6 -0
- package/assets/images/icons/search.svg +12 -0
- package/assets/images/icons/sun.svg +3 -0
- package/assets/images/icons/transfer.svg +5 -0
- package/assets/images/icons/trash-2.svg +8 -0
- package/assets/images/icons/upgrade.svg +4 -0
- package/assets/images/icons/wave.svg +214 -0
- package/assets/images/icons/x.svg +5 -0
- package/components/ActionLogo.vue +38 -0
- package/components/ActionMetadata.vue +73 -0
- package/components/ChainLogo.vue +1 -1
- package/components/CopyClipboard.vue +64 -0
- 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 +17 -1
- package/package.json +6 -3
- package/utils/avocado.ts +2 -0
- package/utils/bignumber.ts +20 -0
- package/utils/formatter.ts +1 -1
- package/utils/helper.ts +7 -0
- package/utils/metadata.ts +314 -148
- package/utils/network.ts +18 -3
- package/utils/services.ts +14 -0
- package/utils/utils.d.ts +127 -107
package/nuxt.config.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
|
+
import ViteComponents from "unplugin-vue-components/vite";
|
|
3
|
+
|
|
2
4
|
export default defineNuxtConfig({
|
|
3
|
-
modules: ["@nuxtjs/tailwindcss"],
|
|
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
|
+
},
|
|
4
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.d63c845",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"types": "global.d.ts",
|
|
@@ -16,11 +16,14 @@
|
|
|
16
16
|
"@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
|
|
17
17
|
"@nuxtjs/tailwindcss": "^6.6.5",
|
|
18
18
|
"@typechain/ethers-v5": "^10.2.0",
|
|
19
|
-
"nuxt": "^3.
|
|
19
|
+
"nuxt": "^3.6.1",
|
|
20
|
+
"nuxt-svgo": "^3.1.0",
|
|
20
21
|
"rimraf": "^3.0.2",
|
|
21
|
-
"typechain": "^8.1.1"
|
|
22
|
+
"typechain": "^8.1.1",
|
|
23
|
+
"unplugin-vue-components": "^0.25.1"
|
|
22
24
|
},
|
|
23
25
|
"dependencies": {
|
|
26
|
+
"@vueuse/nuxt": "^10.2.0",
|
|
24
27
|
"bignumber.js": "^9.1.1",
|
|
25
28
|
"ethers": "^5.7.2"
|
|
26
29
|
}
|
package/utils/avocado.ts
CHANGED
package/utils/bignumber.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
2
|
import { BigNumber as BN } from "ethers";
|
|
3
3
|
|
|
4
|
+
type CombinedBigNumber = BigNumber | string | number;
|
|
5
|
+
|
|
4
6
|
export const toBN = (value: BigNumber.Value | BN) =>
|
|
5
7
|
new BigNumber(BN.isBigNumber(value) ? value.toString() : value);
|
|
6
8
|
export const isZero = (value: BigNumber.Value | BN) => toBN(value).isZero();
|
|
@@ -29,3 +31,21 @@ export const ensureValue = (value: any) => {
|
|
|
29
31
|
export const max = (...args: BigNumber.Value[]) => {
|
|
30
32
|
return BigNumber.max(...args);
|
|
31
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
|
+
}
|
package/utils/formatter.ts
CHANGED
package/utils/helper.ts
CHANGED
|
@@ -52,3 +52,10 @@ export function onImageError(this: HTMLImageElement) {
|
|
|
52
52
|
parentElement.classList.add("bg-gray-300");
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
export function formatMultipleAddresses(addresses: string[], shorten = true) {
|
|
57
|
+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' })
|
|
58
|
+
const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
|
|
59
|
+
|
|
60
|
+
return formattedString
|
|
61
|
+
}
|
package/utils/metadata.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
|
-
import { Forwarder__factory } from "
|
|
2
|
+
import { Forwarder__factory } from "../contracts";
|
|
3
|
+
|
|
4
|
+
export const MetadataEnums = {
|
|
5
|
+
"transfer": "transfer",
|
|
6
|
+
"bridge": "bridge",
|
|
7
|
+
"swap": "swap",
|
|
8
|
+
"gas-topup": "gas-topup",
|
|
9
|
+
"upgrade": "upgrade",
|
|
10
|
+
"dapp": "dapp",
|
|
11
|
+
"deploy": "deploy",
|
|
12
|
+
"permit2": "permit2",
|
|
13
|
+
"cross-transfer": "cross-transfer",
|
|
14
|
+
"auth": "auth",
|
|
15
|
+
"rejection": "rejection",
|
|
16
|
+
"instadapp-pro": "instadapp-pro",
|
|
17
|
+
"add-signers": "add-signers",
|
|
18
|
+
"remove-signers": "remove-signers",
|
|
19
|
+
"change-threshold": "change-threshold",
|
|
20
|
+
} as const;
|
|
3
21
|
|
|
4
22
|
const multiMetadataTypes = ["bytes[]"];
|
|
5
23
|
|
|
6
24
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
7
25
|
|
|
8
|
-
const actionMetadataTypes = {
|
|
26
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
9
27
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
10
28
|
"cross-transfer": [
|
|
11
29
|
"address fromToken",
|
|
@@ -34,6 +52,7 @@ const actionMetadataTypes = {
|
|
|
34
52
|
"gas-topup": ["uint256 amount", "address token", "address onBehalf"],
|
|
35
53
|
upgrade: ["bytes32 version", "address walletImpl"],
|
|
36
54
|
dapp: ["string name", "string url"],
|
|
55
|
+
auth: ["address address", "uint256 chainId", "bool remove"],
|
|
37
56
|
deploy: [],
|
|
38
57
|
permit2: [
|
|
39
58
|
"address token",
|
|
@@ -41,6 +60,11 @@ const actionMetadataTypes = {
|
|
|
41
60
|
"uint160 amount",
|
|
42
61
|
"uint48 expiration",
|
|
43
62
|
],
|
|
63
|
+
"instadapp-pro": ["string castDetails"],
|
|
64
|
+
'add-signers': ['address[] signers'],
|
|
65
|
+
'remove-signers': ['address[] signers'],
|
|
66
|
+
'change-threshold': ['uint8 count'],
|
|
67
|
+
'rejection': ['bytes32 id'],
|
|
44
68
|
};
|
|
45
69
|
|
|
46
70
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -61,7 +85,7 @@ export const encodeDappMetadata = (
|
|
|
61
85
|
);
|
|
62
86
|
|
|
63
87
|
const data = encodeMetadata({
|
|
64
|
-
type:
|
|
88
|
+
type: MetadataEnums.dapp,
|
|
65
89
|
encodedData,
|
|
66
90
|
});
|
|
67
91
|
|
|
@@ -78,7 +102,21 @@ export const encodeTransferMetadata = (
|
|
|
78
102
|
);
|
|
79
103
|
|
|
80
104
|
const data = encodeMetadata({
|
|
81
|
-
type:
|
|
105
|
+
type: MetadataEnums.transfer,
|
|
106
|
+
encodedData,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return single ? encodeMultipleActions(data) : data;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
113
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
114
|
+
actionMetadataTypes.rejection,
|
|
115
|
+
[id]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const data = encodeMetadata({
|
|
119
|
+
type: MetadataEnums.rejection,
|
|
82
120
|
encodedData,
|
|
83
121
|
});
|
|
84
122
|
|
|
@@ -101,7 +139,24 @@ export const encodeCrossTransferMetadata = (
|
|
|
101
139
|
);
|
|
102
140
|
|
|
103
141
|
const data = encodeMetadata({
|
|
104
|
-
type: "cross-transfer",
|
|
142
|
+
type: MetadataEnums["cross-transfer"],
|
|
143
|
+
encodedData,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return single ? encodeMultipleActions(data) : data;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const encodeAuthMetadata = (
|
|
150
|
+
params: AuthMetadataProps,
|
|
151
|
+
single = true
|
|
152
|
+
) => {
|
|
153
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
154
|
+
actionMetadataTypes["auth"],
|
|
155
|
+
[params.address, params.chainId, params.remove]
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const data = encodeMetadata({
|
|
159
|
+
type: MetadataEnums.auth,
|
|
105
160
|
encodedData,
|
|
106
161
|
});
|
|
107
162
|
|
|
@@ -110,7 +165,7 @@ export const encodeCrossTransferMetadata = (
|
|
|
110
165
|
|
|
111
166
|
export const encodeDeployMetadata = (single = true) => {
|
|
112
167
|
const data = encodeMetadata({
|
|
113
|
-
type:
|
|
168
|
+
type: MetadataEnums.deploy,
|
|
114
169
|
encodedData: "0x",
|
|
115
170
|
});
|
|
116
171
|
|
|
@@ -127,7 +182,7 @@ export const encodeWCSignMetadata = (
|
|
|
127
182
|
);
|
|
128
183
|
|
|
129
184
|
const data = encodeMetadata({
|
|
130
|
-
type:
|
|
185
|
+
type: MetadataEnums.permit2,
|
|
131
186
|
encodedData,
|
|
132
187
|
});
|
|
133
188
|
|
|
@@ -144,7 +199,7 @@ export const encodeUpgradeMetadata = (
|
|
|
144
199
|
);
|
|
145
200
|
|
|
146
201
|
const data = encodeMetadata({
|
|
147
|
-
type:
|
|
202
|
+
type: MetadataEnums.upgrade,
|
|
148
203
|
encodedData,
|
|
149
204
|
});
|
|
150
205
|
|
|
@@ -168,7 +223,7 @@ export const encodeSwapMetadata = (
|
|
|
168
223
|
);
|
|
169
224
|
|
|
170
225
|
const data = encodeMetadata({
|
|
171
|
-
type:
|
|
226
|
+
type: MetadataEnums.swap,
|
|
172
227
|
encodedData,
|
|
173
228
|
});
|
|
174
229
|
|
|
@@ -184,10 +239,8 @@ export const encodeTopupMetadata = (
|
|
|
184
239
|
[params.amount, params.token, params.onBehalf]
|
|
185
240
|
);
|
|
186
241
|
|
|
187
|
-
console.log(params);
|
|
188
|
-
|
|
189
242
|
const data = encodeMetadata({
|
|
190
|
-
type: "gas-topup",
|
|
243
|
+
type: MetadataEnums["gas-topup"],
|
|
191
244
|
encodedData,
|
|
192
245
|
});
|
|
193
246
|
|
|
@@ -212,7 +265,58 @@ export const encodeBridgeMetadata = (
|
|
|
212
265
|
);
|
|
213
266
|
|
|
214
267
|
const data = encodeMetadata({
|
|
215
|
-
type:
|
|
268
|
+
type: MetadataEnums.bridge,
|
|
269
|
+
encodedData,
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
return single ? encodeMultipleActions(data) : data;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const encodeChangeThresholdMetadata = (
|
|
276
|
+
threshold: string | number,
|
|
277
|
+
single = true
|
|
278
|
+
) => {
|
|
279
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
280
|
+
actionMetadataTypes["change-threshold"],
|
|
281
|
+
[toBN(threshold).toNumber()]
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const data = encodeMetadata({
|
|
285
|
+
type: MetadataEnums["change-threshold"],
|
|
286
|
+
encodedData,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return single ? encodeMultipleActions(data) : data;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
export const encodeRemoveSignersMetadata = (
|
|
293
|
+
addresses: string[],
|
|
294
|
+
single = true
|
|
295
|
+
) => {
|
|
296
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
297
|
+
actionMetadataTypes["remove-signers"],
|
|
298
|
+
[addresses]
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
const data = encodeMetadata({
|
|
302
|
+
type: MetadataEnums["remove-signers"],
|
|
303
|
+
encodedData,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
return single ? encodeMultipleActions(data) : data;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export const encodeAddSignersMetadata = (
|
|
310
|
+
addresses: string[],
|
|
311
|
+
single = true
|
|
312
|
+
) => {
|
|
313
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
314
|
+
actionMetadataTypes["add-signers"],
|
|
315
|
+
[addresses]
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const data = encodeMetadata({
|
|
319
|
+
type: MetadataEnums["add-signers"],
|
|
216
320
|
encodedData,
|
|
217
321
|
});
|
|
218
322
|
|
|
@@ -223,148 +327,210 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
223
327
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
224
328
|
};
|
|
225
329
|
|
|
226
|
-
export const
|
|
330
|
+
export const decodeData = (data: string) => {
|
|
227
331
|
try {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
332
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
333
|
+
|
|
334
|
+
return parseMetadata(metadata);
|
|
335
|
+
} catch (e) {
|
|
336
|
+
// console.log(e);
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const decodeMetadata = (metadata: string) => {
|
|
342
|
+
try {
|
|
343
|
+
return parseMetadata(metadata);
|
|
344
|
+
} catch (e) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const getMetadataFromData = (data: string) => {
|
|
350
|
+
const iface = Forwarder__factory.createInterface();
|
|
351
|
+
let metadata = "0x";
|
|
352
|
+
|
|
353
|
+
if (data.startsWith("0x18e7f485")) {
|
|
354
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
355
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
356
|
+
return null;
|
|
241
357
|
} else {
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
executeDataV2.params_.metadata === "0x" ||
|
|
245
|
-
!executeDataV2.params_.metadata
|
|
246
|
-
) {
|
|
247
|
-
return null;
|
|
248
|
-
} else {
|
|
249
|
-
metadata = executeDataV2.params_.metadata;
|
|
250
|
-
}
|
|
358
|
+
metadata = executeData.metadata_;
|
|
251
359
|
}
|
|
360
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
361
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
362
|
+
if (
|
|
363
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
364
|
+
!executeDataV2.params_.metadata
|
|
365
|
+
) {
|
|
366
|
+
return null;
|
|
367
|
+
} else {
|
|
368
|
+
metadata = executeDataV2.params_.metadata;
|
|
369
|
+
}
|
|
370
|
+
} else if (data.startsWith("0x85114d53")) {
|
|
371
|
+
const executeDataV3 = iface.decodeFunctionData("executeV3", data);
|
|
372
|
+
if (
|
|
373
|
+
executeDataV3.params_.metadata === "0x" ||
|
|
374
|
+
!executeDataV3.params_.metadata
|
|
375
|
+
) {
|
|
376
|
+
return null;
|
|
377
|
+
} else {
|
|
378
|
+
metadata = executeDataV3.params_.metadata;
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
const executeDataMultisigV3 = iface.decodeFunctionData(
|
|
382
|
+
"executeMultisigV3",
|
|
383
|
+
data
|
|
384
|
+
);
|
|
385
|
+
if (
|
|
386
|
+
executeDataMultisigV3.params_.metadata === "0x" ||
|
|
387
|
+
!executeDataMultisigV3.params_.metadata
|
|
388
|
+
) {
|
|
389
|
+
return null;
|
|
390
|
+
} else {
|
|
391
|
+
metadata = executeDataMultisigV3.params_.metadata;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return metadata;
|
|
396
|
+
};
|
|
397
|
+
|
|
252
398
|
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
type,
|
|
340
|
-
token: decodedData.token,
|
|
341
|
-
spender: decodedData.spender,
|
|
342
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
343
|
-
expiration: decodedData.expiration,
|
|
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
|
-
};
|
|
358
|
-
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
399
|
+
const typesPayload: IPayload = {
|
|
400
|
+
transfer: (data, type) => ({
|
|
401
|
+
type,
|
|
402
|
+
token: data.token,
|
|
403
|
+
amount: toBN(data.amount).toFixed(),
|
|
404
|
+
receiver: data.receiver,
|
|
405
|
+
}),
|
|
406
|
+
bridge: (data, type) => ({
|
|
407
|
+
type,
|
|
408
|
+
amount: toBN(data.amount).toFixed(),
|
|
409
|
+
receiver: data.receiver,
|
|
410
|
+
toToken: data.toToken,
|
|
411
|
+
fromToken: data.fromToken,
|
|
412
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
413
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
414
|
+
}),
|
|
415
|
+
swap: (data, type) => ({
|
|
416
|
+
type,
|
|
417
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
418
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
419
|
+
buyToken: data.buyToken,
|
|
420
|
+
sellToken: data.sellToken,
|
|
421
|
+
receiver: data.receiver,
|
|
422
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
423
|
+
}),
|
|
424
|
+
upgrade: (data, type) => ({
|
|
425
|
+
type,
|
|
426
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
427
|
+
walletImpl: data.walletImpl,
|
|
428
|
+
}),
|
|
429
|
+
"gas-topup": (data, type) => ({
|
|
430
|
+
type,
|
|
431
|
+
amount: toBN(data.amount).toFixed(),
|
|
432
|
+
token: data.token,
|
|
433
|
+
onBehalf: data.onBehalf,
|
|
434
|
+
}),
|
|
435
|
+
"dapp": (data, type) => ({
|
|
436
|
+
type,
|
|
437
|
+
name: data.name,
|
|
438
|
+
url: data.url,
|
|
439
|
+
}),
|
|
440
|
+
"deploy": (data, type) => ({
|
|
441
|
+
type,
|
|
442
|
+
}),
|
|
443
|
+
"permit2": (data, type) => ({
|
|
444
|
+
type,
|
|
445
|
+
token: data.token,
|
|
446
|
+
spender: data.spender,
|
|
447
|
+
amount: toBN(data.amount).toFixed(),
|
|
448
|
+
expiration: data.expiration,
|
|
449
|
+
}),
|
|
450
|
+
"cross-transfer": (data, type) => ({
|
|
451
|
+
type,
|
|
452
|
+
fromToken: data.fromToken,
|
|
453
|
+
toToken: data.toToken,
|
|
454
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
455
|
+
amount: toBN(data.amount).toFixed(),
|
|
456
|
+
receiver: data.receiver,
|
|
457
|
+
}),
|
|
458
|
+
"auth": (data) => ({
|
|
459
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
460
|
+
address: data.address,
|
|
461
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
462
|
+
remove: data.remove,
|
|
463
|
+
}),
|
|
464
|
+
"instadapp-pro": (data, type) => ({
|
|
465
|
+
type,
|
|
466
|
+
castDetails: data.castDetails,
|
|
467
|
+
}),
|
|
468
|
+
"rejection": (data, type) => ({
|
|
469
|
+
type,
|
|
470
|
+
id: data.id,
|
|
471
|
+
}),
|
|
472
|
+
"add-signers": (data, type) => ({
|
|
473
|
+
type,
|
|
474
|
+
addresses: data.signers,
|
|
475
|
+
}),
|
|
476
|
+
"remove-signers": (data, type) => ({
|
|
477
|
+
type,
|
|
478
|
+
addresses: data.signers,
|
|
479
|
+
}),
|
|
480
|
+
"change-threshold": (data, type) => ({
|
|
481
|
+
type,
|
|
482
|
+
count: data.count,
|
|
483
|
+
}),
|
|
484
|
+
};
|
|
361
485
|
|
|
486
|
+
const parseMetadata = (metadata: string) => {
|
|
487
|
+
const metadataArr = [];
|
|
488
|
+
|
|
489
|
+
const [decodedMultiMetadata = []] =
|
|
490
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
491
|
+
multiMetadataTypes,
|
|
492
|
+
metadata
|
|
493
|
+
) as string[]) || [];
|
|
494
|
+
|
|
495
|
+
for (let metadata of decodedMultiMetadata) {
|
|
496
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
497
|
+
metadataTypes,
|
|
498
|
+
metadata
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
const type = ethers.utils.parseBytes32String(
|
|
502
|
+
decodedMetadata.type
|
|
503
|
+
) as keyof typeof actionMetadataTypes;
|
|
504
|
+
|
|
505
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
506
|
+
actionMetadataTypes[type],
|
|
507
|
+
decodedMetadata.data
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
const payloadFunc = typesPayload[type]
|
|
511
|
+
|
|
512
|
+
if (payloadFunc) {
|
|
513
|
+
const payload = payloadFunc(decodedData, type)
|
|
362
514
|
metadataArr.push(payload);
|
|
363
515
|
}
|
|
364
516
|
|
|
365
|
-
return metadataArr;
|
|
366
|
-
} catch (e) {
|
|
367
|
-
console.log(e);
|
|
368
|
-
return null;
|
|
369
517
|
}
|
|
518
|
+
|
|
519
|
+
return metadataArr;
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
526
|
+
* @param {string} txType - The input sentence to modify
|
|
527
|
+
*
|
|
528
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
529
|
+
*/
|
|
530
|
+
export const formatTxType = (txType: string) => {
|
|
531
|
+
const finalSentence = txType
|
|
532
|
+
.replace("-", " ")
|
|
533
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
534
|
+
|
|
535
|
+
return finalSentence;
|
|
370
536
|
};
|