@instadapp/avocado-base 0.0.0-dev.d831e20 → 0.0.0-dev.dd1950d

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,30 +1,35 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.d831e20",
3
+ "version": "0.0.0-dev.dd1950d",
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
- "unplugin-vue-components": "^0.25.1"
25
+ "unplugin-vue-components": "^0.25.1",
26
+ "vue-tippy": "^6.0.0"
24
27
  },
25
28
  "dependencies": {
26
29
  "@vueuse/nuxt": "^10.2.0",
27
30
  "bignumber.js": "^9.1.1",
28
- "ethers": "^5.7.2"
31
+ "ethers": "^5.7.2",
32
+ "viem": "^2.10.5",
33
+ "xxhashjs": "^0.2.2"
29
34
  }
30
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;
@@ -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)) {
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,29 @@
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
+ 'bridge-v2': 'bridge-v2',
9
+ swap: "swap",
10
+ "gas-topup": "gas-topup",
11
+ upgrade: "upgrade",
12
+ dapp: "dapp",
13
+ deploy: "deploy",
14
+ permit2: "permit2",
15
+ "cross-transfer": "cross-transfer",
16
+ auth: "auth",
17
+ rejection: "rejection",
18
+ "instadapp-pro": "instadapp-pro",
19
+ "add-signers": "add-signers",
20
+ "remove-signers": "remove-signers",
21
+ "change-threshold": "change-threshold",
22
+ import: "import",
23
+ mass: "mass",
24
+ "tx-builder": "tx-builder",
25
+ "avocado-bridge": "avocado-bridge",
26
+ } as const;
21
27
 
22
28
  const multiMetadataTypes = ["bytes[]"];
23
29
 
@@ -41,6 +47,16 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
41
47
  "uint256 bridgeFee",
42
48
  "address nativeToken",
43
49
  ],
50
+ 'bridge-v2': [
51
+ "uint256 amount",
52
+ "address receiver",
53
+ "address fromToken",
54
+ "address toToken",
55
+ "uint256 toChainId",
56
+ "uint256 bridgeFee",
57
+ "address nativeToken",
58
+ "bytes32 provider",
59
+ ],
44
60
  swap: [
45
61
  "address sellToken",
46
62
  "address buyToken",
@@ -52,8 +68,10 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
52
68
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
53
69
  upgrade: ["bytes32 version", "address walletImpl"],
54
70
  dapp: ["string name", "string url"],
71
+ import: ["bytes32 protocol", "uint256 valueInUsd"],
55
72
  auth: ["address address", "uint256 chainId", "bool remove"],
56
73
  deploy: [],
74
+ "tx-builder": ["bytes32 actionCount"],
57
75
  permit2: [
58
76
  "address token",
59
77
  "address spender",
@@ -61,10 +79,12 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
61
79
  "uint48 expiration",
62
80
  ],
63
81
  "instadapp-pro": ["string castDetails"],
64
- 'add-signers': ['address[] signers'],
65
- 'remove-signers': ['address[] signers'],
66
- 'change-threshold': ['uint8 count'],
67
- 'rejection': ['bytes32 id'],
82
+ "add-signers": ["address[] signers"],
83
+ "remove-signers": ["address[] signers"],
84
+ "change-threshold": ["uint8 count"],
85
+ rejection: ["bytes32 id"],
86
+ "avocado-bridge": ["bytes32 id", "uint256 toChainId"],
87
+ mass: ["bool isMass"],
68
88
  };
69
89
 
