@pear-protocol/exchanges-sdk 0.6.1 → 0.6.2
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.
|
@@ -4,7 +4,6 @@ import { BaseAccountSyncer } from '../base';
|
|
|
4
4
|
import { toFundingPaymentEntries } from './funding';
|
|
5
5
|
|
|
6
6
|
const HYPERLIQUID_FILL_PAGE_LIMIT = 2e3;
|
|
7
|
-
const HYPERLIQUID_FILL_RETENTION_LIMIT = 1e4;
|
|
8
7
|
class HyperliquidAccountSyncer extends BaseAccountSyncer {
|
|
9
8
|
address;
|
|
10
9
|
constructor(config) {
|
|
@@ -66,7 +65,6 @@ class HyperliquidAccountSyncer extends BaseAccountSyncer {
|
|
|
66
65
|
}, {});
|
|
67
66
|
const allFills = [];
|
|
68
67
|
const seenFillIds = /* @__PURE__ */ new Set();
|
|
69
|
-
let oldestReachableFillTime = null;
|
|
70
68
|
const addFill = (fill) => {
|
|
71
69
|
const fillId = hyperliquidFillId(fill);
|
|
72
70
|
if (!seenFillIds.has(fillId)) {
|
|
@@ -87,17 +85,9 @@ class HyperliquidAccountSyncer extends BaseAccountSyncer {
|
|
|
87
85
|
this.demo
|
|
88
86
|
);
|
|
89
87
|
batchSize = batch.length;
|
|
90
|
-
if (batch.length > 0 && oldestReachableFillTime === null) {
|
|
91
|
-
oldestReachableFillTime = Math.min(...batch.map((fill) => fill.time));
|
|
92
|
-
}
|
|
93
88
|
for (const rawFill of batch) {
|
|
94
89
|
addFill(rawFill);
|
|
95
90
|
}
|
|
96
|
-
if (seenFillIds.size >= HYPERLIQUID_FILL_RETENTION_LIMIT && oldestReachableFillTime !== null && since.getTime() < oldestReachableFillTime) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Hyperliquid fill history is incomplete: requested since ${since.getTime()} predates oldest reachable fill ${oldestReachableFillTime} within the ${HYPERLIQUID_FILL_RETENTION_LIMIT}-fill retention limit.`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
91
|
if (batchSize === HYPERLIQUID_FILL_PAGE_LIMIT) {
|
|
102
92
|
const nextCursor = batch[batch.length - 1]?.time ?? cursor;
|
|
103
93
|
if (nextCursor <= cursor) {
|
|
@@ -164,29 +164,26 @@ describe("HyperliquidAccountSyncer fill mapping", () => {
|
|
|
164
164
|
expect(fetchInfoMock).toHaveBeenCalledTimes(2);
|
|
165
165
|
consoleWarn.mockRestore();
|
|
166
166
|
});
|
|
167
|
-
it("
|
|
167
|
+
it("imports the reachable history of a never-synced account whose older fills fell out of retention", async () => {
|
|
168
168
|
let page = 0;
|
|
169
169
|
fetchInfoMock.mockImplementation(async (body) => {
|
|
170
|
-
if (body.type
|
|
170
|
+
if (body.type === "userTwapSliceFillsByTime") return [];
|
|
171
|
+
if (page >= 5) return [];
|
|
171
172
|
const firstTime = 1e3 + page * 2e3;
|
|
172
173
|
page += 1;
|
|
173
174
|
return Array.from({ length: 2e3 }, (_, index) => rawFill(firstTime + index));
|
|
174
175
|
});
|
|
175
176
|
const syncer = createSyncer();
|
|
176
|
-
await
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
).rejects.toThrow(
|
|
184
|
-
"Hyperliquid fill history is incomplete: requested since 0 predates oldest reachable fill 1000 within the 10000-fill retention limit."
|
|
185
|
-
);
|
|
186
|
-
expect(fetchInfoMock).toHaveBeenCalledTimes(5);
|
|
177
|
+
const fills = await syncer.listExternalFills({
|
|
178
|
+
since: /* @__PURE__ */ new Date(0),
|
|
179
|
+
instruments: [instrument],
|
|
180
|
+
openPositions: [],
|
|
181
|
+
provisionalFills: []
|
|
182
|
+
});
|
|
183
|
+
expect(fills).toHaveLength(1e4);
|
|
187
184
|
expect(fetchInfoMock).toHaveBeenCalledWith(expect.objectContaining({ aggregateByTime: false }), true);
|
|
188
185
|
});
|
|
189
|
-
it("
|
|
186
|
+
it("pages through a full retention window of fills", async () => {
|
|
190
187
|
let page = 0;
|
|
191
188
|
fetchInfoMock.mockImplementation(async (body) => {
|
|
192
189
|
if (body.type === "userTwapSliceFillsByTime") return [];
|