@sodax/dapp-kit 0.0.1-rc.1 → 0.0.1-rc.11

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 (80) hide show
  1. package/README.md +15 -13
  2. package/dist/contexts/index.d.ts +2 -1
  3. package/dist/contexts/index.d.ts.map +1 -1
  4. package/dist/core/index.d.ts +2 -3
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/hooks/mm/index.d.ts +3 -1
  7. package/dist/hooks/mm/index.d.ts.map +1 -1
  8. package/dist/hooks/mm/useBorrow.d.ts +13 -4
  9. package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
  10. package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
  11. package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
  12. package/dist/hooks/mm/useMMApprove.d.ts +27 -0
  13. package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
  14. package/dist/hooks/mm/useRepay.d.ts +13 -4
  15. package/dist/hooks/mm/useRepay.d.ts.map +1 -1
  16. package/dist/hooks/mm/useReservesData.d.ts +19 -0
  17. package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
  18. package/dist/hooks/mm/useSupply.d.ts +4 -2
  19. package/dist/hooks/mm/useSupply.d.ts.map +1 -1
  20. package/dist/hooks/mm/useUserReservesData.d.ts +1 -7
  21. package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
  22. package/dist/hooks/mm/useWithdraw.d.ts +11 -4
  23. package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
  24. package/dist/hooks/provider/useHubProvider.d.ts +1 -1
  25. package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
  26. package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
  27. package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
  28. package/dist/hooks/shared/index.d.ts +1 -2
  29. package/dist/hooks/shared/index.d.ts.map +1 -1
  30. package/dist/hooks/shared/useEstimateGas.d.ts +4 -0
  31. package/dist/hooks/shared/useEstimateGas.d.ts.map +1 -0
  32. package/dist/hooks/swap/index.d.ts +2 -0
  33. package/dist/hooks/swap/index.d.ts.map +1 -1
  34. package/dist/hooks/swap/useCreateIntentOrder.d.ts +6 -6
  35. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +1 -1
  36. package/dist/hooks/swap/useQuote.d.ts +4 -4
  37. package/dist/hooks/swap/useQuote.d.ts.map +1 -1
  38. package/dist/hooks/swap/useStatus.d.ts +3 -3
  39. package/dist/hooks/swap/useStatus.d.ts.map +1 -1
  40. package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
  41. package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
  42. package/dist/hooks/swap/useSwapApprove.d.ts +26 -0
  43. package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
  44. package/dist/index.js +242 -189
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.mjs +239 -188
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/providers/SodaxProvider.d.ts.map +1 -1
  49. package/package.json +4 -4
  50. package/src/contexts/index.ts +2 -1
  51. package/src/core/index.ts +5 -35
  52. package/src/hooks/mm/index.ts +3 -1
  53. package/src/hooks/mm/useBorrow.ts +20 -10
  54. package/src/hooks/mm/useMMAllowance.ts +55 -0
  55. package/src/hooks/mm/useMMApprove.ts +67 -0
  56. package/src/hooks/mm/useRepay.ts +20 -10
  57. package/src/hooks/mm/useReservesData.ts +37 -0
  58. package/src/hooks/mm/useSupply.ts +9 -6
  59. package/src/hooks/mm/useUserReservesData.ts +17 -34
  60. package/src/hooks/mm/useWithdraw.ts +17 -11
  61. package/src/hooks/provider/useHubProvider.ts +2 -21
  62. package/src/hooks/provider/useSpokeProvider.ts +87 -10
  63. package/src/hooks/shared/index.ts +1 -2
  64. package/src/hooks/shared/useEstimateGas.ts +20 -0
  65. package/src/hooks/swap/index.ts +2 -0
  66. package/src/hooks/swap/useCreateIntentOrder.ts +9 -11
  67. package/src/hooks/swap/useQuote.ts +5 -5
  68. package/src/hooks/swap/useStatus.ts +3 -3
  69. package/src/hooks/swap/useSwapAllowance.ts +44 -0
  70. package/src/hooks/swap/useSwapApprove.ts +68 -0
  71. package/src/providers/SodaxProvider.tsx +18 -3
  72. package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
  73. package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
  74. package/dist/hooks/shared/useAllowance.d.ts +0 -3
  75. package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
  76. package/dist/hooks/shared/useApprove.d.ts +0 -10
  77. package/dist/hooks/shared/useApprove.d.ts.map +0 -1
  78. package/src/hooks/mm/useHubWalletAddress.ts +0 -49
  79. package/src/hooks/shared/useAllowance.ts +0 -31
  80. package/src/hooks/shared/useApprove.ts +0 -53
