@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.
- package/README.md +52 -2
- package/dist/advanced.cjs +8376 -0
- package/dist/advanced.d.cts +550 -0
- package/dist/advanced.d.ts +550 -0
- package/dist/advanced.js +451 -0
- package/dist/chunk-A3SHHRX4.js +104 -0
- package/dist/chunk-HUQQVBC4.js +4262 -0
- package/dist/{chunk-EOYGUCDM.js → chunk-ITFCQWPG.js} +755 -1382
- package/dist/chunk-PVB7EBAM.js +2517 -0
- package/dist/errors-C3h8ANmE.d.ts +1560 -0
- package/dist/errors-hm7aqnRM.d.cts +1560 -0
- package/dist/index.cjs +4861 -3988
- package/dist/index.d.cts +69 -2812
- package/dist/index.d.ts +69 -2812
- package/dist/index.js +179 -3719
- package/dist/lockupContract-5r5RlgOJ.d.cts +137 -0
- package/dist/lockupContract-5r5RlgOJ.d.ts +137 -0
- package/dist/node/index.cjs +61 -10
- package/dist/node/index.d.cts +249 -591
- package/dist/node/index.d.ts +249 -591
- package/dist/node/index.js +65 -10
- package/dist/nostr.cjs +191 -11
- package/dist/nostr.d.cts +23 -68
- package/dist/nostr.d.ts +23 -68
- package/dist/nostr.js +3 -4
- package/dist/offer-Bd9Yvd8Z.d.ts +261 -0
- package/dist/offer-F88rtL_I.d.cts +261 -0
- package/dist/protocol.cjs +4086 -3706
- package/dist/protocol.d.cts +163 -768
- package/dist/protocol.d.ts +163 -768
- package/dist/protocol.js +190 -173
- package/dist/repositories/realm/index.cjs +55 -11
- package/dist/repositories/realm/index.d.cts +18 -30
- package/dist/repositories/realm/index.d.ts +18 -30
- package/dist/repositories/realm/index.js +49 -12
- package/dist/repositories/sqlite/index.cjs +61 -10
- package/dist/repositories/sqlite/index.d.cts +7 -6
- package/dist/repositories/sqlite/index.d.ts +7 -6
- package/dist/repositories/sqlite/index.js +57 -11
- package/dist/repository-BuYWGAKz.d.cts +2261 -0
- package/dist/repository-DYnRLPt-.d.ts +2261 -0
- package/dist/rfq-60PGpQ_x.d.cts +950 -0
- package/dist/rfq-60PGpQ_x.d.ts +950 -0
- package/dist/watch-BTyiBLSd.d.ts +74 -0
- package/dist/watch-M_KY-5ho.d.cts +74 -0
- package/package.json +20 -10
- package/dist/chunk-LYCMM3VB.js +0 -1357
- package/dist/chunk-U7VWWTL6.js +0 -66
- package/dist/repository-_zU9_pM3.d.cts +0 -3426
- package/dist/repository-kO95noyv.d.ts +0 -3426
- package/dist/rfq-DdBV4JO5.d.cts +0 -1097
- package/dist/rfq-DdBV4JO5.d.ts +0 -1097
- package/dist/watch-CQqvwgwY.d.cts +0 -96
- package/dist/watch-wMbmfN4p.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
|
|
63
|
-
return
|
|
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
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
120
|
-
return
|
|
121
|
-
|
|
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 {
|
|
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, b1 as MarketsCacheEntry } from '../../repository-BuYWGAKz.cjs';
|
|
3
4
|
import '@arkade-os/solver-discovery';
|
|
4
|
-
import '
|
|
5
|
-
import '../../rfq-DdBV4JO5.cjs';
|
|
5
|
+
import '../../rfq-60PGpQ_x.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
|
-
|
|
32
|
+
getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
|
|
33
33
|
saveRfqSwap(record: RfqSwapRecord): Promise<void>;
|
|
34
34
|
getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* `
|
|
58
|
-
*
|
|
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
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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 {
|
|
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, b1 as MarketsCacheEntry } from '../../repository-DYnRLPt-.js';
|
|
3
4
|
import '@arkade-os/solver-discovery';
|
|
4
|
-
import '
|
|
5
|
-
import '../../rfq-DdBV4JO5.js';
|
|
5
|
+
import '../../rfq-60PGpQ_x.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
|
-
|
|
32
|
+
getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
|
|
33
33
|
saveRfqSwap(record: RfqSwapRecord): Promise<void>;
|
|
34
34
|
getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* `
|
|
58
|
-
*
|
|
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
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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-
|
|
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
|
|
32
|
-
return
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
89
|
-
return
|
|
90
|
-
|
|
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
|
|
128
|
-
|
|
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
|
|
162
|
+
async getRfqSwapsPage(filter, page) {
|
|
163
|
+
(0, import_sdk2.assertPageRequest)(page);
|
|
164
|
+
assertRfqSwapPageFilter(filter);
|
|
151
165
|
await this.ensureInit();
|
|
152
|
-
const
|
|
153
|
-
|
|
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
|
|
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(
|
|
182
|
-
|
|
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 {
|
|
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, b1 as MarketsCacheEntry } from '../../repository-BuYWGAKz.cjs';
|
|
3
4
|
import '@arkade-os/solver-discovery';
|
|
4
|
-
import '
|
|
5
|
-
import '../../rfq-DdBV4JO5.cjs';
|
|
5
|
+
import '../../rfq-60PGpQ_x.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
|
-
|
|
61
|
+
getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
|
|
62
62
|
saveRfqSwap(record: RfqSwapRecord): Promise<void>;
|
|
63
63
|
getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
|
|
64
|
-
|
|
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
|
-
|
|
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 {
|
|
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, b1 as MarketsCacheEntry } from '../../repository-DYnRLPt-.js';
|
|
3
4
|
import '@arkade-os/solver-discovery';
|
|
4
|
-
import '
|
|
5
|
-
import '../../rfq-DdBV4JO5.js';
|
|
5
|
+
import '../../rfq-60PGpQ_x.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
|
-
|
|
61
|
+
getAssetSwapsPage(page: PageRequest): Promise<PageResult<AssetSwap>>;
|
|
62
62
|
saveRfqSwap(record: RfqSwapRecord): Promise<void>;
|
|
63
63
|
getRfqSwap(rfqId: string): Promise<RfqSwapRecord | undefined>;
|
|
64
|
-
|
|
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
|
-
|
|
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-
|
|
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
|
|
104
|
-
|
|
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
|
|
133
|
+
async getRfqSwapsPage(filter, page) {
|
|
134
|
+
assertPageRequest(page);
|
|
135
|
+
assertRfqSwapPageFilter(filter);
|
|
127
136
|
await this.ensureInit();
|
|
128
|
-
const
|
|
129
|
-
|
|
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
|
|
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(
|
|
158
|
-
|
|
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();
|