@sodax/dapp-kit 1.5.7-beta → 2.0.0-rc.2

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 (202) hide show
  1. package/README.md +300 -422
  2. package/ai-exported/AGENTS.md +134 -0
  3. package/ai-exported/integration/README.md +49 -0
  4. package/ai-exported/integration/ai-rules.md +79 -0
  5. package/ai-exported/integration/architecture.md +274 -0
  6. package/ai-exported/integration/features/README.md +29 -0
  7. package/ai-exported/integration/features/auxiliary-services.md +169 -0
  8. package/ai-exported/integration/features/bitcoin.md +87 -0
  9. package/ai-exported/integration/features/bridge.md +91 -0
  10. package/ai-exported/integration/features/dex.md +152 -0
  11. package/ai-exported/integration/features/migration.md +118 -0
  12. package/ai-exported/integration/features/money-market.md +116 -0
  13. package/ai-exported/integration/features/staking.md +123 -0
  14. package/ai-exported/integration/features/swap.md +101 -0
  15. package/ai-exported/integration/quickstart.md +187 -0
  16. package/ai-exported/integration/recipes/README.md +136 -0
  17. package/ai-exported/integration/recipes/backend-queries.md +157 -0
  18. package/ai-exported/integration/recipes/bitcoin.md +193 -0
  19. package/ai-exported/integration/recipes/bridge.md +174 -0
  20. package/ai-exported/integration/recipes/dex.md +204 -0
  21. package/ai-exported/integration/recipes/invalidations.md +115 -0
  22. package/ai-exported/integration/recipes/migration.md +212 -0
  23. package/ai-exported/integration/recipes/money-market.md +206 -0
  24. package/ai-exported/integration/recipes/mutation-error-handling.md +118 -0
  25. package/ai-exported/integration/recipes/observability.md +93 -0
  26. package/ai-exported/integration/recipes/setup.md +144 -0
  27. package/ai-exported/integration/recipes/staking.md +202 -0
  28. package/ai-exported/integration/recipes/swap.md +272 -0
  29. package/ai-exported/integration/recipes/wallet-connectivity.md +101 -0
  30. package/ai-exported/integration/reference/README.md +12 -0
  31. package/ai-exported/integration/reference/glossary.md +188 -0
  32. package/ai-exported/integration/reference/hooks-index.md +190 -0
  33. package/ai-exported/integration/reference/public-api.md +110 -0
  34. package/ai-exported/integration/reference/querykey-conventions.md +179 -0
  35. package/ai-exported/migration/README.md +60 -0
  36. package/ai-exported/migration/ai-rules.md +81 -0
  37. package/ai-exported/migration/breaking-changes/hook-signatures.md +233 -0
  38. package/ai-exported/migration/breaking-changes/querykey-conventions.md +108 -0
  39. package/ai-exported/migration/breaking-changes/result-handling.md +211 -0
  40. package/ai-exported/migration/breaking-changes/sdk-leakage.md +165 -0
  41. package/ai-exported/migration/checklist.md +89 -0
  42. package/ai-exported/migration/features/README.md +34 -0
  43. package/ai-exported/migration/features/auxiliary-services.md +114 -0
  44. package/ai-exported/migration/features/bitcoin.md +88 -0
  45. package/ai-exported/migration/features/bridge.md +123 -0
  46. package/ai-exported/migration/features/dex.md +101 -0
  47. package/ai-exported/migration/features/migration.md +120 -0
  48. package/ai-exported/migration/features/money-market.md +97 -0
  49. package/ai-exported/migration/features/staking.md +109 -0
  50. package/ai-exported/migration/features/swap.md +118 -0
  51. package/ai-exported/migration/recipes.md +188 -0
  52. package/ai-exported/migration/reference/README.md +15 -0
  53. package/ai-exported/migration/reference/deleted-hooks.md +110 -0
  54. package/ai-exported/migration/reference/error-shape-crosswalk.md +144 -0
  55. package/ai-exported/migration/reference/renamed-hooks.md +66 -0
  56. package/dist/index.cjs +2642 -0
  57. package/dist/index.cjs.map +1 -0
  58. package/dist/index.d.cts +1550 -0
  59. package/dist/index.d.ts +1020 -2051
  60. package/dist/index.mjs +1581 -1531
  61. package/dist/index.mjs.map +1 -1
  62. package/package.json +21 -11
  63. package/src/contexts/index.ts +0 -3
  64. package/src/hooks/_mutationContract.test.ts +99 -0
  65. package/src/hooks/backend/README.md +2 -2
  66. package/src/hooks/backend/index.ts +13 -13
  67. package/src/hooks/backend/unwrapResult.ts +1 -0
  68. package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +13 -45
  69. package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +29 -59
  70. package/src/hooks/backend/useBackendIntentByHash.ts +21 -47
  71. package/src/hooks/backend/useBackendIntentByTxHash.ts +23 -50
  72. package/src/hooks/backend/useBackendMoneyMarketAsset.ts +21 -54
  73. package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +30 -57
  74. package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +31 -58
  75. package/src/hooks/backend/useBackendMoneyMarketPosition.ts +22 -38
  76. package/src/hooks/backend/useBackendOrderbook.ts +27 -49
  77. package/src/hooks/backend/useBackendSubmitSwapTx.ts +30 -36
  78. package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +38 -58
  79. package/src/hooks/backend/useBackendUserIntents.ts +25 -63
  80. package/src/hooks/bitcoin/index.ts +9 -8
  81. package/src/hooks/bitcoin/useBitcoinBalance.ts +20 -5
  82. package/src/hooks/bitcoin/useExpiredUtxos.ts +26 -16
  83. package/src/hooks/bitcoin/useFundTradingWallet.ts +33 -30
  84. package/src/hooks/bitcoin/useRadfiAuth.ts +43 -40
  85. package/src/hooks/bitcoin/useRadfiSession.ts +53 -59
  86. package/src/hooks/bitcoin/useRadfiWithdraw.ts +35 -53
  87. package/src/hooks/bitcoin/useRenewUtxos.ts +30 -50
  88. package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
  89. package/src/hooks/bitcoin/useTradingWalletBalance.ts +25 -14
  90. package/src/hooks/bridge/index.ts +5 -5
  91. package/src/hooks/bridge/useBridge.ts +29 -55
  92. package/src/hooks/bridge/useBridgeAllowance.ts +38 -38
  93. package/src/hooks/bridge/useBridgeApprove.ts +32 -57
  94. package/src/hooks/bridge/useGetBridgeableAmount.ts +23 -37
  95. package/src/hooks/bridge/useGetBridgeableTokens.ts +27 -50
  96. package/src/hooks/dex/index.ts +16 -16
  97. package/src/hooks/dex/useClaimRewards.ts +35 -54
  98. package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +7 -20
  99. package/src/hooks/dex/useCreateDepositParams.ts +7 -21
  100. package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +13 -28
  101. package/src/hooks/dex/useCreateWithdrawParams.ts +7 -20
  102. package/src/hooks/dex/useDecreaseLiquidity.ts +40 -66
  103. package/src/hooks/dex/useDexAllowance.ts +29 -75
  104. package/src/hooks/dex/useDexApprove.ts +32 -43
  105. package/src/hooks/dex/useDexDeposit.ts +42 -49
  106. package/src/hooks/dex/useDexWithdraw.ts +32 -43
  107. package/src/hooks/dex/useLiquidityAmounts.ts +13 -82
  108. package/src/hooks/dex/usePoolBalances.ts +50 -72
  109. package/src/hooks/dex/usePoolData.ts +17 -43
  110. package/src/hooks/dex/usePools.ts +11 -38
  111. package/src/hooks/dex/usePositionInfo.ts +27 -62
  112. package/src/hooks/dex/useSupplyLiquidity.ts +80 -75
  113. package/src/hooks/index.ts +12 -10
  114. package/src/hooks/migrate/index.ts +13 -4
  115. package/src/hooks/migrate/useMigrateBaln.ts +42 -0
  116. package/src/hooks/migrate/useMigrateIcxToSoda.ts +44 -0
  117. package/src/hooks/migrate/useMigratebnUSD.ts +47 -0
  118. package/src/hooks/migrate/useMigrationAllowance.ts +76 -0
  119. package/src/hooks/migrate/useMigrationApprove.ts +66 -0
  120. package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +39 -0
  121. package/src/hooks/mm/index.ts +14 -12
  122. package/src/hooks/mm/useAToken.ts +25 -41
  123. package/src/hooks/mm/useATokensBalances.ts +29 -60
  124. package/src/hooks/mm/useBorrow.ts +38 -56
  125. package/src/hooks/mm/useMMAllowance.ts +37 -73
  126. package/src/hooks/mm/useMMApprove.ts +36 -43
  127. package/src/hooks/mm/useRepay.ts +33 -53
  128. package/src/hooks/mm/useReservesData.ts +12 -38
  129. package/src/hooks/mm/useReservesHumanized.ts +12 -31
  130. package/src/hooks/mm/useReservesList.ts +11 -31
  131. package/src/hooks/mm/useReservesUsdFormat.ts +15 -35
  132. package/src/hooks/mm/useSupply.ts +45 -51
  133. package/src/hooks/mm/useUserFormattedSummary.ts +32 -84
  134. package/src/hooks/mm/useUserReservesData.ts +27 -77
  135. package/src/hooks/mm/useWithdraw.ts +38 -54
  136. package/src/hooks/partner/index.ts +6 -0
  137. package/src/hooks/partner/useApproveToken.ts +42 -0
  138. package/src/hooks/partner/useFeeClaimSwap.ts +38 -0
  139. package/src/hooks/partner/useFetchAssetsBalances.ts +37 -0
  140. package/src/hooks/partner/useGetAutoSwapPreferences.ts +37 -0
  141. package/src/hooks/partner/useIsTokenApproved.ts +39 -0
  142. package/src/hooks/partner/useSetSwapPreference.ts +50 -0
  143. package/src/hooks/provider/index.ts +1 -2
  144. package/src/hooks/provider/useHubProvider.ts +1 -1
  145. package/src/hooks/recovery/index.ts +2 -0
  146. package/src/hooks/recovery/useHubAssetBalances.ts +43 -0
  147. package/src/hooks/recovery/useWithdrawHubAsset.ts +48 -0
  148. package/src/hooks/shared/index.ts +10 -6
  149. package/src/hooks/shared/types.ts +77 -0
  150. package/src/hooks/shared/unwrapResult.ts +19 -0
  151. package/src/hooks/shared/useDeriveUserWalletAddress.ts +22 -40
  152. package/src/hooks/shared/useEstimateGas.ts +18 -15
  153. package/src/hooks/shared/useGetUserHubWalletAddress.ts +25 -26
  154. package/src/hooks/shared/useRequestTrustline.ts +28 -61
  155. package/src/hooks/shared/useSafeMutation.test.ts +43 -0
  156. package/src/hooks/shared/useSafeMutation.ts +68 -0
  157. package/src/hooks/shared/useSodaxContext.ts +1 -1
  158. package/src/hooks/shared/useStellarTrustlineCheck.ts +30 -64
  159. package/src/hooks/shared/useXBalances.test.ts +113 -0
  160. package/src/hooks/shared/useXBalances.ts +61 -0
  161. package/src/hooks/staking/index.ts +18 -18
  162. package/src/hooks/staking/useCancelUnstake.ts +30 -41
  163. package/src/hooks/staking/useClaim.ts +27 -36
  164. package/src/hooks/staking/useConvertedAssets.ts +24 -34
  165. package/src/hooks/staking/useInstantUnstake.ts +33 -40
  166. package/src/hooks/staking/useInstantUnstakeAllowance.ts +37 -45
  167. package/src/hooks/staking/useInstantUnstakeApprove.ts +42 -42
  168. package/src/hooks/staking/useInstantUnstakeRatio.ts +24 -41
  169. package/src/hooks/staking/useStake.ts +32 -37
  170. package/src/hooks/staking/useStakeAllowance.ts +30 -43
  171. package/src/hooks/staking/useStakeApprove.ts +40 -40
  172. package/src/hooks/staking/useStakeRatio.ts +24 -40
  173. package/src/hooks/staking/useStakingConfig.ts +14 -27
  174. package/src/hooks/staking/useStakingInfo.ts +30 -38
  175. package/src/hooks/staking/useUnstake.ts +29 -43
  176. package/src/hooks/staking/useUnstakeAllowance.ts +37 -44
  177. package/src/hooks/staking/useUnstakeApprove.ts +40 -43
  178. package/src/hooks/staking/useUnstakingInfo.ts +29 -41
  179. package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +31 -47
  180. package/src/hooks/swap/index.ts +8 -8
  181. package/src/hooks/swap/useCancelLimitOrder.ts +24 -41
  182. package/src/hooks/swap/useCancelSwap.ts +24 -33
  183. package/src/hooks/swap/useCreateLimitOrder.ts +29 -62
  184. package/src/hooks/swap/useQuote.ts +17 -43
  185. package/src/hooks/swap/useStatus.ts +22 -29
  186. package/src/hooks/swap/useSwap.ts +31 -49
  187. package/src/hooks/swap/useSwapAllowance.ts +38 -35
  188. package/src/hooks/swap/useSwapApprove.ts +48 -57
  189. package/src/index.ts +5 -3
  190. package/src/providers/SodaxProvider.tsx +17 -11
  191. package/src/providers/createSodaxQueryClient.ts +96 -0
  192. package/src/providers/index.ts +2 -1
  193. package/src/utils/dex-utils.ts +27 -5
  194. package/src/utils/index.ts +1 -1
  195. package/dist/index.d.mts +0 -2581
  196. package/dist/index.js +0 -2574
  197. package/dist/index.js.map +0 -1
  198. package/src/hooks/migrate/types.ts +0 -15
  199. package/src/hooks/migrate/useMigrate.tsx +0 -110
  200. package/src/hooks/migrate/useMigrationAllowance.tsx +0 -79
  201. package/src/hooks/migrate/useMigrationApprove.tsx +0 -129
  202. package/src/hooks/provider/useSpokeProvider.ts +0 -172
