@instadapp/avocado-base 0.0.0-dev.babcb27 → 0.0.0-dev.bf2fef7

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 (60) hide show
  1. package/abi/forwarder.json +1253 -149
  2. package/assets/images/icons/arrow-left.svg +5 -0
  3. package/assets/images/icons/arrow-right.svg +5 -0
  4. package/assets/images/icons/avocado.svg +4 -0
  5. package/assets/images/icons/bridge-2.svg +3 -0
  6. package/assets/images/icons/bridge.svg +7 -0
  7. package/assets/images/icons/calendar.svg +8 -0
  8. package/assets/images/icons/check-circle.svg +4 -0
  9. package/assets/images/icons/chevron-down.svg +4 -0
  10. package/assets/images/icons/clipboard.svg +7 -0
  11. package/assets/images/icons/clock-circle.svg +5 -0
  12. package/assets/images/icons/copy.svg +5 -0
  13. package/assets/images/icons/error-circle.svg +6 -0
  14. package/assets/images/icons/exclamation-circle.svg +13 -0
  15. package/assets/images/icons/exclamation-octagon.svg +13 -0
  16. package/assets/images/icons/exclamation-triangle.svg +5 -0
  17. package/assets/images/icons/external-link.svg +6 -0
  18. package/assets/images/icons/eye.svg +4 -0
  19. package/assets/images/icons/flowers.svg +8 -0
  20. package/assets/images/icons/gas-emoji.svg +193 -0
  21. package/assets/images/icons/gas.svg +7 -0
  22. package/assets/images/icons/gift.svg +153 -0
  23. package/assets/images/icons/globe.svg +110 -0
  24. package/assets/images/icons/hamburger.svg +6 -0
  25. package/assets/images/icons/logout.svg +3 -0
  26. package/assets/images/icons/moon.svg +3 -0
  27. package/assets/images/icons/network.svg +13 -0
  28. package/assets/images/icons/options.svg +5 -0
  29. package/assets/images/icons/plus.svg +5 -0
  30. package/assets/images/icons/power-off-bg.svg +24 -0
  31. package/assets/images/icons/power-off.svg +19 -0
  32. package/assets/images/icons/power-on.svg +19 -0
  33. package/assets/images/icons/qr.svg +20 -0
  34. package/assets/images/icons/question-circle.svg +14 -0
  35. package/assets/images/icons/refresh.svg +6 -0
  36. package/assets/images/icons/search.svg +12 -0
  37. package/assets/images/icons/sun.svg +3 -0
  38. package/assets/images/icons/wave.svg +214 -0
  39. package/assets/images/icons/x.svg +5 -0
  40. package/components/ActionMetadata.vue +73 -0
  41. package/components/ChainLogo.vue +1 -1
  42. package/components/metadata/Bridge.vue +39 -0
  43. package/components/metadata/CrossTransfer.vue +67 -0
  44. package/components/metadata/GasTopup.vue +33 -0
  45. package/components/metadata/Permit2.vue +37 -0
  46. package/components/metadata/Swap.vue +67 -0
  47. package/components/metadata/Transfer.vue +46 -0
  48. package/components.d.ts +13 -0
  49. package/contracts/Forwarder.ts +856 -2
  50. package/contracts/factories/Forwarder__factory.ts +816 -16
  51. package/nuxt.config.ts +17 -1
  52. package/package.json +6 -3
  53. package/utils/avocado.ts +2 -0
  54. package/utils/bignumber.ts +20 -0
  55. package/utils/formatter.ts +49 -6
  56. package/utils/helper.ts +7 -0
  57. package/utils/metadata.ts +317 -123
  58. package/utils/network.ts +33 -9
  59. package/utils/services.ts +14 -0
  60. package/utils/utils.d.ts +48 -10
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.babcb27",
3
+ "version": "0.0.0-dev.bf2fef7",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
@@ -16,11 +16,14 @@
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"
22
24
  },
