@instadapp/avocado-base 0.0.0-dev.822475d → 0.0.0-dev.8596b31

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.
Files changed (41) hide show
  1. package/abi/multisigForwarder.json +697 -0
  2. package/app.vue +7 -0
  3. package/assets/images/icons/change-threshold.svg +4 -0
  4. package/assets/images/icons/cross-transfer.svg +7 -0
  5. package/assets/images/icons/dapp.svg +4 -0
  6. package/assets/images/icons/deploy.svg +12 -0
  7. package/assets/images/icons/gas.svg +12 -5
  8. package/assets/images/icons/hammer.svg +5 -0
  9. package/assets/images/icons/info-2.svg +12 -0
  10. package/assets/images/icons/instadapp-pro.svg +4 -0
  11. package/assets/images/icons/multi-send.svg +7 -0
  12. package/assets/images/icons/permit-sign.svg +11 -0
  13. package/assets/images/icons/plus-circle.svg +6 -0
  14. package/assets/images/icons/refresh.svg +4 -4
  15. package/assets/images/icons/reject-proposal.svg +6 -0
  16. package/assets/images/icons/transfer.svg +5 -0
  17. package/assets/images/icons/trash-2.svg +8 -0
  18. package/assets/images/icons/upgrade.svg +4 -0
  19. package/components/ActionLogo.vue +40 -0
  20. package/components/ActionMetadata.vue +45 -17
  21. package/components/AuthorityAvatar.vue +38 -0
  22. package/components/ChainLogo.vue +14 -556
  23. package/components/CopyClipboard.vue +64 -0
  24. package/components/metadata/Bridge.vue +30 -8
  25. package/components/metadata/CrossTransfer.vue +19 -5
  26. package/components/metadata/GasTopup.vue +10 -2
  27. package/components/metadata/Permit2.vue +6 -1
  28. package/components/metadata/Signers.vue +63 -0
  29. package/components/metadata/Swap.vue +12 -4
  30. package/components/metadata/Transfer.vue +14 -7
  31. package/contracts/MultisigForwarder.ts +859 -0
  32. package/contracts/factories/MultisigForwarder__factory.ts +721 -0
  33. package/contracts/factories/index.ts +1 -0
  34. package/contracts/index.ts +2 -0
  35. package/package.json +5 -3
  36. package/utils/formatter.ts +1 -1
  37. package/utils/helper.ts +8 -0
  38. package/utils/metadata.ts +248 -133
  39. package/utils/network.ts +197 -74
  40. package/utils/services.ts +8 -1
  41. package/utils/utils.d.ts +130 -126
@@ -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.822475d",
3
+ "version": "0.0.0-dev.8596b31",
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)) {
package/utils/helper.ts CHANGED
@@ -52,3 +52,11 @@ 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
+ }
62
+
package/utils/metadata.ts CHANGED
@@ -1,11 +1,32 @@
1
1
  import { ethers, utils } from "ethers";
2
- import { Forwarder__factory } from "../contracts";
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
+ } as const;
3
24
 
4
25
  const multiMetadataTypes = ["bytes[]"];
5
26
 
6
27
  const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
7
28
 
