@arkade-os/swap 0.1.0-rc.13 → 0.1.0-rc.15

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 (53) hide show
  1. package/README.md +11 -0
  2. package/dist/advanced.cjs +1028 -1006
  3. package/dist/advanced.d.cts +145 -279
  4. package/dist/advanced.d.ts +145 -279
  5. package/dist/advanced.js +14 -8
  6. package/dist/{chunk-SC3SAY3X.js → chunk-4WPDXLXH.js} +501 -271
  7. package/dist/chunk-A3SHHRX4.js +104 -0
  8. package/dist/{chunk-KRXPQQJ7.js → chunk-BBP25BWH.js} +198 -218
  9. package/dist/{chunk-ZDFMD4FA.js → chunk-RX3WPV5D.js} +356 -584
  10. package/dist/errors-BcOgFV-F.d.ts +1559 -0
  11. package/dist/errors-n6IHTG-Z.d.cts +1559 -0
  12. package/dist/index.cjs +1406 -1331
  13. package/dist/index.d.cts +69 -186
  14. package/dist/index.d.ts +69 -186
  15. package/dist/index.js +102 -158
  16. package/dist/lockupContract-B_jNbjrG.d.ts +215 -0
  17. package/dist/lockupContract-ZsftgqMc.d.cts +215 -0
  18. package/dist/node/index.cjs +61 -10
  19. package/dist/node/index.d.cts +227 -600
  20. package/dist/node/index.d.ts +227 -600
  21. package/dist/node/index.js +65 -10
  22. package/dist/nostr.cjs +11 -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--1zVkNsV.d.ts +261 -0
  27. package/dist/offer-DsP1q6GE.d.cts +261 -0
  28. package/dist/protocol.cjs +747 -1012
  29. package/dist/protocol.d.cts +120 -255
  30. package/dist/protocol.d.ts +120 -255
  31. package/dist/protocol.js +146 -149
  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-BY6GUQiW.d.ts +2233 -0
  41. package/dist/repository-C32GKpR5.d.cts +2233 -0
  42. package/dist/{rfq-BWE8qkV2.d.ts → rfq-60PGpQ_x.d.cts} +178 -408
  43. package/dist/{rfq-BWE8qkV2.d.cts → rfq-60PGpQ_x.d.ts} +178 -408
  44. package/dist/{watch-D8Z78RAV.d.ts → watch-Cejw5cNQ.d.cts} +12 -30
  45. package/dist/{watch-C4ReJR5z.d.cts → watch-D8uzWrHc.d.ts} +12 -30
  46. package/package.json +2 -2
  47. package/dist/chunk-U7VWWTL6.js +0 -66
  48. package/dist/errors-LXMcNhNS.d.ts +0 -2222
  49. package/dist/errors-XUs8r0LT.d.cts +0 -2222
  50. package/dist/lockupContract-BhMebZCb.d.cts +0 -650
  51. package/dist/lockupContract-CAiN97fX.d.ts +0 -650
  52. package/dist/repository-BJLuVFQ0.d.ts +0 -3436
  53. package/dist/repository-DsR3b0JJ.d.cts +0 -3436
