@liberfi.io/react-predict 0.1.49 → 0.1.50
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 +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +64 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -15
- package/dist/index.mjs.map +1 -1
- package/dist/{server-rYuNULuJ.d.mts → server-CaB0XJAa.d.mts} +23 -1
- package/dist/{server-rYuNULuJ.d.ts → server-CaB0XJAa.d.ts} +23 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +30 -14
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +30 -14
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -132,6 +132,28 @@ var PredictClient = class {
|
|
|
132
132
|
return await httpGet(url);
|
|
133
133
|
}
|
|
134
134
|
// -------------------------------------------------------------------------
|
|
135
|
+
// Available shares (for sell flow)
|
|
136
|
+
// -------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Get the number of shares available for selling, accounting for active orders.
|
|
139
|
+
*
|
|
140
|
+
* Maps to `GET /api/v1/available-shares?source=...&user=...&market=...&side=...`.
|
|
141
|
+
*
|
|
142
|
+
* @param source - Provider source.
|
|
143
|
+
* @param user - Wallet address.
|
|
144
|
+
* @param market - Market slug.
|
|
145
|
+
* @param side - Position side ("yes" or "no").
|
|
146
|
+
* @param headers - Optional extra headers (e.g. Polymarket POLY_* HMAC headers).
|
|
147
|
+
*/
|
|
148
|
+
async getAvailableShares(source, user, market, side, headers) {
|
|
149
|
+
const query = buildQuery({ source, user, market, side });
|
|
150
|
+
const url = `${this.endpoint}/api/v1/available-shares${query}`;
|
|
151
|
+
return await httpGet(
|
|
152
|
+
url,
|
|
153
|
+
headers ? { headers } : void 0
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
// -------------------------------------------------------------------------
|
|
135
157
|
// Balance
|
|
136
158
|
// -------------------------------------------------------------------------
|
|
137
159
|
/**
|
|
@@ -1223,6 +1245,7 @@ function usePositions(params, queryOptions = {}) {
|
|
|
1223
1245
|
queryFn: () => client.getPositions(params.user, params.source),
|
|
1224
1246
|
enabled: Boolean(params.user),
|
|
1225
1247
|
staleTime: 1e4,
|
|
1248
|
+
refetchInterval: 3e4,
|
|
1226
1249
|
...queryOptions
|
|
1227
1250
|
});
|
|
1228
1251
|
}
|
|
@@ -1234,6 +1257,37 @@ function usePositionsMulti(params, queryOptions = {}) {
|
|
|
1234
1257
|
queryFn: () => client.getPositions(params),
|
|
1235
1258
|
enabled: hasAnyWallet,
|
|
1236
1259
|
staleTime: 1e4,
|
|
1260
|
+
refetchInterval: 3e4,
|
|
1261
|
+
...queryOptions
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function availableSharesQueryKey(params) {
|
|
1265
|
+
return [
|
|
1266
|
+
"predict",
|
|
1267
|
+
"available-shares",
|
|
1268
|
+
params.source,
|
|
1269
|
+
params.user,
|
|
1270
|
+
params.market,
|
|
1271
|
+
params.side
|
|
1272
|
+
];
|
|
1273
|
+
}
|
|
1274
|
+
function useAvailableShares(params, options, queryOptions = {}) {
|
|
1275
|
+
const client = usePredictClient();
|
|
1276
|
+
return useQuery({
|
|
1277
|
+
queryKey: availableSharesQueryKey(params),
|
|
1278
|
+
queryFn: async () => {
|
|
1279
|
+
const headers = await options?.getHeaders?.();
|
|
1280
|
+
return client.getAvailableShares(
|
|
1281
|
+
params.source,
|
|
1282
|
+
params.user,
|
|
1283
|
+
params.market,
|
|
1284
|
+
params.side,
|
|
1285
|
+
headers
|
|
1286
|
+
);
|
|
1287
|
+
},
|
|
1288
|
+
enabled: Boolean(params.user && params.market && params.side),
|
|
1289
|
+
staleTime: 5e3,
|
|
1290
|
+
refetchInterval: 1e4,
|
|
1237
1291
|
...queryOptions
|
|
1238
1292
|
});
|
|
1239
1293
|
}
|
|
@@ -1881,17 +1935,13 @@ var DEFAULT_ROUNDING = { size: 2, price: 2, amount: 4 };
|
|
|
1881
1935
|
function decimalPlaces(n, d) {
|
|
1882
1936
|
return parseFloat(n.toFixed(d));
|
|
1883
1937
|
}
|
|
1938
|
+
function floorDecimalPlaces(n, d) {
|
|
1939
|
+
const factor = 10 ** d;
|
|
1940
|
+
return Math.floor(n * factor) / factor;
|
|
1941
|
+
}
|
|
1884
1942
|
function toMicroUsdc(amount) {
|
|
1885
1943
|
return BigInt(Math.round(amount * 1e6));
|
|
1886
1944
|
}
|
|
1887
|
-
function ceilMicro(raw, maxDecimals) {
|
|
1888
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1889
|
-
return (raw + factor - 1n) / factor * factor;
|
|
1890
|
-
}
|
|
1891
|
-
function floorMicro(raw, maxDecimals) {
|
|
1892
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1893
|
-
return raw / factor * factor;
|
|
1894
|
-
}
|
|
1895
1945
|
function normalizeTokenId(tokenId) {
|
|
1896
1946
|
if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
|
|
1897
1947
|
return BigInt(tokenId).toString(10);
|
|
@@ -1902,14 +1952,12 @@ function buildOrderMessage(input) {
|
|
|
1902
1952
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
1903
1953
|
const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
|
|
1904
1954
|
const rawPrice = decimalPlaces(input.price, rc.price);
|
|
1905
|
-
const rawSize = decimalPlaces(input.size, rc.size);
|
|
1906
|
-
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1955
|
+
const rawSize = side === SIDE.SELL ? floorDecimalPlaces(input.size, rc.size) : decimalPlaces(input.size, rc.size);
|
|
1907
1956
|
const sizeInMicro = toMicroUsdc(rawSize);
|
|
1957
|
+
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1908
1958
|
const amountInMicro = toMicroUsdc(rawAmount);
|
|
1909
|
-
const
|
|
1910
|
-
const
|
|
1911
|
-
const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
|
|
1912
|
-
const takerAmount = side === SIDE.BUY ? sharesMicro.toString() : usdcMicro.toString();
|
|
1959
|
+
const makerAmount = side === SIDE.BUY ? amountInMicro.toString() : sizeInMicro.toString();
|
|
1960
|
+
const takerAmount = side === SIDE.BUY ? sizeInMicro.toString() : amountInMicro.toString();
|
|
1913
1961
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
1914
1962
|
return {
|
|
1915
1963
|
salt: Math.floor(Math.random() * 1e15).toString(),
|
|
@@ -2040,6 +2088,6 @@ async function pollTxConfirmed(fetchStatus, txHash) {
|
|
|
2040
2088
|
);
|
|
2041
2089
|
}
|
|
2042
2090
|
|
|
2043
|
-
export { CLOB_AUTH_DOMAIN, CLOB_AUTH_TYPES, CTF_EXCHANGE_ADDRESS, CTF_ORDER_TYPES, ChartRange, NEG_RISK_CTF_EXCHANGE_ADDRESS, ORDER_TYPE, POLYGON_CHAIN_ID, PolymarketContext, PolymarketProvider, PredictClient, PredictContext, PredictProvider, PredictWsClient, SIDE, USDC_ADDRESS, balanceQueryKey, buildClobAuthMessage, buildClobPayload, buildCtfExchangeDomain, buildOrderMessage, buildPolymarketL2Headers, buildSignedOrder, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, hmacSha256Base64, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersQueryKey, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, useEventStats, useEvents, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, withdrawStatusQueryKey };
|
|
2091
|
+
export { CLOB_AUTH_DOMAIN, CLOB_AUTH_TYPES, CTF_EXCHANGE_ADDRESS, CTF_ORDER_TYPES, ChartRange, NEG_RISK_CTF_EXCHANGE_ADDRESS, ORDER_TYPE, POLYGON_CHAIN_ID, PolymarketContext, PolymarketProvider, PredictClient, PredictContext, PredictProvider, PredictWsClient, SIDE, USDC_ADDRESS, availableSharesQueryKey, balanceQueryKey, buildClobAuthMessage, buildClobPayload, buildCtfExchangeDomain, buildOrderMessage, buildPolymarketL2Headers, buildSignedOrder, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, hmacSha256Base64, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersQueryKey, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, useEventStats, useEvents, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, withdrawStatusQueryKey };
|
|
2044
2092
|
//# sourceMappingURL=index.mjs.map
|
|
2045
2093
|
//# sourceMappingURL=index.mjs.map
|