@arkade-os/swap 0.1.0-rc.7 → 0.1.0-rc.8

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.
Files changed (36) hide show
  1. package/dist/advanced.cjs +122 -25
  2. package/dist/advanced.d.cts +7 -7
  3. package/dist/advanced.d.ts +7 -7
  4. package/dist/advanced.js +3 -3
  5. package/dist/{chunk-BQLGQ4WB.js → chunk-4PATNGYQ.js} +128 -16
  6. package/dist/{chunk-6HIU2LNP.js → chunk-ARYFNDJY.js} +78 -3
  7. package/dist/{chunk-O3XMAZXS.js → chunk-HV7EIUE2.js} +6 -11
  8. package/dist/{errors-BVT_j3eG.d.ts → errors-CSpOUdCN.d.ts} +6 -6
  9. package/dist/{errors-cn-FJT6r.d.cts → errors-DVn92LQd.d.cts} +6 -6
  10. package/dist/index.cjs +301 -33
  11. package/dist/index.d.cts +63 -7
  12. package/dist/index.d.ts +63 -7
  13. package/dist/index.js +132 -5
  14. package/dist/lockupContract-6TYZOBbn.d.ts +490 -0
  15. package/dist/lockupContract-aLCQQiSu.d.cts +490 -0
  16. package/dist/nostr.cjs +76 -3
  17. package/dist/nostr.d.cts +1 -1
  18. package/dist/nostr.d.ts +1 -1
  19. package/dist/nostr.js +1 -1
  20. package/dist/protocol.cjs +161 -22
  21. package/dist/protocol.d.cts +8 -388
  22. package/dist/protocol.d.ts +8 -388
  23. package/dist/protocol.js +4 -3
  24. package/dist/repositories/realm/index.d.cts +2 -2
  25. package/dist/repositories/realm/index.d.ts +2 -2
  26. package/dist/repositories/sqlite/index.d.cts +2 -2
  27. package/dist/repositories/sqlite/index.d.ts +2 -2
  28. package/dist/{repository-BIHMUO6i.d.cts → repository-D0gFF_GA.d.cts} +1 -1
  29. package/dist/{repository-OUoAxV1Z.d.ts → repository-tDT8p-Nx.d.ts} +1 -1
  30. package/dist/{rfq-RONK76D7.d.ts → rfq-DhkgiwQ7.d.cts} +20 -2
  31. package/dist/{rfq-RONK76D7.d.cts → rfq-DhkgiwQ7.d.ts} +20 -2
  32. package/dist/{watch-BUfoPEMC.d.cts → watch-C4cMEeZT.d.cts} +1 -1
  33. package/dist/{watch-Ci61IXyG.d.ts → watch-DbWXdpzm.d.ts} +1 -1
  34. package/package.json +2 -2
  35. package/dist/lockupContract-BvfhGH62.d.cts +0 -108
  36. package/dist/lockupContract-BvfhGH62.d.ts +0 -108
package/dist/advanced.cjs CHANGED
@@ -506,7 +506,7 @@ function deriveLightningReceive(input) {
506
506
  }
507
507
  };
508
508
  }
