@sodax/dapp-kit 0.0.1-rc.3 → 0.0.1-rc.31

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 (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -53
  3. package/dist/index.d.mts +1514 -0
  4. package/dist/index.d.ts +1514 -4
  5. package/dist/index.js +1141 -189
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1096 -187
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +7 -8
  10. package/src/contexts/index.ts +2 -0
  11. package/src/core/index.ts +5 -33
  12. package/src/hooks/backend/README.md +135 -0
  13. package/src/hooks/backend/index.ts +23 -0
  14. package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +49 -0
  15. package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +61 -0
  16. package/src/hooks/backend/useBackendIntentByHash.ts +53 -0
  17. package/src/hooks/backend/useBackendIntentByTxHash.ts +52 -0
  18. package/src/hooks/backend/useBackendMoneyMarketAsset.ts +57 -0
  19. package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +67 -0
  20. package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +67 -0
  21. package/src/hooks/backend/useBackendMoneyMarketPosition.ts +56 -0
  22. package/src/hooks/backend/useBackendOrderbook.ts +63 -0
  23. package/src/hooks/bridge/index.ts +5 -0
  24. package/src/hooks/bridge/useBridge.ts +57 -0
  25. package/src/hooks/bridge/useBridgeAllowance.ts +49 -0
  26. package/src/hooks/bridge/useBridgeApprove.ts +68 -0
  27. package/src/hooks/bridge/useGetBridgeableAmount.ts +50 -0
  28. package/src/hooks/bridge/useGetBridgeableTokens.ts +62 -0
  29. package/src/hooks/index.ts +4 -0
  30. package/src/hooks/migrate/index.ts +4 -0
  31. package/src/hooks/migrate/types.ts +15 -0
  32. package/src/hooks/migrate/useMigrate.tsx +110 -0
  33. package/src/hooks/migrate/useMigrationAllowance.tsx +79 -0
  34. package/src/hooks/migrate/useMigrationApprove.tsx +129 -0
  35. package/src/hooks/mm/index.ts +3 -1
  36. package/src/hooks/mm/useBorrow.ts +20 -10
  37. package/src/hooks/mm/useMMAllowance.ts +56 -0
  38. package/src/hooks/mm/useMMApprove.ts +68 -0
  39. package/src/hooks/mm/useRepay.ts +20 -10
  40. package/src/hooks/mm/useReservesData.ts +30 -0
  41. package/src/hooks/mm/useReservesHumanized.ts +30 -0
  42. package/src/hooks/mm/useReservesList.ts +29 -0
  43. package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
  44. package/src/hooks/mm/useSupply.ts +9 -6
  45. package/src/hooks/mm/useUserFormattedSummary.ts +54 -0
  46. package/src/hooks/mm/useUserReservesData.ts +30 -48
  47. package/src/hooks/mm/useWithdraw.ts +17 -11
  48. package/src/hooks/provider/useHubProvider.ts +3 -21
  49. package/src/hooks/provider/useSpokeProvider.ts +97 -6
  50. package/src/hooks/shared/index.ts +4 -2
  51. package/src/hooks/shared/useDeriveUserWalletAddress.ts +44 -0
  52. package/src/hooks/shared/useEstimateGas.ts +18 -0
  53. package/src/hooks/shared/useRequestTrustline.ts +103 -0
  54. package/src/hooks/shared/useStellarTrustlineCheck.ts +71 -0
  55. package/src/hooks/staking/index.ts +19 -0
  56. package/src/hooks/staking/useCancelUnstake.ts +52 -0
  57. package/src/hooks/staking/useClaim.ts +46 -0
  58. package/src/hooks/staking/useConvertedAssets.ts +47 -0
  59. package/src/hooks/staking/useInstantUnstake.ts +50 -0
  60. package/src/hooks/staking/useInstantUnstakeAllowance.ts +59 -0
  61. package/src/hooks/staking/useInstantUnstakeApprove.ts +52 -0
  62. package/src/hooks/staking/useInstantUnstakeRatio.ts +54 -0
  63. package/src/hooks/staking/useStake.ts +47 -0
  64. package/src/hooks/staking/useStakeAllowance.ts +57 -0
  65. package/src/hooks/staking/useStakeApprove.ts +50 -0
  66. package/src/hooks/staking/useStakeRatio.ts +53 -0
  67. package/src/hooks/staking/useStakingConfig.ts +40 -0
  68. package/src/hooks/staking/useStakingInfo.ts +50 -0
  69. package/src/hooks/staking/useUnstake.ts +54 -0
  70. package/src/hooks/staking/useUnstakeAllowance.ts +58 -0
  71. package/src/hooks/staking/useUnstakeApprove.ts +52 -0
  72. package/src/hooks/staking/useUnstakingInfo.ts +53 -0
  73. package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +59 -0
  74. package/src/hooks/swap/index.ts +4 -1
  75. package/src/hooks/swap/useCancelSwap.ts +44 -0
  76. package/src/hooks/swap/useQuote.ts +20 -6
  77. package/src/hooks/swap/useStatus.ts +3 -3
  78. package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +22 -19
  79. package/src/hooks/swap/useSwapAllowance.ts +48 -0
  80. package/src/hooks/swap/useSwapApprove.ts +68 -0
  81. package/src/providers/SodaxProvider.tsx +7 -4
  82. package/dist/contexts/index.d.ts +0 -7
  83. package/dist/contexts/index.d.ts.map +0 -1
  84. package/dist/core/index.d.ts +0 -4
  85. package/dist/core/index.d.ts.map +0 -1
  86. package/dist/hooks/index.d.ts +0 -5
  87. package/dist/hooks/index.d.ts.map +0 -1
  88. package/dist/hooks/mm/index.d.ts +0 -7
  89. package/dist/hooks/mm/index.d.ts.map +0 -1
  90. package/dist/hooks/mm/useBorrow.d.ts +0 -26
  91. package/dist/hooks/mm/useBorrow.d.ts.map +0 -1
  92. package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
  93. package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
  94. package/dist/hooks/mm/useRepay.d.ts +0 -26
  95. package/dist/hooks/mm/useRepay.d.ts.map +0 -1
  96. package/dist/hooks/mm/useSupply.d.ts +0 -32
  97. package/dist/hooks/mm/useSupply.d.ts.map +0 -1
  98. package/dist/hooks/mm/useUserReservesData.d.ts +0 -9
  99. package/dist/hooks/mm/useUserReservesData.d.ts.map +0 -1
  100. package/dist/hooks/mm/useWithdraw.d.ts +0 -26
  101. package/dist/hooks/mm/useWithdraw.d.ts.map +0 -1
  102. package/dist/hooks/provider/index.d.ts +0 -3
  103. package/dist/hooks/provider/index.d.ts.map +0 -1
  104. package/dist/hooks/provider/useHubProvider.d.ts +0 -3
  105. package/dist/hooks/provider/useHubProvider.d.ts.map +0 -1
  106. package/dist/hooks/provider/useSpokeProvider.d.ts +0 -4
  107. package/dist/hooks/provider/useSpokeProvider.d.ts.map +0 -1
  108. package/dist/hooks/shared/index.d.ts +0 -4
  109. package/dist/hooks/shared/index.d.ts.map +0 -1
  110. package/dist/hooks/shared/useAllowance.d.ts +0 -3
  111. package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
  112. package/dist/hooks/shared/useApprove.d.ts +0 -10
  113. package/dist/hooks/shared/useApprove.d.ts.map +0 -1
  114. package/dist/hooks/shared/useSodaxContext.d.ts +0 -8
  115. package/dist/hooks/shared/useSodaxContext.d.ts.map +0 -1
  116. package/dist/hooks/swap/index.d.ts +0 -4
  117. package/dist/hooks/swap/index.d.ts.map +0 -1
  118. package/dist/hooks/swap/useCreateIntentOrder.d.ts +0 -33
  119. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
  120. package/dist/hooks/swap/useQuote.d.ts +0 -39
  121. package/dist/hooks/swap/useQuote.d.ts.map +0 -1
  122. package/dist/hooks/swap/useStatus.d.ts +0 -31
  123. package/dist/hooks/swap/useStatus.d.ts.map +0 -1
  124. package/dist/index.d.ts.map +0 -1
  125. package/dist/providers/SodaxProvider.d.ts +0 -10
  126. package/dist/providers/SodaxProvider.d.ts.map +0 -1
  127. package/dist/providers/index.d.ts +0 -2
  128. package/dist/providers/index.d.ts.map +0 -1
  129. package/src/hooks/mm/useHubWalletAddress.ts +0 -49
  130. package/src/hooks/shared/useAllowance.ts +0 -31
  131. package/src/hooks/shared/useApprove.ts +0 -53
@@ -0,0 +1,58 @@
1
+ // packages/dapp-kit/src/hooks/staking/useStakeAllowance.ts
2
+ import { useSodaxContext } from '../shared/useSodaxContext';
3
+ import type { UnstakeParams, SpokeProvider } from '@sodax/sdk';
4
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
5
+
6
+ /**
7
+ * Hook for checking xSODA token allowance for unstaking operations.
8
+ * Uses React Query for efficient caching and state management.
9
+ *
10
+ * @param {Omit<UnstakeParams, 'action'> | undefined} params - The unstaking parameters. If undefined, the query will be disabled.
11
+ * @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the allowance check
12
+ * @returns {UseQueryResult<boolean, Error>} Query result object containing allowance data and state
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const { data: hasAllowed, isLoading } = useUnstakeAllowance(
17
+ * {
18
+ * amount: 1000000000000000000n, // 1 xSODA
19
+ * account: '0x...'
20
+ * },
21
+ * spokeProvider
22
+ * );
23
+ *
24
+ * if (isLoading) return <div>Checking allowance...</div>;
25
+ * if (hasAllowed) {
26
+ * console.log('Sufficient allowance for unstaking');
27
+ * }
28
+ * ```
29
+ */
30
+ export function useUnstakeAllowance(
31
+ params: Omit<UnstakeParams, 'action'> | undefined,
32
+ spokeProvider: SpokeProvider | undefined,
33
+ ): UseQueryResult<boolean, Error> {
34
+ const { sodax } = useSodaxContext();
35
+
36
+ return useQuery({
37
+ queryKey: ['soda', 'unstakeAllowance', params, spokeProvider?.chainConfig.chain.id],
38
+ queryFn: async () => {
39
+ if (!params || !spokeProvider) {
40
+ return false;
41
+ }
42
+
43
+ const result = await sodax.staking.isAllowanceValid({
44
+ params: { ...params, action: 'unstake' },
45
+ spokeProvider,
46
+ });
47
+
48
+ if (!result.ok) {
49
+ console.error(`Unstake allowance check failed: ${result.error.code}, error: ${result.error.error}`);
50
+ throw new Error(`Unstake allowance check failed: ${result.error.code}`);
51
+ }
52
+
53
+ return result.value;
54
+ },
55
+ enabled: !!params && !!spokeProvider,
56
+ refetchInterval: 5000, // Refetch every 5 seconds
57
+ });
58
+ }
@@ -0,0 +1,52 @@
1
+ // packages/dapp-kit/src/hooks/staking/useStakeApprove.ts
2
+ import { useSodaxContext } from '../shared/useSodaxContext';
3
+ import type { TxReturnType, UnstakeParams } from '@sodax/sdk';
4
+ import { useMutation, type UseMutationResult } from '@tanstack/react-query';
5
+ import type { SpokeProvider } from '@sodax/sdk';
6
+
7
+ /**
8
+ * Hook for approving xSODA token spending for unstaking operations.
9
+ * Uses React Query's useMutation for better state management and caching.
10
+ *
11
+ * @param {SpokeProvider | undefined} spokeProvider - The spoke provider to use for the approval
12
+ * @returns {UseMutationResult<TxReturnType<SpokeProvider, false>, Error, Omit<UnstakeParams, 'action'>>} Mutation result object containing mutation function and state
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const { mutateAsync: approve, isPending } = useUnstakeApprove(spokeProvider);
17
+ *
18
+ * const handleApprove = async () => {
19
+ * const result = await approve({
20
+ * amount: 1000000000000000000n, // 1 xSODA
21
+ * account: '0x...'
22
+ * });
23
+ *
24
+ * console.log('Approval successful:', result);
25
+ * };
26
+ * ```
27
+ */
28
+ export function useUnstakeApprove(
29
+ spokeProvider: SpokeProvider | undefined,
30
+ ): UseMutationResult<TxReturnType<SpokeProvider, false>, Error, Omit<UnstakeParams, 'action'>> {
31
+ const { sodax } = useSodaxContext();
32
+
33
+ return useMutation<TxReturnType<SpokeProvider, false>, Error, Omit<UnstakeParams, 'action'>>({
34
+ mutationFn: async (params: Omit<UnstakeParams, 'action'>) => {
35
+ console.log('useUnstakeApprove called with params:', params);
36
+ if (!spokeProvider) {
37
+ throw new Error('Spoke provider not found');
38
+ }
39
+
40
+ const result = await sodax.staking.approve({
41
+ params: { ...params, action: 'unstake' },
42
+ spokeProvider,
43
+ });
44
+
45
+ if (!result.ok) {
46
+ throw new Error(`Unstake approval failed: ${result.error.code}`);
47
+ }
48
+
49
+ return result.value;
50
+ },
51
+ });
52
+ }
@@ -0,0 +1,53 @@
1
+ // packages/dapp-kit/src/hooks/staking/useUnstakingInfoWithPenalty.ts
2
+ import { useSodaxContext } from '../shared/useSodaxContext';
3
+ import type { UnstakingInfo, SpokeProvider } from '@sodax/sdk';
4
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
5
+
6
+ /**
7
+ * Hook for fetching unstaking information from the stakedSoda contract.
8
+ * Uses React Query for efficient caching and state management.
9
+ *
10
+ * @param {string | undefined} userAddress - The user address to fetch unstaking info for
11
+ * @param {SpokeProvider | undefined} spokeProvider - The spoke provider instance
12
+ * @param {number} refetchInterval - The interval in milliseconds to refetch data (default: 5000)
13
+ * @returns {UseQueryResult<UnstakingInfo, Error>} Query result object containing unstaking info and state
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const { data: unstakingInfo, isLoading, error } = useUnstakingInfo(userAddress, spokeProvider);
18
+ *
19
+ * if (isLoading) return <div>Loading unstaking info...</div>;
20
+ * if (unstakingInfo) {
21
+ * console.log('Total unstaking:', unstakingInfo.totalUnstaking);
22
+ * unstakingInfo.userUnstakeSodaRequests.forEach(request => {
23
+ * console.log('Request amount:', request.request.amount);
24
+ * });
25
+ * }
26
+ * ```
27
+ */
28
+ export function useUnstakingInfo(
29
+ userAddress: string | undefined,
30
+ spokeProvider: SpokeProvider | undefined,
31
+ refetchInterval = 5000,
32
+ ): UseQueryResult<UnstakingInfo, Error> {
33
+ const { sodax } = useSodaxContext();
34
+
35
+ return useQuery({
36
+ queryKey: ['soda', 'unstakingInfoWithPenalty', spokeProvider?.chainConfig.chain.id, userAddress],
37
+ queryFn: async () => {
38
+ if (!spokeProvider || !userAddress) {
39
+ throw new Error('Spoke provider or user address not found');
40
+ }
41
+
42
+ const result = await sodax.staking.getUnstakingInfo(spokeProvider);
43
+
44
+ if (!result.ok) {
45
+ throw new Error(`Failed to fetch unstaking info: ${result.error.code}`);
46
+ }
47
+
48
+ return result.value;
49
+ },
50
+ enabled: !!spokeProvider && !!userAddress,
51
+ refetchInterval,
52
+ });
53
+ }
@@ -0,0 +1,59 @@
1
+ // packages/dapp-kit/src/hooks/staking/useUnstakingInfoWithPenalty.ts
2
+ import { useSodaxContext } from '../shared/useSodaxContext';
3
+ import type { UnstakingInfo, UnstakeRequestWithPenalty, SpokeProvider } from '@sodax/sdk';
4
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
5
+
6
+ export type UnstakingInfoWithPenalty = UnstakingInfo & {
7
+ requestsWithPenalty: UnstakeRequestWithPenalty[];
8
+ };
9
+
10
+ /**
11
+ * Hook for fetching unstaking information with penalty calculations from the stakedSoda contract.
12
+ * Uses React Query for efficient caching and state management.
13
+ *
14
+ * @param {string | undefined} userAddress - The user address to fetch unstaking info for
15
+ * @param {SpokeProvider | undefined} spokeProvider - The spoke provider instance
16
+ * @param {number} refetchInterval - The interval in milliseconds to refetch data (default: 5000)
17
+ * @returns {UseQueryResult<UnstakingInfoWithPenalty, Error>} Query result object containing unstaking info with penalties and state
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const { data: unstakingInfo, isLoading, error } = useUnstakingInfoWithPenalty(userAddress, spokeProvider);
22
+ *
23
+ * if (isLoading) return <div>Loading unstaking info...</div>;
24
+ * if (unstakingInfo) {
25
+ * console.log('Total unstaking:', unstakingInfo.totalUnstaking);
26
+ * unstakingInfo.requestsWithPenalty.forEach(request => {
27
+ * console.log('Penalty:', request.penaltyPercentage + '%');
28
+ * console.log('Claimable amount:', request.claimableAmount);
29
+ * });
30
+ * }
31
+ * ```
32
+ */
33
+ export function useUnstakingInfoWithPenalty(
34
+ userAddress: string | undefined,
35
+ spokeProvider: SpokeProvider | undefined,
36
+ refetchInterval = 5000,
37
+ ): UseQueryResult<UnstakingInfoWithPenalty, Error> {
38
+ const { sodax } = useSodaxContext();
39
+
40
+ return useQuery({
41
+ queryKey: ['soda', 'unstakingInfoWithPenalty', spokeProvider?.chainConfig.chain.id, userAddress],
42
+ queryFn: async () => {
43
+ if (!spokeProvider) {
44
+ throw new Error('Spoke provider not found');
45
+ }
46
+
47
+ // Get unstaking info with penalty calculations
48
+ const penaltyResult = await sodax.staking.getUnstakingInfoWithPenalty(spokeProvider);
49
+
50
+ if (!penaltyResult.ok) {
51
+ throw new Error(`Failed to fetch unstaking info with penalty: ${penaltyResult.error.code}`);
52
+ }
53
+
54
+ return penaltyResult.value;
55
+ },
56
+ enabled: !!spokeProvider && !!userAddress,
57
+ refetchInterval,
58
+ });
59
+ }
@@ -1,3 +1,6 @@
1
1
  export * from './useQuote';
2
- export * from './useCreateIntentOrder';
2
+ export * from './useSwap';
3
3
  export * from './useStatus';
4
+ export * from './useSwapAllowance';
5
+ export * from './useSwapApprove';
6
+ export * from './useCancelSwap';
@@ -0,0 +1,44 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext';
2
+ import type { Intent, Result, SpokeProvider, TxReturnType } from '@sodax/sdk';
3
+ import { useMutation, type UseMutationResult } from '@tanstack/react-query';
4
+
5
+ type CancelIntentParams = {
6
+ intent: Intent;
7
+ raw?: boolean;
8
+ };
9
+
10
+ type CancelIntentResult = Result<TxReturnType<SpokeProvider, boolean>>;
11
+
12
+ /**
13
+ * Hook for canceling a swap intent order.
14
+ * Uses React Query's useMutation for better state management and caching.
15
+ *
16
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for canceling the intent
17
+ * @returns {UseMutationResult} Mutation result object containing mutation function and state
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const { mutateAsync: cancelSwap, isPending } = useCancelSwap(spokeProvider);
22
+ *
23
+ * const handleCancelSwap = async () => {
24
+ * const result = await cancelSwap({
25
+ * intent: intentObject,
26
+ * raw: false // optional, defaults to false
27
+ * });
28
+ * };
29
+ * ```
30
+ */
31
+ export function useCancelSwap(
32
+ spokeProvider: SpokeProvider | undefined,
33
+ ): UseMutationResult<CancelIntentResult, Error, CancelIntentParams> {
34
+ const { sodax } = useSodaxContext();
35
+
36
+ return useMutation<CancelIntentResult, Error, CancelIntentParams>({
37
+ mutationFn: async ({ intent, raw = false }: CancelIntentParams) => {
38
+ if (!spokeProvider) {
39
+ throw new Error('Spoke provider not found');
40
+ }
41
+ return sodax.solver.cancelIntent(intent, spokeProvider, raw);
42
+ },
43
+ });
44
+ }
@@ -1,15 +1,16 @@
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
+ import { useMemo } from 'react';
4
5
 
5
6
  /**
6
7
  * Hook for fetching a quote for an intent-based swap.
7
8
  *
8
9
  * This hook provides real-time quote data for an intent-based swap.
9
10
  *
10
- * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.
11
+ * @param {SolverIntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.
11
12
  *
12
- * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:
13
+ * @returns {UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined>} A query result object containing:
13
14
  * - data: The quote result from the solver
14
15
  * - isLoading: Boolean indicating if the quote is being fetched
15
16
  * - error: Error object if the quote request failed
@@ -38,11 +39,24 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
38
39
  * - Uses React Query for efficient caching and state management
39
40
  */
40
41
  export const useQuote = (
41
- payload: IntentQuoteRequest | undefined,
42
- ): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {
42
+ payload: SolverIntentQuoteRequest | undefined,
43
+ ): UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined> => {
43
44
  const { sodax } = useSodaxContext();
45
+
46
+ // Create a serializable query key by converting BigInt to string
47
+ const queryKey = useMemo(() => {
48
+ if (!payload) return ['quote', undefined];
49
+ return [
50
+ 'quote',
51
+ {
52
+ ...payload,
53
+ amount: payload.amount.toString(),
54
+ },
55
+ ];
56
+ }, [payload]);
57
+
44
58
  return useQuery({
45
- queryKey: [payload],
59
+ queryKey,
46
60
  queryFn: async () => {
47
61
  if (!payload) {
48
62
  return undefined;
@@ -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],
@@ -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
- import { useMutation, type UseMutationResult } from '@tanstack/react-query';
12
+ import { useMutation, type UseMutationResult, useQueryClient } 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,25 @@ 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);
43
+ const queryClient = useQueryClient();
48
44
 
49
45
  return useMutation<CreateIntentResult, Error, CreateIntentParams>({
50
46
  mutationFn: async (params: CreateIntentParams) => {
51
47
  if (!spokeProvider) {
52
48
  throw new Error('Spoke provider not found');
53
49
  }
54
- return sodax.solver.createAndSubmitIntent(params, spokeProvider);
50
+ return sodax.solver.swap({
51
+ intentParams: params,
52
+ spokeProvider,
53
+ });
54
+ },
55
+ onSuccess: () => {
56
+ // Invalidate balance queries to refresh both source and destination token balances
57
+ queryClient.invalidateQueries({ queryKey: ['xBalances'] });
55
58
  },
56
59
  });
57
60
  }
@@ -0,0 +1,48 @@
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
+ refetchInterval: 2000,
47
+ });
48
+ }
@@ -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] });
59
+ },
60
+ });
61
+
62
+ return {
63
+ approve,
64
+ isLoading: isPending,
65
+ error: error,
66
+ resetError,
67
+ };
68
+ }
@@ -1,16 +1,19 @@
1
1
  import type { ReactNode, ReactElement } from 'react';
