@instadapp/avocado-base 0.0.0-dev.e144f0f → 0.0.0-dev.e2f5814

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