@instadapp/avocado-base 0.0.37 → 0.0.38
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 +22 -2
- package/package.json +1 -1
- package/utils/helper.ts +7 -0
- package/utils/metadata.ts +155 -115
- package/utils/utils.d.ts +20 -13
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
|
|
3
3
|
const props = defineProps<{
|
|
4
|
-
metadata:
|
|
4
|
+
metadata: {
|
|
5
|
+
type: MetadataTypes
|
|
6
|
+
[key: string]: any
|
|
7
|
+
};
|
|
5
8
|
chain_id: number | string;
|
|
6
9
|
compact?: boolean;
|
|
7
10
|
}>();
|
|
@@ -31,7 +34,7 @@ provide('compact', props.compact);
|
|
|
31
34
|
<div v-if="metadata.type === 'deploy'" class="self-start capitalize">
|
|
32
35
|
{{ metadata?.type }}
|
|
33
36
|
</div>
|
|
34
|
-
<div v-if="metadata.type === '
|
|
37
|
+
<div v-if="metadata.type === 'auth'" class="self-start capitalize flex gap-3">
|
|
35
38
|
Authority {{ metadata.remove ? 'Removed' : 'Added' }}:
|
|
36
39
|
<a
|
|
37
40
|
class="text-primary break-all"
|
|
@@ -49,5 +52,22 @@ provide('compact', props.compact);
|
|
|
49
52
|
Instadapp Pro |
|
|
50
53
|
{{ metadata?.castDetails }}
|
|
51
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>
|
|
52
72
|
</div>
|
|
53
73
|
</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,7 +43,10 @@ const actionMetadataTypes = {
|
|
|
43
43
|
"uint48 expiration",
|
|
44
44
|
],
|
|
45
45
|
"instadapp-pro": ["string castDetails"],
|
|
46
|
-
|
|
46
|
+
'add-signers': ['address[] signers'],
|
|
47
|
+
'remove-signers': ['address[] signers'],
|
|
48
|
+
'change-threshold': ['uint8 count'],
|
|
49
|
+
'rejection': ['bytes32 id'],
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -88,14 +91,14 @@ export const encodeTransferMetadata = (
|
|
|
88
91
|
return single ? encodeMultipleActions(data) : data;
|
|
89
92
|
};
|
|
90
93
|
|
|
91
|
-
export const
|
|
94
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
92
95
|
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
93
|
-
actionMetadataTypes.
|
|
94
|
-
[
|
|
96
|
+
actionMetadataTypes.rejection,
|
|
97
|
+
[id]
|
|
95
98
|
);
|
|
96
99
|
|
|
97
100
|
const data = encodeMetadata({
|
|
98
|
-
type: "
|
|
101
|
+
type: "rejection",
|
|
99
102
|
encodedData,
|
|
100
103
|
});
|
|
101
104
|
|
|
@@ -253,6 +256,57 @@ export const encodeBridgeMetadata = (
|
|
|
253
256
|
return single ? encodeMultipleActions(data) : data;
|
|
254
257
|
};
|
|
255
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
|
+
|
|
256
310
|
export const encodeMultipleActions = (...actionData: string[]) => {
|
|
257
311
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
258
312
|
};
|
|
@@ -325,9 +379,96 @@ const getMetadataFromData = (data: string) => {
|
|
|
325
379
|
return metadata;
|
|
326
380
|
};
|
|
327
381
|
|
|
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
|
+
|
|
328
470
|
const parseMetadata = (metadata: string) => {
|
|
329
471
|
const metadataArr = [];
|
|
330
|
-
let payload = {};
|
|
331
472
|
|
|
332
473
|
const [decodedMultiMetadata = []] =
|
|
333
474
|
(ethers.utils.defaultAbiCoder.decode(
|
|
@@ -350,121 +491,20 @@ const parseMetadata = (metadata: string) => {
|
|
|
350
491
|
decodedMetadata.data
|
|
351
492
|
);
|
|
352
493
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
359
|
-
receiver: decodedData.receiver,
|
|
360
|
-
};
|
|
361
|
-
break;
|
|
362
|
-
case "bridge":
|
|
363
|
-
payload = {
|
|
364
|
-
type,
|
|
365
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
366
|
-
receiver: decodedData.receiver,
|
|
367
|
-
toToken: decodedData.toToken,
|
|
368
|
-
fromToken: decodedData.fromToken,
|
|
369
|
-
toChainId: decodedData.toChainId
|
|
370
|
-
? decodedData.toChainId.toString()
|
|
371
|
-
: null,
|
|
372
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
373
|
-
};
|
|
374
|
-
break;
|
|
375
|
-
case "swap":
|
|
376
|
-
payload = {
|
|
377
|
-
type,
|
|
378
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
379
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
380
|
-
buyToken: decodedData.buyToken,
|
|
381
|
-
sellToken: decodedData.sellToken,
|
|
382
|
-
receiver: decodedData.receiver,
|
|
383
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
384
|
-
};
|
|
385
|
-
break;
|
|
386
|
-
case "upgrade":
|
|
387
|
-
payload = {
|
|
388
|
-
type,
|
|
389
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
390
|
-
walletImpl: decodedData?.walletImpl,
|
|
391
|
-
};
|
|
392
|
-
break;
|
|
393
|
-
case "gas-topup":
|
|
394
|
-
payload = {
|
|
395
|
-
type,
|
|
396
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
397
|
-
token: decodedData.token,
|
|
398
|
-
onBehalf: decodedData.onBehalf,
|
|
399
|
-
};
|
|
400
|
-
break;
|
|
401
|
-
case "dapp":
|
|
402
|
-
payload = {
|
|
403
|
-
type,
|
|
404
|
-
name: decodedData?.name,
|
|
405
|
-
url: decodedData?.url,
|
|
406
|
-
};
|
|
407
|
-
break;
|
|
408
|
-
case "deploy":
|
|
409
|
-
payload = {
|
|
410
|
-
type,
|
|
411
|
-
};
|
|
412
|
-
break;
|
|
413
|
-
|
|
414
|
-
case "permit2":
|
|
415
|
-
payload = {
|
|
416
|
-
type,
|
|
417
|
-
token: decodedData.token,
|
|
418
|
-
spender: decodedData.spender,
|
|
419
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
420
|
-
expiration: decodedData.expiration,
|
|
421
|
-
};
|
|
422
|
-
break;
|
|
423
|
-
|
|
424
|
-
case "cross-transfer":
|
|
425
|
-
payload = {
|
|
426
|
-
type,
|
|
427
|
-
fromToken: decodedData.fromToken,
|
|
428
|
-
toToken: decodedData.toToken,
|
|
429
|
-
toChainId: decodedData.toChainId
|
|
430
|
-
? decodedData.toChainId.toString()
|
|
431
|
-
: null,
|
|
432
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
433
|
-
receiver: decodedData.receiver,
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
break;
|
|
437
|
-
case "auth":
|
|
438
|
-
payload = {
|
|
439
|
-
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
440
|
-
address: decodedData.address,
|
|
441
|
-
chainId: decodedData.chainId ? decodedData.chainId.toString() : null,
|
|
442
|
-
remove: decodedData.remove,
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
break;
|
|
446
|
-
case "instadapp-pro":
|
|
447
|
-
payload = {
|
|
448
|
-
type,
|
|
449
|
-
castDetails: decodedData.castDetails,
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
break;
|
|
453
|
-
|
|
454
|
-
case "reject":
|
|
455
|
-
payload = {
|
|
456
|
-
type,
|
|
457
|
-
reason: decodedData.reason,
|
|
458
|
-
};
|
|
459
|
-
break;
|
|
494
|
+
const payloadFunc = typesPayload[type]
|
|
495
|
+
|
|
496
|
+
if (payloadFunc) {
|
|
497
|
+
const payload = payloadFunc(decodedData, type)
|
|
498
|
+
metadataArr.push(payload);
|
|
460
499
|
}
|
|
461
500
|
|
|
462
|
-
metadataArr.push(payload);
|
|
463
501
|
}
|
|
464
502
|
|
|
465
503
|
return metadataArr;
|
|
466
504
|
};
|
|
467
505
|
|
|
506
|
+
|
|
507
|
+
|
|
468
508
|
/**
|
|
469
509
|
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
470
510
|
* @param {string} txType - The input sentence to modify
|
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,19 +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"
|
|
116
|
-
| "reject";
|
|
123
|
+
type: MetadataTypes,
|
|
117
124
|
encodedData: string;
|
|
118
125
|
version?: string;
|
|
119
126
|
};
|