wagmi-extended 1.1.8 → 2.0.1

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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/fetch-functions/erc20/fetchAllowanceX.d.ts +4 -0
  3. package/dist/fetch-functions/erc20/fetchBalanceOfX.d.ts +4 -0
  4. package/dist/fetch-functions/erc20/fetchERC20DataX.d.ts +18 -0
  5. package/dist/fetch-functions/erc20/fetchNameX.d.ts +4 -0
  6. package/dist/fetch-functions/erc20/fetchSymbolX.d.ts +4 -0
  7. package/dist/fetch-functions/erc20/fetchTotalSupplyX.d.ts +4 -0
  8. package/dist/fetch-functions/erc4626/fetchERC4626AssetX.d.ts +4 -0
  9. package/dist/fetch-functions/erc4626/fetchERC4626ConvertToAssetsX.d.ts +4 -0
  10. package/dist/fetch-functions/erc4626/fetchERC4626ConvertToSharesX.d.ts +4 -0
  11. package/dist/fetch-functions/erc4626/fetchERC4626DataX.d.ts +24 -0
  12. package/dist/fetch-functions/erc4626/fetchERC4626MaxDepositX.d.ts +4 -0
  13. package/dist/fetch-functions/erc4626/fetchERC4626MaxMintX.d.ts +4 -0
  14. package/dist/fetch-functions/erc4626/fetchERC4626MaxRedeemX.d.ts +4 -0
  15. package/dist/fetch-functions/erc4626/fetchERC4626MaxWithdrawX.d.ts +4 -0
  16. package/dist/fetch-functions/erc4626/fetchERC4626TotalAssetsX.d.ts +4 -0
  17. package/dist/hooks/{useContractWriteX.d.ts → mutations/useContractWriteX.d.ts} +40 -35
  18. package/dist/hooks/{useHandleTransactionMutationX.d.ts → mutations/useHandleTransactionMutationX.d.ts} +8 -1
  19. package/dist/hooks/{useSendTransactionX.d.ts → mutations/useSendTransactionX.d.ts} +14 -13
  20. package/dist/hooks/queries/useERC20Data.d.ts +22 -0
  21. package/dist/hooks/queries/useFetchERC4626DataX.d.ts +28 -0
  22. package/dist/hooks/{useTokenX.d.ts → queries/useTokenX.d.ts} +18 -18
  23. package/dist/index.cjs.js +348 -114
  24. package/dist/index.cjs.js.map +1 -1
  25. package/dist/index.d.ts +16 -5
  26. package/dist/index.esm.js +339 -116
  27. package/dist/index.esm.js.map +1 -1
  28. package/dist/query-config/index.d.ts +20 -2
  29. package/dist/utils/ensureClientAndConfig.d.ts +6 -0
  30. package/package.json +1 -1
  31. package/src/fetch-functions/erc20/fetchAllowanceX.ts +31 -0
  32. package/src/fetch-functions/erc20/fetchBalanceOfX.ts +28 -0
  33. package/src/fetch-functions/erc20/fetchERC20DataX.ts +52 -0
  34. package/src/fetch-functions/erc20/fetchNameX.ts +26 -0
  35. package/src/fetch-functions/erc20/fetchSymbolX.ts +26 -0
  36. package/src/fetch-functions/erc20/fetchTotalSupplyX.ts +26 -0
  37. package/src/fetch-functions/erc4626/fetchERC4626AssetX.ts +25 -0
  38. package/src/fetch-functions/erc4626/fetchERC4626ConvertToAssetsX.ts +27 -0
  39. package/src/fetch-functions/erc4626/fetchERC4626ConvertToSharesX.ts +27 -0
  40. package/src/fetch-functions/erc4626/fetchERC4626DataX.ts +60 -0
  41. package/src/fetch-functions/erc4626/fetchERC4626MaxDepositX.ts +27 -0
  42. package/src/fetch-functions/erc4626/fetchERC4626MaxMintX.ts +27 -0
  43. package/src/fetch-functions/erc4626/fetchERC4626MaxRedeemX.ts +27 -0
  44. package/src/fetch-functions/erc4626/fetchERC4626MaxWithdrawX.ts +27 -0
  45. package/src/fetch-functions/erc4626/fetchERC4626TotalAssetsX.ts +25 -0
  46. package/src/fetch-functions/fetchTokenX.ts +16 -30
  47. package/src/hooks/{useContractWriteX.ts → mutations/useContractWriteX.ts} +32 -12
  48. package/src/hooks/{useERC20ApproveX.ts → mutations/useERC20ApproveX.ts} +1 -1
  49. package/src/hooks/{useHandleTransactionMutationX.ts → mutations/useHandleTransactionMutationX.ts} +30 -4
  50. package/src/hooks/{useSendTransactionX.ts → mutations/useSendTransactionX.ts} +36 -3
  51. package/src/hooks/queries/useERC20Data.ts +40 -0
  52. package/src/hooks/{useFetchAssetAllowanceX.ts → queries/useFetchAssetAllowanceX.ts} +6 -4
  53. package/src/hooks/queries/useFetchERC4626DataX.ts +39 -0
  54. package/src/hooks/{useTokenX.ts → queries/useTokenX.ts} +1 -1
  55. package/src/index.ts +16 -5
  56. package/src/query-config/index.ts +13 -3
  57. package/src/utils/ensureClientAndConfig.ts +18 -0
  58. package/dist/fetch-functions/fetchAllowanceX.d.ts +0 -2
  59. package/src/fetch-functions/fetchAllowanceX.ts +0 -22
  60. /package/dist/hooks/{useERC20ApproveX.d.ts → mutations/useERC20ApproveX.d.ts} +0 -0
  61. /package/dist/hooks/{useInvalidateQueries.d.ts → mutations/useInvalidateQueries.d.ts} +0 -0
  62. /package/dist/hooks/{useFetchAssetAllowanceX.d.ts → queries/useFetchAssetAllowanceX.d.ts} +0 -0
  63. /package/src/hooks/{useInvalidateQueries.ts → mutations/useInvalidateQueries.ts} +0 -0
