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

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.
@@ -27,7 +27,9 @@ Pair: [`../../integration/features/swap.md`](../../integration/features/swap.md)
27
27
  + if (!walletProvider) return;
28
28
  - const result = await swap.mutateAsync({ params: intentParams });
29
29
  - if (result.ok) {
30
- - const { intent, intentDeliveryInfo } = result.value;
30
+ - // v1: result.value was a TUPLE — destructure positionally
31
+ - const [executionResponse] = result.value;
32
+ - const txHash = executionResponse.intent_hash;
31
33
  - /* ... */
32
34
  - } else {
33
35
  - toast.error(result.error.message);
@@ -37,12 +39,25 @@ Pair: [`../../integration/features/swap.md`](../../integration/features/swap.md)
37
39
  + toast.error(result.error instanceof Error ? result.error.message : 'Swap failed');
38
40
  + return;
39
41
  + }
40
- + const { intent, intentDeliveryInfo } = result.value;
42
+ + // v2: result.value is a NAMED OBJECT (SwapResponse) — destructure by name
43
+ + const { solverExecutionResponse, intent, intentDeliveryInfo } = result.value;
44
+ + const intentHash = solverExecutionResponse.intent_hash; // protocol-level intent id (v1 ≈ executionResponse.intent_hash)
45
+ + const spokeTxHash = intentDeliveryInfo.srcTxHash; // on-chain tx hash on srcChainKey — use for tx-history display
41
46
  + /* ... */
42
47
  };
43
48
  }
44
49
  ```
45
50
 
51
+ #### `SwapResponse` field map (`result.value`)
52
+
53
+ | Field | Type | Use it for |
54
+ |---|---|---|
55
+ | `solverExecutionResponse` | `{ answer: 'OK'; intent_hash: Hex }` | Protocol-level intent identifier. **`solverExecutionResponse.intent_hash` is the v2 equivalent of v1's `executionResponse.intent_hash`.** Pass it to `useStatus({ params: { intentTxHash } })` to poll execution status. |
56
+ | `intent` | `Intent` | Intent metadata (`intentId: bigint`, `creator`, tokens, amounts, `srcChain`/`dstChain` as `IntentRelayChainId` bigints). **No transaction hashes on this object** — don't read `intent.intent_hash` (does not exist) or `intent.tx_hash`. |
57
+ | `intentDeliveryInfo` | `{ srcChainKey, srcTxHash, srcAddress, dstChainKey, dstTxHash, dstAddress }` | **On-chain transaction hashes.** `srcTxHash` is the spoke-chain tx on `srcChainKey` (the one that typically feeds a user-facing transaction history); `dstTxHash` is the delivery tx on `dstChainKey`. |
58
+
59
+ **Porting `[executionResponse] = result.value` (v1 tuple) → v2:** rename to `{ solverExecutionResponse } = result.value`. Any `executionResponse.intent_hash` read becomes `solverExecutionResponse.intent_hash`. If the value was being used as the **transaction hash** in a transaction-history row (not as the intent identifier), switch to `intentDeliveryInfo.srcTxHash` instead — `intent_hash` and `srcTxHash` are not interchangeable.
60
+
46
61
  ### `useSwapApprove` — return shape
47
62
 
48
63
  ```diff
