wagmi-extended 1.1.7 → 2.0.0

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