@@ -1,68 +1,43 @@
1
- import { useSodaxContext } from '../shared/useSodaxContext';
2
- import type { CreateBridgeIntentParams, SpokeProvider } from '@sodax/sdk';
3
- import { useMutation, useQueryClient } from '@tanstack/react-query';
1
+ // packages/dapp-kit/src/hooks/bridge/useBridgeApprove.ts
2
+ import type { BridgeParams, SpokeChainKey, TxReturnType } from '@sodax/sdk';
3
+ import { useQueryClient } from '@tanstack/react-query';
4
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
5
+ import type { MutationHookParams } from '../shared/types.js';
6
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
7
+ import { unwrapResult } from '../shared/unwrapResult.js';
4
8
 
5
- interface UseBridgeApproveReturn {
6
- approve: (params: CreateBridgeIntentParams) => Promise<boolean>;
7
- isLoading: boolean;
8
- error: Error | null;
9
- resetError: () => void;
10
- }
9
+ /**
10
+ * Mutation variables for {@link useBridgeApprove}. Generic over `K extends SpokeChainKey`
11
+ * (defaults to the full union). Sophisticated callers can lock K at the hook call site to narrow
12
+ * the `walletProvider` and `params.srcChainKey` types.
13
+ */
14
+ export type UseBridgeApproveVars<K extends SpokeChainKey = SpokeChainKey> = Omit<BridgeParams<K, false>, 'raw'>;
11
15
 
