@arkade-os/swap 0.1.0-rc.2 → 0.1.0-rc.21

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 (54) hide show
  1. package/README.md +52 -2
  2. package/dist/advanced.cjs +8376 -0
  3. package/dist/advanced.d.cts +550 -0
  4. package/dist/advanced.d.ts +550 -0
  5. package/dist/advanced.js +451 -0
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-HUQQVBC4.js +4262 -0
  8. package/dist/{chunk-EOYGUCDM.js → chunk-ITFCQWPG.js} +755 -1382
  9. package/dist/chunk-PVB7EBAM.js +2517 -0
  10. package/dist/errors-C3h8ANmE.d.ts +1560 -0
  11. package/dist/errors-hm7aqnRM.d.cts +1560 -0
  12. package/dist/index.cjs +4861 -3988
  13. package/dist/index.d.cts +69 -2812
  14. package/dist/index.d.ts +69 -2812
  15. package/dist/index.js +179 -3719
  16. package/dist/lockupContract-5r5RlgOJ.d.cts +137 -0
  17. package/dist/lockupContract-5r5RlgOJ.d.ts +137 -0
  18. package/dist/node/index.cjs +61 -10
  19. package/dist/node/index.d.cts +249 -591
  20. package/dist/node/index.d.ts +249 -591
  21. package/dist/node/index.js +65 -10
  22. package/dist/nostr.cjs +191 -11
  23. package/dist/nostr.d.cts +23 -68
  24. package/dist/nostr.d.ts +23 -68
  25. package/dist/nostr.js +3 -4
  26. package/dist/offer-Bd9Yvd8Z.d.ts +261 -0
  27. package/dist/offer-F88rtL_I.d.cts +261 -0
  28. package/dist/protocol.cjs +4086 -3706
  29. package/dist/protocol.d.cts +163 -768
  30. package/dist/protocol.d.ts +163 -768
  31. package/dist/protocol.js +190 -173
  32. package/dist/repositories/realm/index.cjs +55 -11
  33. package/dist/repositories/realm/index.d.cts +18 -30
  34. package/dist/repositories/realm/index.d.ts +18 -30
  35. package/dist/repositories/realm/index.js +49 -12
  36. package/dist/repositories/sqlite/index.cjs +61 -10
  37. package/dist/repositories/sqlite/index.d.cts +7 -6
  38. package/dist/repositories/sqlite/index.d.ts +7 -6
  39. package/dist/repositories/sqlite/index.js +57 -11
  40. package/dist/repository-BuYWGAKz.d.cts +2261 -0
  41. package/dist/repository-DYnRLPt-.d.ts +2261 -0
  42. package/dist/rfq-60PGpQ_x.d.cts +950 -0
  43. package/dist/rfq-60PGpQ_x.d.ts +950 -0
  44. package/dist/watch-BTyiBLSd.d.ts +74 -0
  45. package/dist/watch-M_KY-5ho.d.cts +74 -0
  46. package/package.json +20 -10
  47. package/dist/chunk-LYCMM3VB.js +0 -1357
  48. package/dist/chunk-U7VWWTL6.js +0 -66
  49. package/dist/repository-_zU9_pM3.d.cts +0 -3426
  50. package/dist/repository-kO95noyv.d.ts +0 -3426
  51. package/dist/rfq-DdBV4JO5.d.cts +0 -1097
  52. package/dist/rfq-DdBV4JO5.d.ts +0 -1097
  53. package/dist/watch-CQqvwgwY.d.cts +0 -96
  54. package/dist/watch-wMbmfN4p.d.ts +0 -96
