@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/background.cjs
CHANGED
|
@@ -544,20 +544,26 @@ var BoltzSwapProvider = class {
|
|
|
544
544
|
invoiceAmount,
|
|
545
545
|
claimPublicKey,
|
|
546
546
|
preimageHash,
|
|
547
|
-
description
|
|
547
|
+
description,
|
|
548
|
+
descriptionHash
|
|
548
549
|
}) {
|
|
549
550
|
if (claimPublicKey.length != 66) {
|
|
550
551
|
throw new SwapError({
|
|
551
552
|
message: "claimPublicKey must be a compressed public key"
|
|
552
553
|
});
|
|
553
554
|
}
|
|
555
|
+
if (descriptionHash !== void 0 && !/^[0-9a-fA-F]{64}$/.test(descriptionHash)) {
|
|
556
|
+
throw new SwapError({
|
|
557
|
+
message: "descriptionHash must be a 32-byte SHA256 (64 hex chars)"
|
|
558
|
+
});
|
|
559
|
+
}
|
|
554
560
|
const requestBody = {
|
|
555
561
|
from: "BTC",
|
|
556
562
|
to: "ARK",
|
|
557
563
|
invoiceAmount,
|
|
558
564
|
claimPublicKey,
|
|
559
565
|
preimageHash,
|
|
560
|
-
description: description?.trim() || "Send to Arkade address",
|
|
566
|
+
...descriptionHash ? { descriptionHash } : { description: description?.trim() || "Send to Arkade address" },
|
|
561
567
|
...this.referralId ? { referralId: this.referralId } : {}
|
|
562
568
|
};
|
|
563
569
|
const response = await this.request(
|
|
@@ -1312,6 +1318,12 @@ var decodeInvoice = (invoice) => {
|
|
|
1312
1318
|
expiry: decoded.expiry ?? 3600,
|
|
1313
1319
|
amountSats: Number(millisats / 1000n),
|
|
1314
1320
|
description: decoded.sections.find((s) => s.name === "description")?.value ?? "",
|
|
1321
|
+
// description_hash (BOLT11 `h`) is missing from light-bolt11-decoder's
|
|
1322
|
+
// Section union even though the decoder emits it. Widen just this lookup
|
|
1323
|
+
// rather than patch the library's types (separate repo, out of scope).
|
|
1324
|
+
descriptionHash: decoded.sections.find(
|
|
1325
|
+
(s) => s.name === "description_hash"
|
|
1326
|
+
)?.value ?? "",
|
|
1315
1327
|
paymentHash: decoded.sections.find((s) => s.name === "payment_hash")?.value ?? ""
|
|
1316
1328
|
};
|
|
1317
1329
|
};
|
|
@@ -3043,6 +3055,40 @@ var claimVHTLCwithOffchainTx = async (identity, vhtlcScript, serverXOnlyPublicKe
|
|
|
3043
3055
|
await arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
3044
3056
|
return arkTxid;
|
|
3045
3057
|
};
|
|
3058
|
+
var refundWithoutReceiverVHTLCwithOffchainTx = async (identity, vhtlcScript, serverXOnlyPublicKey, input, output, arkInfo, arkProvider) => {
|
|
3059
|
+
const rawCheckpointTapscript = import_base8.hex.decode(arkInfo.checkpointTapscript);
|
|
3060
|
+
const serverUnrollScript = import_sdk7.CSVMultisigTapscript.decode(rawCheckpointTapscript);
|
|
3061
|
+
const { arkTx, checkpoints } = (0, import_sdk7.buildOffchainTx)([input], [output], serverUnrollScript);
|
|
3062
|
+
const signedArkTx = await identity.sign(arkTx);
|
|
3063
|
+
const { arkTxid, finalArkTx, signedCheckpointTxs } = await arkProvider.submitTx(
|
|
3064
|
+
import_base8.base64.encode(signedArkTx.toPSBT()),
|
|
3065
|
+
checkpoints.map((c) => import_base8.base64.encode(c.toPSBT()))
|
|
3066
|
+
);
|
|
3067
|
+
const finalTx = import_sdk7.Transaction.fromPSBT(import_base8.base64.decode(finalArkTx));
|
|
3068
|
+
const serverPubkeyHex = import_base8.hex.encode(serverXOnlyPublicKey);
|
|
3069
|
+
const refundLeafHash = (0, import_payment3.tapLeafHash)(
|
|
3070
|
+
scriptFromTapLeafScript(vhtlcScript.refundWithoutReceiver())
|
|
3071
|
+
);
|
|
3072
|
+
for (let i = 0; i < finalTx.inputsLength; i++) {
|
|
3073
|
+
if (!verifySignatures(finalTx, i, [serverPubkeyHex], refundLeafHash)) {
|
|
3074
|
+
throw new Error("Invalid final Ark transaction");
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
const finalCheckpoints = await Promise.all(
|
|
3078
|
+
signedCheckpointTxs.map(async (c, idx) => {
|
|
3079
|
+
const tx = import_sdk7.Transaction.fromPSBT(import_base8.base64.decode(c));
|
|
3080
|
+
const checkpointLeaf = checkpoints[idx].getInput(0).tapLeafScript[0];
|
|
3081
|
+
const cpLeafHash = (0, import_payment3.tapLeafHash)(scriptFromTapLeafScript(checkpointLeaf));
|
|
3082
|
+
if (!verifySignatures(tx, 0, [serverPubkeyHex], cpLeafHash)) {
|
|
3083
|
+
throw new Error("Invalid server signature in checkpoint transaction");
|
|
3084
|
+
}
|
|
3085
|
+
const signedCheckpoint = await identity.sign(tx, [0]);
|
|
3086
|
+
return import_base8.base64.encode(signedCheckpoint.toPSBT());
|
|
3087
|
+
})
|
|
3088
|
+
);
|
|
3089
|
+
await arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
3090
|
+
return arkTxid;
|
|
3091
|
+
};
|
|
3046
3092
|
var refundVHTLCwithOffchainTx = async (swapId, identity, arkProvider, boltzXOnlyPublicKey, ourXOnlyPublicKey, serverXOnlyPublicKey, input, output, arkInfo, refundFunc) => {
|
|
3047
3093
|
const rawCheckpointTapscript = import_base8.hex.decode(arkInfo.checkpointTapscript);
|
|
3048
3094
|
const serverUnrollScript = import_sdk7.CSVMultisigTapscript.decode(rawCheckpointTapscript);
|
|
@@ -3349,7 +3395,7 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
3349
3395
|
invoiceAmount: args.amount,
|
|
3350
3396
|
claimPublicKey,
|
|
3351
3397
|
preimageHash,
|
|
3352
|
-
...args.description?.trim() ? { description: args.description.trim() } : {}
|
|
3398
|
+
...args.descriptionHash !== void 0 ? { descriptionHash: args.descriptionHash } : args.description?.trim() ? { description: args.description.trim() } : {}
|
|
3353
3399
|
};
|
|
3354
3400
|
const swapResponse = await this.swapProvider.createReverseSwap(swapRequest);
|
|
3355
3401
|
const decodedInvoice = decodeInvoice(swapResponse.invoice);
|
|
@@ -3797,85 +3843,22 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
3797
3843
|
}
|
|
3798
3844
|
const outputScript = import_sdk8.ArkAddress.decode(address).pkScript;
|
|
3799
3845
|
const refundWithoutReceiverLeaf = vhtlcScript.refundWithoutReceiver();
|
|
3800
|
-
const
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
await this.joinBatch(
|
|
3817
|
-
this.wallet.identity,
|
|
3818
|
-
input2,
|
|
3819
|
-
output,
|
|
3820
|
-
arkInfo,
|
|
3821
|
-
isRecoverableVtxo
|
|
3822
|
-
);
|
|
3823
|
-
sweptCount++;
|
|
3824
|
-
continue;
|
|
3825
|
-
}
|
|
3826
|
-
if (isRecoverableVtxo) {
|
|
3827
|
-
logger.error(
|
|
3828
|
-
`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.`
|
|
3829
|
-
);
|
|
3830
|
-
skippedCount++;
|
|
3831
|
-
continue;
|
|
3832
|
-
}
|
|
3833
|
-
const input = {
|
|
3834
|
-
...vtxo,
|
|
3835
|
-
tapLeafScript: vhtlcScript.refund(),
|
|
3836
|
-
tapTree: vhtlcScript.encode()
|
|
3837
|
-
};
|
|
3838
|
-
try {
|
|
3839
|
-
if (boltzCallCount > 0) {
|
|
3840
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
3841
|
-
}
|
|
3842
|
-
boltzCallCount++;
|
|
3843
|
-
await refundVHTLCwithOffchainTx(
|
|
3844
|
-
pendingSwap.id,
|
|
3845
|
-
this.wallet.identity,
|
|
3846
|
-
this.arkProvider,
|
|
3847
|
-
boltzXOnlyPublicKey,
|
|
3848
|
-
ourXOnlyPublicKey,
|
|
3849
|
-
serverXOnlyPublicKey,
|
|
3850
|
-
input,
|
|
3851
|
-
output,
|
|
3852
|
-
arkInfo,
|
|
3853
|
-
this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
|
|
3854
|
-
);
|
|
3855
|
-
sweptCount++;
|
|
3856
|
-
} catch (error) {
|
|
3857
|
-
if (!(error instanceof BoltzRefundError)) {
|
|
3858
|
-
throw error;
|
|
3859
|
-
}
|
|
3860
|
-
if (!isSubmarineRefundLocktimeReached(vhtlcTimeouts.refund)) {
|
|
3861
|
-
logger.error(
|
|
3862
|
-
`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.`
|
|
3863
|
-
);
|
|
3864
|
-
skippedCount++;
|
|
3865
|
-
continue;
|
|
3866
|
-
}
|
|
3867
|
-
logger.warn(
|
|
3868
|
-
`Swap ${pendingSwap.id}: Boltz rejected VTXO outpoint, falling back to refundWithoutReceiver via joinBatch`
|
|
3869
|
-
);
|
|
3870
|
-
const fallbackInput = {
|
|
3871
|
-
...vtxo,
|
|
3872
|
-
tapLeafScript: refundWithoutReceiverLeaf,
|
|
3873
|
-
tapTree: vhtlcScript.encode()
|
|
3874
|
-
};
|
|
3875
|
-
await this.joinBatch(this.wallet.identity, fallbackInput, output, arkInfo, false);
|
|
3876
|
-
sweptCount++;
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3846
|
+
const refundContext = {
|
|
3847
|
+
arkInfo,
|
|
3848
|
+
vhtlcScript,
|
|
3849
|
+
serverXOnlyPublicKey,
|
|
3850
|
+
refundWithoutReceiverLeaf,
|
|
3851
|
+
outputScript
|
|
3852
|
+
};
|
|
3853
|
+
const { swept: sweptCount, skipped: skippedCount } = await this.refundVtxos({
|
|
3854
|
+
swapId: pendingSwap.id,
|
|
3855
|
+
vtxos: refundableVtxos,
|
|
3856
|
+
refundLocktime: vhtlcTimeouts.refund,
|
|
3857
|
+
refundContext,
|
|
3858
|
+
boltzXOnlyPublicKey,
|
|
3859
|
+
ourXOnlyPublicKey,
|
|
3860
|
+
refundViaBoltz: this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
|
|
3861
|
+
});
|
|
3879
3862
|
if (!isSubmarineSuccessStatus(pendingSwap.status)) {
|
|
3880
3863
|
const fullyRefunded = skippedCount === 0;
|
|
3881
3864
|
await updateSubmarineSwapStatus(
|
|
@@ -4433,7 +4416,10 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
4433
4416
|
* swap's ARK lockup address.
|
|
4434
4417
|
*
|
|
4435
4418
|
* Path selection per VTXO:
|
|
4436
|
-
* - CLTV
|
|
4419
|
+
* - CLTV elapsed, live VTXO → `refundWithoutReceiver` offchain (sender +
|
|
4420
|
+
* server, no Boltz, no batch round).
|
|
4421
|
+
* - CLTV elapsed, swept VTXO → `refundWithoutReceiver` via `joinBatch`
|
|
4422
|
+
* (a swept VTXO is no longer a live leaf).
|
|
4437
4423
|
* - Pre-CLTV recoverable → skipped (Boltz can't co-sign swept-batch refund).
|
|
4438
4424
|
* - Pre-CLTV non-recoverable → cooperative 3-of-3 refund via Boltz.
|
|
4439
4425
|
*
|
|
@@ -4490,84 +4476,22 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
4490
4476
|
const outputScript = import_sdk8.ArkAddress.decode(address).pkScript;
|
|
4491
4477
|
const refundWithoutReceiverLeaf = vhtlcScript.refundWithoutReceiver();
|
|
4492
4478
|
const refundLocktime = pendingSwap.response.lockupDetails.timeouts.refund;
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
this.wallet.identity,
|
|
4510
|
-
input2,
|
|
4511
|
-
output,
|
|
4512
|
-
arkInfo,
|
|
4513
|
-
isRecoverableVtxo
|
|
4514
|
-
);
|
|
4515
|
-
sweptCount++;
|
|
4516
|
-
continue;
|
|
4517
|
-
}
|
|
4518
|
-
if (isRecoverableVtxo) {
|
|
4519
|
-
logger.error(
|
|
4520
|
-
`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.`
|
|
4521
|
-
);
|
|
4522
|
-
skippedCount++;
|
|
4523
|
-
continue;
|
|
4524
|
-
}
|
|
4525
|
-
const input = {
|
|
4526
|
-
...vtxo,
|
|
4527
|
-
tapLeafScript: vhtlcScript.refund(),
|
|
4528
|
-
tapTree: vhtlcScript.encode()
|
|
4529
|
-
};
|
|
4530
|
-
try {
|
|
4531
|
-
if (boltzCallCount > 0) {
|
|
4532
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
4533
|
-
}
|
|
4534
|
-
boltzCallCount++;
|
|
4535
|
-
await refundVHTLCwithOffchainTx(
|
|
4536
|
-
pendingSwap.id,
|
|
4537
|
-
this.wallet.identity,
|
|
4538
|
-
this.arkProvider,
|
|
4539
|
-
boltzXOnlyPublicKey,
|
|
4540
|
-
ourXOnlyPublicKey,
|
|
4541
|
-
serverXOnlyPublicKey,
|
|
4542
|
-
input,
|
|
4543
|
-
output,
|
|
4544
|
-
arkInfo,
|
|
4545
|
-
this.swapProvider.refundChainSwap.bind(this.swapProvider)
|
|
4546
|
-
);
|
|
4547
|
-
sweptCount++;
|
|
4548
|
-
} catch (error) {
|
|
4549
|
-
if (!(error instanceof BoltzRefundError)) {
|
|
4550
|
-
throw error;
|
|
4551
|
-
}
|
|
4552
|
-
if (!isSubmarineRefundLocktimeReached(refundLocktime)) {
|
|
4553
|
-
logger.error(
|
|
4554
|
-
`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.`
|
|
4555
|
-
);
|
|
4556
|
-
skippedCount++;
|
|
4557
|
-
continue;
|
|
4558
|
-
}
|
|
4559
|
-
logger.warn(
|
|
4560
|
-
`Swap ${pendingSwap.id}: Boltz rejected VTXO outpoint, falling back to refundWithoutReceiver via joinBatch`
|
|
4561
|
-
);
|
|
4562
|
-
const fallbackInput = {
|
|
4563
|
-
...vtxo,
|
|
4564
|
-
tapLeafScript: refundWithoutReceiverLeaf,
|
|
4565
|
-
tapTree: vhtlcScript.encode()
|
|
4566
|
-
};
|
|
4567
|
-
await this.joinBatch(this.wallet.identity, fallbackInput, output, arkInfo, false);
|
|
4568
|
-
sweptCount++;
|
|
4569
|
-
}
|
|
4570
|
-
}
|
|
4479
|
+
const refundContext = {
|
|
4480
|
+
arkInfo,
|
|
4481
|
+
vhtlcScript,
|
|
4482
|
+
serverXOnlyPublicKey,
|
|
4483
|
+
refundWithoutReceiverLeaf,
|
|
4484
|
+
outputScript
|
|
4485
|
+
};
|
|
4486
|
+
const { swept: sweptCount, skipped: skippedCount } = await this.refundVtxos({
|
|
4487
|
+
swapId: pendingSwap.id,
|
|
4488
|
+
vtxos: unspentVtxos,
|
|
4489
|
+
refundLocktime,
|
|
4490
|
+
refundContext,
|
|
4491
|
+
boltzXOnlyPublicKey,
|
|
4492
|
+
ourXOnlyPublicKey,
|
|
4493
|
+
refundViaBoltz: this.swapProvider.refundChainSwap.bind(this.swapProvider)
|
|
4494
|
+
});
|
|
4571
4495
|
const finalStatus = await this.getSwapStatus(pendingSwap.id);
|
|
4572
4496
|
await this.savePendingChainSwap({
|
|
4573
4497
|
...pendingSwap,
|
|
@@ -5100,6 +5024,120 @@ var ArkadeSwaps = class _ArkadeSwaps {
|
|
|
5100
5024
|
async joinBatch(identity, input, output, arkInfo, isRecoverable2 = true) {
|
|
5101
5025
|
return joinBatch(this.arkProvider, identity, input, output, arkInfo, isRecoverable2);
|
|
5102
5026
|
}
|
|
5027
|
+
/**
|
|
5028
|
+
* Settle a `refundWithoutReceiver` (sender + server, no Boltz) refund for a
|
|
5029
|
+
* single VTXO whose CLTV refund locktime has elapsed.
|
|
5030
|
+
*
|
|
5031
|
+
* A live VTXO settles the leaf with an offchain Ark tx — no batch round. A
|
|
5032
|
+
* swept (recoverable) VTXO is no longer a live leaf, so it can only be
|
|
5033
|
+
* reclaimed by re-registering it into a batch.
|
|
5034
|
+
*/
|
|
5035
|
+
async settleRefundWithoutReceiver(ctx, vtxo) {
|
|
5036
|
+
const input = {
|
|
5037
|
+
...vtxo,
|
|
5038
|
+
tapLeafScript: ctx.refundWithoutReceiverLeaf,
|
|
5039
|
+
tapTree: ctx.vhtlcScript.encode()
|
|
5040
|
+
};
|
|
5041
|
+
const output = { amount: BigInt(vtxo.value), script: ctx.outputScript };
|
|
5042
|
+
if ((0, import_sdk8.isRecoverable)(vtxo)) {
|
|
5043
|
+
await this.joinBatch(this.wallet.identity, input, output, ctx.arkInfo, true);
|
|
5044
|
+
} else {
|
|
5045
|
+
await refundWithoutReceiverVHTLCwithOffchainTx(
|
|
5046
|
+
this.wallet.identity,
|
|
5047
|
+
ctx.vhtlcScript,
|
|
5048
|
+
ctx.serverXOnlyPublicKey,
|
|
5049
|
+
input,
|
|
5050
|
+
output,
|
|
5051
|
+
ctx.arkInfo,
|
|
5052
|
+
this.arkProvider
|
|
5053
|
+
);
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
/**
|
|
5057
|
+
* Refund every VTXO at a swap's VHTLC address back to the wallet, shared by
|
|
5058
|
+
* {@link ArkadeSwaps.refundVHTLC} (submarine) and {@link ArkadeSwaps.refundArk}
|
|
5059
|
+
* (chain). Path selection per VTXO:
|
|
5060
|
+
* - CLTV elapsed → `refundWithoutReceiver` (offchain for a live VTXO, via a
|
|
5061
|
+
* batch round for a swept one — see {@link settleRefundWithoutReceiver}).
|
|
5062
|
+
* - Pre-CLTV recoverable → skipped (Boltz can't co-sign a swept-batch refund).
|
|
5063
|
+
* - Pre-CLTV non-recoverable → cooperative 3-of-3 refund via Boltz, falling
|
|
5064
|
+
* back to `refundWithoutReceiver` offchain if Boltz rejects after the
|
|
5065
|
+
* locktime has since elapsed.
|
|
5066
|
+
*
|
|
5067
|
+
* @returns Counts of VTXOs swept vs. deferred.
|
|
5068
|
+
*/
|
|
5069
|
+
async refundVtxos(params) {
|
|
5070
|
+
const {
|
|
5071
|
+
swapId,
|
|
5072
|
+
vtxos,
|
|
5073
|
+
refundLocktime,
|
|
5074
|
+
refundContext,
|
|
5075
|
+
boltzXOnlyPublicKey,
|
|
5076
|
+
ourXOnlyPublicKey,
|
|
5077
|
+
refundViaBoltz
|
|
5078
|
+
} = params;
|
|
5079
|
+
const { vhtlcScript, serverXOnlyPublicKey, arkInfo, outputScript } = refundContext;
|
|
5080
|
+
let boltzCallCount = 0;
|
|
5081
|
+
let sweptCount = 0;
|
|
5082
|
+
let skippedCount = 0;
|
|
5083
|
+
for (const vtxo of vtxos) {
|
|
5084
|
+
const isRecoverableVtxo = (0, import_sdk8.isRecoverable)(vtxo);
|
|
5085
|
+
const output = { amount: BigInt(vtxo.value), script: outputScript };
|
|
5086
|
+
if (isSubmarineRefundLocktimeReached(refundLocktime)) {
|
|
5087
|
+
await this.settleRefundWithoutReceiver(refundContext, vtxo);
|
|
5088
|
+
sweptCount++;
|
|
5089
|
+
continue;
|
|
5090
|
+
}
|
|
5091
|
+
if (isRecoverableVtxo) {
|
|
5092
|
+
logger.error(
|
|
5093
|
+
`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.`
|
|
5094
|
+
);
|
|
5095
|
+
skippedCount++;
|
|
5096
|
+
continue;
|
|
5097
|
+
}
|
|
5098
|
+
const input = {
|
|
5099
|
+
...vtxo,
|
|
5100
|
+
tapLeafScript: vhtlcScript.refund(),
|
|
5101
|
+
tapTree: vhtlcScript.encode()
|
|
5102
|
+
};
|
|
5103
|
+
try {
|
|
5104
|
+
if (boltzCallCount > 0) {
|
|
5105
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
5106
|
+
}
|
|
5107
|
+
boltzCallCount++;
|
|
5108
|
+
await refundVHTLCwithOffchainTx(
|
|
5109
|
+
swapId,
|
|
5110
|
+
this.wallet.identity,
|
|
5111
|
+
this.arkProvider,
|
|
5112
|
+
boltzXOnlyPublicKey,
|
|
5113
|
+
ourXOnlyPublicKey,
|
|
5114
|
+
serverXOnlyPublicKey,
|
|
5115
|
+
input,
|
|
5116
|
+
output,
|
|
5117
|
+
arkInfo,
|
|
5118
|
+
refundViaBoltz
|
|
5119
|
+
);
|
|
5120
|
+
sweptCount++;
|
|
5121
|
+
} catch (error) {
|
|
5122
|
+
if (!(error instanceof BoltzRefundError)) {
|
|
5123
|
+
throw error;
|
|
5124
|
+
}
|
|
5125
|
+
if (!isSubmarineRefundLocktimeReached(refundLocktime)) {
|
|
5126
|
+
logger.error(
|
|
5127
|
+
`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.`
|
|
5128
|
+
);
|
|
5129
|
+
skippedCount++;
|
|
5130
|
+
continue;
|
|
5131
|
+
}
|
|
5132
|
+
logger.warn(
|
|
5133
|
+
`Swap ${swapId}: Boltz rejected VTXO outpoint, falling back to refundWithoutReceiver offchain`
|
|
5134
|
+
);
|
|
5135
|
+
await this.settleRefundWithoutReceiver(refundContext, vtxo);
|
|
5136
|
+
sweptCount++;
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
return { swept: sweptCount, skipped: skippedCount };
|
|
5140
|
+
}
|
|
5103
5141
|
/**
|
|
5104
5142
|
* Creates a VHTLC script for the swap.
|
|
5105
5143
|
* Works for submarine, reverse, and chain swaps.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { D as DefineSwapBackgroundTaskOptions } from '../swapsPollProcessor-
|
|
2
|
-
export { P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies, s as swapsPollProcessor } from '../swapsPollProcessor-
|
|
1
|
+
import { D as DefineSwapBackgroundTaskOptions } from '../swapsPollProcessor-B98F6MQF.cjs';
|
|
2
|
+
export { P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies, s as swapsPollProcessor } from '../swapsPollProcessor-B98F6MQF.cjs';
|
|
3
3
|
import '@arkade-os/sdk/worker/expo';
|
|
4
4
|
import '@arkade-os/sdk';
|
|
5
|
-
import '../types-
|
|
5
|
+
import '../types-CS62-oEy.cjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Define the Expo background task handler for swap polling.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { D as DefineSwapBackgroundTaskOptions } from '../swapsPollProcessor-
|
|
2
|
-
export { P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies, s as swapsPollProcessor } from '../swapsPollProcessor-
|
|
1
|
+
import { D as DefineSwapBackgroundTaskOptions } from '../swapsPollProcessor-Ov-wp17v.js';
|
|
2
|
+
export { P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies, s as swapsPollProcessor } from '../swapsPollProcessor-Ov-wp17v.js';
|
|
3
3
|
import '@arkade-os/sdk/worker/expo';
|
|
4
4
|
import '@arkade-os/sdk';
|
|
5
|
-
import '../types-
|
|
5
|
+
import '../types-CS62-oEy.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Define the Expo background task handler for swap polling.
|
package/dist/expo/background.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SWAP_POLL_TASK_TYPE,
|
|
3
3
|
swapsPollProcessor
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-WPAI2ECT.js";
|
|
5
5
|
import {
|
|
6
6
|
BoltzSwapProvider
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-5GBBRBFS.js";
|
|
8
8
|
import "../chunk-SJQJQO7P.js";
|
|
9
9
|
|
|
10
10
|
// src/expo/background.ts
|