@lombard.finance/sdk-devtools 0.1.0-canary-2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Lombard Finance
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,348 @@
1
+ # @lombard.finance/sdk-devtools
2
+
3
+ Developer tools for the Lombard SDK. Provides debugging, inspection, and testing utilities for developers integrating with the Lombard protocol.
4
+
5
+ ## How It Works
6
+
7
+ The SDK DevTools automatically hooks into SDK actions to collect events and state:
8
+
9
+ ```
10
+ ┌─────────────────────────────────────────────────────────────────────────────┐
11
+ │ YOUR APP │
12
+ ├─────────────────────────────────────────────────────────────────────────────┤
13
+ │ │
14
+ │ ┌─────────────────────┐ ┌─────────────────────┐ │
15
+ │ │ Lombard SDK │ │ DevTools │ │
16
+ │ │ │ │ │ │
17
+ │ │ const stake = sdk │───────▶│ Automatically │ │
18
+ │ │ .chain.btc.stake() │ events │ collects events, │ │
19
+ │ │ │ │ tracks status │ │
20
+ │ └─────────────────────┘ └──────────┬──────────┘ │
21
+ │ │ │
22
+ │ ▼ │
23
+ │ ┌─────────────────────────┐ │
24
+ │ │ DevToolsPanel │ │
25
+ │ │ (Visual debugger) │ │
26
+ │ └─────────────────────────┘ │
27
+ │ │
28
+ └─────────────────────────────────────────────────────────────────────────────┘
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ yarn add @lombard.finance/sdk-devtools
35
+ # or
36
+ npm install @lombard.finance/sdk-devtools
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Wrap Your App with DevToolsProvider
42
+
43
+ ```tsx
44
+ import { DevToolsProvider } from '@lombard.finance/sdk-devtools';
45
+
46
+ function App() {
47
+ return (
48
+ <DevToolsProvider enabled={process.env.NODE_ENV !== 'production'}>
49
+ <MyApp />
50
+ </DevToolsProvider>
51
+ );
52
+ }
53
+ ```
54
+
55
+ ### 2. Register SDK Actions
56
+
57
+ ```tsx
58
+ import { useDevToolsContext } from '@lombard.finance/sdk-devtools';
59
+ import { createLombardSDK, Chain, AssetId } from '@lombard.finance/sdk';
60
+
61
+ function StakeComponent() {
62
+ const { registerAction } = useDevToolsContext();
63
+ const [stake, setStake] = useState(null);
64
+
65
+ // Create and register the action
66
+ useEffect(() => {
67
+ async function init() {
68
+ const sdk = await createLombardSDK({
69
+ env: 'testnet',
70
+ providers: { evm: () => window.ethereum },
71
+ });
72
+
73
+ const action = sdk.chain.btc.stake({
74
+ destChain: Chain.ETHEREUM,
75
+ assetOut: AssetId.LBTC,
76
+ });
77
+
78
+ // Register with DevTools - events are now collected automatically!
79
+ const unregister = registerAction('btc-stake', action, {
80
+ category: 'btc',
81
+ });
82
+
83
+ setStake(action);
84
+
85
+ return unregister;
86
+ }
87
+
88
+ init();
89
+ }, [registerAction]);
90
+
91
+ // Use the action normally
92
+ async function handleStake() {
93
+ await stake.prepare({ amount: '0.001', recipient: '0x...' });
94
+ await stake.authorize();
95
+ const address = await stake.generateDepositAddress();
96
+ console.log('Deposit to:', address);
97
+ }
98
+
99
+ return <button onClick={handleStake}>Stake BTC</button>;
100
+ }
101
+ ```
102
+
103
+ ### 3. Display DevTools Panel
104
+
105
+ ```tsx
106
+ import {
107
+ DevToolsPanel,
108
+ useDevToolsContext,
109
+ } from '@lombard.finance/sdk-devtools';
110
+
111
+ function DebugPanel() {
112
+ const { events, clearEvents, actions } = useDevToolsContext();
113
+
114
+ // Get state summary for all registered actions
115
+ const stateSummary = useMemo(() => {
116
+ const summary = {};
117
+ actions.forEach((reg, name) => {
118
+ summary[name] = {
119
+ status: reg.action.status,
120
+ isLoading: reg.action.isLoading,
121
+ };
122
+ });
123
+ return summary;
124
+ }, [actions]);
125
+
126
+ return (
127
+ <DevToolsPanel
128
+ events={events}
129
+ onClearEvents={clearEvents}
130
+ state={stateSummary}
131
+ />
132
+ );
133
+ }
134
+ ```
135
+
136
+ ## Alternative: Without Provider
137
+
138
+ For simpler setups or non-React apps, use the bridge directly:
139
+
140
+ ```tsx
141
+ import { DevToolsBridge, DevToolsPanel } from '@lombard.finance/sdk-devtools';
142
+
143
+ // Create bridge
144
+ const bridge = new DevToolsBridge({ consoleLogging: true });
145
+
146
+ // Register action
147
+ const stake = sdk.chain.btc.stake({ ... });
148
+ const unregister = bridge.registerAction('stake', stake);
149
+
150
+ // Get events for display
151
+ const events = bridge.getEvents();
152
+
153
+ // In React:
154
+ function DebugView() {
155
+ const [events, setEvents] = useState([]);
156
+
157
+ useEffect(() => {
158
+ return bridge.onEvent(() => {
159
+ setEvents(bridge.getEvents());
160
+ });
161
+ }, []);
162
+
163
+ return (
164
+ <DevToolsPanel
165
+ events={events}
166
+ onClearEvents={() => bridge.clearEvents()}
167
+ />
168
+ );
169
+ }
170
+ ```
171
+
172
+ ## Using Hook for Single Action
173
+
174
+ For monitoring a single action with full state:
175
+
176
+ ```tsx
177
+ import { useActionEvents } from '@lombard.finance/sdk-devtools';
178
+
179
+ function StakeProgress({ action }) {
180
+ const { events, status, isLoading, error, isFailed } =
181
+ useActionEvents(action);
182
+
183
+ return (
184
+ <div>
185
+ <StatusBadge status={status} />
186
+ {isLoading && <Spinner />}
187
+ {isFailed && <Error message={error.message} />}
188
+ <EventLog events={events} onClear={() => {}} />
189
+ </div>
190
+ );
191
+ }
192
+ ```
193
+
194
+ ## Components
195
+
196
+ ### DevToolsPanel
197
+
198
+ Full debug panel with tabs for events, actions, and state:
199
+
200
+ ```tsx
201
+ <DevToolsPanel
202
+ events={events}
203
+ onClearEvents={clearEvents}
204
+ reducerLogs={logs} // Optional: Redux-style action log
205
+ onClearReducerLogs={clearLogs} // Optional
206
+ state={{ status: 'ready' }} // Optional: State to inspect
207
+ initialTab="events" // Optional: 'events' | 'reducer' | 'state'
208
+ title="SDK Debug" // Optional
209
+ />
210
+ ```
211
+
212
+ ### Individual Components
213
+
214
+ ```tsx
215
+ import {
216
+ EventLog,
217
+ StateInspector,
218
+ StatusBadge,
219
+ StepIndicator,
220
+ createSteps,
221
+ } from '@lombard.finance/sdk-devtools';
222
+
223
+ // Status Badge
224
+ <StatusBadge status="needs_fee_authorization" />
225
+
226
+ // Step Indicator
227
+ const steps = [
228
+ { id: 'create', label: 'Create' },
229
+ { id: 'prepare', label: 'Prepare' },
230
+ { id: 'authorize', label: 'Authorize' },
231
+ { id: 'execute', label: 'Execute' },
232
+ ];
233
+
234
+ <StepIndicator
235
+ steps={createSteps(steps, currentStep)}
236
+ currentStep={currentStep}
237
+ />
238
+
239
+ // Event Log (standalone)
240
+ <EventLog events={events} onClear={clearEvents} />
241
+
242
+ // State Inspector (JSON tree viewer)
243
+ <StateInspector state={{ amount: '0.001' }} title="Transaction" />
244
+ ```
245
+
246
+ ## Mock Wallet
247
+
248
+ Test flows without connecting a real wallet:
249
+
250
+ ```tsx
251
+ import { useMockWallet, MOCK_ADDRESSES } from '@lombard.finance/sdk-devtools';
252
+
253
+ function WalletSection() {
254
+ const mockWallet = useMockWallet();
255
+
256
+ return (
257
+ <div>
258
+ {!mockWallet.isEnabled ? (
259
+ <button onClick={mockWallet.enable}>Use Mock Wallet</button>
260
+ ) : (
261
+ <div>
262
+ <p>Mock Address: {mockWallet.address}</p>
263
+ <p>⚠️ Cannot sign transactions</p>
264
+ <button onClick={mockWallet.disable}>Disable Mock</button>
265
+ </div>
266
+ )}
267
+ </div>
268
+ );
269
+ }
270
+
271
+ // Available mock addresses
272
+ console.log(MOCK_ADDRESSES.evm); // 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
273
+ console.log(MOCK_ADDRESSES.bitcoin); // bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh
274
+ console.log(MOCK_ADDRESSES.solana); // DRpbCBMxVnDK7maPMxTm9dRYNLGhPEYALmJY9VvUdWTm
275
+ ```
276
+
277
+ ## SDK Events Collected
278
+
279
+ The bridge automatically subscribes to these SDK events:
280
+
281
+ | Event | Description |
282
+ | --------------- | ---------------------------------------------------------------- |
283
+ | `status-change` | Action status changed (e.g., `idle` → `needs_fee_authorization`) |
284
+ | `loading` | Loading state changed |
285
+ | `error` | An error occurred |
286
+ | `completed` | Action completed successfully |
287
+ | `failed` | Action failed |
288
+ | `progress` | Progress update with step details |
289
+
290
+ ## API Reference
291
+
292
+ ### Provider
293
+
294
+ | Export | Description |
295
+ | -------------------- | ------------------------------- |
296
+ | `DevToolsProvider` | React context provider |
297
+ | `useDevToolsContext` | Hook to access DevTools context |
298
+ | `useRegisterAction` | Hook to register an action |
299
+
300
+ ### Bridge
301
+
302
+ | Export | Description |
303
+ | --------------------- | --------------------------- |
304
+ | `DevToolsBridge` | Core bridge class |
305
+ | `getDevToolsBridge` | Get global singleton bridge |
306
+ | `resetDevToolsBridge` | Reset global bridge |
307
+
308
+ ### Hooks
309
+
310
+ | Hook | Description |
311
+ | -------------------- | ---------------------------------------- |
312
+ | `useDevTools` | Full DevTools state and methods |
313
+ | `useMonitoredAction` | Create and auto-register an action |
314
+ | `useActionEvents` | Subscribe to events from a single action |
315
+ | `useMockWallet` | Mock wallet for testing |
316
+
317
+ ### Components
318
+
319
+ | Component | Description |
320
+ | ---------------- | ----------------------- |
321
+ | `DevToolsPanel` | Full tabbed debug panel |
322
+ | `EventLog` | SDK event stream |
323
+ | `ReducerLog` | Redux-style action log |
324
+ | `StateInspector` | JSON tree viewer |
325
+ | `StatusBadge` | Status indicator |
326
+ | `StepIndicator` | Progress steps |
327
+
328
+ ## Styling
329
+
330
+ Components use Tailwind CSS classes. For best results, ensure Tailwind is configured in your project. Components support dark mode via `dark:` prefix classes.
331
+
332
+ ## Production
333
+
334
+ DevTools is automatically disabled in production when using `DevToolsProvider`:
335
+
336
+ ```tsx
337
+ <DevToolsProvider enabled={process.env.NODE_ENV !== 'production'}>
338
+ ```
339
+
340
+ Or disable manually:
341
+
342
+ ```tsx
343
+ <DevToolsProvider enabled={false}>
344
+ ```
345
+
346
+ ## License
347
+
348
+ MIT