@liberfi.io/react-predict 0.3.71 → 0.3.72
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/dist/index.d.mts +83 -4
- package/dist/index.d.ts +83 -4
- package/dist/index.js +151 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -10
- package/dist/index.mjs.map +1 -1
- package/dist/{server-1_Lm8FLS.d.mts → server-CzifZBb_.d.mts} +1 -1
- package/dist/{server-1_Lm8FLS.d.ts → server-CzifZBb_.d.ts} +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
|
@@ -2390,6 +2390,16 @@ function PredictProvider({
|
|
|
2390
2390
|
const value = useMemo(() => ({ client, wsClient: ws }), [client, ws]);
|
|
2391
2391
|
return /* @__PURE__ */ jsx(PredictContext.Provider, { value, children });
|
|
2392
2392
|
}
|
|
2393
|
+
|
|
2394
|
+
// src/market-data/adapters/create-client-market-venue-adapter.ts
|
|
2395
|
+
function createClientMarketVenueAdapter(client) {
|
|
2396
|
+
return {
|
|
2397
|
+
watchMarketData: (request) => client.watchMarketData(request),
|
|
2398
|
+
getMarketDataQuotes: (markets) => client.getMarketDataQuotes(markets),
|
|
2399
|
+
getMarketDataOrderbooks: (slug, source) => client.getMarketDataOrderbooks(slug, source),
|
|
2400
|
+
getMarketStructure: (path, ifNoneMatch) => client.getMarketStructure(path, ifNoneMatch)
|
|
2401
|
+
};
|
|
2402
|
+
}
|
|
2393
2403
|
var MarketDataContext = createContext(
|
|
2394
2404
|
null
|
|
2395
2405
|
);
|
|
@@ -2400,14 +2410,15 @@ function MarketDataProvider({
|
|
|
2400
2410
|
children
|
|
2401
2411
|
}) {
|
|
2402
2412
|
const store = useMemo(() => new MarketDataStore(), []);
|
|
2413
|
+
const venue = useMemo(() => createClientMarketVenueAdapter(client), [client]);
|
|
2403
2414
|
const runtime = useMemo(
|
|
2404
2415
|
() => new MarketDataRuntime({
|
|
2405
2416
|
enabled: capability.enabled,
|
|
2406
|
-
client,
|
|
2417
|
+
client: venue,
|
|
2407
2418
|
store,
|
|
2408
2419
|
transportFactory
|
|
2409
2420
|
}),
|
|
2410
|
-
[capability.enabled,
|
|
2421
|
+
[capability.enabled, venue, store, transportFactory]
|
|
2411
2422
|
);
|
|
2412
2423
|
useEffect(() => () => runtime.dispose(), [runtime]);
|
|
2413
2424
|
const value = useMemo(
|
|
@@ -4241,7 +4252,7 @@ function useRunPolymarketSetup(walletAddress) {
|
|
|
4241
4252
|
mutationFn: (address) => client.runPolymarketSetup(address),
|
|
4242
4253
|
onSuccess: () => {
|
|
4243
4254
|
if (walletAddress) {
|
|
4244
|
-
queryClient.invalidateQueries({
|
|
4255
|
+
void queryClient.invalidateQueries({
|
|
4245
4256
|
queryKey: polymarketSetupQueryKey(walletAddress)
|
|
4246
4257
|
});
|
|
4247
4258
|
}
|
|
@@ -4255,7 +4266,7 @@ function useDeployPolymarketDepositWallet(walletAddress) {
|
|
|
4255
4266
|
mutationFn: (address) => client.deployPolymarketDepositWallet(address),
|
|
4256
4267
|
onSuccess: () => {
|
|
4257
4268
|
if (walletAddress) {
|
|
4258
|
-
queryClient.invalidateQueries({
|
|
4269
|
+
void queryClient.invalidateQueries({
|
|
4259
4270
|
queryKey: polymarketSetupQueryKey(walletAddress)
|
|
4260
4271
|
});
|
|
4261
4272
|
}
|
|
@@ -4275,8 +4286,8 @@ function useWithdrawSubmitMutation(mutationOptions = {}) {
|
|
|
4275
4286
|
return useMutation({
|
|
4276
4287
|
mutationFn: (body) => client.withdrawSubmit(body),
|
|
4277
4288
|
onSuccess: () => {
|
|
4278
|
-
queryClient.invalidateQueries({ queryKey: ["predict", "balance"] });
|
|
4279
|
-
queryClient.invalidateQueries({ queryKey: ["predict", "positions"] });
|
|
4289
|
+
void queryClient.invalidateQueries({ queryKey: ["predict", "balance"] });
|
|
4290
|
+
void queryClient.invalidateQueries({ queryKey: ["predict", "positions"] });
|
|
4280
4291
|
},
|
|
4281
4292
|
...mutationOptions
|
|
4282
4293
|
});
|
|
@@ -4341,7 +4352,7 @@ function usePolymarketDeposit(mutationOptions = {}) {
|
|
|
4341
4352
|
};
|
|
4342
4353
|
},
|
|
4343
4354
|
onSuccess: () => {
|
|
4344
|
-
queryClient.invalidateQueries({ queryKey: ["predict", "balance"] });
|
|
4355
|
+
void queryClient.invalidateQueries({ queryKey: ["predict", "balance"] });
|
|
4345
4356
|
},
|
|
4346
4357
|
...mutationOptions
|
|
4347
4358
|
});
|
|
@@ -4546,11 +4557,12 @@ function usePricesSubscription({
|
|
|
4546
4557
|
onUpdateRef.current?.(msg);
|
|
4547
4558
|
}, []);
|
|
4548
4559
|
useEffect(() => {
|
|
4549
|
-
|
|
4560
|
+
const slugList = slugsKey.length === 0 ? [] : slugsKey.split(",");
|
|
4561
|
+
if (!wsClient || !enabled || slugList.length === 0) {
|
|
4550
4562
|
setIsSubscribed(false);
|
|
4551
4563
|
return;
|
|
4552
4564
|
}
|
|
4553
|
-
const unsub = wsClient.subscribePrices(
|
|
4565
|
+
const unsub = wsClient.subscribePrices(slugList, handleUpdate);
|
|
4554
4566
|
setIsSubscribed(true);
|
|
4555
4567
|
return () => {
|
|
4556
4568
|
unsub();
|
|
@@ -5120,6 +5132,133 @@ function walkOrderbook({
|
|
|
5120
5132
|
};
|
|
5121
5133
|
}
|
|
5122
5134
|
|
|
5123
|
-
|
|
5135
|
+
// src/utils/order-intent-runtime.ts
|
|
5136
|
+
var PredictionOrderRejectedError = class extends Error {
|
|
5137
|
+
constructor(message = "prediction order rejected") {
|
|
5138
|
+
super(message);
|
|
5139
|
+
this.name = "PredictionOrderRejectedError";
|
|
5140
|
+
}
|
|
5141
|
+
};
|
|
5142
|
+
function createPredictionOrderRuntime(options) {
|
|
5143
|
+
let current = { status: "idle" };
|
|
5144
|
+
const accepted = /* @__PURE__ */ new Set();
|
|
5145
|
+
const confirmTimeoutMs = options.confirmTimeoutMs ?? 3e4;
|
|
5146
|
+
const clock = options.clock ?? { now: () => Date.now() };
|
|
5147
|
+
const set = (next) => {
|
|
5148
|
+
current = next;
|
|
5149
|
+
options.onChange?.(next);
|
|
5150
|
+
return next;
|
|
5151
|
+
};
|
|
5152
|
+
return {
|
|
5153
|
+
snapshot() {
|
|
5154
|
+
return current;
|
|
5155
|
+
},
|
|
5156
|
+
cancel() {
|
|
5157
|
+
if (current.status === "succeeded" || current.status === "confirming" || current.status === "submitting") {
|
|
5158
|
+
return current;
|
|
5159
|
+
}
|
|
5160
|
+
return set({ status: "cancelled", intent: current.intent });
|
|
5161
|
+
},
|
|
5162
|
+
async submit(intent) {
|
|
5163
|
+
if (accepted.has(intent.id)) {
|
|
5164
|
+
return current.status === "idle" ? set({ status: "succeeded", intent, acceptedId: intent.id }) : current;
|
|
5165
|
+
}
|
|
5166
|
+
if (current.intent?.id === intent.id && (current.status === "submitting" || current.status === "confirming" || current.status === "succeeded")) {
|
|
5167
|
+
return current;
|
|
5168
|
+
}
|
|
5169
|
+
set({ status: "validating", intent });
|
|
5170
|
+
if (intent.venue === "kalshi") {
|
|
5171
|
+
const verified = options.kyc ? await options.kyc.verified() : false;
|
|
5172
|
+
if (!verified) {
|
|
5173
|
+
return set({ status: "needs-kyc", intent });
|
|
5174
|
+
}
|
|
5175
|
+
}
|
|
5176
|
+
if (intent.venue === "polymarket") {
|
|
5177
|
+
const verified = options.setup ? await options.setup.verified() : false;
|
|
5178
|
+
if (!verified) {
|
|
5179
|
+
return set({ status: "needs-setup", intent });
|
|
5180
|
+
}
|
|
5181
|
+
}
|
|
5182
|
+
if (!options.signer) {
|
|
5183
|
+
return set({
|
|
5184
|
+
status: "failed",
|
|
5185
|
+
intent,
|
|
5186
|
+
error: new PredictionOrderRejectedError("missing signer")
|
|
5187
|
+
});
|
|
5188
|
+
}
|
|
5189
|
+
set({ status: "signing", intent });
|
|
5190
|
+
let signed;
|
|
5191
|
+
try {
|
|
5192
|
+
signed = await options.signer.sign(intent);
|
|
5193
|
+
} catch (error) {
|
|
5194
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
5195
|
+
return set({ status: "failed", intent, error: err });
|
|
5196
|
+
}
|
|
5197
|
+
set({ status: "submitting", intent });
|
|
5198
|
+
let acceptedId;
|
|
5199
|
+
try {
|
|
5200
|
+
const result = await options.execution.submit(intent, signed);
|
|
5201
|
+
if (!result.accepted) {
|
|
5202
|
+
return set({
|
|
5203
|
+
status: "failed",
|
|
5204
|
+
intent,
|
|
5205
|
+
error: new PredictionOrderRejectedError()
|
|
5206
|
+
});
|
|
5207
|
+
}
|
|
5208
|
+
acceptedId = result.id ?? intent.id;
|
|
5209
|
+
accepted.add(intent.id);
|
|
5210
|
+
accepted.add(acceptedId);
|
|
5211
|
+
} catch (error) {
|
|
5212
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
5213
|
+
return set({ status: "failed", intent, error: err });
|
|
5214
|
+
}
|
|
5215
|
+
set({ status: "confirming", intent, acceptedId });
|
|
5216
|
+
if (!options.confirmation) {
|
|
5217
|
+
return set({ status: "succeeded", intent, acceptedId });
|
|
5218
|
+
}
|
|
5219
|
+
const deadline = clock.now() + confirmTimeoutMs;
|
|
5220
|
+
const outcome = await options.confirmation.wait(acceptedId, {
|
|
5221
|
+
timedOut: () => clock.now() >= deadline
|
|
5222
|
+
});
|
|
5223
|
+
if (outcome === "timed-out") {
|
|
5224
|
+
return set({ status: "timed-out", intent, acceptedId });
|
|
5225
|
+
}
|
|
5226
|
+
return set({ status: "succeeded", intent, acceptedId });
|
|
5227
|
+
}
|
|
5228
|
+
};
|
|
5229
|
+
}
|
|
5230
|
+
|
|
5231
|
+
// src/utils/in-memory-order-ports.ts
|
|
5232
|
+
function createInMemoryOrderPorts(options = {}) {
|
|
5233
|
+
let submits = 0;
|
|
5234
|
+
return {
|
|
5235
|
+
signer: {
|
|
5236
|
+
async sign(intent) {
|
|
5237
|
+
if (options.signError) throw options.signError;
|
|
5238
|
+
return { signed: intent.id };
|
|
5239
|
+
}
|
|
5240
|
+
},
|
|
5241
|
+
execution: {
|
|
5242
|
+
async submit(intent) {
|
|
5243
|
+
submits += 1;
|
|
5244
|
+
return {
|
|
5245
|
+
accepted: options.accept !== false,
|
|
5246
|
+
id: intent.id
|
|
5247
|
+
};
|
|
5248
|
+
}
|
|
5249
|
+
},
|
|
5250
|
+
confirmation: {
|
|
5251
|
+
async wait(_acceptedId, signal) {
|
|
5252
|
+
if (signal.timedOut() || options.confirm === "timed-out") {
|
|
5253
|
+
return "timed-out";
|
|
5254
|
+
}
|
|
5255
|
+
return "confirmed";
|
|
5256
|
+
}
|
|
5257
|
+
},
|
|
5258
|
+
submitCount: () => submits
|
|
5259
|
+
};
|
|
5260
|
+
}
|
|
5261
|
+
|
|
5262
|
+
export { CLOB_AUTH_DOMAIN, CLOB_AUTH_TYPES, CTF_EXCHANGE_ADDRESS, CTF_ORDER_TYPES, ChartRange, MARKET_DATA_BACKEND_CONTRACT_COMMIT, MARKET_DATA_CONTRACT_MANIFEST_SHA256, MARKET_STRUCTURE_MEDIA_TYPE_V1, MarketDataHttpError, MarketDataProvider, MarketDataRuntime, MarketDataStore, MarketDataWatchScheduler, NEG_RISK_CTF_EXCHANGE_ADDRESS, ORDER_TYPE, POLYGON_CHAIN_ID, PolymarketContext, PolymarketProvider, PredictClient, PredictContext, PredictProvider, PredictWsClient, PredictionOrderRejectedError, RecoveryBarrier, SIDE, USDC_ADDRESS, assertMarketDataBBAComponent, assertMarketDataValueComponent, availableSharesQueryKey, balanceQueryKey, buildClobAuthMessage, buildClobPayload, buildCtfExchangeDomain, buildOrderMessage, buildPolymarketL2Headers, buildSignedOrder, buildSignedV2OrderPayload, candlesticksQueryKey, chunkWatchRequest, comparePublicationCursor, createInMemoryOrderPorts, createPredictClient, createPredictWsClient, createPredictionOrderRuntime, decodeBookEnvelope, decodeItemEnvelope, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, esportsMatchesQueryKey, esportsPropsQueryKey, esportsTaxonomyQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEsportsMatches, fetchEsportsProps, fetchEsportsTaxonomy, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, fetchPredictSearch, fetchSportsMatchDetail, fetchSportsMatches, fetchSportsProps, fetchSportsRouting, fetchSportsTaxonomy, getPolymarketSharesPrecision, hmacSha256Base64, infiniteCommentsQueryKey, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, normalizePolymarketTickSize, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, parseInitialQuotes, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, polymarketSupportedAssetsQueryKey, polymarketWithdrawStatusQueryKey, positionValueMultiQueryKey, positionValueQueryKey, positionsMultiQueryKey, positionsQueryKey, predictSearchQueryKey, priceHistoryQueryKey, rebateConfigQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, sportsMatchDetailQueryKey, sportsMatchesQueryKey, sportsPropsQueryKey, sportsRoutingQueryKey, sportsTaxonomyQueryKey, tickSizeQueryKey, tradesQueryKey, updatePolymarketBalanceAllowance, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useDeployPolymarketDepositWallet, useEsportsMatches, useEsportsProps, useEsportsTaxonomy, useEvent, useEventStats, useEvents, useFeeRate, useInfiniteComments, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfinitePredictSearch, useInfiniteTrades, useInfiniteTradesMulti, useMarket, useMarketDataCapability, useMarketDataOrderbooks, useMarketDataResource, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketSupportedAssets, usePolymarketWithdraw, usePolymarketWithdrawPrepareMutation, usePolymarketWithdrawQuoteMutation, usePolymarketWithdrawRelayBuildMutation, usePolymarketWithdrawRelaySubmitMutation, usePolymarketWithdrawStatusQuery, usePositionValue, usePositionValueMulti, usePositions, usePositionsMulti, usePredictClient, usePredictSearch, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRebateConfig, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useSportsMatchDetail, useSportsMatches, useSportsOrderbook, useSportsProps, useSportsRouting, useSportsTaxonomy, useTickSize, useTradeResultConfirmation, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
|
|
5124
5263
|
//# sourceMappingURL=index.mjs.map
|
|
5125
5264
|
//# sourceMappingURL=index.mjs.map
|