@sodax/dapp-kit 0.0.1-rc.7 → 0.0.1-rc.9

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 (61) hide show
  1. package/README.md +11 -12
  2. package/dist/core/index.d.ts +1 -2
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/hooks/mm/index.d.ts +2 -3
  5. package/dist/hooks/mm/index.d.ts.map +1 -1
  6. package/dist/hooks/mm/useBorrow.d.ts +1 -1
  7. package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
  8. package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
  9. package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
  10. package/dist/hooks/mm/useMMApprove.d.ts +27 -0
  11. package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
  12. package/dist/hooks/mm/useRepay.d.ts +1 -1
  13. package/dist/hooks/mm/useRepay.d.ts.map +1 -1
  14. package/dist/hooks/mm/useSupply.d.ts +1 -1
  15. package/dist/hooks/mm/useSupply.d.ts.map +1 -1
  16. package/dist/hooks/mm/useUserReservesData.d.ts +1 -7
  17. package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
  18. package/dist/hooks/mm/useWithdraw.d.ts +1 -1
  19. package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
  20. package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
  21. package/dist/hooks/swap/index.d.ts +2 -0
  22. package/dist/hooks/swap/index.d.ts.map +1 -1
  23. package/dist/hooks/swap/useCreateIntentOrder.d.ts +3 -3
  24. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +1 -1
  25. package/dist/hooks/swap/useQuote.d.ts +4 -4
  26. package/dist/hooks/swap/useQuote.d.ts.map +1 -1
  27. package/dist/hooks/swap/useStatus.d.ts +3 -3
  28. package/dist/hooks/swap/useStatus.d.ts.map +1 -1
  29. package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
  30. package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
  31. package/dist/hooks/swap/useSwapApprove.d.ts +26 -0
  32. package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
  33. package/dist/index.js +86 -67
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +84 -65
  36. package/dist/index.mjs.map +1 -1
  37. package/package.json +4 -4
  38. package/src/core/index.ts +4 -27
  39. package/src/hooks/mm/index.ts +2 -3
  40. package/src/hooks/mm/useBorrow.ts +2 -2
  41. package/src/hooks/mm/useMMAllowance.ts +55 -0
  42. package/src/hooks/mm/{useApprove.ts → useMMApprove.ts} +17 -5
  43. package/src/hooks/mm/useRepay.ts +2 -2
  44. package/src/hooks/mm/useSupply.ts +2 -2
  45. package/src/hooks/mm/useUserReservesData.ts +1 -7
  46. package/src/hooks/mm/useWithdraw.ts +2 -2
  47. package/src/hooks/provider/useSpokeProvider.ts +21 -0
  48. package/src/hooks/swap/index.ts +2 -0
  49. package/src/hooks/swap/useCreateIntentOrder.ts +5 -5
  50. package/src/hooks/swap/useQuote.ts +5 -5
  51. package/src/hooks/swap/useStatus.ts +3 -3
  52. package/src/hooks/swap/useSwapAllowance.ts +44 -0
  53. package/src/hooks/swap/useSwapApprove.ts +68 -0
  54. package/dist/hooks/mm/useAllowance.d.ts +0 -4
  55. package/dist/hooks/mm/useAllowance.d.ts.map +0 -1
  56. package/dist/hooks/mm/useApprove.d.ts +0 -14
  57. package/dist/hooks/mm/useApprove.d.ts.map +0 -1
  58. package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
  59. package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
  60. package/src/hooks/mm/useAllowance.ts +0 -33
  61. package/src/hooks/mm/useHubWalletAddress.ts +0 -49
@@ -6,7 +6,7 @@ import { useSodaxContext } from '../shared/useSodaxContext';
6
6
 
7
7
  interface SupplyResponse {
8
8
  ok: true;
9
- value: [`0x${string}`, `0x${string}`];
9
+ value: [string, string];
10
10
  }
11
11
 
