@arkade-os/swap 0.1.0-rc.9 → 0.1.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.
Files changed (57) hide show
  1. package/README.md +261 -252
  2. package/dist/advanced.cjs +6613 -3224
  3. package/dist/advanced.d.cts +328 -283
  4. package/dist/advanced.d.ts +328 -283
  5. package/dist/advanced.js +347 -34
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-FMRAV77W.js +3065 -0
  8. package/dist/chunk-T4FHBWZI.js +3459 -0
  9. package/dist/{chunk-NS3K6BZG.js → chunk-YHESEL4I.js} +1792 -636
  10. package/dist/index.cjs +6901 -3901
  11. package/dist/index.d.cts +71 -243
  12. package/dist/index.d.ts +71 -243
  13. package/dist/index.js +131 -167
  14. package/dist/lockupContract-CIXkJPxV.d.ts +148 -0
  15. package/dist/lockupContract-CkhWMKCo.d.cts +148 -0
  16. package/dist/node/index.cjs +61 -10
  17. package/dist/node/index.d.cts +307 -635
  18. package/dist/node/index.d.ts +307 -635
  19. package/dist/node/index.js +65 -10
  20. package/dist/nostr.cjs +427 -49
  21. package/dist/nostr.d.cts +59 -70
  22. package/dist/nostr.d.ts +59 -70
  23. package/dist/nostr.js +268 -36
  24. package/dist/offer-BPD2ortO.d.ts +269 -0
  25. package/dist/offer-Diff5Flc.d.cts +269 -0
  26. package/dist/offerFillPlan-B-5ae_gQ.d.cts +1671 -0
  27. package/dist/offerFillPlan-CJzneX6F.d.ts +1671 -0
  28. package/dist/protocol.cjs +5717 -4275
  29. package/dist/protocol.d.cts +258 -328
  30. package/dist/protocol.d.ts +258 -328
  31. package/dist/protocol.js +200 -224
  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-BBVRh9ez.d.ts +2357 -0
  41. package/dist/repository-C4pvymhs.d.cts +2357 -0
  42. package/dist/{rfq-BO6o7NwS.d.ts → rfq-C0tHOvn6.d.cts} +323 -444
  43. package/dist/{rfq-BO6o7NwS.d.cts → rfq-C0tHOvn6.d.ts} +323 -444
  44. package/dist/watch-7BiRa4oB.d.ts +74 -0
  45. package/dist/watch-Bxq-lx_6.d.cts +74 -0
  46. package/package.json +10 -10
  47. package/dist/chunk-JFKGMPMH.js +0 -3456
  48. package/dist/chunk-LLG7RD2T.js +0 -1499
  49. package/dist/chunk-U7VWWTL6.js +0 -66
  50. package/dist/errors-CNISbN0M.d.ts +0 -2218
  51. package/dist/errors-DwNhIP0N.d.cts +0 -2218
  52. package/dist/lockupContract-C8-Mcg69.d.ts +0 -664
  53. package/dist/lockupContract-mIt4syse.d.cts +0 -664
  54. package/dist/repository-CGPLbjBe.d.ts +0 -3489
  55. package/dist/repository-DSGGq0ct.d.cts +0 -3489
  56. package/dist/watch-DWyVqyEN.d.cts +0 -96
  57. package/dist/watch-DmvHNX6T.d.ts +0 -96
@@ -30,8 +30,17 @@ __export(realm_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(realm_exports);
32
32
 
33
+ // src/repositories/realm/repository.ts
34
+ var import_sdk2 = require("@arkade-os/sdk");
35
+
33
36
  // src/repository.ts
37
+ var import_sdk = require("@arkade-os/sdk");
34
38
  var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
39
+ function assertRfqSwapPageFilter(filter) {
40
+ if (filter.since !== void 0 && (!Number.isSafeInteger(filter.since) || filter.since < 0)) {
41
+ throw new RangeError("RFQ history since must be non-negative Unix seconds");
42
+ }
43
+ }
35
44
 
36
45
  // src/repositories/realm/repository.ts
37
46
  var SWAPS = "ArkadeAssetSwap";
@@ -59,10 +68,8 @@ var RealmAssetSwapRepository = class {
59
68
  );
60
69
  });
61
70
  }
