@instadapp/avocado-base 0.0.36 → 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 +165 -103
- package/utils/utils.d.ts +20 -12
|
@@ -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,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,6 +256,57 @@ 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
|
};
|
|
@@ -310,9 +379,96 @@ const getMetadataFromData = (data: string) => {
|
|
|
310
379
|
return metadata;
|
|
311
380
|
};
|
|
312
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
|
+
|
|
313
470
|
const parseMetadata = (metadata: string) => {
|
|
314
471
|
const metadataArr = [];
|
|
315
|
-
let payload = {};
|
|
316
472
|
|
|
317
473
|
const [decodedMultiMetadata = []] =
|
|
318
474
|
(ethers.utils.defaultAbiCoder.decode(
|
|
@@ -335,114 +491,20 @@ const parseMetadata = (metadata: string) => {
|
|
|
335
491
|
decodedMetadata.data
|
|
336
492
|
);
|
|
337
493
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
344
|
-
receiver: decodedData.receiver,
|
|
345
|
-
};
|
|
346
|
-
break;
|
|
347
|
-
case "bridge":
|
|
348
|
-
payload = {
|
|
349
|
-
type,
|
|
350
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
351
|
-
receiver: decodedData.receiver,
|
|
352
|
-
toToken: decodedData.toToken,
|
|
353
|
-
fromToken: decodedData.fromToken,
|
|
354
|
-
toChainId: decodedData.toChainId
|
|
355
|
-
? decodedData.toChainId.toString()
|
|
356
|
-
: null,
|
|
357
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
358
|
-
};
|
|
359
|
-
break;
|
|
360
|
-
case "swap":
|
|
361
|
-
payload = {
|
|
362
|
-
type,
|
|
363
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
364
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
365
|
-
buyToken: decodedData.buyToken,
|
|
366
|
-
sellToken: decodedData.sellToken,
|
|
367
|
-
receiver: decodedData.receiver,
|
|
368
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
369
|
-
};
|
|
370
|
-
break;
|
|
371
|
-
case "upgrade":
|
|
372
|
-
payload = {
|
|
373
|
-
type,
|
|
374
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
375
|
-
walletImpl: decodedData?.walletImpl,
|
|
376
|
-
};
|
|
377
|
-
break;
|
|
378
|
-
case "gas-topup":
|
|
379
|
-
payload = {
|
|
380
|
-
type,
|
|
381
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
382
|
-
token: decodedData.token,
|
|
383
|
-
onBehalf: decodedData.onBehalf,
|
|
384
|
-
};
|
|
385
|
-
break;
|
|
386
|
-
case "dapp":
|
|
387
|
-
payload = {
|
|
388
|
-
type,
|
|
389
|
-
name: decodedData?.name,
|
|
390
|
-
url: decodedData?.url,
|
|
391
|
-
};
|
|
392
|
-
break;
|
|
393
|
-
case "deploy":
|
|
394
|
-
payload = {
|
|
395
|
-
type,
|
|
396
|
-
};
|
|
397
|
-
break;
|
|
398
|
-
|
|
399
|
-
case "permit2":
|
|
400
|
-
payload = {
|
|
401
|
-
type,
|
|
402
|
-
token: decodedData.token,
|
|
403
|
-
spender: decodedData.spender,
|
|
404
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
405
|
-
expiration: decodedData.expiration,
|
|
406
|
-
};
|
|
407
|
-
break;
|
|
408
|
-
|
|
409
|
-
case "cross-transfer":
|
|
410
|
-
payload = {
|
|
411
|
-
type,
|
|
412
|
-
fromToken: decodedData.fromToken,
|
|
413
|
-
toToken: decodedData.toToken,
|
|
414
|
-
toChainId: decodedData.toChainId
|
|
415
|
-
? decodedData.toChainId.toString()
|
|
416
|
-
: null,
|
|
417
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
418
|
-
receiver: decodedData.receiver,
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
break;
|
|
422
|
-
case "auth":
|
|
423
|
-
payload = {
|
|
424
|
-
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
425
|
-
address: decodedData.address,
|
|
426
|
-
chainId: decodedData.chainId ? decodedData.chainId.toString() : null,
|
|
427
|
-
remove: decodedData.remove,
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
break;
|
|
431
|
-
case "instadapp-pro":
|
|
432
|
-
payload = {
|
|
433
|
-
type,
|
|
434
|
-
castDetails: decodedData.castDetails,
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
break;
|
|
494
|
+
const payloadFunc = typesPayload[type]
|
|
495
|
+
|
|
496
|
+
if (payloadFunc) {
|
|
497
|
+
const payload = payloadFunc(decodedData, type)
|
|
498
|
+
metadataArr.push(payload);
|
|
438
499
|
}
|
|
439
500
|
|
|
440
|
-
metadataArr.push(payload);
|
|
441
501
|
}
|
|
442
502
|
|
|
443
503
|
return metadataArr;
|
|
444
504
|
};
|
|
445
505
|
|
|
506
|
+
|
|
507
|
+
|
|
446
508
|
/**
|
|
447
509
|
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
448
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,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
|
};
|