23
25
  "dependencies": {
26
+ "@vueuse/nuxt": "^10.2.0",
24
27
  "bignumber.js": "^9.1.1",
25
28
  "ethers": "^5.7.2"
26
29
  }
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
+ }
@@ -1,11 +1,14 @@
1
1
  export function formatPercent(
2
- value: number,
2
+ value?: number | string,
3
3
  fractionDigits = 2,
4
4
  maxValue = null
5
5
  ) {
6
- if (isZero(value)) return "0.00%";
6
+ if (!value || isZero(value)) return "0.00%";
7
7
 
8
- if (maxValue && gt(times(value, "100"), maxValue)) return `>${maxValue}%`;
8
+ const valueAsNumber = toBN(value).toNumber();
9
+
10
+ if (maxValue && gt(times(valueAsNumber, "100"), maxValue))
11
+ return `>${maxValue}%`;
9
12
 
10
13
  const formatter = new Intl.NumberFormat("en-US", {
11
14
  style: "percent",
@@ -13,7 +16,7 @@ export function formatPercent(
13
16
  maximumFractionDigits: fractionDigits,
14
17
  });
15
18
 
16
- return formatter.format(value);
19
+ return formatter.format(valueAsNumber);
17
20
  }
18
21
 
19
22
  export function shortenHash(hash: string, length: number = 4) {
@@ -42,10 +45,50 @@ export function signedNumber(numb: string | number) {
42
45
  }).format(toBN(numb).toNumber());
43
46
  }
44
47
 
45
- export function formatDecimal(value: string | number, decimalPlaces = 5) {
48
+ function getFractionDigits(value: string | number) {
49
+ const absoluteValue = toBN(value).abs();
50
+
51
+ if (isZero(absoluteValue)) {
52
+ return 2;
53
+ } else if (lt(absoluteValue, 0.01)) {
54
+ return 6;
55
+ } else if (lt(absoluteValue, 1)) {
56
+ return 4;
57
+ } else if (lt(absoluteValue, 10000)) {
58
+ return 2;
59
+ } else {
60
+ return 0;
61
+ }
62
+ }
63
+
64
+ export function formatDecimal(value: string | number, fractionDigits?: number) {
46
65
  if (!value) {
47
66
  value = "0";
48
67
  }
68
+ if (lt(value, "0.0001") && gt(value, "0")) {
69
+ return "< 0.0001";
70
+ } else {
71
+ const num = toBN(value);
72
+ let decimals;
73
+
74
+ if (num.lt(1)) {
75
+ decimals = 8;
76
+ } else if (num.lt(10)) {
77
+ decimals = 6;
78
+ } else if (num.lt(100)) {
79
+ decimals = 4;
80
+ } else if (num.lt(1000)) {
81
+ decimals = 3;
82
+ } else if (num.lt(10000)) {
83
+ decimals = 2;
84
+ } else if (num.lt(100000)) {
85
+ decimals = 1;
86
+ } else {
87
+ decimals = 0;
88
+ }
49
89
 
50
- return toBN(value).decimalPlaces(decimalPlaces).toFormat();
90
+ const formattedNumber = num.toFixed(fractionDigits || decimals);
91
+
92
+ return toBN(formattedNumber).toFormat();
93
+ }
51
94
  }
package/utils/helper.ts CHANGED
@@ -52,3 +52,10 @@ 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
+ }
package/utils/metadata.ts CHANGED
@@ -1,12 +1,19 @@
1
1
  import { ethers, utils } from "ethers";
2
- import { Forwarder__factory } from "@/contracts";
2
+ import { Forwarder__factory } from "../contracts";
3
3
 
4
4
  const multiMetadataTypes = ["bytes[]"];
5
5
 
6
6
  const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
7
7
 