package/dist/index.esm.js CHANGED
@@ -1,11 +1,24 @@
1
- import { useConfig, useWriteContract, useSendTransaction, useAccount } from 'wagmi';
1
+ import { useConfig, usePublicClient, useWriteContract, useSendTransaction, useAccount } from 'wagmi';
2
2
  import { waitForTransactionReceipt } from 'wagmi/actions';
3
3
  import { useState, useEffect } from 'react';
4
- import { ContractFunctionRevertedError, erc20Abi, maxUint256, zeroAddress } from 'viem';
5
4
  import { useQueryClient, useQuery } from '@tanstack/react-query';
6
- import { readContract } from 'viem/actions';
5
+ import { ContractFunctionRevertedError, erc20Abi, maxUint256, zeroAddress, erc4626Abi } from 'viem';
7
6
  import { readContractQueryOptions } from 'wagmi/query';
8
7
 
8
+ /**
9
+ * Hook to invalidate multiple queries in the React Query cache.
10
+ *
11
+ * @returns An object with the invalidateMany function.
12
+ */
13
+ function useInvalidateQueries() {
14
+ const queryClient = useQueryClient();
15
+ const invalidateMany = async (queries) => {
16
+ const promises = queries.map((queryKey) => queryClient.invalidateQueries({ queryKey }));
17
+ await Promise.all(promises);
18
+ };
19
+ return { invalidateMany };
20
+ }
21
+
9
22
  /**
10
23
  * Default error mapping that contains a set of error identifiers mapped to user-friendly error messages.
11
24
  */
@@ -89,20 +102,6 @@ const getParsedErrorX = (error) => {
89
102
  return message;
90
103
  };
91
104
 
