@sodax/dapp-kit 0.0.1-rc.8 → 1.0.0-beta

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -60
  3. package/dist/index.d.mts +1558 -0
  4. package/dist/index.d.ts +1558 -4
  5. package/dist/index.js +1030 -135
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +988 -134
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +7 -8
  10. package/src/contexts/index.ts +3 -2
  11. package/src/hooks/backend/README.md +135 -0
  12. package/src/hooks/backend/index.ts +23 -0
  13. package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +49 -0
  14. package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +61 -0
  15. package/src/hooks/backend/useBackendIntentByHash.ts +53 -0
  16. package/src/hooks/backend/useBackendIntentByTxHash.ts +57 -0
  17. package/src/hooks/backend/useBackendMoneyMarketAsset.ts +57 -0
  18. package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +67 -0
  19. package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +67 -0
  20. package/src/hooks/backend/useBackendMoneyMarketPosition.ts +56 -0
  21. package/src/hooks/backend/useBackendOrderbook.ts +63 -0
  22. package/src/hooks/bridge/index.ts +5 -0
  23. package/src/hooks/bridge/useBridge.ts +57 -0
  24. package/src/hooks/bridge/useBridgeAllowance.ts +49 -0
  25. package/src/hooks/bridge/useBridgeApprove.ts +68 -0
  26. package/src/hooks/bridge/useGetBridgeableAmount.ts +50 -0
  27. package/src/hooks/bridge/useGetBridgeableTokens.ts +62 -0
  28. package/src/hooks/index.ts +4 -0
  29. package/src/hooks/migrate/index.ts +4 -0
  30. package/src/hooks/migrate/types.ts +15 -0
  31. package/src/hooks/migrate/useMigrate.tsx +110 -0
  32. package/src/hooks/migrate/useMigrationAllowance.tsx +79 -0
  33. package/src/hooks/migrate/useMigrationApprove.tsx +129 -0
  34. package/src/hooks/mm/index.ts +2 -1
  35. package/src/hooks/mm/useAToken.ts +47 -0
  36. package/src/hooks/mm/useBorrow.ts +2 -2
  37. package/src/hooks/mm/useMMAllowance.ts +2 -1
  38. package/src/hooks/mm/useMMApprove.ts +2 -1
  39. package/src/hooks/mm/useRepay.ts +2 -2
  40. package/src/hooks/mm/useReservesData.ts +1 -8
  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 +2 -2
  45. package/src/hooks/mm/useUserFormattedSummary.ts +54 -0
  46. package/src/hooks/mm/useUserReservesData.ts +30 -37
  47. package/src/hooks/mm/useWithdraw.ts +2 -2
  48. package/src/hooks/provider/useHubProvider.ts +3 -3
  49. package/src/hooks/provider/useSpokeProvider.ts +50 -18
  50. package/src/hooks/shared/index.ts +4 -0
  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 +2 -1
  75. package/src/hooks/swap/useCancelSwap.ts +44 -0
  76. package/src/hooks/swap/useQuote.ts +21 -7
  77. package/src/hooks/swap/useStatus.ts +4 -4
  78. package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +19 -14
  79. package/src/hooks/swap/useSwapAllowance.ts +5 -1
  80. package/src/hooks/swap/useSwapApprove.ts +14 -14
  81. package/src/index.ts +0 -1
  82. package/src/providers/SodaxProvider.tsx +8 -20
  83. package/dist/contexts/index.d.ts +0 -8
  84. package/dist/contexts/index.d.ts.map +0 -1
  85. package/dist/core/index.d.ts +0 -4
  86. package/dist/core/index.d.ts.map +0 -1
  87. package/dist/hooks/index.d.ts +0 -5
  88. package/dist/hooks/index.d.ts.map +0 -1
  89. package/dist/hooks/mm/index.d.ts +0 -10
  90. package/dist/hooks/mm/index.d.ts.map +0 -1
  91. package/dist/hooks/mm/useBorrow.d.ts +0 -35
  92. package/dist/hooks/mm/useBorrow.d.ts.map +0 -1
  93. package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
  94. package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
  95. package/dist/hooks/mm/useMMAllowance.d.ts +0 -26
  96. package/dist/hooks/mm/useMMAllowance.d.ts.map +0 -1
  97. package/dist/hooks/mm/useMMApprove.d.ts +0 -27
  98. package/dist/hooks/mm/useMMApprove.d.ts.map +0 -1
  99. package/dist/hooks/mm/useRepay.d.ts +0 -35
  100. package/dist/hooks/mm/useRepay.d.ts.map +0 -1
  101. package/dist/hooks/mm/useReservesData.d.ts +0 -19
  102. package/dist/hooks/mm/useReservesData.d.ts.map +0 -1
  103. package/dist/hooks/mm/useSupply.d.ts +0 -34
  104. package/dist/hooks/mm/useSupply.d.ts.map +0 -1
  105. package/dist/hooks/mm/useUserReservesData.d.ts +0 -9
  106. package/dist/hooks/mm/useUserReservesData.d.ts.map +0 -1
  107. package/dist/hooks/mm/useWithdraw.d.ts +0 -33
  108. package/dist/hooks/mm/useWithdraw.d.ts.map +0 -1
  109. package/dist/hooks/provider/index.d.ts +0 -3
  110. package/dist/hooks/provider/index.d.ts.map +0 -1
  111. package/dist/hooks/provider/useHubProvider.d.ts +0 -3
  112. package/dist/hooks/provider/useHubProvider.d.ts.map +0 -1
  113. package/dist/hooks/provider/useSpokeProvider.d.ts +0 -18
  114. package/dist/hooks/provider/useSpokeProvider.d.ts.map +0 -1
  115. package/dist/hooks/shared/index.d.ts +0 -2
  116. package/dist/hooks/shared/index.d.ts.map +0 -1
  117. package/dist/hooks/shared/useSodaxContext.d.ts +0 -8
  118. package/dist/hooks/shared/useSodaxContext.d.ts.map +0 -1
  119. package/dist/hooks/swap/index.d.ts +0 -6
  120. package/dist/hooks/swap/index.d.ts.map +0 -1
  121. package/dist/hooks/swap/useCreateIntentOrder.d.ts +0 -33
  122. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
  123. package/dist/hooks/swap/useQuote.d.ts +0 -39
  124. package/dist/hooks/swap/useQuote.d.ts.map +0 -1
  125. package/dist/hooks/swap/useStatus.d.ts +0 -31
  126. package/dist/hooks/swap/useStatus.d.ts.map +0 -1
  127. package/dist/hooks/swap/useSwapAllowance.d.ts +0 -23
  128. package/dist/hooks/swap/useSwapAllowance.d.ts.map +0 -1
  129. package/dist/hooks/swap/useSwapApprove.d.ts +0 -26
  130. package/dist/hooks/swap/useSwapApprove.d.ts.map +0 -1
  131. package/dist/index.d.ts.map +0 -1
  132. package/dist/providers/SodaxProvider.d.ts +0 -10
  133. package/dist/providers/SodaxProvider.d.ts.map +0 -1
  134. package/dist/providers/index.d.ts +0 -2
  135. package/dist/providers/index.d.ts.map +0 -1
  136. package/src/core/index.ts +0 -35
  137. package/src/hooks/mm/useHubWalletAddress.ts +0 -49
