@instadapp/avocado-base 0.0.0-dev.30dac02 → 0.0.0-dev.31df1b6

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 (83) hide show
  1. package/abi/forwarder.json +8 -8
  2. package/abi/multisigForwarder.json +697 -0
  3. package/app.vue +7 -0
  4. package/assets/images/icons/arrow-left.svg +5 -0
  5. package/assets/images/icons/arrow-right.svg +5 -0
  6. package/assets/images/icons/avocado.svg +4 -0
  7. package/assets/images/icons/bridge-2.svg +3 -0
  8. package/assets/images/icons/bridge.svg +7 -0
  9. package/assets/images/icons/calendar.svg +8 -0
  10. package/assets/images/icons/change-threshold.svg +4 -0
  11. package/assets/images/icons/check-circle.svg +4 -0
  12. package/assets/images/icons/chevron-down.svg +4 -0
  13. package/assets/images/icons/clipboard.svg +7 -0
  14. package/assets/images/icons/clock-circle.svg +5 -0
  15. package/assets/images/icons/copy.svg +5 -0
  16. package/assets/images/icons/cross-transfer.svg +7 -0
  17. package/assets/images/icons/dapp.svg +4 -0
  18. package/assets/images/icons/deploy.svg +12 -0
  19. package/assets/images/icons/error-circle.svg +6 -0
  20. package/assets/images/icons/exclamation-circle.svg +13 -0
  21. package/assets/images/icons/exclamation-octagon.svg +13 -0
  22. package/assets/images/icons/exclamation-triangle.svg +5 -0
  23. package/assets/images/icons/external-link.svg +6 -0
  24. package/assets/images/icons/eye.svg +4 -0
  25. package/assets/images/icons/flowers.svg +8 -0
  26. package/assets/images/icons/gas-emoji.svg +193 -0
  27. package/assets/images/icons/gas.svg +14 -0
  28. package/assets/images/icons/gift.svg +153 -0
  29. package/assets/images/icons/globe.svg +110 -0
  30. package/assets/images/icons/hamburger.svg +6 -0
  31. package/assets/images/icons/info-2.svg +12 -0
  32. package/assets/images/icons/instadapp-pro.svg +4 -0
  33. package/assets/images/icons/logout.svg +3 -0
  34. package/assets/images/icons/moon.svg +3 -0
  35. package/assets/images/icons/multi-send.svg +7 -0
  36. package/assets/images/icons/network.svg +13 -0
  37. package/assets/images/icons/options.svg +5 -0
  38. package/assets/images/icons/permit-sign.svg +11 -0
  39. package/assets/images/icons/plus-circle.svg +6 -0
  40. package/assets/images/icons/plus.svg +5 -0
  41. package/assets/images/icons/power-off-bg.svg +24 -0
  42. package/assets/images/icons/power-off.svg +19 -0
  43. package/assets/images/icons/power-on.svg +19 -0
  44. package/assets/images/icons/qr.svg +20 -0
  45. package/assets/images/icons/question-circle.svg +14 -0
  46. package/assets/images/icons/refresh.svg +6 -0
  47. package/assets/images/icons/reject-proposal.svg +6 -0
  48. package/assets/images/icons/search.svg +12 -0
  49. package/assets/images/icons/sun.svg +3 -0
  50. package/assets/images/icons/transfer.svg +5 -0
  51. package/assets/images/icons/trash-2.svg +8 -0
  52. package/assets/images/icons/upgrade.svg +4 -0
  53. package/assets/images/icons/wave.svg +214 -0
  54. package/assets/images/icons/x.svg +5 -0
  55. package/components/ActionLogo.vue +38 -0
  56. package/components/ActionMetadata.vue +72 -0
  57. package/components/AuthorityAvatar.vue +38 -0
  58. package/components/ChainLogo.vue +14 -556
  59. package/components/CopyClipboard.vue +64 -0
  60. package/components/metadata/Bridge.vue +59 -0
  61. package/components/metadata/CrossTransfer.vue +71 -0
  62. package/components/metadata/GasTopup.vue +39 -0
  63. package/components/metadata/Permit2.vue +42 -0
  64. package/components/metadata/Signers.vue +62 -0
  65. package/components/metadata/Swap.vue +74 -0
  66. package/components/metadata/Transfer.vue +50 -0
  67. package/components.d.ts +13 -0
  68. package/contracts/Forwarder.ts +4 -4
  69. package/contracts/MultisigForwarder.ts +859 -0
  70. package/contracts/factories/Forwarder__factory.ts +8 -8
  71. package/contracts/factories/MultisigForwarder__factory.ts +721 -0
  72. package/contracts/factories/index.ts +1 -0
  73. package/contracts/index.ts +2 -0
  74. package/nuxt.config.ts +17 -1
  75. package/package.json +9 -4
  76. package/utils/avocado.ts +2 -0
  77. package/utils/bignumber.ts +20 -0
  78. package/utils/formatter.ts +1 -1
  79. package/utils/helper.ts +8 -0
  80. package/utils/metadata.ts +290 -170
  81. package/utils/network.ts +136 -80
  82. package/utils/services.ts +21 -0
  83. package/utils/utils.d.ts +129 -114