8
- const actionMetadataTypes = {
8
+ const actionMetadataTypes: Record<MetadataTypes, string[]> = {
9
9
  transfer: ["address token", "uint256 amount", "address receiver"],
10
+ "cross-transfer": [
11
+ "address fromToken",
12
+ "address toToken",
13
+ "uint256 toChainId",
14
+ "uint256 amount",
15
+ "address receiver",
16
+ ],
10
17
  bridge: [
11
18
  "uint256 amount",
12
19
  "address receiver",
@@ -27,6 +34,7 @@ const actionMetadataTypes = {
27
34
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
28
35
  upgrade: ["bytes32 version", "address walletImpl"],
29
36
  dapp: ["string name", "string url"],
37
+ auth: ["address address", "uint256 chainId", "bool remove"],
30
38
  deploy: [],
31
39
  permit2: [
32
40
  "address token",
@@ -34,6 +42,11 @@ const actionMetadataTypes = {
34
42
  "uint160 amount",
35
43
  "uint48 expiration",
36
44
  ],
45
+ "instadapp-pro": ["string castDetails"],
46
+ 'add-signers': ['address[] signers'],
47
+ 'remove-signers': ['address[] signers'],
48
+ 'change-threshold': ['uint8 count'],
49
+ 'rejection': ['bytes32 id'],
37
50
  };
38
51
 
39
52
  const encodeMetadata = (props: MetadataProps) => {
@@ -78,6 +91,60 @@ export const encodeTransferMetadata = (
78
91
  return single ? encodeMultipleActions(data) : data;
79
92
  };
80
93
 
94
+ export const encodeRejectionMetadata = (id: string, single = true) => {
95
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
96
+ actionMetadataTypes.rejection,
97
+ [id]
98
+ );
99
+
100
+ const data = encodeMetadata({
101
+ type: "rejection",
102
+ encodedData,
103
+ });
104
+
105
+ return single ? encodeMultipleActions(data) : data;
106
+ };
107
+
108
+ export const encodeCrossTransferMetadata = (
109
+ params: CrossSendMetadataProps,
110
+ single = true
111
+ ) => {
112
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
113
+ actionMetadataTypes["cross-transfer"],
114
+ [
115
+ params.fromToken,
116
+ params.toToken,
117
+ params.toChainId,
118
+ params.amount,
119
+ params.receiver,
120
+ ]
121
+ );
122
+
123
+ const data = encodeMetadata({
124
+ type: "cross-transfer",
125
+ encodedData,
126
+ });
127
+
128
+ return single ? encodeMultipleActions(data) : data;
129
+ };
130
+
131
+ export const encodeAuthMetadata = (
132
+ params: AuthMetadataProps,
133
+ single = true
134
+ ) => {
135
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
136
+ actionMetadataTypes["auth"],
137
+ [params.address, params.chainId, params.remove]
138
+ );
139
+
140
+ const data = encodeMetadata({
141
+ type: "auth",
142
+ encodedData,
143
+ });
144
+
145
+ return single ? encodeMultipleActions(data) : data;
146
+ };
147
+
81
148
  export const encodeDeployMetadata = (single = true) => {
82
149
  const data = encodeMetadata({
83
150
  type: "deploy",
@@ -189,138 +256,265 @@ export const encodeBridgeMetadata = (
189
256
  return single ? encodeMultipleActions(data) : data;
190
257
  };
191
258
 
259
+ export const encodeChangeThresholdMetadata = (
260
+ threshold: string | number,
261
+ single = true
262
+ ) => {
263
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
264
+ actionMetadataTypes["change-threshold"],
265
+ [toBN(threshold).toNumber()]
266
+ );
267
+
268
+ const data = encodeMetadata({
269
+ type: "change-threshold",
270
+ encodedData,
271
+ });
272
+
273
+ return single ? encodeMultipleActions(data) : data;
274
+ };
275
+
276
+ export const encodeRemoveSignersMetadata = (
277
+ addresses: string[],
278
+ single = true
279
+ ) => {
280
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
281
+ actionMetadataTypes["remove-signers"],
282
+ [addresses]
283
+ );
284
+
285
+ const data = encodeMetadata({
286
+ type: "remove-signers",
287
+ encodedData,
288
+ });
289
+
290
+ return single ? encodeMultipleActions(data) : data;
291
+ };
292
+
293
+ export const encodeAddSignersMetadata = (
294
+ addresses: string[],
295
+ single = true
296
+ ) => {
297
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
298
+ actionMetadataTypes["add-signers"],
299
+ [addresses]
300
+ );
301
+
302
+ const data = encodeMetadata({
303
+ type: "add-signers",
304
+ encodedData,
305
+ });
306
+
307
+ return single ? encodeMultipleActions(data) : data;
308
+ };
309
+
192
310
  export const encodeMultipleActions = (...actionData: string[]) => {
193
311
  return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
194
312
  };
195
313
 
196
- export const decodeMetadata = (data: string) => {
314
+ export const decodeData = (data: string) => {
197
315
  try {
198
- const iface = Forwarder__factory.createInterface();
199
- let metadata = "0x";
200
- let payload = {};
201
-
202
- if (!data) return payload;
203
-
204
- if (data.startsWith("0x18e7f485")) {
205
- const executeData = iface.decodeFunctionData("execute", data);
206
- if (executeData.metadata_ === "0x" || !executeData.metadata_) {
207
- return null;
208
- } else {
209
- metadata = executeData.metadata_;
210
- }
316
+ const metadata = getMetadataFromData(data) || "0x";
317
+
318
+ return parseMetadata(metadata);
319
+ } catch (e) {
320
+ // console.log(e);
321
+ return null;
322
+ }
323
+ };
324
+
325
+ export const decodeMetadata = (metadata: string) => {
326
+ try {
327
+ return parseMetadata(metadata);
328
+ } catch (e) {
329
+ return null;
330
+ }
331
+ };
332
+
333
+ const getMetadataFromData = (data: string) => {
334
+ const iface = Forwarder__factory.createInterface();
335
+ let metadata = "0x";
336
+
337
+ if (data.startsWith("0x18e7f485")) {
338
+ const executeData = iface.decodeFunctionData("execute", data);
339
+ if (executeData.metadata_ === "0x" || !executeData.metadata_) {
340
+ return null;
341
+ } else {
342
+ metadata = executeData.metadata_;
343
+ }
344
+ } else if (data.startsWith("0x14f80a8d")) {
345
+ const executeDataV2 = iface.decodeFunctionData("executeV2", data);
346
+ if (
347
+ executeDataV2.params_.metadata === "0x" ||
348
+ !executeDataV2.params_.metadata
349
+ ) {
350
+ return null;
351
+ } else {
352
+ metadata = executeDataV2.params_.metadata;
353
+ }
354
+ } else if (data.startsWith("0x85114d53")) {
355
+ const executeDataV3 = iface.decodeFunctionData("executeV3", data);
356
+ if (
357
+ executeDataV3.params_.metadata === "0x" ||
358
+ !executeDataV3.params_.metadata
359
+ ) {
360
+ return null;
361
+ } else {
362
+ metadata = executeDataV3.params_.metadata;
363
+ }
364
+ } else {
365
+ const executeDataMultisigV3 = iface.decodeFunctionData(
366
+ "executeMultisigV3",
367
+ data
368
+ );
369
+ if (
370
+ executeDataMultisigV3.params_.metadata === "0x" ||
371
+ !executeDataMultisigV3.params_.metadata
372
+ ) {
373
+ return null;
211
374
  } else {
212
- const executeDataV2 = iface.decodeFunctionData("executeV2", data);
213
- if (
214
- executeDataV2.params_.metadata === "0x" ||
215
- !executeDataV2.params_.metadata
216
- ) {
217
- return null;
218
- } else {
219
- metadata = executeDataV2.params_.metadata;
220
- }
375
+ metadata = executeDataMultisigV3.params_.metadata;
221
376
  }
377
+ }
378
+
379
+ return metadata;
380
+ };
222
381
 
223
- const metadataArr = [];
224
-
225
- const [decodedMultiMetadata = []] =
226
- (ethers.utils.defaultAbiCoder.decode(
227
- multiMetadataTypes,
228
- metadata
229
- ) as string[]) || [];
230
-
231
- for (let metadata of decodedMultiMetadata) {
232
- const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
233
- metadataTypes,
234
- metadata
235
- );
236
-
237
- const type = ethers.utils.parseBytes32String(
238
- decodedMetadata.type
239
- ) as keyof typeof actionMetadataTypes;
240
-
241
- const decodedData = ethers.utils.defaultAbiCoder.decode(
242
- actionMetadataTypes[type],
243
- decodedMetadata.data
244
- );
245
-
246
- switch (type) {
247
- case "transfer":
248
- payload = {
249
- type,
250
- token: decodedData.token,
251
- amount: toBN(decodedData.amount).toFixed(),
252
- receiver: decodedData.receiver,
253
- };
254
- break;
255
- case "bridge":
256
- payload = {
257
- type,
258
- amount: toBN(decodedData.amount).toFixed(),
259
- receiver: decodedData.receiver,
260
- toToken: decodedData.toToken,
261
- fromToken: decodedData.fromToken,
262
- toChainId: decodedData.toChainId
263
- ? decodedData.toChainId.toString()
264
- : null,
265
- bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
266
- };
267
- break;
268
- case "swap":
269
- payload = {
270
- type,
271
- buyAmount: toBN(decodedData.buyAmount).toFixed(),
272
- sellAmount: toBN(decodedData.sellAmount).toFixed(),
273
- buyToken: decodedData.buyToken,
274
- sellToken: decodedData.sellToken,
275
- receiver: decodedData.receiver,
276
- protocol: utils.parseBytes32String(decodedData?.protocol || ""),
277
- };
278
- break;
279
- case "upgrade":
280
- payload = {
281
- type,
282
- version: utils.parseBytes32String(decodedData?.version || ""),
283
- walletImpl: decodedData?.walletImpl,
284
- };
285
- break;
286
- case "gas-topup":
287
- payload = {
288
- type,
289
- amount: toBN(decodedData.amount).toFixed(),
290
- token: decodedData.token,
291
- onBehalf: decodedData.onBehalf,
292
- };
293
- break;
294
- case "dapp":
295
- payload = {
296
- type,
297
- name: decodedData?.name,
298
- url: decodedData?.url,
299
- };
300
- break;
301
- case "deploy":
302
- payload = {
303
- type,
304
- };
305
-
306
- case "permit2":
307
- payload = {
308
- type,
309
- token: decodedData.token,
310
- spender: decodedData.spender,
311
- amount: toBN(decodedData.amount).toFixed(),
312
- expiration: decodedData.expiration,
313
- };
314
-
315
- break;
316
- }
317
382
 
383
+ const typesPayload: IPayload = {
384
+ "transfer": (data, type) => ({
385
+ type,
386
+ token: data.token,
387
+ amount: toBN(data.amount).toFixed(),
388
+ receiver: data.receiver,
389
+ }),
390
+ "bridge": (data, type) => ({
391
+ type,
392
+ amount: toBN(data.amount).toFixed(),
393
+ receiver: data.receiver,
394
+ toToken: data.toToken,
395
+ fromToken: data.fromToken,
396
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
397
+ bridgeFee: toBN(data.bridgeFee).toFixed(),
398
+ }),
399
+ "swap": (data, type) => ({
400
+ type,
401
+ buyAmount: toBN(data.buyAmount).toFixed(),
402
+ sellAmount: toBN(data.sellAmount).toFixed(),
403
+ buyToken: data.buyToken,
404
+ sellToken: data.sellToken,
405
+ receiver: data.receiver,
406
+ protocol: utils.parseBytes32String(data.protocol || ""),
407
+ }),
408
+ "upgrade": (data, type) => ({
409
+ type,
410
+ version: utils.parseBytes32String(data.version || ""),
411
+ walletImpl: data.walletImpl,
412
+ }),
413
+ "gas-topup": (data, type) => ({
414
+ type,
415
+ amount: toBN(data.amount).toFixed(),
416
+ token: data.token,
417
+ onBehalf: data.onBehalf,
418
+ }),
419
+ "dapp": (data, type) => ({
420
+ type,
421
+ name: data.name,
422
+ url: data.url,
423
+ }),
424
+ "deploy": (data, type) => ({
425
+ type,
426
+ }),
427
+ "permit2": (data, type) => ({
428
+ type,
429
+ token: data.token,
430
+ spender: data.spender,
431
+ amount: toBN(data.amount).toFixed(),
432
+ expiration: data.expiration,
433
+ }),
434
+ "cross-transfer": (data, type) => ({
435
+ type,
436
+ fromToken: data.fromToken,
437
+ toToken: data.toToken,
438
+ toChainId: data.toChainId ? data.toChainId.toString() : null,
439
+ amount: toBN(data.amount).toFixed(),
440
+ receiver: data.receiver,
441
+ }),
442
+ "auth": (data) => ({
443
+ type: data.remove ? "remove-authority" : "add-authority",
444
+ address: data.address,
445
+ chainId: data.chainId ? data.chainId.toString() : null,
446
+ remove: data.remove,
447
+ }),
448
+ "instadapp-pro": (data, type) => ({
449
+ type,
450
+ castDetails: data.castDetails,
451
+ }),
452
+ "rejection": (data, type) => ({
453
+ type,
454
+ id: data.id,
455
+ }),
456
+ "add-signers": (data, type) => ({
457
+ type,
458
+ addresses: data.signers,
459
+ }),
460
+ "remove-signers": (data, type) => ({
461
+ type,
462
+ addresses: data.signers,
463
+ }),
464
+ "change-threshold": (data, type) => ({
465
+ type,
466
+ count: data.count,
467
+ })
468
+ };
469
+
470
+ const parseMetadata = (metadata: string) => {
471
+ const metadataArr = [];
472
+
473
+ const [decodedMultiMetadata = []] =
474
+ (ethers.utils.defaultAbiCoder.decode(
475
+ multiMetadataTypes,
476
+ metadata
477
+ ) as string[]) || [];
478
+
479
+ for (let metadata of decodedMultiMetadata) {
480
+ const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
481
+ metadataTypes,
482
+ metadata
483
+ );
484
+
485
+ const type = ethers.utils.parseBytes32String(
486
+ decodedMetadata.type
487
+ ) as keyof typeof actionMetadataTypes;
488
+
489
+ const decodedData = ethers.utils.defaultAbiCoder.decode(
490
+ actionMetadataTypes[type],
491
+ decodedMetadata.data
492
+ );
493
+
494
+ const payloadFunc = typesPayload[type]
495
+
496
+ if (payloadFunc) {
497
+ const payload = payloadFunc(decodedData, type)
318
498
  metadataArr.push(payload);
319
499
  }
320
500
 
321
- return metadataArr;
322
- } catch (e) {
323
- console.log(e);
324
- return null;
325
501
  }
502
+
503
+ return metadataArr;
504
+ };
505
+
506
+
507
+
508
+ /**
509
+ * Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
510
+ * @param {string} txType - The input sentence to modify
511
+ *
512
+ * @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
513
+ */
514
+ export const formatTxType = (txType: string) => {
515
+ const finalSentence = txType
516
+ .replace("-", " ")
517
+ .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
518
+
519
+ return finalSentence;
326
520
  };