@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,144 @@
|
|
|
1
|
+
# Error shape crosswalk — v1 → v2
|
|
2
|
+
|
|
3
|
+
The shape and type of errors flowing through dapp-kit hooks changed in v2. The change is mostly SDK-level (one canonical `SodaxError<C>` replaces 7+ per-feature classes) but it surfaces in dapp-kit at the consumer level — wherever you catch or branch on errors from hooks.
|
|
4
|
+
|
|
5
|
+
## Where v2 errors appear
|
|
6
|
+
|
|
7
|
+
| Surface | v1 | v2 |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `mutation.error` | Only on actual exceptions | Includes SDK `!ok` errors (now thrown inside `mutationFn`) |
|
|
10
|
+
| `mutation.data` | `Result<T>` (`{ ok, value, error }`) | Unwrapped success type `T`; SDK `!ok` flows to `mutation.error` |
|
|
11
|
+
| `mutateAsync` rejection | Only on exceptions | Includes SDK `!ok` rejections |
|
|
12
|
+
| `mutateAsyncSafe` `result.error` | (didn't exist) | Includes SDK `!ok` errors (re-packed from the throw) |
|
|
13
|
+
| `onError` callback | Fired only for exceptions | Fires for SDK `!ok` too |
|
|
14
|
+
|
|
15
|
+
The semantic shift is: v1 treated SDK `!ok` as "successful but with an error inside"; v2 treats it as a thrown error. See [`../breaking-changes/result-handling.md`](../breaking-changes/result-handling.md) for the full picture.
|
|
16
|
+
|
|
17
|
+
## Error class crosswalk (SDK-level — leaks through)
|
|
18
|
+
|
|
19
|
+
In v1, each SDK feature had its own error class:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// @ai-snippets-skip — describes deleted v1 type surface, not runnable
|
|
23
|
+
// v1
|
|
24
|
+
class MoneyMarketError<C extends MoneyMarketErrorCode> extends Error { /* ... */ }
|
|
25
|
+
class IntentError<C extends IntentErrorCode> extends Error { /* ... */ }
|
|
26
|
+
class StakingError<C extends StakingErrorCode> extends Error { /* ... */ }
|
|
27
|
+
class BridgeError<C extends BridgeErrorCode> extends Error { /* ... */ }
|
|
28
|
+
class MigrationError<C extends MigrationErrorCode> extends Error { /* ... */ }
|
|
29
|
+
class AssetServiceError<C extends AssetServiceErrorCode> extends Error { /* ... */ }
|
|
30
|
+
class ConcentratedLiquidityError<C extends ConcentratedLiquidityErrorCode> extends Error { /* ... */ }
|
|
31
|
+
// ...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In v2, all are consolidated:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
// @ai-snippets-skip — type-shape reference; the real class is exported from @sodax/sdk
|
|
38
|
+
// v2
|
|
39
|
+
class SodaxError<C extends SodaxErrorCode = SodaxErrorCode> extends Error {
|
|
40
|
+
readonly code: C; // closed reason union (no feature prefix)
|
|
41
|
+
readonly feature: SodaxFeature; // 'swap' | 'moneyMarket' | 'bridge' | …
|
|
42
|
+
readonly cause?: unknown;
|
|
43
|
+
readonly context?: SodaxErrorContext;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Discriminate via `(error.feature, error.code)` instead of class name.
|
|
48
|
+
|
|
49
|
+
## Error code crosswalk (key examples)
|
|
50
|
+
|
|
51
|
+
The SDK reduced the per-feature code unions to a unified 13-code reason vocabulary, with feature-specific context on `error.context.action` / `error.context.method`. Examples:
|
|
52
|
+
|
|
53
|
+
| v1 (per-feature) | v2 |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `MoneyMarketError<'CREATE_SUPPLY_INTENT_FAILED'>` | `SodaxError<'INTENT_CREATION_FAILED'>` with `feature: 'moneyMarket'`, `context.action: 'supply'` |
|
|
56
|
+
| `MoneyMarketError<'SUPPLY_FAILED'>` | `SodaxError<'EXECUTION_FAILED'>` with `feature: 'moneyMarket'`, `context.action: 'supply'` |
|
|
57
|
+
| `IntentError<'CREATE_INTENT_FAILED'>` | `SodaxError<'INTENT_CREATION_FAILED'>` with `feature: 'swap'`, `context.action: 'createIntent'` |
|
|
58
|
+
| `IntentError<'POST_EXECUTION_FAILED'>` | `SodaxError<'EXECUTION_FAILED'>` with `feature: 'swap'`, `context.phase: 'postExecution'` |
|
|
59
|
+
| `StakingError<'STAKE_FAILED'>` | `SodaxError<'EXECUTION_FAILED'>` with `feature: 'staking'`, `context.action: 'stake'` |
|
|
60
|
+
| `BridgeError<'BRIDGE_FAILED'>` | `SodaxError<'EXECUTION_FAILED'>` with `feature: 'bridge'`, `context.action: 'bridge'` |
|
|
61
|
+
| `MigrationError<'MIGRATE_BNUSD_FORWARD_FAILED'>` | `SodaxError<'EXECUTION_FAILED'>` with `feature: 'migration'`, `context.action: 'migratebnUSD'`, `context.direction: 'forward'` |
|
|
62
|
+
| `*Error<'ALLOWANCE_CHECK_FAILED'>` | `SodaxError<'ALLOWANCE_CHECK_FAILED'>` (unchanged code; new feature/context fields) |
|
|
63
|
+
| `*Error<'APPROVE_FAILED'>` | Same |
|
|
64
|
+
| `*Error<'GAS_ESTIMATION_FAILED'>` | Same |
|
|
65
|
+
| `*Error<'RELAY_TIMEOUT'>` | `SodaxError<'RELAY_TIMEOUT'>` with `relayCode: 'RELAY_TIMEOUT'` on context |
|
|
66
|
+
|
|
67
|
+
Full crosswalk (per feature): [`@sodax/sdk`: `migration/reference/error-code-crosswalk.md`](https://github.com/icon-project/sodax-sdks/blob/main/packages/skills/knowledge/sdk/migration/reference/error-code-crosswalk.md).
|
|
68
|
+
|
|
69
|
+
## How to migrate error-handling code
|
|
70
|
+
|
|
71
|
+
### Pattern 1: `instanceof` checks → `isSodaxError`
|
|
72
|
+
|
|
73
|
+
```diff
|
|
74
|
+
- catch (e) {
|
|
75
|
+
- if (e instanceof MoneyMarketError) {
|
|
76
|
+
- handleMmError(e.code);
|
|
77
|
+
- }
|
|
78
|
+
- }
|
|
79
|
+
+ catch (e) {
|
|
80
|
+
+ if (isSodaxError(e) && e.feature === 'moneyMarket') {
|
|
81
|
+
+ handleMmError(e.code);
|
|
82
|
+
+ }
|
|
83
|
+
+ }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`isSodaxError` is exported from `@sodax/dapp-kit` (re-exported from `@sodax/sdk`).
|
|
87
|
+
|
|
88
|
+
### Pattern 2: switch on code
|
|
89
|
+
|
|
90
|
+
```diff
|
|
91
|
+
catch (e) {
|
|
92
|
+
- if (e instanceof IntentError) {
|
|
93
|
+
- switch (e.code) {
|
|
94
|
+
- case 'CREATE_INTENT_FAILED': /* ... */ break;
|
|
95
|
+
- case 'POST_EXECUTION_FAILED': /* ... */ break;
|
|
96
|
+
- case 'RELAY_TIMEOUT': /* ... */ break;
|
|
97
|
+
- }
|
|
98
|
+
- }
|
|
99
|
+
+ if (isSodaxError(e) && e.feature === 'swap') {
|
|
100
|
+
+ switch (e.code) {
|
|
101
|
+
+ case 'INTENT_CREATION_FAILED': /* was CREATE_INTENT_FAILED */ break;
|
|
102
|
+
+ case 'EXECUTION_FAILED': /* was POST_EXECUTION_FAILED — check e.context.phase */ break;
|
|
103
|
+
+ case 'RELAY_TIMEOUT': /* unchanged code */ break;
|
|
104
|
+
+ }
|
|
105
|
+
+ }
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Pattern 3: error-text helper
|
|
110
|
+
|
|
111
|
+
If your v1 code has a helper that maps `error.code` to a UI message, write a small adapter:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// adapters/v1ErrorShape.ts
|
|
115
|
+
import { isSodaxError } from '@sodax/dapp-kit';
|
|
116
|
+
|
|
117
|
+
const V1_CODE_MAP: Record<string, string> = {
|
|
118
|
+
'INTENT_CREATION_FAILED': 'CREATE_INTENT_FAILED',
|
|
119
|
+
'EXECUTION_FAILED': 'POST_EXECUTION_FAILED',
|
|
120
|
+
// ... etc.
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export function adaptToV1Code(error: unknown): string | undefined {
|
|
124
|
+
if (!isSodaxError(error)) return undefined;
|
|
125
|
+
return V1_CODE_MAP[error.code] ?? error.code;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Plan to delete the adapter once you've ported all error UI.
|
|
130
|
+
|
|
131
|
+
## Pitfalls
|
|
132
|
+
|
|
133
|
+
1. **`onError` callbacks fire MORE in v2.** They previously didn't fire for SDK `!ok` (success-path-with-error pattern). Now they do. Audit toasts / logs to make sure they're appropriate.
|
|
134
|
+
2. **`mutation.error` reads MORE in v2.** Same reason — SDK errors flow through it now.
|
|
135
|
+
3. **`isSodaxError(e)` is the cross-bundle-safe check.** Bare `instanceof SodaxError` may break in monorepos with multiple package copies (mixed ESM/CJS, etc.). Use the type guard.
|
|
136
|
+
4. **The `feature` field is your discriminator.** A `SodaxError` from a swap mutation has `feature: 'swap'`. A bridge mutation has `feature: 'bridge'`. The `code` is the reason; `feature` is the source.
|
|
137
|
+
|
|
138
|
+
## Cross-references
|
|
139
|
+
|
|
140
|
+
- [`../breaking-changes/result-handling.md`](../breaking-changes/result-handling.md) — semantic shift in `Result<T>` handling.
|
|
141
|
+
- [`../breaking-changes/sdk-leakage.md`](../breaking-changes/sdk-leakage.md) — broader SDK-side migrations.
|
|
142
|
+
- [`@sodax/sdk`: `migration/breaking-changes/result-and-errors.md`](https://github.com/icon-project/sodax-sdks/blob/main/packages/skills/knowledge/sdk/migration/breaking-changes/result-and-errors.md) — full SDK error-class consolidation.
|
|
143
|
+
- [`@sodax/sdk`: `migration/reference/error-code-crosswalk.md`](https://github.com/icon-project/sodax-sdks/blob/main/packages/skills/knowledge/sdk/migration/reference/error-code-crosswalk.md) — per-feature error code crosswalks.
|
|
144
|
+
- [`../../integration/architecture.md`](../../integration/architecture.md) § "SDK Result handling" — design rationale.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Renamed hooks — v1 → v2
|
|
2
|
+
|
|
3
|
+
Hooks whose **name** changed between versions. Most v1 → v2 changes were signature-level (single-object params, `mutateAsyncSafe`, etc.) — actual hook renames are rare. The list below is the small set.
|
|
4
|
+
|
|
5
|
+
## Hooks renamed
|
|
6
|
+
|
|
7
|
+
| v1 | v2 | Notes |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| (none significant) | | Most hook names are stable across v1 → v2 |
|
|
10
|
+
|
|
11
|
+
### Why this list is short
|
|
12
|
+
|
|
13
|
+
The v2 canonicalization pass focused on hook **shapes** (single-object params, return-shape consolidation, mutateAsyncSafe), not naming. For most consumer code, the hook name you `import { ... }`'d in v1 is still the right hook in v2 — the breaking change is in the call shape, not the import.
|
|
14
|
+
|
|
15
|
+
## Hooks whose generic / type shape changed
|
|
16
|
+
|
|
17
|
+
These keep their name but their TypeScript signature is different. Usually requires per-call-site fixes.
|
|
18
|
+
|
|
19
|
+
| Hook | v1 → v2 change |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `useSwap` | Hook init: `(spokeProvider) → ({ mutationOptions })`. Vars: `{ params } → { params, walletProvider }`. |
|
|
22
|
+
| `useSwapAllowance` | Query params: `(params, spokeProvider) → { params: { payload, srcChainKey, walletProvider } }`. SDK request nested under `params.payload`. Data unwrapped to `boolean`. |
|
|
23
|
+
| `useSwapApprove` | Return: `{ approve, isLoading } → SafeUseMutationResult` (with `mutateAsync` / `isPending`). Vars accept `CreateIntentParams \| CreateLimitOrderParams`. TData is `TxReturnType<K, false>` (chain-keyed receipt union). |
|
|
24
|
+
| `useStatus` | Now `useStatus({ params: { intentTxHash } })` — single-object shape AND key renamed from `intentHash` → `intentTxHash`. Data is `Result<SolverIntentStatusResponse, SolverErrorResponse> \| undefined` (Result-wrapped). Polls 3s. |
|
|
25
|
+
| `useQuote` | Now `useQuote({ params: { payload } })` — SDK request nested under `params.payload` (NOT directly under `params`). Data is `Result<SolverIntentQuoteResponse, SolverErrorResponse> \| undefined`. Polls 3s. |
|
|
26
|
+
| `useCancelSwap` / `useCancelLimitOrder` | TVars are FLAT (no `params` wrapper): `{ srcChainKey, intent, walletProvider }`. |
|
|
27
|
+
| `useCreateLimitOrder` | Hook init: `(spokeProvider) → ({ mutationOptions })`. Vars: `{ params, walletProvider }`. mutationKey is `['swap', 'limitOrder', 'create']`. |
|
|
28
|
+
| All MM mutations (`useSupply`/etc.) | Same as `useSwap`. Plus `srcChainKey` / `srcAddress` required in params (SDK-leakage). All four actions accept optional `dstChainKey`/`dstAddress` for cross-chain delivery (not just borrow/repay). |
|
|
29
|
+
| `useMMAllowance` | Query params: `{ params: { payload: MoneyMarketParams<K> } }`. For `'borrow'` / `'withdraw'` actions: `enabled: false` — `data` stays `undefined`. |
|
|
30
|
+
| `useUserReservesData` | Param key rename: `address → userAddress`; chain key is `spokeChainKey`. |
|
|
31
|
+
| `useUserFormattedSummary` | Same. |
|
|
32
|
+
| `useATokensBalances` | Params: `{ aTokens, spokeProvider, userAddress } → { params: { aTokens, spokeChainKey, userAddress } }`. `spokeProvider` dropped; chain key is **`spokeChainKey`** (NOT `srcChainKey`); user field is **`userAddress`** (NOT `address`). Data: `Map<Address, bigint> \| undefined` (already unwrapped). |
|
|
33
|
+
| `useAToken` | Unaffected by the position-hook renames — takes only `{ aToken }`. Data: `Erc20Token & { chainKey }` (`hubAsset` / `vault` NOT included). |
|
|
34
|
+
| All staking mutations | Same as MM. Plus dedicated approve hooks per token (`useStakeApprove` ↔ `useUnstakeApprove` ↔ `useInstantUnstakeApprove`). |
|
|
35
|
+
| `useStakeRatio` | Return: `Result<bigint> → [xSodaAmount, previewDepositAmount]` (unwrapped tuple — NOT Result-wrapped in v2). |
|
|
36
|
+
| `useStakingInfo` / `useUnstakingInfo` / `useUnstakingInfoWithPenalty` / `useStakingConfig` / `useInstantUnstakeRatio` / `useConvertedAssets` | All unwrapped in v2 (hooks throw on SDK `!ok`). Branch on `isError`/`error`, not `data?.ok`. |
|
|
37
|
+
| `useUnstakingInfo` | Return shape: array → object `{ userUnstakeSodaRequests, totalUnstaking }`. `UserUnstakeInfo` items expose `id` (the requestId) and `request` (original `UnstakeSodaRequest`). |
|
|
38
|
+
| All three staking allowance hooks | Query params: `{ params: { payload: Omit<<Action>Params<K>, 'action'> } }`. Data unwrapped to `boolean`. |
|
|
39
|
+
| `useBridge` | Params: `srcChainId/dstChainId/recipient → srcChainKey/dstChainKey/recipient`. Plus field renames inside `CreateBridgeIntentParams`: `srcAsset → srcToken`, `dstAsset → dstToken`. Return: tuple → `TxHashPair` object (`{ srcChainTxHash, dstChainTxHash }`). |
|
|
40
|
+
| `useBridgeAllowance` | Query params: nested `{ params: { payload, walletProvider } }`. Data unwrapped to `boolean` (queryFn returns `false` on SDK `!ok` — does NOT throw). |
|
|
41
|
+
| `useGetBridgeableAmount` | Params: 4 fields → `{ from: XToken, to: XToken }`. Return: `bigint → BridgeLimit` object (`{ amount, decimals, type: 'DEPOSIT_LIMIT' \| 'WITHDRAWAL_LIMIT' }`). |
|
|
42
|
+
| `useGetBridgeableTokens` | Params: positional → `{ params: { from, to, token } }`. |
|
|
43
|
+
| All DEX mutations | Same as MM. `useSupplyLiquidity` now handles both mint-new and increase-existing — fan-out gated by `params.tokenId` + `params.isValidPosition`. |
|
|
44
|
+
| `useDexAllowance` | Now `{ params: { payload: CreateAssetDepositParams<K> } }`. No `walletProvider` (read-only). |
|
|
45
|
+
| `PoolKey` shape | Real fields are `currency0`, `currency1`, `fee`, `hooks?`, `poolManager`, `parameters` — NOT `poolAddress`/`token0Symbol`/etc. |
|
|
46
|
+
| `useCreate*Params` builders | All take FLAT props object — NOT `{ params }`-wrapped (`useCreateDepositParams`, `useCreateWithdrawParams`, `useCreateSupplyLiquidityParams`, `useCreateDecreaseLiquidityParams`). |
|
|
47
|
+
| `useFeeClaimSwap` (partner) | Same as MM mutation pattern. TData is `IntentAutoSwapResult` (NOT `SwapResponse`). |
|
|
48
|
+
| `useXBalances` | Params: positional → `{ params: { xService, xChainId, xTokens, address } }`. All four required. `xService` injected from `@sodax/wallet-sdk-react`. |
|
|
49
|
+
| `useEstimateGas` | Mutation; vars: `EstimateGasParams<C>` (flat, not `{ params, walletProvider }`-wrapped). |
|
|
50
|
+
| `useDeriveUserWalletAddress`, `useGetUserHubWalletAddress` | Single-object query shape. |
|
|
51
|
+
| `useStellarTrustlineCheck` | Single-object shape with `{ token, amount, chainId, walletProvider }` under `params`. |
|
|
52
|
+
| `useRequestTrustline` | Custom utility hook (NOT a canonical mutation). Takes `(token: string \| undefined)` positionally, returns `{ requestTrustline, isLoading, isRequested, error, data }`. The `requestTrustline` callback takes `{ token, amount, srcChainKey, walletProvider }`. |
|
|
53
|
+
| `useBackendOrderbook` / `useBackendAllMoneyMarketBorrowers` | Pagination MUST be nested under `params`: `{ params: { pagination: { offset, limit } } }`. |
|
|
54
|
+
| `useBackendUserIntents` | Data is `UserIntentsResponse = { items: IntentResponse[], total, offset, limit }` — NOT a bare array. Access `data?.items`. |
|
|
55
|
+
| `useBackendSubmitSwapTx` | Mutation. `apiConfig` moved from hook init to `mutate(vars)`. |
|
|
56
|
+
| All migration hooks | **NEW**: 6 per-action hooks replacing v1's single `useMigrate`. See [`deleted-hooks.md`](deleted-hooks.md). |
|
|
57
|
+
| `useMigrationAllowance` | Query params nest under `params` with inner field literally named `params` (NOT `payload`): `{ params: { params: <migration-params>, action: 'migrate' \| 'revert' } }`. |
|
|
58
|
+
| `BalnMigrateParams` (used by `useMigrateBaln`) | NEW required field `stake: boolean`. `lockupPeriod` is the `LockupPeriod` enum (5 members; values in seconds, not months). |
|
|
59
|
+
| `useTradingWalletBalance` | Return is `RadfiWalletBalance = { btcSatoshi, pendingSatoshi, externalPendingSatoshi, totalUtxos }` — NOT `{ confirmed, pending }`. |
|
|
60
|
+
| `useExpiredUtxos` | Return is `RadfiUtxo[]` (with `_id`, `txid`, `vout`, `txidVout`, `satoshi`, `amount`, `address`, `isSpent`, `status`, `source`, optional `runes`). Both this and `useTradingWalletBalance` take `{ params: { walletProvider, tradingAddress } }`. |
|
|
61
|
+
| `useRadfiAuth` | TData is `RadfiAuthResult = { accessToken, refreshToken, tradingAddress }` (3 fields — `publicKey` is persisted to localStorage but NOT returned). |
|
|
62
|
+
| All Bitcoin/Radfi mutations | Standard pattern — drop hook-init args; pass through `mutate(vars)`. |
|
|
63
|
+
|
|
64
|
+
## Cross-references
|
|
65
|
+
|
|
66
|
+
- [`deleted-hooks.md`](deleted-hooks.md) — hooks that no longer exist at all.
|
|
67
|
+
- [`../breaking-changes/hook-signatures.md`](../breaking-changes/hook-signatures.md) — shape changes in detail.
|
|
68
|
+
- [`../features/`](../features/) — per-feature porting playbooks.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Knowledge tree — `@sodax/sdk`
|
|
2
|
+
|
|
3
|
+
Long-form knowledge supporting the `@sodax/sdk` skills under `@sodax/skills`. The action-oriented entry points are the SKILL.md files in the sibling `skills/` directory:
|
|
4
|
+
|
|
5
|
+
- New code → `packages/skills/skills/sodax-sdk-integration/SKILL.md`
|
|
6
|
+
- Porting v1 → `packages/skills/skills/sodax-sdk-migration/SKILL.md`
|
|
7
|
+
|
|
8
|
+
**Don't read this tree top-to-bottom.** Load files from the **Workflow** section of the relevant SKILL.md — token budgets are sized so the right 2–3 files fit in your context.
|
|
9
|
+
|
|
10
|
+
## Package summary
|
|
11
|
+
|
|
12
|
+
`@sodax/sdk` is the official SDK for SODAX, a cross-chain DeFi platform built on a hub-and-spoke architecture (Sonic is the hub; 19 spoke chains across EVM and non-EVM ecosystems). The SDK provides cross-chain swaps (intent-based via solver), lending/borrowing (money market), staking, bridging, concentrated-liquidity DEX, ICX/bnUSD/BALN migration, and partner-fee operations. It is runtime-agnostic and runs in Node.js, browsers, and bundled apps.
|
|
13
|
+
|
|
14
|
+
This package is **v2**. v2 was a deep architectural reshape of v1 — chain-key driven routing replaced per-chain provider 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. Code written against v1 will not compile against v2.
|
|
15
|
+
|
|
16
|
+
## Layout
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
knowledge/sdk/
|
|
20
|
+
├── AGENTS.md # You are here
|
|
21
|
+
├── integration/ # New v2 code
|
|
22
|
+
│ ├── README.md # Index for this tree
|
|
23
|
+
│ ├── ai-rules.md # DO / DO NOT / workflow — read before per-feature docs
|
|
24
|
+
│ ├── quickstart.md # Install + initialize + first-run troubleshooting
|
|
25
|
+
│ ├── architecture.md # Every v2 design concept (TOC-navigable)
|
|
26
|
+
│ ├── features/ # One file per feature service (swap, money-market, staking, bridge, dex, icx-bnusd-baln, auxiliary-services)
|
|
27
|
+
│ ├── recipes/ # One file per pattern (init, result/errors, raw, signed, narrowing, testing, gas, backend-init)
|
|
28
|
+
│ ├── reference/ # One file per table (chain keys, wallet providers, error codes, public API, glossary)
|
|
29
|
+
│ └── chain-specifics.md # Non-EVM quirks (Stellar trustline, BTC PSBT, Solana PDA, ICON, NEAR)
|
|
30
|
+
└── migration/ # Port v1 → v2
|
|
31
|
+
├── README.md
|
|
32
|
+
├── ai-rules.md
|
|
33
|
+
├── breaking-changes/ # type-system / architecture / result-and-errors
|
|
34
|
+
├── features/ # Per-feature migration playbooks
|
|
35
|
+
└── recipes.md # Codemods + error-shape adapter + Result adapter
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Cross-references
|
|
39
|
+
|
|
40
|
+
- Higher-level React layer: `packages/skills/knowledge/dapp-kit/` (the `@sodax/dapp-kit` knowledge tree).
|
|
41
|
+
- Wallet provider impls: `packages/skills/knowledge/wallet-sdk-core/` (Node/script signing) and `packages/skills/knowledge/wallet-sdk-react/` (React).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Integration — `@sodax/sdk` v2
|
|
2
|
+
|
|
3
|
+
This tree documents v2 of the SDK for **new consumers** building against it. If you're porting v1 code, start at [`../migration/README.md`](../migration/README.md) instead.
|
|
4
|
+
|
|
5
|
+
## Files in this tree
|
|
6
|
+
|
|
7
|
+
| File | What's in it |
|
|
8
|
+
|---|---|
|
|
9
|
+
| [`quickstart.md`](quickstart.md) | Install, initialize a `Sodax` instance, and the top init/setup errors and how to fix them. Covers reads (no wallet), raw-tx flows (no wallet), and signed flows (consumer-supplied wallet provider). |
|
|
10
|
+
| [`architecture.md`](architecture.md) | Every v2 design concept the SDK rests on, in a single TOC-navigable file: hub-and-spoke model, `SpokeService` router, `Sodax` facade + `ConfigService`, `ChainKeys`, `WalletProviderSlot<K, Raw>`, `Result<T>`, `SodaxError<C>` + 13-code vocabulary, relay layer (`mapRelayFailure`, `relayTxAndWaitPacket`). |
|
|
11
|
+
| [`features/swap.md`](features/swap.md) | `SwapService`: intent-based swaps via the solver — `createIntent`, `swap`, `postExecution`, limit orders, `cancelIntent`. |
|
|
12
|
+
| [`features/money-market.md`](features/money-market.md) | `MoneyMarketService`: cross-chain lending/borrowing — supply, borrow, withdraw, repay, reserves, allowance. |
|
|
13
|
+
| [`features/staking.md`](features/staking.md) | `StakingService`: SODA → xSoda — stake, unstake, instant unstake, claim, cancel; ratio + info reads. |
|
|
14
|
+
| [`features/bridge.md`](features/bridge.md) | `BridgeService`: cross-chain token transfer via vault — `bridge`, `createBridgeIntent`, `getBridgeableAmount`, `getBridgeableTokens`. |
|
|
15
|
+
| [`features/dex.md`](features/dex.md) | `ClService` (concentrated liquidity) + `AssetService`: position lifecycle (mint/increase/decrease), claim rewards, asset deposit/withdraw. |
|
|
16
|
+
| [`features/icx-bnusd-baln.md`](features/icx-bnusd-baln.md) | `MigrationService` (the SDK module): ICX, bnUSD, BALN sub-services + lock management. |
|
|
17
|
+
| [`features/auxiliary-services.md`](features/auxiliary-services.md) | `PartnerService` + `RecoveryService` + `BackendApiService` — small APIs grouped together. |
|
|
18
|
+
| [`recipes/`](recipes/) | Copy-pasteable patterns: SDK initialization, `Result` + error discrimination, raw-tx flow, signed-tx flow, chain-key narrowing + cast-at-boundary, testing (mocks/stubs), gas estimation, backend-server init. |
|
|
19
|
+
| [`reference/`](reference/) | Lookup tables: 20-chain `ChainKeys` table with family + relay id, `I*WalletProvider` interfaces, 13 `SodaxErrorCode` meanings + per-feature narrow unions, public API surface (incl. `@sodax/types` re-export rule), glossary. |
|
|
20
|
+
| [`chain-specifics.md`](chain-specifics.md) | Non-EVM quirks — Stellar trustline check/request, Bitcoin PSBT + Radfi auth/session, Solana PDA derivation, ICON Hana wallet + chain-key string, NEAR connector discovery. |
|
|
21
|
+
|
|
22
|
+
## Reading order for a new integrator
|
|
23
|
+
|
|
24
|
+
1. `quickstart.md` — get the SDK installed and a `Sodax` instance running.
|
|
25
|
+
2. `architecture.md` — understand the type system (`ChainKeys`, `Result`, `WalletProviderSlot`, `SodaxError`) before writing call sites.
|
|
26
|
+
3. `recipes/` — pick the patterns you need (signed vs raw, error handling, narrowing).
|
|
27
|
+
4. `features/<x>.md` — read the file for the feature you're integrating.
|
|
28
|
+
5. `chain-specifics.md` — only if you target a non-EVM chain; skip otherwise.
|
|
29
|
+
6. `reference/` — keep open while writing for table lookups.
|
|
30
|
+
|
|
31
|
+
## Cross-references to migration
|
|
32
|
+
|
|
33
|
+
If your project also has v1 call sites, port them first using:
|
|
34
|
+
|
|
35
|
+
- [`../migration/README.md`](../migration/README.md) — overview, reading order, and cross-cutting checklist.
|
|
36
|
+
- [`../migration/breaking-changes/type-system.md`](../migration/breaking-changes/type-system.md) — type renames and shape changes you'll hit on import.
|
|
37
|
+
- [`../migration/breaking-changes/architecture.md`](../migration/breaking-changes/architecture.md) — `*SpokeProvider` deletion, `ConfigService` replacing static lookups, relay flow reshape.
|
|
38
|
+
- [`../migration/breaking-changes/result-and-errors.md`](../migration/breaking-changes/result-and-errors.md) — throws → `Result<T>` and module errors → `SodaxError<C>`, with the v1↔v2 code crosswalk.
|
|
39
|
+
- [`../migration/features/`](../migration/features/) — per-feature playbooks in lockstep with the integration features here.
|
|
40
|
+
|
|
41
|
+
The naming rule: **every feature in `integration/features/` has a sibling in `migration/features/` with the same filename.** When you're deep in one, the other is one path-swap away.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# AI rules — `@sodax/sdk` integration
|
|
2
|
+
|
|
3
|
+
DO / DO NOT / workflow / stop conditions for AI agents writing `@sodax/sdk` v2 code. Read this **before** the per-feature docs — these rules are how you avoid the load-bearing v2 traps.
|
|
4
|
+
|
|
5
|
+
## Workflow (do these in order)
|
|
6
|
+
|
|
7
|
+
1. **Survey the project before touching code.**
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm tsc --noEmit # baseline typecheck
|
|
11
|
+
grep -rE '@sodax/(sdk|types)' --include='*.ts' --include='*.tsx' src/ # see what's already imported
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
2. **Always initialize first.** `new Sodax()` constructs the facade; `await sodax.config.initialize()` loads chain/token config from the backend (with packaged-defaults fallback). Skipping `initialize()` works but means stale defaults — `findSupportedTokenBySymbol` may return `undefined` for tokens added after the SDK release.
|
|
15
|
+
3. **Pick `raw: true` vs `raw: false` explicitly.** Reads and unsigned-tx-building flows take `raw: true` and don't need a wallet. Signed flows take `raw: false` + a chain-narrowed `walletProvider`. The discriminator is mandatory — without it the type system rejects the call. See [`architecture.md`](architecture.md) § 6.
|
|
16
|
+
4. **Branch on `result.ok` before reading `.value` or `.error`.** Every async public method returns `Promise<Result<T, SodaxError>>`. `try/catch` does **not** catch SDK-level failures — see DO NOT § below.
|
|
17
|
+
5. **Discriminate errors by `(error.feature, error.code)`.** Use `isSodaxError(e)` first, then switch on the pair. Don't string-match `error.message`.
|
|
18
|
+
|
|
19
|
+
## DO
|
|
20
|
+
|
|
21
|
+
- **DO** branch on `result.ok` for every SDK call. Forward sub-`Result`s without re-wrapping (`if (!sub.ok) return sub`).
|
|
22
|
+
- **DO** use `isSodaxError(e)` over bare `instanceof SodaxError`. Bundle-safe in cross-realm code (mixed ESM/CJS, monorepos with multiple package copies).
|
|
23
|
+
- **DO** discriminate errors via `(error.feature, error.code)`. The narrow per-method code unions (e.g. `CreateSupplyIntentErrorCode`) enable exhaustive `switch`.
|
|
24
|
+
- **DO** use `ChainKeys.X` constants for chain identifiers. Never hard-code chain-key string values like `'ethereum'` or `'0xa4b1.arbitrum'`.
|
|
25
|
+
- **DO** use `declare const xxxWallet: I*WalletProvider` placeholders in code examples or generated docs. Implementations are not part of `@sodax/sdk`; substitute the consumer's own wallet object at the call site.
|
|
26
|
+
- **DO** import everything from `@sodax/sdk` root. Types from `@sodax/types` are re-exported.
|
|
27
|
+
- **DO** preserve literal chain keys in generic positions where possible (e.g. `srcChainKey: ChainKeys.ETHEREUM_MAINNET as const`) — TypeScript narrowing flows from the literal, including the `walletProvider` parameter type.
|
|
28
|
+
|
|
29
|
+
## DO NOT
|
|
30
|
+
|
|
31
|
+
- **DO NOT** wrap `await sodax.<method>(...)` in `try/catch` and expect SDK-level failures (`RELAY_TIMEOUT`, `EXECUTION_FAILED`, etc.) to land there. They don't — the SDK resolves `{ ok: false, error }` instead of throwing. `catch` only fires for synchronous wrapper exceptions.
|
|
32
|
+
- **DO NOT** import from `@sodax/sdk/dist/...`. Deep imports are unstable across releases; only the package root barrel is the public contract.
|
|
33
|
+
- **DO NOT** add `@sodax/types` as a separate dependency. It's bundled / re-exported via `@sodax/sdk`. Adding it independently invites version skew.
|
|
34
|
+
- **DO NOT** destructure cross-chain mutation results as arrays — `[a, b] = result.value` is wrong. The shape is `TxHashPair = { srcChainTxHash, dstChainTxHash }` (object). This applies to `bridge.bridge`, `staking.{stake,unstake,instantUnstake,claim,cancelUnstake}`, `dex.assetService.{deposit,withdraw}`, `dex.clService.{supplyLiquidity,increaseLiquidity,decreaseLiquidity,claimRewards}`, `moneyMarket.{supply,borrow,withdraw,repay}`, `migration.{migratebnUSD,migrateIcxToSoda,revertMigrateSodaToIcx,migrateBaln}` — all of them.
|
|
35
|
+
- **DO NOT** treat method names from `MoneyMarketService` as the source of MM reads. `getReservesData`, `getUserReservesData`, `getATokensBalances`, etc. live on `sodax.backendApi`, not `sodax.moneyMarket`. See [`features/auxiliary-services.md`](features/auxiliary-services.md) § "BackendApiService".
|
|
36
|
+
- **DO NOT** reach for an `intentRelayApi` property on the `Sodax` instance — there is no such property. The relay layer is exposed as two top-level functions, `relayTxAndWaitPacket` and `submitTransaction` (re-exported from `@sodax/sdk`). Call them directly if you need custom relay orchestration.
|
|
37
|
+
- **DO NOT** call `getStakeRatio` and treat its return as `Result<bigint>`. It's `Result<[xSodaAmount, previewDepositAmount]>` — a tuple of two bigints.
|
|
38
|
+
- **DO NOT** assume `BalnSwapService` lock-management methods (`stake`, `unstake`, `claim`, `claimUnstaked`, `cancelUnstake`, `getDetailedUserLocks`) return `Result<T>`. They still throw on error in v2 — known carve-out. Wrap them in `try/catch`.
|
|
39
|
+
- **DO NOT** call methods that need a wallet provider with `raw: true` — TypeScript rejects `walletProvider` when `raw: true`. Use `raw: false` + `walletProvider`, or stick to read methods.
|
|
40
|
+
|
|
41
|
+
## Stop conditions (defer to user)
|
|
42
|
+
|
|
43
|
+
| Signal | Why stop |
|
|
44
|
+
|---|---|
|
|
45
|
+
| User wants a chain not in `ChainKeys.*` | Adding a new chain requires SDK-level changes to `@sodax/types`/`@sodax/sdk` — out of scope for consumer code. |
|
|
46
|
+
| User wants to skip `await sodax.config.initialize()` | Explain consequences: stale defaults, no awareness of new tokens / fee parameters. Don't silently skip. |
|
|
47
|
+
| User code expects sibling-package imports (e.g. `@sodax/wallet-sdk-core` instances) | Out of scope here — consumer owns the wallet-provider implementation. Document the `I*WalletProvider` shape they need to satisfy or instruct them to install `@sodax/wallet-sdk-core` separately and refer to that package's docs. |
|
|
48
|
+
| User wants browser-extension wallet wiring inside SDK code | Not the SDK's concern. Consumer owns the wallet layer. |
|
|
49
|
+
|
|
50
|
+
## Verification protocol
|
|
51
|
+
|
|
52
|
+
Before declaring an SDK integration "done":
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 1. Type-check the consumer.
|
|
56
|
+
pnpm -C <consumer> tsc --noEmit
|
|
57
|
+
|
|
58
|
+
# 2. Confirm no leftover v1 patterns (if porting).
|
|
59
|
+
grep -rE '_MAINNET_CHAIN_ID\b|\bxChainId\b|\bSpokeChainId\b|\bSpokeProvider\b' src/
|
|
60
|
+
|
|
61
|
+
# 3. Confirm Result branching is in place.
|
|
62
|
+
grep -rE 'await sodax\.\w+\.\w+\([^)]*\)' src/ | grep -v '\.ok\|\.value\|\.error' # any SDK call without result.ok / value / error in nearby lines
|
|
63
|
+
|
|
64
|
+
# 4. Smoke-test a read flow before a signed flow.
|
|
65
|
+
# sodax.config.findSupportedTokenBySymbol(...) etc. — no wallet needed.
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Done criteria
|
|
69
|
+
|
|
70
|
+
- [ ] `await sodax.config.initialize()` runs at app startup (or before first feature call).
|
|
71
|
+
- [ ] Every `await sodax.<feature>.<method>(...)` is followed by `if (!result.ok)` branching.
|
|
72
|
+
- [ ] No `try/catch` wraps SDK calls expecting to catch `RELAY_TIMEOUT` / `EXECUTION_FAILED`.
|
|
73
|
+
- [ ] No `import` from `@sodax/sdk/dist/...`.
|
|
74
|
+
- [ ] No standalone `@sodax/types` dependency in `package.json`.
|
|
75
|
+
- [ ] Consumer typecheck (`pnpm tsc --noEmit`) is clean.
|