@@ -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/nuxt.config.ts CHANGED
@@ -1,4 +1,20 @@
1
1
  // https://nuxt.com/docs/api/configuration/nuxt-config
2
+ import ViteComponents from "unplugin-vue-components/vite";
3
+
2
4
  export default defineNuxtConfig({
3
- modules: ["@nuxtjs/tailwindcss"],
5
+ modules: ["@nuxtjs/tailwindcss", "nuxt-svgo", "@vueuse/nuxt"],
6
+ svgo: {
7
+ defaultImport: "component",
8
+ autoImportPath: "./assets/images/icons",
9
+ svgoConfig: {
10
+ plugins: ["prefixIds"],
11
+ },
12
+ },
13
+ vite: {
14
+ plugins: [
15
+ ViteComponents({
16
+ dts: true,
17
+ }),
18
+ ],
19
+ },
4
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.30dac02",
3
+ "version": "0.0.0-dev.31df1b6",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
@@ -16,12 +16,17 @@
16
16
  "@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
17
17
  "@nuxtjs/tailwindcss": "^6.6.5",
18
18
  "@typechain/ethers-v5": "^10.2.0",
19
- "nuxt": "^3.3.3",
19
+ "nuxt": "^3.6.1",
20
+ "nuxt-svgo": "^3.1.0",
20
21
  "rimraf": "^3.0.2",
21
- "typechain": "^8.1.1"
22
+ "typechain": "^8.1.1",
23
+ "unplugin-vue-components": "^0.25.1",
24
+ "vue-tippy": "^6.0.0"
22
25
  },
23
26
  "dependencies": {
27
+ "@vueuse/nuxt": "^10.2.0",
24
28
  "bignumber.js": "^9.1.1",
25
- "ethers": "^5.7.2"
29
+ "ethers": "^5.7.2",
30
+ "xxhashjs": "^0.2.2"
26
31
  }
27
32
  }
package/utils/avocado.ts CHANGED
@@ -20,3 +20,5 @@ export const AVO_STAGING_DEPOSIT_ADDRESS =
20
20
  export const AVO_PROD_RPC_URL = "https://rpc.avocado.instadapp.io";
21
21
 
22
22
  export const AVO_STAGING_RPC_URL = "https://rpc.avocado.instad.app";
23
+
24
+ export const blockQueryURL = "https://blockquery.instadapp.io";
@@ -1,6 +1,8 @@
1
1
  import { BigNumber } from "bignumber.js";
2
2
  import { BigNumber as BN } from "ethers";
3
3
 
4
+ type CombinedBigNumber = BigNumber | string | number;
5
+
4
6
  export const toBN = (value: BigNumber.Value | BN) =>
5
7
  new BigNumber(BN.isBigNumber(value) ? value.toString() : value);
6
8
  export const isZero = (value: BigNumber.Value | BN) => toBN(value).isZero();
@@ -29,3 +31,21 @@ export const ensureValue = (value: any) => {
29
31
  export const max = (...args: BigNumber.Value[]) => {
30
32
  return BigNumber.max(...args);
31
33
  };
34
+
35
+ export function pow(value: CombinedBigNumber, exponent: string | number) {
36
+ return toBN(value).pow(toBN(exponent));
37
+ }
38
+
39
+ export function toWei(val: CombinedBigNumber, decimals: number): string {
40
+ const num = toBN(val);
41
+ const multiplier = pow(10, decimals);
42
+ return times(num, multiplier).toFixed(0);
43
+ }
44
+
45
+ export function fromWei(val: CombinedBigNumber, decimal = 18) {
46
+ return toBN(val).div(new BigNumber(10).pow(decimal));
47
+ }
48
+
49
+ export function abs(value: CombinedBigNumber) {
50
+ return toBN(value).abs();
51
+ }
@@ -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,30 @@
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
+ } as const;
3
22
 