70
90
  const encodeMetadata = (props: MetadataProps) => {
@@ -92,6 +112,24 @@ export const encodeDappMetadata = (
92
112
  return single ? encodeMultipleActions(data) : data;
93
113
  };
94
114
 
115
+ export const encodeAvocadoBridgeMetadata = (
116
+ id: string,
117
+ toChainId: string | number,
118
+ single = true
119
+ ) => {
120
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
121
+ actionMetadataTypes["avocado-bridge"],
122
+ [id, toChainId]
123
+ );
124
+
125
+ const data = encodeMetadata({
126
+ type: MetadataEnums["avocado-bridge"],
127
+ encodedData,
128
+ });
129
+
130
+ return single ? encodeMultipleActions(data) : data;
131
+ };
132
+
95
133
  export const encodeTransferMetadata = (
96
134
  params: SendMetadataProps,
97
135
  single = true
@@ -172,6 +210,23 @@ export const encodeDeployMetadata = (single = true) => {
172
210
  return single ? encodeMultipleActions(data) : data;
173
211
  };
174
212
 
213
+ export const encodeTransactionBuilderMetadata = (
214
+ actionCount: string,
215
+ single = true
216
+ ) => {
217
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
218
+ actionMetadataTypes["tx-builder"],
219
+ [actionCount]
220
+ );
221
+
222
+ const data = encodeMetadata({
223
+ type: MetadataEnums["tx-builder"],
224
+ encodedData,
225
+ });
226
+
227
+ return single ? encodeMultipleActions(data) : data;
228
+ };
229
+
175
230
  export const encodeWCSignMetadata = (
176
231
  params: SignMetadataProps,
177
232
  single = true
@@ -251,7 +306,21 @@ export const encodeBridgeMetadata = (
251
306
  params: BridgeMetadataProps,
252
307
  single = true
253
308
  ) => {
254
- const encodedData = ethers.utils.defaultAbiCoder.encode(
309
+ const type = params.version === '2' ? MetadataEnums.bridge : MetadataEnums["bridge-v2"]
310
+
311
+ const encodedData = params.version === '2' ? ethers.utils.defaultAbiCoder.encode(
312
+ actionMetadataTypes["bridge-v2"],
313
+ [
314
+ params.amount,
315
+ params.receiver,
316
+ params.fromToken,
317
+ params.toToken,
318
+ params.toChainId,
319
+ params.bridgeFee,
320
+ params.nativeToken,
321
+ params.provider
322
+ ]
323
+ ): ethers.utils.defaultAbiCoder.encode(
255
324
  actionMetadataTypes.bridge,
256
325
  [
257
326
  params.amount,
@@ -265,7 +334,7 @@ export const encodeBridgeMetadata = (
265
334
  );
266
335
 
267
336
  const data = encodeMetadata({
268
- type: MetadataEnums.bridge,
337
+ type,
269
338
  encodedData,
270
339
  });
271
340
 
@@ -306,6 +375,33 @@ export const encodeRemoveSignersMetadata = (
306
375
  return single ? encodeMultipleActions(data) : data;
307
376
  };
308
377
 
378
+ export const encodeImportMetadata = (
379
+ protocol: string,
380
+ valueInUsd: string,
381
+ single = true
382
+ ) => {
383
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
384
+ actionMetadataTypes["import"],
385
+ [protocol, valueInUsd]
386
+ );
387
+
388
+ const data = encodeMetadata({
389
+ type: MetadataEnums["import"],
390
+ encodedData,
391
+ });
392
+
393
+ return single ? encodeMultipleActions(data) : data;
394
+ };
395
+
396
+ export const encodeMassMetadata = (single = true) => {
397
+ const data = encodeMetadata({
398
+ type: MetadataEnums.mass,
399
+ encodedData: '0x',
400
+ });
401
+
402
+ return single ? encodeMultipleActions(data) : data;
403
+ }
404
+
309
405
  export const encodeAddSignersMetadata = (
310
406
  addresses: string[],
311
407
  single = true
@@ -346,8 +442,10 @@ export const decodeMetadata = (metadata: string) => {
346
442
  }
347
443
  };
348
444
 
445
+ const iface = Forwarder__factory.createInterface();
446
+ const ifaceMultisig = MultisigForwarder__factory.createInterface();
447
+
349
448
  const getMetadataFromData = (data: string) => {
350
- const iface = Forwarder__factory.createInterface();
351
449
  let metadata = "0x";
352
450
 
353
451
  if (data.startsWith("0x18e7f485")) {
@@ -367,36 +465,30 @@ const getMetadataFromData = (data: string) => {
367
465
  } else {
368
466
  metadata = executeDataV2.params_.metadata;
369
467
  }
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
468
  } else {
381
- const executeDataMultisigV3 = iface.decodeFunctionData(
382
- "executeMultisigV3",
469
+ const executeDataMultisig = ifaceMultisig.decodeFunctionData(
470
+ "executeV1",
383
471
  data
384
472
  );
385
473
  if (
386
- executeDataMultisigV3.params_.metadata === "0x" ||
387
- !executeDataMultisigV3.params_.metadata
474
+ executeDataMultisig.params_.metadata === "0x" ||
475
+ !executeDataMultisig.params_.metadata
388
476
  ) {
389
477
  return null;
390
478
  } else {
391
- metadata = executeDataMultisigV3.params_.metadata;
479
+ metadata = executeDataMultisig.params_.metadata;
392
480
  }
393
481
  }
394
482
 
395
483
  return metadata;
396
484
  };
397
485
 
398
-
399
486
  const typesPayload: IPayload = {
487
+ import: (data, type) => ({
488
+ type,
489
+ protocol: utils.parseBytes32String(data.protocol || ""),
490
+ valueInUsd: toBN(data.valueInUsd).toFixed(),
491
+ }),
400
492
  transfer: (data, type) => ({
401
493
  type,
402
494
  token: data.token,
@@ -412,6 +504,16 @@ const typesPayload: IPayload = {
412
504
  toChainId: data.toChainId ? data.toChainId.toString() : null,
413
505
  bridgeFee: toBN(data.bridgeFee).toFixed(),
414
506
  }),
507
+ 'bridge-v2': (data, type) => ({
508
+ type,
509
+ amount: toBN(data.amount).toFixed(),
510
+ receiver: data.receiver,
511
+ toToken: data.toToken,
512
+ fromToken: data.fromToken,
513
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
514
+ bridgeFee: toBN(data.bridgeFee).toFixed(),
515
+ provider: data.provider,
516
+ }),
415
517
  swap: (data, type) => ({
416
518
  type,
417
519
  buyAmount: toBN(data.buyAmount).toFixed(),
@@ -432,15 +534,19 @@ const typesPayload: IPayload = {
432
534
  token: data.token,
433
535
  onBehalf: data.onBehalf,
434
536
  }),
435
- "dapp": (data, type) => ({
537
+ dapp: (data, type) => ({
436
538
  type,
437
539
  name: data.name,
438
540
  url: data.url,
439
541
  }),
440
- "deploy": (data, type) => ({
542
+ deploy: (data, type) => ({
441
543
  type,
442
544
  }),
443
- "permit2": (data, type) => ({
545
+ "tx-builder": (data, type) => ({
546
+ type,
547
+ actionCount: utils.parseBytes32String(data.actionCount || ""),
548
+ }),
549
+ permit2: (data, type) => ({
444
550
  type,
445
551
  token: data.token,
446
552
  spender: data.spender,
@@ -455,7 +561,7 @@ const typesPayload: IPayload = {
455
561
  amount: toBN(data.amount).toFixed(),
456
562
  receiver: data.receiver,
457
563
  }),
458
- "auth": (data) => ({
564
+ auth: (data) => ({
459
565
  type: data.remove ? "remove-authority" : "add-authority",
460
566
  address: data.address,
461
567
  chainId: data.chainId ? data.chainId.toString() : null,
@@ -465,7 +571,7 @@ const typesPayload: IPayload = {
465
571
  type,
466
572
  castDetails: data.castDetails,
467
573
  }),
468
- "rejection": (data, type) => ({
574
+ rejection: (data, type) => ({
469
575
  type,
470
576
  id: data.id,
471
577
  }),
@@ -481,6 +587,15 @@ const typesPayload: IPayload = {
481
587
  type,
482
588
  count: data.count,
483
589
  }),
590
+ "avocado-bridge": (data, type) => ({
591
+ type,
592
+ id: data.id,
593
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
594
+ }),
595
+ mass: (data, type) => ({
596
+ type,
597
+ data,
598
+ }),
484
599
  };
485
600
 
486
601
  const parseMetadata = (metadata: string) => {
@@ -502,25 +617,22 @@ const parseMetadata = (metadata: string) => {
502
617
  decodedMetadata.type
503
618
  ) as keyof typeof actionMetadataTypes;
504
619
 
505
- const decodedData = ethers.utils.defaultAbiCoder.decode(
620
+ const decodedData = decodedMetadata?.data === '0x' ? '' : ethers.utils.defaultAbiCoder.decode(
506
621
  actionMetadataTypes[type],
507
622
  decodedMetadata.data
508
623
  );
509
624
 
510
- const payloadFunc = typesPayload[type]
511
-
625
+ const payloadFunc = typesPayload[type];
626
+
512
627
  if (payloadFunc) {
513
- const payload = payloadFunc(decodedData, type)
628
+ const payload = payloadFunc(decodedData, type);
514
629
  metadataArr.push(payload);
515
630
  }
516
-
517
631
  }
518
632
 
519
633
  return metadataArr;
520
634
  };
521
635
 
522
-
523
-
524
636
  /**
525
637
  * Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
526
638
  * @param {string} txType - The input sentence to modify
@@ -528,6 +640,10 @@ const parseMetadata = (metadata: string) => {
528
640
  * @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
529
641
  */
530
642
  export const formatTxType = (txType: string) => {
643
+ if(txType === 'mass') {
644
+ return 'Chain Agnostic Payments'
645
+ }
646
+
531
647
  const finalSentence = txType
532
648
  .replace("-", " ")
533
649
  .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());