@satora/swap 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -551,7 +551,9 @@ declare class SwapTracker {
551
551
  * status hint drives. Reconciles just that swap's legs (targeted, on the
552
552
  * managers), then recomputes its action. The hint is only a *trigger*: the
553
553
  * chain stays the source of truth, so a premature hint that the chain doesn't
554
- * yet reflect changes nothing. A no-op for an untracked swap.
554
+ * yet reflect changes nothing, except that a hint saying the server's HTLC is
555
+ * funded is followed by a few more reads of that leg until the chain shows it.
556
+ * A no-op for an untracked swap.
555
557
  */
556
558
  applyHint(swapId: string, opts?: {
557
559
  force?: boolean;
@@ -728,8 +730,6 @@ declare class Client {
728
730
  /** Delegated to the legacy client (migration checkpoint). */
729
731
  getQuote(...args: Parameters<Client$1["getQuote"]>): ReturnType<Client$1["getQuote"]>;
730
732
  /** Delegated to the legacy client (migration checkpoint). */
731
- createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
732
- /** Delegated to the legacy client (migration checkpoint). */
733
733
  getLightningSendQuote(...args: Parameters<Client$1["getLightningSendQuote"]>): ReturnType<Client$1["getLightningSendQuote"]>;
734
734
  /** Delegated to the legacy client (migration checkpoint). */
735
735
  getSwap(...args: Parameters<Client$1["getSwap"]>): ReturnType<Client$1["getSwap"]>;
@@ -793,6 +793,8 @@ declare class Client {
793
793
  /** Delegated to the legacy client (migration checkpoint). */
794
794
  createArkadeToLightningSwap(...args: Parameters<Client$1["createArkadeToLightningSwap"]>): ReturnType<Client$1["createArkadeToLightningSwap"]>;
795
795
  /** Delegated to the legacy client (migration checkpoint). */
796
+ createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
797
+ /** Delegated to the legacy client (migration checkpoint). */
796
798
  createLightningToBitcoinSwap(...args: Parameters<Client$1["createLightningToBitcoinSwap"]>): ReturnType<Client$1["createLightningToBitcoinSwap"]>;
797
799
  /** Delegated to the legacy client (migration checkpoint). */
798
800
  createBitcoinToLightningSwap(...args: Parameters<Client$1["createBitcoinToLightningSwap"]>): ReturnType<Client$1["createBitcoinToLightningSwap"]>;
package/dist/index.d.ts CHANGED
@@ -551,7 +551,9 @@ declare class SwapTracker {
551
551
  * status hint drives. Reconciles just that swap's legs (targeted, on the
552
552
  * managers), then recomputes its action. The hint is only a *trigger*: the
553
553
  * chain stays the source of truth, so a premature hint that the chain doesn't
554
- * yet reflect changes nothing. A no-op for an untracked swap.
554
+ * yet reflect changes nothing, except that a hint saying the server's HTLC is
555
+ * funded is followed by a few more reads of that leg until the chain shows it.
556
+ * A no-op for an untracked swap.
555
557
  */
556
558
  applyHint(swapId: string, opts?: {
557
559
  force?: boolean;
@@ -728,8 +730,6 @@ declare class Client {
728
730
  /** Delegated to the legacy client (migration checkpoint). */
729
731
  getQuote(...args: Parameters<Client$1["getQuote"]>): ReturnType<Client$1["getQuote"]>;
730
732
  /** Delegated to the legacy client (migration checkpoint). */
731
- createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
732
- /** Delegated to the legacy client (migration checkpoint). */
733
733
  getLightningSendQuote(...args: Parameters<Client$1["getLightningSendQuote"]>): ReturnType<Client$1["getLightningSendQuote"]>;
734
734
  /** Delegated to the legacy client (migration checkpoint). */
735
735
  getSwap(...args: Parameters<Client$1["getSwap"]>): ReturnType<Client$1["getSwap"]>;
@@ -793,6 +793,8 @@ declare class Client {
793
793
  /** Delegated to the legacy client (migration checkpoint). */
794
794
  createArkadeToLightningSwap(...args: Parameters<Client$1["createArkadeToLightningSwap"]>): ReturnType<Client$1["createArkadeToLightningSwap"]>;
795
795
  /** Delegated to the legacy client (migration checkpoint). */
796
+ createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
797
+ /** Delegated to the legacy client (migration checkpoint). */
796
798
  createLightningToBitcoinSwap(...args: Parameters<Client$1["createLightningToBitcoinSwap"]>): ReturnType<Client$1["createLightningToBitcoinSwap"]>;
797
799
  /** Delegated to the legacy client (migration checkpoint). */
798
800
  createBitcoinToLightningSwap(...args: Parameters<Client$1["createBitcoinToLightningSwap"]>): ReturnType<Client$1["createBitcoinToLightningSwap"]>;
package/dist/index.js CHANGED
@@ -2166,6 +2166,13 @@ var CLAIM_SUBMITTED = /* @__PURE__ */ new Set([
2166
2166
  "clientredeemed",
2167
2167
  "serverredeemed"
2168
2168
  ]);
2169
+ var SERVER_LEG_FUNDED = /* @__PURE__ */ new Set([
2170
+ "serverfunded",
2171
+ "clientredeeming",
2172
+ "clientredeemed",
2173
+ "serverredeemed"
2174
+ ]);
2175
+ var HINT_REREAD_DELAYS_MS = [1e3, 2e3, 4e3, 8e3];
2169
2176
  var DEFAULT_AT_RISK_RECONCILE_INTERVAL_MS = 6e4;
2170
2177
  var RETRY_UNREGISTERED_INTERVAL_MS = 6e4;
2171
2178
  var SwapTracker = class {
@@ -2188,6 +2195,8 @@ var SwapTracker = class {
2188
2195
  #lastRetryAt = 0;
2189
2196
  #eventUnsubs = [];
2190
2197
  #timer;
2198
+ /** Pending follow-up read per swap, see {@link HINT_REREAD_DELAYS_MS}. */
2199
+ #hintRereads = /* @__PURE__ */ new Map();
2191
2200
  constructor(managers, options) {
2192
2201
  this.#managers = managers;
2193
2202
  this.#refreshIntervalMs = options?.refreshIntervalMs ?? 0;
@@ -2378,7 +2387,9 @@ var SwapTracker = class {
2378
2387
  * status hint drives. Reconciles just that swap's legs (targeted, on the
2379
2388
  * managers), then recomputes its action. The hint is only a *trigger*: the
2380
2389
  * chain stays the source of truth, so a premature hint that the chain doesn't
2381
- * yet reflect changes nothing. A no-op for an untracked swap.
2390
+ * yet reflect changes nothing, except that a hint saying the server's HTLC is
2391
+ * funded is followed by a few more reads of that leg until the chain shows it.
2392
+ * A no-op for an untracked swap.
2382
2393
  */
2383
2394
  async applyHint(swapId, opts) {
2384
2395
  const swap = this.#swaps.get(swapId);
@@ -2396,6 +2407,38 @@ var SwapTracker = class {
2396
2407
  );
2397
2408
  });
2398
2409
  this.#recompute(swap, opts?.force ?? false);
2410
+ this.#cancelHintReread(swapId);
2411
+ this.#rereadUntilServerLegSeen(swap, 0);
2412
+ }
2413
+ #rereadUntilServerLegSeen(swap, attempt) {
2414
+ const leg = swap.serverHtlc;
2415
+ const hint = this.#hintStatuses.get(swap.swapId);
2416
+ if (!leg || hint === void 0 || !SERVER_LEG_FUNDED.has(hint)) return;
2417
+ if (this.#swaps.get(swap.swapId) !== swap) return;
2418
+ const seen = this.#managerFor(leg).getState(leg);
2419
+ if (seen !== void 0 && seen !== "absent") return;
2420
+ const delay = HINT_REREAD_DELAYS_MS[attempt];
2421
+ if (delay === void 0) return;
2422
+ const timer = setTimeout(() => {
2423
+ this.#hintRereads.delete(swap.swapId);
2424
+ if (this.#swaps.get(swap.swapId) !== swap) return;
2425
+ void this.#managerFor(leg).reconcile(leg).catch((error) => {
2426
+ console.warn(
2427
+ `SwapTracker: re-read after hint failed for ${swap.swapId}:`,
2428
+ error
2429
+ );
2430
+ }).then(() => {
2431
+ this.#recompute(swap);
2432
+ if (!this.#hintRereads.has(swap.swapId))
2433
+ this.#rereadUntilServerLegSeen(swap, attempt + 1);
2434
+ });
2435
+ }, delay);
2436
+ this.#hintRereads.set(swap.swapId, timer);
2437
+ }
2438
+ #cancelHintReread(swapId) {
2439
+ const timer = this.#hintRereads.get(swapId);
2440
+ if (timer !== void 0) clearTimeout(timer);
2441
+ this.#hintRereads.delete(swapId);
2399
2442
  }
2400
2443
  /** Notify `cb` of the current action for each tracked swap, then on every change. */
2401
2444
  subscribeToActions(cb) {
@@ -2414,6 +2457,8 @@ var SwapTracker = class {
2414
2457
  stop() {
2415
2458
  if (this.#timer) clearInterval(this.#timer);
2416
2459
  this.#timer = void 0;
2460
+ for (const swapId of [...this.#hintRereads.keys()])
2461
+ this.#cancelHintReread(swapId);
2417
2462
  for (const unsub of this.#eventUnsubs) unsub();
2418
2463
  this.#eventUnsubs = [];
2419
2464
  for (const swap of this.#swaps.values())
@@ -2501,6 +2546,7 @@ var SwapTracker = class {
2501
2546
  if (actions.recommended === "none") this.#untrack(swap);
2502
2547
  }
2503
2548
  #untrack(swap) {
2549
+ this.#cancelHintReread(swap.swapId);
2504
2550
  this.#swaps.delete(swap.swapId);
2505
2551
  for (const leg of legsOf(swap)) void this.#managerFor(leg).unregister(leg);
2506
2552
  }
@@ -2674,10 +2720,6 @@ var Client = class {
2674
2720
  return this.#legacy.getQuote(...args);
2675
2721
  }
2676
2722
  /** Delegated to the legacy client (migration checkpoint). */
2677
- createLightningToEvmSwap(...args) {
2678
- return this.#legacy.createLightningToEvmSwap(...args);
2679
- }
2680
- /** Delegated to the legacy client (migration checkpoint). */
2681
2723
  getLightningSendQuote(...args) {
2682
2724
  return this.#legacy.getLightningSendQuote(...args);
2683
2725
  }
@@ -2813,6 +2855,12 @@ var Client = class {
2813
2855
  );
2814
2856
  }
2815
2857
  /** Delegated to the legacy client (migration checkpoint). */
2858
+ createLightningToEvmSwap(...args) {
2859
+ return this.#trackAfterCreate(
2860
+ this.#legacy.createLightningToEvmSwap(...args)
2861
+ );
2862
+ }
2863
+ /** Delegated to the legacy client (migration checkpoint). */
2816
2864
  createLightningToBitcoinSwap(...args) {
2817
2865
  return this.#trackAfterCreate(
2818
2866
  this.#legacy.createLightningToBitcoinSwap(...args)