@instadapp/avocado-base 0.0.0-dev.fa14908 → 0.0.0-dev.fb3d631

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,23 +1,25 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.fa14908",
3
+ "version": "0.0.0-dev.fb3d631",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
7
+ "engines": {
8
+ "node": ">=v18.18.0"
9
+ },
7
10
  "scripts": {
8
11
  "build": "nuxt build",
9
12
  "dev": "nuxt dev",
10
13
  "generate": "nuxt generate",
11
14
  "preview": "nuxt preview",
12
- "generate:contracts": "rimraf contracts && typechain --target=ethers-v5 'abi/*.json' --out-dir 'contracts'"
15
+ "generate:contracts": "rimraf contracts && typechain --target=ethers-v5 'abi/*.json' --out-dir 'contracts'",
16
+ "typecheck": "nuxi typecheck"
13
17
  },
14
18
  "devDependencies": {
15
- "@instadapp/avocado": "^0.1.10",
16
- "@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
17
- "@nuxtjs/tailwindcss": "^6.6.5",
19
+ "@nuxtjs/tailwindcss": "^6.11.3",
18
20
  "@typechain/ethers-v5": "^10.2.0",
19
- "nuxt": "^3.6.1",
20
- "nuxt-svgo": "^3.1.0",
21
+ "nuxt": "^3.10.1",
22
+ "nuxt-svgo": "^4.0.0",
21
23
  "rimraf": "^3.0.2",
22
24
  "typechain": "^8.1.1",
23
25
  "unplugin-vue-components": "^0.25.1",
@@ -27,6 +29,7 @@
27
29
  "@vueuse/nuxt": "^10.2.0",
28
30
  "bignumber.js": "^9.1.1",
29
31
  "ethers": "^5.7.2",
32
+ "viem": "^2.10.5",
30
33
  "xxhashjs": "^0.2.2"
31
34
  }
32
35
  }
@@ -19,7 +19,7 @@ export function formatPercent(
19
19
  return formatter.format(valueAsNumber);
20
20
  }
21
21
 
22
- export function shortenHash(hash: string, length: number = 4) {
22
+ export function shortenHash(hash: string | `0x${string}`, length: number = 4) {
23
23
  if (!hash) return;
24
24
  if (hash.length < 12) return hash;
25
25
  const beginningChars = hash.startsWith("0x") ? length + 2 : length;
package/utils/metadata.ts CHANGED
@@ -1,23 +1,28 @@
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
+ mass: "mass",
23
+ "tx-builder": "tx-builder",
24
+ "avocado-bridge": "avocado-bridge",
25
+ } as const;
21
26
 
22
27
  const multiMetadataTypes = ["bytes[]"];
23
28
 
@@ -52,8 +57,10 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
52
57
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
53
58
  upgrade: ["bytes32 version", "address walletImpl"],
54
59
  dapp: ["string name", "string url"],
60
+ import: ["bytes32 protocol", "uint256 valueInUsd"],
55
61
  auth: ["address address", "uint256 chainId", "bool remove"],
56
62
  deploy: [],
63
+ "tx-builder": ["bytes32 actionCount"],
57
64
  permit2: [
58
65
  "address token",
59
66
  "address spender",
@@ -61,10 +68,12 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
61
68
  "uint48 expiration",
62
69
  ],
63
70
  "instadapp-pro": ["string castDetails"],
64
- 'add-signers': ['address[] signers'],
65
- 'remove-signers': ['address[] signers'],
66
- 'change-threshold': ['uint8 count'],
67
- 'rejection': ['bytes32 id'],
71
+ "add-signers": ["address[] signers"],
72
+ "remove-signers": ["address[] signers"],
73
+ "change-threshold": ["uint8 count"],
74
+ rejection: ["bytes32 id"],
75
+ "avocado-bridge": ["bytes32 id", "uint256 toChainId"],
76
+ mass: ["bool isMass"],
68
77
  };
69
78
 
