@sodax/dapp-kit 2.0.0-rc.2 → 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/README.md +9 -63
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +3 -6
- package/package.json +31 -19
- package/src/providers/SodaxProvider.tsx +15 -11
- package/ai-exported/AGENTS.md +0 -134
- package/ai-exported/integration/README.md +0 -49
- package/ai-exported/integration/ai-rules.md +0 -79
- package/ai-exported/integration/architecture.md +0 -274
- package/ai-exported/integration/features/README.md +0 -29
- package/ai-exported/integration/features/auxiliary-services.md +0 -169
- package/ai-exported/integration/features/bitcoin.md +0 -87
- package/ai-exported/integration/features/bridge.md +0 -91
- package/ai-exported/integration/features/dex.md +0 -152
- package/ai-exported/integration/features/migration.md +0 -118
- package/ai-exported/integration/features/money-market.md +0 -116
- package/ai-exported/integration/features/staking.md +0 -123
- package/ai-exported/integration/features/swap.md +0 -101
- package/ai-exported/integration/quickstart.md +0 -187
- package/ai-exported/integration/recipes/README.md +0 -136
- package/ai-exported/integration/recipes/backend-queries.md +0 -157
- package/ai-exported/integration/recipes/bitcoin.md +0 -193
- package/ai-exported/integration/recipes/bridge.md +0 -174
- package/ai-exported/integration/recipes/dex.md +0 -204
- package/ai-exported/integration/recipes/invalidations.md +0 -115
- package/ai-exported/integration/recipes/migration.md +0 -212
- package/ai-exported/integration/recipes/money-market.md +0 -206
- package/ai-exported/integration/recipes/mutation-error-handling.md +0 -118
- package/ai-exported/integration/recipes/observability.md +0 -93
- package/ai-exported/integration/recipes/setup.md +0 -144
- package/ai-exported/integration/recipes/staking.md +0 -202
- package/ai-exported/integration/recipes/swap.md +0 -272
- package/ai-exported/integration/recipes/wallet-connectivity.md +0 -101
- package/ai-exported/integration/reference/README.md +0 -12
- package/ai-exported/integration/reference/glossary.md +0 -188
- package/ai-exported/integration/reference/hooks-index.md +0 -190
- package/ai-exported/integration/reference/public-api.md +0 -110
- package/ai-exported/integration/reference/querykey-conventions.md +0 -179
- package/ai-exported/migration/README.md +0 -60
- package/ai-exported/migration/ai-rules.md +0 -81
- package/ai-exported/migration/breaking-changes/hook-signatures.md +0 -233
- package/ai-exported/migration/breaking-changes/querykey-conventions.md +0 -108
- package/ai-exported/migration/breaking-changes/result-handling.md +0 -211
- package/ai-exported/migration/breaking-changes/sdk-leakage.md +0 -165
- package/ai-exported/migration/checklist.md +0 -89
- package/ai-exported/migration/features/README.md +0 -34
- package/ai-exported/migration/features/auxiliary-services.md +0 -114
- package/ai-exported/migration/features/bitcoin.md +0 -88
- package/ai-exported/migration/features/bridge.md +0 -123
- package/ai-exported/migration/features/dex.md +0 -101
- package/ai-exported/migration/features/migration.md +0 -120
- package/ai-exported/migration/features/money-market.md +0 -97
- package/ai-exported/migration/features/staking.md +0 -109
- package/ai-exported/migration/features/swap.md +0 -118
- package/ai-exported/migration/recipes.md +0 -188
- package/ai-exported/migration/reference/README.md +0 -15
- package/ai-exported/migration/reference/deleted-hooks.md +0 -110
- package/ai-exported/migration/reference/error-shape-crosswalk.md +0 -144
- package/ai-exported/migration/reference/renamed-hooks.md +0 -66
- package/dist/index.cjs +0 -2642
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1550
- package/dist/index.mjs.map +0 -1
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# Recipe: Wallet Connectivity
|
|
2
|
-
|
|
3
|
-
Connect wallets and pass wallet providers to feature hooks.
|
|
4
|
-
|
|
5
|
-
**Depends on:** [setup.md](setup.md)
|
|
6
|
-
|
|
7
|
-
## Hooks
|
|
8
|
-
|
|
9
|
-
| Hook | Package | Type | Purpose |
|
|
10
|
-
|------|---------|------|---------|
|
|
11
|
-
| `useWalletProvider` | `@sodax/wallet-sdk-react` | Utility | Get wallet provider for a chain from connected wallet |
|
|
12
|
-
| `useHubProvider` | `@sodax/dapp-kit` | Utility | Access the hub chain (Sonic) provider |
|
|
13
|
-
| `useDeriveUserWalletAddress` | `@sodax/dapp-kit` | Query | Derive hub wallet address from spoke address (CREATE3) |
|
|
14
|
-
| `useGetUserHubWalletAddress` | `@sodax/dapp-kit` | Query | Derive hub wallet address via wallet router |
|
|
15
|
-
| `useXBalances` | `@sodax/dapp-kit` | Query | Cross-chain token balances for an address |
|
|
16
|
-
| `useEstimateGas` | `@sodax/dapp-kit` | Mutation | Estimate gas for raw transactions |
|
|
17
|
-
| `useStellarTrustlineCheck` | `@sodax/dapp-kit` | Query | Check if Stellar account has sufficient trustline |
|
|
18
|
-
| `useRequestTrustline` | `@sodax/dapp-kit` | Mutation | Request a Stellar trustline for a token |
|
|
19
|
-
|
|
20
|
-
## Connect a Wallet
|
|
21
|
-
|
|
22
|
-
`@sodax/wallet-sdk-react` provides per-chain wallet hooks:
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
// @ai-snippets-skip
|
|
26
|
-
import { useEvmWallet } from '@sodax/wallet-sdk-react';
|
|
27
|
-
|
|
28
|
-
function ConnectButton() {
|
|
29
|
-
const { connect, disconnect, address, isConnected } = useEvmWallet();
|
|
30
|
-
|
|
31
|
-
if (isConnected) {
|
|
32
|
-
return (
|
|
33
|
-
<div>
|
|
34
|
-
<span>{address}</span>
|
|
35
|
-
<button onClick={disconnect}>Disconnect</button>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return <button onClick={() => connect()}>Connect Wallet</button>;
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Get a Wallet Provider
|
|
44
|
-
|
|
45
|
-
`useWalletProvider` returns a typed wallet provider for a specific chain. Pass it directly to feature hook mutation calls:
|
|
46
|
-
|
|
47
|
-
```tsx
|
|
48
|
-
import { useWalletProvider } from '@sodax/wallet-sdk-react';
|
|
49
|
-
import { ChainKeys } from '@sodax/sdk';
|
|
50
|
-
|
|
51
|
-
function MyFeature() {
|
|
52
|
-
const walletProvider = useWalletProvider({ xChainId: ChainKeys.BSC_MAINNET });
|
|
53
|
-
// undefined until wallet is connected for that chain
|
|
54
|
-
// Pass as: useSwap() then swap({ params, walletProvider })
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Fetch Token Balances
|
|
59
|
-
|
|
60
|
-
`useXBalances` from `@sodax/dapp-kit` fetches on-chain balances for a wallet address:
|
|
61
|
-
|
|
62
|
-
```tsx
|
|
63
|
-
import { useXBalances } from '@sodax/dapp-kit';
|
|
64
|
-
import { useXService, getXChainType } from '@sodax/wallet-sdk-react';
|
|
65
|
-
import { ChainKeys, type XToken } from '@sodax/sdk';
|
|
66
|
-
|
|
67
|
-
function TokenBalance({ address, xTokens }: { address: string; xTokens: readonly XToken[] }) {
|
|
68
|
-
const xChainId = ChainKeys.BSC_MAINNET;
|
|
69
|
-
// `useXBalances` requires an `xService` from `@sodax/wallet-sdk-react` plus the chain key,
|
|
70
|
-
// the token list to read, and the user's address — all four fields are part of `params`.
|
|
71
|
-
const xService = useXService({ xChainType: getXChainType(xChainId) });
|
|
72
|
-
const { data: balances } = useXBalances({
|
|
73
|
-
params: { xService, xChainId, xTokens, address },
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// balances is a map of token address → balance (bigint)
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Use Wallet Provider in Feature Hooks
|
|
81
|
-
|
|
82
|
-
All mutation hooks accept no arguments at initialization level. The `walletProvider` flows through `mutate(vars)`:
|
|
83
|
-
|
|
84
|
-
```tsx
|
|
85
|
-
import { useSwap } from '@sodax/dapp-kit';
|
|
86
|
-
import { useWalletProvider } from '@sodax/wallet-sdk-react';
|
|
87
|
-
import { ChainKeys } from '@sodax/sdk';
|
|
88
|
-
|
|
89
|
-
function SwapButton() {
|
|
90
|
-
const walletProvider = useWalletProvider({ xChainId: ChainKeys.BSC_MAINNET });
|
|
91
|
-
const { mutateAsync: swap, isPending } = useSwap();
|
|
92
|
-
|
|
93
|
-
const handleSwap = async () => {
|
|
94
|
-
if (!walletProvider) return;
|
|
95
|
-
const result = await swap({ params: intentParams, walletProvider });
|
|
96
|
-
// ...
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
This pattern is consistent across all features: `useSwap`, `useBridge`, `useSupply`, `useStake`, `useDexDeposit`, etc.
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# Reference — `@sodax/dapp-kit` v2
|
|
2
|
-
|
|
3
|
-
Lookup tables. Read while writing code; not a tutorial.
|
|
4
|
-
|
|
5
|
-
| File | What's in it |
|
|
6
|
-
|---|---|
|
|
7
|
-
| [`hooks-index.md`](hooks-index.md) | Comprehensive hook table (organized by feature, with hook type and purpose). |
|
|
8
|
-
| [`querykey-conventions.md`](querykey-conventions.md) | Mandatory queryKey/mutationKey shape rules + per-feature key tables. |
|
|
9
|
-
| [`public-api.md`](public-api.md) | What `@sodax/dapp-kit` exports + import rules. |
|
|
10
|
-
| [`glossary.md`](glossary.md) | Type aliases (`ReadHookParams`, `MutationHookParams`, `SafeUseMutationResult`, `MutationHookOptions`, etc.). |
|
|
11
|
-
|
|
12
|
-
For full SDK reference (chain keys, error codes, `Sodax` class surface, wallet provider interfaces), see [`../../../../sdk/ai-exported/integration/reference/`](../../../../sdk/ai-exported/integration/reference/) — `@sodax/dapp-kit` re-exports the SDK's public surface, so those types are reachable from `@sodax/dapp-kit` directly.
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# Glossary — `@sodax/dapp-kit` v2
|
|
2
|
-
|
|
3
|
-
Type aliases, conventions, and domain terms specific to dapp-kit. SDK-side terms (Hub, Spoke, Intent, ChainKey, SodaxError, etc.) are documented in [`../../../../sdk/ai-exported/integration/reference/glossary.md`](../../../../sdk/ai-exported/integration/reference/glossary.md).
|
|
4
|
-
|
|
5
|
-
## Hook shape types
|
|
6
|
-
|
|
7
|
-
### `ReadHookParams<TData, TParams = void>`
|
|
8
|
-
|
|
9
|
-
Canonical shape for query hook arguments. Single object with `params` and `queryOptions` keys.
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
// @ai-snippets-skip
|
|
13
|
-
type ReadHookParams<TData, TParams = void> = TParams extends void
|
|
14
|
-
? { queryOptions?: ReadQueryOptions<TData> }
|
|
15
|
-
: { params?: TParams; queryOptions?: ReadQueryOptions<TData> };
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
If a hook has no domain inputs (e.g. `useStakingConfig`), it uses `ReadHookParams<TData>` (no `TParams`) and accepts `({} = {})` for ergonomic no-arg calls.
|
|
19
|
-
|
|
20
|
-
### `ReadQueryOptions<TData>`
|
|
21
|
-
|
|
22
|
-
The options slot for query hooks, omitting hook-owned fields.
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
// @ai-snippets-skip
|
|
26
|
-
type ReadQueryOptions<TData> = Omit<UseQueryOptions<TData, Error>, 'queryKey' | 'queryFn' | 'enabled'>;
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Hook owns `queryKey`, `queryFn`, and `enabled` — never consumer-overridable. `enabled` is derived from required-input presence.
|
|
30
|
-
|
|
31
|
-
### `MutationHookParams<TData, TVars>`
|
|
32
|
-
|
|
33
|
-
Canonical shape for mutation hook arguments. Single object with one key: `mutationOptions`.
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
// @ai-snippets-skip
|
|
37
|
-
type MutationHookParams<TData, TVars> = {
|
|
38
|
-
mutationOptions?: MutationHookOptions<TData, TVars>;
|
|
39
|
-
};
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Domain inputs (`params`, `walletProvider`, per-call config) flow through `mutate(vars)` via `TVars`.
|
|
43
|
-
|
|
44
|
-
### `MutationHookOptions<TData, TVars>`
|
|
45
|
-
|
|
46
|
-
The options slot for mutation hooks, omitting hook-owned fields.
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
// @ai-snippets-skip
|
|
50
|
-
type MutationHookOptions<TData, TVars> = Omit<UseMutationOptions<TData, Error, TVars>, 'mutationFn'>;
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Hook owns `mutationFn`. Consumer can override `mutationKey`, `onSuccess`, `onError`, `retry`, `meta`, etc.
|
|
54
|
-
|
|
55
|
-
### `SafeUseMutationResult<TData, TError, TVars>`
|
|
56
|
-
|
|
57
|
-
The return type of every dapp-kit mutation hook. Extends React Query's `UseMutationResult` with `mutateAsyncSafe`.
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
// @ai-snippets-skip
|
|
61
|
-
type SafeUseMutationResult<TData, TError, TVars> = UseMutationResult<TData, TError, TVars> & {
|
|
62
|
-
mutateAsyncSafe: (vars: TVars) => Promise<Result<TData>>;
|
|
63
|
-
};
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
`mutateAsyncSafe` never rejects — it packs the rejection into `Result<T>`. Use it for sequenced flows.
|
|
67
|
-
|
|
68
|
-
### `Result<T>`
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
type Result<T> = { ok: true; value: T } | { ok: false; error: Error | unknown };
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Re-exported from `@sodax/sdk`. Used as:
|
|
75
|
-
- The SDK service method return type (which `unwrapResult` translates to throws).
|
|
76
|
-
- The return type of `mutateAsyncSafe`.
|
|
77
|
-
- The `data` of some query hooks (when the underlying SDK method returns Result and we choose to surface it directly to the consumer rather than unwrapping in the hook).
|
|
78
|
-
|
|
79
|
-
### `TxHashPair`
|
|
80
|
-
|
|
81
|
-
```ts
|
|
82
|
-
type TxHashPair = {
|
|
83
|
-
srcChainTxHash: string;
|
|
84
|
-
dstChainTxHash: string;
|
|
85
|
-
};
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Re-exported from `@sodax/sdk`. Universal cross-chain mutation return: spoke chain tx + relayed hub tx. Returned by `useBridge`, all four MM mutations, all five staking mutations, `useDexDeposit`/`useDexWithdraw`, all four migration mutations.
|
|
89
|
-
|
|
90
|
-
**Always destructure as `{ srcChainTxHash, dstChainTxHash }`, never as `[a, b]`.**
|
|
91
|
-
|
|
92
|
-
## Hook lifecycle terms
|
|
93
|
-
|
|
94
|
-
### `mutationFn`
|
|
95
|
-
|
|
96
|
-
The function React Query invokes for a mutation. In dapp-kit, every `mutationFn` calls `unwrapResult(await sodax.<feature>.<method>(vars))`. Throws on SDK `!ok`. Hook-owned, never consumer-overridable.
|
|
97
|
-
|
|
98
|
-
### `unwrapResult`
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
// @ai-snippets-skip
|
|
102
|
-
function unwrapResult<T>(result: Result<T>): T;
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
`{ ok: true; value }` → `value`. `{ ok: false; error }` → throws `error`. The bridge from SDK Result contract to React Query throw contract.
|
|
106
|
-
|
|
107
|
-
### `toResult`
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
// @ai-snippets-skip
|
|
111
|
-
function toResult<T>(promise: Promise<T>): Promise<Result<T>>;
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Inverse of `unwrapResult` for the rejection direction. Used internally by `useSafeMutation` to build `mutateAsyncSafe`.
|
|
115
|
-
|
|
116
|
-
### `useSafeMutation`
|
|
117
|
-
|
|
118
|
-
Drop-in for React Query's `useMutation`. Returns `SafeUseMutationResult` (extends `UseMutationResult` with `mutateAsyncSafe`). Every dapp-kit mutation hook calls this — never call React Query's `useMutation` directly.
|
|
119
|
-
|
|
120
|
-
### `mutateAsyncSafe`
|
|
121
|
-
|
|
122
|
-
The third call shape on every mutation hook. Returns `Promise<Result<TData>>`. Never rejects. Recommended for imperative sequenced flows.
|
|
123
|
-
|
|
124
|
-
## Provider terms
|
|
125
|
-
|
|
126
|
-
### `SodaxProvider`
|
|
127
|
-
|
|
128
|
-
App-level React component. Provides:
|
|
129
|
-
- A `Sodax` SDK instance (via `useSodaxContext()`)
|
|
130
|
-
- RPC config for all chains
|
|
131
|
-
- Hub provider access (via `useHubProvider()`)
|
|
132
|
-
|
|
133
|
-
Optional config: `<SodaxProvider config={DeepPartial<SodaxConfig>}>`. Without config, SDK uses packaged defaults.
|
|
134
|
-
|
|
135
|
-
### `createSodaxQueryClient`
|
|
136
|
-
|
|
137
|
-
Factory for a `QueryClient` with `MutationCache.onError` pre-wired for global mutation observability. Optional — if you construct your own `QueryClient`, dapp-kit hooks still work; you just don't get the global observability seam.
|
|
138
|
-
|
|
139
|
-
### `useSodaxContext`
|
|
140
|
-
|
|
141
|
-
The escape hatch into the SDK from any component under `SodaxProvider`. Returns `{ sodax: Sodax }`. Most hooks use this internally; consumers rarely need it directly.
|
|
142
|
-
|
|
143
|
-
## Convention terms
|
|
144
|
-
|
|
145
|
-
### "Single-object params"
|
|
146
|
-
|
|
147
|
-
Every hook accepts exactly one object argument. No positional args. For mutations: `{ mutationOptions }`. For queries: `{ params, queryOptions }`. Mechanically enforced.
|
|
148
|
-
|
|
149
|
-
### "Zero-domain-param policy"
|
|
150
|
-
|
|
151
|
-
The mutation-hook rule that no domain inputs (`params`, `walletProvider`, etc.) live at the hook-init level — they all flow through `mutate(vars)` via `TVars`. This lets a single hook serve many call shapes without remounting.
|
|
152
|
-
|
|
153
|
-
### "Hook-owned invalidations"
|
|
154
|
-
|
|
155
|
-
Mutation hooks invalidate the relevant query keys in their own `onSuccess`. Consumer-provided `onSuccess` runs after. Replaces v1's manual `invalidateMmQueries` utilities.
|
|
156
|
-
|
|
157
|
-
### "Composed `onSuccess`"
|
|
158
|
-
|
|
159
|
-
The pattern by which a hook's internal `onSuccess` calls invalidations first, then `await mutationOptions?.onSuccess?.(...)` so the consumer's callback still fires.
|
|
160
|
-
|
|
161
|
-
### "queryKey rule"
|
|
162
|
-
|
|
163
|
-
Every queryKey/mutationKey starts with the feature directory name (`'swap'`, `'mm'`, `'bridge'`, `'staking'`, `'dex'`, `'bitcoin'`, `'partner'`, `'recovery'`, `'backend'`, `'shared'`, `'migrate'`). camelCase segments. Bigints stringified. See [`querykey-conventions.md`](querykey-conventions.md).
|
|
164
|
-
|
|
165
|
-
### "Default `mutationKey` before the spread"
|
|
166
|
-
|
|
167
|
-
<!-- ai-keys-allow -->
|
|
168
|
-
The order inside `useSafeMutation` calls: default `mutationKey: ['feature', 'action']` BEFORE `...mutationOptions`, then `mutationFn` AFTER. This way the consumer can override the default key via `mutationOptions.mutationKey`, but `mutationFn` (hook-owned) always wins.
|
|
169
|
-
|
|
170
|
-
## v1 → v2 remapping
|
|
171
|
-
|
|
172
|
-
When porting v1 code, these shifts are pervasive:
|
|
173
|
-
|
|
174
|
-
| v1 | v2 |
|
|
175
|
-
|---|---|
|
|
176
|
-
| Positional hook args | Single-object params |
|
|
177
|
-
| Hook-level `spokeProvider` | `walletProvider` flows through `mutate(vars)` |
|
|
178
|
-
| `Result<T>` returned via React Query success | Throws in `mutationFn`; use `mutateAsyncSafe` for `Result<T>` flow |
|
|
179
|
-
| Approve hook returns `{ approve, isLoading, error }` | Returns `SafeUseMutationResult` with `mutateAsync` / `isPending` |
|
|
180
|
-
| Consumer-managed invalidations (`invalidateMmQueries`) | Hook-owned in composed `onSuccess` |
|
|
181
|
-
| Ad-hoc queryKey shapes | Feature-prefixed, camelCase, stringified bigints |
|
|
182
|
-
|
|
183
|
-
## Cross-references
|
|
184
|
-
|
|
185
|
-
- [`../architecture.md`](../architecture.md) — full design rationale for these types and conventions.
|
|
186
|
-
- [`querykey-conventions.md`](querykey-conventions.md) — queryKey/mutationKey rules.
|
|
187
|
-
- [`public-api.md`](public-api.md) — what's exported.
|
|
188
|
-
- [`../../../../sdk/ai-exported/integration/reference/glossary.md`](../../../../sdk/ai-exported/integration/reference/glossary.md) — SDK-side terms (Hub, Spoke, Intent, ChainKey, SodaxError).
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
# Hooks index — `@sodax/dapp-kit` v2
|
|
2
|
-
|
|
3
|
-
Comprehensive hook table across 11 feature domains. Use this when you know the feature you're building but don't remember the exact hook name.
|
|
4
|
-
|
|
5
|
-
## Provider + context
|
|
6
|
-
|
|
7
|
-
| Hook | Type | Purpose |
|
|
8
|
-
|---|---|---|
|
|
9
|
-
| `SodaxProvider` | Component | Wraps app; provides `Sodax` instance + RPC config |
|
|
10
|
-
| `createSodaxQueryClient` | Factory | Returns `QueryClient` with global mutation observability |
|
|
11
|
-
| `useSodaxContext` | Utility | Access the `Sodax` SDK instance |
|
|
12
|
-
| `useHubProvider` | Utility | Hub chain (Sonic) provider |
|
|
13
|
-
|
|
14
|
-
## Swap
|
|
15
|
-
|
|
16
|
-
| Hook | Type | Purpose |
|
|
17
|
-
|---|---|---|
|
|
18
|
-
| `useQuote` | Query | Real-time swap quote (auto-refreshes 3s) |
|
|
19
|
-
| `useSwap` | Mutation | Execute a complete cross-chain swap |
|
|
20
|
-
| `useSwapAllowance` | Query | Check token approval status |
|
|
21
|
-
| `useSwapApprove` | Mutation | Approve tokens for the swap contract |
|
|
22
|
-
| `useStatus` | Query | Track intent execution status (polls 3s once `intentTxHash` supplied; Result-wrapped data) |
|
|
23
|
-
| `useCancelSwap` | Mutation | Cancel an active swap intent |
|
|
24
|
-
| `useCreateLimitOrder` | Mutation | Create a limit order (no deadline) |
|
|
25
|
-
| `useCancelLimitOrder` | Mutation | Cancel a limit order |
|
|
26
|
-
|
|
27
|
-
## Money market
|
|
28
|
-
|
|
29
|
-
| Hook | Type | Purpose |
|
|
30
|
-
|---|---|---|
|
|
31
|
-
| `useSupply` | Mutation | Supply tokens as collateral |
|
|
32
|
-
| `useWithdraw` | Mutation | Withdraw supplied tokens |
|
|
33
|
-
| `useBorrow` | Mutation | Borrow against collateral |
|
|
34
|
-
| `useRepay` | Mutation | Repay borrowed tokens |
|
|
35
|
-
| `useMMAllowance` | Query | Approval check (`enabled: false` for borrow/withdraw — `data` stays `undefined`) |
|
|
36
|
-
| `useMMApprove` | Mutation | Approve tokens |
|
|
37
|
-
| `useReservesData` | Query | All reserve data (raw) |
|
|
38
|
-
| `useReservesHumanized` | Query | Reserves in decimal-normalized form |
|
|
39
|
-
| `useReservesList` | Query | List of reserve asset addresses |
|
|
40
|
-
| `useReservesUsdFormat` | Query | Reserves with USD overlays |
|
|
41
|
-
| `useUserFormattedSummary` | Query | Health factor, collateral, debt summary |
|
|
42
|
-
| `useUserReservesData` | Query | Per-reserve user position |
|
|
43
|
-
| `useAToken` | Query | aToken metadata |
|
|
44
|
-
| `useATokensBalances` | Query | aToken balances |
|
|
45
|
-
|
|
46
|
-
## Bridge
|
|
47
|
-
|
|
48
|
-
| Hook | Type | Purpose |
|
|
49
|
-
|---|---|---|
|
|
50
|
-
| `useBridge` | Mutation | Execute a cross-chain bridge transfer |
|
|
51
|
-
| `useBridgeAllowance` | Query | Approval check |
|
|
52
|
-
| `useBridgeApprove` | Mutation | Approve tokens for bridge |
|
|
53
|
-
| `useGetBridgeableAmount` | Query | Max bridgeable amount between two `XToken`s |
|
|
54
|
-
| `useGetBridgeableTokens` | Query | Tokens bridgeable to a destination chain |
|
|
55
|
-
|
|
56
|
-
## Staking
|
|
57
|
-
|
|
58
|
-
| Hook | Type | Purpose |
|
|
59
|
-
|---|---|---|
|
|
60
|
-
| `useStake` | Mutation | Stake SODA, receive xSODA |
|
|
61
|
-
| `useUnstake` | Mutation | Request unstake (waiting period) |
|
|
62
|
-
| `useInstantUnstake` | Mutation | Instant unstake (with slippage) |
|
|
63
|
-
| `useClaim` | Mutation | Claim SODA after waiting period |
|
|
64
|
-
| `useCancelUnstake` | Mutation | Cancel pending unstake |
|
|
65
|
-
| `useStakeApprove` | Mutation | Approve SODA for staking |
|
|
66
|
-
| `useUnstakeApprove` | Mutation | Approve xSODA for unstaking |
|
|
67
|
-
| `useInstantUnstakeApprove` | Mutation | Approve xSODA for instant unstaking |
|
|
68
|
-
| `useStakeAllowance` | Query | Check SODA approval |
|
|
69
|
-
| `useUnstakeAllowance` | Query | Check xSODA approval (unstaking) |
|
|
70
|
-
| `useInstantUnstakeAllowance` | Query | Check xSODA approval (instant) |
|
|
71
|
-
| `useStakingInfo` | Query | User position |
|
|
72
|
-
| `useUnstakingInfo` | Query | Pending unstake requests |
|
|
73
|
-
| `useUnstakingInfoWithPenalty` | Query | Pending requests + penalty calcs |
|
|
74
|
-
| `useStakingConfig` | Query | Unstaking period, max penalty |
|
|
75
|
-
| `useStakeRatio` | Query | SODA-to-xSODA exchange rate (returns tuple) |
|
|
76
|
-
| `useInstantUnstakeRatio` | Query | Instant unstake rate |
|
|
77
|
-
| `useConvertedAssets` | Query | xSODA → SODA conversion |
|
|
78
|
-
|
|
79
|
-
## DEX
|
|
80
|
-
|
|
81
|
-
| Hook | Type | Purpose |
|
|
82
|
-
|---|---|---|
|
|
83
|
-
| `usePools` | Query | List available pools (synchronous; no auto-refresh) |
|
|
84
|
-
| `usePoolData` | Query | Pool details (price, tick, liquidity) |
|
|
85
|
-
| `usePoolBalances` | Query | User's pool token balances |
|
|
86
|
-
| `usePositionInfo` | Query | Position details by tokenId |
|
|
87
|
-
| `useLiquidityAmounts` | Query | Token amounts for a tick range |
|
|
88
|
-
| `useDexDeposit` | Mutation | Deposit assets into pool tokens |
|
|
89
|
-
| `useDexWithdraw` | Mutation | Withdraw assets from pool tokens |
|
|
90
|
-
| `useDexAllowance` | Query | Approval check |
|
|
91
|
-
| `useDexApprove` | Mutation | Approve tokens |
|
|
92
|
-
| `useSupplyLiquidity` | Mutation | Supply liquidity (mint or increase) |
|
|
93
|
-
| `useDecreaseLiquidity` | Mutation | Remove liquidity |
|
|
94
|
-
| `useClaimRewards` | Mutation | Claim trading fees |
|
|
95
|
-
| `useCreateDepositParams` | Param builder | Build deposit params with ERC-4626 conversion |
|
|
96
|
-
| `useCreateWithdrawParams` | Param builder | Build withdraw params |
|
|
97
|
-
| `useCreateSupplyLiquidityParams` | Param builder | Build tick-range + liquidity params |
|
|
98
|
-
| `useCreateDecreaseLiquidityParams` | Param builder | Build decrease params from position state |
|
|
99
|
-
|
|
100
|
-
## Migration
|
|
101
|
-
|
|
102
|
-
| Hook | Type | Purpose |
|
|
103
|
-
|---|---|---|
|
|
104
|
-
| `useMigrateIcxToSoda` | Mutation | ICX/wICX (ICON) → SODA (Sonic) |
|
|
105
|
-
| `useRevertMigrateSodaToIcx` | Mutation | SODA (Sonic) → wICX (ICON) |
|
|
106
|
-
| `useMigratebnUSD` | Mutation | Legacy bnUSD ↔ new bnUSD (bidirectional) |
|
|
107
|
-
| `useMigrateBaln` | Mutation | BALN (ICON) → SODA with optional lock period |
|
|
108
|
-
| `useMigrationApprove` | Mutation | Approve before migration (action-discriminated) |
|
|
109
|
-
| `useMigrationAllowance` | Query | Approval check (action-discriminated) |
|
|
110
|
-
|
|
111
|
-
## Bitcoin / Radfi
|
|
112
|
-
|
|
113
|
-
| Hook | Type | Purpose |
|
|
114
|
-
|---|---|---|
|
|
115
|
-
| `useRadfiAuth` | Mutation | Authenticate via BIP322 signing |
|
|
116
|
-
| `useRadfiSession` | Utility | Manage full session lifecycle |
|
|
117
|
-
| `useTradingWallet` | Utility | Synchronously read trading wallet from localStorage |
|
|
118
|
-
| `useBitcoinBalance` | Query | BTC balance for any address |
|
|
119
|
-
| `useTradingWalletBalance` | Query | Trading wallet balance from Radfi API |
|
|
120
|
-
| `useFundTradingWallet` | Mutation | Fund trading wallet from personal wallet |
|
|
121
|
-
| `useRadfiWithdraw` | Mutation | Withdraw from trading wallet |
|
|
122
|
-
| `useExpiredUtxos` | Query | Expired UTXOs (polls 60s) |
|
|
123
|
-
| `useRenewUtxos` | Mutation | Renew expired UTXOs |
|
|
124
|
-
|
|
125
|
-
## Backend queries
|
|
126
|
-
|
|
127
|
-
### Intents
|
|
128
|
-
|
|
129
|
-
| Hook | Polling |
|
|
130
|
-
|---|---|
|
|
131
|
-
| `useBackendIntentByTxHash` | 1s (refetchInterval; fires once a `txHash` is set, unconditional) |
|
|
132
|
-
| `useBackendIntentByHash` | none |
|
|
133
|
-
| `useBackendUserIntents` | none |
|
|
134
|
-
|
|
135
|
-
### Orderbook + swap submission
|
|
136
|
-
|
|
137
|
-
| Hook | Type / Polling |
|
|
138
|
-
|---|---|
|
|
139
|
-
| `useBackendOrderbook` | Query; `staleTime: 30s` — fresh-window only, no background refetch |
|
|
140
|
-
| `useBackendSubmitSwapTx` | Mutation |
|
|
141
|
-
| `useBackendSubmitSwapTxStatus` | Query; polls until `executed` / `failed` |
|
|
142
|
-
|
|
143
|
-
### Money market data
|
|
144
|
-
|
|
145
|
-
| Hook | Purpose |
|
|
146
|
-
|---|---|
|
|
147
|
-
| `useBackendMoneyMarketPosition` | User position |
|
|
148
|
-
| `useBackendMoneyMarketAsset` | Asset details |
|
|
149
|
-
| `useBackendAllMoneyMarketAssets` | All MM assets |
|
|
150
|
-
| `useBackendMoneyMarketAssetSuppliers` | Suppliers for an asset |
|
|
151
|
-
| `useBackendMoneyMarketAssetBorrowers` | Borrowers for an asset |
|
|
152
|
-
| `useBackendAllMoneyMarketBorrowers` | All borrowers |
|
|
153
|
-
|
|
154
|
-
## Partner
|
|
155
|
-
|
|
156
|
-
| Hook | Type | Purpose |
|
|
157
|
-
|---|---|---|
|
|
158
|
-
| `useFetchAssetsBalances` | Query | Fetch partner asset balances |
|
|
159
|
-
| `useGetAutoSwapPreferences` | Query | Get auto-swap preferences |
|
|
160
|
-
| `useIsTokenApproved` | Query | Check token approval |
|
|
161
|
-
| `useApproveToken` | Mutation | Approve token |
|
|
162
|
-
| `useSetSwapPreference` | Mutation | Set swap preference |
|
|
163
|
-
| `useFeeClaimSwap` | Mutation | Claim partner fees via swap |
|
|
164
|
-
|
|
165
|
-
## Recovery
|
|
166
|
-
|
|
167
|
-
| Hook | Type | Purpose |
|
|
168
|
-
|---|---|---|
|
|
169
|
-
| `useHubAssetBalances` | Query | Hub asset balances |
|
|
170
|
-
| `useWithdrawHubAsset` | Mutation | Withdraw hub asset |
|
|
171
|
-
|
|
172
|
-
## Shared
|
|
173
|
-
|
|
174
|
-
| Hook | Type | Purpose |
|
|
175
|
-
|---|---|---|
|
|
176
|
-
| `useXBalances` | Query | Cross-chain token balances |
|
|
177
|
-
| `useDeriveUserWalletAddress` | Query | Derive hub wallet (CREATE3) |
|
|
178
|
-
| `useGetUserHubWalletAddress` | Query | Derive hub wallet (wallet router) |
|
|
179
|
-
| `useEstimateGas` | Mutation | Estimate gas for raw tx |
|
|
180
|
-
| `useStellarTrustlineCheck` | Query | Check Stellar trustline |
|
|
181
|
-
| `useRequestTrustline` | Mutation | Request a Stellar trustline |
|
|
182
|
-
| `useSafeMutation` | Internal | The wrapper every mutation hook calls |
|
|
183
|
-
| `unwrapResult` | Internal | `Result<T>` → throw / return |
|
|
184
|
-
| `toResult` | Internal | `Promise<T>` → `Result<T>` |
|
|
185
|
-
|
|
186
|
-
## Cross-references
|
|
187
|
-
|
|
188
|
-
- [`../features/`](../features/) — per-feature reference docs (params types, return shapes, gotchas).
|
|
189
|
-
- [`../recipes/`](../recipes/) — copy-paste worked examples per feature.
|
|
190
|
-
- [`querykey-conventions.md`](querykey-conventions.md) — queryKey/mutationKey shape rules.
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# Public API — `@sodax/dapp-kit`
|
|
2
|
-
|
|
3
|
-
What `@sodax/dapp-kit` exports + import rules.
|
|
4
|
-
|
|
5
|
-
## Barrel exports
|
|
6
|
-
|
|
7
|
-
The package's `src/index.ts` re-exports four buckets:
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
// @ai-snippets-skip
|
|
11
|
-
export * from './hooks/index.js'; // hooks across 11 feature dirs
|
|
12
|
-
export * from './providers/index.js'; // SodaxProvider, createSodaxQueryClient
|
|
13
|
-
export * from './utils/index.js'; // dex-utils param builders
|
|
14
|
-
export * from '@sodax/sdk'; // FULL @sodax/sdk re-export
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Practical implications:
|
|
18
|
-
- All hooks are importable from the root: `import { useSwap, useSupply, ... } from '@sodax/dapp-kit'`.
|
|
19
|
-
- All `@sodax/sdk` types are importable from `@sodax/dapp-kit` directly: `import { ChainKeys, type SodaxConfig, type CreateIntentParams } from '@sodax/dapp-kit'`.
|
|
20
|
-
- You may also import directly from `@sodax/sdk` — both work, both are stable.
|
|
21
|
-
|
|
22
|
-
## Provider
|
|
23
|
-
|
|
24
|
-
| Export | Type | Purpose |
|
|
25
|
-
|---|---|---|
|
|
26
|
-
| `SodaxProvider` | Component | App-level wrapper; provides `Sodax` SDK instance + RPC config |
|
|
27
|
-
| `createSodaxQueryClient` | Factory | Returns a `QueryClient` pre-wired with `MutationCache.onError` for global mutation observability |
|
|
28
|
-
|
|
29
|
-
## Hooks
|
|
30
|
-
|
|
31
|
-
See [`hooks-index.md`](hooks-index.md) for the comprehensive table.
|
|
32
|
-
|
|
33
|
-
## Utility types (for writing your own hooks against dapp-kit)
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
// @ai-snippets-skip
|
|
37
|
-
type ReadHookParams<TData, TParams = void> = TParams extends void
|
|
38
|
-
? { queryOptions?: ReadQueryOptions<TData> }
|
|
39
|
-
: { params?: TParams; queryOptions?: ReadQueryOptions<TData> };
|
|
40
|
-
|
|
41
|
-
type ReadQueryOptions<TData> = Omit<UseQueryOptions<TData, Error>, 'queryKey' | 'queryFn' | 'enabled'>;
|
|
42
|
-
|
|
43
|
-
type MutationHookParams<TData, TVars> = {
|
|
44
|
-
mutationOptions?: MutationHookOptions<TData, TVars>;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type MutationHookOptions<TData, TVars> = Omit<UseMutationOptions<TData, Error, TVars>, 'mutationFn'>;
|
|
48
|
-
|
|
49
|
-
type SafeUseMutationResult<TData, TError, TVars> = UseMutationResult<TData, TError, TVars> & {
|
|
50
|
-
mutateAsyncSafe: (vars: TVars) => Promise<Result<TData>>;
|
|
51
|
-
};
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Helper functions (exported but mostly internal)
|
|
55
|
-
|
|
56
|
-
| Export | Purpose |
|
|
57
|
-
|---|---|
|
|
58
|
-
| `useSafeMutation` | Drop-in replacement for React Query's `useMutation` — every dapp-kit mutation hook calls this internally |
|
|
59
|
-
| `unwrapResult` | `Result<T>` → throw on `!ok`, return `value` on `ok` |
|
|
60
|
-
| `toResult` | `Promise<T>` → `Promise<Result<T>>` |
|
|
61
|
-
|
|
62
|
-
You won't need these unless you're writing a wrapper hook around a dapp-kit mutation hook. See [`../architecture.md`](../architecture.md) § "Mutation hook shape" for the full contract.
|
|
63
|
-
|
|
64
|
-
## DEX param builders (exported from utils)
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
import {
|
|
68
|
-
createDepositParamsProps,
|
|
69
|
-
createWithdrawParamsProps,
|
|
70
|
-
createSupplyLiquidityParamsProps,
|
|
71
|
-
createDecreaseLiquidityParamsProps,
|
|
72
|
-
} from '@sodax/dapp-kit';
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
These are pure functions for assembling DEX feature params from pool data + user input. The hooks `useCreateDepositParams`, etc., wrap them with React Query state.
|
|
76
|
-
|
|
77
|
-
## Import rules
|
|
78
|
-
|
|
79
|
-
### DO
|
|
80
|
-
|
|
81
|
-
- ✓ Import from the package root: `import { useSwap } from '@sodax/dapp-kit'`.
|
|
82
|
-
- ✓ Import SDK types from dapp-kit: `import { ChainKeys, type SodaxConfig } from '@sodax/dapp-kit'`. Re-exported transparently.
|
|
83
|
-
- ✓ Import SDK types from SDK: `import { ChainKeys } from '@sodax/sdk'`. Same outcome.
|
|
84
|
-
- ✓ Import wallet-sdk-react hooks separately: `import { useWalletProvider } from '@sodax/wallet-sdk-react'`. Sibling package, not re-exported.
|
|
85
|
-
|
|
86
|
-
### DO NOT
|
|
87
|
-
|
|
88
|
-
- ✗ Deep-import from `dist/`: importing from a path like `@sodax/dapp-kit/dist/...`. Internal paths are not stable; only the package root is the public contract.
|
|
89
|
-
- ✗ Add `@sodax/types` as a separate dependency. It's transitively re-exported via `@sodax/sdk` (which dapp-kit re-exports). Adding it independently invites version skew.
|
|
90
|
-
- ✗ Import from `@sodax/wallet-sdk-core`. That's the Node-side wallet implementations package — irrelevant for React consumers; use `@sodax/wallet-sdk-react`.
|
|
91
|
-
|
|
92
|
-
## Tarball contents
|
|
93
|
-
|
|
94
|
-
The published `@sodax/dapp-kit` tarball contains:
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
dist/ # Built ESM (.mjs) + CJS (.cjs) + .d.ts
|
|
98
|
-
ai-exported/ # This documentation tree
|
|
99
|
-
package.json
|
|
100
|
-
README.md
|
|
101
|
-
LICENSE
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Don't rely on any other path being present.
|
|
105
|
-
|
|
106
|
-
## Cross-references
|
|
107
|
-
|
|
108
|
-
- [`../architecture.md`](../architecture.md) — design rationale for the canonical hook shapes.
|
|
109
|
-
- [`hooks-index.md`](hooks-index.md) — full hook list.
|
|
110
|
-
- [`../../../../sdk/ai-exported/integration/reference/public-api.md`](../../../../sdk/ai-exported/integration/reference/public-api.md) — underlying SDK's public API surface.
|