@instadapp/avocado-base 0.0.0-dev.8d2b9ac → 0.0.0-dev.8ed8fca

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,13 @@ 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 { MultisigAgnosticForwarder } from "./MultisigAgnosticForwarder";
10
+ export type { MultisigForwarder } from "./MultisigForwarder";
9
11
  export * as factories from "./factories";
10
12
  export { AvoFactoryProxy__factory } from "./factories/AvoFactoryProxy__factory";
11
13
  export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
12
14
  export { Erc20__factory } from "./factories/Erc20__factory";
13
15
  export { Forwarder__factory } from "./factories/Forwarder__factory";
14
16
  export { GaslessWallet__factory } from "./factories/GaslessWallet__factory";
17
+ export { MultisigAgnosticForwarder__factory } from "./factories/MultisigAgnosticForwarder__factory";
18
+ export { MultisigForwarder__factory } from "./factories/MultisigForwarder__factory";
@@ -0,0 +1,19 @@
1
+ // @ts-check
2
+ import antfu from '@antfu/eslint-config'
3
+ import withNuxt from './.nuxt/eslint.config.mjs'
4
+
5
+ export default withNuxt(
6
+ antfu({
7
+ yaml: false,
8
+ rules: {
9
+ 'style/max-statements-per-line': 'off',
10
+ 'max-statements-per-line': 'off',
11
+ '@stylistic/max-statements-per-line': 'off',
12
+ 'vue/return-in-computed-property': 'off',
13
+ 'no-console': 'off',
14
+ 'ts/ban-ts-comment': 'off',
15
+ 'vue/prop-name-casing': 'off',
16
+ 'node/prefer-global/process': 'off',
17
+ },
18
+ }),
19
+ )
package/nuxt.config.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import ViteComponents from "unplugin-vue-components/vite";
3
3
 
4
4
  export default defineNuxtConfig({
5
- modules: ["@nuxtjs/tailwindcss", "nuxt-svgo", "@vueuse/nuxt"],
5
+ modules: ["@nuxtjs/tailwindcss", "nuxt-svgo", "@vueuse/nuxt", "@nuxt/eslint"],
6
6
  svgo: {
7
7
  defaultImport: "component",
8
8
  autoImportPath: "./assets/images/icons",
@@ -17,4 +17,9 @@ export default defineNuxtConfig({
17
17
  }),
18
18
  ],
19
19
  },
20
- });
20
+ eslint: {
21
+ config: {
22
+ standalone: false,
23
+ },
24
+ },
25
+ });
package/package.json CHANGED
@@ -1,32 +1,37 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.8d2b9ac",
4
3
  "type": "module",
4
+ "version": "0.0.0-dev.8ed8fca",
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"
17
+ },
18
+ "dependencies": {
19
+ "@antfu/eslint-config": "^2.21.1",
20
+ "@vueuse/nuxt": "^10.2.0",
21
+ "bignumber.js": "^9.1.1",
22
+ "ethers": "^5.7.2",
23
+ "viem": "^2.10.5",
24
+ "xxhashjs": "^0.2.2"
13
25
  },
14
26
  "devDependencies": {
15
- "@instadapp/avocado": "^0.1.10",
16
- "@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
17
- "@nuxtjs/tailwindcss": "^6.6.5",
27
+ "@nuxt/eslint": "^0.3.13",
28
+ "@nuxtjs/tailwindcss": "^6.11.3",
18
29
  "@typechain/ethers-v5": "^10.2.0",
19
- "nuxt": "^3.6.1",
20
- "nuxt-svgo": "^3.1.0",
30
+ "nuxt": "3.10.1",
31
+ "nuxt-svgo": "^4.0.0",
21
32
  "rimraf": "^3.0.2",
22
33
  "typechain": "^8.1.1",
23
34
  "unplugin-vue-components": "^0.25.1",
24
35
  "vue-tippy": "^6.0.0"
25
- },
26
- "dependencies": {
27
- "@vueuse/nuxt": "^10.2.0",
28
- "bignumber.js": "^9.1.1",
29
- "ethers": "^5.7.2",
30
- "xxhashjs": "^0.2.2"
31
36
  }
