@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,56 +1,39 @@
1
- import { allXTokens } from '@/core';
2
- import { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';
1
+ import { encodeAddress, EvmWalletAbstraction, getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';
3
2
  import type { HubChainId, SpokeChainId } from '@sodax/types';
4
- import { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';
5
3
  import type { ChainId } from '@sodax/types';
6
4
  import { useQuery } from '@tanstack/react-query';
7
5
  import { useHubProvider } from '../provider/useHubProvider';
8
- import { useHubWalletAddress } from './useHubWalletAddress';
9
6
  import { useSodaxContext } from '../shared/useSodaxContext';
10
7
 
11
- export function useUserReservesData(spokeChainId: ChainId) {
8
+ export function useUserReservesData(spokeChainId: ChainId, address: string | undefined) {
12
9
  const { sodax } = useSodaxContext();
13
10
  const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;
14
- const hubWalletProvider = useWalletProvider(hubChainId);
15
11
  const hubProvider = useHubProvider();
16
- const { address } = useXAccount(spokeChainId);
17
- const { data: hubWalletAddress } = useHubWalletAddress(
18
- spokeChainId as SpokeChainId,
19
- address,
20
- hubProvider as EvmHubProvider,
21
- );
22
12
 
23
13
  const { data: userReserves } = useQuery({
24
- queryKey: ['userReserves', hubWalletAddress],
14
+ queryKey: ['userReserves', spokeChainId, address],
25
15
  queryFn: async () => {
26
- if (!hubWalletProvider) {
16
+ if (!hubProvider || !address) {
27
17
  return;
28
18
  }
29
19
 
30
- if (!hubWalletAddress) {
31
- return;
32
- }
20
+ const addressBytes = encodeAddress(spokeChainId, address);
21
+ const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
22
+ spokeChainId as SpokeChainId,
23
+ addressBytes,
24
+ hubProvider as EvmHubProvider,
25
+ );
33
26
 
34
27
  const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
35
- try {
36
- const [res] = await sodax.moneyMarket.getUserReservesData(
37
- hubWalletAddress as `0x${string}`,
38
- moneyMarketConfig.uiPoolDataProvider,
39
- moneyMarketConfig.poolAddressesProvider,
40
- );
28
+ const [res] = await sodax.moneyMarket.getUserReservesData(
29
+ hubWalletAddress as `0x${string}`,
30
+ moneyMarketConfig.uiPoolDataProvider,
31
+ moneyMarketConfig.poolAddressesProvider,
32
+ );
41
33
 
42
- return res?.map(r => {
43
- return {
44
- ...r,
45
- token: allXTokens.find(t => t.address === r.underlyingAsset),
46
- };
47
- });
48
- } catch (error) {
49
- console.log('error', error);
50
- return;
51
- }
34
+ return res;
52
35
  },
53
- enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,
36
+ enabled: !!spokeChainId && !!hubProvider && !!address,
54
37
  refetchInterval: 5000,
55
38
  });
56
39
 
@@ -1,13 +1,12 @@
1
- import type { SpokeChainId } from '@sodax/sdk';
2
- import type { ChainId, XToken } from '@sodax/types';
1
+ import type { SpokeProvider } from '@sodax/sdk';
2
+ import type { XToken } from '@sodax/types';
3
3
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
4
4
  import { parseUnits } from 'viem';
5
- import { useSpokeProvider } from '../provider/useSpokeProvider';
6
5
  import { useSodaxContext } from '../shared/useSodaxContext';
7
6
 
8
7
  interface WithdrawResponse {
9
8
  ok: true;
10
- value: [`0x${string}`, `0x${string}`];
9
+ value: [string, string];
11
10
  }
12
11
 
13
12
  /**
@@ -17,9 +16,15 @@ interface WithdrawResponse {
17
16
  * handling the entire withdrawal process including transaction creation, submission,
18
17
  * and cross-chain communication.
19
18
  *
19
+ * @param {XToken} spokeToken - The token to withdraw from the spoke chain. Must be an XToken with valid address and chain information.
20
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the withdraw transaction. Must be a valid SpokeProvider instance.
21
+ *
22
+ * @returns {UseMutationResult<WithdrawResponse, Error, string>} A mutation result object with the following properties:
23
+ * - mutateAsync: Function to execute the withdraw transaction
24
+ * - isPending: Boolean indicating if a transaction is in progress
20
25
  * @example
21
26
  * ```typescript
22
- * const { mutateAsync: withdraw, isPending, error } = useWithdraw(hubToken, spokeChainId);
27
+ * const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);
23
28
  * await withdraw('100');
24
29
  * ```
25
30
  *
@@ -28,11 +33,10 @@ interface WithdrawResponse {
28
33
  * - Transaction execution fails
29
34
  */
30
35
  export function useWithdraw(
31
- hubToken: XToken,
32
- spokeChainId: ChainId,
36
+ spokeToken: XToken,
37
+ spokeProvider: SpokeProvider | undefined,
33
38
  ): UseMutationResult<WithdrawResponse, Error, string> {
34
39
  const { sodax } = useSodaxContext();
35
- const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);
36
40
 
37
41
  return useMutation<WithdrawResponse, Error, string>({
38
42
  mutationFn: async (amount: string) => {
@@ -40,10 +44,12 @@ export function useWithdraw(
40
44
  throw new Error('spokeProvider is not found');
41
45
  }
42
46
 
43
- const response = await sodax.moneyMarket.withdrawAndSubmit(
47
+ const response = await sodax.moneyMarket.withdraw(
44
48
  {
45
- token: hubToken.address,
46
- amount: parseUnits(amount, hubToken.decimals),
49
+ token: spokeToken.address,
50
+ // vault token on hub chain decimals is 18
51
+ amount: parseUnits(amount, 18),
52
+ action: 'withdraw',
47
53
  },
48
54
  spokeProvider,
49
55
  );
@@ -1,27 +1,8 @@
1
- import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';
2
- import { getXChainType } from '@sodax/wallet-sdk';
3
- import { useMemo } from 'react';
1
+ import type { EvmHubProvider } from '@sodax/sdk';
4
2
  import { useSodaxContext } from '../shared/useSodaxContext';
5
3
 
6
4
  export function useHubProvider(): EvmHubProvider | undefined {
7
- const { sodax } = useSodaxContext();
8
- const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;
9
- const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;
10
- const xChainType = getXChainType(hubChainId);
11
- const hubProvider = useMemo(() => {
12
- if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {
13
- // @ts-ignore
14
- const hubChainCfg = getHubChainConfig(hubChainId);
15
-
16
- if (!hubChainCfg) return undefined;
17
-
18
- return new EvmHubProvider({
19
- hubRpcUrl: hubRpcUrl,
20
- chainConfig: hubChainCfg,
21
- });
22
- }
23
- return undefined;
24
- }, [xChainType, hubChainId, hubRpcUrl]);
5
+ const { hubProvider } = useSodaxContext();
25
6
 
26
7
  return hubProvider;
27
8
  }
@@ -1,23 +1,100 @@
1
- import { EvmSpokeProvider, spokeChainConfig, SuiSpokeProvider } from '@sodax/sdk';
2
- import type { SpokeChainId } from '@sodax/types';
1
+ import {
2
+ EvmSpokeProvider,
3
+ spokeChainConfig,
4
+ type SuiSpokeChainConfig,
5
+ SuiSpokeProvider,
6
+ type EvmSpokeChainConfig,
7
+ IconSpokeProvider,
8
+ type IconSpokeChainConfig,
9
+ InjectiveSpokeProvider,
10
+ type InjectiveSpokeChainConfig,
11
+ StellarSpokeProvider,
12
+ type StellarSpokeChainConfig,
13
+ type SpokeProvider,
14
+ type IWalletProvider,
15
+ SolanaSpokeProvider,
16
+ type SolanaChainConfig,
17
+ } from '@sodax/sdk';
18
+ import type {
19
+ IEvmWalletProvider,
20
+ IIconWalletProvider,
21
+ ISuiWalletProvider,
22
+ SpokeChainId,
23
+ IInjectiveWalletProvider,
24
+ IStellarWalletProvider,
25
+ ISolanaWalletProvider,
26
+ } from '@sodax/types';
3
27
  import { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';
4
28
  import { useMemo } from 'react';
5
29
 
6
- export function useSpokeProvider(spokeChainId: SpokeChainId) {
30
+ /**
31
+ * Hook to get the appropriate spoke provider based on the chain type.
32
+ * Supports EVM, SUI, ICON and INJECTIVE chains.
33
+ *
34
+ * @param {SpokeChainId | undefined} spokeChainId - The spoke chain ID to get the provider for
35
+ * @param {IWalletProvider | undefined} walletProvider - The wallet provider to use
36
+ * @returns {SpokeProvider | undefined} The appropriate spoke provider instance for the given chain ID, or undefined if invalid/unsupported
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * // Using a specific SpokeChainId and wallet provider
41
+ * const spokeProvider = useSpokeProvider(spokeChainId, walletProvider);
42
+ * ```
43
+ */
44
+ export function useSpokeProvider(
45
+ spokeChainId: SpokeChainId | undefined,
46
+ walletProvider?: IWalletProvider | undefined,
47
+ ): SpokeProvider | undefined {
7
48
  const xChainType = getXChainType(spokeChainId);
8
- const walletProvider = useWalletProvider(spokeChainId);
49
+ const walletProvider_ = useWalletProvider(spokeChainId);
50
+ const _walletProvider = walletProvider ?? walletProvider_;
51
+
9
52
  const spokeProvider = useMemo(() => {
10
- if (!walletProvider) return undefined;
53
+ if (!_walletProvider) return undefined;
54
+ if (!spokeChainId) return undefined;
55
+
11
56
  if (xChainType === 'EVM') {
12
- // @ts-ignore
13
- return new EvmSpokeProvider(walletProvider, spokeChainConfig[spokeChainId]);
57
+ return new EvmSpokeProvider(
58
+ _walletProvider as IEvmWalletProvider,
59
+ spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,
60
+ );
14
61
  }
15
62
  if (xChainType === 'SUI') {
16
- // @ts-ignore
17
- return new SuiSpokeProvider(spokeChainConfig[spokeChainId], walletProvider);
63
+ return new SuiSpokeProvider(
64
+ spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,
65
+ _walletProvider as ISuiWalletProvider,
66
+ );
67
+ }
68
+ if (xChainType === 'ICON') {
69
+ return new IconSpokeProvider(
70
+ _walletProvider as IIconWalletProvider,
71
+ spokeChainConfig[spokeChainId] as IconSpokeChainConfig,
72
+ );
18
73
  }
74
+ if (xChainType === 'INJECTIVE') {
75
+ return new InjectiveSpokeProvider(
76
+ spokeChainConfig[spokeChainId] as InjectiveSpokeChainConfig,
77
+ _walletProvider as IInjectiveWalletProvider,
78
+ );
79
+ }
80
+
81
+ if (xChainType === 'STELLAR') {
82
+ const stellarConfig = spokeChainConfig[spokeChainId] as StellarSpokeChainConfig;
83
+ return new StellarSpokeProvider(_walletProvider as IStellarWalletProvider, stellarConfig, {
84
+ horizonRpcUrl: stellarConfig.horizonRpcUrl,
85
+ sorobanRpcUrl: stellarConfig.sorobanRpcUrl,
86
+ });
87
+ }
88
+
89
+ if (xChainType === 'SOLANA') {
90
+ return new SolanaSpokeProvider(
91
+ _walletProvider as ISolanaWalletProvider,
92
+ spokeChainConfig[spokeChainId] as SolanaChainConfig,
93
+ );
94
+ }
95
+
19
96
  return undefined;
20
- }, [walletProvider, xChainType, spokeChainId]);
97
+ }, [spokeChainId, xChainType, _walletProvider]);
21
98
 
22
99
  return spokeProvider;
23
100
  }
@@ -1,3 +1,2 @@
1
1
  export * from './useSodaxContext';
2
- export * from './useAllowance';
3
- export * from './useApprove';
2
+ export * from './useEstimateGas';
@@ -0,0 +1,20 @@
1
+ import { type GetEstimateGasReturnType, type SpokeProvider, SpokeService, type TxReturnType } from '@sodax/sdk';
2
+ import { useMutation, type UseMutationResult } from '@tanstack/react-query';
3
+
4
+ export function useEstimateGas<T extends SpokeProvider = SpokeProvider>(
5
+ spokeProvider: T | undefined,
6
+ ): UseMutationResult<GetEstimateGasReturnType<T>, Error, TxReturnType<T, true>> {
7
+
8
+ return useMutation<GetEstimateGasReturnType<T>, Error, TxReturnType<T, true>>({
9
+ mutationFn: async (rawTx: TxReturnType<T, true>) => {
10
+ if (!spokeProvider) {
11
+ throw new Error('spokeProvider is not found');
12
+ }
13
+
14
+ const response = await SpokeService.estimateGas(rawTx, spokeProvider);
15
+
16
+ return response;
17
+ },
18
+ });
19
+ }
20
+
@@ -1,3 +1,5 @@
1
1
  export * from './useQuote';
2
2
  export * from './useCreateIntentOrder';
3
3
  export * from './useStatus';
4
+ export * from './useSwapAllowance';
5
+ export * from './useSwapApprove';
@@ -1,32 +1,31 @@
1
1
  import { useSodaxContext } from '../shared/useSodaxContext';
2
2
  import type {
3
3
  CreateIntentParams,
4
- SpokeChainId,
5
- IntentExecutionResponse,
4
+ SolverExecutionResponse,
6
5
  Result,
7
- IntentSubmitErrorCode,
6
+ IntentErrorCode,
8
7
  Intent,
9
8
  PacketData,
10
- IntentSubmitError,
9
+ IntentError,
10
+ SpokeProvider,
11
11
  } from '@sodax/sdk';
12
- import { useSpokeProvider } from '../provider/useSpokeProvider';
13
12
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
14
13
 
15
14
  type CreateIntentResult = Result<
16
- [IntentExecutionResponse, Intent, PacketData],
17
- IntentSubmitError<IntentSubmitErrorCode>
15
+ [SolverExecutionResponse, Intent, PacketData],
16
+ IntentError<IntentErrorCode>
18
17
  >;
19
18
 
20
19
  /**
21
20
  * Hook for creating and submitting an intent order for cross-chain swaps.
22
21
  * Uses React Query's useMutation for better state management and caching.
23
22
  *
24
- * @param {SpokeChainId} chainId - The source chain ID where the swap will originate
23
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
25
24
  * @returns {UseMutationResult} Mutation result object containing mutation function and state
26
25
  *
27
26
  * @example
28
27
  * ```typescript
29
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');
28
+ * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(spokeProvider);
30
29
  *
31
30
  * const handleSwap = async () => {
32
31
  * const result = await createIntent({
@@ -41,10 +40,9 @@ type CreateIntentResult = Result<
41
40
  * ```
42
41
  */
43
42
  export function useCreateIntentOrder(
44
- chainId: SpokeChainId,
43
+ spokeProvider: SpokeProvider | undefined,
45
44
  ): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {
46
45
  const { sodax } = useSodaxContext();
47
- const spokeProvider = useSpokeProvider(chainId);
48
46
 
49
47
  return useMutation<CreateIntentResult, Error, CreateIntentParams>({
50
48
  mutationFn: async (params: CreateIntentParams) => {
@@ -1,4 +1,4 @@
1
- import type { IntentErrorResponse, IntentQuoteRequest, IntentQuoteResponse, Result } from '@sodax/sdk';
1
+ import type { SolverErrorResponse, SolverIntentQuoteRequest, SolverIntentQuoteResponse, Result } from '@sodax/sdk';
2
2
  import { useSodaxContext } from '../shared/useSodaxContext';
3
3
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
4
4
 
@@ -7,9 +7,9 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
7
7
  *
8
8
  * This hook provides real-time quote data for an intent-based swap.
9
9
  *
10
- * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.
10
+ * @param {SolverIntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.
11
11
  *
12
- * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:
12
+ * @returns {UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined>} A query result object containing:
13
13
  * - data: The quote result from the solver
14
14
  * - isLoading: Boolean indicating if the quote is being fetched
15
15
  * - error: Error object if the quote request failed
@@ -38,8 +38,8 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
38
38
  * - Uses React Query for efficient caching and state management
39
39
  */
40
40
  export const useQuote = (
41
- payload: IntentQuoteRequest | undefined,
42
- ): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {
41
+ payload: SolverIntentQuoteRequest | undefined,
42
+ ): UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined> => {
43
43
  const { sodax } = useSodaxContext();
44
44
  return useQuery({
45
45
  queryKey: [payload],
@@ -1,4 +1,4 @@
1
- import type { Hex, IntentErrorResponse, IntentStatusResponse, Result } from '@sodax/sdk';
1
+ import type { Hex, SolverErrorResponse, SolverIntentStatusResponse, Result } from '@sodax/sdk';
2
2
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
3
  import { useSodaxContext } from '../shared/useSodaxContext';
4
4
 
@@ -9,7 +9,7 @@ import { useSodaxContext } from '../shared/useSodaxContext';
9
9
  *
10
10
  * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain
11
11
  *
12
- * @returns {UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined>} A query result object containing:
12
+ * @returns {UseQueryResult<Result<SolverIntentStatusResponse, SolverErrorResponse> | undefined>} A query result object containing:
13
13
  * - data: The status result from the solver
14
14
  * - isLoading: Boolean indicating if the status is being fetched
15
15
  * - error: Error object if the status request failed
@@ -32,7 +32,7 @@ import { useSodaxContext } from '../shared/useSodaxContext';
32
32
 
33
33
  export const useStatus = (
34
34
  intent_tx_hash: Hex,
35
- ): UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined> => {
35
+ ): UseQueryResult<Result<SolverIntentStatusResponse, SolverErrorResponse> | undefined> => {
36
36
  const { sodax } = useSodaxContext();
37
37
  return useQuery({
38
38
  queryKey: [intent_tx_hash],
@@ -0,0 +1,44 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext';
3
+ import type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';
4
+
5
+ /**
6
+ * Hook for checking token allowance for money market operations.
7
+ *
8
+ * This hook verifies if the user has approved enough tokens for a specific money market action
9
+ * (borrow/repay). It automatically queries and tracks the allowance status.
10
+ *
11
+ * @param {CreateIntentParams} params - The parameters for the intent to check allowance for.
12
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for allowance checks
13
+ *
14
+ * @returns {UseQueryResult<boolean, Error>} A React Query result containing:
15
+ * - data: Boolean indicating if allowance is sufficient
16
+ * - isLoading: Loading state indicator
17
+ * - error: Any error that occurred during the check
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const { data: hasAllowed, isLoading } = useMMAllowance(params, spokeProvider);
22
+ * ```
23
+ */
24
+ export function useSwapAllowance(
25
+ params: CreateIntentParams | undefined,
26
+ spokeProvider: SpokeProvider | undefined,
27
+ ): UseQueryResult<boolean, Error> {
28
+ const { sodax } = useSodaxContext();
29
+
30
+ return useQuery({
31
+ queryKey: ['allowance', params],
32
+ queryFn: async () => {
33
+ if (!spokeProvider || !params) {
34
+ return false;
35
+ }
36
+ const allowance = await sodax.solver.isAllowanceValid(params, spokeProvider);
37
+ if (allowance.ok) {
38
+ return allowance.value;
39
+ }
40
+ return false;
41
+ },
42
+ enabled: !!spokeProvider && !!params,
43
+ });
44
+ }
@@ -0,0 +1,68 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext';
2
+ import type { Token } from '@sodax/types';
3
+ import { type Address, parseUnits } from 'viem';
4
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
5
+ import type { SpokeProvider } from '@sodax/sdk';
6
+
7
+ interface UseApproveReturn {
8
+ approve: ({ amount }: { amount: string }) => Promise<boolean>;
9
+ isLoading: boolean;
10
+ error: Error | null;
11
+ resetError: () => void;
12
+ }
13
+
14
+ /**
15
+ * Hook for approving token spending for money market actions
16
+ * @param token The token to approve spending for
17
+ * @param spokeProvider The spoke provider instance for the chain
18
+ * @returns Object containing approve function, loading state, error state and reset function
19
+ * @example
20
+ * ```tsx
21
+ * const { approve, isLoading, error } = useApprove(token, spokeProvider);
22
+ *
23
+ * // Approve tokens for supply action
24
+ * await approve({ amount: "100", action: "supply" });
25
+ * ```
26
+ */
27
+
28
+ export function useSwapApprove(token: Token | undefined, spokeProvider: SpokeProvider | undefined): UseApproveReturn {
29
+ const { sodax } = useSodaxContext();
30
+ const queryClient = useQueryClient();
31
+
32
+ const {
33
+ mutateAsync: approve,
34
+ isPending,
35
+ error,
36
+ reset: resetError,
37
+ } = useMutation({
38
+ mutationFn: async ({ amount }: { amount: string }) => {
39
+ if (!spokeProvider) {
40
+ throw new Error('Spoke provider not found');
41
+ }
42
+ if (!token) {
43
+ throw new Error('Token not found');
44
+ }
45
+
46
+ const allowance = await sodax.solver.approve(
47
+ token.address as Address,
48
+ parseUnits(amount, token.decimals),
49
+ spokeProvider,
50
+ );
51
+ if (!allowance.ok) {
52
+ throw new Error('Failed to approve tokens');
53
+ }
54
+ return allowance.ok;
55
+ },
56
+ onSuccess: () => {
57
+ // Invalidate allowance query to refetch the new allowance
58
+ queryClient.invalidateQueries({ queryKey: ['allowance', token?.address] });
59
+ },
60
+ });
61
+
62
+ return {
63
+ approve,
64
+ isLoading: isPending,
65
+ error: error,
66
+ resetError,
67
+ };
68
+ }
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode, ReactElement } from 'react';
2
- import { Sodax, type SodaxConfig } from '@sodax/sdk';
2
+ import { EvmHubProvider, getHubChainConfig, Sodax, type SodaxConfig } from '@sodax/sdk';
3
3
  import { SodaxContext } from '@/contexts';
4
- import React from 'react';
4
+ import React, { useMemo } from 'react';
5
5
 
6
6
  interface SodaxProviderProps {
7
7
  children: ReactNode;
@@ -12,5 +12,20 @@ interface SodaxProviderProps {
12
12
  export const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {
13
13
  const sodax = new Sodax(config);
14
14
 
15
- return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;
15
+ const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
16
+ const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
17
+
18
+ const hubProvider = useMemo(() => {
19
+ if (hubChainId && hubRpcUrl) {
20
+ const hubChainCfg = getHubChainConfig(hubChainId);
21
+
22
+ return new EvmHubProvider({
23
+ hubRpcUrl: hubRpcUrl,
24
+ chainConfig: hubChainCfg,
25
+ });
26
+ }
27
+ return undefined;
28
+ }, [hubChainId, hubRpcUrl]);
29
+
30
+ return <SodaxContext.Provider value={{ sodax, testnet, hubProvider }}>{children}</SodaxContext.Provider>;
16
31
  };
@@ -1,24 +0,0 @@
1
- import { type EvmHubProvider, type SpokeChainId } from '@sodax/sdk';
2
- import { type UseQueryResult } from '@tanstack/react-query';
3
- /**
4
- * Hook for retrieving the hub wallet address for a given spoke chain and address.
5
- *
6
- * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.
7
- * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.
8
- *
9
- * @param spokeChainId - The chain ID of the spoke chain
10
- * @param address - The user's address on the spoke chain
11
- * @param hubProvider - The hub provider instance
12
- *
13
- * @returns {UseQueryResult<string | null>} A query result object containing:
14
- * - data: The hub wallet address or null if not found
15
- * - isLoading: Boolean indicating if the query is in progress
16
- * - error: Error object if the query failed, null otherwise
17
- *
18
- * @example
19
- * ```typescript
20
- * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);
21
- * ```
22
- */
23
- export declare function useHubWalletAddress(spokeChainId: SpokeChainId, address: string | undefined, hubProvider: EvmHubProvider): UseQueryResult<string | null>;
24
- //# sourceMappingURL=useHubWalletAddress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHubWalletAddress.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useHubWalletAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAwB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,WAAW,EAAE,cAAc,GAC1B,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAoB/B"}
@@ -1,3 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- export declare function useAllowance(token: XToken, amount: string): import("@tanstack/react-query").UseQueryResult<boolean, Error>;
3
- //# sourceMappingURL=useAllowance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useAllowance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAKzD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kEAwBzD"}
@@ -1,10 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- interface UseApproveReturn {
3
- approve: (amount: string) => Promise<boolean>;
4
- isLoading: boolean;
5
- error: Error | null;
6
- resetError: () => void;
7
- }
8
- export declare function useApprove(token: XToken): UseApproveReturn;
9
- export {};
10
- //# sourceMappingURL=useApprove.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useApprove.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAKzD,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAsC1D"}