@lendasat/lendaswap-sdk 0.1.0
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 +105 -0
- package/dist/api.d.ts +413 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +306 -0
- package/dist/api.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/price-feed.d.ts +121 -0
- package/dist/price-feed.d.ts.map +1 -0
- package/dist/price-feed.js +178 -0
- package/dist/price-feed.js.map +1 -0
- package/dist/storage/dexieSwapStorage.d.ts +111 -0
- package/dist/storage/dexieSwapStorage.d.ts.map +1 -0
- package/dist/storage/dexieSwapStorage.js +139 -0
- package/dist/storage/dexieSwapStorage.js.map +1 -0
- package/dist/storage/dexieWalletStorage.d.ts +99 -0
- package/dist/storage/dexieWalletStorage.d.ts.map +1 -0
- package/dist/storage/dexieWalletStorage.js +139 -0
- package/dist/storage/dexieWalletStorage.js.map +1 -0
- package/dist/storage/index.d.ts +18 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +20 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexedDB.d.ts +30 -0
- package/dist/storage/indexedDB.d.ts.map +1 -0
- package/dist/storage/indexedDB.js +108 -0
- package/dist/storage/indexedDB.js.map +1 -0
- package/dist/storage/localStorage.d.ts +32 -0
- package/dist/storage/localStorage.d.ts.map +1 -0
- package/dist/storage/localStorage.js +58 -0
- package/dist/storage/localStorage.js.map +1 -0
- package/dist/storage/memory.d.ts +35 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +50 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet.d.ts +108 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +188 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @lendaswap/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript SDK for Lendaswap - Bitcoin-to-stablecoin atomic swaps.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This SDK provides a high-level interface for interacting with the Lendaswap API, enabling atomic swaps between Bitcoin (Lightning/Arkade) and EVM stablecoins (USDC, USDT on Polygon/Ethereum).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @lendaswap/sdk
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @lendaswap/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ApiClient } from '@lendaswap/sdk';
|
|
21
|
+
|
|
22
|
+
// Create an API client
|
|
23
|
+
const api = await ApiClient.create('https://api.lendaswap.com');
|
|
24
|
+
|
|
25
|
+
// Get available trading pairs
|
|
26
|
+
const pairs = await api.getAssetPairs();
|
|
27
|
+
|
|
28
|
+
// Get a quote for swapping 100,000 sats to USDC
|
|
29
|
+
const quote = await api.getQuote('btc_arkade', 'usdc_pol', 100000n);
|
|
30
|
+
console.log('Exchange rate:', quote.exchange_rate);
|
|
31
|
+
console.log('You receive:', quote.min_amount, 'USDC');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **API Client** - Full-featured client for the Lendaswap REST API
|
|
37
|
+
- **Wallet Management** - HD wallet derivation for swap parameters
|
|
38
|
+
- **Price Feed** - Real-time WebSocket price updates
|
|
39
|
+
- **Storage Providers** - LocalStorage, IndexedDB, and in-memory options
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### ApiClient
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const api = await ApiClient.create(baseUrl);
|
|
47
|
+
|
|
48
|
+
// Trading pairs and quotes
|
|
49
|
+
await api.getAssetPairs();
|
|
50
|
+
await api.getQuote(from, to, amount);
|
|
51
|
+
|
|
52
|
+
// Swap operations
|
|
53
|
+
await api.createArkadeToEvmSwap(request, network);
|
|
54
|
+
await api.createEvmToArkadeSwap(request, network);
|
|
55
|
+
await api.createEvmToLightningSwap(request, network);
|
|
56
|
+
await api.getSwap(id);
|
|
57
|
+
await api.claimGelato(swapId, secret);
|
|
58
|
+
|
|
59
|
+
// Recovery
|
|
60
|
+
await api.recoverSwaps(xpub);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Wallet
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { Wallet, LocalStorageProvider } from '@lendaswap/sdk';
|
|
67
|
+
|
|
68
|
+
const storage = new LocalStorageProvider();
|
|
69
|
+
const wallet = await Wallet.create(storage, 'bitcoin');
|
|
70
|
+
|
|
71
|
+
// Generate or retrieve mnemonic
|
|
72
|
+
const mnemonic = await wallet.generateOrGetMnemonic();
|
|
73
|
+
|
|
74
|
+
// Derive swap parameters (preimage, hash lock, keys)
|
|
75
|
+
const params = await wallet.deriveSwapParams();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### PriceFeedService
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { PriceFeedService } from '@lendaswap/sdk';
|
|
82
|
+
|
|
83
|
+
const priceFeed = new PriceFeedService('https://api.lendaswap.com');
|
|
84
|
+
|
|
85
|
+
priceFeed.subscribe((prices) => {
|
|
86
|
+
console.log('Price update:', prices);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
priceFeed.connect();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Supported Tokens
|
|
93
|
+
|
|
94
|
+
| Token | Chain | ID |
|
|
95
|
+
| ----- | --------- | --------------- |
|
|
96
|
+
| BTC | Lightning | `btc_lightning` |
|
|
97
|
+
| BTC | Arkade | `btc_arkade` |
|
|
98
|
+
| USDC | Polygon | `usdc_pol` |
|
|
99
|
+
| USDT | Polygon | `usdt0_pol` |
|
|
100
|
+
| USDC | Ethereum | `usdc_eth` |
|
|
101
|
+
| USDT | Ethereum | `usdt_eth` |
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client wrapper for the Lendaswap REST API.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a high-level TypeScript API that wraps the WASM-based
|
|
5
|
+
* API client for easier use in TypeScript/JavaScript applications.
|
|
6
|
+
*/
|
|
7
|
+
import type { VhtlcAmounts } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the WASM module.
|
|
10
|
+
*
|
|
11
|
+
* This is called automatically when creating a Wallet, but can be called
|
|
12
|
+
* explicitly for eager initialization.
|
|
13
|
+
*
|
|
14
|
+
* @param wasmPath - Optional path to the WASM file (for Node.js environments)
|
|
15
|
+
*/
|
|
16
|
+
export declare function initWasm(wasmPath?: string): Promise<void>;
|
|
17
|
+
export { QuoteResponse, TokenId, Version, VhtlcAmounts, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
18
|
+
/**
|
|
19
|
+
* Token identifier for supported assets.
|
|
20
|
+
*/
|
|
21
|
+
export type TokenIdString = "btc_lightning" | "btc_arkade" | "usdc_pol" | "usdt0_pol" | "usdc_eth" | "usdt_eth";
|
|
22
|
+
/**
|
|
23
|
+
* Blockchain network.
|
|
24
|
+
*/
|
|
25
|
+
export type Chain = "Bitcoin" | "Polygon" | "Ethereum" | "Lightning" | "Arkade";
|
|
26
|
+
/**
|
|
27
|
+
* Token information returned from the API.
|
|
28
|
+
* Note: serde serializes with snake_case, so we use snake_case here.
|
|
29
|
+
*/
|
|
30
|
+
export interface TokenInfo {
|
|
31
|
+
token_id: TokenIdString;
|
|
32
|
+
symbol: string;
|
|
33
|
+
chain: Chain;
|
|
34
|
+
name: string;
|
|
35
|
+
decimals: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Asset pair for trading.
|
|
39
|
+
*/
|
|
40
|
+
export interface AssetPair {
|
|
41
|
+
source: TokenInfo;
|
|
42
|
+
target: TokenInfo;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Swap status enumeration.
|
|
46
|
+
* These match the server-side status values.
|
|
47
|
+
*/
|
|
48
|
+
export type SwapStatus = "pending" | "clientfunded" | "clientrefunded" | "serverfunded" | "clientredeeming" | "clientredeemed" | "serverredeemed" | "clientfundedserverrefunded" | "clientrefundedserverfunded" | "clientrefundedserverrefunded" | "expired" | "clientinvalidfunded" | "clientfundedtoolate";
|
|
49
|
+
/**
|
|
50
|
+
* Common fields shared across all swap directions.
|
|
51
|
+
* These fields are flattened into the response by serde.
|
|
52
|
+
*/
|
|
53
|
+
export interface SwapCommonFields {
|
|
54
|
+
id: string;
|
|
55
|
+
status: SwapStatus;
|
|
56
|
+
hash_lock: string;
|
|
57
|
+
fee_sats: number;
|
|
58
|
+
usd_amount: number;
|
|
59
|
+
sender_pk: string;
|
|
60
|
+
receiver_pk: string;
|
|
61
|
+
server_pk: string;
|
|
62
|
+
refund_locktime: number;
|
|
63
|
+
unilateral_claim_delay: number;
|
|
64
|
+
unilateral_refund_delay: number;
|
|
65
|
+
unilateral_refund_without_receiver_delay: number;
|
|
66
|
+
network: string;
|
|
67
|
+
created_at: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* BTC to EVM swap response.
|
|
71
|
+
* Note: direction field is added by the SDK, not returned by the server.
|
|
72
|
+
*/
|
|
73
|
+
export interface BtcToEvmSwapResponse extends SwapCommonFields {
|
|
74
|
+
direction: "btc_to_evm";
|
|
75
|
+
htlc_address_evm: string;
|
|
76
|
+
htlc_address_arkade: string;
|
|
77
|
+
user_address_evm: string;
|
|
78
|
+
ln_invoice: string;
|
|
79
|
+
sats_receive: number;
|
|
80
|
+
source_token: TokenIdString;
|
|
81
|
+
target_token: TokenIdString;
|
|
82
|
+
bitcoin_htlc_claim_txid: string | null;
|
|
83
|
+
bitcoin_htlc_fund_txid: string | null;
|
|
84
|
+
evm_htlc_claim_txid: string | null;
|
|
85
|
+
evm_htlc_fund_txid: string | null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* EVM to BTC swap response.
|
|
89
|
+
* Note: direction field is added by the SDK, not returned by the server.
|
|
90
|
+
*/
|
|
91
|
+
export interface EvmToBtcSwapResponse extends SwapCommonFields {
|
|
92
|
+
direction: "evm_to_btc";
|
|
93
|
+
htlc_address_evm: string;
|
|
94
|
+
htlc_address_arkade: string;
|
|
95
|
+
user_address_evm: string;
|
|
96
|
+
user_address_arkade: string | null;
|
|
97
|
+
ln_invoice: string;
|
|
98
|
+
source_token: TokenIdString;
|
|
99
|
+
target_token: TokenIdString;
|
|
100
|
+
sats_receive: number;
|
|
101
|
+
bitcoin_htlc_fund_txid: string | null;
|
|
102
|
+
bitcoin_htlc_claim_txid: string | null;
|
|
103
|
+
evm_htlc_claim_txid: string | null;
|
|
104
|
+
evm_htlc_fund_txid: string | null;
|
|
105
|
+
create_swap_tx: string | null;
|
|
106
|
+
approve_tx: string | null;
|
|
107
|
+
gelato_forwarder_address: string | null;
|
|
108
|
+
gelato_user_nonce: string | null;
|
|
109
|
+
gelato_user_deadline: string | null;
|
|
110
|
+
source_token_address: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Union type for swap responses based on direction.
|
|
114
|
+
*/
|
|
115
|
+
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
|
+
/**
|
|
135
|
+
* Extended swap storage data that includes the swap response and optional secret.
|
|
136
|
+
* Used for persisting swap data locally with the preimage secret.
|
|
137
|
+
*/
|
|
138
|
+
export interface ExtendedSwapStorageData {
|
|
139
|
+
response: GetSwapResponse;
|
|
140
|
+
swap_params: SwapParams;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Request to create an Arkade to EVM swap (BTC → Token).
|
|
144
|
+
*/
|
|
145
|
+
export interface SwapRequest {
|
|
146
|
+
target_address: string;
|
|
147
|
+
target_amount: number;
|
|
148
|
+
target_token: TokenIdString;
|
|
149
|
+
referral_code?: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Request to create an EVM to Arkade swap (Token → BTC).
|
|
153
|
+
*/
|
|
154
|
+
export interface EvmToArkadeSwapRequest {
|
|
155
|
+
target_address: string;
|
|
156
|
+
source_amount: number;
|
|
157
|
+
source_token: TokenIdString;
|
|
158
|
+
user_address: string;
|
|
159
|
+
referral_code?: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Request to create an EVM to Lightning swap.
|
|
163
|
+
*/
|
|
164
|
+
export interface EvmToLightningSwapRequest {
|
|
165
|
+
bolt11_invoice: string;
|
|
166
|
+
source_token: TokenIdString;
|
|
167
|
+
user_address: string;
|
|
168
|
+
referral_code?: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Gelato relay submit request.
|
|
172
|
+
*/
|
|
173
|
+
export interface GelatoSubmitRequest {
|
|
174
|
+
create_swap_signature: string;
|
|
175
|
+
user_nonce: string;
|
|
176
|
+
user_deadline: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gelato relay submit response.
|
|
180
|
+
*/
|
|
181
|
+
export interface GelatoSubmitResponse {
|
|
182
|
+
create_swap_task_id: string;
|
|
183
|
+
message: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Recovered swap with index.
|
|
187
|
+
*/
|
|
188
|
+
export type RecoveredSwap = GetSwapResponse & {
|
|
189
|
+
index: number;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Response from the recover swaps endpoint.
|
|
193
|
+
*/
|
|
194
|
+
export interface RecoverSwapsResponse {
|
|
195
|
+
swaps: RecoveredSwap[];
|
|
196
|
+
highest_index: number;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Quote request parameters.
|
|
200
|
+
*/
|
|
201
|
+
export interface QuoteRequest {
|
|
202
|
+
from: TokenIdString;
|
|
203
|
+
to: TokenIdString;
|
|
204
|
+
base_amount: number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Version information (snake_case for consistency with other API types).
|
|
208
|
+
*/
|
|
209
|
+
export interface VersionInfo {
|
|
210
|
+
tag: string;
|
|
211
|
+
commit_hash: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Quote response (snake_case for consistency with other API types).
|
|
215
|
+
*/
|
|
216
|
+
export interface QuoteResponseInfo {
|
|
217
|
+
exchange_rate: string;
|
|
218
|
+
network_fee: number;
|
|
219
|
+
protocol_fee: number;
|
|
220
|
+
protocol_fee_rate: number;
|
|
221
|
+
min_amount: number;
|
|
222
|
+
max_amount: number;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Typed storage provider interface for wallet data (mnemonic, key index).
|
|
226
|
+
* Provides typed async methods for wallet credential storage.
|
|
227
|
+
*/
|
|
228
|
+
export interface WalletStorageProvider {
|
|
229
|
+
/** Get the mnemonic phrase. Returns null if not stored. */
|
|
230
|
+
getMnemonic: () => Promise<string | null>;
|
|
231
|
+
/** Store the mnemonic phrase. Overwrites any existing mnemonic. */
|
|
232
|
+
setMnemonic: (mnemonic: string) => Promise<void>;
|
|
233
|
+
/** Get the current key derivation index. Returns 0 if not set. */
|
|
234
|
+
getKeyIndex: () => Promise<number>;
|
|
235
|
+
/** Set the key derivation index. */
|
|
236
|
+
setKeyIndex: (index: number) => Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Typed storage provider interface for swap data.
|
|
240
|
+
* Uses ExtendedSwapStorageData objects directly, allowing implementations
|
|
241
|
+
* to store them efficiently (e.g., as objects in IndexedDB via Dexie).
|
|
242
|
+
*/
|
|
243
|
+
export interface SwapStorageProvider {
|
|
244
|
+
/** Get swap data by swap ID. Returns null if not found. */
|
|
245
|
+
get: (swapId: string) => Promise<ExtendedSwapStorageData | null>;
|
|
246
|
+
/** Store swap data. Overwrites any existing swap with the same ID. */
|
|
247
|
+
store: (swapId: string, data: ExtendedSwapStorageData) => Promise<void>;
|
|
248
|
+
/** Delete swap data by swap ID. */
|
|
249
|
+
delete: (swapId: string) => Promise<void>;
|
|
250
|
+
/** List all stored swap IDs. */
|
|
251
|
+
list: () => Promise<string[]>;
|
|
252
|
+
/** List all stored swaps. */
|
|
253
|
+
getAll: () => Promise<ExtendedSwapStorageData[]>;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Network type for Bitcoin networks.
|
|
257
|
+
*/
|
|
258
|
+
export type Network = "bitcoin" | "testnet" | "regtest" | "mutinynet";
|
|
259
|
+
export declare class Client {
|
|
260
|
+
private client;
|
|
261
|
+
private constructor();
|
|
262
|
+
/**
|
|
263
|
+
* Create a new Client instance.
|
|
264
|
+
*
|
|
265
|
+
* @param baseUrl - The base URL of the Lendaswap API
|
|
266
|
+
* @param walletStorage - Storage provider for persisting wallet data (mnemonic, key index)
|
|
267
|
+
* @param swapStorage - Storage provider for persisting swap data (uses Dexie/IndexedDB)
|
|
268
|
+
* @param network - Bitcoin network ("bitcoin", "testnet", "regtest", "mutinynet")
|
|
269
|
+
* @param arkadeUrl - Arkade's server url
|
|
270
|
+
* @param wasmPath - Optional path to the WASM file (for Node.js environments)
|
|
271
|
+
* @returns A new Client instance
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* import Dexie from 'dexie';
|
|
276
|
+
*
|
|
277
|
+
* // Wallet storage using localStorage with typed methods
|
|
278
|
+
* const walletStorage: WalletStorageProvider = {
|
|
279
|
+
* getMnemonic: async () => localStorage.getItem('mnemonic'),
|
|
280
|
+
* setMnemonic: async (mnemonic) => localStorage.setItem('mnemonic', mnemonic),
|
|
281
|
+
* getKeyIndex: async () => parseInt(localStorage.getItem('key_index') ?? '0'),
|
|
282
|
+
* setKeyIndex: async (index) => localStorage.setItem('key_index', index.toString()),
|
|
283
|
+
* };
|
|
284
|
+
*
|
|
285
|
+
* // Swap storage using Dexie (IndexedDB)
|
|
286
|
+
* const db = new Dexie('lendaswap');
|
|
287
|
+
* db.version(1).stores({ swaps: 'id' });
|
|
288
|
+
*
|
|
289
|
+
* const swapStorage: SwapStorageProvider = {
|
|
290
|
+
* get: async (swapId) => await db.table('swaps').get(swapId) ?? null,
|
|
291
|
+
* store: async (swapId, data) => await db.table('swaps').put({ id: swapId, ...data }),
|
|
292
|
+
* delete: async (swapId) => await db.table('swaps').delete(swapId),
|
|
293
|
+
* list: async () => await db.table('swaps').toCollection().primaryKeys() as string[],
|
|
294
|
+
* getAll: async () => await db.table('swaps').toArray(),
|
|
295
|
+
* };
|
|
296
|
+
*
|
|
297
|
+
* const client = await Client.create(
|
|
298
|
+
* 'https://api.lendaswap.com',
|
|
299
|
+
* walletStorage,
|
|
300
|
+
* swapStorage,
|
|
301
|
+
* 'bitcoin',
|
|
302
|
+
* 'https://arkade.computer'
|
|
303
|
+
* );
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
static create(baseUrl: string, walletStorage: WalletStorageProvider, swapStorage: SwapStorageProvider, network: Network, arkadeUrl: string, wasmPath?: string): Promise<Client>;
|
|
307
|
+
init(mnemonic?: string): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Create an Arkade to EVM swap (BTC → Token).
|
|
310
|
+
*
|
|
311
|
+
* @param request - The swap request parameters
|
|
312
|
+
* @param targetNetwork - Target EVM network (e.g., 'polygon', 'ethereum')
|
|
313
|
+
* @returns The created swap response
|
|
314
|
+
*/
|
|
315
|
+
createArkadeToEvmSwap(request: SwapRequest, targetNetwork: "ethereum" | "polygon"): Promise<BtcToEvmSwapResponse>;
|
|
316
|
+
/**
|
|
317
|
+
* Create an EVM to Arkade swap (Token → BTC).
|
|
318
|
+
*
|
|
319
|
+
* @param request - The swap request parameters
|
|
320
|
+
* @param sourceNetwork - Source EVM network (e.g., 'polygon', 'ethereum')
|
|
321
|
+
* @returns The created swap response
|
|
322
|
+
*/
|
|
323
|
+
createEvmToArkadeSwap(request: EvmToArkadeSwapRequest, sourceNetwork: "ethereum" | "polygon"): Promise<EvmToBtcSwapResponse>;
|
|
324
|
+
/**
|
|
325
|
+
* Create an EVM to Lightning swap (Token → BTC).
|
|
326
|
+
*
|
|
327
|
+
* @param request - The swap request parameters
|
|
328
|
+
* @param sourceNetwork - Source EVM network (e.g., 'polygon', 'ethereum')
|
|
329
|
+
* @returns The created swap response
|
|
330
|
+
*/
|
|
331
|
+
createEvmToLightningSwap(request: EvmToLightningSwapRequest, sourceNetwork: "ethereum" | "polygon"): Promise<EvmToBtcSwapResponse>;
|
|
332
|
+
getAssetPairs(): Promise<AssetPair[]>;
|
|
333
|
+
/**
|
|
334
|
+
* Get a quote for a swap.
|
|
335
|
+
*
|
|
336
|
+
* @param from - Source token ID (e.g., 'btc_arkade')
|
|
337
|
+
* @param to - Destination token ID (e.g., 'usdc_pol')
|
|
338
|
+
* @param baseAmount - Amount in base units (satoshis for BTC, wei for EVM)
|
|
339
|
+
* @returns Quote response with exchange rate and fees
|
|
340
|
+
*/
|
|
341
|
+
getQuote(from: TokenIdString, to: TokenIdString, baseAmount: bigint): Promise<QuoteResponseInfo>;
|
|
342
|
+
/**
|
|
343
|
+
* Get a swap by its ID.
|
|
344
|
+
*
|
|
345
|
+
* @param id - The swap ID
|
|
346
|
+
* @returns The swap response
|
|
347
|
+
*/
|
|
348
|
+
getSwap(id: string): Promise<ExtendedSwapStorageData>;
|
|
349
|
+
/**
|
|
350
|
+
* Gets all stored swaps.
|
|
351
|
+
*
|
|
352
|
+
* @returns A vec of swaps
|
|
353
|
+
*/
|
|
354
|
+
listAllSwaps(): Promise<ExtendedSwapStorageData[]>;
|
|
355
|
+
/**
|
|
356
|
+
* Claim a swap via Gelato relay (gasless).
|
|
357
|
+
*
|
|
358
|
+
* @param swapId - The swap ID
|
|
359
|
+
* @param secret - The preimage secret (hex-encoded)
|
|
360
|
+
*/
|
|
361
|
+
claimGelato(swapId: string, secret?: string): Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* Get the VHTLC amounts associated with a swap.
|
|
364
|
+
*
|
|
365
|
+
* @param swapId - The swap ID
|
|
366
|
+
* @returns VhtlcAmounts
|
|
367
|
+
*/
|
|
368
|
+
amountsForSwap(swapId: string): Promise<VhtlcAmounts>;
|
|
369
|
+
/**
|
|
370
|
+
* Claim a swap VHTLC
|
|
371
|
+
*
|
|
372
|
+
* @param swapId - The swap ID
|
|
373
|
+
*/
|
|
374
|
+
claimVhtlc(swapId: string): Promise<void>;
|
|
375
|
+
/**
|
|
376
|
+
* Claim a swap VHTLC
|
|
377
|
+
*
|
|
378
|
+
* @param swapId - The swap ID
|
|
379
|
+
* @returns The TXID of the Ark transaction which refunded the VHTLC.
|
|
380
|
+
*/
|
|
381
|
+
refundVhtlc(swapId: string, refundAddress: string): Promise<string>;
|
|
382
|
+
/**
|
|
383
|
+
* Get the API version.
|
|
384
|
+
*
|
|
385
|
+
* @returns Version information
|
|
386
|
+
*/
|
|
387
|
+
getVersion(): Promise<VersionInfo>;
|
|
388
|
+
/**
|
|
389
|
+
* Recover swaps for the currently loaded mnemonic.
|
|
390
|
+
*
|
|
391
|
+
* @returns Response containing recovered swaps
|
|
392
|
+
*/
|
|
393
|
+
recoverSwaps(): Promise<ExtendedSwapStorageData[]>;
|
|
394
|
+
/**
|
|
395
|
+
* Get current loaded mnemonic
|
|
396
|
+
* @returns The mnemonic as string
|
|
397
|
+
*/
|
|
398
|
+
getMnemonic(): Promise<string>;
|
|
399
|
+
/**
|
|
400
|
+
* Get current loaded user id xpub
|
|
401
|
+
* @returns The xpub as string
|
|
402
|
+
*/
|
|
403
|
+
getUserIdXpub(): Promise<string>;
|
|
404
|
+
/**
|
|
405
|
+
* Deletes all stored swaps
|
|
406
|
+
*/
|
|
407
|
+
clearSwapStorage(): Promise<void>;
|
|
408
|
+
/**
|
|
409
|
+
* Delete one particular swap by id
|
|
410
|
+
*/
|
|
411
|
+
deleteSwap(id: string): Promise<void>;
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4C/D;AAGD,OAAO,EACL,aAAa,EACb,OAAO,EACP,OAAO,EACP,YAAY,GACb,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,YAAY,GACZ,UAAU,GACV,WAAW,GACX,UAAU,GACV,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,SAAS,GAAG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