62
- async getAllSwaps() {
63
- return [...this.realm.objects(SWAPS)].map(
64
- (o) => JSON.parse(o.data)
65
- );
71
+ async getAssetSwapsPage(page) {
72
+ return this.pageRealm(SWAPS, "id", page);
66
73
  }
67
74
  async saveRfqSwap(record) {
68
75
  this.realm.write(() => {
@@ -84,10 +91,34 @@ var RealmAssetSwapRepository = class {
84
91
  ];
85
92
  return found ? JSON.parse(found.data) : void 0;
86
93
  }
87
- async getAllRfqSwaps() {
88
- return [...this.realm.objects(RFQ_SWAPS)].map(
89
- (o) => JSON.parse(o.data)
94
+ async getRfqSwapsPage(filter, page) {
95
+ (0, import_sdk2.assertPageRequest)(page);
96
+ assertRfqSwapPageFilter(filter);
97
+ let results = this.realm.objects(
98
+ RFQ_SWAPS
90
99
  );
100
+ if (filter.state !== void 0) results = results.filtered("state == $0", filter.state);
101
+ const since = Math.max(filter.since ?? 0, page.after?.updatedAt ?? 0);
102
+ results = results.filtered("updatedAt >= $0", since);
103
+ if (page.after && page.after.updatedAt >= (filter.since ?? 0)) {
104
+ results = results.filtered(
105
+ "updatedAt > $0 OR (updatedAt == $0 AND rfqId > $1)",
106
+ page.after.updatedAt,
107
+ page.after.rfqId
108
+ );
109
+ }
110
+ const rows = [];
111
+ for (const row of results.sorted([
112
+ ["updatedAt", false],
113
+ ["rfqId", false]
114
+ ])) {
115
+ rows.push(JSON.parse(row.data));
116
+ if (rows.length > page.limit) break;
117
+ }
118
+ return (0, import_sdk2.pageResult)(rows, page.limit, (record) => ({
119
+ updatedAt: record.updatedAt,
120
+ rfqId: record.rfqId
121
+ }));
91
122
  }
92
123
  async removeRfqSwap(rfqId) {
93
124
  this.realm.write(() => {
@@ -116,10 +147,23 @@ var RealmAssetSwapRepository = class {
116
147
  ];
117
148
  return found ? JSON.parse(found.data) : void 0;
118
149
  }
119
- async getAllSwapRecords() {
120
- return [...this.realm.objects(SWAP_RECORDS)].map(
121
- (o) => JSON.parse(o.data)
122
- );
150
+ async getSwapRecordsPage(page) {
151
+ return this.pageRealm(SWAP_RECORDS, "id", page);
152
+ }
153
+ pageRealm(schema, key, page) {
154
+ (0, import_sdk2.assertPageRequest)(page);
155
+ let results = this.realm.objects(schema);
156
+ if (page.after !== void 0) results = results.filtered(`${key} > $0`, page.after);
157
+ const rows = [];
158
+ for (const row of results.sorted(key)) {
159
+ rows.push({ key: row[key], data: row.data });
160
+ if (rows.length > page.limit) break;
161
+ }
162
+ const result = (0, import_sdk2.pageResult)(rows, page.limit, (row) => row.key);
163
+ return {
164
+ items: result.items.map((row) => JSON.parse(row.data)),
165
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
166
+ };
123
167
  }
124
168
  async removeSwapRecord(id) {
125
169
  this.realm.write(() => {
@@ -1,8 +1,8 @@
1
1
  import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
- import { c as AssetSwapRepository, aW as AssetSwap, d as RfqSwapRecord, S as SwapRecord, aX as MarketsCacheEntry } from '../../repository-DSGGq0ct.cjs';
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-C4pvymhs.cjs';
3
4
  import '@arkade-os/solver-discovery';
4
- import '@arkade-os/sdk';
5
- import '../../rfq-BO6o7NwS.cjs';
5
+ import '../../rfq-C0tHOvn6.cjs';
6
6
 
7
7
  /**
8
8
  * Realm backend for React Native.
@@ -29,14 +29,15 @@ declare class RealmAssetSwapRepository implements AssetSwapRepository {
29
29
  readonly version: 5;
30
30
  constructor(realm: RealmLike);
31
31
  saveSwap(swap: AssetSwap): Promise<void>;
32
- getAllSwaps(): Promise<AssetSwap[]>;
32
+ getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
33
33
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
34
34
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
35
- getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
35
+ getRfqSwapsPage(filter: RfqSwapPageFilter, page: PageRequest<RfqSwapPageCursor>): Promise<PageResult<RfqSwapRecord, RfqSwapPageCursor>>;
36
36
  removeRfqSwap(rfqId: string): Promise<void>;
37
37
  saveSwapRecord(record: SwapRecord): Promise<void>;
38
38
  getSwapRecord(id: string): Promise<SwapRecord | undefined>;
39
- getAllSwapRecords(): Promise<SwapRecord[]>;
39
+ getSwapRecordsPage(page: PageRequest): Promise<PageResult<SwapRecord>>;
40
+ private pageRealm;
40
41
  removeSwapRecord(id: string): Promise<void>;
41
42
  getScannedTxids(): Promise<Set<string>>;
42
43
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -52,23 +53,14 @@ declare class RealmAssetSwapRepository implements AssetSwapRepository {
52
53
  /**
53
54
  * Realm object schemas for the asset-swap repository.
54
55
  *
55
- * The names land in the **consuming application's** schema namespace, next to
56
- * its own models and the SDK's `Ark*`, so they are prefixed with
57
- * `ArkadeAssetSwap`. Unlike the SQLite backend there is no
58
- * prefix option: a Realm schema name is baked into the schema objects the
59
- * consumer registers and into every `realm.objects(…)` call here.
56
+ * Prefixed `ArkadeAssetSwap` because the names land in the consuming app's schema namespace; unlike
57
+ * SQLite there is no prefix option, since the name is baked into the schema objects and every
58
+ * `realm.objects(…)` call. Plain objects in Realm's ObjectSchema shape (`realm` is not a dependency);
59
+ * no migration helper ships, so consumers bump their own `schemaVersion` when schemas are added.
60
60
  *
61
- * Since `realm` is not a dependency of this package, schemas are plain JS
62
- * objects conforming to Realm's ObjectSchema shape. They are new, so a consumer
63
- * adds them to its Realm config and bumps its own `schemaVersion`; no migration
64
- * helper ships here.
65
- *
66
- * `ArkadeRfqSwap` arrived after the first three, and `ArkadeSwapRecord` after
67
- * that. A consumer already shipping the earlier set has to add the new one and
68
- * bump `schemaVersion` again — Realm creates schemas on open, so a config that
69
- * lists four while the code reads five fails on the fifth `realm.objects(…)`
70
- * rather than at open. Export {@link AssetSwapRealmSchemas} into the config
71
- * rather than listing names by hand and the mismatch cannot happen.
61
+ * Realm creates schemas on open, so a config missing a newer schema (`ArkadeRfqSwap`,
62
+ * `ArkadeSwapRecord`) fails on the first `realm.objects(…)` for it, not at open. Register
63
+ * {@link AssetSwapRealmSchemas} rather than listing names by hand.
72
64
  */
73
65
  declare const ArkadeAssetSwapSchema: {
74
66
  name: string;
@@ -96,7 +88,7 @@ declare const ArkadeAssetSwapMarketsCacheSchema: {
96
88
  };
97
89
  };
98
90
  /** Monitored RFQ swaps, keyed by `rfqId`. `state` and `updatedAt` are mapped out
99
- * for querying and for the retention sweep (`shouldRetainRfqSwap`); the record
91
+ * for state and date-filtered history queries; the record
100
92
  * itself goes in whole, `profile` included. */
101
93
  declare const ArkadeRfqSwapSchema: {
102
94
  name: string;
@@ -108,13 +100,9 @@ declare const ArkadeRfqSwapSchema: {
108
100
  data: string;
109
101
  };
110
102
  };
111
- /**
112
- * The v2 client's accept records, keyed by the client-minted quote id.
113
- *
114
- * `family` and `updatedAt` are mapped out for querying; the record itself goes
115
- * in whole, which is what keeps a nested corridor `profile` from being lost the
116
- * way a field-mapped schema could lose it.
117
- */
103
+ /** The v2 client's accept records, keyed by the client-minted quote id. `family` and `updatedAt` are
104
+ * mapped out for querying; the record goes in whole so a nested corridor `profile` cannot be lost
105
+ * the way a field-mapped schema could lose it. */
118
106
  declare const ArkadeSwapRecordSchema: {
119
107
  name: string;
120
108
  primaryKey: string;
@@ -1,8 +1,8 @@
1
1
  import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
- import { c as AssetSwapRepository, aW as AssetSwap, d as RfqSwapRecord, S as SwapRecord, aX as MarketsCacheEntry } from '../../repository-CGPLbjBe.js';
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-BBVRh9ez.js';
3
4
  import '@arkade-os/solver-discovery';
4
- import '@arkade-os/sdk';
5
- import '../../rfq-BO6o7NwS.js';
5
+ import '../../rfq-C0tHOvn6.js';
6
6
 
7
7
  /**
8
8
  * Realm backend for React Native.
@@ -29,14 +29,15 @@ declare class RealmAssetSwapRepository implements AssetSwapRepository {
29
29
  readonly version: 5;
30
30
  constructor(realm: RealmLike);
31
31
  saveSwap(swap: AssetSwap): Promise<void>;
32
- getAllSwaps(): Promise<AssetSwap[]>;
32
+ getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
33
33
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
34
34
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
35
- getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
35
+ getRfqSwapsPage(filter: RfqSwapPageFilter, page: PageRequest<RfqSwapPageCursor>): Promise<PageResult<RfqSwapRecord, RfqSwapPageCursor>>;
36
36
  removeRfqSwap(rfqId: string): Promise<void>;
37
37
  saveSwapRecord(record: SwapRecord): Promise<void>;
38
38
  getSwapRecord(id: string): Promise<SwapRecord | undefined>;
39
- getAllSwapRecords(): Promise<SwapRecord[]>;
39
+ getSwapRecordsPage(page: PageRequest): Promise<PageResult<SwapRecord>>;
40
+ private pageRealm;
40
41
  removeSwapRecord(id: string): Promise<void>;
41
42
  getScannedTxids(): Promise<Set<string>>;
42
43
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -52,23 +53,14 @@ declare class RealmAssetSwapRepository implements AssetSwapRepository {
52
53
  /**
53
54
  * Realm object schemas for the asset-swap repository.
54
55
  *
55
- * The names land in the **consuming application's** schema namespace, next to
56
- * its own models and the SDK's `Ark*`, so they are prefixed with
57
- * `ArkadeAssetSwap`. Unlike the SQLite backend there is no
58
- * prefix option: a Realm schema name is baked into the schema objects the
59
- * consumer registers and into every `realm.objects(…)` call here.
56
+ * Prefixed `ArkadeAssetSwap` because the names land in the consuming app's schema namespace; unlike
57
+ * SQLite there is no prefix option, since the name is baked into the schema objects and every
58
+ * `realm.objects(…)` call. Plain objects in Realm's ObjectSchema shape (`realm` is not a dependency);
59
+ * no migration helper ships, so consumers bump their own `schemaVersion` when schemas are added.
60
60
  *
61
- * Since `realm` is not a dependency of this package, schemas are plain JS
62
- * objects conforming to Realm's ObjectSchema shape. They are new, so a consumer
63
- * adds them to its Realm config and bumps its own `schemaVersion`; no migration
64
- * helper ships here.
65
- *
66
- * `ArkadeRfqSwap` arrived after the first three, and `ArkadeSwapRecord` after
67
- * that. A consumer already shipping the earlier set has to add the new one and
68
- * bump `schemaVersion` again — Realm creates schemas on open, so a config that
69
- * lists four while the code reads five fails on the fifth `realm.objects(…)`
70
- * rather than at open. Export {@link AssetSwapRealmSchemas} into the config
71
- * rather than listing names by hand and the mismatch cannot happen.
61
+ * Realm creates schemas on open, so a config missing a newer schema (`ArkadeRfqSwap`,
62
+ * `ArkadeSwapRecord`) fails on the first `realm.objects(…)` for it, not at open. Register
63
+ * {@link AssetSwapRealmSchemas} rather than listing names by hand.
72
64
  */
73
65
  declare const ArkadeAssetSwapSchema: {
74
66
  name: string;
@@ -96,7 +88,7 @@ declare const ArkadeAssetSwapMarketsCacheSchema: {
96
88
  };
97
89
  };
98
90
  /** Monitored RFQ swaps, keyed by `rfqId`. `state` and `updatedAt` are mapped out
99
- * for querying and for the retention sweep (`shouldRetainRfqSwap`); the record
91
+ * for state and date-filtered history queries; the record
100
92
  * itself goes in whole, `profile` included. */
101
93
  declare const ArkadeRfqSwapSchema: {
102
94
  name: string;
@@ -108,13 +100,9 @@ declare const ArkadeRfqSwapSchema: {
108
100
  data: string;
109
101
  };
110
102
  };
111
- /**
112
- * The v2 client's accept records, keyed by the client-minted quote id.
113
- *
114
- * `family` and `updatedAt` are mapped out for querying; the record itself goes
115
- * in whole, which is what keeps a nested corridor `profile` from being lost the
116
- * way a field-mapped schema could lose it.
117
- */
103
+ /** The v2 client's accept records, keyed by the client-minted quote id. `family` and `updatedAt` are
104
+ * mapped out for querying; the record goes in whole so a nested corridor `profile` cannot be lost
105
+ * the way a field-mapped schema could lose it. */
118
106
  declare const ArkadeSwapRecordSchema: {
119
107
  name: string;
120
108
  primaryKey: string;
@@ -1,8 +1,10 @@
1
1
  import {
2
+ assertRfqSwapPageFilter,
2
3
  marketsCacheKey
3
- } from "../../chunk-U7VWWTL6.js";
4
+ } from "../../chunk-A3SHHRX4.js";
4
5
 
5
6
  // src/repositories/realm/repository.ts
7
+ import { assertPageRequest, pageResult } from "@arkade-os/sdk";
6
8
  var SWAPS = "ArkadeAssetSwap";
7
9
  var RFQ_SWAPS = "ArkadeRfqSwap";
8
10
  var SWAP_RECORDS = "ArkadeSwapRecord";
@@ -28,10 +30,8 @@ var RealmAssetSwapRepository = class {
28
30
  );
29
31
  });
30
32
  }
31
- async getAllSwaps() {
32
- return [...this.realm.objects(SWAPS)].map(
33
- (o) => JSON.parse(o.data)
34
- );
33
+ async getAssetSwapsPage(page) {
34
+ return this.pageRealm(SWAPS, "id", page);
35
35
  }
36
36
  async saveRfqSwap(record) {
37
37
  this.realm.write(() => {
@@ -53,10 +53,34 @@ var RealmAssetSwapRepository = class {
53
53
  ];
54
54
  return found ? JSON.parse(found.data) : void 0;
55
55
  }
56
- async getAllRfqSwaps() {
57
- return [...this.realm.objects(RFQ_SWAPS)].map(
58
- (o) => JSON.parse(o.data)
56
+ async getRfqSwapsPage(filter, page) {
57
+ assertPageRequest(page);
58
+ assertRfqSwapPageFilter(filter);
59
+ let results = this.realm.objects(
60
+ RFQ_SWAPS
59
61
  );
62
+ if (filter.state !== void 0) results = results.filtered("state == $0", filter.state);
63
+ const since = Math.max(filter.since ?? 0, page.after?.updatedAt ?? 0);
64
+ results = results.filtered("updatedAt >= $0", since);
65
+ if (page.after && page.after.updatedAt >= (filter.since ?? 0)) {
66
+ results = results.filtered(
67
+ "updatedAt > $0 OR (updatedAt == $0 AND rfqId > $1)",
68
+ page.after.updatedAt,
69
+ page.after.rfqId
70
+ );
71
+ }
72
+ const rows = [];
73
+ for (const row of results.sorted([
74
+ ["updatedAt", false],
75
+ ["rfqId", false]
76
+ ])) {
77
+ rows.push(JSON.parse(row.data));
78
+ if (rows.length > page.limit) break;
79
+ }
80
+ return pageResult(rows, page.limit, (record) => ({
81
+ updatedAt: record.updatedAt,
82
+ rfqId: record.rfqId
83
+ }));
60
84
  }
61
85
  async removeRfqSwap(rfqId) {
62
86
  this.realm.write(() => {
@@ -85,10 +109,23 @@ var RealmAssetSwapRepository = class {
85
109
  ];
86
110
  return found ? JSON.parse(found.data) : void 0;
87
111
  }
88
- async getAllSwapRecords() {
89
- return [...this.realm.objects(SWAP_RECORDS)].map(
90
- (o) => JSON.parse(o.data)
91
- );
112
+ async getSwapRecordsPage(page) {
113
+ return this.pageRealm(SWAP_RECORDS, "id", page);
114
+ }
115
+ pageRealm(schema, key, page) {
116
+ assertPageRequest(page);
117
+ let results = this.realm.objects(schema);
118
+ if (page.after !== void 0) results = results.filtered(`${key} > $0`, page.after);
119
+ const rows = [];
120
+ for (const row of results.sorted(key)) {
121
+ rows.push({ key: row[key], data: row.data });
122
+ if (rows.length > page.limit) break;
123
+ }
124
+ const result = pageResult(rows, page.limit, (row) => row.key);
125
+ return {
126
+ items: result.items.map((row) => JSON.parse(row.data)),
127
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
128
+ };
92
129
  }
93
130
  async removeSwapRecord(id) {
94
131
  this.realm.write(() => {
@@ -26,9 +26,16 @@ module.exports = __toCommonJS(sqlite_exports);
26
26
 
27
27
  // src/repositories/sqlite/repository.ts
28
28
  var import_sqlite = require("@arkade-os/sdk/repositories/sqlite");
29
+ var import_sdk2 = require("@arkade-os/sdk");
29
30
 
30
31
  // src/repository.ts
32
+ var import_sdk = require("@arkade-os/sdk");
31
33
  var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
34
+ function assertRfqSwapPageFilter(filter) {
35
+ if (filter.since !== void 0 && (!Number.isSafeInteger(filter.since) || filter.since < 0)) {
36
+ throw new RangeError("RFQ history since must be non-negative Unix seconds");
37
+ }
38
+ }
32
39
 
33
40
  // src/repositories/sqlite/repository.ts
34
41
  var DEFAULT_PREFIX = "arkade_";
@@ -87,6 +94,13 @@ var SQLiteAssetSwapRepository = class {
87
94
  updated_at INTEGER NOT NULL,
88
95
  data TEXT NOT NULL
89
96
  )`);
97
+ await this.db.run(
98
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_updated ON ${this.rfqSwaps} (updated_at, rfq_id)`
99
+ );
100
+ await this.db.run(
101
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
102
+ );
103
+ await this.db.run(`DROP INDEX IF EXISTS idx_${this.prefix}rfq_swaps_page`);
90
104
  await this.db.run(
91
105
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
92
106
  );
@@ -124,10 +138,8 @@ var SQLiteAssetSwapRepository = class {
124
138
  );
125
139
  });
126
140
  }
127
- async getAllSwaps() {
128
- await this.ensureInit();
129
- const rows = await this.db.all(`SELECT data FROM ${this.swaps}`);
130
- return rows.map((r) => JSON.parse(r.data));
141
+ async getAssetSwapsPage(page) {
142
+ return this.pageTable(this.swaps, "id", page);
131
143
  }
132
144
  async saveRfqSwap(record) {
133
145
  await this.ensureInit();
@@ -147,10 +159,38 @@ var SQLiteAssetSwapRepository = class {
147
159
  );
148
160
  return row ? JSON.parse(row.data) : void 0;
149
161
  }
150
- async getAllRfqSwaps() {
162
+ async getRfqSwapsPage(filter, page) {
163
+ (0, import_sdk2.assertPageRequest)(page);
164
+ assertRfqSwapPageFilter(filter);
151
165
  await this.ensureInit();
152
- const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
153
- return rows.map((r) => JSON.parse(r.data));
166
+ const conditions = [];
167
+ const params = [];
168
+ if (filter.state !== void 0) {
169
+ conditions.push("state = ?");
170
+ params.push(filter.state);
171
+ }
172
+ if (filter.since !== void 0) {
173
+ conditions.push("updated_at >= ?");
174
+ params.push(filter.since);
175
+ }
176
+ if (page.after !== void 0) {
177
+ conditions.push("(updated_at, rfq_id) > (?, ?)");
178
+ params.push(page.after.updatedAt, page.after.rfqId);
179
+ }
180
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
181
+ const rows = await this.db.all(
182
+ `SELECT data, updated_at, rfq_id FROM ${this.rfqSwaps}${where}
183
+ ORDER BY updated_at, rfq_id LIMIT ?`,
184
+ [...params, page.limit + 1]
185
+ );
186
+ const result = (0, import_sdk2.pageResult)(rows, page.limit, (row) => ({
187
+ updatedAt: row.updated_at,
188
+ rfqId: row.rfq_id
189
+ }));
190
+ return {
191
+ items: result.items.map((row) => JSON.parse(row.data)),
192
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
193
+ };
154
194
  }
155
195
  async removeRfqSwap(rfqId) {
156
196
  await this.ensureInit();
@@ -176,10 +216,21 @@ var SQLiteAssetSwapRepository = class {
176
216
  );
177
217
  return row ? JSON.parse(row.data) : void 0;
178
218
  }
179
- async getAllSwapRecords() {
219
+ async getSwapRecordsPage(page) {
220
+ return this.pageTable(this.swapRecords, "id", page);
221
+ }
222
+ async pageTable(table, key, page) {
223
+ (0, import_sdk2.assertPageRequest)(page);
180
224
  await this.ensureInit();
181
- const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
182
- return rows.map((r) => JSON.parse(r.data));
225
+ const rows = await this.db.all(
226
+ 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 ?`,
227
+ page.after === void 0 ? [page.limit + 1] : [page.after, page.limit + 1]
228
+ );
229
+ const result = (0, import_sdk2.pageResult)(rows, page.limit, (row) => row.key);
230
+ return {
231
+ items: result.items.map((row) => JSON.parse(row.data)),
232
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
233
+ };
183
234
  }
184
235
  async removeSwapRecord(id) {
185
236
  await this.ensureInit();
@@ -1,8 +1,8 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
- import { c as AssetSwapRepository, aW as AssetSwap, d as RfqSwapRecord, S as SwapRecord, aX as MarketsCacheEntry } from '../../repository-DSGGq0ct.cjs';
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-C4pvymhs.cjs';
3
4
  import '@arkade-os/solver-discovery';
4
- import '@arkade-os/sdk';
5
- import '../../rfq-BO6o7NwS.cjs';
5
+ import '../../rfq-C0tHOvn6.cjs';
6
6
 
7
7
  /**
8
8
  * SQLite backend over the SDK's `SQLExecutor`, so any driver plugs in
@@ -58,14 +58,15 @@ declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
58
58
  * nest. */
59
59
  private withTx;
60
60
  saveSwap(swap: AssetSwap): Promise<void>;
61
- getAllSwaps(): Promise<AssetSwap[]>;
61
+ getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
62
62
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
63
63
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
64
- getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
64
+ getRfqSwapsPage(filter: RfqSwapPageFilter, page: PageRequest<RfqSwapPageCursor>): Promise<PageResult<RfqSwapRecord, RfqSwapPageCursor>>;
65
65
  removeRfqSwap(rfqId: string): Promise<void>;
66
66
  saveSwapRecord(record: SwapRecord): Promise<void>;
67
67
  getSwapRecord(id: string): Promise<SwapRecord | undefined>;
68
- getAllSwapRecords(): Promise<SwapRecord[]>;
68
+ getSwapRecordsPage(page: PageRequest): Promise<PageResult<SwapRecord>>;
69
+ private pageTable;
69
70
  removeSwapRecord(id: string): Promise<void>;
70
71
  getScannedTxids(): Promise<Set<string>>;
71
72
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  import { SQLExecutor } from '@arkade-os/sdk/repositories/sqlite';
2
- import { c as AssetSwapRepository, aW as AssetSwap, d as RfqSwapRecord, S as SwapRecord, aX as MarketsCacheEntry } from '../../repository-CGPLbjBe.js';
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-BBVRh9ez.js';
3
4
  import '@arkade-os/solver-discovery';
4
- import '@arkade-os/sdk';
5
- import '../../rfq-BO6o7NwS.js';
5
+ import '../../rfq-C0tHOvn6.js';
6
6
 
7
7
  /**
8
8
  * SQLite backend over the SDK's `SQLExecutor`, so any driver plugs in
@@ -58,14 +58,15 @@ declare class SQLiteAssetSwapRepository implements AssetSwapRepository {
58
58
  * nest. */
59
59
  private withTx;
60
60
  saveSwap(swap: AssetSwap): Promise<void>;
61
- getAllSwaps(): Promise<AssetSwap[]>;
61
+ getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
62
62
  saveRfqSwap(record: RfqSwapRecord): Promise<void>;
63
63
  getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
64
- getAllRfqSwaps(): Promise<RfqSwapRecord[]>;
64
+ getRfqSwapsPage(filter: RfqSwapPageFilter, page: PageRequest<RfqSwapPageCursor>): Promise<PageResult<RfqSwapRecord, RfqSwapPageCursor>>;
65
65
  removeRfqSwap(rfqId: string): Promise<void>;
66
66
  saveSwapRecord(record: SwapRecord): Promise<void>;
67
67
  getSwapRecord(id: string): Promise<SwapRecord | undefined>;
68
- getAllSwapRecords(): Promise<SwapRecord[]>;
68
+ getSwapRecordsPage(page: PageRequest): Promise<PageResult<SwapRecord>>;
69
+ private pageTable;
69
70
  removeSwapRecord(id: string): Promise<void>;
70
71
  getScannedTxids(): Promise<Set<string>>;
71
72
  markTxidsScanned(txids: Iterable<string>): Promise<void>;
@@ -1,12 +1,14 @@
1
1
  import {
2
+ assertRfqSwapPageFilter,
2
3
  marketsCacheKey
3
- } from "../../chunk-U7VWWTL6.js";
4
+ } from "../../chunk-A3SHHRX4.js";
4
5
 
5
6
  // src/repositories/sqlite/repository.ts
6
7
  import {
7
8
  runInTransaction,
8
9
  sanitizeTablePrefix
9
10
  } from "@arkade-os/sdk/repositories/sqlite";
11
+ import { assertPageRequest, pageResult } from "@arkade-os/sdk";
10
12
  var DEFAULT_PREFIX = "arkade_";
11
13
  var INSERT_CHUNK = 500;
12
14
  var SQLiteAssetSwapRepository = class {
@@ -63,6 +65,13 @@ var SQLiteAssetSwapRepository = class {
63
65
  updated_at INTEGER NOT NULL,
64
66
  data TEXT NOT NULL
65
67
  )`);
68
+ await this.db.run(
69
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_updated ON ${this.rfqSwaps} (updated_at, rfq_id)`
70
+ );
71
+ await this.db.run(
72
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
73
+ );
74
+ await this.db.run(`DROP INDEX IF EXISTS idx_${this.prefix}rfq_swaps_page`);
66
75
  await this.db.run(
67
76
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
68
77
  );
@@ -100,10 +109,8 @@ var SQLiteAssetSwapRepository = class {
100
109
  );
101
110
  });
102
111
  }
103
- async getAllSwaps() {
104
- await this.ensureInit();
105
- const rows = await this.db.all(`SELECT data FROM ${this.swaps}`);
106
- return rows.map((r) => JSON.parse(r.data));
112
+ async getAssetSwapsPage(page) {
113
+ return this.pageTable(this.swaps, "id", page);
107
114
  }
108
115
  async saveRfqSwap(record) {
109
116
  await this.ensureInit();
@@ -123,10 +130,38 @@ var SQLiteAssetSwapRepository = class {
123
130
  );
124
131
  return row ? JSON.parse(row.data) : void 0;
125
132
  }
126
- async getAllRfqSwaps() {
133
+ async getRfqSwapsPage(filter, page) {
134
+ assertPageRequest(page);
135
+ assertRfqSwapPageFilter(filter);
127
136
  await this.ensureInit();
128
- const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
129
- return rows.map((r) => JSON.parse(r.data));
137
+ const conditions = [];
138
+ const params = [];
139
+ if (filter.state !== void 0) {
140
+ conditions.push("state = ?");
141
+ params.push(filter.state);
142
+ }
143
+ if (filter.since !== void 0) {
144
+ conditions.push("updated_at >= ?");
145
+ params.push(filter.since);
146
+ }
147
+ if (page.after !== void 0) {
148
+ conditions.push("(updated_at, rfq_id) > (?, ?)");
149
+ params.push(page.after.updatedAt, page.after.rfqId);
150
+ }
151
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
152
+ const rows = await this.db.all(
153
+ `SELECT data, updated_at, rfq_id FROM ${this.rfqSwaps}${where}
154
+ ORDER BY updated_at, rfq_id LIMIT ?`,
155
+ [...params, page.limit + 1]
156
+ );
157
+ const result = pageResult(rows, page.limit, (row) => ({
158
+ updatedAt: row.updated_at,
159
+ rfqId: row.rfq_id
160
+ }));
161
+ return {
162
+ items: result.items.map((row) => JSON.parse(row.data)),
163
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
164
+ };
130
165
  }
131
166
  async removeRfqSwap(rfqId) {
132
167
  await this.ensureInit();
@@ -152,10 +187,21 @@ var SQLiteAssetSwapRepository = class {
152
187
  );
153
188
  return row ? JSON.parse(row.data) : void 0;
154
189
  }
155
- async getAllSwapRecords() {
190
+ async getSwapRecordsPage(page) {
191
+ return this.pageTable(this.swapRecords, "id", page);
192
+ }
193
+ async pageTable(table, key, page) {
194
+ assertPageRequest(page);
156
195
  await this.ensureInit();
157
- const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
158
- return rows.map((r) => JSON.parse(r.data));
196
+ const rows = await this.db.all(
197
+ 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 ?`,
198
+ page.after === void 0 ? [page.limit + 1] : [page.after, page.limit + 1]
199
+ );
200
+ const result = pageResult(rows, page.limit, (row) => row.key);
201
+ return {
202
+ items: result.items.map((row) => JSON.parse(row.data)),
203
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
204
+ };
159
205
  }
160
206
  async removeSwapRecord(id) {
161
207
  await this.ensureInit();