@arkade-os/swap 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/advanced.cjs +150 -33
  2. package/dist/advanced.d.cts +10 -8
  3. package/dist/advanced.d.ts +10 -8
  4. package/dist/advanced.js +7 -3
  5. package/dist/{chunk-WKJFXXSR.js → chunk-BLECLU5Q.js} +91 -14
  6. package/dist/{chunk-FMRAV77W.js → chunk-ICSREL7N.js} +14 -12
  7. package/dist/{chunk-HRMWBULL.js → chunk-J2PMAQP2.js} +70 -25
  8. package/dist/index.cjs +146 -33
  9. package/dist/index.d.cts +5 -5
  10. package/dist/index.d.ts +5 -5
  11. package/dist/index.js +3 -3
  12. package/dist/{lockupContract-D7BNjksX.d.ts → lockupContract-CIXkJPxV.d.ts} +1 -1
  13. package/dist/{lockupContract-G-9CNRMq.d.cts → lockupContract-CkhWMKCo.d.cts} +1 -1
  14. package/dist/nostr.js +1 -1
  15. package/dist/{offer-DdB1M6FZ.d.ts → offer-BPD2ortO.d.ts} +1 -1
  16. package/dist/{offer-CcJfx5Fj.d.cts → offer-Diff5Flc.d.cts} +1 -1
  17. package/dist/{offerFillPlan-BII0PW92.d.cts → offerFillPlan-B-5ae_gQ.d.cts} +40 -11
  18. package/dist/{offerFillPlan-CNTLVD7j.d.ts → offerFillPlan-CJzneX6F.d.ts} +40 -11
  19. package/dist/protocol.cjs +99 -25
  20. package/dist/protocol.d.cts +6 -6
  21. package/dist/protocol.d.ts +6 -6
  22. package/dist/protocol.js +4 -4
  23. package/dist/repositories/realm/index.d.cts +1 -1
  24. package/dist/repositories/realm/index.d.ts +1 -1
  25. package/dist/repositories/sqlite/index.d.cts +1 -1
  26. package/dist/repositories/sqlite/index.d.ts +1 -1
  27. package/dist/{repository-DmPzpbd7.d.ts → repository-BBVRh9ez.d.ts} +17 -2
  28. package/dist/{repository-DqdLVrVv.d.cts → repository-C4pvymhs.d.cts} +17 -2
  29. package/dist/{watch-CmJQDtsy.d.ts → watch-7BiRa4oB.d.ts} +1 -1
  30. package/dist/{watch-BonYT9af.d.cts → watch-Bxq-lx_6.d.cts} +1 -1
  31. package/package.json +2 -2
@@ -1,8 +1,8 @@
1
1
  import { IWallet, NetworkName, Network, SignerSet, OnchainProvider, ArkadeInfo, VHTLC, ProvisionedKey, ProvisionedClaimSecret, Transaction } from '@arkade-os/sdk';
2
- import { bd as SwapOperator, d as AssetSwapRepository, m as Pubkey, bf as RfqSwapManagerCallbacks, C as Corridor, I as Instrument, bg as RfqSwapActionName, N as NetworkRef, A as AssetId, ao as SnapshotRef, a4 as MarketBackend, X as CardMarketRef, a5 as MarketRef, E as AssetRef, r as AmountOn, ap as Swap, Y as CorridorId, _ as DepositArtifact, l as QuoteInput, a9 as Quote, ae as RankedBid, as as SwapUpdate, au as Unsubscribe, S as SwapRecord, Q as QuoteId, a7 as Outcome, L as LockupSpendIndexer, bc as SwapContractRegistry, j as ResolvedEndpoint, P as PinnedAmount, D as AssetPaymentTerms, B as AssetPaymentInput, O as OfferSwapRecord, G as AssetSwapId, aq as SwapFamily, i as RouteResolution } from './repository-DmPzpbd7.js';
2
+ import { bd as SwapOperator, d as AssetSwapRepository, m as Pubkey, bf as RfqSwapManagerCallbacks, C as Corridor, I as Instrument, bg as RfqSwapActionName, N as NetworkRef, A as AssetId, ao as SnapshotRef, a4 as MarketBackend, X as CardMarketRef, a5 as MarketRef, E as AssetRef, r as AmountOn, ap as Swap, Y as CorridorId, _ as DepositArtifact, l as QuoteInput, a9 as Quote, ae as RankedBid, as as SwapUpdate, au as Unsubscribe, S as SwapRecord, Q as QuoteId, a7 as Outcome, L as LockupSpendIndexer, bc as SwapContractRegistry, j as ResolvedEndpoint, P as PinnedAmount, D as AssetPaymentTerms, B as AssetPaymentInput, O as OfferSwapRecord, G as AssetSwapId, aq as SwapFamily, i as RouteResolution } from './repository-BBVRh9ez.js';
3
3
  import { I as InvoiceFacts, C as ChainSource, R as RfqQuote, e as RfqTransport, L as LightningSendContractParams, f as LightningReceiveContractParams, O as OnchainHtlc, g as OnchainHtlcParams, h as OnchainNetwork, S as SwapRefusal } from './rfq-C0tHOvn6.js';
4
4
  import { Network as Network$1, LocalCardInput, TransportCardFetcher, DiscoveredMarket, Side, OfferPlan } from '@arkade-os/solver-discovery';
5
- import { D as DerivedOffer, F as FillFunding, a as FillOutpoint, b as FillInputOwner } from './offer-DdB1M6FZ.js';
5
+ import { D as DerivedOffer, F as FillFunding, a as FillOutpoint, b as FillInputOwner } from './offer-BPD2ortO.js';
6
6
  import * as nostr_tools from 'nostr-tools';
7
7
 
8
8
  /**
@@ -498,7 +498,8 @@ declare const isAddressable: (card: DiscoveredMarket) => boolean;
498
498
  declare const marketBackendOf: (card: DiscoveredMarket) => MarketBackend;
499
499
  /**
500
500
  * The cards on a snapshot this client may act on at all: the policy's registry allowlist, then
501
- * addressability. Shared with `markets()` so it cannot offer a card the quote path would refuse.
501
+ * addressability. Shared with `markets()`; eligibility is not, so `markets()` can list a card
502
+ * `quote()` refuses.
502
503
  */
503
504
  declare const usableMarkets: (snapshot: DiscoverySnapshot, policy?: SwapPolicy) => DiscoveredMarket[];
504
505
  /**
@@ -529,12 +530,34 @@ declare const marketRefOf: (candidate: MarketCandidate, snapshot: SnapshotRef) =
529
530
  declare const cardMarketOf: (card: DiscoveredMarket, snapshot: SnapshotRef, key: string, backend: MarketBackend) => CardMarketRef;
530
531
  /** Narrow a `MarketRef` to the card arm — the only one `quote()` mints. */
531
532
  declare const isCardMarket: (market: MarketRef) => market is CardMarketRef;
533
+ /** One side of a {@link Market}. */
534
+ interface MarketLeg {
535
+ /** Absent when the leg has no public id, e.g. an `eip155:` leg. */
536
+ readonly asset?: AssetId;
537
+ /** For `Amount.format`. */
538
+ readonly decimals: number;
539
+ /**
540
+ * The card's announced bounds, in atomic units. Indicative: the solver can still refuse.
541
+ * `null`: the solver will not pay this leg out; a one-way card still routes it as the give leg.
542
+ * Only an amount pinned with `amountOn: "take"` is checked: a give-pinned amount still resolves,
543
+ * and a feed card still quotes it, even if the resulting take is out of range.
544
+ */
545
+ readonly limits: {
546
+ readonly min: bigint;
547
+ readonly max: bigint;
548
+ } | null;
549
+ }
532
550
  /**
533
- * A market as the v2 client publishes it — the same {@link CardMarketRef} a quote cites, so a
534
- * caller picking a market for a custom `quote()` reads the provenance the quote will carry.
535
- * Discovery's `DiscoveredMarket` never crosses the v2 root, so this carries no discovery asset id.
551
+ * A market as the v2 client publishes it: the {@link CardMarketRef} a quote would cite, plus its
552
+ * legs. Find a leg by `asset`, not position: they are in card order. The legs stay off
553
+ * `CardMarketRef` because that is written into durable records, which forbid `bigint`.
536
554
  */
