@arkade-os/swap 0.0.22 → 0.0.23

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.
@@ -1,5 +1,5 @@
1
1
  import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
- import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, M as MarketsCacheEntry } from '../../repository-PNlTFdsj.js';
2
+ import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, b as RfqSwapState, c as RfqHistoryCursor, M as MarketsCacheEntry } from '../../repository-BT33JsPT.js';
3
3
  import '@arkade-os/solver-discovery';
4
4
  import '@arkade-os/sdk';
5
5
  import '../../rfq-B95nPfaa.js';
@@ -33,6 +33,8 @@ declare class RealmAssetSwapRepository implements AssetSwapRepository {
33
33
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
34
34
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
35
35
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
36
+ getRfqSwapsPage(state: RfqSwapState, afterId: string | undefined, limit: number): Promise<RfqSwapRecord[]>;
37
+ getRfqSwapsUpdatedPage(state: RfqSwapState, since: number, after: RfqHistoryCursor | undefined, limit: number): Promise<RfqSwapRecord[]>;
36
38
  removeRfqSwap(rfqId: string): Promise<void>;
37
39
  getScannedTxids(): Promise<Set<string>>;
38
40
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -1,6 +1,8 @@
1
1
  import {
2
+ assertRfqSwapPageLimit,
3
+ assertRfqSwapSince,
2
4
  marketsCacheKey
3
- } from "../../chunk-6ZUS47GA.js";
5
+ } from "../../chunk-PJF4DWD7.js";
4
6
 
5
7
  // src/repositories/realm/repository.ts
6
8
  var SWAPS = "ArkadeAssetSwap";
@@ -57,6 +59,36 @@ var RealmAssetSwapRepository = class {
57
59
  (o) => JSON.parse(o.data)
58
60
  );
59
61
  }