92
- /**
93
- * Hook to invalidate multiple queries in the React Query cache.
94
- *
95
- * @returns An object with the invalidateMany function.
96
- */
97
- function useInvalidateQueries() {
98
- const queryClient = useQueryClient();
99
- const invalidateMany = async (queries) => {
100
- const promises = queries.map((queryKey) => queryClient.invalidateQueries({ queryKey }));
101
- await Promise.all(promises);
102
- };
103
- return { invalidateMany };
104
- }
105
-
106
105
  /**
107
106
  * Custom hook to handle transaction mutations.
108
107
  *
@@ -110,6 +109,7 @@ function useInvalidateQueries() {
110
109
  */
111
110
  function useHandleTransactionMutationX({ settings, }) {
112
111
  const wagmiConfig = useConfig();
112
+ const queryClient = useQueryClient();
113
113
  const { invalidateMany } = useInvalidateQueries();
114
114
  const [isPending, setIsPending] = useState(false);
115
115
  const [errorMessage, setErrorMessage] = useState(undefined);
@@ -134,10 +134,21 @@ function useHandleTransactionMutationX({ settings, }) {
134
134
  throw new Error("Execution reverted.");
135
135
  }
136
136
  // 3. invalidate queries
137
- if (settings === null || settings === void 0 ? void 0 : settings.queriesToInvalidate)
138
- await invalidateMany(settings === null || settings === void 0 ? void 0 : settings.queriesToInvalidate);
137
+ const { queriesToInvalidate, invalidatePredicate } = settings || {};
138
+ if (invalidatePredicate) {
139
+ // 1) predicate-based
140
+ await queryClient.invalidateQueries({
141
+ predicate: invalidatePredicate,
142
+ });
143
+ }
144
+ if (queriesToInvalidate) {
145
+ // 2) explicit key list
146
+ await invalidateMany(queriesToInvalidate);
147
+ }
139
148
  // 4. call onSuccess callback
140
149
  (_a = settings === null || settings === void 0 ? void 0 : settings.onSuccess) === null || _a === void 0 ? void 0 : _a.call(settings, txHash);
150
+ if (settings === null || settings === void 0 ? void 0 : settings.onSuccessAsync)
151
+ await settings.onSuccessAsync(txHash);
141
152
  if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogging)) {
142
153
  // 5. log result
143
154
  // eslint-disable-next-line no-console
@@ -157,11 +168,15 @@ function useHandleTransactionMutationX({ settings, }) {
157
168
  setErrorMessage(parsedError);
158
169
  // 3. call callback
159
170
  (_b = settings === null || settings === void 0 ? void 0 : settings.onError) === null || _b === void 0 ? void 0 : _b.call(settings, error);
171
+ if (settings === null || settings === void 0 ? void 0 : settings.onErrorAsync)
172
+ await settings.onErrorAsync(error);
160
173
  }
161
174
  finally {
162
175
  setIsPending(false);
163
176
  // 1. call callback
164
177
  (_c = settings === null || settings === void 0 ? void 0 : settings.onSettled) === null || _c === void 0 ? void 0 : _c.call(settings);
178
+ if (settings === null || settings === void 0 ? void 0 : settings.onSettledAsync)
179
+ await settings.onSettledAsync();
165
180
  }
166
181
  return undefined;
167
182
  };
@@ -233,20 +248,33 @@ function useHandleTransactionMutationX({ settings, }) {
233
248
  * }
234
249
  */
