@liberfi.io/react-predict 0.1.48 → 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 +68 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -17
- package/dist/index.mjs.map +1 -1
- package/dist/{server-Curi-jN1.d.mts → server-CaB0XJAa.d.mts} +33 -1
- package/dist/{server-Curi-jN1.d.ts → server-CaB0XJAa.d.ts} +33 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +34 -16
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +34 -16
- 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
|
/**
|
|
@@ -946,7 +968,8 @@ function resolveEventsParams(input = {}) {
|
|
|
946
968
|
sort_asc,
|
|
947
969
|
minVolume,
|
|
948
970
|
minLiquidity,
|
|
949
|
-
timeRemaining
|
|
971
|
+
timeRemaining,
|
|
972
|
+
markets_limit = 3
|
|
950
973
|
} = input;
|
|
951
974
|
const tag_slug = resolveTagSlug(tagSlugSelection);
|
|
952
975
|
const min_volume = minVolume !== void 0 && minVolume !== "" ? Number(minVolume) : void 0;
|
|
@@ -962,7 +985,8 @@ function resolveEventsParams(input = {}) {
|
|
|
962
985
|
...sort_asc !== void 0 ? { sort_asc } : {},
|
|
963
986
|
...min_volume !== void 0 && !isNaN(min_volume) ? { min_volume } : {},
|
|
964
987
|
...min_liquidity !== void 0 && !isNaN(min_liquidity) ? { min_liquidity } : {},
|
|
965
|
-
...end_before ? { end_before } : {}
|
|
988
|
+
...end_before ? { end_before } : {},
|
|
989
|
+
...markets_limit ? { markets_limit } : {}
|
|
966
990
|
};
|
|
967
991
|
}
|
|
968
992
|
function infiniteEventsQueryKey(params) {
|
|
@@ -1221,6 +1245,7 @@ function usePositions(params, queryOptions = {}) {
|
|
|
1221
1245
|
queryFn: () => client.getPositions(params.user, params.source),
|
|
1222
1246
|
enabled: Boolean(params.user),
|
|
1223
1247
|
staleTime: 1e4,
|
|
1248
|
+
refetchInterval: 3e4,
|
|
1224
1249
|
...queryOptions
|
|
1225
1250
|
});
|
|
1226
1251
|
}
|
|
@@ -1232,6 +1257,37 @@ function usePositionsMulti(params, queryOptions = {}) {
|
|
|
1232
1257
|
queryFn: () => client.getPositions(params),
|
|
1233
1258
|
enabled: hasAnyWallet,
|
|
1234
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,
|
|
1235
1291
|
...queryOptions
|
|
1236
1292
|
});
|
|
1237
1293
|
}
|
|
@@ -1879,17 +1935,13 @@ var DEFAULT_ROUNDING = { size: 2, price: 2, amount: 4 };
|
|
|
1879
1935
|
function decimalPlaces(n, d) {
|
|
1880
1936
|
return parseFloat(n.toFixed(d));
|
|
1881
1937
|
}
|
|
1938
|
+
function floorDecimalPlaces(n, d) {
|
|
1939
|
+
const factor = 10 ** d;
|
|
1940
|
+
return Math.floor(n * factor) / factor;
|
|
1941
|
+
}
|
|
1882
1942
|
function toMicroUsdc(amount) {
|
|
1883
1943
|
return BigInt(Math.round(amount * 1e6));
|
|
1884
1944
|
}
|
|
1885
|
-
function ceilMicro(raw, maxDecimals) {
|
|
1886
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1887
|
-
return (raw + factor - 1n) / factor * factor;
|
|
1888
|
-
}
|
|
1889
|
-
function floorMicro(raw, maxDecimals) {
|
|
1890
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1891
|
-
return raw / factor * factor;
|
|
1892
|
-
}
|
|
1893
1945
|
function normalizeTokenId(tokenId) {
|
|
1894
1946
|
if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
|
|
1895
1947
|
return BigInt(tokenId).toString(10);
|
|
@@ -1900,14 +1952,12 @@ function buildOrderMessage(input) {
|
|
|
1900
1952
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
1901
1953
|
const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
|
|
1902
1954
|
const rawPrice = decimalPlaces(input.price, rc.price);
|
|
1903
|
-
const rawSize = decimalPlaces(input.size, rc.size);
|
|
1904
|
-
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1955
|
+
const rawSize = side === SIDE.SELL ? floorDecimalPlaces(input.size, rc.size) : decimalPlaces(input.size, rc.size);
|
|
1905
1956
|
const sizeInMicro = toMicroUsdc(rawSize);
|
|
1957
|
+
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1906
1958
|
const amountInMicro = toMicroUsdc(rawAmount);
|
|
1907
|
-
const
|
|
1908
|
-
const
|
|
1909
|
-
const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
|
|
1910
|
-
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();
|
|
1911
1961
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
1912
1962
|
return {
|
|
1913
1963
|
salt: Math.floor(Math.random() * 1e15).toString(),
|
|
@@ -2038,6 +2088,6 @@ async function pollTxConfirmed(fetchStatus, txHash) {
|
|
|
2038
2088
|
);
|
|
2039
2089
|
}
|
|
2040
2090
|
|
|
2041
|
-
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 };
|
|
2042
2092
|
//# sourceMappingURL=index.mjs.map
|
|
2043
2093
|
//# sourceMappingURL=index.mjs.map
|