@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,201 @@
|
|
|
1
|
+
# Recipe: Sign and broadcast (per chain)
|
|
2
|
+
|
|
3
|
+
Minimal raw-tx flows for each chain. Use these as smoke tests after construction, or when integrating outside of `@sodax/sdk`.
|
|
4
|
+
|
|
5
|
+
**Depends on:** [`setup-private-key.md`](./setup-private-key.md) or [`setup-browser-extension.md`](./setup-browser-extension.md).
|
|
6
|
+
|
|
7
|
+
For SDK-mediated flows (deposit, swap, bridge, lend, stake) see [`bridge-to-sdk.md`](./bridge-to-sdk.md) instead — this recipe is for chain-native raw transactions.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## EVM
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import type { EvmRawTransaction } from '@sodax/types';
|
|
15
|
+
|
|
16
|
+
const tx: EvmRawTransaction = {
|
|
17
|
+
to: '0x…',
|
|
18
|
+
value: 1_000_000_000_000_000n, // 0.001 ETH
|
|
19
|
+
data: '0x',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const hash = await provider.sendTransaction(tx);
|
|
23
|
+
// Optional per-call override: { gas: 5_000_000n }
|
|
24
|
+
|
|
25
|
+
const receipt = await provider.waitForTransactionReceipt(hash);
|
|
26
|
+
// Receipt is bigint-stringified — JSON-safe. receipt.blockNumber: string.
|
|
27
|
+
console.log(receipt.status, receipt.blockNumber);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Solana
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import type { SolanaRawTransactionInstruction } from '@sodax/types';
|
|
36
|
+
|
|
37
|
+
const instructions: SolanaRawTransactionInstruction[] = [/* … */];
|
|
38
|
+
|
|
39
|
+
const rawTx = await provider.buildV0Txn(instructions);
|
|
40
|
+
const signature = await provider.sendTransactionWithConfirmation(rawTx);
|
|
41
|
+
|
|
42
|
+
console.log('signature:', signature);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`buildV0Txn` picks the keypair-vs-adapter signing path internally. `sendTransactionWithConfirmation` waits to the `defaults.confirmCommitment` level (default `'finalized'`).
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Sui
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import type { SuiTransaction } from '@sodax/types';
|
|
53
|
+
|
|
54
|
+
const tx: SuiTransaction = /* build with @mysten/sui Transaction builder */;
|
|
55
|
+
|
|
56
|
+
const digest = await provider.signAndExecuteTxn(tx);
|
|
57
|
+
// Pre-flight dry-run is on by default. Disable for a doomed-tx flow:
|
|
58
|
+
// await provider.signAndExecuteTxn(tx, { dryRun: { enabled: false } });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Bitcoin
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// 1. Build a PSBT externally (or via your wallet kit) and serialise to base64.
|
|
67
|
+
const psbtBase64 = '/* … */';
|
|
68
|
+
|
|
69
|
+
// 2. Sign (finalize defaults to defaults.defaultFinalize, default true).
|
|
70
|
+
const signedTxOrPsbt = await provider.signTransaction(psbtBase64);
|
|
71
|
+
|
|
72
|
+
// 3. Broadcast — either via the wallet kit (browser mode) or your own broadcaster.
|
|
73
|
+
// PK mode does not implement a broadcaster in this provider — you submit the
|
|
74
|
+
// finalised tx to your own node or a public API.
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For message signing:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const sig = await provider.signEcdsaMessage('hello');
|
|
81
|
+
const sig322 = await provider.signBip322Message('hello');
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Stellar
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import type { XDR } from '@sodax/types';
|
|
90
|
+
|
|
91
|
+
// 1. Build the XDR externally (TransactionBuilder from @stellar/stellar-sdk).
|
|
92
|
+
const txXdr: XDR = '/* … */';
|
|
93
|
+
|
|
94
|
+
// 2. Sign.
|
|
95
|
+
const signedXdr = await provider.signTransaction(txXdr);
|
|
96
|
+
|
|
97
|
+
// 3. Submit to Horizon (the provider's `server` is private; build a Horizon.Server
|
|
98
|
+
// yourself or use a service layer that wraps submit).
|
|
99
|
+
|
|
100
|
+
// 4. Wait for inclusion (polls Horizon).
|
|
101
|
+
const receipt = await provider.waitForTransactionReceipt(submittedHash);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## ICON
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import type { IcxCallTransaction } from '@sodax/types';
|
|
110
|
+
|
|
111
|
+
const tx: IcxCallTransaction = /* build with icon-sdk-js IcxTransactionBuilder */;
|
|
112
|
+
|
|
113
|
+
const hash = await provider.sendTransaction(tx);
|
|
114
|
+
// Override step limit / version per call: { stepLimit: 5_000_000 }
|
|
115
|
+
|
|
116
|
+
const result = await provider.waitForTransactionReceipt(hash);
|
|
117
|
+
console.log(result.status);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Injective
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
// Reads the address (and pubkey) from the configured secret / msgBroadcaster.
|
|
126
|
+
const address = await provider.getWalletAddress();
|
|
127
|
+
const pubKey = await provider.getWalletPubKey();
|
|
128
|
+
|
|
129
|
+
// Build + execute via the upstream MsgBroadcaster. See @injectivelabs/sdk-ts
|
|
130
|
+
// docs for the canonical message builders (MsgSend, MsgExecuteContract, …).
|
|
131
|
+
const txResp = await provider.execute(/* params per @sodax/types */);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
For inspection-only flows, `getRawTransaction(…)` returns the unsigned tx without broadcasting.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## NEAR
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import type { CallContractParams, NearRawTransaction } from '@sodax/types';
|
|
142
|
+
|
|
143
|
+
const params: CallContractParams = /* … */;
|
|
144
|
+
const tx: NearRawTransaction = await provider.getRawTransaction(params);
|
|
145
|
+
|
|
146
|
+
const hash = await provider.signAndSubmitTxn(tx);
|
|
147
|
+
// Override waitUntil per call: { waitUntil: 'EXECUTED' }
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Stacks
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import type { StacksTransactionParams } from '@sodax/types';
|
|
156
|
+
import { PostConditionMode } from '@sodax/wallet-sdk-core';
|
|
157
|
+
|
|
158
|
+
const params: StacksTransactionParams = {
|
|
159
|
+
postConditionMode: PostConditionMode.Deny,
|
|
160
|
+
/* … */
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const txResp = await provider.sendTransaction(params);
|
|
164
|
+
|
|
165
|
+
// Read-only call (no broadcast):
|
|
166
|
+
const clarityValue = await provider.readContract(params);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Verification (any chain)
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pnpm checkTs
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
// Smoke test: address read
|
|
179
|
+
console.log(await provider.getWalletAddress());
|
|
180
|
+
|
|
181
|
+
// Then attempt a tiny tx on testnet. Save the returned hash and inspect it
|
|
182
|
+
// in the chain's explorer.
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Patterns to avoid
|
|
188
|
+
|
|
189
|
+
| Anti-pattern | Why bad | Replacement |
|
|
190
|
+
|---|---|---|
|
|
191
|
+
| Constructing the `Connection` / `SuiClient` / `Horizon.Server` yourself in PK mode | Duplicates work the provider already does | Read it off the provider (`provider.connection`, etc.) when exposed; otherwise just call the method. |
|
|
192
|
+
| Storing the signed tx in localStorage / IndexedDB | Persists secrets in browser storage | Sign + broadcast in one flow; don't persist signed-but-unbroadcast txs. |
|
|
193
|
+
| Catching every error generically and logging "tx failed" | Hides real causes (nonce, insufficient gas, malformed XDR, …) | Surface the upstream error; the provider doesn't wrap them. |
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## See also
|
|
198
|
+
|
|
199
|
+
- [`bridge-to-sdk.md`](./bridge-to-sdk.md) — handing off to `@sodax/sdk` for SODAX hub/spoke flows.
|
|
200
|
+
- [`defaults-and-overrides.md`](./defaults-and-overrides.md) — tuning the defaults slice.
|
|
201
|
+
- [`../features/<chain>.md`](../features/) — chain-specific method signatures and quirks.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Recipe: Testing — mocking providers
|
|
2
|
+
|
|
3
|
+
Patterns for unit-testing code that consumes `IXxxWalletProvider` interfaces. The same approach scales to integration tests against testnets.
|
|
4
|
+
|
|
5
|
+
**Depends on:** [`bridge-to-sdk.md`](./bridge-to-sdk.md) — your code should already type its functions against the interface, not the class.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Pattern 1 — Type the function signature on the interface
|
|
10
|
+
|
|
11
|
+
Make the function under test accept the interface, not the concrete class:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// ✅ Testable — accept the interface
|
|
15
|
+
import type { IEvmWalletProvider } from '@sodax/types';
|
|
16
|
+
|
|
17
|
+
export async function depositFlow(wallet: IEvmWalletProvider, amount: bigint) {
|
|
18
|
+
const addr = await wallet.getWalletAddress();
|
|
19
|
+
// …
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Mock the interface in the test:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
27
|
+
import type { IEvmWalletProvider } from '@sodax/types';
|
|
28
|
+
import { depositFlow } from '../depositFlow';
|
|
29
|
+
|
|
30
|
+
describe('depositFlow', () => {
|
|
31
|
+
it('uses the address from the provider', async () => {
|
|
32
|
+
const mockProvider: IEvmWalletProvider = {
|
|
33
|
+
chainType: 'EVM',
|
|
34
|
+
getWalletAddress: vi.fn(async () => '0xabc' as const),
|
|
35
|
+
sendTransaction: vi.fn(async () => '0xdeadbeef'),
|
|
36
|
+
waitForTransactionReceipt: vi.fn(async () => ({ /* … */ } as any)),
|
|
37
|
+
publicClient: undefined as never, // not used in this test
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
await depositFlow(mockProvider, 100n);
|
|
41
|
+
expect(mockProvider.getWalletAddress).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> Test files are the **only** place where `as any` / `as unknown as` casts should be tolerated — production code paths should rely on the discriminated unions instead.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Pattern 2 — Use the real provider against a local key
|
|
51
|
+
|
|
52
|
+
For end-to-end logic tests, construct a real provider with a deterministic key — no mocking, no network calls:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { describe, it } from 'vitest';
|
|
56
|
+
import { EvmWalletProvider } from '@sodax/wallet-sdk-core';
|
|
57
|
+
import { ChainKeys } from '@sodax/types';
|
|
58
|
+
|
|
59
|
+
const TEST_PK = '0x' + 'ab'.repeat(32) as `0x${string}`; // dev-only key
|
|
60
|
+
|
|
61
|
+
describe('EvmWalletProvider', () => {
|
|
62
|
+
it('derives the address from the private key', async () => {
|
|
63
|
+
const provider = new EvmWalletProvider({
|
|
64
|
+
privateKey: TEST_PK,
|
|
65
|
+
chainId: ChainKeys.SONIC_MAINNET,
|
|
66
|
+
});
|
|
67
|
+
const addr = await provider.getWalletAddress();
|
|
68
|
+
expect(addr).toMatch(/^0x[a-fA-F0-9]{40}$/);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`getWalletAddress` doesn't hit the network — viem derives the EOA from the key in-process.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Pattern 3 — Stub the upstream chain SDK with `vi.mock`
|
|
78
|
+
|
|
79
|
+
When you can't avoid testing the bits that **do** hit the network (sending, polling), stub the upstream chain SDK:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { vi } from 'vitest';
|
|
83
|
+
|
|
84
|
+
vi.mock('viem', async (importActual) => {
|
|
85
|
+
const actual = await importActual<typeof import('viem')>();
|
|
86
|
+
return {
|
|
87
|
+
...actual,
|
|
88
|
+
createWalletClient: vi.fn(() => ({
|
|
89
|
+
sendTransaction: vi.fn(async () => '0xfakehash'),
|
|
90
|
+
account: { address: '0xabc' as const },
|
|
91
|
+
// …
|
|
92
|
+
})),
|
|
93
|
+
createPublicClient: vi.fn(() => ({
|
|
94
|
+
waitForTransactionReceipt: vi.fn(async () => mockReceipt),
|
|
95
|
+
})),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This isolates the test from the network without rewriting the provider. The downside is that you're now testing your mock; reserve this pattern for cases where pattern 1 isn't enough.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Pattern 4 — Run against a testnet (true integration)
|
|
105
|
+
|
|
106
|
+
For real end-to-end coverage, use a testnet (Sonic Testnet, Solana Devnet, BTC Testnet, etc.) and a CI-managed key:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// vitest.config.ts — gate behind an env flag so devs don't accidentally run it
|
|
110
|
+
test: {
|
|
111
|
+
exclude: process.env.RUN_E2E ? [] : ['**/*.e2e.test.ts'],
|
|
112
|
+
},
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
// foo.e2e.test.ts
|
|
117
|
+
import { EvmWalletProvider } from '@sodax/wallet-sdk-core';
|
|
118
|
+
import { ChainKeys } from '@sodax/types';
|
|
119
|
+
|
|
120
|
+
const PK = process.env.E2E_EVM_PK as `0x${string}`;
|
|
121
|
+
const RPC = process.env.E2E_EVM_RPC;
|
|
122
|
+
|
|
123
|
+
describe.skipIf(!PK)('e2e — EVM testnet', () => {
|
|
124
|
+
it('sends a 0-value tx', async () => {
|
|
125
|
+
const provider = new EvmWalletProvider({ privateKey: PK, chainId: ChainKeys.SONIC_MAINNET, rpcUrl: RPC });
|
|
126
|
+
const hash = await provider.sendTransaction({ to: '0x…', value: 0n, data: '0x' });
|
|
127
|
+
expect(hash).toMatch(/^0x[a-fA-F0-9]{64}$/);
|
|
128
|
+
}, 60_000);
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`apps/node/src/tests/` in this repo follows this pattern — see those test files for live examples.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## What NOT to test
|
|
137
|
+
|
|
138
|
+
| Test idea | Why skip | Alternative |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| The merge semantics of `defaults` | Already covered by `src/utils/merge.test.ts` in this package | Trust the merge; test your **policy** values are right |
|
|
141
|
+
| viem's `sendTransaction` semantics | Not your code | Mock at pattern 3 if you need to assert your provider passes args through |
|
|
142
|
+
| Wallet-extension UI flows in unit tests | Browser-only | Use Playwright / Cypress against a real extension build |
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Verification
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pnpm test
|
|
150
|
+
pnpm checkTs
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Confirm test files use the interface, not the class, for type annotations
|
|
155
|
+
grep -rn "IEvmWalletProvider\|ISolanaWalletProvider\|IBitcoinWalletProvider" <user-src>/**/*.test.ts
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## See also
|
|
161
|
+
|
|
162
|
+
- `src/utils/merge.test.ts` — reference test style for utility-level tests in this package.
|
|
163
|
+
- Every `src/wallet-providers/*/`*`WalletProvider.test.ts` file — provider-level test patterns.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Reference
|
|
2
|
+
|
|
3
|
+
Lookup tables. Use these to answer "what does X look like" without reading source.
|
|
4
|
+
|
|
5
|
+
| File | Use for |
|
|
6
|
+
|---|---|
|
|
7
|
+
| [`public-api.md`](./public-api.md) | Every named export from `@sodax/wallet-sdk-core`. |
|
|
8
|
+
| [`provider-classes.md`](./provider-classes.md) | Class × config × interface × default-merge-helper matrix. |
|
|
9
|
+
| [`interfaces.md`](./interfaces.md) | `IXxxWalletProvider` method signatures (sourced from `@sodax/types`). |
|
|
10
|
+
| [`chain-support.md`](./chain-support.md) | Chain family → spoke chain keys + provider. |
|
|
11
|
+
| [`glossary.md`](./glossary.md) | Terms used across the docs. |
|
|
12
|
+
|
|
13
|
+
All files in this directory are intentionally **terse and table-heavy** — for narrative explanations see [`../architecture.md`](../architecture.md) and the per-chain [`../features/`](../features/) files.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Chain support
|
|
2
|
+
|
|
3
|
+
Chain families and spoke chain keys this package can sign for. Keys live in `@sodax/types`.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## EVM (one provider, 12 chains)
|
|
8
|
+
|
|
9
|
+
`EvmWalletProvider` covers every EVM spoke chain via `getEvmViemChain()`. The provider is exhaustive — adding a new `EvmChainKey` to `@sodax/types` requires updating `getEvmViemChain` (caught at compile time via a `never` assertion in the default branch).
|
|
10
|
+
|
|
11
|
+
| Spoke chain key | viem chain |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `ChainKeys.SONIC_MAINNET` (hub) | `sonic` |
|
|
14
|
+
| `ChainKeys.ETHEREUM_MAINNET` | `mainnet` |
|
|
15
|
+
| `ChainKeys.ARBITRUM_MAINNET` | `arbitrum` |
|
|
16
|
+
| `ChainKeys.BASE_MAINNET` | `base` |
|
|
17
|
+
| `ChainKeys.BSC_MAINNET` | `bsc` |
|
|
18
|
+
| `ChainKeys.OPTIMISM_MAINNET` | `optimism` |
|
|
19
|
+
| `ChainKeys.POLYGON_MAINNET` | `polygon` |
|
|
20
|
+
| `ChainKeys.AVALANCHE_MAINNET` | `avalanche` |
|
|
21
|
+
| `ChainKeys.HYPEREVM_MAINNET` | `hyper` (defined inside this package) |
|
|
22
|
+
| `ChainKeys.LIGHTLINK_MAINNET` | `lightlinkPhoenix` |
|
|
23
|
+
| `ChainKeys.REDBELLY_MAINNET` | `redbellyMainnet` |
|
|
24
|
+
| `ChainKeys.KAIA_MAINNET` | `kaia` |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Non-EVM (one provider per chain family)
|
|
29
|
+
|
|
30
|
+
| Chain family | Provider | Spoke chain key(s) |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| Solana | `SolanaWalletProvider` | `ChainKeys.SOLANA_MAINNET` |
|
|
33
|
+
| Sui | `SuiWalletProvider` | `ChainKeys.SUI_MAINNET` |
|
|
34
|
+
| Bitcoin | `BitcoinWalletProvider` | `ChainKeys.BITCOIN_MAINNET` |
|
|
35
|
+
| Stellar | `StellarWalletProvider` | `ChainKeys.STELLAR_MAINNET` |
|
|
36
|
+
| ICON | `IconWalletProvider` | `ChainKeys.ICON_MAINNET` |
|
|
37
|
+
| Injective | `InjectiveWalletProvider` | `ChainKeys.INJECTIVE_MAINNET` |
|
|
38
|
+
| NEAR | `NearWalletProvider` | `ChainKeys.NEAR_MAINNET` |
|
|
39
|
+
| Stacks | `StacksWalletProvider` | `ChainKeys.STACKS_MAINNET` |
|
|
40
|
+
|
|
41
|
+
> 20 spoke chains total = 12 EVM + 8 non-EVM. The hub chain (Sonic) is counted with EVM.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Upstream chain-SDK matrix
|
|
46
|
+
|
|
47
|
+
Run-time deps each provider pulls in. See [`../recipes/library-exports.md`](../recipes/library-exports.md) for how to re-import their **types** without a direct dep.
|
|
48
|
+
|
|
49
|
+
| Provider | Upstream SDKs |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `EvmWalletProvider` | `viem` |
|
|
52
|
+
| `SolanaWalletProvider` | `@solana/web3.js`, `@solana/spl-token`, `@solana/wallet-adapter-base` |
|
|
53
|
+
| `SuiWalletProvider` | `@mysten/sui`, `@mysten/wallet-standard` |
|
|
54
|
+
| `BitcoinWalletProvider` | `bitcoinjs-lib`, `ecpair`, `secp256k1`, `@bitcoinerlab/secp256k1`, `bip322-js` |
|
|
55
|
+
| `StellarWalletProvider` | `@stellar/stellar-sdk` |
|
|
56
|
+
| `IconWalletProvider` | `icon-sdk-js` |
|
|
57
|
+
| `InjectiveWalletProvider` | `@injectivelabs/sdk-ts`, `@injectivelabs/wallet-core`, `@injectivelabs/networks`, `@injectivelabs/ts-types` |
|
|
58
|
+
| `NearWalletProvider` | `near-api-js`, `@hot-labs/near-connect` |
|
|
59
|
+
| `StacksWalletProvider` | `@stacks/transactions`, `@stacks/connect`, `@stacks/network` |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## When to NOT use this package
|
|
64
|
+
|
|
65
|
+
If your chain is not in the table above, this package does not yet support it. Adding a new chain is a **maintainer task** — open an issue if your chain is missing.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Glossary
|
|
2
|
+
|
|
3
|
+
Terms used across the `wallet-sdk-core` docs.
|
|
4
|
+
|
|
5
|
+
| Term | Meaning |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **`BaseWalletProvider`** | Abstract base class every provider extends. Holds `defaults` and exposes `mergePolicy` / `mergeDefaults`. |
|
|
8
|
+
| **Browser-extension mode** | Construction mode where the caller supplies pre-built chain clients / wallet kits from a wallet extension (MetaMask, Phantom, Xverse, Hana, Freighter, Leather, …). |
|
|
9
|
+
| **`chainType`** | Literal string identifier on each provider class (`'EVM'`, `'SOLANA'`, …). Mirrors `ChainType` in `@sodax/types`. |
|
|
10
|
+
| **Discriminant style** | How the union narrows. Either **field presence** (most chains) or an explicit **`type` field** (Bitcoin, Stellar). |
|
|
11
|
+
| **`defaults`** | Optional config slice merged into every method call. Shape per chain is `*WalletDefaults`. |
|
|
12
|
+
| **EOA** | Externally Owned Account — a wallet derived from a key, as opposed to a contract account. Some chains brand it (`IconEoaAddress`, `InjectiveEoaAddress`). |
|
|
13
|
+
| **Field presence** | A discriminated union narrowed by which fields exist (`'privateKey' in config` vs `'walletClient' in config`). |
|
|
14
|
+
| **Flat merge** (`mergeDefaults`) | Defaults are a flat object; per-call options shallow-merge over the entire object. |
|
|
15
|
+
| **Hub / Spoke** | SODAX architecture term. Sonic is the hub; all other 19 chains are spokes. `wallet-sdk-core` provides spoke-side wallet primitives. |
|
|
16
|
+
| **`IXxxWalletProvider`** | Chain-specific interface from `@sodax/types`. The class implements it; the SDK consumes it. |
|
|
17
|
+
| **`library-exports`** | `src/types/library-exports.ts` — curated re-exports of upstream chain-SDK types (and 2 runtime enums). |
|
|
18
|
+
| **Mnemonics** | BIP-39 phrase. Used as the private-key credential on Sui (no raw-key option) and as one option on Injective via the `secret` wrapper. |
|
|
19
|
+
| **Per-method merge** (`mergePolicy`) | Defaults are grouped per method (`defaults.sendTransaction`, …); per-call options shallow-merge over the matching slice. |
|
|
20
|
+
| **Private-key mode** | Construction mode where the caller supplies a raw secret (or mnemonic / nested `secret` for some chains). Server / script / CI flows only. |
|
|
21
|
+
| **PSBT** | Partially Signed Bitcoin Transaction. Bitcoin `signTransaction` accepts a base64-encoded PSBT. |
|
|
22
|
+
| **`secret`** (Injective only) | Nested credential wrapper accepting `{ privateKey }` or `{ mnemonics }` in `SecretInjectiveWalletConfig`. |
|
|
23
|
+
| **Shallow merge** | Top-level keys are merged; nested objects are replaced wholesale. See `src/utils/merge.ts`. |
|
|
24
|
+
| **Spoke chain key** | Branded string from `@sodax/types` identifying a chain (`ChainKeys.SONIC_MAINNET`, `ChainKeys.BSC_MAINNET`, …). |
|
|
25
|
+
| **`type` discriminant** | Explicit uppercase `type: 'PRIVATE_KEY' \| 'BROWSER_EXTENSION'` field. Used by Bitcoin and Stellar only. |
|
|
26
|
+
| **`WalletAddressProvider`** | Base interface in `@sodax/types` — exposes `getWalletAddress(): Promise<string>`. Every `IXxxWalletProvider` extends it. |
|
|
27
|
+
| **`walletsKit`** | Consumer-supplied adapter in Bitcoin / Stellar browser-extension mode. Conforms to `BitcoinWalletsKit` / `StellarWalletsKit`. |
|
|
28
|
+
| **XDR** | Stellar's binary transaction format, encoded as a string. Type alias `XDR` from `@sodax/types`. |
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# `IXxxWalletProvider` interfaces
|
|
2
|
+
|
|
3
|
+
The signatures `@sodax/sdk` consumes. Sourced from `@sodax/types`; one interface per chain. Pass the **interface**, not the class, in function signatures — see [`../recipes/bridge-to-sdk.md`](../recipes/bridge-to-sdk.md).
|
|
4
|
+
|
|
5
|
+
The tables below summarise the methods each provider exposes. For full type-level signatures (including the chain-specific param/return types) consult `@sodax/types`'s package — these tables intentionally elide deep generics.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## `IEvmWalletProvider`
|
|
10
|
+
|
|
11
|
+
| Method | Signature (abridged) |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `getWalletAddress` | `() => Promise<Address>` |
|
|
14
|
+
| `sendTransaction` | `(tx: EvmRawTransaction, opts?: EvmSendTransactionPolicy) => Promise<Hash>` |
|
|
15
|
+
| `waitForTransactionReceipt` | `(hash: Hash, opts?: EvmWaitForTransactionReceiptPolicy) => Promise<EvmRawTransactionReceipt>` |
|
|
16
|
+
|
|
17
|
+
Plus public field: `publicClient: PublicClient`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## `ISolanaWalletProvider`
|
|
22
|
+
|
|
23
|
+
| Method | Signature (abridged) |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
26
|
+
| `getWalletBase58PublicKey` | `() => SolanaBase58PublicKey` |
|
|
27
|
+
| `sendTransaction` | `(rawTx, opts?: SendOptions) => Promise<string>` |
|
|
28
|
+
| `sendTransactionWithConfirmation` | `(rawTx, sendOpts?, confirmCommitment?) => Promise<string>` |
|
|
29
|
+
| `waitForConfirmation` | `(signature, commitment?) => Promise<…>` |
|
|
30
|
+
| `buildV0Txn` | `(rawInstructions) => Promise<SolanaSerializedTransaction>` |
|
|
31
|
+
| `getAssociatedTokenAddress` | `(mint) => Promise<SolanaBase58PublicKey>` |
|
|
32
|
+
| `getBalance` | `(publicKey) => Promise<number>` |
|
|
33
|
+
| `getTokenAccountBalance` | `(publicKey) => Promise<RpcResponseAndContext<TokenAmount>>` |
|
|
34
|
+
|
|
35
|
+
Plus public field: `connection: Connection`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## `ISuiWalletProvider`
|
|
40
|
+
|
|
41
|
+
| Method | Signature (abridged) |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
44
|
+
| `signAndExecuteTxn` | `(txn: SuiTransaction, opts?: SuiSignAndExecutePolicy) => Promise<string>` |
|
|
45
|
+
| `viewContract` | `(txn, …) => Promise<…>` |
|
|
46
|
+
| `getCoins` | `(address, token, opts?: SuiGetCoinsPolicy) => Promise<SuiPaginatedCoins>` |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## `IBitcoinWalletProvider`
|
|
51
|
+
|
|
52
|
+
| Method | Signature (abridged) |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
55
|
+
| `getPublicKey` | `() => Promise<string>` |
|
|
56
|
+
| `getAddressType` | `(address: string) => Promise<BtcAddressType>` |
|
|
57
|
+
| `signTransaction` | `(psbtBase64: string, finalize?: boolean) => Promise<string>` |
|
|
58
|
+
| `signEcdsaMessage` | `(message: string) => Promise<string>` |
|
|
59
|
+
| `signBip322Message` | `(message: string) => Promise<string>` |
|
|
60
|
+
| `getPayment` | `(keyPair, addressType) => bitcoin.Payment` (PK mode helper) |
|
|
61
|
+
| `sendBitcoin` | `(toAddress: string, satoshis: bigint) => Promise<string>` (only if wallet kit implements it) |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## `IStellarWalletProvider`
|
|
66
|
+
|
|
67
|
+
| Method | Signature (abridged) |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
70
|
+
| `signTransaction` | `(tx: XDR) => Promise<XDR>` |
|
|
71
|
+
| `waitForTransactionReceipt` | `(hash: string, opts?: Partial<StellarWalletDefaults>) => Promise<…>` |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## `IIconWalletProvider`
|
|
76
|
+
|
|
77
|
+
| Method | Signature (abridged) |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `getWalletAddress` | `() => Promise<IconEoaAddress>` |
|
|
80
|
+
| `sendTransaction` | `(tx: IcxCallTransaction, opts?: IconWalletDefaults) => Promise<Hash>` |
|
|
81
|
+
| `waitForTransactionReceipt` | `(txHash: Hash) => Promise<IconTransactionResult>` |
|
|
82
|
+
|
|
83
|
+
Plus public field: `iconService: IconService`.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## `IInjectiveWalletProvider`
|
|
88
|
+
|
|
89
|
+
| Method | Signature (abridged) |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `getWalletAddress` | `() => Promise<InjectiveEoaAddress>` |
|
|
92
|
+
| `getWalletPubKey` | `() => Promise<string>` |
|
|
93
|
+
| `getRawTransaction` | `(…) => Promise<…>` |
|
|
94
|
+
| `execute` | `(…) => Promise<…>` |
|
|
95
|
+
|
|
96
|
+
Plus public field: `wallet: InjectiveWallet`.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## `INearWalletProvider`
|
|
101
|
+
|
|
102
|
+
| Method | Signature (abridged) |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
105
|
+
| `getRawTransaction` | `(params: CallContractParams) => Promise<NearRawTransaction>` |
|
|
106
|
+
| `signAndSubmitTxn` | `(tx: NearRawTransaction, opts?: NearWalletDefaults) => Promise<string>` |
|
|
107
|
+
|
|
108
|
+
Plus public fields (PK mode only): `account?: Account`, `rpcProvider?: JsonRpcProvider`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## `IStacksWalletProvider`
|
|
113
|
+
|
|
114
|
+
| Method | Signature (abridged) |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `getWalletAddress` | `() => Promise<string>` |
|
|
117
|
+
| `getPublicKey` | `() => Promise<string>` |
|
|
118
|
+
| `sendTransaction` | `(params: StacksTransactionParams) => Promise<…>` |
|
|
119
|
+
| `readContract` | `(params: StacksTransactionParams) => Promise<ClarityValue>` |
|
|
120
|
+
| `getBalance` | `(address: string) => Promise<bigint>` |
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Authoritative source
|
|
125
|
+
|
|
126
|
+
These tables are summarised. For the full, current type-level signatures (including generics, branded types, and union narrowings) read:
|
|
127
|
+
|
|
128
|
+
- `@sodax/types/src/wallet-providers/*.ts` (each interface lives here)
|
|
129
|
+
- The implementing class in `packages/wallet-sdk-core/src/wallet-providers/<chain>/`.
|
|
130
|
+
|
|
131
|
+
If a method exists on the class but not on the interface, it is an **implementation detail** — do not depend on it from outside the package.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Provider classes — class × config × interface × merge helper
|
|
2
|
+
|
|
3
|
+
One row per chain. Use this when you know the chain and need to look up everything else.
|
|
4
|
+
|
|
5
|
+
| Chain | Class | Config union | Interface (`@sodax/types`) | Default merge helper | Discriminant |
|
|
6
|
+
|---|---|---|---|---|---|
|
|
7
|
+
| EVM | `EvmWalletProvider` | `EvmWalletConfig` | `IEvmWalletProvider` | `mergePolicy` (per-method) | Field presence (no `type`) |
|
|
8
|
+
| Solana | `SolanaWalletProvider` | `SolanaWalletConfig` | `ISolanaWalletProvider` | `mergePolicy` (per-method) | Field presence (no `type`) |
|
|
9
|
+
| Sui | `SuiWalletProvider` | `SuiWalletConfig` | `ISuiWalletProvider` | `mergePolicy` (per-method) | Field presence — uses `mnemonics` |
|
|
10
|
+
| Bitcoin | `BitcoinWalletProvider` | `BitcoinWalletConfig` | `IBitcoinWalletProvider` | `mergeDefaults` (flat) | **`type` field** (`'PRIVATE_KEY' \| 'BROWSER_EXTENSION'`) |
|
|
11
|
+
| Stellar | `StellarWalletProvider` | `StellarWalletConfig` | `IStellarWalletProvider` | `mergeDefaults` (flat) | **`type` field** |
|
|
12
|
+
| ICON | `IconWalletProvider` | `IconWalletConfig` | `IIconWalletProvider` | `mergeDefaults` (flat) | Field presence (no `type`) |
|
|
13
|
+
| Injective | `InjectiveWalletProvider` | `InjectiveWalletConfig` | `IInjectiveWalletProvider` | `mergeDefaults` (flat) | Field presence — PK variant uses `secret` wrapper |
|
|
14
|
+
| NEAR | `NearWalletProvider` | `NearWalletConfig` | `INearWalletProvider` | `mergeDefaults` (flat) | Field presence (no `type`) |
|
|
15
|
+
| Stacks | `StacksWalletProvider` | `StacksWalletConfig` | `IStacksWalletProvider` | `mergeDefaults` (flat) | Field presence (no `type`) |
|
|
16
|
+
|
|
17
|
+
> EVM, Solana, and Sui group their `defaults` per method (e.g. `defaults.sendTransaction`, `defaults.signAndExecuteTxn`). Every other chain has a flat `defaults` object. See [`../architecture.md`](../architecture.md) § `BaseWalletProvider`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## All exported `chainType` literals
|
|
22
|
+
|
|
23
|
+
| Provider | `chainType` |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `EvmWalletProvider` | `'EVM'` |
|
|
26
|
+
| `SolanaWalletProvider` | `'SOLANA'` |
|
|
27
|
+
| `SuiWalletProvider` | `'SUI'` |
|
|
28
|
+
| `BitcoinWalletProvider` | `'BITCOIN'` |
|
|
29
|
+
| `StellarWalletProvider` | `'STELLAR'` |
|
|
30
|
+
| `IconWalletProvider` | `'ICON'` |
|
|
31
|
+
| `InjectiveWalletProvider` | `'INJECTIVE'` |
|
|
32
|
+
| `NearWalletProvider` | `'NEAR'` |
|
|
33
|
+
| `StacksWalletProvider` | `'STACKS'` |
|
|
34
|
+
|
|
35
|
+
These match `ChainType` values in `@sodax/types`. Useful for runtime discrimination of a generic `IXxxWalletProvider`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Class hierarchy
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
BaseWalletProvider<TDefaults> ← abstract base from this package
|
|
43
|
+
├── EvmWalletProvider implements IEvmWalletProvider
|
|
44
|
+
├── SolanaWalletProvider implements ISolanaWalletProvider
|
|
45
|
+
├── SuiWalletProvider implements ISuiWalletProvider
|
|
46
|
+
├── BitcoinWalletProvider implements IBitcoinWalletProvider
|
|
47
|
+
├── StellarWalletProvider implements IStellarWalletProvider
|
|
48
|
+
├── IconWalletProvider implements IIconWalletProvider
|
|
49
|
+
├── InjectiveWalletProvider implements IInjectiveWalletProvider
|
|
50
|
+
├── NearWalletProvider implements INearWalletProvider
|
|
51
|
+
└── StacksWalletProvider implements IStacksWalletProvider
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Subclassing `BaseWalletProvider` is **maintainer-only** — it implies adding a new chain to the package.
|