@sodax/wallet-sdk-core 2.0.0-rc.1 → 2.0.0-rc.2
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/ai-exported/AGENTS.md +139 -0
- package/ai-exported/integration/README.md +108 -0
- package/ai-exported/integration/ai-rules.md +141 -0
- package/ai-exported/integration/architecture.md +212 -0
- package/ai-exported/integration/features/README.md +22 -0
- package/ai-exported/integration/features/bitcoin.md +103 -0
- package/ai-exported/integration/features/evm.md +102 -0
- package/ai-exported/integration/features/icon.md +88 -0
- package/ai-exported/integration/features/injective.md +92 -0
- package/ai-exported/integration/features/near.md +92 -0
- package/ai-exported/integration/features/solana.md +104 -0
- package/ai-exported/integration/features/stacks.md +91 -0
- package/ai-exported/integration/features/stellar.md +95 -0
- package/ai-exported/integration/features/sui.md +96 -0
- package/ai-exported/integration/quickstart.md +259 -0
- package/ai-exported/integration/recipes/README.md +15 -0
- package/ai-exported/integration/recipes/bridge-to-sdk.md +145 -0
- package/ai-exported/integration/recipes/defaults-and-overrides.md +159 -0
- package/ai-exported/integration/recipes/library-exports.md +129 -0
- package/ai-exported/integration/recipes/setup-browser-extension.md +137 -0
- package/ai-exported/integration/recipes/setup-private-key.md +115 -0
- package/ai-exported/integration/recipes/sign-and-broadcast.md +201 -0
- package/ai-exported/integration/recipes/testing.md +163 -0
- package/ai-exported/integration/reference/README.md +13 -0
- package/ai-exported/integration/reference/chain-support.md +65 -0
- package/ai-exported/integration/reference/glossary.md +28 -0
- package/ai-exported/integration/reference/interfaces.md +131 -0
- package/ai-exported/integration/reference/provider-classes.md +54 -0
- package/ai-exported/integration/reference/public-api.md +128 -0
- package/ai-exported/migration/README.md +84 -0
- package/ai-exported/migration/ai-rules.md +139 -0
- package/ai-exported/migration/breaking-changes/README.md +14 -0
- package/ai-exported/migration/breaking-changes/base-wallet-provider.md +52 -0
- package/ai-exported/migration/breaking-changes/defaults-config.md +57 -0
- package/ai-exported/migration/breaking-changes/folder-layout.md +99 -0
- package/ai-exported/migration/breaking-changes/library-exports.md +58 -0
- package/ai-exported/migration/checklist.md +62 -0
- package/ai-exported/migration/recipes/README.md +12 -0
- package/ai-exported/migration/recipes/adopt-defaults.md +84 -0
- package/ai-exported/migration/recipes/adopt-library-exports.md +99 -0
- package/ai-exported/migration/reference/README.md +12 -0
- package/ai-exported/migration/reference/added-fields.md +71 -0
- package/ai-exported/migration/reference/deleted-exports.md +35 -0
- package/ai-exported/migration/reference/renamed-symbols.md +31 -0
- package/ai-exported/migration/reference/return-shapes.md +23 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# AGENTS.md — `@sodax/wallet-sdk-core` AI Export
|
|
2
|
+
|
|
3
|
+
You are a coding agent helping a developer **integrate** or **migrate** the `@sodax/wallet-sdk-core` package. This document is your entry point. Read this first, then route to the right sub-folder.
|
|
4
|
+
|
|
5
|
+
The files in this `ai-exported/` directory are designed for AI consumption: short, table-heavy, self-contained recipes, and machine-checkable checklists. Human-readable narrative lives in each folder's `README.md`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What this package is
|
|
10
|
+
|
|
11
|
+
`@sodax/wallet-sdk-core` is the **low-level** wallet layer of the SODAX stack — one provider class per chain family (9 in total: EVM, Solana, Sui, Bitcoin, Stellar, ICON, Injective, NEAR, Stacks). Each class accepts either a **private-key** config (server-side scripts, CI, Node) or a **browser-extension** config (consumer dApps with pre-built clients/wallet kits), signs transactions, and broadcasts them.
|
|
12
|
+
|
|
13
|
+
It is **not** a React layer (that is `@sodax/wallet-sdk-react`) and **not** a hooks layer (that is `@sodax/dapp-kit`). Most React consumers never touch this package directly — they get a typed `IXxxWalletProvider` via `useWalletProvider(...)` and hand it to `@sodax/sdk` calls. Direct usage of `wallet-sdk-core` is the right choice for:
|
|
14
|
+
|
|
15
|
+
- Backend / Node scripts (CI tests, indexers, bots).
|
|
16
|
+
- Custom browser flows that don't use React.
|
|
17
|
+
- Tests that need to sign with a deterministic key.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Step 1 — Identify the task
|
|
22
|
+
|
|
23
|
+
| User says... | Path | Start at |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| "sign a tx from a script", "instantiate `EvmWalletProvider`", "first time using this lib" | **integration** | `integration/ai-rules.md` |
|
|
26
|
+
| "configure default gas", "set up `defaults`", "shallow merge surprised me" | **integration** | `integration/recipes/defaults-and-overrides.md` |
|
|
27
|
+
| "where do I import `WalletClient` / `SuiClient` from", "avoid direct viem dep" | **integration** | `integration/recipes/library-exports.md` |
|
|
28
|
+
| "upgrade from v1 / sodax-frontend", "bump from older RC" | **migration** | `migration/ai-rules.md` |
|
|
29
|
+
| Deep import from `@sodax/wallet-sdk-core/wallet-providers/EvmWalletProvider` broke | **migration** | `migration/breaking-changes/folder-layout.md` |
|
|
30
|
+
| Looking up a provider class or its config shape | direct | `integration/reference/provider-classes.md` |
|
|
31
|
+
| Looking up the discriminated union shape per chain | direct | `integration/features/<chain>.md` |
|
|
32
|
+
|
|
33
|
+
The package name **did not change** across versions — both v1 and v2 publish as `@sodax/wallet-sdk-core`. **All v1→v2 surface changes are additive** — class names, config-type names, and config shapes are identical. The only mechanical migration is replacing deep imports from v1's flat `wallet-providers/*.ts` layout with barrel imports.
|
|
34
|
+
|
|
35
|
+
If a project does anything more than that at the wallet-sdk-core surface, you are almost certainly looking at an `@sodax/sdk` / `@sodax/types` migration, not this one. Route accordingly.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Step 2 — Load the right context
|
|
40
|
+
|
|
41
|
+
**For integration tasks:**
|
|
42
|
+
|
|
43
|
+
1. `integration/ai-rules.md` — DO/DON'T + workflow + stop conditions
|
|
44
|
+
2. `integration/architecture.md` — mental model (BaseWalletProvider, discriminants, defaults merge)
|
|
45
|
+
3. `integration/quickstart.md` — copy-paste minimal example for the chain you need
|
|
46
|
+
4. `integration/features/<chain>.md` — per-chain config table, methods, gotchas
|
|
47
|
+
5. `integration/recipes/<task>.md` — task-specific guide (setup-private-key, bridge-to-sdk, …)
|
|
48
|
+
6. `integration/reference/*.md` — full barrel exports, interfaces, chain support
|
|
49
|
+
|
|
50
|
+
**For migration tasks:**
|
|
51
|
+
|
|
52
|
+
1. `migration/ai-rules.md` — DO/DON'T + workflow. The headline: **v1 code drops in unchanged.** No mandatory edits at the wallet-sdk-core surface.
|
|
53
|
+
2. `migration/README.md` — what (additively) changed, read order, TL;DR
|
|
54
|
+
3. `migration/breaking-changes/*.md` — narrative WHY behind each additive shift (folder layout, base-class, defaults, library-exports)
|
|
55
|
+
4. `migration/reference/*.md` — confirm no renames / no deletions exist
|
|
56
|
+
5. `migration/recipes/<task>.md` — paired before/after for **optional** cleanup (adopt-defaults, adopt-library-exports)
|
|
57
|
+
6. `migration/checklist.md` — verification loop
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Step 3 — Honor flow-specific stop conditions
|
|
62
|
+
|
|
63
|
+
Each flow has its own list of conditions that **HARD STOP** code generation and require asking the user:
|
|
64
|
+
|
|
65
|
+
- Migration stops → [`migration/ai-rules.md`](./migration/ai-rules.md) § "Stop conditions"
|
|
66
|
+
- Integration stops → [`integration/ai-rules.md`](./integration/ai-rules.md) § "Stop conditions"
|
|
67
|
+
|
|
68
|
+
Read the relevant list **before** applying any change. When stopping, quote the offending file/line and present the user with concrete options. Do **not** guess.
|
|
69
|
+
|
|
70
|
+
Cross-flow signals (true regardless of flow):
|
|
71
|
+
|
|
72
|
+
- User asks for a chain family not in [`integration/reference/chain-support.md`](./integration/reference/chain-support.md). Adding a new chain is a maintainer task, not user-app integration.
|
|
73
|
+
- User wants to extend `BaseWalletProvider` directly. That is a maintainer-only path — confirm scope before writing code.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Step 4 — Verification protocol
|
|
78
|
+
|
|
79
|
+
After **every** code change you make:
|
|
80
|
+
|
|
81
|
+
1. Run `pnpm checkTs` from the user's app root (or the package the change touched).
|
|
82
|
+
2. If errors mention `@sodax/wallet-sdk-core`, look up the symbol in `integration/reference/` or `migration/reference/`.
|
|
83
|
+
3. If a symbol isn't in any reference file, **stop and ask**. Do not invent migrations.
|
|
84
|
+
4. After all errors resolve, mark the relevant items in `migration/checklist.md` (for migrations) or move to the next recipe.
|
|
85
|
+
|
|
86
|
+
You are **done** when:
|
|
87
|
+
- `pnpm checkTs` exits clean for the user's project.
|
|
88
|
+
- All items in `migration/checklist.md` are checked (migration only).
|
|
89
|
+
- The user has confirmed the changed flow works in their dev / test environment.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Conventions in this directory
|
|
94
|
+
|
|
95
|
+
- **Recipes are self-contained.** A recipe file in `recipes/` contains everything needed to apply the change — before/after code, steps, verification. Do not jump between files.
|
|
96
|
+
- **Reference files are tables.** `reference/*.md` contains markdown tables and paired code blocks. Treat them as lookup, not narrative.
|
|
97
|
+
- **Token budget**: Each file is sized to fit comfortably in your context. If you find yourself loading more than 3 files for a single task, you are probably doing it wrong — re-route via the table above.
|
|
98
|
+
- **Single source of truth**: Behavioral / breaking-change *explanations* live only in `migration/breaking-changes/*.md`. Other files reference them but do not duplicate the prose.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Quick symbol lookup
|
|
103
|
+
|
|
104
|
+
If the user mentions a symbol you don't recognize, grep these files in order:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
integration/reference/public-api.md — every named export from the package
|
|
108
|
+
integration/reference/provider-classes.md — provider class + config + interface mapping
|
|
109
|
+
integration/reference/interfaces.md — IXxxWalletProvider method signatures
|
|
110
|
+
integration/reference/chain-support.md — chain family → provider + dependencies
|
|
111
|
+
migration/reference/renamed-symbols.md — confirms zero renames between v1 and v2
|
|
112
|
+
migration/reference/deleted-exports.md — confirms zero deletions between v1 and v2
|
|
113
|
+
migration/reference/added-fields.md — additive `defaults` / `*WalletDefaults` / `*Policy` types
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
If still not found: the symbol may be **internal** (not exported from the package root) or **removed**. Ask the user to share the source file/line so you can decide.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Package context
|
|
121
|
+
|
|
122
|
+
- **Name**: `@sodax/wallet-sdk-core`
|
|
123
|
+
- **Version target**: latest RC / stable on npm.
|
|
124
|
+
- **Peer deps**: none — chain SDKs are direct dependencies and consumers can re-import types via `library-exports`.
|
|
125
|
+
- **Install**: `pnpm add @sodax/wallet-sdk-core`
|
|
126
|
+
- **Runtime**: Node ≥ 18 + browser (tsup `platform: 'neutral'`).
|
|
127
|
+
- **Audience**: backend engineers, script authors, and React-layer authors building higher-level wrappers (`@sodax/wallet-sdk-react`).
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Pointers
|
|
132
|
+
|
|
133
|
+
- [`integration/README.md`](./integration/README.md) — start here for new integrations: file index, recommended reading order, install snippet, dual-config overview.
|
|
134
|
+
- [`migration/README.md`](./migration/README.md) — start here for upgrades: file index, reading order, cross-cutting checklist pointer.
|
|
135
|
+
- [`integration/quickstart.md`](./integration/quickstart.md) — minimal end-to-end example per chain.
|
|
136
|
+
- [`integration/architecture.md`](./integration/architecture.md) — mental model: `BaseWalletProvider`, defaults shallow merge, dual-config discriminants, `library-exports`.
|
|
137
|
+
- [`integration/features/`](./integration/features/) — per-chain config table, methods, gotchas (one file per chain).
|
|
138
|
+
- [`integration/reference/`](./integration/reference/) — public API, provider classes, interfaces, chain support, glossary.
|
|
139
|
+
- [`migration/breaking-changes/`](./migration/breaking-changes/) — narrative WHY behind each version-to-version shift.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Integration: First-time setup (Human-readable overview)
|
|
2
|
+
|
|
3
|
+
This folder helps you integrate `@sodax/wallet-sdk-core` into a fresh project — most commonly a Node script, a backend service, or a custom non-React frontend. It is the **human-facing** entry point for new integrations. If you are a coding agent, read [`ai-rules.md`](./ai-rules.md) first.
|
|
4
|
+
|
|
5
|
+
If you are upgrading from an older version of the package instead, see `../migration/`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What this package does
|
|
10
|
+
|
|
11
|
+
`@sodax/wallet-sdk-core` is a **low-level multi-chain wallet provider layer**. For each of the 9 chain families that SODAX supports it ships **one provider class** that:
|
|
12
|
+
|
|
13
|
+
- Accepts a **discriminated union config** — `PrivateKey*WalletConfig | BrowserExtension*WalletConfig`.
|
|
14
|
+
- Extends a small `BaseWalletProvider` to merge per-call options over a typed `defaults` shape.
|
|
15
|
+
- Implements the chain-specific `IXxxWalletProvider` interface from `@sodax/types`, so it can be passed straight into `@sodax/sdk` calls.
|
|
16
|
+
|
|
17
|
+
It is intentionally framework-agnostic — Node ≥ 18, browser, edge runtimes are all supported (tsup `platform: 'neutral'`).
|
|
18
|
+
|
|
19
|
+
| Chain family | Provider class | Underlying chain SDK |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| EVM (12 chains) | `EvmWalletProvider` | `viem` |
|
|
22
|
+
| Solana | `SolanaWalletProvider` | `@solana/web3.js` |
|
|
23
|
+
| Sui | `SuiWalletProvider` | `@mysten/sui` + `@mysten/wallet-standard` |
|
|
24
|
+
| Bitcoin | `BitcoinWalletProvider` | `bitcoinjs-lib` (+ `ecpair`, `secp256k1`) |
|
|
25
|
+
| Stellar | `StellarWalletProvider` | `@stellar/stellar-sdk` |
|
|
26
|
+
| ICON | `IconWalletProvider` | `icon-sdk-js` |
|
|
27
|
+
| Injective | `InjectiveWalletProvider` | `@injectivelabs/sdk-ts` + `@injectivelabs/wallet-core` |
|
|
28
|
+
| NEAR | `NearWalletProvider` | `near-api-js` + `@hot-labs/near-connect` |
|
|
29
|
+
| Stacks | `StacksWalletProvider` | `@stacks/transactions` + `@stacks/connect` |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Recommended path (in order)
|
|
34
|
+
|
|
35
|
+
If this is your first time using the package:
|
|
36
|
+
|
|
37
|
+
1. [`architecture.md`](./architecture.md) — read once before any recipe. Explains `BaseWalletProvider`, the `defaults` shallow-merge model, dual-config discriminants, and the `library-exports` indirection. Picking the wrong config variant is the most common mistake — the mental model prevents it.
|
|
38
|
+
2. [`quickstart.md`](./quickstart.md) — minimal end-to-end example for the chain you need. Copy, edit, run.
|
|
39
|
+
3. [`features/<chain>.md`](./features/) — chain-specific config table, methods, and gotchas (one file per chain).
|
|
40
|
+
4. Pick the right recipes:
|
|
41
|
+
- [`recipes/setup-private-key.md`](./recipes/setup-private-key.md) — server-side / CI flow.
|
|
42
|
+
- [`recipes/setup-browser-extension.md`](./recipes/setup-browser-extension.md) — consumer dApp flow.
|
|
43
|
+
- [`recipes/bridge-to-sdk.md`](./recipes/bridge-to-sdk.md) — hand off the provider to `@sodax/sdk` calls.
|
|
44
|
+
- [`recipes/defaults-and-overrides.md`](./recipes/defaults-and-overrides.md) — merge semantics for the `defaults` config.
|
|
45
|
+
- [`recipes/library-exports.md`](./recipes/library-exports.md) — re-importing upstream chain-SDK types without a direct dep.
|
|
46
|
+
- [`recipes/sign-and-broadcast.md`](./recipes/sign-and-broadcast.md) — typical send-transaction flow per chain.
|
|
47
|
+
- [`recipes/testing.md`](./recipes/testing.md) — mocking providers in unit tests.
|
|
48
|
+
5. Reference docs (lookup as needed):
|
|
49
|
+
- [`reference/public-api.md`](./reference/public-api.md) — every named export from the package root.
|
|
50
|
+
- [`reference/provider-classes.md`](./reference/provider-classes.md) — provider × config × interface table.
|
|
51
|
+
- [`reference/interfaces.md`](./reference/interfaces.md) — `IXxxWalletProvider` method signatures.
|
|
52
|
+
- [`reference/chain-support.md`](./reference/chain-support.md) — chain family → spoke chain keys.
|
|
53
|
+
- [`reference/glossary.md`](./reference/glossary.md) — terms used across the docs.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm add @sodax/wallet-sdk-core @sodax/types
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Most consumers will also need `@sodax/sdk` (for the hub/spoke services that accept the wallet provider) and one or more chain SDKs (for browser-extension wallet objects). Re-export the types you need via `library-exports` — see [`recipes/library-exports.md`](./recipes/library-exports.md).
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Two configuration modes
|
|
68
|
+
|
|
69
|
+
Every provider class supports **two** construction modes. Picking the wrong one is the most common integration mistake.
|
|
70
|
+
|
|
71
|
+
| Mode | When to use | Discriminant style |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| **Private-key** | Node scripts, CI tests, indexers, bots — anywhere you possess the raw key | Either field presence (EVM, Solana, Sui, ICON, Injective, NEAR, Stacks) OR `type: 'PRIVATE_KEY'` (Bitcoin, Stellar) |
|
|
74
|
+
| **Browser-extension** | Consumer dApps where a wallet extension provides a pre-built client / signer | Either field presence (different fields from PK variant) OR `type: 'BROWSER_EXTENSION'` (Bitcoin, Stellar) |
|
|
75
|
+
|
|
76
|
+
For a chain-by-chain breakdown of the exact discriminant shape, see [`features/`](./features/) and [`architecture.md`](./architecture.md) § "Discriminant variants".
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Pair with `@sodax/sdk` and `@sodax/wallet-sdk-react`
|
|
81
|
+
|
|
82
|
+
The most common stack:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
@sodax/sdk ← business logic (swaps, lending, staking, …)
|
|
86
|
+
@sodax/wallet-sdk-react ← React layer that surfaces a typed IXxxWalletProvider via hooks
|
|
87
|
+
@sodax/wallet-sdk-core ← this package — concrete provider classes
|
|
88
|
+
@sodax/types ← shared type definitions
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
In a React dApp you usually consume this package **indirectly** — `useWalletProvider({ xChainId })` (from `@sodax/wallet-sdk-react`) returns a typed `IXxxWalletProvider` that comes from a `wallet-sdk-core` instance under the hood. You only construct provider classes from `wallet-sdk-core` directly when running scripts, tests, or non-React clients.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Conventions worth knowing
|
|
96
|
+
|
|
97
|
+
- **`defaults` is optional but powerful.** Every provider accepts a `defaults` config slice; per-call options shallow-merge over it. Use it to encode env-level fixed choices (RPC commitment, default gas, default memo) once.
|
|
98
|
+
- **Shallow merge, not deep.** Nested objects in `defaults` are **replaced wholesale** by per-call options of the same key. See `src/utils/merge.ts` and [`recipes/defaults-and-overrides.md`](./recipes/defaults-and-overrides.md).
|
|
99
|
+
- **`library-exports` removes upstream deps.** You can `import type { WalletClient } from '@sodax/wallet-sdk-core'` instead of taking a direct dep on `viem`. See [`recipes/library-exports.md`](./recipes/library-exports.md).
|
|
100
|
+
- **The barrel is the source of truth.** Internal utilities (`shallowMerge`, helper functions) are **not** exported. If something isn't on `@sodax/wallet-sdk-core`'s root, do not deep-import it.
|
|
101
|
+
- **No `as unknown as` casts.** The discriminated unions are precise — if TypeScript complains, your config is wrong, not the type.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Getting help
|
|
106
|
+
|
|
107
|
+
- API surface lookup: [`reference/`](./reference/).
|
|
108
|
+
- Bug or missing feature: [open an issue](https://github.com/icon-project/sodax-sdks/issues).
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# AI Rules — Fresh Integration
|
|
2
|
+
|
|
3
|
+
You are integrating `@sodax/wallet-sdk-core` into a user's project for the first time. Follow this protocol exactly.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Workflow (do these in order)
|
|
8
|
+
|
|
9
|
+
### 1. Survey the project
|
|
10
|
+
|
|
11
|
+
Before changing anything, gather context:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Runtime — Node script? React dApp? Edge runtime?
|
|
15
|
+
cat <user>/package.json | grep -E '"type|"main|"module'
|
|
16
|
+
|
|
17
|
+
# Node version — must be >= 18
|
|
18
|
+
cat <user>/.nvmrc 2>/dev/null
|
|
19
|
+
node --version
|
|
20
|
+
|
|
21
|
+
# Is the user already using @sodax/wallet-sdk-react?
|
|
22
|
+
cat <user>/package.json | grep '"@sodax/wallet-sdk-react'
|
|
23
|
+
|
|
24
|
+
# Are upstream chain SDKs already direct deps? (may indicate they don't yet know about library-exports)
|
|
25
|
+
cat <user>/package.json | grep -E '"viem"|"@solana/web3.js"|"@mysten/sui"|"@stellar/stellar-sdk"|"@stacks/transactions"|"@injectivelabs"|"near-api-js"|"bitcoinjs-lib"|"icon-sdk-js"'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**If Node < 18**, stop and tell the user — this package requires Node ≥ 18.
|
|
29
|
+
|
|
30
|
+
**If the user is already using `@sodax/wallet-sdk-react` in the same project**, ask whether they really need to construct providers directly. In a React app the answer is usually **no**: `useWalletProvider({ xChainId })` returns the typed provider for them. Direct construction is only correct for scripts, tests, or non-React clients.
|
|
31
|
+
|
|
32
|
+
### 2. Pick the right mode
|
|
33
|
+
|
|
34
|
+
For **each** chain the user wants to integrate, decide between:
|
|
35
|
+
|
|
36
|
+
| Mode | When to pick | Stop and ask if... |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| **Private-key** | A Node script, CI runner, indexer, or test that legitimately possesses a raw key. | The user pastes a real-looking key in a frontend file. Never embed a private key in a browser bundle. |
|
|
39
|
+
| **Browser-extension** | A dApp where a wallet extension (MetaMask, Phantom, Xverse, Hana, Freighter, Leather, …) provides the signing primitives. | The user has neither a key nor a wallet adapter on hand. They probably want `@sodax/wallet-sdk-react` instead. |
|
|
40
|
+
|
|
41
|
+
Ask the user which mode applies **before** writing code. Default to **private-key** for `apps/node`-style scripts and **browser-extension** for `apps/web`-style dApps.
|
|
42
|
+
|
|
43
|
+
### 3. Apply the matching recipe
|
|
44
|
+
|
|
45
|
+
- Private-key flow → [`recipes/setup-private-key.md`](./recipes/setup-private-key.md).
|
|
46
|
+
- Browser-extension flow → [`recipes/setup-browser-extension.md`](./recipes/setup-browser-extension.md).
|
|
47
|
+
|
|
48
|
+
Each recipe is self-contained — install snippet, config, first method call, verification.
|
|
49
|
+
|
|
50
|
+
### 4. Hand off to `@sodax/sdk` if needed
|
|
51
|
+
|
|
52
|
+
If the user wants to swap / bridge / stake / lend / migrate, they need to pass the provider to `@sodax/sdk` calls. Apply [`recipes/bridge-to-sdk.md`](./recipes/bridge-to-sdk.md). Do not invent your own bridging pattern.
|
|
53
|
+
|
|
54
|
+
### 5. Add advanced features as separate steps
|
|
55
|
+
|
|
56
|
+
Only after the basic flow works should you add:
|
|
57
|
+
|
|
58
|
+
- Default config slices ([`recipes/defaults-and-overrides.md`](./recipes/defaults-and-overrides.md))
|
|
59
|
+
- Importing upstream chain types via `library-exports` ([`recipes/library-exports.md`](./recipes/library-exports.md))
|
|
60
|
+
- Sign + broadcast flow for the chain ([`recipes/sign-and-broadcast.md`](./recipes/sign-and-broadcast.md))
|
|
61
|
+
- Mocking providers in tests ([`recipes/testing.md`](./recipes/testing.md))
|
|
62
|
+
|
|
63
|
+
Each is independent — apply only what the user asked for.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## DO
|
|
68
|
+
|
|
69
|
+
- **DO** use the discriminated union types in your `import` statement so TypeScript narrows the config correctly:
|
|
70
|
+
```ts
|
|
71
|
+
import { EvmWalletProvider, type EvmWalletConfig } from '@sodax/wallet-sdk-core';
|
|
72
|
+
```
|
|
73
|
+
- **DO** use chain key constants from `@sodax/types` (`ChainKeys.SONIC_MAINNET`, `ChainKeys.BSC_MAINNET`, …) instead of magic numbers / strings.
|
|
74
|
+
- **DO** re-export upstream chain types via `library-exports` (`import type { WalletClient } from '@sodax/wallet-sdk-core'`) — keeps direct chain-SDK deps out of `package.json`.
|
|
75
|
+
- **DO** pass an `IXxxWalletProvider` (the **interface** from `@sodax/types`), not the concrete class, to SDK calls. Interfaces are how the SDK stays decoupled from this package.
|
|
76
|
+
- **DO** put RPC URLs, network selectors, default gas, etc. in the `defaults` config slice — one place, one source of truth.
|
|
77
|
+
- **DO** consult [`features/<chain>.md`](./features/) for the chain you are integrating before writing the constructor call. Each chain has slightly different field names.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## DO NOT
|
|
82
|
+
|
|
83
|
+
- **DO NOT** embed a private key in a frontend bundle. Browser-extension config exists for a reason.
|
|
84
|
+
- **DO NOT** import from `@sodax/wallet-sdk-core/src/...` deep paths. Only the package root is public.
|
|
85
|
+
- **DO NOT** deep-import the internal `shallowMerge` from `src/utils/merge.ts`. It is intentionally not exported.
|
|
86
|
+
- **DO NOT** extend `BaseWalletProvider` in user code unless you are adding a brand-new chain to this package. That is a maintainer-only path.
|
|
87
|
+
- **DO NOT** widen the discriminated union with a cast (e.g. `as EvmWalletConfig`). If TypeScript complains, your fields are wrong — fix the fields.
|
|
88
|
+
- **DO NOT** mutate `defaults` after construction. Providers freeze the `defaults` reference; later mutations are silently ignored.
|
|
89
|
+
- **DO NOT** mix discriminant styles for a chain. Bitcoin and Stellar **require** an uppercase `type: 'PRIVATE_KEY' | 'BROWSER_EXTENSION'`; every other chain uses **field presence**. See [`architecture.md`](./architecture.md) § "Discriminant variants".
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Stop conditions (defer to user)
|
|
94
|
+
|
|
95
|
+
| Signal | Why stop |
|
|
96
|
+
|---|---|
|
|
97
|
+
| User asks for a chain family not in [chain support](./reference/chain-support.md) | Adding a new chain is a maintainer task, not user-app integration. |
|
|
98
|
+
| User wants to extend `BaseWalletProvider` directly | Maintainer-only path. Confirm scope first. |
|
|
99
|
+
| User wants to deep-merge `defaults` with per-call options | Not supported — merge is **shallow** by design. See [`recipes/defaults-and-overrides.md`](./recipes/defaults-and-overrides.md). If the user really needs deep merge, they must combine before passing. |
|
|
100
|
+
| User wants to inject a custom `Transport` / `Connection` / `SuiClient` in private-key mode | Some chains expose this via `defaults`; others don't. Check the chain's [feature file](./features/) first. |
|
|
101
|
+
| User wants to use a wallet brand the chain SDK does not support | Out of scope — wallet brand support lives in the upstream chain SDK / kit. |
|
|
102
|
+
| User is in a React app and wants to construct providers in components | Almost always wrong. Direct user to `@sodax/wallet-sdk-react`'s `useWalletProvider` hook. |
|
|
103
|
+
| User asks "how do I sign with X without a key and without an extension" | They probably want a custom signer — this package does not currently model that. Flag as out of scope. |
|
|
104
|
+
|
|
105
|
+
When stopping, **quote the file/line** of the offending code and present the user with concrete options.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Verification protocol (after every recipe)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# 1. Type check passes
|
|
113
|
+
pnpm checkTs
|
|
114
|
+
|
|
115
|
+
# 2. No deep imports
|
|
116
|
+
grep -rn "@sodax/wallet-sdk-core/" <user-src> | grep -v "from '@sodax/wallet-sdk-core'"
|
|
117
|
+
# expect empty — only barrel imports allowed
|
|
118
|
+
|
|
119
|
+
# 3. No direct upstream chain-SDK imports for types that library-exports provides
|
|
120
|
+
grep -rn "from 'viem'" <user-src> | grep -E "WalletClient|PublicClient|TransactionReceipt"
|
|
121
|
+
# if any match, suggest re-importing via @sodax/wallet-sdk-core
|
|
122
|
+
|
|
123
|
+
# 4. Sample call works
|
|
124
|
+
# (manual — run a one-shot sign + broadcast on testnet)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If steps 1–3 pass and the user confirms step 4, the recipe is done.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Done criteria
|
|
132
|
+
|
|
133
|
+
The integration is complete when:
|
|
134
|
+
|
|
135
|
+
- [ ] `pnpm checkTs` exits clean.
|
|
136
|
+
- [ ] The user has at least one provider instance constructed via the correct discriminated union variant.
|
|
137
|
+
- [ ] Types are imported from `@sodax/wallet-sdk-core` (and `@sodax/types`) only — no deep paths.
|
|
138
|
+
- [ ] If using `@sodax/sdk`: the provider is passed via the `IXxxWalletProvider` interface, not the concrete class.
|
|
139
|
+
- [ ] A sign + broadcast (or get-address) call has succeeded against testnet or a local mock.
|
|
140
|
+
|
|
141
|
+
Do not declare integration done before all of the above are true.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Architecture — Mental Model
|
|
2
|
+
|
|
3
|
+
This file explains **why** `@sodax/wallet-sdk-core` is shaped the way it is. Read it once before applying recipes — knowing the model lets you handle ambiguous user code without guessing.
|
|
4
|
+
|
|
5
|
+
If you are looking for "how do I do X", go to [`recipes/`](./recipes/) or [`features/`](./features/). This file is purely conceptual.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## The shape of the package
|
|
10
|
+
|
|
11
|
+
`@sodax/wallet-sdk-core` is a **uniform low-level wallet layer over heterogeneous chain SDKs**. For each of the 9 chain families that SODAX supports, the package ships:
|
|
12
|
+
|
|
13
|
+
1. A `*WalletProvider` **class** that implements a chain-specific interface (`IEvmWalletProvider`, `ISolanaWalletProvider`, …) imported from `@sodax/types`.
|
|
14
|
+
2. A discriminated-union **config type** (`*WalletConfig = PrivateKey* | BrowserExtension*`).
|
|
15
|
+
3. A `*WalletDefaults` type — the per-method default option shape merged into each call.
|
|
16
|
+
|
|
17
|
+
Each provider class extends a small abstract `BaseWalletProvider<TDefaults>`. That base holds the `defaults` reference and exposes two helpers:
|
|
18
|
+
|
|
19
|
+
- `mergePolicy(key, options)` — shallow-merges per-call options over `defaults[key]`. Used when defaults are grouped per method (e.g. `defaults.sendTransaction`).
|
|
20
|
+
- `mergeDefaults(options)` — shallow-merges per-call options over the entire flat `defaults`. Used when defaults are not grouped.
|
|
21
|
+
|
|
22
|
+
Subclasses do three things on top:
|
|
23
|
+
|
|
24
|
+
1. Declare a `chainType` literal (`'EVM' as const`, `'BITCOIN' as const`, …).
|
|
25
|
+
2. Discriminate the config and initialize chain-specific state (viem client, Solana `Connection`, `SuiClient`, …).
|
|
26
|
+
3. Implement the chain-specific interface methods (`sendTransaction`, `signTransaction`, …).
|
|
27
|
+
|
|
28
|
+
Consumers only ever see the public surface: construct the class with one of the union variants, call its methods, and hand the instance to `@sodax/sdk` via its `IXxxWalletProvider` interface.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## File-system tour
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
src/
|
|
36
|
+
├── index.ts # Barrel: re-exports wallet-providers + types
|
|
37
|
+
├── types/
|
|
38
|
+
│ ├── index.ts # Re-exports library-exports
|
|
39
|
+
│ └── library-exports.ts # Re-exported types (and a few enums) from upstream chain SDKs
|
|
40
|
+
├── utils/ # Internal — shallowMerge; NOT re-exported
|
|
41
|
+
│ ├── index.ts
|
|
42
|
+
│ ├── merge.ts
|
|
43
|
+
│ └── merge.test.ts
|
|
44
|
+
└── wallet-providers/
|
|
45
|
+
├── index.ts # Barrel: re-exports every provider folder
|
|
46
|
+
├── BaseWalletProvider.ts # Abstract base class
|
|
47
|
+
├── evm/
|
|
48
|
+
│ ├── EvmWalletProvider.ts
|
|
49
|
+
│ ├── EvmWalletProvider.test.ts
|
|
50
|
+
│ ├── types.ts
|
|
51
|
+
│ └── index.ts
|
|
52
|
+
├── solana/ { …same shape… }
|
|
53
|
+
├── sui/ { …same shape… }
|
|
54
|
+
├── bitcoin/ { …same shape… }
|
|
55
|
+
├── stellar/ { …same shape… }
|
|
56
|
+
├── icon/ { …same shape… }
|
|
57
|
+
├── injective/{ …same shape… }
|
|
58
|
+
├── near/ { …same shape… }
|
|
59
|
+
└── stacks/ { …same shape… }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Three things to internalize:
|
|
63
|
+
|
|
64
|
+
1. **The package root is the only public surface.** `src/utils/*` is internal — `shallowMerge` etc. are deliberately not re-exported.
|
|
65
|
+
2. **Each chain is folder-isolated.** Adding a new chain means creating a folder under `src/wallet-providers/<chain>/` and listing it in `wallet-providers/index.ts`. Nothing else changes.
|
|
66
|
+
3. **`types/library-exports.ts` is the indirection point** between upstream chain SDKs and consumers. Re-exporting from here means consumer apps don't need direct deps on `viem`, `@mysten/sui`, etc. for type-only usage.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## `BaseWalletProvider` and the `defaults` model
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
abstract class BaseWalletProvider<TDefaults extends object> {
|
|
74
|
+
protected readonly defaults: TDefaults;
|
|
75
|
+
|
|
76
|
+
constructor(defaults: TDefaults | undefined) {
|
|
77
|
+
this.defaults = (defaults ?? {}) as TDefaults;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
abstract getWalletAddress(): Promise<string>;
|
|
81
|
+
|
|
82
|
+
protected mergePolicy<K extends keyof TDefaults>(key: K, options?: …): … { /* shallowMerge */ }
|
|
83
|
+
protected mergeDefaults(options?: Partial<TDefaults>): TDefaults { /* shallowMerge */ }
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Three rules govern the `defaults` model:
|
|
88
|
+
|
|
89
|
+
1. **Every field of `TDefaults` is optional.** The constructor falls back to `{}` if the consumer omits `defaults` entirely. Required fields would silently arrive as `undefined` at runtime without TypeScript catching it — see the JSDoc comment in `BaseWalletProvider.ts`.
|
|
90
|
+
2. **Merge is shallow.** Top-level keys merge; nested objects are **replaced wholesale**. If `defaults.sendTransaction = { gas: 3_000_000n, nonce: 0 }` and the caller passes `{ gas: 5_000_000n }`, the merged policy is `{ gas: 5_000_000n }` — `nonce` is dropped. See `src/utils/merge.ts`. The behaviour is intentional: deep merge would silently smuggle stale fields across call sites.
|
|
91
|
+
3. **`undefined` layers and `undefined` values are skipped.** Passing `{ field: undefined }` does **not** override an earlier layer — the merge treats `undefined` as "no opinion".
|
|
92
|
+
|
|
93
|
+
Two helpers exist because chains group their defaults differently:
|
|
94
|
+
|
|
95
|
+
- **Per-method grouping** — `mergePolicy('sendTransaction', options)` looks up `defaults.sendTransaction` and merges `options` over it. Used by EVM (`sendTransaction`, `waitForTransactionReceipt`), Sui (`signAndExecuteTxn`, `getCoins`).
|
|
96
|
+
- **Flat grouping** — `mergeDefaults(options)` merges `options` over the whole `defaults` object. Used by chains whose `defaults` is a flat record (Bitcoin's `{ defaultFinalize }`, Stellar's `{ pollInterval, pollTimeout, networkPassphrase }`).
|
|
97
|
+
|
|
98
|
+
For a concrete worked example see [`recipes/defaults-and-overrides.md`](./recipes/defaults-and-overrides.md).
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Discriminant variants
|
|
103
|
+
|
|
104
|
+
Every chain supports two construction modes — but the discriminant **looks different per chain**. The rule of thumb:
|
|
105
|
+
|
|
106
|
+
| Discriminant style | Chains | Example |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| **Field presence** (no `type` field) | EVM, Solana, Sui, ICON, Injective, NEAR, Stacks | EVM: `privateKey + chainId` → private-key. `walletClient + publicClient` → browser-extension. |
|
|
109
|
+
| **Explicit uppercase `type`** | Bitcoin, Stellar | `{ type: 'PRIVATE_KEY', … }` vs `{ type: 'BROWSER_EXTENSION', … }` |
|
|
110
|
+
|
|
111
|
+
Why the inconsistency: the field-presence form is shorter for the common case but only works when the two variants share **zero** required-field overlap. Bitcoin and Stellar have shared required fields (`network`, `walletsKit` shapes that overlap with PK fields) that would make field presence ambiguous, so they use explicit `type`.
|
|
112
|
+
|
|
113
|
+
Two more wrinkles to know about:
|
|
114
|
+
|
|
115
|
+
- **Sui uses `mnemonics`, not `privateKey`.** The library derives an Ed25519 keypair from the mnemonic phrase. There is no raw-secret-key option.
|
|
116
|
+
- **Injective uses a nested `secret` object.** Because Injective can be constructed from **either** a private key **or** a BIP-39 mnemonic, the private-key variant nests credentials under `secret: { privateKey } | { mnemonics }` instead of placing them at the top level. The type is named `SecretInjectiveWalletConfig` (not `PrivateKey*`) to reflect this.
|
|
117
|
+
|
|
118
|
+
For chain-by-chain breakdowns see [`features/`](./features/).
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## `library-exports` — the upstream-SDK indirection
|
|
123
|
+
|
|
124
|
+
`src/types/library-exports.ts` re-exports a curated set of types (and a few runtime values) from each upstream chain SDK:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
// viem types
|
|
128
|
+
export type { Account, Address, Chain, Transport, PublicClient, WalletClient,
|
|
129
|
+
HttpTransportConfig, PublicClientConfig, WalletClientConfig,
|
|
130
|
+
SendTransactionParameters, WaitForTransactionReceiptParameters,
|
|
131
|
+
TransactionReceipt } from 'viem';
|
|
132
|
+
|
|
133
|
+
// Sui types
|
|
134
|
+
export type { SuiTransactionBlockResponseOptions } from '@mysten/sui/client';
|
|
135
|
+
export type { Transaction, TransactionArgument } from '@mysten/sui/transactions';
|
|
136
|
+
export type { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
137
|
+
|
|
138
|
+
// Solana types
|
|
139
|
+
export type { Commitment, ConnectionConfig, SendOptions } from '@solana/web3.js';
|
|
140
|
+
|
|
141
|
+
// Injective types
|
|
142
|
+
export type { Network } from '@injectivelabs/networks';
|
|
143
|
+
export type { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
144
|
+
export type { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
145
|
+
|
|
146
|
+
// Stellar (also re-exports the `Networks` runtime value)
|
|
147
|
+
export { Networks } from '@stellar/stellar-sdk';
|
|
148
|
+
|
|
149
|
+
// Stacks (also re-exports the `PostConditionMode` enum)
|
|
150
|
+
export { PostConditionMode } from '@stacks/transactions';
|
|
151
|
+
export type { ClarityValue, PostConditionModeName } from '@stacks/transactions';
|
|
152
|
+
export type { StacksNetwork } from '@stacks/network';
|
|
153
|
+
export type { StacksProvider } from '@stacks/connect';
|
|
154
|
+
|
|
155
|
+
// Near
|
|
156
|
+
export type { KeyPairString } from 'near-api-js';
|
|
157
|
+
export type { NearConnector } from '@hot-labs/near-connect';
|
|
158
|
+
|
|
159
|
+
// Bitcoin
|
|
160
|
+
export type { Network as BitcoinJsNetwork } from 'bitcoinjs-lib/src/networks.js';
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Consumers can import the types they need directly from `@sodax/wallet-sdk-core` instead of adding `viem`, `@mysten/sui`, etc. to their `package.json`:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import type { WalletClient, PublicClient, TransactionReceipt } from '@sodax/wallet-sdk-core';
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Note the file name: `library-exports`, not `library-types`. It deliberately re-exports a small number of **runtime** values (`Networks`, `PostConditionMode`) — hence the broader name.
|
|
170
|
+
|
|
171
|
+
For the typical reasons to use it (and when not to), see [`recipes/library-exports.md`](./recipes/library-exports.md).
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## The `IXxxWalletProvider` interface — your handoff to `@sodax/sdk`
|
|
176
|
+
|
|
177
|
+
Each provider class implements a chain-specific interface from `@sodax/types`:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
class EvmWalletProvider extends BaseWalletProvider<EvmWalletDefaults> implements IEvmWalletProvider { … }
|
|
181
|
+
class BitcoinWalletProvider extends BaseWalletProvider<BitcoinWalletDefaults> implements IBitcoinWalletProvider { … }
|
|
182
|
+
// …and so on
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
When you call `@sodax/sdk` methods, the SDK expects the **interface**, not the concrete class:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import type { IEvmWalletProvider } from '@sodax/types';
|
|
189
|
+
|
|
190
|
+
async function deposit(evmProvider: IEvmWalletProvider) { /* … */ }
|
|
191
|
+
|
|
192
|
+
const evm = new EvmWalletProvider({ … });
|
|
193
|
+
await deposit(evm); // ✅ EvmWalletProvider implements IEvmWalletProvider
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
This indirection is how the SDK stays decoupled from `wallet-sdk-core`. In a React app, `useWalletProvider({ xChainId })` from `@sodax/wallet-sdk-react` returns the interface directly — the React layer constructs the concrete class internally.
|
|
197
|
+
|
|
198
|
+
For the full interface signatures, see [`reference/interfaces.md`](./reference/interfaces.md).
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Things that look weird until you know why
|
|
203
|
+
|
|
204
|
+
- **`InjectiveWalletConfig` is `BrowserExtensionInjectiveWalletConfig | SecretInjectiveWalletConfig`** — note the `Secret*` (not `PrivateKey*`) name. It also accepts mnemonics, hence the broader name. See [`features/injective.md`](./features/injective.md).
|
|
205
|
+
- **EVM in browser-extension mode ignores `defaults.transport`, `defaults.publicClient`, and `defaults.walletClient`.** Because the consumer supplied pre-built clients, these defaults are no-ops — the provider logs a one-time `console.warn`. Pass them only in private-key mode. See `EvmWalletProvider.ts`.
|
|
206
|
+
- **HyperEVM is defined inside this package.** `viem/chains` does not ship a HyperEVM config, so `wallet-providers/evm/EvmWalletProvider.ts` exports a `hyper` chain object via `defineChain`. You shouldn't need to import it directly — `getEvmViemChain(ChainKeys.HYPEREVM_MAINNET)` returns it.
|
|
207
|
+
- **`getEvmViemChain(key)` is exhaustively typed.** The default branch is a `never`-assertion — if `@sodax/types` adds a new `EvmChainKey` value, this function fails to typecheck until the case is added. That's by design.
|
|
208
|
+
- **Sui browser-extension mode requires THREE objects** — `client`, `wallet`, and `account`. Many wallet adapters expose the first two but not the third. See [`features/sui.md`](./features/sui.md).
|
|
209
|
+
- **Stellar requires `rpcUrl` in both modes** (technically optional, but defaults to a public RPC). Use a private RPC for production.
|
|
210
|
+
- **Bitcoin in private-key mode also takes an optional `addressType`** (P2WPKH / P2TR / …). Browser-extension mode infers it from the wallet kit.
|
|
211
|
+
|
|
212
|
+
Everything else is covered by [`features/`](./features/) on a per-chain basis.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Per-chain feature docs
|
|
2
|
+
|
|
3
|
+
One file per chain family. Each file documents:
|
|
4
|
+
|
|
5
|
+
- The provider class and the discriminated union of accepted configs.
|
|
6
|
+
- The `*Defaults` shape.
|
|
7
|
+
- The methods exposed on the provider (and how they merge defaults).
|
|
8
|
+
- Common gotchas specific to the chain.
|
|
9
|
+
|
|
10
|
+
| Chain family | Provider | Discriminant style | Underlying SDK |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| [EVM](./evm.md) | `EvmWalletProvider` | Field presence (no `type`) | `viem` |
|
|
13
|
+
| [Solana](./solana.md) | `SolanaWalletProvider` | Field presence | `@solana/web3.js` |
|
|
14
|
+
| [Sui](./sui.md) | `SuiWalletProvider` | Field presence (uses `mnemonics`) | `@mysten/sui` + `@mysten/wallet-standard` |
|
|
15
|
+
| [Bitcoin](./bitcoin.md) | `BitcoinWalletProvider` | Explicit `type` | `bitcoinjs-lib`, `ecpair`, `secp256k1` |
|
|
16
|
+
| [Stellar](./stellar.md) | `StellarWalletProvider` | Explicit `type` | `@stellar/stellar-sdk` |
|
|
17
|
+
| [ICON](./icon.md) | `IconWalletProvider` | Field presence | `icon-sdk-js` |
|
|
18
|
+
| [Injective](./injective.md)| `InjectiveWalletProvider` | Field presence (uses `secret` wrapper) | `@injectivelabs/sdk-ts`, `@injectivelabs/wallet-core` |
|
|
19
|
+
| [NEAR](./near.md) | `NearWalletProvider` | Field presence | `near-api-js` + `@hot-labs/near-connect` |
|
|
20
|
+
| [Stacks](./stacks.md) | `StacksWalletProvider` | Field presence | `@stacks/transactions`, `@stacks/connect` |
|
|
21
|
+
|
|
22
|
+
For the mental model behind these tables — why discriminants differ, how `defaults` merges, what `library-exports` re-exports — see [`../architecture.md`](../architecture.md).
|