70
79
  const encodeMetadata = (props: MetadataProps) => {
@@ -92,6 +101,24 @@ export const encodeDappMetadata = (
92
101
  return single ? encodeMultipleActions(data) : data;
93
102
  };
94
103
 
104
+ export const encodeAvocadoBridgeMetadata = (
105
+ id: string,
106
+ toChainId: string | number,
107
+ single = true
108
+ ) => {
109
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
110
+ actionMetadataTypes["avocado-bridge"],
111
+ [id, toChainId]
112
+ );
113
+
114
+ const data = encodeMetadata({
115
+ type: MetadataEnums["avocado-bridge"],
116
+ encodedData,
117
+ });
118
+
119
+ return single ? encodeMultipleActions(data) : data;
120
+ };
121
+
95
122
  export const encodeTransferMetadata = (
96
123
  params: SendMetadataProps,
97
124
  single = true
@@ -172,6 +199,23 @@ export const encodeDeployMetadata = (single = true) => {
172
199
  return single ? encodeMultipleActions(data) : data;
173
200
  };
174
201
 
202
+ export const encodeTransactionBuilderMetadata = (
203
+ actionCount: string,
204
+ single = true
205
+ ) => {
206
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
207
+ actionMetadataTypes["tx-builder"],
208
+ [actionCount]
209
+ );
210
+
211
+ const data = encodeMetadata({
212
+ type: MetadataEnums["tx-builder"],
213
+ encodedData,
214
+ });
215
+
216
+ return single ? encodeMultipleActions(data) : data;
217
+ };
218
+
175
219
  export const encodeWCSignMetadata = (
176
220
  params: SignMetadataProps,
177
221
  single = true
@@ -306,6 +350,33 @@ export const encodeRemoveSignersMetadata = (
306
350
  return single ? encodeMultipleActions(data) : data;
307
351
  };
308
352
 
353
+ export const encodeImportMetadata = (
354
+ protocol: string,
355
+ valueInUsd: string,
356
+ single = true
357
+ ) => {
358
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
359
+ actionMetadataTypes["import"],
360
+ [protocol, valueInUsd]
361
+ );
362
+
363
+ const data = encodeMetadata({
364
+ type: MetadataEnums["import"],
365
+ encodedData,
366
+ });
367
+
368
+ return single ? encodeMultipleActions(data) : data;
369
+ };
370
+
371
+ export const encodeMassMetadata = (single = true) => {
372
+ const data = encodeMetadata({
373
+ type: MetadataEnums.mass,
374
+ encodedData: '0x',
375
+ });
376
+
377
+ return single ? encodeMultipleActions(data) : data;
378
+ }
379
+
309
380
  export const encodeAddSignersMetadata = (
310
381
  addresses: string[],
311
382
  single = true
@@ -346,8 +417,10 @@ export const decodeMetadata = (metadata: string) => {
346
417
  }
347
418
  };
348
419
 