8
- const actionMetadataTypes = {
29
+ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
9
30
  transfer: ["address token", "uint256 amount", "address receiver"],
10
31
  "cross-transfer": [
11
32
  "address fromToken",
@@ -34,8 +55,10 @@ const actionMetadataTypes = {
34
55
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
35
56
  upgrade: ["bytes32 version", "address walletImpl"],
36
57
  dapp: ["string name", "string url"],
58
+ import: ["bytes32 protocol", "uint256 valueInUsd"],
37
59
  auth: ["address address", "uint256 chainId", "bool remove"],
38
60
  deploy: [],
61
+ "tx-builder": ["bytes32 actionCount"],
39
62
  permit2: [
40
63
  "address token",
41
64
  "address spender",
@@ -43,6 +66,10 @@ const actionMetadataTypes = {
43
66
  "uint48 expiration",
44
67
  ],
45
68
  "instadapp-pro": ["string castDetails"],
69
+ "add-signers": ["address[] signers"],
70
+ "remove-signers": ["address[] signers"],
71
+ "change-threshold": ["uint8 count"],
72
+ rejection: ["bytes32 id"],
46
73
  };
47
74
 
48
75
  const encodeMetadata = (props: MetadataProps) => {
@@ -63,7 +90,7 @@ export const encodeDappMetadata = (
63
90
  );
64
91
 
65
92
  const data = encodeMetadata({
66
- type: "dapp",
93
+ type: MetadataEnums.dapp,
67
94
  encodedData,
68
95
  });
69
96
 
@@ -80,7 +107,21 @@ export const encodeTransferMetadata = (
80
107
  );
81
108
 
82
109
  const data = encodeMetadata({
83
- type: "transfer",
110
+ type: MetadataEnums.transfer,
111
+ encodedData,
112
+ });
113
+
114
+ return single ? encodeMultipleActions(data) : data;
115
+ };
116
+
117
+ export const encodeRejectionMetadata = (id: string, single = true) => {
118
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
119
+ actionMetadataTypes.rejection,
120
+ [id]
121
+ );
122
+
123
+ const data = encodeMetadata({
124
+ type: MetadataEnums.rejection,
84
125
  encodedData,
85
126
  });
86
127
 
@@ -103,7 +144,7 @@ export const encodeCrossTransferMetadata = (
103
144
  );
104
145
 
105
146
  const data = encodeMetadata({
106
- type: "cross-transfer",
147
+ type: MetadataEnums["cross-transfer"],
107
148
  encodedData,
108
149
  });
109
150
 
@@ -120,7 +161,7 @@ export const encodeAuthMetadata = (
120
161
  );
121
162
 
122
163
  const data = encodeMetadata({
123
- type: "auth",
164
+ type: MetadataEnums.auth,
124
165
  encodedData,
125
166
  });
126
167
 
@@ -129,13 +170,30 @@ export const encodeAuthMetadata = (
129
170
 
130
171
  export const encodeDeployMetadata = (single = true) => {
131
172
  const data = encodeMetadata({
132
- type: "deploy",
173
+ type: MetadataEnums.deploy,
133
174
  encodedData: "0x",
134
175
  });
135
176
 
136
177
  return single ? encodeMultipleActions(data) : data;
137
178
  };
138
179
 
180
+ export const encodeTransactionBuilderMetadata = (
181
+ actionCount: string,
182
+ single = true
183
+ ) => {
184
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
185
+ actionMetadataTypes["tx-builder"],
186
+ [actionCount]
187
+ );
188
+
189
+ const data = encodeMetadata({
190
+ type: MetadataEnums["tx-builder"],
191
+ encodedData,
192
+ });
193
+
194
+ return single ? encodeMultipleActions(data) : data;
195
+ };
196
+
139
197
  export const encodeWCSignMetadata = (
140
198
  params: SignMetadataProps,
141
199
  single = true
@@ -146,7 +204,7 @@ export const encodeWCSignMetadata = (
146
204
  );
147
205
 
148
206
  const data = encodeMetadata({
149
- type: "permit2",
207
+ type: MetadataEnums.permit2,
150
208
  encodedData,
151
209
  });
152
210
 
@@ -163,7 +221,7 @@ export const encodeUpgradeMetadata = (
163
221
  );
164
222
 
165
223
  const data = encodeMetadata({
166
- type: "upgrade",
224
+ type: MetadataEnums.upgrade,
167
225
  encodedData,
168
226
  });
169
227
 
@@ -187,7 +245,7 @@ export const encodeSwapMetadata = (
187
245
  );
188
246
 
189
247
  const data = encodeMetadata({
190
- type: "swap",
248
+ type: MetadataEnums.swap,
191
249
  encodedData,
192
250
  });
193
251
 
@@ -203,10 +261,8 @@ export const encodeTopupMetadata = (
203
261
  [params.amount, params.token, params.onBehalf]
204
262
  );
205
263
 
206
- console.log(params);
207
-
208
264
  const data = encodeMetadata({
209
- type: "gas-topup",
265
+ type: MetadataEnums["gas-topup"],
210
266
  encodedData,
211
267
  });
212
268
 
@@ -231,7 +287,76 @@ export const encodeBridgeMetadata = (
231
287
  );
232
288
 
233
289
  const data = encodeMetadata({
234
- type: "bridge",
290
+ type: MetadataEnums.bridge,
291
+ encodedData,
292
+ });
293
+
294
+ return single ? encodeMultipleActions(data) : data;
295
+ };
296
+
297
+ export const encodeChangeThresholdMetadata = (
298
+ threshold: string | number,
299
+ single = true
300
+ ) => {
301
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
302
+ actionMetadataTypes["change-threshold"],
303
+ [toBN(threshold).toNumber()]
304
+ );
305
+
306
+ const data = encodeMetadata({
307
+ type: MetadataEnums["change-threshold"],
308
+ encodedData,
309
+ });
310
+
311
+ return single ? encodeMultipleActions(data) : data;
312
+ };
313
+
314
+ export const encodeRemoveSignersMetadata = (
315
+ addresses: string[],
316
+ single = true
317
+ ) => {
318
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
319
+ actionMetadataTypes["remove-signers"],
320
+ [addresses]
321
+ );
322
+
323
+ const data = encodeMetadata({
324
+ type: MetadataEnums["remove-signers"],
325
+ encodedData,
326
+ });
327
+
328
+ return single ? encodeMultipleActions(data) : data;
329
+ };
330
+
331
+ export const encodeImportMetadata = (
332
+ protocol: string,
333
+ valueInUsd: string,
334
+ single = true
335
+ ) => {
336
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
337
+ actionMetadataTypes["import"],
338
+ [protocol, valueInUsd]
339
+ );
340
+
341
+ const data = encodeMetadata({
342
+ type: MetadataEnums["import"],
343
+ encodedData,
344
+ });
345
+
346
+ return single ? encodeMultipleActions(data) : data;
347
+ };
348
+
349
+ export const encodeAddSignersMetadata = (
350
+ addresses: string[],
351
+ single = true
352
+ ) => {
353
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
354
+ actionMetadataTypes["add-signers"],
355
+ [addresses]
356
+ );
357
+
358
+ const data = encodeMetadata({
359
+ type: MetadataEnums["add-signers"],
235
360
  encodedData,
236
361
  });
