@arkade-os/swap 0.0.11 → 0.0.12
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/{chunk-RIC5ZTZK.js → chunk-XXWOODUE.js} +46 -1
- package/dist/index.cjs +391 -40
- package/dist/index.d.cts +115 -6
- package/dist/index.d.ts +115 -6
- package/dist/index.js +322 -21
- package/dist/nostr.d.cts +1 -1
- package/dist/nostr.d.ts +1 -1
- package/dist/nostr.js +1 -1
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/{repository-CfE18Fif.d.ts → repository-DaK1RzRq.d.cts} +4 -1
- package/dist/{repository-B02vsgcV.d.cts → repository-DlLvj_y6.d.ts} +4 -1
- package/dist/{rfq-DkckzRKK.d.ts → rfq-DzsmhXX3.d.cts} +31 -4
- package/dist/{rfq-DkckzRKK.d.cts → rfq-DzsmhXX3.d.ts} +31 -4
- package/package.json +2 -2
|
@@ -17,6 +17,7 @@ var L1_NETWORKS = {
|
|
|
17
17
|
testnet: btc.TEST_NETWORK,
|
|
18
18
|
regtest: { ...btc.TEST_NETWORK, bech32: "bcrt" }
|
|
19
19
|
};
|
|
20
|
+
var l1ScriptForAddress = (address, network) => btc.OutScript.encode(btc.Address(L1_NETWORKS[network]).decode(address));
|
|
20
21
|
function onchainHtlcScript(params, network) {
|
|
21
22
|
if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
|
|
22
23
|
throw new Error("claimKey and refundKey must be 32-byte x-only keys");
|
|
@@ -199,7 +200,11 @@ async function classifyOnchainHtlc(chain, input) {
|
|
|
199
200
|
const best = utxos.sort((a, b) => b.amount > a.amount ? 1 : -1)[0];
|
|
200
201
|
if (!best) {
|
|
201
202
|
if (!input.funding) return { phase: "unfunded" };
|
|
202
|
-
const spend = await chain.getSpendingTx(
|
|
203
|
+
const spend = await chain.getSpendingTx(
|
|
204
|
+
input.funding.txid,
|
|
205
|
+
input.funding.vout,
|
|
206
|
+
input.htlc.pkScript
|
|
207
|
+
);
|
|
203
208
|
if (!spend) return { phase: "unfunded" };
|
|
204
209
|
const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
|
|
205
210
|
const txid = btc.Transaction.fromRaw(hex.decode(spend.txHex), {
|
|
@@ -451,6 +456,43 @@ var assertFundable = (input) => {
|
|
|
451
456
|
if (input.quote.refund_locktime !== void 0 && input.quote.refund_locktime - input.now < MIN_HEADROOM_SECONDS) {
|
|
452
457
|
fail("insufficient_headroom", "refund deadline headroom below 90 minutes");
|
|
453
458
|
}
|
|
459
|
+
if (input.maxFee) {
|
|
460
|
+
const { bps, sats, referenceRate } = input.maxFee;
|
|
461
|
+
if (bps === void 0 && sats === void 0) {
|
|
462
|
+
fail("max_fee_unbounded", "maxFee names neither bps nor sats");
|
|
463
|
+
}
|
|
464
|
+
if (bps !== void 0 && (!Number.isInteger(bps) || bps < 0 || bps > 1e4)) {
|
|
465
|
+
fail("max_fee_out_of_range", `maxFee.bps must be an integer in 0..10000, got ${bps}`);
|
|
466
|
+
}
|
|
467
|
+
if (sats !== void 0 && (!Number.isInteger(sats) || sats < 0)) {
|
|
468
|
+
fail("max_fee_out_of_range", `maxFee.sats must be a non-negative integer, got ${sats}`);
|
|
469
|
+
}
|
|
470
|
+
const legs = input.quote.pair.split("->");
|
|
471
|
+
const assetOf = (leg) => leg.slice(leg.indexOf(":") + 1);
|
|
472
|
+
const sameAsset = legs.length === 2 && assetOf(legs[0]) === assetOf(legs[1]);
|
|
473
|
+
if (!sameAsset && referenceRate === void 0) {
|
|
474
|
+
fail(
|
|
475
|
+
"fee_gate_unavailable",
|
|
476
|
+
`maxFee cannot gate ${input.quote.pair}: its legs name different assets, so from_amount - to_amount is not a fee. Supply maxFee.referenceRate (to-units per from-unit) from a source of your OWN \u2014 reading it off the solver's published feed would check the solver against its own number`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
if (!sameAsset && (!Number.isFinite(referenceRate) || referenceRate <= 0)) {
|
|
480
|
+
fail(
|
|
481
|
+
"max_fee_out_of_range",
|
|
482
|
+
`maxFee.referenceRate must be a positive finite number, got ${referenceRate}`
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
const fee = sameAsset ? input.quote.from_amount - input.quote.to_amount : Math.ceil(
|
|
486
|
+
(input.quote.from_amount * referenceRate - input.quote.to_amount) / referenceRate
|
|
487
|
+
);
|
|
488
|
+
const allowed = Math.max(
|
|
489
|
+
sats ?? 0,
|
|
490
|
+
Math.floor(input.quote.from_amount * (bps ?? 0) / 1e4)
|
|
491
|
+
);
|
|
492
|
+
if (fee > allowed) {
|
|
493
|
+
fail("fee_too_high", `fee ${fee} exceeds the ${allowed} this client allows`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
454
496
|
if (input.onchain) {
|
|
455
497
|
const { htlcLocktime, minConfirmations, direction } = input.onchain;
|
|
456
498
|
if (!Number.isInteger(minConfirmations) || minConfirmations < 1 || minConfirmations > MAX_MIN_CONFIRMATIONS) {
|
|
@@ -846,6 +888,7 @@ async function requestOnchainSend(wallet, arkServerUrl, transport, params) {
|
|
|
846
888
|
amountSide: params.amountSide
|
|
847
889
|
})
|
|
848
890
|
);
|
|
891
|
+
assertQuotedAmount(quote, params.amountSide, params.amount);
|
|
849
892
|
const network = getNetwork(info.network);
|
|
850
893
|
const derived = deriveOnchainSend({
|
|
851
894
|
quote,
|
|
@@ -1230,6 +1273,8 @@ export {
|
|
|
1230
1273
|
ONCHAIN_DUST_SATS,
|
|
1231
1274
|
newPreimage,
|
|
1232
1275
|
paymentHashOf,
|
|
1276
|
+
L1_NETWORKS,
|
|
1277
|
+
l1ScriptForAddress,
|
|
1233
1278
|
onchainHtlcScript,
|
|
1234
1279
|
buildHtlcClaim,
|
|
1235
1280
|
buildHtlcRefund,
|