@arkade-os/boltz-swap 0.3.43 → 0.3.45
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/dist/{arkade-swaps-LvsGHtre.d.ts → arkade-swaps-C8CmzknM.d.cts} +28 -2
- package/dist/{arkade-swaps-C3sUFr5f.d.cts → arkade-swaps-gXHRbR09.d.ts} +28 -2
- package/dist/{chunk-UXYHW7KV.js → chunk-5GBBRBFS.js} +199 -161
- package/dist/{chunk-CWY37W4B.js → chunk-WPAI2ECT.js} +1 -1
- package/dist/expo/background.cjs +199 -161
- package/dist/expo/background.d.cts +3 -3
- package/dist/expo/background.d.ts +3 -3
- package/dist/expo/background.js +2 -2
- package/dist/expo/index.cjs +199 -161
- package/dist/expo/index.d.cts +4 -4
- package/dist/expo/index.d.ts +4 -4
- package/dist/expo/index.js +2 -2
- package/dist/index.cjs +200 -162
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- 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/{swapsPollProcessor-CGMXUKPe.d.cts → swapsPollProcessor-B98F6MQF.d.cts} +1 -1
- package/dist/{swapsPollProcessor-CuDM6sxV.d.ts → swapsPollProcessor-Ov-wp17v.d.ts} +1 -1
- package/dist/{types-8NrCdOpS.d.cts → types-CS62-oEy.d.cts} +19 -2
- package/dist/{types-8NrCdOpS.d.ts → types-CS62-oEy.d.ts} +19 -2
- package/package.json +2 -2
package/dist/expo/index.cjs
CHANGED
|
@@ -535,20 +535,26 @@ var BoltzSwapProvider = class {
|
|
|
535
535
|
invoiceAmount,
|
|
536
536
|
claimPublicKey,
|
|
537
537
|
preimageHash,
|
|
538
|
-
description
|
|
538
|
+
description,
|
|
539
|
+
descriptionHash
|
|
539
540
|
}) {
|
|
540
541
|
if (claimPublicKey.length != 66) {
|
|
541
542
|
throw new SwapError({
|
|
542
543
|
message: "claimPublicKey must be a compressed public key"
|
|
543
544
|
});
|
|
544
545
|
}
|
|
546
|
+
if (descriptionHash !== void 0 && !/^[0-9a-fA-F]{64}$/.test(descriptionHash)) {
|
|
547
|
+
throw new SwapError({
|
|
548
|
+
message: "descriptionHash must be a 32-byte SHA256 (64 hex chars)"
|
|
549
|
+
});
|
|
550
|
+
}
|
|
545
551
|
const requestBody = {
|
|
546
552
|
from: "BTC",
|
|
547
553
|
to: "ARK",
|
|
548
554
|
invoiceAmount,
|
|
549
555
|
claimPublicKey,
|
|
550
556
|
preimageHash,
|
|
551
|
-
description: description?.trim() || "Send to Arkade address",
|
|
557
|
+
...descriptionHash ? { descriptionHash } : { description: description?.trim() || "Send to Arkade address" },
|
|
552
558
|
...this.referralId ? { referralId: this.referralId } : {}
|
|
553
559
|
};
|
|
554
560
|
const response = await this.request(
|
|
@@ -1302,6 +1308,12 @@ var decodeInvoice = (invoice) => {
|
|
|
1302
1308
|
expiry: decoded.expiry ?? 3600,
|
|
1303
1309
|
amountSats: Number(millisats / 1000n),
|
|
1304
1310
|
description: decoded.sections.find((s) => s.name === "description")?.value ?? "",
|
|
1311
|
+
// description_hash (BOLT11 `h`) is missing from light-bolt11-decoder's
|
|
1312
|
+
// Section union even though the decoder emits it. Widen just this lookup
|
|
1313
|
+
// rather than patch the library's types (separate repo, out of scope).
|
|
1314
|
+
descriptionHash: decoded.sections.find(
|
|
1315
|
+
(s) => s.name === "description_hash"
|
|
1316
|
+
)?.value ?? "",
|
|
1305
1317
|
paymentHash: decoded.sections.find((s) => s.name === "payment_hash")?.value ?? ""
|
|
1306
1318
|
};
|
|
1307
1319
|
};
|
|
@@ -3033,6 +3045,40 @@ var claimVHTLCwithOffchainTx = async (identity, vhtlcScript, serverXOnlyPublicKe
|
|
|
3033
3045
|
await arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
3034
3046
|
return arkTxid;
|
|
3035
3047
|
};
|
|
3048
|
+
var refundWithoutReceiverVHTLCwithOffchainTx = async (identity, vhtlcScript, serverXOnlyPublicKey, input, output, arkInfo, arkProvider) => {
|
|
3049
|
+
const rawCheckpointTapscript = import_base8.hex.decode(arkInfo.checkpointTapscript);
|
|
3050
|
+
const serverUnrollScript = import_sdk7.CSVMultisigTapscript.decode(rawCheckpointTapscript);
|
|
3051
|
+
const { arkTx, checkpoints } = (0, import_sdk7.buildOffchainTx)([input], [output], serverUnrollScript);
|
|
3052
|
+
const signedArkTx = await identity.sign(arkTx);
|
|
3053
|
+
const { arkTxid, finalArkTx, signedCheckpointTxs } = await arkProvider.submitTx(
|
|
3054
|
+
import_base8.base64.encode(signedArkTx.toPSBT()),
|
|
3055
|
+
checkpoints.map((c) => import_base8.base64.encode(c.toPSBT()))
|
|
3056
|
+
);
|
|
3057
|
+
const finalTx = import_sdk7.Transaction.fromPSBT(import_base8.base64.decode(finalArkTx));
|
|
3058
|
+
const serverPubkeyHex = import_base8.hex.encode(serverXOnlyPublicKey);
|
|
3059
|
+
const refundLeafHash = (0, import_payment3.tapLeafHash)(
|
|
3060
|
+
scriptFromTapLeafScript(vhtlcScript.refundWithoutReceiver())
|
|
3061
|
+
);
|
|
3062
|
+
for (let i = 0; i < finalTx.inputsLength; i++) {
|
|
3063
|
+
if (!verifySignatures(finalTx, i, [serverPubkeyHex], refundLeafHash)) {
|
|
3064
|
+
throw new Error("Invalid final Ark transaction");
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
const finalCheckpoints = await Promise.all(
|
|
3068
|
+
signedCheckpointTxs.map(async (c, idx) => {
|
|
3069
|
+
const tx = import_sdk7.Transaction.fromPSBT(import_base8.base64.decode(c));
|
|
3070
|
+
const checkpointLeaf = checkpoints[idx].getInput(0).tapLeafScript[0];
|
|
3071
|
+
const cpLeafHash = (0, import_payment3.tapLeafHash)(scriptFromTapLeafScript(checkpointLeaf));
|
|
3072
|
+
if (!verifySignatures(tx, 0, [serverPubkeyHex], cpLeafHash)) {
|
|
3073
|
+
throw new Error("Invalid server signature in checkpoint transaction");
|
|
3074
|
+
}
|
|
3075
|
+
const signedCheckpoint = await identity.sign(tx, [0]);
|
|
3076
|
+
return import_base8.base64.encode(signedCheckpoint.toPSBT());
|
|
3077
|
+
})
|
|
3078
|
+
);
|
|
3079
|
+
await arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
3080
|
+
return arkTxid;
|
|
3081
|
+
};
|
|
3036
3082
|
var refundVHTLCwithOffchainTx = async (swapId, identity, arkProvider, boltzXOnlyPublicKey, ourXOnlyPublicKey, serverXOnlyPublicKey, input, output, arkInfo, refundFunc) => {
|
|
3037
3083
|
const rawCheckpointTapscript = import_base8.hex.decode(arkInfo.checkpointTapscript);
|
|
3038
3084
|
const serverUnrollScript = import_sdk7.CSVMultisigTapscript.decode(rawCheckpointTapscript);
|
|
@@ -3339,7 +3385,7 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
3339
3385
|
invoiceAmount: args.amount,
|
|
3340
3386
|
claimPublicKey,
|
|
3341
3387
|
preimageHash,
|
|
3342
|
-
...args.description?.trim() ? { description: args.description.trim() } : {}
|
|
3388
|
+
...args.descriptionHash !== void 0 ? { descriptionHash: args.descriptionHash } : args.description?.trim() ? { description: args.description.trim() } : {}
|
|
3343
3389
|
};
|
|
3344
3390
|
const swapResponse = await this.swapProvider.createReverseSwap(swapRequest);
|
|
3345
3391
|
const decodedInvoice = decodeInvoice(swapResponse.invoice);
|
|
@@ -3787,85 +3833,22 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
3787
3833
|
}
|
|
3788
3834
|
const outputScript = import_sdk8.ArkAddress.decode(address).pkScript;
|
|
3789
3835
|
const refundWithoutReceiverLeaf = vhtlcScript.refundWithoutReceiver();
|
|
3790
|
-
const
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
await this.joinBatch(
|
|
3807
|
-
this.wallet.identity,
|
|
3808
|
-
input2,
|
|
3809
|
-
output,
|
|
3810
|
-
arkInfo,
|
|
3811
|
-
isRecoverableVtxo
|
|
3812
|
-
);
|
|
3813
|
-
sweptCount++;
|
|
3814
|
-
continue;
|
|
3815
|
-
}
|
|
3816
|
-
if (isRecoverableVtxo) {
|
|
3817
|
-
logger.error(
|
|
3818
|
-
`Swap ${pendingSwap.id}: recoverable VTXO ${vtxo.txid}:${vtxo.vout} cannot be refunded yet \u2014 refundWithoutReceiver locktime has not passed (refundLocktime=${vhtlcTimeouts.refund}, currentTimestamp=${Math.floor(Date.now() / 1e3)}). Refund will be retried after locktime.`
|
|
3819
|
-
);
|
|
3820
|
-
skippedCount++;
|
|
3821
|
-
continue;
|
|
3822
|
-
}
|
|
3823
|
-
const input = {
|
|
3824
|
-
...vtxo,
|
|
3825
|
-
tapLeafScript: vhtlcScript.refund(),
|
|
3826
|
-
tapTree: vhtlcScript.encode()
|
|
3827
|
-
};
|
|
3828
|
-
try {
|
|
3829
|
-
if (boltzCallCount > 0) {
|
|
3830
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
3831
|
-
}
|
|
3832
|
-
boltzCallCount++;
|
|
3833
|
-
await refundVHTLCwithOffchainTx(
|
|
3834
|
-
pendingSwap.id,
|
|
3835
|
-
this.wallet.identity,
|
|
3836
|
-
this.arkProvider,
|
|
3837
|
-
boltzXOnlyPublicKey,
|
|
3838
|
-
ourXOnlyPublicKey,
|
|
3839
|
-
serverXOnlyPublicKey,
|
|
3840
|
-
input,
|
|
3841
|
-
output,
|
|
3842
|
-
arkInfo,
|
|
3843
|
-
this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
|
|
3844
|
-
);
|
|
3845
|
-
sweptCount++;
|
|
3846
|
-
} catch (error) {
|
|
3847
|
-
if (!(error instanceof BoltzRefundError)) {
|
|
3848
|
-
throw error;
|
|
3849
|
-
}
|
|
3850
|
-
if (!isSubmarineRefundLocktimeReached(vhtlcTimeouts.refund)) {
|
|
3851
|
-
logger.error(
|
|
3852
|
-
`Swap ${pendingSwap.id}: Boltz rejected VTXO outpoint and refundWithoutReceiver locktime has not passed yet (currentTimestamp=${Math.floor(Date.now() / 1e3)}, locktime=${vhtlcTimeouts.refund}). Refund will be retried after locktime.`
|
|
3853
|
-
);
|
|
3854
|
-
skippedCount++;
|
|
3855
|
-
continue;
|
|
3856
|
-
}
|
|
3857
|
-
logger.warn(
|
|
3858
|
-
`Swap ${pendingSwap.id}: Boltz rejected VTXO outpoint, falling back to refundWithoutReceiver via joinBatch`
|
|
3859
|
-
);
|
|
3860
|
-
const fallbackInput = {
|
|
3861
|
-
...vtxo,
|
|
3862
|
-
tapLeafScript: refundWithoutReceiverLeaf,
|
|
3863
|
-
tapTree: vhtlcScript.encode()
|
|
3864
|
-
};
|
|
3865
|
-
await this.joinBatch(this.wallet.identity, fallbackInput, output, arkInfo, false);
|
|
3866
|
-
sweptCount++;
|
|
3867
|
-
}
|
|
3868
|
-
}
|
|
3836
|
+
const refundContext = {
|
|
3837
|
+
arkInfo,
|
|
3838
|
+
vhtlcScript,
|
|
3839
|
+
serverXOnlyPublicKey,
|
|
3840
|
+
refundWithoutReceiverLeaf,
|
|
3841
|
+
outputScript
|
|
3842
|
+
};
|
|
3843
|
+
const { swept: sweptCount, skipped: skippedCount } = await this.refundVtxos({
|
|
3844
|
+
swapId: pendingSwap.id,
|
|
3845
|
+
vtxos: refundableVtxos,
|
|
3846
|
+
refundLocktime: vhtlcTimeouts.refund,
|
|
3847
|
+
refundContext,
|
|
3848
|
+
boltzXOnlyPublicKey,
|
|
3849
|
+
ourXOnlyPublicKey,
|
|
3850
|
+
refundViaBoltz: this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
|
|
3851
|
+
});
|
|
3869
3852
|
if (!isSubmarineSuccessStatus(pendingSwap.status)) {
|
|
3870
3853
|
const fullyRefunded = skippedCount === 0;
|
|
3871
3854
|
await updateSubmarineSwapStatus(
|
|
@@ -4423,7 +4406,10 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
4423
4406
|
* swap's ARK lockup address.
|
|
4424
4407
|
*
|
|
4425
4408
|
* Path selection per VTXO:
|
|
4426
|
-
* - CLTV
|
|
4409
|
+
* - CLTV elapsed, live VTXO → `refundWithoutReceiver` offchain (sender +
|
|
4410
|
+
* server, no Boltz, no batch round).
|
|
4411
|
+
* - CLTV elapsed, swept VTXO → `refundWithoutReceiver` via `joinBatch`
|
|
4412
|
+
* (a swept VTXO is no longer a live leaf).
|
|
4427
4413
|
* - Pre-CLTV recoverable → skipped (Boltz can't co-sign swept-batch refund).
|
|
4428
4414
|
* - Pre-CLTV non-recoverable → cooperative 3-of-3 refund via Boltz.
|
|
4429
4415
|
*
|
|
@@ -4480,84 +4466,22 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
4480
4466
|
const outputScript = import_sdk8.ArkAddress.decode(address).pkScript;
|
|
4481
4467
|
const refundWithoutReceiverLeaf = vhtlcScript.refundWithoutReceiver();
|
|
4482
4468
|
const refundLocktime = pendingSwap.response.lockupDetails.timeouts.refund;
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
this.wallet.identity,
|
|
4500
|
-
input2,
|
|
4501
|
-
output,
|
|
4502
|
-
arkInfo,
|
|
4503
|
-
isRecoverableVtxo
|
|
4504
|
-
);
|
|
4505
|
-
sweptCount++;
|
|
4506
|
-
continue;
|
|
4507
|
-
}
|
|
4508
|
-
if (isRecoverableVtxo) {
|
|
4509
|
-
logger.error(
|
|
4510
|
-
`Swap ${pendingSwap.id}: recoverable VTXO ${vtxo.txid}:${vtxo.vout} cannot be refunded yet \u2014 refundWithoutReceiver locktime has not passed (refundLocktime=${refundLocktime}, currentTimestamp=${Math.floor(Date.now() / 1e3)}). Refund will be retried after locktime.`
|
|
4511
|
-
);
|
|
4512
|
-
skippedCount++;
|
|
4513
|
-
continue;
|
|
4514
|
-
}
|
|
4515
|
-
const input = {
|
|
4516
|
-
...vtxo,
|
|
4517
|
-
tapLeafScript: vhtlcScript.refund(),
|
|
4518
|
-
tapTree: vhtlcScript.encode()
|
|
4519
|
-
};
|
|
4520
|
-
try {
|
|
4521
|
-
if (boltzCallCount > 0) {
|
|
4522
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
4523
|
-
}
|
|
4524
|
-
boltzCallCount++;
|
|
4525
|
-
await refundVHTLCwithOffchainTx(
|
|
4526
|
-
pendingSwap.id,
|
|
4527
|
-
this.wallet.identity,
|
|
4528
|
-
this.arkProvider,
|
|
4529
|
-
boltzXOnlyPublicKey,
|
|
4530
|
-
ourXOnlyPublicKey,
|
|
4531
|
-
serverXOnlyPublicKey,
|
|
4532
|
-
input,
|
|
4533
|
-
output,
|
|
4534
|
-
arkInfo,
|
|
4535
|
-
this.swapProvider.refundChainSwap.bind(this.swapProvider)
|
|
4536
|
-
);
|
|
4537
|
-
sweptCount++;
|
|
4538
|
-
} catch (error) {
|
|
4539
|
-
if (!(error instanceof BoltzRefundError)) {
|
|
4540
|
-
throw error;
|
|
4541
|
-
}
|
|
4542
|
-
if (!isSubmarineRefundLocktimeReached(refundLocktime)) {
|
|
4543
|
-
logger.error(
|
|
4544
|
-
`Swap ${pendingSwap.id}: Boltz rejected VTXO outpoint and refundWithoutReceiver locktime has not passed yet (currentTimestamp=${Math.floor(Date.now() / 1e3)}, locktime=${refundLocktime}). Refund will be retried after locktime.`
|
|
4545
|
-
);
|
|
4546
|
-
skippedCount++;
|
|
4547
|
-
continue;
|
|
4548
|
-
}
|
|
4549
|
-
logger.warn(
|
|
4550
|
-
`Swap ${pendingSwap.id}: Boltz rejected VTXO outpoint, falling back to refundWithoutReceiver via joinBatch`
|
|
4551
|
-
);
|
|
4552
|
-
const fallbackInput = {
|
|
4553
|
-
...vtxo,
|
|
4554
|
-
tapLeafScript: refundWithoutReceiverLeaf,
|
|
4555
|
-
tapTree: vhtlcScript.encode()
|
|
4556
|
-
};
|
|
4557
|
-
await this.joinBatch(this.wallet.identity, fallbackInput, output, arkInfo, false);
|
|
4558
|
-
sweptCount++;
|
|
4559
|
-
}
|
|
4560
|
-
}
|
|
4469
|
+
const refundContext = {
|
|
4470
|
+
arkInfo,
|
|
4471
|
+
vhtlcScript,
|
|
4472
|
+
serverXOnlyPublicKey,
|
|
4473
|
+
refundWithoutReceiverLeaf,
|
|
4474
|
+
outputScript
|
|
4475
|
+
};
|
|
4476
|
+
const { swept: sweptCount, skipped: skippedCount } = await this.refundVtxos({
|
|
4477
|
+
swapId: pendingSwap.id,
|
|
4478
|
+
vtxos: unspentVtxos,
|
|
4479
|
+
refundLocktime,
|
|
4480
|
+
refundContext,
|
|
4481
|
+
boltzXOnlyPublicKey,
|
|
4482
|
+
ourXOnlyPublicKey,
|
|
4483
|
+
refundViaBoltz: this.swapProvider.refundChainSwap.bind(this.swapProvider)
|
|
4484
|
+
});
|
|
4561
4485
|
const finalStatus = await this.getSwapStatus(pendingSwap.id);
|
|
4562
4486
|
await this.savePendingChainSwap({
|
|
4563
4487
|
...pendingSwap,
|
|
@@ -5090,6 +5014,120 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
5090
5014
|
async joinBatch(identity, input, output, arkInfo, isRecoverable2 = true) {
|
|
5091
5015
|
return joinBatch(this.arkProvider, identity, input, output, arkInfo, isRecoverable2);
|
|
5092
5016
|
}
|
|
5017
|
+
/**
|
|
5018
|
+
* Settle a `refundWithoutReceiver` (sender + server, no Boltz) refund for a
|
|
5019
|
+
* single VTXO whose CLTV refund locktime has elapsed.
|
|
5020
|
+
*
|
|
5021
|
+
* A live VTXO settles the leaf with an offchain Ark tx — no batch round. A
|
|
5022
|
+
* swept (recoverable) VTXO is no longer a live leaf, so it can only be
|
|
5023
|
+
* reclaimed by re-registering it into a batch.
|
|
5024
|
+
*/
|
|
5025
|
+
async settleRefundWithoutReceiver(ctx, vtxo) {
|
|
5026
|
+
const input = {
|
|
5027
|
+
...vtxo,
|
|
5028
|
+
tapLeafScript: ctx.refundWithoutReceiverLeaf,
|
|
5029
|
+
tapTree: ctx.vhtlcScript.encode()
|
|
5030
|
+
};
|
|
5031
|
+
const output = { amount: BigInt(vtxo.value), script: ctx.outputScript };
|
|
5032
|
+
if ((0, import_sdk8.isRecoverable)(vtxo)) {
|
|
5033
|
+
await this.joinBatch(this.wallet.identity, input, output, ctx.arkInfo, true);
|
|
5034
|
+
} else {
|
|
5035
|
+
await refundWithoutReceiverVHTLCwithOffchainTx(
|
|
5036
|
+
this.wallet.identity,
|
|
5037
|
+
ctx.vhtlcScript,
|
|
5038
|
+
ctx.serverXOnlyPublicKey,
|
|
5039
|
+
input,
|
|
5040
|
+
output,
|
|
5041
|
+
ctx.arkInfo,
|
|
5042
|
+
this.arkProvider
|
|
5043
|
+
);
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
/**
|
|
5047
|
+
* Refund every VTXO at a swap's VHTLC address back to the wallet, shared by
|
|
5048
|
+
* {@link ArkadeSwaps.refundVHTLC} (submarine) and {@link ArkadeSwaps.refundArk}
|
|
5049
|
+
* (chain). Path selection per VTXO:
|
|
5050
|
+
* - CLTV elapsed → `refundWithoutReceiver` (offchain for a live VTXO, via a
|
|
5051
|
+
* batch round for a swept one — see {@link settleRefundWithoutReceiver}).
|
|
5052
|
+
* - Pre-CLTV recoverable → skipped (Boltz can't co-sign a swept-batch refund).
|
|
5053
|
+
* - Pre-CLTV non-recoverable → cooperative 3-of-3 refund via Boltz, falling
|
|
5054
|
+
* back to `refundWithoutReceiver` offchain if Boltz rejects after the
|
|
5055
|
+
* locktime has since elapsed.
|
|
5056
|
+
*
|
|
5057
|
+
* @returns Counts of VTXOs swept vs. deferred.
|
|
5058
|
+
*/
|
|
5059
|
+
async refundVtxos(params) {
|
|
5060
|
+
const {
|
|
5061
|
+
swapId,
|
|
5062
|
+
vtxos,
|
|
5063
|
+
refundLocktime,
|
|
5064
|
+
refundContext,
|
|
5065
|
+
boltzXOnlyPublicKey,
|
|
5066
|
+
ourXOnlyPublicKey,
|
|
5067
|
+
refundViaBoltz
|
|
5068
|
+
} = params;
|
|
5069
|
+
const { vhtlcScript, serverXOnlyPublicKey, arkInfo, outputScript } = refundContext;
|
|
5070
|
+
let boltzCallCount = 0;
|
|
5071
|
+
let sweptCount = 0;
|
|
5072
|
+
let skippedCount = 0;
|
|
5073
|
+
for (const vtxo of vtxos) {
|
|
5074
|
+
const isRecoverableVtxo = (0, import_sdk8.isRecoverable)(vtxo);
|
|
5075
|
+
const output = { amount: BigInt(vtxo.value), script: outputScript };
|
|
5076
|
+
if (isSubmarineRefundLocktimeReached(refundLocktime)) {
|
|
5077
|
+
await this.settleRefundWithoutReceiver(refundContext, vtxo);
|
|
5078
|
+
sweptCount++;
|
|
5079
|
+
continue;
|
|
5080
|
+
}
|
|
5081
|
+
if (isRecoverableVtxo) {
|
|
5082
|
+
logger.error(
|
|
5083
|
+
`Swap ${swapId}: recoverable VTXO ${vtxo.txid}:${vtxo.vout} cannot be refunded yet \u2014 refundWithoutReceiver locktime has not passed (refundLocktime=${refundLocktime}, currentTimestamp=${Math.floor(Date.now() / 1e3)}). Refund will be retried after locktime.`
|
|
5084
|
+
);
|
|
5085
|
+
skippedCount++;
|
|
5086
|
+
continue;
|
|
5087
|
+
}
|
|
5088
|
+
const input = {
|
|
5089
|
+
...vtxo,
|
|
5090
|
+
tapLeafScript: vhtlcScript.refund(),
|
|
5091
|
+
tapTree: vhtlcScript.encode()
|
|
5092
|
+
};
|
|
5093
|
+
try {
|
|
5094
|
+
if (boltzCallCount > 0) {
|
|
5095
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
5096
|
+
}
|
|
5097
|
+
boltzCallCount++;
|
|
5098
|
+
await refundVHTLCwithOffchainTx(
|
|
5099
|
+
swapId,
|
|
5100
|
+
this.wallet.identity,
|
|
5101
|
+
this.arkProvider,
|
|
5102
|
+
boltzXOnlyPublicKey,
|
|
5103
|
+
ourXOnlyPublicKey,
|
|
5104
|
+
serverXOnlyPublicKey,
|
|
5105
|
+
input,
|
|
5106
|
+
output,
|
|
5107
|
+
arkInfo,
|
|
5108
|
+
refundViaBoltz
|
|
5109
|
+
);
|
|
5110
|
+
sweptCount++;
|
|
5111
|
+
} catch (error) {
|
|
5112
|
+
if (!(error instanceof BoltzRefundError)) {
|
|
5113
|
+
throw error;
|
|
5114
|
+
}
|
|
5115
|
+
if (!isSubmarineRefundLocktimeReached(refundLocktime)) {
|
|
5116
|
+
logger.error(
|
|
5117
|
+
`Swap ${swapId}: Boltz rejected VTXO outpoint and refundWithoutReceiver locktime has not passed yet (currentTimestamp=${Math.floor(Date.now() / 1e3)}, locktime=${refundLocktime}). Refund will be retried after locktime.`
|
|
5118
|
+
);
|
|
5119
|
+
skippedCount++;
|
|
5120
|
+
continue;
|
|
5121
|
+
}
|
|
5122
|
+
logger.warn(
|
|
5123
|
+
`Swap ${swapId}: Boltz rejected VTXO outpoint, falling back to refundWithoutReceiver offchain`
|
|
5124
|
+
);
|
|
5125
|
+
await this.settleRefundWithoutReceiver(refundContext, vtxo);
|
|
5126
|
+
sweptCount++;
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
return { swept: sweptCount, skipped: skippedCount };
|
|
5130
|
+
}
|
|
5093
5131
|
/**
|
|
5094
5132
|
* Creates a VHTLC script for the swap.
|
|
5095
5133
|
* Works for submarine, reverse, and chain swaps.
|
package/dist/expo/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { I as IArkadeSwaps, A as ArkadeSwaps, Q as QuoteSwapOptions, V as VhtlcTimeouts } from '../arkade-swaps-
|
|
2
|
-
import { n as SwapManagerClient, C as CreateLightningInvoiceRequest, e as CreateLightningInvoiceResponse, S as SendLightningPaymentRequest, o as SendLightningPaymentResponse, O as OptimisticSendLightningPaymentResponse, c as BoltzSubmarineSwap, b as BoltzReverseSwap, f as SubmarineRefundOutcome, g as SubmarineRecoveryInfo, h as SubmarineRecoveryResult, F as FeesResponse, a as BoltzChainSwap, j as ArkToBtcResponse, l as ChainArkRefundOutcome, k as BtcToArkResponse, d as Chain, i as ChainFeesResponse, L as LimitsResponse, G as GetSwapStatusResponse, B as BoltzSwap } from '../types-
|
|
3
|
-
import { E as ExpoArkadeSwapsConfig } from '../swapsPollProcessor-
|
|
4
|
-
export { D as DefineSwapBackgroundTaskOptions, b as ExpoArkadeLightningConfig, c as ExpoSwapBackgroundConfig, P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies } from '../swapsPollProcessor-
|
|
1
|
+
import { I as IArkadeSwaps, A as ArkadeSwaps, Q as QuoteSwapOptions, V as VhtlcTimeouts } from '../arkade-swaps-C8CmzknM.cjs';
|
|
2
|
+
import { n as SwapManagerClient, C as CreateLightningInvoiceRequest, e as CreateLightningInvoiceResponse, S as SendLightningPaymentRequest, o as SendLightningPaymentResponse, O as OptimisticSendLightningPaymentResponse, c as BoltzSubmarineSwap, b as BoltzReverseSwap, f as SubmarineRefundOutcome, g as SubmarineRecoveryInfo, h as SubmarineRecoveryResult, F as FeesResponse, a as BoltzChainSwap, j as ArkToBtcResponse, l as ChainArkRefundOutcome, k as BtcToArkResponse, d as Chain, i as ChainFeesResponse, L as LimitsResponse, G as GetSwapStatusResponse, B as BoltzSwap } from '../types-CS62-oEy.cjs';
|
|
3
|
+
import { E as ExpoArkadeSwapsConfig } from '../swapsPollProcessor-B98F6MQF.cjs';
|
|
4
|
+
export { D as DefineSwapBackgroundTaskOptions, b as ExpoArkadeLightningConfig, c as ExpoSwapBackgroundConfig, P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies } from '../swapsPollProcessor-B98F6MQF.cjs';
|
|
5
5
|
import { ArkInfo, Identity, ArkTxInput, VHTLC } from '@arkade-os/sdk';
|
|
6
6
|
import { TransactionOutput } from '@scure/btc-signer/psbt.js';
|
|
7
7
|
import '@arkade-os/sdk/worker/expo';
|
package/dist/expo/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { I as IArkadeSwaps, A as ArkadeSwaps, Q as QuoteSwapOptions, V as VhtlcTimeouts } from '../arkade-swaps-
|
|
2
|
-
import { n as SwapManagerClient, C as CreateLightningInvoiceRequest, e as CreateLightningInvoiceResponse, S as SendLightningPaymentRequest, o as SendLightningPaymentResponse, O as OptimisticSendLightningPaymentResponse, c as BoltzSubmarineSwap, b as BoltzReverseSwap, f as SubmarineRefundOutcome, g as SubmarineRecoveryInfo, h as SubmarineRecoveryResult, F as FeesResponse, a as BoltzChainSwap, j as ArkToBtcResponse, l as ChainArkRefundOutcome, k as BtcToArkResponse, d as Chain, i as ChainFeesResponse, L as LimitsResponse, G as GetSwapStatusResponse, B as BoltzSwap } from '../types-
|
|
3
|
-
import { E as ExpoArkadeSwapsConfig } from '../swapsPollProcessor-
|
|
4
|
-
export { D as DefineSwapBackgroundTaskOptions, b as ExpoArkadeLightningConfig, c as ExpoSwapBackgroundConfig, P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies } from '../swapsPollProcessor-
|
|
1
|
+
import { I as IArkadeSwaps, A as ArkadeSwaps, Q as QuoteSwapOptions, V as VhtlcTimeouts } from '../arkade-swaps-gXHRbR09.js';
|
|
2
|
+
import { n as SwapManagerClient, C as CreateLightningInvoiceRequest, e as CreateLightningInvoiceResponse, S as SendLightningPaymentRequest, o as SendLightningPaymentResponse, O as OptimisticSendLightningPaymentResponse, c as BoltzSubmarineSwap, b as BoltzReverseSwap, f as SubmarineRefundOutcome, g as SubmarineRecoveryInfo, h as SubmarineRecoveryResult, F as FeesResponse, a as BoltzChainSwap, j as ArkToBtcResponse, l as ChainArkRefundOutcome, k as BtcToArkResponse, d as Chain, i as ChainFeesResponse, L as LimitsResponse, G as GetSwapStatusResponse, B as BoltzSwap } from '../types-CS62-oEy.js';
|
|
3
|
+
import { E as ExpoArkadeSwapsConfig } from '../swapsPollProcessor-Ov-wp17v.js';
|
|
4
|
+
export { D as DefineSwapBackgroundTaskOptions, b as ExpoArkadeLightningConfig, c as ExpoSwapBackgroundConfig, P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies } from '../swapsPollProcessor-Ov-wp17v.js';
|
|
5
5
|
import { ArkInfo, Identity, ArkTxInput, VHTLC } from '@arkade-os/sdk';
|
|
6
6
|
import { TransactionOutput } from '@scure/btc-signer/psbt.js';
|
|
7
7
|
import '@arkade-os/sdk/worker/expo';
|
package/dist/expo/index.js
CHANGED