@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.
- package/README.md +139 -480
- package/dist/{arkade-swaps-Brpa88Fg.d.cts → arkade-swaps-DHjneVaF.d.ts} +86 -26
- package/dist/{arkade-swaps-DnvQayY0.d.ts → arkade-swaps-w-cm-cPg.d.cts} +86 -26
- package/dist/{background-OI6ONB3C.js → background-2UJPEKEU.js} +2 -2
- package/dist/{chunk-WNTQXNGX.js → chunk-LKAPZQDE.js} +1 -1
- package/dist/{chunk-XVJ47GNJ.js → chunk-Y7C7NJ5D.js} +163 -33
- package/dist/expo/index.cjs +164 -34
- package/dist/expo/index.d.cts +3 -2
- package/dist/expo/index.d.ts +3 -2
- package/dist/expo/index.js +4 -4
- package/dist/index.cjs +163 -33
- package/dist/index.d.cts +34 -4
- package/dist/index.d.ts +34 -4
- package/dist/index.js +1 -1
- package/dist/repositories/realm/index.d.cts +1 -1
- package/dist/repositories/realm/index.d.ts +1 -1
- package/dist/repositories/sqlite/index.d.cts +1 -1
- package/dist/repositories/sqlite/index.d.ts +1 -1
- package/dist/{types-BRYTZH1Z.d.cts → types-t0r41rlw.d.cts} +267 -10
- package/dist/{types-BRYTZH1Z.d.ts → types-t0r41rlw.d.ts} +267 -10
- package/package.json +2 -2
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
2
|
var SwapError = class extends Error {
|
|
3
|
+
/** Whether the swap can still be claimed (default: false). */
|
|
3
4
|
isClaimable;
|
|
5
|
+
/** Whether the swap can be refunded (default: false). */
|
|
4
6
|
isRefundable;
|
|
7
|
+
/** The pending swap associated with this error, if available. */
|
|
5
8
|
pendingSwap;
|
|
6
9
|
constructor(options = {}) {
|
|
7
10
|
super(options.message ?? "Error during swap.");
|
|
@@ -33,7 +36,9 @@ var InsufficientFundsError = class extends SwapError {
|
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
var NetworkError = class extends Error {
|
|
39
|
+
/** HTTP status code from the failed request, if available. */
|
|
36
40
|
statusCode;
|
|
41
|
+
/** Raw error payload from the Boltz API, if available. */
|
|
37
42
|
errorData;
|
|
38
43
|
constructor(message, statusCode, errorData) {
|
|
39
44
|
super(message);
|
|
@@ -272,7 +277,10 @@ var isTree = (data) => {
|
|
|
272
277
|
return data && typeof data === "object" && isLeaf(data.claimLeaf) && isLeaf(data.refundLeaf) && isLeaf(data.refundWithoutBoltzLeaf) && isLeaf(data.unilateralClaimLeaf) && isLeaf(data.unilateralRefundLeaf) && isLeaf(data.unilateralRefundWithoutBoltzLeaf);
|
|
273
278
|
};
|
|
274
279
|
var isDetails = (data) => {
|
|
275
|
-
return data && typeof data === "object" && isTree(data.tree) && (data.amount === void 0 || typeof data.amount === "number") && typeof data.keyIndex === "number" && (data.transaction === void 0 || data.transaction && typeof data.transaction === "object" && typeof data.transaction.id === "string" && typeof data.transaction.vout === "number") && typeof data.lockupAddress === "string" && typeof data.serverPublicKey === "string" && typeof data.timeoutBlockHeight === "number" && isTimeoutBlockHeights(data.timeoutBlockHeights) && (data.preimageHash === void 0 || typeof data.preimageHash === "string");
|
|
280
|
+
return data && typeof data === "object" && isTree(data.tree) && (data.amount === void 0 || typeof data.amount === "number") && typeof data.keyIndex === "number" && (data.transaction === void 0 || data.transaction && typeof data.transaction === "object" && typeof data.transaction.id === "string" && typeof data.transaction.vout === "number") && typeof data.lockupAddress === "string" && typeof data.serverPublicKey === "string" && typeof data.timeoutBlockHeight === "number" && (data.timeoutBlockHeights === void 0 || isTimeoutBlockHeights(data.timeoutBlockHeights)) && (data.preimageHash === void 0 || typeof data.preimageHash === "string");
|
|
281
|
+
};
|
|
282
|
+
var isRestoredChainSwap = (data) => {
|
|
283
|
+
return data && typeof data === "object" && typeof data.id === "string" && data.type === "chain" && typeof data.status === "string" && typeof data.createdAt === "number" && (data.from === "ARK" || data.from === "BTC") && (data.to === "ARK" || data.to === "BTC") && typeof data.preimageHash === "string" && data.refundDetails && typeof data.refundDetails === "object" && isTree(data.refundDetails.tree) && typeof data.refundDetails.amount === "number" && typeof data.refundDetails.keyIndex === "number" && (data.refundDetails.transaction === void 0 || data.refundDetails.transaction && typeof data.refundDetails.transaction === "object" && typeof data.refundDetails.transaction.id === "string" && typeof data.refundDetails.transaction.vout === "number") && typeof data.refundDetails.lockupAddress === "string" && typeof data.refundDetails.serverPublicKey === "string" && typeof data.refundDetails.timeoutBlockHeight === "number";
|
|
276
284
|
};
|
|
277
285
|
var isRestoredSubmarineSwap = (data) => {
|
|
278
286
|
return data && typeof data === "object" && data.to === "BTC" && typeof data.id === "string" && data.from === "ARK" && data.type === "submarine" && typeof data.createdAt === "number" && typeof data.preimageHash === "string" && typeof data.status === "string" && isDetails(data.refundDetails);
|
|
@@ -282,10 +290,11 @@ var isRestoredReverseSwap = (data) => {
|
|
|
282
290
|
};
|
|
283
291
|
var isCreateSwapsRestoreResponse = (data) => {
|
|
284
292
|
return Array.isArray(data) && data.every(
|
|
285
|
-
(item) => isRestoredReverseSwap(item) || isRestoredSubmarineSwap(item)
|
|
293
|
+
(item) => isRestoredChainSwap(item) || isRestoredReverseSwap(item) || isRestoredSubmarineSwap(item)
|
|
286
294
|
);
|
|
287
295
|
};
|
|
288
296
|
var BASE_URLS = {
|
|
297
|
+
bitcoin: "https://api.ark.boltz.exchange",
|
|
289
298
|
mutinynet: "https://api.boltz.mutinynet.arkade.sh",
|
|
290
299
|
regtest: "http://localhost:9069"
|
|
291
300
|
};
|
|
@@ -294,6 +303,7 @@ var BoltzSwapProvider = class {
|
|
|
294
303
|
apiUrl;
|
|
295
304
|
network;
|
|
296
305
|
referralId;
|
|
306
|
+
/** @param config Provider configuration with network and optional API URL. */
|
|
297
307
|
constructor(config) {
|
|
298
308
|
this.network = config.network;
|
|
299
309
|
this.referralId = config.referralId;
|
|
@@ -305,15 +315,19 @@ var BoltzSwapProvider = class {
|
|
|
305
315
|
this.apiUrl = apiUrl;
|
|
306
316
|
this.wsUrl = this.apiUrl.replace(/^http(s)?:\/\//, "ws$1://").replace("9069", "9004") + "/v2/ws";
|
|
307
317
|
}
|
|
318
|
+
/** Returns the Boltz API base URL. */
|
|
308
319
|
getApiUrl() {
|
|
309
320
|
return this.apiUrl;
|
|
310
321
|
}
|
|
322
|
+
/** Returns the Boltz WebSocket URL (derived from apiUrl). */
|
|
311
323
|
getWsUrl() {
|
|
312
324
|
return this.wsUrl;
|
|
313
325
|
}
|
|
326
|
+
/** Returns the configured network. */
|
|
314
327
|
getNetwork() {
|
|
315
328
|
return this.network;
|
|
316
329
|
}
|
|
330
|
+
/** Returns current Lightning swap fees (submarine + reverse) from Boltz. */
|
|
317
331
|
async getFees() {
|
|
318
332
|
const [submarine, reverse] = await Promise.all([
|
|
319
333
|
this.request(
|
|
@@ -337,6 +351,7 @@ var BoltzSwapProvider = class {
|
|
|
337
351
|
}
|
|
338
352
|
};
|
|
339
353
|
}
|
|
354
|
+
/** Returns current Lightning swap min/max limits from Boltz. */
|
|
340
355
|
async getLimits() {
|
|
341
356
|
const response = await this.request(
|
|
342
357
|
"/v2/swap/submarine",
|
|
@@ -349,6 +364,7 @@ var BoltzSwapProvider = class {
|
|
|
349
364
|
max: response.ARK.BTC.limits.maximal
|
|
350
365
|
};
|
|
351
366
|
}
|
|
367
|
+
/** Gets the lockup transaction ID for a reverse swap. */
|
|
352
368
|
async getReverseSwapTxId(id) {
|
|
353
369
|
const res = await this.request(
|
|
354
370
|
`/v2/swap/reverse/${id}/transaction`,
|
|
@@ -360,6 +376,7 @@ var BoltzSwapProvider = class {
|
|
|
360
376
|
});
|
|
361
377
|
return res;
|
|
362
378
|
}
|
|
379
|
+
/** Queries the current status of a swap by ID. */
|
|
363
380
|
async getSwapStatus(id) {
|
|
364
381
|
const response = await this.request(
|
|
365
382
|
`/v2/swap/${id}`,
|
|
@@ -371,6 +388,7 @@ var BoltzSwapProvider = class {
|
|
|
371
388
|
});
|
|
372
389
|
return response;
|
|
373
390
|
}
|
|
391
|
+
/** Gets the preimage for a settled submarine swap (proof of payment). */
|
|
374
392
|
async getSwapPreimage(id) {
|
|
375
393
|
const res = await this.request(
|
|
376
394
|
`/v2/swap/submarine/${id}/preimage`,
|
|
@@ -382,6 +400,7 @@ var BoltzSwapProvider = class {
|
|
|
382
400
|
});
|
|
383
401
|
return res;
|
|
384
402
|
}
|
|
403
|
+
/** Creates a submarine swap (Arkade → Lightning) on Boltz. */
|
|
385
404
|
async createSubmarineSwap({
|
|
386
405
|
invoice,
|
|
387
406
|
refundPublicKey
|
|
@@ -407,6 +426,7 @@ var BoltzSwapProvider = class {
|
|
|
407
426
|
throw new SchemaError({ message: "Error creating submarine swap" });
|
|
408
427
|
return response;
|
|
409
428
|
}
|
|
429
|
+
/** Creates a reverse swap (Lightning → Arkade) on Boltz. */
|
|
410
430
|
async createReverseSwap({
|
|
411
431
|
invoiceAmount,
|
|
412
432
|
claimPublicKey,
|
|
@@ -436,6 +456,7 @@ var BoltzSwapProvider = class {
|
|
|
436
456
|
throw new SchemaError({ message: "Error creating reverse swap" });
|
|
437
457
|
return response;
|
|
438
458
|
}
|
|
459
|
+
/** Creates a chain swap (ARK ↔ BTC) on Boltz. */
|
|
439
460
|
async createChainSwap({
|
|
440
461
|
to,
|
|
441
462
|
from,
|
|
@@ -494,6 +515,7 @@ var BoltzSwapProvider = class {
|
|
|
494
515
|
throw new SchemaError({ message: "Error creating chain swap" });
|
|
495
516
|
return response;
|
|
496
517
|
}
|
|
518
|
+
/** Requests Boltz co-signature for a submarine swap refund. Returns signed transaction + checkpoint. */
|
|
497
519
|
async refundSubmarineSwap(swapId, transaction, checkpoint) {
|
|
498
520
|
const requestBody = {
|
|
499
521
|
checkpoint: base64.encode(checkpoint.toPSBT()),
|
|
@@ -517,6 +539,7 @@ var BoltzSwapProvider = class {
|
|
|
517
539
|
)
|
|
518
540
|
};
|
|
519
541
|
}
|
|
542
|
+
/** Requests Boltz co-signature for a chain swap refund. Returns signed transaction + checkpoint. */
|
|
520
543
|
async refundChainSwap(swapId, transaction, checkpoint) {
|
|
521
544
|
const requestBody = {
|
|
522
545
|
checkpoint: base64.encode(checkpoint.toPSBT()),
|
|
@@ -540,6 +563,7 @@ var BoltzSwapProvider = class {
|
|
|
540
563
|
)
|
|
541
564
|
};
|
|
542
565
|
}
|
|
566
|
+
/** Monitors swap status updates via WebSocket. Calls update callback on each status change. Resolves when terminal. */
|
|
543
567
|
async monitorSwap(swapId, update) {
|
|
544
568
|
return new Promise((resolve, reject) => {
|
|
545
569
|
const webSocket = new globalThis.WebSocket(this.wsUrl);
|
|
@@ -607,6 +631,7 @@ var BoltzSwapProvider = class {
|
|
|
607
631
|
};
|
|
608
632
|
});
|
|
609
633
|
}
|
|
634
|
+
/** Returns current chain swap fees for a given pair (e.g. ARK→BTC). */
|
|
610
635
|
async getChainFees(from, to) {
|
|
611
636
|
if (from === to) {
|
|
612
637
|
throw new SwapError({ message: "Invalid chain pair" });
|
|
@@ -624,6 +649,7 @@ var BoltzSwapProvider = class {
|
|
|
624
649
|
}
|
|
625
650
|
return response[from][to].fees;
|
|
626
651
|
}
|
|
652
|
+
/** Returns current chain swap min/max limits for a given pair. */
|
|
627
653
|
async getChainLimits(from, to) {
|
|
628
654
|
if (from === to) {
|
|
629
655
|
throw new SwapError({ message: "Invalid chain pair" });
|
|
@@ -644,6 +670,7 @@ var BoltzSwapProvider = class {
|
|
|
644
670
|
max: response[from][to].limits.maximal
|
|
645
671
|
};
|
|
646
672
|
}
|
|
673
|
+
/** Gets claim details (pubNonce, publicKey, transactionHash) for cooperative chain swap claiming. */
|
|
647
674
|
async getChainClaimDetails(swapId) {
|
|
648
675
|
const response = await this.request(
|
|
649
676
|
`/v2/swap/chain/${swapId}/claim`,
|
|
@@ -655,6 +682,7 @@ var BoltzSwapProvider = class {
|
|
|
655
682
|
});
|
|
656
683
|
return response;
|
|
657
684
|
}
|
|
685
|
+
/** Gets a renegotiated quote for a chain swap when lockup amount differs from expected. */
|
|
658
686
|
async getChainQuote(swapId) {
|
|
659
687
|
const response = await this.request(
|
|
660
688
|
`/v2/swap/chain/${swapId}/quote`,
|
|
@@ -666,6 +694,7 @@ var BoltzSwapProvider = class {
|
|
|
666
694
|
});
|
|
667
695
|
return response;
|
|
668
696
|
}
|
|
697
|
+
/** Accepts a renegotiated quote amount for a chain swap. */
|
|
669
698
|
async postChainQuote(swapId, request) {
|
|
670
699
|
const response = await this.request(
|
|
671
700
|
`/v2/swap/chain/${swapId}/quote`,
|
|
@@ -678,6 +707,7 @@ var BoltzSwapProvider = class {
|
|
|
678
707
|
});
|
|
679
708
|
return response;
|
|
680
709
|
}
|
|
710
|
+
/** Broadcasts a raw BTC transaction through Boltz. */
|
|
681
711
|
async postBtcTransaction(hex9) {
|
|
682
712
|
const requestBody = { hex: hex9 };
|
|
683
713
|
const response = await this.request(
|
|
@@ -691,6 +721,7 @@ var BoltzSwapProvider = class {
|
|
|
691
721
|
});
|
|
692
722
|
return response;
|
|
693
723
|
}
|
|
724
|
+
/** Posts claim details (preimage + signing data) or cooperative signature for a chain swap. */
|
|
694
725
|
async postChainClaimDetails(swapId, request) {
|
|
695
726
|
const response = await this.request(
|
|
696
727
|
`/v2/swap/chain/${swapId}/claim`,
|
|
@@ -703,6 +734,7 @@ var BoltzSwapProvider = class {
|
|
|
703
734
|
});
|
|
704
735
|
return response;
|
|
705
736
|
}
|
|
737
|
+
/** Restores swaps from Boltz API using the wallet's public key. */
|
|
706
738
|
async restoreSwaps(publicKey) {
|
|
707
739
|
const requestBody = {
|
|
708
740
|
publicKey
|
|
@@ -2798,24 +2830,61 @@ var validFinalArkTx = (finalArkTx, _pubkey, _tapLeaves) => {
|
|
|
2798
2830
|
};
|
|
2799
2831
|
|
|
2800
2832
|
// src/arkade-swaps.ts
|
|
2801
|
-
var ArkadeSwaps = class {
|
|
2833
|
+
var ArkadeSwaps = class _ArkadeSwaps {
|
|
2834
|
+
/** The Arkade wallet instance used for signing and address generation. */
|
|
2802
2835
|
wallet;
|
|
2836
|
+
/** Provider for Ark protocol operations (VTXO management, batch joining). */
|
|
2803
2837
|
arkProvider;
|
|
2838
|
+
/** Boltz API client for creating and monitoring swaps. */
|
|
2804
2839
|
swapProvider;
|
|
2840
|
+
/** Provider for querying VTXO state on the Ark indexer. */
|
|
2805
2841
|
indexerProvider;
|
|
2842
|
+
/** Background swap monitor, or null if not enabled. */
|
|
2806
2843
|
swapManager = null;
|
|
2844
|
+
/** Storage backend for persisting swap data. */
|
|
2807
2845
|
swapRepository;
|
|
2846
|
+
/**
|
|
2847
|
+
* Creates an ArkadeSwaps instance, auto-detecting the network from the wallet's Ark server.
|
|
2848
|
+
* If no `swapProvider` is given, one is created automatically using the detected network.
|
|
2849
|
+
*
|
|
2850
|
+
* This is the recommended way to initialize ArkadeSwaps.
|
|
2851
|
+
*
|
|
2852
|
+
* @param config - Configuration options. swapProvider is auto-created from the wallet's network if omitted.
|
|
2853
|
+
* @returns A fully initialized ArkadeSwaps instance.
|
|
2854
|
+
*
|
|
2855
|
+
* @example
|
|
2856
|
+
* ```ts
|
|
2857
|
+
* const swaps = await ArkadeSwaps.create({
|
|
2858
|
+
* wallet,
|
|
2859
|
+
* swapManager: true,
|
|
2860
|
+
* });
|
|
2861
|
+
* ```
|
|
2862
|
+
*/
|
|
2863
|
+
static async create(config) {
|
|
2864
|
+
if (config.swapProvider) {
|
|
2865
|
+
return new _ArkadeSwaps(config);
|
|
2866
|
+
}
|
|
2867
|
+
const arkProvider = config.arkProvider ?? config.wallet.arkProvider;
|
|
2868
|
+
if (!arkProvider)
|
|
2869
|
+
throw new Error(
|
|
2870
|
+
"Ark provider is required either in wallet or config."
|
|
2871
|
+
);
|
|
2872
|
+
const arkInfo = await arkProvider.getInfo();
|
|
2873
|
+
const network = arkInfo.network;
|
|
2874
|
+
const swapProvider = new BoltzSwapProvider({ network });
|
|
2875
|
+
return new _ArkadeSwaps({ ...config, swapProvider });
|
|
2876
|
+
}
|
|
2808
2877
|
constructor(config) {
|
|
2809
2878
|
if (!config.wallet) throw new Error("Wallet is required.");
|
|
2810
2879
|
if (!config.swapProvider) throw new Error("Swap provider is required.");
|
|
2811
2880
|
this.wallet = config.wallet;
|
|
2812
|
-
const arkProvider = config.
|
|
2881
|
+
const arkProvider = config.arkProvider ?? config.wallet.arkProvider;
|
|
2813
2882
|
if (!arkProvider)
|
|
2814
2883
|
throw new Error(
|
|
2815
2884
|
"Ark provider is required either in wallet or config."
|
|
2816
2885
|
);
|
|
2817
2886
|
this.arkProvider = arkProvider;
|
|
2818
|
-
const indexerProvider = config.
|
|
2887
|
+
const indexerProvider = config.indexerProvider ?? config.wallet.indexerProvider;
|
|
2819
2888
|
if (!indexerProvider)
|
|
2820
2889
|
throw new Error(
|
|
2821
2890
|
"Indexer provider is required either in wallet or config."
|
|
@@ -2827,8 +2896,8 @@ var ArkadeSwaps = class {
|
|
|
2827
2896
|
} else {
|
|
2828
2897
|
this.swapRepository = new IndexedDbSwapRepository();
|
|
2829
2898
|
}
|
|
2830
|
-
if (config.swapManager) {
|
|
2831
|
-
const swapManagerConfig = config.swapManager === true ? {} : config.swapManager;
|
|
2899
|
+
if (config.swapManager !== false) {
|
|
2900
|
+
const swapManagerConfig = !config.swapManager || config.swapManager === true ? {} : config.swapManager;
|
|
2832
2901
|
const shouldAutostart = swapManagerConfig.autoStart ?? true;
|
|
2833
2902
|
this.swapManager = new SwapManager(
|
|
2834
2903
|
this.swapProvider,
|
|
@@ -2945,9 +3014,11 @@ var ArkadeSwaps = class {
|
|
|
2945
3014
|
// Lightning: Reverse swaps (receive Lightning -> Arkade)
|
|
2946
3015
|
// =========================================================================
|
|
2947
3016
|
/**
|
|
2948
|
-
* Creates a Lightning invoice.
|
|
2949
|
-
* @param args -
|
|
2950
|
-
* @
|
|
3017
|
+
* Creates a Lightning invoice via a reverse swap (Lightning → Arkade).
|
|
3018
|
+
* @param args.amount - Invoice amount in satoshis.
|
|
3019
|
+
* @param args.description - Optional description for the BOLT11 invoice.
|
|
3020
|
+
* @returns Object containing the BOLT11 invoice, payment hash, preimage, and pending swap for monitoring.
|
|
3021
|
+
* @throws {SwapError} If amount is <= 0 or wallet key retrieval fails.
|
|
2951
3022
|
*/
|
|
2952
3023
|
async createLightningInvoice(args) {
|
|
2953
3024
|
const pendingSwap = await this.createReverseSwap(args);
|
|
@@ -2962,9 +3033,11 @@ var ArkadeSwaps = class {
|
|
|
2962
3033
|
};
|
|
2963
3034
|
}
|
|
2964
3035
|
/**
|
|
2965
|
-
* Creates a reverse swap.
|
|
2966
|
-
* @param args -
|
|
2967
|
-
* @
|
|
3036
|
+
* Creates a reverse swap (Lightning → Arkade) and saves it to storage.
|
|
3037
|
+
* @param args.amount - Amount in satoshis for the reverse swap.
|
|
3038
|
+
* @param args.description - Optional invoice description.
|
|
3039
|
+
* @returns The pending reverse swap, added to SwapManager if enabled.
|
|
3040
|
+
* @throws {SwapError} If amount is <= 0 or key retrieval fails.
|
|
2968
3041
|
*/
|
|
2969
3042
|
async createReverseSwap(args) {
|
|
2970
3043
|
if (args.amount <= 0)
|
|
@@ -3003,8 +3076,9 @@ var ArkadeSwaps = class {
|
|
|
3003
3076
|
return pendingSwap;
|
|
3004
3077
|
}
|
|
3005
3078
|
/**
|
|
3006
|
-
* Claims the VHTLC for a pending reverse swap.
|
|
3007
|
-
* @param pendingSwap - The
|
|
3079
|
+
* Claims the VHTLC for a pending reverse swap, transferring locked funds to the wallet.
|
|
3080
|
+
* @param pendingSwap - The reverse swap whose VHTLC should be claimed.
|
|
3081
|
+
* @throws {Error} If preimage is missing, VHTLC script creation fails, or no spendable VTXOs found.
|
|
3008
3082
|
*/
|
|
3009
3083
|
async claimVHTLC(pendingSwap) {
|
|
3010
3084
|
if (!pendingSwap.preimage)
|
|
@@ -3084,9 +3158,13 @@ var ArkadeSwaps = class {
|
|
|
3084
3158
|
);
|
|
3085
3159
|
}
|
|
3086
3160
|
/**
|
|
3087
|
-
* Waits for
|
|
3088
|
-
*
|
|
3161
|
+
* Waits for a reverse swap to be confirmed and claims the VHTLC.
|
|
3162
|
+
* Delegates to SwapManager if enabled, otherwise monitors via WebSocket.
|
|
3163
|
+
* @param pendingSwap - The reverse swap to monitor and claim.
|
|
3089
3164
|
* @returns The transaction ID of the claimed VHTLC.
|
|
3165
|
+
* @throws {InvoiceExpiredError} If the Lightning invoice expires.
|
|
3166
|
+
* @throws {SwapExpiredError} If the swap exceeds its time limit.
|
|
3167
|
+
* @throws {TransactionFailedError} If the on-chain transaction fails.
|
|
3090
3168
|
*/
|
|
3091
3169
|
async waitAndClaim(pendingSwap) {
|
|
3092
3170
|
if (this.swapManager && await this.swapManager.hasSwap(pendingSwap.id)) {
|
|
@@ -3166,9 +3244,11 @@ var ArkadeSwaps = class {
|
|
|
3166
3244
|
// Lightning: Submarine swaps (send Arkade -> Lightning)
|
|
3167
3245
|
// =========================================================================
|
|
3168
3246
|
/**
|
|
3169
|
-
* Sends a Lightning payment.
|
|
3170
|
-
*
|
|
3171
|
-
* @
|
|
3247
|
+
* Sends a Lightning payment via a submarine swap (Arkade → Lightning).
|
|
3248
|
+
* Creates the swap, sends funds, and waits for settlement. Auto-refunds on failure.
|
|
3249
|
+
* @param args.invoice - BOLT11 Lightning invoice to pay.
|
|
3250
|
+
* @returns The amount paid, preimage (proof of payment), and transaction ID.
|
|
3251
|
+
* @throws {TransactionFailedError} If the payment fails (auto-refunds if possible).
|
|
3172
3252
|
*/
|
|
3173
3253
|
async sendLightningPayment(args) {
|
|
3174
3254
|
const pendingSwap = await this.createSubmarineSwap(args);
|
|
@@ -3198,9 +3278,10 @@ var ArkadeSwaps = class {
|
|
|
3198
3278
|
}
|
|
3199
3279
|
}
|
|
3200
3280
|
/**
|
|
3201
|
-
* Creates a submarine swap.
|
|
3202
|
-
* @param args -
|
|
3203
|
-
* @returns The
|
|
3281
|
+
* Creates a submarine swap (Arkade → Lightning) and saves it to storage.
|
|
3282
|
+
* @param args.invoice - BOLT11 Lightning invoice to pay.
|
|
3283
|
+
* @returns The pending submarine swap, added to SwapManager if enabled.
|
|
3284
|
+
* @throws {SwapError} If invoice is missing or key retrieval fails.
|
|
3204
3285
|
*/
|
|
3205
3286
|
async createSubmarineSwap(args) {
|
|
3206
3287
|
const refundPublicKey = hex8.encode(
|
|
@@ -3232,8 +3313,10 @@ var ArkadeSwaps = class {
|
|
|
3232
3313
|
return pendingSwap;
|
|
3233
3314
|
}
|
|
3234
3315
|
/**
|
|
3235
|
-
*
|
|
3236
|
-
*
|
|
3316
|
+
* Refunds the VHTLC for a failed submarine swap, returning locked funds to the wallet.
|
|
3317
|
+
* Uses multi-party signatures (user + Boltz + server) for non-recoverable VTXOs.
|
|
3318
|
+
* @param pendingSwap - The submarine swap to refund.
|
|
3319
|
+
* @throws {Error} If preimage hash is unavailable, VHTLC not found, or already spent.
|
|
3237
3320
|
*/
|
|
3238
3321
|
async refundVHTLC(pendingSwap) {
|
|
3239
3322
|
const preimageHash = pendingSwap.request.invoice ? getInvoicePaymentHash(pendingSwap.request.invoice) : pendingSwap.preimageHash;
|
|
@@ -3317,9 +3400,12 @@ var ArkadeSwaps = class {
|
|
|
3317
3400
|
);
|
|
3318
3401
|
}
|
|
3319
3402
|
/**
|
|
3320
|
-
* Waits for
|
|
3321
|
-
* @param pendingSwap - The
|
|
3322
|
-
* @returns The
|
|
3403
|
+
* Waits for a submarine swap's Lightning payment to settle.
|
|
3404
|
+
* @param pendingSwap - The submarine swap to monitor.
|
|
3405
|
+
* @returns The preimage from the settled Lightning payment (proof of payment).
|
|
3406
|
+
* @throws {SwapExpiredError} If the swap expires.
|
|
3407
|
+
* @throws {InvoiceFailedToPayError} If Boltz fails to route the payment.
|
|
3408
|
+
* @throws {TransactionLockupFailedError} If the lockup transaction fails.
|
|
3323
3409
|
*/
|
|
3324
3410
|
async waitForSwapSettlement(pendingSwap) {
|
|
3325
3411
|
return new Promise((resolve, reject) => {
|
|
@@ -3390,8 +3476,12 @@ var ArkadeSwaps = class {
|
|
|
3390
3476
|
// =========================================================================
|
|
3391
3477
|
/**
|
|
3392
3478
|
* Creates a chain swap from ARK to BTC.
|
|
3393
|
-
* @param args -
|
|
3394
|
-
* @
|
|
3479
|
+
* @param args.btcAddress - Destination Bitcoin address.
|
|
3480
|
+
* @param args.senderLockAmount - Exact amount sender locks (receiver gets less after fees). Specify this OR receiverLockAmount.
|
|
3481
|
+
* @param args.receiverLockAmount - Exact amount receiver gets (sender pays more). Specify this OR senderLockAmount.
|
|
3482
|
+
* @param args.feeSatsPerByte - Fee rate for the BTC claim transaction (default: 1).
|
|
3483
|
+
* @returns The ARK lockup address, amount to pay, and pending swap.
|
|
3484
|
+
* @throws {SwapError} If chain swap verification fails.
|
|
3395
3485
|
*/
|
|
3396
3486
|
async arkToBtc(args) {
|
|
3397
3487
|
const pendingSwap = await this.createChainSwap({
|
|
@@ -3683,8 +3773,11 @@ var ArkadeSwaps = class {
|
|
|
3683
3773
|
// =========================================================================
|
|
3684
3774
|
/**
|
|
3685
3775
|
* Creates a chain swap from BTC to ARK.
|
|
3686
|
-
* @param args -
|
|
3687
|
-
* @
|
|
3776
|
+
* @param args.feeSatsPerByte - Fee rate for BTC transactions (default: 1).
|
|
3777
|
+
* @param args.senderLockAmount - Exact BTC amount to lock. Specify this OR receiverLockAmount.
|
|
3778
|
+
* @param args.receiverLockAmount - Exact ARK amount to receive. Specify this OR senderLockAmount.
|
|
3779
|
+
* @returns The BTC lockup address, amount to pay, and pending swap.
|
|
3780
|
+
* @throws {SwapError} If chain swap verification fails.
|
|
3688
3781
|
*/
|
|
3689
3782
|
async btcToArk(args) {
|
|
3690
3783
|
const pendingSwap = await this.createChainSwap({
|
|
@@ -4226,6 +4319,7 @@ var ArkadeSwaps = class {
|
|
|
4226
4319
|
);
|
|
4227
4320
|
if (!publicKey) throw new Error("Failed to get public key from wallet");
|
|
4228
4321
|
const fees = boltzFees ?? await this.swapProvider.getFees();
|
|
4322
|
+
const chainSwaps = [];
|
|
4229
4323
|
const reverseSwaps = [];
|
|
4230
4324
|
const submarineSwaps = [];
|
|
4231
4325
|
const restoredSwaps = await this.swapProvider.restoreSwaps(publicKey);
|
|
@@ -4318,9 +4412,45 @@ var ArkadeSwaps = class {
|
|
|
4318
4412
|
}
|
|
4319
4413
|
}
|
|
4320
4414
|
});
|
|
4415
|
+
} else if (isRestoredChainSwap(swap)) {
|
|
4416
|
+
const {
|
|
4417
|
+
amount,
|
|
4418
|
+
lockupAddress,
|
|
4419
|
+
serverPublicKey,
|
|
4420
|
+
timeoutBlockHeight
|
|
4421
|
+
} = swap.refundDetails;
|
|
4422
|
+
chainSwaps.push({
|
|
4423
|
+
id,
|
|
4424
|
+
type: "chain",
|
|
4425
|
+
createdAt,
|
|
4426
|
+
preimage: "",
|
|
4427
|
+
ephemeralKey: "",
|
|
4428
|
+
feeSatsPerByte: 1,
|
|
4429
|
+
amount,
|
|
4430
|
+
status,
|
|
4431
|
+
request: {
|
|
4432
|
+
to: swap.to,
|
|
4433
|
+
from: swap.from,
|
|
4434
|
+
preimageHash: swap.preimageHash,
|
|
4435
|
+
claimPublicKey: "",
|
|
4436
|
+
feeSatsPerByte: 1,
|
|
4437
|
+
refundPublicKey: "",
|
|
4438
|
+
serverLockAmount: amount,
|
|
4439
|
+
userLockAmount: amount
|
|
4440
|
+
},
|
|
4441
|
+
response: {
|
|
4442
|
+
id,
|
|
4443
|
+
lockupDetails: {
|
|
4444
|
+
amount,
|
|
4445
|
+
lockupAddress,
|
|
4446
|
+
serverPublicKey,
|
|
4447
|
+
timeoutBlockHeight
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
});
|
|
4321
4451
|
}
|
|
4322
4452
|
}
|
|
4323
|
-
return { reverseSwaps, submarineSwaps };
|
|
4453
|
+
return { chainSwaps, reverseSwaps, submarineSwaps };
|
|
4324
4454
|
}
|
|
4325
4455
|
/**
|
|
4326
4456
|
* Enrich a restored reverse swap with its preimage.
|