@sodax/dapp-kit 2.0.0-rc.3 → 2.0.0-rc.4

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 (61) hide show
  1. package/README.md +9 -63
  2. package/dist/index.mjs +0 -2
  3. package/package.json +31 -20
  4. package/ai-exported/AGENTS.md +0 -134
  5. package/ai-exported/integration/README.md +0 -49
  6. package/ai-exported/integration/ai-rules.md +0 -80
  7. package/ai-exported/integration/architecture.md +0 -276
  8. package/ai-exported/integration/features/README.md +0 -29
  9. package/ai-exported/integration/features/auxiliary-services.md +0 -169
  10. package/ai-exported/integration/features/bitcoin.md +0 -87
  11. package/ai-exported/integration/features/bridge.md +0 -91
  12. package/ai-exported/integration/features/dex.md +0 -152
  13. package/ai-exported/integration/features/migration.md +0 -118
  14. package/ai-exported/integration/features/money-market.md +0 -144
  15. package/ai-exported/integration/features/staking.md +0 -123
  16. package/ai-exported/integration/features/swap.md +0 -101
  17. package/ai-exported/integration/quickstart.md +0 -187
  18. package/ai-exported/integration/recipes/README.md +0 -136
  19. package/ai-exported/integration/recipes/backend-queries.md +0 -157
  20. package/ai-exported/integration/recipes/bitcoin.md +0 -193
  21. package/ai-exported/integration/recipes/bridge.md +0 -174
  22. package/ai-exported/integration/recipes/dex.md +0 -204
  23. package/ai-exported/integration/recipes/invalidations.md +0 -115
  24. package/ai-exported/integration/recipes/migration.md +0 -212
  25. package/ai-exported/integration/recipes/money-market.md +0 -207
  26. package/ai-exported/integration/recipes/mutation-error-handling.md +0 -118
  27. package/ai-exported/integration/recipes/observability.md +0 -93
  28. package/ai-exported/integration/recipes/setup.md +0 -168
  29. package/ai-exported/integration/recipes/staking.md +0 -202
  30. package/ai-exported/integration/recipes/swap.md +0 -272
  31. package/ai-exported/integration/recipes/wallet-connectivity.md +0 -128
  32. package/ai-exported/integration/reference/README.md +0 -12
  33. package/ai-exported/integration/reference/glossary.md +0 -190
  34. package/ai-exported/integration/reference/hooks-index.md +0 -190
  35. package/ai-exported/integration/reference/public-api.md +0 -110
  36. package/ai-exported/integration/reference/querykey-conventions.md +0 -179
  37. package/ai-exported/migration/README.md +0 -60
  38. package/ai-exported/migration/ai-rules.md +0 -81
  39. package/ai-exported/migration/breaking-changes/hook-signatures.md +0 -233
  40. package/ai-exported/migration/breaking-changes/querykey-conventions.md +0 -108
  41. package/ai-exported/migration/breaking-changes/result-handling.md +0 -211
  42. package/ai-exported/migration/breaking-changes/sdk-leakage.md +0 -167
  43. package/ai-exported/migration/checklist.md +0 -89
  44. package/ai-exported/migration/features/README.md +0 -34
  45. package/ai-exported/migration/features/auxiliary-services.md +0 -114
  46. package/ai-exported/migration/features/bitcoin.md +0 -88
  47. package/ai-exported/migration/features/bridge.md +0 -160
  48. package/ai-exported/migration/features/dex.md +0 -101
  49. package/ai-exported/migration/features/migration.md +0 -120
  50. package/ai-exported/migration/features/money-market.md +0 -139
  51. package/ai-exported/migration/features/staking.md +0 -109
  52. package/ai-exported/migration/features/swap.md +0 -133
  53. package/ai-exported/migration/recipes.md +0 -185
  54. package/ai-exported/migration/reference/README.md +0 -15
  55. package/ai-exported/migration/reference/deleted-hooks.md +0 -110
  56. package/ai-exported/migration/reference/error-shape-crosswalk.md +0 -144
  57. package/ai-exported/migration/reference/renamed-hooks.md +0 -68
  58. package/dist/index.cjs +0 -2641
  59. package/dist/index.cjs.map +0 -1
  60. package/dist/index.d.cts +0 -1557
  61. package/dist/index.mjs.map +0 -1
