@instadapp/avocado-base 0.0.0-dev.883661e → 0.0.0-dev.8b85ca3
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/.github/workflows/npm-publish-dev.yml +2 -5
- package/abi/multisigForwarder.json +697 -0
- 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/hammer.svg +5 -0
- package/assets/images/icons/info-2.svg +12 -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/stars.svg +4 -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 +42 -0
- package/components/ActionMetadata.vue +82 -0
- package/components/AuthorityAvatar.vue +37 -0
- package/components/ChainLogo.vue +14 -563
- package/components/CopyClipboard.vue +58 -0
- package/components/metadata/Bridge.vue +59 -0
- package/components/metadata/CrossTransfer.vue +79 -0
- package/components/metadata/GasTopup.vue +39 -0
- package/components/metadata/Permit2.vue +42 -0
- package/components/metadata/Signers.vue +66 -0
- package/components/metadata/Swap.vue +67 -0
- package/components/metadata/Transfer.vue +50 -0
- package/components.d.ts +13 -0
- package/contracts/MultisigForwarder.ts +859 -0
- package/contracts/factories/MultisigForwarder__factory.ts +721 -0
- package/contracts/factories/index.ts +1 -0
- package/contracts/index.ts +2 -0
- package/nuxt.config.ts +17 -1
- package/package.json +16 -8
- package/utils/avocado.ts +2 -0
- package/utils/bignumber.ts +20 -0
- package/utils/formatter.ts +2 -2
- package/utils/helper.ts +8 -0
- package/utils/metadata.ts +374 -188
- package/utils/network.ts +335 -74
- package/utils/services.ts +21 -0
- package/utils/utils.d.ts +136 -114
package/utils/metadata.ts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
|
-
import { Forwarder__factory } from "../contracts";
|
|
2
|
+
import { Forwarder__factory, MultisigForwarder__factory } from "../contracts";
|
|
3
|
+
import { toBN } from "./bignumber";
|
|
4
|
+
|
|
5
|
+
export const MetadataEnums = {
|
|
6
|
+
transfer: "transfer",
|
|
7
|
+
bridge: "bridge",
|
|
8
|
+
swap: "swap",
|
|
9
|
+
"gas-topup": "gas-topup",
|
|
10
|
+
upgrade: "upgrade",
|
|
11
|
+
dapp: "dapp",
|
|
12
|
+
deploy: "deploy",
|
|
13
|
+
permit2: "permit2",
|
|
14
|
+
"cross-transfer": "cross-transfer",
|
|
15
|
+
auth: "auth",
|
|
16
|
+
rejection: "rejection",
|
|
17
|
+
"instadapp-pro": "instadapp-pro",
|
|
18
|
+
"add-signers": "add-signers",
|
|
19
|
+
"remove-signers": "remove-signers",
|
|
20
|
+
"change-threshold": "change-threshold",
|
|
21
|
+
import: "import",
|
|
22
|
+
mass: "mass",
|
|
23
|
+
"tx-builder": "tx-builder",
|
|
24
|
+
"avocado-bridge": "avocado-bridge",
|
|
25
|
+
} as const;
|
|
3
26
|
|
|
4
27
|
const multiMetadataTypes = ["bytes[]"];
|
|
5
28
|
|
|
6
29
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
7
30
|
|
|
8
|
-
const actionMetadataTypes = {
|
|
31
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
9
32
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
10
33
|
"cross-transfer": [
|
|
11
34
|
"address fromToken",
|
|
@@ -34,8 +57,10 @@ const actionMetadataTypes = {
|
|
|
34
57
|
"gas-topup": ["uint256 amount", "address token", "address onBehalf"],
|
|
35
58
|
upgrade: ["bytes32 version", "address walletImpl"],
|
|
36
59
|
dapp: ["string name", "string url"],
|
|
60
|
+
import: ["bytes32 protocol", "uint256 valueInUsd"],
|
|
37
61
|
auth: ["address address", "uint256 chainId", "bool remove"],
|
|
38
62
|
deploy: [],
|
|
63
|
+
"tx-builder": ["bytes32 actionCount"],
|
|
39
64
|
permit2: [
|
|
40
65
|
"address token",
|
|
41
66
|
"address spender",
|
|
@@ -43,6 +68,12 @@ const actionMetadataTypes = {
|
|
|
43
68
|
"uint48 expiration",
|
|
44
69
|
],
|
|
45
70
|
"instadapp-pro": ["string castDetails"],
|
|
71
|
+
"add-signers": ["address[] signers"],
|
|
72
|
+
"remove-signers": ["address[] signers"],
|
|
73
|
+
"change-threshold": ["uint8 count"],
|
|
74
|
+
rejection: ["bytes32 id"],
|
|
75
|
+
"avocado-bridge": ["bytes32 id", "uint256 toChainId"],
|
|
76
|
+
mass: ["bool isMass"],
|
|
46
77
|
};
|
|
47
78
|
|
|
48
79
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -63,7 +94,25 @@ export const encodeDappMetadata = (
|
|
|
63
94
|
);
|
|
64
95
|
|
|
65
96
|
const data = encodeMetadata({
|
|
66
|
-
type:
|
|
97
|
+
type: MetadataEnums.dapp,
|
|
98
|
+
encodedData,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return single ? encodeMultipleActions(data) : data;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const encodeAvocadoBridgeMetadata = (
|
|
105
|
+
id: string,
|
|
106
|
+
toChainId: string | number,
|
|
107
|
+
single = true
|
|
108
|
+
) => {
|
|
109
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
110
|
+
actionMetadataTypes["avocado-bridge"],
|
|
111
|
+
[id, toChainId]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const data = encodeMetadata({
|
|
115
|
+
type: MetadataEnums["avocado-bridge"],
|
|
67
116
|
encodedData,
|
|
68
117
|
});
|
|
69
118
|
|
|
@@ -80,7 +129,21 @@ export const encodeTransferMetadata = (
|
|
|
80
129
|
);
|
|
81
130
|
|
|
82
131
|
const data = encodeMetadata({
|
|
83
|
-
type:
|
|
132
|
+
type: MetadataEnums.transfer,
|
|
133
|
+
encodedData,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return single ? encodeMultipleActions(data) : data;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
140
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
141
|
+
actionMetadataTypes.rejection,
|
|
142
|
+
[id]
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const data = encodeMetadata({
|
|
146
|
+
type: MetadataEnums.rejection,
|
|
84
147
|
encodedData,
|
|
85
148
|
});
|
|
86
149
|
|
|
@@ -103,7 +166,7 @@ export const encodeCrossTransferMetadata = (
|
|
|
103
166
|
);
|
|
104
167
|
|
|
105
168
|
const data = encodeMetadata({
|
|
106
|
-
type: "cross-transfer",
|
|
169
|
+
type: MetadataEnums["cross-transfer"],
|
|
107
170
|
encodedData,
|
|
108
171
|
});
|
|
109
172
|
|
|
@@ -120,7 +183,7 @@ export const encodeAuthMetadata = (
|
|
|
120
183
|
);
|
|
121
184
|
|
|
122
185
|
const data = encodeMetadata({
|
|
123
|
-
type:
|
|
186
|
+
type: MetadataEnums.auth,
|
|
124
187
|
encodedData,
|
|
125
188
|
});
|
|
126
189
|
|
|
@@ -129,13 +192,30 @@ export const encodeAuthMetadata = (
|
|
|
129
192
|
|
|
130
193
|
export const encodeDeployMetadata = (single = true) => {
|
|
131
194
|
const data = encodeMetadata({
|
|
132
|
-
type:
|
|
195
|
+
type: MetadataEnums.deploy,
|
|
133
196
|
encodedData: "0x",
|
|
134
197
|
});
|
|
135
198
|
|
|
136
199
|
return single ? encodeMultipleActions(data) : data;
|
|
137
200
|
};
|
|
138
201
|
|
|
202
|
+
export const encodeTransactionBuilderMetadata = (
|
|
203
|
+
actionCount: string,
|
|
204
|
+
single = true
|
|
205
|
+
) => {
|
|
206
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
207
|
+
actionMetadataTypes["tx-builder"],
|
|
208
|
+
[actionCount]
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const data = encodeMetadata({
|
|
212
|
+
type: MetadataEnums["tx-builder"],
|
|
213
|
+
encodedData,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return single ? encodeMultipleActions(data) : data;
|
|
217
|
+
};
|
|
218
|
+
|
|
139
219
|
export const encodeWCSignMetadata = (
|
|
140
220
|
params: SignMetadataProps,
|
|
141
221
|
single = true
|
|
@@ -146,7 +226,7 @@ export const encodeWCSignMetadata = (
|
|
|
146
226
|
);
|
|
147
227
|
|
|
148
228
|
const data = encodeMetadata({
|
|
149
|
-
type:
|
|
229
|
+
type: MetadataEnums.permit2,
|
|
150
230
|
encodedData,
|
|
151
231
|
});
|
|
152
232
|
|
|
@@ -163,7 +243,7 @@ export const encodeUpgradeMetadata = (
|
|
|
163
243
|
);
|
|
164
244
|
|
|
165
245
|
const data = encodeMetadata({
|
|
166
|
-
type:
|
|
246
|
+
type: MetadataEnums.upgrade,
|
|
167
247
|
encodedData,
|
|
168
248
|
});
|
|
169
249
|
|
|
@@ -187,7 +267,7 @@ export const encodeSwapMetadata = (
|
|
|
187
267
|
);
|
|
188
268
|
|
|
189
269
|
const data = encodeMetadata({
|
|
190
|
-
type:
|
|
270
|
+
type: MetadataEnums.swap,
|
|
191
271
|
encodedData,
|
|
192
272
|
});
|
|
193
273
|
|
|
@@ -203,10 +283,8 @@ export const encodeTopupMetadata = (
|
|
|
203
283
|
[params.amount, params.token, params.onBehalf]
|
|
204
284
|
);
|
|
205
285
|
|
|
206
|
-
console.log(params);
|
|
207
|
-
|
|
208
286
|
const data = encodeMetadata({
|
|
209
|
-
type: "gas-topup",
|
|
287
|
+
type: MetadataEnums["gas-topup"],
|
|
210
288
|
encodedData,
|
|
211
289
|
});
|
|
212
290
|
|
|
@@ -231,7 +309,85 @@ export const encodeBridgeMetadata = (
|
|
|
231
309
|
);
|
|
232
310
|
|
|
233
311
|
const data = encodeMetadata({
|
|
234
|
-
type:
|
|
312
|
+
type: MetadataEnums.bridge,
|
|
313
|
+
encodedData,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
return single ? encodeMultipleActions(data) : data;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export const encodeChangeThresholdMetadata = (
|
|
320
|
+
threshold: string | number,
|
|
321
|
+
single = true
|
|
322
|
+
) => {
|
|
323
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
324
|
+
actionMetadataTypes["change-threshold"],
|
|
325
|
+
[toBN(threshold).toNumber()]
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
const data = encodeMetadata({
|
|
329
|
+
type: MetadataEnums["change-threshold"],
|
|
330
|
+
encodedData,
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
return single ? encodeMultipleActions(data) : data;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export const encodeRemoveSignersMetadata = (
|
|
337
|
+
addresses: string[],
|
|
338
|
+
single = true
|
|
339
|
+
) => {
|
|
340
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
341
|
+
actionMetadataTypes["remove-signers"],
|
|
342
|
+
[addresses]
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
const data = encodeMetadata({
|
|
346
|
+
type: MetadataEnums["remove-signers"],
|
|
347
|
+
encodedData,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
return single ? encodeMultipleActions(data) : data;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export const encodeImportMetadata = (
|
|
354
|
+
protocol: string,
|
|
355
|
+
valueInUsd: string,
|
|
356
|
+
single = true
|
|
357
|
+
) => {
|
|
358
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
359
|
+
actionMetadataTypes["import"],
|
|
360
|
+
[protocol, valueInUsd]
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const data = encodeMetadata({
|
|
364
|
+
type: MetadataEnums["import"],
|
|
365
|
+
encodedData,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
return single ? encodeMultipleActions(data) : data;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
export const encodeMassMetadata = (single = true) => {
|
|
372
|
+
const data = encodeMetadata({
|
|
373
|
+
type: MetadataEnums.mass,
|
|
374
|
+
encodedData: '0x',
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
return single ? encodeMultipleActions(data) : data;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export const encodeAddSignersMetadata = (
|
|
381
|
+
addresses: string[],
|
|
382
|
+
single = true
|
|
383
|
+
) => {
|
|
384
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
385
|
+
actionMetadataTypes["add-signers"],
|
|
386
|
+
[addresses]
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
const data = encodeMetadata({
|
|
390
|
+
type: MetadataEnums["add-signers"],
|
|
235
391
|
encodedData,
|
|
236
392
|
});
|
|
237
393
|
|
|
@@ -242,186 +398,216 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
242
398
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
243
399
|
};
|
|
244
400
|
|
|
245
|
-
export const
|
|
401
|
+
export const decodeData = (data: string) => {
|
|
246
402
|
try {
|
|
247
|
-
const
|
|
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
|
-
|
|
403
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
404
|
+
|
|
405
|
+
return parseMetadata(metadata);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
// console.log(e);
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
export const decodeMetadata = (metadata: string) => {
|
|
413
|
+
try {
|
|
414
|
+
return parseMetadata(metadata);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const iface = Forwarder__factory.createInterface();
|
|
421
|
+
const ifaceMultisig = MultisigForwarder__factory.createInterface();
|
|
422
|
+
|
|
423
|
+
const getMetadataFromData = (data: string) => {
|
|
424
|
+
let metadata = "0x";
|
|
425
|
+
|
|
426
|
+
if (data.startsWith("0x18e7f485")) {
|
|
427
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
428
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
429
|
+
return null;
|
|
430
|
+
} else {
|
|
431
|
+
metadata = executeData.metadata_;
|
|
432
|
+
}
|
|
433
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
434
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
435
|
+
if (
|
|
436
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
437
|
+
!executeDataV2.params_.metadata
|
|
438
|
+
) {
|
|
439
|
+
return null;
|
|
280
440
|
} else {
|
|
281
|
-
|
|
282
|
-
if (
|
|
283
|
-
executeDataMultisigV3.params_.metadata === "0x" ||
|
|
284
|
-
!executeDataMultisigV3.params_.metadata
|
|
285
|
-
) {
|
|
286
|
-
return null;
|
|
287
|
-
} else {
|
|
288
|
-
metadata = executeDataMultisigV3.params_.metadata;
|
|
289
|
-
}
|
|
441
|
+
metadata = executeDataV2.params_.metadata;
|
|
290
442
|
}
|
|
443
|
+
} else {
|
|
444
|
+
const executeDataMultisig = ifaceMultisig.decodeFunctionData(
|
|
445
|
+
"executeV1",
|
|
446
|
+
data
|
|
447
|
+
);
|
|
448
|
+
if (
|
|
449
|
+
executeDataMultisig.params_.metadata === "0x" ||
|
|
450
|
+
!executeDataMultisig.params_.metadata
|
|
451
|
+
) {
|
|
452
|
+
return null;
|
|
453
|
+
} else {
|
|
454
|
+
metadata = executeDataMultisig.params_.metadata;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
291
457
|
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
458
|
+
return metadata;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const typesPayload: IPayload = {
|
|
462
|
+
import: (data, type) => ({
|
|
463
|
+
type,
|
|
464
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
465
|
+
valueInUsd: toBN(data.valueInUsd).toFixed(),
|
|
466
|
+
}),
|
|
467
|
+
transfer: (data, type) => ({
|
|
468
|
+
type,
|
|
469
|
+
token: data.token,
|
|
470
|
+
amount: toBN(data.amount).toFixed(),
|
|
471
|
+
receiver: data.receiver,
|
|
472
|
+
}),
|
|
473
|
+
bridge: (data, type) => ({
|
|
474
|
+
type,
|
|
475
|
+
amount: toBN(data.amount).toFixed(),
|
|
476
|
+
receiver: data.receiver,
|
|
477
|
+
toToken: data.toToken,
|
|
478
|
+
fromToken: data.fromToken,
|
|
479
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
480
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
481
|
+
}),
|
|
482
|
+
swap: (data, type) => ({
|
|
483
|
+
type,
|
|
484
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
485
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
486
|
+
buyToken: data.buyToken,
|
|
487
|
+
sellToken: data.sellToken,
|
|
488
|
+
receiver: data.receiver,
|
|
489
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
490
|
+
}),
|
|
491
|
+
upgrade: (data, type) => ({
|
|
492
|
+
type,
|
|
493
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
494
|
+
walletImpl: data.walletImpl,
|
|
495
|
+
}),
|
|
496
|
+
"gas-topup": (data, type) => ({
|
|
497
|
+
type,
|
|
498
|
+
amount: toBN(data.amount).toFixed(),
|
|
499
|
+
token: data.token,
|
|
500
|
+
onBehalf: data.onBehalf,
|
|
501
|
+
}),
|
|
502
|
+
dapp: (data, type) => ({
|
|
503
|
+
type,
|
|
504
|
+
name: data.name,
|
|
505
|
+
url: data.url,
|
|
506
|
+
}),
|
|
507
|
+
deploy: (data, type) => ({
|
|
508
|
+
type,
|
|
509
|
+
}),
|
|
510
|
+
"tx-builder": (data, type) => ({
|
|
511
|
+
type,
|
|
512
|
+
actionCount: utils.parseBytes32String(data.actionCount || ""),
|
|
513
|
+
}),
|
|
514
|
+
permit2: (data, type) => ({
|
|
515
|
+
type,
|
|
516
|
+
token: data.token,
|
|
517
|
+
spender: data.spender,
|
|
518
|
+
amount: toBN(data.amount).toFixed(),
|
|
519
|
+
expiration: data.expiration,
|
|
520
|
+
}),
|
|
521
|
+
"cross-transfer": (data, type) => ({
|
|
522
|
+
type,
|
|
523
|
+
fromToken: data.fromToken,
|
|
524
|
+
toToken: data.toToken,
|
|
525
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
526
|
+
amount: toBN(data.amount).toFixed(),
|
|
527
|
+
receiver: data.receiver,
|
|
528
|
+
}),
|
|
529
|
+
auth: (data) => ({
|
|
530
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
531
|
+
address: data.address,
|
|
532
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
533
|
+
remove: data.remove,
|
|
534
|
+
}),
|
|
535
|
+
"instadapp-pro": (data, type) => ({
|
|
536
|
+
type,
|
|
537
|
+
castDetails: data.castDetails,
|
|
538
|
+
}),
|
|
539
|
+
rejection: (data, type) => ({
|
|
540
|
+
type,
|
|
541
|
+
id: data.id,
|
|
542
|
+
}),
|
|
543
|
+
"add-signers": (data, type) => ({
|
|
544
|
+
type,
|
|
545
|
+
addresses: data.signers,
|
|
546
|
+
}),
|
|
547
|
+
"remove-signers": (data, type) => ({
|
|
548
|
+
type,
|
|
549
|
+
addresses: data.signers,
|
|
550
|
+
}),
|
|
551
|
+
"change-threshold": (data, type) => ({
|
|
552
|
+
type,
|
|
553
|
+
count: data.count,
|
|
554
|
+
}),
|
|
555
|
+
"avocado-bridge": (data, type) => ({
|
|
556
|
+
type,
|
|
557
|
+
id: data.id,
|
|
558
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
559
|
+
}),
|
|
560
|
+
mass: (data, type) => ({
|
|
561
|
+
type: 'Chain Agnostic Payments',
|
|
562
|
+
data,
|
|
563
|
+
}),
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
const parseMetadata = (metadata: string) => {
|
|
567
|
+
const metadataArr = [];
|
|
568
|
+
|
|
569
|
+
const [decodedMultiMetadata = []] =
|
|
570
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
571
|
+
multiMetadataTypes,
|
|
572
|
+
metadata
|
|
573
|
+
) as string[]) || [];
|
|
574
|
+
|
|
575
|
+
for (let metadata of decodedMultiMetadata) {
|
|
576
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
577
|
+
metadataTypes,
|
|
578
|
+
metadata
|
|
579
|
+
);
|
|
580
|
+
|
|
581
|
+
const type = ethers.utils.parseBytes32String(
|
|
582
|
+
decodedMetadata.type
|
|
583
|
+
) as keyof typeof actionMetadataTypes;
|
|
584
|
+
|
|
585
|
+
const decodedData = decodedMetadata?.data === '0x' ? '' : ethers.utils.defaultAbiCoder.decode(
|
|
586
|
+
actionMetadataTypes[type],
|
|
587
|
+
decodedMetadata.data
|
|
588
|
+
);
|
|
418
589
|
|
|
590
|
+
const payloadFunc = typesPayload[type];
|
|
591
|
+
|
|
592
|
+
if (payloadFunc) {
|
|
593
|
+
const payload = payloadFunc(decodedData, type);
|
|
419
594
|
metadataArr.push(payload);
|
|
420
595
|
}
|
|
421
|
-
|
|
422
|
-
return metadataArr;
|
|
423
|
-
} catch (e) {
|
|
424
|
-
console.log(e);
|
|
425
|
-
return null;
|
|
426
596
|
}
|
|
597
|
+
|
|
598
|
+
return metadataArr;
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
603
|
+
* @param {string} txType - The input sentence to modify
|
|
604
|
+
*
|
|
605
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
606
|
+
*/
|
|
607
|
+
export const formatTxType = (txType: string) => {
|
|
608
|
+
const finalSentence = txType
|
|
609
|
+
.replace("-", " ")
|
|
610
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
611
|
+
|
|
612
|
+
return finalSentence;
|
|
427
613
|
};
|