32
37
  }
@@ -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/helper.ts CHANGED
@@ -1,5 +1,3 @@
1
- import * as XXH from 'xxhashjs';
2
-
3
1
  export const indexSorter = (aIndex: number, bIndex: number) => {
4
2
  if (aIndex === -1 && bIndex === -1) {
5
3
  return 0; // fallback to other sorting criteria
@@ -62,12 +60,3 @@ export function formatMultipleAddresses(addresses: string[], shorten = true) {
62
60
  return formattedString
63
61
  }
64
62
 
65
- export function generateColor(address: string): string {
66
- const hash = XXH.h32(address, 0xABCD).toNumber()
67
-
68
- const hue = hash % 360
69
- const saturation = 80 + (hash % 30)
70
- const lightness = 70 + (hash % 20)
71
-
72
- return `hsl(${hue}, ${saturation}%, ${lightness}%)`
73
- }
package/utils/metadata.ts CHANGED
@@ -1,23 +1,30 @@
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, MultisigAgnosticForwarder__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
+ 'cross-transfer-v2': 'cross-transfer-v2',
17
+ auth: "auth",
18
+ rejection: "rejection",
19
+ "instadapp-pro": "instadapp-pro",
20
+ "add-signers": "add-signers",
21
+ "remove-signers": "remove-signers",
22
+ "change-threshold": "change-threshold",
23
+ import: "import",
24
+ mass: "mass",
25
+ "tx-builder": "tx-builder",
26
+ "avocado-bridge": "avocado-bridge",
27
+ } as const;
21
28
 
22
29
  const multiMetadataTypes = ["bytes[]"];
23
30
 
@@ -32,6 +39,14 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
32
39
  "uint256 amount",
33
40
  "address receiver",
34
41
  ],
42
+ "cross-transfer-v2": [
43
+ "address fromToken",
44
+ "address toToken",
45
+ "uint256 toChainId",
46
+ "uint256 amount",
47
+ "address receiver",
48
+ "bytes32 provider",
49
+ ],
35
50
  bridge: [
36
51
  "uint256 amount",
37
52
  "address receiver",
@@ -41,6 +56,16 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
41
56
  "uint256 bridgeFee",
42
57
  "address nativeToken",
43
58
  ],
59
+ 'bridge-v2': [
60
+ "uint256 amount",
61
+ "address receiver",
62
+ "address fromToken",
63
+ "address toToken",
64
+ "uint256 toChainId",
65
+ "uint256 bridgeFee",
66
+ "address nativeToken",
67
+ "bytes32 provider",
68
+ ],
44
69
  swap: [
45
70
  "address sellToken",
46
71
  "address buyToken",
@@ -52,8 +77,10 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
52
77
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
53
78
  upgrade: ["bytes32 version", "address walletImpl"],
54
79
  dapp: ["string name", "string url"],
80
+ import: ["bytes32 protocol", "uint256 valueInUsd"],
55
81
  auth: ["address address", "uint256 chainId", "bool remove"],
56
82
  deploy: [],
83
+ "tx-builder": ["bytes32 actionCount"],
57
84
  permit2: [
58
85
  "address token",
59
86
  "address spender",
@@ -61,10 +88,12 @@ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
61
88
  "uint48 expiration",
62
89
  ],
63
90
  "instadapp-pro": ["string castDetails"],
64
- 'add-signers': ['address[] signers'],
65
- 'remove-signers': ['address[] signers'],
66
- 'change-threshold': ['uint8 count'],
67
- 'rejection': ['bytes32 id'],
91
+ "add-signers": ["address[] signers"],
92
+ "remove-signers": ["address[] signers"],
93
+ "change-threshold": ["uint8 count"],
94
+ rejection: ["bytes32 id"],
95
+ "avocado-bridge": ["bytes32 id", "uint256 toChainId"],
96
+ mass: ["bool isMass"],
68
97
  };
69
98
 