509
- var import_base7, import_legacy2, import_sdk5, import_sdk6, solverHex, ARKADE_BTC, LIGHTNING_BTC, ONCHAIN_BTC, rfqPair, LIGHTNING_SEND_PAIR, LIGHTNING_RECEIVE_PAIR, ONCHAIN_SEND_PAIR, ONCHAIN_RECEIVE_PAIR, SwapRefusal, AddressMismatch, newRfqId, lightningSendRequest, MIN_HEADROOM_SECONDS, gateError, assertFinite, MAX_PAIR_LENGTH, assertPairLength, verifyLockupAddress, LOCKUP_SHAPE_VARIANTS, matchQuotedLockup, assertFundable, expectQuote, pairOf, SEQUENCE_GRANULARITY_SECONDS, SOLO_REFUND_HEADROOM_SECONDS, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, l1NetworkFromArk, onchainSendRequest, lightningReceiveRequest, MIN_CLAIM_WINDOW_SECONDS, assertReceivable;
509
+ var import_base7, import_legacy2, import_sdk5, import_sdk6, solverHex, ARKADE_BTC, LIGHTNING_BTC, ONCHAIN_BTC, rfqPair, LIGHTNING_SEND_PAIR, LIGHTNING_RECEIVE_PAIR, ONCHAIN_SEND_PAIR, ONCHAIN_RECEIVE_PAIR, RFQ_REFUSAL_ERROR_CODES, isRfqRefusalErrorCode, REFUSAL_FIELDS, REFUSAL_UNITS, safeInteger, safeRefusalDetail, refusalMessage, SwapRefusal, AddressMismatch, newRfqId, lightningSendRequest, MIN_HEADROOM_SECONDS, gateError, assertFinite, MAX_PAIR_LENGTH, assertPairLength, verifyLockupAddress, LOCKUP_SHAPE_VARIANTS, matchQuotedLockup, assertFundable, expectQuote, pairOf, SEQUENCE_GRANULARITY_SECONDS, SOLO_REFUND_HEADROOM_SECONDS, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, l1NetworkFromArk, onchainSendRequest, lightningReceiveRequest, MIN_CLAIM_WINDOW_SECONDS, assertReceivable;
510
510
  var init_rfq = __esm({
511
511
  "src/rfq.ts"() {
512
512
  "use strict";
@@ -533,6 +533,57 @@ var init_rfq = __esm({
533
533
  LIGHTNING_RECEIVE_PAIR = rfqPair(LIGHTNING_BTC, ARKADE_BTC);
534
534
  ONCHAIN_SEND_PAIR = rfqPair(ARKADE_BTC, ONCHAIN_BTC);
535
535
  ONCHAIN_RECEIVE_PAIR = rfqPair(ONCHAIN_BTC, ARKADE_BTC);
536
+ RFQ_REFUSAL_ERROR_CODES = [
537
+ "amount_side_unsupported",
538
+ "exact_out_unsupported",
539
+ "invalid_amount",
540
+ "invalid_payout_address",
541
+ "invalid_refund_address",
542
+ "invoice_amount_mismatch",
543
+ "invoice_cltv_too_large",
544
+ "invoice_malformed",
545
+ "invoice_missing_amount",
546
+ "invoice_missing_network",
547
+ "invoice_missing_payment_hash",
548
+ "invoice_missing_timestamp",
549
+ "invoice_mixed_case",
550
+ "invoice_sub_satoshi_amount",
551
+ "invoice_too_long",
552
+ "invoice_wrong_network"
553
+ ];
554
+ isRfqRefusalErrorCode = (value) => typeof value === "string" && RFQ_REFUSAL_ERROR_CODES.includes(value);
555
+ REFUSAL_FIELDS = /* @__PURE__ */ new Set([
556
+ "amount",
557
+ "amount_side",
558
+ "profile.invoice",
559
+ "profile.payout_address",
560
+ "profile.refund_address"
561
+ ]);
562
+ REFUSAL_UNITS = /* @__PURE__ */ new Set(["blocks", "characters", "sats"]);
563
+ safeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
564
+ safeRefusalDetail = (detail) => {
565
+ if (!isRfqRefusalErrorCode(detail.errorCode)) return {};
566
+ return {
567
+ errorCode: detail.errorCode,
568
+ field: typeof detail.field === "string" && REFUSAL_FIELDS.has(detail.field) ? detail.field : void 0,
569
+ actual: safeInteger(detail.actual),
570
+ expected: safeInteger(detail.expected),
571
+ limit: safeInteger(detail.limit),
572
+ unit: typeof detail.unit === "string" && REFUSAL_UNITS.has(detail.unit) ? detail.unit : void 0
573
+ };
574
+ };
575
+ refusalMessage = (reason, detail) => {
576
+ if (!detail.errorCode) return `solver refused: ${reason}`;
577
+ const where = detail.field ? ` at ${detail.field}` : "";
578
+ const unit = detail.unit ? ` ${detail.unit}` : "";
579
+ if (detail.actual !== void 0 && detail.limit !== void 0) {
580
+ return `solver refused: ${reason} (${detail.errorCode}${where}: ${detail.actual}${unit}, limit ${detail.limit})`;
581
+ }
582
+ if (detail.actual !== void 0 && detail.expected !== void 0) {
583
+ return `solver refused: ${reason} (${detail.errorCode}${where}: ${detail.actual}${unit}, expected ${detail.expected})`;
584
+ }
585
+ return `solver refused: ${reason} (${detail.errorCode}${where})`;
586
+ };
536
587
  SwapRefusal = class extends Error {
537
588
  /** Literal-typed so the v2 error taxonomy's union discriminates on `name`
538
589
  * — a `string` here collapses the discriminant for every member. Same value
@@ -540,10 +591,23 @@ var init_rfq = __esm({
540
591
  name = "SwapRefusal";
541
592
  reason;
542
593
  rfqId;
543
- constructor(reason, rfqId) {
544
- super(`solver refused: ${reason}`);
594
+ errorCode;
595
+ field;
596
+ actual;
597
+ expected;
598
+ limit;
599
+ unit;
600
+ constructor(reason, rfqId, detail = {}) {
601
+ const safeDetail = safeRefusalDetail(detail);
602
+ super(refusalMessage(reason, safeDetail));
545
603
  this.reason = reason;
546
604
  this.rfqId = rfqId;
605
+ this.errorCode = safeDetail.errorCode;
606
+ this.field = safeDetail.field;
607
+ this.actual = safeDetail.actual;
608
+ this.expected = safeDetail.expected;
609
+ this.limit = safeDetail.limit;
610
+ this.unit = safeDetail.unit;
547
611
  }
548
612
  };
549
613
  AddressMismatch = class extends Error {
@@ -684,7 +748,16 @@ var init_rfq = __esm({
684
748
  };
685
749
  expectQuote = (payload, rfqId, requestedPair) => {
686
750
  const p = payload;
687
- if (p?.type === "rfq_refusal") throw new SwapRefusal(p.reason ?? "unknown", p.rfq_id ?? rfqId);
751
+ if (p?.type === "rfq_refusal") {
752
+ throw new SwapRefusal(p.reason ?? "unknown", p.rfq_id ?? rfqId, {
753
+ errorCode: p.error_code,
754
+ field: p.field,
755
+ actual: p.actual,
756
+ expected: p.expected,
757
+ limit: p.limit,
758
+ unit: p.unit
759
+ });
760
+ }
688
761
  if (p?.type !== "rfq_quote" || p.rfq_id !== rfqId) {
689
762
  throw new Error(`unexpected reply: ${p?.type ?? "no payload"}`);
690
763
  }
@@ -1176,10 +1249,10 @@ function addressOutstanding(swaps, script) {
1176
1249
  }
1177
1250
  return true;
1178
1251
  }
1179
- async function promoteOfferContract(manager, script) {
1252
+ async function promoteOfferContract(manager, script, issued = Date.now()) {
1180
1253
  await serialize(script, async () => {
1181
1254
  await manager.setContractWatchState(script, "watched");
1182
- issuedAt.set(script, Date.now());
1255
+ issuedAt.set(script, issued);
1183
1256
  });
1184
1257
  }
1185
1258
  async function retireOfferContract(manager, swaps, script) {
@@ -1512,7 +1585,6 @@ function decodeExitDelay(value) {
1512
1585
  var OFFER_CONTRACT_LABEL = "Arkade swap offer";
1513
1586
  var OFFER_CONTRACT_KIND = "asset-swap-offer";
1514
1587
  async function registerOfferContract(wallet, info, binding, operatorPubkey, expectedPkScript) {
1515
- const { program, args, keys } = swapProgramBinding(binding, operatorPubkey);
1516
1588
  const contractManager = await wallet.getContractManager();
1517
1589
  const client = await import_sdk2.arkade.Arkade.connect({
1518
1590
  // Registration derives and persists; it never broadcasts and never
@@ -1528,15 +1600,22 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
1528
1600
  network: (0, import_sdk2.networkFromArkadeInfo)(info),
1529
1601
  contractManager
1530
1602
  });
1603
+ await contractManager.createContract(
1604
+ offerContractParams(client, binding, operatorPubkey, expectedPkScript)
1605
+ );
1606
+ await promoteOfferContract(contractManager, import_base2.hex.encode(expectedPkScript));
1607
+ }
1608
+ function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
1609
+ const { program, args, keys } = swapProgramBinding(binding, operatorPubkey);
1531
1610
  const contract = new import_sdk2.arkade.ArkadeContract(client, program, args, keys);
1532
1611
  if (import_base2.hex.encode(contract.pkScript) !== import_base2.hex.encode(expectedPkScript)) {
1533
1612
  throw new Error("derived covenant does not match the offer's swapPkScript");
1534
1613
  }
1535
- await contract.register({
1614
+ return {
1615
+ ...contract.toContractParams(),
1536
1616
  label: OFFER_CONTRACT_LABEL,
1537
1617
  metadata: { genericallySpendable: false, kind: OFFER_CONTRACT_KIND }
1538
- });
1539
- await promoteOfferContract(contractManager, import_base2.hex.encode(expectedPkScript));
1618
+ };
1540
1619
  }
1541
1620
  function serverExitDelay(delay) {
1542
1621
  if (typeof delay !== "bigint" || delay <= BigInt(0)) {
@@ -3788,16 +3867,33 @@ function classifyDepositSpend(offer, operatorPubkey, spendTxs, deposit) {
3788
3867
  return "indeterminate";
3789
3868
  }
3790
3869
  async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
3791
- const { operatorPubkey, scanned = /* @__PURE__ */ new Set() } = opts;
3792
- const candidates = unscannedSwapCandidates(txs, existingIds, scanned);
3793
- if (candidates.length === 0) return { restored: [], scannedTxids: [] };
3870
+ const { operatorPubkey, scanned = /* @__PURE__ */ new Set(), reopen = [] } = opts;
3871
+ const reopened = [];
3872
+ for (const swap of reopen) {
3873
+ try {
3874
+ reopened.push({
3875
+ fundingTx: { type: "sent", redeemTxid: swap.fundingTxid },
3876
+ offer: decodeOffer(import_base11.hex.decode(swap.offerHex)),
3877
+ offerHex: swap.offerHex,
3878
+ existing: swap
3879
+ });
3880
+ } catch {
3881
+ }
3882
+ }
3883
+ const reopenedTxids = new Set(reopened.map(({ fundingTx }) => fundingTx.redeemTxid));
3884
+ const candidates = unscannedSwapCandidates(txs, existingIds, scanned).filter(
3885
+ ({ redeemTxid }) => !reopenedTxids.has(redeemTxid)
3886
+ );
3887
+ if (candidates.length === 0 && reopened.length === 0) {
3888
+ return { restored: [], scannedTxids: [] };
3889
+ }
3794
3890
  const byTxid = new Map(candidates.map((tx) => [tx.redeemTxid, tx]));
3795
3891
  const parsedByTxid = await fetchParsedTxs(
3796
3892
  indexer,
3797
3893
  candidates.map((tx) => tx.redeemTxid)
3798
3894
  );
3799
3895
  const fetchedTxids = [];
3800
- const found = [];
3896
+ const found = [...reopened];
3801
3897
  for (const [txid, parsed] of parsedByTxid) {
3802
3898
  const fundingTx = byTxid.get(txid);
3803
3899
  if (!fundingTx) continue;
@@ -3835,7 +3931,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
3835
3931
  const spendTxByTxid = await fetchParsedTxs(indexer, [...spendTxids]);
3836
3932
  const restored = [];
3837
3933
  const unresolved = /* @__PURE__ */ new Set();
3838
- for (const { fundingTx, offer, offerHex } of found) {
3934
+ for (const { fundingTx, offer, offerHex, existing } of found) {
3839
3935
  const swapPkScript = import_base11.hex.encode(offer.swapPkScript);
3840
3936
  const vtxo = vtxoByScriptAndTxid.get(`${swapPkScript}:${fundingTx.redeemTxid}`);
3841
3937
  if (!vtxo) {
@@ -3866,6 +3962,12 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
3866
3962
  }
3867
3963
  status = kind;
3868
3964
  }
3965
+ const completion = status === "fulfilled" && spentTxid && txByAnyId.get(spentTxid)?.createdAt ? { completedAt: txByAnyId.get(spentTxid).createdAt * 1e3 } : {};
3966
+ if (existing) {
3967
+ if (status === "pending") continue;
3968
+ restored.push({ ...existing, status, spentTxid, ...completion });
3969
+ continue;
3970
+ }
3869
3971
  restored.push({
3870
3972
  id: fundingTx.redeemTxid,
3871
3973
  fromAsset,
@@ -3885,7 +3987,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
3885
3987
  createdAt: fundingTx.createdAt ? fundingTx.createdAt * 1e3 : vtxo.createdAt.getTime(),
3886
3988
  // the completion time is the caller's record of the spend, if it
3887
3989
  // has one — the psbt that classified it carries no timestamp
3888
- ...status === "fulfilled" && spentTxid && txByAnyId.get(spentTxid)?.createdAt ? { completedAt: txByAnyId.get(spentTxid).createdAt * 1e3 } : {}
3990
+ ...completion
3889
3991
  });
3890
3992
  }
3891
3993
  return { restored, scannedTxids: fetchedTxids.filter((id) => !unresolved.has(id)) };
@@ -6604,7 +6706,6 @@ var verifyPlanLegs = (plan, legs, give) => {
6604
6706
 
6605
6707
  // src/client/quoteRfq.ts
6606
6708
  var import_base18 = require("@scure/base");
6607
- var import_secp256k12 = require("@noble/curves/secp256k1.js");
6608
6709
  var import_sdk26 = require("@arkade-os/sdk");
6609
6710
  init_claimPacket();
6610
6711
  init_onchainHtlc();
@@ -6680,9 +6781,7 @@ var covenantInputs = (input) => {
6680
6781
  };
6681
6782
  var sealingKey = (deps) => {
6682
6783
  const configured = deps.covclaimd?.pubkey;
6683
- if (configured === void 0) {
6684
- return import_secp256k12.secp256k1.getPublicKey(import_secp256k12.secp256k1.utils.randomSecretKey(), true);
6685
- }
6784
+ if (configured === void 0) return void 0;
6686
6785
  const key = import_base18.hex.decode(configured);
6687
6786
  if (key.length !== 33) {
6688
6787
  throw new Error(
@@ -6795,10 +6894,8 @@ var quoteLightningReceive = async (input) => {
6795
6894
  const paymentHash = import_base18.hex.encode(secrets.paymentHash);
6796
6895
  const payoutAddress = await input.wallet.getAddress();
6797
6896
  const lightning = input.corridors.get("lightning").deps;
6798
- const claimPacket = await sealClaimPacket({
6799
- preimage: secrets.preimage,
6800
- covclaimdPubkey: sealingKey(lightning)
6801
- });
6897
+ const sealTo = sealingKey(lightning);
6898
+ const claimPacket = sealTo ? await sealClaimPacket({ preimage: secrets.preimage, covclaimdPubkey: sealTo }) : void 0;
6802
6899
  const wire = await input.transport.requestQuote(
6803
6900
  withCanonicalAmount(
6804
6901
  lightningReceiveRequest({
@@ -6806,7 +6903,7 @@ var quoteLightningReceive = async (input) => {
6806
6903
  paymentHash,
6807
6904
  payoutAddress,
6808
6905
  payoutPubkey: secrets.pubkey,
6809
- claimPacket: claimPacket.ciphertext,
6906
+ claimPacket: claimPacket?.ciphertext,
6810
6907
  // Placeholder: the v1 builders type this field `number`, and the
6811
6908
  // wire adapter re-encodes it as the canonical decimal string.
6812
6909
  // Encoding it here as well would put the decision in two places.
@@ -1,13 +1,13 @@
1
- import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './errors-cn-FJT6r.cjs';
2
- export { e as AcceptConflict, f as AcceptInput, g as AmbiguousDestination, h as AmountEncodingUnsupported, i as AmountMismatch, j as AttestingRfqTransport, k as CORRIDOR_FACTORIES, l as CancelInput, m as CancelOutcome, n as ClaimedDestination, o as ClientDisposed, p as CorridorBase, q as CorridorClaim, r as CorridorCovenant, s as CorridorDeadline, t as CorridorDeps, u as CorridorDepsByCorridor, v as CorridorDrive, w as CorridorLockup, x as CorridorModule, y as CorridorOverrides, z as CorridorPass, B as DiscoveryConfig, E as DiscoveryIndexInput, F as DiscoverySnapshotUnavailable, G as DriveMode, H as DriveRefusal, I as ExchangeOptions, J as FEED_TTL_MS, K as FeeCeiling, N as FeedFetch, P as FeedQuoteInput, Q as INDEXED_NETWORKS, R as InconsistentRoute, T as InsufficientFunds, U as LockupOwner, V as Market, W as MaxFeeExceeded, X as MissingCorridorDep, Y as NotCancellable, Z as ONCHAIN_CLAIM_FEE_RATE_SATVB, _ as ObservationSeam, $ as OfferPreparation, a0 as OnchainClaim, a1 as OperatorUnreachable, a2 as ParsedRfqQuote, a3 as PayOptions, a4 as PayResult, a5 as QuoteCheck, a6 as QuoteExpired, a7 as QuotePreparation, a8 as QuoteVerificationFailed, a9 as REGISTRY_URL, aa as ReceiveArtifact, ab as ReceiveOptions, ac as ReceiveRequest, ad as RecoveryResult, ae as RegisteredAsset, af as RfqAuctionPolicy, ag as RfqPreparation, ah as RfqQuoteInput, ai as RfqRendezvous, aj as RfqTransportFactory, ak as RouteSide, al as SWAP_ERROR_NAMES, am as SwapClient, an as SwapClientConfig, ao as SwapDrive, ap as SwapDriveConfig, aq as SwapDriveRefusedError, ar as SwapError, as as SwapErrorName, at as SwapFilter, au as UnsupportedRoute, av as VerbDeps, aw as acceptQuote, ax as attesting, ay as cancelSwap, az as canonicalAssetId, aA as cardMarketOf, aB as chooseMarket, aC as conflictingFields, aD as corridorSet, aE as createSwapClient, aF as createSwapDrive, aG as discoveryIndex, aH as eligibleMarkets, aI as enforceFeeCeiling, aJ as exchange, aK as feedFetch, aL as isAddressable, aM as isCardMarket, aN as isIndexedNetwork, aO as isSwapError, aP as isUsableCard, aQ as liveArkadeInfo, aR as marketBackendOf, aS as marketKeyOf, aT as marketRefOf, aU as nostrTransportFactory, aV as parseRfqQuote, aW as pay, aX as quoteFromFeed, aY as quoteViaRfq, aZ as readableRecord, a_ as receive, a$ as resolveCorridorBase, b0 as resolveCorridorDeps, b1 as rfqLeg, b2 as rfqPairFor, b3 as swapRecordOf, b4 as toDiscoveryLeg, b5 as usableMarkets, b6 as withCanonicalAmount } from './errors-cn-FJT6r.cjs';
1
+ import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './errors-DVn92LQd.cjs';
2
+ export { e as AcceptConflict, f as AcceptInput, g as AmbiguousDestination, h as AmountEncodingUnsupported, i as AmountMismatch, j as AttestingRfqTransport, k as CORRIDOR_FACTORIES, l as CancelInput, m as CancelOutcome, n as ClaimedDestination, o as ClientDisposed, p as CorridorBase, q as CorridorClaim, r as CorridorCovenant, s as CorridorDeadline, t as CorridorDeps, u as CorridorDepsByCorridor, v as CorridorDrive, w as CorridorLockup, x as CorridorModule, y as CorridorOverrides, z as CorridorPass, B as DiscoveryConfig, E as DiscoveryIndexInput, F as DiscoverySnapshotUnavailable, G as DriveMode, H as DriveRefusal, I as ExchangeOptions, J as FEED_TTL_MS, K as FeeCeiling, N as FeedFetch, P as FeedQuoteInput, Q as INDEXED_NETWORKS, R as InconsistentRoute, T as InsufficientFunds, U as LockupOwner, V as Market, W as MaxFeeExceeded, X as MissingCorridorDep, Y as NotCancellable, Z as ONCHAIN_CLAIM_FEE_RATE_SATVB, _ as ObservationSeam, $ as OfferPreparation, a0 as OnchainClaim, a1 as OperatorUnreachable, a2 as ParsedRfqQuote, a3 as PayOptions, a4 as PayResult, a5 as QuoteCheck, a6 as QuoteExpired, a7 as QuotePreparation, a8 as QuoteVerificationFailed, a9 as REGISTRY_URL, aa as ReceiveArtifact, ab as ReceiveOptions, ac as ReceiveRequest, ad as RecoveryResult, ae as RegisteredAsset, af as RfqAuctionPolicy, ag as RfqPreparation, ah as RfqQuoteInput, ai as RfqRendezvous, aj as RfqTransportFactory, ak as RouteSide, al as SWAP_ERROR_NAMES, am as SwapClient, an as SwapClientConfig, ao as SwapDrive, ap as SwapDriveConfig, aq as SwapDriveRefusedError, ar as SwapError, as as SwapErrorName, at as SwapFilter, au as UnsupportedRoute, av as VerbDeps, aw as acceptQuote, ax as attesting, ay as cancelSwap, az as canonicalAssetId, aA as cardMarketOf, aB as chooseMarket, aC as conflictingFields, aD as corridorSet, aE as createSwapClient, aF as createSwapDrive, aG as discoveryIndex, aH as eligibleMarkets, aI as enforceFeeCeiling, aJ as exchange, aK as feedFetch, aL as isAddressable, aM as isCardMarket, aN as isIndexedNetwork, aO as isSwapError, aP as isUsableCard, aQ as liveArkadeInfo, aR as marketBackendOf, aS as marketKeyOf, aT as marketRefOf, aU as nostrTransportFactory, aV as parseRfqQuote, aW as pay, aX as quoteFromFeed, aY as quoteViaRfq, aZ as readableRecord, a_ as receive, a$ as resolveCorridorBase, b0 as resolveCorridorDeps, b1 as rfqLeg, b2 as rfqPairFor, b3 as swapRecordOf, b4 as toDiscoveryLeg, b5 as usableMarkets, b6 as withCanonicalAmount } from './errors-DVn92LQd.cjs';
3
3
  import { DiscoveredMarket } from '@arkade-os/solver-discovery';
4
- import { N as NetworkRef, C as Corridor, A as AssetId, R as Rail, a as RfqSwapRecordStore, b as CorridorSwapRecord, Q as QuoteId, S as SwapRecord, O as OfferSwapRecord, c as AssetSwapRepository, d as RfqSwapRecord, L as LockupSpendIndexer, e as AssetSwapStatus, f as RouteResolution, g as ResolvedEndpoint, P as PinnedAmount, I as Instrument, h as Route, i as QuoteInput, j as Pubkey } from './repository-BIHMUO6i.cjs';
5
- export { k as ACTIVITY_TOKEN, l as ARKADE_ASSET_NAMESPACE, m as Amount, n as AmountFormatError, o as AmountOn, p as AmountRefusal, q as Artifact, r as AssetIdError, s as AssetIdRefusal, t as AssetNamespace, u as AssetOn, v as AssetPart, w as AssetRef, x as AssetScale, y as AssetSwapId, z as AtomicDecimal, B as AuctionMarketRef, D as AuctionProvenance, E as BITCOIN_RAILS, F as BTC_ASSET_PART, G as BitcoinRail, H as CORRIDORS, J as CORRIDOR_PASS, K as CardMarketRef, M as CorridorId, T as CorridorKind, U as DepositArtifact, V as DisplayDecimal, W as Endpoint, X as Ep, Y as Hex, Z as LOCKUP_OWNER, _ as MarketBackend, $ as MarketRef, a0 as OFFER_SWAP_ID_PREFIX, a1 as Outcome, a2 as ParsedAssetId, a3 as Quote, a4 as QuoteLeg, a5 as RAILS, a6 as RFQ_SWAP_ID_PREFIX, a7 as RailOf, a8 as RankedBid, a9 as RawState, aa as RecordedArtifact, ab as RecordedEndpoint, ac as RecordedInstrument, ad as RecordedLeg, ae as RfqAmountSide, af as SnapshotRef, ag as Swap, ah as SwapFamily, ai as SwapRecordCommon, aj as SwapUpdate, ak as Unsubscribe, al as arkadeAsset, am as artifactOf, an as assetPartOf, ao as assetSwapIdOf, ap as bitcoinNetworkOf, aq as btcOn, ar as corridorOfRail, as as corridorOutcome, at as decodeRfqAmount, au as encodeRfqAmount, av as familyOfSwapId, aw as formatAssetId, ax as fromAtomicDecimal, ay as fromRfqAmountSide, az as fundsFromWallet, aA as instrumentOf, aB as isAssetId, aC as isAtomicDecimal, aD as isNetworkRef, aE as issuanceOf, aF as legOf, aG as offerOutcome, aH as parseAssetId, aI as quoteIdOfSwapId, aJ as railOf, aK as railOfCorridor, aL as readsChain, aM as recordArtifact, aN as recordEndpoint, aO as recordInstrument, aP as recordLeg, aQ as recordOutcome, aR as sameAsset, aS as swapOf, aT as toAtomicDecimal, aU as toRfqAmountSide, aV as toSafeNumber } from './repository-BIHMUO6i.cjs';
6
- import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-RONK76D7.cjs';
7
- export { S as SwapRefusal } from './rfq-RONK76D7.cjs';
4
+ import { N as NetworkRef, C as Corridor, A as AssetId, R as Rail, a as RfqSwapRecordStore, b as CorridorSwapRecord, Q as QuoteId, S as SwapRecord, O as OfferSwapRecord, c as AssetSwapRepository, d as RfqSwapRecord, L as LockupSpendIndexer, e as AssetSwapStatus, f as RouteResolution, g as ResolvedEndpoint, P as PinnedAmount, I as Instrument, h as Route, i as QuoteInput, j as Pubkey } from './repository-D0gFF_GA.cjs';
5
+ export { k as ACTIVITY_TOKEN, l as ARKADE_ASSET_NAMESPACE, m as Amount, n as AmountFormatError, o as AmountOn, p as AmountRefusal, q as Artifact, r as AssetIdError, s as AssetIdRefusal, t as AssetNamespace, u as AssetOn, v as AssetPart, w as AssetRef, x as AssetScale, y as AssetSwapId, z as AtomicDecimal, B as AuctionMarketRef, D as AuctionProvenance, E as BITCOIN_RAILS, F as BTC_ASSET_PART, G as BitcoinRail, H as CORRIDORS, J as CORRIDOR_PASS, K as CardMarketRef, M as CorridorId, T as CorridorKind, U as DepositArtifact, V as DisplayDecimal, W as Endpoint, X as Ep, Y as Hex, Z as LOCKUP_OWNER, _ as MarketBackend, $ as MarketRef, a0 as OFFER_SWAP_ID_PREFIX, a1 as Outcome, a2 as ParsedAssetId, a3 as Quote, a4 as QuoteLeg, a5 as RAILS, a6 as RFQ_SWAP_ID_PREFIX, a7 as RailOf, a8 as RankedBid, a9 as RawState, aa as RecordedArtifact, ab as RecordedEndpoint, ac as RecordedInstrument, ad as RecordedLeg, ae as RfqAmountSide, af as SnapshotRef, ag as Swap, ah as SwapFamily, ai as SwapRecordCommon, aj as SwapUpdate, ak as Unsubscribe, al as arkadeAsset, am as artifactOf, an as assetPartOf, ao as assetSwapIdOf, ap as bitcoinNetworkOf, aq as btcOn, ar as corridorOfRail, as as corridorOutcome, at as decodeRfqAmount, au as encodeRfqAmount, av as familyOfSwapId, aw as formatAssetId, ax as fromAtomicDecimal, ay as fromRfqAmountSide, az as fundsFromWallet, aA as instrumentOf, aB as isAssetId, aC as isAtomicDecimal, aD as isNetworkRef, aE as issuanceOf, aF as legOf, aG as offerOutcome, aH as parseAssetId, aI as quoteIdOfSwapId, aJ as railOf, aK as railOfCorridor, aL as readsChain, aM as recordArtifact, aN as recordEndpoint, aO as recordInstrument, aP as recordLeg, aQ as recordOutcome, aR as sameAsset, aS as swapOf, aT as toAtomicDecimal, aU as toRfqAmountSide, aV as toSafeNumber } from './repository-D0gFF_GA.cjs';
6
+ import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-DhkgiwQ7.cjs';
7
+ export { S as SwapRefusal } from './rfq-DhkgiwQ7.cjs';
8
8
  import * as btc from '@scure/btc-signer';
9
9
  import { OnchainProvider, NetworkName, IWallet, VHTLC } from '@arkade-os/sdk';
10
- import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-BUfoPEMC.cjs';
10
+ import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-C4cMEeZT.cjs';
11
11
 
12
12
  /**
13
13
  * The alias table, filled from discovery.
@@ -1,13 +1,13 @@
1
- import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './errors-BVT_j3eG.js';
2
- export { e as AcceptConflict, f as AcceptInput, g as AmbiguousDestination, h as AmountEncodingUnsupported, i as AmountMismatch, j as AttestingRfqTransport, k as CORRIDOR_FACTORIES, l as CancelInput, m as CancelOutcome, n as ClaimedDestination, o as ClientDisposed, p as CorridorBase, q as CorridorClaim, r as CorridorCovenant, s as CorridorDeadline, t as CorridorDeps, u as CorridorDepsByCorridor, v as CorridorDrive, w as CorridorLockup, x as CorridorModule, y as CorridorOverrides, z as CorridorPass, B as DiscoveryConfig, E as DiscoveryIndexInput, F as DiscoverySnapshotUnavailable, G as DriveMode, H as DriveRefusal, I as ExchangeOptions, J as FEED_TTL_MS, K as FeeCeiling, N as FeedFetch, P as FeedQuoteInput, Q as INDEXED_NETWORKS, R as InconsistentRoute, T as InsufficientFunds, U as LockupOwner, V as Market, W as MaxFeeExceeded, X as MissingCorridorDep, Y as NotCancellable, Z as ONCHAIN_CLAIM_FEE_RATE_SATVB, _ as ObservationSeam, $ as OfferPreparation, a0 as OnchainClaim, a1 as OperatorUnreachable, a2 as ParsedRfqQuote, a3 as PayOptions, a4 as PayResult, a5 as QuoteCheck, a6 as QuoteExpired, a7 as QuotePreparation, a8 as QuoteVerificationFailed, a9 as REGISTRY_URL, aa as ReceiveArtifact, ab as ReceiveOptions, ac as ReceiveRequest, ad as RecoveryResult, ae as RegisteredAsset, af as RfqAuctionPolicy, ag as RfqPreparation, ah as RfqQuoteInput, ai as RfqRendezvous, aj as RfqTransportFactory, ak as RouteSide, al as SWAP_ERROR_NAMES, am as SwapClient, an as SwapClientConfig, ao as SwapDrive, ap as SwapDriveConfig, aq as SwapDriveRefusedError, ar as SwapError, as as SwapErrorName, at as SwapFilter, au as UnsupportedRoute, av as VerbDeps, aw as acceptQuote, ax as attesting, ay as cancelSwap, az as canonicalAssetId, aA as cardMarketOf, aB as chooseMarket, aC as conflictingFields, aD as corridorSet, aE as createSwapClient, aF as createSwapDrive, aG as discoveryIndex, aH as eligibleMarkets, aI as enforceFeeCeiling, aJ as exchange, aK as feedFetch, aL as isAddressable, aM as isCardMarket, aN as isIndexedNetwork, aO as isSwapError, aP as isUsableCard, aQ as liveArkadeInfo, aR as marketBackendOf, aS as marketKeyOf, aT as marketRefOf, aU as nostrTransportFactory, aV as parseRfqQuote, aW as pay, aX as quoteFromFeed, aY as quoteViaRfq, aZ as readableRecord, a_ as receive, a$ as resolveCorridorBase, b0 as resolveCorridorDeps, b1 as rfqLeg, b2 as rfqPairFor, b3 as swapRecordOf, b4 as toDiscoveryLeg, b5 as usableMarkets, b6 as withCanonicalAmount } from './errors-BVT_j3eG.js';
1
+ import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './errors-CSpOUdCN.js';
2
+ export { e as AcceptConflict, f as AcceptInput, g as AmbiguousDestination, h as AmountEncodingUnsupported, i as AmountMismatch, j as AttestingRfqTransport, k as CORRIDOR_FACTORIES, l as CancelInput, m as CancelOutcome, n as ClaimedDestination, o as ClientDisposed, p as CorridorBase, q as CorridorClaim, r as CorridorCovenant, s as CorridorDeadline, t as CorridorDeps, u as CorridorDepsByCorridor, v as CorridorDrive, w as CorridorLockup, x as CorridorModule, y as CorridorOverrides, z as CorridorPass, B as DiscoveryConfig, E as DiscoveryIndexInput, F as DiscoverySnapshotUnavailable, G as DriveMode, H as DriveRefusal, I as ExchangeOptions, J as FEED_TTL_MS, K as FeeCeiling, N as FeedFetch, P as FeedQuoteInput, Q as INDEXED_NETWORKS, R as InconsistentRoute, T as InsufficientFunds, U as LockupOwner, V as Market, W as MaxFeeExceeded, X as MissingCorridorDep, Y as NotCancellable, Z as ONCHAIN_CLAIM_FEE_RATE_SATVB, _ as ObservationSeam, $ as OfferPreparation, a0 as OnchainClaim, a1 as OperatorUnreachable, a2 as ParsedRfqQuote, a3 as PayOptions, a4 as PayResult, a5 as QuoteCheck, a6 as QuoteExpired, a7 as QuotePreparation, a8 as QuoteVerificationFailed, a9 as REGISTRY_URL, aa as ReceiveArtifact, ab as ReceiveOptions, ac as ReceiveRequest, ad as RecoveryResult, ae as RegisteredAsset, af as RfqAuctionPolicy, ag as RfqPreparation, ah as RfqQuoteInput, ai as RfqRendezvous, aj as RfqTransportFactory, ak as RouteSide, al as SWAP_ERROR_NAMES, am as SwapClient, an as SwapClientConfig, ao as SwapDrive, ap as SwapDriveConfig, aq as SwapDriveRefusedError, ar as SwapError, as as SwapErrorName, at as SwapFilter, au as UnsupportedRoute, av as VerbDeps, aw as acceptQuote, ax as attesting, ay as cancelSwap, az as canonicalAssetId, aA as cardMarketOf, aB as chooseMarket, aC as conflictingFields, aD as corridorSet, aE as createSwapClient, aF as createSwapDrive, aG as discoveryIndex, aH as eligibleMarkets, aI as enforceFeeCeiling, aJ as exchange, aK as feedFetch, aL as isAddressable, aM as isCardMarket, aN as isIndexedNetwork, aO as isSwapError, aP as isUsableCard, aQ as liveArkadeInfo, aR as marketBackendOf, aS as marketKeyOf, aT as marketRefOf, aU as nostrTransportFactory, aV as parseRfqQuote, aW as pay, aX as quoteFromFeed, aY as quoteViaRfq, aZ as readableRecord, a_ as receive, a$ as resolveCorridorBase, b0 as resolveCorridorDeps, b1 as rfqLeg, b2 as rfqPairFor, b3 as swapRecordOf, b4 as toDiscoveryLeg, b5 as usableMarkets, b6 as withCanonicalAmount } from './errors-CSpOUdCN.js';
3
3
  import { DiscoveredMarket } from '@arkade-os/solver-discovery';
4
- import { N as NetworkRef, C as Corridor, A as AssetId, R as Rail, a as RfqSwapRecordStore, b as CorridorSwapRecord, Q as QuoteId, S as SwapRecord, O as OfferSwapRecord, c as AssetSwapRepository, d as RfqSwapRecord, L as LockupSpendIndexer, e as AssetSwapStatus, f as RouteResolution, g as ResolvedEndpoint, P as PinnedAmount, I as Instrument, h as Route, i as QuoteInput, j as Pubkey } from './repository-OUoAxV1Z.js';
5
- export { k as ACTIVITY_TOKEN, l as ARKADE_ASSET_NAMESPACE, m as Amount, n as AmountFormatError, o as AmountOn, p as AmountRefusal, q as Artifact, r as AssetIdError, s as AssetIdRefusal, t as AssetNamespace, u as AssetOn, v as AssetPart, w as AssetRef, x as AssetScale, y as AssetSwapId, z as AtomicDecimal, B as AuctionMarketRef, D as AuctionProvenance, E as BITCOIN_RAILS, F as BTC_ASSET_PART, G as BitcoinRail, H as CORRIDORS, J as CORRIDOR_PASS, K as CardMarketRef, M as CorridorId, T as CorridorKind, U as DepositArtifact, V as DisplayDecimal, W as Endpoint, X as Ep, Y as Hex, Z as LOCKUP_OWNER, _ as MarketBackend, $ as MarketRef, a0 as OFFER_SWAP_ID_PREFIX, a1 as Outcome, a2 as ParsedAssetId, a3 as Quote, a4 as QuoteLeg, a5 as RAILS, a6 as RFQ_SWAP_ID_PREFIX, a7 as RailOf, a8 as RankedBid, a9 as RawState, aa as RecordedArtifact, ab as RecordedEndpoint, ac as RecordedInstrument, ad as RecordedLeg, ae as RfqAmountSide, af as SnapshotRef, ag as Swap, ah as SwapFamily, ai as SwapRecordCommon, aj as SwapUpdate, ak as Unsubscribe, al as arkadeAsset, am as artifactOf, an as assetPartOf, ao as assetSwapIdOf, ap as bitcoinNetworkOf, aq as btcOn, ar as corridorOfRail, as as corridorOutcome, at as decodeRfqAmount, au as encodeRfqAmount, av as familyOfSwapId, aw as formatAssetId, ax as fromAtomicDecimal, ay as fromRfqAmountSide, az as fundsFromWallet, aA as instrumentOf, aB as isAssetId, aC as isAtomicDecimal, aD as isNetworkRef, aE as issuanceOf, aF as legOf, aG as offerOutcome, aH as parseAssetId, aI as quoteIdOfSwapId, aJ as railOf, aK as railOfCorridor, aL as readsChain, aM as recordArtifact, aN as recordEndpoint, aO as recordInstrument, aP as recordLeg, aQ as recordOutcome, aR as sameAsset, aS as swapOf, aT as toAtomicDecimal, aU as toRfqAmountSide, aV as toSafeNumber } from './repository-OUoAxV1Z.js';
6
- import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-RONK76D7.js';
7
- export { S as SwapRefusal } from './rfq-RONK76D7.js';
4
+ import { N as NetworkRef, C as Corridor, A as AssetId, R as Rail, a as RfqSwapRecordStore, b as CorridorSwapRecord, Q as QuoteId, S as SwapRecord, O as OfferSwapRecord, c as AssetSwapRepository, d as RfqSwapRecord, L as LockupSpendIndexer, e as AssetSwapStatus, f as RouteResolution, g as ResolvedEndpoint, P as PinnedAmount, I as Instrument, h as Route, i as QuoteInput, j as Pubkey } from './repository-tDT8p-Nx.js';
5
+ export { k as ACTIVITY_TOKEN, l as ARKADE_ASSET_NAMESPACE, m as Amount, n as AmountFormatError, o as AmountOn, p as AmountRefusal, q as Artifact, r as AssetIdError, s as AssetIdRefusal, t as AssetNamespace, u as AssetOn, v as AssetPart, w as AssetRef, x as AssetScale, y as AssetSwapId, z as AtomicDecimal, B as AuctionMarketRef, D as AuctionProvenance, E as BITCOIN_RAILS, F as BTC_ASSET_PART, G as BitcoinRail, H as CORRIDORS, J as CORRIDOR_PASS, K as CardMarketRef, M as CorridorId, T as CorridorKind, U as DepositArtifact, V as DisplayDecimal, W as Endpoint, X as Ep, Y as Hex, Z as LOCKUP_OWNER, _ as MarketBackend, $ as MarketRef, a0 as OFFER_SWAP_ID_PREFIX, a1 as Outcome, a2 as ParsedAssetId, a3 as Quote, a4 as QuoteLeg, a5 as RAILS, a6 as RFQ_SWAP_ID_PREFIX, a7 as RailOf, a8 as RankedBid, a9 as RawState, aa as RecordedArtifact, ab as RecordedEndpoint, ac as RecordedInstrument, ad as RecordedLeg, ae as RfqAmountSide, af as SnapshotRef, ag as Swap, ah as SwapFamily, ai as SwapRecordCommon, aj as SwapUpdate, ak as Unsubscribe, al as arkadeAsset, am as artifactOf, an as assetPartOf, ao as assetSwapIdOf, ap as bitcoinNetworkOf, aq as btcOn, ar as corridorOfRail, as as corridorOutcome, at as decodeRfqAmount, au as encodeRfqAmount, av as familyOfSwapId, aw as formatAssetId, ax as fromAtomicDecimal, ay as fromRfqAmountSide, az as fundsFromWallet, aA as instrumentOf, aB as isAssetId, aC as isAtomicDecimal, aD as isNetworkRef, aE as issuanceOf, aF as legOf, aG as offerOutcome, aH as parseAssetId, aI as quoteIdOfSwapId, aJ as railOf, aK as railOfCorridor, aL as readsChain, aM as recordArtifact, aN as recordEndpoint, aO as recordInstrument, aP as recordLeg, aQ as recordOutcome, aR as sameAsset, aS as swapOf, aT as toAtomicDecimal, aU as toRfqAmountSide, aV as toSafeNumber } from './repository-tDT8p-Nx.js';
6
+ import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-DhkgiwQ7.js';
7
+ export { S as SwapRefusal } from './rfq-DhkgiwQ7.js';
8
8
  import * as btc from '@scure/btc-signer';
9
9
  import { OnchainProvider, NetworkName, IWallet, VHTLC } from '@arkade-os/sdk';
10
- import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-Ci61IXyG.js';
10
+ import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-DbWXdpzm.js';
11
11
 
12
12
  /**
13
13
  * The alias table, filled from discovery.
package/dist/advanced.js CHANGED
@@ -133,7 +133,7 @@ import {
133
133
  withCanonicalAmount,
134
134
  withOfferStatus,
135
135
  withRfqState
136
- } from "./chunk-O3XMAZXS.js";
136
+ } from "./chunk-HV7EIUE2.js";
137
137
  import {
138
138
  ACTIVITY_TOKEN,
139
139
  CORRIDOR_PASS,
@@ -148,11 +148,11 @@ import {
148
148
  onchainCorridor,
149
149
  readsChain,
150
150
  recordOutcome
151
- } from "./chunk-BQLGQ4WB.js";
151
+ } from "./chunk-4PATNGYQ.js";
152
152
  import {
153
153
  SwapRefusal,
154
154
  sealClaimPacket
155
- } from "./chunk-6HIU2LNP.js";
155
+ } from "./chunk-ARYFNDJY.js";
156
156
 
157
157
  // src/reveal.ts
158
158
  import { base64, hex } from "@scure/base";
@@ -7,7 +7,7 @@ import {
7
7
  lockupContractParams,
8
8
  onchainHtlcScript,
9
9
  registerLockupContract
10
- } from "./chunk-6HIU2LNP.js";
10
+ } from "./chunk-ARYFNDJY.js";
11
11
 
12
12
  // src/store.ts
13
13
  import { hex } from "@scure/base";
@@ -239,10 +239,10 @@ function addressOutstanding(swaps, script) {
239
239
  }
240
240
  return true;
241
241
  }
242
- async function promoteOfferContract(manager, script) {
242
+ async function promoteOfferContract(manager, script, issued = Date.now()) {
243
243
  await serialize(script, async () => {
244
244
  await manager.setContractWatchState(script, "watched");
245
- issuedAt.set(script, Date.now());
245
+ issuedAt.set(script, issued);
246
246
  });
247
247
  }
248
248
  async function retireOfferContract(manager, swaps, script) {
@@ -470,7 +470,6 @@ function decodeExitDelay(value) {
470
470
  var OFFER_CONTRACT_LABEL = "Arkade swap offer";
471
471
  var OFFER_CONTRACT_KIND = "asset-swap-offer";
472
472
  async function registerOfferContract(wallet, info, binding, operatorPubkey, expectedPkScript) {
473
- const { program, args, keys } = swapProgramBinding(binding, operatorPubkey);
474
473
  const contractManager = await wallet.getContractManager();
475
474
  const client = await arkade.Arkade.connect({
476
475
  // Registration derives and persists; it never broadcasts and never
@@ -486,15 +485,67 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
486
485
  network: networkFromArkadeInfo(info),
487
486
  contractManager
488
487
  });
488
+ await contractManager.createContract(
489
+ offerContractParams(client, binding, operatorPubkey, expectedPkScript)
490
+ );
491
+ await promoteOfferContract(contractManager, hex2.encode(expectedPkScript));
492
+ }
493
+ function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
494
+ const { program, args, keys } = swapProgramBinding(binding, operatorPubkey);
489
495
  const contract = new arkade.ArkadeContract(client, program, args, keys);
490
496
  if (hex2.encode(contract.pkScript) !== hex2.encode(expectedPkScript)) {
491
497
  throw new Error("derived covenant does not match the offer's swapPkScript");
492
498
  }
493
- await contract.register({
499
+ return {
500
+ ...contract.toContractParams(),
494
501
  label: OFFER_CONTRACT_LABEL,
495
502
  metadata: { genericallySpendable: false, kind: OFFER_CONTRACT_KIND }
503
+ };
504
+ }
505
+ async function restoreOfferCoverage(wallet, swaps) {
506
+ const live = swaps.filter((swap) => !RETIRABLE.includes(swap.status));
507
+ if (live.length === 0) return;
508
+ const [info, contractManager] = await Promise.all([
509
+ wallet.getArkadeInfo({ requireLive: true }),
510
+ wallet.getContractManager()
511
+ ]);
512
+ const operatorPubkey = hex2.decode(toXOnlySignerHex(info.signerPubkey));
513
+ const client = await arkade.Arkade.connect({
514
+ arkade: { getInfo: async () => info },
515
+ identity: wallet.identity,
516
+ network: networkFromArkadeInfo(info),
517
+ contractManager
496
518
  });
497
- await promoteOfferContract(contractManager, hex2.encode(expectedPkScript));
519
+ const seen = /* @__PURE__ */ new Set();
520
+ const covenants = [];
521
+ for (const swap of live) {
522
+ if (seen.has(swap.swapPkScript)) continue;
523
+ seen.add(swap.swapPkScript);
524
+ try {
525
+ const { swapPkScript: _, ...binding } = decodeOffer(hex2.decode(swap.offerHex));
526
+ covenants.push({
527
+ script: swap.swapPkScript,
528
+ issued: swap.createdAt,
529
+ params: offerContractParams(
530
+ client,
531
+ binding,
532
+ operatorPubkey,
533
+ hex2.decode(swap.swapPkScript)
534
+ )
535
+ });
536
+ } catch (error) {
537
+ console.warn(`[swap] could not restore coverage for ${swap.swapPkScript}`, error);
538
+ }
539
+ }
540
+ const params = covenants.map((covenant) => covenant.params);
541
+ if (contractManager.createContracts) {
542
+ await contractManager.createContracts(params);
543
+ } else {
544
+ for (const contract of params) await contractManager.createContract(contract);
545
+ }
546
+ for (const covenant of covenants) {
547
+ await promoteOfferContract(contractManager, covenant.script, covenant.issued);
548
+ }
498
549
  }
499
550
  function serverExitDelay(delay) {
500
551
  if (typeof delay !== "bigint" || delay <= BigInt(0)) {
@@ -1356,6 +1407,16 @@ import {
1356
1407
  sideLimits
1357
1408
  } from "@arkade-os/solver-discovery";
1358
1409
  import { isSubdust } from "@arkade-os/sdk";
1410
+
1411
+ // src/marketShape.ts
1412
+ var assetOf = (market, side) => side === "base" ? market.base_asset : market.quote_asset;
1413
+ var marketAssetId = (market, side) => {
1414
+ const asset2 = assetOf(market, side);
1415
+ if (typeof asset2?.caip19_id === "string") return asset2.caip19_id;
1416
+ return typeof asset2?.id === "string" ? asset2.id : void 0;
1417
+ };
1418
+
1419
+ // src/markets.ts
1359
1420
  var QUOTE_OPTIONS = { safetyBps: 0 };
1360
1421
  var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
1361
1422
  const cache = /* @__PURE__ */ new Map();
@@ -1404,14 +1465,17 @@ var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
1404
1465
  var MARKETS_CACHE_TTL_MS = 60 * 60 * 1e3;
1405
1466
  var isMarketShaped = (m) => {
1406
1467
  const market = m;
1407
- return typeof market?.pair === "string" && typeof market.base_asset?.id === "string" && typeof market.quote_asset?.id === "string" && typeof market.quote_asset.decimals === "number";
1468
+ if (!market) return false;
1469
+ return typeof market.base_asset?.id === "string" && typeof market.quote_asset?.id === "string" && typeof market.quote_asset.decimals === "number";
1408
1470
  };
1409
1471
  var readMarketsCache = async (repository, network, registry) => {
1410
1472
  try {
1411
1473
  const entry = await repository.getCachedMarkets(network, registry);
1412
1474
  if (!Array.isArray(entry?.markets) || typeof entry?.fetchedAt !== "number")
1413
1475
  return void 0;
1414
- return entry.markets.every(isMarketShaped) ? entry : void 0;
1476
+ const markets = entry.markets.filter(isMarketShaped);
1477
+ if (entry.markets.length > 0 && markets.length === 0) return void 0;
1478
+ return { ...entry, markets };
1415
1479
  } catch {
1416
1480
  return void 0;
1417
1481
  }
@@ -1452,10 +1516,33 @@ var discoverMarkets = async (options) => {
1452
1516
  };
1453
1517
  var findMarket = (markets, fromId, toId) => {
1454
1518
  if (fromId === toId) return void 0;
1455
- const givingBase = bestMarket(markets, { baseId: fromId, quoteId: toId, wantSide: "quote" });
1519
+ const resolveMarketId = (id) => {
1520
+ for (const market of markets) {
1521
+ for (const side of ["base", "quote"]) {
1522
+ const asset2 = side === "base" ? market.base_asset : market.quote_asset;
1523
+ if (asset2.id === id) return id;
1524
+ const canonical = marketAssetId(market, side) ?? "";
1525
+ const matchesBtc = id === BTC_ASSET_ID && /^arkade:[^/]+\/slip44:(?:0|1)$/.test(canonical);
1526
+ const matchesAsset = /^[0-9a-f]{68}$/.test(id) && canonical.endsWith(`/asset:${id}`);
1527
+ if ((matchesBtc || matchesAsset) && typeof asset2.id === "string") return asset2.id;
1528
+ }
1529
+ }
1530
+ return id;
1531
+ };
1532
+ const resolvedFrom = resolveMarketId(fromId);
1533
+ const resolvedTo = resolveMarketId(toId);
1534
+ const givingBase = bestMarket(markets, {
1535
+ baseId: resolvedFrom,
1536
+ quoteId: resolvedTo,
1537
+ wantSide: "quote"
1538
+ });
1456
1539
  if (givingBase) return { market: givingBase, give: "base" };
1457
1540
  return {
1458
- market: bestMarket(markets, { baseId: toId, quoteId: fromId, wantSide: "base" }),
1541
+ market: bestMarket(markets, {
1542
+ baseId: resolvedTo,
1543
+ quoteId: resolvedFrom,
1544
+ wantSide: "base"
1545
+ }),
1459
1546
  give: "quote"
1460
1547
  };
1461
1548
  };
@@ -1545,16 +1632,33 @@ function classifyDepositSpend(offer, operatorPubkey, spendTxs, deposit) {
1545
1632
  return "indeterminate";
1546
1633
  }
1547
1634
  async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
1548
- const { operatorPubkey, scanned = /* @__PURE__ */ new Set() } = opts;
1549
- const candidates = unscannedSwapCandidates(txs, existingIds, scanned);
1550
- if (candidates.length === 0) return { restored: [], scannedTxids: [] };
1635
+ const { operatorPubkey, scanned = /* @__PURE__ */ new Set(), reopen = [] } = opts;
1636
+ const reopened = [];
1637
+ for (const swap of reopen) {
1638
+ try {
1639
+ reopened.push({
1640
+ fundingTx: { type: "sent", redeemTxid: swap.fundingTxid },
1641
+ offer: decodeOffer(hex5.decode(swap.offerHex)),
1642
+ offerHex: swap.offerHex,
1643
+ existing: swap
1644
+ });
1645
+ } catch {
1646
+ }
1647
+ }
1648
+ const reopenedTxids = new Set(reopened.map(({ fundingTx }) => fundingTx.redeemTxid));
1649
+ const candidates = unscannedSwapCandidates(txs, existingIds, scanned).filter(
1650
+ ({ redeemTxid }) => !reopenedTxids.has(redeemTxid)
1651
+ );
1652
+ if (candidates.length === 0 && reopened.length === 0) {
1653
+ return { restored: [], scannedTxids: [] };
1654
+ }
1551
1655
  const byTxid = new Map(candidates.map((tx) => [tx.redeemTxid, tx]));
1552
1656
  const parsedByTxid = await fetchParsedTxs(
1553
1657
  indexer,
1554
1658
  candidates.map((tx) => tx.redeemTxid)
1555
1659
  );
1556
1660
  const fetchedTxids = [];
1557
- const found = [];
1661
+ const found = [...reopened];
1558
1662
  for (const [txid, parsed] of parsedByTxid) {
1559
1663
  const fundingTx = byTxid.get(txid);
1560
1664
  if (!fundingTx) continue;
@@ -1592,7 +1696,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
1592
1696
  const spendTxByTxid = await fetchParsedTxs(indexer, [...spendTxids]);
1593
1697
  const restored = [];
1594
1698
  const unresolved = /* @__PURE__ */ new Set();
1595
- for (const { fundingTx, offer, offerHex } of found) {
1699
+ for (const { fundingTx, offer, offerHex, existing } of found) {
1596
1700
  const swapPkScript = hex5.encode(offer.swapPkScript);
1597
1701
  const vtxo = vtxoByScriptAndTxid.get(`${swapPkScript}:${fundingTx.redeemTxid}`);
1598
1702
  if (!vtxo) {
@@ -1623,6 +1727,12 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
1623
1727
  }
1624
1728
  status = kind;
1625
1729
  }
1730
+ const completion = status === "fulfilled" && spentTxid && txByAnyId.get(spentTxid)?.createdAt ? { completedAt: txByAnyId.get(spentTxid).createdAt * 1e3 } : {};
1731
+ if (existing) {
1732
+ if (status === "pending") continue;
1733
+ restored.push({ ...existing, status, spentTxid, ...completion });
1734
+ continue;
1735
+ }
1626
1736
  restored.push({
1627
1737
  id: fundingTx.redeemTxid,
1628
1738
  fromAsset,
@@ -1642,7 +1752,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
1642
1752
  createdAt: fundingTx.createdAt ? fundingTx.createdAt * 1e3 : vtxo.createdAt.getTime(),
1643
1753
  // the completion time is the caller's record of the spend, if it
1644
1754
  // has one — the psbt that classified it carries no timestamp
1645
- ...status === "fulfilled" && spentTxid && txByAnyId.get(spentTxid)?.createdAt ? { completedAt: txByAnyId.get(spentTxid).createdAt * 1e3 } : {}
1755
+ ...completion
1646
1756
  });
1647
1757
  }
1648
1758
  return { restored, scannedTxids: fetchedTxids.filter((id) => !unresolved.has(id)) };
@@ -3109,6 +3219,7 @@ export {
3109
3219
  retireOfferContract,
3110
3220
  retireSettledOfferContracts,
3111
3221
  BTC_ASSET_ID,
3222
+ getAssetSwapsOrThrow,
3112
3223
  getAssetSwaps,
3113
3224
  addAssetSwap,
3114
3225
  updateAssetSwap,
@@ -3120,6 +3231,7 @@ export {
3120
3231
  OFFER_PACKET_TYPE,
3121
3232
  encodeOffer,
3122
3233
  decodeOffer,
3234
+ restoreOfferCoverage,
3123
3235
  createOffer,
3124
3236
  cancelOffer,
3125
3237
  NoSpendableDepositError,