@sodax/skills 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/.claude-plugin/plugin.json +13 -0
- package/AGENTS.md +81 -0
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/knowledge/dapp-kit/AGENTS.md +50 -0
- package/knowledge/dapp-kit/integration/README.md +49 -0
- package/knowledge/dapp-kit/integration/ai-rules.md +80 -0
- package/knowledge/dapp-kit/integration/architecture.md +276 -0
- package/knowledge/dapp-kit/integration/features/README.md +29 -0
- package/knowledge/dapp-kit/integration/features/auxiliary-services.md +169 -0
- package/knowledge/dapp-kit/integration/features/bitcoin.md +87 -0
- package/knowledge/dapp-kit/integration/features/bridge.md +91 -0
- package/knowledge/dapp-kit/integration/features/dex.md +152 -0
- package/knowledge/dapp-kit/integration/features/migration.md +118 -0
- package/knowledge/dapp-kit/integration/features/money-market.md +144 -0
- package/knowledge/dapp-kit/integration/features/staking.md +123 -0
- package/knowledge/dapp-kit/integration/features/swap.md +101 -0
- package/knowledge/dapp-kit/integration/quickstart.md +188 -0
- package/knowledge/dapp-kit/integration/recipes/README.md +136 -0
- package/knowledge/dapp-kit/integration/recipes/backend-queries.md +157 -0
- package/knowledge/dapp-kit/integration/recipes/bitcoin.md +193 -0
- package/knowledge/dapp-kit/integration/recipes/bridge.md +174 -0
- package/knowledge/dapp-kit/integration/recipes/dex.md +204 -0
- package/knowledge/dapp-kit/integration/recipes/invalidations.md +115 -0
- package/knowledge/dapp-kit/integration/recipes/migration.md +212 -0
- package/knowledge/dapp-kit/integration/recipes/money-market.md +207 -0
- package/knowledge/dapp-kit/integration/recipes/mutation-error-handling.md +118 -0
- package/knowledge/dapp-kit/integration/recipes/observability.md +93 -0
- package/knowledge/dapp-kit/integration/recipes/setup.md +168 -0
- package/knowledge/dapp-kit/integration/recipes/staking.md +202 -0
- package/knowledge/dapp-kit/integration/recipes/swap.md +272 -0
- package/knowledge/dapp-kit/integration/recipes/wallet-connectivity.md +128 -0
- package/knowledge/dapp-kit/integration/reference/README.md +12 -0
- package/knowledge/dapp-kit/integration/reference/glossary.md +190 -0
- package/knowledge/dapp-kit/integration/reference/hooks-index.md +190 -0
- package/knowledge/dapp-kit/integration/reference/public-api.md +110 -0
- package/knowledge/dapp-kit/integration/reference/querykey-conventions.md +179 -0
- package/knowledge/dapp-kit/migration/README.md +60 -0
- package/knowledge/dapp-kit/migration/ai-rules.md +81 -0
- package/knowledge/dapp-kit/migration/breaking-changes/hook-signatures.md +233 -0
- package/knowledge/dapp-kit/migration/breaking-changes/querykey-conventions.md +108 -0
- package/knowledge/dapp-kit/migration/breaking-changes/result-handling.md +211 -0
- package/knowledge/dapp-kit/migration/breaking-changes/sdk-leakage.md +167 -0
- package/knowledge/dapp-kit/migration/checklist.md +89 -0
- package/knowledge/dapp-kit/migration/features/README.md +34 -0
- package/knowledge/dapp-kit/migration/features/auxiliary-services.md +114 -0
- package/knowledge/dapp-kit/migration/features/bitcoin.md +88 -0
- package/knowledge/dapp-kit/migration/features/bridge.md +160 -0
- package/knowledge/dapp-kit/migration/features/dex.md +101 -0
- package/knowledge/dapp-kit/migration/features/migration.md +120 -0
- package/knowledge/dapp-kit/migration/features/money-market.md +139 -0
- package/knowledge/dapp-kit/migration/features/staking.md +109 -0
- package/knowledge/dapp-kit/migration/features/swap.md +133 -0
- package/knowledge/dapp-kit/migration/recipes.md +185 -0
- package/knowledge/dapp-kit/migration/reference/README.md +15 -0
- package/knowledge/dapp-kit/migration/reference/deleted-hooks.md +110 -0
- package/knowledge/dapp-kit/migration/reference/error-shape-crosswalk.md +144 -0
- package/knowledge/dapp-kit/migration/reference/renamed-hooks.md +68 -0
- package/knowledge/sdk/AGENTS.md +41 -0
- package/knowledge/sdk/integration/README.md +41 -0
- package/knowledge/sdk/integration/ai-rules.md +75 -0
- package/knowledge/sdk/integration/architecture.md +533 -0
- package/knowledge/sdk/integration/chain-specifics.md +189 -0
- package/knowledge/sdk/integration/features/README.md +19 -0
- package/knowledge/sdk/integration/features/auxiliary-services.md +189 -0
- package/knowledge/sdk/integration/features/bridge.md +136 -0
- package/knowledge/sdk/integration/features/dex.md +182 -0
- package/knowledge/sdk/integration/features/icx-bnusd-baln.md +181 -0
- package/knowledge/sdk/integration/features/money-market.md +198 -0
- package/knowledge/sdk/integration/features/staking.md +166 -0
- package/knowledge/sdk/integration/features/swap.md +207 -0
- package/knowledge/sdk/integration/quickstart.md +213 -0
- package/knowledge/sdk/integration/recipes/README.md +21 -0
- package/knowledge/sdk/integration/recipes/backend-server-init.md +69 -0
- package/knowledge/sdk/integration/recipes/chain-key-narrowing.md +65 -0
- package/knowledge/sdk/integration/recipes/gas-estimation.md +33 -0
- package/knowledge/sdk/integration/recipes/initialize-sodax.md +78 -0
- package/knowledge/sdk/integration/recipes/raw-tx-flow.md +71 -0
- package/knowledge/sdk/integration/recipes/result-and-errors.md +104 -0
- package/knowledge/sdk/integration/recipes/signed-tx-flow.md +46 -0
- package/knowledge/sdk/integration/recipes/testing.md +101 -0
- package/knowledge/sdk/integration/reference/README.md +18 -0
- package/knowledge/sdk/integration/reference/chain-keys.md +67 -0
- package/knowledge/sdk/integration/reference/error-codes.md +165 -0
- package/knowledge/sdk/integration/reference/glossary.md +32 -0
- package/knowledge/sdk/integration/reference/public-api.md +138 -0
- package/knowledge/sdk/integration/reference/wallet-providers.md +62 -0
- package/knowledge/sdk/migration/README.md +58 -0
- package/knowledge/sdk/migration/ai-rules.md +80 -0
- package/knowledge/sdk/migration/breaking-changes/architecture.md +344 -0
- package/knowledge/sdk/migration/breaking-changes/result-and-errors.md +363 -0
- package/knowledge/sdk/migration/breaking-changes/type-system.md +341 -0
- package/knowledge/sdk/migration/checklist.md +67 -0
- package/knowledge/sdk/migration/features/README.md +35 -0
- package/knowledge/sdk/migration/features/auxiliary-services.md +156 -0
- package/knowledge/sdk/migration/features/bridge.md +128 -0
- package/knowledge/sdk/migration/features/dex.md +143 -0
- package/knowledge/sdk/migration/features/icx-bnusd-baln.md +151 -0
- package/knowledge/sdk/migration/features/money-market.md +214 -0
- package/knowledge/sdk/migration/features/staking.md +138 -0
- package/knowledge/sdk/migration/features/swap.md +198 -0
- package/knowledge/sdk/migration/recipes.md +350 -0
- package/knowledge/sdk/migration/reference/README.md +18 -0
- package/knowledge/sdk/migration/reference/deleted-exports.md +127 -0
- package/knowledge/sdk/migration/reference/error-code-crosswalk.md +104 -0
- package/knowledge/sdk/migration/reference/return-shapes.md +49 -0
- package/knowledge/sdk/migration/reference/sodax-config.md +145 -0
- package/knowledge/wallet-sdk-core/AGENTS.md +43 -0
- package/knowledge/wallet-sdk-core/integration/README.md +108 -0
- package/knowledge/wallet-sdk-core/integration/ai-rules.md +141 -0
- package/knowledge/wallet-sdk-core/integration/architecture.md +212 -0
- package/knowledge/wallet-sdk-core/integration/features/README.md +22 -0
- package/knowledge/wallet-sdk-core/integration/features/bitcoin.md +103 -0
- package/knowledge/wallet-sdk-core/integration/features/evm.md +102 -0
- package/knowledge/wallet-sdk-core/integration/features/icon.md +88 -0
- package/knowledge/wallet-sdk-core/integration/features/injective.md +92 -0
- package/knowledge/wallet-sdk-core/integration/features/near.md +92 -0
- package/knowledge/wallet-sdk-core/integration/features/solana.md +104 -0
- package/knowledge/wallet-sdk-core/integration/features/stacks.md +91 -0
- package/knowledge/wallet-sdk-core/integration/features/stellar.md +95 -0
- package/knowledge/wallet-sdk-core/integration/features/sui.md +96 -0
- package/knowledge/wallet-sdk-core/integration/quickstart.md +259 -0
- package/knowledge/wallet-sdk-core/integration/recipes/README.md +15 -0
- package/knowledge/wallet-sdk-core/integration/recipes/bridge-to-sdk.md +145 -0
- package/knowledge/wallet-sdk-core/integration/recipes/defaults-and-overrides.md +159 -0
- package/knowledge/wallet-sdk-core/integration/recipes/library-exports.md +129 -0
- package/knowledge/wallet-sdk-core/integration/recipes/setup-browser-extension.md +137 -0
- package/knowledge/wallet-sdk-core/integration/recipes/setup-private-key.md +115 -0
- package/knowledge/wallet-sdk-core/integration/recipes/sign-and-broadcast.md +201 -0
- package/knowledge/wallet-sdk-core/integration/recipes/testing.md +163 -0
- package/knowledge/wallet-sdk-core/integration/reference/README.md +13 -0
- package/knowledge/wallet-sdk-core/integration/reference/chain-support.md +65 -0
- package/knowledge/wallet-sdk-core/integration/reference/glossary.md +28 -0
- package/knowledge/wallet-sdk-core/integration/reference/interfaces.md +131 -0
- package/knowledge/wallet-sdk-core/integration/reference/provider-classes.md +54 -0
- package/knowledge/wallet-sdk-core/integration/reference/public-api.md +128 -0
- package/knowledge/wallet-sdk-core/migration/README.md +84 -0
- package/knowledge/wallet-sdk-core/migration/ai-rules.md +139 -0
- package/knowledge/wallet-sdk-core/migration/breaking-changes/README.md +14 -0
- package/knowledge/wallet-sdk-core/migration/breaking-changes/base-wallet-provider.md +52 -0
- package/knowledge/wallet-sdk-core/migration/breaking-changes/defaults-config.md +57 -0
- package/knowledge/wallet-sdk-core/migration/breaking-changes/folder-layout.md +99 -0
- package/knowledge/wallet-sdk-core/migration/breaking-changes/library-exports.md +58 -0
- package/knowledge/wallet-sdk-core/migration/checklist.md +62 -0
- package/knowledge/wallet-sdk-core/migration/recipes/README.md +12 -0
- package/knowledge/wallet-sdk-core/migration/recipes/adopt-defaults.md +84 -0
- package/knowledge/wallet-sdk-core/migration/recipes/adopt-library-exports.md +99 -0
- package/knowledge/wallet-sdk-core/migration/reference/README.md +12 -0
- package/knowledge/wallet-sdk-core/migration/reference/added-fields.md +71 -0
- package/knowledge/wallet-sdk-core/migration/reference/deleted-exports.md +35 -0
- package/knowledge/wallet-sdk-core/migration/reference/renamed-symbols.md +31 -0
- package/knowledge/wallet-sdk-core/migration/reference/return-shapes.md +23 -0
- package/knowledge/wallet-sdk-react/AGENTS.md +46 -0
- package/knowledge/wallet-sdk-react/integration/README.md +103 -0
- package/knowledge/wallet-sdk-react/integration/ai-rules.md +136 -0
- package/knowledge/wallet-sdk-react/integration/architecture.md +185 -0
- package/knowledge/wallet-sdk-react/integration/examples/01-minimal-evm.tsx +75 -0
- package/knowledge/wallet-sdk-react/integration/examples/02-multi-chain-modal.tsx +169 -0
- package/knowledge/wallet-sdk-react/integration/examples/03-nextjs-app-router.tsx +99 -0
- package/knowledge/wallet-sdk-react/integration/examples/04-walletconnect-setup.tsx +89 -0
- package/knowledge/wallet-sdk-react/integration/examples/README.md +29 -0
- package/knowledge/wallet-sdk-react/integration/recipes/batch-operations.md +224 -0
- package/knowledge/wallet-sdk-react/integration/recipes/bridge-to-sdk.md +165 -0
- package/knowledge/wallet-sdk-react/integration/recipes/chain-detection.md +259 -0
- package/knowledge/wallet-sdk-react/integration/recipes/connect-button.md +159 -0
- package/knowledge/wallet-sdk-react/integration/recipes/multi-chain-modal.md +203 -0
- package/knowledge/wallet-sdk-react/integration/recipes/setup.md +163 -0
- package/knowledge/wallet-sdk-react/integration/recipes/sign-message.md +138 -0
- package/knowledge/wallet-sdk-react/integration/recipes/sub-path-imports.md +97 -0
- package/knowledge/wallet-sdk-react/integration/recipes/switch-chain.md +144 -0
- package/knowledge/wallet-sdk-react/integration/recipes/walletconnect-setup.md +139 -0
- package/knowledge/wallet-sdk-react/integration/reference/api-surface.md +176 -0
- package/knowledge/wallet-sdk-react/integration/reference/chain-support.md +79 -0
- package/knowledge/wallet-sdk-react/integration/reference/connectors.md +75 -0
- package/knowledge/wallet-sdk-react/integration/reference/hooks.md +212 -0
- package/knowledge/wallet-sdk-react/integration/reference/wallet-brands.md +107 -0
- package/knowledge/wallet-sdk-react/migration/README.md +49 -0
- package/knowledge/wallet-sdk-react/migration/ai-rules.md +144 -0
- package/knowledge/wallet-sdk-react/migration/breaking-changes.md +310 -0
- package/knowledge/wallet-sdk-react/migration/checklist.md +159 -0
- package/knowledge/wallet-sdk-react/migration/recipes/connect-button.md +170 -0
- package/knowledge/wallet-sdk-react/migration/recipes/multi-chain-modal.md +245 -0
- package/knowledge/wallet-sdk-react/migration/recipes/ssr-setup.md +165 -0
- package/knowledge/wallet-sdk-react/migration/recipes/walletconnect-migration.md +170 -0
- package/knowledge/wallet-sdk-react/migration/reference/components.md +75 -0
- package/knowledge/wallet-sdk-react/migration/reference/config.md +339 -0
- package/knowledge/wallet-sdk-react/migration/reference/hooks.md +336 -0
- package/knowledge/wallet-sdk-react/migration/reference/imports.md +158 -0
- package/package.json +59 -0
- package/skills/sodax-dapp-kit-integration/SKILL.md +71 -0
- package/skills/sodax-dapp-kit-migration/SKILL.md +58 -0
- package/skills/sodax-sdk-integration/SKILL.md +66 -0
- package/skills/sodax-sdk-migration/SKILL.md +75 -0
- package/skills/sodax-wallet-sdk-core-integration/SKILL.md +55 -0
- package/skills/sodax-wallet-sdk-core-migration/SKILL.md +56 -0
- package/skills/sodax-wallet-sdk-react-integration/SKILL.md +80 -0
- package/skills/sodax-wallet-sdk-react-migration/SKILL.md +71 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-dapp-kit-migration
|
|
3
|
+
description: 'Port EXISTING v1 `@sodax/dapp-kit` React hooks to v2 — a deep canonicalization pass: single-object hook params, mandatory `mutateAsyncSafe`, hook-owned invalidations, throw-on-`Result.!ok` inside `mutationFn`, canonical queryKey/mutationKey conventions. Plus the SDK underneath was reshaped (chain-key-driven routing, `Result<T>` everywhere, `WalletProviderSlot<K, Raw>`). v1 dapp-kit code will not compile against v2. Use whenever a React dapp imports v1 hooks (positional args, hook-init `spokeProvider`, `useSpokeProvider`, `invalidateMmQueries`, legacy `useMigrate`, `*_MAINNET_CHAIN_ID`). Triggers on "migrate @sodax/dapp-kit", "useSpokeProvider gone", "dapp-kit v1 → v2", "invalidateMmQueries broken", "dapp-kit hook signatures changed".'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Pick this skill when the consumer has v1 dapp-kit patterns. Grep signals:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
grep -rE 'useSpokeProvider|invalidateMmQueries|useMigrate\b' src/
|
|
12
|
+
grep -rE '_MAINNET_CHAIN_ID\b|\bxChainId\b' src/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If the project has both v1 patterns AND wants new features: **migration first, then integration**. Stale v1 patterns leak into new code if you skip it.
|
|
16
|
+
|
|
17
|
+
For new v2 code with no v1 history → use `sodax-dapp-kit-integration` instead.
|
|
18
|
+
|
|
19
|
+
The SDK underneath also changed — load `sodax-sdk-migration` alongside this one (the migration trees cross-link).
|
|
20
|
+
|
|
21
|
+
# Workflow
|
|
22
|
+
|
|
23
|
+
1. Read [`../../knowledge/dapp-kit/migration/ai-rules.md`](../../knowledge/dapp-kit/migration/ai-rules.md) — DO / DO NOT / workflow / stop conditions.
|
|
24
|
+
2. Read [`../../knowledge/dapp-kit/migration/README.md`](../../knowledge/dapp-kit/migration/README.md) — overview, reading order, glossary.
|
|
25
|
+
3. Walk [`checklist.md`](../../knowledge/dapp-kit/migration/checklist.md) — top-down cross-cutting steps.
|
|
26
|
+
4. **Cross-cutting breaking changes** in order:
|
|
27
|
+
- [`breaking-changes/hook-signatures.md`](../../knowledge/dapp-kit/migration/breaking-changes/hook-signatures.md) — single-arg policy + `ReadHookParams` / `MutationHookParams`.
|
|
28
|
+
- [`breaking-changes/result-handling.md`](../../knowledge/dapp-kit/migration/breaking-changes/result-handling.md) — `Result<T>` success-path → throws; `mutateAsyncSafe`.
|
|
29
|
+
- [`breaking-changes/querykey-conventions.md`](../../knowledge/dapp-kit/migration/breaking-changes/querykey-conventions.md) — camelCase + default mutationKey.
|
|
30
|
+
- [`breaking-changes/sdk-leakage.md`](../../knowledge/dapp-kit/migration/breaking-changes/sdk-leakage.md) — cross-links to SDK migration tree.
|
|
31
|
+
5. **Per-feature playbooks** under [`features/`](../../knowledge/dapp-kit/migration/features/) — `swap.md`, `money-market.md`, `staking.md`, `bridge.md`, `dex.md`, `migration.md`, `bitcoin.md`, `auxiliary-services.md`.
|
|
32
|
+
6. **Codemods + adapters** → [`recipes.md`](../../knowledge/dapp-kit/migration/recipes.md).
|
|
33
|
+
7. **Reference** → [`reference/`](../../knowledge/dapp-kit/migration/reference/) — `deleted-hooks.md` (e.g. `useSpokeProvider`, `invalidateMmQueries`, legacy `useMigrate`), `renamed-hooks.md`, `error-shape-crosswalk.md`.
|
|
34
|
+
|
|
35
|
+
# Top traps to avoid
|
|
36
|
+
|
|
37
|
+
1. **Reaching for `useSpokeProvider`.** Deleted. Pass `walletProvider` from `useWalletProvider({ xChainId: chainKey })` (`@sodax/wallet-sdk-react`) directly into `mutate(vars)`.
|
|
38
|
+
2. **Treating mutation `data` as `Result<T>`.** v2's `mutationFn` unwraps before resolving — `data` is the unwrapped success value.
|
|
39
|
+
3. **Forgetting `try/catch` on `mutateAsync`.** v2's `mutateAsync` rejects on SDK `!ok`. Prefer `mutateAsyncSafe` (never rejects).
|
|
40
|
+
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.
|
|
41
|
+
5. **Reading `xToken.xChainId` or hard-coding `*_MAINNET_CHAIN_ID`.** SDK leakage. Renamed: `XToken.chainKey`, `ChainKeys.X_MAINNET`.
|
|
42
|
+
|
|
43
|
+
# Verification
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm tsc --noEmit # must exit clean
|
|
47
|
+
grep -rE 'useSpokeProvider|invalidateMmQueries\b' src/ # empty
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Manual:
|
|
51
|
+
- Sequenced flows use `mutateAsyncSafe` and branch on `result.ok`.
|
|
52
|
+
- React Query devtools show hook-owned invalidations on success (consumer `onSuccess` runs after, doesn't duplicate them).
|
|
53
|
+
|
|
54
|
+
# Related skills
|
|
55
|
+
|
|
56
|
+
- `sodax-dapp-kit-integration` — write new v2 code (after migration completes).
|
|
57
|
+
- `sodax-sdk-migration` — the SDK-side migration runs in lockstep (chain-key renames, Result, error model).
|
|
58
|
+
- `sodax-wallet-sdk-react-migration` — if the wallet layer also has v1 patterns.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-sdk-integration
|
|
3
|
+
description: 'Build NEW code against @sodax/sdk v2 — the SODAX cross-chain DeFi SDK (hub-and-spoke architecture, Sonic hub + 19 spoke chains across EVM and non-EVM). Covers intent-based swaps, lending/borrowing (money market), staking, bridging, concentrated-liquidity DEX, ICX/bnUSD/BALN migration, partner fees, and stuck-asset recovery. Use this skill whenever a non-React or backend codebase calls `@sodax/sdk` directly (Node scripts, indexers, bots, server APIs, custom non-React browser flows). Triggers on "use @sodax/sdk", "swap with Sodax", "Sodax bridge", "Sodax money market", "Sodax staking", "cross-chain DeFi", "Sonic hub", any `Sodax` / `ChainKeys` / `Result<T>` / `SodaxError` symbol, or any cross-chain DeFi operation in a backend context. For React dapps, prefer `sodax-dapp-kit-integration` instead.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Pick this skill when the consumer is **writing new v2 code** that calls `@sodax/sdk` directly (no React wrapper). Common signals:
|
|
9
|
+
|
|
10
|
+
- Node.js server, script, indexer, bot, or CI test that uses `Sodax`.
|
|
11
|
+
- Custom browser flow without `@sodax/dapp-kit`.
|
|
12
|
+
- Any cross-chain DeFi action: swap, bridge, money market (supply/borrow/withdraw/repay), staking, DEX (concentrated liquidity), migration (ICX/bnUSD/BALN), partner fees, recovery.
|
|
13
|
+
|
|
14
|
+
For React dapps using hooks → use `sodax-dapp-kit-integration` instead (this skill is still relevant for any unwrapped SDK call).
|
|
15
|
+
|
|
16
|
+
For porting v1 code → use `sodax-sdk-migration` first.
|
|
17
|
+
|
|
18
|
+
# Workflow
|
|
19
|
+
|
|
20
|
+
Follow in order. Skipping `ai-rules.md` is the most common cause of agents reverting to v1 patterns.
|
|
21
|
+
|
|
22
|
+
1. Read [`../../knowledge/sdk/integration/ai-rules.md`](../../knowledge/sdk/integration/ai-rules.md) — DO / DO NOT / workflow / stop conditions.
|
|
23
|
+
2. Read [`../../knowledge/sdk/integration/quickstart.md`](../../knowledge/sdk/integration/quickstart.md) — install, initialize, first-run troubleshooting.
|
|
24
|
+
3. For your feature, read [`../../knowledge/sdk/integration/features/`](../../knowledge/sdk/integration/features/) — `swap.md`, `money-market.md`, `staking.md`, `bridge.md`, `dex.md`, `icx-bnusd-baln.md`, `auxiliary-services.md`.
|
|
25
|
+
4. For specific patterns (init, raw vs signed, chain narrowing, gas, testing, errors), read [`../../knowledge/sdk/integration/recipes/`](../../knowledge/sdk/integration/recipes/).
|
|
26
|
+
5. Lookups (chain keys, error codes, public API surface, wallet provider types, glossary) → [`../../knowledge/sdk/integration/reference/`](../../knowledge/sdk/integration/reference/).
|
|
27
|
+
6. Non-EVM quirks (Stellar trustline, BTC PSBT, Solana PDA, ICON, NEAR) → [`../../knowledge/sdk/integration/chain-specifics.md`](../../knowledge/sdk/integration/chain-specifics.md).
|
|
28
|
+
|
|
29
|
+
# v2 in one minute
|
|
30
|
+
|
|
31
|
+
1. **Chain key drives everything.** Pass `srcChainKey: ChainKeys.ETHEREUM_MAINNET` on the request payload — the SDK routes internally and TypeScript narrows `walletProvider` to the chain-specific interface via `GetWalletProviderType<K>`. There are **no** `*SpokeProvider` classes to construct.
|
|
32
|
+
2. **Every async public method returns `Result<T>`.** Branch on `result.ok`. No throws across service boundaries. Sub-Result forwarding is the default: `if (!sub.ok) return sub`.
|
|
33
|
+
3. **Errors are `SodaxError<C>`.** A single class with a closed 13-code reason vocabulary plus a `feature` field. The pair `(feature, code)` is your discriminator. Use `isSodaxError(e)` (not bare `instanceof`).
|
|
34
|
+
4. **Signed vs raw is a discriminated union.** `WalletProviderSlot<K, Raw>` enforces at compile time: `{ raw: false, walletProvider }` for signing, `{ raw: true }` for unsigned-tx building. Mixing them is a TypeScript error.
|
|
35
|
+
5. **Config is dynamic; overrides only land on `sodax.config`.** Always read via `sodax.config.*` (e.g. `sodax.config.spokeChainConfig[chainKey]`). Direct imports of `spokeChainConfig` / `sodaxConfig` from `@sodax/types` / `@sodax/sdk` are packaged-default snapshots and silently miss both `await sodax.config.initialize()` updates and `new Sodax(config)` overrides.
|
|
36
|
+
|
|
37
|
+
# Top traps to avoid
|
|
38
|
+
|
|
39
|
+
1. **Reaching for a `*SpokeProvider`.** They're deleted. Pass an object satisfying the chain-specific `I*WalletProvider` interface directly into the SDK call payload. Implementations come from your application — write your own or install `@sodax/wallet-sdk-core`.
|
|
40
|
+
2. **Forgetting `raw: false`.** Without the discriminator, `walletProvider` is rejected with "Object literal may only specify known properties." Add `raw: false` for signed flows; `raw: true` for unsigned-tx building.
|
|
41
|
+
3. **Importing from `@sodax/types` directly.** `@sodax/sdk` re-exports the entire `@sodax/types` surface. Add `@sodax/sdk` as your only dependency; importing `@sodax/types` separately risks version skew.
|
|
42
|
+
4. **Treating `Result<T>` as throw-on-failure.** v2 mutation methods do **not** throw on SDK-level failure — they resolve `{ ok: false, error }`. A `try/catch` only catches *exceptions* from inside `mutationFn` (e.g. missing `walletProvider`); it will **not** catch `RELAY_TIMEOUT` or `EXECUTION_FAILED`. Branch on `.ok`.
|
|
43
|
+
5. **Reading `xToken.xChainId` or hard-coding `*_MAINNET_CHAIN_ID`.** Renamed: `XToken.chainKey` and `ChainKeys.*`. v1 numeric/string chain-id constants are gone.
|
|
44
|
+
|
|
45
|
+
# Conventions agents must follow
|
|
46
|
+
|
|
47
|
+
- **`Result<T>` discrimination on `.ok`.** Always branch on `result.ok` before reading `.value` or `.error`. Forward sub-Results without re-wrapping (`if (!sub.ok) return sub`).
|
|
48
|
+
- **`(feature, code)` for error switching.** Use `isSodaxError(e)`, then `e.feature` and `e.code` for routing logic. Don't string-match on `e.message`.
|
|
49
|
+
- **`ChainKeys.*` over hard-coded strings.** The set of supported chains evolves per release.
|
|
50
|
+
- **No `as unknown as <Type>` double-casts.** v2 type narrowing makes them unnecessary — chain-key generic flow + `GetWalletProviderType<K>` resolves to the exact interface.
|
|
51
|
+
- **Don't generate `try { await sodax.<method>(...) } catch` for SDK-level failures.** That catch never fires for `Result.!ok`. Branch on `result.ok`.
|
|
52
|
+
- Import only from the package root: `import { Sodax, ChainKeys, type SpokeChainKey } from '@sodax/sdk'`. Don't deep-import from `dist/...`.
|
|
53
|
+
|
|
54
|
+
# Verification
|
|
55
|
+
|
|
56
|
+
1. `pnpm tsc --noEmit` from the consumer repo — must exit clean.
|
|
57
|
+
2. Every `await sodax.<feature>.<method>(...)` call site has `if (!result.ok)` branching.
|
|
58
|
+
3. No `xToken.xChainId`, no `*_MAINNET_CHAIN_ID`, no `*SpokeProvider` references.
|
|
59
|
+
4. `isSodaxError(e)` (not bare `instanceof SodaxError`) in cross-bundle code.
|
|
60
|
+
|
|
61
|
+
# Related skills
|
|
62
|
+
|
|
63
|
+
- `sodax-sdk-migration` — port v1 SDK call sites to v2.
|
|
64
|
+
- `sodax-wallet-sdk-core-integration` — set up a wallet provider for signing flows.
|
|
65
|
+
- `sodax-dapp-kit-integration` — React hooks wrapping this SDK.
|
|
66
|
+
- `sodax-wallet-sdk-react-integration` — React wallet connectivity layer.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-sdk-migration
|
|
3
|
+
description: 'Port EXISTING v1 `@sodax/sdk` consumer code to v2 — the deep architectural reshape (chain-key-driven routing replaced `*SpokeProvider` classes; `Result<T>` replaced throwing methods; `SodaxError<C>` replaced module-specific error unions; `WalletProviderSlot<K, Raw>` replaced ad-hoc wallet/raw branching; `ConfigService` replaced static lookup tables). Use whenever a codebase has v1 fingerprints — `_MAINNET_CHAIN_ID`, `*SpokeProvider`, `xChainId`, `SpokeChainId`, `MoneyMarketError`/`IntentError`/`StakingError`/`BridgeError`/`MigrationError`/`AssetServiceError`/`ConcentratedLiquidityError`/`RelayError` — and the consumer wants to compile against v2. Triggers on "migrate Sodax v1", "upgrade @sodax/sdk", "v1 → v2", "port to new Sodax", "useSpokeProvider broken", "Sodax error types changed". v1 code will not compile against v2.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Pick this skill when the consumer has **existing v1 SDK code** that needs to compile against v2. Common signals (grep for these):
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
grep -rE '_MAINNET_CHAIN_ID\b|\bSpokeProvider\b|\bxChainId\b|\bSpokeChainId\b|hubAssets|moneyMarketSupportedTokens' src/
|
|
12
|
+
grep -rE 'instanceof (MoneyMarketError|IntentError|StakingError|BridgeError|MigrationError|AssetServiceError|ConcentratedLiquidityError|RelayError)' src/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If the consumer has v1 fingerprints AND also wants new features: **do migration first**. Stale v1 patterns leak into new code if you skip it.
|
|
16
|
+
|
|
17
|
+
For new v2 code with no v1 history → use `sodax-sdk-integration` instead.
|
|
18
|
+
|
|
19
|
+
# Workflow
|
|
20
|
+
|
|
21
|
+
1. Read [`../../knowledge/sdk/migration/ai-rules.md`](../../knowledge/sdk/migration/ai-rules.md) — DO / DO NOT / workflow / stop conditions. **Read first** — prevents the most common porting mistakes.
|
|
22
|
+
2. Read [`../../knowledge/sdk/migration/README.md`](../../knowledge/sdk/migration/README.md) — overview, reading order, cross-cutting checklist, v1↔v2 glossary.
|
|
23
|
+
3. **Cross-cutting first.** In order:
|
|
24
|
+
- [`breaking-changes/type-system.md`](../../knowledge/sdk/migration/breaking-changes/type-system.md) — renames at `@sodax/types`, `ChainKeys`, `WalletProviderSlot`, `RpcConfig`, `IConfigApi` Result.
|
|
25
|
+
- [`breaking-changes/architecture.md`](../../knowledge/sdk/migration/breaking-changes/architecture.md) — `*SpokeProvider` deletion, `ConfigService`, relay reshape.
|
|
26
|
+
- [`breaking-changes/result-and-errors.md`](../../knowledge/sdk/migration/breaking-changes/result-and-errors.md) — throws → `Result<T>`; module errors → `SodaxError<C>`; v1↔v2 code crosswalk.
|
|
27
|
+
4. **Per-feature playbooks** under [`features/`](../../knowledge/sdk/migration/features/) — `swap.md`, `money-market.md`, `staking.md`, `bridge.md`, `dex.md`, `icx-bnusd-baln.md`, `auxiliary-services.md` — read only the ones the consumer uses.
|
|
28
|
+
5. **Codemods + adapters** for mechanical replacement → [`recipes.md`](../../knowledge/sdk/migration/recipes.md).
|
|
29
|
+
6. **Cross-check** symbols in [`reference/`](../../knowledge/sdk/migration/reference/) — `deleted-exports.md`, `error-code-crosswalk.md`, `return-shapes.md`, `sodax-config.md`.
|
|
30
|
+
|
|
31
|
+
# Mechanical type renames (do these first)
|
|
32
|
+
|
|
33
|
+
Apply in this order — type-level changes don't affect behavior; runtime patterns require thinking.
|
|
34
|
+
|
|
35
|
+
| v1 | v2 | Codemod |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `*_MAINNET_CHAIN_ID` | `ChainKeys.*_MAINNET` | regex `(\w+)_MAINNET_CHAIN_ID` → `ChainKeys.$1_MAINNET` |
|
|
38
|
+
| `XToken.xChainId` (and tokens-likes) | `XToken.chainKey` | field rename |
|
|
39
|
+
| `SpokeChainId` / `ChainId` | `SpokeChainKey` | type rename |
|
|
40
|
+
| `Token` | `XToken` | type rename |
|
|
41
|
+
| `AddressType` (BTC) | `BtcAddressType` | only at `@sodax/types` import sites |
|
|
42
|
+
|
|
43
|
+
Then on every signed-call payload: drop `spokeProvider`, add `walletProvider`, add `raw: false` discriminator, rename `intentParams` → `params`. Plus add `srcChainKey` + `srcAddress` to every action params object (MM, staking, deposit, …).
|
|
44
|
+
|
|
45
|
+
# Top traps to avoid
|
|
46
|
+
|
|
47
|
+
1. **Reaching for a `*SpokeProvider`.** They're deleted. Pass `walletProvider` (an `I*WalletProvider` impl) directly in the call payload.
|
|
48
|
+
2. **`instanceof MoneyMarketError` (and other module error classes).** Deleted. Replace with `isSodaxError(e) && e.feature === 'moneyMarket'`.
|
|
49
|
+
3. **Destructuring cross-chain results as arrays.** v1 had `bridge()` returning a string and others returning tuples; v2 returns `TxHashPair = { srcChainTxHash, dstChainTxHash }` for **every** cross-chain mutation. Destructure as `{ srcChainTxHash, dstChainTxHash } = result.value`.
|
|
50
|
+
4. **Keeping `try/catch` to inspect v1 error codes.** v2 returns `Result<T>` — failure lives on `result.error.code`, not on a thrown error. The v2 code names changed too — see `reference/error-code-crosswalk.md`.
|
|
51
|
+
5. **Calling `getStakingInfo(hubAddress)`.** Renamed to `getStakingInfoFromSpoke(srcAddress, srcChainKey)`. `getStakingInfo` is not a public method anymore.
|
|
52
|
+
|
|
53
|
+
# DO NOT
|
|
54
|
+
|
|
55
|
+
- Grep-replace `srcChain` → `srcChainKey` blindly. The `Intent` read shape keeps `srcChain` / `dstChain` as `IntentRelayChainId` (bigint). Only **request** types changed.
|
|
56
|
+
- Assume `BalnSwapService` lock methods (`stake`, `unstake`, `claim`, `claimUnstaked`, `cancelUnstake`, `getDetailedUserLocks`) return `Result<T>`. They still throw — known carve-out. Keep `try/catch` for those specific calls.
|
|
57
|
+
- Add `@sodax/types` as a peer dependency. It's bundled into `@sodax/sdk`'s public surface.
|
|
58
|
+
|
|
59
|
+
# Verification
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm tsc --noEmit # must exit clean
|
|
63
|
+
# No leftover v1 fingerprints:
|
|
64
|
+
grep -rE '_MAINNET_CHAIN_ID\b|\bxChainId\b|\bSpokeChainId\b|\bSpokeProvider\b|hubAssets|moneyMarketSupportedTokens' src/ # empty
|
|
65
|
+
grep -rE 'MoneyMarketError|IntentError|StakingError|BridgeError|MigrationError|AssetServiceError|ConcentratedLiquidityError|RelayError' src/ # empty
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Every `await sodax.<feature>.<method>(...)` call site must have `if (!result.ok)` branching (highest-leverage change — if you stop early, ensure result branching is at least in place).
|
|
69
|
+
|
|
70
|
+
# Related skills
|
|
71
|
+
|
|
72
|
+
- `sodax-sdk-integration` — write new v2 code (use after migration completes).
|
|
73
|
+
- `sodax-wallet-sdk-core-migration` — also additively upgrade the wallet-sdk-core surface (renames are minimal there; mostly deep-import → barrel-import).
|
|
74
|
+
- `sodax-dapp-kit-migration` — if the consumer also uses React hooks.
|
|
75
|
+
- `sodax-wallet-sdk-react-migration` — if the consumer also has v1 wallet-sdk-react.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-wallet-sdk-core-integration
|
|
3
|
+
description: 'Build NEW code with `@sodax/wallet-sdk-core` — the low-level multi-chain wallet layer (one provider class per chain family across 9 chain types: EVM, Solana, Sui, Bitcoin, Stellar, ICON, Injective, NEAR, Stacks). Each class accepts either a private-key config (Node scripts, CI, bots, indexers) or a browser-extension config (custom non-React browser flows) and signs + broadcasts transactions. Use whenever a backend, script, test, or non-React browser flow needs to instantiate a wallet provider directly — `EvmWalletProvider`, `SolanaWalletProvider`, etc. Triggers on "instantiate EvmWalletProvider", "sign a tx from a Node script", "wallet provider for backend", "private-key signing", "wallet-sdk-core setup", any `*WalletProvider` class name. For React dapps prefer `sodax-wallet-sdk-react-integration` instead — most React consumers never touch this package directly and get a typed `IXxxWalletProvider` via `useWalletProvider(...)`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Direct usage of `@sodax/wallet-sdk-core` is the right choice for:
|
|
9
|
+
|
|
10
|
+
- Backend / Node scripts (CI tests, indexers, bots, server APIs).
|
|
11
|
+
- Custom browser flows that don't use React.
|
|
12
|
+
- Tests that need to sign with a deterministic key.
|
|
13
|
+
|
|
14
|
+
For React consumers → use `sodax-wallet-sdk-react-integration` (they get the typed wallet provider via `useWalletProvider(...)` and pass it to `@sodax/sdk` calls).
|
|
15
|
+
|
|
16
|
+
For upgrades from older versions → use `sodax-wallet-sdk-core-migration` (but note: v1 → v2 changes are **additive** — all v1 surface still exists, mostly just a deep-import → barrel-import cleanup).
|
|
17
|
+
|
|
18
|
+
# Workflow
|
|
19
|
+
|
|
20
|
+
1. Read [`../../knowledge/wallet-sdk-core/integration/ai-rules.md`](../../knowledge/wallet-sdk-core/integration/ai-rules.md) — DO / DON'T + workflow + stop conditions.
|
|
21
|
+
2. Read [`../../knowledge/wallet-sdk-core/integration/architecture.md`](../../knowledge/wallet-sdk-core/integration/architecture.md) — mental model: `BaseWalletProvider`, dual-config discriminants (`{ type: 'PRIVATE_KEY', … }` vs `{ type: 'BROWSER_EXTENSION', … }`), shallow `defaults` merge, library-exports.
|
|
22
|
+
3. Read [`../../knowledge/wallet-sdk-core/integration/quickstart.md`](../../knowledge/wallet-sdk-core/integration/quickstart.md) — copy-paste minimal example for the chain you need.
|
|
23
|
+
4. For your chain, read [`../../knowledge/wallet-sdk-core/integration/features/`](../../knowledge/wallet-sdk-core/integration/features/) — per-chain config table + methods + gotchas (one file per chain family).
|
|
24
|
+
5. Task-specific recipes → [`../../knowledge/wallet-sdk-core/integration/recipes/`](../../knowledge/wallet-sdk-core/integration/recipes/) — `setup-private-key.md`, `setup-browser-extension.md`, `sign-and-broadcast.md`, `defaults-and-overrides.md`, `library-exports.md`, `bridge-to-sdk.md` (pass provider to `@sodax/sdk`).
|
|
25
|
+
6. Lookups → [`../../knowledge/wallet-sdk-core/integration/reference/`](../../knowledge/wallet-sdk-core/integration/reference/) — public API, provider classes, interfaces (`IXxxWalletProvider`), chain support, glossary.
|
|
26
|
+
|
|
27
|
+
# Conventions to follow
|
|
28
|
+
|
|
29
|
+
- **Dual-config discriminant.** Every chain's provider config has a `type` discriminator: `'PRIVATE_KEY'` (Node / scripts) or `'BROWSER_EXTENSION'` (consumer dApps). Pick one — don't merge them.
|
|
30
|
+
- **`defaults` is a shallow merge.** Each provider accepts a `defaults` field for per-method overrides (e.g. `waitForTransactionReceipt`, `gasPrice`). The merge into the per-call options is **shallow**, not deep. Top-level keys overwrite wholesale.
|
|
31
|
+
- **Use barrel imports**, not deep imports. Import classes from `@sodax/wallet-sdk-core`, not from `@sodax/wallet-sdk-core/wallet-providers/<chain>.ts`.
|
|
32
|
+
- **Re-import chain SDK types from the barrel.** `@sodax/wallet-sdk-core` re-exports the types you need (e.g. `WalletClient` from viem, `SuiClient` from `@mysten/sui`). Don't add the underlying SDK as a direct dep — risks version skew.
|
|
33
|
+
- **`IXxxWalletProvider` is the interface to pass into `@sodax/sdk`.** When bridging to the SDK, narrow with `useWalletProvider({ xChainId: ChainKeys.X })` (React) or just construct the provider directly and pass it in the SDK call payload (`{ raw: false, walletProvider }`).
|
|
34
|
+
|
|
35
|
+
# Top traps to avoid
|
|
36
|
+
|
|
37
|
+
1. **Mixing the two config variants.** `PRIVATE_KEY` and `BROWSER_EXTENSION` are mutually exclusive. Each chain's `*WalletProviderConfig` is a discriminated union — TypeScript catches mixing, but only if you don't use `as`.
|
|
38
|
+
2. **Adding viem / `@mysten/sui` / `@solana/web3.js` as a direct dep** when the type was importable from `@sodax/wallet-sdk-core`. See `integration/recipes/library-exports.md`.
|
|
39
|
+
3. **Deep-importing `@sodax/wallet-sdk-core/wallet-providers/EvmWalletProvider`**. v1's flat layout is gone; use barrel imports.
|
|
40
|
+
4. **Expecting `defaults` to deep-merge.** It doesn't — top-level keys overwrite wholesale.
|
|
41
|
+
5. **Trying to extend `BaseWalletProvider` directly** in consumer code. That's a maintainer-only path — write a thin wrapper over an existing provider instead.
|
|
42
|
+
|
|
43
|
+
# Verification
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm tsc --noEmit # must exit clean
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If errors mention `@sodax/wallet-sdk-core`, look up the symbol in `integration/reference/`. If the symbol isn't there, stop and ask the user — don't invent classes.
|
|
50
|
+
|
|
51
|
+
# Related skills
|
|
52
|
+
|
|
53
|
+
- `sodax-wallet-sdk-core-migration` — additive v1 → v2 upgrade (mostly deep-import → barrel cleanup).
|
|
54
|
+
- `sodax-sdk-integration` — pass the constructed provider into SDK calls (`{ raw: false, walletProvider }`).
|
|
55
|
+
- `sodax-wallet-sdk-react-integration` — for React dapps; this skill is only relevant if NOT using React.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-wallet-sdk-core-migration
|
|
3
|
+
description: 'Port EXISTING `@sodax/wallet-sdk-core` consumer code across versions. v1 → v2 changes are additive — same class names, same config-type names, same config shapes. The only mechanical migration is replacing deep imports from v1''s flat `wallet-providers/<chain>.ts` layout with barrel imports, plus optionally adopting the new `defaults` field and re-imported library types. Use when a project imports from `@sodax/wallet-sdk-core/wallet-providers/…`, when bumping from an older RC, or when adopting the new additive `defaults` / `*WalletDefaults` / `*Policy` fields. Most projects don''t need this — if a project does anything more than the deep-import cleanup at the wallet-sdk-core surface, the real migration target is probably `@sodax/sdk` or `@sodax/types`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Pick this skill ONLY if you see one of these patterns:
|
|
9
|
+
|
|
10
|
+
- Deep imports: `import { … } from '@sodax/wallet-sdk-core/wallet-providers/EvmWalletProvider'` (or similar per-chain file).
|
|
11
|
+
- Bumping `@sodax/wallet-sdk-core` from an older RC and wanting to adopt new additive features (`defaults`, `*WalletDefaults`, `*Policy` types).
|
|
12
|
+
|
|
13
|
+
The package name **did not change** across versions. Class names, config-type names, and config shapes are **identical** v1 → v2. **No mandatory edits** at the wallet-sdk-core surface — v1 code drops in unchanged.
|
|
14
|
+
|
|
15
|
+
If a project does more than the deep-import cleanup at this surface, the real migration target is almost certainly `@sodax/sdk` (chain-key renames, Result<T>, error model) or `@sodax/types`. Route to `sodax-sdk-migration` instead.
|
|
16
|
+
|
|
17
|
+
# Workflow
|
|
18
|
+
|
|
19
|
+
1. Read [`../../knowledge/wallet-sdk-core/migration/ai-rules.md`](../../knowledge/wallet-sdk-core/migration/ai-rules.md) — DO / DON'T + workflow. **The headline: v1 code drops in unchanged.**
|
|
20
|
+
2. Read [`../../knowledge/wallet-sdk-core/migration/README.md`](../../knowledge/wallet-sdk-core/migration/README.md) — what (additively) changed, read order, TL;DR.
|
|
21
|
+
3. Read the breaking-change writeups under [`breaking-changes/`](../../knowledge/wallet-sdk-core/migration/breaking-changes/) — `folder-layout.md` (deep-import → barrel), `defaults-config.md`, `base-wallet-provider.md`, `library-exports.md`.
|
|
22
|
+
4. For mechanical changes, apply the recipes in [`recipes/`](../../knowledge/wallet-sdk-core/migration/recipes/) — `adopt-defaults.md`, `adopt-library-exports.md`. **Both are optional** — they're cleanup paths, not requirements.
|
|
23
|
+
5. Confirm no renames / deletions exist by checking [`reference/`](../../knowledge/wallet-sdk-core/migration/reference/) — `renamed-symbols.md` (empty), `deleted-exports.md` (empty), `added-fields.md` (additive new surface).
|
|
24
|
+
6. Verify with [`checklist.md`](../../knowledge/wallet-sdk-core/migration/checklist.md).
|
|
25
|
+
|
|
26
|
+
# Top mechanical changes
|
|
27
|
+
|
|
28
|
+
1. **Deep imports → barrel imports.** Replace `import { EvmWalletProvider } from '@sodax/wallet-sdk-core/wallet-providers/EvmWalletProvider'` with `import { EvmWalletProvider } from '@sodax/wallet-sdk-core'`. The flat `wallet-providers/*.ts` layout is gone.
|
|
29
|
+
2. **(Optional) Re-import chain SDK types from the barrel.** Replace direct imports of `WalletClient` (viem), `SuiClient` (@mysten/sui), etc. with re-exports from `@sodax/wallet-sdk-core`. Removes the underlying SDK as a direct dep, eliminates version skew. See `recipes/adopt-library-exports.md`.
|
|
30
|
+
3. **(Optional) Adopt `defaults` field.** New `defaults` (shallow-merge) field on each provider's config lets you set per-method overrides centrally. See `recipes/adopt-defaults.md`.
|
|
31
|
+
|
|
32
|
+
# Top traps to avoid
|
|
33
|
+
|
|
34
|
+
1. **Treating this as a real migration.** It isn't — v1 code drops in unchanged at the wallet-sdk-core surface. If the consumer's compile errors point at this package, look one layer deeper — they're almost certainly `@sodax/types` renames bleeding through (e.g. `xChainId` → `chainKey`) and the real fix is in `@sodax/sdk`'s migration.
|
|
35
|
+
2. **Extending `BaseWalletProvider` in consumer code.** That's a maintainer path. If a project subclasses it, scope confirmation with the user before touching anything.
|
|
36
|
+
|
|
37
|
+
# Stop conditions (defer to user)
|
|
38
|
+
|
|
39
|
+
| Signal | Why stop |
|
|
40
|
+
|---|---|
|
|
41
|
+
| Compile errors mention `@sodax/sdk` or `@sodax/types` symbols | Not this migration. Route to `sodax-sdk-migration`. |
|
|
42
|
+
| Project extends `BaseWalletProvider` with non-trivial logic | Maintainer-only path. Confirm scope first. |
|
|
43
|
+
| User wants a chain family not in `integration/reference/chain-support.md` | Adding a new chain is a maintainer task. |
|
|
44
|
+
|
|
45
|
+
# Verification
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm tsc --noEmit # must exit clean
|
|
49
|
+
# No leftover deep imports from v1's flat layout:
|
|
50
|
+
grep -rE "from '@sodax/wallet-sdk-core/wallet-providers/" src/ # empty
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# Related skills
|
|
54
|
+
|
|
55
|
+
- `sodax-wallet-sdk-core-integration` — write new code (more relevant than this skill for most projects).
|
|
56
|
+
- `sodax-sdk-migration` — the SDK-side migration is where the real v1 → v2 work happens.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-wallet-sdk-react-integration
|
|
3
|
+
description: 'Build NEW code with `@sodax/wallet-sdk-react` — the React wallet connectivity layer for multi-chain dapps. Covers `SodaxWalletProvider` setup, hook-based connect/disconnect/account/signing UX across 9 chain types (EVM, Solana, Sui, Bitcoin, Stellar, ICON, Injective, NEAR, Stacks), headless wallet-modal primitives, WalletConnect for non-injected wallets (Fireblocks/Ledger/mobile), and `useWalletProvider` for bridging the connected wallet into `@sodax/sdk` calls. Use whenever a React dapp needs SODAX wallet connection. Triggers on "add wallet connect", "set up SodaxWalletProvider", "useXConnect", "useXAccount", "useWalletProvider", "useWalletModal", "wallet modal", "connect button", "multi-chain wallet UI", "WalletConnect for Fireblocks". Peer deps: `react >= 19`, `@tanstack/react-query 5.x`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Pick this skill when the consumer is a React dapp that needs SODAX wallet connectivity. Common signals:
|
|
9
|
+
|
|
10
|
+
- "I need a wallet connect button" — `useXConnect`, `useXAccount`.
|
|
11
|
+
- "Multi-chain modal UI" — `useWalletModal`, `useChainGroups`, `useConnectedChains`.
|
|
12
|
+
- "Pass the connected wallet to a `@sodax/sdk` swap" — `useWalletProvider({ xChainId })`.
|
|
13
|
+
- "Add WalletConnect for enterprise custody (Fireblocks, mobile)" — `walletConnect` field on `SodaxWalletConfig.EVM`.
|
|
14
|
+
- "SSR with Next.js" — `ssr: true` flag on the EVM slot.
|
|
15
|
+
|
|
16
|
+
For backend / non-React → use `sodax-wallet-sdk-core-integration` instead.
|
|
17
|
+
|
|
18
|
+
For React dapps with hooks wrapping the SDK → also load `sodax-dapp-kit-integration`.
|
|
19
|
+
|
|
20
|
+
For porting v1 wallet-sdk-react code → use `sodax-wallet-sdk-react-migration` first.
|
|
21
|
+
|
|
22
|
+
# Workflow
|
|
23
|
+
|
|
24
|
+
1. Read [`../../knowledge/wallet-sdk-react/integration/ai-rules.md`](../../knowledge/wallet-sdk-react/integration/ai-rules.md) — DO / DON'T + workflow.
|
|
25
|
+
2. **Always start with setup** → [`../../knowledge/wallet-sdk-react/integration/recipes/setup.md`](../../knowledge/wallet-sdk-react/integration/recipes/setup.md). Mount `SodaxWalletProvider`, declare chain-type slots, wire `@tanstack/react-query`.
|
|
26
|
+
3. Read [`../../knowledge/wallet-sdk-react/integration/architecture.md`](../../knowledge/wallet-sdk-react/integration/architecture.md) — provider mount tree, frozen config, EVM single-connection model, `xChainType` vs `xChainId`.
|
|
27
|
+
4. Task-specific recipes → [`../../knowledge/wallet-sdk-react/integration/recipes/`](../../knowledge/wallet-sdk-react/integration/recipes/) — `connect-button.md`, `multi-chain-modal.md`, `walletconnect-setup.md`, `bridge-to-sdk.md`, `sign-message.md`, `switch-chain.md`, `batch-operations.md`, `chain-detection.md`, `sub-path-imports.md`.
|
|
28
|
+
5. Working examples → [`../../knowledge/wallet-sdk-react/integration/examples/`](../../knowledge/wallet-sdk-react/integration/examples/) — 4 working `.tsx` app shells (`01-minimal-evm`, `02-multi-chain-modal`, `03-nextjs-app-router`, `04-walletconnect-setup`).
|
|
29
|
+
6. Lookups → [`../../knowledge/wallet-sdk-react/integration/reference/`](../../knowledge/wallet-sdk-react/integration/reference/) — hooks, connectors, chain-support, wallet-brands, api-surface.
|
|
30
|
+
|
|
31
|
+
# Conventions to follow
|
|
32
|
+
|
|
33
|
+
- **Single object parameter on every hook.** `useXConnectors({ xChainType: 'EVM' })`, `useXAccount({ xChainId: ChainKeys.BSC_MAINNET })`, `useWalletProvider({ xChainType: 'EVM' })`. `useXAccount` and `useWalletProvider` take **either** `xChainId` (chain key) **or** `xChainType` (family) — never both.
|
|
34
|
+
- **`useXConnect` is a React Query mutation.** Pass an `IXConnector` to `mutate` / `mutateAsync`. For provider-managed chains (EVM/Solana/Sui), the resolved value is `undefined` — read the connected account via `useXAccount` after the mutation lands.
|
|
35
|
+
- **Persisted connections.** Connections survive page reloads via `localStorage` (key `xwagmi-store`). Gate UI on hydration with `useConnectedChains().status === 'ready'` to avoid flicker.
|
|
36
|
+
- **EVM is one connection across all networks.** wagmi covers every configured EVM network under one connector — `useChainGroups` / `useConnectedChains` report a single `EVM` row.
|
|
37
|
+
- **Configurable chain opt-in.** `SodaxWalletProvider config` accepts a `SodaxWalletConfig` where top-level keys are `ChainType` slots (`EVM`, `SOLANA`, `SUI`, `BITCOIN`, `STELLAR`, `INJECTIVE`, `ICON`, `NEAR`, `STACKS`). Omit a slot to skip mounting that adapter; pass `{}` to mount with SDK defaults.
|
|
38
|
+
- **Don't import concrete chain classes from the barrel.** `EvmXService`, `XverseXConnector`, etc. are **deep-import only** (`@sodax/wallet-sdk-react/xchains/<chain>`). The barrel only exports hooks, types, interfaces, and `SodaxWalletProvider`.
|
|
39
|
+
|
|
40
|
+
# Wallet modal primitives
|
|
41
|
+
|
|
42
|
+
Headless building blocks (render-agnostic, wallet-agnostic):
|
|
43
|
+
|
|
44
|
+
| Hook | Purpose |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `useWalletModal({ onConnected })` | State machine: `closed → chainSelect → walletSelect → connecting → success \| error`. |
|
|
47
|
+
| `useConnectionFlow()` | `connect + status + retry` without a modal. |
|
|
48
|
+
| `useBatchConnect({ connectors, skipConnected })` | Sequential connect across every chain a wallet identifier covers. |
|
|
49
|
+
| `useBatchDisconnect({ connectors? })` | Mirror of `useBatchConnect`; omit `connectors` to disconnect all. |
|
|
50
|
+
| `useChainGroups({ order? })` | One entry per enabled chain; EVM collapses to one group. |
|
|
51
|
+
| `useConnectedChains({ order? })` | Aggregate connected view; `status: 'loading' \| 'ready'`. |
|
|
52
|
+
| `useIsWalletInstalled({ connectors?, chainType? })` | Cross-chain install check; filters AND. |
|
|
53
|
+
| `sortConnectors(xs, { preferred })` | Preferred first, then installed, then original. |
|
|
54
|
+
|
|
55
|
+
Reference app: `apps/wallet-modal-example` in the SODAX monorepo.
|
|
56
|
+
|
|
57
|
+
# Top traps to avoid
|
|
58
|
+
|
|
59
|
+
1. **Passing both `xChainId` and `xChainType`** to `useXAccount` / `useWalletProvider`. They're mutually exclusive.
|
|
60
|
+
2. **Casting the return value of `useWalletProvider`.** Use the chain-key narrowing pattern (passing a specific `xChainId`) to get the typed `IXxxWalletProvider` without `as`.
|
|
61
|
+
3. **Importing concrete classes from the barrel.** `EvmXService`, `XverseXConnector`, etc. live behind `@sodax/wallet-sdk-react/xchains/<chain>` deep imports.
|
|
62
|
+
4. **Ignoring the persist-hydration gate.** Render UI before `useConnectedChains().status === 'ready'` and you get a flicker / stale-state.
|
|
63
|
+
5. **Forgetting WalletConnect setup for enterprise custody.** Default EVM discovery is EIP-6963 (browser extensions only). Fireblocks / Ledger / mobile-only wallets need the `walletConnect` field on the `EVM` slot.
|
|
64
|
+
|
|
65
|
+
# Verification
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pnpm tsc --noEmit # must exit clean
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Manually verify in browser:
|
|
72
|
+
- Connect / disconnect flows work for at least one wallet per enabled chain.
|
|
73
|
+
- Page reload preserves the connection (until `useXDisconnect`).
|
|
74
|
+
- `useWalletProvider({ xChainId: ChainKeys.X })` returns the chain-narrowed `IXxxWalletProvider`, ready to pass into `@sodax/sdk` calls (with `raw: false`).
|
|
75
|
+
|
|
76
|
+
# Related skills
|
|
77
|
+
|
|
78
|
+
- `sodax-wallet-sdk-react-migration` — port v1 wallet-sdk-react code (deleted `useXWagmiStore`, removed `rpcConfig`/`options`/`initialState` props, etc.).
|
|
79
|
+
- `sodax-dapp-kit-integration` — React hooks wrapping `@sodax/sdk`. Use `useWalletProvider` to bridge.
|
|
80
|
+
- `sodax-sdk-integration` — for any direct SDK call from the React app.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sodax-wallet-sdk-react-migration
|
|
3
|
+
description: 'Port EXISTING v1 `@sodax/wallet-sdk-react` consumer code to v2 — the store hook was removed from the public API (each `useXWagmiStore(state => state.X)` selector must be replaced with a public hook like `useXServices` / `useXService({ xChainType })` / `useXConnections` / `useXConnection({ xChainType })`; do NOT rename to `useXWalletStore` — the v2 barrel does not export it), hook signatures unified to single-object params, `SodaxWalletProvider` props reshaped (the old `rpcConfig` / `options` / `initialState` were removed in favor of a single `config: SodaxWalletConfig` object), and the chain-slot wrapper (`chains: { EVM, SOLANA, ... }`) was flattened so chain-type slots are top-level on `SodaxWalletConfig`. Use whenever a React dapp imports `useXWagmiStore`, calls hooks with positional args, or sets `rpcConfig` / `options` / `initialState` on `SodaxWalletProvider`. Triggers on "useXWagmiStore is gone", "SodaxWalletProvider props broke", "old wallet-sdk-react hooks", "upgrade @sodax/wallet-sdk-react".'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# When to use this skill
|
|
7
|
+
|
|
8
|
+
Pick this skill if the consumer has v1 wallet-sdk-react patterns. Grep signals:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
grep -rE 'useXWagmiStore|rpcConfig|initialState' src/
|
|
12
|
+
grep -rE 'SodaxWalletProvider.*(options|rpcConfig|initialState)' src/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The package name **did not change** between v1 and v2 — both versions publish as `@sodax/wallet-sdk-react`. Migration is detected by import surface, not by package name.
|
|
16
|
+
|
|
17
|
+
If a project has both v1 patterns AND a request for new features: **migration first, then integration**.
|
|
18
|
+
|
|
19
|
+
# Workflow
|
|
20
|
+
|
|
21
|
+
1. Read [`../../knowledge/wallet-sdk-react/migration/ai-rules.md`](../../knowledge/wallet-sdk-react/migration/ai-rules.md) — DO / DON'T + workflow + stop conditions.
|
|
22
|
+
2. Read [`../../knowledge/wallet-sdk-react/migration/breaking-changes.md`](../../knowledge/wallet-sdk-react/migration/breaking-changes.md) — full narrative of every v1 → v2 change.
|
|
23
|
+
3. Apply per-task recipes from [`../../knowledge/wallet-sdk-react/migration/recipes/`](../../knowledge/wallet-sdk-react/migration/recipes/) — `connect-button.md`, `multi-chain-modal.md`, `ssr-setup.md`, `walletconnect-migration.md`.
|
|
24
|
+
4. Use [`reference/`](../../knowledge/wallet-sdk-react/migration/reference/) lookups when symbols don't match — `imports.md`, `hooks.md`, `config.md`, `components.md`.
|
|
25
|
+
5. Verify with [`checklist.md`](../../knowledge/wallet-sdk-react/migration/checklist.md).
|
|
26
|
+
|
|
27
|
+
# Top mechanical changes
|
|
28
|
+
|
|
29
|
+
1. **`useXWagmiStore` removed from the public API.** v2 does **not** export the store hook at all — neither `useXWagmiStore` nor `useXWalletStore` is available from the package barrel. Replace each `useXWagmiStore(state => state.X)` selector with the matching public hook (`useXServices`, `useXService({ xChainType })`, `useXConnections`, `useXConnection({ xChainType })`, etc.). See [`../../knowledge/wallet-sdk-react/migration/reference/imports.md`](../../knowledge/wallet-sdk-react/migration/reference/imports.md) § "Store hook removed from the public API" for the full field-to-hook map and a STOP decision tree for selectors hitting v2-internal fields. The localStorage persistence key `'xwagmi-store'` is unchanged, so user connections survive the upgrade.
|
|
30
|
+
2. **Hook args unified to a single object.** v1 hooks took positional args; v2 hooks take `{ xChainType }` or `{ xChainId }` (mutually exclusive on `useXAccount` / `useWalletProvider`).
|
|
31
|
+
3. **`SodaxWalletProvider` props.** v1's `rpcConfig`, `options`, `initialState` props are removed. v2 takes one `config: SodaxWalletConfig` prop where top-level keys are `ChainType` slots (`EVM`, `SOLANA`, `SUI`, …). The old `chains: { EVM, SOLANA, ... }` wrapper is also gone — chain-type slots are now top-level.
|
|
32
|
+
4. **Per-chain entry shape varies.** EVM/SOLANA/SUI/ICON/NEAR use `{ rpcUrl?, defaults? }`; BITCOIN/STELLAR/INJECTIVE extend their `*RpcConfig` with `{ defaults? }`; STACKS accepts a preset name or `StacksNetworkLike & { defaults? }`.
|
|
33
|
+
|
|
34
|
+
# Stop conditions (defer to user)
|
|
35
|
+
|
|
36
|
+
| Signal | Why stop |
|
|
37
|
+
|---|---|
|
|
38
|
+
| User wants a chain family not in `integration/reference/chain-support.md` | Adding a new chain is a maintainer task. |
|
|
39
|
+
| User has a custom `XService` / `XConnector` subclass with non-trivial logic | Custom subclasses are a maintainer-only path. Confirm scope first. |
|
|
40
|
+
| User mixes v1 and v2 patterns in new code being written | Do migration first, then integration. |
|
|
41
|
+
|
|
42
|
+
# DO
|
|
43
|
+
|
|
44
|
+
- Replace every `useXWagmiStore(state => state.X)` selector with the matching v2 public hook (`useXServices`, `useXService({ xChainType })`, `useXConnections`, `useXConnection({ xChainType })`, …) — drop the `useXWagmiStore` import entirely. See `../../knowledge/wallet-sdk-react/migration/reference/imports.md` § "Store hook removed" for the field-to-hook map.
|
|
45
|
+
- Reshape `SodaxWalletProvider` props to the single `config` object.
|
|
46
|
+
- Move RPC config from old `rpcConfig` prop to per-chain `{ rpcUrl }` under the relevant slot.
|
|
47
|
+
- For EVM-only WalletConnect setup (Fireblocks etc.), add `walletConnect: { projectId: '…' }` to the EVM slot — see `recipes/walletconnect-migration.md`.
|
|
48
|
+
|
|
49
|
+
# DO NOT
|
|
50
|
+
|
|
51
|
+
- **Rename `useXWagmiStore` to `useXWalletStore`.** The v2 barrel does not export either name. The store implementation file is named `useXWalletStore.ts` internally, but the hook is private — every consumer call site must move to a public hook.
|
|
52
|
+
- Keep destructuring positional args from hooks — every v2 hook takes one object.
|
|
53
|
+
- Use `rpcConfig` / `options` / `initialState` props on `SodaxWalletProvider` — they're gone.
|
|
54
|
+
- Pass both `xChainId` and `xChainType` to `useXAccount` / `useWalletProvider` — mutually exclusive.
|
|
55
|
+
- Forget about persist hydration. `useConnectedChains().status === 'ready'` gates UI; render too early and you get flicker.
|
|
56
|
+
|
|
57
|
+
# Verification
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm tsc --noEmit # must exit clean
|
|
61
|
+
grep -rE 'useXWagmiStore|useXWalletStore' src/ # empty — v2 exports neither
|
|
62
|
+
grep -rE 'SodaxWalletProvider.*(rpcConfig|initialState)' src/ # empty
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Manual: connections still survive page reload (localStorage key `xwagmi-store` was preserved for backward compat).
|
|
66
|
+
|
|
67
|
+
# Related skills
|
|
68
|
+
|
|
69
|
+
- `sodax-wallet-sdk-react-integration` — write new code (use after migration completes).
|
|
70
|
+
- `sodax-dapp-kit-migration` — if the consumer also uses React hooks wrapping the SDK.
|
|
71
|
+
- `sodax-sdk-migration` — the SDK-level v1 → v2 work that often runs alongside this one.
|