@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.
Files changed (197) hide show
  1. package/.claude-plugin/plugin.json +13 -0
  2. package/AGENTS.md +81 -0
  3. package/LICENSE +21 -0
  4. package/README.md +49 -0
  5. package/knowledge/dapp-kit/AGENTS.md +50 -0
  6. package/knowledge/dapp-kit/integration/README.md +49 -0
  7. package/knowledge/dapp-kit/integration/ai-rules.md +80 -0
  8. package/knowledge/dapp-kit/integration/architecture.md +276 -0
  9. package/knowledge/dapp-kit/integration/features/README.md +29 -0
  10. package/knowledge/dapp-kit/integration/features/auxiliary-services.md +169 -0
  11. package/knowledge/dapp-kit/integration/features/bitcoin.md +87 -0
  12. package/knowledge/dapp-kit/integration/features/bridge.md +91 -0
  13. package/knowledge/dapp-kit/integration/features/dex.md +152 -0
  14. package/knowledge/dapp-kit/integration/features/migration.md +118 -0
  15. package/knowledge/dapp-kit/integration/features/money-market.md +144 -0
  16. package/knowledge/dapp-kit/integration/features/staking.md +123 -0
  17. package/knowledge/dapp-kit/integration/features/swap.md +101 -0
  18. package/knowledge/dapp-kit/integration/quickstart.md +188 -0
  19. package/knowledge/dapp-kit/integration/recipes/README.md +136 -0
  20. package/knowledge/dapp-kit/integration/recipes/backend-queries.md +157 -0
  21. package/knowledge/dapp-kit/integration/recipes/bitcoin.md +193 -0
  22. package/knowledge/dapp-kit/integration/recipes/bridge.md +174 -0
  23. package/knowledge/dapp-kit/integration/recipes/dex.md +204 -0
  24. package/knowledge/dapp-kit/integration/recipes/invalidations.md +115 -0
  25. package/knowledge/dapp-kit/integration/recipes/migration.md +212 -0
  26. package/knowledge/dapp-kit/integration/recipes/money-market.md +207 -0
  27. package/knowledge/dapp-kit/integration/recipes/mutation-error-handling.md +118 -0
  28. package/knowledge/dapp-kit/integration/recipes/observability.md +93 -0
  29. package/knowledge/dapp-kit/integration/recipes/setup.md +168 -0
  30. package/knowledge/dapp-kit/integration/recipes/staking.md +202 -0
  31. package/knowledge/dapp-kit/integration/recipes/swap.md +272 -0
  32. package/knowledge/dapp-kit/integration/recipes/wallet-connectivity.md +128 -0
  33. package/knowledge/dapp-kit/integration/reference/README.md +12 -0
  34. package/knowledge/dapp-kit/integration/reference/glossary.md +190 -0
  35. package/knowledge/dapp-kit/integration/reference/hooks-index.md +190 -0
  36. package/knowledge/dapp-kit/integration/reference/public-api.md +110 -0
  37. package/knowledge/dapp-kit/integration/reference/querykey-conventions.md +179 -0
  38. package/knowledge/dapp-kit/migration/README.md +60 -0
  39. package/knowledge/dapp-kit/migration/ai-rules.md +81 -0
  40. package/knowledge/dapp-kit/migration/breaking-changes/hook-signatures.md +233 -0
  41. package/knowledge/dapp-kit/migration/breaking-changes/querykey-conventions.md +108 -0
  42. package/knowledge/dapp-kit/migration/breaking-changes/result-handling.md +211 -0
  43. package/knowledge/dapp-kit/migration/breaking-changes/sdk-leakage.md +167 -0
  44. package/knowledge/dapp-kit/migration/checklist.md +89 -0
  45. package/knowledge/dapp-kit/migration/features/README.md +34 -0
  46. package/knowledge/dapp-kit/migration/features/auxiliary-services.md +114 -0
  47. package/knowledge/dapp-kit/migration/features/bitcoin.md +88 -0
  48. package/knowledge/dapp-kit/migration/features/bridge.md +160 -0
  49. package/knowledge/dapp-kit/migration/features/dex.md +101 -0
  50. package/knowledge/dapp-kit/migration/features/migration.md +120 -0
  51. package/knowledge/dapp-kit/migration/features/money-market.md +139 -0
  52. package/knowledge/dapp-kit/migration/features/staking.md +109 -0
  53. package/knowledge/dapp-kit/migration/features/swap.md +133 -0
  54. package/knowledge/dapp-kit/migration/recipes.md +185 -0
  55. package/knowledge/dapp-kit/migration/reference/README.md +15 -0
  56. package/knowledge/dapp-kit/migration/reference/deleted-hooks.md +110 -0
  57. package/knowledge/dapp-kit/migration/reference/error-shape-crosswalk.md +144 -0
  58. package/knowledge/dapp-kit/migration/reference/renamed-hooks.md +68 -0
  59. package/knowledge/sdk/AGENTS.md +41 -0
  60. package/knowledge/sdk/integration/README.md +41 -0
  61. package/knowledge/sdk/integration/ai-rules.md +75 -0
  62. package/knowledge/sdk/integration/architecture.md +533 -0
  63. package/knowledge/sdk/integration/chain-specifics.md +189 -0
  64. package/knowledge/sdk/integration/features/README.md +19 -0
  65. package/knowledge/sdk/integration/features/auxiliary-services.md +189 -0
  66. package/knowledge/sdk/integration/features/bridge.md +136 -0
  67. package/knowledge/sdk/integration/features/dex.md +182 -0
  68. package/knowledge/sdk/integration/features/icx-bnusd-baln.md +181 -0
  69. package/knowledge/sdk/integration/features/money-market.md +198 -0
  70. package/knowledge/sdk/integration/features/staking.md +166 -0
  71. package/knowledge/sdk/integration/features/swap.md +207 -0
  72. package/knowledge/sdk/integration/quickstart.md +213 -0
  73. package/knowledge/sdk/integration/recipes/README.md +21 -0
  74. package/knowledge/sdk/integration/recipes/backend-server-init.md +69 -0
  75. package/knowledge/sdk/integration/recipes/chain-key-narrowing.md +65 -0
  76. package/knowledge/sdk/integration/recipes/gas-estimation.md +33 -0
  77. package/knowledge/sdk/integration/recipes/initialize-sodax.md +78 -0
  78. package/knowledge/sdk/integration/recipes/raw-tx-flow.md +71 -0
  79. package/knowledge/sdk/integration/recipes/result-and-errors.md +104 -0
  80. package/knowledge/sdk/integration/recipes/signed-tx-flow.md +46 -0
  81. package/knowledge/sdk/integration/recipes/testing.md +101 -0
  82. package/knowledge/sdk/integration/reference/README.md +18 -0
  83. package/knowledge/sdk/integration/reference/chain-keys.md +67 -0
  84. package/knowledge/sdk/integration/reference/error-codes.md +165 -0
  85. package/knowledge/sdk/integration/reference/glossary.md +32 -0
  86. package/knowledge/sdk/integration/reference/public-api.md +138 -0
  87. package/knowledge/sdk/integration/reference/wallet-providers.md +62 -0
  88. package/knowledge/sdk/migration/README.md +58 -0
  89. package/knowledge/sdk/migration/ai-rules.md +80 -0
  90. package/knowledge/sdk/migration/breaking-changes/architecture.md +344 -0
  91. package/knowledge/sdk/migration/breaking-changes/result-and-errors.md +363 -0
  92. package/knowledge/sdk/migration/breaking-changes/type-system.md +341 -0
  93. package/knowledge/sdk/migration/checklist.md +67 -0
  94. package/knowledge/sdk/migration/features/README.md +35 -0
  95. package/knowledge/sdk/migration/features/auxiliary-services.md +156 -0
  96. package/knowledge/sdk/migration/features/bridge.md +128 -0
  97. package/knowledge/sdk/migration/features/dex.md +143 -0
  98. package/knowledge/sdk/migration/features/icx-bnusd-baln.md +151 -0
  99. package/knowledge/sdk/migration/features/money-market.md +214 -0
  100. package/knowledge/sdk/migration/features/staking.md +138 -0
  101. package/knowledge/sdk/migration/features/swap.md +198 -0
  102. package/knowledge/sdk/migration/recipes.md +350 -0
  103. package/knowledge/sdk/migration/reference/README.md +18 -0
  104. package/knowledge/sdk/migration/reference/deleted-exports.md +127 -0
  105. package/knowledge/sdk/migration/reference/error-code-crosswalk.md +104 -0
  106. package/knowledge/sdk/migration/reference/return-shapes.md +49 -0
  107. package/knowledge/sdk/migration/reference/sodax-config.md +145 -0
  108. package/knowledge/wallet-sdk-core/AGENTS.md +43 -0
  109. package/knowledge/wallet-sdk-core/integration/README.md +108 -0
  110. package/knowledge/wallet-sdk-core/integration/ai-rules.md +141 -0
  111. package/knowledge/wallet-sdk-core/integration/architecture.md +212 -0
  112. package/knowledge/wallet-sdk-core/integration/features/README.md +22 -0
  113. package/knowledge/wallet-sdk-core/integration/features/bitcoin.md +103 -0
  114. package/knowledge/wallet-sdk-core/integration/features/evm.md +102 -0
  115. package/knowledge/wallet-sdk-core/integration/features/icon.md +88 -0
  116. package/knowledge/wallet-sdk-core/integration/features/injective.md +92 -0
  117. package/knowledge/wallet-sdk-core/integration/features/near.md +92 -0
  118. package/knowledge/wallet-sdk-core/integration/features/solana.md +104 -0
  119. package/knowledge/wallet-sdk-core/integration/features/stacks.md +91 -0
  120. package/knowledge/wallet-sdk-core/integration/features/stellar.md +95 -0
  121. package/knowledge/wallet-sdk-core/integration/features/sui.md +96 -0
  122. package/knowledge/wallet-sdk-core/integration/quickstart.md +259 -0
  123. package/knowledge/wallet-sdk-core/integration/recipes/README.md +15 -0
  124. package/knowledge/wallet-sdk-core/integration/recipes/bridge-to-sdk.md +145 -0
  125. package/knowledge/wallet-sdk-core/integration/recipes/defaults-and-overrides.md +159 -0
  126. package/knowledge/wallet-sdk-core/integration/recipes/library-exports.md +129 -0
  127. package/knowledge/wallet-sdk-core/integration/recipes/setup-browser-extension.md +137 -0
  128. package/knowledge/wallet-sdk-core/integration/recipes/setup-private-key.md +115 -0
  129. package/knowledge/wallet-sdk-core/integration/recipes/sign-and-broadcast.md +201 -0
  130. package/knowledge/wallet-sdk-core/integration/recipes/testing.md +163 -0
  131. package/knowledge/wallet-sdk-core/integration/reference/README.md +13 -0
  132. package/knowledge/wallet-sdk-core/integration/reference/chain-support.md +65 -0
  133. package/knowledge/wallet-sdk-core/integration/reference/glossary.md +28 -0
  134. package/knowledge/wallet-sdk-core/integration/reference/interfaces.md +131 -0
  135. package/knowledge/wallet-sdk-core/integration/reference/provider-classes.md +54 -0
  136. package/knowledge/wallet-sdk-core/integration/reference/public-api.md +128 -0
  137. package/knowledge/wallet-sdk-core/migration/README.md +84 -0
  138. package/knowledge/wallet-sdk-core/migration/ai-rules.md +139 -0
  139. package/knowledge/wallet-sdk-core/migration/breaking-changes/README.md +14 -0
  140. package/knowledge/wallet-sdk-core/migration/breaking-changes/base-wallet-provider.md +52 -0
  141. package/knowledge/wallet-sdk-core/migration/breaking-changes/defaults-config.md +57 -0
  142. package/knowledge/wallet-sdk-core/migration/breaking-changes/folder-layout.md +99 -0
  143. package/knowledge/wallet-sdk-core/migration/breaking-changes/library-exports.md +58 -0
  144. package/knowledge/wallet-sdk-core/migration/checklist.md +62 -0
  145. package/knowledge/wallet-sdk-core/migration/recipes/README.md +12 -0
  146. package/knowledge/wallet-sdk-core/migration/recipes/adopt-defaults.md +84 -0
  147. package/knowledge/wallet-sdk-core/migration/recipes/adopt-library-exports.md +99 -0
  148. package/knowledge/wallet-sdk-core/migration/reference/README.md +12 -0
  149. package/knowledge/wallet-sdk-core/migration/reference/added-fields.md +71 -0
  150. package/knowledge/wallet-sdk-core/migration/reference/deleted-exports.md +35 -0
  151. package/knowledge/wallet-sdk-core/migration/reference/renamed-symbols.md +31 -0
  152. package/knowledge/wallet-sdk-core/migration/reference/return-shapes.md +23 -0
  153. package/knowledge/wallet-sdk-react/AGENTS.md +46 -0
  154. package/knowledge/wallet-sdk-react/integration/README.md +103 -0
  155. package/knowledge/wallet-sdk-react/integration/ai-rules.md +136 -0
  156. package/knowledge/wallet-sdk-react/integration/architecture.md +185 -0
  157. package/knowledge/wallet-sdk-react/integration/examples/01-minimal-evm.tsx +75 -0
  158. package/knowledge/wallet-sdk-react/integration/examples/02-multi-chain-modal.tsx +169 -0
  159. package/knowledge/wallet-sdk-react/integration/examples/03-nextjs-app-router.tsx +99 -0
  160. package/knowledge/wallet-sdk-react/integration/examples/04-walletconnect-setup.tsx +89 -0
  161. package/knowledge/wallet-sdk-react/integration/examples/README.md +29 -0
  162. package/knowledge/wallet-sdk-react/integration/recipes/batch-operations.md +224 -0
  163. package/knowledge/wallet-sdk-react/integration/recipes/bridge-to-sdk.md +165 -0
  164. package/knowledge/wallet-sdk-react/integration/recipes/chain-detection.md +259 -0
  165. package/knowledge/wallet-sdk-react/integration/recipes/connect-button.md +159 -0
  166. package/knowledge/wallet-sdk-react/integration/recipes/multi-chain-modal.md +203 -0
  167. package/knowledge/wallet-sdk-react/integration/recipes/setup.md +163 -0
  168. package/knowledge/wallet-sdk-react/integration/recipes/sign-message.md +138 -0
  169. package/knowledge/wallet-sdk-react/integration/recipes/sub-path-imports.md +97 -0
  170. package/knowledge/wallet-sdk-react/integration/recipes/switch-chain.md +144 -0
  171. package/knowledge/wallet-sdk-react/integration/recipes/walletconnect-setup.md +139 -0
  172. package/knowledge/wallet-sdk-react/integration/reference/api-surface.md +176 -0
  173. package/knowledge/wallet-sdk-react/integration/reference/chain-support.md +79 -0
  174. package/knowledge/wallet-sdk-react/integration/reference/connectors.md +75 -0
  175. package/knowledge/wallet-sdk-react/integration/reference/hooks.md +212 -0
  176. package/knowledge/wallet-sdk-react/integration/reference/wallet-brands.md +107 -0
  177. package/knowledge/wallet-sdk-react/migration/README.md +49 -0
  178. package/knowledge/wallet-sdk-react/migration/ai-rules.md +144 -0
  179. package/knowledge/wallet-sdk-react/migration/breaking-changes.md +310 -0
  180. package/knowledge/wallet-sdk-react/migration/checklist.md +159 -0
  181. package/knowledge/wallet-sdk-react/migration/recipes/connect-button.md +170 -0
  182. package/knowledge/wallet-sdk-react/migration/recipes/multi-chain-modal.md +245 -0
  183. package/knowledge/wallet-sdk-react/migration/recipes/ssr-setup.md +165 -0
  184. package/knowledge/wallet-sdk-react/migration/recipes/walletconnect-migration.md +170 -0
  185. package/knowledge/wallet-sdk-react/migration/reference/components.md +75 -0
  186. package/knowledge/wallet-sdk-react/migration/reference/config.md +339 -0
  187. package/knowledge/wallet-sdk-react/migration/reference/hooks.md +336 -0
  188. package/knowledge/wallet-sdk-react/migration/reference/imports.md +158 -0
  189. package/package.json +59 -0
  190. package/skills/sodax-dapp-kit-integration/SKILL.md +71 -0
  191. package/skills/sodax-dapp-kit-migration/SKILL.md +58 -0
  192. package/skills/sodax-sdk-integration/SKILL.md +66 -0
  193. package/skills/sodax-sdk-migration/SKILL.md +75 -0
  194. package/skills/sodax-wallet-sdk-core-integration/SKILL.md +55 -0
  195. package/skills/sodax-wallet-sdk-core-migration/SKILL.md +56 -0
  196. package/skills/sodax-wallet-sdk-react-integration/SKILL.md +80 -0
  197. package/skills/sodax-wallet-sdk-react-migration/SKILL.md +71 -0
