@arkade-os/boltz-swap 0.3.0 → 0.3.2

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.
@@ -1,34 +1,69 @@
1
1
  import { Transaction, NetworkName, IWallet, ArkProvider, IndexerProvider } from '@arkade-os/sdk';
2
2
 
3
+ /** Configuration for BoltzSwapProvider. */
3
4
  interface SwapProviderConfig {
5
+ /** Custom API URL. If omitted, defaults based on `network` (e.g. bitcoin → https://api.ark.boltz.exchange). */
4
6
  apiUrl?: string;
7
+ /** The network to operate on (e.g. "mutinynet", "regtest", "bitcoin"). */
5
8
  network: Network;
9
+ /** Optional referral ID appended to swap requests. */
6
10
  referralId?: string;
7
11
  }
12
+ /**
13
+ * All possible Boltz swap status values.
14
+ *
15
+ * Lifecycle (submarine): swap.created → invoice.set → invoice.pending → invoice.paid → transaction.claimed
16
+ * Lifecycle (reverse): swap.created → transaction.mempool → transaction.confirmed → invoice.settled
17
+ * Lifecycle (chain): swap.created → transaction.mempool → transaction.server.mempool → transaction.claimed
18
+ */
8
19
  type BoltzSwapStatus = "invoice.expired" | "invoice.failedToPay" | "invoice.paid" | "invoice.pending" | "invoice.set" | "invoice.settled" | "swap.created" | "swap.expired" | "transaction.claim.pending" | "transaction.claimed" | "transaction.confirmed" | "transaction.failed" | "transaction.lockupFailed" | "transaction.mempool" | "transaction.refunded" | "transaction.server.mempool" | "transaction.server.confirmed";
20
+ /** Returns true if the status indicates a failed submarine swap. */
9
21
  declare const isSubmarineFailedStatus: (status: BoltzSwapStatus) => boolean;
22
+ /** Returns true if the submarine swap has reached a terminal state. */
10
23
  declare const isSubmarineFinalStatus: (status: BoltzSwapStatus) => boolean;
24
+ /** Returns true if the submarine swap is still in progress. */
11
25
  declare const isSubmarinePendingStatus: (status: BoltzSwapStatus) => boolean;
26
+ /** Returns true if the submarine swap is eligible for refund. */
12
27
  declare const isSubmarineRefundableStatus: (status: BoltzSwapStatus) => boolean;
28
+ /** Returns true if the submarine swap completed successfully. */
13
29
  declare const isSubmarineSuccessStatus: (status: BoltzSwapStatus) => boolean;
30
+ /** Returns true if the reverse swap failed. */
14
31
  declare const isReverseFailedStatus: (status: BoltzSwapStatus) => boolean;
32
+ /** Returns true if the reverse swap has reached a terminal state. */
15
33
  declare const isReverseFinalStatus: (status: BoltzSwapStatus) => boolean;
34
+ /** Returns true if the reverse swap is still in progress. */
16
35
  declare const isReversePendingStatus: (status: BoltzSwapStatus) => boolean;
36
+ /** Returns true if the reverse swap VHTLC can be claimed. */
17
37
  declare const isReverseClaimableStatus: (status: BoltzSwapStatus) => boolean;
38
+ /** Returns true if the reverse swap completed successfully. */
18
39
  declare const isReverseSuccessStatus: (status: BoltzSwapStatus) => boolean;
40
+ /** Returns true if the chain swap failed. */
19
41
  declare const isChainFailedStatus: (status: BoltzSwapStatus) => boolean;
42
+ /** Returns true if the chain swap is claimable (server transaction in mempool or confirmed). */
20
43
  declare const isChainClaimableStatus: (status: BoltzSwapStatus) => boolean;
44
+ /** Returns true if the chain swap has reached a terminal state. */
21
45
  declare const isChainFinalStatus: (status: BoltzSwapStatus) => boolean;
46
+ /** Returns true if the chain swap is still in progress. */
22
47
  declare const isChainPendingStatus: (status: BoltzSwapStatus) => boolean;
48
+ /** Returns true if the chain swap is eligible for refund (swap.expired). */
23
49
  declare const isChainRefundableStatus: (status: BoltzSwapStatus) => boolean;
50
+ /** Returns true if the chain swap is ready for cooperative signing. */
24
51
  declare const isChainSignableStatus: (status: BoltzSwapStatus) => boolean;
52
+ /** Returns true if the chain swap completed successfully. */
25
53
  declare const isChainSuccessStatus: (status: BoltzSwapStatus) => boolean;
54
+ /** Type guard: narrows PendingSwap to PendingReverseSwap. */
26
55
  declare const isPendingReverseSwap: (swap: PendingSwap) => swap is PendingReverseSwap;
