@instadapp/avocado-base 0.0.0-dev.c9f5a55 → 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/components/ActionMetadata.vue +26 -3
- package/components/metadata/Bridge.vue +4 -2
- package/components/metadata/CrossTransfer.vue +4 -2
- package/components/metadata/GasTopup.vue +3 -1
- package/components/metadata/Swap.vue +3 -2
- package/components/metadata/Transfer.vue +8 -5
- package/package.json +1 -1
- package/utils/helper.ts +7 -0
- package/utils/metadata.ts +267 -177
- package/utils/utils.d.ts +20 -12
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
|
|
3
|
-
defineProps<{
|
|
4
|
-
metadata:
|
|
3
|
+
const props = defineProps<{
|
|
4
|
+
metadata: {
|
|
5
|
+
type: MetadataTypes
|
|
6
|
+
[key: string]: any
|
|
7
|
+
};
|
|
5
8
|
chain_id: number | string;
|
|
9
|
+
compact?: boolean;
|
|
6
10
|
}>();
|
|
7
11
|
|
|
12
|
+
provide('compact', props.compact);
|
|
13
|
+
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<template>
|
|
@@ -28,7 +34,7 @@ defineProps<{
|
|
|
28
34
|
<div v-if="metadata.type === 'deploy'" class="self-start capitalize">
|
|
29
35
|
{{ metadata?.type }}
|
|
30
36
|
</div>
|
|
31
|
-
<div v-if="metadata.type === '
|
|
37
|
+
<div v-if="metadata.type === 'auth'" class="self-start capitalize flex gap-3">
|
|
32
38
|
Authority {{ metadata.remove ? 'Removed' : 'Added' }}:
|
|
33
39
|
<a
|
|
34
40
|
class="text-primary break-all"
|
|
@@ -46,5 +52,22 @@ defineProps<{
|
|
|
46
52
|
Instadapp Pro |
|
|
47
53
|
{{ metadata?.castDetails }}
|
|
48
54
|
</div>
|
|
55
|
+
|
|
56
|
+
<div v-if="metadata.type === 'add-signers' || metadata.type === 'remove-signers'" class="text-left w-fit" v-tippy="formatMultipleAddresses(metadata.addresses, false)" >
|
|
57
|
+
{{ formatMultipleAddresses(metadata.addresses) }}
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div v-if="metadata.type === 'change-threshold'" class="text-left w-fit" >
|
|
61
|
+
Change Threshold to {{ metadata.count }}
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div v-tippy="{
|
|
65
|
+
content: metadata.id,
|
|
66
|
+
maxWidth: 'none',
|
|
67
|
+
interactive: true,
|
|
68
|
+
}"
|
|
69
|
+
v-if="metadata.type === 'rejection'" class="text-left w-fit">
|
|
70
|
+
{{ shortenHash(metadata.id) }}
|
|
71
|
+
</div>
|
|
49
72
|
</div>
|
|
50
73
|
</template>
|
|
@@ -5,6 +5,8 @@ const props = defineProps<{
|
|
|
5
5
|
chain_id: number | string
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
|
+
const compact = inject('compact');
|
|
9
|
+
|
|
8
10
|
const toToken = asyncComputed(() =>
|
|
9
11
|
fetchTokenByAddress(props.metadata?.toToken, props.metadata?.toChainId)
|
|
10
12
|
);
|
|
@@ -22,12 +24,12 @@ const bridgeAmountFormatted = computed(() =>
|
|
|
22
24
|
class="flex gap-5 items-center"
|
|
23
25
|
v-if="metadata.type === 'bridge' && toToken"
|
|
24
26
|
>
|
|
25
|
-
<span class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
27
|
+
<span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
26
28
|
<span class="inline-flex gap-2.5 items-center">
|
|
27
29
|
<img width="20" height="20" class="w-5 h-5" :src="toToken.logo_url" />
|
|
28
30
|
{{ bridgeAmountFormatted }}
|
|
29
31
|
<span class="uppercase">{{ toToken?.symbol }}</span>
|
|
30
|
-
<SvgoBridge class="text-slate-400 w-
|
|
32
|
+
<SvgoBridge class="text-slate-400 w-4 h-4" />
|
|
31
33
|
<span class="flex items-center gap-2.5">
|
|
32
34
|
<ChainLogo class="w-5" :chain="metadata.toChainId" />
|
|
33
35
|
<span>{{ chainIdToName(metadata.toChainId) }}</span>
|
|
@@ -5,6 +5,8 @@ const props = defineProps<{
|
|
|
5
5
|
chain_id: number | string
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
|
+
const compact = inject('compact');
|
|
9
|
+
|
|
8
10
|
const fromToken = asyncComputed(() => {
|
|
9
11
|
if (!props?.chain_id) return null;
|
|
10
12
|
|
|
@@ -27,7 +29,7 @@ const formattedFromAmount = computed(() =>
|
|
|
27
29
|
</div>
|
|
28
30
|
<div class="flex gap-5 flex-col" v-else>
|
|
29
31
|
<div class="flex items-center gap-5">
|
|
30
|
-
<span class="capitalize text-xs sm:text-sm">Cross-chain send</span>
|
|
32
|
+
<span v-if="!compact" class="capitalize text-xs sm:text-sm">Cross-chain send</span>
|
|
31
33
|
<span class="inline-flex gap-2.5 items-center">
|
|
32
34
|
<img width="20" height="20" class="w-5 h-5" :src="fromToken?.logo_url" />
|
|
33
35
|
{{ formattedFromAmount }}
|
|
@@ -41,7 +43,7 @@ const formattedFromAmount = computed(() =>
|
|
|
41
43
|
<span>{{ chainIdToName(chain_id) }}</span>
|
|
42
44
|
</span>
|
|
43
45
|
|
|
44
|
-
<
|
|
46
|
+
<SvgoArrowRight class="w-4 h-4 text-slate-400" />
|
|
45
47
|
|
|
46
48
|
<span class="flex items-center gap-2.5">
|
|
47
49
|
<ChainLogo class="w-5" :chain="metadata?.toChainId" />
|
|
@@ -9,6 +9,8 @@ const token = asyncComputed(() =>
|
|
|
9
9
|
fetchTokenByAddress(props.metadata?.token, props?.chain_id)
|
|
10
10
|
);
|
|
11
11
|
|
|
12
|
+
const compact = inject('compact');
|
|
13
|
+
|
|
12
14
|
const formattedAmount = computed(() =>
|
|
13
15
|
formatDecimal(
|
|
14
16
|
fromWei(props.metadata?.amount, token?.value?.decimals).toFixed()
|
|
@@ -19,7 +21,7 @@ const formattedAmount = computed(() =>
|
|
|
19
21
|
<template>
|
|
20
22
|
<div v-if="!token" class="rounded-5 w-24 h-4 loading-box" />
|
|
21
23
|
<div class="flex items-center gap-5" v-else>
|
|
22
|
-
<span class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
24
|
+
<span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
23
25
|
<span class="inline-flex gap-2.5 items-center">
|
|
24
26
|
<img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
|
|
25
27
|
{{ formattedAmount }}
|
|
@@ -5,6 +5,7 @@ const props = defineProps<{
|
|
|
5
5
|
chain_id: number | string
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
|
+
const compact = inject('compact');
|
|
8
9
|
|
|
9
10
|
const buyToken = asyncComputed(() =>
|
|
10
11
|
fetchTokenByAddress(props.metadata?.buyToken, props?.chain_id)
|
|
@@ -45,7 +46,7 @@ const formatProtocol = (protocol: string) => {
|
|
|
45
46
|
class="flex items-center gap-5"
|
|
46
47
|
v-else
|
|
47
48
|
>
|
|
48
|
-
<span class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
49
|
+
<span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
49
50
|
<span class="inline-flex gap-2.5 items-center">
|
|
50
51
|
<img width="20" height="20" class="w-5 h-5" :src="sellToken?.logo_url" />
|
|
51
52
|
{{ sellAmountFormatted }}
|
|
@@ -56,7 +57,7 @@ const formatProtocol = (protocol: string) => {
|
|
|
56
57
|
<span class="uppercase">{{ buyToken?.symbol }}</span>
|
|
57
58
|
<span
|
|
58
59
|
class="capitalize hidden sm:flex items-center gap-2.5"
|
|
59
|
-
v-if="metadata.protocol"
|
|
60
|
+
v-if="metadata.protocol && !compact"
|
|
60
61
|
>
|
|
61
62
|
On <ProtocolLogo class="w-5 h-5" :name="metadata.protocol" />
|
|
62
63
|
{{ formatProtocol(metadata.protocol) }}
|
|
@@ -5,6 +5,7 @@ const props = defineProps<{
|
|
|
5
5
|
chain_id: number | string
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
|
+
const compact = inject('compact');
|
|
8
9
|
|
|
9
10
|
const token = asyncComputed(() => {
|
|
10
11
|
if (!props?.chain_id) return null;
|
|
@@ -25,19 +26,21 @@ const formattedAmount = computed(() =>
|
|
|
25
26
|
<template>
|
|
26
27
|
<div v-if="!token" class="rounded-5 w-24 h-4 loading-box" />
|
|
27
28
|
<div class="flex items-center gap-5" v-else>
|
|
28
|
-
<span class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
29
|
+
<span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
29
30
|
<span class="inline-flex gap-2.5 items-center">
|
|
30
31
|
<img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
|
|
31
32
|
{{ formattedAmount }}
|
|
32
33
|
<span class="uppercase">{{ token?.symbol }}</span>
|
|
33
34
|
<SvgoArrowRight class="w-4 h-4 text-slate-400 mx-2" />
|
|
34
|
-
<
|
|
35
|
+
<NuxtLink
|
|
35
36
|
class="text-primary"
|
|
36
|
-
|
|
37
|
+
target="_blank"
|
|
38
|
+
external
|
|
39
|
+
:to="
|
|
37
40
|
getExplorerUrl(chain_id, `/address/${metadata.receiver}`)
|
|
38
41
|
"
|
|
39
|
-
>{{ shortenHash(metadata.receiver) }}
|
|
40
|
-
|
|
42
|
+
>{{ shortenHash(metadata.receiver) }}
|
|
43
|
+
</NuxtLink>
|
|
41
44
|
</span>
|
|
42
45
|
</div>
|
|
43
46
|
</template>
|
package/package.json
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
|
@@ -5,7 +5,7 @@ const multiMetadataTypes = ["bytes[]"];
|
|
|
5
5
|
|
|
6
6
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
7
7
|
|
|
8
|
-
const actionMetadataTypes = {
|
|
8
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
9
9
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
10
10
|
"cross-transfer": [
|
|
11
11
|
"address fromToken",
|
|
@@ -43,6 +43,10 @@ const actionMetadataTypes = {
|
|
|
43
43
|
"uint48 expiration",
|
|
44
44
|
],
|
|
45
45
|
"instadapp-pro": ["string castDetails"],
|
|
46
|
+
'add-signers': ['address[] signers'],
|
|
47
|
+
'remove-signers': ['address[] signers'],
|
|
48
|
+
'change-threshold': ['uint8 count'],
|
|
49
|
+
'rejection': ['bytes32 id'],
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -87,6 +91,20 @@ export const encodeTransferMetadata = (
|
|
|
87
91
|
return single ? encodeMultipleActions(data) : data;
|
|
88
92
|
};
|
|
89
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
|
+
|
|
90
108
|
export const encodeCrossTransferMetadata = (
|
|
91
109
|
params: CrossSendMetadataProps,
|
|
92
110
|
single = true
|
|
@@ -238,193 +256,265 @@ export const encodeBridgeMetadata = (
|
|
|
238
256
|
return single ? encodeMultipleActions(data) : data;
|
|
239
257
|
};
|
|
240
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
|
+
|
|
241
310
|
export const encodeMultipleActions = (...actionData: string[]) => {
|
|
242
311
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
243
312
|
};
|
|
244
313
|
|
|
245
|
-
export const
|
|
314
|
+
export const decodeData = (data: string) => {
|
|
315
|
+
try {
|
|
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) => {
|
|
246
326
|
try {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
262
|
-
if (
|
|
263
|
-
executeDataV2.params_.metadata === "0x" ||
|
|
264
|
-
!executeDataV2.params_.metadata
|
|
265
|
-
) {
|
|
266
|
-
return null;
|
|
267
|
-
} else {
|
|
268
|
-
metadata = executeDataV2.params_.metadata;
|
|
269
|
-
}
|
|
270
|
-
} else if (data.startsWith("0x85114d53")) {
|
|
271
|
-
const executeDataV3 = iface.decodeFunctionData("executeV3", data);
|
|
272
|
-
if (
|
|
273
|
-
executeDataV3.params_.metadata === "0x" ||
|
|
274
|
-
!executeDataV3.params_.metadata
|
|
275
|
-
) {
|
|
276
|
-
return null;
|
|
277
|
-
} else {
|
|
278
|
-
metadata = executeDataV3.params_.metadata;
|
|
279
|
-
}
|
|
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;
|
|
280
341
|
} else {
|
|
281
|
-
|
|
282
|
-
"executeMultisigV3",
|
|
283
|
-
data
|
|
284
|
-
);
|
|
285
|
-
if (
|
|
286
|
-
executeDataMultisigV3.params_.metadata === "0x" ||
|
|
287
|
-
!executeDataMultisigV3.params_.metadata
|
|
288
|
-
) {
|
|
289
|
-
return null;
|
|
290
|
-
} else {
|
|
291
|
-
metadata = executeDataMultisigV3.params_.metadata;
|
|
292
|
-
}
|
|
342
|
+
metadata = executeData.metadata_;
|
|
293
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;
|
|
374
|
+
} else {
|
|
375
|
+
metadata = executeDataMultisigV3.params_.metadata;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return metadata;
|
|
380
|
+
};
|
|
381
|
+
|
|
294
382
|
|
|
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
|
-
type,
|
|
382
|
-
token: decodedData.token,
|
|
383
|
-
spender: decodedData.spender,
|
|
384
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
385
|
-
expiration: decodedData.expiration,
|
|
386
|
-
};
|
|
387
|
-
break;
|
|
388
|
-
|
|
389
|
-
case "cross-transfer":
|
|
390
|
-
payload = {
|
|
391
|
-
type,
|
|
392
|
-
fromToken: decodedData.fromToken,
|
|
393
|
-
toToken: decodedData.toToken,
|
|
394
|
-
toChainId: decodedData.toChainId
|
|
395
|
-
? decodedData.toChainId.toString()
|
|
396
|
-
: null,
|
|
397
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
398
|
-
receiver: decodedData.receiver,
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
break;
|
|
402
|
-
case "auth":
|
|
403
|
-
payload = {
|
|
404
|
-
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
405
|
-
address: decodedData.address,
|
|
406
|
-
chainId: decodedData.chainId
|
|
407
|
-
? decodedData.chainId.toString()
|
|
408
|
-
: null,
|
|
409
|
-
remove: decodedData.remove,
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
break;
|
|
413
|
-
case "instadapp-pro":
|
|
414
|
-
payload = {
|
|
415
|
-
type,
|
|
416
|
-
castDetails: decodedData.castDetails,
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
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
|
+
};
|
|
421
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)
|
|
422
498
|
metadataArr.push(payload);
|
|
423
499
|
}
|
|
424
500
|
|
|
425
|
-
return metadataArr;
|
|
426
|
-
} catch (e) {
|
|
427
|
-
// console.log(e);
|
|
428
|
-
return null;
|
|
429
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;
|
|
430
520
|
};
|
package/utils/utils.d.ts
CHANGED
|
@@ -13,6 +13,25 @@ type ChainId =
|
|
|
13
13
|
| 63400;
|
|
14
14
|
|
|
15
15
|
type ISlackMessageType = "danger" | "error" | "success" | "banner";
|
|
16
|
+
type MetadataTypes = "transfer"
|
|
17
|
+
| "bridge"
|
|
18
|
+
| "swap"
|
|
19
|
+
| "gas-topup"
|
|
20
|
+
| "upgrade"
|
|
21
|
+
| "dapp"
|
|
22
|
+
| "deploy"
|
|
23
|
+
| "permit2"
|
|
24
|
+
| "cross-transfer"
|
|
25
|
+
| "auth"
|
|
26
|
+
| "rejection"
|
|
27
|
+
| 'instadapp-pro'
|
|
28
|
+
| 'add-signers'
|
|
29
|
+
| 'remove-signers'
|
|
30
|
+
| 'change-threshold'
|
|
31
|
+
|
|
32
|
+
type PayloadFunction = (data: any, type: MetadataTypes) => any;
|
|
33
|
+
|
|
34
|
+
type IPayload = Record<MetadataTypes, PayloadFunction>;
|
|
16
35
|
|
|
17
36
|
interface Network {
|
|
18
37
|
name: string;
|
|
@@ -101,18 +120,7 @@ type SwapMetadataProps = {
|
|
|
101
120
|
};
|
|
102
121
|
|
|
103
122
|
type MetadataProps = {
|
|
104
|
-
type:
|
|
105
|
-
| "transfer"
|
|
106
|
-
| "bridge"
|
|
107
|
-
| "swap"
|
|
108
|
-
| "multi"
|
|
109
|
-
| "gas-topup"
|
|
110
|
-
| "upgrade"
|
|
111
|
-
| "dapp"
|
|
112
|
-
| "deploy"
|
|
113
|
-
| "permit2"
|
|
114
|
-
| "cross-transfer"
|
|
115
|
-
| "auth";
|
|
123
|
+
type: MetadataTypes,
|
|
116
124
|
encodedData: string;
|
|
117
125
|
version?: string;
|
|
118
126
|
};
|