237
362
 
@@ -261,8 +386,10 @@ export const decodeMetadata = (metadata: string) => {
261
386
  }
262
387
  };
263
388
 
389
+ const iface = Forwarder__factory.createInterface();
390
+ const ifaceMultisig = MultisigForwarder__factory.createInterface();
391
+
264
392
  const getMetadataFromData = (data: string) => {
265
- const iface = Forwarder__factory.createInterface();
266
393
  let metadata = "0x";
267
394
 
268
395
  if (data.startsWith("0x18e7f485")) {
@@ -282,37 +409,122 @@ const getMetadataFromData = (data: string) => {
282
409
  } else {
283
410
  metadata = executeDataV2.params_.metadata;
284
411
  }
285
- } else if (data.startsWith("0x85114d53")) {
286
- const executeDataV3 = iface.decodeFunctionData("executeV3", data);
287
- if (
288
- executeDataV3.params_.metadata === "0x" ||
289
- !executeDataV3.params_.metadata
290
- ) {
291
- return null;
292
- } else {
293
- metadata = executeDataV3.params_.metadata;
294
- }
295
412
  } else {
296
- const executeDataMultisigV3 = iface.decodeFunctionData(
297
- "executeMultisigV3",
413
+ const executeDataMultisig = ifaceMultisig.decodeFunctionData(
414
+ "executeV1",
298
415
  data
299
416
  );
300
417
  if (
301
- executeDataMultisigV3.params_.metadata === "0x" ||
302
- !executeDataMultisigV3.params_.metadata
418
+ executeDataMultisig.params_.metadata === "0x" ||
419
+ !executeDataMultisig.params_.metadata
303
420
  ) {
304
421
  return null;
305
422
  } else {
306
- metadata = executeDataMultisigV3.params_.metadata;
423
+ metadata = executeDataMultisig.params_.metadata;
307
424
  }
308
425
  }
309
426
 
310
427
  return metadata;
311
428
  };
312
429
 
430
+ const typesPayload: IPayload = {
431
+ import: (data, type) => ({
432
+ type,
433
+ protocol: utils.parseBytes32String(data.protocol || ""),
434
+ valueInUsd: toBN(data.valueInUsd).toFixed(),
435
+ }),
436
+ transfer: (data, type) => ({
437
+ type,
438
+ token: data.token,
439
+ amount: toBN(data.amount).toFixed(),
440
+ receiver: data.receiver,
441
+ }),
442
+ bridge: (data, type) => ({
443
+ type,
444
+ amount: toBN(data.amount).toFixed(),
445
+ receiver: data.receiver,
446
+ toToken: data.toToken,
447
+ fromToken: data.fromToken,
448
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
449
+ bridgeFee: toBN(data.bridgeFee).toFixed(),
450
+ }),
451
+ swap: (data, type) => ({
452
+ type,
453
+ buyAmount: toBN(data.buyAmount).toFixed(),
454
+ sellAmount: toBN(data.sellAmount).toFixed(),
455
+ buyToken: data.buyToken,
456
+ sellToken: data.sellToken,
457
+ receiver: data.receiver,
458
+ protocol: utils.parseBytes32String(data.protocol || ""),
459
+ }),
460
+ upgrade: (data, type) => ({
461
+ type,
462
+ version: utils.parseBytes32String(data.version || ""),
463
+ walletImpl: data.walletImpl,
464
+ }),
465
+ "gas-topup": (data, type) => ({
466
+ type,
467
+ amount: toBN(data.amount).toFixed(),
468
+ token: data.token,
469
+ onBehalf: data.onBehalf,
470
+ }),
471
+ dapp: (data, type) => ({
472
+ type,
473
+ name: data.name,
474
+ url: data.url,
475
+ }),
476
+ deploy: (data, type) => ({
477
+ type,
478
+ }),
479
+ "tx-builder": (data, type) => ({
480
+ type,
481
+ actionCount: utils.parseBytes32String(data.actionCount || ""),
482
+ }),
483
+ permit2: (data, type) => ({
484
+ type,
485
+ token: data.token,
486
+ spender: data.spender,
487
+ amount: toBN(data.amount).toFixed(),
488
+ expiration: data.expiration,
489
+ }),
490
+ "cross-transfer": (data, type) => ({
491
+ type,
492
+ fromToken: data.fromToken,
493
+ toToken: data.toToken,
494
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
495
+ amount: toBN(data.amount).toFixed(),
496
+ receiver: data.receiver,
497
+ }),
498
+ auth: (data) => ({
499
+ type: data.remove ? "remove-authority" : "add-authority",
500
+ address: data.address,
501
+ chainId: data.chainId ? data.chainId.toString() : null,
502
+ remove: data.remove,
503
+ }),
504
+ "instadapp-pro": (data, type) => ({
505
+ type,
506
+ castDetails: data.castDetails,
507
+ }),
508
+ rejection: (data, type) => ({
509
+ type,
510
+ id: data.id,
511
+ }),
512
+ "add-signers": (data, type) => ({
513
+ type,
514
+ addresses: data.signers,
515
+ }),
516
+ "remove-signers": (data, type) => ({
517
+ type,
518
+ addresses: data.signers,
519
+ }),
520
+ "change-threshold": (data, type) => ({
521
+ type,
522
+ count: data.count,
523
+ }),
524
+ };
525
+
313
526
  const parseMetadata = (metadata: string) => {
314
527
  const metadataArr = [];
315
- let payload = {};
316
528
 
317
529
  const [decodedMultiMetadata = []] =
318
530
  (ethers.utils.defaultAbiCoder.decode(
@@ -335,109 +547,12 @@ const parseMetadata = (metadata: string) => {
335
547
  decodedMetadata.data
336
548
  );
337
549
 
338
- switch (type) {
339
- case "transfer":
340
- payload = {
341
- type,
342
- token: decodedData.token,
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;
438
- }
550
+ const payloadFunc = typesPayload[type];
439
551
 
440
- metadataArr.push(payload);
552
+ if (payloadFunc) {
553
+ const payload = payloadFunc(decodedData, type);
554
+ metadataArr.push(payload);
555
+ }
441
556
  }
442
557
 
443
558
  return metadataArr;