@@ -1,114 +0,0 @@
1
- # Auxiliary services migration — v1 → v2 (dapp-kit)
2
-
3
- Pair: [`../../integration/features/auxiliary-services.md`](../../integration/features/auxiliary-services.md).
4
-
5
- Smaller surfaces grouped together: partner, recovery, backend queries, shared utilities. Most changes are mechanical — single-object params, mutateAsyncSafe — same as the other features.
6
-
7
- ## Partner
8
-
9
- ```diff
10
- - const claim = useFeeClaimSwap(spokeProvider);
11
- - await claim.mutateAsync(params);
12
- + const walletProvider = useWalletProvider({ xChainId: ChainKeys.SONIC_MAINNET });
13
- + const { mutateAsyncSafe: claim } = useFeeClaimSwap();
14
- + const result = await claim({ params, walletProvider });
15
- ```
16
-
17
- `useApproveToken`, `useSetSwapPreference` — same pattern.
18
-
19
- `useFetchAssetsBalances`, `useGetAutoSwapPreferences`, `useIsTokenApproved` — convert to single-object query shape.
20
-
21
- ## Recovery
22
-
23
- ```diff
24
- - const withdraw = useWithdrawHubAsset(spokeProvider);
25
- + const { mutateAsyncSafe: withdraw } = useWithdrawHubAsset();
26
- + await withdraw({ params, walletProvider });
27
- ```
28
-
29
- ## Backend queries
30
-
31
- Read-only. No `walletProvider` involved. Convert to single-object query shape.
32
-
33
- ```diff
34
- - const { data: intent } = useBackendIntentByTxHash(txHash);
35
- + const { data: intent } = useBackendIntentByTxHash({ params: { txHash } });
36
-
37
- - const { data: orderbook } = useBackendOrderbook({ offset: '0', limit: '20' });
38
- + const { data: orderbook } = useBackendOrderbook({ pagination: { offset: '0', limit: '20' } });
39
-
40
- - const { data: position } = useBackendMoneyMarketPosition(userAddress);
41
- + const { data: position } = useBackendMoneyMarketPosition({ params: { userAddress } });
42
-
43
- - const { data: assets } = useBackendAllMoneyMarketAssets();
44
- + const { data: assets } = useBackendAllMoneyMarketAssets({});
45
- ```
46
-
47
- `useBackendSubmitSwapTx` is a mutation — per-call config flows through `mutate(vars)`:
48
-
49
- ```diff
50
- - const submit = useBackendSubmitSwapTx({ baseURL: 'https://...' }); // v1: per-instance config
51
- - await submit.mutateAsync(swapPayload);
52
- + const { mutateAsync: submit } = useBackendSubmitSwapTx();
53
- + await submit({ request: swapPayload, apiConfig: { baseURL: 'https://...' } }); // v2: per-call config
54
- ```
55
-
56
- ## Shared utilities
57
-
58
- ### `useXBalances`
59
-
60
- v2 requires four fields under `params`: `xService` (from `@sodax/wallet-sdk-react`), `xChainId`, `xTokens`, and `address`. The token list is no longer optional.
61
-
62
- ```diff
63
- - const { data: balances } = useXBalances(BSC_MAINNET_CHAIN_ID, address, tokens);
64
- + import { useXService, getXChainType } from '@sodax/wallet-sdk-react';
65
- + const xChainId = ChainKeys.BSC_MAINNET;
66
- + const xService = useXService({ xChainType: getXChainType(xChainId) });
67
- + const { data: balances } = useXBalances({
68
- + params: { xService, xChainId, xTokens, address },
69
- + });
70
- ```
71
-
72
- Note: the request param is still `xChainId` (not renamed to `chainKey`). This is intentional — `xChainId` overlays the cross-chain abstraction; the rename only happened for token-side fields. Don't conflate.
73
-
74
- ### `useEstimateGas`
75
-
76
- ```diff
77
- - const estimate = useEstimateGas(walletProvider);
78
- - await estimate.mutateAsync({ rawTx });
79
- + const { mutateAsyncSafe: estimateGas } = useEstimateGas();
80
- + const result = await estimateGas({ rawTx, walletProvider });
81
- ```
82
-
83
- ### `useStellarTrustlineCheck` / `useRequestTrustline`
84
-
85
- ```diff
86
- - const { data: hasTrustline } = useStellarTrustlineCheck(account, asset);
87
- + const { data: hasTrustline } = useStellarTrustlineCheck({ params: { account, asset } });
88
-
89
- - const request = useRequestTrustline(walletProvider);
90
- - await request.mutateAsync({ account, asset });
91
- + const { mutateAsync: request } = useRequestTrustline();
92
- + await request({ account, asset, walletProvider });
93
- ```
94
-
95
- ### `useDeriveUserWalletAddress` / `useGetUserHubWalletAddress`
96
-
97
- ```diff
98
- - const { data: hubAddress } = useDeriveUserWalletAddress(spokeChainKey, srcAddress);
99
- + const { data: hubAddress } = useDeriveUserWalletAddress({ params: { spokeChainKey, srcAddress } });
100
- ```
101
-
102
- ## Pitfalls
103
-
104
- 1. **`useBackendIntentByTxHash` polls every 1s while pending** — same as v1, but make sure your `queryOptions.refetchInterval` overrides if needed.
105
- 2. **`useBackendOrderbook` does NOT auto-refetch** — it has `staleTime: 30s` only, so data stays fresh for 30s after a fetch but won't refresh on its own. Trigger a refetch manually or pass `refetchInterval` via `queryOptions` if you need polling.
106
- 3. **`useXBalances` uses `xChainId` (not `chainKey`)** — request-side field name retained on this hook.
107
- 4. **`useBackendSubmitSwapTx` config moved to per-call.** v1 may have had `baseURL` at hook init; v2 puts it in `mutate(vars).apiConfig`. Lets you have a single hook serve multiple backends if needed.
108
-
109
- ## Cross-references
110
-
111
- - [`../../integration/features/auxiliary-services.md`](../../integration/features/auxiliary-services.md) — v2 reference.
112
- - [`../../integration/recipes/backend-queries.md`](../../integration/recipes/backend-queries.md) — backend hooks worked examples.
113
- - [`../../integration/recipes/wallet-connectivity.md`](../../integration/recipes/wallet-connectivity.md) — `useXBalances` worked example.
114
- - [`../../../../sdk/ai-exported/migration/features/auxiliary-services.md`](../../../../sdk/ai-exported/migration/features/auxiliary-services.md) — underlying SDK auxiliary migrations.
@@ -1,88 +0,0 @@
1
- # Bitcoin (Radfi) migration — v1 → v2 (dapp-kit)
2
-
3
- Pair: [`../../integration/features/bitcoin.md`](../../integration/features/bitcoin.md).
4
-
5
- Bitcoin / Radfi hook surface was new in v1 with limited adoption; v2 standardizes its shapes against the canonical hook conventions. Treat the v2 forms below as the canonical reference — if your v1 code used a different shape, swap to v2's directly.
6
-
7
- ## TL;DR
8
-
9
- > Cross-cutting conventions (drop `spokeProvider`, single-object hook init, `mutate(vars)` for domain inputs, `mutateAsyncSafe` ergonomics) — see [`../breaking-changes/hook-signatures.md`](../breaking-changes/hook-signatures.md) and [`../breaking-changes/result-handling.md`](../breaking-changes/result-handling.md). Bitcoin-specific deltas:
10
-
11
- 1. **`useRadfiSession` API unchanged** — still takes a `walletProvider` directly (not via `mutate(vars)`); it manages session lifecycle.
12
- 2. **`useTradingWallet(walletAddress)` is synchronous** — no Query/Mutation; reads localStorage. Unchanged.
13
- 3. **`useBitcoinBalance` / `useTradingWalletBalance`** use single-object query shape `{ params, queryOptions }`.
14
- 4. **Withdrawal/funding mutations** follow the canonical mutation hook shape — only `{ mutationOptions }` at hook init; `walletProvider` and per-call config flow through `mutate(vars)`.
15
-
16
- ## v2 canonical shapes
17
-
18
- ### `useFundTradingWallet`
19
-
20
- ```ts
21
- // @ai-snippets-skip
22
- const walletProvider = useWalletProvider({ xChainId: ChainKeys.BITCOIN_MAINNET });
23
- const { mutateAsyncSafe: fund } = useFundTradingWallet();
24
- const result = await fund({ amount: 100_000n, walletProvider });
25
- if (!result.ok) return;
26
- const txId = result.value;
27
- ```
28
-
29
- ### `useRadfiWithdraw`
30
-
31
- ```ts
32
- // @ai-snippets-skip
33
- const { mutateAsyncSafe: withdraw } = useRadfiWithdraw();
34
- const result = await withdraw({
35
- amount: '10000',
36
- tokenId: '0:0',
37
- withdrawTo,
38
- walletProvider,
39
- });
40
- ```
41
-
42
- ### `useRenewUtxos`
43
-
44
- ```ts
45
- // @ai-snippets-skip
46
- await renewUtxos({ txIdVouts, walletProvider });
47
- ```
48
-
49
- ### `useRadfiSession`
50
-
51
- ```ts
52
- // @ai-snippets-skip
53
- // Unchanged — still takes walletProvider directly (not via mutate vars).
54
- const { isAuthed, tradingAddress, login, isLoginPending } = useRadfiSession(walletProvider);
55
- ```
56
-
57
- The session-management lifecycle hook needs constant access to the wallet provider for token refresh — it doesn't fit the `mutate(vars)` pattern.
58
-
59
- ### `useBitcoinBalance` / `useTradingWalletBalance`
60
-
61
- Single-object query shape:
62
-
63
- ```diff
64
- - const { data } = useBitcoinBalance(address);
65
- + const { data } = useBitcoinBalance({ params: { address } });
66
-
67
- - const { data } = useTradingWalletBalance(walletProvider, tradingAddress);
68
- + const { data } = useTradingWalletBalance({ params: { walletProvider, tradingAddress } });
69
- ```
70
-
71
- ### `useExpiredUtxos`
72
-
73
- ```diff
74
- - const { data: expiredUtxos } = useExpiredUtxos(walletProvider, tradingAddress);
75
- + const { data: expiredUtxos } = useExpiredUtxos({ params: { walletProvider, tradingAddress } });
76
- ```
77
-
78
- ## Pitfalls
79
-
80
- 1. **`useRadfiSession` is the lifecycle owner.** Don't create your own `useRadfiAuth` ad-hoc handlers if you're using `useRadfiSession` — it manages auth + refresh + persistence.
81
- 2. **Session tokens in localStorage are NOT for asset access.** They're API rate-limit tokens. Compromise of localStorage data doesn't let an attacker move funds.
82
- 3. **Trading wallet is auto-created** during first authentication — don't add a separate "create wallet" step in your UI.
83
- 4. **PSBT signing flow is internal.** v1 may have surfaced the unsigned PSBT for explicit consumer signing; v2 hooks orchestrate the full flow (build → sign → co-sign → broadcast) inside `mutationFn`.
84
-
85
- ## Cross-references
86
-
87
- - [`../../integration/features/bitcoin.md`](../../integration/features/bitcoin.md) — v2 reference.
88
- - [`../../integration/recipes/bitcoin.md`](../../integration/recipes/bitcoin.md) — full v2 worked examples.
@@ -1,160 +0,0 @@
1
- # Bridge migration — v1 → v2 (dapp-kit)
2
-
3
- Pair: [`../../integration/features/bridge.md`](../../integration/features/bridge.md).
4
-
5
- ## TL;DR
6
-
7
- > Cross-cutting conventions (drop `spokeProvider`, single-object hook init, `mutate(vars)` for domain inputs, `mutateAsyncSafe` ergonomics) — see [`../breaking-changes/hook-signatures.md`](../breaking-changes/hook-signatures.md) and [`../breaking-changes/result-handling.md`](../breaking-changes/result-handling.md). Feature-specific deltas below:
8
-
9
- 1. **`CreateBridgeIntentParams` field renames** (SDK-leakage):
10
- - `srcChainId` → `srcChainKey`
11
- - `dstChainId` → `dstChainKey`
12
- - `srcAsset` → `srcToken`
13
- - `dstAsset` → `dstToken`
14
- - `recipient` is **unchanged** (stays `recipient` in v2 — it is NOT renamed to `dstAddress`; the only `dstAddress`-shaped field in v2 lives on money-market params, not bridge)
15
- - **NEW required**: `srcAddress` (the user's spoke-side sender address, distinct from `recipient` which is the destination)
16
- 2. **`bridge()` return shape changed.** v1 was `Promise<string>` (a single tx hash that threw on error). v2 returns `Promise<Result<TxHashPair, BridgeOrchestrationError>>` where `TxHashPair = { srcChainTxHash: string; dstChainTxHash: string }`. **This is the shape at the direct-SDK boundary** (`sodax.bridge.bridge(...)`); the `useBridge` hook does not adapt the inner object, it only unwraps the `Result` wrapper (so the hook surfaces `TxHashPair` directly via `data` / `mutateAsync` / `mutateAsyncSafe`'s `value`). Don't destructure as a tuple — there was no `[spokeTxHash, hubTxHash]` form in either v1 or v2.
17
- 3. **`useGetBridgeableAmount` reshape.** v1 took `(srcChainId, srcAsset, dstChainId, dstAsset)`. v2 takes `{ from: XToken, to: XToken }` — each `XToken` carries its own `chainKey`.
18
- 4. **`useGetBridgeableAmount` return value is `BridgeLimit`, not bare `bigint`.** Access `.value.amount` and `.value.decimals`.
19
- 5. **`useGetBridgeableTokens` is sync now** in the SDK. The hook still returns `UseQueryResult` but the underlying SDK call doesn't fire RPC — it's config-derived.
20
- 6. **Allowance/approve** — same shape changes as every other feature.
21
-
22
- ## Per-method delta
23
-
24
- ### `useBridge` — params + return
25
-
26
- ```diff
27
- function BridgeButton({ srcAddress }) {
28
- - const bridge = useBridge(spokeProvider);
29
- + const walletProvider = useWalletProvider({ xChainId: ChainKeys.BASE_MAINNET });
30
- + const { mutateAsyncSafe: bridge } = useBridge();
31
-
32
- const handleBridge = async () => {
33
- + if (!walletProvider) return;
34
- - // v1: single tx hash, throws on failure
35
- - const txHash: string = await bridge.mutateAsync({
36
- - params: {
37
- - srcChainId: BASE_MAINNET_CHAIN_ID,
38
- - srcAsset: '0x...',
39
- - amount: 1_000_000n,
40
- - dstChainId: POLYGON_MAINNET_CHAIN_ID,
41
- - dstAsset: '0x...',
42
- - recipient: '0x...',
43
- - },
44
- - });
45
- + const result = await bridge({
46
- + params: {
47
- + srcChainKey: ChainKeys.BASE_MAINNET,
48
- + srcAddress, // NEW: required (your spoke-side sender)
49
- + srcToken: '0x...', // RENAMED from `srcAsset`
50
- + amount: 1_000_000n,
51
- + dstChainKey: ChainKeys.POLYGON_MAINNET,
52
- + dstToken: '0x...', // RENAMED from `dstAsset`
53
- + recipient: '0x...', // UNCHANGED — destination receiver
54
- + },
55
- + walletProvider,
56
- + });
57
- + if (!result.ok) return;
58
- + const { srcChainTxHash, dstChainTxHash } = result.value; // TxHashPair object, not [a, b]
59
- };
60
- }
61
- ```
62
-
63
- ### Calling `sodax.bridge.bridge()` directly (no hook)
64
-
65
- If you call the SDK directly inside a custom `useMutation` (instead of `useBridge`), the return shape is **exactly the same** — the dapp-kit hook only unwraps the `Result` wrapper, it does not reshape `TxHashPair`:
66
-
67
- ```diff
68
- - // v1 direct-SDK call:
69
- - const txHash: string = await sodax.bridge.bridge({ params: { /* v1 shape */ }, spokeProvider });
70
- + // v2 direct-SDK call:
71
- + const result = await sodax.bridge.bridge({
72
- + params: {
73
- + srcChainKey: ChainKeys.BASE_MAINNET,
74
- + srcAddress,
75
- + srcToken: '0x...',
76
- + amount: 1_000_000n,
77
- + dstChainKey: ChainKeys.POLYGON_MAINNET,
78
- + dstToken: '0x...',
79
- + recipient: '0x...',
80
- + },
81
- + raw: false,
82
- + walletProvider,
83
- + });
84
- + // Type: Result<TxHashPair, BridgeOrchestrationError>
85
- + if (!result.ok) {
86
- + // result.error is a SodaxError<C> with feature: 'bridge'
87
- + return;
88
- + }
89
- + const { srcChainTxHash, dstChainTxHash } = result.value; // same shape as the hook
90
- ```
91
-
92
- The hook equivalence in code:
93
-
94
- ```ts
95
- // @ai-snippets-skip
96
- // What `useBridge` does internally (sketch):
97
- // mutationFn: async vars => unwrapResult(await sodax.bridge.bridge({ ...vars, raw: false }))
98
- // `unwrapResult` throws on `!ok` and returns `value` on `ok` — that's the only adapter.
99
- ```
100
-
101
- ### `useGetBridgeableAmount` — params + return reshape
102
-
103
- ```diff
104
- - const { data: amount } = useGetBridgeableAmount({
105
- - params: {
106
- - srcChainId: BASE_MAINNET_CHAIN_ID,
107
- - srcAsset: '0x...',
108
- - dstChainId: POLYGON_MAINNET_CHAIN_ID,
109
- - dstAsset: '0x...',
110
- - },
111
- - });
112
- - if (amount) {
113
- - <p>Max: {formatUnits(amount, 6)}</p>; // v1 was bare bigint
114
- - }
115
- + const { data: result } = useGetBridgeableAmount({
116
- + params: { from: srcXToken, to: dstXToken }, // each XToken carries chainKey
117
- + });
118
- + if (result?.ok) {
119
- + <p>Max: {formatUnits(result.value.amount, result.value.decimals)}</p>;
120
- + }
121
- ```
122
-
123
- ### `useGetBridgeableTokens`
124
-
125
- ```diff
126
- - const { data: tokens } = useGetBridgeableTokens(BASE_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, srcAsset);
127
- + const { data: result } = useGetBridgeableTokens({
128
- + params: { from: ChainKeys.BASE_MAINNET, to: ChainKeys.POLYGON_MAINNET, token: srcAsset },
129
- + });
130
- + if (result?.ok) {
131
- + const tokens: XToken[] = result.value;
132
- + }
133
- ```
134
-
135
- ### `useBridgeAllowance` / `useBridgeApprove`
136
-
137
- `useBridgeAllowance` query inputs (payload + walletProvider) all nest under `params` in v2:
138
-
139
- ```diff
140
- - const { data: allowanceResult } = useBridgeAllowance({ params, spokeProvider });
141
- + const { data: isApproved } = useBridgeAllowance({
142
- + params: { payload: bridgeParams, walletProvider },
143
- + });
144
- + // `data` is `boolean | undefined` (already unwrapped).
145
- ```
146
-
147
- `useBridgeApprove` mutation drops `spokeProvider` from hook init; `mutate(vars)` takes `{ params, walletProvider }`.
148
-
149
- ## Pitfalls
150
-
151
- 1. **`useGetBridgeableAmount` data shape changed.** v1 returned bare `bigint`; v2 returns `Result<BridgeLimit>` where `BridgeLimit = { amount, decimals, type }`. UI code that displayed the bigint directly needs `.value.amount`.
152
- 2. **Tokens must share the same vault** to be bridgeable. Use `useGetBridgeableTokens` to enumerate compatible destinations — passing an incompatible pair to `bridge()` rejects with `VALIDATION_FAILED`.
153
- 3. **`useBridge` return is `TxHashPair`** — destructure as `{ srcChainTxHash, dstChainTxHash }`, not `[a, b]`.
154
- 4. **`recipient` field renamed to `dstAddress`** for consistency with the rest of the SDK.
155
-
156
- ## Cross-references
157
-
158
- - [`../../integration/features/bridge.md`](../../integration/features/bridge.md) — v2 reference.
159
- - [`../../integration/recipes/bridge.md`](../../integration/recipes/bridge.md) — full v2 worked example.
160
- - [`../../../../sdk/ai-exported/migration/features/bridge.md`](../../../../sdk/ai-exported/migration/features/bridge.md) — underlying SDK bridge migration.
@@ -1,101 +0,0 @@
1
- # DEX migration — v1 → v2 (dapp-kit)
2
-
3
- Pair: [`../../integration/features/dex.md`](../../integration/features/dex.md).
4
-
5
- ## TL;DR
6
-
7
- > Cross-cutting conventions (drop `spokeProvider`, single-object hook init, `mutate(vars)` for domain inputs, `mutateAsyncSafe` ergonomics) — see [`../breaking-changes/hook-signatures.md`](../breaking-changes/hook-signatures.md) and [`../breaking-changes/result-handling.md`](../breaking-changes/result-handling.md). Feature-specific deltas below:
8
-
9
- 1. **All mutations** (`useDexDeposit`, `useDexWithdraw`, `useSupplyLiquidity`, `useDecreaseLiquidity`, `useClaimRewards`, `useDexApprove`) — single-object hook init + `mutate({ params, walletProvider })`. SDK-leakage adds required `srcChainKey` + `srcAddress` to all action params.
10
- 2. **`useSupplyLiquidity` handles both mint-new and increase-existing** — pass `tokenId` in params for increase, omit for mint. Use `useCreateSupplyLiquidityParams` to handle the routing.
11
- 3. **`usePools` returns synchronously** in the SDK. The hook still returns `UseQueryResult` but the underlying call is config-derived (no RPC) — `staleTime: Infinity`, no auto-refresh.
12
- 4. **Param builders take a FLAT props object** — `useCreateDepositParams`, `useCreateWithdrawParams`, `useCreateSupplyLiquidityParams`, `useCreateDecreaseLiquidityParams` — NOT `{ params: { ... } }`-wrapped. Their inputs use `srcChainKey` (not `srcChainId`); the result is spread into the mutation's `params` field at the call site.
13
-
14
- ## Per-method delta
15
-
16
- ### `useDexDeposit` / `useDexWithdraw`
17
-
18
- ```diff
19
- - const deposit = useDexDeposit(spokeProvider);
20
- - await deposit.mutateAsync({ params: { asset, amount, poolToken } });
21
- + const walletProvider = useWalletProvider({ xChainId: ChainKeys.BASE_MAINNET });
22
- + const { mutateAsyncSafe: deposit } = useDexDeposit();
23
- + const result = await deposit({
24
- + params: {
25
- + srcChainKey: ChainKeys.BASE_MAINNET,
26
- + srcAddress, // NEW
27
- + asset,
28
- + amount,
29
- + poolToken,
30
- + },
31
- + walletProvider,
32
- + });
33
- + if (!result.ok) return;
34
- + const { srcChainTxHash, dstChainTxHash } = result.value;
35
- ```
36
-
37
- ### `useSupplyLiquidity` — mint vs increase routing
38
-
39
- ```diff
40
- - // v1: separate hooks for mint and increase
41
- - const mint = useMintLiquidity(spokeProvider);
42
- - const increase = useIncreaseLiquidity(spokeProvider);
43
- - if (existingTokenId) {
44
- - await increase.mutateAsync({ params: { tokenId, poolKey, ... } });
45
- - } else {
46
- - await mint.mutateAsync({ params: { poolKey, ... } });
47
- - }
48
-
49
- + // v2: single hook handles both via tokenId presence
50
- + const { mutateAsyncSafe: supply } = useSupplyLiquidity();
51
- + const supplyParams = useCreateSupplyLiquidityParams({
52
- + params: { poolKey, tickLower, tickUpper, amount0, amount1, tokenId: existingTokenId },
53
- + });
54
- + if (supplyParams && walletProvider) {
55
- + const result = await supply({ params: supplyParams, walletProvider });
56
- + }
57
- ```
58
-
59
- ### `useDecreaseLiquidity` / `useClaimRewards`
60
-
61
- Standard pattern — drop `spokeProvider` from hook init, add `srcChainKey` / `srcAddress` to params, pass `walletProvider` via `mutate(vars)`.
62
-
63
- ### `useDexAllowance` / `useDexApprove`
64
-
65
- `useDexAllowance` wraps the deposit params under `params.payload`. Read-only — no `walletProvider`:
66
-
67
- ```diff
68
- - const { data: allowance } = useDexAllowance({ params: depositParams, walletProvider });
69
- + const { data: isApproved } = useDexAllowance({ params: { payload: depositParams } });
70
- + // `data` is `boolean | undefined`; the hook calls `isAllowanceValid` with `raw: true`.
71
- ```
72
-
73
- `useDexApprove` mutation drops `spokeProvider` from hook init; `mutate(vars)` takes `{ params, walletProvider }`.
74
-
75
- ### `usePoolData` / `usePositionInfo` / `usePools`
76
-
77
- Convert to single-object query shape:
78
-
79
- ```diff
80
- - const { data } = usePoolData(poolKey);
81
- + const { data } = usePoolData({ params: { poolKey } });
82
-
83
- - const { data } = usePositionInfo(tokenId, poolKey);
84
- + const { data } = usePositionInfo({ params: { tokenId, poolKey } });
85
-
86
- - const { data: pools } = usePools();
87
- + const { data: pools } = usePools({}); // single-object shape, even with no params
88
- ```
89
-
90
- ## Pitfalls
91
-
92
- 1. **`useSupplyLiquidity` is now ONE hook for both mint and increase.** v1 may have had two separate hooks. Use `tokenId` presence in `params` to drive the routing — `useCreateSupplyLiquidityParams` handles this for you.
93
- 2. **Two-step flow stays the same.** First `useDexDeposit` brings the spoke asset to the hub as pool-token shares. Then `useSupplyLiquidity` uses those shares to mint/grow a position. UI sequencing unchanged.
94
- 3. **Ticks are logarithmic.** Calculation libraries unchanged; just be aware that `tickLower` / `tickUpper` are tick indices, not prices.
95
- 4. **`usePools` never auto-refreshes** — pools are static config. Override `queryOptions.refetchInterval` only if you really know your config changed.
96
-
97
- ## Cross-references
98
-
99
- - [`../../integration/features/dex.md`](../../integration/features/dex.md) — v2 reference.
100
- - [`../../integration/recipes/dex.md`](../../integration/recipes/dex.md) — full v2 worked example.
101
- - [`../../../../sdk/ai-exported/migration/features/dex.md`](../../../../sdk/ai-exported/migration/features/dex.md) — underlying SDK DEX migration.
@@ -1,120 +0,0 @@
1
- # Migration migration — v1 → v2 (dapp-kit)
2
-
3
- Pair: [`../../integration/features/migration.md`](../../integration/features/migration.md).
4
-
5
- The biggest single API change in dapp-kit v2: v1 had a single `useMigrate(spokeProvider)`-style hook (often commented out by the time consumers needed it); v2 split it into 6 dedicated hooks.
6
-
7
- ## TL;DR
8
-
9
- > Cross-cutting conventions (drop `spokeProvider`, single-object hook init, `mutate(vars)` for domain inputs, `mutateAsyncSafe` ergonomics) — see [`../breaking-changes/hook-signatures.md`](../breaking-changes/hook-signatures.md) and [`../breaking-changes/result-handling.md`](../breaking-changes/result-handling.md). Feature-specific deltas below:
10
-
11
- 1. **`useMigrate(spokeProvider)` is gone.** Replaced by **six per-action hooks**:
12
- - `useMigrateIcxToSoda` — wICX (ICON) → SODA (Sonic)
13
- - `useRevertMigrateSodaToIcx` — SODA → wICX (revert)
14
- - `useMigratebnUSD` — legacy bnUSD ↔ new bnUSD (bidirectional)
15
- - `useMigrateBaln` — BALN (ICON) → SODA with optional lock period
16
- - `useMigrationApprove` — approve before migration (action-discriminated)
17
- - `useMigrationAllowance` — check approval (action-discriminated)
18
- 2. **`useMigratebnUSD` is bidirectional.** v2 detects direction from `(srcbnUSD, dstbnUSD)` token addresses — no separate forward/reverse hook.
19
- 3. **All mutations** drop `spokeProvider`; `walletProvider` flows through `mutate(vars)`. SDK-leakage adds `srcChainKey` / `srcAddress` to all action params.
20
- 4. **`useMigrationApprove` / `useMigrationAllowance` are action-discriminated.** Same hook handles all migration approvals; pass `action: 'migrate' | 'revert'` to disambiguate.
21
- 5. **BALN `lockupPeriod` is a literal union, not arbitrary number.** `0 | 1 | 2 | 3 | 6 | 12 | 18 | 24` (months).
22
-
23
- ## Per-method delta
24
-
25
- ### v1 single hook → v2 six hooks
26
-
27
- ```diff
28
- - // v1 — single hook
29
- - const migrate = useMigrate(spokeProvider);
30
- - await migrate.mutateAsync({ params: { type: 'icxToSoda', amount, /* ... */ } });
31
-
32
- + // v2 — pick the right hook
33
- + const { mutateAsyncSafe: migrate } = useMigrateIcxToSoda();
34
- + const result = await migrate({
35
- + params: {
36
- + srcChainKey: ChainKeys.ICON_MAINNET,
37
- + srcAddress: 'hx...',
38
- + address: 'cx88fd...', // wICX token address
39
- + amount,
40
- + dstAddress: '0x...', // Sonic recipient
41
- + },
42
- + walletProvider,
43
- + });
44
- + if (!result.ok) return;
45
- + const { srcChainTxHash, dstChainTxHash } = result.value;
46
- ```
47
-
48
- ### `useMigratebnUSD` — bidirectional via token addresses
49
-
50
- ```diff
51
- - // v1 might have had separate forward/reverse hooks (or all-in-one)
52
- + // v2: one hook; direction detected from (srcbnUSD, dstbnUSD)
53
- + const { mutateAsyncSafe: migratebnUSD } = useMigratebnUSD();
54
- + const result = await migratebnUSD({
55
- + params: {
56
- + srcChainKey: ChainKeys.BASE_MAINNET,
57
- + srcAddress: '0x...',
58
- + srcbnUSD: '0x... (legacy or new)',
59
- + dstChainKey: ChainKeys.ARBITRUM_MAINNET,
60
- + dstbnUSD: '0x... (the other one)',
61
- + amount,
62
- + dstAddress: '0x...',
63
- + },
64
- + walletProvider,
65
- + });
66
- + if (!result.ok) {
67
- + const direction = result.error.context?.direction; // 'forward' | 'reverse'
68
- + /* ... */
69
- + }
70
- ```
71
-
72
- ### `useMigrateBaln` — lock period
73
-
74
- ```diff
75
- + const { mutateAsyncSafe: migrateBaln } = useMigrateBaln();
76
- + await migrateBaln({
77
- + params: {
78
- + srcChainKey: ChainKeys.ICON_MAINNET,
79
- + srcAddress: 'hx...',
80
- + amount,
81
- + lockupPeriod: 12, // 0 | 1 | 2 | 3 | 6 | 12 | 18 | 24
82
- + dstAddress: '0x...',
83
- + },
84
- + walletProvider,
85
- + });
86
- ```
87
-
88
- ### `useMigrationApprove` / `useMigrationAllowance` — action-discriminated
89
-
90
- ```diff
91
- - const { approve } = useMigrationApprove(spokeProvider);
92
- - await approve(params);
93
- + const { data: isApproved } = useMigrationAllowance({
94
- + params: { params: revertParams, action: 'revert' },
95
- + });
96
- + const { mutateAsync: approve } = useMigrationApprove();
97
- + await approve({ params: revertParams, walletProvider, action: 'revert' });
98
- ```
99
-
100
- ## Approval requirements
101
-
102
- | Migration | Approval needed? |
103
- |---|---|
104
- | ICX/wICX (ICON) → SODA | No (ICON has no ERC-20 allowance) |
105
- | SODA → wICX (revert) | Yes |
106
- | Legacy bnUSD ↔ new bnUSD (EVM/Stellar source) | Yes |
107
- | BALN (ICON) → SODA | No |
108
-
109
- ## Pitfalls
110
-
111
- 1. **The single `useMigrate` is gone.** Pick the per-action hook that matches your migration. The v1 one-size-fits-all approach doesn't have a v2 shim.
112
- 2. **`useMigratebnUSD` direction detection.** v2 detects from token addresses. If both `srcbnUSD` and `dstbnUSD` are on the same side (both legacy or both new), the SDK rejects with `VALIDATION_FAILED`. Use `error.context?.direction` to disambiguate in error messaging.
113
- 3. **`lockupPeriod` is a literal union.** TypeScript rejects `lockupPeriod: 7`. Allowed: `0 | 1 | 2 | 3 | 6 | 12 | 18 | 24`. Reward multiplier ranges 0.5x (0 months) → 1.5x (24 months).
114
- 4. **ICON-side migrations don't need approval** — ICON has no ERC-20 allowance mechanism. Don't render an approve step for `useMigrateIcxToSoda` or `useMigrateBaln`.
115
-
116
- ## Cross-references
117
-
118
- - [`../../integration/features/migration.md`](../../integration/features/migration.md) — v2 reference.
119
- - [`../../integration/recipes/migration.md`](../../integration/recipes/migration.md) — full v2 worked examples (ICX, BALN, bnUSD, revert).
120
- - [`../../../../sdk/ai-exported/migration/features/icx-bnusd-baln.md`](../../../../sdk/ai-exported/migration/features/icx-bnusd-baln.md) — underlying SDK migration migration.