@sodax/dapp-kit 1.5.7-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 +1581 -1531
  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 +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
@@ -0,0 +1,188 @@
1
+ # Glossary — `@sodax/dapp-kit` v2
2
+
3
+ Type aliases, conventions, and domain terms specific to dapp-kit. SDK-side terms (Hub, Spoke, Intent, ChainKey, SodaxError, etc.) are documented in [`../../../../sdk/ai-exported/integration/reference/glossary.md`](../../../../sdk/ai-exported/integration/reference/glossary.md).
4
+
5
+ ## Hook shape types
6
+
7
+ ### `ReadHookParams<TData, TParams = void>`
8
+
9
+ Canonical shape for query hook arguments. Single object with `params` and `queryOptions` keys.
10
+
11
+ ```ts
12
+ // @ai-snippets-skip
13
+ type ReadHookParams<TData, TParams = void> = TParams extends void
14
+ ? { queryOptions?: ReadQueryOptions<TData> }
15
+ : { params?: TParams; queryOptions?: ReadQueryOptions<TData> };
16
+ ```
17
+
18
+ If a hook has no domain inputs (e.g. `useStakingConfig`), it uses `ReadHookParams<TData>` (no `TParams`) and accepts `({} = {})` for ergonomic no-arg calls.
19
+
20
+ ### `ReadQueryOptions<TData>`
21
+
22
+ The options slot for query hooks, omitting hook-owned fields.
23
+
24
+ ```ts
25
+ // @ai-snippets-skip
26
+ type ReadQueryOptions<TData> = Omit<UseQueryOptions<TData, Error>, 'queryKey' | 'queryFn' | 'enabled'>;
27
+ ```
28
+
29
+ Hook owns `queryKey`, `queryFn`, and `enabled` — never consumer-overridable. `enabled` is derived from required-input presence.
30
+
31
+ ### `MutationHookParams<TData, TVars>`
32
+
33
+ Canonical shape for mutation hook arguments. Single object with one key: `mutationOptions`.
34
+
35
+ ```ts
36
+ // @ai-snippets-skip
37
+ type MutationHookParams<TData, TVars> = {
38
+ mutationOptions?: MutationHookOptions<TData, TVars>;
39
+ };
40
+ ```
41
+
42
+ Domain inputs (`params`, `walletProvider`, per-call config) flow through `mutate(vars)` via `TVars`.
43
+
44
+ ### `MutationHookOptions<TData, TVars>`
45
+
46
+ The options slot for mutation hooks, omitting hook-owned fields.
47
+
48
+ ```ts
49
+ // @ai-snippets-skip
50
+ type MutationHookOptions<TData, TVars> = Omit<UseMutationOptions<TData, Error, TVars>, 'mutationFn'>;
51
+ ```
52
+
53
+ Hook owns `mutationFn`. Consumer can override `mutationKey`, `onSuccess`, `onError`, `retry`, `meta`, etc.
54
+
55
+ ### `SafeUseMutationResult<TData, TError, TVars>`
56
+
57
+ The return type of every dapp-kit mutation hook. Extends React Query's `UseMutationResult` with `mutateAsyncSafe`.
58
+
59
+ ```ts
60
+ // @ai-snippets-skip
61
+ type SafeUseMutationResult<TData, TError, TVars> = UseMutationResult<TData, TError, TVars> & {
62
+ mutateAsyncSafe: (vars: TVars) => Promise<Result<TData>>;
63
+ };
64
+ ```
65
+
66
+ `mutateAsyncSafe` never rejects — it packs the rejection into `Result<T>`. Use it for sequenced flows.
67
+
68
+ ### `Result<T>`
69
+
70
+ ```ts
71
+ type Result<T> = { ok: true; value: T } | { ok: false; error: Error | unknown };
72
+ ```
73
+
74
+ Re-exported from `@sodax/sdk`. Used as:
75
+ - The SDK service method return type (which `unwrapResult` translates to throws).
76
+ - The return type of `mutateAsyncSafe`.
77
+ - The `data` of some query hooks (when the underlying SDK method returns Result and we choose to surface it directly to the consumer rather than unwrapping in the hook).
78
+
79
+ ### `TxHashPair`
80
+
81
+ ```ts
82
+ type TxHashPair = {
83
+ srcChainTxHash: string;
84
+ dstChainTxHash: string;
85
+ };
86
+ ```
87
+
88
+ Re-exported from `@sodax/sdk`. Universal cross-chain mutation return: spoke chain tx + relayed hub tx. Returned by `useBridge`, all four MM mutations, all five staking mutations, `useDexDeposit`/`useDexWithdraw`, all four migration mutations.
89
+
90
+ **Always destructure as `{ srcChainTxHash, dstChainTxHash }`, never as `[a, b]`.**
91
+
92
+ ## Hook lifecycle terms
93
+
94
+ ### `mutationFn`
95
+
96
+ The function React Query invokes for a mutation. In dapp-kit, every `mutationFn` calls `unwrapResult(await sodax.<feature>.<method>(vars))`. Throws on SDK `!ok`. Hook-owned, never consumer-overridable.
97
+
98
+ ### `unwrapResult`
99
+
100
+ ```ts
101
+ // @ai-snippets-skip
102
+ function unwrapResult<T>(result: Result<T>): T;
103
+ ```
104
+
105
+ `{ ok: true; value }` → `value`. `{ ok: false; error }` → throws `error`. The bridge from SDK Result contract to React Query throw contract.
106
+
107
+ ### `toResult`
108
+
109
+ ```ts
110
+ // @ai-snippets-skip
111
+ function toResult<T>(promise: Promise<T>): Promise<Result<T>>;
112
+ ```
113
+
114
+ Inverse of `unwrapResult` for the rejection direction. Used internally by `useSafeMutation` to build `mutateAsyncSafe`.
115
+
116
+ ### `useSafeMutation`
117
+
118
+ Drop-in for React Query's `useMutation`. Returns `SafeUseMutationResult` (extends `UseMutationResult` with `mutateAsyncSafe`). Every dapp-kit mutation hook calls this — never call React Query's `useMutation` directly.
119
+
120
+ ### `mutateAsyncSafe`
121
+
122
+ The third call shape on every mutation hook. Returns `Promise<Result<TData>>`. Never rejects. Recommended for imperative sequenced flows.
123
+
124
+ ## Provider terms
125
+
126
+ ### `SodaxProvider`
127
+
128
+ App-level React component. Provides:
129
+ - A `Sodax` SDK instance (via `useSodaxContext()`)
130
+ - RPC config for all chains
131
+ - Hub provider access (via `useHubProvider()`)
132
+
133
+ Optional config: `<SodaxProvider config={DeepPartial<SodaxConfig>}>`. Without config, SDK uses packaged defaults.
134
+
135
+ ### `createSodaxQueryClient`
136
+
137
+ Factory for a `QueryClient` with `MutationCache.onError` pre-wired for global mutation observability. Optional — if you construct your own `QueryClient`, dapp-kit hooks still work; you just don't get the global observability seam.
138
+
139
+ ### `useSodaxContext`
140
+
141
+ The escape hatch into the SDK from any component under `SodaxProvider`. Returns `{ sodax: Sodax }`. Most hooks use this internally; consumers rarely need it directly.
142
+
143
+ ## Convention terms
144
+
145
+ ### "Single-object params"
146
+
147
+ Every hook accepts exactly one object argument. No positional args. For mutations: `{ mutationOptions }`. For queries: `{ params, queryOptions }`. Mechanically enforced.
148
+
149
+ ### "Zero-domain-param policy"
150
+
151
+ The mutation-hook rule that no domain inputs (`params`, `walletProvider`, etc.) live at the hook-init level — they all flow through `mutate(vars)` via `TVars`. This lets a single hook serve many call shapes without remounting.
152
+
153
+ ### "Hook-owned invalidations"
154
+
155
+ Mutation hooks invalidate the relevant query keys in their own `onSuccess`. Consumer-provided `onSuccess` runs after. Replaces v1's manual `invalidateMmQueries` utilities.
156
+
157
+ ### "Composed `onSuccess`"
158
+
159
+ The pattern by which a hook's internal `onSuccess` calls invalidations first, then `await mutationOptions?.onSuccess?.(...)` so the consumer's callback still fires.
160
+
161
+ ### "queryKey rule"
162
+
163
+ Every queryKey/mutationKey starts with the feature directory name (`'swap'`, `'mm'`, `'bridge'`, `'staking'`, `'dex'`, `'bitcoin'`, `'partner'`, `'recovery'`, `'backend'`, `'shared'`, `'migrate'`). camelCase segments. Bigints stringified. See [`querykey-conventions.md`](querykey-conventions.md).
164
+
165
+ ### "Default `mutationKey` before the spread"
166
+
167
+ <!-- ai-keys-allow -->
168
+ The order inside `useSafeMutation` calls: default `mutationKey: ['feature', 'action']` BEFORE `...mutationOptions`, then `mutationFn` AFTER. This way the consumer can override the default key via `mutationOptions.mutationKey`, but `mutationFn` (hook-owned) always wins.
169
+
170
+ ## v1 → v2 remapping
171
+
172
+ When porting v1 code, these shifts are pervasive:
173
+
174
+ | v1 | v2 |
175
+ |---|---|
176
+ | Positional hook args | Single-object params |
177
+ | Hook-level `spokeProvider` | `walletProvider` flows through `mutate(vars)` |
178
+ | `Result<T>` returned via React Query success | Throws in `mutationFn`; use `mutateAsyncSafe` for `Result<T>` flow |
179
+ | Approve hook returns `{ approve, isLoading, error }` | Returns `SafeUseMutationResult` with `mutateAsync` / `isPending` |
180
+ | Consumer-managed invalidations (`invalidateMmQueries`) | Hook-owned in composed `onSuccess` |
181
+ | Ad-hoc queryKey shapes | Feature-prefixed, camelCase, stringified bigints |
182
+
183
+ ## Cross-references
184
+
185
+ - [`../architecture.md`](../architecture.md) — full design rationale for these types and conventions.
186
+ - [`querykey-conventions.md`](querykey-conventions.md) — queryKey/mutationKey rules.
187
+ - [`public-api.md`](public-api.md) — what's exported.
188
+ - [`../../../../sdk/ai-exported/integration/reference/glossary.md`](../../../../sdk/ai-exported/integration/reference/glossary.md) — SDK-side terms (Hub, Spoke, Intent, ChainKey, SodaxError).
@@ -0,0 +1,194 @@
1
+ # Hooks index — `@sodax/dapp-kit` v2
2
+
3
+ Comprehensive hook table. ~95 hooks across 11 feature domains. Use this when you know the feature you're building but don't remember the exact hook name.
4
+
5
+ ## Provider + context
6
+
7
+ | Hook | Type | Purpose |
8
+ |---|---|---|
9
+ | `SodaxProvider` | Component | Wraps app; provides `Sodax` instance + RPC config |
10
+ | `createSodaxQueryClient` | Factory | Returns `QueryClient` with global mutation observability |
11
+ | `useSodaxContext` | Utility | Access the `Sodax` SDK instance |
12
+ | `useHubProvider` | Utility | Hub chain (Sonic) provider |
13
+
14
+ ## Swap (8)
15
+
16
+ | Hook | Type | Purpose |
17
+ |---|---|---|
18
+ | `useQuote` | Query | Real-time swap quote (auto-refreshes 3s) |
19
+ | `useSwap` | Mutation | Execute a complete cross-chain swap |
20
+ | `useSwapAllowance` | Query | Check token approval status |
21
+ | `useSwapApprove` | Mutation | Approve tokens for the swap contract |
22
+ | `useStatus` | Query | Track intent execution status (polls 3s once `intentTxHash` supplied; Result-wrapped data) |
23
+ | `useCancelSwap` | Mutation | Cancel an active swap intent |
24
+ | `useCreateLimitOrder` | Mutation | Create a limit order (no deadline) |
25
+ | `useCancelLimitOrder` | Mutation | Cancel a limit order |
26
+
27
+ ## Money market (13)
28
+
29
+ | Hook | Type | Purpose |
30
+ |---|---|---|
31
+ | `useSupply` | Mutation | Supply tokens as collateral |
32
+ | `useWithdraw` | Mutation | Withdraw supplied tokens |
33
+ | `useBorrow` | Mutation | Borrow against collateral |
34
+ | `useRepay` | Mutation | Repay borrowed tokens |
35
+ | `useMMAllowance` | Query | Approval check (`enabled: false` for borrow/withdraw — `data` stays `undefined`) |
36
+ | `useMMApprove` | Mutation | Approve tokens |
37
+ | `useReservesData` | Query | All reserve data (raw) |
38
+ | `useReservesHumanized` | Query | Reserves in decimal-normalized form |
39
+ | `useReservesList` | Query | List of reserve asset addresses |
40
+ | `useReservesUsdFormat` | Query | Reserves with USD overlays |
41
+ | `useUserFormattedSummary` | Query | Health factor, collateral, debt summary |
42
+ | `useUserReservesData` | Query | Per-reserve user position |
43
+ | `useAToken` | Query | aToken metadata |
44
+ | `useATokensBalances` | Query | aToken balances |
45
+
46
+ ## Bridge (5)
47
+
48
+ | Hook | Type | Purpose |
49
+ |---|---|---|
50
+ | `useBridge` | Mutation | Execute a cross-chain bridge transfer |
51
+ | `useBridgeAllowance` | Query | Approval check |
52
+ | `useBridgeApprove` | Mutation | Approve tokens for bridge |
53
+ | `useGetBridgeableAmount` | Query | Max bridgeable amount between two `XToken`s |
54
+ | `useGetBridgeableTokens` | Query | Tokens bridgeable to a destination chain |
55
+
56
+ ## Staking (~18)
57
+
58
+ | Hook | Type | Purpose |
59
+ |---|---|---|
60
+ | `useStake` | Mutation | Stake SODA, receive xSODA |
61
+ | `useUnstake` | Mutation | Request unstake (waiting period) |
62
+ | `useInstantUnstake` | Mutation | Instant unstake (with slippage) |
63
+ | `useClaim` | Mutation | Claim SODA after waiting period |
64
+ | `useCancelUnstake` | Mutation | Cancel pending unstake |
65
+ | `useStakeApprove` | Mutation | Approve SODA for staking |
66
+ | `useUnstakeApprove` | Mutation | Approve xSODA for unstaking |
67
+ | `useInstantUnstakeApprove` | Mutation | Approve xSODA for instant unstaking |
68
+ | `useStakeAllowance` | Query | Check SODA approval |
69
+ | `useUnstakeAllowance` | Query | Check xSODA approval (unstaking) |
70
+ | `useInstantUnstakeAllowance` | Query | Check xSODA approval (instant) |
71
+ | `useStakingInfo` | Query | User position |
72
+ | `useUnstakingInfo` | Query | Pending unstake requests |
73
+ | `useUnstakingInfoWithPenalty` | Query | Pending requests + penalty calcs |
74
+ | `useStakingConfig` | Query | Unstaking period, max penalty |
75
+ | `useStakeRatio` | Query | SODA-to-xSODA exchange rate (returns tuple) |
76
+ | `useInstantUnstakeRatio` | Query | Instant unstake rate |
77
+ | `useConvertedAssets` | Query | xSODA → SODA conversion |
78
+
79
+ ## DEX (~13)
80
+
81
+ | Hook | Type | Purpose |
82
+ |---|---|---|
83
+ | `usePools` | Query | List available pools (synchronous; no auto-refresh) |
84
+ | `usePoolData` | Query | Pool details (price, tick, liquidity) |
85
+ | `usePoolBalances` | Query | User's pool token balances |
86
+ | `usePositionInfo` | Query | Position details by tokenId |
87
+ | `useLiquidityAmounts` | Query | Token amounts for a tick range |
88
+ | `useDexDeposit` | Mutation | Deposit assets into pool tokens |
89
+ | `useDexWithdraw` | Mutation | Withdraw assets from pool tokens |
90
+ | `useDexAllowance` | Query | Approval check |
91
+ | `useDexApprove` | Mutation | Approve tokens |
92
+ | `useSupplyLiquidity` | Mutation | Supply liquidity (mint or increase) |
93
+ | `useDecreaseLiquidity` | Mutation | Remove liquidity |
94
+ | `useClaimRewards` | Mutation | Claim trading fees |
95
+ | `useCreateDepositParams` | Param builder | Build deposit params with ERC-4626 conversion |
96
+ | `useCreateWithdrawParams` | Param builder | Build withdraw params |
97
+ | `useCreateSupplyLiquidityParams` | Param builder | Build tick-range + liquidity params |
98
+ | `useCreateDecreaseLiquidityParams` | Param builder | Build decrease params from position state |
99
+
100
+ ## Migration (6)
101
+
102
+ | Hook | Type | Purpose |
103
+ |---|---|---|
104
+ | `useMigrateIcxToSoda` | Mutation | ICX/wICX (ICON) → SODA (Sonic) |
105
+ | `useRevertMigrateSodaToIcx` | Mutation | SODA (Sonic) → wICX (ICON) |
106
+ | `useMigratebnUSD` | Mutation | Legacy bnUSD ↔ new bnUSD (bidirectional) |
107
+ | `useMigrateBaln` | Mutation | BALN (ICON) → SODA with optional lock period |
108
+ | `useMigrationApprove` | Mutation | Approve before migration (action-discriminated) |
109
+ | `useMigrationAllowance` | Query | Approval check (action-discriminated) |
110
+
111
+ ## Bitcoin / Radfi (~8)
112
+
113
+ | Hook | Type | Purpose |
114
+ |---|---|---|
115
+ | `useRadfiAuth` | Mutation | Authenticate via BIP322 signing |
116
+ | `useRadfiSession` | Utility | Manage full session lifecycle |
117
+ | `useTradingWallet` | Utility | Synchronously read trading wallet from localStorage |
118
+ | `useBitcoinBalance` | Query | BTC balance for any address |
119
+ | `useTradingWalletBalance` | Query | Trading wallet balance from Radfi API |
120
+ | `useFundTradingWallet` | Mutation | Fund trading wallet from personal wallet |
121
+ | `useRadfiWithdraw` | Mutation | Withdraw from trading wallet |
122
+ | `useExpiredUtxos` | Query | Expired UTXOs (polls 60s) |
123
+ | `useRenewUtxos` | Mutation | Renew expired UTXOs |
124
+
125
+ ## Backend queries (~13)
126
+
127
+ ### Intents
128
+
129
+ | Hook | Polling |
130
+ |---|---|
131
+ | `useBackendIntentByTxHash` | 1s (refetchInterval; fires once a `txHash` is set, unconditional) |
132
+ | `useBackendIntentByHash` | none |
133
+ | `useBackendUserIntents` | none |
134
+
135
+ ### Orderbook + swap submission
136
+
137
+ | Hook | Type / Polling |
138
+ |---|---|
139
+ | `useBackendOrderbook` | Query; `staleTime: 30s` — fresh-window only, no background refetch |
140
+ | `useBackendSubmitSwapTx` | Mutation |
141
+ | `useBackendSubmitSwapTxStatus` | Query; polls until `executed` / `failed` |
142
+
143
+ ### Money market data
144
+
145
+ | Hook | Purpose |
146
+ |---|---|
147
+ | `useBackendMoneyMarketPosition` | User position |
148
+ | `useBackendMoneyMarketAsset` | Asset details |
149
+ | `useBackendAllMoneyMarketAssets` | All MM assets |
150
+ | `useBackendMoneyMarketAssetSuppliers` | Suppliers for an asset |
151
+ | `useBackendMoneyMarketAssetBorrowers` | Borrowers for an asset |
152
+ | `useBackendAllMoneyMarketBorrowers` | All borrowers |
153
+
154
+ ## Partner (6)
155
+
156
+ | Hook | Type | Purpose |
157
+ |---|---|---|
158
+ | `useFetchAssetsBalances` | Query | Fetch partner asset balances |
159
+ | `useGetAutoSwapPreferences` | Query | Get auto-swap preferences |
160
+ | `useIsTokenApproved` | Query | Check token approval |
161
+ | `useApproveToken` | Mutation | Approve token |
162
+ | `useSetSwapPreference` | Mutation | Set swap preference |
163
+ | `useFeeClaimSwap` | Mutation | Claim partner fees via swap |
164
+
165
+ ## Recovery (2)
166
+
167
+ | Hook | Type | Purpose |
168
+ |---|---|---|
169
+ | `useHubAssetBalances` | Query | Hub asset balances |
170
+ | `useWithdrawHubAsset` | Mutation | Withdraw hub asset |
171
+
172
+ ## Shared (~9)
173
+
174
+ | Hook | Type | Purpose |
175
+ |---|---|---|
176
+ | `useXBalances` | Query | Cross-chain token balances |
177
+ | `useDeriveUserWalletAddress` | Query | Derive hub wallet (CREATE3) |
178
+ | `useGetUserHubWalletAddress` | Query | Derive hub wallet (wallet router) |
179
+ | `useEstimateGas` | Mutation | Estimate gas for raw tx |
180
+ | `useStellarTrustlineCheck` | Query | Check Stellar trustline |
181
+ | `useRequestTrustline` | Mutation | Request a Stellar trustline |
182
+ | `useSafeMutation` | Internal | The wrapper every mutation hook calls |
183
+ | `unwrapResult` | Internal | `Result<T>` → throw / return |
184
+ | `toResult` | Internal | `Promise<T>` → `Result<T>` |
185
+
186
+ ## Total
187
+
188
+ 41 mutations + ~50 queries + utilities + provider = **~95 hooks**.
189
+
190
+ ## Cross-references
191
+
192
+ - [`../features/`](../features/) — per-feature reference docs (params types, return shapes, gotchas).
193
+ - [`../recipes/`](../recipes/) — copy-paste worked examples per feature.
194
+ - [`querykey-conventions.md`](querykey-conventions.md) — queryKey/mutationKey shape rules.
@@ -0,0 +1,110 @@
1
+ # Public API — `@sodax/dapp-kit`
2
+
3
+ What `@sodax/dapp-kit` exports + import rules.
4
+
5
+ ## Barrel exports
6
+
7
+ The package's `src/index.ts` re-exports four buckets:
8
+
9
+ ```ts
10
+ // @ai-snippets-skip
11
+ export * from './hooks/index.js'; // ~95 hooks across 11 feature dirs
12
+ export * from './providers/index.js'; // SodaxProvider, createSodaxQueryClient
13
+ export * from './utils/index.js'; // dex-utils param builders
14
+ export * from '@sodax/sdk'; // FULL @sodax/sdk re-export
15
+ ```
16
+
17
+ Practical implications:
18
+ - All ~95 hooks are importable from the root: `import { useSwap, useSupply, ... } from '@sodax/dapp-kit'`.
19
+ - All `@sodax/sdk` types are importable from `@sodax/dapp-kit` directly: `import { ChainKeys, type SodaxConfig, type CreateIntentParams } from '@sodax/dapp-kit'`.
20
+ - You may also import directly from `@sodax/sdk` — both work, both are stable.
21
+
22
+ ## Provider
23
+
24
+ | Export | Type | Purpose |
25
+ |---|---|---|
26
+ | `SodaxProvider` | Component | App-level wrapper; provides `Sodax` SDK instance + RPC config |
27
+ | `createSodaxQueryClient` | Factory | Returns a `QueryClient` pre-wired with `MutationCache.onError` for global mutation observability |
28
+
29
+ ## Hooks
30
+
31
+ See [`hooks-index.md`](hooks-index.md) for the comprehensive table.
32
+
33
+ ## Utility types (for writing your own hooks against dapp-kit)
34
+
35
+ ```ts
36
+ // @ai-snippets-skip
37
+ type ReadHookParams<TData, TParams = void> = TParams extends void
38
+ ? { queryOptions?: ReadQueryOptions<TData> }
39
+ : { params?: TParams; queryOptions?: ReadQueryOptions<TData> };
40
+
41
+ type ReadQueryOptions<TData> = Omit<UseQueryOptions<TData, Error>, 'queryKey' | 'queryFn' | 'enabled'>;
42
+
43
+ type MutationHookParams<TData, TVars> = {
44
+ mutationOptions?: MutationHookOptions<TData, TVars>;
45
+ };
46
+
47
+ type MutationHookOptions<TData, TVars> = Omit<UseMutationOptions<TData, Error, TVars>, 'mutationFn'>;
48
+
49
+ type SafeUseMutationResult<TData, TError, TVars> = UseMutationResult<TData, TError, TVars> & {
50
+ mutateAsyncSafe: (vars: TVars) => Promise<Result<TData>>;
51
+ };
52
+ ```
53
+
54
+ ## Helper functions (exported but mostly internal)
55
+
56
+ | Export | Purpose |
57
+ |---|---|
58
+ | `useSafeMutation` | Drop-in replacement for React Query's `useMutation` — every dapp-kit mutation hook calls this internally |
59
+ | `unwrapResult` | `Result<T>` → throw on `!ok`, return `value` on `ok` |
60
+ | `toResult` | `Promise<T>` → `Promise<Result<T>>` |
61
+
62
+ You won't need these unless you're writing a wrapper hook around a dapp-kit mutation hook. See [`../architecture.md`](../architecture.md) § "Mutation hook shape" for the full contract.
63
+
64
+ ## DEX param builders (exported from utils)
65
+
66
+ ```ts
67
+ import {
68
+ createDepositParamsProps,
69
+ createWithdrawParamsProps,
70
+ createSupplyLiquidityParamsProps,
71
+ createDecreaseLiquidityParamsProps,
72
+ } from '@sodax/dapp-kit';
73
+ ```
74
+
75
+ These are pure functions for assembling DEX feature params from pool data + user input. The hooks `useCreateDepositParams`, etc., wrap them with React Query state.
76
+
77
+ ## Import rules
78
+
79
+ ### DO
80
+
81
+ - ✓ Import from the package root: `import { useSwap } from '@sodax/dapp-kit'`.
82
+ - ✓ Import SDK types from dapp-kit: `import { ChainKeys, type SodaxConfig } from '@sodax/dapp-kit'`. Re-exported transparently.
83
+ - ✓ Import SDK types from SDK: `import { ChainKeys } from '@sodax/sdk'`. Same outcome.
84
+ - ✓ Import wallet-sdk-react hooks separately: `import { useWalletProvider } from '@sodax/wallet-sdk-react'`. Sibling package, not re-exported.
85
+
86
+ ### DO NOT
87
+
88
+ - ✗ Deep-import from `dist/`: importing from a path like `@sodax/dapp-kit/dist/...`. Internal paths are not stable; only the package root is the public contract.
89
+ - ✗ Add `@sodax/types` as a separate dependency. It's transitively re-exported via `@sodax/sdk` (which dapp-kit re-exports). Adding it independently invites version skew.
90
+ - ✗ Import from `@sodax/wallet-sdk-core`. That's the Node-side wallet implementations package — irrelevant for React consumers; use `@sodax/wallet-sdk-react`.
91
+
92
+ ## Tarball contents
93
+
94
+ The published `@sodax/dapp-kit` tarball contains:
95
+
96
+ ```
97
+ dist/ # Built ESM (.mjs) + CJS (.cjs) + .d.ts
98
+ ai-exported/ # This documentation tree
99
+ package.json
100
+ README.md
101
+ LICENSE
102
+ ```
103
+
104
+ Don't rely on any other path being present.
105
+
106
+ ## Cross-references
107
+
108
+ - [`../architecture.md`](../architecture.md) — design rationale for the canonical hook shapes.
109
+ - [`hooks-index.md`](hooks-index.md) — full hook list.
110
+ - [`../../../../sdk/ai-exported/integration/reference/public-api.md`](../../../../sdk/ai-exported/integration/reference/public-api.md) — underlying SDK's public API surface.
@@ -0,0 +1,179 @@
1
+ # queryKey / mutationKey conventions — `@sodax/dapp-kit`
2
+
3
+ Mandatory shape rules for every `queryKey` and `mutationKey`. Mechanically enforced on mutation keys by [`packages/dapp-kit/src/hooks/_mutationContract.test.ts`](../../../src/hooks/_mutationContract.test.ts); reviewer-enforced on query keys.
4
+
5
+ ## The five rules
6
+
7
+ ### Rule 1 — first segment is the feature directory name
8
+
9
+ | Hook directory | First segment |
10
+ |---|---|
11
+ | `backend/` | `'backend'` |
12
+ | `bitcoin/` | `'bitcoin'` |
13
+ | `bridge/` | `'bridge'` |
14
+ | `dex/` | `'dex'` |
15
+ | `mm/` | `'mm'` |
16
+ | `partner/` | `'partner'` |
17
+ | `recovery/` | `'recovery'` |
18
+ | `shared/` | `'shared'` |
19
+ | `staking/` | `'staking'` |
20
+ | `swap/` | `'swap'` |
21
+ | `migrate/` | `'migrate'` |
22
+
23
+ No exceptions. A hook in `swap/` whose key starts with `'intent'` is wrong.
24
+
25
+ ### Rule 2 — camelCase for all segments
26
+
27
+ No kebab-case (`'btc-balance'`), no ad-hoc casing, no `snake_case`. Identifiers are camelCase string literals (`'tradingWalletBalance'`, `'submitSwapTx'`).
28
+
29
+ ### Rule 3 — shape is `[feature, action, ...identifiers]`
30
+
31
+ Stable order: chain → token/asset → user → amount.
32
+
33
+ ```ts
34
+ // @ai-snippets-skip
35
+ queryKey: ['mm', 'allowance', srcChainKey, token, action]
36
+ // not ['mm', 'allowance', token, srcChainKey, action]
37
+ ```
38
+
39
+ ### Rule 4 — bigints stringify
40
+
41
+ React Query's hash uses `JSON.stringify` which throws on raw bigints. Always coerce:
42
+
43
+ ```ts
44
+ queryKey: ['staking', 'stakeRatio', amount.toString()] // ✓
45
+ queryKey: ['staking', 'stakeRatio', amount] // ✗ — runtime crash
46
+ ```
47
+
48
+ Exception: query keys that pass bigint via the read hook's typed params and the corresponding invalidations use the same raw value — match the read hook's shape exactly. New code should always stringify.
49
+
50
+ ### Rule 5 — invalidate the narrowest key that could change
51
+
52
+ If the mutation knows the affected `tokenId` / user / chain, scope the invalidation to it. Bare keys (no segments past the action) are reserved for "we don't know which variant changed" cases and should be commented.
53
+
54
+ ```ts
55
+ // Good — narrow scope
56
+ queryClient.invalidateQueries({ queryKey: ['dex', 'positionInfo', tokenId, poolKey] });
57
+
58
+ // Acceptable — when the mutation can't scope further
59
+ queryClient.invalidateQueries({ queryKey: ['swap', 'allowance'] }); // wipe all allowance variants on approve
60
+ ```
61
+
62
+ ## Worked examples
63
+
64
+ ```ts
65
+ // @ai-snippets-skip
66
+ // Cross-feature pattern: allowance reads. Shapes vary per feature (each carries
67
+ // the inputs that actually scope the allowance). Match the read hook's shape exactly
68
+ // from invalidations.
69
+ queryKey: ['mm', 'allowance', srcChainKey, token, action]
70
+ queryKey: ['swap', 'allowance', srcChainKey, srcAddress, inputToken, inputAmount.toString()]
71
+ queryKey: ['bridge', 'allowance', srcChainKey, srcAddress, srcToken, amount.toString()]
72
+ queryKey: ['dex', 'allowance', srcChainKey, asset, amount.toString()]
73
+ queryKey: ['staking', 'allowance', srcChainKey, action, srcAddress, amount.toString()]
74
+ // ^^ action is a fixed literal per hook: 'stake' / 'unstake' / 'instantUnstake'
75
+
76
+ // User position reads
77
+ queryKey: ['mm', 'userReservesData', spokeChainKey, userAddress]
78
+ queryKey: ['staking', 'info', srcChainKey, srcAddress] // useStakingInfo — second segment is 'info', not 'stakingInfo'
79
+ queryKey: ['shared', 'xBalances', xChainId, tokens, address]
80
+
81
+ // Mutation default keys
82
+ mutationKey: ['swap'] // useSwap
83
+ mutationKey: ['swap', 'approve'] // useSwapApprove
84
+ mutationKey: ['swap', 'cancel'] // useCancelSwap
85
+ mutationKey: ['swap', 'limitOrder', 'create'] // useCreateLimitOrder
86
+ mutationKey: ['swap', 'limitOrder', 'cancel'] // useCancelLimitOrder
87
+ mutationKey: ['mm', 'supply']
88
+ mutationKey: ['staking', 'stake']
89
+ mutationKey: ['staking', 'approve', 'stake'] // useStakeApprove (action discriminator inside the key)
90
+ mutationKey: ['bridge'] // useBridge — single segment (no 'execute' suffix)
91
+ mutationKey: ['migrate', 'icxToSoda']
92
+ mutationKey: ['dex', 'supplyLiquidity']
93
+ ```
94
+
95
+ ## Per-feature key tables
96
+
97
+ Skip if you're writing a feature hook for the first time and want to align with existing conventions.
98
+
99
+ ### Swap
100
+
101
+ | Key | Hook |
102
+ |---|---|
103
+ | `['swap', 'quote', { ...payload, amount: payload.amount.toString() }]` | `useQuote` (object segment with bigint stringified) |
104
+ | `['swap', 'allowance', srcChainKey, srcAddress, inputToken, inputAmount.toString()]` | `useSwapAllowance` |
105
+ | `['swap', 'status', intentTxHash]` | `useStatus` |
106
+ | `['swap']` | `useSwap` mutation key |
107
+ | `['swap', 'approve']` | `useSwapApprove` |
108
+ | `['swap', 'cancel']` | `useCancelSwap` |
109
+ | `['swap', 'limitOrder', 'create']` | `useCreateLimitOrder` |
110
+ | `['swap', 'limitOrder', 'cancel']` | `useCancelLimitOrder` |
111
+
112
+ ### Money market
113
+
114
+ | Key | Hook |
115
+ |---|---|
116
+ | `['mm', 'reservesData']` | `useReservesData` |
117
+ | `['mm', 'reservesHumanized']` | `useReservesHumanized` |
118
+ | `['mm', 'reservesList']` | `useReservesList` |
119
+ | `['mm', 'reservesUsdFormat']` | `useReservesUsdFormat` |
120
+ | `['mm', 'userReservesData', spokeChainKey, userAddress]` | `useUserReservesData` |
121
+ | `['mm', 'userFormattedSummary', spokeChainKey, userAddress]` | `useUserFormattedSummary` |
122
+ | `['mm', 'allowance', srcChainKey, token, action]` | `useMMAllowance` |
123
+ | `['mm', 'aToken', aToken]` | `useAToken` |
124
+ | `['mm', 'aTokensBalances', aTokens, spokeChainKey, userAddress]` | `useATokensBalances` |
125
+ | `['mm', 'supply']` | `useSupply` mutation |
126
+ | `['mm', 'borrow']` | `useBorrow` |
127
+ | `['mm', 'withdraw']` | `useWithdraw` |
128
+ | `['mm', 'repay']` | `useRepay` |
129
+ | `['mm', 'approve']` | `useMMApprove` |
130
+
131
+ ### Staking
132
+
133
+ | Key | Hook |
134
+ |---|---|
135
+ | `['staking', 'info', srcChainKey, srcAddress]` | `useStakingInfo` (second segment is `'info'`, NOT `'stakingInfo'`) |
136
+ | `['staking', 'unstakingInfo', srcChainKey, srcAddress]` | `useUnstakingInfo` |
137
+ | `['staking', 'unstakingInfoWithPenalty', srcChainKey, srcAddress]` | `useUnstakingInfoWithPenalty` |
138
+ | `['staking', 'config']` | `useStakingConfig` |
139
+ | `['staking', 'stakeRatio', amount.toString()]` | `useStakeRatio` |
140
+ | `['staking', 'instantUnstakeRatio', amount.toString()]` | `useInstantUnstakeRatio` |
141
+ | `['staking', 'convertedAssets', amount.toString()]` | `useConvertedAssets` |
142
+ | `['staking', 'allowance', srcChainKey, action, srcAddress, amount.toString()]` | `useStakeAllowance` / `useUnstakeAllowance` / `useInstantUnstakeAllowance` — `action` is a fixed literal per hook |
143
+ | `['staking', 'stake']` | `useStake` mutation |
144
+ | `['staking', 'unstake']` | `useUnstake` |
145
+ | `['staking', 'instantUnstake']` | `useInstantUnstake` |
146
+ | `['staking', 'claim']` | `useClaim` |
147
+ | `['staking', 'cancelUnstake']` | `useCancelUnstake` |
148
+ | `['staking', 'approve', 'stake' \| 'unstake' \| 'instantUnstake']` | `useStakeApprove` / `useUnstakeApprove` / `useInstantUnstakeApprove` |
149
+
150
+ ### Bridge / DEX / Migration / Bitcoin / etc.
151
+
152
+ Follow the same shape. See the source hook files (`packages/dapp-kit/src/hooks/<feature>/`) for current keys.
153
+
154
+ ## v1 → v2
155
+
156
+ In v1 dapp-kit, queryKey conventions were ad-hoc:
157
+
158
+ ```ts
159
+ // @ai-snippets-skip — queryKey-shape examples; `...` is a placeholder, not real code
160
+ // ai-keys-allow — v1 keys shown for migration context; not real v2 source keys
161
+ // v1 examples
162
+ queryKey: ['xBalances', ...] // missing feature prefix
163
+ queryKey: ['btc-balance', ...] // kebab-case
164
+ queryKey: ['api', 'mm', ...] // wrong feature prefix
165
+ mutationKey: undefined // many hooks had no default
166
+
167
+ // v2
168
+ queryKey: ['shared', 'xBalances', ...] // feature-prefixed
169
+ queryKey: ['bitcoin', 'balance', ...] // camelCase
170
+ queryKey: ['backend', 'mm', ...] // correctly nested under 'backend'
171
+ mutationKey: ['mm', 'supply'] // every hook has a default; consumer can override via mutationOptions.mutationKey
172
+ ```
173
+
174
+ For migration code grafting onto dapp-kit's cache invalidation, see [`../../migration/breaking-changes/querykey-conventions.md`](../../migration/breaking-changes/querykey-conventions.md).
175
+
176
+ ## Cross-references
177
+
178
+ - [`../architecture.md`](../architecture.md) § "queryKey / mutationKey conventions" — full design rationale.
179
+ - [`hooks-index.md`](hooks-index.md) — full hook table.