@instadapp/avocado-base 0.0.0-dev.b9e4c6c → 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 (59) hide show
  1. package/abi/forwarder.json +8 -8
  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 +4 -4
  50. package/contracts/factories/Forwarder__factory.ts +8 -8
  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/helper.ts +7 -0
  56. package/utils/metadata.ts +286 -146
  57. package/utils/network.ts +3 -3
  58. package/utils/services.ts +14 -0
  59. package/utils/utils.d.ts +38 -11
package/utils/metadata.ts CHANGED
@@ -5,7 +5,7 @@ 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
10
  "cross-transfer": [
11
11
  "address fromToken",
@@ -34,6 +34,7 @@ const actionMetadataTypes = {
34
34
  "gas-topup": ["uint256 amount", "address token", "address onBehalf"],
35
35
  upgrade: ["bytes32 version", "address walletImpl"],
36
36
  dapp: ["string name", "string url"],
37
+ auth: ["address address", "uint256 chainId", "bool remove"],
37
38
  deploy: [],
38
39
  permit2: [
39
40
  "address token",
@@ -41,6 +42,11 @@ const actionMetadataTypes = {
41
42
  "uint160 amount",
42
43
  "uint48 expiration",
43
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'],
44
50
  };
45
51
 
46
52
  const encodeMetadata = (props: MetadataProps) => {
@@ -85,6 +91,20 @@ export const encodeTransferMetadata = (
85
91
  return single ? encodeMultipleActions(data) : data;
86
92
  };
87
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
+
88
108
  export const encodeCrossTransferMetadata = (
89
109
  params: CrossSendMetadataProps,
90
110
  single = true
@@ -108,6 +128,23 @@ export const encodeCrossTransferMetadata = (
108
128
  return single ? encodeMultipleActions(data) : data;
109
129
  };
110
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
+
111
148
  export const encodeDeployMetadata = (single = true) => {
112
149
  const data = encodeMetadata({
113
150
  type: "deploy",
@@ -219,162 +256,265 @@ export const encodeBridgeMetadata = (
219
256
  return single ? encodeMultipleActions(data) : data;
220
257
  };
221
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
+
222
310
  export const encodeMultipleActions = (...actionData: string[]) => {
223
311
  return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
224
312
  };
225
313
 
226
- export const decodeMetadata = (data: string) => {
314
+ export const decodeData = (data: string) => {
227
315
  try {
228
- const iface = Forwarder__factory.createInterface();
229
- let metadata = "0x";
230
- let payload = {};
231
-
232
- if (!data) return payload;
233
-
234
- if (data.startsWith("0x18e7f485")) {
235
- const executeData = iface.decodeFunctionData("execute", data);
236
- if (executeData.metadata_ === "0x" || !executeData.metadata_) {
237
- return null;
238
- } else {
239
- metadata = executeData.metadata_;
240
- }
241
- } else if (data.startsWith("0x14f80a8d")) {
242
- const executeDataV2 = iface.decodeFunctionData("executeV2", data);
243
- if (
244
- executeDataV2.params_.metadata === "0x" ||
245
- !executeDataV2.params_.metadata
246
- ) {
247
- return null;
248
- } else {
249
- metadata = executeDataV2.params_.metadata;
250
- }
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;
251
341
  } else {
252
- const executeDataV3 = iface.decodeFunctionData("executeV3", data);
253
- if (
254
- executeDataV3.params_.metadata === "0x" ||
255
- !executeDataV3.params_.metadata
256
- ) {
257
- return null;
258
- } else {
259
- metadata = executeDataV3.params_.metadata;
260
- }
342
+ metadata = executeData.metadata_;
261
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;
374
+ } else {
375
+ metadata = executeDataMultisigV3.params_.metadata;
376
+ }
377
+ }
378
+
379
+ return metadata;
380
+ };
381
+
262
382
 
263
- const metadataArr = [];
264
-
265
- const [decodedMultiMetadata = []] =
266
- (ethers.utils.defaultAbiCoder.decode(
267
- multiMetadataTypes,
268
- metadata
269
- ) as string[]) || [];
270
-
271
- for (let metadata of decodedMultiMetadata) {
272
- const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
273
- metadataTypes,
274
- metadata
275
- );
276
-
277
- const type = ethers.utils.parseBytes32String(
278
- decodedMetadata.type
279
- ) as keyof typeof actionMetadataTypes;
280
-
281
- const decodedData = ethers.utils.defaultAbiCoder.decode(
282
- actionMetadataTypes[type],
283
- decodedMetadata.data
284
- );
285
-
286
- switch (type) {
287
- case "transfer":
288
- payload = {
289
- type,
290
- token: decodedData.token,
291
- amount: toBN(decodedData.amount).toFixed(),
292
- receiver: decodedData.receiver,
293
- };
294
- break;
295
- case "bridge":
296
- payload = {
297
- type,
298
- amount: toBN(decodedData.amount).toFixed(),
299
- receiver: decodedData.receiver,
300
- toToken: decodedData.toToken,
301
- fromToken: decodedData.fromToken,
302
- toChainId: decodedData.toChainId
303
- ? decodedData.toChainId.toString()
304
- : null,
305
- bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
306
- };
307
- break;
308
- case "swap":
309
- payload = {
310
- type,
311
- buyAmount: toBN(decodedData.buyAmount).toFixed(),
312
- sellAmount: toBN(decodedData.sellAmount).toFixed(),
313
- buyToken: decodedData.buyToken,
314
- sellToken: decodedData.sellToken,
315
- receiver: decodedData.receiver,
316
- protocol: utils.parseBytes32String(decodedData?.protocol || ""),
317
- };
318
- break;
319
- case "upgrade":
320
- payload = {
321
- type,
322
- version: utils.parseBytes32String(decodedData?.version || ""),
323
- walletImpl: decodedData?.walletImpl,
324
- };
325
- break;
326
- case "gas-topup":
327
- payload = {
328
- type,
329
- amount: toBN(decodedData.amount).toFixed(),
330
- token: decodedData.token,
331
- onBehalf: decodedData.onBehalf,
332
- };
333
- break;
334
- case "dapp":
335
- payload = {
336
- type,
337
- name: decodedData?.name,
338
- url: decodedData?.url,
339
- };
340
- break;
341
- case "deploy":
342
- payload = {
343
- type,
344
- };
345
- break;
346
-
347
- case "permit2":
348
- payload = {
349
- type,
350
- token: decodedData.token,
351
- spender: decodedData.spender,
352
- amount: toBN(decodedData.amount).toFixed(),
353
- expiration: decodedData.expiration,
354
- };
355
- break;
356
-
357
- case "cross-transfer":
358
- payload = {
359
- type,
360
- fromToken: decodedData.fromToken,
361
- toToken: decodedData.toToken,
362
- toChainId: decodedData.toChainId
363
- ? decodedData.toChainId.toString()
364
- : null,
365
- amount: toBN(decodedData.amount).toFixed(),
366
- receiver: decodedData.receiver,
367
- };
368
-
369
- break;
370
- }
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
+ };
371
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)
372
498
  metadataArr.push(payload);
373
499
  }
374
500
 
375
- return metadataArr;
376
- } catch (e) {
377
- console.log(e);
378
- return null;
379
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;
380
520
  };
package/utils/network.ts CHANGED
@@ -4,7 +4,7 @@ export const bridgeDisabledNetworks = [1101];
4
4
 
5
5
  export const networks: Network[] = [
6
6
  {
7
- name: "Mainnet",
7
+ name: "Ethereum",
8
8
  debankName: "eth",
9
9
  ankrName: "eth",
10
10
  zerionName: "ethereum",
@@ -114,7 +114,7 @@ export const networks: Network[] = [
114
114
  symbol: "AVAX",
115
115
  decimals: 18,
116
116
  },
117
- rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
117
+ rpcUrls: ["https://rpc.ankr.com/avalanche"],
118
118
  },
119
119
  },
120
120
  {
@@ -174,7 +174,7 @@ export const networks: Network[] = [
174
174
  },
175
175
  params: {
176
176
  chainName: "polygon zkEVM",
177
- rpcUrls: ["https://rpc.ankr.com/polygon_zkevm"],
177
+ rpcUrls: ["https://zkevm-rpc.com"],
178
178
 
179
179
  nativeCurrency: {
180
180
  name: "Ethereum",
@@ -0,0 +1,14 @@
1
+ export const fetchTokenByAddress = async (
2
+ address: string,
3
+ chainId: string | number
4
+ ) => {
5
+ if (!address || !chainId) return null;
6
+ const [token] = (await $fetch(`${blockQueryURL}/${chainId}/tokens`, {
7
+ params: {
8
+ sparkline: false,
9
+ "addresses[]": [address],
10
+ },
11
+ })) as ITokenPrice[];
12
+
13
+ return token;
14
+ };
package/utils/utils.d.ts CHANGED
@@ -13,6 +13,25 @@ type ChainId =
13
13
  | 63400;
14
14
 
15
15
  type ISlackMessageType = "danger" | "error" | "success" | "banner";
16
+ type MetadataTypes = "transfer"
17
+ | "bridge"
18
+ | "swap"
19
+ | "gas-topup"
20
+ | "upgrade"
21
+ | "dapp"
22
+ | "deploy"
23
+ | "permit2"
24
+ | "cross-transfer"
25
+ | "auth"
26
+ | "rejection"
27
+ | 'instadapp-pro'
28
+ | 'add-signers'
29
+ | 'remove-signers'
30
+ | 'change-threshold'
31
+
32
+ type PayloadFunction = (data: any, type: MetadataTypes) => any;
33
+
34
+ type IPayload = Record<MetadataTypes, PayloadFunction>;
16
35
 
17
36
  interface Network {
18
37
  name: string;
@@ -64,6 +83,12 @@ type CrossSendMetadataProps = {
64
83
  receiver: string;
65
84
  };
66
85
 
86
+ type AuthMetadataProps = {
87
+ address: string;
88
+ chainId: string;
89
+ remove: boolean;
90
+ };
91
+
67
92
  type UpgradeMetadataProps = {
68
93
  version: string;
69
94
  walletImpl: string;
@@ -95,17 +120,19 @@ type SwapMetadataProps = {
95
120
  };
96
121
 
97
122
  type MetadataProps = {
98
- type:
99
- | "transfer"
100
- | "bridge"
101
- | "swap"
102
- | "multi"
103
- | "gas-topup"
104
- | "upgrade"
105
- | "dapp"
106
- | "deploy"
107
- | "permit2"
108
- | "cross-transfer";
123
+ type: MetadataTypes,
109
124
  encodedData: string;
110
125
  version?: string;
111
126
  };
127
+
128
+ interface ITokenPrice {
129
+ address: string;
130
+ chain_id: string;
131
+ name: string;
132
+ symbol: string;
133
+ decimals: number;
134
+ logo_url: string;
135
+ price: string;
136
+ coingecko_id: string;
137
+ sparkline_price_7d: number[];
138
+ }