62
+ async getRfqSwapsPage(state, afterId, limit) {
63
+ assertRfqSwapPageLimit(limit);
64
+ const rows = this.realm.objects(RFQ_SWAPS).filtered("state == $0 AND rfqId > $1", state, afterId ?? "").sorted("rfqId");
65
+ const page = [];
66
+ for (const row of rows) {
67
+ page.push(JSON.parse(row.data));
68
+ if (page.length === limit) break;
69
+ }
70
+ return page;
71
+ }
72
+ async getRfqSwapsUpdatedPage(state, since, after, limit) {
73
+ assertRfqSwapPageLimit(limit);
74
+ assertRfqSwapSince(since);
75
+ const rows = after ? this.realm.objects(RFQ_SWAPS).filtered(
76
+ "state == $0 AND updatedAt >= $1 AND (updatedAt > $2 OR (updatedAt == $2 AND rfqId > $3))",
77
+ state,
78
+ since,
79
+ after.updatedAt,
80
+ after.rfqId
81
+ ) : this.realm.objects(RFQ_SWAPS).filtered("state == $0 AND updatedAt >= $1", state, since);
82
+ const page = [];
83
+ for (const row of rows.sorted([
84
+ ["updatedAt", false],
85
+ ["rfqId", false]
86
+ ])) {
87
+ page.push(JSON.parse(row.data));
88
+ if (page.length === limit) break;
89
+ }
90
+ return page;
91
+ }
60
92
  async removeRfqSwap(rfqId) {
61
93
  this.realm.write(() => {
62
94
  this.realm.delete(
@@ -28,6 +28,19 @@ module.exports = __toCommonJS(sqlite_exports);
28
28
  var import_sqlite = require("@arkade-os/sdk/repositories/sqlite");
29
29
 
30
30
  // src/repository.ts
31
+ var RFQ_SWAP_MAX_PAGE_SIZE = 500;
32
+ function assertRfqSwapPageLimit(limit) {
33
+ if (!Number.isInteger(limit) || limit < 1 || limit > RFQ_SWAP_MAX_PAGE_SIZE) {
34
+ throw new RangeError(
35
+ `RFQ swap page limit must be an integer from 1 to ${RFQ_SWAP_MAX_PAGE_SIZE}`
36
+ );
37
+ }
38
+ }
39
+ function assertRfqSwapSince(since) {
40
+ if (!Number.isSafeInteger(since) || since < 0) {
41
+ throw new RangeError("RFQ history since must be a non-negative Unix timestamp in seconds");
42
+ }
43
+ }
31
44
  var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
32
45
 
33
46
  // src/repositories/sqlite/repository.ts
@@ -88,6 +101,12 @@ var SQLiteAssetSwapRepository = class {
88
101
  await this.db.run(
89
102
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
90
103
  );
104
+ await this.db.run(
105
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
106
+ );
107
+ await this.db.run(
108
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_page ON ${this.rfqSwaps} (state, rfq_id)`
109
+ );
91
110
  await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.scanned} (txid TEXT PRIMARY KEY)`);
92
111
  await this.db.run(
93
112
  `CREATE TABLE IF NOT EXISTS ${this.markets} (cache_key TEXT PRIMARY KEY, data TEXT NOT NULL)`
@@ -141,6 +160,26 @@ var SQLiteAssetSwapRepository = class {
141
160
  const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
142
161
  return rows.map((r) => JSON.parse(r.data));
143
162
  }
163
+ async getRfqSwapsPage(state, afterId, limit) {
164
+ assertRfqSwapPageLimit(limit);
165
+ await this.ensureInit();
166
+ const rows = await this.db.all(
167
+ `SELECT data FROM ${this.rfqSwaps} WHERE state = ? AND rfq_id > ? ORDER BY rfq_id LIMIT ?`,
168
+ [state, afterId ?? "", limit]
169
+ );
170
+ return rows.map((row) => JSON.parse(row.data));
171
+ }
172
+ async getRfqSwapsUpdatedPage(state, since, after, limit) {
173
+ assertRfqSwapPageLimit(limit);
174
+ assertRfqSwapSince(since);
175
+ await this.ensureInit();
176
+ const cursor = after ? "AND (updated_at > ? OR (updated_at = ? AND rfq_id > ?))" : "";
177
+ const rows = await this.db.all(
178
+ `SELECT data FROM ${this.rfqSwaps} WHERE state = ? AND updated_at >= ? ${cursor} ORDER BY updated_at, rfq_id LIMIT ?`,
179
+ after ? [state, since, after.updatedAt, after.updatedAt, after.rfqId, limit] : [state, since, limit]
180
+ );
181
+ return rows.map((row) => JSON.parse(row.data));
182
+ }
144
183
  async removeRfqSwap(rfqId) {
145
184
  await this.ensureInit();
146
185
  await this.withTx(async () => {
@@ -1,5 +1,5 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
- import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, M as MarketsCacheEntry } from '../../repository-CZYc8Y38.cjs';
2
+ import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, b as RfqSwapState, c as RfqHistoryCursor, M as MarketsCacheEntry } from '../../repository-CSBh-0NH.cjs';
3
3
  import '@arkade-os/solver-discovery';
4
4
  import '@arkade-os/sdk';
5
5
  import '../../rfq-B95nPfaa.cjs';
@@ -61,6 +61,8 @@ declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
61
61
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
62
62
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
63
63
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
64
+ getRfqSwapsPage(state: RfqSwapState, afterId: string | undefined, limit: number): Promise<RfqSwapRecord[]>;
65
+ getRfqSwapsUpdatedPage(state: RfqSwapState, since: number, after: RfqHistoryCursor | undefined, limit: number): Promise<RfqSwapRecord[]>;
64
66
  removeRfqSwap(rfqId: string): Promise<void>;
65
67
  getScannedTxids(): Promise<Set<string>>;
66
68
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
- import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, M as MarketsCacheEntry } from '../../repository-PNlTFdsj.js';
2
+ import { A as AssetSwapRepository, a as AssetSwap, R as RfqSwapRecord, b as RfqSwapState, c as RfqHistoryCursor, M as MarketsCacheEntry } from '../../repository-BT33JsPT.js';
3
3
  import '@arkade-os/solver-discovery';
4
4
  import '@arkade-os/sdk';
5
5
  import '../../rfq-B95nPfaa.js';
@@ -61,6 +61,8 @@ declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
61
61
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
62
62
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
63
63
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
64
+ getRfqSwapsPage(state: RfqSwapState, afterId: string | undefined, limit: number): Promise<RfqSwapRecord[]>;
65
+ getRfqSwapsUpdatedPage(state: RfqSwapState, since: number, after: RfqHistoryCursor | undefined, limit: number): Promise<RfqSwapRecord[]>;
64
66
  removeRfqSwap(rfqId: string): Promise<void>;
65
67
  getScannedTxids(): Promise<Set<string>>;
66
68
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -1,6 +1,8 @@
1
1
  import {
2
+ assertRfqSwapPageLimit,
3
+ assertRfqSwapSince,
2
4
  marketsCacheKey
3
- } from "../../chunk-6ZUS47GA.js";
5
+ } from "../../chunk-PJF4DWD7.js";
4
6
 
5
7
  // src/repositories/sqlite/repository.ts
6
8
  import {
@@ -64,6 +66,12 @@ var SQLiteAssetSwapRepository = class {
64
66
  await this.db.run(
65
67
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
66
68
  );
69
+ await this.db.run(
70
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
71
+ );
72
+ await this.db.run(
73
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_page ON ${this.rfqSwaps} (state, rfq_id)`
74
+ );
67
75
  await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.scanned} (txid TEXT PRIMARY KEY)`);
68
76
  await this.db.run(
69
77
  `CREATE TABLE IF NOT EXISTS ${this.markets} (cache_key TEXT PRIMARY KEY, data TEXT NOT NULL)`
@@ -117,6 +125,26 @@ var SQLiteAssetSwapRepository = class {
117
125
  const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
118
126
  return rows.map((r) => JSON.parse(r.data));
119
127
  }
128
+ async getRfqSwapsPage(state, afterId, limit) {
129
+ assertRfqSwapPageLimit(limit);
130
+ await this.ensureInit();
131
+ const rows = await this.db.all(
132
+ `SELECT data FROM ${this.rfqSwaps} WHERE state = ? AND rfq_id > ? ORDER BY rfq_id LIMIT ?`,
133
+ [state, afterId ?? "", limit]
134
+ );
135
+ return rows.map((row) => JSON.parse(row.data));
136
+ }
137
+ async getRfqSwapsUpdatedPage(state, since, after, limit) {
138
+ assertRfqSwapPageLimit(limit);
139
+ assertRfqSwapSince(since);
140
+ await this.ensureInit();
141
+ const cursor = after ? "AND (updated_at > ? OR (updated_at = ? AND rfq_id > ?))" : "";
142
+ const rows = await this.db.all(
143
+ `SELECT data FROM ${this.rfqSwaps} WHERE state = ? AND updated_at >= ? ${cursor} ORDER BY updated_at, rfq_id LIMIT ?`,
144
+ after ? [state, since, after.updatedAt, after.updatedAt, after.rfqId, limit] : [state, since, limit]
145
+ );
146
+ return rows.map((row) => JSON.parse(row.data));
147
+ }
120
148
  async removeRfqSwap(rfqId) {
121
149
  await this.ensureInit();
122
150
  await this.withTx(async () => {
@@ -320,7 +320,7 @@ declare class LockupNeedsRecoveryError extends Error {
320
320
  *
321
321
  * ONE read from the registered contract row (getContractsWithVtxos), not from the indexer by script.
322
322
  * The row's isSwept flag is the authority on which outputs are swept-but-recoverable versus live-spendable,
323
- * and hasTerminalSpend prunes already-consumed outputs before they reach the caller.
323
+ * and isVtxoSpent prunes already-consumed outputs before they reach the caller.
324
324
  *
325
325
  * **Visible is not the same as refundable.** A `recoverable` output cannot be
326
326
  * spent offchain at all — see {@link LockupVtxo.recoverable} — so this set is
@@ -333,7 +333,7 @@ declare class LockupNeedsRecoveryError extends Error {
333
333
  * reach it, and `LockupVtxo` carries no field to say so, so a caller could not
334
334
  * tell it apart from a live one. The manager's rows carry the canonical facts
335
335
  * (`isUnrolled`, `isSpent`, `spentBy`, `settledBy`), so both exclusions are
336
- * exact rather than defensive — the same predicate (`hasTerminalSpend`) the
336
+ * exact rather than defensive — the same predicate (`isVtxoSpent`) the
337
337
  * wallet's own spend gate uses. It costs the two waiting callers nothing
338
338
  * they wanted: `awaitLockupFunding` keeps waiting for a claimable lockup
339
339
  * instead of publishing `P` into a spend that cannot land, and
@@ -742,6 +742,7 @@ type RfqSwapState =
742
742
  * without `needs_counterparty`: retiring on it would unwatch a funded lockup
743
743
  * whose claim is still the thing that ends the swap. */
744
744
  declare const RFQ_SWAP_TERMINAL_STATES: readonly ["settled", "refunded", "failed"];
745
+ declare const RFQ_SWAP_ACTIVE_STATES: readonly ["pending", "claimable", "claimed", "needs_counterparty"];
745
746
  declare const isRfqSwapTerminal: (state: RfqSwapState) => boolean;
746
747
 
747
748
  /**
@@ -1154,6 +1155,7 @@ interface RfqSwapRecordStore {
1154
1155
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
1155
1156
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
1156
1157
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
1158
+ getRfqSwapsPage?(state: RfqSwapState, afterId: string | undefined, limit: number): Promise<RfqSwapRecord[]>;
1157
1159
  removeRfqSwap(rfqId: string): Promise<void>;
1158
1160
  }
1159
1161
  /**
@@ -1192,15 +1194,16 @@ interface RfqRestoreOptions {
1192
1194
  * override cannot produce a swap watching the wrong covenant.
1193
1195
  */
1194
1196
  params?: (record: RfqSwapRecord) => Promise<LockupParams>;
1197
+ /** Include terminal history in the returned array. Expensive for large wallets. */
1198
+ includeTerminal?: boolean;
1195
1199
  }
1196
- /** What {@link RfqSwapManager.restoreFromRepository} did. Every stored record
1197
- * is in exactly one of the three lists. */
1200
+ /** What {@link RfqSwapManager.restoreFromRepository} did. */
1198
1201
  interface RfqRestoreResult {
1199
- /** Rebuilt: monitored, or kept as finished when already terminal. */
1202
+ /** Rebuilt active swaps, plus terminal history when `includeTerminal` is set. */
1200
1203
  restored: RfqSwap[];
1201
1204
  /** Kept in the store, but not rebuildable right now. */
1202
1205
  failed: RfqRestoreFailure[];
1203
- /** Removed: terminal and past `RFQ_SWAP_RETENTION_SECONDS`. */
1206
+ /** Compatibility field; normal restore leaves history stored. */
1204
1207
  pruned: string[];
1205
1208
  }
1206
1209
  /** The observation seams. None is owned by the manager, and none holds keys —
@@ -1295,6 +1298,7 @@ interface RfqSwapManagerDeps {
1295
1298
  * submitted something.
1296
1299
  */
1297
1300
  declare class RfqSwapManager {
1301
+ private static readonly POLL_CONCURRENCY;
1298
1302
  private readonly deps;
1299
1303
  private readonly config;
1300
1304
  private callbacks;
@@ -1359,9 +1363,12 @@ declare class RfqSwapManager {
1359
1363
  private readonly claimedOutpoints;
1360
1364
  /** Live `onContractEvent` subscription, held so `stop()` can drop it. */
1361
1365
  private unsubscribeContracts;
1362
- /** Terminal records, kept so a late {@link waitForSwapCompletion} still
1363
- * answers instead of throwing "not found". Cleared by {@link removeSwap}. */
1366
+ /** Recent terminal swaps; older durable outcomes are read from the record store on demand. */
1364
1367
  private readonly finished;
1368
+ /** Explicit removals stay suppressed for this manager lifetime; normal completions never enter this set.
1369
+ * Each maps to its removal sequence, so restore can tell a removal made during its rebuild. */
1370
+ private readonly removed;
1371
+ private removalSeq;
1365
1372
  private readonly waiters;
1366
1373
  /**
1367
1374
  * The request-time origin of each swap the manager may have to CREATE a
@@ -1380,6 +1387,8 @@ declare class RfqSwapManager {
1380
1387
  private readonly dirty;
1381
1388
  /** Race guard: one action at a time per swap. */
1382
1389
  private readonly inProgress;
1390
+ private activePolls;
1391
+ private readonly pollWaiters;
1383
1392
  private timer;
1384
1393
  private running;
1385
1394
  constructor(deps: RfqSwapManagerDeps, config?: RfqSwapManagerConfig);
@@ -1395,8 +1404,7 @@ declare class RfqSwapManager {
1395
1404
  * Rebuild every stored swap and take over monitoring them.
1396
1405
  *
1397
1406
  * The composition a consumer otherwise writes by hand, and the one place
1398
- * all four pieces meet: retention decides what to keep
1399
- * (`shouldRetainRfqSwap`), the lockup's contract row supplies the covenant
1407
+ * three pieces meet: the lockup's contract row supplies the covenant
1400
1408
  * (`lockupContractParams`), `rebuildRfqSwap` turns a record back into a
1401
1409
  * live swap, and each rebuilt swap arrives with its own origin, so nothing
1402
1410
  * is asked of the caller.
@@ -1406,9 +1414,10 @@ declare class RfqSwapManager {
1406
1414
  * forced to start driving money to do it. Call this first and `start()`
1407
1415
  * after; a manager already running polls the restored swaps at once.
1408
1416
  *
1409
- * Retention runs BEFORE the rebuild, so a record past
1410
- * `RFQ_SWAP_RETENTION_SECONDS` costs no contract lookup on its way to being
1411
- * dropped.
1417
+ * The default loads only active states through bounded pages when the
1418
+ * repository supports them. Terminal history stays durable and a late
1419
+ * completion lookup reads one record by key. `includeTerminal` opts into
1420
+ * the previous all-record result when a caller needs it.
1412
1421
  *
1413
1422
  * **A record that cannot be rebuilt is reported, never swallowed and never
1414
1423
  * fatal.** `rebuildRfqSwap` throws by design when the covenant params do
@@ -1427,13 +1436,12 @@ declare class RfqSwapManager {
1427
1436
  * lives in `shouldRetainRfqSwap`, which this defers to rather than
1428
1437
  * restating.
1429
1438
  *
1430
- * Public because retention is a caller's cadence, not the manager's: a
1431
- * long-lived process wants it on a timer of its own, a mobile app wants it
1432
- * at boot. {@link restoreFromRepository} runs it first, so the boot path
1433
- * needs no separate call.
1439
+ * This legacy deletion API is explicit; normal restore preserves history.
1440
+ * It loads every stored record: no backend offers indexed deletion for it.
1434
1441
  */
1435
1442
  pruneRetiredSwaps(): Promise<string[]>;
1436
1443
  private dropRetired;
1444
+ private forgetRetired;
1437
1445
  private requireRepository;
1438
1446
  /** The default covenant source: the wallet's own contract row for each
1439
1447
  * lockup, which is where registration put it before the address could be
@@ -1442,8 +1450,7 @@ declare class RfqSwapManager {
1442
1450
  /**
1443
1451
  * Load records and begin monitoring. Runs one pass immediately — a caller
1444
1452
  * resuming after a restart may be well past a deadline already — then
1445
- * every `pollIntervalMs`. Records that are already terminal are kept only
1446
- * so {@link waitForSwapCompletion} can answer for them.
1453
+ * every `pollIntervalMs`. Terminal outcomes in a repository are read on demand.
1447
1454
  *
1448
1455
  * Calling it again while running loads the records and returns rather than
1449
1456
  * re-arming — dropping them silently would strand a funded swap on a
@@ -1507,6 +1514,7 @@ declare class RfqSwapManager {
1507
1514
  hasSwap(rfqId: string): Promise<boolean>;
1508
1515
  /** True while an action for this swap holds the per-swap lock. */
1509
1516
  isProcessing(rfqId: string): Promise<boolean>;
1517
+ /** `finishedSwaps` counts terminal swaps cached in memory, not those only in the repository. */
1510
1518
  getStats(): Promise<{
1511
1519
  isRunning: boolean;
1512
1520
  monitoredSwaps: number;
@@ -1524,6 +1532,8 @@ declare class RfqSwapManager {
1524
1532
  * no-op for any swap already being worked on.
1525
1533
  */
1526
1534
  poll(): Promise<void>;
1535
+ private pollMany;
1536
+ private acquirePollSlot;
1527
1537
  /**
1528
1538
  * Resolve once this swap's PAYOUT is decided — which for onchain-send is
1529
1539
  * the L1 claim, not the end of the record's life: once `claimTxid` is set
@@ -1715,6 +1725,7 @@ declare class RfqSwapManager {
1715
1725
  * also fires on failure is a trap worth not inheriting.
1716
1726
  */
1717
1727
  private finalize;
1728
+ private rememberFinished;
1718
1729
  private settleWaiters;
1719
1730
  }
1720
1731
  /** What {@link RfqSwapManager.waitForSwapCompletion} reports. `txid` is the
@@ -1754,7 +1765,7 @@ type LockupParams = Record<string, string>;
1754
1765
  *
1755
1766
  * Terminal records are history, not garbage: the covenant's spender is a
1756
1767
  * transaction the wallet never signed, so its own history cannot reconstruct
1757
- * them. Kept for a month, then dropped so a hot wallet's store stays bounded.
1768
+ * them. The legacy explicit prune API uses this window; restore preserves them.
1758
1769
  *
1759
1770
  * Seconds, not milliseconds, because that is the unit `RfqSwap.updatedAt`
1760
1771
  * carries; the manager stamps it from `RfqSwapManagerConfig.now`, which is
@@ -1883,6 +1894,11 @@ declare function rebuildRfqSwap(record: RfqSwapRecord, params: LockupParams): Pe
1883
1894
  */
1884
1895
  declare function shouldRetainRfqSwap(record: RfqSwapRecord, now: number): boolean;
1885
1896
 
1897
+ declare const RFQ_SWAP_MAX_PAGE_SIZE = 500;
1898
+ interface RfqHistoryCursor {
1899
+ updatedAt: number;
1900
+ rfqId: string;
1901
+ }
1886
1902
  /** A registry discovery result held for reuse. Refetchable — unlike a swap
1887
1903
  * record, losing it costs one network round trip — but it must survive a cold
1888
1904
  * boot: serving it stale is what keeps quoting alive while a registry is down. */
@@ -1901,9 +1917,8 @@ interface MarketsCacheEntry {
1901
1917
  * lifetime: all three belong to one wallet on one device, and a consumer
1902
1918
  * that wipes one wants all three gone.
1903
1919
  *
1904
- * ponytail: no query filters — every consumer reads all swaps and filters
1905
- * in memory; mirror the Boltz plugin's GetSwapsFilter when a consumer needs
1906
- * subset queries.
1920
+ * RFQ history also has an optional state-scoped cursor read. Custom stores
1921
+ * without it keep the legacy all-record fallback.
1907
1922
  */
1908
1923
  interface AssetSwapRepository extends AsyncDisposable {
1909
1924
  /** 4 adds `getRfqSwap`. 3 added the other RFQ methods below; 2 was the
@@ -1935,12 +1950,14 @@ interface AssetSwapRepository extends AsyncDisposable {
1935
1950
  * as a refund that cannot be signed, long after the write.
1936
1951
  */
1937
1952
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
1938
- /** One record by key. `undefined` on a miss — retention prunes terminal
1939
- * records, so absence is ordinary and not an error. */
1953
+ /** One record by key. */
1940
1954
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
1941
- /** Every stored RFQ swap record, in no particular order. */
1955
+ /** Every stored RFQ swap record, in no particular order. Unbounded. */
1942
1956
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
1943
- /** Drop one, once it is past retention — see `shouldRetainRfqSwap`. */
1957
+ /** Optional keyset page, ordered by rfqId within one state. `afterId` is exclusive; limit 1–500. */
1958
+ getRfqSwapsPage?(state: RfqSwapState, afterId: string | undefined, limit: number): Promise<RfqSwapRecord[]>;
1959
+ getRfqSwapsUpdatedPage?(state: RfqSwapState, since: number, after: RfqHistoryCursor | undefined, limit: number): Promise<RfqSwapRecord[]>;
1960
+ /** Drop one record. Only explicit pruning calls this; restore keeps history. */
1944
1961
  removeRfqSwap(rfqId: string): Promise<void>;
1945
1962
  /** Sent txids already checked for offer packets (see restore.ts). */
1946
1963
  getScannedTxids(): Promise<Set<string>>;
@@ -1961,6 +1978,8 @@ declare class InMemoryAssetSwapRepository implements AssetSwapRepository {
1961
1978
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
1962
1979
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
1963
1980
  getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
1981
+ getRfqSwapsPage(state: RfqSwapState, afterId: string | undefined, limit: number): Promise<RfqSwapRecord[]>;
1982
+ getRfqSwapsUpdatedPage(state: RfqSwapState, since: number, after: RfqHistoryCursor | undefined, limit: number): Promise<RfqSwapRecord[]>;
1964
1983
  removeRfqSwap(rfqId: string): Promise<void>;
1965
1984
  getScannedTxids(): Promise<Set<string>>;
1966
1985
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -1970,4 +1989,4 @@ declare class InMemoryAssetSwapRepository implements AssetSwapRepository {
1970
1989
  [Symbol.asyncDispose](): Promise<void>;
1971
1990
  }
1972
1991
 
1973
- export { isRfqSwapTerminal as $, type AssetSwapRepository as A, BTC_ASSET_ID as B, type RfqSwapActionName as C, type RfqSwapLockup as D, RfqSwapManager as E, type RfqSwapManagerCallbacks as F, type RfqSwapManagerConfig as G, type RfqSwapManagerDeps as H, InMemoryAssetSwapRepository as I, type RfqSwapManagerEvents as J, type RfqSwapOrigin as K, type LockupContractSource as L, type MarketsCacheEntry as M, RfqSwapOriginRequired as N, type OnchainSendAction as O, type PersistableRfqSwap as P, type RfqSwapOutcome as Q, type RfqSwapRecord as R, type SwapSecretsProjection as S, type RfqSwapRecordStore as T, type SwapContractRegistry as U, addAssetSwap as V, awaitRfqResolution as W, createRfqSwapRecord as X, findLockupVtxos as Y, getAssetSwaps as Z, getAssetSwapsOrThrow as _, type AssetSwap as a, isRfqTerminal as a0, nextOnchainAction as a1, preimageForSwapRecord as a2, pushRefundWithoutReceiver as a3, readLockupFate as a4, rebuildRfqSwap as a5, refundIfUnresolved as a6, rfqSwapOriginOf as a7, shouldRetainRfqSwap as a8, swapSecretsToRecord as a9, updateAssetSwap as aa, updateAssetSwapBestEffort as ab, updateRfqSwapRecord as ac, type RefundArkProvider as b, type LockupVtxo as c, type RfqSwap as d, type ArkadeRefundResult as e, type LockupSpendIndexer as f, type RfqSwapState as g, type AssetSwapStatus as h, type AvailableRfqSwapManagerCallbacks as i, type LightningReceiveSwap as j, type LightningSendSwap as k, type LockupFate as l, LockupNeedsRecoveryError as m, type LockupParams as n, type LockupSpend as o, type OnchainSendSwap as p, type PreimageBlockedReason as q, PreimageNotRecoverableError as r, REFUND_MTP_LAG_SECONDS as s, RFQ_RESOLVED_STATES as t, RFQ_SWAP_RETENTION_SECONDS as u, RFQ_SWAP_TERMINAL_STATES as v, type RefundOutcome as w, type RfqRestoreFailure as x, type RfqRestoreOptions as y, type RfqRestoreResult as z };
1992
+ export { findLockupVtxos as $, type AssetSwapRepository as A, BTC_ASSET_ID as B, type RfqRestoreFailure as C, type RfqRestoreOptions as D, type RfqRestoreResult as E, type RfqSwapActionName as F, type RfqSwapLockup as G, RfqSwapManager as H, InMemoryAssetSwapRepository as I, type RfqSwapManagerCallbacks as J, type RfqSwapManagerConfig as K, type LockupContractSource as L, type MarketsCacheEntry as M, type RfqSwapManagerDeps as N, type OnchainSendAction as O, type PersistableRfqSwap as P, type RfqSwapManagerEvents as Q, type RfqSwapRecord as R, type SwapSecretsProjection as S, type RfqSwapOrigin as T, RfqSwapOriginRequired as U, type RfqSwapOutcome as V, type RfqSwapRecordStore as W, type SwapContractRegistry as X, addAssetSwap as Y, awaitRfqResolution as Z, createRfqSwapRecord as _, type AssetSwap as a, getAssetSwaps as a0, getAssetSwapsOrThrow as a1, isRfqSwapTerminal as a2, isRfqTerminal as a3, nextOnchainAction as a4, preimageForSwapRecord as a5, pushRefundWithoutReceiver as a6, readLockupFate as a7, rebuildRfqSwap as a8, refundIfUnresolved as a9, rfqSwapOriginOf as aa, shouldRetainRfqSwap as ab, swapSecretsToRecord as ac, updateAssetSwap as ad, updateAssetSwapBestEffort as ae, updateRfqSwapRecord as af, type RfqSwapState as b, type RfqHistoryCursor as c, type RefundArkProvider as d, type LockupVtxo as e, type RfqSwap as f, type ArkadeRefundResult as g, type LockupSpendIndexer as h, type AssetSwapStatus as i, type AvailableRfqSwapManagerCallbacks as j, type LightningReceiveSwap as k, type LightningSendSwap as l, type LockupFate as m, LockupNeedsRecoveryError as n, type LockupParams as o, type LockupSpend as p, type OnchainSendSwap as q, type PreimageBlockedReason as r, PreimageNotRecoverableError as s, REFUND_MTP_LAG_SECONDS as t, RFQ_RESOLVED_STATES as u, RFQ_SWAP_ACTIVE_STATES as v, RFQ_SWAP_MAX_PAGE_SIZE as w, RFQ_SWAP_RETENTION_SECONDS as x, RFQ_SWAP_TERMINAL_STATES as y, type RefundOutcome as z };