@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
package/README.md CHANGED
@@ -117,7 +117,7 @@ function SwapButton({ intentParams }: { intentParams: CreateIntentParams }) {
117
117
 
118
118
  ## Requirements
119
119
 
120
- - Node.js >= 18.0.0
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` ships an AI-ready documentation tree at `node_modules/@sodax/dapp-kit/ai-exported/`. It's tool-neutral: any agent that can read files (Claude Code, Cursor, Aider, Copilot Chat, ChatGPT with file context, etc.) can use it without further setup.
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
- ### Get started
291
+ **Recommended: [`skills` CLI](https://github.com/vercel-labs/skills)** — from your project root:
292
292
 
293
- Point your agent at `node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md` — it routes to the rest. Three sample prompts covering the typical entry points:
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
- ### What's inside
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
- If you're contributing to this repo, run them with `pnpm -C packages/dapp-kit run check:ai-exported` (or `:scope`, `:links`, `:imports`, `:snippets`, `:keys`, `:consistency`).
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.mjs CHANGED
@@ -2514,5 +2514,3 @@ function createSodaxQueryClient({
2514
2514
  }
2515
2515
 
2516
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 };
2517
- //# sourceMappingURL=index.mjs.map
2518
- //# 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.3",
5
- "description": "dapp-kit of New World",
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.cjs",
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
- "src",
13
- "ai-exported"
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.3"
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.1.9"
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.0.0"
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,15 +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
- "knip": "knip",
54
- "lint": "biome lint . --write",
55
- "check:ai-exported": "bash ./scripts/check-ai-exported.sh",
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",
62
- "check:ai": "pnpm run check:ai-exported && pnpm run check:ai-scope && pnpm run check:ai-links && pnpm run check:ai-imports && pnpm run check:ai-snippets && pnpm run check:ai-keys && pnpm run check:ai-consistency"
71
+ "check-exports": "attw --pack --profile esm-only",
72
+ "check:knip": "knip",
73
+ "lint": "biome lint . --write"
63
74
  }
64
75
  }
@@ -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,80 +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
- - **DO NOT** reach for `as any` / `as IEvmWalletProvider` casts when wiring `useWalletProvider({ xChainId })` into mutation `mutate(vars)`. v2 supports the broad-union case structurally; the cast is not needed. See `recipes/wallet-connectivity.md` § "No type cast is needed".
43
-
44
- ## Stop conditions (defer to user)
45
-
46
- | Signal | Why stop |
47
- |---|---|
48
- | User wants a chain not in `ChainKeys.*` | Adding a new chain requires SDK-level changes — out of scope for consumer code. |
49
- | 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. |
50
- | 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. |
51
- | 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. |
52
-
53
- ## Verification protocol
54
-
55
- Before declaring a dapp-kit integration "done":
56
-
57
- ```bash
58
- # 1. Type-check the consumer.
59
- pnpm -C <consumer> tsc --noEmit
60
-
61
- # 2. Confirm no leftover v1 patterns (if porting).
62
- grep -rE '\buseSpokeProvider\b|\binvalidateMmQueries\b|_MAINNET_CHAIN_ID\b|\bxChainId\b' src/
63
-
64
- # 3. Confirm all SDK-level mutation results are handled (either mutateAsyncSafe + result.ok branch
65
- # or mutateAsync wrapped in try/catch).
66
- grep -rE 'mutateAsync\(' src/ | grep -v 'try\|catch\|mutateAsyncSafe'
67
-
68
- # 4. Confirm all hooks are imported from @sodax/dapp-kit, not deep paths.
69
- # (matches `'@sodax/dapp-kit/dist'` and similar deep-import patterns)
70
- grep -rE "@sodax/dapp-kit/[a-z]" src/ # zero hits expected (only the root path is public)
71
- ```
72
-
73
- ## Done criteria
74
-
75
- - [ ] `SodaxProvider` + `QueryClientProvider` (preferably `createSodaxQueryClient()`) wired at the app root.
76
- - [ ] Every mutation invocation uses `mutateAsyncSafe` (preferred), `mutateAsync` wrapped in `try/catch`, or fire-and-forget `mutate` with state read in render.
77
- - [ ] No `useSpokeProvider`, no `invalidateMmQueries`, no `*_MAINNET_CHAIN_ID` constants, no `xChainId` outside known v2 hooks (e.g. `useXBalances` still uses `xChainId`).
78
- - [ ] No `import` from `@sodax/dapp-kit/dist/...` or any other deep path.
79
- - [ ] No standalone `@sodax/types` dependency in `package.json`.
80
- - [ ] Consumer typecheck (`pnpm tsc --noEmit`) is clean.