@instadapp/avocado-base 0.0.0-dev.e90081b → 0.0.0-dev.ebef45a
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/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/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/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 +72 -0
- package/components/AuthorityAvatar.vue +38 -0
- package/components/ChainLogo.vue +14 -556
- package/components/CopyClipboard.vue +64 -0
- package/components/metadata/Bridge.vue +59 -0
- package/components/metadata/CrossTransfer.vue +71 -0
- package/components/metadata/GasTopup.vue +39 -0
- package/components/metadata/Permit2.vue +42 -0
- package/components/metadata/Signers.vue +47 -0
- package/components/metadata/Swap.vue +74 -0
- package/components/metadata/Transfer.vue +50 -0
- package/components.d.ts +13 -0
- package/nuxt.config.ts +17 -1
- package/package.json +9 -4
- package/utils/avocado.ts +2 -0
- package/utils/bignumber.ts +20 -0
- package/utils/formatter.ts +1 -1
- package/utils/helper.ts +8 -0
- package/utils/metadata.ts +295 -186
- package/utils/network.ts +133 -79
- package/utils/services.ts +21 -0
- package/utils/utils.d.ts +129 -114
package/utils/metadata.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
2
|
import { Forwarder__factory } from "../contracts";
|
|
3
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;
|
|
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",
|
|
@@ -43,6 +61,10 @@ const actionMetadataTypes = {
|
|
|
43
61
|
"uint48 expiration",
|
|
44
62
|
],
|
|
45
63
|
"instadapp-pro": ["string castDetails"],
|
|
64
|
+
'add-signers': ['address[] signers'],
|
|
65
|
+
'remove-signers': ['address[] signers'],
|
|
66
|
+
'change-threshold': ['uint8 count'],
|
|
67
|
+
'rejection': ['bytes32 id'],
|
|
46
68
|
};
|
|
47
69
|
|
|
48
70
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -63,7 +85,7 @@ export const encodeDappMetadata = (
|
|
|
63
85
|
);
|
|
64
86
|
|
|
65
87
|
const data = encodeMetadata({
|
|
66
|
-
type:
|
|
88
|
+
type: MetadataEnums.dapp,
|
|
67
89
|
encodedData,
|
|
68
90
|
});
|
|
69
91
|
|
|
@@ -80,7 +102,21 @@ export const encodeTransferMetadata = (
|
|
|
80
102
|
);
|
|
81
103
|
|
|
82
104
|
const data = encodeMetadata({
|
|
83
|
-
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,
|
|
84
120
|
encodedData,
|
|
85
121
|
});
|
|
86
122
|
|
|
@@ -103,7 +139,7 @@ export const encodeCrossTransferMetadata = (
|
|
|
103
139
|
);
|
|
104
140
|
|
|
105
141
|
const data = encodeMetadata({
|
|
106
|
-
type: "cross-transfer",
|
|
142
|
+
type: MetadataEnums["cross-transfer"],
|
|
107
143
|
encodedData,
|
|
108
144
|
});
|
|
109
145
|
|
|
@@ -120,7 +156,7 @@ export const encodeAuthMetadata = (
|
|
|
120
156
|
);
|
|
121
157
|
|
|
122
158
|
const data = encodeMetadata({
|
|
123
|
-
type:
|
|
159
|
+
type: MetadataEnums.auth,
|
|
124
160
|
encodedData,
|
|
125
161
|
});
|
|
126
162
|
|
|
@@ -129,7 +165,7 @@ export const encodeAuthMetadata = (
|
|
|
129
165
|
|
|
130
166
|
export const encodeDeployMetadata = (single = true) => {
|
|
131
167
|
const data = encodeMetadata({
|
|
132
|
-
type:
|
|
168
|
+
type: MetadataEnums.deploy,
|
|
133
169
|
encodedData: "0x",
|
|
134
170
|
});
|
|
135
171
|
|
|
@@ -146,7 +182,7 @@ export const encodeWCSignMetadata = (
|
|
|
146
182
|
);
|
|
147
183
|
|
|
148
184
|
const data = encodeMetadata({
|
|
149
|
-
type:
|
|
185
|
+
type: MetadataEnums.permit2,
|
|
150
186
|
encodedData,
|
|
151
187
|
});
|
|
152
188
|
|
|
@@ -163,7 +199,7 @@ export const encodeUpgradeMetadata = (
|
|
|
163
199
|
);
|
|
164
200
|
|
|
165
201
|
const data = encodeMetadata({
|
|
166
|
-
type:
|
|
202
|
+
type: MetadataEnums.upgrade,
|
|
167
203
|
encodedData,
|
|
168
204
|
});
|
|
169
205
|
|
|
@@ -187,7 +223,7 @@ export const encodeSwapMetadata = (
|
|
|
187
223
|
);
|
|
188
224
|
|
|
189
225
|
const data = encodeMetadata({
|
|
190
|
-
type:
|
|
226
|
+
type: MetadataEnums.swap,
|
|
191
227
|
encodedData,
|
|
192
228
|
});
|
|
193
229
|
|
|
@@ -203,10 +239,8 @@ export const encodeTopupMetadata = (
|
|
|
203
239
|
[params.amount, params.token, params.onBehalf]
|
|
204
240
|
);
|
|
205
241
|
|
|
206
|
-
console.log(params);
|
|
207
|
-
|
|
208
242
|
const data = encodeMetadata({
|
|
209
|
-
type: "gas-topup",
|
|
243
|
+
type: MetadataEnums["gas-topup"],
|
|
210
244
|
encodedData,
|
|
211
245
|
});
|
|
212
246
|
|
|
@@ -231,7 +265,58 @@ export const encodeBridgeMetadata = (
|
|
|
231
265
|
);
|
|
232
266
|
|
|
233
267
|
const data = encodeMetadata({
|
|
234
|
-
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"],
|
|
235
320
|
encodedData,
|
|
236
321
|
});
|
|
237
322
|
|
|
@@ -242,186 +327,210 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
242
327
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
243
328
|
};
|
|
244
329
|
|
|
245
|
-
export const
|
|
330
|
+
export const decodeData = (data: string) => {
|
|
331
|
+
try {
|
|
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) => {
|
|
246
342
|
try {
|
|
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
|
-
|
|
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;
|
|
357
|
+
} else {
|
|
358
|
+
metadata = executeData.metadata_;
|
|
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;
|
|
280
377
|
} 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
|
-
}
|
|
378
|
+
metadata = executeDataV3.params_.metadata;
|
|
290
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
|
+
};
|
|
291
397
|
|
|
292
|
-
const metadataArr = [];
|
|
293
|
-
|
|
294
|
-
const [decodedMultiMetadata = []] =
|
|
295
|
-
(ethers.utils.defaultAbiCoder.decode(
|
|
296
|
-
multiMetadataTypes,
|
|
297
|
-
metadata
|
|
298
|
-
) as string[]) || [];
|
|
299
|
-
|
|
300
|
-
for (let metadata of decodedMultiMetadata) {
|
|
301
|
-
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
302
|
-
metadataTypes,
|
|
303
|
-
metadata
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
const type = ethers.utils.parseBytes32String(
|
|
307
|
-
decodedMetadata.type
|
|
308
|
-
) as keyof typeof actionMetadataTypes;
|
|
309
|
-
|
|
310
|
-
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
311
|
-
actionMetadataTypes[type],
|
|
312
|
-
decodedMetadata.data
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
switch (type) {
|
|
316
|
-
case "transfer":
|
|
317
|
-
payload = {
|
|
318
|
-
type,
|
|
319
|
-
token: decodedData.token,
|
|
320
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
321
|
-
receiver: decodedData.receiver,
|
|
322
|
-
};
|
|
323
|
-
break;
|
|
324
|
-
case "bridge":
|
|
325
|
-
payload = {
|
|
326
|
-
type,
|
|
327
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
328
|
-
receiver: decodedData.receiver,
|
|
329
|
-
toToken: decodedData.toToken,
|
|
330
|
-
fromToken: decodedData.fromToken,
|
|
331
|
-
toChainId: decodedData.toChainId
|
|
332
|
-
? decodedData.toChainId.toString()
|
|
333
|
-
: null,
|
|
334
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
335
|
-
};
|
|
336
|
-
break;
|
|
337
|
-
case "swap":
|
|
338
|
-
payload = {
|
|
339
|
-
type,
|
|
340
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
341
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
342
|
-
buyToken: decodedData.buyToken,
|
|
343
|
-
sellToken: decodedData.sellToken,
|
|
344
|
-
receiver: decodedData.receiver,
|
|
345
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
346
|
-
};
|
|
347
|
-
break;
|
|
348
|
-
case "upgrade":
|
|
349
|
-
payload = {
|
|
350
|
-
type,
|
|
351
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
352
|
-
walletImpl: decodedData?.walletImpl,
|
|
353
|
-
};
|
|
354
|
-
break;
|
|
355
|
-
case "gas-topup":
|
|
356
|
-
payload = {
|
|
357
|
-
type,
|
|
358
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
359
|
-
token: decodedData.token,
|
|
360
|
-
onBehalf: decodedData.onBehalf,
|
|
361
|
-
};
|
|
362
|
-
break;
|
|
363
|
-
case "dapp":
|
|
364
|
-
payload = {
|
|
365
|
-
type,
|
|
366
|
-
name: decodedData?.name,
|
|
367
|
-
url: decodedData?.url,
|
|
368
|
-
};
|
|
369
|
-
break;
|
|
370
|
-
case "deploy":
|
|
371
|
-
payload = {
|
|
372
|
-
type,
|
|
373
|
-
};
|
|
374
|
-
break;
|
|
375
|
-
|
|
376
|
-
case "permit2":
|
|
377
|
-
payload = {
|
|
378
|
-
type,
|
|
379
|
-
token: decodedData.token,
|
|
380
|
-
spender: decodedData.spender,
|
|
381
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
382
|
-
expiration: decodedData.expiration,
|
|
383
|
-
};
|
|
384
|
-
break;
|
|
385
|
-
|
|
386
|
-
case "cross-transfer":
|
|
387
|
-
payload = {
|
|
388
|
-
type,
|
|
389
|
-
fromToken: decodedData.fromToken,
|
|
390
|
-
toToken: decodedData.toToken,
|
|
391
|
-
toChainId: decodedData.toChainId
|
|
392
|
-
? decodedData.toChainId.toString()
|
|
393
|
-
: null,
|
|
394
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
395
|
-
receiver: decodedData.receiver,
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
break;
|
|
399
|
-
case "auth":
|
|
400
|
-
payload = {
|
|
401
|
-
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
402
|
-
address: decodedData.address,
|
|
403
|
-
chainId: decodedData.chainId
|
|
404
|
-
? decodedData.chainId.toString()
|
|
405
|
-
: null,
|
|
406
|
-
remove: decodedData.remove,
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
break;
|
|
410
|
-
case "instadapp-pro":
|
|
411
|
-
payload = {
|
|
412
|
-
type,
|
|
413
|
-
castDetails: decodedData.castDetails,
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
398
|
|
|
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
|
+
};
|
|
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)
|
|
419
514
|
metadataArr.push(payload);
|
|
420
515
|
}
|
|
421
516
|
|
|
422
|
-
return metadataArr;
|
|
423
|
-
} catch (e) {
|
|
424
|
-
console.log(e);
|
|
425
|
-
return null;
|
|
426
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;
|
|
427
536
|
};
|