537
- type Market = CardMarketRef;
555
+ interface Market extends CardMarketRef {
556
+ readonly legs: readonly [MarketLeg, MarketLeg];
557
+ }
558
+ /** A card as {@link Market}. `network` is the wallet's, as routing uses, so a legacy leg's id
559
+ * matches `resolve()` under a `DiscoveryConfig.network` override. */
560
+ declare const marketOf: (card: DiscoveredMarket, snapshot: SnapshotRef, network: NetworkRef) => Market;
538
561
 
539
562
  /**
540
563
  * The three product-facing verbs: `pay`, `receive` and `exchange` each compile a
@@ -1304,9 +1327,15 @@ interface SwapClient {
1304
1327
  */
1305
1328
  swaps(filter?: SwapFilter): Promise<Swap[]>;
1306
1329
  /**
1307
- * The markets a `quote()` could be priced against, in the `Quote.market` shape and under the same
1308
- * filters, so it cannot offer one `quote()` would refuse. Fetches when no snapshot is in hand, as
1309
- * `quote()` does, since callers reach for it BEFORE quoting.
1330
+ * The markets on the active snapshot, in the `Quote.market` shape plus each leg's announced
1331
+ * limits, with no RFQ and no disclosure. Shares `quote()`'s registry allowlist and addressability
1332
+ * filter but not its eligibility, so it can list a card `quote()` refuses. Fetches when no
1333
+ * snapshot is in hand, as `quote()` does, since callers reach for it BEFORE quoting.
1334
+ *
1335
+ * `key` is not unique: correlate with `resolve().market` on `key` + `source` + `discoveryPubkey`,
1336
+ * or `solver` on spot cards, which have no `discoveryPubkey`. These fields identify a solver's
1337
+ * market, not one card. A solver may publish several with different limits: `pair` separates a
1338
+ * flipped card, but nothing public separates fee tiers.
1310
1339
  *
1311
1340
  * @throws {DiscoverySnapshotUnavailable} when the fetch leaves it with
1312
1341
  * nothing either.
@@ -1639,4 +1668,4 @@ interface BuildOfferFillPlanOpts {
1639
1668
  declare function buildOfferFillPlan(wallet: IWallet, arkServerUrl: string, offerHex: string, opts: BuildOfferFillPlanOpts): Promise<JointGraph>;
1640
1669
  declare function verifyOfferFillPlan(plan: JointGraph): boolean;
1641
1670
 
1642
- export { type JointGraph as $, type AssetAliasTable as A, type BuildOfferFillPlanOpts as B, type CorridorFactory as C, type DiscoveryIndex as D, type CorridorOverrides as E, type CorridorPass as F, type CorridorRfqPreparation as G, DEFAULT_MAX_REFUND_WINDOW_SECONDS as H, type DiscoveryConfig as I, type DiscoveryIndexInput as J, DiscoverySnapshotUnavailable as K, type LightningCorridorDeps as L, type MarketCandidate as M, type DriveMode as N, type OnchainCorridorDeps as O, type DriveRefusal as P, type ExchangeOptions as Q, FEED_TTL_MS as R, type SwapPolicy as S, type FeeCeiling as T, type FeedFetch as U, type FeedQuoteInput as V, type FillSponsor as W, type FillSponsorFare as X, INDEXED_NETWORKS as Y, InconsistentRoute as Z, InsufficientFunds as _, type ArkadeCorridorDeps as a, isAddressable as a$, type LockupOwner as a0, type Market as a1, MaxFeeExceeded as a2, MissingCorridorDep as a3, NotCancellable as a4, OFFER_FILL_OWNERS as a5, OFFER_FILL_TEMPLATE as a6, ONCHAIN_CLAIM_FEE_RATE_SATVB as a7, type ObservationSeam as a8, type OfferPreparation as a9, type SwapDriveConfig as aA, SwapDriveRefusedError as aB, type SwapError as aC, type SwapErrorName as aD, type SwapFilter as aE, UnsupportedRoute as aF, type VerbDeps as aG, acceptQuote as aH, attesting as aI, buildOfferFillPlan as aJ, cancelSwap as aK, canonicalAssetId as aL, cardMarketOf as aM, chooseMarket as aN, conflictingFields as aO, corridorSet as aP, createNostrTransportFactory as aQ, createSwapClient as aR, createSwapDrive as aS, deepFreeze as aT, digestJointGraph as aU, discoveryIndex as aV, eligibleMarkets as aW, enforceFeeCeiling as aX, exchange as aY, feedFetch as aZ, feedSpread as a_, type OnchainClaim as aa, type OnchainRefund as ab, OperatorUnreachable as ac, type ParsedRfqQuote as ad, type PayOptions as ae, type PayResult as af, type QuoteCheck as ag, QuoteExpired as ah, type QuotePreparation as ai, QuoteVerificationFailed as aj, REGISTRY_URL as ak, type ReceiveArtifact as al, type ReceiveOptions as am, type ReceiveRequest as an, type RecoveryResult as ao, type RegisteredAsset as ap, type RfqAuctionPolicy as aq, type RfqPreparation as ar, type RfqQuoteInput as as, type RfqRendezvous as at, type RfqTransportFactory as au, type RouteSide as av, SWAP_ERROR_NAMES as aw, type SwapClient as ax, type SwapClientConfig as ay, type SwapDrive as az, type CorridorSet as b, isCardMarket as b0, isIndexedNetwork as b1, isSwapError as b2, isUsableCard as b3, liveArkadeInfo as b4, marketBackendOf as b5, marketKeyOf as b6, marketRefOf as b7, nostrTransportFactory as b8, parseRfqQuote as b9, pay as ba, quoteFromFeed as bb, quoteViaRfq as bc, readableRecord as bd, receive as be, resolveCorridorBase as bf, resolveCorridorDeps as bg, rfqLeg as bh, rfqPairFor as bi, swapRecordOf as bj, toDiscoveryLeg as bk, unsignedPsbtBytes as bl, usableMarkets as bm, verifyJointGraph as bn, verifyOfferFillPlan as bo, verifyPlanLegs as bp, withCanonicalAmount as bq, type DiscoveryLeg as c, type DiscoverySnapshot as d, AcceptConflict as e, type AcceptInput as f, type AcceptOptions as g, AmbiguousDestination as h, AmountEncodingUnsupported as i, AmountMismatch as j, type AssetRfqPreparation as k, type AttestingRfqTransport as l, CORRIDOR_FACTORIES as m, type CancelInput as n, type CancelOutcome as o, type ClaimedDestination as p, ClientDisposed as q, type CorridorBase as r, type CorridorClaim as s, type CorridorCovenant as t, type CorridorDeadline as u, type CorridorDeps as v, type CorridorDepsByCorridor as w, type CorridorDrive as x, type CorridorLockup as y, type CorridorModule as z };
1671
+ export { type JointGraph as $, type AssetAliasTable as A, type BuildOfferFillPlanOpts as B, type CorridorFactory as C, type DiscoveryIndex as D, type CorridorOverrides as E, type CorridorPass as F, type CorridorRfqPreparation as G, DEFAULT_MAX_REFUND_WINDOW_SECONDS as H, type DiscoveryConfig as I, type DiscoveryIndexInput as J, DiscoverySnapshotUnavailable as K, type LightningCorridorDeps as L, type MarketCandidate as M, type DriveMode as N, type OnchainCorridorDeps as O, type DriveRefusal as P, type ExchangeOptions as Q, FEED_TTL_MS as R, type SwapPolicy as S, type FeeCeiling as T, type FeedFetch as U, type FeedQuoteInput as V, type FillSponsor as W, type FillSponsorFare as X, INDEXED_NETWORKS as Y, InconsistentRoute as Z, InsufficientFunds as _, type ArkadeCorridorDeps as a, feedSpread as a$, type LockupOwner as a0, type Market as a1, type MarketLeg as a2, MaxFeeExceeded as a3, MissingCorridorDep as a4, NotCancellable as a5, OFFER_FILL_OWNERS as a6, OFFER_FILL_TEMPLATE as a7, ONCHAIN_CLAIM_FEE_RATE_SATVB as a8, type ObservationSeam as a9, type SwapDrive as aA, type SwapDriveConfig as aB, SwapDriveRefusedError as aC, type SwapError as aD, type SwapErrorName as aE, type SwapFilter as aF, UnsupportedRoute as aG, type VerbDeps as aH, acceptQuote as aI, attesting as aJ, buildOfferFillPlan as aK, cancelSwap as aL, canonicalAssetId as aM, cardMarketOf as aN, chooseMarket as aO, conflictingFields as aP, corridorSet as aQ, createNostrTransportFactory as aR, createSwapClient as aS, createSwapDrive as aT, deepFreeze as aU, digestJointGraph as aV, discoveryIndex as aW, eligibleMarkets as aX, enforceFeeCeiling as aY, exchange as aZ, feedFetch as a_, type OfferPreparation as aa, type OnchainClaim as ab, type OnchainRefund as ac, OperatorUnreachable as ad, type ParsedRfqQuote as ae, type PayOptions as af, type PayResult as ag, type QuoteCheck as ah, QuoteExpired as ai, type QuotePreparation as aj, QuoteVerificationFailed as ak, REGISTRY_URL as al, type ReceiveArtifact as am, type ReceiveOptions as an, type ReceiveRequest as ao, type RecoveryResult as ap, type RegisteredAsset as aq, type RfqAuctionPolicy as ar, type RfqPreparation as as, type RfqQuoteInput as at, type RfqRendezvous as au, type RfqTransportFactory as av, type RouteSide as aw, SWAP_ERROR_NAMES as ax, type SwapClient as ay, type SwapClientConfig as az, type CorridorSet as b, isAddressable as b0, isCardMarket as b1, isIndexedNetwork as b2, isSwapError as b3, isUsableCard as b4, liveArkadeInfo as b5, marketBackendOf as b6, marketKeyOf as b7, marketOf as b8, marketRefOf as b9, nostrTransportFactory as ba, parseRfqQuote as bb, pay as bc, quoteFromFeed as bd, quoteViaRfq as be, readableRecord as bf, receive as bg, resolveCorridorBase as bh, resolveCorridorDeps as bi, rfqLeg as bj, rfqPairFor as bk, swapRecordOf as bl, toDiscoveryLeg as bm, unsignedPsbtBytes as bn, usableMarkets as bo, verifyJointGraph as bp, verifyOfferFillPlan as bq, verifyPlanLegs as br, withCanonicalAmount as bs, type DiscoveryLeg as c, type DiscoverySnapshot as d, AcceptConflict as e, type AcceptInput as f, type AcceptOptions as g, AmbiguousDestination as h, AmountEncodingUnsupported as i, AmountMismatch as j, type AssetRfqPreparation as k, type AttestingRfqTransport as l, CORRIDOR_FACTORIES as m, type CancelInput as n, type CancelOutcome as o, type ClaimedDestination as p, ClientDisposed as q, type CorridorBase as r, type CorridorClaim as s, type CorridorCovenant as t, type CorridorDeadline as u, type CorridorDeps as v, type CorridorDepsByCorridor as w, type CorridorDrive as x, type CorridorLockup as y, type CorridorModule as z };
package/dist/protocol.cjs CHANGED
@@ -1709,10 +1709,12 @@ function deriveLightningSend(input) {
1709
1709
  }
1710
1710
  async function requestLightningSend(wallet, transport, params) {
1711
1711
  const rfqId = params.rfqId ?? newRfqId();
1712
- const secrets = await (0, import_sdk7.provisionRefundKey)(wallet);
1712
+ const [secrets, info] = await Promise.all([
1713
+ (0, import_sdk7.provisionRefundKey)(wallet),
1714
+ wallet.getArkadeInfo({ requireLive: true })
1715
+ ]);
1713
1716
  const senderPubkey = secrets.pubkey;
1714
1717
  const refundAddress = secrets.address;
1715
- const info = await wallet.getArkadeInfo({ requireLive: true });
1716
1718
  const quote = await transport.requestQuote(
1717
1719
  lightningSendRequest({ rfqId, invoice: params.invoice.raw, refundAddress, senderPubkey })
1718
1720
  );
@@ -1914,7 +1916,11 @@ function deriveOnchainSend(input) {
1914
1916
  }
1915
1917
  async function requestOnchainSend(wallet, transport, params) {
1916
1918
  const rfqId = params.rfqId ?? newRfqId();
1917
- const secrets = await (0, import_sdk7.provisionClaimSecret)(wallet, { preimage: params.preimage });
1919
+ const [secrets, info, refundAddress] = await Promise.all([
1920
+ (0, import_sdk7.provisionClaimSecret)(wallet, { preimage: params.preimage }),
1921
+ wallet.getArkadeInfo({ requireLive: true }),
1922
+ wallet.getAddress()
1923
+ ]);
1918
1924
  if (secrets.mustPersistPreimage) {
1919
1925
  console.warn(
1920
1926
  "[swap] this swap's preimage cannot be re-derived from the seed and MUST be persisted with the record before funding"
@@ -1922,10 +1928,6 @@ async function requestOnchainSend(wallet, transport, params) {
1922
1928
  }
1923
1929
  const paymentHash = import_base6.hex.encode(secrets.paymentHash);
1924
1930
  const senderPubkey = secrets.pubkey;
1925
- const [info, refundAddress] = await Promise.all([
1926
- wallet.getArkadeInfo({ requireLive: true }),
1927
- wallet.getAddress()
1928
- ]);
1929
1931
  const quote = await transport.requestQuote(
1930
1932
  onchainSendRequest({
1931
1933
  rfqId,
@@ -2870,7 +2872,11 @@ var init_rfq = __esm({
2870
2872
  return { contractParams, matched };
2871
2873
  };
2872
2874
  provisionReceive = async (wallet, params, persistBefore) => {
2873
- const secrets = await (0, import_sdk7.provisionClaimSecret)(wallet);
2875
+ const [secrets, info, payoutAddress] = await Promise.all([
2876
+ (0, import_sdk7.provisionClaimSecret)(wallet),
2877
+ wallet.getArkadeInfo({ requireLive: true }),
2878
+ wallet.getAddress()
2879
+ ]);
2874
2880
  if (secrets.mustPersistPreimage) {
2875
2881
  console.warn(
2876
2882
  `[swap] this swap's preimage cannot be re-derived from the seed and MUST be persisted with the record before ${persistBefore}`
@@ -2879,10 +2885,6 @@ var init_rfq = __esm({
2879
2885
  const preimage = secrets.preimage;
2880
2886
  const paymentHash = import_base6.hex.encode(secrets.paymentHash);
2881
2887
  const payoutPubkey = secrets.pubkey;
2882
- const [info, payoutAddress] = await Promise.all([
2883
- wallet.getArkadeInfo({ requireLive: true }),
2884
- wallet.getAddress()
2885
- ]);
2886
2888
  const binds = bindsClaimAmount();
2887
2889
  const claimPacket = params.covclaimdPubkey && (!binds || params.amountSide === "to") ? await sealClaimPacket({
2888
2890
  preimage,
@@ -3475,7 +3477,8 @@ async function findLockupVtxos(contracts, swapPkScript) {
3475
3477
  txid: vtxo.txid,
3476
3478
  vout: vtxo.vout,
3477
3479
  value: Number(vtxo.value),
3478
- recoverable: vtxo.isSwept
3480
+ recoverable: vtxo.isSwept,
3481
+ ...vtxo.assets?.length ? { assets: vtxo.assets } : {}
3479
3482
  });
3480
3483
  }
3481
3484
  return out;
@@ -3485,17 +3488,17 @@ var candidateWitnessItems = (tx, inputIndex) => [
3485
3488
  ...(0, import_sdk8.getArkPsbtFields)(tx, inputIndex, import_sdk8.ConditionWitness).flat(),
3486
3489
  ...tx.getInput(inputIndex).finalScriptWitness ?? []
3487
3490
  ];
3488
- var spendsRefundLeaf = (tx, inputIndex) => {
3491
+ var refundLeafScript = (tx, inputIndex) => {
3489
3492
  const input = tx.getInput(inputIndex);
3490
3493
  const witness = input.finalScriptWitness;
3491
3494
  const leaves = input.tapLeafScript ?? [];
3492
3495
  const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0, import_sdk8.scriptFromTapLeafScript)(leaves[0]) : void 0;
3493
- if (!script) return false;
3496
+ if (!script) return void 0;
3494
3497
  try {
3495
3498
  const { type } = (0, import_sdk8.decodeTapscript)(script);
3496
- return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig";
3499
+ return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig" ? script : void 0;
3497
3500
  } catch {
3498
- return false;
3501
+ return void 0;
3499
3502
  }
3500
3503
  };
3501
3504
  async function readLockupFate(indexer, input) {
@@ -3528,6 +3531,7 @@ async function readLockupFate(indexer, input) {
3528
3531
  const spends = [...spentBy.values()];
3529
3532
  const { txs } = await indexer.getVirtualTxs([...spentBy.keys()]);
3530
3533
  const refunded = /* @__PURE__ */ new Set();
