@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.
- package/.claude-plugin/plugin.json +18 -0
- package/AGENTS.md +83 -0
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/package.json +58 -0
- package/skills/sodax-dapp-kit/SKILL.md +129 -0
- package/skills/sodax-dapp-kit/integration/knowledge/README.md +49 -0
- package/skills/sodax-dapp-kit/integration/knowledge/ai-rules.md +80 -0
- package/skills/sodax-dapp-kit/integration/knowledge/architecture.md +276 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/README.md +29 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/auxiliary-services.md +169 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/bitcoin.md +87 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/bridge.md +91 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/dex.md +152 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/migration.md +118 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/money-market.md +144 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/staking.md +123 -0
- package/skills/sodax-dapp-kit/integration/knowledge/features/swap.md +101 -0
- package/skills/sodax-dapp-kit/integration/knowledge/quickstart.md +188 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/README.md +136 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/backend-queries.md +157 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/bitcoin.md +193 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/bridge.md +174 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/dex.md +204 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/invalidations.md +115 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/migration.md +212 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/money-market.md +207 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/mutation-error-handling.md +118 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/observability.md +93 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/setup.md +168 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/staking.md +202 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/swap.md +272 -0
- package/skills/sodax-dapp-kit/integration/knowledge/recipes/wallet-connectivity.md +128 -0
- package/skills/sodax-dapp-kit/integration/knowledge/reference/README.md +12 -0
- package/skills/sodax-dapp-kit/integration/knowledge/reference/glossary.md +190 -0
- package/skills/sodax-dapp-kit/integration/knowledge/reference/hooks-index.md +190 -0
- package/skills/sodax-dapp-kit/integration/knowledge/reference/public-api.md +110 -0
- package/skills/sodax-dapp-kit/integration/knowledge/reference/querykey-conventions.md +179 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/README.md +60 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/ai-rules.md +81 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/hook-signatures.md +233 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/querykey-conventions.md +108 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/result-handling.md +211 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/breaking-changes/sdk-leakage.md +167 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/checklist.md +89 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/README.md +34 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/auxiliary-services.md +114 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/bitcoin.md +88 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/bridge.md +160 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/dex.md +101 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/migration.md +120 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/money-market.md +139 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/staking.md +109 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/features/swap.md +133 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/recipes.md +185 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/README.md +15 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/deleted-hooks.md +110 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/error-shape-crosswalk.md +144 -0
- package/skills/sodax-dapp-kit/migration-v1-to-v2/knowledge/reference/renamed-hooks.md +68 -0
- package/skills/sodax-sdk/SKILL.md +140 -0
- package/skills/sodax-sdk/backend-api/SKILL.md +52 -0
- package/skills/sodax-sdk/bridge/SKILL.md +49 -0
- package/skills/sodax-sdk/dex/SKILL.md +50 -0
- package/skills/sodax-sdk/integration/knowledge/README.md +43 -0
- package/skills/sodax-sdk/integration/knowledge/ai-rules.md +75 -0
- package/skills/sodax-sdk/integration/knowledge/architecture.md +517 -0
- package/skills/sodax-sdk/integration/knowledge/chain-specifics.md +189 -0
- package/skills/sodax-sdk/integration/knowledge/features/README.md +21 -0
- package/skills/sodax-sdk/integration/knowledge/features/backend-api.md +81 -0
- package/skills/sodax-sdk/integration/knowledge/features/bridge.md +172 -0
- package/skills/sodax-sdk/integration/knowledge/features/dex.md +182 -0
- package/skills/sodax-sdk/integration/knowledge/features/migration.md +181 -0
- package/skills/sodax-sdk/integration/knowledge/features/money-market.md +198 -0
- package/skills/sodax-sdk/integration/knowledge/features/partner.md +63 -0
- package/skills/sodax-sdk/integration/knowledge/features/recovery.md +50 -0
- package/skills/sodax-sdk/integration/knowledge/features/staking.md +171 -0
- package/skills/sodax-sdk/integration/knowledge/features/swap.md +273 -0
- package/skills/sodax-sdk/integration/knowledge/quickstart.md +213 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/README.md +21 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/backend-server-init.md +69 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/chain-key-narrowing.md +65 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/gas-estimation.md +33 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/initialize-sodax.md +78 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/raw-tx-flow.md +71 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/result-and-errors.md +104 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/signed-tx-flow.md +46 -0
- package/skills/sodax-sdk/integration/knowledge/recipes/testing.md +101 -0
- package/skills/sodax-sdk/integration/knowledge/reference/README.md +18 -0
- package/skills/sodax-sdk/integration/knowledge/reference/chain-keys.md +67 -0
- package/skills/sodax-sdk/integration/knowledge/reference/error-codes.md +165 -0
- package/skills/sodax-sdk/integration/knowledge/reference/glossary.md +32 -0
- package/skills/sodax-sdk/integration/knowledge/reference/public-api.md +138 -0
- package/skills/sodax-sdk/integration/knowledge/reference/wallet-providers.md +62 -0
- package/skills/sodax-sdk/migration/SKILL.md +65 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/README.md +58 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/ai-rules.md +76 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/breaking-changes/architecture.md +344 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/breaking-changes/result-and-errors.md +363 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/breaking-changes/type-system.md +341 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/checklist.md +67 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/README.md +37 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/backend-api.md +92 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/bridge.md +128 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/dex.md +143 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/migration.md +151 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/money-market.md +214 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/partner.md +59 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/recovery.md +35 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/staking.md +143 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/features/swap.md +198 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/recipes.md +350 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/README.md +18 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/deleted-exports.md +127 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/error-code-crosswalk.md +104 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/return-shapes.md +49 -0
- package/skills/sodax-sdk/migration-v1-to-v2/knowledge/reference/sodax-config.md +145 -0
- package/skills/sodax-sdk/money-market/SKILL.md +52 -0
- package/skills/sodax-sdk/partner/SKILL.md +51 -0
- package/skills/sodax-sdk/recovery/SKILL.md +49 -0
- package/skills/sodax-sdk/staking/SKILL.md +49 -0
- package/skills/sodax-sdk/swap/SKILL.md +67 -0
- package/skills/sodax-wallet-sdk-core/SKILL.md +114 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/README.md +108 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/ai-rules.md +141 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/architecture.md +212 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/README.md +22 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/bitcoin.md +103 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/evm.md +102 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/icon.md +88 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/injective.md +92 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/near.md +92 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/solana.md +104 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/stacks.md +91 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/stellar.md +95 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/features/sui.md +96 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/quickstart.md +259 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/README.md +15 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/bridge-to-sdk.md +145 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/defaults-and-overrides.md +159 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/library-exports.md +129 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/setup-browser-extension.md +137 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/setup-private-key.md +115 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/sign-and-broadcast.md +201 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/recipes/testing.md +163 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/README.md +13 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/chain-support.md +65 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/glossary.md +28 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/interfaces.md +131 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/provider-classes.md +54 -0
- package/skills/sodax-wallet-sdk-core/integration/knowledge/reference/public-api.md +128 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/README.md +84 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/ai-rules.md +139 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/README.md +14 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/base-wallet-provider.md +52 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/defaults-config.md +57 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/folder-layout.md +99 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/breaking-changes/library-exports.md +58 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/checklist.md +62 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/recipes/README.md +12 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/recipes/adopt-defaults.md +84 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/recipes/adopt-library-exports.md +99 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/README.md +12 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/added-fields.md +71 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/deleted-exports.md +35 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/renamed-symbols.md +31 -0
- package/skills/sodax-wallet-sdk-core/migration-v1-to-v2/knowledge/reference/return-shapes.md +23 -0
- package/skills/sodax-wallet-sdk-react/SKILL.md +154 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/README.md +103 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/ai-rules.md +136 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/architecture.md +185 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/01-minimal-evm.tsx +75 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/02-multi-chain-modal.tsx +169 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/03-nextjs-app-router.tsx +99 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/04-walletconnect-setup.tsx +89 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/examples/README.md +29 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/batch-operations.md +224 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/bridge-to-sdk.md +165 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/chain-detection.md +259 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/connect-button.md +159 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/multi-chain-modal.md +203 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/setup.md +163 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/sign-message.md +138 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/sub-path-imports.md +97 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/switch-chain.md +144 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/recipes/walletconnect-setup.md +139 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/api-surface.md +176 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/chain-support.md +79 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/connectors.md +75 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/hooks.md +212 -0
- package/skills/sodax-wallet-sdk-react/integration/knowledge/reference/wallet-brands.md +107 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/README.md +49 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/ai-rules.md +144 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/breaking-changes.md +310 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/checklist.md +159 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/connect-button.md +170 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/multi-chain-modal.md +245 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/ssr-setup.md +165 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/recipes/walletconnect-migration.md +170 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/components.md +75 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/config.md +339 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/hooks.md +336 -0
- package/skills/sodax-wallet-sdk-react/migration-v1-to-v2/knowledge/reference/imports.md +158 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Partner migration — v1 → v2
|
|
2
|
+
|
|
3
|
+
Pure-SDK migration playbook for `PartnerService`.
|
|
4
|
+
|
|
5
|
+
Pair: [`features/partner.md`](../../../integration/knowledge/features/partner.md).
|
|
6
|
+
|
|
7
|
+
## TL;DR
|
|
8
|
+
|
|
9
|
+
Standard pattern. Drop `spokeProvider`; pass `walletProvider`. Add `srcChainKey` + `srcAddress` to claim params. v1's 5 typed errors collapse into `SodaxError<C>` with `feature: 'partner'`.
|
|
10
|
+
|
|
11
|
+
## Type / symbol cheat sheet
|
|
12
|
+
|
|
13
|
+
| Type | v1 shape | v2 shape | Notes |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| Partner action params | non-generic | now generic `<K>` with `srcChainKey`, `srcAddress` | |
|
|
16
|
+
| Partner errors (5 types) | `PartnerFeeClaimError<...>` and 4 siblings | `SodaxError<C>` with `feature: 'partner'` | All 5 v1 typed errors collapse. |
|
|
17
|
+
|
|
18
|
+
## v1 → v2 error code crosswalk
|
|
19
|
+
|
|
20
|
+
All 5 v1 partner error codes map to `EXECUTION_FAILED` with `error.context.action` discriminating between the operations.
|
|
21
|
+
|
|
22
|
+
## Per-method delta
|
|
23
|
+
|
|
24
|
+
Partner operations live on `sodax.partners.feeClaim` (a `PartnerFeeClaimService`), not directly on `sodax.partners`. v1 method names also changed:
|
|
25
|
+
|
|
26
|
+
```diff
|
|
27
|
+
- await sodax.partners.claimFees({ /* … */ }, spokeProvider);
|
|
28
|
+
+ // Approve once, then configure auto-swap preference, then run swaps.
|
|
29
|
+
+ // Full method list lives in integration/features/partner.md.
|
|
30
|
+
+ const approved = await sodax.partners.feeClaim.isTokenApproved({ token, srcAddress });
|
|
31
|
+
+ if (approved.ok && !approved.value) {
|
|
32
|
+
+ await sodax.partners.feeClaim.approveToken({
|
|
33
|
+
+ params: { token, amount },
|
|
34
|
+
+ raw: false,
|
|
35
|
+
+ walletProvider,
|
|
36
|
+
+ });
|
|
37
|
+
+ }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Pitfalls
|
|
41
|
+
|
|
42
|
+
1. **Partner methods moved.** They live on `sodax.partners.feeClaim`, not `sodax.partners` directly. The parent only exposes `feeClaim` and `config` as public fields.
|
|
43
|
+
2. **All 5 v1 partner errors collapse to `feature: 'partner'`.** Even though they share the `EXECUTION_FAILED` code with every other feature.
|
|
44
|
+
|
|
45
|
+
## Verification
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm -C <your-app-dir> checkTs
|
|
49
|
+
|
|
50
|
+
# Targeted scans:
|
|
51
|
+
grep -rE "spokeProvider:\s*\w+|isPartnerError\b|PartnerFeeClaimError\b" src/
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Cross-references
|
|
55
|
+
|
|
56
|
+
- v2 partner usage: [`features/partner.md`](../../../integration/knowledge/features/partner.md).
|
|
57
|
+
- Stuck-asset recovery migration (separate service, new in v2): [`./recovery.md`](recovery.md).
|
|
58
|
+
- Backend API migration (the load-bearing `Result`-wrapping change): [`./backend-api.md`](backend-api.md).
|
|
59
|
+
- Result/error model: [`../breaking-changes/result-and-errors.md`](../breaking-changes/result-and-errors.md).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Recovery migration — v1 → v2
|
|
2
|
+
|
|
3
|
+
Pure-SDK migration playbook for `RecoveryService`.
|
|
4
|
+
|
|
5
|
+
Pair: [`features/recovery.md`](../../../integration/knowledge/features/recovery.md).
|
|
6
|
+
|
|
7
|
+
## TL;DR
|
|
8
|
+
|
|
9
|
+
**`RecoveryService` is new in v2.** No v1 equivalent — there's no migration to do for code that didn't exist before. This file exists so the v1 → v2 audit doesn't miss the addition.
|
|
10
|
+
|
|
11
|
+
If you have v1 code that worked around the absence (e.g. manually walked the hub wallet abstraction to find stuck assets), replace it with `fetchHubAssetBalances` + `withdrawHubAsset`:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const balances = await sodax.recovery.fetchHubAssetBalances({ /* user / hub-wallet args */ });
|
|
15
|
+
if (balances.ok && balances.value.length > 0) {
|
|
16
|
+
await sodax.recovery.withdrawHubAsset({
|
|
17
|
+
params: { /* hub-asset address, amount, destination spoke chain + address */ },
|
|
18
|
+
raw: false,
|
|
19
|
+
walletProvider: sonicWp,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
See [`features/recovery.md`](../../../integration/knowledge/features/recovery.md) for the full method signatures and error codes.
|
|
25
|
+
|
|
26
|
+
## Pitfalls
|
|
27
|
+
|
|
28
|
+
1. **Recovery is not a replacement for real error handling.** Use it after investigating why the original cross-chain operation failed — relay timeouts may resolve on retry; structural failures need fixing first.
|
|
29
|
+
|
|
30
|
+
## Cross-references
|
|
31
|
+
|
|
32
|
+
- v2 recovery usage: [`features/recovery.md`](../../../integration/knowledge/features/recovery.md).
|
|
33
|
+
- Partner migration (separate service): [`./partner.md`](partner.md).
|
|
34
|
+
- Backend API migration (separate service): [`./backend-api.md`](backend-api.md).
|
|
35
|
+
- Result/error model: [`../breaking-changes/result-and-errors.md`](../breaking-changes/result-and-errors.md).
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Staking migration — v1 → v2
|
|
2
|
+
|
|
3
|
+
Pure-SDK migration playbook for `StakingService`.
|
|
4
|
+
|
|
5
|
+
Pair: [`features/staking.md`](../../../integration/knowledge/features/staking.md).
|
|
6
|
+
|
|
7
|
+
## TL;DR
|
|
8
|
+
|
|
9
|
+
1. **Drop `spokeProvider` from every params object.** Pass `walletProvider` directly into the SDK call.
|
|
10
|
+
2. **Add `srcChainKey` + `srcAddress` to every `*Params<K>`.** `account` field is renamed to `srcAddress`.
|
|
11
|
+
3. **All 5 staking actions are cross-chain.** Even though staking writes happen on the hub, every SDK method (`stake`, `unstake`, `instantUnstake`, `claim`, `cancelUnstake`) accepts `srcChainKey: K extends SpokeChainKey` and relays spoke→hub via `relayTxAndWaitPacket`. **Return shape is always `Result<TxHashPair>`.**
|
|
12
|
+
4. **`approve` is an exception — it returns `Result<TxReturnType<K, false>>` (single hash).** Approve is spoke-only (no relay) — it just spends ERC20 allowance on the source chain.
|
|
13
|
+
5. **Approve and allowance are action-discriminated.** `staking.approve` and `staking.isAllowanceValid` take a `StakingParamsUnion` discriminated by `params.action`. `'stake'` approves SODA; `'unstake'` and `'instantUnstake'` approve xSoda.
|
|
14
|
+
6. **Info getter signatures changed.** v1 took `spokeProvider`; v2 takes `(srcAddress, srcChainKey)`. The SDK derives the hub wallet internally.
|
|
15
|
+
7. **Hub-only / amount-only reads have no chain context.** `getStakingConfig()`, `getStakeRatio(amount)`, `getInstantUnstakeRatio(amount)`, `getConvertedAssets(amount)` — none accept `srcChainKey`. (Take `bigint` amount directly, not an object.) `getStakeRatio` returns `Result<[xSodaAmount, previewDepositAmount]>` (a tuple — both are bigints).
|
|
16
|
+
8. **Errors → `SodaxError` + `Result<T>`.** v1's `StakingError<StakingErrorCode>` is gone.
|
|
17
|
+
|
|
18
|
+
## Type / symbol cheat sheet
|
|
19
|
+
|
|
20
|
+
### Field-level renames
|
|
21
|
+
|
|
22
|
+
| Type | v1 shape | v2 shape | Notes |
|
|
23
|
+
|---|---|---|---|
|
|
24
|
+
| `StakeParams` | `{ amount, account, minReceive, action: 'stake' }` | `{ srcChainKey, srcAddress, amount, minReceive, action: 'stake' }` | Now generic `<K>`. `account` → `srcAddress`. |
|
|
25
|
+
| `UnstakeParams` | `{ amount, account, action: 'unstake' }` | `{ srcChainKey, srcAddress, amount, action: 'unstake' }` | |
|
|
26
|
+
| `InstantUnstakeParams` | `{ amount, minAmount, account, action: 'instantUnstake' }` | `{ srcChainKey, srcAddress, amount, minAmount, action: 'instantUnstake' }` | |
|
|
27
|
+
| `ClaimParams` | `{ requestId, amount, action: 'claim' }` | `{ srcChainKey, srcAddress, requestId, amount, action: 'claim' }` | Adds chain context. |
|
|
28
|
+
| `CancelUnstakeParams` | `{ requestId, action: 'cancelUnstake' }` | `{ srcChainKey, srcAddress, requestId, action: 'cancelUnstake' }` | Adds chain context. |
|
|
29
|
+
| `getStakingInfo` (read) | `(spokeProvider) => Promise<StakingInfo>` | `getStakingInfoFromSpoke(srcAddress, srcChainKey) => Promise<Result<StakingInfo>>` (or `getStakingInfo(hubAddress)` if you already have the hub address) | v1 took a `spokeProvider` and resolved internally; v2 splits this into two public reads — `getStakingInfoFromSpoke` for spoke-side resolution, `getStakingInfo` for direct hub-side reads. Both return `Result`. |
|
|
30
|
+
| `getUnstakingInfo` (read) | `(userAddress, spokeProvider)` | `(srcAddress, srcChainKey)` | v1 ignored `userAddress`; v2 reads it for real. |
|
|
31
|
+
| `getUnstakingInfoWithPenalty` (read) | new (v2) | `(srcAddress, srcChainKey) => Promise<Result<UnstakingInfo & { requestsWithPenalty: UnstakeRequestWithPenalty[] }>>` | Wraps `getUnstakingInfo`'s base shape with a penalty-augmented request list. |
|
|
32
|
+
|
|
33
|
+
### Deleted symbols
|
|
34
|
+
|
|
35
|
+
- `StakingError<StakingErrorCode>` and `isStakingError` — replaced by `SodaxError<C>` + `feature: 'staking'`.
|
|
36
|
+
- `spokeProvider instanceof SonicSpokeProvider` runtime checks — replace with `isHubChainKeyType(chainKey)` from `@sodax/sdk`.
|
|
37
|
+
|
|
38
|
+
### Renamed / re-shaped (not deleted)
|
|
39
|
+
|
|
40
|
+
- v1 `getStakingInfo(spokeProvider)` had implicit spoke-side resolution. v2 surfaces two public reads instead:
|
|
41
|
+
- `getStakingInfoFromSpoke(srcAddress, srcChainKey)` — for the spoke-side flow; derives the hub wallet via `HubService.getUserHubWalletAddress` internally.
|
|
42
|
+
- `getStakingInfo(hubAddress: Address)` — direct hub-side read, kept public for when the hub address is already known.
|
|
43
|
+
|
|
44
|
+
### v1 → v2 error code crosswalk (staking-specific)
|
|
45
|
+
|
|
46
|
+
| v1 `StakingErrorCode` | v2 code + context |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `STAKE_FAILED` | `EXECUTION_FAILED` (`action: 'stake'`) |
|
|
49
|
+
| `UNSTAKE_FAILED` | `EXECUTION_FAILED` (`action: 'unstake'`) |
|
|
50
|
+
| `INSTANT_UNSTAKE_FAILED` | `EXECUTION_FAILED` (`action: 'instantUnstake'`) |
|
|
51
|
+
| `CLAIM_FAILED` | `EXECUTION_FAILED` (`action: 'claim'`) |
|
|
52
|
+
| `CANCEL_UNSTAKE_FAILED` | `EXECUTION_FAILED` (`action: 'cancelUnstake'`) |
|
|
53
|
+
| `GET_STAKING_INFO_FAILED` | `LOOKUP_FAILED` (`method: 'getStakingInfo'` or `'getStakingInfoFromSpoke'`) |
|
|
54
|
+
| `GET_UNSTAKING_INFO_FAILED` | `LOOKUP_FAILED` (`method: 'getUnstakingInfo'`) |
|
|
55
|
+
| `GET_STAKING_CONFIG_FAILED` | `LOOKUP_FAILED` (`method: 'getStakingConfig'`) |
|
|
56
|
+
| `GET_STAKE_RATIO_FAILED` | `LOOKUP_FAILED` (`method: 'getStakeRatio'`) |
|
|
57
|
+
|
|
58
|
+
## Per-method delta
|
|
59
|
+
|
|
60
|
+
### `stake`
|
|
61
|
+
|
|
62
|
+
```diff
|
|
63
|
+
- await sodax.staking.stake({ amount, account, minReceive, action: 'stake' }, spokeProvider);
|
|
64
|
+
+ const result = await sodax.staking.stake({
|
|
65
|
+
+ params: {
|
|
66
|
+
+ srcChainKey: ChainKeys.ARBITRUM_MAINNET,
|
|
67
|
+
+ srcAddress: '0x…',
|
|
68
|
+
+ amount, minReceive,
|
|
69
|
+
+ action: 'stake',
|
|
70
|
+
+ },
|
|
71
|
+
+ raw: false,
|
|
72
|
+
+ walletProvider,
|
|
73
|
+
+ });
|
|
74
|
+
+ if (!result.ok) return;
|
|
75
|
+
+ const { srcChainTxHash, dstChainTxHash } = result.value;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `unstake` / `instantUnstake` / `claim` / `cancelUnstake`
|
|
79
|
+
|
|
80
|
+
Same shape as stake. `account` → `srcAddress`. `requestId` (claim, cancelUnstake) is unchanged.
|
|
81
|
+
|
|
82
|
+
### `approve` / `isAllowanceValid` — action-discriminated
|
|
83
|
+
|
|
84
|
+
```diff
|
|
85
|
+
- await sodax.staking.approveStake({ amount, account, ... }, spokeProvider);
|
|
86
|
+
+ await sodax.staking.approve({
|
|
87
|
+
+ params: { srcChainKey, srcAddress, amount, action: 'stake' },
|
|
88
|
+
+ raw: false,
|
|
89
|
+
+ walletProvider,
|
|
90
|
+
+ });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
For `isAllowanceValid`:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const result = await sodax.staking.isAllowanceValid({
|
|
97
|
+
params: { srcChainKey, srcAddress, amount, action: 'stake' },
|
|
98
|
+
raw: true, // read-only
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Info reads
|
|
103
|
+
|
|
104
|
+
```diff
|
|
105
|
+
- const info = await sodax.staking.getStakingInfo(spokeProvider);
|
|
106
|
+
+ const result = await sodax.staking.getStakingInfoFromSpoke(srcAddress, srcChainKey);
|
|
107
|
+
+ if (!result.ok) return;
|
|
108
|
+
+ const info = result.value;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
For amount-only reads (no chain context):
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const result = await sodax.staking.getStakeRatio(parseUnits('100', 18));
|
|
115
|
+
if (result.ok) {
|
|
116
|
+
const [xSodaAmount, previewDepositAmount] = result.value;
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Pitfalls
|
|
121
|
+
|
|
122
|
+
Cross-cutting traps (Result destructuring, error-model migration, srcChain/dstChain renames, etc.) live in [`../ai-rules.md`](../ai-rules.md). The list below is feature-specific — typecheck fingerprints, return-shape diffs, and gotchas unique to this feature.
|
|
123
|
+
|
|
124
|
+
1. **Wrong return shape for actions.** Treating `stake/unstake/etc.` as returning `Result<TxReturnType<K, false>>` (single hash) is **wrong** — they return `Result<TxHashPair>` because they always relay spoke→hub. Only `approve` returns a single hash.
|
|
125
|
+
2. **Forgetting `raw: true` on the allowance query.** TypeScript error: `Property 'walletProvider' is missing`. `isAllowanceValid` requires `WalletProviderSlot<K, Raw>`; `raw: false` would force a wallet provider. Use `raw: true` for read-only.
|
|
126
|
+
3. **Forgetting to remove the v1 `account` field from params.** v2 uses `srcAddress`. If both are set, TypeScript rejects the literal.
|
|
127
|
+
4. **Confusing `getStakingInfo` and `getStakingInfoFromSpoke`.** Both are public in v2 — pick by which address you have. `getStakingInfo(hubAddress: Address)` reads the hub wallet directly; `getStakingInfoFromSpoke(srcAddress, srcChainKey)` derives the hub wallet from a spoke address via `HubService.getUserHubWalletAddress`, then delegates. Passing a spoke address into `getStakingInfo` returns wrong data (no hub-wallet resolution); always use the spoke variant when starting from a spoke address.
|
|
128
|
+
5. **`UnstakingInfo` no longer accepts `userAddress` separately.** v1 took both `spokeProvider` and `userAddress` props but ignored `userAddress` inside. v2 takes `srcAddress` and uses it.
|
|
129
|
+
|
|
130
|
+
## Verification
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
pnpm -C <your-app-dir> checkTs
|
|
134
|
+
|
|
135
|
+
# Targeted scans:
|
|
136
|
+
grep -rE "spokeProvider:\s*\w+|account:\s*[`'][^`']+['\"`]" src/ # leftover v1 patterns
|
|
137
|
+
grep -rE "isStakingError\b|StakingError\b" src/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Cross-references
|
|
141
|
+
|
|
142
|
+
- v2 staking usage: [`features/staking.md`](../../../integration/knowledge/features/staking.md).
|
|
143
|
+
- Cross-cutting prerequisites listed in [`../README.md`](../README.md).
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Swap migration — v1 → v2
|
|
2
|
+
|
|
3
|
+
Pure-SDK migration playbook for `SwapService`.
|
|
4
|
+
|
|
5
|
+
Pair: [`features/swap.md`](../../../integration/knowledge/features/swap.md).
|
|
6
|
+
|
|
7
|
+
## TL;DR
|
|
8
|
+
|
|
9
|
+
1. **Drop the `*SpokeProvider` argument.** Pass `walletProvider` directly into the SDK call payload alongside `params` and `raw: false`.
|
|
10
|
+
2. **Add `raw: false` (or `raw: true`) to every call shape.** Without it, TypeScript can't pick a branch of `WalletProviderSlot` and rejects `walletProvider`.
|
|
11
|
+
3. **Field renames on `CreateIntentParams<K>` and `CreateLimitOrderParams<K>`:**
|
|
12
|
+
- `srcChain` → `srcChainKey`
|
|
13
|
+
- `dstChain` → `dstChainKey`
|
|
14
|
+
- **`Intent.srcChain` / `Intent.dstChain` are unchanged** (read shape) — they're `IntentRelayChainId` (bigint).
|
|
15
|
+
4. **`CreateIntentResult` shape changed.** v1 was a tuple `[spokeTxHash, intent, relayData]`; v2 is an object `{ tx, intent, relayData }`. Destructure accordingly.
|
|
16
|
+
5. **`SubmitSwapTxRequest.srcChainId` → `srcChainKey`.** And `relayData` field on the request expects a **string** (`relayData.payload`), not the `RelayExtraData` object.
|
|
17
|
+
6. **Errors → `SodaxError` + `Result<T>`.** v1's `IntentError<IntentErrorCode>` is gone. Branch on `result.ok`; use `(error.feature, error.code)` for discrimination.
|
|
18
|
+
|
|
19
|
+
## Type / symbol cheat sheet
|
|
20
|
+
|
|
21
|
+
### Field-level renames
|
|
22
|
+
|
|
23
|
+
| Type | v1 field | v2 field | Notes |
|
|
24
|
+
|---|---|---|---|
|
|
25
|
+
| `CreateIntentParams` (request) | `srcChain`, `dstChain` | `srcChainKey`, `dstChainKey` | Now generic: `CreateIntentParams<K extends SpokeChainKey>`. |
|
|
26
|
+
| `CreateLimitOrderParams` (request) | `srcChain`, `dstChain` | `srcChainKey`, `dstChainKey` | `Omit<CreateIntentParams<K>, 'deadline'>`. |
|
|
27
|
+
| `SubmitSwapTxRequest` (backend req) | `srcChainId` | `srcChainKey` | And `relayData: string` (was the object in v1). |
|
|
28
|
+
| `Intent` (read shape) | `srcChain`, `dstChain` | **unchanged** | `IntentRelayChainId` (bigint). Don't grep-replace blindly. |
|
|
29
|
+
| `XToken` | `xChainId` | `chainKey` | Type renamed from `Token` → `XToken`. |
|
|
30
|
+
| `CreateIntentResult` | tuple `[spokeTxHash, intent, relayData]` | object `{ tx, intent, relayData }` | Generic: `CreateIntentResult<K, Raw>`. |
|
|
31
|
+
|
|
32
|
+
### Deleted symbols
|
|
33
|
+
|
|
34
|
+
- The `SpokeProvider` union and per-chain `*SpokeProvider` classes — gone. v2 takes `walletProvider` directly. See [`../breaking-changes/architecture.md`](../breaking-changes/architecture.md) § 1.
|
|
35
|
+
- `IntentError<IntentErrorCode>` and `isIntentError` / `isIntentPostExecutionFailedError` / `isIntentSubmitTxFailedError` type guards. Replaced by `isSodaxError` + feature/code discrimination.
|
|
36
|
+
- `CustomProvider` (Hana wallet window typedecl) — declare `unknown` or import directly from the wallet vendor.
|
|
37
|
+
- `hubAssets` global — gone. `XToken.vault` and `XToken.hubAsset` baked in.
|
|
38
|
+
|
|
39
|
+
### v1 → v2 error code crosswalk (swap-specific)
|
|
40
|
+
|
|
41
|
+
| v1 `IntentErrorCode` | v2 `SodaxErrorCode` + context |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `CREATE_INTENT_FAILED` | `INTENT_CREATION_FAILED` (`action: 'createIntent'`) |
|
|
44
|
+
| `CREATE_LIMIT_ORDER_FAILED` | `INTENT_CREATION_FAILED` (`action: 'createLimitOrder'`) |
|
|
45
|
+
| `POST_EXECUTION_FAILED` | `EXECUTION_FAILED` (`action: 'swap'`, `phase: 'postExecution'`) |
|
|
46
|
+
| `SOLVER_API_ERROR` | `EXTERNAL_API_ERROR` (`api: 'solver'`, with `solverCode`/`solverDetail` on context) |
|
|
47
|
+
| `SIMULATION_FAILED` | `EXECUTION_FAILED` (`phase: 'execution'`) |
|
|
48
|
+
| `SUBMIT_TX_FAILED` (relay) | `TX_SUBMIT_FAILED` (`relayCode: 'SUBMIT_TX_FAILED'`) |
|
|
49
|
+
| `RELAY_TIMEOUT` | `RELAY_TIMEOUT` (unchanged code; still on `relayCode`) |
|
|
50
|
+
|
|
51
|
+
## Per-method delta
|
|
52
|
+
|
|
53
|
+
### `swap`
|
|
54
|
+
|
|
55
|
+
```diff
|
|
56
|
+
- await sodax.swaps.swap({
|
|
57
|
+
- intentParams,
|
|
58
|
+
- spokeProvider: sourceSpokeProvider,
|
|
59
|
+
- });
|
|
60
|
+
+ const result = await sodax.swaps.swap({
|
|
61
|
+
+ params: intentParams,
|
|
62
|
+
+ raw: false,
|
|
63
|
+
+ walletProvider: sourceWalletProvider,
|
|
64
|
+
+ });
|
|
65
|
+
+ if (!result.ok) return;
|
|
66
|
+
+ const { spokeTxHash, intent, relayData } = result.value;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `createIntent`
|
|
70
|
+
|
|
71
|
+
```diff
|
|
72
|
+
- const [spokeTxHash, intent, relayData] = await sodax.swaps.createIntent({
|
|
73
|
+
- intentParams,
|
|
74
|
+
- spokeProvider: sourceSpokeProvider,
|
|
75
|
+
- });
|
|
76
|
+
+ const result = await sodax.swaps.createIntent({
|
|
77
|
+
+ params: intentParams,
|
|
78
|
+
+ raw: false,
|
|
79
|
+
+ walletProvider: sourceWalletProvider,
|
|
80
|
+
+ });
|
|
81
|
+
+ if (!result.ok) return;
|
|
82
|
+
+ const { tx: spokeTxHash, intent, relayData } = result.value;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### `createLimitOrder`
|
|
86
|
+
|
|
87
|
+
Same as `createIntent` shape (with `CreateLimitOrderParams`). v1 took `{ limitOrderParams, spokeProvider }`; v2 takes `{ params, raw: false, walletProvider }`.
|
|
88
|
+
|
|
89
|
+
### `cancelIntent` / `cancelLimitOrder`
|
|
90
|
+
|
|
91
|
+
```diff
|
|
92
|
+
- await sodax.swaps.cancelIntent({ srcChain, intent, spokeProvider });
|
|
93
|
+
+ await sodax.swaps.cancelIntent({
|
|
94
|
+
+ params: { srcChainKey, intent },
|
|
95
|
+
+ raw: false,
|
|
96
|
+
+ walletProvider,
|
|
97
|
+
+ });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `approve` / `isAllowanceValid`
|
|
101
|
+
|
|
102
|
+
v1: `await sodax.swaps.approve({ intentParams, spokeProvider })`.
|
|
103
|
+
v2: `await sodax.swaps.approve({ params: intentParams, raw: false, walletProvider })`.
|
|
104
|
+
|
|
105
|
+
For `isAllowanceValid` in **read-only** flows (e.g. UI polling), use `raw: true` to skip the wallet-provider requirement:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const result = await sodax.swaps.isAllowanceValid({ params, raw: true });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The underlying read doesn't consult the wallet provider; `raw: true` is the contract for read-only access.
|
|
112
|
+
|
|
113
|
+
### Backend submit-tx (`SubmitSwapTxRequest`)
|
|
114
|
+
|
|
115
|
+
```diff
|
|
116
|
+
const request: SubmitSwapTxRequest = {
|
|
117
|
+
txHash: spokeTxHash as string,
|
|
118
|
+
- srcChainId: sourceChain,
|
|
119
|
+
+ srcChainKey: src.chain,
|
|
120
|
+
walletAddress: sourceAccount.address ?? '',
|
|
121
|
+
intent: swapIntentData,
|
|
122
|
+
- relayData, // was the RelayExtraData object
|
|
123
|
+
+ relayData: relayData.payload, // now a string
|
|
124
|
+
};
|
|
125
|
+
const submitResult = await sodax.backendApi.submitSwapTx(request);
|
|
126
|
+
if (!submitResult.ok) return;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Worked example — `handleSubmitTxSwap` flow
|
|
130
|
+
|
|
131
|
+
```diff
|
|
132
|
+
const handleSubmitTxSwap = async (intentOrderPayload: CreateIntentParams) => {
|
|
133
|
+
- if (!sourceProvider) return;
|
|
134
|
+
+ if (!sourceWalletProvider) return;
|
|
135
|
+
- const createIntentResult = await sodax.swaps.createIntent({
|
|
136
|
+
- intentParams: intentOrderPayload,
|
|
137
|
+
- spokeProvider: sourceProvider,
|
|
138
|
+
- });
|
|
139
|
+
+ const createIntentResult = await sodax.swaps.createIntent({
|
|
140
|
+
+ params: intentOrderPayload,
|
|
141
|
+
+ raw: false,
|
|
142
|
+
+ walletProvider: sourceWalletProvider,
|
|
143
|
+
+ });
|
|
144
|
+
if (!createIntentResult.ok) return;
|
|
145
|
+
- const [spokeTxHash, intent, relayData] = createIntentResult.value;
|
|
146
|
+
+ const { tx: spokeTxHash, intent, relayData } = createIntentResult.value;
|
|
147
|
+
const swapIntentData: SwapIntentData = {
|
|
148
|
+
/* … */
|
|
149
|
+
- srcChain: Number(intent.srcChain), // Intent.srcChain still on read shape
|
|
150
|
+
- dstChain: Number(intent.dstChain), // Intent.dstChain still on read shape
|
|
151
|
+
+ srcChain: Number(intent.srcChain), // unchanged — Intent shape kept these
|
|
152
|
+
+ dstChain: Number(intent.dstChain),
|
|
153
|
+
};
|
|
154
|
+
const request: SubmitSwapTxRequest = {
|
|
155
|
+
txHash: spokeTxHash as string,
|
|
156
|
+
- srcChainId: sourceChain,
|
|
157
|
+
+ srcChainKey: src.chain,
|
|
158
|
+
walletAddress: sourceAccount.address ?? '',
|
|
159
|
+
intent: swapIntentData,
|
|
160
|
+
- relayData,
|
|
161
|
+
+ relayData: relayData.payload,
|
|
162
|
+
};
|
|
163
|
+
- await submitSwapTx(request);
|
|
164
|
+
+ const submitResult = await sodax.backendApi.submitSwapTx(request);
|
|
165
|
+
+ if (!submitResult.ok) return;
|
|
166
|
+
};
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Pitfalls
|
|
170
|
+
|
|
171
|
+
Cross-cutting traps (Result destructuring, error-model migration, srcChain/dstChain renames, etc.) live in [`../ai-rules.md`](../ai-rules.md). The list below is feature-specific — typecheck fingerprints, return-shape diffs, and gotchas unique to this feature.
|
|
172
|
+
|
|
173
|
+
1. **Over-broad regex on `srcChain` / `dstChain`.** Request types renamed; `Intent` (read shape) didn't. Distinguish "I'm building a request" from "I'm reading an intent."
|
|
174
|
+
2. **`createIntent` success shape changed from tuple to object.** `{ tx, intent, relayData }`, not `[spokeTxHash, intent, relayData]`.
|
|
175
|
+
3. **`relayData` on `SubmitSwapTxRequest` is a `string`.** It's `relayData.payload`, not the full `RelayExtraData` object.
|
|
176
|
+
4. **`spokeTxHash` is `TxReturnType<K, false>`, not necessarily `string`.** For most chains it's a string already, but the SDK type is broader. Cast at the boundary when passing to APIs that strictly want `string`: `txHash: spokeTxHash as string`.
|
|
177
|
+
5. **`Intent.deadline` is `bigint`.** `Math.floor(Date.now() / 1000) + 60 * 5` returns a number; wrap in `BigInt(...)`.
|
|
178
|
+
6. **`IntentResponse.srcChain` / `dstChain` from the backend are `IntentRelayChainId` (number/bigint), not chain keys.** Convert via `sodax.config.getSpokeChainKeyFromIntentRelayChainId(BigInt(intent.dstChain))` when displaying.
|
|
179
|
+
7. **`hubAssets` is gone.** Anything that walked `hubAssets[chainId]` for vault lookup must use `XToken.vault` (now baked in) or `sodax.config.getOriginalAssetAddress()`.
|
|
180
|
+
8. **`SodaxConfig.swaps` vs `.solver`.** v1 mixed solver endpoints under `swaps`; v2 splits — `swaps` for supported tokens, `solver` for endpoints. See [`../breaking-changes/architecture.md`](../breaking-changes/architecture.md) Appendix B.
|
|
181
|
+
|
|
182
|
+
## Verification
|
|
183
|
+
|
|
184
|
+
After migrating swap call sites:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Should produce zero errors when the migration is complete:
|
|
188
|
+
pnpm -C <your-app-dir> checkTs
|
|
189
|
+
|
|
190
|
+
# Targeted scan for leftover v1 patterns:
|
|
191
|
+
grep -rE "spokeProvider:\s*\w+|intentParams:\s*\w+|srcChain:\s*\w+\.[a-z]+ChainId" src/
|
|
192
|
+
grep -rE "isIntentError\b|isIntentPostExecutionFailedError\b|isIntentSubmitTxFailedError\b" src/
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Cross-references
|
|
196
|
+
|
|
197
|
+
- v2 swap usage: [`features/swap.md`](../../../integration/knowledge/features/swap.md).
|
|
198
|
+
- Cross-cutting prerequisites (type-system, architecture, result/errors) listed in [`../README.md`](../README.md).
|