@lendasat/lendaswap-sdk 0.1.0 → 0.1.3
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 +260 -37
- package/dist/api.d.ts +100 -28
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +139 -21
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/price-feed.d.ts +10 -10
- package/dist/price-feed.d.ts.map +1 -1
- package/dist/storage/dexieSwapStorage.d.ts +2 -2
- package/dist/storage/dexieSwapStorage.js +2 -2
- package/dist/storage/dexieWalletStorage.d.ts +2 -2
- package/dist/storage/dexieWalletStorage.js +2 -2
- package/dist/usd-price.d.ts +83 -0
- package/dist/usd-price.d.ts.map +1 -0
- package/dist/usd-price.js +157 -0
- package/dist/usd-price.js.map +1 -0
- package/package.json +15 -16
- package/dist/storage/indexedDB.d.ts +0 -30
- package/dist/storage/indexedDB.d.ts.map +0 -1
- package/dist/storage/indexedDB.js +0 -108
- package/dist/storage/indexedDB.js.map +0 -1
- package/dist/storage/localStorage.d.ts +0 -32
- package/dist/storage/localStorage.d.ts.map +0 -1
- package/dist/storage/localStorage.js +0 -58
- package/dist/storage/localStorage.js.map +0 -1
- package/dist/storage/memory.d.ts +0 -35
- package/dist/storage/memory.d.ts.map +0 -1
- package/dist/storage/memory.js +0 -50
- package/dist/storage/memory.js.map +0 -1
- package/dist/wallet.d.ts +0 -108
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -188
- package/dist/wallet.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,92 +1,315 @@
|
|
|
1
|
-
# @lendaswap
|
|
1
|
+
# @lendasat/lendaswap-sdk
|
|
2
2
|
|
|
3
3
|
TypeScript/JavaScript SDK for Lendaswap - Bitcoin-to-stablecoin atomic swaps.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This SDK provides a high-level interface for interacting with the Lendaswap API, enabling atomic swaps between Bitcoin (
|
|
7
|
+
This SDK provides a high-level interface for interacting with the Lendaswap API, enabling atomic swaps between Bitcoin (
|
|
8
|
+
Lightning/Arkade) and EVM stablecoins (USDC, USDT on Polygon/Ethereum).
|
|
8
9
|
|
|
9
10
|
## Installation
|
|
10
11
|
|
|
11
12
|
```bash
|
|
12
|
-
npm install @lendaswap
|
|
13
|
+
npm install @lendasat/lendaswap-sdk
|
|
13
14
|
# or
|
|
14
|
-
pnpm add @lendaswap
|
|
15
|
+
pnpm add @lendasat/lendaswap-sdk
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
## Quick Start
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
import { ApiClient } from '@lendaswap/sdk';
|
|
20
|
+
### Get Asset Pairs and Quote
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
```typescript
|
|
23
|
+
import {
|
|
24
|
+
Client,
|
|
25
|
+
createDexieWalletStorage,
|
|
26
|
+
createDexieSwapStorage,
|
|
27
|
+
} from '@lendasat/lendaswap-sdk';
|
|
28
|
+
|
|
29
|
+
// Create storage providers (uses IndexedDB via Dexie)
|
|
30
|
+
const walletStorage = createDexieWalletStorage();
|
|
31
|
+
const swapStorage = createDexieSwapStorage();
|
|
32
|
+
|
|
33
|
+
// Create client
|
|
34
|
+
const client = await Client.create(
|
|
35
|
+
'https://apilendaswap.lendasat.com',
|
|
36
|
+
walletStorage,
|
|
37
|
+
swapStorage,
|
|
38
|
+
'bitcoin',
|
|
39
|
+
'https://arkade.computer'
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Initialize wallet (generates or loads mnemonic)
|
|
43
|
+
await client.init();
|
|
24
44
|
|
|
25
45
|
// Get available trading pairs
|
|
26
|
-
const pairs = await
|
|
46
|
+
const pairs = await client.getAssetPairs();
|
|
47
|
+
console.log('Available pairs:', pairs);
|
|
27
48
|
|
|
28
|
-
// Get a quote for swapping 100,000 sats to USDC
|
|
29
|
-
const quote = await
|
|
49
|
+
// Get a quote for swapping 100,000 sats to USDC on Polygon
|
|
50
|
+
const quote = await client.getQuote('btc_arkade', 'usdc_pol', 100_000n);
|
|
30
51
|
console.log('Exchange rate:', quote.exchange_rate);
|
|
31
52
|
console.log('You receive:', quote.min_amount, 'USDC');
|
|
53
|
+
console.log('Protocol fee:', quote.protocol_fee);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Arkade to Polygon Swap (with Gelato Auto-Redeem)
|
|
57
|
+
|
|
58
|
+
This example shows how to swap BTC from Arkade to USDC on Polygon. The swap uses Gelato relay for gasless claiming on
|
|
59
|
+
the EVM side.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import {
|
|
63
|
+
Client,
|
|
64
|
+
createDexieWalletStorage,
|
|
65
|
+
createDexieSwapStorage,
|
|
66
|
+
} from '@lendasat/lendaswap-sdk';
|
|
67
|
+
|
|
68
|
+
const walletStorage = createDexieWalletStorage();
|
|
69
|
+
const swapStorage = createDexieSwapStorage();
|
|
70
|
+
|
|
71
|
+
const client = await Client.create(
|
|
72
|
+
'https://apilendaswap.lendasat.com',
|
|
73
|
+
walletStorage,
|
|
74
|
+
swapStorage,
|
|
75
|
+
'bitcoin',
|
|
76
|
+
'https://arkade.computer'
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
await client.init();
|
|
80
|
+
|
|
81
|
+
// Create Arkade → USDC (Polygon) swap
|
|
82
|
+
const swap = await client.createArkadeToEvmSwap(
|
|
83
|
+
{
|
|
84
|
+
target_address: '0xYourPolygonAddress',
|
|
85
|
+
target_amount: 10, // 10 USDC
|
|
86
|
+
target_token: 'usdc_pol',
|
|
87
|
+
},
|
|
88
|
+
'polygon'
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
console.log('Swap created:', swap.swap_id);
|
|
92
|
+
console.log('Send BTC to Arkade VHTLC to proceed');
|
|
93
|
+
|
|
94
|
+
// After sending BTC, claim via Gelato (gasless)
|
|
95
|
+
// The secret is automatically derived from your wallet
|
|
96
|
+
await client.claimGelato(swap.swap_id);
|
|
97
|
+
console.log('Swap claimed via Gelato relay!');
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### USDC (Ethereum) to Lightning Swap
|
|
101
|
+
|
|
102
|
+
This example shows how to swap USDC on Ethereum to Bitcoin via Lightning. You'll need to sign the EVM transaction using
|
|
103
|
+
a wallet like MetaMask.
|
|
104
|
+
|
|
105
|
+
We recommend using [wagmi](https://wagmi.sh/) with [viem](https://viem.sh/) for React apps,
|
|
106
|
+
or [ethers.js](https://docs.ethers.org/) for vanilla JS/TS.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import {
|
|
110
|
+
Client,
|
|
111
|
+
createDexieWalletStorage,
|
|
112
|
+
createDexieSwapStorage,
|
|
113
|
+
} from '@lendasat/lendaswap-sdk';
|
|
114
|
+
|
|
115
|
+
const walletStorage = createDexieWalletStorage();
|
|
116
|
+
const swapStorage = createDexieSwapStorage();
|
|
117
|
+
|
|
118
|
+
const client = await Client.create(
|
|
119
|
+
'https://apilendaswap.lendasat.com',
|
|
120
|
+
walletStorage,
|
|
121
|
+
swapStorage,
|
|
122
|
+
'bitcoin',
|
|
123
|
+
'https://arkade.computer'
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
await client.init();
|
|
127
|
+
|
|
128
|
+
// Create USDC (Ethereum) → Lightning swap
|
|
129
|
+
const swap = await client.createEvmToLightningSwap(
|
|
130
|
+
{
|
|
131
|
+
bolt11_invoice: 'lnbc...', // Your Lightning invoice
|
|
132
|
+
user_address: '0xYourEthereumAddress', // Your connected wallet address
|
|
133
|
+
source_token: 'usdc_eth',
|
|
134
|
+
},
|
|
135
|
+
'ethereum'
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
console.log('Swap created:', swap.swap_id);
|
|
139
|
+
console.log('Contract address:', swap.contract_address);
|
|
140
|
+
console.log('Amount to send:', swap.source_amount);
|
|
141
|
+
|
|
142
|
+
// Now use your wallet to send the transaction to the HTLC contract
|
|
143
|
+
// Example with wagmi/viem:
|
|
144
|
+
//
|
|
145
|
+
// import { useWriteContract } from 'wagmi';
|
|
146
|
+
// const { writeContract } = useWriteContract();
|
|
147
|
+
//
|
|
148
|
+
// await writeContract({
|
|
149
|
+
// address: swap.contract_address,
|
|
150
|
+
// abi: htlcAbi,
|
|
151
|
+
// functionName: 'deposit',
|
|
152
|
+
// args: [swap.hash_lock, swap.timelock, ...],
|
|
153
|
+
// value: swap.source_amount,
|
|
154
|
+
// });
|
|
155
|
+
//
|
|
156
|
+
// Example with ethers.js:
|
|
157
|
+
//
|
|
158
|
+
// const signer = await provider.getSigner();
|
|
159
|
+
// const contract = new ethers.Contract(swap.contract_address, htlcAbi, signer);
|
|
160
|
+
// await contract.deposit(swap.hash_lock, swap.timelock, ...);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Real-time Price Feed (WebSocket)
|
|
164
|
+
|
|
165
|
+
Subscribe to real-time price updates via WebSocket:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import {PriceFeedService} from '@lendasat/lendaswap-sdk';
|
|
169
|
+
|
|
170
|
+
const priceFeed = new PriceFeedService('https://apilendaswap.lendasat.com');
|
|
171
|
+
|
|
172
|
+
// Subscribe to price updates
|
|
173
|
+
const unsubscribe = priceFeed.subscribe((update) => {
|
|
174
|
+
console.log('Timestamp:', update.timestamp);
|
|
175
|
+
|
|
176
|
+
for (const pair of update.pairs) {
|
|
177
|
+
console.log(`${pair.pair}:`);
|
|
178
|
+
console.log(` 1 unit: ${pair.tiers.tier_1}`);
|
|
179
|
+
console.log(` 100 units: ${pair.tiers.tier_100}`);
|
|
180
|
+
console.log(` 1,000 units: ${pair.tiers.tier_1000}`);
|
|
181
|
+
console.log(` 5,000 units: ${pair.tiers.tier_5000}`);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Check connection status
|
|
186
|
+
console.log('Connected:', priceFeed.isConnected());
|
|
187
|
+
console.log('Listeners:', priceFeed.listenerCount());
|
|
188
|
+
|
|
189
|
+
// Unsubscribe when done
|
|
190
|
+
unsubscribe();
|
|
32
191
|
```
|
|
33
192
|
|
|
34
193
|
## Features
|
|
35
194
|
|
|
36
|
-
- **
|
|
195
|
+
- **Client** - Full-featured client for the Lendaswap API with WASM-powered cryptography
|
|
37
196
|
- **Wallet Management** - HD wallet derivation for swap parameters
|
|
38
|
-
- **Price Feed** - Real-time WebSocket price updates
|
|
39
|
-
- **Storage Providers** -
|
|
197
|
+
- **Price Feed** - Real-time WebSocket price updates with auto-reconnection
|
|
198
|
+
- **Storage Providers** - Dexie (IndexedDB) storage for wallet and swap data
|
|
199
|
+
- **Configurable Logging** - Set log level via code or localStorage
|
|
40
200
|
|
|
41
201
|
## API Reference
|
|
42
202
|
|
|
43
|
-
###
|
|
203
|
+
### Client
|
|
44
204
|
|
|
45
205
|
```typescript
|
|
46
|
-
const
|
|
206
|
+
const client = await Client.create(
|
|
207
|
+
baseUrl,
|
|
208
|
+
walletStorage,
|
|
209
|
+
swapStorage,
|
|
210
|
+
network,
|
|
211
|
+
arkadeUrl
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// Initialize wallet
|
|
215
|
+
await client.init();
|
|
216
|
+
await client.init('your mnemonic phrase'); // Or with existing mnemonic
|
|
47
217
|
|
|
48
218
|
// Trading pairs and quotes
|
|
49
|
-
await
|
|
50
|
-
await
|
|
219
|
+
await client.getAssetPairs();
|
|
220
|
+
await client.getQuote(from, to, amount);
|
|
51
221
|
|
|
52
222
|
// Swap operations
|
|
53
|
-
await
|
|
54
|
-
await
|
|
55
|
-
await
|
|
56
|
-
await
|
|
57
|
-
await
|
|
223
|
+
await client.createArkadeToEvmSwap(request, targetNetwork);
|
|
224
|
+
await client.createEvmToArkadeSwap(request, sourceNetwork);
|
|
225
|
+
await client.createEvmToLightningSwap(request, sourceNetwork);
|
|
226
|
+
await client.getSwap(id);
|
|
227
|
+
await client.listAllSwaps();
|
|
228
|
+
|
|
229
|
+
// Claiming and refunding
|
|
230
|
+
await client.claimGelato(swapId); // Gasless EVM claim via Gelato
|
|
231
|
+
await client.claimVhtlc(swapId); // Claim Arkade VHTLC
|
|
232
|
+
await client.refundVhtlc(swapId, addr); // Refund expired VHTLC
|
|
58
233
|
|
|
59
234
|
// Recovery
|
|
60
|
-
await
|
|
235
|
+
await client.recoverSwaps();
|
|
236
|
+
|
|
237
|
+
// Wallet info
|
|
238
|
+
await client.getMnemonic();
|
|
239
|
+
await client.getUserIdXpub();
|
|
61
240
|
```
|
|
62
241
|
|
|
63
|
-
###
|
|
242
|
+
### Storage Providers
|
|
64
243
|
|
|
65
244
|
```typescript
|
|
66
|
-
import {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
245
|
+
import {
|
|
246
|
+
createDexieWalletStorage,
|
|
247
|
+
createDexieSwapStorage,
|
|
248
|
+
} from '@lendasat/lendaswap-sdk';
|
|
249
|
+
|
|
250
|
+
// Pre-built Dexie (IndexedDB) storage providers
|
|
251
|
+
const walletStorage = createDexieWalletStorage();
|
|
252
|
+
const swapStorage = createDexieSwapStorage();
|
|
253
|
+
```
|
|
70
254
|
|
|
71
|
-
|
|
72
|
-
const mnemonic = await wallet.generateOrGetMnemonic();
|
|
255
|
+
Or implement custom storage:
|
|
73
256
|
|
|
74
|
-
|
|
75
|
-
|
|
257
|
+
```typescript
|
|
258
|
+
import type {
|
|
259
|
+
WalletStorageProvider,
|
|
260
|
+
SwapStorageProvider,
|
|
261
|
+
} from '@lendasat/lendaswap-sdk';
|
|
262
|
+
|
|
263
|
+
const walletStorage: WalletStorageProvider = {
|
|
264
|
+
getMnemonic: async () => localStorage.getItem('mnemonic'),
|
|
265
|
+
setMnemonic: async (m) => localStorage.setItem('mnemonic', m),
|
|
266
|
+
getKeyIndex: async () => parseInt(localStorage.getItem('idx') ?? '0'),
|
|
267
|
+
setKeyIndex: async (i) => localStorage.setItem('idx', i.toString()),
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const swapStorage: SwapStorageProvider = {
|
|
271
|
+
get: async (id) => /* fetch from your storage */,
|
|
272
|
+
store: async (id, data) => /* store to your storage */,
|
|
273
|
+
delete: async (id) => /* delete from your storage */,
|
|
274
|
+
list: async () => /* return all swap IDs */,
|
|
275
|
+
getAll: async () => /* return all swap data */,
|
|
276
|
+
};
|
|
76
277
|
```
|
|
77
278
|
|
|
78
279
|
### PriceFeedService
|
|
79
280
|
|
|
80
281
|
```typescript
|
|
81
|
-
import {
|
|
282
|
+
import {PriceFeedService} from '@lendasat/lendaswap-sdk';
|
|
82
283
|
|
|
83
|
-
const priceFeed = new PriceFeedService('https://
|
|
284
|
+
const priceFeed = new PriceFeedService('https://apilendaswap.lendasat.com');
|
|
84
285
|
|
|
85
|
-
|
|
286
|
+
// Subscribe (auto-connects)
|
|
287
|
+
const unsubscribe = priceFeed.subscribe((prices) => {
|
|
86
288
|
console.log('Price update:', prices);
|
|
87
289
|
});
|
|
88
290
|
|
|
89
|
-
|
|
291
|
+
// Status
|
|
292
|
+
priceFeed.isConnected();
|
|
293
|
+
priceFeed.listenerCount();
|
|
294
|
+
|
|
295
|
+
// Cleanup
|
|
296
|
+
unsubscribe();
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Logging
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { setLogLevel, getLogLevel } from '@lendasat/lendaswap-sdk';
|
|
303
|
+
|
|
304
|
+
// Set log level programmatically
|
|
305
|
+
setLogLevel('debug'); // 'trace' | 'debug' | 'info' | 'warn' | 'error'
|
|
306
|
+
|
|
307
|
+
// Get current log level
|
|
308
|
+
console.log('Current level:', getLogLevel());
|
|
309
|
+
|
|
310
|
+
// Or set via localStorage (persists across page reloads)
|
|
311
|
+
localStorage.setItem('lendaswap_log_level', 'debug');
|
|
312
|
+
// Reload page for changes to take effect
|
|
90
313
|
```
|
|
91
314
|
|
|
92
315
|
## Supported Tokens
|
package/dist/api.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This module provides a high-level TypeScript API that wraps the WASM-based
|
|
5
5
|
* API client for easier use in TypeScript/JavaScript applications.
|
|
6
6
|
*/
|
|
7
|
+
import { type CreateVtxoSwapResult, type EstimateVtxoSwapResponse, type SwapParams, type VtxoSwapResponse } from "../wasm/lendaswap_wasm_sdk.js";
|
|
7
8
|
import type { VhtlcAmounts } from "./types.js";
|
|
8
9
|
/**
|
|
9
10
|
* Initialize the WASM module.
|
|
@@ -14,28 +15,30 @@ import type { VhtlcAmounts } from "./types.js";
|
|
|
14
15
|
* @param wasmPath - Optional path to the WASM file (for Node.js environments)
|
|
15
16
|
*/
|
|
16
17
|
export declare function initWasm(wasmPath?: string): Promise<void>;
|
|
17
|
-
export { QuoteResponse, TokenId, Version, VhtlcAmounts, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
18
|
+
export { CreateVtxoSwapResult, EstimateVtxoSwapResponse, QuoteResponse, SwapParams as VtxoSwapParams, TokenId, Version, VhtlcAmounts, VtxoSwapResponse, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Known token identifiers.
|
|
21
|
+
* Add new tokens here as they become supported.
|
|
22
|
+
* Uses (string & {}) to allow unknown tokens while preserving autocomplete.
|
|
20
23
|
*/
|
|
21
|
-
export type TokenIdString = "btc_lightning" | "btc_arkade" | "usdc_pol" | "usdt0_pol" | "usdc_eth" | "usdt_eth";
|
|
24
|
+
export type TokenIdString = "btc_lightning" | "btc_arkade" | "usdc_pol" | "usdt0_pol" | "usdc_eth" | "usdt_eth" | "xaut_eth" | (string & {});
|
|
22
25
|
/**
|
|
23
26
|
* Blockchain network.
|
|
27
|
+
* Uses (string & {}) to allow unknown chains while preserving autocomplete.
|
|
24
28
|
*/
|
|
25
|
-
export type Chain = "
|
|
29
|
+
export type Chain = "Arkade" | "Lightning" | "Polygon" | "Ethereum" | (string & {});
|
|
26
30
|
/**
|
|
27
|
-
* Token information
|
|
28
|
-
* Note: serde serializes with snake_case, so we use snake_case here.
|
|
31
|
+
* Token information with typed token ID.
|
|
29
32
|
*/
|
|
30
33
|
export interface TokenInfo {
|
|
31
|
-
|
|
34
|
+
tokenId: TokenIdString;
|
|
32
35
|
symbol: string;
|
|
33
36
|
chain: Chain;
|
|
34
37
|
name: string;
|
|
35
38
|
decimals: number;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
|
-
* Asset pair
|
|
41
|
+
* Asset pair with typed token info.
|
|
39
42
|
*/
|
|
40
43
|
export interface AssetPair {
|
|
41
44
|
source: TokenInfo;
|
|
@@ -55,7 +58,7 @@ export interface SwapCommonFields {
|
|
|
55
58
|
status: SwapStatus;
|
|
56
59
|
hash_lock: string;
|
|
57
60
|
fee_sats: number;
|
|
58
|
-
|
|
61
|
+
asset_amount: number;
|
|
59
62
|
sender_pk: string;
|
|
60
63
|
receiver_pk: string;
|
|
61
64
|
server_pk: string;
|
|
@@ -113,24 +116,6 @@ export interface EvmToBtcSwapResponse extends SwapCommonFields {
|
|
|
113
116
|
* Union type for swap responses based on direction.
|
|
114
117
|
*/
|
|
115
118
|
export type GetSwapResponse = BtcToEvmSwapResponse | EvmToBtcSwapResponse;
|
|
116
|
-
/**
|
|
117
|
-
* Swap parameters derived from the wallet for creating swaps.
|
|
118
|
-
* Contains cryptographic keys and preimage data.
|
|
119
|
-
*/
|
|
120
|
-
export interface SwapParams {
|
|
121
|
-
/** Secret key (hex-encoded) */
|
|
122
|
-
secret_key: string;
|
|
123
|
-
/** Public key (hex-encoded) */
|
|
124
|
-
public_key: string;
|
|
125
|
-
/** Preimage for the HTLC (32 bytes, hex-encoded) */
|
|
126
|
-
preimage: string;
|
|
127
|
-
/** Hash of the preimage (32 bytes, hex-encoded) */
|
|
128
|
-
preimage_hash: string;
|
|
129
|
-
/** User ID public key (hex-encoded) */
|
|
130
|
-
user_id: string;
|
|
131
|
-
/** Key derivation index */
|
|
132
|
-
key_index: number;
|
|
133
|
-
}
|
|
134
119
|
/**
|
|
135
120
|
* Extended swap storage data that includes the swap response and optional secret.
|
|
136
121
|
* Used for persisting swap data locally with the preimage secret.
|
|
@@ -221,6 +206,11 @@ export interface QuoteResponseInfo {
|
|
|
221
206
|
min_amount: number;
|
|
222
207
|
max_amount: number;
|
|
223
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* VTXO swap status values.
|
|
211
|
+
* Note: WASM returns status as lowercase string (e.g., "pending", "clientfunded")
|
|
212
|
+
*/
|
|
213
|
+
export type VtxoSwapStatus = "pending" | "clientfunded" | "serverfunded" | "clientredeemed" | "serverredeemed" | "clientrefunded" | "clientfundedserverrefunded" | "expired";
|
|
224
214
|
/**
|
|
225
215
|
* Typed storage provider interface for wallet data (mnemonic, key index).
|
|
226
216
|
* Provides typed async methods for wallet credential storage.
|
|
@@ -295,7 +285,7 @@ export declare class Client {
|
|
|
295
285
|
* };
|
|
296
286
|
*
|
|
297
287
|
* const client = await Client.create(
|
|
298
|
-
* 'https://
|
|
288
|
+
* 'https://apilendaswap.lendasat.com',
|
|
299
289
|
* walletStorage,
|
|
300
290
|
* swapStorage,
|
|
301
291
|
* 'bitcoin',
|
|
@@ -330,6 +320,7 @@ export declare class Client {
|
|
|
330
320
|
*/
|
|
331
321
|
createEvmToLightningSwap(request: EvmToLightningSwapRequest, sourceNetwork: "ethereum" | "polygon"): Promise<EvmToBtcSwapResponse>;
|
|
332
322
|
getAssetPairs(): Promise<AssetPair[]>;
|
|
323
|
+
getTokens(): Promise<TokenInfo[]>;
|
|
333
324
|
/**
|
|
334
325
|
* Get a quote for a swap.
|
|
335
326
|
*
|
|
@@ -409,5 +400,86 @@ export declare class Client {
|
|
|
409
400
|
* Delete one particular swap by id
|
|
410
401
|
*/
|
|
411
402
|
deleteSwap(id: string): Promise<void>;
|
|
403
|
+
/**
|
|
404
|
+
* Estimate the fee for a VTXO swap.
|
|
405
|
+
*
|
|
406
|
+
* @param vtxos - List of VTXO outpoints to refresh ("txid:vout" format)
|
|
407
|
+
* @returns Estimate response with fee and output amounts
|
|
408
|
+
*/
|
|
409
|
+
estimateVtxoSwap(vtxos: string[]): Promise<EstimateVtxoSwapResponse>;
|
|
410
|
+
/**
|
|
411
|
+
* Create a VTXO swap for refreshing VTXOs.
|
|
412
|
+
*
|
|
413
|
+
* This creates a swap where the client will fund their VHTLC first,
|
|
414
|
+
* then the server funds their VHTLC, and the client claims the server's
|
|
415
|
+
* VHTLC to complete the swap.
|
|
416
|
+
*
|
|
417
|
+
* @param vtxos - List of VTXO outpoints to refresh ("txid:vout" format)
|
|
418
|
+
* @returns The swap response and swap parameters
|
|
419
|
+
*/
|
|
420
|
+
createVtxoSwap(vtxos: string[]): Promise<CreateVtxoSwapResult>;
|
|
421
|
+
/**
|
|
422
|
+
* Get VTXO swap details by ID.
|
|
423
|
+
*
|
|
424
|
+
* @param id - The swap ID
|
|
425
|
+
* @returns The VTXO swap response
|
|
426
|
+
*/
|
|
427
|
+
getVtxoSwap(id: string): Promise<VtxoSwapResponse>;
|
|
428
|
+
/**
|
|
429
|
+
* Claim the server's VHTLC in a VTXO swap.
|
|
430
|
+
*
|
|
431
|
+
* This should be called after the server has funded their VHTLC.
|
|
432
|
+
* The client reveals the preimage to claim the fresh VTXOs.
|
|
433
|
+
*
|
|
434
|
+
* @param swap - The VTXO swap response
|
|
435
|
+
* @param swapParams - The client's swap parameters (containing preimage)
|
|
436
|
+
* @param claimAddress - The Arkade address to receive the claimed funds
|
|
437
|
+
* @returns The claim transaction ID
|
|
438
|
+
*/
|
|
439
|
+
claimVtxoSwap(swap: VtxoSwapResponse, swapParams: SwapParams, claimAddress: string): Promise<string>;
|
|
440
|
+
/**
|
|
441
|
+
* Refund the client's VHTLC in a VTXO swap.
|
|
442
|
+
*
|
|
443
|
+
* This can be called if the swap fails (e.g., server doesn't fund)
|
|
444
|
+
* and the client's locktime has expired.
|
|
445
|
+
*
|
|
446
|
+
* @param swap - The VTXO swap response
|
|
447
|
+
* @param swapParams - The client's swap parameters
|
|
448
|
+
* @param refundAddress - The Arkade address to receive the refunded funds
|
|
449
|
+
* @returns The refund transaction ID
|
|
450
|
+
*/
|
|
451
|
+
refundVtxoSwap(swap: VtxoSwapResponse, swapParams: SwapParams, refundAddress: string): Promise<string>;
|
|
412
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Log level type for SDK logging configuration.
|
|
455
|
+
*/
|
|
456
|
+
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
|
|
457
|
+
/**
|
|
458
|
+
* Set the SDK log level.
|
|
459
|
+
*
|
|
460
|
+
* This configures the log level for all Rust/WASM code in the SDK.
|
|
461
|
+
* The level is persisted in localStorage under key "lendaswap_log_level",
|
|
462
|
+
* so it will be used on page reload.
|
|
463
|
+
*
|
|
464
|
+
* @param level - Log level: "trace", "debug", "info", "warn", "error"
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* import { setLogLevel } from '@lendasat/lendaswap-sdk';
|
|
469
|
+
*
|
|
470
|
+
* // Enable debug logging
|
|
471
|
+
* setLogLevel('debug');
|
|
472
|
+
*
|
|
473
|
+
* // Or set via localStorage directly (for debugging in browser console)
|
|
474
|
+
* localStorage.setItem('lendaswap_log_level', 'debug');
|
|
475
|
+
* // Then reload the page
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
479
|
+
/**
|
|
480
|
+
* Get the current SDK log level.
|
|
481
|
+
*
|
|
482
|
+
* @returns Current log level
|
|
483
|
+
*/
|
|
484
|
+
export declare function getLogLevel(): LogLevel;
|
|
413
485
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
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