4
23
  const multiMetadataTypes = ["bytes[]"];
5
24
 
6
25
  const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
7
26
 
8
- const actionMetadataTypes = {
27
+ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
9
28
  transfer: ["address token", "uint256 amount", "address receiver"],
10
29
  "cross-transfer": [
11
30
  "address fromToken",
@@ -42,6 +61,11 @@ const actionMetadataTypes = {
42
61
  "uint160 amount",
43
62
  "uint48 expiration",
44
63
  ],
64
+ "instadapp-pro": ["string castDetails"],
65
+ 'add-signers': ['address[] signers'],
66
+ 'remove-signers': ['address[] signers'],
67
+ 'change-threshold': ['uint8 count'],
68
+ 'rejection': ['bytes32 id'],
45
69
  };
46
70
 
47
71
  const encodeMetadata = (props: MetadataProps) => {
@@ -62,7 +86,7 @@ export const encodeDappMetadata = (
62
86
  );
63
87
 
64
88
  const data = encodeMetadata({
65
- type: "dapp",
89
+ type: MetadataEnums.dapp,
66
90
  encodedData,
67
91
  });
68
92
 
@@ -79,7 +103,21 @@ export const encodeTransferMetadata = (
79
103
  );
80
104
 
81
105
  const data = encodeMetadata({
82
- type: "transfer",
106
+ type: MetadataEnums.transfer,
107
+ encodedData,
108
+ });
109
+
110
+ return single ? encodeMultipleActions(data) : data;
111
+ };
112
+
113
+ export const encodeRejectionMetadata = (id: string, single = true) => {
114
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
115
+ actionMetadataTypes.rejection,
116
+ [id]
117
+ );
118
+
119
+ const data = encodeMetadata({
120
+ type: MetadataEnums.rejection,
83
121
  encodedData,
84
122
  });
85
123
 
@@ -102,7 +140,7 @@ export const encodeCrossTransferMetadata = (
102
140
  );
103
141
 
104
142
  const data = encodeMetadata({
105
- type: "cross-transfer",
143
+ type: MetadataEnums["cross-transfer"],
106
144
  encodedData,
107
145
  });
108
146
 
@@ -119,7 +157,7 @@ export const encodeAuthMetadata = (
119
157
  );
120
158
 
121
159
  const data = encodeMetadata({
122
- type: "auth",
160
+ type: MetadataEnums.auth,
123
161
  encodedData,
124
162
  });
125
163
 
@@ -128,7 +166,7 @@ export const encodeAuthMetadata = (
128
166
 
129
167
  export const encodeDeployMetadata = (single = true) => {
130
168
  const data = encodeMetadata({
131
- type: "deploy",
169
+ type: MetadataEnums.deploy,
132
170
  encodedData: "0x",
133
171
  });
134
172
 
@@ -145,7 +183,7 @@ export const encodeWCSignMetadata = (
145
183
  );
146
184
 
147
185
  const data = encodeMetadata({
148
- type: "permit2",
186
+ type: MetadataEnums.permit2,
149
187
  encodedData,
150
188
  });
151
189
 
@@ -162,7 +200,7 @@ export const encodeUpgradeMetadata = (
162
200
  );
163
201
 
164
202
  const data = encodeMetadata({
165
- type: "upgrade",
203
+ type: MetadataEnums.upgrade,
166
204
  encodedData,
167
205
  });
168
206
 
@@ -186,7 +224,7 @@ export const encodeSwapMetadata = (
186
224
  );
187
225
 
188
226
  const data = encodeMetadata({
189
- type: "swap",
227
+ type: MetadataEnums.swap,
190
228
  encodedData,
191
229
  });
192
230
 
@@ -202,10 +240,8 @@ export const encodeTopupMetadata = (
202
240
  [params.amount, params.token, params.onBehalf]
203
241
  );
204
242
 
205
- console.log(params);
206
-
207
243
  const data = encodeMetadata({
208
- type: "gas-topup",
244
+ type: MetadataEnums["gas-topup"],
209
245
  encodedData,
210
246
  });
211
247
 
@@ -230,7 +266,58 @@ export const encodeBridgeMetadata = (
230
266
  );
231
267
 
232
268
  const data = encodeMetadata({
233
- type: "bridge",
269
+ type: MetadataEnums.bridge,
270
+ encodedData,
271
+ });
272
+
273
+ return single ? encodeMultipleActions(data) : data;
274
+ };
275
+
276
+ export const encodeChangeThresholdMetadata = (
277
+ threshold: string | number,
278
+ single = true
279
+ ) => {
280
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
281
+ actionMetadataTypes["change-threshold"],
282
+ [toBN(threshold).toNumber()]
283
+ );
284
+
285
+ const data = encodeMetadata({
286
+ type: MetadataEnums["change-threshold"],
287
+ encodedData,
288
+ });
289
+
290
+ return single ? encodeMultipleActions(data) : data;
291
+ };
292
+
293
+ export const encodeRemoveSignersMetadata = (
294
+ addresses: string[],
295
+ single = true
296
+ ) => {
297
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
298
+ actionMetadataTypes["remove-signers"],
299
+ [addresses]
300
+ );
301
+
302
+ const data = encodeMetadata({
303
+ type: MetadataEnums["remove-signers"],
304
+ encodedData,
305
+ });
306
+
307
+ return single ? encodeMultipleActions(data) : data;
308
+ };
309
+
310
+ export const encodeAddSignersMetadata = (
311
+ addresses: string[],
312
+ single = true
313
+ ) => {
314
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
315
+ actionMetadataTypes["add-signers"],
316
+ [addresses]
317
+ );
318
+
319
+ const data = encodeMetadata({
320
+ type: MetadataEnums["add-signers"],
234
321
  encodedData,
235
322
  });
