@sodax/dapp-kit 0.0.1-rc.2 → 0.0.1-rc.21

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 (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -37
  3. package/dist/contexts/index.d.ts +4 -1
  4. package/dist/contexts/index.d.ts.map +1 -1
  5. package/dist/core/index.d.ts +2 -3
  6. package/dist/core/index.d.ts.map +1 -1
  7. package/dist/hooks/mm/index.d.ts +3 -1
  8. package/dist/hooks/mm/index.d.ts.map +1 -1
  9. package/dist/hooks/mm/useBorrow.d.ts +13 -4
  10. package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
  11. package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
  12. package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
  13. package/dist/hooks/mm/useMMApprove.d.ts +27 -0
  14. package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
  15. package/dist/hooks/mm/useRepay.d.ts +13 -4
  16. package/dist/hooks/mm/useRepay.d.ts.map +1 -1
  17. package/dist/hooks/mm/useReservesData.d.ts +19 -0
  18. package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
  19. package/dist/hooks/mm/useReservesHumanized.d.ts +21 -0
  20. package/dist/hooks/mm/useReservesHumanized.d.ts.map +1 -0
  21. package/dist/hooks/mm/useReservesList.d.ts +18 -0
  22. package/dist/hooks/mm/useReservesList.d.ts.map +1 -0
  23. package/dist/hooks/mm/useReservesUsdFormat.d.ts +23 -0
  24. package/dist/hooks/mm/useReservesUsdFormat.d.ts.map +1 -0
  25. package/dist/hooks/mm/useSupply.d.ts +4 -2
  26. package/dist/hooks/mm/useSupply.d.ts.map +1 -1
  27. package/dist/hooks/mm/useUserFormattedSummary.d.ts +21 -0
  28. package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -0
  29. package/dist/hooks/mm/useUserReservesData.d.ts +19 -8
  30. package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
  31. package/dist/hooks/mm/useWithdraw.d.ts +11 -4
  32. package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
  33. package/dist/hooks/provider/useHubProvider.d.ts +1 -1
  34. package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
  35. package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
  36. package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
  37. package/dist/hooks/shared/index.d.ts +1 -2
  38. package/dist/hooks/shared/index.d.ts.map +1 -1
  39. package/dist/hooks/shared/useEstimateGas.d.ts +4 -0
  40. package/dist/hooks/shared/useEstimateGas.d.ts.map +1 -0
  41. package/dist/hooks/swap/index.d.ts +4 -1
  42. package/dist/hooks/swap/index.d.ts.map +1 -1
  43. package/dist/hooks/swap/useCancelSwap.d.ts +29 -0
  44. package/dist/hooks/swap/useCancelSwap.d.ts.map +1 -0
  45. package/dist/hooks/swap/useQuote.d.ts +4 -4
  46. package/dist/hooks/swap/useQuote.d.ts.map +1 -1
  47. package/dist/hooks/swap/useStatus.d.ts +3 -3
  48. package/dist/hooks/swap/useStatus.d.ts.map +1 -1
  49. package/dist/hooks/swap/useSwap.d.ts +29 -0
  50. package/dist/hooks/swap/useSwap.d.ts.map +1 -0
  51. package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
  52. package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
  53. package/dist/hooks/swap/useSwapApprove.d.ts +25 -0
  54. package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
  55. package/dist/index.d.ts +1 -0
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +244 -189
  58. package/dist/index.js.map +1 -1
  59. package/dist/index.mjs +238 -186
  60. package/dist/index.mjs.map +1 -1
  61. package/dist/providers/SodaxProvider.d.ts +4 -2
  62. package/dist/providers/SodaxProvider.d.ts.map +1 -1
  63. package/dist/types.d.ts +17 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/package.json +5 -6
  66. package/src/contexts/index.ts +4 -1
  67. package/src/core/index.ts +5 -33
  68. package/src/hooks/mm/index.ts +3 -1
  69. package/src/hooks/mm/useBorrow.ts +20 -10
  70. package/src/hooks/mm/useMMAllowance.ts +55 -0
  71. package/src/hooks/mm/useMMApprove.ts +67 -0
  72. package/src/hooks/mm/useRepay.ts +20 -10
  73. package/src/hooks/mm/useReservesData.ts +30 -0
  74. package/src/hooks/mm/useReservesHumanized.ts +30 -0
  75. package/src/hooks/mm/useReservesList.ts +29 -0
  76. package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
  77. package/src/hooks/mm/useSupply.ts +9 -6
  78. package/src/hooks/mm/useUserFormattedSummary.ts +54 -0
  79. package/src/hooks/mm/useUserReservesData.ts +30 -48
  80. package/src/hooks/mm/useWithdraw.ts +17 -11
  81. package/src/hooks/provider/useHubProvider.ts +2 -20
  82. package/src/hooks/provider/useSpokeProvider.ts +91 -6
  83. package/src/hooks/shared/index.ts +1 -2
  84. package/src/hooks/shared/useEstimateGas.ts +18 -0
  85. package/src/hooks/swap/index.ts +4 -1
  86. package/src/hooks/swap/useCancelSwap.ts +44 -0
  87. package/src/hooks/swap/useQuote.ts +5 -5
  88. package/src/hooks/swap/useStatus.ts +3 -3
  89. package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +16 -18
  90. package/src/hooks/swap/useSwapAllowance.ts +47 -0
  91. package/src/hooks/swap/useSwapApprove.ts +68 -0
  92. package/src/index.ts +1 -0
  93. package/src/providers/SodaxProvider.tsx +22 -5
  94. package/src/types.ts +22 -0
  95. package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
  96. package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
  97. package/dist/hooks/shared/useAllowance.d.ts +0 -3
  98. package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
  99. package/dist/hooks/shared/useApprove.d.ts +0 -10
  100. package/dist/hooks/shared/useApprove.d.ts.map +0 -1
  101. package/dist/hooks/swap/useCreateIntentOrder.d.ts +0 -33
  102. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
  103. package/src/hooks/mm/useHubWalletAddress.ts +0 -49
  104. package/src/hooks/shared/useAllowance.ts +0 -31
  105. package/src/hooks/shared/useApprove.ts +0 -53
@@ -1,35 +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
- PacketData,
10
- IntentSubmitError,
8
+ IntentError,
9
+ SpokeProvider,
10
+ IntentDeliveryInfo,
11
11
  } from '@sodax/sdk';
