@liberfi.io/react-predict 0.1.37 → 0.1.39
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 +39 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -16
- 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 +24 -15
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +24 -15
- 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,20 +1847,20 @@ 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
|
|
1863
|
+
function truncateMicro(raw, maxDecimals) {
|
|
1846
1864
|
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1847
1865
|
return raw / factor * factor;
|
|
1848
1866
|
}
|
|
@@ -1854,12 +1872,16 @@ function normalizeTokenId(tokenId) {
|
|
|
1854
1872
|
}
|
|
1855
1873
|
function buildOrderMessage(input) {
|
|
1856
1874
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
1857
|
-
const
|
|
1858
|
-
const
|
|
1859
|
-
const
|
|
1860
|
-
const
|
|
1861
|
-
const
|
|
1862
|
-
const
|
|
1875
|
+
const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
|
|
1876
|
+
const rawPrice = decimalPlaces(input.price, rc.price);
|
|
1877
|
+
const rawSize = decimalPlaces(input.size, rc.size);
|
|
1878
|
+
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1879
|
+
const sizeInMicro = toMicroUsdc(rawSize);
|
|
1880
|
+
const amountInMicro = toMicroUsdc(rawAmount);
|
|
1881
|
+
const usdcMicro = truncateMicro(amountInMicro, 2);
|
|
1882
|
+
const sharesMicro = truncateMicro(sizeInMicro, 4);
|
|
1883
|
+
const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
|
|
1884
|
+
const takerAmount = side === SIDE.BUY ? sharesMicro.toString() : usdcMicro.toString();
|
|
1863
1885
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
1864
1886
|
return {
|
|
1865
1887
|
salt: Math.floor(Math.random() * 1e15).toString(),
|
|
@@ -1990,6 +2012,6 @@ async function pollTxConfirmed(fetchStatus, txHash) {
|
|
|
1990
2012
|
);
|
|
1991
2013
|
}
|
|
1992
2014
|
|
|
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 };
|
|
2015
|
+
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
2016
|
//# sourceMappingURL=index.mjs.map
|
|
1995
2017
|
//# sourceMappingURL=index.mjs.map
|