56
+ /** Type guard: narrows PendingSwap to PendingSubmarineSwap. */
27
57
  declare const isPendingSubmarineSwap: (swap: PendingSwap) => swap is PendingSubmarineSwap;
58
+ /** Type guard: narrows PendingSwap to PendingChainSwap. */
28
59
  declare const isPendingChainSwap: (swap: PendingSwap) => swap is PendingChainSwap;
60
+ /** Type guard: checks if swap is a refundable submarine swap (failed + not yet refunded). */
29
61
  declare const isSubmarineSwapRefundable: (swap: PendingSwap) => swap is PendingSubmarineSwap;
62
+ /** Type guard: checks if swap is a refundable chain swap (expired ARK → BTC). */
30
63
  declare const isChainSwapRefundable: (swap: PendingSwap) => swap is PendingChainSwap;
64
+ /** Type guard: checks if swap is a claimable reverse swap. */
31
65
  declare const isReverseSwapClaimable: (swap: PendingSwap) => swap is PendingReverseSwap;
66
+ /** Type guard: checks if swap is a claimable chain swap. */
32
67
  declare const isChainSwapClaimable: (swap: PendingSwap) => swap is PendingChainSwap;
33
68
  type TimeoutBlockHeights = {
34
69
  refund: number;
@@ -50,33 +85,55 @@ type GetSwapStatusResponse = {
50
85
  preimage?: string;
51
86
  };
52
87
  };
88
+ /** Request to create a submarine swap (Arkade → Lightning). */
53
89
  type CreateSubmarineSwapRequest = {
90
+ /** BOLT11 Lightning invoice to pay. */
54
91
  invoice: string;
92
+ /** Compressed public key (33 bytes / 66 hex chars) for the refund path. */
55
93
  refundPublicKey: string;
56
94
  };
95
+ /** Response from creating a submarine swap. */
57
96
  type CreateSubmarineSwapResponse = {
97
+ /** Unique swap ID. */
58
98
  id: string;
99
+ /** ARK lockup address to send funds to. */
59
100
  address: string;
101
+ /** Amount in satoshis to send. */
60
102
  expectedAmount: number;
103
+ /** Boltz's public key for the claim path. */
61
104
  claimPublicKey: string;
105
+ /** Whether zero-conf transactions are accepted. */
62
106
  acceptZeroConf: boolean;
107
+ /** Block heights for various timeout/refund scenarios. */
63
108
  timeoutBlockHeights: TimeoutBlockHeights;
64
109
  };
65
110
  type GetSwapPreimageResponse = {
66
111
  preimage: string;
67
112
  };
113
+ /** Request to create a reverse swap (Lightning → Arkade). */
68
114
  type CreateReverseSwapRequest = {
115
+ /** Compressed public key (33 bytes / 66 hex chars) for the claim path. */
69
116
  claimPublicKey: string;
117
+ /** Invoice amount in satoshis. */
70
118
  invoiceAmount: number;
119
+ /** SHA256 hash of the preimage (hex-encoded). */
71
120
  preimageHash: string;
121
+ /** Optional description for the BOLT11 invoice. */
72
122
  description?: string;
73
123
  };
124
+ /** Response from creating a reverse swap. */
74
125
  type CreateReverseSwapResponse = {
126
+ /** Unique swap ID. */
75
127
  id: string;
128
+ /** BOLT11-encoded Lightning invoice to be paid. */
76
129
  invoice: string;
130
+ /** On-chain amount in satoshis (after Boltz fees). */
77
131
  onchainAmount: number;
132
+ /** ARK lockup address where Boltz will lock funds. */
78
133
  lockupAddress: string;
134
+ /** Boltz's public key for the refund path. */
79
135
  refundPublicKey: string;
136
+ /** Block heights for various timeout/refund scenarios. */
80
137
  timeoutBlockHeights: TimeoutBlockHeights;
81
138
  };
