@pod-network/trade-sdk 0.1.0-rc.0
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 +113 -0
- package/dist/client.d.ts +93 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +168 -0
- package/dist/client.js.map +1 -0
- package/dist/codec/decode.d.ts +22 -0
- package/dist/codec/decode.d.ts.map +1 -0
- package/dist/codec/decode.js +251 -0
- package/dist/codec/decode.js.map +1 -0
- package/dist/codec/fixed.d.ts +11 -0
- package/dist/codec/fixed.d.ts.map +1 -0
- package/dist/codec/fixed.js +37 -0
- package/dist/codec/fixed.js.map +1 -0
- package/dist/codec/resolution.d.ts +14 -0
- package/dist/codec/resolution.d.ts.map +1 -0
- package/dist/codec/resolution.js +35 -0
- package/dist/codec/resolution.js.map +1 -0
- package/dist/codec/units.d.ts +35 -0
- package/dist/codec/units.d.ts.map +1 -0
- package/dist/codec/units.js +86 -0
- package/dist/codec/units.js.map +1 -0
- package/dist/datafeed.d.ts +4 -0
- package/dist/datafeed.d.ts.map +1 -0
- package/dist/datafeed.js +73 -0
- package/dist/datafeed.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/resource.d.ts +50 -0
- package/dist/stores/resource.d.ts.map +1 -0
- package/dist/stores/resource.js +154 -0
- package/dist/stores/resource.js.map +1 -0
- package/dist/sync/account-metrics.d.ts +26 -0
- package/dist/sync/account-metrics.d.ts.map +1 -0
- package/dist/sync/account-metrics.js +41 -0
- package/dist/sync/account-metrics.js.map +1 -0
- package/dist/sync/candles.d.ts +68 -0
- package/dist/sync/candles.d.ts.map +1 -0
- package/dist/sync/candles.js +318 -0
- package/dist/sync/candles.js.map +1 -0
- package/dist/sync/order-preview.d.ts +74 -0
- package/dist/sync/order-preview.d.ts.map +1 -0
- package/dist/sync/order-preview.js +86 -0
- package/dist/sync/order-preview.js.map +1 -0
- package/dist/sync/orders.d.ts +49 -0
- package/dist/sync/orders.d.ts.map +1 -0
- package/dist/sync/orders.js +210 -0
- package/dist/sync/orders.js.map +1 -0
- package/dist/sync/positions-live.d.ts +3 -0
- package/dist/sync/positions-live.d.ts.map +1 -0
- package/dist/sync/positions-live.js +86 -0
- package/dist/sync/positions-live.js.map +1 -0
- package/dist/sync/sources.d.ts +40 -0
- package/dist/sync/sources.d.ts.map +1 -0
- package/dist/sync/sources.js +197 -0
- package/dist/sync/sources.js.map +1 -0
- package/dist/transport/rest.d.ts +83 -0
- package/dist/transport/rest.d.ts.map +1 -0
- package/dist/transport/rest.js +146 -0
- package/dist/transport/rest.js.map +1 -0
- package/dist/transport/ws.d.ts +60 -0
- package/dist/transport/ws.d.ts.map +1 -0
- package/dist/transport/ws.js +235 -0
- package/dist/transport/ws.js.map +1 -0
- package/dist/types/public.d.ts +292 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/types/public.js +4 -0
- package/dist/types/public.js.map +1 -0
- package/dist/types/wire.d.ts +283 -0
- package/dist/types/wire.d.ts.map +1 -0
- package/dist/types/wire.js +6 -0
- package/dist/types/wire.js.map +1 -0
- package/dist/write/delegation.d.ts +54 -0
- package/dist/write/delegation.d.ts.map +1 -0
- package/dist/write/delegation.js +81 -0
- package/dist/write/delegation.js.map +1 -0
- package/dist/write/index.d.ts +261 -0
- package/dist/write/index.d.ts.map +1 -0
- package/dist/write/index.js +428 -0
- package/dist/write/index.js.map +1 -0
- package/package.json +43 -0
- package/src/client.ts +229 -0
- package/src/codec/decode.ts +277 -0
- package/src/codec/fixed.ts +41 -0
- package/src/codec/resolution.ts +39 -0
- package/src/codec/units.ts +100 -0
- package/src/datafeed.ts +94 -0
- package/src/index.ts +49 -0
- package/src/stores/resource.ts +172 -0
- package/src/sync/account-metrics.ts +71 -0
- package/src/sync/candles.ts +326 -0
- package/src/sync/order-preview.ts +152 -0
- package/src/sync/orders.ts +205 -0
- package/src/sync/positions-live.ts +102 -0
- package/src/sync/sources.ts +239 -0
- package/src/transport/rest.ts +213 -0
- package/src/transport/ws.ts +255 -0
- package/src/types/public.ts +335 -0
- package/src/types/wire.ts +301 -0
- package/src/write/delegation.ts +113 -0
- package/src/write/index.ts +642 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Per-entity ResourceSource factories: seed once over REST where it helps, then
|
|
2
|
+
// maintain in memory from the matching `pod_*` channel.
|
|
3
|
+
//
|
|
4
|
+
// Reconnect model:
|
|
5
|
+
// - Current-state channels (markets/positions/triggers) subscribe with
|
|
6
|
+
// `since: 0`, so every (re)subscribe yields a fresh immediate snapshot — no
|
|
7
|
+
// staleness possible, nothing to re-seed.
|
|
8
|
+
// - REST-seeded channels (markets static, orderbook, balances) seed
|
|
9
|
+
// immediately — the fetch doesn't need the socket, so first data isn't
|
|
10
|
+
// held behind the WS handshake — and re-seed on every (re)connect via
|
|
11
|
+
// `seedNowAndOnReconnect`, so state is refreshed after any downtime.
|
|
12
|
+
// - The WS client auto-resubscribes live subs on reconnect; tick-log channels
|
|
13
|
+
// that use `since` (candles/orders) advance/refresh it and fall back to a
|
|
14
|
+
// REST re-seed via `onError` when `since` is too old (down too long).
|
|
15
|
+
import { decodeMarketDynamics, decodeOrderbook, decodePositions, decodeTrigger, } from "../codec/decode.js";
|
|
16
|
+
// Static-list serialization for MarketsCache. Version is embedded in the
|
|
17
|
+
// payload: a mismatch after an SDK format change just falls back to a cold
|
|
18
|
+
// start. bigints round-trip as "<digits>n" strings.
|
|
19
|
+
const MARKETS_CACHE_VERSION = 1;
|
|
20
|
+
const serializeMarkets = (markets) => JSON.stringify({ v: MARKETS_CACHE_VERSION, markets }, (_k, v) => (typeof v === "bigint" ? `${v}n` : v));
|
|
21
|
+
const parseCachedMarkets = (raw) => {
|
|
22
|
+
if (!raw)
|
|
23
|
+
return undefined;
|
|
24
|
+
const data = JSON.parse(raw, (_k, v) => typeof v === "string" && /^-?\d+n$/.test(v) ? BigInt(v.slice(0, -1)) : v);
|
|
25
|
+
return data?.v === MARKETS_CACHE_VERSION ? data.markets : undefined;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Seed now — a REST fetch needs no socket, so don't hold first data behind the
|
|
29
|
+
* WS handshake — and re-seed on every (re)connect so state refreshes after any
|
|
30
|
+
* downtime. On a cold start the connect completes shortly after the immediate
|
|
31
|
+
* seed and triggers one extra seed; that duplicate is what guarantees a seed
|
|
32
|
+
* at/after the moment the WS subscription goes live, exactly as before.
|
|
33
|
+
*/
|
|
34
|
+
export function seedNowAndOnReconnect(ws, fn) {
|
|
35
|
+
const off = ws.on("open", fn);
|
|
36
|
+
fn();
|
|
37
|
+
return off;
|
|
38
|
+
}
|
|
39
|
+
export function statusSource({ rest, ws }) {
|
|
40
|
+
return (h) => {
|
|
41
|
+
let alive = true;
|
|
42
|
+
const seed = () => { rest.status().then((s) => { if (alive)
|
|
43
|
+
h.set(s); }).catch((e) => h.fail(e)); };
|
|
44
|
+
const off = seedNowAndOnReconnect(ws, seed);
|
|
45
|
+
return () => { alive = false; off(); };
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function marketsSource({ rest, ws, marketResyncMs, marketsCache }) {
|
|
49
|
+
return (h) => {
|
|
50
|
+
let alive = true;
|
|
51
|
+
const byId = new Map();
|
|
52
|
+
// Stable display order = the static /clob/markets order, so the list never
|
|
53
|
+
// reshuffles as dynamics arrive (markets not yet in the static list sort last).
|
|
54
|
+
const orderIndex = new Map();
|
|
55
|
+
const publish = () => h.set([...byId.values()]
|
|
56
|
+
// pod_markets dynamics can arrive (and create an entry) before the static
|
|
57
|
+
// /clob/markets seed — those lack base/quote/name. Don't expose a market
|
|
58
|
+
// until its static config has merged in; the dynamics stay buffered.
|
|
59
|
+
.filter((m) => m.base !== undefined)
|
|
60
|
+
.sort((a, b) => (orderIndex.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (orderIndex.get(b.id) ?? Number.MAX_SAFE_INTEGER)
|
|
61
|
+
|| a.id.localeCompare(b.id)));
|
|
62
|
+
const mergePatch = (patch) => {
|
|
63
|
+
const existing = byId.get(patch.id);
|
|
64
|
+
byId.set(patch.id, existing ? { ...existing, ...patch } : patch);
|
|
65
|
+
};
|
|
66
|
+
// Last session's static list (never dynamics — those stay live-only):
|
|
67
|
+
// seeded synchronously so market-keyed UI mounts without a round trip.
|
|
68
|
+
// The REST seed below overwrites it field-for-field when it lands.
|
|
69
|
+
const fromCache = new Set();
|
|
70
|
+
try {
|
|
71
|
+
const cached = marketsCache && parseCachedMarkets(marketsCache.get());
|
|
72
|
+
cached?.forEach((m, i) => { orderIndex.set(m.id, i); byId.set(m.id, m); fromCache.add(m.id); });
|
|
73
|
+
if (byId.size)
|
|
74
|
+
publish();
|
|
75
|
+
}
|
|
76
|
+
catch { /* absent/corrupt cache — plain cold start */ }
|
|
77
|
+
const seedStatic = () => rest.markets().then((markets) => {
|
|
78
|
+
if (!alive)
|
|
79
|
+
return;
|
|
80
|
+
// Fresh static truth: drop cache-seeded markets that no longer exist,
|
|
81
|
+
// so a delisting can't outlive the first seed. (Dynamics-only entries
|
|
82
|
+
// buffered from the WS stream are untouched, as before.)
|
|
83
|
+
const fresh = new Set(markets.map((m) => m.id));
|
|
84
|
+
for (const id of fromCache)
|
|
85
|
+
if (!fresh.has(id)) {
|
|
86
|
+
byId.delete(id);
|
|
87
|
+
orderIndex.delete(id);
|
|
88
|
+
}
|
|
89
|
+
fromCache.clear();
|
|
90
|
+
markets.forEach((m, i) => { orderIndex.set(m.id, i); byId.set(m.id, { ...byId.get(m.id), ...m }); });
|
|
91
|
+
publish();
|
|
92
|
+
try {
|
|
93
|
+
marketsCache?.set(serializeMarkets(markets));
|
|
94
|
+
}
|
|
95
|
+
catch { /* storage denied/full */ }
|
|
96
|
+
}).catch((e) => { if (!byId.size)
|
|
97
|
+
h.fail(e); });
|
|
98
|
+
// 24h vol/high/low slide with time and only the REST stats reflect that
|
|
99
|
+
// (the WS only pushes on a clear) — so poll them periodically.
|
|
100
|
+
const seedStats = () => rest.marketStats().then((page) => {
|
|
101
|
+
if (!alive)
|
|
102
|
+
return;
|
|
103
|
+
page.markets.forEach(mergePatch);
|
|
104
|
+
publish();
|
|
105
|
+
}).catch(() => { });
|
|
106
|
+
const offOpen = seedNowAndOnReconnect(ws, () => { void seedStatic(); void seedStats(); });
|
|
107
|
+
const timer = marketResyncMs > 0 ? setInterval(seedStats, marketResyncMs) : undefined;
|
|
108
|
+
// Live clearing/mark/funding between polls.
|
|
109
|
+
const sub = ws.subscribe("pod_markets", { since: 0 }, (result) => {
|
|
110
|
+
const items = Array.isArray(result) ? result : [result];
|
|
111
|
+
for (const it of items) {
|
|
112
|
+
const w = it;
|
|
113
|
+
mergePatch(decodeMarketDynamics({ ...w, orderbook_id: w.orderbook_id ?? w.orderbook }));
|
|
114
|
+
}
|
|
115
|
+
publish();
|
|
116
|
+
});
|
|
117
|
+
return () => { alive = false; offOpen(); if (timer)
|
|
118
|
+
clearInterval(timer); sub.unsubscribe(); };
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export function orderbookSource({ rest, ws }, id, depth) {
|
|
122
|
+
return (h) => {
|
|
123
|
+
let alive = true;
|
|
124
|
+
const seed = () => {
|
|
125
|
+
rest.orderbook(id).then((ob) => {
|
|
126
|
+
const cur = h.current();
|
|
127
|
+
if (alive && (!cur || cur.timeMs <= ob.timeMs))
|
|
128
|
+
h.set(ob);
|
|
129
|
+
}).catch((e) => { if (!h.current())
|
|
130
|
+
h.fail(e); });
|
|
131
|
+
};
|
|
132
|
+
const offOpen = seedNowAndOnReconnect(ws, seed);
|
|
133
|
+
const sub = ws.subscribe("pod_orderbook", { clobIds: [id], depth }, (result) => {
|
|
134
|
+
const ob = decodeOrderbook(result);
|
|
135
|
+
const cur = h.current();
|
|
136
|
+
if (!cur || ob.timeMs >= cur.timeMs)
|
|
137
|
+
h.set(ob);
|
|
138
|
+
});
|
|
139
|
+
return () => { alive = false; offOpen(); sub.unsubscribe(); };
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export function positionsSource({ rest, ws, positionResyncMs }, account) {
|
|
143
|
+
return (h) => {
|
|
144
|
+
let alive = true;
|
|
145
|
+
// Baseline refreshes from three triggers, all just replacing the snapshot:
|
|
146
|
+
// - WS since:0 immediate + on every account-touching tick,
|
|
147
|
+
// - a periodic REST poll that re-aligns to the backend's exact accounting
|
|
148
|
+
// (corrects mark-extrapolation drift even when the account isn't touched).
|
|
149
|
+
const reseed = () => rest.positions(account).then((s) => { if (alive)
|
|
150
|
+
h.set(s); }).catch(() => { });
|
|
151
|
+
reseed();
|
|
152
|
+
const timer = positionResyncMs > 0 ? setInterval(reseed, positionResyncMs) : undefined;
|
|
153
|
+
const sub = ws.subscribe("pod_positions", { account, since: 0 }, (result) => {
|
|
154
|
+
if (alive)
|
|
155
|
+
h.set(decodePositions(result.data));
|
|
156
|
+
});
|
|
157
|
+
return () => { alive = false; if (timer)
|
|
158
|
+
clearInterval(timer); sub.unsubscribe(); };
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export function balancesSource({ rest, ws, positionResyncMs }, account) {
|
|
162
|
+
return (h) => {
|
|
163
|
+
let alive = true;
|
|
164
|
+
// No dedicated balances stream — seed over REST, re-poll periodically, and
|
|
165
|
+
// re-fetch (debounced) whenever the account is touched on pod_positions, so
|
|
166
|
+
// a spot fill / deposit reflects promptly without spamming a fetch per tick.
|
|
167
|
+
const seed = () => rest.balances(account).then((b) => { if (alive)
|
|
168
|
+
h.set(b); }).catch((e) => { if (!h.current())
|
|
169
|
+
h.fail(e); });
|
|
170
|
+
const offOpen = seedNowAndOnReconnect(ws, seed);
|
|
171
|
+
const timer = positionResyncMs > 0 ? setInterval(seed, positionResyncMs) : undefined;
|
|
172
|
+
let debounce;
|
|
173
|
+
const sub = ws.subscribe("pod_positions", { account, since: 0 }, () => {
|
|
174
|
+
if (!alive || debounce)
|
|
175
|
+
return;
|
|
176
|
+
debounce = setTimeout(() => { debounce = undefined; seed(); }, 500);
|
|
177
|
+
});
|
|
178
|
+
return () => {
|
|
179
|
+
alive = false;
|
|
180
|
+
offOpen();
|
|
181
|
+
if (timer)
|
|
182
|
+
clearInterval(timer);
|
|
183
|
+
if (debounce)
|
|
184
|
+
clearTimeout(debounce);
|
|
185
|
+
sub.unsubscribe();
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export function triggersSource({ ws }, account) {
|
|
190
|
+
return (h) => {
|
|
191
|
+
const sub = ws.subscribe("pod_triggers", { account, since: 0 }, (result) => {
|
|
192
|
+
h.set(result.triggers.map(decodeTrigger));
|
|
193
|
+
});
|
|
194
|
+
return () => sub.unsubscribe();
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/sync/sources.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,wDAAwD;AACxD,EAAE;AACF,mBAAmB;AACnB,wEAAwE;AACxE,+EAA+E;AAC/E,6CAA6C;AAC7C,qEAAqE;AACrE,0EAA0E;AAC1E,yEAAyE;AACzE,wEAAwE;AACxE,+EAA+E;AAC/E,6EAA6E;AAC7E,yEAAyE;AAQzE,OAAO,EACL,oBAAoB,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,GACtE,MAAM,oBAAoB,CAAC;AA4B5B,yEAAyE;AACzE,2EAA2E;AAC3E,oDAAoD;AACpD,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,gBAAgB,GAAG,CAAC,OAAiB,EAAU,EAAE,CACrD,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,qBAAqB,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,CAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CA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AAC;QAClE,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Address, BackstopTransfer, Balances, Bar, CandleQuery, LeaderboardPage, LeaderboardQuery, Market, MarketId, Order, Orderbook, PositionsSnapshot, Resolution, Status, Trigger, TxExplorer } from "../types/public.js";
|
|
2
|
+
export type MarketDynamicsPatch = Partial<Market> & {
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
export interface MarketStatsPage {
|
|
6
|
+
solutionNow: number;
|
|
7
|
+
markets: MarketDynamicsPatch[];
|
|
8
|
+
}
|
|
9
|
+
export interface OrdersPage {
|
|
10
|
+
orders: Order[];
|
|
11
|
+
nextCursor: string | null;
|
|
12
|
+
totalCount: number;
|
|
13
|
+
solutionNow: number;
|
|
14
|
+
}
|
|
15
|
+
export interface BackstopPage {
|
|
16
|
+
transfers: BackstopTransfer[];
|
|
17
|
+
totalCount: number;
|
|
18
|
+
solutionNow: number;
|
|
19
|
+
}
|
|
20
|
+
export interface TriggersPage {
|
|
21
|
+
triggers: Trigger[];
|
|
22
|
+
totalCount: number;
|
|
23
|
+
nextCursor: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface CandlesPage {
|
|
26
|
+
bars: Bar[];
|
|
27
|
+
resolution: Resolution;
|
|
28
|
+
range: {
|
|
29
|
+
from: number;
|
|
30
|
+
to: number;
|
|
31
|
+
} | null;
|
|
32
|
+
solutionNow: number;
|
|
33
|
+
}
|
|
34
|
+
export interface OrdersQueryRest {
|
|
35
|
+
until?: number;
|
|
36
|
+
limit?: number;
|
|
37
|
+
cursor?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TriggersQueryRest {
|
|
40
|
+
orderbook?: MarketId;
|
|
41
|
+
limit?: number;
|
|
42
|
+
}
|
|
43
|
+
export declare class PodHttpError extends Error {
|
|
44
|
+
status: number;
|
|
45
|
+
url: string;
|
|
46
|
+
constructor(status: number, url: string, message: string);
|
|
47
|
+
}
|
|
48
|
+
type FetchFn = typeof fetch;
|
|
49
|
+
export interface RestClientOptions {
|
|
50
|
+
restUrl: string;
|
|
51
|
+
fetch?: FetchFn;
|
|
52
|
+
}
|
|
53
|
+
export declare class PodRestClient {
|
|
54
|
+
private readonly base;
|
|
55
|
+
private readonly fetchFn;
|
|
56
|
+
private readonly inflight;
|
|
57
|
+
constructor(opts: RestClientOptions);
|
|
58
|
+
private get;
|
|
59
|
+
private buildUrl;
|
|
60
|
+
private doGet;
|
|
61
|
+
status(): Promise<Status>;
|
|
62
|
+
markets(): Promise<Market[]>;
|
|
63
|
+
marketStats(opts?: {
|
|
64
|
+
to?: number;
|
|
65
|
+
}): Promise<MarketStatsPage>;
|
|
66
|
+
candles(id: MarketId, q: CandleQuery): Promise<CandlesPage>;
|
|
67
|
+
orders(account: Address, q?: OrdersQueryRest): Promise<OrdersPage>;
|
|
68
|
+
backstopTransfers(account: Address): Promise<BackstopPage>;
|
|
69
|
+
orderbook(id: MarketId): Promise<Orderbook>;
|
|
70
|
+
/** Perp positions + account aggregates (spot holdings are at `/clob/balances`). */
|
|
71
|
+
positions(account: Address): Promise<PositionsSnapshot>;
|
|
72
|
+
/** Spot holdings + native cash. */
|
|
73
|
+
balances(account: Address): Promise<Balances>;
|
|
74
|
+
/** Flat explorer view of a transaction (fields, receipt, logs, attestations,
|
|
75
|
+
* decoded calldata). Returned as-is (hex fields raw). */
|
|
76
|
+
transaction(hash: string): Promise<TxExplorer>;
|
|
77
|
+
/** Accounts ranked by net PnL (realized + unrealized), descending. Paginate
|
|
78
|
+
* with `{ limit, offset }`; ranks are 1-based over the full ordering. */
|
|
79
|
+
leaderboard(q?: LeaderboardQuery): Promise<LeaderboardPage>;
|
|
80
|
+
triggers(account: Address, q?: TriggersQueryRest): Promise<TriggersPage>;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
83
|
+
//# sour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AAC,YAAY,CAAC;IAS1D,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAIjD,mFAAmF;IAC7E,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI7D,mCAAmC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAInD;6DACyD;IACnD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIpD;6EACyE;IACnE,WAAW,CAAC,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAO3D,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;CAW/E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Layer 1: typed one-shot REST reads of `/clob/*`. Plain fetch so the browser /
|
|
2
|
+
// CDN honor the server's Cache-Control; identical concurrent GETs are deduped.
|
|
3
|
+
// ms in, decoded (bigint / ms) out.
|
|
4
|
+
import { decodeBackstopTransfer, decodeBalances, decodeCandle, decodeLeaderboard, decodeMarketDynamics, decodeMarketStatic, decodeOrder, decodeOrderbook, decodePositions, decodeStatus, decodeTrigger, } from "../codec/decode.js";
|
|
5
|
+
import { msToSecs, usToMs } from "../codec/units.js";
|
|
6
|
+
export class PodHttpError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
url;
|
|
9
|
+
constructor(status, url, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.url = url;
|
|
13
|
+
this.name = "PodHttpError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class PodRestClient {
|
|
17
|
+
base;
|
|
18
|
+
fetchFn;
|
|
19
|
+
inflight = new Map();
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
this.base = opts.restUrl.replace(/\/$/, "");
|
|
22
|
+
this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
23
|
+
}
|
|
24
|
+
async get(path, query) {
|
|
25
|
+
const url = this.buildUrl(path, query);
|
|
26
|
+
const existing = this.inflight.get(url);
|
|
27
|
+
if (existing)
|
|
28
|
+
return existing;
|
|
29
|
+
const p = this.doGet(url).finally(() => this.inflight.delete(url));
|
|
30
|
+
this.inflight.set(url, p);
|
|
31
|
+
return p;
|
|
32
|
+
}
|
|
33
|
+
buildUrl(path, query) {
|
|
34
|
+
// Resolve against the page origin so a relative/empty base (same-origin
|
|
35
|
+
// deployment or a dev proxy) works as well as an absolute base.
|
|
36
|
+
const origin = globalThis.location?.origin;
|
|
37
|
+
const u = origin ? new URL(this.base + path, origin) : new URL(this.base + path);
|
|
38
|
+
if (query) {
|
|
39
|
+
for (const [k, v] of Object.entries(query)) {
|
|
40
|
+
if (v !== undefined)
|
|
41
|
+
u.searchParams.set(k, String(v));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return u.toString();
|
|
45
|
+
}
|
|
46
|
+
async doGet(url) {
|
|
47
|
+
const res = await this.fetchFn(url, { headers: { accept: "application/json" } });
|
|
48
|
+
if (!res.ok) {
|
|
49
|
+
let body = "";
|
|
50
|
+
try {
|
|
51
|
+
body = await res.text();
|
|
52
|
+
}
|
|
53
|
+
catch { /* ignore */ }
|
|
54
|
+
throw new PodHttpError(res.status, url, `GET ${url} -> ${res.status} ${body}`.trim());
|
|
55
|
+
}
|
|
56
|
+
return (await res.json());
|
|
57
|
+
}
|
|
58
|
+
async status() {
|
|
59
|
+
return decodeStatus(await this.get("/clob/status"));
|
|
60
|
+
}
|
|
61
|
+
async markets() {
|
|
62
|
+
const w = await this.get("/clob/markets");
|
|
63
|
+
return w.map(decodeMarketStatic);
|
|
64
|
+
}
|
|
65
|
+
async marketStats(opts) {
|
|
66
|
+
const w = await this.get("/clob/markets/stats", {
|
|
67
|
+
to: opts?.to !== undefined ? msToSecs(opts.to) : undefined,
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
solutionNow: Math.trunc(w.solution_now / 1000),
|
|
71
|
+
markets: w.markets.map(decodeMarketDynamics),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async candles(id, q) {
|
|
75
|
+
const w = await this.get(`/clob/candles/${id}`, {
|
|
76
|
+
resolution: q.resolution,
|
|
77
|
+
from: q.from !== undefined ? msToSecs(q.from) : undefined,
|
|
78
|
+
to: q.to !== undefined ? msToSecs(q.to) : undefined,
|
|
79
|
+
limit: q.limit,
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
// Wire is newest-first; return oldest-first for chart consumption.
|
|
83
|
+
bars: w.candles.map(decodeCandle).reverse(),
|
|
84
|
+
resolution: w.resolution,
|
|
85
|
+
range: w.range ? { from: usToMs(w.range.from_us), to: usToMs(w.range.to_us) } : null,
|
|
86
|
+
solutionNow: usToMs(w.solution_now_us),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async orders(account, q) {
|
|
90
|
+
const w = await this.get(`/clob/orders/${account}`, {
|
|
91
|
+
until: q?.until !== undefined ? msToSecs(q.until) : undefined,
|
|
92
|
+
limit: q?.limit,
|
|
93
|
+
cursor: q?.cursor,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
orders: w.orders.map(decodeOrder),
|
|
97
|
+
nextCursor: w.next_cursor,
|
|
98
|
+
totalCount: w.total_count,
|
|
99
|
+
solutionNow: Math.trunc(w.solution_now / 1000),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async backstopTransfers(account) {
|
|
103
|
+
const w = await this.get(`/clob/backstop-transfers/${account}`);
|
|
104
|
+
return {
|
|
105
|
+
transfers: w.backstop_transfers.map(decodeBackstopTransfer),
|
|
106
|
+
totalCount: w.total_count,
|
|
107
|
+
solutionNow: Math.trunc(w.solution_now / 1000),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async orderbook(id) {
|
|
111
|
+
return decodeOrderbook(await this.get(`/clob/orderbook/${id}`));
|
|
112
|
+
}
|
|
113
|
+
/** Perp positions + account aggregates (spot holdings are at `/clob/balances`). */
|
|
114
|
+
async positions(account) {
|
|
115
|
+
return decodePositions(await this.get(`/clob/positions/${account}`));
|
|
116
|
+
}
|
|
117
|
+
/** Spot holdings + native cash. */
|
|
118
|
+
async balances(account) {
|
|
119
|
+
return decodeBalances(await this.get(`/clob/balances/${account}`));
|
|
120
|
+
}
|
|
121
|
+
/** Flat explorer view of a transaction (fields, receipt, logs, attestations,
|
|
122
|
+
* decoded calldata). Returned as-is (hex fields raw). */
|
|
123
|
+
async transaction(hash) {
|
|
124
|
+
return this.get(`/tx/${hash}`);
|
|
125
|
+
}
|
|
126
|
+
/** Accounts ranked by net PnL (realized + unrealized), descending. Paginate
|
|
127
|
+
* with `{ limit, offset }`; ranks are 1-based over the full ordering. */
|
|
128
|
+
async leaderboard(q) {
|
|
129
|
+
const w = await this.get("/clob/leaderboard", {
|
|
130
|
+
limit: q?.limit, offset: q?.offset, address: q?.account,
|
|
131
|
+
});
|
|
132
|
+
return decodeLeaderboard(w, q?.offset ?? 0);
|
|
133
|
+
}
|
|
134
|
+
async triggers(account, q) {
|
|
135
|
+
const w = await this.get(`/clob/triggers/${account}`, {
|
|
136
|
+
orderbook: q?.orderbook,
|
|
137
|
+
limit: q?.limit,
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
triggers: w.triggers.map(decodeTrigger),
|
|
141
|
+
totalCount: w.total_count,
|
|
142
|
+
nextCursor: w.next_cursor,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/transport/rest.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,+EAA+E;AAC/E,oCAAoC;AAWpC,OAAO,EACL,sBAAsB,EAAE,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D,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,CAAmB,kBAAkB,OAAO,EAAE,EAAE;YACtE,SAAS,EAAE,CAAC,EAAE,SAAS;YACvB,KAAK,EAAE,CAAC,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,OAAO;YACL,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC;YACvC,UAAU,EAAE,CAAC,CAAC,WAAW;YACzB,UAAU,EAAE,CAAC,CAAC,WAAW;SAC1B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Address, MarketId } from "../types/public.js";
|
|
2
|
+
export type Channel = "pod_orderbook" | "pod_orders" | "pod_candles" | "pod_markets" | "pod_positions" | "pod_triggers";
|
|
3
|
+
export interface SubParams {
|
|
4
|
+
clobIds?: MarketId[];
|
|
5
|
+
account?: Address;
|
|
6
|
+
depth?: number;
|
|
7
|
+
since?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Subscription {
|
|
10
|
+
unsubscribe(): void;
|
|
11
|
+
/** Update stored params (e.g. advance `since`) used on the next (re)subscribe. */
|
|
12
|
+
update(params: SubParams): void;
|
|
13
|
+
/** Force a fresh eth_subscribe with the current params (used after `onError`). */
|
|
14
|
+
resubscribe(): void;
|
|
15
|
+
}
|
|
16
|
+
export type ConnectionState = "connecting" | "open" | "closed";
|
|
17
|
+
export type WsEvent = "open" | "close" | "reconnect" | "error";
|
|
18
|
+
export type WebSocketCtor = {
|
|
19
|
+
new (url: string): WebSocket;
|
|
20
|
+
};
|
|
21
|
+
export interface WsClientOptions {
|
|
22
|
+
wsUrl: string;
|
|
23
|
+
WebSocket?: WebSocketCtor;
|
|
24
|
+
maxDelayMs?: number;
|
|
25
|
+
idleTimeoutMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class PodWsClient {
|
|
28
|
+
private readonly url;
|
|
29
|
+
private readonly WS;
|
|
30
|
+
private readonly maxDelayMs;
|
|
31
|
+
private readonly idleTimeoutMs;
|
|
32
|
+
private ws?;
|
|
33
|
+
private _state;
|
|
34
|
+
private attempts;
|
|
35
|
+
private reconnectTimer?;
|
|
36
|
+
private idleTimer?;
|
|
37
|
+
private wantOpen;
|
|
38
|
+
private readonly subs;
|
|
39
|
+
private readonly bySubId;
|
|
40
|
+
private readonly pending;
|
|
41
|
+
private readonly listeners;
|
|
42
|
+
constructor(opts: WsClientOptions);
|
|
43
|
+
get state(): ConnectionState;
|
|
44
|
+
on(event: WsEvent, handler: (e?: unknown) => void): () => void;
|
|
45
|
+
private emit;
|
|
46
|
+
connect(): void;
|
|
47
|
+
close(): void;
|
|
48
|
+
subscribe(channel: Channel, params: SubParams, onMessage: (result: unknown) => void, onError?: (err: unknown) => void): Subscription;
|
|
49
|
+
private open;
|
|
50
|
+
private scheduleReconnect;
|
|
51
|
+
private armIdle;
|
|
52
|
+
private clearReconnect;
|
|
53
|
+
private clearTimers;
|
|
54
|
+
private send;
|
|
55
|
+
private wireParams;
|
|
56
|
+
private sendSubscribe;
|
|
57
|
+
private removeSub;
|
|
58
|
+
private onMessage;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/transport/ws.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,MAAM,OAAO,GACf,eAAe,GAAG,YAAY,GAAG,aAAa,GAC9C,aAAa,GAAG,eAAe,GAAG,cAAc,CAAC;AAErD,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IA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