@instadapp/avocado-base 0.0.0-dev.d63c845 → 0.0.0-dev.d8050bd

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.
@@ -6,9 +6,11 @@ export type { BalanceResolver } from "./BalanceResolver";
6
6
  export type { Erc20 } from "./Erc20";
7
7
  export type { Forwarder } from "./Forwarder";
8
8
  export type { GaslessWallet } from "./GaslessWallet";
9
+ export type { MultisigForwarder } from "./MultisigForwarder";
9
10
  export * as factories from "./factories";
10
11
  export { AvoFactoryProxy__factory } from "./factories/AvoFactoryProxy__factory";
11
12
  export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
12
13
  export { Erc20__factory } from "./factories/Erc20__factory";
13
14
  export { Forwarder__factory } from "./factories/Forwarder__factory";
14
15
  export { GaslessWallet__factory } from "./factories/GaslessWallet__factory";
16
+ export { MultisigForwarder__factory } from "./factories/MultisigForwarder__factory";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.d63c845",
3
+ "version": "0.0.0-dev.d8050bd",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
@@ -20,11 +20,13 @@
20
20
  "nuxt-svgo": "^3.1.0",
21
21
  "rimraf": "^3.0.2",
22
22
  "typechain": "^8.1.1",
23
- "unplugin-vue-components": "^0.25.1"
23
+ "unplugin-vue-components": "^0.25.1",
24
+ "vue-tippy": "^6.0.0"
24
25
  },
25
26
  "dependencies": {
26
27
  "@vueuse/nuxt": "^10.2.0",
27
28
  "bignumber.js": "^9.1.1",
28
- "ethers": "^5.7.2"
29
+ "ethers": "^5.7.2",
30
+ "xxhashjs": "^0.2.2"
29
31
  }
30
32
  }
@@ -72,7 +72,7 @@ export function formatDecimal(value: string | number, fractionDigits?: number) {
72
72
  let decimals;
73
73
 
74
74
  if (num.lt(1)) {
75
- decimals = 8;
75
+ decimals = 4;
76
76
  } else if (num.lt(10)) {
77
77
  decimals = 6;
78
78
  } else if (num.lt(100)) {
@@ -84,7 +84,7 @@ export function formatDecimal(value: string | number, fractionDigits?: number) {
84
84
  } else if (num.lt(100000)) {
85
85
  decimals = 1;
86
86
  } else {
87
- decimals = 4;
87
+ decimals = 0;
88
88
  }
89
89
 
90
90
  const formattedNumber = num.toFixed(fractionDigits || decimals);
package/utils/helper.ts CHANGED
@@ -58,4 +58,5 @@ export function formatMultipleAddresses(addresses: string[], shorten = true) {
58
58
  const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
59
59
 
60
60
  return formattedString
61
- }
61
+ }
62
+
package/utils/metadata.ts CHANGED
@@ -1,23 +1,27 @@
1
1
  import { ethers, utils } from "ethers";
2
- import { Forwarder__factory } from "../contracts";
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;
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
+ "tx-builder": "tx-builder",
23
+ "avocado-bridge": "avocado-bridge",
24
+ } as const;
21
25
 
22
26
  const multiMetadataTypes = ["bytes[]"];
23
27
 
@@ -52,8 +56,10 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
52
56
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
53
57
  upgrade: ["bytes32 version", "address walletImpl"],
54
58
  dapp: ["string name", "string url"],
59
+ import: ["bytes32 protocol", "uint256 valueInUsd"],
55
60
  auth: ["address address", "uint256 chainId", "bool remove"],
56
61
  deploy: [],
62
+ "tx-builder": ["bytes32 actionCount"],
57
63
  permit2: [
58
64
  "address token",
59
65
  "address spender",
@@ -61,10 +67,11 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
61
67
  "uint48 expiration",
62
68
  ],
63
69
  "instadapp-pro": ["string castDetails"],
64
- 'add-signers': ['address[] signers'],
65
- 'remove-signers': ['address[] signers'],
66
- 'change-threshold': ['uint8 count'],
67
- 'rejection': ['bytes32 id'],
70
+ "add-signers": ["address[] signers"],
71
+ "remove-signers": ["address[] signers"],
72
+ "change-threshold": ["uint8 count"],
73
+ rejection: ["bytes32 id"],
74
+ "avocado-bridge": ["bytes32 id", "uint256 toChainId"],
68
75
  };
69
76
 
70
77
  const encodeMetadata = (props: MetadataProps) => {
@@ -92,6 +99,24 @@ export const encodeDappMetadata = (
92
99
  return single ? encodeMultipleActions(data) : data;
93
100
  };
94
101
 
102
+ export const encodeAvocadoBridgeMetadata = (
103
+ id: string,
104
+ toChainId: string | number,
105
+ single = true
106
+ ) => {
107
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
108
+ actionMetadataTypes["avocado-bridge"],
109
+ [id, toChainId]
110
+ );
111
+
112
+ const data = encodeMetadata({
113
+ type: MetadataEnums["avocado-bridge"],
114
+ encodedData,
115
+ });
116
+
117
+ return single ? encodeMultipleActions(data) : data;
118
+ };
119
+
95
120
  export const encodeTransferMetadata = (
96
121
  params: SendMetadataProps,
97
122
  single = true
@@ -172,6 +197,23 @@ export const encodeDeployMetadata = (single = true) => {
172
197
  return single ? encodeMultipleActions(data) : data;
173
198
  };
174
199
 
200
+ export const encodeTransactionBuilderMetadata = (
201
+ actionCount: string,
202
+ single = true
203
+ ) => {
204
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
205
+ actionMetadataTypes["tx-builder"],
206
+ [actionCount]
207
+ );
208
+
209
+ const data = encodeMetadata({
210
+ type: MetadataEnums["tx-builder"],
211
+ encodedData,
212
+ });
213
+
214
+ return single ? encodeMultipleActions(data) : data;
215
+ };
216
+
175
217
  export const encodeWCSignMetadata = (
176
218
  params: SignMetadataProps,
177
219
  single = true
@@ -306,6 +348,24 @@ export const encodeRemoveSignersMetadata = (
306
348
  return single ? encodeMultipleActions(data) : data;
307
349
  };
308
350
 
351
+ export const encodeImportMetadata = (
352
+ protocol: string,
353
+ valueInUsd: string,
354
+ single = true
355
+ ) => {
356
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
357
+ actionMetadataTypes["import"],
358
+ [protocol, valueInUsd]
359
+ );
360
+
361
+ const data = encodeMetadata({
362
+ type: MetadataEnums["import"],
363
+ encodedData,
364
+ });
365
+
366
+ return single ? encodeMultipleActions(data) : data;
367
+ };
368
+
309
369
  export const encodeAddSignersMetadata = (
310
370
  addresses: string[],
311
371
  single = true
@@ -346,8 +406,10 @@ export const decodeMetadata = (metadata: string) => {
346
406
  }
347
407
  };