@@ -0,0 +1,104 @@
1
+ // src/repository.ts
2
+ import {
3
+ assertPageRequest,
4
+ collectPages,
5
+ pageResult
6
+ } from "@arkade-os/sdk";
7
+ var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
8
+ function assertRfqSwapPageFilter(filter) {
9
+ if (filter.since !== void 0 && (!Number.isSafeInteger(filter.since) || filter.since < 0)) {
10
+ throw new RangeError("RFQ history since must be non-negative Unix seconds");
11
+ }
12
+ }
13
+ var InMemoryAssetSwapRepository = class {
14
+ version = 5;
15
+ swaps = /* @__PURE__ */ new Map();
16
+ records = /* @__PURE__ */ new Map();
17
+ rfqSwaps = /* @__PURE__ */ new Map();
18
+ scanned = /* @__PURE__ */ new Set();
19
+ markets = /* @__PURE__ */ new Map();
20
+ async saveSwap(swap) {
21
+ this.swaps.set(swap.id, swap);
22
+ }
23
+ async getAssetSwapsPage(page) {
24
+ return pageMap(this.swaps, page);
25
+ }
26
+ async saveRfqSwap(record) {
27
+ this.rfqSwaps.set(record.rfqId, record);
28
+ }
29
+ async getRfqSwap(rfqId) {
30
+ return this.rfqSwaps.get(rfqId);
31
+ }
32
+ async getRfqSwapsPage(filter, page) {
33
+ assertPageRequest(page);
34
+ assertRfqSwapPageFilter(filter);
35
+ const rows = [...this.rfqSwaps.values()].filter(
36
+ (record) => (filter.state === void 0 || record.state === filter.state) && (filter.since === void 0 || record.updatedAt >= filter.since) && (!page.after || record.updatedAt > page.after.updatedAt || record.updatedAt === page.after.updatedAt && record.rfqId > page.after.rfqId)
37
+ ).sort(
38
+ (a, b) => a.updatedAt - b.updatedAt || (a.rfqId < b.rfqId ? -1 : a.rfqId > b.rfqId ? 1 : 0)
39
+ ).slice(0, page.limit + 1);
40
+ return pageResult(rows, page.limit, (record) => ({
41
+ updatedAt: record.updatedAt,
42
+ rfqId: record.rfqId
43
+ }));
44
+ }
45
+ async removeRfqSwap(rfqId) {
46
+ this.rfqSwaps.delete(rfqId);
47
+ }
48
+ async saveSwapRecord(record) {
49
+ this.records.set(record.id, record);
50
+ }
51
+ async getSwapRecord(id) {
52
+ return this.records.get(id);
53
+ }
54
+ async getSwapRecordsPage(page) {
55
+ return pageMap(this.records, page);
56
+ }
57
+ async removeSwapRecord(id) {
58
+ this.records.delete(id);
59
+ }
60
+ async getScannedTxids() {
61
+ return new Set(this.scanned);
62
+ }
63
+ async markTxidsScanned(txids) {
64
+ for (const txid of txids) this.scanned.add(txid);
65
+ }
66
+ async getCachedMarkets(network, registry) {
67
+ return this.markets.get(marketsCacheKey(network, registry));
68
+ }
69
+ async saveCachedMarkets(network, registry, entry) {
70
+ this.markets.set(marketsCacheKey(network, registry), entry);
71
+ }
72
+ async clear() {
73
+ this.swaps.clear();
74
+ this.rfqSwaps.clear();
75
+ this.records.clear();
76
+ this.scanned.clear();
77
+ this.markets.clear();
78
+ }
79
+ async [Symbol.asyncDispose]() {
80
+ }
81
+ };
82
+ function pageMap(records, page) {
83
+ assertPageRequest(page);
84
+ const rows = [...records].filter(([id]) => page.after === void 0 || id > page.after).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).slice(0, page.limit + 1);
85
+ const result = pageResult(rows, page.limit, ([id]) => id);
86
+ return {
87
+ items: result.items.map(([, item]) => item),
88
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
89
+ };
90
+ }
91
+ var collectAssetSwaps = (repository) => collectPages((page) => repository.getAssetSwapsPage(page));
92
+ var collectRfqSwaps = (repository, filter = {}) => collectPages(
93
+ (page) => repository.getRfqSwapsPage(filter, page)
94
+ );
95
+ var collectSwapRecords = (repository) => collectPages((page) => repository.getSwapRecordsPage(page));
96
+
97
+ export {
98
+ marketsCacheKey,
99
+ assertRfqSwapPageFilter,
100
+ InMemoryAssetSwapRepository,
101
+ collectAssetSwaps,
102
+ collectRfqSwaps,
103
+ collectSwapRecords
104
+ };