@@ -1,49 +0,0 @@
1
- import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';
2
- import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
-
4
- /**
5
- * Hook for retrieving the hub wallet address for a given spoke chain and address.
6
- *
7
- * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.
8
- * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.
9
- *
10
- * @param spokeChainId - The chain ID of the spoke chain
11
- * @param address - The user's address on the spoke chain
12
- * @param hubProvider - The hub provider instance
13
- *
14
- * @returns {UseQueryResult<string | null>} A query result object containing:
15
- * - data: The hub wallet address or null if not found
16
- * - isLoading: Boolean indicating if the query is in progress
17
- * - error: Error object if the query failed, null otherwise
18
- *
19
- * @example
20
- * ```typescript
21
- * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);
22
- * ```
23
- */
24
-
25
- export function useHubWalletAddress(
26
- spokeChainId: SpokeChainId,
27
- address: string | undefined,
28
- hubProvider: EvmHubProvider,
29
- ): UseQueryResult<string | null> {
30
- return useQuery({
31
- queryKey: ['hubWallet', spokeChainId, address],
32
- queryFn: async () => {
33
- if (!address) return null;
34
-
35
- try {
36
- const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
37
- spokeChainId,
38
- address as `0x${string}`,
39
- hubProvider,
40
- );
41
- return hubWalletAddress;
42
- } catch (error) {
43
- console.log('error', error);
44
- return null;
45
- }
46
- },
47
- enabled: !!address && !!hubProvider,
48
- });
49
- }
@@ -1,31 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- import type { SpokeChainId, XToken } from '@sodax/types';
3
- import { useSodaxContext } from '../shared/useSodaxContext';
4
- import { useSpokeProvider } from '../provider/useSpokeProvider';
5
- import { parseUnits } from 'viem';
6
-
7
- export function useAllowance(token: XToken, amount: string) {
8
- const { sodax } = useSodaxContext();
9
- const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
10
-
11
- return useQuery({
12
- queryKey: ['allowance', token.address, amount],
13
- queryFn: async () => {
14
- if (!spokeProvider) {
15
- return false;
16
- }
17
- const allowance = await sodax.moneyMarket.isAllowanceValid(
18
- {
19
- token: token.address,
20
- amount: parseUnits(amount, token.decimals),
21
- },
22
- spokeProvider,
23
- );
24
- if (allowance.ok) {
25
- return allowance.value;
26
- }
27
- return false;
28
- },
29
- enabled: !!spokeProvider,
30
- });
31
- }
@@ -1,53 +0,0 @@
1
- import { useSodaxContext } from '../shared/useSodaxContext';
2
- import { useSpokeProvider } from '../provider/useSpokeProvider';
3
- import type { SpokeChainId, XToken } from '@sodax/types';
4
- import { parseUnits } from 'viem';
5
- import { useMutation, useQueryClient } from '@tanstack/react-query';
6
- import type { Address } from '@sodax/sdk';
7
-
8
- interface UseApproveReturn {
9
- approve: (amount: string) => Promise<boolean>;
10
- isLoading: boolean;
11
- error: Error | null;
12
- resetError: () => void;
13
- }
14
-
15
- export function useApprove(token: XToken): UseApproveReturn {
16
- const { sodax } = useSodaxContext();
17
- const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
18
- const queryClient = useQueryClient();
19
-
20
- const {
21
- mutateAsync: approve,
22
- isPending,
23
- error,
24
- reset: resetError,
25
- } = useMutation({
26
- mutationFn: async (amount: string) => {
27
- if (!spokeProvider) {
28
- throw new Error('Spoke provider not found');
29
- }
30
- const allowance = await sodax.moneyMarket.approve(
31
- token.address as Address,
32
- parseUnits(amount, token.decimals),
33
- spokeProvider.chainConfig.addresses.assetManager as Address,
34
- spokeProvider,
35
- );
36
- if (!allowance.ok) {
37
- throw new Error('Failed to approve tokens');
38
- }
39
- return allowance.ok;
40
- },
41
- onSuccess: () => {
42
- // Invalidate allowance query to refetch the new allowance
43
- queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });
44
- },
45
- });
46
-
47
- return {
48
- approve,
49
- isLoading: isPending,
50
- error: error as Error | null,
51
- resetError,
52
- };
53
- }