@@ -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,5 +1,6 @@
1
1
  export * from './useQuote';
2
- export * from './useCreateIntentOrder';
2
+ export * from './useSwap';
3
3
  export * from './useStatus';
4
4
  export * from './useSwapAllowance';
5
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.swaps.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,16 +39,29 @@ 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;
49
63
  }
50
- return sodax.solver.getQuote(payload);
64
+ return sodax.swaps.getQuote(payload);
51
65
  },
52
66
  enabled: !!payload,
53
67
  refetchInterval: 3000,
@@ -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,12 +32,12 @@ 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],
39
39
  queryFn: async () => {
40
- return sodax.solver.getStatus({ intent_tx_hash });
40
+ return sodax.swaps.getStatus({ intent_tx_hash });
41
41
  },
42
42
  refetchInterval: 3000, // 3s
43
43
  });
@@ -1,23 +1,20 @@
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
- PacketData,
9
- IntentSubmitError,
8
+ IntentError,
10
9
  SpokeProvider,
10
+ IntentDeliveryInfo,
11
11
  } from '@sodax/sdk';
12
- import { useMutation, type UseMutationResult } from '@tanstack/react-query';
12
+ import { useMutation, type UseMutationResult, useQueryClient } from '@tanstack/react-query';
13
13
 
14
- type CreateIntentResult = Result<
15
- [IntentExecutionResponse, Intent, PacketData],
16
- IntentSubmitError<IntentSubmitErrorCode>
17
- >;
14
+ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>;
18
15
 