420
+ const iface = Forwarder__factory.createInterface();
421
+ const ifaceMultisig = MultisigForwarder__factory.createInterface();
422
+
349
423
  const getMetadataFromData = (data: string) => {
350
- const iface = Forwarder__factory.createInterface();
351
424
  let metadata = "0x";
352
425
 
353
426
  if (data.startsWith("0x18e7f485")) {
@@ -367,36 +440,30 @@ const getMetadataFromData = (data: string) => {
367
440
  } else {
368
441
  metadata = executeDataV2.params_.metadata;
369
442
  }
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
443
  } else {
381
- const executeDataMultisigV3 = iface.decodeFunctionData(
382
- "executeMultisigV3",
444
+ const executeDataMultisig = ifaceMultisig.decodeFunctionData(
445
+ "executeV1",
383
446
  data
384
447
  );
385
448
  if (
386
- executeDataMultisigV3.params_.metadata === "0x" ||
387
- !executeDataMultisigV3.params_.metadata
449
+ executeDataMultisig.params_.metadata === "0x" ||
450
+ !executeDataMultisig.params_.metadata
388
451
  ) {
389
452
  return null;
390
453
  } else {
391
- metadata = executeDataMultisigV3.params_.metadata;
454
+ metadata = executeDataMultisig.params_.metadata;
392
455
  }
393
456
  }
394
457
 
395
458
  return metadata;
396
459
  };
397
460
 
398
-
399
461
  const typesPayload: IPayload = {
462
+ import: (data, type) => ({
463
+ type,
464
+ protocol: utils.parseBytes32String(data.protocol || ""),
465
+ valueInUsd: toBN(data.valueInUsd).toFixed(),
466
+ }),
400
467
  transfer: (data, type) => ({
401
468
  type,
402
469
  token: data.token,
@@ -432,15 +499,19 @@ const typesPayload: IPayload = {
432
499
  token: data.token,
433
500
  onBehalf: data.onBehalf,
434
501
  }),
435
- "dapp": (data, type) => ({
502
+ dapp: (data, type) => ({
436
503
  type,
437
504
  name: data.name,
438
505
  url: data.url,
439
506
  }),
440
- "deploy": (data, type) => ({
507
+ deploy: (data, type) => ({
508
+ type,
509
+ }),
510
+ "tx-builder": (data, type) => ({
441
511
  type,
512
+ actionCount: utils.parseBytes32String(data.actionCount || ""),
442
513
  }),
443
- "permit2": (data, type) => ({
514
+ permit2: (data, type) => ({
444
515
  type,
445
516
  token: data.token,
446
517
  spender: data.spender,
@@ -455,7 +526,7 @@ const typesPayload: IPayload = {
455
526
  amount: toBN(data.amount).toFixed(),
456
527
  receiver: data.receiver,
457
528
  }),
458
- "auth": (data) => ({
529
+ auth: (data) => ({
459
530
  type: data.remove ? "remove-authority" : "add-authority",
460
531
  address: data.address,
461
532
  chainId: data.chainId ? data.chainId.toString() : null,
@@ -465,7 +536,7 @@ const typesPayload: IPayload = {
465
536
  type,
466
537
  castDetails: data.castDetails,
467
538
  }),
468
- "rejection": (data, type) => ({
539
+ rejection: (data, type) => ({
469
540
  type,
470
541
  id: data.id,
471
542
  }),
@@ -481,6 +552,15 @@ const typesPayload: IPayload = {
481
552
  type,
482
553
  count: data.count,
483
554
  }),
555
+ "avocado-bridge": (data, type) => ({
556
+ type,
557
+ id: data.id,
558
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
559
+ }),
560
+ mass: (data, type) => ({
561
+ type,
562
+ data,
563
+ }),
484
564
  };
485
565
 
486
566
  const parseMetadata = (metadata: string) => {
@@ -502,25 +582,22 @@ const parseMetadata = (metadata: string) => {
502
582
  decodedMetadata.type
503
583
  ) as keyof typeof actionMetadataTypes;
504
584
 
505
- const decodedData = ethers.utils.defaultAbiCoder.decode(
585
+ const decodedData = decodedMetadata?.data === '0x' ? '' : ethers.utils.defaultAbiCoder.decode(
506
586
  actionMetadataTypes[type],
507
587
  decodedMetadata.data
508
588
  );
509
589
 
510
- const payloadFunc = typesPayload[type]
511
-
590
+ const payloadFunc = typesPayload[type];
591
+
512
592
  if (payloadFunc) {
513
- const payload = payloadFunc(decodedData, type)
593
+ const payload = payloadFunc(decodedData, type);
514
594
  metadataArr.push(payload);
515
595
  }
516
-
517
596
  }
518
597
 
519
598
  return metadataArr;
520
599
  };
521
600
 
522
-
523
-
524
601
  /**
525
602
  * Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
526
603
  * @param {string} txType - The input sentence to modify
@@ -528,6 +605,10 @@ const parseMetadata = (metadata: string) => {
528
605
  * @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
529
606
  */
530
607
  export const formatTxType = (txType: string) => {
608
+ if(txType === 'mass') {
609
+ return 'Chain Agnostic Payments'
610
+ }
611
+
531
612
  const finalSentence = txType
532
613
  .replace("-", " ")
533
614
  .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());