@liberfi.io/react-predict 0.1.37 → 0.1.38
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 +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -19
- package/dist/index.mjs.map +1 -1
- package/dist/{server-BOEaPGc-.d.mts → server-CYqs2N2z.d.mts} +13 -1
- package/dist/{server-BOEaPGc-.d.ts → server-CYqs2N2z.d.ts} +13 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +21 -18
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +21 -18
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -203,6 +203,11 @@ var PredictClient = class {
|
|
|
203
203
|
const url = `${this.endpoint}/api/v1/orders/polymarket`;
|
|
204
204
|
return await httpPost(url, input, { headers });
|
|
205
205
|
}
|
|
206
|
+
/** Maps to `GET /api/v1/polymarket/tick-size?token_id=xxx`. */
|
|
207
|
+
async getPolymarketTickSize(tokenId) {
|
|
208
|
+
const url = `${this.endpoint}/api/v1/polymarket/tick-size?token_id=${encodeURIComponent(tokenId)}`;
|
|
209
|
+
return await httpGet(url);
|
|
210
|
+
}
|
|
206
211
|
// -------------------------------------------------------------------------
|
|
207
212
|
// DFlow trading
|
|
208
213
|
// -------------------------------------------------------------------------
|
|
@@ -1548,6 +1553,19 @@ function usePolymarketWithdraw() {
|
|
|
1548
1553
|
mutationFn: (req) => client.executePolymarketWithdraw(req)
|
|
1549
1554
|
});
|
|
1550
1555
|
}
|
|
1556
|
+
function tickSizeQueryKey(tokenId) {
|
|
1557
|
+
return ["predict", "polymarket", "tick-size", tokenId];
|
|
1558
|
+
}
|
|
1559
|
+
function useTickSize(tokenId, queryOptions = {}) {
|
|
1560
|
+
const client = usePredictClient();
|
|
1561
|
+
return useQuery({
|
|
1562
|
+
queryKey: tickSizeQueryKey(tokenId ?? ""),
|
|
1563
|
+
queryFn: () => client.getPolymarketTickSize(tokenId),
|
|
1564
|
+
enabled: !!tokenId,
|
|
1565
|
+
staleTime: 5 * 6e4,
|
|
1566
|
+
...queryOptions
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1551
1569
|
function usePredictWsClient() {
|
|
1552
1570
|
const context = useContext(PredictContext);
|
|
1553
1571
|
if (!context) {
|
|
@@ -1829,23 +1847,19 @@ var ORDER_TYPE = {
|
|
|
1829
1847
|
// Fill-And-Kill
|
|
1830
1848
|
};
|
|
1831
1849
|
var SIDE = { BUY: 0, SELL: 1 };
|
|
1832
|
-
var
|
|
1833
|
-
"0.1": 1,
|
|
1834
|
-
"0.01": 2,
|
|
1835
|
-
"0.001": 3,
|
|
1836
|
-
"0.0001": 4
|
|
1850
|
+
var ROUNDING_CONFIG = {
|
|
1851
|
+
"0.1": { size: 2, price: 1, amount: 3 },
|
|
1852
|
+
"0.01": { size: 2, price: 2, amount: 4 },
|
|
1853
|
+
"0.001": { size: 3, price: 3, amount: 6 },
|
|
1854
|
+
"0.0001": { size: 4, price: 4, amount: 8 }
|
|
1837
1855
|
};
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
return
|
|
1856
|
+
var DEFAULT_ROUNDING = { size: 2, price: 2, amount: 4 };
|
|
1857
|
+
function decimalPlaces(n, d) {
|
|
1858
|
+
return parseFloat(n.toFixed(d));
|
|
1841
1859
|
}
|
|
1842
1860
|
function toMicroUsdc(amount) {
|
|
1843
1861
|
return BigInt(Math.round(amount * 1e6));
|
|
1844
1862
|
}
|
|
1845
|
-
function truncateToDecimals(raw, maxDecimals) {
|
|
1846
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1847
|
-
return raw / factor * factor;
|
|
1848
|
-
}
|
|
1849
1863
|
function normalizeTokenId(tokenId) {
|
|
1850
1864
|
if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
|
|
1851
1865
|
return BigInt(tokenId).toString(10);
|
|
@@ -1854,12 +1868,14 @@ function normalizeTokenId(tokenId) {
|
|
|
1854
1868
|
}
|
|
1855
1869
|
function buildOrderMessage(input) {
|
|
1856
1870
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
1857
|
-
const
|
|
1858
|
-
const
|
|
1859
|
-
const
|
|
1860
|
-
const
|
|
1861
|
-
const
|
|
1862
|
-
const
|
|
1871
|
+
const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
|
|
1872
|
+
const rawPrice = decimalPlaces(input.price, rc.price);
|
|
1873
|
+
const rawSize = decimalPlaces(input.size, rc.size);
|
|
1874
|
+
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1875
|
+
const sizeInMicro = toMicroUsdc(rawSize);
|
|
1876
|
+
const amountInMicro = toMicroUsdc(rawAmount);
|
|
1877
|
+
const makerAmount = side === SIDE.BUY ? amountInMicro.toString() : sizeInMicro.toString();
|
|
1878
|
+
const takerAmount = side === SIDE.BUY ? sizeInMicro.toString() : amountInMicro.toString();
|
|
1863
1879
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
1864
1880
|
return {
|
|
1865
1881
|
salt: Math.floor(Math.random() * 1e15).toString(),
|
|
@@ -1990,6 +2006,6 @@ async function pollTxConfirmed(fetchStatus, txHash) {
|
|
|
1990
2006
|
);
|
|
1991
2007
|
}
|
|
1992
2008
|
|
|
1993
|
-
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, 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, tradesQueryKey, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, 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, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, withdrawStatusQueryKey };
|
|
2009
|
+
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, 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, 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 };
|
|
1994
2010
|
//# sourceMappingURL=index.mjs.map
|
|
1995
2011
|
//# sourceMappingURL=index.mjs.map
|