12
16
  /**
13
- * Hook for approving token spending for bridge actions
14
- * @param spokeProvider The spoke provider instance for the chain
15
- * @returns Object containing approve function, loading state, error state and reset function
16
- * @example
17
- * ```tsx
18
- * const { approve, isLoading, error } = useBridgeApprove(spokeProvider);
17
+ * React hook for approving ERC-20 token spending (or trustline establishment) for a bridge
18
+ * action.
19
19
  *
20
- * // Approve tokens for bridge action
21
- * await approve({
22
- * srcChainId: '0x2105.base',
23
- * srcAsset: '0x...',
24
- * amount: 1000n,
25
- * dstChainId: '0x89.polygon',
26
- * dstAsset: '0x...',
27
- * recipient: '0x...'
28
- * });
29
- * ```
20
+ * Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
21
+ * `onError`, `retry`). Returns the unwrapped tx return value on success. Invalidates all
22
+ * `['bridge', 'allowance', ...]` queries so any pending allowance check refreshes.
30
23
  */
31
- export function useBridgeApprove(spokeProvider: SpokeProvider | undefined): UseBridgeApproveReturn {
24
+ export function useBridgeApprove<K extends SpokeChainKey = SpokeChainKey>({
25
+ mutationOptions,
26
+ }: MutationHookParams<TxReturnType<K, false>, UseBridgeApproveVars<K>> = {}): SafeUseMutationResult<
27
+ TxReturnType<K, false>,
28
+ Error,
29
+ UseBridgeApproveVars<K>
30
+ > {
32
31
  const { sodax } = useSodaxContext();
33
32
  const queryClient = useQueryClient();
34
33
 
35
- const {
36
- mutateAsync: approve,
37
- isPending,
38
- error,
39
- reset: resetError,
40
- } = useMutation({
41
- mutationFn: async (params: CreateBridgeIntentParams) => {
42
- if (!spokeProvider) {
43
- throw new Error('Spoke provider not found');
44
- }
45
-
46
- const allowance = await sodax.bridge.approve({
47
- params,
48
- spokeProvider,
49
- });
50
-
51
- if (!allowance.ok) {
52
- throw new Error('Failed to approve tokens for bridge');
53
- }
54
- return true;
55
- },
56
- onSuccess: (_, params) => {
57
- // Invalidate allowance query to refetch the new allowance
58
- queryClient.invalidateQueries({ queryKey: ['bridge-allowance', params] });
34
+ return useSafeMutation<TxReturnType<K, false>, Error, UseBridgeApproveVars<K>>({
35
+ mutationKey: ['bridge', 'approve'],
36
+ ...mutationOptions,
37
+ mutationFn: async vars => unwrapResult(await sodax.bridge.approve({ ...vars, raw: false } as BridgeParams<K, false>)),
38
+ onSuccess: async (data, vars, ctx) => {
39
+ queryClient.invalidateQueries({ queryKey: ['bridge', 'allowance'] });
40
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
59
41
  },
60
42
  });
61
-
62
- return {
63
- approve,
64
- isLoading: isPending,
65
- error: error,
66
- resetError,
67
- };
68
43
  }
@@ -1,51 +1,37 @@
1
1
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
- import { useSodaxContext } from '../shared/useSodaxContext';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
3
  import type { BridgeLimit, XToken } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
4
5
 
5
- /**
6
- * Hook for getting the amount available to be bridged.
7
- *
8
- * This hook is used to check if a target chain has enough balance to bridge when bridging.
9
- * It automatically queries and tracks the available amount to be bridged.
10
- *
11
- * @param {SpokeChainId | undefined} chainId - The chain ID to get the balance for
12
- * @param {string | undefined} token - The token address to get the balance for
13
- *
14
- * @returns {UseQueryResult<BridgeLimit, Error>} A React Query result containing:
15
- * - data: Data about available amount to be bridged
16
- * - error: Any error that occurred during the check
17
- *
18
- * @example
19
- * ```typescript
20
- * const { data: balance, isLoading } = useSpokeAssetManagerTokenBalance(chainId, tokenAddress);
21
- *
22
- * if (balance) {
23
- * console.log('Asset manager token balance:', balance.toString());
24
- * }
25
- * ```
26
- */
27
- export function useGetBridgeableAmount(
28
- from: XToken | undefined,
29
- to: XToken | undefined,
30
- ): UseQueryResult<BridgeLimit, Error> {
6
+ export type UseGetBridgeableAmountParams = ReadHookParams<
7
+ BridgeLimit,
8
+ {
9
+ from: XToken | undefined;
10
+ to: XToken | undefined;
11
+ }
12
+ >;
13
+
14
+ export function useGetBridgeableAmount({
15
+ params,
16
+ queryOptions,
17
+ }: UseGetBridgeableAmountParams = {}): UseQueryResult<BridgeLimit, Error> {
31
18
  const { sodax } = useSodaxContext();
19
+ const from = params?.from;
20
+ const to = params?.to;
32
21
 
33
- return useQuery({
34
- queryKey: ['spoke-asset-manager-token-balance', from, to],
22
+ return useQuery<BridgeLimit, Error>({
23
+ queryKey: ['bridge', 'bridgeableAmount', from, to],
35
24
  queryFn: async () => {
36
25
  if (!from || !to) {
37
- return { amount: 0n, decimals: 0, type: 'DEPOSIT_LIMIT' } as const;
26
+ throw new Error('from and to tokens are required');
38
27
  }
39
-
40
28
  const result = await sodax.bridge.getBridgeableAmount(from, to);
41
-
42
- if (result.ok) {
43
- return result.value;
29
+ if (!result.ok) {
30
+ throw result.error;
44
31
  }
45
-
46
- console.error('Error getting bridgeable amount:', result.error);
47
- return { amount: 0n, decimals: 0, type: 'DEPOSIT_LIMIT' } as const;
32
+ return result.value;
48
33
  },
49
34
  enabled: !!from && !!to,
35
+ ...queryOptions,
50
36
  });
51
37
  }
@@ -1,62 +1,39 @@
1
1
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
- import type { XToken, SpokeChainId } from '@sodax/sdk';
3
- import { useSodaxContext } from '../shared';
2
+ import type { XToken, SpokeChainKey } from '@sodax/sdk';
3
+ import { useSodaxContext } from '../shared/index.js';
4
+ import type { ReadHookParams } from '../shared/types.js';
4
5
 
5
- /**
6
- /**
7
- * Hook for retrieving all bridgeable tokens from a source token on one chain to a destination chain.
8
- *
9
- * This hook queries and tracks the set of tokens on the destination chain that can be bridged to,
10
- * given a source chain, destination chain, and source token address.
11
- *
12
- * @param {SpokeChainId | undefined} from - The source chain ID
13
- * @param {SpokeChainId | undefined} to - The destination chain ID
14
- * @param {string | undefined} token - The source token address
15
- *
16
- * @returns {UseQueryResult<XToken[], Error>} A React Query result containing:
17
- * - data: Array of bridgeable tokens (XToken[]) on the destination chain
18
- * - error: Any error that occurred during the query
19
- *
20
- *
21
- * @example
22
- * ```typescript
23
- * const { data: bridgeableTokens, isLoading } = useGetBridgeableTokens(
24
- * fromChainId,
25
- * toChainId,
26
- * fromTokenAddress
27
- * );
28
- *
29
- * if (bridgeableTokens && bridgeableTokens.length > 0) {
30
- * bridgeableTokens.forEach(token => {
31
- * console.log(`Bridgeable token: ${token.symbol} (${token.address}) on chain ${token.xChainId}`);
32
- * });
33
- * } else {
34
- * console.log('No bridgeable tokens found for the selected route.');
35
- * }
36
- * ```
37
- */
38
- export function useGetBridgeableTokens(
39
- from: SpokeChainId | undefined,
40
- to: SpokeChainId | undefined,
41
- token: string | undefined,
42
- ): UseQueryResult<XToken[], Error> {
6
+ export type UseGetBridgeableTokensParams = ReadHookParams<
7
+ XToken[],
8
+ {
9
+ from: SpokeChainKey | undefined;
10
+ to: SpokeChainKey | undefined;
11
+ token: string | undefined;
12
+ }
13
+ >;
14
+
15
+ export function useGetBridgeableTokens({
16
+ params,
17
+ queryOptions,
18
+ }: UseGetBridgeableTokensParams = {}): UseQueryResult<XToken[], Error> {
43
19
  const { sodax } = useSodaxContext();
20
+ const from = params?.from;
21
+ const to = params?.to;
22
+ const token = params?.token;
44
23
 
45
- return useQuery({
46
- queryKey: ['bridgeable-tokens', from, to, token],
47
- queryFn: async () => {
24
+ return useQuery<XToken[], Error>({
25
+ queryKey: ['bridge', 'bridgeableTokens', from, to, token],
26
+ queryFn: () => {
48
27
  if (!from || !to || !token) {
49
- return [];
28
+ throw new Error('from, to and token are required');
50
29
  }
51
-
52
30
  const result = sodax.bridge.getBridgeableTokens(from, to, token);
53
- if (result.ok) {
54
- return result.value;
31
+ if (!result.ok) {
32
+ throw result.error;
55
33
  }
56
-
57
- console.error('Error getting bridgeable tokens:', result.error);
58
- return [];
34
+ return result.value;
59
35
  },
60
36
  enabled: !!from && !!to && !!token,
37
+ ...queryOptions,
61
38
  });
62
39
  }
@@ -1,16 +1,16 @@
1
- export * from './usePools';
2
- export * from './usePoolData';
3
- export * from './usePoolBalances';
4
- export * from './usePositionInfo';
5
- export * from './useDexDeposit';
6
- export * from './useDexWithdraw';
7
- export * from './useDexAllowance';
8
- export * from './useDexApprove';
9
- export * from './useLiquidityAmounts';
10
- export * from './useSupplyLiquidity';
11
- export * from './useDecreaseLiquidity';
12
- export * from './useCreateDepositParams';
13
- export * from './useCreateSupplyLiquidityParams';
14
- export * from './useCreateDecreaseLiquidityParams';
15
- export * from './useCreateWithdrawParams';
16
- export * from './useClaimRewards';
1
+ export * from './usePools.js';
2
+ export * from './usePoolData.js';
3
+ export * from './usePoolBalances.js';
4
+ export * from './usePositionInfo.js';
5
+ export * from './useDexDeposit.js';
6
+ export * from './useDexWithdraw.js';
7
+ export * from './useDexAllowance.js';
8
+ export * from './useDexApprove.js';
9
+ export * from './useLiquidityAmounts.js';
10
+ export * from './useSupplyLiquidity.js';
11
+ export * from './useDecreaseLiquidity.js';
12
+ export * from './useCreateDepositParams.js';
13
+ export * from './useCreateSupplyLiquidityParams.js';
14
+ export * from './useCreateDecreaseLiquidityParams.js';
15
+ export * from './useCreateWithdrawParams.js';
16
+ export * from './useClaimRewards.js';
@@ -1,68 +1,49 @@
1
- import type {
2
- ConcentratedLiquidityClaimRewardsParams,
3
- ConcentratedLiquidityError,
4
- ConcentratedLiquidityErrorCode,
5
- SpokeProvider,
6
- SpokeTxHash,
7
- HubTxHash,
8
- } from '@sodax/sdk';
9
- import { useSodaxContext } from '../shared/useSodaxContext';
10
- import { useMutation, type UseMutationResult, useQueryClient } from '@tanstack/react-query';
1
+ // packages/dapp-kit/src/hooks/dex/useClaimRewards.ts
2
+ import type { ClLiquidityClaimRewardsAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
3
+ import { useQueryClient } from '@tanstack/react-query';
4
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
5
+ import type { MutationHookParams } from '../shared/types.js';
6
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
7
+ import { unwrapResult } from '../shared/unwrapResult.js';
11
8
 
12
- export type UseClaimRewardsParams = {
13
- params: ConcentratedLiquidityClaimRewardsParams;
14
- spokeProvider: SpokeProvider;
15
- };
9
+ /**
10
+ * Mutation variables for {@link useClaimRewards}. Generic over `K extends SpokeChainKey` (defaults
11
+ * to the full union). Sophisticated callers can lock K at the hook call site to narrow the
12
+ * `walletProvider` and `params.srcChainKey` types.
13
+ */
14
+ export type UseClaimRewardsVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
15
+ ClLiquidityClaimRewardsAction<K, false>,
16
+ 'raw'
17
+ >;
16
18
 
17
19
  /**
18
- * React hook for creating a mutation to claim DEX rewards for a concentrated liquidity position.
20
+ * React hook for claiming accrued fees on a concentrated-liquidity position.
19
21
  *
20
- * @returns {UseMutationResult<[SpokeTxHash, HubTxHash], ConcentratedLiquidityError<ConcentratedLiquidityErrorCode>, UseClaimRewardsParams>}
21
- * Returns a react-query mutation result object:
22
- * - On success: resolves to a tuple `[SpokeTxHash, HubTxHash]`.
23
- * - On error: the error is of type `ConcentratedLiquidityError<ConcentratedLiquidityErrorCode>`.
24
- * - The mutation function expects an argument of type {@link UseClaimRewardsParams}
25
- * containing `params` (the claim parameters) and `spokeProvider` (the target provider).
26
- * - On mutation success, invalidates the queries `'dex/poolBalances'` and `'dex/positionInfo'`.
27
- *
28
- * @example
29
- * const claimRewardsMutation = useClaimRewards();
30
- * claimRewardsMutation.mutateAsync({
31
- * params: { poolKey, tokenId, tickLower, tickUpper },
32
- * spokeProvider,
33
- * });
22
+ * Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
23
+ * `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
34
24
  */
35
- export function useClaimRewards(): UseMutationResult<
36
- [SpokeTxHash, HubTxHash],
37
- ConcentratedLiquidityError<ConcentratedLiquidityErrorCode>,
38
- UseClaimRewardsParams
25
+ export function useClaimRewards<K extends SpokeChainKey = SpokeChainKey>({
26
+ mutationOptions,
27
+ }: MutationHookParams<TxHashPair, UseClaimRewardsVars<K>> = {}): SafeUseMutationResult<
28
+ TxHashPair,
29
+ Error,
30
+ UseClaimRewardsVars<K>
39
31
  > {
40
32
  const { sodax } = useSodaxContext();
41
33
  const queryClient = useQueryClient();
42
34
 
43
- return useMutation({
44
- mutationFn: async ({ params, spokeProvider }: UseClaimRewardsParams) => {
45
- if (!spokeProvider) {
46
- throw new Error('Spoke provider is required');
47
- }
48
- const result = await sodax.dex.clService.claimRewards({
49
- params,
50
- spokeProvider,
51
- });
52
-
53
- if (!result.ok) {
54
- throw new Error(`Claim rewards failed: ${result.error?.code || 'Unknown error'}`);
55
- }
56
-
57
- return result.value;
58
- },
59
- onSuccess: (_, { params, spokeProvider }) => {
60
- // Invalidate relevant queries
35
+ return useSafeMutation<TxHashPair, Error, UseClaimRewardsVars<K>>({
36
+ mutationKey: ['dex', 'claimRewards'],
37
+ ...mutationOptions,
38
+ mutationFn: async vars => unwrapResult(await sodax.dex.clService.claimRewards({ ...vars, raw: false })),
39
+ onSuccess: async (data, vars, ctx) => {
40
+ const { params } = vars;
41
+ // `usePositionInfo` keys by string tokenId — stringify the bigint to keep the structural match.
61
42
  queryClient.invalidateQueries({
62
- queryKey: ['dex', 'poolBalances', params.poolKey, spokeProvider.chainConfig.chain.id],
43
+ queryKey: ['dex', 'positionInfo', params.tokenId.toString(), params.poolKey],
63
44
  });
64
- queryClient.invalidateQueries({ queryKey: ['dex', 'positionInfo', params.tokenId, params.poolKey] });
65
- queryClient.invalidateQueries({ queryKey: ['dex', 'poolData', params.poolKey] });
45
+ queryClient.invalidateQueries({ queryKey: ['dex', 'poolBalances', params.srcChainKey, params.srcAddress] });
46
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
66
47
  },
67
48
  });
68
49
  }
@@ -1,5 +1,5 @@
1
- import { createDecreaseLiquidityParamsProps } from '@/utils/dex-utils';
2
- import type { ClPositionInfo, ConcentratedLiquidityDecreaseLiquidityParams, PoolKey } from '@sodax/sdk';
1
+ import { createDecreaseLiquidityParamsProps, type DecreaseLiquidityParamsCore } from '@/utils/dex-utils.js';
2
+ import type { ClPositionInfo, PoolKey } from '@sodax/sdk';
3
3
  import { useMemo } from 'react';
4
4
 
5
5
  export type UseCreateDecreaseLiquidityParamsProps = {
@@ -10,23 +10,10 @@ export type UseCreateDecreaseLiquidityParamsProps = {
10
10
  slippageTolerance: string | number;
11
11
  };
12
12
 
13
-
14
13
  /**
15
- * React hook to create the decrease liquidity parameters for a given pool and position.
16
- *
17
- * Purpose:
18
- * - Provides a hook which memoizes the decrease liquidity parameters for a given pool and position.
19
- *
20
- * Usage:
21
- * - Call the function with the pool key, token ID, percentage, position info, and slippage tolerance to create the decrease liquidity parameters.
22
- *
23
- * Params:
24
- * @param poolKey - The pool key of the pool to decrease the liquidity from.
25
- * @param tokenId - The token ID of the position to decrease the liquidity from.
26
- * @param percentage - The percentage of liquidity to decrease.
27
- * @param positionInfo - The position info of the position to decrease the liquidity from.
28
- * @param slippageTolerance - The slippage tolerance to use for the decrease.
29
- * @returns The decrease liquidity parameters.
14
+ * React hook to memoize the decrease-liquidity-specific subset of {@link ClDecreaseLiquidityParams}
15
+ * (`{ poolKey, tokenId, liquidity, amount0Min, amount1Min }`). Callers add `srcChainKey` +
16
+ * `srcAddress` at the mutation call site.
30
17
  */
31
18
  export function useCreateDecreaseLiquidityParams({
32
19
  poolKey,
@@ -34,8 +21,8 @@ export function useCreateDecreaseLiquidityParams({
34
21
  percentage,
35
22
  positionInfo,
36
23
  slippageTolerance,
37
- }: UseCreateDecreaseLiquidityParamsProps): ConcentratedLiquidityDecreaseLiquidityParams {
38
- return useMemo<ConcentratedLiquidityDecreaseLiquidityParams>(() => {
24
+ }: UseCreateDecreaseLiquidityParamsProps): DecreaseLiquidityParamsCore {
25
+ return useMemo<DecreaseLiquidityParamsCore>(() => {
39
26
  return createDecreaseLiquidityParamsProps({ poolKey, tokenId, percentage, positionInfo, slippageTolerance });
40
27
  }, [poolKey, tokenId, percentage, positionInfo, slippageTolerance]);
41
28
  }
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from 'react';
2
- import type { CreateAssetDepositParams, PoolData, PoolSpokeAssets } from '@sodax/sdk';
3
- import { createDepositParamsProps } from '@/utils/dex-utils';
2
+ import type { PoolData, PoolSpokeAssets } from '@sodax/sdk';
3
+ import { createDepositParamsProps, type DepositParamsCore } from '@/utils/dex-utils.js';
4
4
 
5
5
  export type UseCreateDepositParamsProps = {
6
6
  tokenIndex: 0 | 1;
@@ -9,35 +9,21 @@ export type UseCreateDepositParamsProps = {
9
9
  poolSpokeAssets: PoolSpokeAssets;
10
10
  };
11
11
 
12
-
13
12
  /**
14
- * React hook to create the deposit parameters for a given pool and token.
15
- *
16
- * Purpose:
17
- * - Provides a hook which memoizes the deposit parameters for a given pool and token.
18
- *
19
- * Usage:
20
- * - Call the function with the token index, amount, pool data, pool key, and spoke provider to create the deposit parameters.
21
- *
22
- * Params:
23
- * @param tokenIndex - The index of the token to deposit.
24
- * @param amount - The amount of the token to deposit.
25
- * @param poolData - The pool data of the pool to deposit to.
26
- * @param poolKey - The pool key of the pool to deposit to.
27
- * @param spokeProvider - The spoke provider to use for the deposit.
28
- * @returns The deposit parameters or undefined if the pool key, spoke provider, or amount is not set.
13
+ * React hook to memoize the deposit-specific subset of {@link CreateAssetDepositParams}
14
+ * (`{ asset, amount, poolToken, dst? }`). Callers add `srcChainKey` + `srcAddress` at the mutation
15
+ * call site.
29
16
  */
30
17
  export function useCreateDepositParams({
31
18
  tokenIndex,
32
19
  amount,
33
20
  poolData,
34
21
  poolSpokeAssets,
35
- }: UseCreateDepositParamsProps): CreateAssetDepositParams | undefined {
36
- return useMemo<CreateAssetDepositParams | undefined>(() => {
22
+ }: UseCreateDepositParamsProps): DepositParamsCore | undefined {
23
+ return useMemo<DepositParamsCore | undefined>(() => {
37
24
  if (!amount || Number.parseFloat(String(amount)) <= 0) {
38
25
  return undefined;
39
26
  }
40
-
41
27
  return createDepositParamsProps({ tokenIndex, amount, poolData, poolSpokeAssets });
42
28
  }, [tokenIndex, amount, poolData, poolSpokeAssets]);
43
29
  }
@@ -1,10 +1,6 @@
1
- import { createSupplyLiquidityParamsProps } from '@/utils/dex-utils';
2
- import type {
3
- ConcentratedLiquiditySupplyParams,
4
- ConcentratedLiquidityIncreaseLiquidityParams,
5
- PoolData,
6
- PoolKey,
7
- } from '@sodax/sdk';
1
+ import { createSupplyLiquidityParamsProps } from '@/utils/dex-utils.js';
2
+ import type { ClSupplyParams, ClIncreaseLiquidityParams, PoolData, PoolKey } from '@sodax/sdk';
3
+ import type { SpokeChainKey } from '@sodax/sdk';
8
4
  import { useMemo } from 'react';
9
5
 
10
6
  export type UseCreateSupplyLiquidityParamsProps = {
@@ -19,33 +15,22 @@ export type UseCreateSupplyLiquidityParamsProps = {
19
15
  isValidPosition?: boolean;
20
16
  };
21
17
 
22
- export type UseCreateSupplyLiquidityParamsResult = ConcentratedLiquiditySupplyParams &
23
- Omit<ConcentratedLiquidityIncreaseLiquidityParams, 'tokenId'> & {
18
+ /**
19
+ * Subset of {@link ClSupplyParams} / {@link ClIncreaseLiquidityParams} produced by
20
+ * {@link useCreateSupplyLiquidityParams}. Callers add `srcChainKey` + `srcAddress` at the mutation
21
+ * call site. `tokenId` and `isValidPosition` distinguish the mint-new vs increase-existing path.
22
+ */
23
+ export type UseCreateSupplyLiquidityParamsResult = Omit<ClSupplyParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'> &
24
+ Omit<ClIncreaseLiquidityParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress' | 'tokenId'> & {
24
25
  tokenId?: string | bigint;
25
26
  positionId?: string | null;
26
27
  isValidPosition?: boolean;
27
28
  };
28
29
 
29
30
  /**
30
- * React hook to create the supply liquidity parameters for a given pool.
31
- *
32
- * Purpose:
33
- * - Provides a hook which memoizes the supply liquidity parameters for a given pool.
34
- *
35
- * Usage:
36
- * - Call the function with the pool data, pool key, minimum price, maximum price, liquidity token0 amount, liquidity token1 amount, slippage tolerance, position id, and validity of the position to create the supply liquidity parameters.
37
- *
38
- * Params:
39
- * @param poolData - The pool data of the pool to supply liquidity to.
40
- * @param poolKey - The pool key of the pool to supply liquidity to.
41
- * @param minPrice - The minimum price of the liquidity to supply.
42
- * @param maxPrice - The maximum price of the liquidity to supply.
43
- * @param liquidityToken0Amount - The amount of the token0 to supply.
44
- * @param liquidityToken1Amount - The amount of the token1 to supply.
45
- * @param slippageTolerance - The slippage tolerance to use for the supply.
46
- * @param positionId - The position id of the position to supply liquidity to.
47
- * @param isValidPosition - Whether the position is valid.
48
- * @returns The supply liquidity parameters.
31
+ * React hook to memoize concentrated-liquidity supply parameters for a given pool. Returns the
32
+ * pool/tick/liquidity/amount fields without `srcChainKey`/`srcAddress` — callers add those at the
33
+ * mutation call site.
49
34
  */
50
35
  export function useCreateSupplyLiquidityParams({
51
36
  poolData,
@@ -1,6 +1,6 @@
1
- import type { CreateAssetWithdrawParams, DestinationParamsType, PoolData, PoolSpokeAssets } from '@sodax/sdk';
1
+ import type { DestinationParamsType, PoolData, PoolSpokeAssets } from '@sodax/sdk';
2
2
  import { useMemo } from 'react';
3
- import { createWithdrawParamsProps } from '@/utils/dex-utils';
3
+ import { createWithdrawParamsProps, type WithdrawParamsCore } from '@/utils/dex-utils.js';
4
4
 
5
5
  export type UseCreateWithdrawParamsProps = {
6
6
  tokenIndex: 0 | 1;
@@ -11,21 +11,9 @@ export type UseCreateWithdrawParamsProps = {
11
11
  };
12
12
 
13
13
  /**
14
- * React hook to create the withdrawal parameters for a given pool and token.
15
- *
16
- * Purpose:
17
- * - Provides a hook which memoizes the withdrawal parameters for a given pool and token.
18
- *
19
- * Usage:
20
- * - Call the function with the token index, amount, pool data, pool spoke assets, and destination parameters to create the withdrawal parameters.
21
- *
22
- * Params:
23
- * @param tokenIndex - The index of the token to withdraw.
24
- * @param amount - The amount of the token to withdraw.
25
- * @param poolData - The pool data of the pool to withdraw from.
26
- * @param poolSpokeAssets - The pool spoke assets of the pool to withdraw from.
27
- * @param dst - The destination parameters for the withdrawal.
28
- * @returns The withdrawal parameters or undefined if the amount is not set.
14
+ * React hook to memoize the withdraw-specific subset of {@link CreateAssetWithdrawParams}
15
+ * (`{ asset, amount, poolToken, dst? }`). Callers add `srcChainKey` + `srcAddress` at the mutation
16
+ * call site.
29
17
  */
30
18
  export function useCreateWithdrawParams({
31
19
  tokenIndex,
@@ -33,12 +21,11 @@ export function useCreateWithdrawParams({
33
21
  poolData,
34
22
  poolSpokeAssets,
35
23
  dst,
36
- }: UseCreateWithdrawParamsProps): CreateAssetWithdrawParams | undefined {
37
- return useMemo<CreateAssetWithdrawParams | undefined>(() => {
24
+ }: UseCreateWithdrawParamsProps): WithdrawParamsCore | undefined {
25
+ return useMemo<WithdrawParamsCore | undefined>(() => {
38
26
  if (!amount || Number.parseFloat(String(amount)) <= 0) {
39
27
  return undefined;
40
28
  }
41
-
42
29
  return createWithdrawParamsProps({ tokenIndex, amount, poolData, poolSpokeAssets, dst });
43
30
  }, [tokenIndex, amount, poolData, poolSpokeAssets, dst]);
44
31
  }