12
12
  /**
@@ -45,7 +45,7 @@ export function useSupply(
45
45
  throw new Error('spokeProvider is not found');
46
46
  }
47
47
 
48
- const response = await sodax.moneyMarket.supplyAndSubmit(
48
+ const response = await sodax.moneyMarket.supply(
49
49
  {
50
50
  token: spokeToken.address,
51
51
  amount: parseUnits(amount, spokeToken.decimals),
@@ -1,4 +1,3 @@
1
- import { allXTokens } from '@/core';
2
1
  import { encodeAddress, EvmWalletAbstraction, getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';
3
2
  import type { HubChainId, SpokeChainId } from '@sodax/types';
4
3
  import type { ChainId } from '@sodax/types';
@@ -32,12 +31,7 @@ export function useUserReservesData(spokeChainId: ChainId, address: string | und
32
31
  moneyMarketConfig.poolAddressesProvider,
33
32
  );
34
33
 
35
- return res?.map(r => {
36
- return {
37
- ...r,
38
- token: allXTokens.find(t => t.address === r.underlyingAsset),
39
- };
40
- });
34
+ return res;
41
35
  },
42
36
  enabled: !!spokeChainId && !!hubProvider && !!address,
43
37
  refetchInterval: 5000,
@@ -6,7 +6,7 @@ import { useSodaxContext } from '../shared/useSodaxContext';
6
6
 
7
7
  interface WithdrawResponse {
8
8
  ok: true;
9
- value: [`0x${string}`, `0x${string}`];
9
+ value: [string, string];
10
10
  }
11
11
 
12
12
  /**
@@ -44,7 +44,7 @@ export function useWithdraw(
44
44
  throw new Error('spokeProvider is not found');
45
45
  }
46
46
 
47
- const response = await sodax.moneyMarket.withdrawAndSubmit(
47
+ const response = await sodax.moneyMarket.withdraw(
48
48
  {
49
49
  token: spokeToken.address,
50
50
  // vault token on hub chain decimals is 18
@@ -8,8 +8,12 @@ import {
8
8
  type IconSpokeChainConfig,
9
9
  CWSpokeProvider,
10
10
  type CosmosSpokeChainConfig,
11
+ StellarSpokeProvider,
12
+ type StellarSpokeChainConfig,
11
13
  type SpokeProvider,
12
14
  type IWalletProvider,
15
+ SolanaSpokeProvider,
16
+ type SolanaChainConfig,
13
17
  } from '@sodax/sdk';
14
18
  import type {
15
19
  IEvmWalletProvider,
@@ -17,6 +21,8 @@ import type {
17
21
  ISuiWalletProvider,
18
22
  SpokeChainId,
19
23
  IInjectiveWalletProvider,
24
+ IStellarWalletProvider,
25
+ ISolanaWalletProvider,
20
26
  } from '@sodax/types';
21
27
  import { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';
22
28
  import { useMemo } from 'react';
@@ -72,6 +78,21 @@ export function useSpokeProvider(
72
78
  );
73
79
  }
74
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
+
75
96
  return undefined;
76
97
  }, [spokeChainId, xChainType, _walletProvider]);
77
98
 
@@ -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,19 +1,19 @@
1
1
  import { useSodaxContext } from '../shared/useSodaxContext';
2
2
  import type {
3
3
  CreateIntentParams,
4
- IntentExecutionResponse,
4
+ SolverExecutionResponse,
5
5
  Result,
6
- IntentSubmitErrorCode,
6
+ IntentErrorCode,
7
7
  Intent,
8
8
  PacketData,
9
- IntentSubmitError,
9
+ IntentError,
10
10
  SpokeProvider,
11
11
  } from '@sodax/sdk';
12
12
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
13
13
 
14
14
  type CreateIntentResult = Result<
15
- [IntentExecutionResponse, Intent, PacketData],
16
- IntentSubmitError<IntentSubmitErrorCode>
15
+ [SolverExecutionResponse, Intent, PacketData],
16
+ IntentError<IntentErrorCode>
17
17
  >;
18
18
 
19
19
  /**
@@ -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,4 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- import type { MoneyMarketAction } from '@sodax/sdk';
3
- export declare function useAllowance(token: XToken, amount: string, action: MoneyMarketAction): import("@tanstack/react-query").UseQueryResult<boolean, Error>;
4
- //# sourceMappingURL=useAllowance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useAllowance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAIzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,kEAyBpF"}
@@ -1,14 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- import type { MoneyMarketAction } from '@sodax/sdk';
3
- interface UseApproveReturn {
4
- approve: ({ amount, action }: {
5
- amount: string;
6
- action: MoneyMarketAction;
7
- }) => Promise<boolean>;
8
- isLoading: boolean;
9
- error: Error | null;
10
- resetError: () => void;
11
- }
12
- export declare function useApprove(token: XToken): UseApproveReturn;
13
- export {};
14
- //# sourceMappingURL=useApprove.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useApprove.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjG,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,CAwC1D"}
@@ -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,33 +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
- import type { MoneyMarketAction } from '@sodax/sdk';
7
-
8
- export function useAllowance(token: XToken, amount: string, action: MoneyMarketAction) {
9
- const { sodax } = useSodaxContext();
10
- const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
11
-
12
- return useQuery({
13
- queryKey: ['allowance', token.address, amount, action],
14
- queryFn: async () => {
15
- if (!spokeProvider) {
16
- return false;
17
- }
18
- const allowance = await sodax.moneyMarket.isAllowanceValid(
19
- {
20
- token: token.address,
21
- amount: parseUnits(amount, token.decimals),
22
- action,
23
- },
24
- spokeProvider,
25
- );
26
- if (allowance.ok) {
27
- return allowance.value;
28
- }
29
- return false;
30
- },
31
- enabled: !!spokeProvider,
32
- });
33
- }
@@ -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
- }