@instadapp/avocado-base 0.0.0-dev.c8c43bc → 0.0.0-dev.cfde212
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 +73 -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 +33 -0
- package/utils/metadata.ts +317 -124
- package/utils/network.ts +130 -67
- package/utils/services.ts +14 -0
- package/utils/utils.d.ts +66 -16
- package/utils/index.ts +0 -93
package/utils/metadata.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
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
|
|
|
7
6
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
8
7
|
|
|
9
|
-
const actionMetadataTypes = {
|
|
8
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
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,11 @@ const actionMetadataTypes = {
|
|
|
35
42
|
"uint160 amount",
|
|
36
43
|
"uint48 expiration",
|
|
37
44
|
],
|
|
45
|
+
"instadapp-pro": ["string castDetails"],
|
|
46
|
+
'add-signers': ['address[] signers'],
|
|
47
|
+
'remove-signers': ['address[] signers'],
|
|
48
|
+
'change-threshold': ['uint8 count'],
|
|
49
|
+
'rejection': ['bytes32 id'],
|
|
38
50
|
};
|
|
39
51
|
|
|
40
52
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -79,6 +91,60 @@ export const encodeTransferMetadata = (
|
|
|
79
91
|
return single ? encodeMultipleActions(data) : data;
|
|
80
92
|
};
|
|
81
93
|
|
|
94
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
95
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
96
|
+
actionMetadataTypes.rejection,
|
|
97
|
+
[id]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const data = encodeMetadata({
|
|
101
|
+
type: "rejection",
|
|
102
|
+
encodedData,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return single ? encodeMultipleActions(data) : data;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const encodeCrossTransferMetadata = (
|
|
109
|
+
params: CrossSendMetadataProps,
|
|
110
|
+
single = true
|
|
111
|
+
) => {
|
|
112
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
113
|
+
actionMetadataTypes["cross-transfer"],
|
|
114
|
+
[
|
|
115
|
+
params.fromToken,
|
|
116
|
+
params.toToken,
|
|
117
|
+
params.toChainId,
|
|
118
|
+
params.amount,
|
|
119
|
+
params.receiver,
|
|
120
|
+
]
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const data = encodeMetadata({
|
|
124
|
+
type: "cross-transfer",
|
|
125
|
+
encodedData,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return single ? encodeMultipleActions(data) : data;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const encodeAuthMetadata = (
|
|
132
|
+
params: AuthMetadataProps,
|
|
133
|
+
single = true
|
|
134
|
+
) => {
|
|
135
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
136
|
+
actionMetadataTypes["auth"],
|
|
137
|
+
[params.address, params.chainId, params.remove]
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const data = encodeMetadata({
|
|
141
|
+
type: "auth",
|
|
142
|
+
encodedData,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return single ? encodeMultipleActions(data) : data;
|
|
146
|
+
};
|
|
147
|
+
|
|
82
148
|
export const encodeDeployMetadata = (single = true) => {
|
|
83
149
|
const data = encodeMetadata({
|
|
84
150
|
type: "deploy",
|
|
@@ -190,138 +256,265 @@ export const encodeBridgeMetadata = (
|
|
|
190
256
|
return single ? encodeMultipleActions(data) : data;
|
|
191
257
|
};
|
|
192
258
|
|
|
259
|
+
export const encodeChangeThresholdMetadata = (
|
|
260
|
+
threshold: string | number,
|
|
261
|
+
single = true
|
|
262
|
+
) => {
|
|
263
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
264
|
+
actionMetadataTypes["change-threshold"],
|
|
265
|
+
[toBN(threshold).toNumber()]
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const data = encodeMetadata({
|
|
269
|
+
type: "change-threshold",
|
|
270
|
+
encodedData,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return single ? encodeMultipleActions(data) : data;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export const encodeRemoveSignersMetadata = (
|
|
277
|
+
addresses: string[],
|
|
278
|
+
single = true
|
|
279
|
+
) => {
|
|
280
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
281
|
+
actionMetadataTypes["remove-signers"],
|
|
282
|
+
[addresses]
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const data = encodeMetadata({
|
|
286
|
+
type: "remove-signers",
|
|
287
|
+
encodedData,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
return single ? encodeMultipleActions(data) : data;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export const encodeAddSignersMetadata = (
|
|
294
|
+
addresses: string[],
|
|
295
|
+
single = true
|
|
296
|
+
) => {
|
|
297
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
298
|
+
actionMetadataTypes["add-signers"],
|
|
299
|
+
[addresses]
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const data = encodeMetadata({
|
|
303
|
+
type: "add-signers",
|
|
304
|
+
encodedData,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return single ? encodeMultipleActions(data) : data;
|
|
308
|
+
};
|
|
309
|
+
|
|
193
310
|
export const encodeMultipleActions = (...actionData: string[]) => {
|
|
194
311
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
195
312
|
};
|
|
196
313
|
|
|
197
|
-
export const
|
|
314
|
+
export const decodeData = (data: string) => {
|
|
198
315
|
try {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
316
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
317
|
+
|
|
318
|
+
return parseMetadata(metadata);
|
|
319
|
+
} catch (e) {
|
|
320
|
+
// console.log(e);
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
export const decodeMetadata = (metadata: string) => {
|
|
326
|
+
try {
|
|
327
|
+
return parseMetadata(metadata);
|
|
328
|
+
} catch (e) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const getMetadataFromData = (data: string) => {
|
|
334
|
+
const iface = Forwarder__factory.createInterface();
|
|
335
|
+
let metadata = "0x";
|
|
336
|
+
|
|
337
|
+
if (data.startsWith("0x18e7f485")) {
|
|
338
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
339
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
340
|
+
return null;
|
|
341
|
+
} else {
|
|
342
|
+
metadata = executeData.metadata_;
|
|
343
|
+
}
|
|
344
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
345
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
346
|
+
if (
|
|
347
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
348
|
+
!executeDataV2.params_.metadata
|
|
349
|
+
) {
|
|
350
|
+
return null;
|
|
351
|
+
} else {
|
|
352
|
+
metadata = executeDataV2.params_.metadata;
|
|
353
|
+
}
|
|
354
|
+
} else if (data.startsWith("0x85114d53")) {
|
|
355
|
+
const executeDataV3 = iface.decodeFunctionData("executeV3", data);
|
|
356
|
+
if (
|
|
357
|
+
executeDataV3.params_.metadata === "0x" ||
|
|
358
|
+
!executeDataV3.params_.metadata
|
|
359
|
+
) {
|
|
360
|
+
return null;
|
|
361
|
+
} else {
|
|
362
|
+
metadata = executeDataV3.params_.metadata;
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
const executeDataMultisigV3 = iface.decodeFunctionData(
|
|
366
|
+
"executeMultisigV3",
|
|
367
|
+
data
|
|
368
|
+
);
|
|
369
|
+
if (
|
|
370
|
+
executeDataMultisigV3.params_.metadata === "0x" ||
|
|
371
|
+
!executeDataMultisigV3.params_.metadata
|
|
372
|
+
) {
|
|
373
|
+
return null;
|
|
212
374
|
} 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
|
-
}
|
|
375
|
+
metadata = executeDataMultisigV3.params_.metadata;
|
|
222
376
|
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return metadata;
|
|
380
|
+
};
|
|
223
381
|
|
|
224
|
-
const metadataArr = [];
|
|
225
|
-
|
|
226
|
-
const [decodedMultiMetadata = []] =
|
|
227
|
-
(ethers.utils.defaultAbiCoder.decode(
|
|
228
|
-
multiMetadataTypes,
|
|
229
|
-
metadata
|
|
230
|
-
) as string[]) || [];
|
|
231
|
-
|
|
232
|
-
for (let metadata of decodedMultiMetadata) {
|
|
233
|
-
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
234
|
-
metadataTypes,
|
|
235
|
-
metadata
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
const type = ethers.utils.parseBytes32String(
|
|
239
|
-
decodedMetadata.type
|
|
240
|
-
) as keyof typeof actionMetadataTypes;
|
|
241
|
-
|
|
242
|
-
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
243
|
-
actionMetadataTypes[type],
|
|
244
|
-
decodedMetadata.data
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
switch (type) {
|
|
248
|
-
case "transfer":
|
|
249
|
-
payload = {
|
|
250
|
-
type,
|
|
251
|
-
token: decodedData.token,
|
|
252
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
253
|
-
receiver: decodedData.receiver,
|
|
254
|
-
};
|
|
255
|
-
break;
|
|
256
|
-
case "bridge":
|
|
257
|
-
payload = {
|
|
258
|
-
type,
|
|
259
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
260
|
-
receiver: decodedData.receiver,
|
|
261
|
-
toToken: decodedData.toToken,
|
|
262
|
-
fromToken: decodedData.fromToken,
|
|
263
|
-
toChainId: decodedData.toChainId
|
|
264
|
-
? decodedData.toChainId.toString()
|
|
265
|
-
: null,
|
|
266
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
267
|
-
};
|
|
268
|
-
break;
|
|
269
|
-
case "swap":
|
|
270
|
-
payload = {
|
|
271
|
-
type,
|
|
272
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
273
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
274
|
-
buyToken: decodedData.buyToken,
|
|
275
|
-
sellToken: decodedData.sellToken,
|
|
276
|
-
receiver: decodedData.receiver,
|
|
277
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
278
|
-
};
|
|
279
|
-
break;
|
|
280
|
-
case "upgrade":
|
|
281
|
-
payload = {
|
|
282
|
-
type,
|
|
283
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
284
|
-
walletImpl: decodedData?.walletImpl,
|
|
285
|
-
};
|
|
286
|
-
break;
|
|
287
|
-
case "gas-topup":
|
|
288
|
-
payload = {
|
|
289
|
-
type,
|
|
290
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
291
|
-
token: decodedData.token,
|
|
292
|
-
onBehalf: decodedData.onBehalf,
|
|
293
|
-
};
|
|
294
|
-
break;
|
|
295
|
-
case "dapp":
|
|
296
|
-
payload = {
|
|
297
|
-
type,
|
|
298
|
-
name: decodedData?.name,
|
|
299
|
-
url: decodedData?.url,
|
|
300
|
-
};
|
|
301
|
-
break;
|
|
302
|
-
case "deploy":
|
|
303
|
-
payload = {
|
|
304
|
-
type,
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
case "permit2":
|
|
308
|
-
payload = {
|
|
309
|
-
type,
|
|
310
|
-
token: decodedData.token,
|
|
311
|
-
spender: decodedData.spender,
|
|
312
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
313
|
-
expiration: decodedData.expiration,
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
382
|
|
|
383
|
+
const typesPayload: IPayload = {
|
|
384
|
+
"transfer": (data, type) => ({
|
|
385
|
+
type,
|
|
386
|
+
token: data.token,
|
|
387
|
+
amount: toBN(data.amount).toFixed(),
|
|
388
|
+
receiver: data.receiver,
|
|
389
|
+
}),
|
|
390
|
+
"bridge": (data, type) => ({
|
|
391
|
+
type,
|
|
392
|
+
amount: toBN(data.amount).toFixed(),
|
|
393
|
+
receiver: data.receiver,
|
|
394
|
+
toToken: data.toToken,
|
|
395
|
+
fromToken: data.fromToken,
|
|
396
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
397
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
398
|
+
}),
|
|
399
|
+
"swap": (data, type) => ({
|
|
400
|
+
type,
|
|
401
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
402
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
403
|
+
buyToken: data.buyToken,
|
|
404
|
+
sellToken: data.sellToken,
|
|
405
|
+
receiver: data.receiver,
|
|
406
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
407
|
+
}),
|
|
408
|
+
"upgrade": (data, type) => ({
|
|
409
|
+
type,
|
|
410
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
411
|
+
walletImpl: data.walletImpl,
|
|
412
|
+
}),
|
|
413
|
+
"gas-topup": (data, type) => ({
|
|
414
|
+
type,
|
|
415
|
+
amount: toBN(data.amount).toFixed(),
|
|
416
|
+
token: data.token,
|
|
417
|
+
onBehalf: data.onBehalf,
|
|
418
|
+
}),
|
|
419
|
+
"dapp": (data, type) => ({
|
|
420
|
+
type,
|
|
421
|
+
name: data.name,
|
|
422
|
+
url: data.url,
|
|
423
|
+
}),
|
|
424
|
+
"deploy": (data, type) => ({
|
|
425
|
+
type,
|
|
426
|
+
}),
|
|
427
|
+
"permit2": (data, type) => ({
|
|
428
|
+
type,
|
|
429
|
+
token: data.token,
|
|
430
|
+
spender: data.spender,
|
|
431
|
+
amount: toBN(data.amount).toFixed(),
|
|
432
|
+
expiration: data.expiration,
|
|
433
|
+
}),
|
|
434
|
+
"cross-transfer": (data, type) => ({
|
|
435
|
+
type,
|
|
436
|
+
fromToken: data.fromToken,
|
|
437
|
+
toToken: data.toToken,
|
|
438
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
439
|
+
amount: toBN(data.amount).toFixed(),
|
|
440
|
+
receiver: data.receiver,
|
|
441
|
+
}),
|
|
442
|
+
"auth": (data) => ({
|
|
443
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
444
|
+
address: data.address,
|
|
445
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
446
|
+
remove: data.remove,
|
|
447
|
+
}),
|
|
448
|
+
"instadapp-pro": (data, type) => ({
|
|
449
|
+
type,
|
|
450
|
+
castDetails: data.castDetails,
|
|
451
|
+
}),
|
|
452
|
+
"rejection": (data, type) => ({
|
|
453
|
+
type,
|
|
454
|
+
id: data.id,
|
|
455
|
+
}),
|
|
456
|
+
"add-signers": (data, type) => ({
|
|
457
|
+
type,
|
|
458
|
+
addresses: data.signers,
|
|
459
|
+
}),
|
|
460
|
+
"remove-signers": (data, type) => ({
|
|
461
|
+
type,
|
|
462
|
+
addresses: data.signers,
|
|
463
|
+
}),
|
|
464
|
+
"change-threshold": (data, type) => ({
|
|
465
|
+
type,
|
|
466
|
+
count: data.count,
|
|
467
|
+
})
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
const parseMetadata = (metadata: string) => {
|
|
471
|
+
const metadataArr = [];
|
|
472
|
+
|
|
473
|
+
const [decodedMultiMetadata = []] =
|
|
474
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
475
|
+
multiMetadataTypes,
|
|
476
|
+
metadata
|
|
477
|
+
) as string[]) || [];
|
|
478
|
+
|
|
479
|
+
for (let metadata of decodedMultiMetadata) {
|
|
480
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
481
|
+
metadataTypes,
|
|
482
|
+
metadata
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
const type = ethers.utils.parseBytes32String(
|
|
486
|
+
decodedMetadata.type
|
|
487
|
+
) as keyof typeof actionMetadataTypes;
|
|
488
|
+
|
|
489
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
490
|
+
actionMetadataTypes[type],
|
|
491
|
+
decodedMetadata.data
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
const payloadFunc = typesPayload[type]
|
|
495
|
+
|
|
496
|
+
if (payloadFunc) {
|
|
497
|
+
const payload = payloadFunc(decodedData, type)
|
|
319
498
|
metadataArr.push(payload);
|
|
320
499
|
}
|
|
321
500
|
|
|
322
|
-
return metadataArr;
|
|
323
|
-
} catch (e) {
|
|
324
|
-
console.log(e);
|
|
325
|
-
return null;
|
|
326
501
|
}
|
|
502
|
+
|
|
503
|
+
return metadataArr;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
510
|
+
* @param {string} txType - The input sentence to modify
|
|
511
|
+
*
|
|
512
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
513
|
+
*/
|
|
514
|
+
export const formatTxType = (txType: string) => {
|
|
515
|
+
const finalSentence = txType
|
|
516
|
+
.replace("-", " ")
|
|
517
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
518
|
+
|
|
519
|
+
return finalSentence;
|
|
327
520
|
};
|