@@ -0,0 +1,137 @@
1
+ import { VHTLC, IContractManager } from '@arkade-os/sdk';
2
+
3
+ interface SealedClaimPacket {
4
+ /** `ephPub(33) ‖ nonce(12) ‖ ciphertext`, base64 (93 bytes decoded). The legacy
5
+ * `claim_packet` shape: usable only via covclaimd's Reveal API, which silently
6
+ * needs both sides on the SAME covclaimd. Prefer {@link SealedClaimPacket.packet}. */
7
+ ciphertext: string;
8
+ /**
9
+ * covclaimd's serialised `ClaimPacket` body, base64: TLV `0x01` ciphertext and `0x03`
10
+ * covclaimd_pub_key. **This is what `claim_packet` should carry** (§ 7.1.2). The
11
+ * solver stamps it as Arkade extension packet `0x04`; covclaimd filters on `0x03`, so
12
+ * the client alone chooses which covclaimd.
13
+ *
14
+ * `0x02` arkade_script is deliberately absent: the covenant commits to
15
+ * `taggedHash("ArkScriptHash", script)`, so only the funder's copy is guaranteed to
16
+ * match (see {@link appendArkadeScript}); a client-derived one could strand the claim.
17
+ */
18
+ packet: string;
19
+ }
20
+ interface ClaimPacketInput {
21
+ preimage: Uint8Array;
22
+ /** covclaimd's public key, 33-byte compressed (from its /v1 info). */
23
+ covclaimdPubkey: Uint8Array;
24
+ }
25
+ /**
26
+ * Seal a preimage to covclaimd.
27
+ *
28
+ * The ephemeral key and nonce CANNOT be caller-supplied: AES-GCM under a repeated
29
+ * (key, nonce) pair is a total break (forgery and plaintext recovery).
30
+ */
31
+ declare function sealClaimPacket(input: ClaimPacketInput): Promise<SealedClaimPacket>;
32
+ /** `ephPub(33) ‖ nonce(12) ‖ preimage(32) ‖ GCM tag(16)`. Distinguishes the two
33
+ * `claim_packet` shapes: a TLV body carrying it is ≥96 bytes, so lengths cannot collide. */
34
+ declare const SEALED_CIPHERTEXT_LENGTH = 93;
35
+ /** The Arkade extension packet type covclaimd scans the arkd tx stream for. */
36
+ declare const CLAIM_PACKET_TYPE = 4;
37
+ /**
38
+ * Stamp the covenant script into a client's packet — the solver's half.
39
+ *
40
+ * Appending rather than rebuilding is safe: covclaimd's `DeserializeClaim` is
41
+ * order-agnostic, so `0x01, 0x03, 0x02` reads back like its own `0x01, 0x02, 0x03`.
42
+ */
43
+ declare const appendArkadeScript: (body: Uint8Array, arkadeScript: Uint8Array) => Uint8Array;
44
+ type ClaimPacketShape = {
45
+ kind: "ciphertext";
46
+ } | {
47
+ kind: "packet";
48
+ body: Uint8Array;
49
+ covclaimdPubkey?: Uint8Array;
50
+ needsArkadeScript: boolean;
51
+ };
52
+ /**
53
+ * Which of the two `claim_packet` shapes a base64 field carries.
54
+ *
55
+ * Never throws: anything not unambiguously a packet reads as the legacy ciphertext,
56
+ * keeping the Reveal-API path rather than failing a swap over an unfamiliar field.
57
+ */
58
+ declare const claimPacketShape: (b64: string) => ClaimPacketShape;
59
+
60
+ /** The contract type a swap lockup registers under: the SDK's handler for `VHTLC.ScriptV2`.
61
+ *
62
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
63
+ */
64
+ declare const SWAP_LOCKUP_CONTRACT_TYPE = "vhtlc-v2";
65
+ /** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
66
+ declare const SWAP_LOCKUP_CONTRACT_LABEL = "Arkade RFQ swap lockup";
67
+ /** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
68
+ declare const SWAP_LOCKUP_CONTRACT_KIND = "rfq-swap-lockup";
69
+ /** The write seam registration needs; a real `ContractManager` satisfies it.
70
+ *
71
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
72
+ */
73
+ type LockupContractWriter = Pick<IContractManager, "createContract">;
74
+ /** The read seam {@link lockupContractParams} needs.
75
+ *
76
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
77
+ */
78
+ type LockupContractReader = Pick<IContractManager, "getContracts">;
79
+ /**
80
+ * No row for a lockup a record claims was funded. The record is fine and its money may be at the
81
+ * address; the wallet's copy of the covenant is missing (store cleared, or a different store
82
+ * registered it). The remedy is a store, not a re-quote.
83
+ *
84
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
85
+ */
86
+ declare class LockupContractMissing extends Error {
87
+ /** The lockup whose row is absent. */
88
+ readonly address: string;
89
+ /** Its pkScript hex — the key the row would have been under. */
90
+ readonly script: string;
91
+ constructor(address: string, script: string);
92
+ }
93
+ /**
94
+ * The lockup could not be written locally: "the quote is fine and your own store failed", unlike
95
+ * {@link SwapRefusal} / {@link AddressMismatch} ("never fund it"). Thrown by `client.accept()`.
96
+ *
97
+ * Nothing is funded yet and on receive legs the invoice never left, so retrying the request is
98
+ * the recovery. `script` lets a caller still holding the swap retry `registerLockupContract`
99
+ * alone; it is NOT enough to resume a request that threw here (no invoice or `secrets`).
100
+ */
101
+ declare class LockupRegistrationFailed extends Error {
102
+ /** The lockup address that was never registered — never fund it: nothing
103
+ * is watching it. */
104
+ readonly address: string;
105
+ /** The covenant the row would have been written from, so the write is retryable without a
106
+ * quote. */
107
+ readonly script: InstanceType<typeof VHTLC.ScriptV2>;
108
+ constructor(script: InstanceType<typeof VHTLC.ScriptV2>, address: string, cause: unknown);
109
+ }
110
+ /**
111
+ * Register a lockup covenant so its VTXOs are watched and — via `vhtlc-v2`'s handler, never
112
+ * generically spendable — kept out of ordinary coin selection.
113
+ *
114
+ * The row carries script-level facts only: rows are keyed by script and first-writer-wins, so
115
+ * anything per-swap written here is stale from the second swap onward. Taking the derived script
116
+ * means the row cannot describe a script other than its key.
117
+ *
118
+ * @throws {LockupRegistrationFailed} so a caller can tell local storage trouble from a bad quote.
119
+ *
120
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
121
+ */
122
+ declare function registerLockupContract(contracts: LockupContractWriter, script: InstanceType<typeof VHTLC.ScriptV2>, address: string): Promise<void>;
123
+ /**
124
+ * The stored covenant parameters of a funded lockup — the other half of `rebuildRfqSwap`. The row
125
+ * is the wallet's own copy of the tree (`createContract` refuses params that do not reproduce the
126
+ * script), which is why an RFQ swap record stores no tree parameters.
127
+ *
128
+ * Looked up by script, decoded from the address here, so a bad address fails as such rather than
129
+ * as a missing row.
130
+ *
131
+ * @throws {LockupContractMissing} when there is no row.
132
+ *
133
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
134
+ */
135
+ declare function lockupContractParams(contracts: LockupContractReader, lockupAddress: string): Promise<Record<string, string>>;
136
+
137
+ export { CLAIM_PACKET_TYPE as C, LockupRegistrationFailed as L, SEALED_CIPHERTEXT_LENGTH as S, type ClaimPacketShape as a, appendArkadeScript as b, claimPacketShape as c, type ClaimPacketInput as d, LockupContractMissing as e, type LockupContractReader as f, type LockupContractWriter as g, SWAP_LOCKUP_CONTRACT_KIND as h, SWAP_LOCKUP_CONTRACT_LABEL as i, SWAP_LOCKUP_CONTRACT_TYPE as j, type SealedClaimPacket as k, lockupContractParams as l, registerLockupContract as r, sealClaimPacket as s };
@@ -0,0 +1,137 @@
1
+ import { VHTLC, IContractManager } from '@arkade-os/sdk';
2
+
3
+ interface SealedClaimPacket {
4
+ /** `ephPub(33) ‖ nonce(12) ‖ ciphertext`, base64 (93 bytes decoded). The legacy
5
+ * `claim_packet` shape: usable only via covclaimd's Reveal API, which silently
6
+ * needs both sides on the SAME covclaimd. Prefer {@link SealedClaimPacket.packet}. */
7
+ ciphertext: string;
8
+ /**
9
+ * covclaimd's serialised `ClaimPacket` body, base64: TLV `0x01` ciphertext and `0x03`
10
+ * covclaimd_pub_key. **This is what `claim_packet` should carry** (§ 7.1.2). The
11
+ * solver stamps it as Arkade extension packet `0x04`; covclaimd filters on `0x03`, so
12
+ * the client alone chooses which covclaimd.
13
+ *
14
+ * `0x02` arkade_script is deliberately absent: the covenant commits to
15
+ * `taggedHash("ArkScriptHash", script)`, so only the funder's copy is guaranteed to
16
+ * match (see {@link appendArkadeScript}); a client-derived one could strand the claim.
17
+ */
18
+ packet: string;
19
+ }
20
+ interface ClaimPacketInput {
21
+ preimage: Uint8Array;
22
+ /** covclaimd's public key, 33-byte compressed (from its /v1 info). */
23
+ covclaimdPubkey: Uint8Array;
24
+ }
25
+ /**
26
+ * Seal a preimage to covclaimd.
27
+ *
28
+ * The ephemeral key and nonce CANNOT be caller-supplied: AES-GCM under a repeated
29
+ * (key, nonce) pair is a total break (forgery and plaintext recovery).
30
+ */
31
+ declare function sealClaimPacket(input: ClaimPacketInput): Promise<SealedClaimPacket>;
32
+ /** `ephPub(33) ‖ nonce(12) ‖ preimage(32) ‖ GCM tag(16)`. Distinguishes the two
33
+ * `claim_packet` shapes: a TLV body carrying it is ≥96 bytes, so lengths cannot collide. */
34
+ declare const SEALED_CIPHERTEXT_LENGTH = 93;
35
+ /** The Arkade extension packet type covclaimd scans the arkd tx stream for. */
36
+ declare const CLAIM_PACKET_TYPE = 4;
37
+ /**
38
+ * Stamp the covenant script into a client's packet — the solver's half.
39
+ *
40
+ * Appending rather than rebuilding is safe: covclaimd's `DeserializeClaim` is
41
+ * order-agnostic, so `0x01, 0x03, 0x02` reads back like its own `0x01, 0x02, 0x03`.
42
+ */
43
+ declare const appendArkadeScript: (body: Uint8Array, arkadeScript: Uint8Array) => Uint8Array;
44
+ type ClaimPacketShape = {
45
+ kind: "ciphertext";
46
+ } | {
47
+ kind: "packet";
48
+ body: Uint8Array;
49
+ covclaimdPubkey?: Uint8Array;
50
+ needsArkadeScript: boolean;
51
+ };
52
+ /**
53
+ * Which of the two `claim_packet` shapes a base64 field carries.
54
+ *
55
+ * Never throws: anything not unambiguously a packet reads as the legacy ciphertext,
56
+ * keeping the Reveal-API path rather than failing a swap over an unfamiliar field.
57
+ */
58
+ declare const claimPacketShape: (b64: string) => ClaimPacketShape;
59
+
60
+ /** The contract type a swap lockup registers under: the SDK's handler for `VHTLC.ScriptV2`.
61
+ *
62
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
63
+ */
64
+ declare const SWAP_LOCKUP_CONTRACT_TYPE = "vhtlc-v2";
65
+ /** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
66
+ declare const SWAP_LOCKUP_CONTRACT_LABEL = "Arkade RFQ swap lockup";
67
+ /** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
68
+ declare const SWAP_LOCKUP_CONTRACT_KIND = "rfq-swap-lockup";
69
+ /** The write seam registration needs; a real `ContractManager` satisfies it.
70
+ *
71
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
72
+ */
73
+ type LockupContractWriter = Pick<IContractManager, "createContract">;
74
+ /** The read seam {@link lockupContractParams} needs.
75
+ *
76
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
77
+ */
78
+ type LockupContractReader = Pick<IContractManager, "getContracts">;
79
+ /**
80
+ * No row for a lockup a record claims was funded. The record is fine and its money may be at the
81
+ * address; the wallet's copy of the covenant is missing (store cleared, or a different store
82
+ * registered it). The remedy is a store, not a re-quote.
83
+ *
84
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
85
+ */
86
+ declare class LockupContractMissing extends Error {
87
+ /** The lockup whose row is absent. */
88
+ readonly address: string;
89
+ /** Its pkScript hex — the key the row would have been under. */
90
+ readonly script: string;
91
+ constructor(address: string, script: string);
92
+ }
93
+ /**
94
+ * The lockup could not be written locally: "the quote is fine and your own store failed", unlike
95
+ * {@link SwapRefusal} / {@link AddressMismatch} ("never fund it"). Thrown by `client.accept()`.
96
+ *
97
+ * Nothing is funded yet and on receive legs the invoice never left, so retrying the request is
98
+ * the recovery. `script` lets a caller still holding the swap retry `registerLockupContract`
99
+ * alone; it is NOT enough to resume a request that threw here (no invoice or `secrets`).
100
+ */
101
+ declare class LockupRegistrationFailed extends Error {
102
+ /** The lockup address that was never registered — never fund it: nothing
103
+ * is watching it. */
104
+ readonly address: string;
105
+ /** The covenant the row would have been written from, so the write is retryable without a
106
+ * quote. */
107
+ readonly script: InstanceType<typeof VHTLC.ScriptV2>;
108
+ constructor(script: InstanceType<typeof VHTLC.ScriptV2>, address: string, cause: unknown);
109
+ }
110
+ /**
111
+ * Register a lockup covenant so its VTXOs are watched and — via `vhtlc-v2`'s handler, never
112
+ * generically spendable — kept out of ordinary coin selection.
113
+ *
114
+ * The row carries script-level facts only: rows are keyed by script and first-writer-wins, so
115
+ * anything per-swap written here is stale from the second swap onward. Taking the derived script
116
+ * means the row cannot describe a script other than its key.
117
+ *
118
+ * @throws {LockupRegistrationFailed} so a caller can tell local storage trouble from a bad quote.
119
+ *
120
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
121
+ */
122
+ declare function registerLockupContract(contracts: LockupContractWriter, script: InstanceType<typeof VHTLC.ScriptV2>, address: string): Promise<void>;
123
+ /**
124
+ * The stored covenant parameters of a funded lockup — the other half of `rebuildRfqSwap`. The row
125
+ * is the wallet's own copy of the tree (`createContract` refuses params that do not reproduce the
126
+ * script), which is why an RFQ swap record stores no tree parameters.
127
+ *
128
+ * Looked up by script, decoded from the address here, so a bad address fails as such rather than
129
+ * as a missing row.
130
+ *
131
+ * @throws {LockupContractMissing} when there is no row.
132
+ *
133
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
134
+ */
135
+ declare function lockupContractParams(contracts: LockupContractReader, lockupAddress: string): Promise<Record<string, string>>;
136
+
137
+ export { CLAIM_PACKET_TYPE as C, LockupRegistrationFailed as L, SEALED_CIPHERTEXT_LENGTH as S, type ClaimPacketShape as a, appendArkadeScript as b, claimPacketShape as c, type ClaimPacketInput as d, LockupContractMissing as e, type LockupContractReader as f, type LockupContractWriter as g, SWAP_LOCKUP_CONTRACT_KIND as h, SWAP_LOCKUP_CONTRACT_LABEL as i, SWAP_LOCKUP_CONTRACT_TYPE as j, type SealedClaimPacket as k, lockupContractParams as l, registerLockupContract as r, sealClaimPacket as s };
@@ -59,9 +59,16 @@ var import_node_path2 = require("node:path");
59
59
 