70
99
  const encodeMetadata = (props: MetadataProps) => {
@@ -92,6 +121,24 @@ export const encodeDappMetadata = (
92
121
  return single ? encodeMultipleActions(data) : data;
93
122
  };
94
123
 
124
+ export const encodeAvocadoBridgeMetadata = (
125
+ id: string,
126
+ toChainId: string | number,
127
+ single = true
128
+ ) => {
129
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
130
+ actionMetadataTypes["avocado-bridge"],
131
+ [id, toChainId]
132
+ );
133
+
134
+ const data = encodeMetadata({
135
+ type: MetadataEnums["avocado-bridge"],
136
+ encodedData,
137
+ });
138
+
139
+ return single ? encodeMultipleActions(data) : data;
140
+ };
141
+
95
142
  export const encodeTransferMetadata = (
96
143
  params: SendMetadataProps,
97
144
  single = true
@@ -127,8 +174,21 @@ export const encodeCrossTransferMetadata = (
127
174
  params: CrossSendMetadataProps,
128
175
  single = true
129
176
  ) => {
130
- const encodedData = ethers.utils.defaultAbiCoder.encode(
131
- actionMetadataTypes["cross-transfer"],
177
+
178
+ const type = params.provider ? MetadataEnums["cross-transfer-v2"] : MetadataEnums["cross-transfer"]
179
+
180
+ const encodedData = params.provider ? ethers.utils.defaultAbiCoder.encode(
181
+ actionMetadataTypes[type],
182
+ [
183
+ params.fromToken,
184
+ params.toToken,
185
+ params.toChainId,
186
+ params.amount,
187
+ params.receiver,
188
+ params.provider
189
+ ]
190
+ ) : ethers.utils.defaultAbiCoder.encode(
191
+ actionMetadataTypes[type],
132
192
  [
133
193
  params.fromToken,
134
194
  params.toToken,
@@ -139,7 +199,7 @@ export const encodeCrossTransferMetadata = (
139
199
  );
140
200
 
141
201
  const data = encodeMetadata({
142
- type: MetadataEnums["cross-transfer"],
202
+ type: MetadataEnums[type],
143
203
  encodedData,
144
204
  });
145
205
 
@@ -172,6 +232,23 @@ export const encodeDeployMetadata = (single = true) => {
172
232
  return single ? encodeMultipleActions(data) : data;
173
233
  };
174
234
 
235
+ export const encodeTransactionBuilderMetadata = (
236
+ actionCount: string,
237
+ single = true
238
+ ) => {
239
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
240
+ actionMetadataTypes["tx-builder"],
241
+ [actionCount]
242
+ );
243
+
244
+ const data = encodeMetadata({
245
+ type: MetadataEnums["tx-builder"],
246
+ encodedData,
247
+ });
248
+
249
+ return single ? encodeMultipleActions(data) : data;
250
+ };
251
+
175
252
  export const encodeWCSignMetadata = (
176
253
  params: SignMetadataProps,
177
254
  single = true
@@ -251,7 +328,21 @@ export const encodeBridgeMetadata = (
251
328
  params: BridgeMetadataProps,
252
329
  single = true
253
330
  ) => {
254
- const encodedData = ethers.utils.defaultAbiCoder.encode(
331
+ const type = params.version === '2' ? MetadataEnums["bridge-v2"] : MetadataEnums.bridge
332
+
333
+ const encodedData = params.version === '2' ? ethers.utils.defaultAbiCoder.encode(
334
+ actionMetadataTypes["bridge-v2"],
335
+ [
336
+ params.amount,
337
+ params.receiver,
338
+ params.fromToken,
339
+ params.toToken,
340
+ params.toChainId,
341
+ params.bridgeFee,
342
+ params.nativeToken,
343
+ params.provider
344
+ ]
345
+ ): ethers.utils.defaultAbiCoder.encode(
255
346
  actionMetadataTypes.bridge,
256
347
  [
257
348
  params.amount,
@@ -265,7 +356,7 @@ export const encodeBridgeMetadata = (
265
356
  );
266
357
 
267
358
  const data = encodeMetadata({
268
- type: MetadataEnums.bridge,
359
+ type,
269
360
  encodedData,
270
361
  });
271
362
 
@@ -306,6 +397,33 @@ export const encodeRemoveSignersMetadata = (
306
397
  return single ? encodeMultipleActions(data) : data;
307
398
  };
308
399
 
400
+ export const encodeImportMetadata = (
401
+ protocol: string,
402
+ valueInUsd: string,
403
+ single = true
404
+ ) => {
405
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
406
+ actionMetadataTypes["import"],
407
+ [protocol, valueInUsd]
408
+ );
409
+
410
+ const data = encodeMetadata({
411
+ type: MetadataEnums["import"],
412
+ encodedData,
413
+ });
414
+
415
+ return single ? encodeMultipleActions(data) : data;
416
+ };
417
+
418
+ export const encodeMassMetadata = (single = true) => {
419
+ const data = encodeMetadata({
420
+ type: MetadataEnums.mass,
421
+ encodedData: '0x',
422
+ });
423
+
424
+ return single ? encodeMultipleActions(data) : data;
425
+ }
426
+
309
427
  export const encodeAddSignersMetadata = (
310
428
  addresses: string[],
311
429
  single = true
@@ -346,11 +464,24 @@ export const decodeMetadata = (metadata: string) => {
346
464
  }
347
465
  };
348
466
 
467
+ const iface = Forwarder__factory.createInterface();
468
+ const ifaceMultisig = MultisigForwarder__factory.createInterface();
469
+ const ifaceAgnostic = MultisigAgnosticForwarder__factory.createInterface();
470
+
349
471
  const getMetadataFromData = (data: string) => {
350
- const iface = Forwarder__factory.createInterface();
351
472
  let metadata = "0x";
352
473
 
353
- if (data.startsWith("0x18e7f485")) {
474
+ if(data.startsWith('0xc5e15557')) {
475
+
476
+ const executeData = ifaceAgnostic.decodeFunctionData("executeChainAgnosticV1", data);
477
+
478
+
479
+ const metadata = executeData?.params_?.params?.metadata
480
+
481
+ return metadata === '0x' || !metadata ? null : metadata
482
+ }
483
+
484
+ else if (data.startsWith("0x18e7f485")) {
354
485
  const executeData = iface.decodeFunctionData("execute", data);
355
486
  if (executeData.metadata_ === "0x" || !executeData.metadata_) {
356
487
  return null;
@@ -367,36 +498,30 @@ const getMetadataFromData = (data: string) => {
367
498
  } else {
368
499
  metadata = executeDataV2.params_.metadata;
369
500
  }
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
501
  } else {
381
- const executeDataMultisigV3 = iface.decodeFunctionData(
382
- "executeMultisigV3",
502
+ const executeDataMultisig = ifaceMultisig.decodeFunctionData(
503
+ "executeV1",
383
504
  data
384
505
  );
385
506
  if (
386
- executeDataMultisigV3.params_.metadata === "0x" ||
387
- !executeDataMultisigV3.params_.metadata
507
+ executeDataMultisig.params_.metadata === "0x" ||
508
+ !executeDataMultisig.params_.metadata
388
509
  ) {
389
510
  return null;
390
511
  } else {
391
- metadata = executeDataMultisigV3.params_.metadata;
512
+ metadata = executeDataMultisig.params_.metadata;
392
513
  }
393
514
  }
394
515
 
395
516
  return metadata;
396
517
  };
397
518
 
398
-
399
519
  const typesPayload: IPayload = {
520
+ import: (data, type) => ({
521
+ type,
522
+ protocol: utils.parseBytes32String(data.protocol || ""),
523
+ valueInUsd: toBN(data.valueInUsd).toFixed(),
524
+ }),
400
525
  transfer: (data, type) => ({
401
526
  type,
402
527
  token: data.token,
@@ -412,6 +537,16 @@ const typesPayload: IPayload = {
412
537
  toChainId: data.toChainId ? data.toChainId.toString() : null,
413
538
  bridgeFee: toBN(data.bridgeFee).toFixed(),
414
539
  }),
540
+ 'bridge-v2': (data, type) => ({
541
+ type: 'bridge',
542
+ amount: toBN(data.amount).toFixed(),
543
+ receiver: data.receiver,
544
+ toToken: data.toToken,
545
+ fromToken: data.fromToken,
546
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
547
+ bridgeFee: toBN(data.bridgeFee).toFixed(),
548
+ provider: utils.parseBytes32String(data.provider || ""),
549
+ }),
415
550
  swap: (data, type) => ({
416
551
  type,
417
552
  buyAmount: toBN(data.buyAmount).toFixed(),
@@ -432,15 +567,19 @@ const typesPayload: IPayload = {
432
567
  token: data.token,
433
568
  onBehalf: data.onBehalf,
434
569
  }),
435
- "dapp": (data, type) => ({
570
+ dapp: (data, type) => ({
436
571
  type,
437
572
  name: data.name,
438
573
  url: data.url,
439
574
  }),
440
- "deploy": (data, type) => ({
575
+ deploy: (data, type) => ({
576
+ type,
577
+ }),
578
+ "tx-builder": (data, type) => ({
441
579
  type,
580
+ actionCount: utils.parseBytes32String(data.actionCount || ""),
442
581
  }),
443
- "permit2": (data, type) => ({
582
+ permit2: (data, type) => ({
444
583
  type,
445
584
  token: data.token,
446
585
  spender: data.spender,
@@ -455,7 +594,16 @@ const typesPayload: IPayload = {
455
594
  amount: toBN(data.amount).toFixed(),
456
595
  receiver: data.receiver,
457
596
  }),
458
- "auth": (data) => ({
597
+ "cross-transfer-v2": (data, type) => ({
598
+ type: 'cross-transfer',
599
+ fromToken: data.fromToken,
600
+ toToken: data.toToken,
601
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
602
+ amount: toBN(data.amount).toFixed(),
603
+ receiver: data.receiver,
604
+ provider: utils.parseBytes32String(data.provider || ""),
605
+ }),
606
+ auth: (data) => ({
459
607
  type: data.remove ? "remove-authority" : "add-authority",
460
608
  address: data.address,
461
609
  chainId: data.chainId ? data.chainId.toString() : null,
@@ -465,7 +613,7 @@ const typesPayload: IPayload = {
465
613
  type,
466
614
  castDetails: data.castDetails,
467
615
  }),
468
- "rejection": (data, type) => ({
616
+ rejection: (data, type) => ({
469
617
  type,
470
618
  id: data.id,
471
619
  }),
@@ -481,6 +629,15 @@ const typesPayload: IPayload = {
481
629
  type,
482
630
  count: data.count,
483
631
  }),
632
+ "avocado-bridge": (data, type) => ({
633
+ type,
634
+ id: data.id,
635
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
636
+ }),
637
+ mass: (data, type) => ({
638
+ type,
639
+ data,
640
+ }),
484
641
  };
485
642
 
486
643
  const parseMetadata = (metadata: string) => {
@@ -502,25 +659,22 @@ const parseMetadata = (metadata: string) => {
502
659
  decodedMetadata.type
503
660
  ) as keyof typeof actionMetadataTypes;
504
661
 
505
- const decodedData = ethers.utils.defaultAbiCoder.decode(
662
+ const decodedData = decodedMetadata?.data === '0x' ? '' : ethers.utils.defaultAbiCoder.decode(
506
663
  actionMetadataTypes[type],
507
664
  decodedMetadata.data
508
665
  );
509
666
 
510
- const payloadFunc = typesPayload[type]
511
-
667
+ const payloadFunc = typesPayload[type];
668
+
512
669
  if (payloadFunc) {
513
- const payload = payloadFunc(decodedData, type)
670
+ const payload = payloadFunc(decodedData, type);
514
671
  metadataArr.push(payload);
515
672
  }
516
-
517
673
  }
518
674
 
519
675
  return metadataArr;
520
676
  };
521
677
 
522
-
523
-
524
678
  /**
525
679
  * Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
526
680
  * @param {string} txType - The input sentence to modify
@@ -528,6 +682,10 @@ const parseMetadata = (metadata: string) => {
528
682
  * @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
529
683
  */
530
684
  export const formatTxType = (txType: string) => {
685
+ if(txType === 'mass') {
686
+ return 'Chain Agnostic Payments'
687
+ }
688
+
531
689
  const finalSentence = txType
532
690
  .replace("-", " ")
533
691
  .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());