3534
+ const leafScripts = /* @__PURE__ */ new Set();
3531
3535
  for (const raw of txs) {
3532
3536
  let tx;
3533
3537
  try {
@@ -3549,11 +3553,15 @@ async function readLockupFate(indexer, input) {
3549
3553
  return { fate: "claimed", preimage: candidate, spends };
3550
3554
  }
3551
3555
  }
3552
- if (spendsRefundLeaf(tx, i)) refunded.add(`${vtxo.txid}:${vtxo.vout}`);
3556
+ const leafScript = refundLeafScript(tx, i);
3557
+ if (leafScript) {
3558
+ refunded.add(`${vtxo.txid}:${vtxo.vout}`);
3559
+ leafScripts.add(import_base7.hex.encode(leafScript));
3560
+ }
3553
3561
  }
3554
3562
  }
3555
3563
  if (sweptLeft) return { fate: "open" };
3556
- return everySpendNamed && all.every((vtxo) => refunded.has(`${vtxo.txid}:${vtxo.vout}`)) ? { fate: "returned", spends } : { fate: "unknown" };
3564
+ return everySpendNamed && all.every((vtxo) => refunded.has(`${vtxo.txid}:${vtxo.vout}`)) ? { fate: "returned", spends, leafScripts: [...leafScripts] } : { fate: "unknown" };
3557
3565
  }