60
60
  // src/repositories/sqlite/repository.ts
61
61
  var import_sqlite = require("@arkade-os/sdk/repositories/sqlite");
62
+ var import_sdk2 = require("@arkade-os/sdk");
62
63
 
63
64
  // src/repository.ts
65
+ var import_sdk = require("@arkade-os/sdk");
64
66
  var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
67
+ function assertRfqSwapPageFilter(filter) {
68
+ if (filter.since !== void 0 && (!Number.isSafeInteger(filter.since) || filter.since < 0)) {
69
+ throw new RangeError("RFQ history since must be non-negative Unix seconds");
70
+ }
71
+ }
65
72
 
66
73
  // src/repositories/sqlite/repository.ts
67
74
  var DEFAULT_PREFIX = "arkade_";
@@ -120,6 +127,13 @@ var SQLiteAssetSwapRepository = class {
120
127
  updated_at INTEGER NOT NULL,
121
128
  data TEXT NOT NULL
122
129
  )`);
130
+ await this.db.run(
131
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_updated ON ${this.rfqSwaps} (updated_at, rfq_id)`
132
+ );
133
+ await this.db.run(
134
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
135
+ );
136
+ await this.db.run(`DROP INDEX IF EXISTS idx_${this.prefix}rfq_swaps_page`);
123
137
  await this.db.run(
124
138
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
125
139
  );