82
139
  type SwapTree = {
@@ -98,20 +155,34 @@ type ChainSwapDetailsResponse = {
98
155
  timeouts?: TimeoutBlockHeights;
99
156
  bip21?: string;
100
157
  };
158
+ /** Request to create a chain swap (ARK ↔ BTC). */
101
159
  type CreateChainSwapRequest = {
160
+ /** Destination chain. */
102
161
  to: Chain;
162
+ /** Source chain. */
103
163
  from: Chain;
164
+ /** SHA256 hash of the preimage (hex-encoded). */
104
165
  preimageHash: string;
166
+ /** Compressed public key for the claim path. */
105
167
  claimPublicKey: string;
168
+ /** Fee rate (sats/vbyte) for BTC transactions. */
106
169
  feeSatsPerByte: number;
170
+ /** Compressed public key for the refund path. */
107
171
  refundPublicKey: string;
172
+ /** Amount Boltz should lock (specify this OR userLockAmount). */
108
173
  serverLockAmount?: number;
174
+ /** Amount user will lock (specify this OR serverLockAmount). */
109
175
  userLockAmount?: number;
176
+ /** Optional referral ID. */
110
177
  referralId?: string;
111
178
  };
179
+ /** Response from creating a chain swap. */
112
180
  type CreateChainSwapResponse = {
181
+ /** Unique swap ID. */
113
182
  id: string;
183
+ /** Details for claiming the received funds. */
114
184
  claimDetails: ChainSwapDetailsResponse;
185
+ /** Details for the lockup (user sends funds here). */
115
186
  lockupDetails: ChainSwapDetailsResponse;
116
187
  };
117
188
  type GetChainClaimDetailsResponse = {
@@ -168,9 +239,30 @@ type Details = {
168
239
  lockupAddress: string;
169
240
  serverPublicKey: string;
170
241
  timeoutBlockHeight: number;
171
- timeoutBlockHeights: TimeoutBlockHeights;
242
+ timeoutBlockHeights?: TimeoutBlockHeights;
172
243
  preimageHash?: string;
173
244
  };
245
+ type RestoredChainSwap = {
246
+ id: string;
247
+ type: "chain";
248
+ status: BoltzSwapStatus;
249
+ createdAt: number;
250
+ from: "ARK" | "BTC";
251
+ to: "ARK" | "BTC";
252
+ preimageHash: string;
253
+ refundDetails: {
254
+ amount: number;
255
+ keyIndex: number;
256
+ lockupAddress: string;
257
+ serverPublicKey: string;
258
+ timeoutBlockHeight: number;
259
+ transaction?: {
260
+ id: string;
261
+ vout: number;
262
+ };
263
+ tree: Tree;
264
+ };
265
+ };
174
266
  type RestoredSubmarineSwap = {
175
267
  to: "BTC";
176
268
  id: string;
@@ -191,40 +283,68 @@ type RestoredReverseSwap = {
191
283
  status: BoltzSwapStatus;
192
284
  claimDetails: Details;
193
285
  };
194
- type CreateSwapsRestoreResponse = (RestoredReverseSwap | RestoredSubmarineSwap)[];
286
+ type CreateSwapsRestoreResponse = (RestoredChainSwap | RestoredReverseSwap | RestoredSubmarineSwap)[];
287
+ /**
288
+ * API client for the Boltz swap service.
289
+ * Handles swap creation, status monitoring, fee/limit queries, and cooperative signing
290
+ * for both Lightning and chain swaps.
291
+ */
195
292
  declare class BoltzSwapProvider {
196
293
  private readonly wsUrl;
197
294
  private readonly apiUrl;
198
295
  private readonly network;
199
296
  private readonly referralId?;
297
+ /** @param config Provider configuration with network and optional API URL. */
200
298
  constructor(config: SwapProviderConfig);
299
+ /** Returns the Boltz API base URL. */
201
300
  getApiUrl(): string;
301
+ /** Returns the Boltz WebSocket URL (derived from apiUrl). */
202
302
  getWsUrl(): string;
303
+ /** Returns the configured network. */
203
304
  getNetwork(): Network;
305
+ /** Returns current Lightning swap fees (submarine + reverse) from Boltz. */
204
306
  getFees(): Promise<FeesResponse>;
307
+ /** Returns current Lightning swap min/max limits from Boltz. */
205
308
  getLimits(): Promise<LimitsResponse>;
309
+ /** Gets the lockup transaction ID for a reverse swap. */
206
310
  getReverseSwapTxId(id: string): Promise<GetReverseSwapTxIdResponse>;
311
+ /** Queries the current status of a swap by ID. */
207
312
  getSwapStatus(id: string): Promise<GetSwapStatusResponse>;
313
+ /** Gets the preimage for a settled submarine swap (proof of payment). */
208
314
  getSwapPreimage(id: string): Promise<GetSwapPreimageResponse>;
315
+ /** Creates a submarine swap (Arkade → Lightning) on Boltz. */
209
316
  createSubmarineSwap({ invoice, refundPublicKey, }: CreateSubmarineSwapRequest): Promise<CreateSubmarineSwapResponse>;
317
+ /** Creates a reverse swap (Lightning → Arkade) on Boltz. */
210
318
  createReverseSwap({ invoiceAmount, claimPublicKey, preimageHash, description, }: CreateReverseSwapRequest): Promise<CreateReverseSwapResponse>;
319
+ /** Creates a chain swap (ARK ↔ BTC) on Boltz. */
211
320
  createChainSwap({ to, from, preimageHash, feeSatsPerByte, claimPublicKey, refundPublicKey, serverLockAmount, userLockAmount, }: CreateChainSwapRequest): Promise<CreateChainSwapResponse>;
321
+ /** Requests Boltz co-signature for a submarine swap refund. Returns signed transaction + checkpoint. */
212
322
  refundSubmarineSwap(swapId: string, transaction: Transaction, checkpoint: Transaction): Promise<{
213
323
  transaction: Transaction;
214
324
  checkpoint: Transaction;
215
325
  }>;
326
+ /** Requests Boltz co-signature for a chain swap refund. Returns signed transaction + checkpoint. */
216
327
  refundChainSwap(swapId: string, transaction: Transaction, checkpoint: Transaction): Promise<{
217
328
  transaction: Transaction;
218
329
  checkpoint: Transaction;
219
330
  }>;
331
+ /** Monitors swap status updates via WebSocket. Calls update callback on each status change. Resolves when terminal. */
220
332
  monitorSwap(swapId: string, update: (type: BoltzSwapStatus, data?: any) => void): Promise<void>;
333
+ /** Returns current chain swap fees for a given pair (e.g. ARK→BTC). */
221
334
  getChainFees(from: Chain, to: Chain): Promise<ChainFeesResponse>;
335
+ /** Returns current chain swap min/max limits for a given pair. */
222
336
  getChainLimits(from: Chain, to: Chain): Promise<LimitsResponse>;
337
+ /** Gets claim details (pubNonce, publicKey, transactionHash) for cooperative chain swap claiming. */
223
338
  getChainClaimDetails(swapId: string): Promise<GetChainClaimDetailsResponse>;
339
+ /** Gets a renegotiated quote for a chain swap when lockup amount differs from expected. */
224
340
  getChainQuote(swapId: string): Promise<GetChainQuoteResponse>;
341
+ /** Accepts a renegotiated quote amount for a chain swap. */
225
342
  postChainQuote(swapId: string, request: PostChainQuoteRequest): Promise<PostChainQuoteResponse>;
343
+ /** Broadcasts a raw BTC transaction through Boltz. */
226
344
  postBtcTransaction(hex: string): Promise<PostBtcTransactionResponse>;
345
+ /** Posts claim details (preimage + signing data) or cooperative signature for a chain swap. */
227
346
  postChainClaimDetails(swapId: string, request: PostChainClaimDetailsRequest): Promise<PostChainClaimDetailsResponse>;
347
+ /** Restores swaps from Boltz API using the wallet's public key. */
228
348
  restoreSwaps(publicKey: string): Promise<CreateSwapsRestoreResponse>;
229
349
  private request;
230
350
  }
@@ -266,6 +386,7 @@ interface SwapManagerConfig {
266
386
  /** Event callbacks for swap lifecycle events (optional, can use on/off methods instead) */
267
387
  events?: SwapManagerEvents;
268
388
  }
389
+ /** Event callbacks for swap lifecycle events. Can be provided in config or registered via on/off methods. */
269
390
  interface SwapManagerEvents {
270
391
  onSwapUpdate?: (swap: PendingSwap, oldStatus: BoltzSwapStatus) => void;
271
392
  onSwapCompleted?: (swap: PendingSwap) => void;
@@ -274,25 +395,43 @@ interface SwapManagerEvents {
274
395
  onWebSocketConnected?: () => void;
275
396
  onWebSocketDisconnected?: (error?: Error) => void;
276
397
  }
398
+ /** Callback for swap status changes. Receives the updated swap and its previous status. */
277
399
  type SwapUpdateListener = (swap: PendingSwap, oldStatus: BoltzSwapStatus) => void;
400
+ /** Callback for swap completions (final success state reached). */
278
401
  type SwapCompletedListener = (swap: PendingSwap) => void;
402
+ /** Callback for swap failures. Includes the error that caused the failure. */
279
403
  type SwapFailedListener = (swap: PendingSwap, error: Error) => void;
404
+ /** Callback after a swap action (claim/refund) has been executed. */
280
405
  type ActionExecutedListener = (swap: PendingSwap, action: Actions) => void;
406
+ /** Callback when the WebSocket connection is established. */
281
407
  type WebSocketConnectedListener = () => void;
408
+ /** Callback when the WebSocket disconnects. Includes the error if disconnection was not clean. */
282
409
  type WebSocketDisconnectedListener = (error?: Error) => void;
410
+ /** Per-swap update callback used with subscribeToSwapUpdates. */
283
411
  type SwapUpdateCallback = (swap: PendingSwap, oldStatus: BoltzSwapStatus) => void;
412
+ /** Public interface for SwapManager consumers. Provides swap monitoring, event subscription, and lifecycle control. */
284
413
  interface SwapManagerClient {
414
+ /** Starts the manager, loading initial swaps and connecting WebSocket. */
285
415
  start(pendingSwaps: PendingSwap[]): Promise<void>;
416
+ /** Stops the manager, closes WebSocket, and clears all timers. */
286
417
  stop(): Promise<void>;
418
+ /** Adds a new swap to be monitored. Immediately subscribes via WebSocket. */
287
419
  addSwap(swap: PendingSwap): Promise<void>;
420
+ /** Removes a swap from monitoring. */
288
421
  removeSwap(swapId: string): Promise<void>;
422
+ /** Returns all currently monitored (non-final) swaps. */
289
423
  getPendingSwaps(): Promise<PendingSwap[]>;
424
+ /** Subscribes to status updates for a specific swap. @returns Unsubscribe function. */
290
425
  subscribeToSwapUpdates(swapId: string, callback: SwapUpdateCallback): Promise<() => void>;
426
+ /** Returns a promise that resolves with { txid } when the swap completes, or rejects on failure. */
291
427
  waitForSwapCompletion(swapId: string): Promise<{
292
428
  txid: string;
293
429
  }>;
430
+ /** Returns true if a claim/refund action is currently executing for this swap. */
294
431
  isProcessing(swapId: string): Promise<boolean>;
432
+ /** Returns true if the manager is monitoring this swap. */
295
433
  hasSwap(swapId: string): Promise<boolean>;
434
+ /** Returns operational statistics (running state, WebSocket status, monitored count, etc.). */
296
435
  getStats(): Promise<{
297
436
  isRunning: boolean;
298
437
  monitoredSwaps: number;
@@ -314,6 +453,7 @@ interface SwapManagerClient {
314
453
  offWebSocketConnected(listener: WebSocketConnectedListener): void;
315
454
  offWebSocketDisconnected(listener: WebSocketDisconnectedListener): void;
316
455
  }
456
+ /** Internal callbacks wired by ArkadeSwaps to perform claim/refund/save operations. */
317
457
  interface SwapManagerCallbacks {
318
458
  claim: (swap: PendingReverseSwap) => Promise<void>;
319
459
  refund: (swap: PendingSubmarineSwap) => Promise<void>;
@@ -323,6 +463,16 @@ interface SwapManagerCallbacks {
323
463
  signServerClaim?: (swap: PendingChainSwap) => Promise<void>;
324
464
  saveSwap: (swap: PendingSwap) => Promise<void>;
325
465
  }
466
+ /**
467
+ * Background swap monitor with WebSocket + polling fallback.
468
+ *
469
+ * Monitors all pending swaps via a single multiplexed WebSocket connection to Boltz.
470
+ * Automatically claims reverse swaps, refunds failed submarine swaps, and handles
471
+ * chain swap actions (claim/refund on both ARK and BTC sides).
472
+ *
473
+ * Falls back to HTTP polling when WebSocket is unavailable, with exponential backoff
474
+ * for both reconnection and polling intervals.
475
+ */
326
476
  declare class SwapManager implements SwapManagerClient {
327
477
  private readonly swapProvider;
328
478
  private readonly config;
@@ -583,94 +733,165 @@ interface SwapRepository extends AsyncDisposable {
583
733
  clear(): Promise<void>;
584
734
  }
585
735
 
736
+ /** A virtual transaction output (VTXO) — an off-chain UTXO in the Ark protocol. */
586
737
  interface Vtxo {
738
+ /** Transaction ID of the VTXO. */
587
739
  txid: string;
740
+ /** Output index in the transaction. */
588
741
  vout: number;
742
+ /** Amount in satoshis. */
589
743
  sats: number;
744
+ /** The output script (hex-encoded). */
590
745
  script: string;
746
+ /** Raw transaction data. */
591
747
  tx: {
748
+ /** Raw transaction hex. */
592
749
  hex: string;
750
+ /** Transaction version number. */
593
751
  version: number;
752
+ /** Transaction locktime. */
594
753
  locktime: number;
595
754
  };
596
755
  }
756
+ /** Network name (e.g. "mutinynet", "regtest", "bitcoin"). */
597
757
  type Network = NetworkName;
758
+ /** The chain side of a swap: "ARK" (off-chain Ark protocol) or "BTC" (on-chain Bitcoin). */
598
759
  type Chain = "ARK" | "BTC";
760
+ /** Response from creating an ARK → BTC chain swap. */
599
761
  interface ArkToBtcResponse {
762
+ /** The ARK lockup address to send funds to. */
600
763
  arkAddress: string;
764
+ /** Amount in satoshis to send to the lockup address. */
601
765
  amountToPay: number;
766
+ /** The pending chain swap object for monitoring. */
602
767
  pendingSwap: PendingChainSwap;
603
768
  }
769
+ /** Response from creating a BTC → ARK chain swap. */
604
770
  interface BtcToArkResponse {
771
+ /** The BTC lockup address to send funds to. */
605
772
  btcAddress: string;
773
+ /** Amount in satoshis to send to the lockup address. */
606
774
  amountToPay: number;
775
+ /** The pending chain swap object for monitoring. */
607
776
  pendingSwap: PendingChainSwap;
608
777
  }
778
+ /** Request to create a Lightning invoice (reverse swap: Lightning → Arkade). */
609
779
  interface CreateLightningInvoiceRequest {
780
+ /** Invoice amount in satoshis. */
610
781
  amount: number;
782
+ /** Optional description embedded in the BOLT11 invoice. */
611
783
  description?: string;
612
784
  }
785
+ /** Response containing the created Lightning invoice and swap details. */
613
786
  interface CreateLightningInvoiceResponse {
787
+ /** The on-chain amount in satoshis (after Boltz fees). */
614
788
  amount: number;
789
+ /** Invoice expiry timestamp (Unix seconds). */
615
790
  expiry: number;
791
+ /** The BOLT11-encoded Lightning invoice string. */
616
792
  invoice: string;
793
+ /** The payment hash (hex-encoded). */
617
794
  paymentHash: string;
795
+ /** The pending reverse swap for monitoring. */
618
796
  pendingSwap: PendingReverseSwap;
797
+ /** The preimage (hex-encoded). Keep secret until claiming. */
619
798
  preimage: string;
620
799
  }
800
+ /** Request to send a Lightning payment (submarine swap: Arkade → Lightning). */
621
801
  interface SendLightningPaymentRequest {
802
+ /** BOLT11-encoded Lightning invoice to pay. */
622
803
  invoice: string;
623
804
  }
805
+ /** Response after a successful Lightning payment. */
624
806
  interface SendLightningPaymentResponse {
807
+ /** Amount paid in satoshis. */
625
808
  amount: number;
809
+ /** Payment preimage proving payment was made (hex-encoded). */
626
810
  preimage: string;
811
+ /** Transaction ID of the Arkade payment. */
627
812
  txid: string;
628
813
  }
814
+ /** Tracks an in-progress reverse swap (Lightning → Arkade). */
629
815
  interface PendingReverseSwap {
816
+ /** Unique swap ID from Boltz. */
630
817
  id: string;
818
+ /** Discriminator — always "reverse". */
631
819
  type: "reverse";
820
+ /** Unix timestamp (seconds) when the swap was created. */
632
821
  createdAt: number;
822
+ /** The swap preimage (hex-encoded). Required for claiming the VHTLC. */
633
823
  preimage: string;
824
+ /** Current Boltz swap status. */
634
825
  status: BoltzSwapStatus;
826
+ /** The original request sent to Boltz. */
635
827
  request: CreateReverseSwapRequest;
828
+ /** Boltz API response with lockup address, invoice, and timeout details. */
636
829
  response: CreateReverseSwapResponse;
637
830
  }
831
+ /** Tracks an in-progress submarine swap (Arkade → Lightning). */
638
832
  interface PendingSubmarineSwap {
833
+ /** Unique swap ID from Boltz. */
639
834
  id: string;
835
+ /** Discriminator — always "submarine". */
640
836
  type: "submarine";
837
+ /** Unix timestamp (seconds) when the swap was created. */
641
838
  createdAt: number;
839
+ /** Payment preimage (hex-encoded). Available after the Lightning payment settles. */
642
840
  preimage?: string;
643
- /** Original preimage hash from Boltz (available for restored swaps) */
841
+ /** Original preimage hash from Boltz (available for restored swaps). */
644
842
  preimageHash?: string;
843
+ /** Whether the swap has been refunded. */
645
844
  refunded?: boolean;
845
+ /** Whether the swap is eligible for refund. */
646
846
  refundable?: boolean;
847
+ /** Current Boltz swap status. */
647
848
  status: BoltzSwapStatus;
849
+ /** The original request sent to Boltz. */
648
850
  request: CreateSubmarineSwapRequest;
851
+ /** Boltz API response with payment address and expected amount. */
649
852
  response: CreateSubmarineSwapResponse;
650
853
  }
854
+ /** Tracks an in-progress chain swap (ARK ↔ BTC). */
651
855
  interface PendingChainSwap {
856
+ /** Unique swap ID from Boltz. */
652
857
  id: string;
858
+ /** Discriminator — always "chain". */
653
859
  type: "chain";
860
+ /** The swap preimage (hex-encoded). Required for claiming. */
654
861
  preimage: string;
862
+ /** Unix timestamp (seconds) when the swap was created. */
655
863
  createdAt: number;
864
+ /** Ephemeral private key (hex) for BTC MuSig2 claim/refund signing. */
656
865
  ephemeralKey: string;
866
+ /** Fee rate (sats/vbyte) used for on-chain BTC transactions. */
657
867
  feeSatsPerByte: number;
868
+ /** Current Boltz swap status. */
658
869
  status: BoltzSwapStatus;
870
+ /** The original chain swap request sent to Boltz. */
659
871
  request: CreateChainSwapRequest;
872
+ /** Boltz API response with lockup and claim details. */
660
873
  response: CreateChainSwapResponse;
874
+ /** Destination address for the received funds. */
661
875
  toAddress?: string;
876
+ /** Swap amount in satoshis. */
662
877
  amount: number;
663
878
  }
879
+ /** Union type of all pending swap types. */
664
880
  type PendingSwap = PendingReverseSwap | PendingSubmarineSwap | PendingChainSwap;
881
+ /** Configuration for initializing ArkadeSwaps via the constructor (swapProvider is required). */
665
882
  interface ArkadeSwapsConfig {
883
+ /** An IWallet instance from @arkade-os/sdk (must expose arkProvider and indexerProvider). */
666
884
  wallet: IWallet;
885
+ /** Explicit ArkProvider. Falls back to wallet.arkProvider if omitted. */
667
886
  arkProvider?: ArkProvider;
887
+ /** BoltzSwapProvider instance for interacting with the Boltz API. */
668
888
  swapProvider: BoltzSwapProvider;
889
+ /** Explicit IndexerProvider. Falls back to wallet.indexerProvider if omitted. */
669
890
  indexerProvider?: IndexerProvider;
670
891
  /**
671
- * Enable background swap monitoring and autonomous actions.
672
- * - `false` or `undefined`: SwapManager disabled
673
- * - `true`: SwapManager enabled with default configuration
892
+ * Background swap monitoring and autonomous actions (enabled by default).
893
+ * - `undefined` or `true`: SwapManager enabled with default configuration
894
+ * - `false`: SwapManager disabled
674
895
  * - `SwapManagerConfig` object: SwapManager enabled with custom configuration
675
896
  */
676
897
  swapManager?: boolean | (SwapManagerConfig & {
@@ -683,50 +904,86 @@ interface ArkadeSwapsConfig {
683
904
  */
684
905
  swapRepository?: SwapRepository;
685
906
  }
907
+ /**
908
+ * Configuration for {@link ArkadeSwaps.create} — same as ArkadeSwapsConfig but
909
+ * `swapProvider` is optional (auto-created from the wallet's network if omitted).
910
+ */
911
+ type ArkadeSwapsCreateConfig = Omit<ArkadeSwapsConfig, "swapProvider"> & {
912
+ swapProvider?: BoltzSwapProvider;
913
+ };
914
+ /** A decoded BOLT11 Lightning invoice. */
686
915
  interface DecodedInvoice {
916
+ /** Invoice expiry timestamp (Unix seconds). */
687
917
  expiry: number;
918
+ /** Invoice amount in satoshis. */
688
919
  amountSats: number;
920
+ /** Invoice description string. */
689
921
  description: string;
922
+ /** Payment hash (hex-encoded). */
690
923
  paymentHash: string;
691
924
  }
925
+ /** Event subscription for incoming Lightning payments. */
692
926
  interface IncomingPaymentSubscription {
927
+ /** Fires when the payment is pending. */
693
928
  on(event: "pending", listener: () => void): this;
929
+ /** Fires when the swap has been created. */
694
930
  on(event: "created", listener: () => void): this;
931
+ /** Fires when the payment has been settled and funds claimed. */
695
932
  on(event: "settled", listener: () => void): this;
933
+ /** Fires when the payment fails. */
696
934
  on(event: "failed", listener: (error: Error) => void): this;
935
+ /** Removes all listeners and cleans up. */
697
936
  unsubscribe(): void;
698
937
  }
938
+ /** Swap amount limits from Boltz. */
699
939
  interface LimitsResponse {
940
+ /** Minimum swap amount in satoshis. */
700
941
  min: number;
942
+ /** Maximum swap amount in satoshis. */
701
943
  max: number;
702
944
  }
703
945
  /**
704
- * Fee info returned by Boltz.
705
- * - percentage: value (e.g., 0.01 = 0.01%)
706
- * - minerFees: values in satoshis
946
+ * Lightning swap fee info from Boltz.
947
+ * - `percentage`: Boltz fee as a percentage (e.g. 0.1 = 0.1%)
948
+ * - `minerFees`: values in satoshis
707
949
  */
708
950
  interface FeesResponse {
951
+ /** Submarine swap (Arkade → Lightning) fees. */
709
952
  submarine: {
953
+ /** Boltz fee as a percentage (e.g. 0.1 = 0.1%). */
710
954
  percentage: number;
955
+ /** Miner fee in satoshis. */
711
956
  minerFees: number;
712
957
  };
958
+ /** Reverse swap (Lightning → Arkade) fees. */
713
959
  reverse: {
960
+ /** Boltz fee as a percentage (e.g. 0.1 = 0.1%). */
714
961
  percentage: number;
962
+ /** Miner fees in satoshis. */
715
963
  minerFees: {
964
+ /** Miner fee for the lockup transaction. */
716
965
  lockup: number;
966
+ /** Miner fee for the claim transaction. */
717
967
  claim: number;
718
968
  };
719
969
  };
720
970
  }
971
+ /** Chain swap fee info from Boltz. */
721
972
  interface ChainFeesResponse {
973
+ /** Boltz fee as a percentage (e.g. 0.1 = 0.1%). */
722
974
  percentage: number;
975
+ /** Miner fees in satoshis. */
723
976
  minerFees: {
977
+ /** Server-side miner fee. */
724
978
  server: number;
979
+ /** User-side miner fees. */
725
980
  user: {
981
+ /** Miner fee for the claim transaction. */
726
982
  claim: number;
983
+ /** Miner fee for the lockup transaction. */
727
984
  lockup: number;
728
985
  };
729
986
  };
730
987
  }
731
988
 
732
- export { type ArkadeSwapsConfig as A, type BtcToArkResponse as B, type CreateLightningInvoiceRequest as C, type DecodedInvoice as D, isReverseFailedStatus as E, type FeesResponse as F, type GetSwapStatusResponse as G, isReverseFinalStatus as H, isReversePendingStatus as I, isReverseSuccessStatus as J, isReverseSwapClaimable as K, type LimitsResponse as L, isSubmarineFailedStatus as M, type Network as N, isSubmarineFinalStatus as O, type PendingSwap as P, isSubmarinePendingStatus as Q, isSubmarineSuccessStatus as R, type SendLightningPaymentRequest as S, isSubmarineRefundableStatus as T, isSubmarineSwapRefundable as U, SwapManager as V, type IncomingPaymentSubscription as W, type Vtxo as X, type SwapManagerConfig as Y, type SwapManagerEvents as Z, type SwapManagerCallbacks as _, type PendingChainSwap as a, type PendingReverseSwap as b, type PendingSubmarineSwap as c, type Chain as d, type CreateLightningInvoiceResponse as e, type SendLightningPaymentResponse as f, type ChainFeesResponse as g, type ArkToBtcResponse as h, type SwapRepository as i, type SwapManagerClient as j, type GetSwapsFilter as k, BoltzSwapProvider as l, type BoltzSwapStatus as m, isChainClaimableStatus as n, isChainFailedStatus as o, isChainFinalStatus as p, isChainPendingStatus as q, isChainRefundableStatus as r, isChainSignableStatus as s, isChainSuccessStatus as t, isChainSwapClaimable as u, isChainSwapRefundable as v, isPendingChainSwap as w, isPendingReverseSwap as x, isPendingSubmarineSwap as y, isReverseClaimableStatus as z };
989
+ export { type SwapManagerCallbacks as $, type ArkadeSwapsConfig as A, type BtcToArkResponse as B, type CreateLightningInvoiceRequest as C, type DecodedInvoice as D, isReverseFailedStatus as E, type FeesResponse as F, type GetSwapStatusResponse as G, isReverseFinalStatus as H, isReversePendingStatus as I, isReverseSuccessStatus as J, isReverseSwapClaimable as K, type LimitsResponse as L, isSubmarineFailedStatus as M, type Network as N, isSubmarineFinalStatus as O, type PendingSwap as P, isSubmarinePendingStatus as Q, isSubmarineSuccessStatus as R, type SendLightningPaymentRequest as S, isSubmarineRefundableStatus as T, isSubmarineSwapRefundable as U, SwapManager as V, type IncomingPaymentSubscription as W, type ArkadeSwapsCreateConfig as X, type Vtxo as Y, type SwapManagerConfig as Z, type SwapManagerEvents as _, type PendingChainSwap as a, type PendingReverseSwap as b, type PendingSubmarineSwap as c, type Chain as d, type CreateLightningInvoiceResponse as e, type SendLightningPaymentResponse as f, type ChainFeesResponse as g, type ArkToBtcResponse as h, type SwapRepository as i, type SwapManagerClient as j, type GetSwapsFilter as k, BoltzSwapProvider as l, type BoltzSwapStatus as m, isChainClaimableStatus as n, isChainFailedStatus as o, isChainFinalStatus as p, isChainPendingStatus as q, isChainRefundableStatus as r, isChainSignableStatus as s, isChainSuccessStatus as t, isChainSwapClaimable as u, isChainSwapRefundable as v, isPendingChainSwap as w, isPendingReverseSwap as x, isPendingSubmarineSwap as y, isReverseClaimableStatus as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/boltz-swap",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "A production-ready TypeScript package that brings Boltz submarine-swaps to Arkade.",
6
6
  "main": "./dist/index.js",
@@ -60,7 +60,7 @@
60
60
  "author": "Arkade-OS",
61
61
  "license": "MIT",
62
62
  "dependencies": {
63
- "@arkade-os/sdk": "0.4.0",
63
+ "@arkade-os/sdk": "0.4.3",
64
64
  "@noble/hashes": "2.0.1",
65
65
  "@scure/base": "2.0.0",
66
66
  "@scure/btc-signer": "2.0.1",