2
+ import React from 'react';
3
+
2
4
  import { Sodax, type SodaxConfig } from '@sodax/sdk';
3
5
  import { SodaxContext } from '@/contexts';
4
- import React from 'react';
6
+ import type { RpcConfig } from '@sodax/types';
5
7
 
6
8
  interface SodaxProviderProps {
7
9
  children: ReactNode;
8
10
  testnet?: boolean;
9
- config: SodaxConfig;
11
+ config?: SodaxConfig;
12
+ rpcConfig: RpcConfig;
10
13
  }
11
14
 
12
- export const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {
15
+ export const SodaxProvider = ({ children, testnet = false, config, rpcConfig }: SodaxProviderProps): ReactElement => {
13
16
  const sodax = new Sodax(config);
14
17
 
15
- return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;
18
+ return <SodaxContext.Provider value={{ sodax, testnet, rpcConfig }}>{children}</SodaxContext.Provider>;
16
19
  };
@@ -1,7 +0,0 @@
1
- import type { Sodax } from '@sodax/sdk';
2
- export interface SodaxContextType {
3
- sodax: Sodax;
4
- testnet: boolean;
5
- }
6
- export declare const SodaxContext: import("react").Context<SodaxContextType | null>;
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,YAAY,kDAA+C,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { XToken, ChainId } from '@sodax/types';
2
- export declare const allXTokens: XToken[];
3
- export declare const getSpokeTokenAddressByVault: (spokeChainId: ChainId, vault: string) => string;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,UAAU,EAAE,MAAM,EAAO,CAAC;AAyBvC,eAAO,MAAM,2BAA2B,iBAAkB,OAAO,SAAS,MAAM,WAU/E,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from './shared';
2
- export * from './provider';
3
- export * from './mm';
4
- export * from './swap';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC"}
@@ -1,7 +0,0 @@
1
- export * from './useBorrow';
2
- export * from './useRepay';
3
- export * from './useSupply';
4
- export * from './useWithdraw';
5
- export * from './useUserReservesData';
6
- export * from './useHubWalletAddress';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
@@ -1,26 +0,0 @@
1
- import type { ChainId, XToken } from '@sodax/types';
2
- import { type UseMutationResult } from '@tanstack/react-query';
3
- interface BorrowResponse {
4
- ok: true;
5
- value: [`0x${string}`, `0x${string}`];
6
- }
7
- /**
8
- * Hook for borrowing tokens from the Sodax money market.
9
- *
10
- * This hook provides functionality to borrow tokens from the money market protocol,
11
- * handling the entire borrow process including transaction creation, submission,
12
- * and cross-chain communication.
13
- *
14
- * @example
15
- * ```typescript
16
- * const { mutateAsync: borrow, isPending, error } = useBorrow(hubToken, spokeChainId);
17
- * await borrow('100');
18
- * ```
19
- *
20
- * @throws {Error} When:
21
- * - spokeProvider is not available
22
- * - Transaction execution fails
23
- */
24
- export declare function useBorrow(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<BorrowResponse, Error, string>;
25
- export {};
26
- //# sourceMappingURL=useBorrow.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBorrow.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useBorrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAK5E,UAAU,cAAc;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,MAAM,CAAC,CA0BnH"}