@@ -42,28 +42,25 @@ for (const file of project.getSourceFiles('src/**/*.{ts,tsx}')) {
42
42
  await project.save();
43
43
  ```
44
44
 
45
- ## Codemod 2: useSpokeProvider deletion
45
+ ## Codemod 2: useSpokeProvider deletion (2-arg → 1-arg)
46
46
 
47
- `useSpokeProvider` is gone in v2. Delete the import + usage; replace with `useWalletProvider` from `@sodax/wallet-sdk-react`.
47
+ `useSpokeProvider` is gone in v2. Replace with `useWalletProvider` from `@sodax/wallet-sdk-react`.
48
48
 
49
- ```bash
50
- # 1. Find all usages first.
51
- grep -rE '\buseSpokeProvider\b' src/
52
-
53
- # 2. Manual delete + rewrite each (no safe sed for this — context varies).
54
- ```
55
-
56
- Per call site, the rewrite:
49
+ v1 had **two positional args**: `useSpokeProvider(spokeChainId, walletProvider)`. v2 collapses to a single options object: `useWalletProvider({ xChainId })`. The second v1 argument is **dropped entirely** — v2 resolves the wallet provider from the wallet-sdk-react store internally based on `xChainId`. If your v1 code constructed a wallet provider separately to pass in, delete that construction code too.
57
50
 
58
51
  ```diff
52
+ - // v1 — 2 positional args (chainKey + walletProvider)
59
53
  - import { useSpokeProvider } from '@sodax/dapp-kit';
60
- - const spokeProvider = useSpokeProvider({ chainId: BSC_MAINNET_CHAIN_ID });
54
+ - const spokeProvider = useSpokeProvider(srcChainId, walletProvider);
55
+
56
+ + // v2 — 1 options arg, no external walletProvider
61
57
  + import { useWalletProvider } from '@sodax/wallet-sdk-react';
62
- + import { ChainKeys } from '@sodax/sdk';
63
- + const walletProvider = useWalletProvider({ xChainId: ChainKeys.BSC_MAINNET });
58
+ + const walletProvider = useWalletProvider({ xChainId: srcChainId });
64
59
  ```
65
60
 
66
- Then update consumers of `spokeProvider` to use `walletProvider` instead usually inside `mutate(vars)` payloads, sometimes inside query hook params.
61
+ A naive single-pass regex over `useSpokeProvider\(([^)]+)\)` eats both args and produces invalid `useWalletProvider({ xChainId: chainKey, walletProvider })`. Do the rewrite in two passes: first the call shape (drop the second positional arg), then the import (from `@sodax/dapp-kit` `@sodax/wallet-sdk-react`). A small number of v1 callers used the single-arg form `useSpokeProvider(chainId)` handle those separately since they don't have a second arg to drop.
62
+
63
+ Update downstream consumers of `spokeProvider` to use `walletProvider` instead — usually inside `mutate(vars)` payloads or query hook params. The field name on payloads also renamed `spokeProvider:` → `walletProvider:` (see `@sodax/sdk/ai-exported/migration/checklist.md` step 7b).
67
64
 
68
65
  ## Codemod 3: invalidate*Queries utilities deletion
69
66
 
@@ -29,6 +29,8 @@ These keep their name but their TypeScript signature is different. Usually requi
29
29
  | `useMMAllowance` | Query params: `{ params: { payload: MoneyMarketParams<K> } }`. For `'borrow'` / `'withdraw'` actions: `enabled: false` — `data` stays `undefined`. |
30
30
  | `useUserReservesData` | Param key rename: `address → userAddress`; chain key is `spokeChainKey`. |
31
31
  | `useUserFormattedSummary` | Same. |
32
+ | `useATokensBalances` | Params: `{ aTokens, spokeProvider, userAddress } → { params: { aTokens, spokeChainKey, userAddress } }`. `spokeProvider` dropped; chain key is **`spokeChainKey`** (NOT `srcChainKey`); user field is **`userAddress`** (NOT `address`). Data: `Map<Address, bigint> \| undefined` (already unwrapped). |
33
+ | `useAToken` | Unaffected by the position-hook renames — takes only `{ aToken }`. Data: `Erc20Token & { chainKey }` (`hubAsset` / `vault` NOT included). |
32
34
  | All staking mutations | Same as MM. Plus dedicated approve hooks per token (`useStakeApprove` ↔ `useUnstakeApprove` ↔ `useInstantUnstakeApprove`). |
33
35
  | `useStakeRatio` | Return: `Result<bigint> → [xSodaAmount, previewDepositAmount]` (unwrapped tuple — NOT Result-wrapped in v2). |
34
36
  | `useStakingInfo` / `useUnstakingInfo` / `useUnstakingInfoWithPenalty` / `useStakingConfig` / `useInstantUnstakeRatio` / `useConvertedAssets` | All unwrapped in v2 (hooks throw on SDK `!ok`). Branch on `isError`/`error`, not `data?.ok`. |
package/dist/index.cjs CHANGED
@@ -2484,10 +2484,9 @@ function useClaimRewards({
2484
2484
  });
2485
2485
  }
2486
2486
  var SodaxProvider = ({ children, config }) => {
2487
- const configRef = react.useRef(config);
2488
- const frozen = configRef.current;
2489
- const sodax = react.useMemo(() => new sdk.Sodax(frozen), [frozen]);
2490
- return /* @__PURE__ */ jsxRuntime.jsx(SodaxContext.Provider, { value: { sodax }, children });
2487
+ const sodax = react.useMemo(() => new sdk.Sodax(config), [config]);
2488
+ const contextValue = react.useMemo(() => ({ sodax }), [sodax]);
2489
+ return /* @__PURE__ */ jsxRuntime.jsx(SodaxContext.Provider, { value: contextValue, children });
2491
2490
  };
2492
2491
  var defaultOnMutationError = (error) => {
2493
2492
  console.error("[sodax] Mutation error:", error);