12
- import { useSpokeProvider } from '../provider/useSpokeProvider';
13
12
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
14
13
 
15
- type CreateIntentResult = Result<
16
- [IntentExecutionResponse, Intent, PacketData],
17
- IntentSubmitError<IntentSubmitErrorCode>
18
- >;
14
+ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>;
19
15
 
20
16
  /**
21
- * Hook for creating and submitting an intent order for cross-chain swaps.
17
+ * Hook for creating and submitting an swap intent order for cross-chain swaps.
22
18
  * Uses React Query's useMutation for better state management and caching.
23
19
  *
24
- * @param {SpokeChainId} chainId - The source chain ID where the swap will originate
20
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
25
21
  * @returns {UseMutationResult} Mutation result object containing mutation function and state
26
22
  *
27
23
  * @example
28
24
  * ```typescript
29
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');
25
+ * const { mutateAsync: swap, isPending } = useSwap(spokeProvider);
30
26
  *
31
27
  * const handleSwap = async () => {
32
- * const result = await createIntent({
28
+ * const result = await swap({
33
29
  * token_src: '0x...',
34
30
  * token_src_blockchain_id: 'arbitrum',
35
31
  * token_dst: '0x...',
@@ -40,18 +36,20 @@ type CreateIntentResult = Result<
40
36
  * };
41
37
  * ```
42
38
  */