235
250
  function useContractWriteX(settings) {
236
- const { isPending, errorMessage, onMutate, onSettled } = useHandleTransactionMutationX({
237
- settings,
238
- });
239
- const { writeContractAsync, ...rest } = useWriteContract({
240
- mutation: {
241
- onMutate,
242
- onSettled,
243
- },
251
+ const publicClient = usePublicClient();
252
+ const { isPending, errorMessage, onMutate, onSettled } = useHandleTransactionMutationX({ settings });
253
+ // Underlying Wagmi write hook:
254
+ const wagmiWrite = useWriteContract({
255
+ mutation: { onMutate, onSettled },
244
256
  });
257
+ async function simulateAsyncAndWriteContract(params) {
258
+ // 0) signal start
259
+ onMutate();
260
+ try {
261
+ // 1) optional dry-run
262
+ const { chain, ...others } = params;
263
+ await (publicClient === null || publicClient === void 0 ? void 0 : publicClient.simulateContract({
264
+ ...others,
265
+ ...(chain != null ? { chain } : {}),
266
+ }));
267
+ wagmiWrite.writeContract(params);
268
+ }
269
+ catch (err) {
270
+ await onSettled(undefined, err, params);
271
+ }
272
+ }
245
273
  return {
246
- ...rest,
274
+ ...wagmiWrite,
275
+ simulateAsyncAndWriteContract,
247
276
  isPending,
248
277
  errorMessage,
249
- writeContractAsync,
250
278
  };
251
279
  }
252
280
 
@@ -297,44 +325,135 @@ function useContractWriteX(settings) {
297
325
  * }
298
326
  */
299
327
  function useSendTransactionX(settings) {
328
+ const publicClient = usePublicClient();
300
329
  const { isPending, errorMessage, onMutate, onSettled } = useHandleTransactionMutationX({
301
330
  settings,
302
331
  });
303
- const { sendTransactionAsync, ...rest } = useSendTransaction({
332
+ const { sendTransaction, ...rest } = useSendTransaction({
304
333
  mutation: {
305
334
  onMutate,
306
335
  onSettled,
307
336
  },
308
337
  });
338
+ /**
339
+ * Wraps sendTransaction with an optional simulation.
340
+ */
341
+ async function simulateAsyncAndSendTransaction(params, simulationParams) {
342
+ var _a;
343
+ onMutate();
344
+ try {
345
+ if (params.to) {
346
+ //simulate!
347
+ await (publicClient === null || publicClient === void 0 ? void 0 : publicClient.simulateContract({
348
+ address: params.to,
349
+ abi: simulationParams.abi,
350
+ functionName: simulationParams.functionName,
351
+ args: (_a = simulationParams.args) !== null && _a !== void 0 ? _a : [],
352
+ account: params.account,
353
+ ...(simulationParams.chain != null
354
+ ? { chain: simulationParams.chain }
355
+ : {}),
356
+ }));
357
+ }
358
+ // actual send!
359
+ await sendTransaction(params);
360
+ }
361
+ catch (err) {
362
+ await onSettled(undefined, err, params);
363
+ }
364
+ }
309
365
  return {
310
366
  ...rest,
311
367
  isPending,
312
368
  errorMessage,
313
- sendTransactionAsync,
369
+ simulateAsyncAndSendTransaction,
314
370
  };
315
371
  }
316
372
 
317
373
  const queryConfig = {
318
- metadataQueryConfig: {
319
- staleTime: Infinity,
374
+ metaDataQuery: {
375
+ staleTime: Number.POSITIVE_INFINITY,
376
+ meta: { category: "metadata" },
320
377
  },
321
- sensitiveDataQueryConfig: {
378
+ lowSensitiveQuery: {
322
379
  staleTime: 60000,
380
+ meta: { category: "lowSensitive" },
323
381
  },
324
- };
382
+ semiSensitiveQuery: {
383
+ staleTime: 180000,
384
+ meta: { category: "semiSensitive" },
385
+ }};
325
386
 
326
- const fetchAllowance = async (asset, spender, userAddress, config) => {
327
- const allowance = await readContract(config, {
328
- address: asset,
329
- abi: erc20Abi,
330
- functionName: "allowance",
331
- args: [userAddress, spender],
332
- });
333
- if (allowance == null) {
334
- throw new Error("Failed to fetch token data or allowance");
387
+ // You can adjust the type for wagmiConfig to match your needs.
388
+ let defaultQueryClient = null;
389
+ let defaultWagmiConfig = null;
390
+ /**
391
+ * Sets the default configuration values.
392
+ *
393
+ * @param queryClient - The default QueryClient instance.
394
+ * @param wagmiConfig - The default Wagmi configuration.
395
+ * @example
396
+ * //In your application initialization (e.g., index.tsx or App.tsx):
397
+ * import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
398
+ * import { wagmiConfig } from "/path/to/wagmi-config";
399
+ * import { setDefaults } from "wagmi-extended";
400
+ *
401
+ * const queryClient = new QueryClient();
402
+ *
403
+ * //Set defaults for the extended library functions.
404
+ * setDefaults(queryClient, wagmiConfig);
405
+ *
406
+ * //Now helper functions like fetchTokenX can use these defaults if no explicit parameters are provided.
407
+ */
408
+ function setDefaults(queryClient, wagmiConfig) {
409
+ defaultQueryClient = queryClient;
410
+ defaultWagmiConfig = wagmiConfig;
411
+ }
412
+ /**
413
+ * Retrieves the currently set default configurations.
414
+ *
415
+ * @throws Will throw an error if defaults are not initialized.
416
+ * @returns An object containing the default queryClient and wagmiConfig.
417
+ *
418
+ * @example
419
+ * // Usage in a helper function:
420
+ * import { getDefaults } from "wagmi-extended";
421
+ *
422
+ * function exampleFunction() {
423
+ * const { queryClient, wagmiConfig } = getDefaults();
424
+ * // Use queryClient and wagmiConfig as needed...
425
+ * }
426
+ */
427
+ function getDefaults() {
428
+ if (!defaultQueryClient || !defaultWagmiConfig) {
429
+ throw new Error("Default configuration not set. Please call setDefaults() first.");
430
+ }
431
+ return { queryClient: defaultQueryClient, wagmiConfig: defaultWagmiConfig };
432
+ }
433
+
434
+ function ensureClientAndConfig(queryClient, wagmiConfig) {
435
+ if (!queryClient || !wagmiConfig) {
436
+ ({ queryClient, wagmiConfig } = getDefaults());
437
+ }
438
+ if (!queryClient || !wagmiConfig) {
439
+ throw new Error("Could not find queryClient or wagmiConfig; pass them in or setDefaults() first");
335
440
  }
441
+ return { queryClient, wagmiConfig };
442
+ }
443
+
444
+ async function fetchAllowanceX(asset, spender, user, queryClient, wagmiConfig) {
445
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
446
+ const allowance = await queryClient.fetchQuery({
447
+ ...readContractQueryOptions(wagmiConfig, {
448
+ address: asset,
449
+ abi: erc20Abi,
450
+ functionName: "allowance",
451
+ args: [user, spender],
452
+ }),
453
+ ...queryConfig.metaDataQuery,
454
+ });
336
455
  return allowance;
337
- };
456
+ }
338
457
 
339
458
  const HookFetchAssetAllowanceQK = (asset, spender, userAddress) => ["HookFetchAllowance", asset, spender, userAddress];
340
459
  /**
@@ -364,12 +483,13 @@ const HookFetchAssetAllowanceQK = (asset, spender, userAddress) => ["HookFetchAl
364
483
  */
365
484
  const useFetchAssetAllowanceX = ({ asset, spender, }) => {
366
485
  const config = useConfig();
486
+ const queryClient = useQueryClient();
367
487
  const { address: userAddress } = useAccount();
368
488
  const { data, ...rest } = useQuery({
369
489
  queryKey: HookFetchAssetAllowanceQK(asset, spender, userAddress),
370
- queryFn: () => fetchAllowance(asset, spender, userAddress, config),
490
+ queryFn: () => fetchAllowanceX(asset, spender, userAddress, queryClient, config),
371
491
  enabled: Boolean(asset) && Boolean(spender) && Boolean(userAddress),
372
- ...queryConfig.sensitiveDataQueryConfig,
492
+ ...queryConfig.lowSensitiveQuery,
373
493
  });
374
494
  return {
375
495
  ...rest,
@@ -467,65 +587,13 @@ const useERC20ApproveX = (tokenAddress, spenderAddress, amount, approveMax) => {
467
587
  };
468
588
  };
469
589
 
470
- // You can adjust the type for wagmiConfig to match your needs.
471
- let defaultQueryClient = null;
472
- let defaultWagmiConfig = null;
473
- /**
474
- * Sets the default configuration values.
475
- *
476
- * @param queryClient - The default QueryClient instance.
477
- * @param wagmiConfig - The default Wagmi configuration.
478
- * @example
479
- * //In your application initialization (e.g., index.tsx or App.tsx):
480
- * import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
481
- * import { wagmiConfig } from "/path/to/wagmi-config";
482
- * import { setDefaults } from "wagmi-extended";
483
- *
484
- * const queryClient = new QueryClient();
485
- *
486
- * //Set defaults for the extended library functions.
487
- * setDefaults(queryClient, wagmiConfig);
488
- *
489
- * //Now helper functions like fetchTokenX can use these defaults if no explicit parameters are provided.
490
- */
491
- function setDefaults(queryClient, wagmiConfig) {
492
- defaultQueryClient = queryClient;
493
- defaultWagmiConfig = wagmiConfig;
494
- }
495
- /**
496
- * Retrieves the currently set default configurations.
497
- *
498
- * @throws Will throw an error if defaults are not initialized.
499
- * @returns An object containing the default queryClient and wagmiConfig.
500
- *
501
- * @example
502
- * // Usage in a helper function:
503
- * import { getDefaults } from "wagmi-extended";
504
- *
505
- * function exampleFunction() {
506
- * const { queryClient, wagmiConfig } = getDefaults();
507
- * // Use queryClient and wagmiConfig as needed...
508
- * }
509
- */
510
- function getDefaults() {
511
- if (!defaultQueryClient || !defaultWagmiConfig) {
512
- throw new Error("Default configuration not set. Please call setDefaults() first.");
513
- }
514
- return { queryClient: defaultQueryClient, wagmiConfig: defaultWagmiConfig };
515
- }
516
-
517
590
  const EthTokenData = {
518
591
  symbol: "ETH",
519
592
  decimals: 18,
520
593
  name: "Ethereum",
521
594
  };
522
595
  async function fetchDecimalsX(token, queryClient, wagmiConfig) {
523
- if (!queryClient || !wagmiConfig) {
524
- ({ queryClient, wagmiConfig } = getDefaults());
525
- }
526
- if (!queryClient || !wagmiConfig) {
527
- throw new Error("Could not find queryClient or wagmiConfig, either pass them as arguments or set them using setDefaults()");
528
- }
596
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
529
597
  if (token === zeroAddress)
530
598
  return EthTokenData.decimals;
531
599
  const decimals = await queryClient.fetchQuery({
@@ -534,17 +602,12 @@ async function fetchDecimalsX(token, queryClient, wagmiConfig) {
534
602
  abi: erc20Abi,
535
603
  functionName: "decimals",
536
604
  }),
537
- ...queryConfig.metadataQueryConfig,
605
+ ...queryConfig.metaDataQuery,
538
606
  });
539
607
  return decimals;
540
608
  }
541
609
  async function fetchSymbolX(token, queryClient, wagmiConfig) {
542
- if (!queryClient || !wagmiConfig) {
543
- ({ queryClient, wagmiConfig } = getDefaults());
544
- }
545
- if (!queryClient || !wagmiConfig) {
546
- throw new Error("Could not find queryClient or wagmiConfig, either pass them as arguments or set them using setDefaults()");
547
- }
610
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
548
611
  if (token === zeroAddress)
549
612
  return EthTokenData.symbol;
550
613
  const symbol = await queryClient.fetchQuery({
@@ -553,26 +616,21 @@ async function fetchSymbolX(token, queryClient, wagmiConfig) {
553
616
  abi: erc20Abi,
554
617
  functionName: "symbol",
555
618
  }),
556
- ...queryConfig.metadataQueryConfig,
619
+ ...queryConfig.metaDataQuery,
557
620
  });
558
621
  return symbol;
559
622
  }
560
623
  async function fetchNameX(token, queryClient, wagmiConfig) {
561
624
  if (token === zeroAddress)
562
625
  return EthTokenData.name;
563
- if (!queryClient || !wagmiConfig) {
564
- ({ queryClient, wagmiConfig } = getDefaults());
565
- }
566
- if (!queryClient || !wagmiConfig) {
567
- throw new Error("Could not find queryClient or wagmiConfig, either pass them as arguments or set them using setDefaults()");
568
- }
626
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
569
627
  const name = await queryClient.fetchQuery({
570
628
  ...readContractQueryOptions(wagmiConfig, {
571
629
  address: token,
572
630
  abi: erc20Abi,
573
631
  functionName: "name",
574
632
  }),
575
- ...queryConfig.metadataQueryConfig,
633
+ ...queryConfig.metaDataQuery,
576
634
  });
577
635
  return name;
578
636
  }
@@ -661,5 +719,170 @@ const useTokenX = (asset) => {
661
719
  };
662
720
  };
663
721
 
664
- export { EthTokenData, HookFetchTokenQK, fetchDecimalsX, fetchNameX, fetchSymbolX, fetchTokenX, getDefaults, getErrorMapping, getParsedErrorX, resetErrorMapping, setDefaults, setErrorMapping, useContractWriteX, useERC20ApproveX, useFetchAssetAllowanceX, useSendTransactionX, useTokenX };
722
+ async function fetchBalanceOfX(asset, user, queryClient, wagmiConfig) {
723
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
724
+ return await queryClient.fetchQuery({
725
+ ...readContractQueryOptions(wagmiConfig, {
726
+ address: asset,
727
+ abi: erc20Abi,
728
+ functionName: "balanceOf",
729
+ args: [user],
730
+ }),
731
+ ...queryConfig.lowSensitiveQuery,
732
+ });
733
+ }
734
+
735
+ async function fetchTotalSupplyX(asset, queryClient, wagmiConfig) {
736
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
737
+ return await queryClient.fetchQuery({
738
+ ...readContractQueryOptions(wagmiConfig, {
739
+ address: asset,
740
+ abi: erc20Abi,
741
+ functionName: "totalSupply",
742
+ }),
743
+ ...queryConfig.semiSensitiveQuery,
744
+ });
745
+ }
746
+
747
+ /**
748
+ * Fetches the full ERC-20 “summary” for a given vault and user context.
749
+ */
750
+ async function fetchERC20DataX(address, user, spender, queryClient, wagmiConfig) {
751
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
752
+ const [name, symbol, decimals, allowance, balanceOf, asset] = await Promise.all([
753
+ fetchNameX(address, queryClient, wagmiConfig),
754
+ fetchSymbolX(address, queryClient, wagmiConfig),
755
+ fetchDecimalsX(address, queryClient, wagmiConfig),
756
+ spender && user
757
+ ? fetchAllowanceX(address, spender, user, queryClient, wagmiConfig)
758
+ : undefined,
759
+ user
760
+ ? fetchBalanceOfX(address, user, queryClient, wagmiConfig)
761
+ : undefined,
762
+ fetchTotalSupplyX(address, queryClient, wagmiConfig),
763
+ ]);
764
+ return {
765
+ name,
766
+ symbol,
767
+ decimals,
768
+ allowance,
769
+ balanceOf,
770
+ asset,
771
+ address,
772
+ user,
773
+ spender,
774
+ };
775
+ }
776
+
777
+ async function fetchERC4626AssetX(vault, queryClient, wagmiConfig) {
778
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
779
+ return queryClient.fetchQuery({
780
+ ...readContractQueryOptions(wagmiConfig, {
781
+ address: vault,
782
+ abi: erc4626Abi,
783
+ functionName: "asset",
784
+ }),
785
+ ...queryConfig.metaDataQuery,
786
+ });
787
+ }
788
+
789
+ async function fetchERC4626TotalAssetsX(vault, queryClient, wagmiConfig) {
790
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
791
+ return queryClient.fetchQuery({
792
+ ...readContractQueryOptions(wagmiConfig, {
793
+ address: vault,
794
+ abi: erc4626Abi,
795
+ functionName: "totalAssets",
796
+ }),
797
+ ...queryConfig.semiSensitiveQuery,
798
+ });
799
+ }
800
+
801
+ async function fetchERC4626MaxDepositX(vault, caller, queryClient, wagmiConfig) {
802
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
803
+ return queryClient.fetchQuery({
804
+ ...readContractQueryOptions(wagmiConfig, {
805
+ address: vault,
806
+ abi: erc4626Abi,
807
+ functionName: "maxDeposit",
808
+ args: [caller],
809
+ }),
810
+ ...queryConfig.semiSensitiveQuery,
811
+ });
812
+ }
813
+
814
+ async function fetchERC4626MaxMintX(vault, caller, queryClient, wagmiConfig) {
815
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
816
+ return queryClient.fetchQuery({
817
+ ...readContractQueryOptions(wagmiConfig, {
818
+ address: vault,
819
+ abi: erc4626Abi,
820
+ functionName: "maxMint",
821
+ args: [caller],
822
+ }),
823
+ ...queryConfig.semiSensitiveQuery,
824
+ });
825
+ }
826
+
827
+ async function fetchERC4626MaxRedeemX(vault, owner, queryClient, wagmiConfig) {
828
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
829
+ return queryClient.fetchQuery({
830
+ ...readContractQueryOptions(wagmiConfig, {
831
+ address: vault,
832
+ abi: erc4626Abi,
833
+ functionName: "maxRedeem",
834
+ args: [owner],
835
+ }),
836
+ ...queryConfig.semiSensitiveQuery,
837
+ });
838
+ }
839
+
840
+ async function fetchERC4626MaxWithdrawX(vault, owner, queryClient, wagmiConfig) {
841
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
842
+ return queryClient.fetchQuery({
843
+ ...readContractQueryOptions(wagmiConfig, {
844
+ address: vault,
845
+ abi: erc4626Abi,
846
+ functionName: "maxWithdraw",
847
+ args: [owner],
848
+ }),
849
+ ...queryConfig.semiSensitiveQuery,
850
+ });
851
+ }
852
+
853
+ /**
854
+ * Fetches the full ERC-4626 “summary” for a given vault and user context.
855
+ */
856
+ async function fetchERC4626DataX(vault, user, spender, queryClient, wagmiConfig) {
857
+ ({ queryClient, wagmiConfig } = ensureClientAndConfig(queryClient, wagmiConfig));
858
+ const [erc20Data, maxDeposit, maxMint, maxRedeem, maxWithdraw] = await Promise.all([
859
+ fetchERC20DataX(vault, user, spender, queryClient, wagmiConfig),
860
+ fetchERC4626AssetX(vault, queryClient, wagmiConfig),
861
+ fetchERC4626TotalAssetsX(vault, queryClient, wagmiConfig),
862
+ user
863
+ ? fetchERC4626MaxDepositX(vault, user, queryClient, wagmiConfig)
864
+ : undefined,
865
+ user
866
+ ? fetchERC4626MaxMintX(vault, user, queryClient, wagmiConfig)
867
+ : undefined,
868
+ user
869
+ ? fetchERC4626MaxRedeemX(vault, user, queryClient, wagmiConfig)
870
+ : undefined,
871
+ user
872
+ ? fetchERC4626MaxWithdrawX(vault, user, queryClient, wagmiConfig)
873
+ : undefined,
874
+ ]);
875
+ return {
876
+ ...erc20Data,
877
+ maxDeposit,
878
+ maxMint,
879
+ maxRedeem,
880
+ maxWithdraw,
881
+ vault,
882
+ owner: user,
883
+ spender,
884
+ };
885
+ }
886
+
887
+ export { EthTokenData, HookFetchTokenQK, fetchAllowanceX, fetchBalanceOfX, fetchDecimalsX, fetchERC20DataX, fetchERC4626AssetX, fetchERC4626DataX, fetchERC4626MaxDepositX, fetchERC4626MaxMintX, fetchERC4626MaxRedeemX, fetchERC4626MaxWithdrawX, fetchERC4626TotalAssetsX, fetchNameX, fetchSymbolX, fetchTokenX, fetchTotalSupplyX, getDefaults, getErrorMapping, getParsedErrorX, resetErrorMapping, setDefaults, setErrorMapping, useContractWriteX, useERC20ApproveX, useFetchAssetAllowanceX, useSendTransactionX, useTokenX };
665
888
  //# sourceMappingURL=index.esm.js.map