@sodax/skills 2.0.0-rc.10

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 (202) hide show
  1. package/.claude-plugin/plugin.json +18 -0
  2. package/AGENTS.md +83 -0
  3. package/LICENSE +21 -0
  4. package/README.md +49 -0
  5. package/package.json +58 -0
  6. package/skills/sodax-dapp-kit/SKILL.md +129 -0
  7. package/skills/sodax-dapp-kit/integration/knowledge/README.md +49 -0
  8. package/skills/sodax-dapp-kit/integration/knowledge/ai-rules.md +80 -0
  9. package/skills/sodax-dapp-kit/integration/knowledge/architecture.md +276 -0
  10. package/skills/sodax-dapp-kit/integration/knowledge/features/README.md +29 -0
  11. package/skills/sodax-dapp-kit/integration/knowledge/features/auxiliary-services.md +169 -0
  12. package/skills/sodax-dapp-kit/integration/knowledge/features/bitcoin.md +87 -0
  13. package/skills/sodax-dapp-kit/integration/knowledge/features/bridge.md +91 -0
  14. package/skills/sodax-dapp-kit/integration/knowledge/features/dex.md +152 -0
  15. package/skills/sodax-dapp-kit/integration/knowledge/features/migration.md +118 -0
  16. package/skills/sodax-dapp-kit/integration/knowledge/features/money-market.md +144 -0
  17. package/skills/sodax-dapp-kit/integration/knowledge/features/staking.md +123 -0
  18. package/skills/sodax-dapp-kit/integration/knowledge/features/swap.md +101 -0
  19. package/skills/sodax-dapp-kit/integration/knowledge/quickstart.md +188 -0
  20. package/skills/sodax-dapp-kit/integration/knowledge/recipes/README.md +136 -0
  21. package/skills/sodax-dapp-kit/integration/knowledge/recipes/backend-queries.md +157 -0
  22. package/skills/sodax-dapp-kit/integration/knowledge/recipes/bitcoin.md +193 -0
  23. package/skills/sodax-dapp-kit/integration/knowledge/recipes/bridge.md +174 -0
  24. package/skills/sodax-dapp-kit/integration/knowledge/recipes/dex.md +204 -0
  25. package/skills/sodax-dapp-kit/integration/knowledge/recipes/invalidations.md +115 -0
  26. package/skills/sodax-dapp-kit/integration/knowledge/recipes/migration.md +212 -0
  27. package/skills/sodax-dapp-kit/integration/knowledge/recipes/money-market.md +207 -0
  28. package/skills/sodax-dapp-kit/integration/knowledge/recipes/mutation-error-handling.md +118 -0
  29. package/skills/sodax-dapp-kit/integration/knowledge/recipes/observability.md +93 -0
  30. package/skills/sodax-dapp-kit/integration/knowledge/recipes/setup.md +168 -0
  31. package/skills/sodax-dapp-kit/integration/knowledge/recipes/staking.md +202 -0
  32. package/skills/sodax-dapp-kit/integration/knowledge/recipes/swap.md +272 -0
  33. package/skills/sodax-dapp-kit/integration/knowledge/recipes/wallet-connectivity.md +128 -0
  34. package/skills/sodax-dapp-kit/integration/knowledge/reference/README.md +12 -0
  35. package/skills/sodax-dapp-kit/integration/knowledge/reference/glossary.md +190 -0
  36. package/skills/sodax-dapp-kit/integration/knowledge/reference/hooks-index.md +190 -0
  37. package/skills/sodax-dapp-kit/integration/knowledge/reference/public-api.md +110 -0
  38. package/skills/sodax-dapp-kit/integration/knowledge/reference/querykey-conventions.md +179 -0
  39. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/README.md +60 -0
  40. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/ai-rules.md +81 -0
  41. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/hook-signatures.md +233 -0
  42. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/querykey-conventions.md +108 -0
  43. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/result-handling.md +211 -0
  44. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/sdk-leakage.md +167 -0
  45. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/checklist.md +89 -0
  46. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/README.md +34 -0
  47. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/auxiliary-services.md +114 -0
  48. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/bitcoin.md +88 -0
  49. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/bridge.md +160 -0
  50. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/dex.md +101 -0
  51. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/migration.md +120 -0
  52. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/money-market.md +139 -0
  53. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/staking.md +109 -0
  54. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/swap.md +133 -0
  55. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/recipes.md +185 -0
  56. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/README.md +15 -0
  57. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/deleted-hooks.md +110 -0
  58. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/error-shape-crosswalk.md +144 -0
  59. package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/renamed-hooks.md +68 -0
  60. package/skills/sodax-sdk/SKILL.md +140 -0
  61. package/skills/sodax-sdk/backend-api/SKILL.md +52 -0
  62. package/skills/sodax-sdk/bridge/SKILL.md +49 -0
  63. package/skills/sodax-sdk/dex/SKILL.md +50 -0
  64. package/skills/sodax-sdk/integration/knowledge/README.md +43 -0
  65. package/skills/sodax-sdk/integration/knowledge/ai-rules.md +75 -0
  66. package/skills/sodax-sdk/integration/knowledge/architecture.md +517 -0
  67. package/skills/sodax-sdk/integration/knowledge/chain-specifics.md +189 -0
  68. package/skills/sodax-sdk/integration/knowledge/features/README.md +21 -0
  69. package/skills/sodax-sdk/integration/knowledge/features/backend-api.md +81 -0
  70. package/skills/sodax-sdk/integration/knowledge/features/bridge.md +172 -0
  71. package/skills/sodax-sdk/integration/knowledge/features/dex.md +182 -0
  72. package/skills/sodax-sdk/integration/knowledge/features/migration.md +181 -0
  73. package/skills/sodax-sdk/integration/knowledge/features/money-market.md +198 -0
  74. package/skills/sodax-sdk/integration/knowledge/features/partner.md +63 -0
  75. package/skills/sodax-sdk/integration/knowledge/features/recovery.md +50 -0
  76. package/skills/sodax-sdk/integration/knowledge/features/staking.md +171 -0
  77. package/skills/sodax-sdk/integration/knowledge/features/swap.md +273 -0
  78. package/skills/sodax-sdk/integration/knowledge/quickstart.md +213 -0
  79. package/skills/sodax-sdk/integration/knowledge/recipes/README.md +21 -0
  80. package/skills/sodax-sdk/integration/knowledge/recipes/backend-server-init.md +69 -0
  81. package/skills/sodax-sdk/integration/knowledge/recipes/chain-key-narrowing.md +65 -0
  82. package/skills/sodax-sdk/integration/knowledge/recipes/gas-estimation.md +33 -0
  83. package/skills/sodax-sdk/integration/knowledge/recipes/initialize-sodax.md +78 -0
  84. package/skills/sodax-sdk/integration/knowledge/recipes/raw-tx-flow.md +71 -0
  85. package/skills/sodax-sdk/integration/knowledge/recipes/result-and-errors.md +104 -0
  86. package/skills/sodax-sdk/integration/knowledge/recipes/signed-tx-flow.md +46 -0
  87. package/skills/sodax-sdk/integration/knowledge/recipes/testing.md +101 -0
  88. package/skills/sodax-sdk/integration/knowledge/reference/README.md +18 -0
  89. package/skills/sodax-sdk/integration/knowledge/reference/chain-keys.md +67 -0
  90. package/skills/sodax-sdk/integration/knowledge/reference/error-codes.md +165 -0
  91. package/skills/sodax-sdk/integration/knowledge/reference/glossary.md +32 -0
  92. package/skills/sodax-sdk/integration/knowledge/reference/public-api.md +138 -0
  93. package/skills/sodax-sdk/integration/knowledge/reference/wallet-providers.md +62 -0
  94. package/skills/sodax-sdk/migration/SKILL.md +65 -0
  95. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/README.md +58 -0
  96. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/ai-rules.md +76 -0
  97. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/breaking-changes/architecture.md +344 -0
  98. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/breaking-changes/result-and-errors.md +363 -0
  99. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/breaking-changes/type-system.md +341 -0
  100. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/checklist.md +67 -0
  101. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/README.md +37 -0
  102. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/backend-api.md +92 -0
  103. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/bridge.md +128 -0
  104. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/dex.md +143 -0
  105. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/migration.md +151 -0
  106. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/money-market.md +214 -0
  107. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/partner.md +59 -0
  108. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/recovery.md +35 -0
  109. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/staking.md +143 -0
  110. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/swap.md +198 -0
  111. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/recipes.md +350 -0
  112. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/README.md +18 -0
  113. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/deleted-exports.md +127 -0
  114. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/error-code-crosswalk.md +104 -0
  115. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/return-shapes.md +49 -0
  116. package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/sodax-config.md +145 -0
  117. package/skills/sodax-sdk/money-market/SKILL.md +52 -0
  118. package/skills/sodax-sdk/partner/SKILL.md +51 -0
  119. package/skills/sodax-sdk/recovery/SKILL.md +49 -0
  120. package/skills/sodax-sdk/staking/SKILL.md +49 -0
  121. package/skills/sodax-sdk/swap/SKILL.md +67 -0
  122. package/skills/sodax-wallet-sdk-core/SKILL.md +114 -0
  123. package/skills/sodax-wallet-sdk-core/integration/knowledge/README.md +108 -0
  124. package/skills/sodax-wallet-sdk-core/integration/knowledge/ai-rules.md +141 -0
  125. package/skills/sodax-wallet-sdk-core/integration/knowledge/architecture.md +212 -0
  126. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/README.md +22 -0
  127. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/bitcoin.md +103 -0
  128. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/evm.md +102 -0
  129. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/icon.md +88 -0
  130. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/injective.md +92 -0
  131. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/near.md +92 -0
  132. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/solana.md +104 -0
  133. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/stacks.md +91 -0
  134. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/stellar.md +95 -0
  135. package/skills/sodax-wallet-sdk-core/integration/knowledge/features/sui.md +96 -0
  136. package/skills/sodax-wallet-sdk-core/integration/knowledge/quickstart.md +259 -0
  137. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/README.md +15 -0
  138. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/bridge-to-sdk.md +145 -0
  139. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/defaults-and-overrides.md +159 -0
  140. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/library-exports.md +129 -0
  141. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/setup-browser-extension.md +137 -0
  142. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/setup-private-key.md +115 -0
  143. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/sign-and-broadcast.md +201 -0
  144. package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/testing.md +163 -0
  145. package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/README.md +13 -0
  146. package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/chain-support.md +65 -0
  147. package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/glossary.md +28 -0
  148. package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/interfaces.md +131 -0
  149. package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/provider-classes.md +54 -0
  150. package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/public-api.md +128 -0
  151. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/README.md +84 -0
  152. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/ai-rules.md +139 -0
  153. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/README.md +14 -0
  154. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/base-wallet-provider.md +52 -0
  155. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/defaults-config.md +57 -0
  156. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/folder-layout.md +99 -0
  157. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/library-exports.md +58 -0
  158. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/checklist.md +62 -0
  159. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/recipes/README.md +12 -0
  160. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/recipes/adopt-defaults.md +84 -0
  161. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/recipes/adopt-library-exports.md +99 -0
  162. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/README.md +12 -0
  163. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/added-fields.md +71 -0
  164. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/deleted-exports.md +35 -0
  165. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/renamed-symbols.md +31 -0
  166. package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/return-shapes.md +23 -0
  167. package/skills/sodax-wallet-sdk-react/SKILL.md +154 -0
  168. package/skills/sodax-wallet-sdk-react/integration/knowledge/README.md +103 -0
  169. package/skills/sodax-wallet-sdk-react/integration/knowledge/ai-rules.md +136 -0
  170. package/skills/sodax-wallet-sdk-react/integration/knowledge/architecture.md +185 -0
  171. package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/01-minimal-evm.tsx +75 -0
  172. package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/02-multi-chain-modal.tsx +169 -0
  173. package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/03-nextjs-app-router.tsx +99 -0
  174. package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/04-walletconnect-setup.tsx +89 -0
  175. package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/README.md +29 -0
  176. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/batch-operations.md +224 -0
  177. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/bridge-to-sdk.md +165 -0
  178. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/chain-detection.md +259 -0
  179. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/connect-button.md +159 -0
  180. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/multi-chain-modal.md +203 -0
  181. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/setup.md +163 -0
  182. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/sign-message.md +138 -0
  183. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/sub-path-imports.md +97 -0
  184. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/switch-chain.md +144 -0
  185. package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/walletconnect-setup.md +139 -0
  186. package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/api-surface.md +176 -0
  187. package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/chain-support.md +79 -0
  188. package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/connectors.md +75 -0
  189. package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/hooks.md +212 -0
  190. package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/wallet-brands.md +107 -0
  191. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/README.md +49 -0
  192. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/ai-rules.md +144 -0
  193. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/breaking-changes.md +310 -0
  194. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/checklist.md +159 -0
  195. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/connect-button.md +170 -0
  196. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/multi-chain-modal.md +245 -0
  197. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/ssr-setup.md +165 -0
  198. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/walletconnect-migration.md +170 -0
  199. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/components.md +75 -0
  200. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/config.md +339 -0
  201. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/hooks.md +336 -0
  202. package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/imports.md +158 -0
