@sodax/dapp-kit 1.5.6-beta → 2.0.0-rc.1

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 +194 -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 +1594 -1532
  61. package/dist/index.mjs.map +1 -1
  62. package/package.json +20 -10
  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 +27 -84
  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 -2562
  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
package/README.md CHANGED
@@ -1,133 +1,69 @@
1
1
  # @sodax/dapp-kit
2
2
 
3
- dApp Kit is a collection of React components, hooks, and utilities designed to streamline dApp development within the Sodax ecosystem. It provides seamless integration with Sodax smart contracts, enabling easy data querying and transaction execution. Additionally, it offers built-in wallet connectivity for all supported wallets in the Sodax network, simplifying the user onboarding experience. Under the hood, dApp Kit leverages @sodax/wallet-kit and @sodax/sdk for seamless functionality.
4
-
3
+ High-level React hooks library for dApp developers. Wraps `@sodax/sdk` with React Query into feature-organized hooks. Used alongside `@sodax/wallet-sdk-react` (no direct dependency shared types come from `@sodax/sdk`).
5
4
 
6
5
  ## Features
7
6
 
8
- - Money Market
9
- - Supply tokens to the money market (`useSupply`)
10
- - Withdraw tokens from the money market (`useWithdraw`)
11
- - Borrow tokens from the money market (`useBorrow`)
12
- - Repay borrowed tokens (`useRepay`)
13
- - Check token allowance (`useMMAllowance`)
14
- - Approve token spending (`useMMApprove`)
15
- - Get user reserves data (`useUserReservesData`)
16
- - Get reserves data (`useReservesData`)
17
- - Get humanized reserves data (`useReservesHumanized`)
18
- - Get list of reserves (`useReservesList`)
19
- - Get USD formatted reserves data (`useReservesUsdFormat`)
20
- - Get formatted user portfolio summary (`useUserFormattedSummary`)
21
-
22
- - Swap/Intent
23
- - Get quote for an intent order (`useQuote`)
24
- - Create and submit an swap intent order (`useSwap`)
25
- - Get status of an intent order (`useStatus`)
26
- - Check token allowance (`useSwapAllowance`)
27
- - Approve token spending (`useSwapApprove`)
28
- - Cancel a swap intent order (`useCancelSwap`)
29
-
30
- - Provider
31
- - Get hub chain provider (`useHubProvider`)
32
- - Get spoke chain provider (`useSpokeProvider`)
33
- - Get wallet provider (`useWalletProvider`)
34
-
35
- - Bridge
36
- - Bridge tokens between chains (`useBridge`)
37
- - Check token allowance for bridging (`useBridgeAllowance`)
38
- - Approve source token for bridging (`useBridgeApprove`)
39
- - Get max amount available to be bridged (`useGetBridgeableAmount`)
40
- - Get available destination tokens based on provided source token (`useGetBridgeableTokens`)
41
-
42
- - Shared
43
- - Derive user wallet address for hub abstraction (`useDeriveUserWalletAddress`)
44
- - Check if Stellar trustline is established for an asset (`useStellarTrustlineCheck`)
45
- - Request creation of Stellar trustline line for an asset (`useRequestTrustline`)
46
-
47
- - Staking
48
- - Stake SODA tokens to receive xSODA shares (`useStake`)
49
- - Unstake xSODA shares (`useUnstake`)
50
- - Instant unstake xSODA shares with penalty (`useInstantUnstake`)
51
- - Claim unstaked SODA tokens after unstaking period (`useClaim`)
52
- - Cancel unstake request (`useCancelUnstake`)
53
- - Check SODA token allowance for staking (`useStakeAllowance`)
54
- - Approve SODA token spending for staking (`useStakeApprove`)
55
- - Check xSODA token allowance for unstaking (`useUnstakeAllowance`)
56
- - Approve xSODA token spending for unstaking (`useUnstakeApprove`)
57
- - Check xSODA token allowance for instant unstaking (`useInstantUnstakeAllowance`)
58
- - Approve xSODA token spending for instant unstaking (`useInstantUnstakeApprove`)
59
- - Get comprehensive staking information (`useStakingInfo`)
60
- - Get unstaking information with penalty details (`useUnstakingInfoWithPenalty`)
61
- - Get unstaking information (`useUnstakingInfo`)
62
- - Get staking configuration (`useStakingConfig`)
63
- - Get stake ratio (SODA to xSODA conversion rate) (`useStakeRatio`)
64
- - Get instant unstake ratio (xSODA to SODA conversion rate with penalty) (`useInstantUnstakeRatio`)
65
- - Get converted assets amount for xSODA shares (`useConvertedAssets`)
66
-
67
- - DEX (Decentralized Exchange)
68
- - Get available pools list (`usePools`)
69
- - Get pool data for a selected pool (`usePoolData`)
70
- - Get token balances for pool tokens (`usePoolBalances`)
71
- - Get position information by token ID (`usePositionInfo`)
72
- - Deposit tokens to a pool (`useDexDeposit`)
73
- - Withdraw tokens from a pool (`useDexWithdraw`)
74
- - Check token allowance for DEX operations (`useDexAllowance`)
75
- - Approve token spending for DEX operations (`useDexApprove`)
76
- - Calculate liquidity amounts based on price range (`useLiquidityAmounts`)
77
- - Supply liquidity to a pool (`useSupplyLiquidity`)
78
- - Decrease liquidity from a position (`useDecreaseLiquidity`)
7
+ - **Swap/Intent** — `useQuote`, `useSwap`, `useSwapAllowance`, `useSwapApprove`, `useCancelSwap`, `useCreateLimitOrder`, `useCancelLimitOrder`, `useStatus`
8
+ - **Bridge** `useBridge`, `useBridgeAllowance`, `useBridgeApprove`, `useGetBridgeableAmount`, `useGetBridgeableTokens`
9
+ - **Money Market** `useSupply`, `useWithdraw`, `useBorrow`, `useRepay`, `useMMAllowance`, `useMMApprove`, plus reserves data hooks
10
+ - **Staking** `useStake`, `useUnstake`, `useInstantUnstake`, `useClaim`, `useCancelUnstake`, approval hooks, info/config/ratio queries
11
+ - **DEX** `useDexDeposit`, `useDexWithdraw`, `useSupplyLiquidity`, `useDecreaseLiquidity`, `useClaimRewards`, pool/position queries, param builders
12
+ - **Migration** `useMigrateIcxToSoda`, `useRevertMigrateSodaToIcx`, `useMigratebnUSD`, `useMigrateBaln`, `useMigrationApprove`, `useMigrationAllowance`
13
+ - **Bitcoin (Radfi)** `useRadfiAuth`, `useRadfiSession`, `useTradingWallet`, `useTradingWalletBalance`, `useBitcoinBalance`, `useFundTradingWallet`, `useRadfiWithdraw`, `useExpiredUtxos`, `useRenewUtxos`
14
+ - **Partner** `useFetchAssetsBalances`, `useGetAutoSwapPreferences`, `useIsTokenApproved`, `useApproveToken`, `useSetSwapPreference`, `useFeeClaimSwap`
15
+ - **Recovery** `useHubAssetBalances`, `useWithdrawHubAsset`
16
+ - **Backend Queries** Intent tracking, orderbook, money market position queries
17
+ - **Shared** `useXBalances`, `useDeriveUserWalletAddress`, `useGetUserHubWalletAddress`, `useStellarTrustlineCheck`, `useRequestTrustline`, `useEstimateGas`
79
18
 
