@instadapp/avocado-base 0.0.0-dev.b270f2b → 0.0.0-dev.b89d937
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 +8 -8
- 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/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 +40 -0
- package/components/ActionMetadata.vue +79 -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 +63 -0
- package/components/metadata/Swap.vue +74 -0
- package/components/metadata/Transfer.vue +50 -0
- package/components.d.ts +13 -0
- package/contracts/Forwarder.ts +4 -4
- package/contracts/MultisigForwarder.ts +859 -0
- package/contracts/factories/Forwarder__factory.ts +8 -8
- 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 +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 +335 -171
- package/utils/network.ts +163 -80
- package/utils/services.ts +21 -0
- package/utils/utils.d.ts +128 -114
package/utils/metadata.ts
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
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
|
+
"transaction-builder": "transaction-builder",
|
|
23
|
+
} as const;
|
|
3
24
|
|
|
4
25
|
const multiMetadataTypes = ["bytes[]"];
|
|
5
26
|
|
|
6
27
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
7
28
|
|
|
8
|
-
const actionMetadataTypes = {
|
|
29
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
9
30
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
10
31
|
"cross-transfer": [
|
|
11
32
|
"address fromToken",
|
|
@@ -34,14 +55,21 @@ const actionMetadataTypes = {
|
|
|
34
55
|
"gas-topup": ["uint256 amount", "address token", "address onBehalf"],
|
|
35
56
|
upgrade: ["bytes32 version", "address walletImpl"],
|
|
36
57
|
dapp: ["string name", "string url"],
|
|
58
|
+
import: ["bytes32 protocol", "uint256 valueInUsd"],
|
|
37
59
|
auth: ["address address", "uint256 chainId", "bool remove"],
|
|
38
60
|
deploy: [],
|
|
61
|
+
"transaction-builder": ["bytes32 actionCount"],
|
|
39
62
|
permit2: [
|
|
40
63
|
"address token",
|
|
41
64
|
"address spender",
|
|
42
65
|
"uint160 amount",
|
|
43
66
|
"uint48 expiration",
|
|
44
67
|
],
|
|
68
|
+
"instadapp-pro": ["string castDetails"],
|
|
69
|
+
"add-signers": ["address[] signers"],
|
|
70
|
+
"remove-signers": ["address[] signers"],
|
|
71
|
+
"change-threshold": ["uint8 count"],
|
|
72
|
+
rejection: ["bytes32 id"],
|
|
45
73
|
};
|
|
46
74
|
|
|
47
75
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -62,7 +90,7 @@ export const encodeDappMetadata = (
|
|
|
62
90
|
);
|
|
63
91
|
|
|
64
92
|
const data = encodeMetadata({
|
|
65
|
-
type:
|
|
93
|
+
type: MetadataEnums.dapp,
|
|
66
94
|
encodedData,
|
|
67
95
|
});
|
|
68
96
|
|
|
@@ -79,7 +107,21 @@ export const encodeTransferMetadata = (
|
|
|
79
107
|
);
|
|
80
108
|
|
|
81
109
|
const data = encodeMetadata({
|
|
82
|
-
type:
|
|
110
|
+
type: MetadataEnums.transfer,
|
|
111
|
+
encodedData,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return single ? encodeMultipleActions(data) : data;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
118
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
119
|
+
actionMetadataTypes.rejection,
|
|
120
|
+
[id]
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const data = encodeMetadata({
|
|
124
|
+
type: MetadataEnums.rejection,
|
|
83
125
|
encodedData,
|
|
84
126
|
});
|
|
85
127
|
|
|
@@ -102,7 +144,7 @@ export const encodeCrossTransferMetadata = (
|
|
|
102
144
|
);
|
|
103
145
|
|
|
104
146
|
const data = encodeMetadata({
|
|
105
|
-
type: "cross-transfer",
|
|
147
|
+
type: MetadataEnums["cross-transfer"],
|
|
106
148
|
encodedData,
|
|
107
149
|
});
|
|
108
150
|
|
|
@@ -119,7 +161,7 @@ export const encodeAuthMetadata = (
|
|
|
119
161
|
);
|
|
120
162
|
|
|
121
163
|
const data = encodeMetadata({
|
|
122
|
-
type:
|
|
164
|
+
type: MetadataEnums.auth,
|
|
123
165
|
encodedData,
|
|
124
166
|
});
|
|
125
167
|
|
|
@@ -128,13 +170,30 @@ export const encodeAuthMetadata = (
|
|
|
128
170
|
|
|
129
171
|
export const encodeDeployMetadata = (single = true) => {
|
|
130
172
|
const data = encodeMetadata({
|
|
131
|
-
type:
|
|
173
|
+
type: MetadataEnums.deploy,
|
|
132
174
|
encodedData: "0x",
|
|
133
175
|
});
|
|
134
176
|
|
|
135
177
|
return single ? encodeMultipleActions(data) : data;
|
|
136
178
|
};
|
|
137
179
|
|
|
180
|
+
export const encodeTransactionBuilderMetadata = (
|
|
181
|
+
actionCount: string,
|
|
182
|
+
single = true
|
|
183
|
+
) => {
|
|
184
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
185
|
+
actionMetadataTypes["transaction-builder"],
|
|
186
|
+
[actionCount]
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const data = encodeMetadata({
|
|
190
|
+
type: MetadataEnums["transaction-builder"],
|
|
191
|
+
encodedData,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return single ? encodeMultipleActions(data) : data;
|
|
195
|
+
};
|
|
196
|
+
|
|
138
197
|
export const encodeWCSignMetadata = (
|
|
139
198
|
params: SignMetadataProps,
|
|
140
199
|
single = true
|
|
@@ -145,7 +204,7 @@ export const encodeWCSignMetadata = (
|
|
|
145
204
|
);
|
|
146
205
|
|
|
147
206
|
const data = encodeMetadata({
|
|
148
|
-
type:
|
|
207
|
+
type: MetadataEnums.permit2,
|
|
149
208
|
encodedData,
|
|
150
209
|
});
|
|
151
210
|
|
|
@@ -162,7 +221,7 @@ export const encodeUpgradeMetadata = (
|
|
|
162
221
|
);
|
|
163
222
|
|
|
164
223
|
const data = encodeMetadata({
|
|
165
|
-
type:
|
|
224
|
+
type: MetadataEnums.upgrade,
|
|
166
225
|
encodedData,
|
|
167
226
|
});
|
|
168
227
|
|
|
@@ -186,7 +245,7 @@ export const encodeSwapMetadata = (
|
|
|
186
245
|
);
|
|
187
246
|
|
|
188
247
|
const data = encodeMetadata({
|
|
189
|
-
type:
|
|
248
|
+
type: MetadataEnums.swap,
|
|
190
249
|
encodedData,
|
|
191
250
|
});
|
|
192
251
|
|
|
@@ -202,10 +261,8 @@ export const encodeTopupMetadata = (
|
|
|
202
261
|
[params.amount, params.token, params.onBehalf]
|
|
203
262
|
);
|
|
204
263
|
|
|
205
|
-
console.log(params);
|
|
206
|
-
|
|
207
264
|
const data = encodeMetadata({
|
|
208
|
-
type: "gas-topup",
|
|
265
|
+
type: MetadataEnums["gas-topup"],
|
|
209
266
|
encodedData,
|
|
210
267
|
});
|
|
211
268
|
|
|
@@ -230,7 +287,76 @@ export const encodeBridgeMetadata = (
|
|
|
230
287
|
);
|
|
231
288
|
|
|
232
289
|
const data = encodeMetadata({
|
|
233
|
-
type:
|
|
290
|
+
type: MetadataEnums.bridge,
|
|
291
|
+
encodedData,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
return single ? encodeMultipleActions(data) : data;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export const encodeChangeThresholdMetadata = (
|
|
298
|
+
threshold: string | number,
|
|
299
|
+
single = true
|
|
300
|
+
) => {
|
|
301
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
302
|
+
actionMetadataTypes["change-threshold"],
|
|
303
|
+
[toBN(threshold).toNumber()]
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const data = encodeMetadata({
|
|
307
|
+
type: MetadataEnums["change-threshold"],
|
|
308
|
+
encodedData,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
return single ? encodeMultipleActions(data) : data;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export const encodeRemoveSignersMetadata = (
|
|
315
|
+
addresses: string[],
|
|
316
|
+
single = true
|
|
317
|
+
) => {
|
|
318
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
319
|
+
actionMetadataTypes["remove-signers"],
|
|
320
|
+
[addresses]
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
const data = encodeMetadata({
|
|
324
|
+
type: MetadataEnums["remove-signers"],
|
|
325
|
+
encodedData,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
return single ? encodeMultipleActions(data) : data;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export const encodeImportMetadata = (
|
|
332
|
+
protocol: string,
|
|
333
|
+
valueInUsd: string,
|
|
334
|
+
single = true
|
|
335
|
+
) => {
|
|
336
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
337
|
+
actionMetadataTypes["import"],
|
|
338
|
+
[protocol, valueInUsd]
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
const data = encodeMetadata({
|
|
342
|
+
type: MetadataEnums["import"],
|
|
343
|
+
encodedData,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
return single ? encodeMultipleActions(data) : data;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
export const encodeAddSignersMetadata = (
|
|
350
|
+
addresses: string[],
|
|
351
|
+
single = true
|
|
352
|
+
) => {
|
|
353
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
354
|
+
actionMetadataTypes["add-signers"],
|
|
355
|
+
[addresses]
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
const data = encodeMetadata({
|
|
359
|
+
type: MetadataEnums["add-signers"],
|
|
234
360
|
encodedData,
|
|
235
361
|
});
|
|
236
362
|
|
|
@@ -241,169 +367,207 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
241
367
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
242
368
|
};
|
|
243
369
|
|
|
244
|
-
export const
|
|
370
|
+
export const decodeData = (data: string) => {
|
|
245
371
|
try {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
372
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
373
|
+
|
|
374
|
+
return parseMetadata(metadata);
|
|
375
|
+
} catch (e) {
|
|
376
|
+
// console.log(e);
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
export const decodeMetadata = (metadata: string) => {
|
|
382
|
+
try {
|
|
383
|
+
return parseMetadata(metadata);
|
|
384
|
+
} catch (e) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const iface = Forwarder__factory.createInterface();
|
|
390
|
+
const ifaceMultisig = MultisigForwarder__factory.createInterface();
|
|
391
|
+
|
|
392
|
+
const getMetadataFromData = (data: string) => {
|
|
393
|
+
let metadata = "0x";
|
|
394
|
+
|
|
395
|
+
if (data.startsWith("0x18e7f485")) {
|
|
396
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
397
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
398
|
+
return null;
|
|
269
399
|
} else {
|
|
270
|
-
|
|
271
|
-
if (
|
|
272
|
-
executeDataV3.params_.metadata === "0x" ||
|
|
273
|
-
!executeDataV3.params_.metadata
|
|
274
|
-
) {
|
|
275
|
-
return null;
|
|
276
|
-
} else {
|
|
277
|
-
metadata = executeDataV3.params_.metadata;
|
|
278
|
-
}
|
|
400
|
+
metadata = executeData.metadata_;
|
|
279
401
|
}
|
|
402
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
403
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
404
|
+
if (
|
|
405
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
406
|
+
!executeDataV2.params_.metadata
|
|
407
|
+
) {
|
|
408
|
+
return null;
|
|
409
|
+
} else {
|
|
410
|
+
metadata = executeDataV2.params_.metadata;
|
|
411
|
+
}
|
|
412
|
+
} else {
|
|
413
|
+
const executeDataMultisig = ifaceMultisig.decodeFunctionData(
|
|
414
|
+
"executeV1",
|
|
415
|
+
data
|
|
416
|
+
);
|
|
417
|
+
if (
|
|
418
|
+
executeDataMultisig.params_.metadata === "0x" ||
|
|
419
|
+
!executeDataMultisig.params_.metadata
|
|
420
|
+
) {
|
|
421
|
+
return null;
|
|
422
|
+
} else {
|
|
423
|
+
metadata = executeDataMultisig.params_.metadata;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return metadata;
|
|
428
|
+
};
|
|
280
429
|
|
|
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
|
-
|
|
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
|
-
|
|
430
|
+
const typesPayload: IPayload = {
|
|
431
|
+
import: (data, type) => ({
|
|
432
|
+
type,
|
|
433
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
434
|
+
valueInUsd: toBN(data.valueInUsd).toFixed(),
|
|
435
|
+
}),
|
|
436
|
+
transfer: (data, type) => ({
|
|
437
|
+
type,
|
|
438
|
+
token: data.token,
|
|
439
|
+
amount: toBN(data.amount).toFixed(),
|
|
440
|
+
receiver: data.receiver,
|
|
441
|
+
}),
|
|
442
|
+
bridge: (data, type) => ({
|
|
443
|
+
type,
|
|
444
|
+
amount: toBN(data.amount).toFixed(),
|
|
445
|
+
receiver: data.receiver,
|
|
446
|
+
toToken: data.toToken,
|
|
447
|
+
fromToken: data.fromToken,
|
|
448
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
449
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
450
|
+
}),
|
|
451
|
+
swap: (data, type) => ({
|
|
452
|
+
type,
|
|
453
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
454
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
455
|
+
buyToken: data.buyToken,
|
|
456
|
+
sellToken: data.sellToken,
|
|
457
|
+
receiver: data.receiver,
|
|
458
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
459
|
+
}),
|
|
460
|
+
upgrade: (data, type) => ({
|
|
461
|
+
type,
|
|
462
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
463
|
+
walletImpl: data.walletImpl,
|
|
464
|
+
}),
|
|
465
|
+
"gas-topup": (data, type) => ({
|
|
466
|
+
type,
|
|
467
|
+
amount: toBN(data.amount).toFixed(),
|
|
468
|
+
token: data.token,
|
|
469
|
+
onBehalf: data.onBehalf,
|
|
470
|
+
}),
|
|
471
|
+
dapp: (data, type) => ({
|
|
472
|
+
type,
|
|
473
|
+
name: data.name,
|
|
474
|
+
url: data.url,
|
|
475
|
+
}),
|
|
476
|
+
deploy: (data, type) => ({
|
|
477
|
+
type,
|
|
478
|
+
}),
|
|
479
|
+
"transaction-builder": (data, type) => ({
|
|
480
|
+
type,
|
|
481
|
+
actionCount: data.actionCount ? toBN(data.actionCount).toNumber() : 0,
|
|
482
|
+
}),
|
|
483
|
+
permit2: (data, type) => ({
|
|
484
|
+
type,
|
|
485
|
+
token: data.token,
|
|
486
|
+
spender: data.spender,
|
|
487
|
+
amount: toBN(data.amount).toFixed(),
|
|
488
|
+
expiration: data.expiration,
|
|
489
|
+
}),
|
|
490
|
+
"cross-transfer": (data, type) => ({
|
|
491
|
+
type,
|
|
492
|
+
fromToken: data.fromToken,
|
|
493
|
+
toToken: data.toToken,
|
|
494
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
495
|
+
amount: toBN(data.amount).toFixed(),
|
|
496
|
+
receiver: data.receiver,
|
|
497
|
+
}),
|
|
498
|
+
auth: (data) => ({
|
|
499
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
500
|
+
address: data.address,
|
|
501
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
502
|
+
remove: data.remove,
|
|
503
|
+
}),
|
|
504
|
+
"instadapp-pro": (data, type) => ({
|
|
505
|
+
type,
|
|
506
|
+
castDetails: data.castDetails,
|
|
507
|
+
}),
|
|
508
|
+
rejection: (data, type) => ({
|
|
509
|
+
type,
|
|
510
|
+
id: data.id,
|
|
511
|
+
}),
|
|
512
|
+
"add-signers": (data, type) => ({
|
|
513
|
+
type,
|
|
514
|
+
addresses: data.signers,
|
|
515
|
+
}),
|
|
516
|
+
"remove-signers": (data, type) => ({
|
|
517
|
+
type,
|
|
518
|
+
addresses: data.signers,
|
|
519
|
+
}),
|
|
520
|
+
"change-threshold": (data, type) => ({
|
|
521
|
+
type,
|
|
522
|
+
count: data.count,
|
|
523
|
+
}),
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
const parseMetadata = (metadata: string) => {
|
|
527
|
+
const metadataArr = [];
|
|
528
|
+
|
|
529
|
+
const [decodedMultiMetadata = []] =
|
|
530
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
531
|
+
multiMetadataTypes,
|
|
532
|
+
metadata
|
|
533
|
+
) as string[]) || [];
|
|
534
|
+
|
|
535
|
+
for (let metadata of decodedMultiMetadata) {
|
|
536
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
537
|
+
metadataTypes,
|
|
538
|
+
metadata
|
|
539
|
+
);
|
|
540
|
+
|
|
541
|
+
const type = ethers.utils.parseBytes32String(
|
|
542
|
+
decodedMetadata.type
|
|
543
|
+
) as keyof typeof actionMetadataTypes;
|
|
544
|
+
|
|
545
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
546
|
+
actionMetadataTypes[type],
|
|
547
|
+
decodedMetadata.data
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
const payloadFunc = typesPayload[type];
|
|
400
551
|
|
|
552
|
+
if (payloadFunc) {
|
|
553
|
+
const payload = payloadFunc(decodedData, type);
|
|
401
554
|
metadataArr.push(payload);
|
|
402
555
|
}
|
|
403
|
-
|
|
404
|
-
return metadataArr;
|
|
405
|
-
} catch (e) {
|
|
406
|
-
console.log(e);
|
|
407
|
-
return null;
|
|
408
556
|
}
|
|
557
|
+
|
|
558
|
+
return metadataArr;
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
563
|
+
* @param {string} txType - The input sentence to modify
|
|
564
|
+
*
|
|
565
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
566
|
+
*/
|
|
567
|
+
export const formatTxType = (txType: string) => {
|
|
568
|
+
const finalSentence = txType
|
|
569
|
+
.replace("-", " ")
|
|
570
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
571
|
+
|
|
572
|
+
return finalSentence;
|
|
409
573
|
};
|