@@ -0,0 +1,273 @@
1
+ # Swap — `SwapService`
2
+
3
+ Intent-based swaps via a solver. Cross-chain by default.
4
+
5
+ Access: `sodax.swaps`. Service class: `SwapService`. Feature tag for errors: `'swap'`.
6
+
7
+ ## How it works
8
+
9
+ 1. **Build an intent** — `createIntent` signs a spoke transaction encoding the swap declaration.
10
+ 2. **Relay to hub** — handled internally; the spoke tx propagates to Sonic.
11
+ 3. **Solver fulfillment** — an off-chain solver picks up the intent and fills it on the destination chain.
12
+ 4. **Post-execution settlement** — `postExecution` finalizes the user's side once the solver completes.
13
+
14
+ Two execution paths:
15
+
16
+ - **`swap`** — full flow in one call. Wraps `createIntent` + relay + `postExecution`. Returns `SwapResponse` on success.
17
+ - **`createIntent` + backend submit** — break it apart for custom relay handling. `createIntent` returns `{ tx, intent, relayData }`; submit `relayData.payload` to the backend swap-tx endpoint via `BackendApiService.submitSwapTx`.
18
+
19
+ ## Public methods
20
+
21
+ ```ts
22
+ sodax.swaps.swap<K extends SpokeChainKey>(action: SwapActionParams<K, false>): Promise<Result<SwapResponse, SodaxError>>;
23
+
24
+ sodax.swaps.getQuote(payload: SolverIntentQuoteRequest): Promise<Result<SolverIntentQuoteResponse, SolverErrorResponse>>;
25
+ // Preview the output amount before signing — useful for UX confirmations / bot previews.
26
+
27
+ sodax.swaps.createIntent<K extends SpokeChainKey, Raw extends boolean>(
28
+ action: SwapActionParams<K, Raw>,
29
+ ): Promise<Result<CreateIntentResult<K, Raw>, SodaxError>>;
30
+
31
+ sodax.swaps.postExecution(
32
+ args: { intent, relayData },
33
+ ): Promise<Result<SwapResponse, SodaxError>>;
34
+
35
+ sodax.swaps.createLimitOrder<K, Raw>(
36
+ action: LimitOrderActionParams<K, Raw>,
37
+ ): Promise<Result<CreateIntentResult<K, Raw>, SodaxError>>;
38
+
39
+ sodax.swaps.createLimitOrderIntent<K, Raw>(/* same as createIntent shape with limit-order params */): /* same return */;
40
+
41
+ sodax.swaps.cancelIntent<K, Raw>(/* … */): Promise<Result<TxReturnType<K, Raw>, SodaxError>>;
42
+ sodax.swaps.cancelLimitOrder<K, Raw>(/* … */): Promise<Result<TxReturnType<K, Raw>, SodaxError>>;
43
+
44
+ sodax.swaps.approve<K, Raw>(/* … */): Promise<Result<TxReturnType<K, Raw>, SodaxError>>;
45
+ sodax.swaps.isAllowanceValid<K, Raw>(/* … */): Promise<Result<boolean, SodaxError>>;
46
+ ```
47
+
48
+ ## Action params shape
49
+
50
+ Generic `K extends SpokeChainKey` carries the literal source chain key. `WalletProviderSlot<K, Raw>` is intersected:
51
+
52
+ ```ts
53
+ type SwapActionParams<K extends SpokeChainKey, Raw extends boolean> = {
54
+ params: CreateIntentParams<K>;
55
+ skipSimulation?: boolean;
56
+ timeout?: number;
57
+ fee?: PartnerFee;
58
+ } & WalletProviderSlot<K, Raw>;
59
+ ```
60
+
61
+ `CreateIntentParams<K>`:
62
+
63
+ ```ts
64
+ type CreateIntentParams<K extends SpokeChainKey> = {
65
+ srcChainKey: K;
66
+ dstChainKey: SpokeChainKey;
67
+ srcAddress: GetAddressType<K>;
68
+ dstAddress: string; // chain-specific format on the destination side
69
+ inputToken: XToken; // must have chainKey === srcChainKey
70
+ outputToken: XToken; // must have chainKey === dstChainKey
71
+ inputAmount: bigint;
72
+ minOutputAmount: bigint;
73
+ deadline: bigint; // unix seconds
74
+ allowPartialFill: boolean;
75
+ solver: `0x${string}`; // solver address; '0x0…0' for default
76
+ data: `0x${string}`; // arbitrary calldata; '0x' for default
77
+ };
78
+ ```
79
+
80
+ `CreateLimitOrderParams<K>` is `Omit<CreateIntentParams<K>, 'deadline'>` (limit orders have a different expiry mechanism).
81
+
82
+ ## Common call shapes
83
+
84
+ ### Quote before signing (preview / confirmation UX)
85
+
86
+ `getQuote` is a read-only call to the solver — no wallet, no signing. Use it for trading-bot previews, UI confirmations, or to set `minOutputAmount` based on a fresh quote.
87
+
88
+ ```ts
89
+ const quote = await sodax.swaps.getQuote({
90
+ token_src: USDC_ARBITRUM.address,
91
+ token_src_blockchain_id: ChainKeys.ARBITRUM_MAINNET,
92
+ token_dst: XLM.address,
93
+ token_dst_blockchain_id: ChainKeys.STELLAR_MAINNET,
94
+ amount: 1_000_000n, // 1 USDC (6 decimals)
95
+ quote_type: 'exact_input', // currently the only supported type
96
+ });
97
+
98
+ if (!quote.ok) {
99
+ // quote.error: SolverErrorResponse — different shape from SodaxError;
100
+ // see `error.detail.code` and `error.detail.message`.
101
+ return;
102
+ }
103
+
104
+ const { quoted_amount } = quote.value; // bigint output amount in dst-token units
105
+ // Use `quoted_amount` (with a slippage buffer) as `minOutputAmount` on the swap call.
106
+ ```
107
+
108
+ `SolverIntentQuoteRequest` uses snake_case fields and **`token_src`/`token_dst` are token addresses** (strings), not full `XToken` objects. `quote_type` is currently `'exact_input'` only.
109
+
110
+ ### Signed swap (full flow)
111
+
112
+ `inputToken` / `outputToken` are full `XToken` objects (with `chainKey`, `address`, `decimals`, `symbol`). Look them up from config — do **not** hand-construct:
113
+
114
+ ```ts
115
+ const inputToken = sodax.config.findSupportedTokenBySymbol(ChainKeys.ARBITRUM_MAINNET, 'USDC');
116
+ const outputToken = sodax.config.findSupportedTokenBySymbol(ChainKeys.STELLAR_MAINNET, 'XLM');
117
+ if (!inputToken || !outputToken) throw new Error('Token missing from config — did you call sodax.config.initialize()?');
118
+
119
+ const result = await sodax.swaps.swap({
120
+ params: {
121
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
122
+ dstChainKey: ChainKeys.STELLAR_MAINNET,
123
+ srcAddress: '0x…',
124
+ dstAddress: 'G…',
125
+ inputToken, // XToken; chainKey === srcChainKey
126
+ outputToken, // XToken; chainKey === dstChainKey
127
+ inputAmount: parseUnits('1', inputToken.decimals), // 1 USDC
128
+ minOutputAmount: parseUnits('50', outputToken.decimals), // 50 XLM floor
129
+ deadline: BigInt(Math.floor(Date.now() / 1000) + 300),
130
+ allowPartialFill: false,
131
+ solver: '0x0000000000000000000000000000000000000000',
132
+ data: '0x',
133
+ },
134
+ raw: false,
135
+ walletProvider: evmWp,
136
+ });
137
+
138
+ if (!result.ok) return;
139
+ const { solverExecutionResponse, intent, intentDeliveryInfo } = result.value;
140
+ // SwapResponse: { solverExecutionResponse, intent, intentDeliveryInfo }
141
+ // Use `intentDeliveryInfo` for spoke / hub tx hashes; `solverExecutionResponse` for solver-side outcome.
142
+ ```
143
+
144
+ ### Hub as source (Sonic → spoke)
145
+
146
+ `srcChainKey` accepts `ChainKeys.SONIC_MAINNET` too — same `WalletProviderSlot<K, Raw>` shape, same `Result<T>` return. The SDK routes through the user's hub-wallet abstraction instead of a spoke deposit. The token lookup pattern is identical; only the chain key changes:
147
+
148
+ ```ts
149
+ const sodaSonic = sodax.config.findSupportedTokenBySymbol(ChainKeys.SONIC_MAINNET, 'SODA');
150
+ const sodaBase = sodax.config.findSupportedTokenBySymbol(ChainKeys.BASE_MAINNET, 'SODA');
151
+ if (!sodaSonic || !sodaBase) throw new Error('SODA missing from config');
152
+
153
+ const result = await sodax.swaps.swap({
154
+ params: {
155
+ srcChainKey: ChainKeys.SONIC_MAINNET,
156
+ dstChainKey: ChainKeys.BASE_MAINNET,
157
+ srcAddress: (await evmWp.getWalletAddress()) as `0x${string}`,
158
+ dstAddress: recipientOnBase,
159
+ inputToken: sodaSonic,
160
+ outputToken: sodaBase,
161
+ inputAmount: parseUnits('1', sodaSonic.decimals),
162
+ minOutputAmount: parseUnits('0.99', sodaBase.decimals), // tighten with getQuote() in production
163
+ deadline: BigInt(Math.floor(Date.now() / 1000) + 300),
164
+ allowPartialFill: false,
165
+ solver: '0x0000000000000000000000000000000000000000',
166
+ data: '0x',
167
+ },
168
+ raw: false,
169
+ walletProvider: evmWp,
170
+ });
171
+ ```
172
+
173
+ If both `srcChainKey` and `dstChainKey` are spoke chains that share a vault for the token, prefer [`sodax.bridge.bridge`](bridge.md) — it skips the solver and tends to be cheaper. Use `swap` when no vault pair exists or when a solver-routed price improves the outcome.
174
+
175
+ ### Create intent only (custom relay)
176
+
177
+ ```ts
178
+ const result = await sodax.swaps.createIntent({
179
+ params: { /* … */ },
180
+ raw: false,
181
+ walletProvider: evmWp,
182
+ });
183
+ if (!result.ok) return;
184
+
185
+ const { tx: spokeTxHash, intent, relayData } = result.value;
186
+ // tx is the spoke tx hash (TxReturnType<K, false>) for raw: false
187
+ // relayData is { payload: string }; submit relayData.payload to your backend
188
+ ```
189
+
190
+ ### Backend submit-tx flow
191
+
192
+ ```ts
193
+ const submitResult = await sodax.backendApi.submitSwapTx({
194
+ txHash: spokeTxHash as string,
195
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
196
+ walletAddress: '0x…',
197
+ intent: /* SwapIntentData built from CreateIntentResult.value.intent */,
198
+ relayData: relayData.payload, // string (not the object)
199
+ });
200
+
201
+ if (!submitResult.ok) {
202
+ // submitResult.error.code: 'EXTERNAL_API_ERROR' with context.api: 'backend'
203
+ return;
204
+ }
205
+ ```
206
+
207
+ ### Raw-tx flow
208
+
209
+ ```ts
210
+ const result = await sodax.swaps.createIntent({
211
+ params: { /* … */ },
212
+ raw: true,
213
+ // walletProvider is forbidden here
214
+ });
215
+ if (!result.ok) return;
216
+ const { tx, intent, relayData } = result.value;
217
+ // tx: chain-specific raw-tx payload (EvmRawTransaction, SolanaRawTransaction, …)
218
+ ```
219
+
220
+ ### Cancel intent
221
+
222
+ ```ts
223
+ await sodax.swaps.cancelIntent({
224
+ params: { srcChainKey, intent /* the full Intent struct */ },
225
+ raw: false,
226
+ walletProvider: evmWp,
227
+ });
228
+ ```
229
+
230
+ ## Return shapes
231
+
232
+ | Method | Success type |
233
+ |---|---|
234
+ | `swap` | `SwapResponse` = `{ solverExecutionResponse, intent, intentDeliveryInfo }` |
235
+ | `createIntent` | `CreateIntentResult<K, Raw>` = `{ tx: TxReturnType<K, Raw>, intent: Intent & FeeAmount, relayData: RelayExtraData }` |
236
+ | `postExecution` | `SwapResponse` |
237
+ | `createLimitOrder` / `createLimitOrderIntent` | Same as `createIntent` |
238
+ | `cancelIntent` / `cancelLimitOrder` | `TxReturnType<K, Raw>` |
239
+ | `approve` | `TxReturnType<K, Raw>` |
240
+ | `isAllowanceValid` | `boolean` |
241
+
242
+ `RelayExtraData`:
243
+
244
+ ```ts
245
+ type RelayExtraData = {
246
+ payload: string; // pass this string to backend submit-tx as `relayData`
247
+ };
248
+ ```
249
+
250
+ ## Error codes
251
+
252
+ `feature: 'swap'`. Per-method narrow unions:
253
+
254
+ | Method | Codes |
255
+ |---|---|
256
+ | `createIntent`, `createLimitOrderIntent` | `VALIDATION_FAILED`, `INTENT_CREATION_FAILED`, `UNKNOWN` |
257
+ | `swap`, `createLimitOrder` | `VALIDATION_FAILED`, `INTENT_CREATION_FAILED`, `EXECUTION_FAILED`, `TX_VERIFICATION_FAILED`, `TX_SUBMIT_FAILED`, `RELAY_TIMEOUT`, `RELAY_FAILED`, `EXTERNAL_API_ERROR`, `UNKNOWN` |
258
+ | `postExecution` | `EXECUTION_FAILED` (with `phase: 'postExecution'`), `EXTERNAL_API_ERROR` (with `api: 'solver'`), `UNKNOWN` |
259
+ | `cancelIntent`, `cancelLimitOrder` | `VALIDATION_FAILED`, `EXECUTION_FAILED`, `UNKNOWN` |
260
+ | `approve` | `VALIDATION_FAILED`, `APPROVE_FAILED`, `UNKNOWN` |
261
+ | `isAllowanceValid` | `VALIDATION_FAILED`, `ALLOWANCE_CHECK_FAILED`, `UNKNOWN` |
262
+
263
+ Solver-specific context on `EXTERNAL_API_ERROR`:
264
+
265
+ - `error.context.api === 'solver'`
266
+ - `error.context.solverCode` — the solver's own error code (e.g. `'INSUFFICIENT_LIQUIDITY'`)
267
+ - `error.context.solverDetail` — the solver's human-readable message
268
+
269
+ ## Cross-references
270
+
271
+ - v1 → v2 swap migration: [`features/swap.md`](../../../migration-v1-to-v2/knowledge/features/swap.md).
272
+ - Error model: [`../architecture.md`](../architecture.md) § 8 and [`../reference/`](../reference/) § 3.
273
+ - Stellar destinations require a trustline first: [`../chain-specifics.md`](../chain-specifics.md) § "Stellar trustline".
@@ -0,0 +1,213 @@
1
+ # Quickstart — `@sodax/sdk` v2
2
+
3
+ Get a `Sodax` instance running in your project. This guide is **`@sodax/sdk`-only**: no other SODAX packages are imported. Where the SDK needs an `I*WalletProvider` instance, examples use a TypeScript `declare` placeholder so the surface stays Core-SDK-clean.
4
+
5
+ ## Section index
6
+
7
+ 1. [Installation](#1-installation)
8
+ 2. [TypeScript](#2-typescript)
9
+ 3. [The wallet-provider contract](#3-the-wallet-provider-contract)
10
+ 4. [Where to get wallet-provider implementations](#4-where-to-get-wallet-provider-implementations)
11
+ 5. [Construct + initialize](#5-construct--initialize)
12
+ 6. [Reads without a wallet](#6-reads-without-a-wallet)
13
+ 7. [Build raw transactions (no wallet)](#7-build-raw-transactions-no-wallet)
14
+ 8. [Calling methods that sign](#8-calling-methods-that-sign)
15
+ 9. [First-time troubleshooting](#9-first-time-troubleshooting)
16
+
17
+ ---
18
+
19
+ ## 1. Installation
20
+
21
+ ```bash
22
+ pnpm add @sodax/sdk
23
+ # or
24
+ npm install @sodax/sdk
25
+ # or
26
+ yarn add @sodax/sdk
27
+ ```
28
+
29
+ **Don't add `@sodax/types` separately.** `@sodax/sdk` re-exports the entire types surface from its barrel. Adding `@sodax/types` as a direct dependency invites version skew on the next minor bump.
30
+
31
+ ## 2. TypeScript
32
+
33
+ Targets Node 20.12+ and modern browsers. The package ships dual ESM (`.mjs`) + CJS (`.cjs`) + DTS, with `"type": "module"`. No additional TypeScript config needed — the package's `exports` field handles resolution for both `tsc` and `bundler` `moduleResolution` modes.
34
+
35
+ If you're on `moduleResolution: 'node'` (legacy), upgrade to `'bundler'` or `'node16'` / `'nodenext'` — `'node'` doesn't read the `exports` field and will fall back to `main` / `module` (which still work, but you may see resolution warnings).
36
+
37
+ ## 3. The wallet-provider contract
38
+
39
+ Methods that sign and broadcast take a `walletProvider` parameter typed as the chain-specific `I*WalletProvider` interface (`IEvmWalletProvider`, `ISolanaWalletProvider`, `ISuiWalletProvider`, `IStellarWalletProvider`, `IIconWalletProvider`, `IInjectiveWalletProvider`, `IStacksWalletProvider`, `INearWalletProvider`, `IBitcoinWalletProvider`). All nine interfaces are exported from `@sodax/sdk`.
40
+
41
+ `@sodax/sdk` does **not** ship implementations of these interfaces. Read methods (`sodax.config.*`, `sodax.bridge.getBridgeableAmount`, `sodax.staking.getStakingConfig`, etc.) and `raw: true` flows do not require a `walletProvider`.
42
+
43
+ ## 4. Where to get wallet-provider implementations
44
+
45
+ Two options:
46
+
47
+ 1. **Implement the interface yourself.** Each `I*WalletProvider` is a small set of methods (`getWalletAddress`, plus chain-specific signing / broadcasting). Wrap whatever wallet abstraction your app already owns (`viem`'s `WalletClient` for EVM, `@solana/web3.js` keypairs for Solana, `@stellar/stellar-sdk` for Stellar, etc.) in an object literal that satisfies the interface.
48
+ 2. **Use `@sodax/wallet-sdk-core`** — a separate SODAX package (not part of `@sodax/sdk`, not a transitive dependency — install it separately) that ships ready-made `I*WalletProvider` implementations for all 9 chain families with both private-key (Node / scripts) and browser-extension (dApp) modes. Refer to that package's own documentation for usage.
49
+
50
+ Examples in this guide use TypeScript `declare const` placeholders so the surface stays Core-SDK-only — substitute your own object regardless of which option you chose.
51
+
52
+ ## 5. Construct + initialize
53
+
54
+ ```ts
55
+ import { Sodax } from '@sodax/sdk';
56
+
57
+ const sodax = new Sodax();
58
+ await sodax.config.initialize(); // load fresh config from backend; falls back to packaged defaults
59
+
60
+ // All feature services are wired and ready:
61
+ // sodax.swaps, sodax.moneyMarket, sodax.bridge, sodax.staking,
62
+ // sodax.dex, sodax.migration, sodax.partners, sodax.recovery,
63
+ // sodax.config, sodax.backendApi, sodax.hubProvider, sodax.spoke
64
+ ```
65
+
66
+ `new Sodax()` accepts an optional `DeepPartial<SodaxConfig>` for custom RPC endpoints, solver / backend URLs, etc. — see [`recipes/`](recipes/) § "Initialize Sodax". `initialize()` is idempotent.
67
+
68
+ ## 6. Reads without a wallet
69
+
70
+ Many SDK calls are pure reads — no wallet provider, no signing. They're the cheapest path to verifying an integration:
71
+
72
+ ```ts
73
+ import { Sodax, ChainKeys } from '@sodax/sdk';
74
+
75
+ const sodax = new Sodax();
76
+ await sodax.config.initialize();
77
+
78
+ // Config / token lookups
79
+ const usdc = sodax.config.findSupportedTokenBySymbol(ChainKeys.ARBITRUM_MAINNET, 'USDC');
80
+ const isValid = sodax.config.isValidSpokeChainKey(ChainKeys.ARBITRUM_MAINNET);
81
+
82
+ // Money market
83
+ const supplyTokens = sodax.moneyMarket.getSupportedTokensByChainId(ChainKeys.ARBITRUM_MAINNET);
84
+
85
+ // Bridge
86
+ const limit = await sodax.bridge.getBridgeableAmount(USDC_ARBITRUM, USDC_STELLAR);
87
+ // limit.value: BridgeLimit = { amount, decimals, type }
88
+
89
+ // Staking (hub-only reads — no chain context needed)
90
+ const stakingConfig = await sodax.staking.getStakingConfig();
91
+
92
+ // DEX
93
+ const pools = sodax.dex.clService.getPools(); // synchronous in v2
94
+ ```
95
+
96
+ ## 7. Build raw transactions (no wallet)
97
+
98
+ For sign-elsewhere flows (gnosis safe, hardware wallet, custom multi-sig), use `raw: true`. The SDK builds the unsigned payload; your application signs and broadcasts:
99
+
100
+ ```ts
101
+ import { Sodax, ChainKeys } from '@sodax/sdk';
102
+
103
+ const sodax = new Sodax();
104
+ await sodax.config.initialize();
105
+
106
+ const result = await sodax.swaps.createIntent({
107
+ params: {
108
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
109
+ dstChainKey: ChainKeys.STELLAR_MAINNET,
110
+ /* … rest of intent params */
111
+ },
112
+ raw: true,
113
+ // walletProvider is FORBIDDEN when raw: true — TypeScript rejects it.
114
+ });
115
+
116
+ if (!result.ok) {
117
+ console.error(result.error.toJSON());
118
+ return;
119
+ }
120
+ const { tx, intent, relayData } = result.value;
121
+ // tx: chain-specific raw-tx payload (EvmRawTransaction, SolanaRawTransaction, …)
122
+ // Sign and broadcast `tx` with whatever signer your application owns.
123
+ ```
124
+
125
+ ## 8. Calling methods that sign
126
+
127
+ For signed flows, supply an `I*WalletProvider`. The example uses a TypeScript `declare` placeholder — at runtime, substitute an object your application owns (one you implemented to satisfy the interface, or one constructed via `@sodax/wallet-sdk-core`).
128
+
129
+ ```ts
130
+ import { Sodax, ChainKeys, type IEvmWalletProvider } from '@sodax/sdk';
131
+
132
+ declare const evmWallet: IEvmWalletProvider;
133
+ // ↑ At runtime, replace with your application's wallet-provider object.
134
+ // Any object that satisfies IEvmWalletProvider works.
135
+
136
+ const sodax = new Sodax();
137
+ await sodax.config.initialize();
138
+
139
+ const result = await sodax.swaps.createIntent({
140
+ params: {
141
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
142
+ dstChainKey: ChainKeys.STELLAR_MAINNET,
143
+ srcAddress: (await evmWallet.getWalletAddress()) as `0x${string}`,
144
+ /* … rest of intent params */
145
+ },
146
+ raw: false,
147
+ walletProvider: evmWallet,
148
+ });
149
+
150
+ if (!result.ok) {
151
+ console.error(result.error.toJSON());
152
+ return;
153
+ }
154
+
155
+ console.log('intent created:', result.value.tx);
156
+ ```
157
+
158
+ The chain key on the payload (`ChainKeys.ARBITRUM_MAINNET`) is what TypeScript narrows the wallet-provider parameter against — passing a Solana wallet would be a compile-time error. See [`architecture.md`](architecture.md) § 6 for the `WalletProviderSlot<K, Raw>` mechanism.
159
+
160
+ ## 9. First-time troubleshooting
161
+
162
+ The errors most likely to hit on a fresh install or first port.
163
+
164
+ ### "Cannot find module '@sodax/sdk' or its corresponding type declarations"
165
+
166
+ - TypeScript `moduleResolution` is `'node'` (legacy). Switch to `'bundler'` or `'node16'`/`'nodenext'`.
167
+ - Or: clear `node_modules` and reinstall. `@sodax/sdk` ships dual exports; resolution should be automatic.
168
+
169
+ ### "Module '\"@sodax/sdk\"' has no exported member 'SONIC_MAINNET_CHAIN_ID'"
170
+
171
+ - v1 constant name. Use `ChainKeys.SONIC_MAINNET`. See [`breaking-changes/type-system.md`](../../migration-v1-to-v2/knowledge/breaking-changes/type-system.md) § 1.
172
+
173
+ ### "Object literal may only specify known properties, and 'walletProvider' does not exist in type ..."
174
+
175
+ - Forgot `raw: false` (or `raw: true`) discriminator on the call. Add it. See [`architecture.md`](architecture.md) § 6.
176
+
177
+ ### "Property 'tx' does not exist on type 'SwapResponse'" or similar
178
+
179
+ - You're treating the return as the success value directly instead of unpacking `result.value`. v2 returns `Promise<Result<T>>` — branch on `result.ok` first. See [`architecture.md`](architecture.md) § 7.
180
+
181
+ ### `sodax.config.findSupportedTokenBySymbol` returns `undefined`
182
+
183
+ - `await sodax.config.initialize()` wasn't called. Add it after `new Sodax()`.
184
+
185
+ ### "Property 'xChainId' does not exist on type 'XToken'"
186
+
187
+ - `XToken.xChainId` was renamed to `XToken.chainKey`. See [`breaking-changes/type-system.md`](../../migration-v1-to-v2/knowledge/breaking-changes/type-system.md) § 4.
188
+
189
+ ### "Type '{ token, amount, action }' does not satisfy the expected type 'MoneyMarketSupplyParams'"
190
+
191
+ - Missing `srcChainKey` and `srcAddress` (required in v2). See [`features/money-market.md`](features/money-market.md).
192
+
193
+ ### "Argument of type 'string' is not assignable to parameter of type 'GetAddressType<K>'"
194
+
195
+ - For EVM chains, `GetAddressType<K>` is `` `0x${string}` ``. Cast at the boundary: `(await walletProvider.getWalletAddress()) as \`0x${string}\``. See [`recipes/`](recipes/) § "Chain-key narrowing".
196
+
197
+ ### `sodax.config.initialize()` hangs / errors
198
+
199
+ - The backend API is unreachable. The SDK should fall back to packaged defaults silently — check your network, then check that `SodaxConfig.api.baseURL` is correct (or omit it for the default).
200
+
201
+ ### Stellar bridge / swap fails with `'Trustline missing'`
202
+
203
+ - Stellar destinations require a trustline for the destination asset before they can receive it. See [`chain-specifics.md`](chain-specifics.md) § "Stellar trustline".
204
+
205
+ ---
206
+
207
+ ## Cross-references
208
+
209
+ - v2 architecture: [`architecture.md`](architecture.md).
210
+ - Recipes for common patterns: [`recipes/`](recipes/).
211
+ - Per-feature usage: [`features/`](features/).
212
+ - Lookup tables (chain keys, error codes, public API): [`reference/`](reference/).
213
+ - v1 → v2 porting: [`README.md`](../../migration-v1-to-v2/knowledge/README.md).
@@ -0,0 +1,21 @@
1
+ # Recipes — `@sodax/sdk` v2
2
+
3
+ Copy-pasteable patterns for the most common Core SDK consumer tasks. Each file is self-contained — drop the snippet into your code, swap in your specifics, done.
4
+
5
+ | Recipe | When |
6
+ |---|---|
7
+ | [`initialize-sodax.md`](initialize-sodax.md) | App startup. `new Sodax()` + `await sodax.config.initialize()`, with and without config override. |
8
+ | [`result-and-errors.md`](result-and-errors.md) | Branching on `result.ok`, switching on `(error.feature, error.code)`, `isSodaxError` over `instanceof`, sub-Result propagation, logger integration. |
9
+ | [`signed-tx-flow.md`](signed-tx-flow.md) | `raw: false` + chain-narrowed `walletProvider`. Returns tx hash (or `TxHashPair` for cross-chain mutations). |
10
+ | [`raw-tx-flow.md`](raw-tx-flow.md) | `raw: true`. Builds an unsigned chain-specific payload; you sign elsewhere. |
11
+ | [`chain-key-narrowing.md`](chain-key-narrowing.md) | Cast-at-boundary pattern; runtime `chainType` discriminant. |
12
+ | [`testing.md`](testing.md) | Mocking the `Sodax` instance, stubbing the relay layer, `Result<T>` assertions. |
13
+ | [`gas-estimation.md`](gas-estimation.md) | Pre-flight gas estimation for raw-tx flows. |
14
+ | [`backend-server-init.md`](backend-server-init.md) | Node script / bot / partner backend pattern with `declare const` wallet placeholders. |
15
+
16
+ ## Cross-references
17
+
18
+ - v2 architectural concepts: [`../architecture.md`](../architecture.md).
19
+ - Lookup tables (chain keys, error codes, public API): [`../reference/`](../reference/).
20
+ - DO / DO NOT / workflow: [`../ai-rules.md`](../ai-rules.md).
21
+ - v1 → v2 migration: [`recipes.md`](../../../migration-v1-to-v2/knowledge/recipes.md).
@@ -0,0 +1,69 @@
1
+ # Backend-server initialization (private-key)
2
+
3
+ Node script / bot / partner backend pattern. The `Sodax` instance holds no wallet itself — your application owns the `I*WalletProvider` object and passes it into each call.
4
+
5
+ ```ts
6
+ import { Sodax, ChainKeys, type IEvmWalletProvider, type SpokeChainKey } from '@sodax/sdk';
7
+
8
+ declare const evmWallet: IEvmWalletProvider;
9
+ // ↑ Your application's wallet-provider object. Implement IEvmWalletProvider yourself,
10
+ // or install `@sodax/wallet-sdk-core` (separate package) which ships an `EvmWalletProvider`
11
+ // class you can construct with `{ privateKey, rpcUrl }`.
12
+
13
+ const sodax = new Sodax({
14
+ rpcConfig: {
15
+ [ChainKeys.ARBITRUM_MAINNET]: process.env.ARBITRUM_RPC_URL!,
16
+ [ChainKeys.SONIC_MAINNET]: process.env.SONIC_RPC_URL!,
17
+ // …
18
+ },
19
+ });
20
+ await sodax.config.initialize();
21
+
22
+ const result = await sodax.swaps.createIntent({
23
+ params: {
24
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
25
+ dstChainKey: ChainKeys.STELLAR_MAINNET,
26
+ srcAddress: (await evmWallet.getWalletAddress()) as `0x${string}`,
27
+ /* … */
28
+ },
29
+ raw: false,
30
+ walletProvider: evmWallet,
31
+ });
32
+ ```
33
+
34
+ ### Multi-chain bots
35
+
36
+ If your bot operates on multiple source chains, hold one wallet provider per chain family and pick the right one at call time:
37
+
38
+ ```ts
39
+ declare const wallets: {
40
+ readonly [ChainKeys.ARBITRUM_MAINNET]: IEvmWalletProvider;
41
+ readonly [ChainKeys.SONIC_MAINNET]: IEvmWalletProvider;
42
+ readonly [ChainKeys.SOLANA_MAINNET]: ISolanaWalletProvider;
43
+ };
44
+
45
+ function getWallet(chainKey: SpokeChainKey) {
46
+ const wp = wallets[chainKey as keyof typeof wallets];
47
+ if (!wp) throw new Error(`No wallet configured for ${chainKey}`);
48
+ return wp;
49
+ }
50
+
51
+ await sodax.swaps.createIntent({
52
+ params: { srcChainKey: ChainKeys.ARBITRUM_MAINNET, /* … */ },
53
+ raw: false,
54
+ walletProvider: getWallet(ChainKeys.ARBITRUM_MAINNET),
55
+ });
56
+ ```
57
+
58
+ ### Pitfall
59
+
60
+ Hold one wallet-provider instance per chain family for the lifetime of your process; don't recreate them per request. Implementations typically own an RPC client connection that's expensive to set up.
61
+
62
+ ---
63
+
64
+
65
+ ## Cross-references
66
+
67
+ - [`README.md`](README.md) — recipe index.
68
+ - [`../architecture.md`](../architecture.md) — concepts behind these patterns.
69
+ - [`../reference/`](../reference/) — chain keys, error codes, public API surface.
@@ -0,0 +1,65 @@
1
+ # Chain-key narrowing (cast-at-boundary)
2
+
3
+ When you have a runtime chain key (e.g. user-selected from a UI) and need a chain-narrowed wallet provider, narrow once at the boundary and let the narrowed binding flow downstream.
4
+
5
+ ### Narrowing inside a feature flow
6
+
7
+ ```ts
8
+ import { ChainKeys, type GetWalletProviderType } from '@sodax/sdk';
9
+
10
+ function isStellar(chainKey: SpokeChainKey): chainKey is typeof ChainKeys.STELLAR_MAINNET {
11
+ return chainKey === ChainKeys.STELLAR_MAINNET;
12
+ }
13
+
14
+ const stellarWp = isStellar(srcChainKey)
15
+ ? (walletProvider as GetWalletProviderType<typeof ChainKeys.STELLAR_MAINNET> | undefined)
16
+ : undefined;
17
+
18
+ if (stellarWp) {
19
+ await checkStellarTrustline({ token, amount, walletProvider: stellarWp });
20
+ }
21
+ ```
22
+
23
+ The cast is local — the `isStellar` guard proves correctness at runtime. **Don't propagate the cast** beyond the narrowed binding; downstream code reads `stellarWp` as the chain-specific type without further casts.
24
+
25
+ ### The `chainType` runtime alternative
26
+
27
+ Every `I*WalletProvider` has a `readonly chainType: '<CHAIN>'` literal. Use it when you don't have the chain key in scope but do have a wallet provider:
28
+
29
+ ```ts
30
+ if (walletProvider.chainType === 'BITCOIN') {
31
+ // walletProvider: IBitcoinWalletProvider
32
+ await checkBitcoinPSBT(walletProvider);
33
+ }
34
+ ```
35
+
36
+ No `as` cast needed — `chainType` is part of the interface.
37
+
38
+ ### Pitfall
39
+
40
+ Do **not** chain a cast through every helper. The cast belongs at the chain-key guard. Anywhere downstream of the guard, the binding is already typed correctly:
41
+
42
+ ```ts
43
+ // Bad — chained casts:
44
+ async function approveSomething(wp: IWalletProvider) {
45
+ await sodax.swaps.approve({
46
+ params,
47
+ walletProvider: wp as GetWalletProviderType<typeof ChainKeys.BITCOIN_MAINNET>,
48
+ raw: false,
49
+ });
50
+ }
51
+
52
+ // Good — one cast at the boundary, narrowed binding flows:
53
+ const btcWp = isBitcoin(srcChainKey)
54
+ ? (walletProvider as GetWalletProviderType<typeof ChainKeys.BITCOIN_MAINNET>)
55
+ : null;
56
+ if (btcWp) await sodax.swaps.approve({ params, walletProvider: btcWp, raw: false });
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Cross-references
62
+
63
+ - [`README.md`](README.md) — recipe index.
64
+ - [`../architecture.md`](../architecture.md) — concepts behind these patterns.
65
+ - [`../reference/`](../reference/) — chain keys, error codes, public API surface.
@@ -0,0 +1,33 @@
1
+ # Gas estimation
2
+
3
+ Pre-flight gas estimation for raw-tx flows. Most signed flows include gas estimation internally; you only need this when building unsigned payloads.
4
+
5
+ ```ts
6
+ const result = await sodax.swaps.estimateGas({
7
+ params: { /* same as createIntent params */ },
8
+ });
9
+
10
+ if (!result.ok) {
11
+ // result.error: SodaxError<'VALIDATION_FAILED' | 'GAS_ESTIMATION_FAILED' | 'UNKNOWN'>
12
+ if (result.error.code === 'GAS_ESTIMATION_FAILED') {
13
+ // Retry — gas estimation failures are usually transient.
14
+ }
15
+ return;
16
+ }
17
+
18
+ const { gasLimit, gasPrice } = result.value;
19
+ ```
20
+
21
+ `estimateGas` returns chain-family-specific shapes — EVM gas params, Solana compute units, etc. See per-feature docs in [`../features/`](../features/) for specifics.
22
+
23
+ ### Distinct from `LOOKUP_FAILED`
24
+
25
+ The SDK keeps `GAS_ESTIMATION_FAILED` as its own code (rather than folding into `LOOKUP_FAILED`) because retry semantics differ. Re-estimation is cheap and almost always the right move on transient failure. Generic `LOOKUP_FAILED` errors typically need user intervention.
26
+
27
+ ---
28
+
29
+ ## Cross-references
30
+
31
+ - [`README.md`](README.md) — recipe index.
32
+ - [`../architecture.md`](../architecture.md) — concepts behind these patterns.
33
+ - [`../reference/`](../reference/) — chain keys, error codes, public API surface.