@arkade-os/swap 0.0.22 → 0.0.24
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 +30 -24
- package/dist/{chunk-6ZUS47GA.js → chunk-PJF4DWD7.js} +31 -0
- package/dist/index.cjs +262 -46
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +235 -48
- package/dist/repositories/realm/index.cjs +43 -0
- package/dist/repositories/realm/index.d.cts +3 -1
- package/dist/repositories/realm/index.d.ts +3 -1
- package/dist/repositories/realm/index.js +33 -1
- package/dist/repositories/sqlite/index.cjs +39 -0
- package/dist/repositories/sqlite/index.d.cts +3 -1
- package/dist/repositories/sqlite/index.d.ts +3 -1
- package/dist/repositories/sqlite/index.js +29 -1
- package/dist/{repository-PNlTFdsj.d.ts → repository-BT33JsPT.d.ts} +47 -28
- package/dist/{repository-CZYc8Y38.d.cts → repository-CSBh-0NH.d.cts} +47 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -677,7 +677,7 @@ from it, and a swap carrying only `lockupPkScript` is refused rather than pushed
|
|
|
677
677
|
### Let the manager own the records
|
|
678
678
|
|
|
679
679
|
Give `RfqSwapManager` a `repository` and it persists RFQ swaps itself — the restore loop, the
|
|
680
|
-
|
|
680
|
+
restore pass and every write, none of which a consumer has to compose:
|
|
681
681
|
|
|
682
682
|
```ts
|
|
683
683
|
const manager = new RfqSwapManager({
|
|
@@ -687,9 +687,8 @@ const manager = new RfqSwapManager({
|
|
|
687
687
|
});
|
|
688
688
|
manager.setCallbacks({ refundArkade, claimLockup });
|
|
689
689
|
|
|
690
|
-
//
|
|
691
|
-
|
|
692
|
-
const { restored, failed, pruned } = await manager.restoreFromRepository();
|
|
690
|
+
// Restore active swaps from bounded state pages; terminal history stays stored.
|
|
691
|
+
const { restored, failed } = await manager.restoreFromRepository();
|
|
693
692
|
await manager.start();
|
|
694
693
|
|
|
695
694
|
// A NEW swap arrives with the request-time half a live record cannot carry.
|
|
@@ -713,14 +712,26 @@ An origin whose `kind` or `lockupAddress` is not this swap's is refused at that
|
|
|
713
712
|
same reason: the write that would catch it happens a pass later, with the funding broadcast.
|
|
714
713
|
`start(swaps)` applies the same rule and is otherwise unchanged. Restored swaps carry their own.
|
|
715
714
|
|
|
716
|
-
`restoreFromRepository` returns
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
`
|
|
715
|
+
`restoreFromRepository` returns active swaps in `restored` and active records that cannot be rebuilt
|
|
716
|
+
in `failed`. Terminal history remains in the repository; `waitForSwapCompletion(rfqId)` reads one
|
|
717
|
+
terminal record on demand, regardless of age. Pass `{ includeTerminal: true }` for the previous
|
|
718
|
+
all-record restore result, which can use substantial memory. Built-in backends page active states by
|
|
719
|
+
`rfqId`; custom repositories without `getRfqSwapsPage` retain the all-record fallback. A record
|
|
720
|
+
that cannot be rebuilt — no contract row (`LockupContractMissing`), mismatched covenant params, or
|
|
721
|
+
missing corridor handler — stays in the store and never strands the others. The legacy explicit
|
|
722
|
+
`pruneRetiredSwaps()` method remains for callers that choose to delete history. Pass `{ params }`
|
|
723
|
+
to take covenants from somewhere other than the contract store.
|
|
724
|
+
|
|
725
|
+
For a bounded history read, call `getRfqSwapsPage(state, afterId, limit)` on a built-in repository.
|
|
726
|
+
Pages are ordered by `rfqId` within one state; the cursor is exclusive and the limit is 1–500.
|
|
727
|
+
`rfqSwapActivityInputsPage({ repository, indexer }, state, afterId, limit)` projects one such page
|
|
728
|
+
with at most 16 concurrent indexer fallbacks. For date-filtered history, use
|
|
729
|
+
`rfqSwapActivityInputsSincePage({ repository, indexer }, state, since, cursor, limit)`, where `since`
|
|
730
|
+
is inclusive Unix seconds and the returned cursor combines `updatedAt` and `rfqId`.
|
|
731
|
+
`getAllRfqSwaps()`, `rfqSwapActivityInputs()`, and the
|
|
732
|
+
wallet's full `getActivityHistory()` still return complete arrays and should not be used for million-row
|
|
733
|
+
history displays. IndexedDB upgrades its RFQ store from version 3 to 4 to add the page index; the
|
|
734
|
+
upgrade preserves records but an older package opening that same database name cannot roll back.
|
|
724
735
|
|
|
725
736
|
**Two sinks, and both gate.** With a repository wired the canonical `RfqSwapRecord` is written
|
|
726
737
|
first, then `saveSwap` if one is installed, and the pass counts as persisted only when both
|
|
@@ -882,7 +893,7 @@ Notes from before 0.0.1, kept for consumers who tracked the branch.
|
|
|
882
893
|
- **The repository interface is at version `4`.** It gained
|
|
883
894
|
`getRfqSwap(rfqId): Promise<RfqSwapRecord | undefined>` — every backend is already keyed by
|
|
884
895
|
`rfqId`, so a consumer updating one record no longer scans them all. A miss returns `undefined`;
|
|
885
|
-
|
|
896
|
+
a record can be absent after an explicit removal. All four in-tree backends implement it
|
|
886
897
|
and `DB_VERSION` is unchanged; a custom implementor adds the two-line read and bumps its own
|
|
887
898
|
`version` to `4`.
|
|
888
899
|
- **`RfqSwapOrigin` gained `fundingArkTxid?`** — the ark transaction that funded the lockup. It is
|
|
@@ -1058,17 +1069,12 @@ scanned? })` — the server key is required because a spend is classified by reb
|
|
|
1058
1069
|
`VHTLCV2ContractHandler.serializeParams(script.options)` and pass that instead; either way the
|
|
1059
1070
|
params are checked against the record's `lockupAddress` before a swap is handed back, so the wrong
|
|
1060
1071
|
row fails at restore rather than at refund time. **Superseded** for a consumer that wires
|
|
1061
|
-
`RfqSwapManagerDeps.repository`: `restoreFromRepository()`
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
- **
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
at boot and pass the rejects to `removeRfqSwap`; skip it and a hot wallet's `rfqSwaps` store grows
|
|
1068
|
-
without bound. `now` is **unix seconds**, the unit `RfqSwap.updatedAt` carries — `Date.now()` would
|
|
1069
|
-
retire every terminal record after ~43 minutes. **Superseded** for a consumer that wires
|
|
1070
|
-
`RfqSwapManagerDeps.repository`: `pruneRetiredSwaps()` is that sweep, and
|
|
1071
|
-
`restoreFromRepository()` runs it first.
|
|
1072
|
+
`RfqSwapManagerDeps.repository`: `restoreFromRepository()` rebuilds
|
|
1073
|
+
active records from state pages. Pass `includeTerminal: true` for the all-record result.
|
|
1074
|
+
|
|
1075
|
+
- **RFQ history is durable.** Restore reads only active states in pages and leaves terminal records
|
|
1076
|
+
stored. The older `pruneRetiredSwaps()` and `shouldRetainRfqSwap` APIs remain only for callers who
|
|
1077
|
+
explicitly choose deletion; their time arguments are Unix seconds.
|
|
1072
1078
|
- **A write that gates something irreversible throws; one that follows it does not.**
|
|
1073
1079
|
`addAssetSwap` and `updateAssetSwap` throw on a failed read or write — nothing irreversible may
|
|
1074
1080
|
happen until the record is durable, which is why `cancelOffer` writes its `cancelling` marker
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
// src/repository.ts
|
|
2
|
+
var RFQ_SWAP_MAX_PAGE_SIZE = 500;
|
|
3
|
+
function assertRfqSwapPageLimit(limit) {
|
|
4
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > RFQ_SWAP_MAX_PAGE_SIZE) {
|
|
5
|
+
throw new RangeError(
|
|
6
|
+
`RFQ swap page limit must be an integer from 1 to ${RFQ_SWAP_MAX_PAGE_SIZE}`
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function assertRfqSwapSince(since) {
|
|
11
|
+
if (!Number.isSafeInteger(since) || since < 0) {
|
|
12
|
+
throw new RangeError("RFQ history since must be a non-negative Unix timestamp in seconds");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
2
15
|
var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
|
|
3
16
|
var InMemoryAssetSwapRepository = class {
|
|
4
17
|
version = 4;
|
|
@@ -21,6 +34,21 @@ var InMemoryAssetSwapRepository = class {
|
|
|
21
34
|
async getAllRfqSwaps() {
|
|
22
35
|
return [...this.rfqSwaps.values()];
|
|
23
36
|
}
|
|
37
|
+
async getRfqSwapsPage(state, afterId, limit) {
|
|
38
|
+
assertRfqSwapPageLimit(limit);
|
|
39
|
+
return [...this.rfqSwaps.values()].filter(
|
|
40
|
+
(record) => record.state === state && (afterId === void 0 || record.rfqId > afterId)
|
|
41
|
+
).sort((a, b) => a.rfqId < b.rfqId ? -1 : a.rfqId > b.rfqId ? 1 : 0).slice(0, limit);
|
|
42
|
+
}
|
|
43
|
+
async getRfqSwapsUpdatedPage(state, since, after, limit) {
|
|
44
|
+
assertRfqSwapPageLimit(limit);
|
|
45
|
+
assertRfqSwapSince(since);
|
|
46
|
+
return [...this.rfqSwaps.values()].filter(
|
|
47
|
+
(record) => record.state === state && record.updatedAt >= since && (!after || record.updatedAt > after.updatedAt || record.updatedAt === after.updatedAt && record.rfqId > after.rfqId)
|
|
48
|
+
).sort(
|
|
49
|
+
(a, b) => a.updatedAt - b.updatedAt || (a.rfqId < b.rfqId ? -1 : a.rfqId > b.rfqId ? 1 : 0)
|
|
50
|
+
).slice(0, limit);
|
|
51
|
+
}
|
|
24
52
|
async removeRfqSwap(rfqId) {
|
|
25
53
|
this.rfqSwaps.delete(rfqId);
|
|
26
54
|
}
|
|
@@ -47,6 +75,9 @@ var InMemoryAssetSwapRepository = class {
|
|
|
47
75
|
};
|
|
48
76
|
|
|
49
77
|
export {
|
|
78
|
+
RFQ_SWAP_MAX_PAGE_SIZE,
|
|
79
|
+
assertRfqSwapPageLimit,
|
|
80
|
+
assertRfqSwapSince,
|
|
50
81
|
marketsCacheKey,
|
|
51
82
|
InMemoryAssetSwapRepository
|
|
52
83
|
};
|