80
19
  ## Installation
81
20
 
82
21
  ```bash
83
- npm install @sodax/dapp-kit
84
- # or
85
- yarn add @sodax/dapp-kit
86
- # or
87
- pnpm add @sodax/dapp-kit
22
+ pnpm add @sodax/dapp-kit @tanstack/react-query
23
+ # Optional: wallet connectivity
24
+ pnpm add @sodax/wallet-sdk-react
88
25
  ```
89
26
 
90
27
  ## Quick Start
91
28
 
92
- 1. First, install the required dependencies:
29
+ ### 1. Set up providers
93
30
 
94
- ```bash
95
- pnpm install @sodax/dapp-kit @tanstack/react-query @sodax/wallet-sdk-react
96
- ```
31
+ RPC URLs are injected through `config.chains`. `SodaxProvider` is the outermost wrapper; `QueryClientProvider` wraps everything inside it.
32
+
33
+ ```tsx
34
+ // providers.tsx
35
+ import { QueryClientProvider } from '@tanstack/react-query';
36
+ import { SodaxProvider, createSodaxQueryClient } from '@sodax/dapp-kit';
37
+ import { SodaxWalletProvider, type SodaxWalletConfig } from '@sodax/wallet-sdk-react';
38
+ import { ChainKeys, type DeepPartial, type SodaxConfig } from '@sodax/sdk';
97
39
 
98
- 2. Set up the providers in your app:
99
-
100
- ```typescript
101
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
102
- import { SodaxWalletProvider } from '@sodax/wallet-sdk-react';
103
- import { SodaxProvider } from '@sodax/dapp-kit';
104
- import type { RpcConfig } from '@sodax/types';
105
-
106
- const queryClient = new QueryClient();
107
-
108
- const rpcConfig: RpcConfig = {
109
- // EVM chains
110
- sonic: 'https://rpc.soniclabs.com',
111
- '0xa86a.avax': 'https://api.avax.network/ext/bc/C/rpc',
112
- '0xa4b1.arbitrum': 'https://arb1.arbitrum.io/rpc',
113
- '0x2105.base': 'https://mainnet.base.org',
114
- '0x38.bsc': 'https://bsc-dataseed1.binance.org',
115
- '0xa.optimism': 'https://mainnet.optimism.io',
116
- '0x89.polygon': 'https://polygon-rpc.com',
117
-
118
- // Other chains
119
- '0x1.icon': 'https://ctz.solidwallet.io/api/v3',
120
- solana: 'https://solana-mainnet.g.alchemy.com/v2/your-api-key',
121
- sui: 'https://fullnode.mainnet.sui.io',
122
- 'injective-1': 'https://sentry.tm.injective.network:26657',
40
+ const queryClient = createSodaxQueryClient();
41
+
42
+ const sodaxConfig: DeepPartial<SodaxConfig> = {
43
+ chains: {
44
+ [ChainKeys.SONIC_MAINNET]: { rpcUrl: 'https://sonic-rpc.publicnode.com' },
45
+ [ChainKeys.BSC_MAINNET]: { rpcUrl: 'https://bsc-dataseed.binance.org' },
46
+ [ChainKeys.BASE_MAINNET]: { rpcUrl: 'https://base.drpc.org' },
47
+ [ChainKeys.ARBITRUM_MAINNET]: { rpcUrl: 'https://arb1.arbitrum.io/rpc' },
48
+ // Add chains your dApp needs
49
+ },
50
+ };
51
+
52
+ const walletConfig: SodaxWalletConfig = {
53
+ EVM: {
54
+ chains: {
55
+ [ChainKeys.BSC_MAINNET]: { rpcUrl: 'https://bsc-dataseed.binance.org' },
56
+ [ChainKeys.BASE_MAINNET]: { rpcUrl: 'https://base.drpc.org' },
57
+ },
58
+ },
123
59
  };
124
60
 
125
- function App() {
61
+ export function Providers({ children }: { children: React.ReactNode }) {
126
62
  return (
127
- <SodaxProvider testnet={false} rpcConfig={rpcConfig}>
63
+ <SodaxProvider config={sodaxConfig}>
128
64
  <QueryClientProvider client={queryClient}>
129
- <SodaxWalletProvider rpcConfig={rpcConfig}>
130
- <YourApp />
65
+ <SodaxWalletProvider config={walletConfig}>
66
+ {children}
131
67
  </SodaxWalletProvider>
132
68
  </QueryClientProvider>
133
69
  </SodaxProvider>
@@ -135,354 +71,296 @@ function App() {
135
71
  }
136
72
  ```
137
73
 
138
- 3. Use the hooks in your components:
139
-
140
- ```typescript
141
- // Connect Wallet Operations
142
- // Money Market Operations
143
- import { useSupply, useWithdraw, useBorrow, useRepay, useUserReservesData, useMMAllowance, useMMApprove } from '@sodax/dapp-kit';
144
- import { parseUnits } from 'viem';
145
- import { useMemo, useState } from 'react';
146
-
147
- function MoneyMarketComponent() {
148
- const [amount, setAmount] = useState<string>('');
149
- const spokeProvider = useSpokeProvider(chainId, walletProvider);
150
-
151
- // Supply tokens
152
- const supplyParams = useMemo(() => {
153
- if (!amount) return undefined;
154
- return {
155
- token: token.address,
156
- amount: parseUnits(amount, token.decimals),
157
- action: 'supply' as const,
158
- };
159
- }, [token.address, token.decimals, amount]);
160
-
161
- const { data: hasSupplyAllowed, isLoading: isSupplyAllowanceLoading } = useMMAllowance(supplyParams, spokeProvider);
162
- const { mutateAsync: approveSupply, isPending: isApprovingSupply, error: approveSupplyError } = useMMApprove();
163
- const { mutateAsync: supply, isPending: isSupplying, error: supplyError } = useSupply();
164
-
165
- const handleApproveSupply = async () => {
166
- if (!spokeProvider || !supplyParams) return;
167
- try {
168
- await approveSupply({ params: supplyParams, spokeProvider });
169
- } catch (err) {
170
- console.error('Error approving supply:', err);
171
- }
172
- };
74
+ ### 2. Get a wallet provider
173
75
 
174
- const handleSupply = async () => {
175
- if (!spokeProvider || !supplyParams) return;
176
- try {
177
- await supply({ params: supplyParams, spokeProvider });
178
- } catch (err) {
179
- console.error('Error supplying:', err);
180
- }
181
- };
76
+ ```tsx
77
+ import { useWalletProvider } from '@sodax/wallet-sdk-react';
78
+ import { ChainKeys } from '@sodax/sdk';
182
79
 
183
- // Withdraw tokens
184
- const withdrawParams = useMemo(() => {
185
- if (!amount) return undefined;
186
- return {
187
- token: token.address,
188
- amount: parseUnits(amount, 18), // vault token on hub chain decimals is 18
189
- action: 'withdraw' as const,
190
- };
191
- }, [token.address, amount]);
192
-
193
- const { data: hasWithdrawAllowed, isLoading: isWithdrawAllowanceLoading } = useMMAllowance(withdrawParams, spokeProvider);
194
- const { data: hasWithdrawAllowed, isLoading: isWithdrawAllowanceLoading } = useMMAllowance({ params: withdrawParams, spokeProvider });
195
-
196
- const { mutateAsync: approveWithdraw, isPending: isApprovingWithdraw, error: approveWithdrawError } = useMMApprove();
197
- const { mutateAsync: withdraw, isPending: isWithdrawing, error: withdrawError } = useWithdraw();
198
-
199
- const handleApproveWithdraw = async () => {
200
- if (!spokeProvider || !withdrawParams) return;
201
- try {
202
- await approveWithdraw({ params: withdrawParams, spokeProvider });
203
- } catch (err) {
204
- console.error('Error approving withdraw:', err);
205
- }
206
- };
80
+ function MyFeature() {
81
+ const walletProvider = useWalletProvider(ChainKeys.BSC_MAINNET);
82
+ // undefined until wallet is connected
83
+ }
84
+ ```
207
85
 
208
- const handleWithdraw = async () => {
209
- if (!spokeProvider || !withdrawParams) return;
210
- try {
211
- await withdraw({ params: withdrawParams, spokeProvider });
212
- } catch (err) {
213
- console.error('Error withdrawing:', err);
214
- }
215
- };
86
+ ### 3. Use feature hooks
216
87
 
217
- // Borrow tokens
218
- const borrowParams = useMemo(() => {
219
- if (!amount) return undefined;
220
- return {
221
- token: token.address,
222
- amount: parseUnits(amount, 18),
223
- action: 'borrow' as const,
224
- };
225
- }, [token.address, amount]);
226
-
227
- const { data: hasBorrowAllowed, isLoading: isBorrowAllowanceLoading } = useMMAllowance({ params: borrowParams, spokeProvider });
228
- const { mutateAsync: approveBorrow, isPending: isApprovingBorrow, error: approveBorrowError } = useMMApprove();
229
- const { mutateAsync: borrow, isPending: isBorrowing, error: borrowError } = useBorrow();
230
-
231
- const handleApproveBorrow = async () => {
232
- if (!spokeProvider || !borrowParams) return;
233
- try {
234
- await approveBorrow({ params: borrowParams, spokeProvider });
235
- } catch (err) {
236
- console.error('Error approving borrow:', err);
237
- }
238
- };
88
+ All mutation hooks accept no arguments at initialization. Domain inputs (params, walletProvider) flow through `mutate(vars)`:
239
89
 
240
- const handleBorrow = async () => {
241
- if (!spokeProvider || !borrowParams) return;
242
- try {
243
- await borrow({ params: borrowParams, spokeProvider });
244
- } catch (err) {
245
- console.error('Error borrowing:', err);
246
- }
247
- };
90
+ ```tsx
91
+ import { useSwap } from '@sodax/dapp-kit';
92
+ import { useWalletProvider } from '@sodax/wallet-sdk-react';
93
+ import { ChainKeys } from '@sodax/sdk';
94
+ import type { CreateIntentParams } from '@sodax/sdk';
248
95
 
249
- // Repay tokens
250
- const repayParams = useMemo(() => {
251
- if (!amount) return undefined;
252
- return {
253
- token: token.address,
254
- amount: parseUnits(amount, token.decimals),
255
- action: 'repay' as const,
256
- };
257
- }, [token.address, token.decimals, amount]);
258
-
259
- const { data: hasRepayAllowed, isLoading: isRepayAllowanceLoading } = useMMAllowance({ params: repayParams, spokeProvider });
260
- const { mutateAsync: approveRepay, isPending: isApprovingRepay, error: approveRepayError } = useMMApprove();
261
- const { mutateAsync: repay, isPending: isRepaying, error: repayError } = useRepay();
262
-
263
- const handleApproveRepay = async () => {
264
- if (!spokeProvider || !repayParams) return;
265
- try {
266
- await approveRepay({ params: repayParams, spokeProvider });
267
- } catch (err) {
268
- console.error('Error approving repay:', err);
269
- }
270
- };
96
+ function SwapButton({ intentParams }: { intentParams: CreateIntentParams }) {
97
+ const walletProvider = useWalletProvider(ChainKeys.BSC_MAINNET);
98
+ const { mutateAsyncSafe: swap, isPending } = useSwap();
271
99
 
272
- const handleRepay = async () => {
273
- if (!spokeProvider || !repayParams) return;
274
- try {
275
- await repay({ params: repayParams, spokeProvider });
276
- } catch (err) {
277
- console.error('Error repaying:', err);
100
+ const handleSwap = async () => {
101
+ if (!walletProvider) return;
102
+ const result = await swap({ params: intentParams, walletProvider });
103
+ if (!result.ok) {
104
+ alert(result.error instanceof Error ? result.error.message : 'Swap failed');
105
+ return;
278
106
  }
107
+ console.log('Swap submitted!', result.value);
279
108
  };
280
109
 
281
- // Get user's supplied assets
282
- const { address } = useXAccount(chainId);
283
- const { data: userReserves } = useUserReservesData({ spokeChainId: chainId, userAddress: address });
284
- }
285
-
286
- // Wallet Address Derivation
287
- import { useDeriveUserWalletAddress, useSpokeProvider } from '@sodax/dapp-kit';
288
-
289
- function WalletAddressComponent() {
290
- const spokeProvider = useSpokeProvider(chainId, walletProvider);
291
-
292
- // Derive user wallet address for hub abstraction
293
- const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
294
-
295
110
  return (
296
- <div>
297
- {isLoading && <div>Deriving wallet address...</div>}
298
- {error && <div>Error: {error.message}</div>}
299
- {derivedAddress && <div>Derived Address: {derivedAddress}</div>}
300
- </div>
111
+ <button onClick={handleSwap} disabled={isPending || !walletProvider}>
112
+ {isPending ? 'Swapping...' : 'Swap'}
113
+ </button>
301
114
  );
302
115
  }
303
-
304
- // Swap Operations
305
- import { useQuote, useSwap, useStatus } from '@sodax/dapp-kit';
306
-
307
- function SwapComponent() {
308
- // Get quote for an intent order
309
- const { data: quote, isLoading: isQuoteLoading } = useQuote({
310
- token_src: '0x...',
311
- token_src_blockchain_id: '0xa86a.avax',
312
- token_dst: '0x...',
313
- token_dst_blockchain_id: '0xa4b1.arbitrum',
314
- amount: '1000000000000000000',
315
- quote_type: 'exact_input',
316
- });
317
-
318
- // Create and submit an intent order
319
- const { mutateAsync: swap, isPending: isCreating } = useSwap();
320
- const handleSwap = async () => {
321
- const order = await swap({
322
- token_src: '0x...',
323
- token_src_blockchain_id: '0xa86a.avax',
324
- token_dst: '0x...',
325
- token_dst_blockchain_id: '0xa4b1.arbitrum',
326
- amount: '1000000000000000000',
327
- quote_type: 'exact_input',
328
- });
329
- };
330
-
331
- // Get status of an intent order
332
- const { data: orderStatus } = useStatus('0x...');
333
- }
334
-
335
- // Bridge Operations
336
- import { useBridge, useBridgeAllowance, useBridgeApprove, useGetBridgeableAmount, useGetBridgeableTokens } from '@sodax/dapp-kit';
337
-
338
- function BridgeComponent() {
339
- const spokeProvider = useSpokeProvider(chainId, walletProvider);
340
-
341
- // Get available destination tokens for bridging
342
- const { data: bridgeableTokens, isLoading: isTokensLoading } = useGetBridgeableTokens(
343
- '0x2105.base', // from chain
344
- '0x89.polygon', // to chain
345
- '0x...' // source token address
346
- );
347
-
348
- // Get maximum amount available to bridge
349
- const { data: bridgeableAmount } = useGetBridgeableAmount(
350
- { address: '0x...', xChainId: '0x2105.base' }, // from token
351
- { address: '0x...', xChainId: '0x89.polygon' } // to token
352
- );
353
-
354
- // Check token allowance for bridge
355
- const { data: hasAllowed } = useBridgeAllowance(bridgeParams, spokeProvider);
356
-
357
- // Approve tokens for bridge
358
- const { approve: approveBridge, isLoading: isApproving } = useBridgeApprove(spokeProvider);
359
- const handleApprove = async () => {
360
- await approveBridge(bridgeParams);
361
- };
362
-
363
- // Execute bridge transaction
364
- const { mutateAsync: bridge, isPending: isBridging } = useBridge(spokeProvider);
365
- const handleBridge = async () => {
366
- const result = await bridge({
367
- srcChainId: '0x2105.base',
368
- srcAsset: '0x...',
369
- amount: 1000n,
370
- dstChainId: '0x89.polygon',
371
- dstAsset: '0x...',
372
- recipient: '0x...'
373
- });
374
-
375
- console.log('Bridge transaction hashes:', {
376
- spokeTxHash: result.value[0],
377
- hubTxHash: result.value[1]
378
- });
379
- };
380
- }
381
116
  ```
382
117
 
383
118
  ## Requirements
384
119
 
385
120
  - Node.js >= 18.0.0
386
- - React >= 19
121
+ - React >= 18
387
122
  - TypeScript
388
123
 
389
124
  ## API Reference
390
125
 
391
- ### Components
392
-
393
- - [`SodaxProvider`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/providers/SodaxProvider.tsx) - Main provider component for Sodax ecosystem integration
394
-
395
- ### Hooks
396
-
397
- #### Money Market Hooks
398
- - [`useBorrow()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useBorrow.ts) - Borrow tokens from the money market
399
- - [`useRepay()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useRepay.ts) - Repay borrowed tokens
400
- - [`useSupply()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useSupply.ts) - Supply tokens to the money market
401
- - [`useWithdraw()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useWithdraw.ts) - Withdraw supplied tokens
402
- - [`useUserReservesData()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useUserReservesData.ts) - Get user's reserves data(supplied asset and debt)
403
- - [`useReservesData()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useReservesData.ts) - Get reserves data
404
- - [`useMMAllowance()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useMMAllowance.ts) - Check token allowance for a specific amount
405
- - [`useMMApprove()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useMMApprove.ts) - Approve token spending
406
- - [`useAToken()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/mm/useAToken.ts) - Fetch aToken token data
407
-
408
- #### Swap Hooks
409
- - [`useQuote()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useQuote.ts) - Get quote for an intent order
410
- - [`useSwap()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useSwap.ts) - Create and submit an intent order
411
- - [`useCreateLimitOrder()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useCreateLimitOrder.ts) - Create a limit order intent (no deadline, must be cancelled manually)
412
- - **Note**: Limit orders use `useSwapAllowance()` for checking token allowance (same as swaps)
413
- - **Note**: Limit orders use `useSwapApprove()` for approving token spending (same as swaps)
414
- - **Note**: Limit orders use `useCancelSwap()` for cancelling (same as swaps)
415
- - [`useStatus()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useStatus.ts) - Get status of an intent order
416
- - [`useSwapAllowance()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useSwapAllowance.ts) - Check token allowance for an intent order
417
- - [`useSwapApprove()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useSwapApprove.ts) - Approve token spending
418
- - [`useCancelSwap()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/swap/useCancelSwap.ts) - Cancel a swap intent order
419
-
420
- #### Shared Hooks
421
- - [`useSodaxContext()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/shared/useSodaxContext.ts) - Access Sodax context and configuration
422
- - [`useEstimateGas()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/shared/useEstimateGas.ts) - Estimate gas costs for transactions
423
- - [`useDeriveUserWalletAddress()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/shared/useDeriveUserWalletAddress.ts) - Derive user wallet address for hub abstraction
424
-
425
- #### Bridge Hooks
426
- - [`useBridge()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/bridge/useBridge.ts) - Execute bridge transactions to transfer tokens between chains
427
- - [`useBridgeAllowance()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/bridge/useBridgeAllowance.ts) - Check token allowance for bridge operations
428
- - [`useBridgeApprove()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/bridge/useBridgeApprove.ts) - Approve token spending for bridge actions
429
- - [`useGetBridgeableAmount()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/bridge/useGetBridgeableAmount.ts) - Get maximum amount available to be bridged
430
- - [`useGetBridgeableTokens()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/bridge/useGetBridgeableTokens.ts) - Get available destination tokens for bridging
431
-
432
- #### DEX Hooks
433
- - [`usePools()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/usePools.ts) - Get available pools list from the DEX service
434
- - [`usePoolData()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/usePoolData.ts) - Get pool data for a selected pool
435
- - [`usePoolBalances()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/usePoolBalances.ts) - Get token balances for pool tokens
436
- - [`usePositionInfo()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/usePositionInfo.ts) - Get position information by token ID
437
- - [`useDexDeposit()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useDexDeposit.ts) - Deposit tokens to a pool
438
- - [`useDexWithdraw()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useDexWithdraw.ts) - Withdraw tokens from a pool
439
- - [`useDexAllowance()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useDexAllowance.ts) - Check token allowance for DEX operations
440
- - [`useDexApprove()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useDexApprove.ts) - Approve token spending for DEX operations
441
- - [`useLiquidityAmounts()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useLiquidityAmounts.ts) - Calculate liquidity amounts based on price range
442
- - [`useSupplyLiquidity()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useSupplyLiquidity.ts) - Supply liquidity to a pool
443
- - [`useDecreaseLiquidity()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useDecreaseLiquidity.ts) - Decrease liquidity from a position
444
- - [`useCreateDepositParams()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useCreateDepositParams.ts) - Build and memoize pool deposit params with basic amount validation
445
- - [`useCreateWithdrawParams()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useCreateWithdrawParams.ts) - Build and memoize pool withdrawal params with basic amount validation
446
- - [`useCreateSupplyLiquidityParams()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useCreateSupplyLiquidityParams.ts) - Build and memoize supply liquidity params with price and slippage validation
447
- - [`useCreateDecreaseLiquidityParams()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/hooks/dex/useCreateDecreaseLiquidityParams.ts) - Build and memoize decrease liquidity params with percentage and slippage validation
448
-
449
- #### DEX Utils
450
- - [`createDepositParamsProps()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/utils/dex-utils.ts) - Create deposit params for a pool token using pool data and spoke asset info
451
- - [`createWithdrawParamsProps()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/utils/dex-utils.ts) - Create withdraw params for a pool token with optional destination info
452
- - [`createSupplyLiquidityParamsProps()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/utils/dex-utils.ts) - Create concentrated liquidity supply params from price range, amounts, and slippage
453
- - [`createDecreaseLiquidityParamsProps()`](https://github.com/icon-project/sodax-frontend/tree/main/packages/dapp-kit/src/utils/dex-utils.ts) - Create decrease liquidity params from position info, percentage, and slippage
454
-
455
- ## Contributing
456
-
457
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
126
+ ### Provider
127
+
128
+ - [`SodaxProvider`](src/providers/SodaxProvider.tsx) Wraps your app, creates the `Sodax` SDK instance. Accepts `config?: DeepPartial<SodaxConfig>`.
129
+ - [`createSodaxQueryClient()`](src/providers/createSodaxQueryClient.ts) — Factory for a `QueryClient` with global mutation observability (`onMutationError` hook, `meta.silent` opt-out).
130
+
131
+ ### Swap Hooks
132
+
133
+ - [`useQuote()`](src/hooks/swap/useQuote.ts) — Real-time quote (auto-refreshes every 3s)
134
+ - [`useSwap()`](src/hooks/swap/useSwap.ts) — Submit a cross-chain swap intent
135
+ - [`useSwapAllowance()`](src/hooks/swap/useSwapAllowance.ts) Check token approval
136
+ - [`useSwapApprove()`](src/hooks/swap/useSwapApprove.ts) Approve token spending
137
+ - [`useStatus()`](src/hooks/swap/useStatus.ts) Track intent execution status
138
+ - [`useCancelSwap()`](src/hooks/swap/useCancelSwap.ts) Cancel a pending swap
139
+ - [`useCreateLimitOrder()`](src/hooks/swap/useCreateLimitOrder.ts) Create a limit order (no deadline)
140
+ - [`useCancelLimitOrder()`](src/hooks/swap/useCancelLimitOrder.ts) Cancel a limit order
141
+
142
+ ### Money Market Hooks
143
+
144
+ - [`useSupply()`](src/hooks/mm/useSupply.ts) Supply collateral
145
+ - [`useWithdraw()`](src/hooks/mm/useWithdraw.ts) Withdraw supplied tokens
146
+ - [`useBorrow()`](src/hooks/mm/useBorrow.ts) Borrow against collateral
147
+ - [`useRepay()`](src/hooks/mm/useRepay.ts) Repay borrowed tokens
148
+ - [`useMMAllowance()`](src/hooks/mm/useMMAllowance.ts) Check approval (auto-skips for borrow/withdraw)
149
+ - [`useMMApprove()`](src/hooks/mm/useMMApprove.ts) Approve token spending
150
+ - [`useReservesData()`](src/hooks/mm/useReservesData.ts) All reserve data
151
+ - [`useReservesHumanized()`](src/hooks/mm/useReservesHumanized.ts) Reserves in decimal-normalized format
152
+ - [`useReservesList()`](src/hooks/mm/useReservesList.ts) List of reserve asset addresses
153
+ - [`useReservesUsdFormat()`](src/hooks/mm/useReservesUsdFormat.ts) Reserves with USD values
154
+ - [`useUserFormattedSummary()`](src/hooks/mm/useUserFormattedSummary.ts) — User portfolio summary (health factor, collateral, debt)
155
+ - [`useUserReservesData()`](src/hooks/mm/useUserReservesData.ts) — User reserve positions
156
+ - [`useAToken()`](src/hooks/mm/useAToken.ts) aToken metadata
157
+ - [`useATokensBalances()`](src/hooks/mm/useATokensBalances.ts) aToken balances
158
+
159
+ ### Bridge Hooks
160
+
161
+ - [`useBridge()`](src/hooks/bridge/useBridge.ts) Execute a cross-chain bridge transfer
162
+ - [`useBridgeAllowance()`](src/hooks/bridge/useBridgeAllowance.ts) Check token approval
163
+ - [`useBridgeApprove()`](src/hooks/bridge/useBridgeApprove.ts) Approve token spending
164
+ - [`useGetBridgeableAmount()`](src/hooks/bridge/useGetBridgeableAmount.ts) Max bridgeable amount between two tokens
165
+ - [`useGetBridgeableTokens()`](src/hooks/bridge/useGetBridgeableTokens.ts) Tokens bridgeable to a destination chain
166
+
167
+ ### Staking Hooks
168
+
169
+ - [`useStake()`](src/hooks/staking/useStake.ts) Stake SODA, receive xSODA
170
+ - [`useUnstake()`](src/hooks/staking/useUnstake.ts) Request unstake (waiting period)
171
+ - [`useInstantUnstake()`](src/hooks/staking/useInstantUnstake.ts) Instant unstake with slippage
172
+ - [`useClaim()`](src/hooks/staking/useClaim.ts) Claim SODA after waiting period
173
+ - [`useCancelUnstake()`](src/hooks/staking/useCancelUnstake.ts) Cancel pending unstake
174
+ - [`useStakeApprove()`](src/hooks/staking/useStakeApprove.ts) Approve SODA for staking
175
+ - [`useUnstakeApprove()`](src/hooks/staking/useUnstakeApprove.ts) Approve xSODA for unstaking
176
+ - [`useInstantUnstakeApprove()`](src/hooks/staking/useInstantUnstakeApprove.ts) Approve xSODA for instant unstaking
177
+ - [`useStakeAllowance()`](src/hooks/staking/useStakeAllowance.ts) Check SODA approval
178
+ - [`useUnstakeAllowance()`](src/hooks/staking/useUnstakeAllowance.ts) Check xSODA approval for unstaking
179
+ - [`useInstantUnstakeAllowance()`](src/hooks/staking/useInstantUnstakeAllowance.ts) Check xSODA approval for instant unstaking
180
+ - [`useStakingInfo()`](src/hooks/staking/useStakingInfo.ts) User staking position
181
+ - [`useUnstakingInfo()`](src/hooks/staking/useUnstakingInfo.ts) Pending unstake requests
182
+ - [`useUnstakingInfoWithPenalty()`](src/hooks/staking/useUnstakingInfoWithPenalty.ts) Unstake requests with penalty calcs
183
+ - [`useStakingConfig()`](src/hooks/staking/useStakingConfig.ts) — Unstaking period, max penalty
184
+ - [`useStakeRatio()`](src/hooks/staking/useStakeRatio.ts) — SODA-to-xSODA exchange rate
185
+ - [`useInstantUnstakeRatio()`](src/hooks/staking/useInstantUnstakeRatio.ts) Instant unstake rate
186
+ - [`useConvertedAssets()`](src/hooks/staking/useConvertedAssets.ts) xSODA to SODA conversion
187
+
188
+ ### DEX Hooks
189
+
190
+ - [`usePools()`](src/hooks/dex/usePools.ts) — List available pools
191
+ - [`usePoolData()`](src/hooks/dex/usePoolData.ts) — Pool details (price, tick, liquidity)
192
+ - [`usePoolBalances()`](src/hooks/dex/usePoolBalances.ts) User pool token balances
193
+ - [`usePositionInfo()`](src/hooks/dex/usePositionInfo.ts) — Position details by token ID
194
+ - [`useDexDeposit()`](src/hooks/dex/useDexDeposit.ts) — Deposit assets into pool tokens
195
+ - [`useDexWithdraw()`](src/hooks/dex/useDexWithdraw.ts) — Withdraw assets from pool tokens
196
+ - [`useDexAllowance()`](src/hooks/dex/useDexAllowance.ts) — Check approval for deposit
197
+ - [`useDexApprove()`](src/hooks/dex/useDexApprove.ts) — Approve token spending
198
+ - [`useLiquidityAmounts()`](src/hooks/dex/useLiquidityAmounts.ts) — Token amounts for a tick range
199
+ - [`useSupplyLiquidity()`](src/hooks/dex/useSupplyLiquidity.ts) — Supply liquidity to a position
200
+ - [`useDecreaseLiquidity()`](src/hooks/dex/useDecreaseLiquidity.ts) — Remove liquidity
201
+ - [`useClaimRewards()`](src/hooks/dex/useClaimRewards.ts) — Claim trading fees
202
+ - [`useCreateDepositParams()`](src/hooks/dex/useCreateDepositParams.ts) — Build deposit params with ERC-4626 conversion
203
+ - [`useCreateWithdrawParams()`](src/hooks/dex/useCreateWithdrawParams.ts) — Build withdraw params
204
+ - [`useCreateSupplyLiquidityParams()`](src/hooks/dex/useCreateSupplyLiquidityParams.ts) — Build tick range + liquidity params
205
+ - [`useCreateDecreaseLiquidityParams()`](src/hooks/dex/useCreateDecreaseLiquidityParams.ts) — Build decrease params from position state
206
+
207
+ ### Migration Hooks
208
+
209
+ - [`useMigrateIcxToSoda()`](src/hooks/migrate/useMigrateIcxToSoda.ts) — ICX/wICX (ICON) → SODA (Sonic)
210
+ - [`useRevertMigrateSodaToIcx()`](src/hooks/migrate/useRevertMigrateSodaToIcx.ts) — SODA (Sonic) → wICX (ICON)
211
+ - [`useMigratebnUSD()`](src/hooks/migrate/useMigratebnUSD.ts) — Legacy bnUSD ↔ new bnUSD (bidirectional)
212
+ - [`useMigrateBaln()`](src/hooks/migrate/useMigrateBaln.ts) — BALN (ICON) → SODA with optional lock period
213
+ - [`useMigrationApprove()`](src/hooks/migrate/useMigrationApprove.ts) — Approve token spending before migration
214
+ - [`useMigrationAllowance()`](src/hooks/migrate/useMigrationAllowance.ts) — Check if approval is needed
215
+
216
+ ### Bitcoin (Radfi) Hooks
217
+
218
+ - [`useRadfiSession()`](src/hooks/bitcoin/useRadfiSession.ts) — Manage Radfi session (login, auto-refresh)
219
+ - [`useRadfiAuth()`](src/hooks/bitcoin/useRadfiAuth.ts) — Authenticate with Radfi via BIP322 signing
220
+ - [`useTradingWallet()`](src/hooks/bitcoin/useTradingWallet.ts) — Get trading wallet address from persisted session
221
+ - [`useBitcoinBalance()`](src/hooks/bitcoin/useBitcoinBalance.ts) — BTC balance for any address
222
+ - [`useTradingWalletBalance()`](src/hooks/bitcoin/useTradingWalletBalance.ts) — Trading wallet balance from Radfi API
223
+ - [`useFundTradingWallet()`](src/hooks/bitcoin/useFundTradingWallet.ts) — Fund trading wallet from personal wallet
224
+ - [`useRadfiWithdraw()`](src/hooks/bitcoin/useRadfiWithdraw.ts) — Withdraw from trading wallet
225
+ - [`useExpiredUtxos()`](src/hooks/bitcoin/useExpiredUtxos.ts) — Fetch expired UTXOs (polls every 60s)
226
+ - [`useRenewUtxos()`](src/hooks/bitcoin/useRenewUtxos.ts) — Renew expired UTXOs
227
+
228
+ ### Partner Hooks
229
+
230
+ - [`useFetchAssetsBalances()`](src/hooks/partner/useFetchAssetsBalances.ts) — Fetch partner asset balances
231
+ - [`useGetAutoSwapPreferences()`](src/hooks/partner/useGetAutoSwapPreferences.ts) — Get auto-swap preferences
232
+ - [`useIsTokenApproved()`](src/hooks/partner/useIsTokenApproved.ts) — Check token approval
233
+ - [`useApproveToken()`](src/hooks/partner/useApproveToken.ts) — Approve token
234
+ - [`useSetSwapPreference()`](src/hooks/partner/useSetSwapPreference.ts) — Set swap preference
235
+ - [`useFeeClaimSwap()`](src/hooks/partner/useFeeClaimSwap.ts) — Claim partner fees via swap
236
+
237
+ ### Recovery Hooks
238
+
239
+ - [`useHubAssetBalances()`](src/hooks/recovery/useHubAssetBalances.ts) — Get hub asset balances
240
+ - [`useWithdrawHubAsset()`](src/hooks/recovery/useWithdrawHubAsset.ts) — Withdraw hub asset
241
+
242
+ ### Shared Hooks
243
+
244
+ - [`useSodaxContext()`](src/hooks/shared/useSodaxContext.ts) — Access the `Sodax` SDK instance
245
+ - [`useHubProvider()`](src/hooks/provider/useHubProvider.ts) — Access the hub chain (Sonic) provider
246
+ - [`useXBalances()`](src/hooks/shared/useXBalances.ts) — Cross-chain token balances for an address
247
+ - [`useDeriveUserWalletAddress()`](src/hooks/shared/useDeriveUserWalletAddress.ts) — Derive hub wallet address (CREATE3)
248
+ - [`useGetUserHubWalletAddress()`](src/hooks/shared/useGetUserHubWalletAddress.ts) — Derive hub wallet address (wallet router)
249
+ - [`useEstimateGas()`](src/hooks/shared/useEstimateGas.ts) — Estimate gas for transactions
250
+ - [`useStellarTrustlineCheck()`](src/hooks/shared/useStellarTrustlineCheck.ts) — Check Stellar trustline
251
+ - [`useRequestTrustline()`](src/hooks/shared/useRequestTrustline.ts) — Request Stellar trustline
252
+
253
+ ### Backend Query Hooks
254
+
255
+ - [`useBackendIntentByTxHash()`](src/hooks/backend/useBackendIntentByTxHash.ts) — Get intent by hub tx hash (polls 1s)
256
+ - [`useBackendIntentByHash()`](src/hooks/backend/useBackendIntentByHash.ts) — Get intent by intent hash
257
+ - [`useBackendUserIntents()`](src/hooks/backend/useBackendUserIntents.ts) — All intents for a user with date filtering
258
+ - [`useBackendOrderbook()`](src/hooks/backend/useBackendOrderbook.ts) — Solver orderbook (cached 30s, no auto-refetch)
259
+ - [`useBackendMoneyMarketPosition()`](src/hooks/backend/useBackendMoneyMarketPosition.ts) — User money market position
260
+ - [`useBackendAllMoneyMarketAssets()`](src/hooks/backend/useBackendAllMoneyMarketAssets.ts) — All MM assets
261
+ - [`useBackendMoneyMarketAsset()`](src/hooks/backend/useBackendMoneyMarketAsset.ts) — Single MM asset details
262
+ - [`useBackendMoneyMarketAssetBorrowers()`](src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts) — Asset borrowers
263
+ - [`useBackendMoneyMarketAssetSuppliers()`](src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts) — Asset suppliers
264
+ - [`useBackendAllMoneyMarketBorrowers()`](src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts) — All borrowers
265
+ - [`useBackendSubmitSwapTx()`](src/hooks/backend/useBackendSubmitSwapTx.ts) — Submit swap tx to backend
266
+ - [`useBackendSubmitSwapTxStatus()`](src/hooks/backend/useBackendSubmitSwapTxStatus.ts) — Check submitted swap status
267
+
268
+ ### DEX Utils
269
+
270
+ - [`createDepositParamsProps()`](src/utils/dex-utils.ts) — Build deposit params from pool data and spoke asset info
271
+ - [`createWithdrawParamsProps()`](src/utils/dex-utils.ts) — Build withdraw params with optional destination info
272
+ - [`createSupplyLiquidityParamsProps()`](src/utils/dex-utils.ts) — Build concentrated liquidity supply params
273
+ - [`createDecreaseLiquidityParamsProps()`](src/utils/dex-utils.ts) — Build decrease liquidity params
458
274
 
459
275
  ## Development
460
276
 
461
277
  ```bash
462
- # Install dependencies
463
- pnpm install
278
+ pnpm install # Install dependencies
279
+ pnpm build # Build the package (ESM + CJS)
280
+ pnpm dev # Watch mode
281
+ pnpm checkTs # Type checking
282
+ pnpm test # Run tests
283
+ pnpm pretty # Format code
284
+ pnpm lint # Lint code
285
+ ```
286
+
287
+ ## AI agent docs
464
288
 
465
- # Build the package
466
- pnpm build
289
+ `@sodax/dapp-kit` ships an AI-ready documentation tree at `node_modules/@sodax/dapp-kit/ai-exported/`. It's tool-neutral: any agent that can read files (Claude Code, Cursor, Aider, Copilot Chat, ChatGPT with file context, etc.) can use it without further setup.
467
290
 
468
- # Run in development mode
469
- pnpm dev
291
+ ### Get started
470
292
 
471
- # Run type checking
472
- pnpm checkTs
293
+ Point your agent at `node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md` — it routes to the rest. Three sample prompts covering the typical entry points:
473
294
 
474
- # Format code
475
- pnpm pretty
295
+ ```
296
+ > Read node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md and integrate
297
+ > SODAX cross-chain swaps into my React app.
298
+
299
+ > Read node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md. My app uses
300
+ > v1 dapp-kit (useSpokeProvider, custom approve return shapes) — port to v2.
476
301
 
477
- # Lint code
478
- pnpm lint
302
+ > Look up the canonical mutation hook shape in
303
+ > node_modules/@sodax/dapp-kit/ai-exported/integration/architecture.md.
479
304
  ```
480
305
 
306
+ ### What's inside
307
+
308
+ ```
309
+ ai-exported/
310
+ ├── AGENTS.md # Tool-neutral entry point — start here
311
+ ├── integration/ # Building NEW v2 dapp-kit code
312
+ │ ├── README.md, ai-rules.md # Index + DO / DO NOT / workflow for agents
313
+ │ ├── quickstart.md # Install + wire providers + first feature
314
+ │ ├── architecture.md # Hook shapes, queryKey conventions, useSafeMutation, mutateAsyncSafe
315
+ │ ├── features/ # 8 feature pages: swap, money-market, staking, bridge,
316
+ │ │ # dex, migration, bitcoin (Radfi), auxiliary-services
317
+ │ ├── recipes/ # 13 patterns: setup, wallet-connectivity, per-feature flows,
318
+ │ │ # mutation error handling, observability, invalidations
319
+ │ └── reference/ # 4 lookup tables: full hook index, queryKey conventions,
320
+ │ # public API surface, glossary
321
+ └── migration/ # Porting EXISTING v1 dapp-kit code to v2
322
+ ├── README.md, ai-rules.md # Index + workflow for porting agents
323
+ ├── checklist.md # Top-down cross-cutting checklist
324
+ ├── breaking-changes/ # 4 cross-cutting changes: hook-signatures, result-handling,
325
+ │ # querykey-conventions, sdk-leakage
326
+ ├── features/ # 8 per-feature porting playbooks
327
+ ├── recipes.md # Codemods + adapters
328
+ └── reference/ # 3 reference tables: deleted hooks, renamed hooks,
329
+ # error-shape crosswalk
330
+ ```
331
+
332
+ ### Scope
333
+
334
+ This tree documents `@sodax/dapp-kit` (a React hooks library) only. It assumes:
335
+
336
+ - **TypeScript + React** (>=18). Examples use TSX.
337
+ - **Framework-agnostic**: works in any React app (Vite, Next.js client components, CRA, Remix, etc.). **No Next.js Server Components content** — dapp-kit is client-side React.
338
+ - **Sibling packages used in examples**: `@sodax/sdk` (peer; types and config; re-exported transparently from dapp-kit), `@sodax/wallet-sdk-react` (sibling; `useWalletProvider` is in every signed-flow example), `@tanstack/react-query` (peer).
339
+ - **`@sodax/types` is re-exported** through `@sodax/sdk` (which dapp-kit re-exports); consumers don't add it as a separate dependency.
340
+
341
+ The underlying Core SDK has its own ai-exported tree at `node_modules/@sodax/sdk/ai-exported/` (resolves correctly in node_modules). The dapp-kit migration tree links to it for SDK-leakage topics (chain-key terminology, `Result<T>` semantics, `SodaxError<C>`).
342
+
343
+ ### Integrity guarantees
344
+
345
+ Every release passes seven CI checks against `ai-exported/`:
346
+
347
+ | Guard | What it catches |
348
+ |---|---|
349
+ | `check:ai-exported` | Each `useFoo` hook reference in markdown matches a real exported hook from `@sodax/dapp-kit` (or an upstream allowlist: React, React Query, wallet-sdk-react). |
350
+ | `check:ai-scope` | No accidental imports from forbidden packages (e.g. `@sodax/wallet-sdk-core` for Node-only flows; `@sodax/types` directly). |
351
+ | `check:ai-links` | Every relative link between markdown files resolves (including cross-package links into `../../../sdk/ai-exported/`). |
352
+ | `check:ai-imports` | Every `import … from '@sodax/dapp-kit'` example in the docs typechecks against the package source. |
353
+ | `check:ai-snippets` | Every fenced `​```ts`/`​```tsx` block is typechecked AS-IS against source (opt-out via `// @ai-snippets-skip` for genuinely illustrative blocks). Catches call-shape drift like wrong `useQuote({ params: <Request> })` vs canonical `useQuote({ params: { payload: <Request> } })`. |
354
+ | `check:ai-keys` | Every `queryKey:` / `mutationKey:` literal in docs (both `kind: [...]` declarations and backticked-array table cells) matches a real source key prefix. Catches drift like `['staking', 'stakingInfo']` in docs when source uses `['staking', 'info']`. |
355
+ | `check:ai-consistency` | Polling-interval claims in docs (e.g. "polls 3s", "auto-refresh every 2s") match the actual `refetchInterval` value in source. Catches drift like docs claiming 1s when source is 3000ms. |
356
+
357
+ If you're contributing to this repo, run them with `pnpm -C packages/dapp-kit run check:ai-exported` (or `:scope`, `:links`, `:imports`, `:snippets`, `:keys`, `:consistency`).
358
+
481
359
  ## License
482
360
 
483
361
  [MIT](LICENSE)
484
362
 
485
363
  ## Support
486
364
 
487
- - [GitHub Issues](https://github.com/icon-project/sodax-frontend/issues)
365
+ - [GitHub Issues](https://github.com/icon-project/sodax-sdks/issues)
488
366
  - [Discord Community](https://discord.gg/sodax-formerly-icon-880651922682560582)