19
16
  /**
20
- * 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.
21
18
  * Uses React Query's useMutation for better state management and caching.
22
19
  *
23
20
  * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
@@ -25,10 +22,10 @@ type CreateIntentResult = Result<
25
22
  *
26
23
  * @example
27
24
  * ```typescript
28
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(spokeProvider);
25
+ * const { mutateAsync: swap, isPending } = useSwap(spokeProvider);
29
26
  *
30
27
  * const handleSwap = async () => {
31
- * const result = await createIntent({
28
+ * const result = await swap({
32
29
  * token_src: '0x...',
33
30
  * token_src_blockchain_id: 'arbitrum',
34
31
  * token_dst: '0x...',
@@ -39,17 +36,25 @@ type CreateIntentResult = Result<
39
36
  * };
40
37
  * ```
41
38
  */
42
- export function useCreateIntentOrder(
39
+ export function useSwap(
43
40
  spokeProvider: SpokeProvider | undefined,
44
41
  ): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {
45
42
  const { sodax } = useSodaxContext();
43
+ const queryClient = useQueryClient();
46
44
 
47
45
  return useMutation<CreateIntentResult, Error, CreateIntentParams>({
48
46
  mutationFn: async (params: CreateIntentParams) => {
49
47
  if (!spokeProvider) {
50
48
  throw new Error('Spoke provider not found');
51
49
  }
52
- return sodax.solver.createAndSubmitIntent(params, spokeProvider);
50
+ return sodax.swaps.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'] });
53
58
  },
54
59
  });
55
60
  }
@@ -33,12 +33,16 @@ export function useSwapAllowance(
33
33
  if (!spokeProvider || !params) {
34
34
  return false;
35
35
  }
36
- const allowance = await sodax.solver.isAllowanceValid(params, spokeProvider);
36
+ const allowance = await sodax.swaps.isAllowanceValid({
37
+ intentParams: params,
38
+ spokeProvider,
39
+ });
37
40
  if (allowance.ok) {
38
41
  return allowance.value;
39
42
  }
40
43
  return false;
41
44
  },
42
45
  enabled: !!spokeProvider && !!params,
46
+ refetchInterval: 2000,
43
47
  });
44
48
  }
@@ -1,11 +1,9 @@
1
1
  import { useSodaxContext } from '../shared/useSodaxContext';
2
- import type { Token } from '@sodax/types';
3
- import { type Address, parseUnits } from 'viem';
4
2
  import { useMutation, useQueryClient } from '@tanstack/react-query';
5
- import type { SpokeProvider } from '@sodax/sdk';
3
+ import type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';
6
4
 
