@liberfi.io/ui-predict 0.1.75 → 0.1.77

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.
@@ -1,420 +0,0 @@
1
- /**
2
- * V2 types for the prediction-server REST API (/api/v1/events).
3
- *
4
- * These types are intentionally isolated from the legacy client types so that
5
- * the v1 (DFlow) and v2 (prediction-server) clients can coexist and be migrated
6
- * incrementally.
7
- *
8
- * Mirrors: github.com/liberfi-io/prediction-server/internal/domain
9
- */
10
- /** Upstream data provider that produced a domain object. */
11
- type V2ProviderSource = "dflow" | "polymarket";
12
- /**
13
- * Provider-specific metadata attached to every domain aggregate.
14
- * Keys are namespaced field paths, e.g. "polymarket.conditionId" or "dflow.yesMint".
15
- * Values are raw JSON-decoded values.
16
- */
17
- type V2ProviderMeta = Record<string, unknown>;
18
- /** Provider-sourced label attached to an Event. */
19
- interface V2Tag {
20
- slug: string;
21
- label: string;
22
- source: V2ProviderSource;
23
- provider_meta?: V2ProviderMeta;
24
- }
25
- /** Lifecycle status of a prediction event (normalised across all providers). */
26
- type V2EventStatus = "pending" | "open" | "closed" | "voided";
27
- /** Settlement / resolution data source for an event. */
28
- interface V2SettlementSource {
29
- url: string;
30
- name?: string;
31
- }
32
- /** Root aggregate for a prediction event from the prediction-server API. */
33
- interface V2Event {
34
- /** Internal database surrogate key (absent when not yet persisted). */
35
- id?: number;
36
- /**
37
- * Canonical business key shared across all providers.
38
- * - DFlow: ticker (e.g. "KXBTCD-25FEB-T68000")
39
- * - Polymarket: slug (e.g. "will-trump-win-2024")
40
- */
41
- slug: string;
42
- title: string;
43
- subtitle?: string;
44
- description?: string;
45
- image_url?: string;
46
- status: V2EventStatus;
47
- /** ISO 8601 timestamp; absent if the provider does not supply it. */
48
- start_at?: string;
49
- end_at?: string;
50
- created_at?: string;
51
- updated_at?: string;
52
- /** Provider-sourced labels for display only. */
53
- tags?: V2Tag[];
54
- /** All values are USD amounts. */
55
- volume?: number;
56
- volume_24h?: number;
57
- liquidity?: number;
58
- open_interest?: number;
59
- settlement_sources?: V2SettlementSource[];
60
- /** Nested markets; omitted when the request used `with_markets=false`. */
61
- markets?: V2Market[];
62
- source: V2ProviderSource;
63
- provider_meta?: V2ProviderMeta;
64
- }
65
- /** Lifecycle status of a prediction market (normalised across all providers). */
66
- type V2MarketStatus = "pending" | "open" | "closed" | "voided";
67
- /** Final resolution of a closed market. Empty string means unresolved. */
68
- type V2MarketResult = "yes" | "no" | "voided" | "";
69
- /** One possible outcome in a binary (or multi-outcome) prediction market. */
70
- interface V2Outcome {
71
- /** Display name, e.g. "Yes" or "No". */
72
- label: string;
73
- /** Current implied probability [0, 1]. */
74
- price?: number;
75
- best_bid?: number;
76
- best_ask?: number;
77
- }
78
- /** Tradeable prediction outcome within an Event. */
79
- interface V2Market {
80
- id?: number;
81
- event_id?: number;
82
- slug: string;
83
- event_slug: string;
84
- question: string;
85
- description?: string;
86
- image_url?: string;
87
- /** Resolution/settlement rules in order. */
88
- rules?: string[];
89
- status: V2MarketStatus;
90
- result?: V2MarketResult;
91
- start_at?: string;
92
- end_at?: string;
93
- expires_at?: string;
94
- created_at?: string;
95
- updated_at?: string;
96
- /** Always present; binary markets have exactly 2 outcomes (YES at [0], NO at [1]). */
97
- outcomes: V2Outcome[];
98
- volume?: number;
99
- volume_24h?: number;
100
- liquidity?: number;
101
- open_interest?: number;
102
- source: V2ProviderSource;
103
- provider_meta?: V2ProviderMeta;
104
- }
105
- /** Generic paginated result set returned by the prediction-server list endpoints. */
106
- interface V2Page<T> {
107
- items: T[];
108
- next_cursor?: string;
109
- has_more?: boolean;
110
- limit?: number;
111
- /** Not all backends support total count. */
112
- total?: number;
113
- }
114
- /** Valid sort fields accepted by `GET /api/v1/events`. */
115
- type V2EventSortField = "volume" | "volume_24h" | "liquidity" | "open_interest" | "end_at" | "start_at" | "created_at";
116
- /** Query parameters for `listEvents`. All fields are optional. */
117
- interface V2ListEventsParams {
118
- /** Page size. Server default: 20. */
119
- limit?: number;
120
- /** Opaque pagination cursor returned by the previous page's `next_cursor`. */
121
- cursor?: string;
122
- /** Filter by event lifecycle status. */
123
- status?: V2EventStatus;
124
- /** Filter by upstream provider. */
125
- source?: V2ProviderSource;
126
- /** Unified navigation tag slug (e.g. "politics", "sports"). */
127
- tag_slug?: string;
128
- /** Full-text search query. */
129
- search?: string;
130
- /** Field to sort by. */
131
- sort_by?: V2EventSortField;
132
- /** When `true`, sort ascending. Defaults to descending. */
133
- sort_asc?: boolean;
134
- /**
135
- * When `false`, markets are omitted from each event for lighter payloads.
136
- * Defaults to `true` on the server.
137
- */
138
- with_markets?: boolean;
139
- }
140
- /** Single price level in an order book. */
141
- interface V2OrderbookOrder {
142
- price: number;
143
- size: number;
144
- }
145
- /** Aggregated order book for a market. */
146
- interface V2Orderbook {
147
- market_id: string;
148
- /** Sorted by price descending. */
149
- bids: V2OrderbookOrder[];
150
- /** Sorted by price ascending. */
151
- asks: V2OrderbookOrder[];
152
- /** best_ask − best_bid; absent when either side is empty. */
153
- spread?: number;
154
- }
155
- /** On-chain trade type. */
156
- type V2TradeType = "TRADE" | "SPLIT" | "MERGE" | "REDEEM" | "REWARD" | "CONVERSION" | "MAKER_REBATE" | "REFERRAL_REWARD";
157
- /** Lightweight event summary embedded in a trade. */
158
- interface V2EventSummary {
159
- slug: string;
160
- title: string;
161
- image_url?: string;
162
- status: V2EventStatus;
163
- }
164
- /** Lightweight market summary embedded in a trade. */
165
- interface V2MarketSummary {
166
- slug: string;
167
- question: string;
168
- status: V2MarketStatus;
169
- }
170
- /** A single trade record. */
171
- interface V2Trade {
172
- id: string;
173
- source: V2ProviderSource;
174
- side: string;
175
- outcome: string;
176
- outcome_index: number;
177
- price: number;
178
- size: number;
179
- usd_size: number;
180
- /** Unix seconds. */
181
- timestamp: number;
182
- tx_hash: string;
183
- wallet: string;
184
- type: V2TradeType;
185
- event?: V2EventSummary;
186
- market?: V2MarketSummary;
187
- provider_meta?: V2ProviderMeta;
188
- }
189
- /** Query parameters for `GET /api/v1/markets/{slug}/trades`. */
190
- interface V2ListMarketTradesParams {
191
- source: V2ProviderSource;
192
- limit?: number;
193
- cursor?: string;
194
- /** Filter by side: `"BUY"` or `"SELL"`. */
195
- side?: string;
196
- }
197
- /** Query parameters for `GET /api/v1/trades` (by wallet). */
198
- interface V2ListTradesByWalletParams {
199
- source: V2ProviderSource;
200
- wallet: string;
201
- limit?: number;
202
- cursor?: string;
203
- /** Comma-separated trade types. */
204
- type?: string;
205
- side?: string;
206
- }
207
- /** A single price-history data point. */
208
- interface V2PricePoint {
209
- /** Unix seconds. */
210
- t: number;
211
- /** Price [0, 1]. */
212
- p: number;
213
- }
214
- /** Response from `GET /api/v1/markets/{slug}/price-history`. */
215
- interface V2PriceHistoryResponse {
216
- points: V2PricePoint[];
217
- }
218
- /** Accepted values for the `range` query parameter. */
219
- type V2PriceHistoryRange = "1d" | "1w" | "1m" | "all";
220
- /** OHLCV candlestick data point. */
221
- interface V2Candlestick {
222
- timestamp: string;
223
- open: number;
224
- high: number;
225
- low: number;
226
- close: number;
227
- volume: number;
228
- }
229
- /** Query parameters for `GET /api/v1/markets/{slug}/candlesticks`. */
230
- interface V2ListCandlesticksParams {
231
- /** Candle interval (e.g. `"1m"`, `"5m"`, `"1h"`, `"1d"`). Default: `"1h"`. */
232
- interval?: string;
233
- /** Number of candles. Default: 100. */
234
- limit?: number;
235
- }
236
- /** Query parameters for `GET /api/v1/events/{slug}/similar`. */
237
- interface V2SimilarEventsParams {
238
- /** Number of results (default 5, max 20). */
239
- limit?: number;
240
- /** When true, only return events from the same provider. */
241
- same_source?: boolean;
242
- }
243
- /** A single user position in a prediction market. */
244
- interface V2Position {
245
- source: V2ProviderSource;
246
- side: string;
247
- size: number;
248
- avg_price: number;
249
- current_price: number;
250
- current_value: number;
251
- initial_value: number;
252
- pnl: number;
253
- pnl_percent: number;
254
- realized_pnl: number;
255
- redeemable: boolean;
256
- event?: V2Event;
257
- market?: V2Market;
258
- provider_meta?: V2ProviderMeta;
259
- }
260
- /** Response from `GET /api/v1/positions`. */
261
- interface V2PositionsResponse {
262
- user: string;
263
- positions: V2Position[];
264
- }
265
- /** Lifecycle status of a user order. */
266
- type V2UserOrderStatus = "live" | "matched" | "cancelled" | "invalid" | "submitted" | "pending" | "open" | "pending_close" | "closed" | "failed" | "expired";
267
- /** Order direction. */
268
- type V2OrderSide = "BUY" | "SELL";
269
- /** A single user order record. */
270
- interface V2UserOrder {
271
- id: string;
272
- source: V2ProviderSource;
273
- status: V2UserOrderStatus;
274
- market_id?: string;
275
- asset_id?: string;
276
- side: V2OrderSide;
277
- outcome?: string;
278
- price?: string;
279
- original_size?: string;
280
- size_matched?: string;
281
- in_amount?: string;
282
- out_amount?: string;
283
- order_type?: string;
284
- /** Unix seconds. */
285
- created_at?: number;
286
- expires_at?: number;
287
- provider_meta?: V2ProviderMeta;
288
- }
289
- /** Query parameters for `GET /api/v1/orders`. */
290
- interface V2ListOrdersParams {
291
- source: V2ProviderSource;
292
- wallet_address?: string;
293
- market_id?: string;
294
- asset_id?: string;
295
- next_cursor?: string;
296
- }
297
- /** Result of `DELETE /api/v1/orders/{id}`. */
298
- interface V2CancelOrderResult {
299
- cancelled: string[];
300
- not_cancelled: Record<string, string>;
301
- }
302
- /** Request body for `POST /api/v1/orders/dflow/quote`. */
303
- interface V2DFlowQuoteRequest {
304
- inputMint: string;
305
- outputMint: string;
306
- amount: string;
307
- userPublicKey: string;
308
- slippageBps?: number;
309
- }
310
- /** Raw upstream response from DFlow quote (transparent passthrough). */
311
- type V2DFlowQuoteResponse = Record<string, unknown>;
312
- /** Context stored alongside a DFlow order for later enrichment. */
313
- interface V2DFlowOrderContext {
314
- user_public_key: string;
315
- input_mint: string;
316
- output_mint: string;
317
- amount: string;
318
- price: string;
319
- side: string;
320
- outcome: string;
321
- market_slug: string;
322
- slippage_bps: number;
323
- }
324
- /** Request body for `POST /api/v1/orders/dflow/submit`. */
325
- interface V2DFlowSubmitRequest {
326
- signedTransaction: string;
327
- orderContext: V2DFlowOrderContext;
328
- }
329
- /** Response from `POST /api/v1/orders/dflow/submit`. */
330
- interface V2DFlowSubmitResponse {
331
- signature: string;
332
- status: V2UserOrderStatus;
333
- }
334
-
335
- /**
336
- * HTTP client for the prediction-server REST API (v2 / prediction-server backend).
337
- *
338
- * Covers `GET /api/v1/events` (listEvents), `GET /api/v1/events/:slug` (getEvent),
339
- * and `GET /api/v1/markets/:slug` (getMarket).
340
- *
341
- * This client is intentionally decoupled from the legacy `DflowPredictClient` so
342
- * that both can be used in parallel during the incremental migration from the old
343
- * DFlow-direct integration to the unified prediction-server backend.
344
- *
345
- * @example
346
- * ```ts
347
- * const client = new PredictClientV2("https://api.example.com");
348
- * const page = await client.listEvents({ status: "open", limit: 20 });
349
- * const event = await client.getEvent("will-trump-win-2024");
350
- * const market = await client.getMarket("will-trump-win-2024-yes");
351
- * ```
352
- */
353
- declare class PredictClientV2 {
354
- private readonly endpoint;
355
- constructor(endpoint: string);
356
- /**
357
- * List prediction events with optional filtering, sorting, and pagination.
358
- *
359
- * Maps to `GET /api/v1/events`.
360
- *
361
- * @param params - Optional query parameters (filter, sort, pagination).
362
- * @returns A paginated page of events.
363
- */
364
- listEvents(params?: V2ListEventsParams): Promise<V2Page<V2Event>>;
365
- /**
366
- * Fetch a single prediction event by its slug.
367
- *
368
- * Maps to `GET /api/v1/events/:slug?source=...`.
369
- *
370
- * @param slug - Canonical event slug (e.g. "will-trump-win-2024" for Polymarket
371
- * or "KXBTCD-25FEB-T68000" for DFlow).
372
- * @param source - Upstream provider (`"dflow"` or `"polymarket"`).
373
- * @returns The matching event.
374
- * @throws When the server responds with 404 or any other non-2xx status.
375
- */
376
- getEvent(slug: string, source?: V2ProviderSource): Promise<V2Event>;
377
- /**
378
- * Fetch a single prediction market by its slug.
379
- *
380
- * Maps to `GET /api/v1/markets/:slug?source=...`.
381
- *
382
- * @param slug - Canonical market slug.
383
- * @param source - Upstream provider (`"dflow"` or `"polymarket"`).
384
- * @returns The matching market.
385
- * @throws When the server responds with 404 or any other non-2xx status.
386
- */
387
- getMarket(slug: string, source?: V2ProviderSource): Promise<V2Market>;
388
- /** Maps to `GET /api/v1/markets/:slug/orderbook?source=...`. */
389
- getOrderbook(slug: string, source: V2ProviderSource): Promise<V2Orderbook>;
390
- /** Maps to `GET /api/v1/markets/:slug/trades?source=...`. */
391
- listMarketTrades(slug: string, params: V2ListMarketTradesParams): Promise<V2Page<V2Trade>>;
392
- /** Maps to `GET /api/v1/markets/:slug/price-history?source=...&range=...`. */
393
- getPriceHistory(slug: string, source: V2ProviderSource, range?: V2PriceHistoryRange): Promise<V2PriceHistoryResponse>;
394
- /** Maps to `GET /api/v1/markets/:slug/candlesticks?interval=...&limit=...`. */
395
- listCandlesticks(slug: string, params?: V2ListCandlesticksParams): Promise<V2Candlestick[]>;
396
- /** Maps to `GET /api/v1/events/:slug/similar?source=...`. */
397
- getSimilarEvents(slug: string, source: V2ProviderSource, params?: V2SimilarEventsParams): Promise<V2Event[]>;
398
- /** Maps to `GET /api/v1/positions?source=...&user=...`. */
399
- getPositions(source: V2ProviderSource, user: string): Promise<V2PositionsResponse>;
400
- /** Maps to `GET /api/v1/orders?source=...&wallet_address=...`. */
401
- listOrders(params: V2ListOrdersParams): Promise<V2Page<V2UserOrder>>;
402
- /** Maps to `GET /api/v1/orders/:id?source=...`. */
403
- getOrder(id: string, source: V2ProviderSource): Promise<V2UserOrder>;
404
- /** Maps to `DELETE /api/v1/orders/:id?source=...`. */
405
- cancelOrder(id: string, source: V2ProviderSource): Promise<V2CancelOrderResult>;
406
- /** Maps to `POST /api/v1/orders/dflow/quote`. */
407
- createDFlowQuote(body: V2DFlowQuoteRequest): Promise<V2DFlowQuoteResponse>;
408
- /** Maps to `POST /api/v1/orders/dflow/submit`. */
409
- submitDFlowTransaction(body: V2DFlowSubmitRequest): Promise<V2DFlowSubmitResponse>;
410
- /** Maps to `GET /api/v1/trades?source=...&wallet=...`. */
411
- listTradesByWallet(params: V2ListTradesByWalletParams): Promise<V2Page<V2Trade>>;
412
- }
413
- /**
414
- * Factory function for `PredictClientV2`.
415
- *
416
- * @param endpoint - Base URL of the prediction-server, without a trailing slash.
417
- */
418
- declare function createPredictClientV2(endpoint: string): PredictClientV2;
419
-
420
- export { type V2Outcome as A, type V2ProviderMeta as B, type V2SettlementSource as C, type V2Tag as D, PredictClientV2 as P, type V2EventSortField as V, type V2ProviderSource as a, type V2Event as b, type V2Market as c, type V2EventStatus as d, type V2Page as e, type V2ListEventsParams as f, type V2SimilarEventsParams as g, type V2Orderbook as h, type V2ListMarketTradesParams as i, type V2Trade as j, type V2PriceHistoryRange as k, type V2PriceHistoryResponse as l, type V2ListCandlesticksParams as m, type V2Candlestick as n, type V2PositionsResponse as o, type V2ListOrdersParams as p, type V2UserOrder as q, type V2CancelOrderResult as r, type V2DFlowQuoteRequest as s, type V2DFlowQuoteResponse as t, type V2DFlowSubmitResponse as u, type V2DFlowSubmitRequest as v, type V2ListTradesByWalletParams as w, createPredictClientV2 as x, type V2MarketResult as y, type V2MarketStatus as z };