@liberfi.io/react-predict 0.1.1

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.
@@ -0,0 +1,589 @@
1
+ import { P as PredictClient, a as PredictWsClient, L as ListEventsParams, b as PredictPage, c as PredictEvent, d as ProviderSource, E as EventStatus, S as SimilarEventsParams, e as PredictMarket, O as Orderbook, f as ListMarketTradesParams, g as PredictTrade, h as PriceHistoryRange, i as PriceHistoryResponse, j as ListCandlesticksParams, C as Candlestick, k as PositionsResponse, B as BalanceResponse, l as ListOrdersParams, m as PredictOrder, n as CancelOrderResult, o as ListTradesParams, D as DFlowQuoteRequest, p as DFlowQuoteResponse, q as DFlowSubmitResponse, r as DFlowSubmitRequest, W as WsConnectionStatus, s as WsDataMessage, t as WsPriceEvent, u as WsOrderbookEvent, v as WsTradeEvent, w as CreateOrderInput } from './server-DlSG7h_v.mjs';
2
+ export { at as BuildClobAuthMessageInput, aE as BuildOrderMessageInput, aG as BuildSignedOrderInput, ak as CLOB_AUTH_DOMAIN, al as CLOB_AUTH_TYPES, au as CTF_EXCHANGE_ADDRESS, az as CTF_ORDER_TYPES, Y as DFlowOrderContext, J as EventSortField, N as EventSummary, aq as HttpMethod, I as MarketOutcome, H as MarketResult, M as MarketStatus, Q as MarketSummary, av as NEG_RISK_CTF_EXCHANGE_ADDRESS, aA as ORDER_TYPE, aF as OrderMessage, X as OrderSide, V as OrderStatus, K as OrderbookLevel, ax as POLYGON_CHAIN_ID, as as PolymarketL2Headers, ar as PolymarketL2HeadersInput, Z as PolymarketOrderType, U as PredictPosition, F as PredictTag, z as PredictWsClientConfig, R as PricePoint, A as ProviderMeta, ae as ResolveEventsParamsInput, aB as SIDE, G as SettlementSource, aH as SignedOrder, af as TagSlugSelection, T as TradeType, aw as USDC_ADDRESS, aj as UseMarketParams, _ as WsChannel, $ as WsChannelEvent, a0 as WsClientMessage, a6 as WsErrorCode, a7 as WsErrorMessage, a2 as WsPingMessage, a4 as WsPongMessage, a3 as WsServerMessage, a1 as WsSubscribeMessage, a5 as WsSubscribedMessage, am as buildClobAuthMessage, ay as buildCtfExchangeDomain, aC as buildOrderMessage, ao as buildPolymarketL2Headers, aD as buildSignedOrder, x as createPredictClient, y as createPredictWsClient, ap as derivePolymarketApiKey, a8 as eventQueryKey, a9 as fetchEvent, ad as fetchEventsPage, ah as fetchMarket, an as hmacSha256Base64, ac as infiniteEventsQueryKey, ag as marketQueryKey, ab as resolveEventsParams, aa as resolveTagSlug, ai as useMarket } from './server-DlSG7h_v.mjs';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as react from 'react';
5
+ import { PropsWithChildren } from 'react';
6
+ import * as _tanstack_react_query from '@tanstack/react-query';
7
+ import { UseQueryOptions, UseInfiniteQueryOptions, InfiniteData, UseMutationOptions } from '@tanstack/react-query';
8
+
9
+ type PredictProviderProps = PropsWithChildren<{
10
+ /**
11
+ * A `PredictClient` instance pointed at the prediction-server endpoint.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { createPredictClient, PredictProvider } from "@liberfi.io/react-predict";
16
+ *
17
+ * const client = createPredictClient("https://api.example.com");
18
+ *
19
+ * <PredictProvider client={client}>
20
+ * <App />
21
+ * </PredictProvider>
22
+ * ```
23
+ */
24
+ client: PredictClient;
25
+ /**
26
+ * Optional WebSocket client for real-time market data.
27
+ *
28
+ * When provided, subscription hooks (`usePricesSubscription`, etc.)
29
+ * and high-level realtime hooks (`useRealtimeOrderbook`, etc.) become
30
+ * functional. Without it they gracefully degrade to REST polling.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * import { createPredictWsClient } from "@liberfi.io/react-predict";
35
+ *
36
+ * const wsClient = createPredictWsClient({
37
+ * wsUrl: "wss://api.example.com/api/v1/ws",
38
+ * });
39
+ *
40
+ * <PredictProvider client={client} wsClient={wsClient}>
41
+ * <App />
42
+ * </PredictProvider>
43
+ * ```
44
+ */
45
+ wsClient?: PredictWsClient | null;
46
+ }>;
47
+ /**
48
+ * Provides the prediction client via React context.
49
+ *
50
+ * Place this provider at the application root (or any subtree boundary)
51
+ * where prediction hooks are used.
52
+ */
53
+ declare function PredictProvider({ client, wsClient, children, }: PredictProviderProps): react_jsx_runtime.JSX.Element;
54
+
55
+ interface PredictContextValue {
56
+ /** The prediction-server HTTP client instance. */
57
+ client: PredictClient;
58
+ /** Optional WebSocket client for real-time data. `null` when not provided. */
59
+ wsClient: PredictWsClient | null;
60
+ }
61
+ /**
62
+ * Context that carries the prediction client (prediction-server backend).
63
+ *
64
+ * Consumers must be wrapped in `PredictProvider`.
65
+ */
66
+ declare const PredictContext: react.Context<PredictContextValue | null>;
67
+
68
+ type PolymarketProviderProps = PropsWithChildren<{
69
+ /**
70
+ * Polymarket CLOB API base URL.
71
+ * Defaults to `https://clob.polymarket.com`.
72
+ */
73
+ clobApiUrl?: string;
74
+ }>;
75
+ /**
76
+ * Provides in-memory Polymarket L2 credentials via React context.
77
+ *
78
+ * The provider is wallet-agnostic. Consumers call `authenticate(signer)` with
79
+ * a `PolymarketSigner` adapter, which handles the L1 EIP-712 signing step.
80
+ *
81
+ * Credentials are derived using `nonce=0` (permanent, deterministic) and are
82
+ * stored only in memory — they are cleared when the page unloads or when
83
+ * `clearCredentials()` is called.
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * <PolymarketProvider>
88
+ * <App />
89
+ * </PolymarketProvider>
90
+ * ```
91
+ */
92
+ declare function PolymarketProvider({ children }: PolymarketProviderProps): react_jsx_runtime.JSX.Element;
93
+
94
+ /**
95
+ * Polymarket L2 API credentials derived from an L1 signature.
96
+ * These are stored in memory (never persisted) and cleared on page unload.
97
+ */
98
+ interface PolymarketCredentials {
99
+ /** L2 API key (hex string). */
100
+ apiKey: string;
101
+ /** L2 HMAC secret (hex string). */
102
+ secret: string;
103
+ /** L2 passphrase (hex string). */
104
+ passphrase: string;
105
+ /** EVM wallet address that owns the credentials. */
106
+ address: string;
107
+ }
108
+ /**
109
+ * Minimal interface for signing EIP-712 typed data.
110
+ * Implemented by the consuming app (IoC — decouples from any wallet library).
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const signer: PolymarketSigner = {
115
+ * address: walletAddress,
116
+ * signatureType: 2, // EOA = 0, MAGIC_LINK = 1, POLY_PROXY = 2
117
+ * signTypedData: async (domain, types, value) => {
118
+ * const provider = await evmWalletAdapter.getEip1193Provider();
119
+ * return provider.request({
120
+ * method: "eth_signTypedData_v4",
121
+ * params: [walletAddress, JSON.stringify({ domain, types, message: value })],
122
+ * });
123
+ * },
124
+ * };
125
+ * ```
126
+ */
127
+ interface PolymarketSigner {
128
+ /** EVM address of the connected wallet. */
129
+ address: string;
130
+ /**
131
+ * Polymarket signature type:
132
+ * - `0` = EOA (MetaMask, Coinbase, etc.)
133
+ * - `1` = Magic Link
134
+ * - `2` = Polymarket proxy (Gnosis Safe)
135
+ */
136
+ signatureType: 0 | 1 | 2;
137
+ /**
138
+ * Sign EIP-712 typed data and return the hex signature.
139
+ * The signature is used for L1 authentication with the Polymarket CLOB API.
140
+ */
141
+ signTypedData: (domain: Record<string, unknown>, types: Record<string, unknown[]>, value: Record<string, unknown>) => Promise<string>;
142
+ }
143
+ interface PolymarketContextValue {
144
+ /** In-memory credentials; `null` before the user authenticates. */
145
+ credentials: PolymarketCredentials | null;
146
+ /** `true` while the L1 → L2 credential exchange is in progress. */
147
+ isAuthenticating: boolean;
148
+ /** Error from the last authentication attempt; `null` when clean. */
149
+ authError: Error | null;
150
+ /**
151
+ * Trigger L1 authentication using the provided signer.
152
+ * Derives L2 credentials with `nonce=0` and stores them in memory.
153
+ */
154
+ authenticate: (signer: PolymarketSigner) => Promise<void>;
155
+ /** Clear all in-memory credentials (e.g. on wallet disconnect). */
156
+ clearCredentials: () => void;
157
+ }
158
+ /**
159
+ * Context that carries Polymarket L2 credentials (in-memory only).
160
+ *
161
+ * Consumers must be wrapped in `PolymarketProvider`.
162
+ */
163
+ declare const PolymarketContext: react.Context<PolymarketContextValue | null>;
164
+
165
+ /**
166
+ * Returns the `PredictClient` instance from context.
167
+ *
168
+ * Must be called inside a component tree wrapped by `PredictProvider`.
169
+ *
170
+ * @throws When used outside of `PredictProvider`.
171
+ */
172
+ declare function usePredictClient(): PredictClient;
173
+
174
+ /** Stable TanStack Query key for the events list. */
175
+ declare function eventsQueryKey(params?: ListEventsParams): unknown[];
176
+ /**
177
+ * Fetch function usable outside React (e.g. in loaders or tests).
178
+ */
179
+ declare function fetchEvents(client: ReturnType<typeof usePredictClient>, params?: ListEventsParams): Promise<PredictPage<PredictEvent>>;
180
+ /**
181
+ * React Query hook for `GET /api/v1/events` via the prediction-server client.
182
+ *
183
+ * @param params - Optional filter / sort / pagination parameters.
184
+ * @param queryOptions - Additional TanStack Query options (e.g. `enabled`, `staleTime`).
185
+ *
186
+ * @example
187
+ * ```tsx
188
+ * const { data, isLoading } = useEvents({ status: "open", limit: 20 });
189
+ * ```
190
+ */
191
+ declare function useEvents(params?: ListEventsParams, queryOptions?: Omit<UseQueryOptions<PredictPage<PredictEvent>, Error, PredictPage<PredictEvent>, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictPage<PredictEvent>, Error>;
192
+
193
+ interface UseEventParams {
194
+ /** Canonical event slug (e.g. "will-trump-win-2024" or "KXBTCD-25FEB-T68000"). */
195
+ slug: string;
196
+ /** Upstream provider. Required by prediction-server for single-event fetch. */
197
+ source?: ProviderSource;
198
+ }
199
+ /**
200
+ * React Query hook for `GET /api/v1/events/:slug` via the prediction-server client.
201
+ *
202
+ * @example
203
+ * ```tsx
204
+ * const { data, isLoading } = useEvent({ slug: "CONTROLH-2026", source: "dflow" });
205
+ * ```
206
+ */
207
+ declare function useEvent(params: UseEventParams, queryOptions?: Omit<UseQueryOptions<PredictEvent, Error, PredictEvent, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictEvent, Error>;
208
+
209
+ type InfiniteQueryOptions = Omit<UseInfiniteQueryOptions<PredictPage<PredictEvent>, Error, InfiniteData<PredictPage<PredictEvent>>, unknown[], string | undefined>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
210
+ /**
211
+ * TanStack Query infinite-query hook for `GET /api/v1/events` with cursor-based
212
+ * pagination via the prediction-server client.
213
+ *
214
+ * @param params - Resolved query parameters (use {@link resolveEventsParams} to build
215
+ * from user inputs). Do NOT include `cursor` — it is managed automatically.
216
+ * @param queryOptions - Additional TanStack Query options.
217
+ *
218
+ * @example
219
+ * ```tsx
220
+ * const params = resolveEventsParams({ status: "open", limit: 20 });
221
+ * const { data, hasNextPage, fetchNextPage } = useInfiniteEvents(params);
222
+ * ```
223
+ */
224
+ declare function useInfiniteEvents(params: ListEventsParams, queryOptions?: InfiniteQueryOptions): _tanstack_react_query.UseInfiniteQueryResult<InfiniteData<PredictPage<PredictEvent>, unknown>, Error>;
225
+
226
+ interface UseSearchEventsParams {
227
+ /** Search keyword. */
228
+ keyword: string;
229
+ /** Page size (default: 20). */
230
+ limit?: number;
231
+ /** Event status filter (default: "open"). */
232
+ status?: EventStatus;
233
+ /** Filter by upstream provider. */
234
+ source?: ProviderSource;
235
+ /** Include nested markets (default: false for lighter search payloads). */
236
+ with_markets?: boolean;
237
+ }
238
+ /**
239
+ * Infinite query hook for searching prediction events via the `listEvents`
240
+ * endpoint with a `search` parameter.
241
+ *
242
+ * @example
243
+ * ```tsx
244
+ * const { data, isLoading, hasNextPage, fetchNextPage } =
245
+ * useSearchEvents({ keyword: "trump" });
246
+ * ```
247
+ */
248
+ declare function useSearchEvents(params: UseSearchEventsParams, queryOptions?: {
249
+ enabled?: boolean;
250
+ }): _tanstack_react_query.UseInfiniteQueryResult<_tanstack_react_query.InfiniteData<PredictPage<PredictEvent>, unknown>, Error>;
251
+
252
+ declare function similarEventsQueryKey(slug: string, source: ProviderSource, params?: SimilarEventsParams): unknown[];
253
+ interface UseSimilarEventsParams {
254
+ slug: string;
255
+ source: ProviderSource;
256
+ limit?: number;
257
+ same_source?: boolean;
258
+ }
259
+ declare function useSimilarEvents(params: UseSimilarEventsParams, queryOptions?: Omit<UseQueryOptions<PredictEvent[], Error, PredictEvent[], unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictEvent[], Error>;
260
+
261
+ declare const ChartRange: {
262
+ readonly ONE_DAY: "1d";
263
+ readonly ONE_WEEK: "1w";
264
+ readonly ONE_MONTH: "1m";
265
+ readonly ALL: "all";
266
+ };
267
+ type ChartRangeType = (typeof ChartRange)[keyof typeof ChartRange];
268
+ interface MarketHistoryPoint {
269
+ /** Unix timestamp in milliseconds. */
270
+ timestamp: number;
271
+ /** Implied probability [0, 1]. */
272
+ price: number;
273
+ }
274
+ interface MarketHistorySeries {
275
+ marketSlug: string;
276
+ label: string;
277
+ /** Chronologically ordered price history. */
278
+ data: MarketHistoryPoint[];
279
+ }
280
+ interface UseMarketHistoryResult {
281
+ series: MarketHistorySeries[];
282
+ isLoading: boolean;
283
+ }
284
+ /**
285
+ * Returns price history series for the provided markets using
286
+ * `GET /api/v1/markets/{slug}/price-history`.
287
+ */
288
+ declare function useMarketHistory(markets: PredictMarket[], range?: ChartRangeType): UseMarketHistoryResult;
289
+
290
+ declare function orderbookQueryKey(slug: string, source: ProviderSource): unknown[];
291
+ interface UseOrderbookParams {
292
+ slug: string;
293
+ source: ProviderSource;
294
+ }
295
+ declare function useOrderbook(params: UseOrderbookParams, queryOptions?: Omit<UseQueryOptions<Orderbook, Error, Orderbook, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<Orderbook, Error>;
296
+
297
+ declare function marketTradesQueryKey(slug: string, params: ListMarketTradesParams): unknown[];
298
+ interface UseMarketTradesParams {
299
+ slug: string;
300
+ source: ProviderSource;
301
+ limit?: number;
302
+ cursor?: string;
303
+ side?: string;
304
+ }
305
+ declare function useMarketTrades(params: UseMarketTradesParams, queryOptions?: Omit<UseQueryOptions<PredictPage<PredictTrade>, Error, PredictPage<PredictTrade>, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictPage<PredictTrade>, Error>;
306
+
307
+ declare function priceHistoryQueryKey(slug: string, source: ProviderSource, range?: PriceHistoryRange): unknown[];
308
+ interface UsePriceHistoryParams {
309
+ slug: string;
310
+ source: ProviderSource;
311
+ range?: PriceHistoryRange;
312
+ }
313
+ declare function usePriceHistory(params: UsePriceHistoryParams, queryOptions?: Omit<UseQueryOptions<PriceHistoryResponse, Error, PriceHistoryResponse, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PriceHistoryResponse, Error>;
314
+
315
+ declare function candlesticksQueryKey(slug: string, params?: ListCandlesticksParams): unknown[];
316
+ interface UseCandlesticksParams {
317
+ slug: string;
318
+ interval?: string;
319
+ limit?: number;
320
+ }
321
+ declare function useCandlesticks(params: UseCandlesticksParams, queryOptions?: Omit<UseQueryOptions<Candlestick[], Error, Candlestick[], unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<Candlestick[], Error>;
322
+
323
+ declare function positionsQueryKey(user: string, source?: ProviderSource): unknown[];
324
+ interface UsePositionsParams {
325
+ /** Provider source. Omit to aggregate all providers. */
326
+ source?: ProviderSource;
327
+ user: string;
328
+ }
329
+ declare function usePositions(params: UsePositionsParams, queryOptions?: Omit<UseQueryOptions<PositionsResponse, Error, PositionsResponse, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PositionsResponse, Error>;
330
+
331
+ declare function balanceQueryKey(source: ProviderSource, user: string): unknown[];
332
+ interface UseBalanceParams {
333
+ source: ProviderSource;
334
+ user: string;
335
+ }
336
+ declare function useBalance(params: UseBalanceParams, queryOptions?: Omit<UseQueryOptions<BalanceResponse, Error, BalanceResponse, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<BalanceResponse, Error>;
337
+
338
+ declare function ordersQueryKey(params: ListOrdersParams): unknown[];
339
+ declare function useOrders(params: ListOrdersParams, queryOptions?: Omit<UseQueryOptions<PredictPage<PredictOrder>, Error, PredictPage<PredictOrder>, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictPage<PredictOrder>, Error>;
340
+
341
+ declare function orderQueryKey(id: string, source: ProviderSource): unknown[];
342
+ interface UseOrderParams {
343
+ id: string;
344
+ source: ProviderSource;
345
+ }
346
+ /**
347
+ * Query a single order by ID. Automatically polls every 1 s while enabled.
348
+ */
349
+ declare function useOrder(params: UseOrderParams, queryOptions?: Omit<UseQueryOptions<PredictOrder, Error, PredictOrder, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictOrder, Error>;
350
+
351
+ interface CancelOrderVariables {
352
+ id: string;
353
+ source: ProviderSource;
354
+ }
355
+ declare function useCancelOrder(mutationOptions?: Omit<UseMutationOptions<CancelOrderResult, Error, CancelOrderVariables>, "mutationFn">): _tanstack_react_query.UseMutationResult<CancelOrderResult, Error, CancelOrderVariables, unknown>;
356
+
357
+ declare function tradesQueryKey(params: ListTradesParams): unknown[];
358
+ declare function useTrades(params: ListTradesParams, queryOptions?: Omit<UseQueryOptions<PredictPage<PredictTrade>, Error, PredictPage<PredictTrade>, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<PredictPage<PredictTrade>, Error>;
359
+
360
+ declare function dflowQuoteQueryKey(params: DFlowQuoteRequest): unknown[];
361
+ /**
362
+ * Fetch a DFlow quote. The query is only enabled when all required
363
+ * fields are present and amount > 0.
364
+ */
365
+ declare function useDFlowQuote(params: DFlowQuoteRequest, queryOptions?: Omit<UseQueryOptions<DFlowQuoteResponse, Error, DFlowQuoteResponse, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<DFlowQuoteResponse, Error>;
366
+
367
+ declare function useDFlowSubmit(mutationOptions?: Omit<UseMutationOptions<DFlowSubmitResponse, Error, DFlowSubmitRequest>, "mutationFn">): _tanstack_react_query.UseMutationResult<DFlowSubmitResponse, Error, DFlowSubmitRequest, unknown>;
368
+
369
+ interface UsePredictWsClientResult {
370
+ /** The WebSocket client instance, or `null` if not provided via `PredictProvider`. */
371
+ wsClient: PredictWsClient | null;
372
+ /** Current connection status. Defaults to `"disconnected"` when no client. */
373
+ wsStatus: WsConnectionStatus;
374
+ /** Shorthand for `wsStatus === "connected"`. */
375
+ isWsConnected: boolean;
376
+ }
377
+ /**
378
+ * Access the `PredictWsClient` from context and track its connection status.
379
+ *
380
+ * Must be called inside a `PredictProvider`.
381
+ */
382
+ declare function usePredictWsClient(): UsePredictWsClientResult;
383
+
384
+ interface UsePricesSubscriptionParams {
385
+ /** WebSocket client (from `usePredictWsClient`). */
386
+ wsClient: PredictWsClient | null;
387
+ /** Market slugs to subscribe to. */
388
+ slugs: string[];
389
+ /** Enable/disable the subscription. Default: `true`. */
390
+ enabled?: boolean;
391
+ /** Optional callback fired on every price update. */
392
+ onUpdate?: (msg: WsDataMessage<WsPriceEvent>) => void;
393
+ }
394
+ interface UsePricesSubscriptionResult {
395
+ /** Latest price data keyed by market slug. */
396
+ prices: Map<string, WsPriceEvent>;
397
+ /** Whether the subscription is active. */
398
+ isSubscribed: boolean;
399
+ }
400
+ /**
401
+ * Subscribe to real-time price updates via WebSocket.
402
+ *
403
+ * Maintains an internal `Map<slug, WsPriceEvent>` that updates on each push.
404
+ * Does **not** interact with React Query.
405
+ */
406
+ declare function usePricesSubscription({ wsClient, slugs, enabled, onUpdate, }: UsePricesSubscriptionParams): UsePricesSubscriptionResult;
407
+
408
+ interface UseOrderbookSubscriptionParams {
409
+ /** WebSocket client (from `usePredictWsClient`). */
410
+ wsClient: PredictWsClient | null;
411
+ /** Market slug to subscribe to. */
412
+ slug: string;
413
+ /** Enable/disable the subscription. Default: `true`. */
414
+ enabled?: boolean;
415
+ /** Optional callback fired on every orderbook snapshot. */
416
+ onUpdate?: (msg: WsDataMessage<WsOrderbookEvent>) => void;
417
+ }
418
+ interface UseOrderbookSubscriptionResult {
419
+ /** Latest full orderbook snapshot, or `null` before the first push. */
420
+ orderbook: WsOrderbookEvent | null;
421
+ /** Whether the subscription is active. */
422
+ isSubscribed: boolean;
423
+ }
424
+ /**
425
+ * Subscribe to real-time orderbook snapshots via WebSocket.
426
+ *
427
+ * Each incoming message is a **full snapshot** — no delta merging needed.
428
+ * Does **not** interact with React Query.
429
+ */
430
+ declare function useOrderbookSubscription({ wsClient, slug, enabled, onUpdate, }: UseOrderbookSubscriptionParams): UseOrderbookSubscriptionResult;
431
+
432
+ interface UseTradesSubscriptionParams {
433
+ /** WebSocket client (from `usePredictWsClient`). */
434
+ wsClient: PredictWsClient | null;
435
+ /** Market slug to subscribe to. */
436
+ slug: string;
437
+ /** Enable/disable the subscription. Default: `true`. */
438
+ enabled?: boolean;
439
+ /** Max trades to keep in the buffer. Default: `100`. */
440
+ maxHistory?: number;
441
+ /** Optional callback fired on every new trade. */
442
+ onUpdate?: (msg: WsDataMessage<WsTradeEvent>) => void;
443
+ }
444
+ interface UseTradesSubscriptionResult {
445
+ /** Buffered trades, newest first. */
446
+ trades: WsTradeEvent[];
447
+ /** Whether the subscription is active. */
448
+ isSubscribed: boolean;
449
+ /** Clear the trade buffer. */
450
+ clearHistory: () => void;
451
+ }
452
+ /**
453
+ * Subscribe to real-time trade events via WebSocket.
454
+ *
455
+ * Maintains a bounded buffer of recent trades (newest first).
456
+ * Does **not** interact with React Query.
457
+ */
458
+ declare function useTradesSubscription({ wsClient, slug, enabled, maxHistory, onUpdate, }: UseTradesSubscriptionParams): UseTradesSubscriptionResult;
459
+
460
+ interface UseRealtimeOrderbookParams {
461
+ slug: string;
462
+ source: ProviderSource;
463
+ }
464
+ /**
465
+ * Orderbook with automatic WS → REST fallback.
466
+ *
467
+ * - When the WebSocket is subscribed, the hook writes incoming snapshots
468
+ * directly into the React Query cache via `setQueryData` (no refetch)
469
+ * and disables REST polling.
470
+ * - When the WebSocket is unavailable or disconnected, the hook falls
471
+ * back to REST polling every 5 seconds.
472
+ *
473
+ * The return value is the same `UseQueryResult` as `useOrderbook`, so
474
+ * migrating from `useOrderbook` is a drop-in replacement.
475
+ */
476
+ declare function useRealtimeOrderbook(params: UseRealtimeOrderbookParams, queryOptions?: Omit<UseQueryOptions<Orderbook, Error, Orderbook, unknown[]>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<Orderbook, Error>;
477
+
478
+ interface UseRealtimePricesParams {
479
+ /** Market slugs to subscribe to. */
480
+ slugs: string[];
481
+ /** Enable/disable. Default: `true`. */
482
+ enabled?: boolean;
483
+ /** Optional callback on each price update. */
484
+ onUpdate?: (msg: WsDataMessage<WsPriceEvent>) => void;
485
+ }
486
+ /**
487
+ * Real-time price updates with graceful degradation.
488
+ *
489
+ * When the WebSocket client is available and connected, this hook
490
+ * subscribes to price updates and returns a `Map<slug, WsPriceEvent>`.
491
+ * When no WebSocket client is provided, `prices` stays empty and
492
+ * `isSubscribed` is `false` — the consumer can fall back to REST data.
493
+ */
494
+ declare function useRealtimePrices({ slugs, enabled, onUpdate, }: UseRealtimePricesParams): UsePricesSubscriptionResult;
495
+
496
+ interface UseRealtimeTradesParams {
497
+ /** Market slug to subscribe to. */
498
+ slug: string;
499
+ /** Enable/disable. Default: `true`. */
500
+ enabled?: boolean;
501
+ /** Max WS trades to buffer. Default: `100`. */
502
+ maxHistory?: number;
503
+ /** Optional callback on each new trade. */
504
+ onUpdate?: (msg: WsDataMessage<WsTradeEvent>) => void;
505
+ /**
506
+ * When `true`, new WS trades are prepended into matching React Query
507
+ * `marketTrades` cache entries so paginated lists update instantly.
508
+ * Default: `true`.
509
+ */
510
+ syncToQueryCache?: boolean;
511
+ }
512
+ type UseRealtimeTradesResult = UseTradesSubscriptionResult;
513
+ /**
514
+ * Real-time trade stream with optional React Query cache sync.
515
+ *
516
+ * Subscribes to the `trades` WS channel for a single market.
517
+ * When `syncToQueryCache` is enabled (default), each new trade is also
518
+ * prepended into any active React Query cache entry whose key matches
519
+ * `["predict", "market-trades", slug, ...]`.
520
+ */
521
+ declare function useRealtimeTrades({ slug, enabled, maxHistory, onUpdate, syncToQueryCache, }: UseRealtimeTradesParams): UseRealtimeTradesResult;
522
+
523
+ /**
524
+ * Access Polymarket L2 credentials and authentication actions.
525
+ *
526
+ * Must be called inside a component tree wrapped by `PolymarketProvider`.
527
+ *
528
+ * @throws When used outside of `PolymarketProvider`.
529
+ *
530
+ * @example
531
+ * ```tsx
532
+ * function TradeButton() {
533
+ * const { credentials, authenticate, isAuthenticating } = usePolymarket();
534
+ *
535
+ * const handleClick = async () => {
536
+ * if (!credentials) {
537
+ * await authenticate(myPolymarketSigner);
538
+ * }
539
+ * // proceed to place order
540
+ * };
541
+ *
542
+ * return (
543
+ * <button onClick={handleClick} disabled={isAuthenticating}>
544
+ * Trade
545
+ * </button>
546
+ * );
547
+ * }
548
+ * ```
549
+ */
550
+ declare function usePolymarket(): PolymarketContextValue;
551
+
552
+ interface CreatePolymarketOrderVariables {
553
+ input: CreateOrderInput;
554
+ /**
555
+ * IoC signer — provided by the consuming app.
556
+ * Used to sign the EIP-712 order struct on the CTF Exchange contract.
557
+ */
558
+ signer: PolymarketSigner;
559
+ }
560
+ /**
561
+ * Mutation hook for creating a Polymarket limit order.
562
+ *
563
+ * Flow:
564
+ * 1. If no L2 credentials exist, triggers L1 → L2 authentication automatically.
565
+ * 2. Builds the EIP-712 `Order` typed data and prompts the wallet for a signature.
566
+ * 3. Constructs HMAC L2 auth headers from the stored credentials.
567
+ * 4. Submits the signed order via `POST /api/v1/orders/polymarket` (prediction-server proxy).
568
+ * 5. Invalidates `orders` and `positions` queries on success.
569
+ *
570
+ * @example
571
+ * ```tsx
572
+ * const { mutateAsync: createOrder, isPending } = useCreatePolymarketOrder();
573
+ *
574
+ * await createOrder({
575
+ * signer: myPolymarketSigner,
576
+ * input: {
577
+ * tokenId: "123456789",
578
+ * price: 0.55,
579
+ * size: 10,
580
+ * side: "BUY",
581
+ * tickSize: "0.01",
582
+ * negRisk: false,
583
+ * },
584
+ * });
585
+ * ```
586
+ */
587
+ declare function useCreatePolymarketOrder(mutationOptions?: Omit<UseMutationOptions<PredictOrder, Error, CreatePolymarketOrderVariables>, "mutationFn">): _tanstack_react_query.UseMutationResult<PredictOrder, Error, CreatePolymarketOrderVariables, unknown>;
588
+
589
+ export { BalanceResponse, CancelOrderResult, type CancelOrderVariables, Candlestick, ChartRange, type ChartRangeType, CreateOrderInput, type CreatePolymarketOrderVariables, DFlowQuoteRequest, DFlowQuoteResponse, DFlowSubmitRequest, DFlowSubmitResponse, EventStatus, ListCandlesticksParams, ListEventsParams, ListMarketTradesParams, ListOrdersParams, ListTradesParams, type MarketHistoryPoint, type MarketHistorySeries, Orderbook, PolymarketContext, type PolymarketContextValue, type PolymarketCredentials, PolymarketProvider, type PolymarketProviderProps, type PolymarketSigner, PositionsResponse, PredictClient, PredictContext, type PredictContextValue, PredictEvent, PredictMarket, PredictOrder, PredictPage, PredictProvider, type PredictProviderProps, PredictTrade, PredictWsClient, PriceHistoryRange, PriceHistoryResponse, ProviderSource, SimilarEventsParams, type UseBalanceParams, type UseCandlesticksParams, type UseEventParams, type UseMarketHistoryResult, type UseMarketTradesParams, type UseOrderParams, type UseOrderbookParams, type UseOrderbookSubscriptionParams, type UseOrderbookSubscriptionResult, type UsePositionsParams, type UsePredictWsClientResult, type UsePriceHistoryParams, type UsePricesSubscriptionParams, type UsePricesSubscriptionResult, type UseRealtimeOrderbookParams, type UseRealtimePricesParams, type UseRealtimeTradesParams, type UseRealtimeTradesResult, type UseSearchEventsParams, type UseSimilarEventsParams, type UseTradesSubscriptionParams, type UseTradesSubscriptionResult, WsConnectionStatus, WsDataMessage, WsOrderbookEvent, WsPriceEvent, WsTradeEvent, balanceQueryKey, candlesticksQueryKey, dflowQuoteQueryKey, eventsQueryKey, fetchEvents, marketTradesQueryKey, orderQueryKey, orderbookQueryKey, ordersQueryKey, positionsQueryKey, priceHistoryQueryKey, similarEventsQueryKey, tradesQueryKey, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowQuote, useDFlowSubmit, useEvent, useEvents, useInfiniteEvents, useMarketHistory, useMarketTrades, useOrder, useOrderbook, useOrderbookSubscription, useOrders, usePolymarket, usePositions, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useSearchEvents, useSimilarEvents, useTrades, useTradesSubscription };