3558
3566
  var assertNoneSwept = (vtxos, contract) => {
3559
3567
  const swept = vtxos.filter((vtxo) => vtxo.recoverable);
@@ -3574,6 +3582,23 @@ var operatorUnrollScript = async (operator, network) => {
3574
3582
  };
3575
3583
  var MAX_LOCKUP_SPEND_INPUTS = 16;
3576
3584
  var boundedLockupSpend = (vtxos) => [...vtxos].sort((a, b) => b.value - a.value).slice(0, MAX_LOCKUP_SPEND_INPUTS);
3585
+ var lockupAssetOutputs = (vtxos) => {
3586
+ const inputs = /* @__PURE__ */ new Map();
3587
+ const totals = /* @__PURE__ */ new Map();
3588
+ vtxos.forEach((vtxo, vin) => {
3589
+ if (!vtxo.assets?.length) return;
3590
+ inputs.set(vin, [...vtxo.assets]);
3591
+ for (const { assetId, amount } of vtxo.assets) {
3592
+ totals.set(assetId, (totals.get(assetId) ?? 0n) + amount);
3593
+ }
3594
+ });
3595
+ if (inputs.size === 0) return [];
3596
+ const receiver = {
3597
+ address: "",
3598
+ assets: [...totals].map(([assetId, amount]) => ({ assetId, amount }))
3599
+ };
3600
+ return [import_sdk8.Extension.create([(0, import_sdk8.createAssetPacket)(inputs, [receiver])]).txOut()];
3601
+ };
3577
3602
  var lockupInputs = (vtxos, contract, leaf) => {
3578
3603
  const tapTree = contract.encode();
3579
3604
  return vtxos.map((vtxo) => ({
@@ -3599,7 +3624,7 @@ async function pushRefundWithoutReceiver(operator, input) {
3599
3624
  const amount = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
3600
3625
  const { arkTx: tx, checkpoints } = (0, import_sdk8.buildOffchainTx)(
3601
3626
  lockupInputs(vtxos, input.contract, leaf),
3602
- [{ script: refundPkScript, amount: BigInt(amount) }],
3627
+ [{ script: refundPkScript, amount: BigInt(amount) }, ...lockupAssetOutputs(vtxos)],
3603
3628
  serverUnrollScript
3604
3629
  );
3605
3630
  const signedTx = await input.sender.sign(tx);
@@ -3645,6 +3670,7 @@ var RFQ_SWAP_ACTIVE_STATES = [
3645
3670
  "needs_counterparty"
3646
3671
  ];
3647
3672
  var isRfqSwapTerminal = (state) => RFQ_SWAP_TERMINAL_STATES.includes(state);
3673
+ var isRecheckableRefundedSend = (record) => record.kind === "lightning_send" && record.state === "refunded" && !record.refundTxid;
3648
3674
 
3649
3675
  // src/rfqRecord.ts
3650
3676
  init_rfqCorridor();
@@ -4216,6 +4242,46 @@ var RfqSwapManager = class _RfqSwapManager {
4216
4242
  }
4217
4243
  return { restored, failed, pruned: [] };
4218
4244
  }
4245
+ /**
4246
+ * Re-read stored `refunded` Lightning sends with no refund txid, one at a time. A misread
4247
+ * could have ended a settled send this way: a `claimed` read settles the record, any other
4248
+ * answer, or a failure, leaves it untouched. Returns the swaps it settled in every sink; one
4249
+ * a sink refused stays monitored for the poll to retry. `stopped` is checked before each
4250
+ * record and before each write, so a caller can walk away mid-run.
4251
+ */
4252
+ async recheckRefundedSends(options = {}) {
4253
+ const repository = this.requireRepository("recheckRefundedSends");
4254
+ const params = options.params ?? this.paramsFromContracts();
4255
+ const settled = [];
4256
+ for (const record of await collectRfqSwaps(repository, { state: "refunded" })) {
4257
+ if (options.stopped?.()) break;
4258
+ if (!isRecheckableRefundedSend(record) || this.monitored.has(record.rfqId)) continue;
4259
+ const removedAt = this.removed.get(record.rfqId);
4260
+ try {
4261
+ const swap = rebuildRfqSwap(record, await params(record));
4262
+ const fate = await readLockupFate(this.deps.indexer, {
4263
+ swapPkScript: swap.lockupPkScript,
4264
+ paymentHash: swap.paymentHash
4265
+ });
4266
+ if (options.stopped?.()) break;
4267
+ if (fate.fate !== "claimed") continue;
4268
+ if (this.monitored.has(record.rfqId)) continue;
4269
+ if (this.removed.get(record.rfqId) !== removedAt) continue;
4270
+ delete swap.lockupSpendTxids;
4271
+ this.stampLockupSpends(swap, fate.spends);
4272
+ this.stampSettlementPreimage(swap, fate.preimage);
4273
+ this.setState(swap, "settled");
4274
+ if (await this.save(swap)) {
4275
+ this.dirty.delete(swap.rfqId);
4276
+ settled.push(swap);
4277
+ } else {
4278
+ this.track(swap);
4279
+ }
4280
+ } catch {
4281
+ }
4282
+ }
4283
+ return settled;
4284
+ }
4219
4285
  /**
4220
4286
  * Drop stored records that are terminal and past `RFQ_SWAP_RETENTION_SECONDS` (per
4221
4287
  * `shouldRetainRfqSwap`), and return their ids. Explicit only: restore keeps history.
@@ -4582,6 +4648,7 @@ var RfqSwapManager = class _RfqSwapManager {
4582
4648
  * finalization and the per-swap lock belong to `pollSwap`.
4583
4649
  */
4584
4650
  async runPass(swap) {
4651
+ if (isRfqSwapTerminal(swap.state)) return;
4585
4652
  await this.ensureRegistered(swap);
4586
4653
  let fate;
4587
4654
  try {
@@ -4593,6 +4660,11 @@ var RfqSwapManager = class _RfqSwapManager {
4593
4660
  } catch {
4594
4661
  fate = { fate: "unknown" };
4595
4662
  }
4663
+ if ((swap.kind === "lightning_send" || swap.kind === "onchain_send") && fate.fate === "returned" && this.config.now() < swap.refundLocktime && !fate.leafScripts.every(
4664
+ (script) => script === swap.lockup?.script.nonInteractiveRefundScript
4665
+ )) {
4666
+ fate = { fate: "unknown" };
4667
+ }
4596
4668
  if (swap.kind === "onchain_receive") return this.driveOnchainReceive(swap, fate);
4597
4669
  if (fate.fate === "claimed" || fate.fate === "returned") {
4598
4670
  this.stampLockupSpends(swap, fate.spends);
@@ -5546,8 +5618,7 @@ var chainSourceFrom = (provider, network) => {
5546
5618
  }));
5547
5619
  },
5548
5620
  async getSpendingTx(txid, vout, pkScript) {
5549
- const outspends = await provider.getTxOutspends(txid);
5550
- const outspend = outspends[vout];
5621
+ const outspend = provider.getTxOutspend ? await provider.getTxOutspend(txid, vout) : (await provider.getTxOutspends(txid))[vout];
5551
5622
  if (!outspend?.spent) return null;
5552
5623
  const spender = outspend.txid || await spenderFromHistory(txid, vout, pkScript);
5553
5624
  if (!spender) return null;
@@ -5611,7 +5682,10 @@ async function pushClaim(operator, input) {
5611
5682
  provider: operator,
5612
5683
  inputs: lockupInputs(vtxos, input.contract, leaf),
5613
5684
  // One aggregate output: this leaf inspects nothing about the output set.
5614
- outputs: [{ script: input.destinationPkScript, amount: BigInt(locked) }],
5685
+ outputs: [
5686
+ { script: input.destinationPkScript, amount: BigInt(locked) },
5687
+ ...lockupAssetOutputs(vtxos)
5688
+ ],
5615
5689
  serverUnrollScript,
5616
5690
  verifyServerSignatures: { serverPubkey: input.contract.options.server }
5617
5691
  });
@@ -6142,7 +6216,7 @@ function solverOnchainRail(deps) {
6142
6216
  const rendezvous = await rendezvousFor(amount);
6143
6217
  if (!rendezvous) {
6144
6218
  throw new Error(
6145
- `${SOLVER_ONCHAIN_RAIL}: no solver serves arkade:BTC -> onchain:BTC at ${amount} sats`
6219
+ `${SOLVER_ONCHAIN_RAIL}: no solver serves onchain payments at ${amount} sats`
6146
6220
  );
6147
6221
  }
6148
6222
  const negotiated = await deps.connect(
@@ -6245,7 +6319,7 @@ function solverLightningRail(deps) {
6245
6319
  const rendezvous = await rendezvousFor(facts.amountSats);
6246
6320
  if (!rendezvous) {
6247
6321
  throw new Error(
6248
- `${SOLVER_LIGHTNING_RAIL}: no solver serves arkade:BTC -> lightning:BTC at ${facts.amountSats} sats`
6322
+ `${SOLVER_LIGHTNING_RAIL}: no solver serves Lightning payments at ${facts.amountSats} sats`
6249
6323
  );
6250
6324
  }
6251
6325
  const negotiated = await deps.connect(
@@ -1,13 +1,13 @@
1
1
  import { ProvisionedKey, ProvisionedClaimSecret, RestIndexerProvider, Transaction, ActivityResolver, IWallet, Network, OnchainProvider, VHTLC, Identity, Asset, PaymentRail } from '@arkade-os/sdk';
2
- import { bh as SwapSecretsProjection, e as RfqSwapRecord, h as AssetSwap, d as AssetSwapRepository, L as LockupSpendIndexer, bb as RfqSwapState, bd as SwapOperator, bi as LockupContractSource, bj as RfqSwap, bk as ArkadeRefundResult, bl as LockupVtxo } from './repository-DqdLVrVv.cjs';
3
- export { c as AssetSwapStatus, bm as AvailableRfqSwapManagerCallbacks, bn as BTC_ASSET_ID, bo as LightningReceiveSwap, bp as LightningSendSwap, bq as LockupFate, br as LockupNeedsRecoveryError, bs as LockupParams, bt as LockupSpend, bu as OnchainReceiveAction, bv as OnchainReceiveNeedsChainSource, bw as OnchainReceiveSwap, bx as OnchainSendAction, by as OnchainSendSwap, bz as PersistableRfqSwap, bA as PreimageBlockedReason, bB as PreimageNotRecoverableError, bC as REFUND_MTP_LAG_SECONDS, bD as RFQ_SWAP_RETENTION_SECONDS, bE as ReceiveLockupSwap, bF as RfqRestoreFailure, bG as RfqRestoreOptions, bH as RfqRestoreResult, bg as RfqSwapActionName, bI as RfqSwapLockup, bJ as RfqSwapManager, bf as RfqSwapManagerCallbacks, bK as RfqSwapManagerConfig, bL as RfqSwapManagerDeps, bM as RfqSwapManagerEvents, bN as RfqSwapOrigin, bO as RfqSwapOriginRequired, bP as RfqSwapOutcome, a as RfqSwapRecordStore, bQ as addAssetSwap, bR as awaitRfqResolution, bS as createRfqSwapRecord, bT as findLockupVtxos, bU as getAssetSwaps, bV as isRfqTerminal, bW as nextOnchainAction, bX as nextOnchainReceiveAction, bY as normalizeRfqSwapRecord, bZ as preimageForSwapRecord, b_ as pushRefundWithoutReceiver, b$ as readLockupFate, c0 as rebuildRfqSwap, c1 as rfqSwapOriginOf, c2 as shouldRetainRfqSwap, c3 as swapSecretsToRecord, c4 as updateAssetSwap, c5 as updateRfqSwapRecord } from './repository-DqdLVrVv.cjs';
2
+ import { bh as SwapSecretsProjection, e as RfqSwapRecord, h as AssetSwap, d as AssetSwapRepository, L as LockupSpendIndexer, bb as RfqSwapState, bd as SwapOperator, bi as LockupContractSource, bj as RfqSwap, bk as ArkadeRefundResult, bl as LockupVtxo } from './repository-C4pvymhs.cjs';
3
+ export { c as AssetSwapStatus, bm as AvailableRfqSwapManagerCallbacks, bn as BTC_ASSET_ID, bo as LightningReceiveSwap, bp as LightningSendSwap, bq as LockupFate, br as LockupNeedsRecoveryError, bs as LockupParams, bt as LockupSpend, bu as OnchainReceiveAction, bv as OnchainReceiveNeedsChainSource, bw as OnchainReceiveSwap, bx as OnchainSendAction, by as OnchainSendSwap, bz as PersistableRfqSwap, bA as PreimageBlockedReason, bB as PreimageNotRecoverableError, bC as REFUND_MTP_LAG_SECONDS, bD as RFQ_SWAP_RETENTION_SECONDS, bE as ReceiveLockupSwap, bF as RfqRestoreFailure, bG as RfqRestoreOptions, bH as RfqRestoreResult, bg as RfqSwapActionName, bI as RfqSwapLockup, bJ as RfqSwapManager, bf as RfqSwapManagerCallbacks, bK as RfqSwapManagerConfig, bL as RfqSwapManagerDeps, bM as RfqSwapManagerEvents, bN as RfqSwapOrigin, bO as RfqSwapOriginRequired, bP as RfqSwapOutcome, a as RfqSwapRecordStore, bQ as addAssetSwap, bR as awaitRfqResolution, bS as createRfqSwapRecord, bT as findLockupVtxos, bU as getAssetSwaps, bV as isRfqTerminal, bW as nextOnchainAction, bX as nextOnchainReceiveAction, bY as normalizeRfqSwapRecord, bZ as preimageForSwapRecord, b_ as pushRefundWithoutReceiver, b$ as readLockupFate, c0 as rebuildRfqSwap, c1 as rfqSwapOriginOf, c2 as shouldRetainRfqSwap, c3 as swapSecretsToRecord, c4 as updateAssetSwap, c5 as updateRfqSwapRecord } from './repository-C4pvymhs.cjs';
4
4
  import { h as OnchainNetwork, O as OnchainHtlc, g as OnchainHtlcParams, C as ChainSource, I as InvoiceFacts, e as RfqTransport, r as requestLightningSend, j as requestOnchainSend } from './rfq-C0tHOvn6.cjs';
5
5
  export { A as ARKADE_BTC, k as AddressMismatch, l as ChainUtxo, H as HtlcUtxo, m as LIGHTNING_BTC, n as LIGHTNING_RECEIVE_PAIR, o as LIGHTNING_SEND_PAIR, p as LOCKTIME_THRESHOLD, f as LightningReceiveContractParams, L as LightningSendContractParams, M as MAX_MIN_CONFIRMATIONS, q as MIN_CLAIM_WINDOW_SECONDS, s as ONCHAIN_BTC, t as ONCHAIN_CLAIM_MARGIN_SECONDS, u as ONCHAIN_DUST_SATS, v as ONCHAIN_ORDER_MARGIN_SECONDS, w as ONCHAIN_RECEIVE_PAIR, x as ONCHAIN_SECONDS_PER_BLOCK, y as ONCHAIN_SEND_PAIR, z as OnchainHtlcPhase, B as RelaySocket, R as RfqQuote, D as RfqRefusalReason, E as RfqStatus, F as arkadeAssetLeg, G as arkadeSwapRequest, J as assertArkadeFundable, K as awaitOnchainFill, N as buildHtlcClaim, P as buildHtlcRefund, Q as canonicalAssetAmount, U as claimOnchainFill, V as classifyOnchainHtlc, W as deriveLightningReceive, X as deriveOnchainReceive, Y as deriveOnchainSend, Z as extractPreimage, _ as httpTransport, $ as l1ScriptForAddress, a0 as lightningReceiveContract, a1 as lightningReceiveRequest, a2 as lightningSendContract, a3 as lightningSendRequest, a4 as newPreimage, a5 as normalizeMakerPkScript, a6 as normalizeMakerPublicKey, a7 as onchainHtlcScript, a8 as onchainReceiveRequest, a9 as onchainSendRequest, aa as paymentHashOf, ab as relayTransport, ac as requestArkadeSwap, ad as requestLightningReceive, ae as requestOnchainReceive, af as unilateralClaimDelay, ag as unilateralRefundDelay, ah as unilateralRefundWithoutReceiverDelay, ai as verifyLockupAddress, aj as verifyOfferAddress, ak as verifyReceiveInvoice } from './rfq-C0tHOvn6.cjs';
6
- export { d as ClaimPacketInput, e as LockupContractMissing, f as LockupContractReader, g as LockupContractWriter, h as SWAP_LOCKUP_CONTRACT_KIND, i as SWAP_LOCKUP_CONTRACT_LABEL, j as SWAP_LOCKUP_CONTRACT_TYPE, k as SealedClaimPacket, l as lockupContractParams, r as registerLockupContract, s as sealClaimPacket } from './lockupContract-G-9CNRMq.cjs';
6
+ export { d as ClaimPacketInput, e as LockupContractMissing, f as LockupContractReader, g as LockupContractWriter, h as SWAP_LOCKUP_CONTRACT_KIND, i as SWAP_LOCKUP_CONTRACT_LABEL, j as SWAP_LOCKUP_CONTRACT_TYPE, k as SealedClaimPacket, l as lockupContractParams, r as registerLockupContract, s as sealClaimPacket } from './lockupContract-CkhWMKCo.cjs';
7
7
  import { Network as Network$1, LocalCardInput, TransportCardFetcher, DiscoveredMarket, Side, OfferPlan } from '@arkade-os/solver-discovery';
8
- import { O as Offer } from './offer-CcJfx5Fj.cjs';
9
- export { A as ASSET_CARRIER_SATS, F as FillFunding, a as FillOutpoint, N as NoSpendableDepositError, c as OFFER_PACKET_TYPE, d as OfferCovenantMismatchError, e as cancelOffer, f as createOffer, g as decodeOffer, h as encodeOffer, i as fillOffer, o as offerContract, j as offerVtxoScript, s as swapPrograms } from './offer-CcJfx5Fj.cjs';
10
- export { c as OfferSwapWatcher, W as WatchOfferSwapsParams, w as watchOfferSwaps } from './watch-BonYT9af.cjs';
8
+ import { O as Offer } from './offer-Diff5Flc.cjs';
9
+ export { A as ASSET_CARRIER_SATS, F as FillFunding, a as FillOutpoint, N as NoSpendableDepositError, c as OFFER_PACKET_TYPE, d as OfferCovenantMismatchError, e as cancelOffer, f as createOffer, g as decodeOffer, h as encodeOffer, i as fillOffer, o as offerContract, j as offerVtxoScript, s as swapPrograms } from './offer-Diff5Flc.cjs';
10
+ export { c as OfferSwapWatcher, W as WatchOfferSwapsParams, w as watchOfferSwaps } from './watch-Bxq-lx_6.cjs';
11
11
 
12
12
  /** Which wallet key signs this leg, at `profile.signer`. Omitted entirely (not blank) by a corridor
13
13
  * whose leg this wallet never signs. */
@@ -1,13 +1,13 @@
1
1
  import { ProvisionedKey, ProvisionedClaimSecret, RestIndexerProvider, Transaction, ActivityResolver, IWallet, Network, OnchainProvider, VHTLC, Identity, Asset, PaymentRail } from '@arkade-os/sdk';
2
- import { bh as SwapSecretsProjection, e as RfqSwapRecord, h as AssetSwap, d as AssetSwapRepository, L as LockupSpendIndexer, bb as RfqSwapState, bd as SwapOperator, bi as LockupContractSource, bj as RfqSwap, bk as ArkadeRefundResult, bl as LockupVtxo } from './repository-DmPzpbd7.js';
3
- export { c as AssetSwapStatus, bm as AvailableRfqSwapManagerCallbacks, bn as BTC_ASSET_ID, bo as LightningReceiveSwap, bp as LightningSendSwap, bq as LockupFate, br as LockupNeedsRecoveryError, bs as LockupParams, bt as LockupSpend, bu as OnchainReceiveAction, bv as OnchainReceiveNeedsChainSource, bw as OnchainReceiveSwap, bx as OnchainSendAction, by as OnchainSendSwap, bz as PersistableRfqSwap, bA as PreimageBlockedReason, bB as PreimageNotRecoverableError, bC as REFUND_MTP_LAG_SECONDS, bD as RFQ_SWAP_RETENTION_SECONDS, bE as ReceiveLockupSwap, bF as RfqRestoreFailure, bG as RfqRestoreOptions, bH as RfqRestoreResult, bg as RfqSwapActionName, bI as RfqSwapLockup, bJ as RfqSwapManager, bf as RfqSwapManagerCallbacks, bK as RfqSwapManagerConfig, bL as RfqSwapManagerDeps, bM as RfqSwapManagerEvents, bN as RfqSwapOrigin, bO as RfqSwapOriginRequired, bP as RfqSwapOutcome, a as RfqSwapRecordStore, bQ as addAssetSwap, bR as awaitRfqResolution, bS as createRfqSwapRecord, bT as findLockupVtxos, bU as getAssetSwaps, bV as isRfqTerminal, bW as nextOnchainAction, bX as nextOnchainReceiveAction, bY as normalizeRfqSwapRecord, bZ as preimageForSwapRecord, b_ as pushRefundWithoutReceiver, b$ as readLockupFate, c0 as rebuildRfqSwap, c1 as rfqSwapOriginOf, c2 as shouldRetainRfqSwap, c3 as swapSecretsToRecord, c4 as updateAssetSwap, c5 as updateRfqSwapRecord } from './repository-DmPzpbd7.js';
2
+ import { bh as SwapSecretsProjection, e as RfqSwapRecord, h as AssetSwap, d as AssetSwapRepository, L as LockupSpendIndexer, bb as RfqSwapState, bd as SwapOperator, bi as LockupContractSource, bj as RfqSwap, bk as ArkadeRefundResult, bl as LockupVtxo } from './repository-BBVRh9ez.js';
3
+ export { c as AssetSwapStatus, bm as AvailableRfqSwapManagerCallbacks, bn as BTC_ASSET_ID, bo as LightningReceiveSwap, bp as LightningSendSwap, bq as LockupFate, br as LockupNeedsRecoveryError, bs as LockupParams, bt as LockupSpend, bu as OnchainReceiveAction, bv as OnchainReceiveNeedsChainSource, bw as OnchainReceiveSwap, bx as OnchainSendAction, by as OnchainSendSwap, bz as PersistableRfqSwap, bA as PreimageBlockedReason, bB as PreimageNotRecoverableError, bC as REFUND_MTP_LAG_SECONDS, bD as RFQ_SWAP_RETENTION_SECONDS, bE as ReceiveLockupSwap, bF as RfqRestoreFailure, bG as RfqRestoreOptions, bH as RfqRestoreResult, bg as RfqSwapActionName, bI as RfqSwapLockup, bJ as RfqSwapManager, bf as RfqSwapManagerCallbacks, bK as RfqSwapManagerConfig, bL as RfqSwapManagerDeps, bM as RfqSwapManagerEvents, bN as RfqSwapOrigin, bO as RfqSwapOriginRequired, bP as RfqSwapOutcome, a as RfqSwapRecordStore, bQ as addAssetSwap, bR as awaitRfqResolution, bS as createRfqSwapRecord, bT as findLockupVtxos, bU as getAssetSwaps, bV as isRfqTerminal, bW as nextOnchainAction, bX as nextOnchainReceiveAction, bY as normalizeRfqSwapRecord, bZ as preimageForSwapRecord, b_ as pushRefundWithoutReceiver, b$ as readLockupFate, c0 as rebuildRfqSwap, c1 as rfqSwapOriginOf, c2 as shouldRetainRfqSwap, c3 as swapSecretsToRecord, c4 as updateAssetSwap, c5 as updateRfqSwapRecord } from './repository-BBVRh9ez.js';
4
4
  import { h as OnchainNetwork, O as OnchainHtlc, g as OnchainHtlcParams, C as ChainSource, I as InvoiceFacts, e as RfqTransport, r as requestLightningSend, j as requestOnchainSend } from './rfq-C0tHOvn6.js';
5
5
  export { A as ARKADE_BTC, k as AddressMismatch, l as ChainUtxo, H as HtlcUtxo, m as LIGHTNING_BTC, n as LIGHTNING_RECEIVE_PAIR, o as LIGHTNING_SEND_PAIR, p as LOCKTIME_THRESHOLD, f as LightningReceiveContractParams, L as LightningSendContractParams, M as MAX_MIN_CONFIRMATIONS, q as MIN_CLAIM_WINDOW_SECONDS, s as ONCHAIN_BTC, t as ONCHAIN_CLAIM_MARGIN_SECONDS, u as ONCHAIN_DUST_SATS, v as ONCHAIN_ORDER_MARGIN_SECONDS, w as ONCHAIN_RECEIVE_PAIR, x as ONCHAIN_SECONDS_PER_BLOCK, y as ONCHAIN_SEND_PAIR, z as OnchainHtlcPhase, B as RelaySocket, R as RfqQuote, D as RfqRefusalReason, E as RfqStatus, F as arkadeAssetLeg, G as arkadeSwapRequest, J as assertArkadeFundable, K as awaitOnchainFill, N as buildHtlcClaim, P as buildHtlcRefund, Q as canonicalAssetAmount, U as claimOnchainFill, V as classifyOnchainHtlc, W as deriveLightningReceive, X as deriveOnchainReceive, Y as deriveOnchainSend, Z as extractPreimage, _ as httpTransport, $ as l1ScriptForAddress, a0 as lightningReceiveContract, a1 as lightningReceiveRequest, a2 as lightningSendContract, a3 as lightningSendRequest, a4 as newPreimage, a5 as normalizeMakerPkScript, a6 as normalizeMakerPublicKey, a7 as onchainHtlcScript, a8 as onchainReceiveRequest, a9 as onchainSendRequest, aa as paymentHashOf, ab as relayTransport, ac as requestArkadeSwap, ad as requestLightningReceive, ae as requestOnchainReceive, af as unilateralClaimDelay, ag as unilateralRefundDelay, ah as unilateralRefundWithoutReceiverDelay, ai as verifyLockupAddress, aj as verifyOfferAddress, ak as verifyReceiveInvoice } from './rfq-C0tHOvn6.js';
6
- export { d as ClaimPacketInput, e as LockupContractMissing, f as LockupContractReader, g as LockupContractWriter, h as SWAP_LOCKUP_CONTRACT_KIND, i as SWAP_LOCKUP_CONTRACT_LABEL, j as SWAP_LOCKUP_CONTRACT_TYPE, k as SealedClaimPacket, l as lockupContractParams, r as registerLockupContract, s as sealClaimPacket } from './lockupContract-D7BNjksX.js';
6
+ export { d as ClaimPacketInput, e as LockupContractMissing, f as LockupContractReader, g as LockupContractWriter, h as SWAP_LOCKUP_CONTRACT_KIND, i as SWAP_LOCKUP_CONTRACT_LABEL, j as SWAP_LOCKUP_CONTRACT_TYPE, k as SealedClaimPacket, l as lockupContractParams, r as registerLockupContract, s as sealClaimPacket } from './lockupContract-CIXkJPxV.js';
7
7
  import { Network as Network$1, LocalCardInput, TransportCardFetcher, DiscoveredMarket, Side, OfferPlan } from '@arkade-os/solver-discovery';
8
- import { O as Offer } from './offer-DdB1M6FZ.js';
9
- export { A as ASSET_CARRIER_SATS, F as FillFunding, a as FillOutpoint, N as NoSpendableDepositError, c as OFFER_PACKET_TYPE, d as OfferCovenantMismatchError, e as cancelOffer, f as createOffer, g as decodeOffer, h as encodeOffer, i as fillOffer, o as offerContract, j as offerVtxoScript, s as swapPrograms } from './offer-DdB1M6FZ.js';
10
- export { c as OfferSwapWatcher, W as WatchOfferSwapsParams, w as watchOfferSwaps } from './watch-CmJQDtsy.js';
8
+ import { O as Offer } from './offer-BPD2ortO.js';
9
+ export { A as ASSET_CARRIER_SATS, F as FillFunding, a as FillOutpoint, N as NoSpendableDepositError, c as OFFER_PACKET_TYPE, d as OfferCovenantMismatchError, e as cancelOffer, f as createOffer, g as decodeOffer, h as encodeOffer, i as fillOffer, o as offerContract, j as offerVtxoScript, s as swapPrograms } from './offer-BPD2ortO.js';
10
+ export { c as OfferSwapWatcher, W as WatchOfferSwapsParams, w as watchOfferSwaps } from './watch-7BiRa4oB.js';
11
11
 
12
12
  /** Which wallet key signs this leg, at `profile.signer`. Omitted entirely (not blank) by a corridor
13
13
  * whose leg this wallet never signs. */
package/dist/protocol.js CHANGED
@@ -42,7 +42,7 @@ import {
42
42
  validatePlan,
43
43
  watchMarkets,
44
44
  watchOfferSwaps
45
- } from "./chunk-WKJFXXSR.js";
45
+ } from "./chunk-BLECLU5Q.js";
46
46
  import {
47
47
  ARKADE_BTC,
48
48
  ASSET_CARRIER_SATS,
@@ -128,7 +128,7 @@ import {
128
128
  verifyLockupAddress,
129
129
  verifyOfferAddress,
130
130
  verifyReceiveInvoice
131
- } from "./chunk-FMRAV77W.js";
131
+ } from "./chunk-ICSREL7N.js";
132
132
  import {
133
133
  collectRfqSwaps
134
134
  } from "./chunk-A3SHHRX4.js";
@@ -450,7 +450,7 @@ function solverOnchainRail(deps) {
450
450
  const rendezvous = await rendezvousFor(amount);
451
451
  if (!rendezvous) {
452
452
  throw new Error(
453
- `${SOLVER_ONCHAIN_RAIL}: no solver serves arkade:BTC -> onchain:BTC at ${amount} sats`
453
+ `${SOLVER_ONCHAIN_RAIL}: no solver serves onchain payments at ${amount} sats`
454
454
  );
455
455
  }
456
456
  const negotiated = await deps.connect(
@@ -553,7 +553,7 @@ function solverLightningRail(deps) {
553
553
  const rendezvous = await rendezvousFor(facts.amountSats);
554
554
  if (!rendezvous) {
555
555
  throw new Error(
556
- `${SOLVER_LIGHTNING_RAIL}: no solver serves arkade:BTC -> lightning:BTC at ${facts.amountSats} sats`
556
+ `${SOLVER_LIGHTNING_RAIL}: no solver serves Lightning payments at ${facts.amountSats} sats`
557
557
  );
558
558
  }
559
559
  const negotiated = await deps.connect(
@@ -1,6 +1,6 @@
1
1
  import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
2
  import { PageRequest, PageResult } from '@arkade-os/sdk';
3
- import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-DqdLVrVv.cjs';
3
+ import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-C4pvymhs.cjs';
4
4
  import '@arkade-os/solver-discovery';
5
5
  import '../../rfq-C0tHOvn6.cjs';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
2
  import { PageRequest, PageResult } from '@arkade-os/sdk';
3
- import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-DmPzpbd7.js';
3
+ import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-BBVRh9ez.js';
4
4
  import '@arkade-os/solver-discovery';
5
5
  import '../../rfq-C0tHOvn6.js';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
2
  import { PageRequest, PageResult } from '@arkade-os/sdk';
3
- import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-DqdLVrVv.cjs';
3
+ import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-C4pvymhs.cjs';
4
4
  import '@arkade-os/solver-discovery';
5
5
  import '../../rfq-C0tHOvn6.cjs';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
2
  import { PageRequest, PageResult } from '@arkade-os/sdk';
3
- import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-DmPzpbd7.js';
3
+ import { d as AssetSwapRepository, h as AssetSwap, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, S as SwapRecord, b9 as MarketsCacheEntry } from '../../repository-BBVRh9ez.js';
4
4
  import '@arkade-os/solver-discovery';
5
5
  import '../../rfq-C0tHOvn6.js';
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { DiscoveredMarket } from '@arkade-os/solver-discovery';
2
- import { IWallet, ProvisionedKey, ProvisionedClaimSecret, ArkProvider, RestIndexerProvider, IContractManager, VHTLC, Identity, Network, InputExpiryFloor, NetworkName, asset, PageRequest, PageResult } from '@arkade-os/sdk';
2
+ import { IWallet, ProvisionedKey, ProvisionedClaimSecret, ArkProvider, Asset, RestIndexerProvider, IContractManager, VHTLC, Identity, Network, InputExpiryFloor, NetworkName, asset, PageRequest, PageResult } from '@arkade-os/sdk';
3
3
  import { e as RfqTransport, E as RfqStatus, O as OnchainHtlc, l as ChainUtxo, C as ChainSource, z as OnchainHtlcPhase } from './rfq-C0tHOvn6.js';
4
4
 
5
5
  /** @deprecated Use `Outcome`. Moved off the package root to `@arkade-os/swap/protocol`. */
@@ -155,6 +155,9 @@ interface LockupVtxo {
155
155
  * refuses these rather than submitting a doomed spend.
156
156
  */
157
157
  recoverable: boolean;
158
+ /** Absent on a sats-only output. Anyone can send an asset to the lockup address, and arkd
159
+ * refuses a spend that does not declare where it goes: see {@link lockupAssetOutputs}. */
160
+ assets?: readonly Asset[];
158
161
  }
159
162
  /**
160
163
  * Thrown when a refund was asked for over outputs that have been swept. Carries the outpoints so
@@ -227,10 +230,12 @@ type LockupFate =
227
230
  preimage: Uint8Array;
228
231
  spends: readonly LockupSpend[];
229
232
  }
230
- /** Every lockup output was spent through a recognized refund leaf. */
233
+ /** Every lockup output was spent through a recognized refund leaf. `leafScripts` are
234
+ * the distinct leaf scripts spent, hex. */
231
235
  | {
232
236
  fate: "returned";
233
237
  spends: readonly LockupSpend[];
238
+ leafScripts: readonly string[];
234
239
  }
235
240
  /**
236
241
  * At least one output was unilaterally exited: onchain under the VHTLC script, beyond any
@@ -898,6 +903,16 @@ declare class RfqSwapManager {
898
903
  * {@link RfqRestoreResult.failed}, never fatal to the others.
899
904
  */
900
905
  restoreFromRepository(options?: RfqRestoreOptions): Promise<RfqRestoreResult>;
906
+ /**
907
+ * Re-read stored `refunded` Lightning sends with no refund txid, one at a time. A misread
908
+ * could have ended a settled send this way: a `claimed` read settles the record, any other
909
+ * answer, or a failure, leaves it untouched. Returns the swaps it settled in every sink; one
910
+ * a sink refused stays monitored for the poll to retry. `stopped` is checked before each
911
+ * record and before each write, so a caller can walk away mid-run.
912
+ */
913
+ recheckRefundedSends(options?: Pick<RfqRestoreOptions, "params"> & {
914
+ stopped?: () => boolean;
915
+ }): Promise<RfqSwap[]>;
901
916
  /**
902
917
  * Drop stored records that are terminal and past `RFQ_SWAP_RETENTION_SECONDS` (per
903
918
  * `shouldRetainRfqSwap`), and return their ids. Explicit only: restore keeps history.
@@ -1,5 +1,5 @@
1
1
  import { DiscoveredMarket } from '@arkade-os/solver-discovery';
2
- import { IWallet, ProvisionedKey, ProvisionedClaimSecret, ArkProvider, RestIndexerProvider, IContractManager, VHTLC, Identity, Network, InputExpiryFloor, NetworkName, asset, PageRequest, PageResult } from '@arkade-os/sdk';
2
+ import { IWallet, ProvisionedKey, ProvisionedClaimSecret, ArkProvider, Asset, RestIndexerProvider, IContractManager, VHTLC, Identity, Network, InputExpiryFloor, NetworkName, asset, PageRequest, PageResult } from '@arkade-os/sdk';
3
3
  import { e as RfqTransport, E as RfqStatus, O as OnchainHtlc, l as ChainUtxo, C as ChainSource, z as OnchainHtlcPhase } from './rfq-C0tHOvn6.cjs';
4
4
 
5
5
  /** @deprecated Use `Outcome`. Moved off the package root to `@arkade-os/swap/protocol`. */
@@ -155,6 +155,9 @@ interface LockupVtxo {
155
155
  * refuses these rather than submitting a doomed spend.
156
156
  */
157
157
  recoverable: boolean;
158
+ /** Absent on a sats-only output. Anyone can send an asset to the lockup address, and arkd
159
+ * refuses a spend that does not declare where it goes: see {@link lockupAssetOutputs}. */
160
+ assets?: readonly Asset[];
158
161
  }
159
162
  /**
160
163
  * Thrown when a refund was asked for over outputs that have been swept. Carries the outpoints so
@@ -227,10 +230,12 @@ type LockupFate =
227
230
  preimage: Uint8Array;
228
231
  spends: readonly LockupSpend[];
229
232
  }
230
- /** Every lockup output was spent through a recognized refund leaf. */
233
+ /** Every lockup output was spent through a recognized refund leaf. `leafScripts` are
234
+ * the distinct leaf scripts spent, hex. */
231
235
  | {
232
236
  fate: "returned";
233
237
  spends: readonly LockupSpend[];
238
+ leafScripts: readonly string[];
234
239
  }
235
240
  /**
236
241
  * At least one output was unilaterally exited: onchain under the VHTLC script, beyond any
@@ -898,6 +903,16 @@ declare class RfqSwapManager {
898
903
  * {@link RfqRestoreResult.failed}, never fatal to the others.
899
904
  */
900
905
  restoreFromRepository(options?: RfqRestoreOptions): Promise<RfqRestoreResult>;
906
+ /**
907
+ * Re-read stored `refunded` Lightning sends with no refund txid, one at a time. A misread
908
+ * could have ended a settled send this way: a `claimed` read settles the record, any other
909
+ * answer, or a failure, leaves it untouched. Returns the swaps it settled in every sink; one
910
+ * a sink refused stays monitored for the poll to retry. `stopped` is checked before each
911
+ * record and before each write, so a caller can walk away mid-run.
912
+ */
913
+ recheckRefundedSends(options?: Pick<RfqRestoreOptions, "params"> & {
914
+ stopped?: () => boolean;
915
+ }): Promise<RfqSwap[]>;
901
916
  /**
902
917
  * Drop stored records that are terminal and past `RFQ_SWAP_RETENTION_SECONDS` (per
903
918
  * `shouldRetainRfqSwap`), and return their ids. Explicit only: restore keeps history.
@@ -1,5 +1,5 @@
1
1
  import { IWallet } from '@arkade-os/sdk';
2
- import { c as AssetSwapStatus, d as AssetSwapRepository, h as AssetSwap } from './repository-DmPzpbd7.js';
2
+ import { c as AssetSwapStatus, d as AssetSwapRepository, h as AssetSwap } from './repository-BBVRh9ez.js';
3
3
 
4
4
  /**
5
5
  * What this watcher needs to know about an offer swap, narrower than {@link AssetSwap}
@@ -1,5 +1,5 @@
1
1
  import { IWallet } from '@arkade-os/sdk';
2
- import { c as AssetSwapStatus, d as AssetSwapRepository, h as AssetSwap } from './repository-DqdLVrVv.cjs';
2
+ import { c as AssetSwapStatus, d as AssetSwapRepository, h as AssetSwap } from './repository-C4pvymhs.cjs';
3
3
 
4
4
  /**
5
5
  * What this watcher needs to know about an offer swap, narrower than {@link AssetSwap}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/swap",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Client-side Arkade Intents asset swaps: state a route, get an outcome. Pay a bolt11 invoice, receive over Lightning, exchange assets, or withdraw onchain.",
6
6
  "repository": {
@@ -104,7 +104,7 @@
104
104
  "@scure/base": "2.4.0",
105
105
  "@scure/btc-signer": "2.4.1",
106
106
  "light-bolt11-decoder": "3.2.0",
107
- "@arkade-os/sdk": "0.5.0"
107
+ "@arkade-os/sdk": "0.5.2"
108
108
  },
109
109
  "peerDependencies": {
110
110
  "nostr-tools": "2.24.1"