348
408
 
409
+ const iface = Forwarder__factory.createInterface();
410
+ const ifaceMultisig = MultisigForwarder__factory.createInterface();
411
+
349
412
  const getMetadataFromData = (data: string) => {
350
- const iface = Forwarder__factory.createInterface();
351
413
  let metadata = "0x";
352
414
 
353
415
  if (data.startsWith("0x18e7f485")) {
@@ -367,36 +429,30 @@ const getMetadataFromData = (data: string) => {
367
429
  } else {
368
430
  metadata = executeDataV2.params_.metadata;
369
431
  }
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;
377
- } else {
378
- metadata = executeDataV3.params_.metadata;
379
- }
380
432
  } else {
381
- const executeDataMultisigV3 = iface.decodeFunctionData(
382
- "executeMultisigV3",
433
+ const executeDataMultisig = ifaceMultisig.decodeFunctionData(
434
+ "executeV1",
383
435
  data
384
436
  );
385
437
  if (
386
- executeDataMultisigV3.params_.metadata === "0x" ||
387
- !executeDataMultisigV3.params_.metadata
438
+ executeDataMultisig.params_.metadata === "0x" ||
439
+ !executeDataMultisig.params_.metadata
388
440
  ) {
389
441
  return null;
390
442
  } else {
391
- metadata = executeDataMultisigV3.params_.metadata;
443
+ metadata = executeDataMultisig.params_.metadata;
392
444
  }
393
445
  }
394
446
 
395
447
  return metadata;
396
448
  };
397
449
 
398
-
399
450
  const typesPayload: IPayload = {
451
+ import: (data, type) => ({
452
+ type,
453
+ protocol: utils.parseBytes32String(data.protocol || ""),
454
+ valueInUsd: toBN(data.valueInUsd).toFixed(),
455
+ }),
400
456
  transfer: (data, type) => ({
401
457
  type,
402
458
  token: data.token,
@@ -432,15 +488,19 @@ const typesPayload: IPayload = {
432
488
  token: data.token,
433
489
  onBehalf: data.onBehalf,
434
490
  }),
435
- "dapp": (data, type) => ({
491
+ dapp: (data, type) => ({
436
492
  type,
437
493
  name: data.name,
438
494
  url: data.url,
439
495
  }),
440
- "deploy": (data, type) => ({
496
+ deploy: (data, type) => ({
441
497
  type,
442
498
  }),
443
- "permit2": (data, type) => ({
499
+ "tx-builder": (data, type) => ({
500
+ type,
501
+ actionCount: utils.parseBytes32String(data.actionCount || ""),
502
+ }),
503
+ permit2: (data, type) => ({
444
504
  type,
445
505
  token: data.token,
446
506
  spender: data.spender,
@@ -455,7 +515,7 @@ const typesPayload: IPayload = {
455
515
  amount: toBN(data.amount).toFixed(),
456
516
  receiver: data.receiver,
457
517
  }),
458
- "auth": (data) => ({
518
+ auth: (data) => ({
459
519
  type: data.remove ? "remove-authority" : "add-authority",
460
520
  address: data.address,
461
521
  chainId: data.chainId ? data.chainId.toString() : null,
@@ -465,7 +525,7 @@ const typesPayload: IPayload = {
465
525
  type,
466
526
  castDetails: data.castDetails,
467
527
  }),
468
- "rejection": (data, type) => ({
528
+ rejection: (data, type) => ({
469
529
  type,
470
530
  id: data.id,
471
531
  }),
@@ -481,6 +541,11 @@ const typesPayload: IPayload = {
481
541
  type,
482
542
  count: data.count,
483
543
  }),
544
+ "avocado-bridge": (data, type) => ({
545
+ type,
546
+ id: data.id,
547
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
548
+ }),
484
549
  };
485
550
 
486
551
  const parseMetadata = (metadata: string) => {
@@ -507,20 +572,17 @@ const parseMetadata = (metadata: string) => {
507
572
  decodedMetadata.data
508
573
  );
509
574
 
510
- const payloadFunc = typesPayload[type]
511
-
575
+ const payloadFunc = typesPayload[type];
576
+
512
577
  if (payloadFunc) {
513
- const payload = payloadFunc(decodedData, type)
578
+ const payload = payloadFunc(decodedData, type);
514
579
  metadataArr.push(payload);
515
580
  }
516
-
517
581
  }
518
582
 
519
583
  return metadataArr;
520
584
  };
521
585
 
522
-
523
-
524
586
  /**
525
587
  * Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
526
588
  * @param {string} txType - The input sentence to modify