@sodax/dapp-kit 2.0.0-rc.2 → 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.
- package/README.md +9 -63
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +3 -6
- package/package.json +31 -19
- package/src/providers/SodaxProvider.tsx +15 -11
- package/ai-exported/AGENTS.md +0 -134
- package/ai-exported/integration/README.md +0 -49
- package/ai-exported/integration/ai-rules.md +0 -79
- package/ai-exported/integration/architecture.md +0 -274
- package/ai-exported/integration/features/README.md +0 -29
- package/ai-exported/integration/features/auxiliary-services.md +0 -169
- package/ai-exported/integration/features/bitcoin.md +0 -87
- package/ai-exported/integration/features/bridge.md +0 -91
- package/ai-exported/integration/features/dex.md +0 -152
- package/ai-exported/integration/features/migration.md +0 -118
- package/ai-exported/integration/features/money-market.md +0 -116
- package/ai-exported/integration/features/staking.md +0 -123
- package/ai-exported/integration/features/swap.md +0 -101
- package/ai-exported/integration/quickstart.md +0 -187
- package/ai-exported/integration/recipes/README.md +0 -136
- package/ai-exported/integration/recipes/backend-queries.md +0 -157
- package/ai-exported/integration/recipes/bitcoin.md +0 -193
- package/ai-exported/integration/recipes/bridge.md +0 -174
- package/ai-exported/integration/recipes/dex.md +0 -204
- package/ai-exported/integration/recipes/invalidations.md +0 -115
- package/ai-exported/integration/recipes/migration.md +0 -212
- package/ai-exported/integration/recipes/money-market.md +0 -206
- package/ai-exported/integration/recipes/mutation-error-handling.md +0 -118
- package/ai-exported/integration/recipes/observability.md +0 -93
- package/ai-exported/integration/recipes/setup.md +0 -144
- package/ai-exported/integration/recipes/staking.md +0 -202
- package/ai-exported/integration/recipes/swap.md +0 -272
- package/ai-exported/integration/recipes/wallet-connectivity.md +0 -101
- package/ai-exported/integration/reference/README.md +0 -12
- package/ai-exported/integration/reference/glossary.md +0 -188
- package/ai-exported/integration/reference/hooks-index.md +0 -190
- package/ai-exported/integration/reference/public-api.md +0 -110
- package/ai-exported/integration/reference/querykey-conventions.md +0 -179
- package/ai-exported/migration/README.md +0 -60
- package/ai-exported/migration/ai-rules.md +0 -81
- package/ai-exported/migration/breaking-changes/hook-signatures.md +0 -233
- package/ai-exported/migration/breaking-changes/querykey-conventions.md +0 -108
- package/ai-exported/migration/breaking-changes/result-handling.md +0 -211
- package/ai-exported/migration/breaking-changes/sdk-leakage.md +0 -165
- package/ai-exported/migration/checklist.md +0 -89
- package/ai-exported/migration/features/README.md +0 -34
- package/ai-exported/migration/features/auxiliary-services.md +0 -114
- package/ai-exported/migration/features/bitcoin.md +0 -88
- package/ai-exported/migration/features/bridge.md +0 -123
- package/ai-exported/migration/features/dex.md +0 -101
- package/ai-exported/migration/features/migration.md +0 -120
- package/ai-exported/migration/features/money-market.md +0 -97
- package/ai-exported/migration/features/staking.md +0 -109
- package/ai-exported/migration/features/swap.md +0 -118
- package/ai-exported/migration/recipes.md +0 -188
- package/ai-exported/migration/reference/README.md +0 -15
- package/ai-exported/migration/reference/deleted-hooks.md +0 -110
- package/ai-exported/migration/reference/error-shape-crosswalk.md +0 -144
- package/ai-exported/migration/reference/renamed-hooks.md +0 -66
- package/dist/index.cjs +0 -2642
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1550
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ function SwapButton({ intentParams }: { intentParams: CreateIntentParams }) {
|
|
|
117
117
|
|
|
118
118
|
## Requirements
|
|
119
119
|
|
|
120
|
-
- Node.js >=
|
|
120
|
+
- Node.js >= 20.12.0
|
|
121
121
|
- React >= 18
|
|
122
122
|
- TypeScript
|
|
123
123
|
|
|
@@ -286,75 +286,21 @@ pnpm lint # Lint code
|
|
|
286
286
|
|
|
287
287
|
## AI agent docs
|
|
288
288
|
|
|
289
|
-
`@sodax/dapp-kit`
|
|
289
|
+
AI-readable docs for `@sodax/dapp-kit` (and the other `@sodax/*` packages) are shipped via [`@sodax/skills`](https://github.com/icon-project/sodax-sdks/tree/main/packages/skills) — a separate npm package bundling Claude-Code SKILL.md files and a long-form knowledge tree.
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
**Recommended: [`skills` CLI](https://github.com/vercel-labs/skills)** — from your project root:
|
|
292
292
|
|
|
293
|
-
|
|
294
|
-
|
|
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.
|
|
301
|
-
|
|
302
|
-
> Look up the canonical mutation hook shape in
|
|
303
|
-
> node_modules/@sodax/dapp-kit/ai-exported/integration/architecture.md.
|
|
293
|
+
```bash
|
|
294
|
+
npx skills@latest add icon-project/sodax-sdks/packages/skills
|
|
304
295
|
```
|
|
305
296
|
|
|
306
|
-
|
|
297
|
+
**npm + `AGENTS.md` pointer** (fallback for web chats, or when you prefer a devDependency over the CLI):
|
|
307
298
|
|
|
299
|
+
```bash
|
|
300
|
+
pnpm add -D @sodax/skills
|
|
308
301
|
```
|
|
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
302
|
|
|
357
|
-
|
|
303
|
+
Then point your agent at `node_modules/@sodax/skills/AGENTS.md`. See [docs/ai-integration-guide.md](https://github.com/icon-project/sodax-sdks/blob/main/docs/ai-integration-guide.md) for all install modes and per-tool wiring.
|
|
358
304
|
|
|
359
305
|
## License
|
|
360
306
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1478,13 +1478,20 @@ declare function useClaimRewards<K extends SpokeChainKey = SpokeChainKey>({ muta
|
|
|
1478
1478
|
interface SodaxProviderProps {
|
|
1479
1479
|
children: ReactNode;
|
|
1480
1480
|
/**
|
|
1481
|
-
* Sodax config
|
|
1482
|
-
*
|
|
1483
|
-
*
|
|
1484
|
-
*
|
|
1481
|
+
* Sodax SDK config. Tracked by **reference** - a new identity re-instantiates the
|
|
1482
|
+
* SDK. Hoist to a module constant or wrap in `useMemo`; include any value the SDK
|
|
1483
|
+
* should react to (e.g. solver env) in the deps. Inline `{...}` re-creates the SDK
|
|
1484
|
+
* every parent render and resets every `useSodaxContext` consumer.
|
|
1485
|
+
*
|
|
1486
|
+
* @example
|
|
1487
|
+
* ```tsx
|
|
1488
|
+
* const config = useMemo(() => ({ solver: solverMap[env] }), [env]);
|
|
1489
|
+
* <SodaxProvider config={config}>...</SodaxProvider>
|
|
1490
|
+
* ```
|
|
1485
1491
|
*/
|
|
1486
1492
|
config?: DeepPartial<SodaxConfig>;
|
|
1487
1493
|
}
|
|
1494
|
+
/** Root provider for `@sodax/dapp-kit`. Must be paired with `QueryClientProvider`. */
|
|
1488
1495
|
declare const SodaxProvider: ({ children, config }: SodaxProviderProps) => ReactElement;
|
|
1489
1496
|
|
|
1490
1497
|
type CreateSodaxQueryClientOptions = {
|
package/dist/index.mjs
CHANGED
|
@@ -2483,10 +2483,9 @@ function useClaimRewards({
|
|
|
2483
2483
|
});
|
|
2484
2484
|
}
|
|
2485
2485
|
var SodaxProvider = ({ children, config }) => {
|
|
2486
|
-
const
|
|
2487
|
-
const
|
|
2488
|
-
|
|
2489
|
-
return /* @__PURE__ */ jsx(SodaxContext.Provider, { value: { sodax }, children });
|
|
2486
|
+
const sodax = useMemo(() => new Sodax(config), [config]);
|
|
2487
|
+
const contextValue = useMemo(() => ({ sodax }), [sodax]);
|
|
2488
|
+
return /* @__PURE__ */ jsx(SodaxContext.Provider, { value: contextValue, children });
|
|
2490
2489
|
};
|
|
2491
2490
|
var defaultOnMutationError = (error) => {
|
|
2492
2491
|
console.error("[sodax] Mutation error:", error);
|
|
@@ -2515,5 +2514,3 @@ function createSodaxQueryClient({
|
|
|
2515
2514
|
}
|
|
2516
2515
|
|
|
2517
2516
|
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
|
2518
|
-
//# sourceMappingURL=index.mjs.map
|
|
2519
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/dapp-kit",
|
|
3
|
+
"private": false,
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
3
7
|
"license": "MIT",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
5
|
-
"description": "
|
|
8
|
+
"version": "2.0.0-rc.4",
|
|
9
|
+
"description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"sodax",
|
|
12
|
+
"dapp-kit",
|
|
13
|
+
"react",
|
|
14
|
+
"react-query",
|
|
15
|
+
"hooks",
|
|
16
|
+
"defi"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/icon-project/sodax-sdks/tree/main/packages/dapp-kit",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/icon-project/sodax-sdks/issues"
|
|
21
|
+
},
|
|
6
22
|
"type": "module",
|
|
7
|
-
"main": "dist/index.
|
|
23
|
+
"main": "dist/index.mjs",
|
|
8
24
|
"types": "dist/index.d.ts",
|
|
9
25
|
"module": "dist/index.mjs",
|
|
10
26
|
"files": [
|
|
11
27
|
"dist",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
28
|
+
"!dist/**/*.map",
|
|
29
|
+
"src"
|
|
14
30
|
],
|
|
15
31
|
"repository": {
|
|
16
32
|
"type": "git",
|
|
@@ -18,29 +34,31 @@
|
|
|
18
34
|
},
|
|
19
35
|
"dependencies": {
|
|
20
36
|
"viem": "2.29.2",
|
|
21
|
-
"@sodax/sdk": "2.0.0-rc.
|
|
37
|
+
"@sodax/sdk": "2.0.0-rc.4"
|
|
22
38
|
},
|
|
23
39
|
"devDependencies": {
|
|
40
|
+
"@arethetypeswrong/cli": "0.17.4",
|
|
24
41
|
"@tanstack/react-query": "5.87.4",
|
|
25
42
|
"@types/react": "19.0.8",
|
|
26
43
|
"knip": "5.30.5",
|
|
44
|
+
"tslib": "2.8.1",
|
|
27
45
|
"tsup": "8.5.0",
|
|
28
46
|
"typescript": "5.5.4",
|
|
29
|
-
"vitest": "2.
|
|
47
|
+
"vitest": "3.2.4"
|
|
30
48
|
},
|
|
31
49
|
"peerDependencies": {
|
|
32
50
|
"@tanstack/react-query": "5.x",
|
|
33
51
|
"react": ">=18"
|
|
34
52
|
},
|
|
35
53
|
"engines": {
|
|
36
|
-
"node": ">=20.
|
|
54
|
+
"node": ">=20.12.0"
|
|
37
55
|
},
|
|
56
|
+
"sideEffects": false,
|
|
38
57
|
"exports": {
|
|
39
58
|
"./package.json": "./package.json",
|
|
40
59
|
".": {
|
|
41
60
|
"types": "./dist/index.d.ts",
|
|
42
|
-
"import": "./dist/index.mjs"
|
|
43
|
-
"require": "./dist/index.cjs"
|
|
61
|
+
"import": "./dist/index.mjs"
|
|
44
62
|
}
|
|
45
63
|
},
|
|
46
64
|
"scripts": {
|
|
@@ -50,14 +68,8 @@
|
|
|
50
68
|
"clean": "rm -rf dist && rm -rf node_modules && rm -rf .turbo",
|
|
51
69
|
"pretty": "biome format . --write",
|
|
52
70
|
"checkTs": "tsc --noEmit",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"check:ai-scope": "bash ./scripts/check-ai-scope.sh",
|
|
57
|
-
"check:ai-links": "bash ./scripts/check-ai-links.sh",
|
|
58
|
-
"check:ai-imports": "bash ./scripts/check-ai-imports.sh",
|
|
59
|
-
"check:ai-snippets": "bash ./scripts/check-ai-snippets.sh",
|
|
60
|
-
"check:ai-keys": "bash ./scripts/check-ai-keys.sh",
|
|
61
|
-
"check:ai-consistency": "bash ./scripts/check-ai-consistency.sh"
|
|
71
|
+
"check-exports": "attw --pack --profile esm-only",
|
|
72
|
+
"check:knip": "knip",
|
|
73
|
+
"lint": "biome lint . --write"
|
|
62
74
|
}
|
|
63
75
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo,
|
|
1
|
+
import { useMemo, type ReactNode, type ReactElement } from 'react';
|
|
2
2
|
import { Sodax, type SodaxConfig } from '@sodax/sdk';
|
|
3
3
|
import { SodaxContext } from '@/contexts/index.js';
|
|
4
4
|
import type { DeepPartial } from '@sodax/sdk';
|
|
@@ -6,20 +6,24 @@ import type { DeepPartial } from '@sodax/sdk';
|
|
|
6
6
|
interface SodaxProviderProps {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
/**
|
|
9
|
-
* Sodax config
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Sodax SDK config. Tracked by **reference** - a new identity re-instantiates the
|
|
10
|
+
* SDK. Hoist to a module constant or wrap in `useMemo`; include any value the SDK
|
|
11
|
+
* should react to (e.g. solver env) in the deps. Inline `{...}` re-creates the SDK
|
|
12
|
+
* every parent render and resets every `useSodaxContext` consumer.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const config = useMemo(() => ({ solver: solverMap[env] }), [env]);
|
|
17
|
+
* <SodaxProvider config={config}>...</SodaxProvider>
|
|
18
|
+
* ```
|
|
13
19
|
*/
|
|
14
20
|
config?: DeepPartial<SodaxConfig>;
|
|
15
21
|
}
|
|
16
22
|
|
|
23
|
+
/** Root provider for `@sodax/dapp-kit`. Must be paired with `QueryClientProvider`. */
|
|
17
24
|
export const SodaxProvider = ({ children, config }: SodaxProviderProps): ReactElement => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const configRef = useRef<DeepPartial<SodaxConfig> | undefined>(config);
|
|
21
|
-
const frozen = configRef.current;
|
|
22
|
-
const sodax = useMemo(() => new Sodax(frozen), [frozen]);
|
|
25
|
+
const sodax = useMemo(() => new Sodax(config), [config]);
|
|
26
|
+
const contextValue = useMemo(() => ({ sodax }), [sodax]);
|
|
23
27
|
|
|
24
|
-
return <SodaxContext.Provider value={
|
|
28
|
+
return <SodaxContext.Provider value={contextValue}>{children}</SodaxContext.Provider>;
|
|
25
29
|
};
|
package/ai-exported/AGENTS.md
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# AGENTS.md — `@sodax/dapp-kit` v2
|
|
2
|
-
|
|
3
|
-
> Tool-neutral entry point for any AI coding agent assisting a consumer of `@sodax/dapp-kit`. If you're at `node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md`, you are in the right place — everything you need is reachable from here without leaving the npm tarball.
|
|
4
|
-
|
|
5
|
-
## Project
|
|
6
|
-
|
|
7
|
-
`@sodax/dapp-kit` is a React hooks library that wraps `@sodax/sdk` with React Query. It provides hooks across 11 feature domains (swap, money market, staking, bridge, dex, migration, partner, recovery, bitcoin/Radfi, backend queries, shared) for consumer dApps. It is **React-only** — Node.js scripts and backend services use `@sodax/sdk` directly.
|
|
8
|
-
|
|
9
|
-
This package is **v2**. v2 was a deep canonicalization pass over v1's hook shapes — single-object params, mandatory `mutateAsyncSafe`, hook-owned invalidations, throw-on-`Result.!ok` inside `mutationFn`, canonical queryKey/mutationKey conventions. Plus the entire SDK underneath was reshaped (chain-key-driven routing, `Result<T>` everywhere, `WalletProviderSlot<K, Raw>`). Code written against v1 dapp-kit will not compile against v2.
|
|
10
|
-
|
|
11
|
-
## When to read what
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
Are you writing NEW code with v2 dapp-kit? → integration/ai-rules.md, then integration/
|
|
15
|
-
Are you porting EXISTING v1 code to v2? → migration/ai-rules.md, then migration/
|
|
16
|
-
Just need a hook table or a queryKey rule? → integration/reference/
|
|
17
|
-
Need to install + wire providers? → integration/recipes/setup.md
|
|
18
|
-
Hit a feature you don't know how to scaffold? → integration/recipes/<feature>.md
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
If a consumer's repo has both v1 call sites and a request to extend with new code, do migration first. Stale v1 patterns leak into new code if you skip it.
|
|
22
|
-
|
|
23
|
-
**Always start with `ai-rules.md` for the tree you're working in** — it's the consolidated DO / DO NOT / workflow / stop-conditions guide that prevents the most common v2 traps. Read it once, then dive into the per-feature docs or recipes.
|
|
24
|
-
|
|
25
|
-
## Top-level layout
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
ai-exported/
|
|
29
|
-
├── AGENTS.md # You are here
|
|
30
|
-
├── integration/ # How to use v2 dapp-kit (new consumers)
|
|
31
|
-
│ ├── README.md # Index for this tree
|
|
32
|
-
│ ├── ai-rules.md # DO / DO NOT / workflow — read before per-feature docs
|
|
33
|
-
│ ├── quickstart.md # Install + wire providers + first feature
|
|
34
|
-
│ ├── architecture.md # Hook shapes, queryKey conventions, useSafeMutation, unwrapResult, Result<T>
|
|
35
|
-
│ ├── features/ # Per-feature reference docs (one file per major feature group)
|
|
36
|
-
│ │ ├── README.md
|
|
37
|
-
│ │ ├── swap.md, money-market.md, staking.md, bridge.md, dex.md
|
|
38
|
-
│ │ ├── migration.md # ICX/bnUSD/BALN migration hooks
|
|
39
|
-
│ │ ├── bitcoin.md # Radfi (dapp-kit-unique)
|
|
40
|
-
│ │ └── auxiliary-services.md # partner + recovery + backend queries + shared
|
|
41
|
-
│ ├── recipes/ # Copy-paste patterns
|
|
42
|
-
│ │ ├── README.md
|
|
43
|
-
│ │ ├── setup.md, wallet-connectivity.md
|
|
44
|
-
│ │ ├── swap.md, money-market.md, staking.md, bridge.md, dex.md
|
|
45
|
-
│ │ ├── migration.md, bitcoin.md, backend-queries.md
|
|
46
|
-
│ │ ├── mutation-error-handling.md # mutate / mutateAsync / mutateAsyncSafe
|
|
47
|
-
│ │ ├── observability.md # createSodaxQueryClient, meta.silent
|
|
48
|
-
│ │ └── invalidations.md # hook-owned vs consumer
|
|
49
|
-
│ └── reference/ # Lookup tables
|
|
50
|
-
│ ├── README.md
|
|
51
|
-
│ ├── hooks-index.md # Comprehensive hook table
|
|
52
|
-
│ ├── querykey-conventions.md # camelCase, feature-prefix, default mutationKey
|
|
53
|
-
│ ├── public-api.md # What @sodax/dapp-kit exports + import rules
|
|
54
|
-
│ └── glossary.md # ReadHookParams, MutationHookParams, SafeUseMutationResult, etc.
|
|
55
|
-
└── migration/ # How to port v1 → v2 dapp-kit
|
|
56
|
-
├── README.md # Overview + reading order + glossary
|
|
57
|
-
├── ai-rules.md # DO / DO NOT / workflow for porting agents
|
|
58
|
-
├── checklist.md # Top-down cross-cutting steps
|
|
59
|
-
├── breaking-changes/
|
|
60
|
-
│ ├── hook-signatures.md # Single-arg policy + ReadHookParams/MutationHookParams
|
|
61
|
-
│ ├── result-handling.md # Result<T> success-path → throws; mutateAsyncSafe
|
|
62
|
-
│ ├── querykey-conventions.md # camelCase + default mutationKey
|
|
63
|
-
│ └── sdk-leakage.md # Cross-links to SDK ai-exported migration tree
|
|
64
|
-
├── features/ # Per-feature porting playbooks (mirror integration/features/)
|
|
65
|
-
│ ├── README.md
|
|
66
|
-
│ ├── swap.md, money-market.md, staking.md, bridge.md, dex.md
|
|
67
|
-
│ ├── migration.md, bitcoin.md, auxiliary-services.md
|
|
68
|
-
├── recipes.md # Codemods + adapters for incremental migration
|
|
69
|
-
└── reference/
|
|
70
|
-
├── README.md
|
|
71
|
-
├── deleted-hooks.md # useSpokeProvider, invalidateMmQueries, legacy useMigrate
|
|
72
|
-
├── renamed-hooks.md
|
|
73
|
-
└── error-shape-crosswalk.md
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## v2 in one minute
|
|
77
|
-
|
|
78
|
-
1. **Hooks accept a single object with one or two top-level keys.** Mutation hooks take only `{ mutationOptions }` at hook-init; query hooks take `{ params, queryOptions }`. ALL domain inputs (`params`, `walletProvider`, per-call config) flow through `mutate(vars)` for mutations.
|
|
79
|
-
2. **Every mutation hook returns `SafeUseMutationResult`** — extends React Query's `UseMutationResult` with `mutateAsyncSafe(vars): Promise<Result<TData>>` (never rejects). Use `mutateAsyncSafe` for sequenced flows; `mutateAsync` for try/catch flows; `mutate` for fire-and-forget render-driven flows.
|
|
80
|
-
3. **`mutationFn` throws on SDK `!ok`.** dapp-kit calls `unwrapResult` on the SDK's `Result<T>`, throwing on failure. This makes React Query's native error model engage (`isError`, `error`, `onError`, `retry`, devtools). `mutateAsyncSafe` packages the throw back into `Result<T>` for ergonomic branching.
|
|
81
|
-
4. **Hook-owned invalidations.** Each mutation hook invalidates the relevant query keys in its `onSuccess`, derived from `vars`. Consumer-provided `onSuccess` runs after. v1's manual `invalidateMmQueries` utilities are gone.
|
|
82
|
-
5. **Canonical queryKey shape.** `[feature, action, ...identifiers]`. First segment matches the directory name (`swap`, `mm`, `bridge`, `staking`, `dex`, `bitcoin`, `partner`, `recovery`, `backend`, `shared`, `migrate`). camelCase. Bigints stringified. Mechanically enforced by `_mutationContract.test.ts`.
|
|
83
|
-
|
|
84
|
-
## Top 5 v1 → v2 traps
|
|
85
|
-
|
|
86
|
-
1. **Reaching for `useSpokeProvider`.** It's deleted. Pass `walletProvider` from `useWalletProvider({ xChainId: chainKey })` (`@sodax/wallet-sdk-react`) directly into `mutate(vars)`. The chain key on the action params is what routes — there is no provider class to derive.
|
|
87
|
-
2. **Treating mutation `data` as `Result<T>`.** v2's `mutationFn` unwraps before resolving — `data` is the unwrapped success value (e.g. `SwapResponse`, `TxHashPair`). For SDK failures, look at `mutation.error` or use `mutateAsyncSafe` for the `Result<T>` shape.
|
|
88
|
-
3. **Forgetting `try/catch` on `mutateAsync`.** v2's `mutateAsync` rejects on SDK `!ok`. If you don't `try/catch`, you'll leak unhandled rejections on user-rejects. Prefer `mutateAsyncSafe` (never rejects).
|
|
89
|
-
4. **Hook-level `spokeProvider` / `params`.** v1 hooks took these positionally or at hook-init. v2 hooks take only `{ mutationOptions }` (mutations) or `{ params, queryOptions }` (queries). All domain inputs live in `mutate(vars)` for mutations.
|
|
90
|
-
5. **Reading `xToken.xChainId` or hard-coding `*_MAINNET_CHAIN_ID`.** SDK leakage — these were renamed: `XToken.chainKey`, `ChainKeys.X_MAINNET`. The legacy `*_MAINNET_CHAIN_ID` constants are gone. See [`migration/breaking-changes/sdk-leakage.md`](migration/breaking-changes/sdk-leakage.md).
|
|
91
|
-
|
|
92
|
-
See `migration/README.md` for the complete trap list and `migration/breaking-changes/` for full v1↔v2 detail.
|
|
93
|
-
|
|
94
|
-
## Public API contract
|
|
95
|
-
|
|
96
|
-
- Import only from the package root: `import { useSwap, SodaxProvider, createSodaxQueryClient } from '@sodax/dapp-kit'`.
|
|
97
|
-
- The package re-exports `@sodax/sdk`'s public surface — `ChainKeys`, `SodaxConfig`, types like `CreateIntentParams`, etc., are available from `@sodax/dapp-kit` directly. You may also import them from `@sodax/sdk`.
|
|
98
|
-
- Do **not** add `@sodax/types` to your dependencies — it's re-exported via `@sodax/sdk`.
|
|
99
|
-
- Do **not** deep-import from `dist/...`. Internal paths are not stable across releases.
|
|
100
|
-
- The published tarball ships `dist/` and `ai-exported/`. Do not rely on any other path being present.
|
|
101
|
-
|
|
102
|
-
## Conventions agents must follow
|
|
103
|
-
|
|
104
|
-
- **Use `useSafeMutation`-built hooks** (i.e. dapp-kit's exported hooks). Never call React Query's `useMutation` directly inside a wrapper around a dapp-kit hook — consumers depend on `mutateAsyncSafe`.
|
|
105
|
-
- **Branch on `mutateAsyncSafe`'s `Result.ok`** for sequenced flows. The user-reject case is modal, not exceptional.
|
|
106
|
-
- **Use `ChainKeys.*` over hard-coded chain strings.** The set evolves per release.
|
|
107
|
-
- **Drop `spokeProvider`** anywhere it appears. It's not a v2 concept. `walletProvider` flows through `mutate(vars)` for signed flows; queries take it directly when needed (e.g. allowance reads).
|
|
108
|
-
- **Don't recreate hook-owned invalidations** at the call site. Each mutation hook already invalidates the relevant keys; consumer `onSuccess` runs after for any extra logic.
|
|
109
|
-
- **Conventional commits if generating commits** (`feat:`, `fix:`, `chore:`).
|
|
110
|
-
|
|
111
|
-
## Enforcement — what CI catches (and what it doesn't)
|
|
112
|
-
|
|
113
|
-
Seven CI guards run on every PR. They catch syntactic + structural drift but NOT prose-level accuracy:
|
|
114
|
-
|
|
115
|
-
| Guard | What it enforces |
|
|
116
|
-
|---|---|
|
|
117
|
-
| `check:ai-exported` | Every `useFoo` reference resolves to a real export. |
|
|
118
|
-
| `check:ai-scope` | No imports from forbidden packages (`@sodax/wallet-sdk-core`, `@sodax/types` directly). |
|
|
119
|
-
| `check:ai-links` | Every relative link between markdown files resolves. |
|
|
120
|
-
| `check:ai-imports` | Every `import … from '@sodax/dapp-kit'` example typechecks. |
|
|
121
|
-
| `check:ai-snippets` | **Opt-out by default** — every ts/tsx code block is typechecked unless marked `// @ai-snippets-skip`. Catches call-shape drift. |
|
|
122
|
-
| `check:ai-keys` | Every `queryKey: [...]` / `mutationKey: [...]` literal (declarations + backticked-array table cells) matches source. Catches `'stakingInfo'` vs `'info'`-style drift. Opt-out via `<!-- ai-keys-allow -->` or `// ai-keys-allow`. |
|
|
123
|
-
| `check:ai-consistency` | Polling-interval claims (`"polls 3s"`, table cells like `useQuote \| 3s`) match the actual `refetchInterval` in source. Opt-out via `<!-- ai-consistency-allow -->`. |
|
|
124
|
-
|
|
125
|
-
If you're authoring a new doc page, write code samples that include explicit imports (so `check:ai-snippets` validates them) and source-derived queryKeys (so `check:ai-keys` accepts them). When showing v1 anti-patterns or pseudocode, use the appropriate `*-allow` / `*-skip` marker — these are first-class affordances, not workarounds.
|
|
126
|
-
|
|
127
|
-
## Pointers
|
|
128
|
-
|
|
129
|
-
- [`integration/README.md`](integration/README.md) — start here for any new v2 dapp-kit work.
|
|
130
|
-
- [`migration/README.md`](migration/README.md) — start here for any v1 → v2 dapp-kit port.
|
|
131
|
-
- [`integration/recipes/setup.md`](integration/recipes/setup.md) — install + wire providers.
|
|
132
|
-
- [`integration/recipes/mutation-error-handling.md`](integration/recipes/mutation-error-handling.md) — picking call shapes (`mutate` / `mutateAsync` / `mutateAsyncSafe`).
|
|
133
|
-
- [`integration/architecture.md`](integration/architecture.md) — full design rationale + canonical hook shapes.
|
|
134
|
-
- [`../../sdk/ai-exported/AGENTS.md`](../../sdk/ai-exported/AGENTS.md) — the underlying Core SDK's tree (resolves correctly in `node_modules/@sodax/`-layout). Useful for SDK-leakage migration topics.
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# Integration — `@sodax/dapp-kit` v2
|
|
2
|
-
|
|
3
|
-
This tree documents v2 of the dapp-kit React hooks for **new consumers** building against it. If you're porting v1 code, start at [`../migration/README.md`](../migration/README.md) instead.
|
|
4
|
-
|
|
5
|
-
## Files in this tree
|
|
6
|
-
|
|
7
|
-
| File | What's in it |
|
|
8
|
-
|---|---|
|
|
9
|
-
| [`ai-rules.md`](ai-rules.md) | **Read first.** DO / DO NOT / workflow / stop-conditions for AI agents writing v2 dapp-kit code. |
|
|
10
|
-
| [`quickstart.md`](quickstart.md) | Install, wire providers, get a wallet provider, run your first mutation. |
|
|
11
|
-
| [`architecture.md`](architecture.md) | Every v2 design concept the hooks rest on: ReadHookParams / MutationHookParams, useSafeMutation, unwrapResult, queryKey conventions, mutateAsyncSafe semantics, createSodaxQueryClient. |
|
|
12
|
-
| [`features/swap.md`](features/swap.md) | Swap hooks: `useQuote`, `useSwap`, `useSwapAllowance`, `useSwapApprove`, limit orders, status polling. |
|
|
13
|
-
| [`features/money-market.md`](features/money-market.md) | Money market hooks: `useSupply`, `useBorrow`, `useWithdraw`, `useRepay`, allowance/approve, reserves data. |
|
|
14
|
-
| [`features/staking.md`](features/staking.md) | Staking hooks: `useStake`, `useUnstake`, `useInstantUnstake`, `useClaim`, `useCancelUnstake`, info/ratio reads. |
|
|
15
|
-
| [`features/bridge.md`](features/bridge.md) | Bridge hooks: `useBridge`, allowance/approve, bridgeable amount/tokens. |
|
|
16
|
-
| [`features/dex.md`](features/dex.md) | DEX hooks: deposit/withdraw, supply/decrease liquidity, claim rewards, position info, pools. |
|
|
17
|
-
| [`features/migration.md`](features/migration.md) | Migration hooks: ICX/bnUSD/BALN forward + reverse, allowance/approve. |
|
|
18
|
-
| [`features/bitcoin.md`](features/bitcoin.md) | Radfi hooks (dapp-kit-unique): session, trading wallet, fund/withdraw, UTXOs. |
|
|
19
|
-
| [`features/auxiliary-services.md`](features/auxiliary-services.md) | Partner, recovery, backend queries, shared (xBalances, gas estimation, trustlines). |
|
|
20
|
-
| [`recipes/`](recipes/) | Copy-paste patterns: setup, wallet connectivity, per-feature flows, mutation error handling, observability, invalidations. |
|
|
21
|
-
| [`reference/`](reference/) | Lookup tables: full hook index, queryKey conventions, public API surface, glossary. |
|
|
22
|
-
|
|
23
|
-
## Reading order for a new integrator
|
|
24
|
-
|
|
25
|
-
1. **[`ai-rules.md`](ai-rules.md)** — agent rules, before any code.
|
|
26
|
-
2. **[`quickstart.md`](quickstart.md)** — get providers wired and a button rendering.
|
|
27
|
-
3. **[`architecture.md`](architecture.md)** — understand `useSafeMutation` / `mutateAsyncSafe` / hook shapes before writing call sites.
|
|
28
|
-
4. **[`recipes/`](recipes/)** — pick the patterns you need (mutation error handling, observability, invalidations).
|
|
29
|
-
5. **[`features/<x>.md`](features/)** — read the file for the feature you're integrating (reference shape; pair with the matching recipe in `recipes/<x>.md` for working examples).
|
|
30
|
-
6. **[`reference/`](reference/)** — keep open while writing for table lookups.
|
|
31
|
-
|
|
32
|
-
## Cross-references to migration
|
|
33
|
-
|
|
34
|
-
If your project also has v1 dapp-kit call sites, port them first using:
|
|
35
|
-
|
|
36
|
-
- [`../migration/README.md`](../migration/README.md) — overview, reading order, and v1↔v2 glossary.
|
|
37
|
-
- [`../migration/checklist.md`](../migration/checklist.md) — top-down cross-cutting checklist.
|
|
38
|
-
- [`../migration/breaking-changes/`](../migration/breaking-changes/) — the four cross-cutting changes (hook-signatures, result-handling, queryKey-conventions, sdk-leakage).
|
|
39
|
-
- [`../migration/features/`](../migration/features/) — per-feature playbooks in lockstep with `integration/features/` here.
|
|
40
|
-
|
|
41
|
-
The naming rule: **every file in `integration/features/` has a sibling in `migration/features/` with the same filename.** When you're deep in one, the other is one path-swap away.
|
|
42
|
-
|
|
43
|
-
## Cross-references to the underlying SDK
|
|
44
|
-
|
|
45
|
-
`@sodax/dapp-kit` re-exports `@sodax/sdk` at the package root, so most types you'd reach for (`ChainKeys`, `SodaxConfig`, `CreateIntentParams`, `XToken`, `Result`, `SodaxError`) are available from `@sodax/dapp-kit` directly. The Core SDK has its own ai-exported tree at [`../../../sdk/ai-exported/`](../../../sdk/ai-exported/) (resolves correctly in `node_modules/@sodax/`-layout). Useful for:
|
|
46
|
-
|
|
47
|
-
- The full SDK migration playbook for v1→v2 (chain-key terminology, `Result<T>` semantics, ConfigService) — referenced from [`../migration/breaking-changes/sdk-leakage.md`](../migration/breaking-changes/sdk-leakage.md).
|
|
48
|
-
- Architectural concepts that surface through hook signatures (`SodaxError<C>` vocabulary, `WalletProviderSlot<K, Raw>` discriminator semantics).
|
|
49
|
-
- Backend / Node.js usage patterns (where dapp-kit isn't applicable).
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# AI rules — `@sodax/dapp-kit` integration
|
|
2
|
-
|
|
3
|
-
DO / DO NOT / workflow / stop conditions for AI agents writing v2 dapp-kit code. Read this **before** the per-feature docs — these rules prevent the most common load-bearing v2 traps.
|
|
4
|
-
|
|
5
|
-
## Workflow (do these in order)
|
|
6
|
-
|
|
7
|
-
1. **Survey the project before touching code.**
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
pnpm tsc --noEmit # baseline typecheck
|
|
11
|
-
grep -rE '@sodax/(dapp-kit|sdk|wallet-sdk-react)' --include='*.ts' --include='*.tsx' src/ # see what's already imported
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
2. **Wire providers first if not already wired.** [`recipes/setup.md`](recipes/setup.md). Provider stack: `SodaxProvider > QueryClientProvider > SodaxWalletProvider > YourApp`.
|
|
15
|
-
3. **Pick `mutate` / `mutateAsync` / `mutateAsyncSafe` deliberately.** See [`recipes/mutation-error-handling.md`](recipes/mutation-error-handling.md). Default to `mutateAsyncSafe` for sequenced flows.
|
|
16
|
-
4. **Branch on `result.ok` for `mutateAsyncSafe` results, or on `mutation.isError` / `mutation.error`** for fire-and-forget. Never assume mutation success.
|
|
17
|
-
5. **Use `useWalletProvider({ xChainId: chainKey })` from `@sodax/wallet-sdk-react` for every signed flow.** Pass the result into `mutate(vars).walletProvider`. Don't create or import any `*SpokeProvider` class — those don't exist in v2.
|
|
18
|
-
|
|
19
|
-
## DO
|
|
20
|
-
|
|
21
|
-
- **DO** call dapp-kit's exported hooks (which wrap `useSafeMutation`). Never call React Query's `useMutation` directly inside a wrapper around a dapp-kit hook — consumers depend on `mutateAsyncSafe`.
|
|
22
|
-
- **DO** branch on `mutateAsyncSafe`'s `Result.ok` for sequenced flows (`if (!hasAllowance) await approve(...); await action(...);`). User-rejects are modal, not exceptional.
|
|
23
|
-
- **DO** use `ChainKeys.X_MAINNET` constants for chain identifiers. Never hard-code chain key strings (`'sonic'`, `'0xa4b1.arbitrum'`).
|
|
24
|
-
- **DO** import everything from `@sodax/dapp-kit` (or `@sodax/sdk` for SDK-only types and constants — `@sodax/dapp-kit` re-exports them anyway).
|
|
25
|
-
- **DO** preserve literal chain keys in generic positions where possible (e.g. `srcChainKey: ChainKeys.ETHEREUM_MAINNET as const`) — TypeScript narrowing flows from the literal, including the `walletProvider` parameter type.
|
|
26
|
-
- **DO** use the canonical hook shape: queries take `{ params, queryOptions }`; mutations take only `{ mutationOptions }` and flow domain inputs through `mutate(vars)`.
|
|
27
|
-
- **DO** compose `onSuccess` instead of replacing it: `mutationOptions: { onSuccess: (data, vars, ctx) => myExtra(...) }` runs AFTER dapp-kit's hook-owned invalidations.
|
|
28
|
-
|
|
29
|
-
## DO NOT
|
|
30
|
-
|
|
31
|
-
- **DO NOT** call `useSpokeProvider` — it's deleted. v1 React consumers got a `SpokeProvider` from this hook; v2 has no such concept. Pass `walletProvider` directly into `mutate(vars)`.
|
|
32
|
-
- **DO NOT** treat mutation `data` as `Result<T>`. `mutationFn` calls `unwrapResult` and throws on `!ok`; `data` is the unwrapped success value (e.g. `SwapResponse`, `TxHashPair`). For SDK failures, look at `mutation.error` or use `mutateAsyncSafe`.
|
|
33
|
-
- **DO NOT** call `mutateAsync` without `try/catch`. It rejects on SDK `!ok`; an unhandled rejection lands in the global handler. Prefer `mutateAsyncSafe` for sequenced flows.
|
|
34
|
-
- **DO NOT** put `params`, `walletProvider`, or per-call config at the hook-init level. They go in `mutate(vars)` for mutations and in `params` for queries.
|
|
35
|
-
- **DO NOT** override `queryKey`, `queryFn`, or `enabled` via `queryOptions` — the hook owns those. The `queryOptions` slot is typed `Omit<UseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>`.
|
|
36
|
-
- **DO NOT** override `mutationFn` via `mutationOptions` — the hook owns it. Type prevents this.
|
|
37
|
-
- **DO NOT** import from `@sodax/dapp-kit/dist/...`. Deep-imports unstable; only the package root barrel is the public contract.
|
|
38
|
-
- **DO NOT** add `@sodax/types` as a separate dependency. It's re-exported transitively via `@sodax/sdk` (which dapp-kit re-exports). Adding it independently invites version skew.
|
|
39
|
-
- **DO NOT** recreate the v1 `invalidateMmQueries(...)` utility or anything similar. Each mutation hook invalidates the relevant keys in its own `onSuccess`. Add cross-feature invalidations via consumer `onSuccess`.
|
|
40
|
-
- **DO NOT** destructure cross-chain mutation results as arrays — `[a, b] = result.value` is wrong. The shape is `TxHashPair = { srcChainTxHash, dstChainTxHash }` (object). This applies to `useBridge`, `useStake`/`useUnstake`/etc., `useDexDeposit`/`useDexWithdraw`, all four MM mutations, and all four migration mutations.
|
|
41
|
-
- **DO NOT** use legacy chain-id constants (`BSC_MAINNET_CHAIN_ID`, etc.). They're gone in v2 — use `ChainKeys.X_MAINNET`.
|
|
42
|
-
|
|
43
|
-
## Stop conditions (defer to user)
|
|
44
|
-
|
|
45
|
-
| Signal | Why stop |
|
|
46
|
-
|---|---|
|
|
47
|
-
| User wants a chain not in `ChainKeys.*` | Adding a new chain requires SDK-level changes — out of scope for consumer code. |
|
|
48
|
-
| User wants to use React Server Components / RSC patterns | dapp-kit is client-side React (uses React Query, hooks, browser APIs). Server Components don't run hooks. Tell the user the dapp-kit code goes in client components. |
|
|
49
|
-
| User wants to skip the wallet-sdk-react integration | If they have their own wallet abstraction, it's possible — they need to construct objects satisfying `I*WalletProvider` interfaces from `@sodax/sdk`. Refer them to `@sodax/sdk`'s ai-exported tree for non-React patterns. |
|
|
50
|
-
| User wants to use v1 dapp-kit (positional args, `useSpokeProvider`, `Result<T>` in success path) | Tell them to either upgrade or stay on v1. The shapes are not compatible. |
|
|
51
|
-
|
|
52
|
-
## Verification protocol
|
|
53
|
-
|
|
54
|
-
Before declaring a dapp-kit integration "done":
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
# 1. Type-check the consumer.
|
|
58
|
-
pnpm -C <consumer> tsc --noEmit
|
|
59
|
-
|
|
60
|
-
# 2. Confirm no leftover v1 patterns (if porting).
|
|
61
|
-
grep -rE '\buseSpokeProvider\b|\binvalidateMmQueries\b|_MAINNET_CHAIN_ID\b|\bxChainId\b' src/
|
|
62
|
-
|
|
63
|
-
# 3. Confirm all SDK-level mutation results are handled (either mutateAsyncSafe + result.ok branch
|
|
64
|
-
# or mutateAsync wrapped in try/catch).
|
|
65
|
-
grep -rE 'mutateAsync\(' src/ | grep -v 'try\|catch\|mutateAsyncSafe'
|
|
66
|
-
|
|
67
|
-
# 4. Confirm all hooks are imported from @sodax/dapp-kit, not deep paths.
|
|
68
|
-
# (matches `'@sodax/dapp-kit/dist'` and similar deep-import patterns)
|
|
69
|
-
grep -rE "@sodax/dapp-kit/[a-z]" src/ # zero hits expected (only the root path is public)
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Done criteria
|
|
73
|
-
|
|
74
|
-
- [ ] `SodaxProvider` + `QueryClientProvider` (preferably `createSodaxQueryClient()`) wired at the app root.
|
|
75
|
-
- [ ] Every mutation invocation uses `mutateAsyncSafe` (preferred), `mutateAsync` wrapped in `try/catch`, or fire-and-forget `mutate` with state read in render.
|
|
76
|
-
- [ ] No `useSpokeProvider`, no `invalidateMmQueries`, no `*_MAINNET_CHAIN_ID` constants, no `xChainId` outside known v2 hooks (e.g. `useXBalances` still uses `xChainId`).
|
|
77
|
-
- [ ] No `import` from `@sodax/dapp-kit/dist/...` or any other deep path.
|
|
78
|
-
- [ ] No standalone `@sodax/types` dependency in `package.json`.
|
|
79
|
-
- [ ] Consumer typecheck (`pnpm tsc --noEmit`) is clean.
|