236
323
 
@@ -241,169 +328,202 @@ export const encodeMultipleActions = (...actionData: string[]) => {
241
328
  return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
242
329
  };
243
330
 
244
- export const decodeMetadata = (data: string) => {
331
+ export const decodeData = (data: string) => {
332
+ try {
333
+ const metadata = getMetadataFromData(data) || "0x";
334
+
335
+ return parseMetadata(metadata);
336
+ } catch (e) {
337
+ // console.log(e);
338
+ return null;
339
+ }
340
+ };
341
+
342
+ export const decodeMetadata = (metadata: string) => {
245
343
  try {
246
- const iface = Forwarder__factory.createInterface();
247
- let metadata = "0x";
248
- let payload = {};
249
-
250
- if (!data) return payload;
251
-
252
- if (data.startsWith("0x18e7f485")) {
253
- const executeData = iface.decodeFunctionData("execute", data);
254
- if (executeData.metadata_ === "0x" || !executeData.metadata_) {
255
- return null;
256
- } else {
257
- metadata = executeData.metadata_;
258
- }
259
- } else if (data.startsWith("0x14f80a8d")) {
260
- const executeDataV2 = iface.decodeFunctionData("executeV2", data);
261
- if (
262
- executeDataV2.params_.metadata === "0x" ||
263
- !executeDataV2.params_.metadata
264
- ) {
265
- return null;
266
- } else {
267
- metadata = executeDataV2.params_.metadata;
268
- }
344
+ return parseMetadata(metadata);
345
+ } catch (e) {
346
+ return null;
347
+ }
348
+ };
349
+
350
+ const iface = Forwarder__factory.createInterface();
351
+ const ifaceMultisig = MultisigForwarder__factory.createInterface();
352
+
353
+ const getMetadataFromData = (data: string) => {
354
+ let metadata = "0x";
355
+
356
+ if (data.startsWith("0x18e7f485")) {
357
+ const executeData = iface.decodeFunctionData("execute", data);
358
+ if (executeData.metadata_ === "0x" || !executeData.metadata_) {
359
+ return null;
360
+ } else {
361
+ metadata = executeData.metadata_;
362
+ }
363
+ } else if (data.startsWith("0x14f80a8d")) {
364
+ const executeDataV2 = iface.decodeFunctionData("executeV2", data);
365
+ if (
366
+ executeDataV2.params_.metadata === "0x" ||
367
+ !executeDataV2.params_.metadata
368
+ ) {
369
+ return null;
370
+ } else {
371
+ metadata = executeDataV2.params_.metadata;
372
+ }
373
+ } else {
374
+ const executeDataMultisig = ifaceMultisig.decodeFunctionData(
375
+ "executeV1",
376
+ data
377
+ );
378
+ if (
379
+ executeDataMultisig.params_.metadata === "0x" ||
380
+ !executeDataMultisig.params_.metadata
381
+ ) {
382
+ return null;
269
383
  } else {
270
- const executeDataV3 = iface.decodeFunctionData("executeV3", data);
271
- if (
272
- executeDataV3.params_.metadata === "0x" ||
273
- !executeDataV3.params_.metadata
274
- ) {
275
- return null;
276
- } else {
277
- metadata = executeDataV3.params_.metadata;
278
- }
384
+ metadata = executeDataMultisig.params_.metadata;
279
385
  }
386
+ }
280
387
 
281
- const metadataArr = [];
282
-
283
- const [decodedMultiMetadata = []] =
284
- (ethers.utils.defaultAbiCoder.decode(
285
- multiMetadataTypes,
286
- metadata
287
- ) as string[]) || [];
288
-
289
- for (let metadata of decodedMultiMetadata) {
290
- const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
291
- metadataTypes,
292
- metadata
293
- );
294
-
295
- const type = ethers.utils.parseBytes32String(
296
- decodedMetadata.type
297
- ) as keyof typeof actionMetadataTypes;
298
-
299
- const decodedData = ethers.utils.defaultAbiCoder.decode(
300
- actionMetadataTypes[type],
301
- decodedMetadata.data
302
- );
303
-
304
- switch (type) {
305
- case "transfer":
306
- payload = {
307
- type,
308
- token: decodedData.token,
309
- amount: toBN(decodedData.amount).toFixed(),
310
- receiver: decodedData.receiver,
311
- };
312
- break;
313
- case "bridge":
314
- payload = {
315
- type,
316
- amount: toBN(decodedData.amount).toFixed(),
317
- receiver: decodedData.receiver,
318
- toToken: decodedData.toToken,
319
- fromToken: decodedData.fromToken,
320
- toChainId: decodedData.toChainId
321
- ? decodedData.toChainId.toString()
322
- : null,
323
- bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
324
- };
325
- break;
326
- case "swap":
327
- payload = {
328
- type,
329
- buyAmount: toBN(decodedData.buyAmount).toFixed(),
330
- sellAmount: toBN(decodedData.sellAmount).toFixed(),
331
- buyToken: decodedData.buyToken,
332
- sellToken: decodedData.sellToken,
333
- receiver: decodedData.receiver,
334
- protocol: utils.parseBytes32String(decodedData?.protocol || ""),
335
- };
336
- break;
337
- case "upgrade":
338
- payload = {
339
- type,
340
- version: utils.parseBytes32String(decodedData?.version || ""),
341
- walletImpl: decodedData?.walletImpl,
342
- };
343
- break;
344
- case "gas-topup":
345
- payload = {
346
- type,
347
- amount: toBN(decodedData.amount).toFixed(),
348
- token: decodedData.token,
349
- onBehalf: decodedData.onBehalf,
350
- };
351
- break;
352
- case "dapp":
353
- payload = {
354
- type,
355
- name: decodedData?.name,
356
- url: decodedData?.url,
357
- };
358
- break;
359
- case "deploy":
360
- payload = {
361
- type,
362
- };
363
- break;
364
-
365
- case "permit2":
366
- payload = {
367
- type,
368
- token: decodedData.token,
369
- spender: decodedData.spender,
370
- amount: toBN(decodedData.amount).toFixed(),
371
- expiration: decodedData.expiration,
372
- };
373
- break;
374
-
375
- case "cross-transfer":
376
- payload = {
377
- type,
378
- fromToken: decodedData.fromToken,
379
- toToken: decodedData.toToken,
380
- toChainId: decodedData.toChainId
381
- ? decodedData.toChainId.toString()
382
- : null,
383
- amount: toBN(decodedData.amount).toFixed(),
384
- receiver: decodedData.receiver,
385
- };
386
-
387
- break;
388
- case "auth":
389
- payload = {
390
- type: decodedData.remove ? "remove-authority" : "add-authority",
391
- address: decodedData.address,
392
- chainId: decodedData.chainId
393
- ? decodedData.chainId.toString()
394
- : null,
395
- remove: decodedData.remove,
396
- };
397
-
398
- break;
399
- }
388
+ return metadata;
389
+ };
400
390
 
391
+
392
+ const typesPayload: IPayload = {
393
+ transfer: (data, type) => ({
394
+ type,
395
+ token: data.token,
396
+ amount: toBN(data.amount).toFixed(),
397
+ receiver: data.receiver,
398
+ }),
399
+ bridge: (data, type) => ({
400
+ type,
401
+ amount: toBN(data.amount).toFixed(),
402
+ receiver: data.receiver,
403
+ toToken: data.toToken,
404
+ fromToken: data.fromToken,
405
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
406
+ bridgeFee: toBN(data.bridgeFee).toFixed(),
407
+ }),
408
+ swap: (data, type) => ({
409
+ type,
410
+ buyAmount: toBN(data.buyAmount).toFixed(),
411
+ sellAmount: toBN(data.sellAmount).toFixed(),
412
+ buyToken: data.buyToken,
413
+ sellToken: data.sellToken,
414
+ receiver: data.receiver,
415
+ protocol: utils.parseBytes32String(data.protocol || ""),
416
+ }),
417
+ upgrade: (data, type) => ({
418
+ type,
419
+ version: utils.parseBytes32String(data.version || ""),
420
+ walletImpl: data.walletImpl,
421
+ }),
422
+ "gas-topup": (data, type) => ({
423
+ type,
424
+ amount: toBN(data.amount).toFixed(),
425
+ token: data.token,
426
+ onBehalf: data.onBehalf,
427
+ }),
428
+ "dapp": (data, type) => ({
429
+ type,
430
+ name: data.name,
431
+ url: data.url,
432
+ }),
433
+ "deploy": (data, type) => ({
434
+ type,
435
+ }),
436
+ "permit2": (data, type) => ({
437
+ type,
438
+ token: data.token,
439
+ spender: data.spender,
440
+ amount: toBN(data.amount).toFixed(),
441
+ expiration: data.expiration,
442
+ }),
443
+ "cross-transfer": (data, type) => ({
444
+ type,
445
+ fromToken: data.fromToken,
446
+ toToken: data.toToken,
447
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
448
+ amount: toBN(data.amount).toFixed(),
449
+ receiver: data.receiver,
450
+ }),
451
+ "auth": (data) => ({
452
+ type: data.remove ? "remove-authority" : "add-authority",
453
+ address: data.address,
454
+ chainId: data.chainId ? data.chainId.toString() : null,
455
+ remove: data.remove,
456
+ }),
457
+ "instadapp-pro": (data, type) => ({
458
+ type,
459
+ castDetails: data.castDetails,
460
+ }),
461
+ "rejection": (data, type) => ({
462
+ type,
463
+ id: data.id,
464
+ }),
465
+ "add-signers": (data, type) => ({
466
+ type,
467
+ addresses: data.signers,
468
+ }),
469
+ "remove-signers": (data, type) => ({
470
+ type,
471
+ addresses: data.signers,
472
+ }),
473
+ "change-threshold": (data, type) => ({
474
+ type,
475
+ count: data.count,
476
+ }),
477
+ };
478
+
479
+ const parseMetadata = (metadata: string) => {
480
+ const metadataArr = [];
481
+
482
+ const [decodedMultiMetadata = []] =
483
+ (ethers.utils.defaultAbiCoder.decode(
484
+ multiMetadataTypes,
485
+ metadata
486
+ ) as string[]) || [];
487
+
488
+ for (let metadata of decodedMultiMetadata) {
489
+ const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
490
+ metadataTypes,
491
+ metadata
492
+ );
493
+
494
+ const type = ethers.utils.parseBytes32String(
495
+ decodedMetadata.type
496
+ ) as keyof typeof actionMetadataTypes;
497
+
498
+ const decodedData = ethers.utils.defaultAbiCoder.decode(
499
+ actionMetadataTypes[type],
500
+ decodedMetadata.data
501
+ );
502
+
503
+ const payloadFunc = typesPayload[type]
504
+
505
+ if (payloadFunc) {
506
+ const payload = payloadFunc(decodedData, type)
401
507
  metadataArr.push(payload);
402
508
  }
403
509
 
404
- return metadataArr;
405
- } catch (e) {
406
- console.log(e);
407
- return null;
408
510
  }
511
+
512
+ return metadataArr;
513
+ };
514
+
515
+
516
+
517
+ /**
518
+ * Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
519
+ * @param {string} txType - The input sentence to modify
520
+ *
521
+ * @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
522
+ */
523
+ export const formatTxType = (txType: string) => {
524
+ const finalSentence = txType
525
+ .replace("-", " ")
526
+ .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
527
+
528
+ return finalSentence;
409
529
  };