@@ -157,10 +171,8 @@ var SQLiteAssetSwapRepository = class {
157
171
  );
158
172
  });
159
173
  }
160
- async getAllSwaps() {
161
- await this.ensureInit();
162
- const rows = await this.db.all(`SELECT data FROM ${this.swaps}`);
163
- return rows.map((r) => JSON.parse(r.data));
174
+ async getAssetSwapsPage(page) {
175
+ return this.pageTable(this.swaps, "id", page);
164
176
  }
165
177
  async saveRfqSwap(record) {
166
178
  await this.ensureInit();
@@ -180,10 +192,38 @@ var SQLiteAssetSwapRepository = class {
180
192
  );
181
193
  return row ? JSON.parse(row.data) : void 0;
182
194
  }
183
- async getAllRfqSwaps() {
195
+ async getRfqSwapsPage(filter, page) {
196
+ (0, import_sdk2.assertPageRequest)(page);
197
+ assertRfqSwapPageFilter(filter);
184
198
  await this.ensureInit();
185
- const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
186
- return rows.map((r) => JSON.parse(r.data));
199
+ const conditions = [];
200
+ const params = [];
201
+ if (filter.state !== void 0) {
202
+ conditions.push("state = ?");
203
+ params.push(filter.state);
204
+ }
205
+ if (filter.since !== void 0) {
206
+ conditions.push("updated_at >= ?");
207
+ params.push(filter.since);
208
+ }
209
+ if (page.after !== void 0) {
210
+ conditions.push("(updated_at, rfq_id) > (?, ?)");
211
+ params.push(page.after.updatedAt, page.after.rfqId);
212
+ }
213
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
214
+ const rows = await this.db.all(
215
+ `SELECT data, updated_at, rfq_id FROM ${this.rfqSwaps}${where}
216
+ ORDER BY updated_at, rfq_id LIMIT ?`,
217
+ [...params, page.limit + 1]
218
+ );
219
+ const result = (0, import_sdk2.pageResult)(rows, page.limit, (row) => ({
220
+ updatedAt: row.updated_at,
221
+ rfqId: row.rfq_id
222
+ }));
223
+ return {
224
+ items: result.items.map((row) => JSON.parse(row.data)),
225
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
226
+ };
187
227
  }
188
228
  async removeRfqSwap(rfqId) {
189
229
  await this.ensureInit();
@@ -209,10 +249,21 @@ var SQLiteAssetSwapRepository = class {
209
249
  );
210
250
  return row ? JSON.parse(row.data) : void 0;
211
251
  }
212
- async getAllSwapRecords() {
252
+ async getSwapRecordsPage(page) {
253
+ return this.pageTable(this.swapRecords, "id", page);
254
+ }
255
+ async pageTable(table, key, page) {
256
+ (0, import_sdk2.assertPageRequest)(page);
213
257
  await this.ensureInit();
214
- const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
215
- return rows.map((r) => JSON.parse(r.data));
258
+ const rows = await this.db.all(
259
+ page.after === void 0 ? `SELECT ${key} AS key, data FROM ${table} ORDER BY ${key} LIMIT ?` : `SELECT ${key} AS key, data FROM ${table} WHERE ${key} > ? ORDER BY ${key} LIMIT ?`,
260
+ page.after === void 0 ? [page.limit + 1] : [page.after, page.limit + 1]
261
+ );
262
+ const result = (0, import_sdk2.pageResult)(rows, page.limit, (row) => row.key);
263
+ return {
264
+ items: result.items.map((row) => JSON.parse(row.data)),
265
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
266
+ };
216
267
  }
217
268
  async removeSwapRecord(id) {
218
269
  await this.ensureInit();