7
5
  interface UseApproveReturn {
8
- approve: ({ amount }: { amount: string }) => Promise<boolean>;
6
+ approve: ({ params }: { params: CreateIntentParams }) => Promise<boolean>;
9
7
  isLoading: boolean;
10
8
  error: Error | null;
11
9
  resetError: () => void;
@@ -25,7 +23,10 @@ interface UseApproveReturn {
25
23
  * ```
26
24
  */
27
25
 
28
- export function useSwapApprove(token: Token | undefined, spokeProvider: SpokeProvider | undefined): UseApproveReturn {
26
+ export function useSwapApprove(
27
+ params: CreateIntentParams | undefined,
28
+ spokeProvider: SpokeProvider | undefined,
29
+ ): UseApproveReturn {
29
30
  const { sodax } = useSodaxContext();
30
31
  const queryClient = useQueryClient();
31
32
 
@@ -35,27 +36,26 @@ export function useSwapApprove(token: Token | undefined, spokeProvider: SpokePro
35
36
  error,
36
37
  reset: resetError,
37
38
  } = useMutation({
38
- mutationFn: async ({ amount }: { amount: string }) => {
39
+ mutationFn: async ({ params }: { params: CreateIntentParams | undefined }) => {
39
40
  if (!spokeProvider) {
40
41
  throw new Error('Spoke provider not found');
41
42
  }
42
- if (!token) {
43
- throw new Error('Token not found');
43
+ if (!params) {
44
+ throw new Error('Swap Params not found');
44
45
  }
45
46
 
46
- const allowance = await sodax.solver.approve(
47
- token.address as Address,
48
- parseUnits(amount, token.decimals),
47
+ const allowance = await sodax.swaps.approve({
48
+ intentParams: params,
49
49
  spokeProvider,
50
- );
50
+ });
51
51
  if (!allowance.ok) {
52
- throw new Error('Failed to approve tokens');
52
+ throw new Error('Failed to approve input token');
53
53
  }
54
54
  return allowance.ok;
55
55
  },
56
56
  onSuccess: () => {
57
57
  // Invalidate allowance query to refetch the new allowance
58
- queryClient.invalidateQueries({ queryKey: ['allowance', token?.address] });
58
+ queryClient.invalidateQueries({ queryKey: ['allowance', params] });
59
59
  },
60
60
  });
61
61
 
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './hooks';
2
2
  export * from './providers';
3
- export * from './core';
@@ -1,31 +1,19 @@
1
1
  import type { ReactNode, ReactElement } from 'react';
2
- import { EvmHubProvider, getHubChainConfig, Sodax, type SodaxConfig } from '@sodax/sdk';
2
+ import React from 'react';
3
+
4
+ import { Sodax, type SodaxConfig } from '@sodax/sdk';
3
5
  import { SodaxContext } from '@/contexts';
4
- import React, { useMemo } 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
- 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>;
18
+ return <SodaxContext.Provider value={{ sodax, testnet, rpcConfig }}>{children}</SodaxContext.Provider>;
31
19
  };
@@ -1,8 +0,0 @@
1
- import type { EvmHubProvider, Sodax } from '@sodax/sdk';
2
- export interface SodaxContextType {
3
- sodax: Sodax;
4
- testnet: boolean;
5
- hubProvider: EvmHubProvider | undefined;
6
- }
7
- export declare const SodaxContext: import("react").Context<SodaxContextType | null>;
8
- //# 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,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC;CACzC;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 | undefined;
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,uBAK/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,10 +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
- export * from './useReservesData';
8
- export * from './useMMAllowance';
9
- export * from './useMMApprove';
10
- //# 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;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -1,35 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- import { type UseMutationResult } from '@tanstack/react-query';
3
- import type { SpokeProvider } from '@sodax/sdk';
4
- interface BorrowResponse {
5
- ok: true;
6
- value: [`0x${string}`, `0x${string}`];
7
- }
8
- /**
9
- * Hook for borrowing tokens from the Sodax money market.
10
- *
11
- * This hook provides functionality to borrow tokens from the money market protocol,
12
- * handling the entire borrow process including transaction creation, submission,
13
- * and cross-chain communication.
14
- *
15
- * @param {XToken} spokeToken - The token to borrow from the spoke chain. Must be an XToken with valid address and chain information.
16
- * @param {SpokeProvider} spokeProvider - The spoke provider to use for the borrow transaction. Must be a valid SpokeProvider instance.
17
- *
18
- * @returns {UseMutationResult<BorrowResponse, Error, string>} A mutation result object with the following properties:
19
- * - mutateAsync: Function to execute the borrow transaction
20
- * - isPending: Boolean indicating if a transaction is in progress
21
- * - error: Error object if the last transaction failed, null otherwise
22
- *
23
- * @example
24
- * ```typescript
25
- * const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);
26
- * await borrow('100');
27
- * ```
28
- *
29
- * @throws {Error} When:
30
- * - spokeProvider is not available
31
- * - Transaction execution fails
32
- */
33
- export declare function useBorrow(spokeToken: XToken, spokeProvider: SpokeProvider | undefined): UseMutationResult<BorrowResponse, Error, string>;
34
- export {};
35
- //# 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,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,UAAU,cAAc;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,MAAM,CAAC,CA0BlD"}
@@ -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,26 +0,0 @@
1
- import { type UseQueryResult } from '@tanstack/react-query';
2
- import type { XToken } from '@sodax/types';
3
- import type { MoneyMarketAction, SpokeProvider } from '@sodax/sdk';
4
- /**
5
- * Hook for checking token allowance for money market operations.
6
- *
7
- * This hook verifies if the user has approved enough tokens for a specific money market action
8
- * (borrow/repay). It automatically queries and tracks the allowance status.
9
- *
10
- * @param {XToken} token - The token to check allowance for. Must be an XToken with valid address and chain information.
11
- * @param {string} amount - The amount to check allowance for, as a decimal string
12
- * @param {MoneyMarketAction} action - The money market action to check allowance for ('borrow' or 'repay')
13
- * @param {SpokeProvider} spokeProvider - The spoke provider to use for allowance checks
14
- *
15
- * @returns {UseQueryResult<boolean, Error>} A React Query result containing:
16
- * - data: Boolean indicating if allowance is sufficient
17
- * - isLoading: Loading state indicator
18
- * - error: Any error that occurred during the check
19
- *
20
- * @example
21
- * ```typescript
22
- * const { data: hasAllowed, isLoading } = useMMAllowance(token, "100", "repay", provider);
23
- * ```
24
- */
25
- export declare function useMMAllowance(token: XToken, amount: string, action: MoneyMarketAction, spokeProvider: SpokeProvider | undefined): UseQueryResult<boolean, Error>;
26
- //# sourceMappingURL=useMMAllowance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMMAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useMMAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAsBhC"}
@@ -1,27 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- import type { MoneyMarketAction, SpokeProvider } 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
- /**
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 } = useMMApprove(token, spokeProvider);
20
- *
21
- * // Approve tokens for supply action
22
- * await approve({ amount: "100", action: "supply" });
23
- * ```
24
- */
25
- export declare function useMMApprove(token: XToken, spokeProvider: SpokeProvider | undefined): UseApproveReturn;
26
- export {};
27
- //# sourceMappingURL=useMMApprove.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMMApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useMMApprove.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnE,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;;;;;;;;;;;;GAYG;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,SAAS,GAAG,gBAAgB,CAuCtG"}
@@ -1,35 +0,0 @@
1
- import type { SpokeProvider } from '@sodax/sdk';
2
- import type { XToken } from '@sodax/types';
3
- import { type UseMutationResult } from '@tanstack/react-query';
4
- interface RepayResponse {
5
- ok: true;
6
- value: [`0x${string}`, `0x${string}`];
7
- }
8
- /**
9
- * Hook for repaying borrowed tokens to the Sodax money market.
10
- *
11
- * This hook provides functionality to repay borrowed tokens back to the money market protocol,
12
- * handling the entire repayment process including transaction creation, submission,
13
- * and cross-chain communication.
14
- *
15
- * @param {XToken} spokeToken - The token to repay on the spoke chain. Must be an XToken with valid address and chain information.
16
- * @param {SpokeProvider} spokeProvider - The spoke provider to use for the repay transaction. Must be a valid SpokeProvider instance.
17
- *
18
- * @returns {UseMutationResult<RepayResponse, Error, string>} A mutation result object with the following properties:
19
- * - mutateAsync: Function to execute the repay transaction
20
- * - isPending: Boolean indicating if a transaction is in progress
21
- * - error: Error object if the last transaction failed, null otherwise
22
- *
23
- * @example
24
- * ```typescript
25
- * const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);
26
- * await repay('100');
27
- * ```
28
- *
29
- * @throws {Error} When:
30
- * - spokeProvider is not available
31
- * - Transaction execution fails
32
- */
33
- export declare function useRepay(spokeToken: XToken, spokeProvider: SpokeProvider | undefined): UseMutationResult<RepayResponse, Error, string>;
34
- export {};
35
- //# sourceMappingURL=useRepay.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRepay.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useRepay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI5E,UAAU,aAAa;IACrB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,CA0BjD"}
@@ -1,19 +0,0 @@
1
- /**
2
- * Hook for fetching reserves data from the Sodax money market.
3
- *
4
- * This hook provides access to the current state of all reserves in the money market protocol,
5
- * including liquidity, interest rates, and other key metrics. The data is automatically
6
- * fetched and cached using React Query.
7
- *
8
- * @example
9
- * ```typescript
10
- * const { data: reservesData, isLoading, error } = useReservesData();
11
- * ```
12
- *
13
- * @returns A React Query result object containing:
14
- * - data: The reserves data when available
15
- * - isLoading: Loading state indicator
16
- * - error: Any error that occurred during data fetching
17
- */
18
- export declare function useReservesData(): import("@tanstack/react-query").UseQueryResult<readonly [readonly import("@sodax/sdk").AggregatedReserveData[], import("@sodax/sdk").BaseCurrencyInfo], Error>;
19
- //# sourceMappingURL=useReservesData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesData.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,eAAe,mKAc9B"}