43
- export function useCreateIntentOrder(
44
- chainId: SpokeChainId,
39
+ export function useSwap(
40
+ spokeProvider: SpokeProvider | undefined,
45
41
  ): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {
46
42
  const { sodax } = useSodaxContext();
47
- const spokeProvider = useSpokeProvider(chainId);
48
43
 
49
44
  return useMutation<CreateIntentResult, Error, CreateIntentParams>({
50
45
  mutationFn: async (params: CreateIntentParams) => {
51
46
  if (!spokeProvider) {
52
47
  throw new Error('Spoke provider not found');
53
48
  }
54
- return sodax.solver.createAndSubmitIntent(params, spokeProvider);
49
+ return sodax.solver.swap({
50
+ intentParams: params,
51
+ spokeProvider,
52
+ });
55
53
  },
56
54
  });
57
55
  }
@@ -0,0 +1,47 @@
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({
37
+ intentParams: params,
38
+ spokeProvider,
39
+ });
40
+ if (allowance.ok) {
41
+ return allowance.value;
42
+ }
43
+ return false;
44
+ },
45
+ enabled: !!spokeProvider && !!params,
46
+ });
47
+ }
@@ -0,0 +1,68 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext';
2
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
3
+ import type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';
4
+
5
+ interface UseApproveReturn {
6
+ approve: ({ params }: { params: CreateIntentParams }) => Promise<boolean>;
7
+ isLoading: boolean;
8
+ error: Error | null;
9
+ resetError: () => void;
10
+ }
11
+
12
+ /**
13
+ * Hook for approving token spending for money market actions
14
+ * @param token The token to approve spending for
15
+ * @param spokeProvider The spoke provider instance for the chain
16
+ * @returns Object containing approve function, loading state, error state and reset function
17
+ * @example
18
+ * ```tsx
19
+ * const { approve, isLoading, error } = useApprove(token, spokeProvider);
20
+ *
21
+ * // Approve tokens for supply action
22
+ * await approve({ amount: "100", action: "supply" });
23
+ * ```
24
+ */
25
+
26
+ export function useSwapApprove(
27
+ params: CreateIntentParams | undefined,
28
+ spokeProvider: SpokeProvider | undefined,
29
+ ): UseApproveReturn {
30
+ const { sodax } = useSodaxContext();
31
+ const queryClient = useQueryClient();
32
+
33
+ const {
34
+ mutateAsync: approve,
35
+ isPending,
36
+ error,
37
+ reset: resetError,
38
+ } = useMutation({
39
+ mutationFn: async ({ params }: { params: CreateIntentParams | undefined }) => {
40
+ if (!spokeProvider) {
41
+ throw new Error('Spoke provider not found');
42
+ }
43
+ if (!params) {
44
+ throw new Error('Swap Params not found');
45
+ }
46
+
47
+ const allowance = await sodax.solver.approve({
48
+ intentParams: params,
49
+ spokeProvider,
50
+ });
51
+ if (!allowance.ok) {
52
+ throw new Error('Failed to approve input token');
53
+ }
54
+ return allowance.ok;
55
+ },
56
+ onSuccess: () => {
57
+ // Invalidate allowance query to refetch the new allowance
58
+ queryClient.invalidateQueries({ queryKey: ['allowance', params?.inputToken] });
59
+ },
60
+ });
61
+
62
+ return {
63
+ approve,
64
+ isLoading: isPending,
65
+ error: error,
66
+ resetError,
67
+ };
68
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './hooks';
2
2
  export * from './providers';
3
3
  export * from './core';
4
+ export * from './types';
@@ -1,16 +1,33 @@
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
+ import type { RpcConfig } from '@/types';
5
6
 
6
7
  interface SodaxProviderProps {
7
8
  children: ReactNode;
8
9
  testnet?: boolean;
9
- config: SodaxConfig;
10
+ config?: SodaxConfig;
11
+ rpcConfig: RpcConfig;
10
12
  }
11
13
 
12
- export const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {
14
+ export const SodaxProvider = ({ children, testnet = false, config, rpcConfig }: SodaxProviderProps): ReactElement => {
13
15
  const sodax = new Sodax(config);
14
16
 
15
- return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;
17
+ const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
18
+ const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
19
+
20
+ const hubProvider = useMemo(() => {
21
+ if (hubChainId && hubRpcUrl) {
22
+ const hubChainCfg = getHubChainConfig(hubChainId);
23
+
24
+ return new EvmHubProvider({
25
+ hubRpcUrl: hubRpcUrl,
26
+ chainConfig: hubChainCfg,
27
+ });
28
+ }
29
+ return undefined;
30
+ }, [hubChainId, hubRpcUrl]);
31
+
32
+ return <SodaxContext.Provider value={{ sodax, testnet, hubProvider, rpcConfig }}>{children}</SodaxContext.Provider>;
16
33
  };
package/src/types.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { StellarRpcConfig } from '@sodax/sdk';
2
+
3
+ export type RpcConfig = {
4
+ // EVM chains - all use string RPC URLs
5
+ sonic?: string;
6
+ '0xa86a.avax'?: string;
7
+ '0xa4b1.arbitrum'?: string;
8
+ '0x2105.base'?: string;
9
+ '0x38.bsc'?: string;
10
+ '0xa.optimism'?: string;
11
+ '0x89.polygon'?: string;
12
+ nibiru?: string;
13
+
14
+ // Other chains - all use string RPC URLs
15
+ 'injective-1'?: string;
16
+ sui?: string;
17
+ solana?: string;
18
+ '0x1.icon'?: string;
19
+
20
+ // Stellar - uses object with horizon and soroban RPC URLs
21
+ stellar?: StellarRpcConfig;
22
+ };
@@ -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"}
@@ -1,33 +0,0 @@
1
- import type { CreateIntentParams, SpokeChainId, IntentExecutionResponse, Result, IntentSubmitErrorCode, Intent, PacketData, IntentSubmitError } from '@sodax/sdk';
2
- import { type UseMutationResult } from '@tanstack/react-query';
3
- type CreateIntentResult = Result<[
4
- IntentExecutionResponse,
5
- Intent,
6
- PacketData
7
- ], IntentSubmitError<IntentSubmitErrorCode>>;
8
- /**
9
- * Hook for creating and submitting an intent order for cross-chain swaps.
10
- * Uses React Query's useMutation for better state management and caching.
11
- *
12
- * @param {SpokeChainId} chainId - The source chain ID where the swap will originate
13
- * @returns {UseMutationResult} Mutation result object containing mutation function and state
14
- *
15
- * @example
16
- * ```typescript
17
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');
18
- *
19
- * const handleSwap = async () => {
20
- * const result = await createIntent({
21
- * token_src: '0x...',
22
- * token_src_blockchain_id: 'arbitrum',
23
- * token_dst: '0x...',
24
- * token_dst_blockchain_id: 'polygon',
25
- * amount: '1000000000000000000',
26
- * min_output_amount: '900000000000000000'
27
- * });
28
- * };
29
- * ```
30
- */
31
- export declare function useCreateIntentOrder(chainId: SpokeChainId): UseMutationResult<CreateIntentResult, Error, CreateIntentParams>;
32
- export {};
33
- //# sourceMappingURL=useCreateIntentOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCreateIntentOrder.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useCreateIntentOrder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,MAAM,EACN,qBAAqB,EACrB,MAAM,EACN,UAAU,EACV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,KAAK,kBAAkB,GAAG,MAAM,CAC9B;IAAC,uBAAuB;IAAE,MAAM;IAAE,UAAU;CAAC,EAC7C,iBAAiB,CAAC,qBAAqB,CAAC,CACzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,YAAY,GACpB,iBAAiB,CAAC,kBAAkB,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAYlE"}
@@ -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
- }