@@ -0,0 +1,344 @@
1
+ # Architecture breaking changes — v1 → v2
2
+
3
+ The structural changes that reshaped the SDK at the service / runtime layer. Read after [`type-system.md`](type-system.md) — by the time you arrive here, your imports should compile and the rest is wiring.
4
+
5
+ The four load-bearing shifts:
6
+
7
+ 1. **Per-chain `*SpokeProvider` classes are deleted.** Routing is by chain key, dispatched internally by `SpokeService`.
8
+ 2. **Static lookup tables — `hubAssets` deleted; `moneyMarketSupportedTokens`, `SodaTokens`, `supportedSpokeChains` still exported as packaged defaults but should yield to `sodax.config.*` so backend updates take effect.** See § 2 below for the per-symbol status table.
9
+ 3. **Relay flow is centralised.** Two functions (`relayTxAndWaitPacket`, `submitTransaction`) and one mapper (`mapRelayFailure`) replace per-feature relay helpers.
10
+ 4. **Invariants and guards are unified.** `sodaxInvariant` + per-feature aliases (`swapInvariant`, `mmInvariant`, etc.) and `isSodaxError` / `isFeatureError` replace ad-hoc throws and module-specific type guards.
11
+
12
+ ---
13
+
14
+ ## 1. Spoke-provider deletion
15
+
16
+ ### What's gone
17
+
18
+ These v1 classes and their union are **deleted**:
19
+
20
+ - `EvmSpokeProvider`
21
+ - `SonicSpokeProvider`
22
+ - `SolanaSpokeProvider`
23
+ - `SuiSpokeProvider`
24
+ - `IconSpokeProvider`
25
+ - `InjectiveSpokeProvider`
26
+ - `StellarSpokeProvider`
27
+ - `StacksSpokeProvider`
28
+ - `BitcoinSpokeProvider`
29
+ - `NearSpokeProvider`
30
+ - The union type `SpokeProvider`
31
+ - The instance-test functions: `isEvmSpokeProvider`, `isSolanaSpokeProvider`, `isBitcoinSpokeProvider`, `isStellarSpokeProvider`, `isIconSpokeProvider`, `isSuiSpokeProvider`, `isInjectiveSpokeProvider`, `isStacksSpokeProvider`, `isNearSpokeProvider`, `isSonicSpokeProvider`.
32
+
33
+ ### What replaces them
34
+
35
+ A single internal router, `SpokeService`, owned by the `Sodax` instance. It holds one per-chain-family service (`EvmSpokeService`, `SolanaSpokeService`, …) and exposes `getSpokeService(chainKey)` for internal feature services. **Consumers never construct or hold a reference to a spoke service.** They pass `walletProvider` and a `srcChainKey` literal, and the SDK dispatches.
36
+
37
+ ### Migration mechanics
38
+
39
+ #### v1: construct + pass
40
+
41
+ ```ts
42
+ // v1
43
+ const evmWp = new EvmWalletProvider({ privateKey: '0x…', rpcUrl: '…' });
44
+ const sourceProvider = new EvmSpokeProvider({ walletProvider: evmWp, chainConfig: ARBITRUM_MAINNET_CONFIG });
45
+
46
+ await sodax.swaps.createIntent({ intentParams, spokeProvider: sourceProvider });
47
+ ```
48
+
49
+ #### v2: pass directly
50
+
51
+ ```ts
52
+ // v2
53
+ const evmWp = new EvmWalletProvider({ privateKey: '0x…', rpcUrl: '…' });
54
+
55
+ await sodax.swaps.createIntent({
56
+ params: { ...intentParams, srcChainKey: ChainKeys.ARBITRUM_MAINNET, srcAddress },
57
+ raw: false,
58
+ walletProvider: evmWp,
59
+ });
60
+ ```
61
+
62
+ The chain config is no longer something the consumer constructs — it's loaded by `ConfigService` from the backend (with a fallback to packaged defaults). The chain key on the payload tells the SDK which spoke service to route to.
63
+
64
+ ### Replacing instance tests with chain-key guards
65
+
66
+ ```diff
67
+ - if (isBitcoinSpokeProvider(provider)) { /* … */ }
68
+ + if (chainKey === ChainKeys.BITCOIN_MAINNET) { /* … */ }
69
+
70
+ - if (provider instanceof StellarSpokeProvider) { /* … */ }
71
+ + if (chainKey === ChainKeys.STELLAR_MAINNET) { /* … */ }
72
+
73
+ - if (isEvmSpokeProvider(provider)) { /* … */ }
74
+ + if (getChainType(chainKey) === 'EVM') { /* … */ }
75
+ ```
76
+
77
+ `getChainType(chainKey)` (from `@sodax/sdk`) returns `'EVM' | 'BITCOIN' | 'SOLANA' | 'STELLAR' | 'SUI' | 'ICON' | 'INJECTIVE' | 'STACKS' | 'NEAR'` and is the canonical chain-family discriminator.
78
+
79
+ Family-level helper guards (`isEvmChainKeyType`, `isBitcoinChainKeyType`, `isSolanaChainKeyType`, etc.) are also exported from `@sodax/sdk` for cases where you want a typed boolean.
80
+
81
+ ### Replacing reads from a spoke-provider instance
82
+
83
+ If your v1 code reached into a spoke provider for chain config or wallet info, those reads now have direct sources:
84
+
85
+ | v1 access | v2 source |
86
+ |---|---|
87
+ | `provider.chainConfig.chain.name` | `baseChainInfo[chainKey].name` (from `@sodax/sdk`) |
88
+ | `provider.chainConfig.chain.type` | `getChainType(chainKey)` |
89
+ | `provider.walletProvider.getWalletAddress()` | The wallet provider you passed in — call `walletProvider.getWalletAddress()` directly. |
90
+ | `provider.publicClient` (EVM only) | If you absolutely need it: `sodax.hubProvider.publicClient` exists for hub-side reads. Spoke-side public clients aren't surfaced — use the typed read methods on each feature service instead. |
91
+
92
+ ### Pitfall
93
+
94
+ If your project's v1 wrapper code instantiated `*SpokeProvider` classes, don't try to recreate that wrapper in v2 — it intentionally doesn't exist. Pass `walletProvider` directly into each SDK call payload.
95
+
96
+ ---
97
+
98
+ ## 2. ConfigService replaces static lookups
99
+
100
+ ### What's gone
101
+
102
+ | v1 global | v2 replacement |
103
+ |---|---|
104
+ | `hubAssets[chainId][address]` (vault lookup) | `token.vault` directly (added to `XToken` — see [`type-system.md`](type-system.md) § 4) |
105
+ | `hubAssets[chainId][address]` (hub-asset address) | `token.hubAsset` directly |
106
+ | `baseChainInfo[chain].id` | `baseChainInfo[chain].key` (field renamed) |
107
+
108
+ ### Static defaults — still exported, prefer the service API
109
+
110
+ These v1 names still ship through `@sodax/sdk` (re-exported from `@sodax/types`), so a v1 `import { ... } from '@sodax/sdk'` will not break. Once you call `await sodax.config.initialize()`, the dynamic config from the backend supersedes the packaged defaults — read through the service API to see runtime updates (new tokens, fee parameters). Without `initialize()`, both paths return the same packaged values.
111
+
112
+ | v1 export | v2 status | Preferred v2 API |
113
+ |---|---|---|
114
+ | `moneyMarketSupportedTokens[chainId]` | Still exported (`packages/types/src/moneyMarket/moneyMarket.ts`) | `sodax.moneyMarket.getSupportedTokensByChainId(chainKey)` |
115
+ | `Object.entries(moneyMarketSupportedTokens)` (walk pattern) | Const still exported | `sodax.moneyMarket.getSupportedTokens()` (returns `Record<SpokeChainKey, XToken[]>`) |
116
+ | `SodaTokens` registry (vault-validation) | Still exported (`packages/types/src/chains/tokens.ts`) | `sodax.config.getMoneyMarketReserveAssets()` or `sodax.moneyMarket.getSupportedReserves()` |
117
+ | `swapSupportedTokens[chainId]` (v1 had no `solverSupportedTokens`) | Still exported (`packages/types/src/swap/swap.ts`) | `sodax.config.getSupportedSwapTokensByChainId(chainKey)` |
118
+ | `getSupportedSolverTokens(chainId)` (free function) | Still exported (`packages/types/src/swap/swap.ts`) | `sodax.config.getSupportedSwapTokensByChainId(chainKey)` |
119
+ | `supportedSpokeChains` (`SpokeChainKey[]`) | Still exported (`packages/types/src/chains/chains.ts`) | `sodax.config.isValidSpokeChainKey(chainKey)` for validation, or read `sodaxConfig.chains` at module scope |
120
+
121
+ ### What replaces them
122
+
123
+ `ConfigService` is a stateful service owned by `Sodax`. It loads chain/token config from the backend API on `await sodax.config.initialize()` and falls back to packaged defaults from `@sodax/types` if the backend is unreachable. After init, every lookup goes through the service:
124
+
125
+ ```ts
126
+ const sodax = new Sodax(/* optional config override */);
127
+ await sodax.config.initialize(); // fetch from backend, fall back on failure
128
+
129
+ // Token lookups
130
+ const usdc = sodax.config.findSupportedTokenBySymbol(ChainKeys.ARBITRUM_MAINNET, 'USDC');
131
+ const supportedOnChain = sodax.config.getSupportedTokensPerChain();
132
+
133
+ // Hub-asset / vault lookups (when the XToken doesn't carry it)
134
+ const original = sodax.config.getOriginalAssetAddress(chainKey, hubAddress);
135
+
136
+ // Chain validity
137
+ const isValid = sodax.config.isValidSpokeChainKey(chainKey);
138
+ ```
139
+
140
+ Feature services (`SwapService`, `MoneyMarketService`, …) receive `ConfigService` via constructor injection and use it internally — consumer-side code reads the same data through `sodax.config.*` or feature-specific wrappers like `sodax.moneyMarket.getSupportedTokens()`.
141
+
142
+ ### Migration mechanics
143
+
144
+ ```diff
145
+ - import { hubAssets, moneyMarketSupportedTokens } from '@sodax/types';
146
+ - const vault = hubAssets[chainId]?.[token.address]?.vault;
147
+ + const vault = token.vault; // baked into XToken in v2
148
+
149
+ - const supplyTokens = moneyMarketSupportedTokens[chainId];
150
+ + const supplyTokens = sodax.moneyMarket.getSupportedTokensByChainId(chainKey);
151
+ ```
152
+
153
+ If your code walked `hubAssets` to find "is this address a known vault?":
154
+
155
+ ```diff
156
+ - const isKnownVault = !!hubAssets[chainId]?.[address];
157
+ + const isKnownVault = sodax.config.getMoneyMarketReserveAssets()
158
+ + .some(asset => asset.address === address);
159
+ ```
160
+
161
+ ### Pitfall
162
+
163
+ The `swaps` config field changed semantics. v1 put solver endpoints under `SodaxConfig.swaps`. v2 has two fields:
164
+
165
+ - `SodaxConfig.swaps`: `SwapsConfig` listing supported solver tokens per chain (data, not endpoints).
166
+ - `SodaxConfig.solver`: `{ intentsContract, solverApiEndpoint, protocolIntentsContract }` (the endpoint/contract config that v1 misplaced under `swaps`).
167
+
168
+ If you pass a config override to `new Sodax({ ... })`, put solver endpoints in `solver`, not `swaps`.
169
+
170
+ ---
171
+
172
+ ## 3. Relay flow and intent-relay reshape
173
+
174
+ ### What changed
175
+
176
+ v1 had per-feature relay helpers (each feature module had its own `*WaitForRelay()` or `relay*Tx()` function). v2 centralises this into `IntentRelayApiService` with two public entry points:
177
+
178
+ - `submitTransaction({ srcChainKey, txHash, payload })` — POSTs the spoke transaction to the relay submit endpoint and resolves the relay's first-stage acknowledgement.
179
+ - `relayTxAndWaitPacket({ srcChainKey, dstChainKey, txHash, payload, timeout? })` — runs `submitTransaction` and then polls until the destination packet reaches `executed`. Resolves with `{ srcTxHash, dstTxHash, packet }` on success.
180
+
181
+ Internally, every feature service now calls `relayTxAndWaitPacket` for the spoke→hub leg. Failures from this layer surface to consumers via `mapRelayFailure`.
182
+
183
+ ### `RELAY_ERROR_CODES` — the public relay-layer contract
184
+
185
+ The relay layer keeps a stable string vocabulary on its own errors (these are **not** `SodaxErrorCode` values — they are the lower-level relay codes that get mapped):
186
+
187
+ ```ts
188
+ type RelayCode =
189
+ | 'SUBMIT_TX_FAILED'
190
+ | 'RELAY_TIMEOUT'
191
+ | 'RELAY_POLLING_FAILED'
192
+ | 'UNKNOWN';
193
+ ```
194
+
195
+ When a relay-layer failure surfaces as a `SodaxError`, the original relay code lives on `error.context.relayCode`.
196
+
197
+ ### `mapRelayFailure` — single shared mapper
198
+
199
+ v1 had five per-feature mappers (each feature reshaped relay errors into its own typed-error union). v2 collapses them into one:
200
+
201
+ ```ts
202
+ import { mapRelayFailure } from '@sodax/sdk';
203
+
204
+ const mapped = mapRelayFailure(error, {
205
+ feature: 'swap',
206
+ action: 'createIntent',
207
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
208
+ dstChainKey: ChainKeys.STELLAR_MAINNET,
209
+ // phase: 'destinationExecution', // optional override; used by migration's bnUSD secondary watcher
210
+ });
211
+ ```
212
+
213
+ `mapped` is a `SodaxError<C>` with code in {`'TX_SUBMIT_FAILED'`, `'RELAY_TIMEOUT'`, `'RELAY_FAILED'`, `'EXECUTION_FAILED'`} and `feature` set to the requested value. Consumers don't usually call `mapRelayFailure` directly — every feature service does this internally — but it's exported for custom orchestration code.
214
+
215
+ ### Migration mechanics for consumers
216
+
217
+ If your v1 code wrapped a feature call to handle relay failures:
218
+
219
+ ```diff
220
+ - try {
221
+ - const tx = await sodax.swaps.createIntent({ intentParams, spokeProvider });
222
+ - } catch (e) {
223
+ - if (e instanceof RelayError && e.code === 'RELAY_TIMEOUT') { /* … */ }
224
+ - else if (e instanceof IntentError) { /* … */ }
225
+ - }
226
+
227
+ + const result = await sodax.swaps.createIntent({ params, raw: false, walletProvider });
228
+ + if (!result.ok) {
229
+ + if (isSodaxError(result.error)) {
230
+ + if (result.error.code === 'RELAY_TIMEOUT') { /* … */ }
231
+ + else if (result.error.feature === 'swap' && result.error.code === 'INTENT_CREATION_FAILED') { /* … */ }
232
+ + }
233
+ + }
234
+ ```
235
+
236
+ The full v1 ↔ v2 code crosswalk is in [`result-and-errors.md`](result-and-errors.md) § "v1 ↔ v2 code crosswalk".
237
+
238
+ ### Pitfall
239
+
240
+ `relayTxAndWaitPacket` is the public name; v1 had `submitTxAndWaitForPacket` and similar variants. If your v1 code imported or wrapped one of those names, the export is gone. Use `relayTxAndWaitPacket` directly, or call the feature service's higher-level method (`sodax.swaps.swap(...)`, `sodax.bridge.bridge(...)`) which wraps it.
241
+
242
+ ---
243
+
244
+ ## 4. Invariants and guards
245
+
246
+ ### What's gone
247
+
248
+ - Per-module typed error unions and their type-guards: `MoneyMarketError`, `IntentError`, `StakingError`, `BridgeError`, `MigrationError`, `AssetServiceError`, `ConcentratedLiquidityError`, `RelayError`, plus 5 partner error types and their `is<Module>Error()` helpers. (Structural deletion — see [`type-system.md`](type-system.md) § 10.)
249
+ - Ad-hoc precondition throws (`if (!x) throw new Error('Amount must be greater than 0')`).
250
+
251
+ ### What replaces them
252
+
253
+ #### `sodaxInvariant` + per-feature aliases
254
+
255
+ Every feature has a 1-line alias for `sodaxInvariant` that pre-fills the `feature` field:
256
+
257
+ ```ts
258
+ // Internal SDK helpers (also exported for custom code)
259
+ import {
260
+ sodaxInvariant,
261
+ swapInvariant,
262
+ mmInvariant,
263
+ bridgeInvariant,
264
+ stakingInvariant,
265
+ migrationInvariant,
266
+ dexInvariant,
267
+ partnerInvariant,
268
+ recoveryInvariant,
269
+ } from '@sodax/sdk';
270
+
271
+ mmInvariant(amount > 0n, 'Amount must be greater than 0');
272
+ // Throws SodaxError<'VALIDATION_FAILED'> with feature: 'moneyMarket' and the message above.
273
+ ```
274
+
275
+ In your own consumer code, if you have your own preconditions, use `sodaxInvariant` directly (you pick the feature):
276
+
277
+ ```ts
278
+ sodaxInvariant(
279
+ isValidSpokeChainKey(chainKey),
280
+ 'Unsupported source chain',
281
+ { feature: 'swap', context: { reason: 'unsupportedChain', srcChainKey: chainKey } },
282
+ );
283
+ ```
284
+
285
+ #### `isSodaxError` and `isFeatureError`
286
+
287
+ ```ts
288
+ import { isSodaxError, isFeatureError } from '@sodax/sdk';
289
+
290
+ if (isSodaxError(e)) {
291
+ // e: SodaxError<SodaxErrorCode>
292
+ }
293
+
294
+ const isMmError = isFeatureError('moneyMarket');
295
+ if (isMmError(e)) {
296
+ // e: SodaxError<SodaxErrorCode> with feature: 'moneyMarket'
297
+ }
298
+ ```
299
+
300
+ `isFeatureError` is a guard factory. Use it once at module top and then as a normal type guard:
301
+
302
+ ```ts
303
+ const isSwapError = isFeatureError('swap');
304
+ const isStakingError = isFeatureError('staking');
305
+ ```
306
+
307
+ #### `isCodeMember` for per-method narrowing
308
+
309
+ When a public method declares a narrow code union (e.g. `useSupplyError`), there's a corresponding `isUseSupplyError` guard you can apply to discriminate within a single feature:
310
+
311
+ ```ts
312
+ // Inside per-feature errors.ts files (referenced by per-method types)
313
+ const SUPPLY_CODES: ReadonlySet<SupplyErrorCode> = new Set([
314
+ 'VALIDATION_FAILED',
315
+ 'INTENT_CREATION_FAILED',
316
+ 'EXECUTION_FAILED',
317
+ 'TX_VERIFICATION_FAILED',
318
+ 'RELAY_TIMEOUT',
319
+ // …
320
+ ]);
321
+ const isSupplyError = isCodeMember(SUPPLY_CODES);
322
+ ```
323
+
324
+ You can build your own `isCodeMember(codes)` guards from `@sodax/sdk` exports.
325
+
326
+ ### Pitfall
327
+
328
+ Don't try to recreate a typed-error union by aliasing `SodaxError` per feature — it defeats the design. The whole point of v2's error model is that one class with `(feature, code)` discrimination covers every case, and your switch statements use those two fields. If your v1 code had `try { … } catch (e: MoneyMarketError) { ... }`, replace the catch with `if (isSodaxError(e) && e.feature === 'moneyMarket')`.
329
+
330
+ ---
331
+
332
+
333
+ The two reference tables that used to live as Appendix A (deleted exports) and Appendix B (`SodaxConfig` reshape) have moved into `../reference/`:
334
+
335
+ - [`../reference/deleted-exports.md`](../reference/deleted-exports.md) — every v1 symbol removed from `@sodax/sdk` and `@sodax/types`, with its v2 replacement.
336
+ - [`../reference/sodax-config.md`](../reference/sodax-config.md) — `SodaxConfig` constructor reshape (`swaps` vs `solver`, `rpcConfig` keying, `hubProviderConfig` → `hubConfig`).
337
+
338
+ ## Cross-references
339
+
340
+ - Type-level renames and shape changes: [`type-system.md`](type-system.md).
341
+ - Result/error model semantics: [`result-and-errors.md`](result-and-errors.md).
342
+ - v2 design context (architectural concepts): [`../../integration/architecture.md`](../../integration/architecture.md).
343
+ - ConfigService usage patterns: [`../../integration/recipes/`](../../integration/recipes/) § "Initialize Sodax".
344
+ - Public API surface: [`../../integration/reference/`](../../integration/reference/) § "Public API surface".