@lightconexyz/lightcone-sdk 0.7.1 → 0.8.1-rc.3
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 +20 -0
- package/dist/auth/client.d.ts +3 -3
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +19 -38
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +95 -54
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +82 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +0 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +0 -4
- package/dist/client.js.map +1 -1
- package/dist/domain/index.d.ts +0 -1
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +1 -2
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/market/tokens.d.ts +2 -0
- package/dist/domain/market/tokens.d.ts.map +1 -1
- package/dist/domain/market/tokens.js +8 -0
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +1 -0
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/metrics/client.d.ts +8 -2
- package/dist/domain/metrics/client.d.ts.map +1 -1
- package/dist/domain/metrics/client.js +48 -1
- package/dist/domain/metrics/client.js.map +1 -1
- package/dist/domain/metrics/wire.d.ts +107 -4
- package/dist/domain/metrics/wire.d.ts.map +1 -1
- package/dist/domain/metrics/wire.js.map +1 -1
- package/dist/domain/order/client.d.ts +4 -2
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/wire.d.ts +41 -24
- package/dist/domain/order/wire.d.ts.map +1 -1
- package/dist/domain/order/wire.js +46 -18
- package/dist/domain/order/wire.js.map +1 -1
- package/dist/domain/orderbook/aggregation.d.ts +50 -0
- package/dist/domain/orderbook/aggregation.d.ts.map +1 -0
- package/dist/domain/orderbook/aggregation.js +85 -0
- package/dist/domain/orderbook/aggregation.js.map +1 -0
- package/dist/domain/orderbook/client.d.ts +11 -1
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +24 -3
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/orderbook/index.d.ts +1 -0
- package/dist/domain/orderbook/index.d.ts.map +1 -1
- package/dist/domain/orderbook/index.js +1 -0
- package/dist/domain/orderbook/index.js.map +1 -1
- package/dist/domain/orderbook/state.d.ts +29 -31
- package/dist/domain/orderbook/state.d.ts.map +1 -1
- package/dist/domain/orderbook/state.js +20 -67
- package/dist/domain/orderbook/state.js.map +1 -1
- package/dist/domain/orderbook/wire.d.ts +32 -0
- package/dist/domain/orderbook/wire.d.ts.map +1 -1
- package/dist/domain/orderbook/wire.js.map +1 -1
- package/dist/env.d.ts +18 -3
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +28 -4
- package/dist/env.js.map +1 -1
- package/dist/http/client.d.ts +1 -4
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +56 -22
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +9 -8
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +20 -4
- package/dist/prelude.js.map +1 -1
- package/dist/shared/fmt/index.d.ts +1 -0
- package/dist/shared/fmt/index.d.ts.map +1 -1
- package/dist/shared/fmt/index.js +2 -1
- package/dist/shared/fmt/index.js.map +1 -1
- package/dist/shared/fmt/str.d.ts +8 -0
- package/dist/shared/fmt/str.d.ts.map +1 -0
- package/dist/shared/fmt/str.js +17 -0
- package/dist/shared/fmt/str.js.map +1 -0
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +11 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/rejection.d.ts.map +1 -1
- package/dist/shared/rejection.js +11 -0
- package/dist/shared/rejection.js.map +1 -1
- package/dist/shared/types.d.ts +41 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +85 -1
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/index.d.ts +25 -2
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +23 -2
- package/dist/ws/index.js.map +1 -1
- package/dist/ws/subscriptions.d.ts +12 -0
- package/dist/ws/subscriptions.d.ts.map +1 -1
- package/dist/ws/subscriptions.js +14 -4
- package/dist/ws/subscriptions.js.map +1 -1
- package/package.json +1 -1
- package/dist/domain/admin/client.d.ts +0 -63
- package/dist/domain/admin/client.d.ts.map +0 -1
- package/dist/domain/admin/client.js +0 -234
- package/dist/domain/admin/client.js.map +0 -1
- package/dist/domain/admin/index.d.ts +0 -16
- package/dist/domain/admin/index.d.ts.map +0 -1
- package/dist/domain/admin/index.js +0 -19
- package/dist/domain/admin/index.js.map +0 -1
- package/dist/domain/admin/wire.d.ts +0 -450
- package/dist/domain/admin/wire.d.ts.map +0 -1
- package/dist/domain/admin/wire.js +0 -3
- package/dist/domain/admin/wire.js.map +0 -1
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
import type { OrderBookId } from "../../shared";
|
|
2
2
|
import type { OrderBook } from "./wire";
|
|
3
|
+
/**
|
|
4
|
+
* The `book_update` stream is snapshot-only: every data frame carries the
|
|
5
|
+
* full top-20 levels per side and replaces the previous book wholesale
|
|
6
|
+
* (last-write-wins). Consumers holding multiple aggregation views of one
|
|
7
|
+
* orderbook on the same connection key their `OrderbookState` instances by
|
|
8
|
+
* `(orderbook_id, aggregation)` using
|
|
9
|
+
* `aggregationFromFrame(book.n_sig_figs, book.mantissa)`.
|
|
10
|
+
*/
|
|
3
11
|
export type OrderbookApplyResult = {
|
|
4
12
|
kind: "applied";
|
|
5
|
-
} | {
|
|
6
|
-
kind: "ignored";
|
|
7
|
-
reason: OrderbookIgnoreReason;
|
|
8
13
|
} | {
|
|
9
14
|
kind: "refresh_required";
|
|
10
15
|
reason: OrderbookRefreshReason;
|
|
11
16
|
};
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} | {
|
|
20
|
-
kind: "already_awaiting_snapshot";
|
|
21
|
-
got: number;
|
|
22
|
-
};
|
|
23
|
-
export type OrderbookRefreshReason = {
|
|
24
|
-
kind: "missing_snapshot";
|
|
25
|
-
got: number;
|
|
26
|
-
} | {
|
|
27
|
-
kind: "sequence_gap";
|
|
28
|
-
expected: number;
|
|
29
|
-
got: number;
|
|
30
|
-
} | {
|
|
17
|
+
export type OrderbookRefreshReason =
|
|
18
|
+
/**
|
|
19
|
+
* The backend explicitly requested a resync: unsubscribe and re-subscribe
|
|
20
|
+
* with the same parameters (including aggregation) to receive a fresh
|
|
21
|
+
* snapshot.
|
|
22
|
+
*/
|
|
23
|
+
{
|
|
31
24
|
kind: "server_resync";
|
|
32
|
-
got: number;
|
|
33
25
|
};
|
|
34
26
|
export declare class OrderbookState {
|
|
35
27
|
readonly orderbookId: OrderBookId;
|
|
28
|
+
/**
|
|
29
|
+
* Projection version of the last applied frame. Strictly increasing but
|
|
30
|
+
* non-contiguous server-side (conflation skips versions), and the initial
|
|
31
|
+
* snapshot after every (re)subscribe is `seq: 0` — informational only,
|
|
32
|
+
* never used to gate frames.
|
|
33
|
+
*/
|
|
36
34
|
seq: number;
|
|
37
35
|
private readonly bidsMap;
|
|
38
36
|
private readonly asksMap;
|
|
39
37
|
private cachedBestBid;
|
|
40
38
|
private cachedBestAsk;
|
|
41
|
-
private hasSnapshot;
|
|
42
|
-
private awaitingSnapshot;
|
|
43
39
|
constructor(orderbookId: OrderBookId);
|
|
44
40
|
/**
|
|
45
|
-
* Apply a WS orderbook
|
|
41
|
+
* Apply a WS orderbook frame (snapshot-only stream, last-write-wins).
|
|
46
42
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
43
|
+
* `resync` frames take precedence and leave the book untouched — the
|
|
44
|
+
* caller must re-subscribe with the same parameters. Every other data
|
|
45
|
+
* frame is a full snapshot by contract and replaces the book wholesale
|
|
46
|
+
* (the `is_snapshot` flag is not consulted), including the `seq: 0`
|
|
47
|
+
* initial snapshot delivered after every (re)subscribe: gating on `seq`
|
|
48
|
+
* would freeze the book after a resync or aggregation change, so `seq` is
|
|
49
|
+
* stored as informational only.
|
|
52
50
|
*/
|
|
53
51
|
apply(book: OrderBook): OrderbookApplyResult;
|
|
54
52
|
bids(): ReadonlyMap<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/domain/orderbook/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/domain/orderbook/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,sBAAsB;AAChC;;;;GAIG;AACH;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC;AAE5B,qBAAa,cAAc;IACzB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,aAAa,CAA4B;gBAErC,WAAW,EAAE,WAAW;IASpC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,oBAAoB;IA2B5C,IAAI,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;IAInC,IAAI,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;IAInC,OAAO,IAAI,MAAM,GAAG,SAAS;IAe7B,OAAO,IAAI,MAAM,GAAG,SAAS;IAc7B,QAAQ,IAAI,MAAM,GAAG,SAAS;IAU9B,MAAM,IAAI,MAAM,GAAG,SAAS;IAU5B,OAAO,IAAI,OAAO;IAIlB,KAAK,IAAI,IAAI;CAOd"}
|
|
@@ -7,13 +7,17 @@ exports.OrderbookState = void 0;
|
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
class OrderbookState {
|
|
9
9
|
orderbookId;
|
|
10
|
+
/**
|
|
11
|
+
* Projection version of the last applied frame. Strictly increasing but
|
|
12
|
+
* non-contiguous server-side (conflation skips versions), and the initial
|
|
13
|
+
* snapshot after every (re)subscribe is `seq: 0` — informational only,
|
|
14
|
+
* never used to gate frames.
|
|
15
|
+
*/
|
|
10
16
|
seq;
|
|
11
17
|
bidsMap;
|
|
12
18
|
asksMap;
|
|
13
19
|
cachedBestBid;
|
|
14
20
|
cachedBestAsk;
|
|
15
|
-
hasSnapshot;
|
|
16
|
-
awaitingSnapshot;
|
|
17
21
|
constructor(orderbookId) {
|
|
18
22
|
this.orderbookId = orderbookId;
|
|
19
23
|
this.seq = 0;
|
|
@@ -21,87 +25,38 @@ class OrderbookState {
|
|
|
21
25
|
this.asksMap = new Map();
|
|
22
26
|
this.cachedBestBid = null;
|
|
23
27
|
this.cachedBestAsk = null;
|
|
24
|
-
this.hasSnapshot = false;
|
|
25
|
-
this.awaitingSnapshot = false;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
|
-
* Apply a WS orderbook
|
|
30
|
+
* Apply a WS orderbook frame (snapshot-only stream, last-write-wins).
|
|
29
31
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* `resync` frames take precedence and leave the book untouched — the
|
|
33
|
+
* caller must re-subscribe with the same parameters. Every other data
|
|
34
|
+
* frame is a full snapshot by contract and replaces the book wholesale
|
|
35
|
+
* (the `is_snapshot` flag is not consulted), including the `seq: 0`
|
|
36
|
+
* initial snapshot delivered after every (re)subscribe: gating on `seq`
|
|
37
|
+
* would freeze the book after a resync or aggregation change, so `seq` is
|
|
38
|
+
* stored as informational only.
|
|
35
39
|
*/
|
|
36
40
|
apply(book) {
|
|
37
|
-
const seq = book.seq ?? 0;
|
|
38
41
|
if (book.resync) {
|
|
39
|
-
this.awaitingSnapshot = true;
|
|
40
42
|
return {
|
|
41
43
|
kind: "refresh_required",
|
|
42
|
-
reason: { kind: "server_resync"
|
|
44
|
+
reason: { kind: "server_resync" },
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.asksMap.clear();
|
|
48
|
-
this.hasSnapshot = true;
|
|
49
|
-
this.awaitingSnapshot = false;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
if (this.awaitingSnapshot) {
|
|
53
|
-
return {
|
|
54
|
-
kind: "ignored",
|
|
55
|
-
reason: { kind: "already_awaiting_snapshot", got: seq },
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// The backend sends snapshots with seq=0 and starts delta seq at 1.
|
|
59
|
-
// A delta with seq=0 means it has no valid sequence, so drop it.
|
|
60
|
-
if (seq <= 0) {
|
|
61
|
-
return {
|
|
62
|
-
kind: "ignored",
|
|
63
|
-
reason: { kind: "invalid_delta_sequence", got: seq },
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (!this.hasSnapshot) {
|
|
67
|
-
this.awaitingSnapshot = true;
|
|
68
|
-
return {
|
|
69
|
-
kind: "refresh_required",
|
|
70
|
-
reason: { kind: "missing_snapshot", got: seq },
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (seq <= this.seq) {
|
|
74
|
-
return {
|
|
75
|
-
kind: "ignored",
|
|
76
|
-
reason: { kind: "stale_delta", current: this.seq, got: seq },
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
const expected = this.seq + 1;
|
|
80
|
-
if (seq !== expected) {
|
|
81
|
-
this.awaitingSnapshot = true;
|
|
82
|
-
return {
|
|
83
|
-
kind: "refresh_required",
|
|
84
|
-
reason: { kind: "sequence_gap", expected, got: seq },
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
this.seq = seq;
|
|
47
|
+
this.bidsMap.clear();
|
|
48
|
+
this.asksMap.clear();
|
|
89
49
|
for (const level of book.bids) {
|
|
90
|
-
if (new decimal_js_1.default(level.size).isZero()) {
|
|
91
|
-
this.bidsMap.delete(level.price);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
50
|
+
if (!new decimal_js_1.default(level.size).isZero()) {
|
|
94
51
|
this.bidsMap.set(level.price, level.size);
|
|
95
52
|
}
|
|
96
53
|
}
|
|
97
54
|
for (const level of book.asks) {
|
|
98
|
-
if (new decimal_js_1.default(level.size).isZero()) {
|
|
99
|
-
this.asksMap.delete(level.price);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
55
|
+
if (!new decimal_js_1.default(level.size).isZero()) {
|
|
102
56
|
this.asksMap.set(level.price, level.size);
|
|
103
57
|
}
|
|
104
58
|
}
|
|
59
|
+
this.seq = book.seq ?? 0;
|
|
105
60
|
this.cachedBestBid = null;
|
|
106
61
|
this.cachedBestAsk = null;
|
|
107
62
|
return { kind: "applied" };
|
|
@@ -164,8 +119,6 @@ class OrderbookState {
|
|
|
164
119
|
this.seq = 0;
|
|
165
120
|
this.cachedBestBid = null;
|
|
166
121
|
this.cachedBestAsk = null;
|
|
167
|
-
this.hasSnapshot = false;
|
|
168
|
-
this.awaitingSnapshot = false;
|
|
169
122
|
}
|
|
170
123
|
}
|
|
171
124
|
exports.OrderbookState = OrderbookState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/domain/orderbook/state.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAiC;AAmBjC,MAAa,cAAc;IAChB,WAAW,CAAc;IAClC,GAAG,CAAS;IACK,OAAO,CAAsB;IAC7B,OAAO,CAAsB;IACtC,aAAa,CAA4B;IACzC,aAAa,CAA4B;IACzC,WAAW,CAAU;IACrB,gBAAgB,CAAU;IAElC,YAAY,WAAwB;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAe;QACnB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAE1B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC7B,OAAO;gBACL,IAAI,EAAE,kBAAkB;gBACxB,MAAM,EAAE,EAAE,IAAI,EAAE,eAAe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\"../../shared\";\nimport type { OrderBook } from \"./wire\";\n\nexport type OrderbookApplyResult =\n | { kind: \"applied\" }\n | { kind: \"ignored\"; reason: OrderbookIgnoreReason }\n | { kind: \"refresh_required\"; reason: OrderbookRefreshReason };\n\nexport type OrderbookIgnoreReason =\n | { kind: \"invalid_delta_sequence\"; got: number }\n | { kind: \"stale_delta\"; current: number; got: number }\n | { kind: \"already_awaiting_snapshot\"; got: number };\n\nexport type OrderbookRefreshReason =\n | { kind: \"missing_snapshot\"; got: number }\n | { kind: \"sequence_gap\"; expected: number; got: number }\n | { kind: \"server_resync\"; got: number };\n\nexport class OrderbookState {\n readonly orderbookId: OrderBookId;\n seq: number;\n private readonly bidsMap: Map<string, string>;\n private readonly asksMap: Map<string, string>;\n private cachedBestBid: string | undefined | null;\n private cachedBestAsk: string | undefined | null;\n private hasSnapshot: boolean;\n private awaitingSnapshot: boolean;\n\n constructor(orderbookId: OrderBookId) {\n this.orderbookId = orderbookId;\n this.seq = 0;\n this.bidsMap = new Map();\n this.asksMap = new Map();\n this.cachedBestBid = null;\n this.cachedBestAsk = null;\n this.hasSnapshot = false;\n this.awaitingSnapshot = false;\n }\n\n /**\n * Apply a WS orderbook message (snapshot replaces, delta merges).\n *\n * Server resync messages take precedence and return `refresh_required`.\n * Otherwise, snapshots are applied and deltas with a `seq` at or below the\n * current value are ignored to prevent stale updates. Deltas that skip one\n * or more expected sequence values are rejected so callers can refresh from\n * a fresh snapshot instead of mutating a corrupted book.\n */\n apply(book: OrderBook): OrderbookApplyResult {\n const seq = book.seq ?? 0;\n\n if (book.resync) {\n this.awaitingSnapshot = true;\n return {\n kind: \"refresh_required\",\n reason: { kind: \"server_resync\", got: seq },\n };\n }\n\n if (book.is_snapshot) {\n this.bidsMap.clear();\n this.asksMap.clear();\n this.hasSnapshot = true;\n this.awaitingSnapshot = false;\n } else {\n if (this.awaitingSnapshot) {\n return {\n kind: \"ignored\",\n reason: { kind: \"already_awaiting_snapshot\", got: seq },\n };\n }\n\n // The backend sends snapshots with seq=0 and starts delta seq at 1.\n // A delta with seq=0 means it has no valid sequence, so drop it.\n if (seq <= 0) {\n return {\n kind: \"ignored\",\n reason: { kind: \"invalid_delta_sequence\", got: seq },\n };\n }\n\n if (!this.hasSnapshot) {\n this.awaitingSnapshot = true;\n return {\n kind: \"refresh_required\",\n reason: { kind: \"missing_snapshot\", got: seq },\n };\n }\n\n if (seq <= this.seq) {\n return {\n kind: \"ignored\",\n reason: { kind: \"stale_delta\", current: this.seq, got: seq },\n };\n }\n\n const expected = this.seq + 1;\n if (seq !== expected) {\n this.awaitingSnapshot = true;\n return {\n kind: \"refresh_required\",\n reason: { kind: \"sequence_gap\", expected, got: seq },\n };\n }\n }\n\n this.seq = seq;\n\n for (const level of book.bids) {\n if (new Decimal(level.size).isZero()) {\n this.bidsMap.delete(level.price);\n } else {\n this.bidsMap.set(level.price, level.size);\n }\n }\n\n for (const level of book.asks) {\n if (new Decimal(level.size).isZero()) {\n this.asksMap.delete(level.price);\n } else {\n this.asksMap.set(level.price, level.size);\n }\n }\n\n this.cachedBestBid = null;\n this.cachedBestAsk = null;\n\n return { kind: \"applied\" };\n }\n\n bids(): ReadonlyMap<string, string> {\n return this.bidsMap;\n }\n\n asks(): ReadonlyMap<string, string> {\n return this.asksMap;\n }\n\n bestBid(): string | undefined {\n if (this.cachedBestBid !== null) {\n return this.cachedBestBid;\n }\n if (this.bidsMap.size === 0) {\n this.cachedBestBid = undefined;\n return undefined;\n }\n const result = Array.from(this.bidsMap.keys())\n .sort((a, b) => new Decimal(a).cmp(new Decimal(b)))\n .at(-1);\n this.cachedBestBid = result;\n return result;\n }\n\n bestAsk(): string | undefined {\n if (this.cachedBestAsk !== null) {\n return this.cachedBestAsk;\n }\n if (this.asksMap.size === 0) {\n this.cachedBestAsk = undefined;\n return undefined;\n }\n const result = Array.from(this.asksMap.keys())\n .sort((a, b) => new Decimal(a).cmp(new Decimal(b)))[0];\n this.cachedBestAsk = result;\n return result;\n }\n\n midPrice(): string | undefined {\n const bid = this.bestBid();\n const ask = this.bestAsk();\n if (!bid || !ask) {\n return undefined;\n }\n\n return new Decimal(bid).plus(ask).div(2).toString();\n }\n\n spread(): string | undefined {\n const bid = this.bestBid();\n const ask = this.bestAsk();\n if (!bid || !ask) {\n return undefined;\n }\n\n return new Decimal(ask).minus(bid).toString();\n }\n\n isEmpty(): boolean {\n return this.bidsMap.size === 0 && this.asksMap.size === 0;\n }\n\n clear(): void {\n this.bidsMap.clear();\n this.asksMap.clear();\n this.seq = 0;\n this.cachedBestBid = null;\n this.cachedBestAsk = null;\n this.hasSnapshot = false;\n this.awaitingSnapshot = false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/domain/orderbook/state.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAiC;AAwBjC,MAAa,cAAc;IAChB,WAAW,CAAc;IAClC;;;;;OAKG;IACH,GAAG,CAAS;IACK,OAAO,CAAsB;IAC7B,OAAO,CAAsB;IACtC,aAAa,CAA4B;IACzC,aAAa,CAA4B;IAEjD,YAAY,WAAwB;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAe;QACnB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO;gBACL,IAAI,EAAE,kBAAkB;gBACxB,MAAM,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;aAClC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC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AE,CAAC;IACtD,CAAC;IAED,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,oBAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;QACb,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF;AAjID,wCAiIC","sourcesContent":["import Decimal from \"decimal.js\";\nimport type { OrderBookId } from \"../../shared\";\nimport type { OrderBook } from \"./wire\";\n\n/**\n * The `book_update` stream is snapshot-only: every data frame carries the\n * full top-20 levels per side and replaces the previous book wholesale\n * (last-write-wins). Consumers holding multiple aggregation views of one\n * orderbook on the same connection key their `OrderbookState` instances by\n * `(orderbook_id, aggregation)` using\n * `aggregationFromFrame(book.n_sig_figs, book.mantissa)`.\n */\nexport type OrderbookApplyResult =\n | { kind: \"applied\" }\n | { kind: \"refresh_required\"; reason: OrderbookRefreshReason };\n\nexport type OrderbookRefreshReason =\n /**\n * The backend explicitly requested a resync: unsubscribe and re-subscribe\n * with the same parameters (including aggregation) to receive a fresh\n * snapshot.\n */\n { kind: \"server_resync\" };\n\nexport class OrderbookState {\n readonly orderbookId: OrderBookId;\n /**\n * Projection version of the last applied frame. Strictly increasing but\n * non-contiguous server-side (conflation skips versions), and the initial\n * snapshot after every (re)subscribe is `seq: 0` — informational only,\n * never used to gate frames.\n */\n seq: number;\n private readonly bidsMap: Map<string, string>;\n private readonly asksMap: Map<string, string>;\n private cachedBestBid: string | undefined | null;\n private cachedBestAsk: string | undefined | null;\n\n constructor(orderbookId: OrderBookId) {\n this.orderbookId = orderbookId;\n this.seq = 0;\n this.bidsMap = new Map();\n this.asksMap = new Map();\n this.cachedBestBid = null;\n this.cachedBestAsk = null;\n }\n\n /**\n * Apply a WS orderbook frame (snapshot-only stream, last-write-wins).\n *\n * `resync` frames take precedence and leave the book untouched — the\n * caller must re-subscribe with the same parameters. Every other data\n * frame is a full snapshot by contract and replaces the book wholesale\n * (the `is_snapshot` flag is not consulted), including the `seq: 0`\n * initial snapshot delivered after every (re)subscribe: gating on `seq`\n * would freeze the book after a resync or aggregation change, so `seq` is\n * stored as informational only.\n */\n apply(book: OrderBook): OrderbookApplyResult {\n if (book.resync) {\n return {\n kind: \"refresh_required\",\n reason: { kind: \"server_resync\" },\n };\n }\n\n this.bidsMap.clear();\n this.asksMap.clear();\n for (const level of book.bids) {\n if (!new Decimal(level.size).isZero()) {\n this.bidsMap.set(level.price, level.size);\n }\n }\n for (const level of book.asks) {\n if (!new Decimal(level.size).isZero()) {\n this.asksMap.set(level.price, level.size);\n }\n }\n this.seq = book.seq ?? 0;\n this.cachedBestBid = null;\n this.cachedBestAsk = null;\n\n return { kind: \"applied\" };\n }\n\n bids(): ReadonlyMap<string, string> {\n return this.bidsMap;\n }\n\n asks(): ReadonlyMap<string, string> {\n return this.asksMap;\n }\n\n bestBid(): string | undefined {\n if (this.cachedBestBid !== null) {\n return this.cachedBestBid;\n }\n if (this.bidsMap.size === 0) {\n this.cachedBestBid = undefined;\n return undefined;\n }\n const result = Array.from(this.bidsMap.keys())\n .sort((a, b) => new Decimal(a).cmp(new Decimal(b)))\n .at(-1);\n this.cachedBestBid = result;\n return result;\n }\n\n bestAsk(): string | undefined {\n if (this.cachedBestAsk !== null) {\n return this.cachedBestAsk;\n }\n if (this.asksMap.size === 0) {\n this.cachedBestAsk = undefined;\n return undefined;\n }\n const result = Array.from(this.asksMap.keys())\n .sort((a, b) => new Decimal(a).cmp(new Decimal(b)))[0];\n this.cachedBestAsk = result;\n return result;\n }\n\n midPrice(): string | undefined {\n const bid = this.bestBid();\n const ask = this.bestAsk();\n if (!bid || !ask) {\n return undefined;\n }\n\n return new Decimal(bid).plus(ask).div(2).toString();\n }\n\n spread(): string | undefined {\n const bid = this.bestBid();\n const ask = this.bestAsk();\n if (!bid || !ask) {\n return undefined;\n }\n\n return new Decimal(ask).minus(bid).toString();\n }\n\n isEmpty(): boolean {\n return this.bidsMap.size === 0 && this.asksMap.size === 0;\n }\n\n clear(): void {\n this.bidsMap.clear();\n this.asksMap.clear();\n this.seq = 0;\n this.cachedBestBid = null;\n this.cachedBestAsk = null;\n }\n}\n"]}
|
|
@@ -24,6 +24,9 @@ export interface RestBookLevel {
|
|
|
24
24
|
size: string;
|
|
25
25
|
orders?: number;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* REST depth response. Depth is capped server-side at 20 levels per side.
|
|
29
|
+
*/
|
|
27
30
|
export interface OrderbookDepthResponse {
|
|
28
31
|
orderbook_id: OrderBookId;
|
|
29
32
|
market_pubkey?: string;
|
|
@@ -33,6 +36,19 @@ export interface OrderbookDepthResponse {
|
|
|
33
36
|
tick_size?: string;
|
|
34
37
|
bids: RestBookLevel[];
|
|
35
38
|
asks: RestBookLevel[];
|
|
39
|
+
/**
|
|
40
|
+
* Display decimals for prices and sizes. Always sent by current backends;
|
|
41
|
+
* optional for tolerance of older payloads.
|
|
42
|
+
*/
|
|
43
|
+
decimals?: OrderbookDepthDecimals;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Price/size display decimals from the depth endpoint. Distinct from
|
|
47
|
+
* `DecimalsResponse` (the `/decimals` endpoint).
|
|
48
|
+
*/
|
|
49
|
+
export interface OrderbookDepthDecimals {
|
|
50
|
+
price: number;
|
|
51
|
+
size: number;
|
|
36
52
|
}
|
|
37
53
|
export interface DecimalsResponse {
|
|
38
54
|
orderbook_id: string;
|
|
@@ -45,6 +61,14 @@ export interface WsBookLevel {
|
|
|
45
61
|
price: string;
|
|
46
62
|
size: string;
|
|
47
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* WS orderbook snapshot frame.
|
|
66
|
+
*
|
|
67
|
+
* The stream is snapshot-only: every data frame carries the full top-20
|
|
68
|
+
* levels per side and replaces the previous book wholesale (last-write-wins).
|
|
69
|
+
* `seq` is strictly increasing but non-contiguous, and the initial snapshot
|
|
70
|
+
* after every (re)subscribe is `seq: 0` — informational only, never a gate.
|
|
71
|
+
*/
|
|
48
72
|
export interface OrderBook {
|
|
49
73
|
orderbook_id: OrderBookId;
|
|
50
74
|
is_snapshot?: boolean;
|
|
@@ -53,6 +77,14 @@ export interface OrderBook {
|
|
|
53
77
|
timestamp?: string;
|
|
54
78
|
bids: WsBookLevel[];
|
|
55
79
|
asks: WsBookLevel[];
|
|
80
|
+
/**
|
|
81
|
+
* Aggregation tags echoed by the backend (omitted = full precision).
|
|
82
|
+
* Always normalized server-side ((5, none) arrives as (5, 1)). Use
|
|
83
|
+
* `aggregationFromFrame(book.n_sig_figs, book.mantissa)` to key
|
|
84
|
+
* per-`(orderbook, aggregation)` book state.
|
|
85
|
+
*/
|
|
86
|
+
n_sig_figs?: number;
|
|
87
|
+
mantissa?: number;
|
|
56
88
|
}
|
|
57
89
|
export interface WsTickerData {
|
|
58
90
|
orderbook_id: OrderBookId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/domain/orderbook/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,WAAW,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AM,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,WAAW,EAAE,CAAC;IACpB,IAAI,EAAE,WAAW,EAAE,CAAC;IACpB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/orderbook/wire.ts"],"names":[],"mappings":"","sourcesContent":["import type { OrderBookId, Side } from \"../../shared\";\n\nexport interface OrderbookResponse {\n id: number;\n market_pubkey: string;\n orderbook_id: string;\n base_token: string;\n quote_token: string;\n outcome_index?: number;\n tick_size: number;\n total_bids: number;\n total_asks: number;\n last_trade_price?: string;\n last_trade_time?: string;\n active: boolean;\n created_at: string;\n updated_at: string;\n}\n\nexport interface OrderbooksResponse {\n orderbooks: OrderbookResponse[];\n total: number;\n}\n\nexport interface RestBookLevel {\n price: string;\n size: string;\n orders?: number;\n}\n\nexport interface OrderbookDepthResponse {\n orderbook_id: OrderBookId;\n market_pubkey?: string;\n best_bid?: string;\n best_ask?: string;\n spread?: string;\n tick_size?: string;\n bids: RestBookLevel[];\n asks: RestBookLevel[];\n}\n\nexport interface DecimalsResponse {\n orderbook_id: string;\n base_decimals: number;\n quote_decimals: number;\n price_decimals: number;\n}\n\nexport interface WsBookLevel {\n side: Side;\n price: string;\n size: string;\n}\n\nexport interface OrderBook {\n orderbook_id: OrderBookId;\n is_snapshot?: boolean;\n seq?: number;\n resync?: boolean;\n timestamp?: string;\n bids: WsBookLevel[];\n asks: WsBookLevel[];\n}\n\nexport interface WsTickerData {\n orderbook_id: OrderBookId;\n best_bid?: string;\n best_ask?: string;\n mid?: string;\n timestamp?: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/orderbook/wire.ts"],"names":[],"mappings":"","sourcesContent":["import type { OrderBookId, Side } from \"../../shared\";\n\nexport interface OrderbookResponse {\n id: number;\n market_pubkey: string;\n orderbook_id: string;\n base_token: string;\n quote_token: string;\n outcome_index?: number;\n tick_size: number;\n total_bids: number;\n total_asks: number;\n last_trade_price?: string;\n last_trade_time?: string;\n active: boolean;\n created_at: string;\n updated_at: string;\n}\n\nexport interface OrderbooksResponse {\n orderbooks: OrderbookResponse[];\n total: number;\n}\n\nexport interface RestBookLevel {\n price: string;\n size: string;\n orders?: number;\n}\n\n/**\n * REST depth response. Depth is capped server-side at 20 levels per side.\n */\nexport interface OrderbookDepthResponse {\n orderbook_id: OrderBookId;\n market_pubkey?: string;\n best_bid?: string;\n best_ask?: string;\n spread?: string;\n tick_size?: string;\n bids: RestBookLevel[];\n asks: RestBookLevel[];\n /**\n * Display decimals for prices and sizes. Always sent by current backends;\n * optional for tolerance of older payloads.\n */\n decimals?: OrderbookDepthDecimals;\n}\n\n/**\n * Price/size display decimals from the depth endpoint. Distinct from\n * `DecimalsResponse` (the `/decimals` endpoint).\n */\nexport interface OrderbookDepthDecimals {\n price: number;\n size: number;\n}\n\nexport interface DecimalsResponse {\n orderbook_id: string;\n base_decimals: number;\n quote_decimals: number;\n price_decimals: number;\n}\n\nexport interface WsBookLevel {\n side: Side;\n price: string;\n size: string;\n}\n\n/**\n * WS orderbook snapshot frame.\n *\n * The stream is snapshot-only: every data frame carries the full top-20\n * levels per side and replaces the previous book wholesale (last-write-wins).\n * `seq` is strictly increasing but non-contiguous, and the initial snapshot\n * after every (re)subscribe is `seq: 0` — informational only, never a gate.\n */\nexport interface OrderBook {\n orderbook_id: OrderBookId;\n is_snapshot?: boolean;\n seq?: number;\n resync?: boolean;\n timestamp?: string;\n bids: WsBookLevel[];\n asks: WsBookLevel[];\n /**\n * Aggregation tags echoed by the backend (omitted = full precision).\n * Always normalized server-side ((5, none) arrives as (5, 1)). Use\n * `aggregationFromFrame(book.n_sig_figs, book.mantissa)` to key\n * per-`(orderbook, aggregation)` book state.\n */\n n_sig_figs?: number;\n mantissa?: number;\n}\n\nexport interface WsTickerData {\n orderbook_id: OrderBookId;\n best_bid?: string;\n best_ask?: string;\n mid?: string;\n timestamp?: string;\n}\n"]}
|
package/dist/env.d.ts
CHANGED
|
@@ -17,11 +17,26 @@ export declare enum LightconeEnv {
|
|
|
17
17
|
Staging = "staging",
|
|
18
18
|
Prod = "prod"
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* REST API base URL for the given environment.
|
|
22
|
+
*
|
|
23
|
+
* If the `SDK_API_URL` environment variable is set, its value is used
|
|
24
|
+
* regardless of the selected environment.
|
|
25
|
+
*/
|
|
21
26
|
export declare function apiUrl(environment: LightconeEnv): string;
|
|
22
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* WebSocket URL for the given environment.
|
|
29
|
+
*
|
|
30
|
+
* If the `SDK_WS_URL` environment variable is set, its value is used
|
|
31
|
+
* regardless of the selected environment.
|
|
32
|
+
*/
|
|
23
33
|
export declare function wsUrl(environment: LightconeEnv): string;
|
|
24
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Solana RPC URL for the given environment.
|
|
36
|
+
*
|
|
37
|
+
* If the `SDK_RPC_URL` environment variable is set, its value is used
|
|
38
|
+
* regardless of the selected environment.
|
|
39
|
+
*/
|
|
25
40
|
export declare function rpcUrl(environment: LightconeEnv): string;
|
|
26
41
|
/**
|
|
27
42
|
* On-chain Lightcone program ID for the given environment.
|
package/dist/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,oBAAY,YAAY;IACtB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAED
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,oBAAY,YAAY;IACtB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,CAWxD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,CAWvD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,CAWxD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAa9D;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,WAA+B,CAAC"}
|
package/dist/env.js
CHANGED
|
@@ -25,8 +25,16 @@ var LightconeEnv;
|
|
|
25
25
|
LightconeEnv["Staging"] = "staging";
|
|
26
26
|
LightconeEnv["Prod"] = "prod";
|
|
27
27
|
})(LightconeEnv || (exports.LightconeEnv = LightconeEnv = {}));
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* REST API base URL for the given environment.
|
|
30
|
+
*
|
|
31
|
+
* If the `SDK_API_URL` environment variable is set, its value is used
|
|
32
|
+
* regardless of the selected environment.
|
|
33
|
+
*/
|
|
29
34
|
function apiUrl(environment) {
|
|
35
|
+
const overrideUrl = typeof process !== "undefined" ? process.env.SDK_API_URL : undefined;
|
|
36
|
+
if (overrideUrl)
|
|
37
|
+
return overrideUrl;
|
|
30
38
|
switch (environment) {
|
|
31
39
|
case LightconeEnv.Local:
|
|
32
40
|
return "https://api.local.lightcone.xyz";
|
|
@@ -36,8 +44,16 @@ function apiUrl(environment) {
|
|
|
36
44
|
return "https://api.lightcone.xyz";
|
|
37
45
|
}
|
|
38
46
|
}
|
|
39
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* WebSocket URL for the given environment.
|
|
49
|
+
*
|
|
50
|
+
* If the `SDK_WS_URL` environment variable is set, its value is used
|
|
51
|
+
* regardless of the selected environment.
|
|
52
|
+
*/
|
|
40
53
|
function wsUrl(environment) {
|
|
54
|
+
const overrideUrl = typeof process !== "undefined" ? process.env.SDK_WS_URL : undefined;
|
|
55
|
+
if (overrideUrl)
|
|
56
|
+
return overrideUrl;
|
|
41
57
|
switch (environment) {
|
|
42
58
|
case LightconeEnv.Local:
|
|
43
59
|
return "wss://ws.local.lightcone.xyz/ws";
|
|
@@ -47,15 +63,23 @@ function wsUrl(environment) {
|
|
|
47
63
|
return "wss://ws.lightcone.xyz/ws";
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Solana RPC URL for the given environment.
|
|
68
|
+
*
|
|
69
|
+
* If the `SDK_RPC_URL` environment variable is set, its value is used
|
|
70
|
+
* regardless of the selected environment.
|
|
71
|
+
*/
|
|
51
72
|
function rpcUrl(environment) {
|
|
73
|
+
const overrideUrl = typeof process !== "undefined" ? process.env.SDK_RPC_URL : undefined;
|
|
74
|
+
if (overrideUrl)
|
|
75
|
+
return overrideUrl;
|
|
52
76
|
switch (environment) {
|
|
53
77
|
case LightconeEnv.Local:
|
|
54
78
|
return "https://api.devnet.solana.com";
|
|
55
79
|
case LightconeEnv.Staging:
|
|
56
80
|
return "https://api.devnet.solana.com";
|
|
57
81
|
case LightconeEnv.Prod:
|
|
58
|
-
return "https://api.
|
|
82
|
+
return "https://api.mainnet-beta.solana.com";
|
|
59
83
|
}
|
|
60
84
|
}
|
|
61
85
|
/**
|
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;AA2BA,wBAWC;AAQD,sBAWC;AAQD,wBAWC;AAQD,8BAaC;AAjGD,6CAA4C;AAE5C;;;;;;;;;;;;GAYG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,mCAAmB,CAAA;IACnB,6BAAa,CAAA;AACf,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,WAAyB;IAC9C,MAAM,WAAW,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IACpC,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,YAAY,CAAC,KAAK;YACrB,OAAO,iCAAiC,CAAC;QAC3C,KAAK,YAAY,CAAC,OAAO;YACvB,OAAO,mCAAmC,CAAC;QAC7C,KAAK,YAAY,CAAC,IAAI;YACpB,OAAO,2BAA2B,CAAC;IACvC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,WAAyB;IAC7C,MAAM,WAAW,GAAG,OAAO,O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AAS,CAAC,8CAA8C,CAAC,CAAC;QACvE,KAAK,YAAY,CAAC,IAAI;YACpB,OAAO,IAAI,mBAAS,CAAC,8CAA8C,CAAC,CAAC;IACzE,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACU,QAAA,UAAU,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Lightcone deployment environment.\n *\n * Pass to `LightconeClientBuilder.env()` to configure the client for a\n * specific deployment. Defaults to `Prod` when not specified.\n *\n * @example\n * ```ts\n * const client = LightconeClient.builder()\n * .env(LightconeEnv.Staging)\n * .build();\n * ```\n */\nexport enum LightconeEnv {\n Local = \"local\",\n Staging = \"staging\",\n Prod = \"prod\",\n}\n\n/**\n * REST API base URL for the given environment.\n *\n * If the `SDK_API_URL` environment variable is set, its value is used\n * regardless of the selected environment.\n */\nexport function apiUrl(environment: LightconeEnv): string {\n const overrideUrl = typeof process !== \"undefined\" ? process.env.SDK_API_URL : undefined;\n if (overrideUrl) return overrideUrl;\n switch (environment) {\n case LightconeEnv.Local:\n return \"https://api.local.lightcone.xyz\";\n case LightconeEnv.Staging:\n return \"https://api.staging.lightcone.xyz\";\n case LightconeEnv.Prod:\n return \"https://api.lightcone.xyz\";\n }\n}\n\n/**\n * WebSocket URL for the given environment.\n *\n * If the `SDK_WS_URL` environment variable is set, its value is used\n * regardless of the selected environment.\n */\nexport function wsUrl(environment: LightconeEnv): string {\n const overrideUrl = typeof process !== \"undefined\" ? process.env.SDK_WS_URL : undefined;\n if (overrideUrl) return overrideUrl;\n switch (environment) {\n case LightconeEnv.Local:\n return \"wss://ws.local.lightcone.xyz/ws\";\n case LightconeEnv.Staging:\n return \"wss://ws.staging.lightcone.xyz/ws\";\n case LightconeEnv.Prod:\n return \"wss://ws.lightcone.xyz/ws\";\n }\n}\n\n/**\n * Solana RPC URL for the given environment.\n *\n * If the `SDK_RPC_URL` environment variable is set, its value is used\n * regardless of the selected environment.\n */\nexport function rpcUrl(environment: LightconeEnv): string {\n const overrideUrl = typeof process !== \"undefined\" ? process.env.SDK_RPC_URL : undefined;\n if (overrideUrl) return overrideUrl;\n switch (environment) {\n case LightconeEnv.Local:\n return \"https://api.devnet.solana.com\";\n case LightconeEnv.Staging:\n return \"https://api.devnet.solana.com\";\n case LightconeEnv.Prod:\n return \"https://api.mainnet-beta.solana.com\";\n }\n}\n\n/**\n * On-chain Lightcone program ID for the given environment.\n *\n * If the `SDK_PROGRAM_ID` environment variable is set, its value is used\n * regardless of the selected environment.\n */\nexport function programId(environment: LightconeEnv): PublicKey {\n const override_id = typeof process !== \"undefined\" ? process.env.SDK_PROGRAM_ID : undefined;\n if (override_id) {\n return new PublicKey(override_id);\n }\n switch (environment) {\n case LightconeEnv.Local:\n return new PublicKey(\"HQZW84F7WbpDLDdd6eaDsBh6LjDQ2uCxpkZgkLakcago\");\n case LightconeEnv.Staging:\n return new PublicKey(\"FAq4NbwPVWNzoaNjcJGhWz4VFT5CbdysLPo7ZWWiWuuE\");\n case LightconeEnv.Prod:\n return new PublicKey(\"B9rCvafkkjh749284jfDu5UB268pHeRLkzFpFf7t4mxK\");\n }\n}\n\n/**\n * Default program ID (production). Used as the default argument in PDA and\n * instruction helper functions. When targeting a non-production environment,\n * always pass `programId` explicitly via `LightconeClient.programId` or\n * `programId(env)`.\n */\nexport const PROGRAM_ID = programId(LightconeEnv.Prod);\n"]}
|
package/dist/http/client.d.ts
CHANGED
|
@@ -2,14 +2,10 @@ import { type RetryPolicy } from "./retry";
|
|
|
2
2
|
export declare class LightconeHttp {
|
|
3
3
|
private readonly normalizedBaseUrl;
|
|
4
4
|
private authToken;
|
|
5
|
-
private adminToken;
|
|
6
5
|
constructor(baseUrl: string);
|
|
7
6
|
baseUrl(): string;
|
|
8
7
|
clearAuthToken(): Promise<void>;
|
|
9
8
|
authTokenRef(): () => Promise<string | undefined>;
|
|
10
|
-
clearAdminToken(): void;
|
|
11
|
-
adminGet<T>(url: string, retry: RetryPolicy): Promise<T>;
|
|
12
|
-
adminPost<T, B extends object>(url: string, body: B, retry: RetryPolicy): Promise<T>;
|
|
13
9
|
get<T>(url: string, retry: RetryPolicy): Promise<T>;
|
|
14
10
|
post<T, B extends object>(url: string, body: B, retry: RetryPolicy): Promise<T>;
|
|
15
11
|
/**
|
|
@@ -28,5 +24,6 @@ export declare class LightconeHttp {
|
|
|
28
24
|
private captureCookies;
|
|
29
25
|
private cookieHeader;
|
|
30
26
|
private mapStatusError;
|
|
27
|
+
private statusErrorToSdk;
|
|
31
28
|
}
|
|
32
29
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAwBlF,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,SAAS,CAAqB;gBAE1B,OAAO,EAAE,MAAM;IAI3B,OAAO,IAAI,MAAM;IAIX,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC,YAAY,IAAI,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAInD,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAIrF;;;;;;;OAOG;IACG,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;YAU5E,gBAAgB;YAmEhB,WAAW;YAiBX,YAAY;YAeZ,WAAW;IAgEzB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,gBAAgB;CAOzB"}
|