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

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 +1253 -149
  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 +856 -2
  69. package/contracts/MultisigForwarder.ts +859 -0
  70. package/contracts/factories/Forwarder__factory.ts +816 -16
  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 +316 -136
  81. package/utils/network.ts +155 -87
  82. package/utils/services.ts +21 -0
  83. package/utils/utils.d.ts +129 -105
@@ -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.e144f0f",
3
+ "version": "0.0.0-dev.e698742",
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,15 +1,35 @@
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",
12
31
  "address toToken",
32
+ "uint256 toChainId",
13
33
  "uint256 amount",
14
34
  "address receiver",
15
35
  ],
@@ -33,6 +53,7 @@ const actionMetadataTypes = {
33
53
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
34
54
  upgrade: ["bytes32 version", "address walletImpl"],
35
55
  dapp: ["string name", "string url"],
56
+ auth: ["address address", "uint256 chainId", "bool remove"],
36
57
  deploy: [],
37
58
  permit2: [
38
59
  "address token",
@@ -40,6 +61,11 @@ const actionMetadataTypes = {
40
61
  "uint160 amount",
41
62
  "uint48 expiration",
42
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'],
43
69
  };
44
70
 
45
71
  const encodeMetadata = (props: MetadataProps) => {
@@ -60,7 +86,7 @@ export const encodeDappMetadata = (
60
86
  );
61
87
 
62
88
  const data = encodeMetadata({
63
- type: "dapp",
89
+ type: MetadataEnums.dapp,
64
90
  encodedData,
65
91
  });
66
92
 
@@ -77,7 +103,21 @@ export const encodeTransferMetadata = (
77
103
  );
78
104
 
79
105
  const data = encodeMetadata({
80
- 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,
81
121
  encodedData,
82
122
  });
83
123
 
@@ -85,16 +125,39 @@ export const encodeTransferMetadata = (
85
125
  };
86
126
 
87
127
  export const encodeCrossTransferMetadata = (
88
- params: CrossSendMetadatProps,
128
+ params: CrossSendMetadataProps,
89
129
  single = true
90
130
  ) => {
91
131
  const encodedData = ethers.utils.defaultAbiCoder.encode(
92
132
  actionMetadataTypes["cross-transfer"],
93
- [params.fromToken, params.toToken, params.amount, params.receiver]
133
+ [
134
+ params.fromToken,
135
+ params.toToken,
136
+ params.toChainId,
137
+ params.amount,
138
+ params.receiver,
139
+ ]
94
140
  );
95
141
 
96
142
  const data = encodeMetadata({
97
- type: "cross-transfer",
143
+ type: MetadataEnums["cross-transfer"],
144
+ encodedData,
145
+ });
146
+
147
+ return single ? encodeMultipleActions(data) : data;
148
+ };
149
+
150
+ export const encodeAuthMetadata = (
151
+ params: AuthMetadataProps,
152
+ single = true
153
+ ) => {
154
+ const encodedData = ethers.utils.defaultAbiCoder.encode(
155
+ actionMetadataTypes["auth"],
156
+ [params.address, params.chainId, params.remove]
157
+ );
158
+
159
+ const data = encodeMetadata({
160
+ type: MetadataEnums.auth,
98
161
  encodedData,
99
162
  });
100
163
 
@@ -103,7 +166,7 @@ export const encodeCrossTransferMetadata = (
103
166
 
104
167
  export const encodeDeployMetadata = (single = true) => {
105
168
  const data = encodeMetadata({
106
- type: "deploy",
169
+ type: MetadataEnums.deploy,
107
170
  encodedData: "0x",
108
171
  });
109
172
 
@@ -120,7 +183,7 @@ export const encodeWCSignMetadata = (
120
183
  );
121
184
 
122
185
  const data = encodeMetadata({
123
- type: "permit2",
186
+ type: MetadataEnums.permit2,
124
187
  encodedData,
125
188
  });
126
189
 
@@ -137,7 +200,7 @@ export const encodeUpgradeMetadata = (
137
200
  );
138
201
 
139
202
  const data = encodeMetadata({
140
- type: "upgrade",
203
+ type: MetadataEnums.upgrade,
141
204
  encodedData,
142
205
  });
143
206
 
@@ -161,7 +224,7 @@ export const encodeSwapMetadata = (
161
224
  );
162
225
 
163
226
  const data = encodeMetadata({
164
- type: "swap",
227
+ type: MetadataEnums.swap,
165
228
  encodedData,
166
229
  });
167
230
 
@@ -177,10 +240,8 @@ export const encodeTopupMetadata = (
177
240
  [params.amount, params.token, params.onBehalf]
178
241
  );
179
242
 
180
- console.log(params);
181
-
182
243
  const data = encodeMetadata({
183
- type: "gas-topup",
244
+ type: MetadataEnums["gas-topup"],
184
245
  encodedData,
185
246
  });
186
247
 
@@ -205,7 +266,58 @@ export const encodeBridgeMetadata = (
205
266
  );
206
267
 
207
268
  const data = encodeMetadata({
208
- 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"],
209
321
  encodedData,
210
322
  });
211
323
 
@@ -216,134 +328,202 @@ export const encodeMultipleActions = (...actionData: string[]) => {
216
328
  return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
217
329
  };
218
330
 
219
- 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) => {
220
343
  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
- }
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;
234
370
  } 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
- }
371
+ metadata = executeDataV2.params_.metadata;
244
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;
383
+ } else {
384
+ metadata = executeDataMultisig.params_.metadata;
385
+ }
386
+ }
245
387
 
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
- }
388
+ return metadata;
389
+ };
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
+ };
340
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)
341
507
  metadataArr.push(payload);
342
508
  }
343
509
 
344
- return metadataArr;
345
- } catch (e) {
346
- console.log(e);
347
- return null;
348
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;
349
529
  };