@liberfi.io/react-predict 0.3.32 → 0.3.34
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 +79 -4
- package/dist/index.d.ts +79 -4
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{server-FZwoxwxh.d.mts → server-DfzGla54.d.mts} +64 -2
- package/dist/{server-FZwoxwxh.d.ts → server-DfzGla54.d.ts} +64 -2
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +24 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +24 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { httpGet, httpDelete, httpPost } from '@liberfi.io/utils';
|
|
|
2
2
|
import { createContext, useMemo, useState, useRef, useCallback, useContext, useEffect } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { useQuery, useInfiniteQuery, useQueries, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
5
|
+
import { OrderBuilder, SignatureTypeV2, Side, OrderType, orderToJsonV2, ClobClient } from '@polymarket/clob-client-v2';
|
|
5
6
|
|
|
6
7
|
// src/client/client.ts
|
|
7
8
|
function buildQuery(params) {
|
|
@@ -279,6 +280,15 @@ var PredictClient = class {
|
|
|
279
280
|
const url = `${this.endpoint}/api/v1/polymarket/fee-rate?token_id=${encodeURIComponent(tokenId)}`;
|
|
280
281
|
return await httpGet(url);
|
|
281
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Builder-attribution / rebate config. Maps to `GET /api/v1/referral/config`.
|
|
285
|
+
* The front-end uses `builder_code` (when `builder_enabled`) to attribute
|
|
286
|
+
* CLOB V2 orders to our builder program.
|
|
287
|
+
*/
|
|
288
|
+
async getRebateConfig() {
|
|
289
|
+
const url = `${this.endpoint}/api/v1/referral/config`;
|
|
290
|
+
return await httpGet(url);
|
|
291
|
+
}
|
|
282
292
|
// -------------------------------------------------------------------------
|
|
283
293
|
// DFlow trading
|
|
284
294
|
// -------------------------------------------------------------------------
|
|
@@ -329,6 +339,21 @@ var PredictClient = class {
|
|
|
329
339
|
wallet_address: walletAddress
|
|
330
340
|
});
|
|
331
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Deploy a Polymarket CLOB V2 deposit wallet (gasless WALLET-CREATE).
|
|
344
|
+
*
|
|
345
|
+
* No user signature is required — the relayer deploys the per-user
|
|
346
|
+
* ERC-1967 proxy and the server waits until it is confirmed on-chain.
|
|
347
|
+
* Used for new (non-Safe) users on the POLY_1271 path.
|
|
348
|
+
*
|
|
349
|
+
* Maps to `POST /api/v1/setup/polymarket/deposit/deploy`.
|
|
350
|
+
*/
|
|
351
|
+
async deployPolymarketDepositWallet(walletAddress) {
|
|
352
|
+
const url = `${this.endpoint}/api/v1/setup/polymarket/deposit/deploy`;
|
|
353
|
+
return await httpPost(url, {
|
|
354
|
+
wallet_address: walletAddress
|
|
355
|
+
});
|
|
356
|
+
}
|
|
332
357
|
// -------------------------------------------------------------------------
|
|
333
358
|
// Cross-platform matches
|
|
334
359
|
// -------------------------------------------------------------------------
|
|
@@ -1666,6 +1691,20 @@ function useRunPolymarketSetup(walletAddress) {
|
|
|
1666
1691
|
}
|
|
1667
1692
|
});
|
|
1668
1693
|
}
|
|
1694
|
+
function useDeployPolymarketDepositWallet(walletAddress) {
|
|
1695
|
+
const client = usePredictClient();
|
|
1696
|
+
const queryClient = useQueryClient();
|
|
1697
|
+
return useMutation({
|
|
1698
|
+
mutationFn: (address) => client.deployPolymarketDepositWallet(address),
|
|
1699
|
+
onSuccess: () => {
|
|
1700
|
+
if (walletAddress) {
|
|
1701
|
+
queryClient.invalidateQueries({
|
|
1702
|
+
queryKey: polymarketSetupQueryKey(walletAddress)
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1669
1708
|
function useWithdrawBuildMutation(mutationOptions = {}) {
|
|
1670
1709
|
const client = usePredictClient();
|
|
1671
1710
|
return useMutation({
|
|
@@ -1848,6 +1887,18 @@ function useFeeRate(tokenId, queryOptions = {}) {
|
|
|
1848
1887
|
...queryOptions
|
|
1849
1888
|
});
|
|
1850
1889
|
}
|
|
1890
|
+
function rebateConfigQueryKey() {
|
|
1891
|
+
return ["predict", "referral", "config"];
|
|
1892
|
+
}
|
|
1893
|
+
function useRebateConfig(queryOptions = {}) {
|
|
1894
|
+
const client = usePredictClient();
|
|
1895
|
+
return useQuery({
|
|
1896
|
+
queryKey: rebateConfigQueryKey(),
|
|
1897
|
+
queryFn: () => client.getRebateConfig(),
|
|
1898
|
+
staleTime: 10 * 6e4,
|
|
1899
|
+
...queryOptions
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1851
1902
|
function usePredictWsClient() {
|
|
1852
1903
|
const context = useContext(PredictContext);
|
|
1853
1904
|
if (!context) {
|
|
@@ -2244,6 +2295,82 @@ function getPolymarketSharesPrecision(tickSize) {
|
|
|
2244
2295
|
const rc = ROUNDING_CONFIG[tickSize] ?? DEFAULT_ROUNDING;
|
|
2245
2296
|
return rc.size;
|
|
2246
2297
|
}
|
|
2298
|
+
var POLYGON_CHAIN_ID2 = 137;
|
|
2299
|
+
var ORDER_VERSION = 2;
|
|
2300
|
+
function toWalletClientLike(signer) {
|
|
2301
|
+
return {
|
|
2302
|
+
account: { address: signer.address },
|
|
2303
|
+
getAddresses: async () => [signer.address],
|
|
2304
|
+
signTypedData: async (args) => signer.signTypedData(
|
|
2305
|
+
args.domain,
|
|
2306
|
+
args.types,
|
|
2307
|
+
args.primaryType,
|
|
2308
|
+
args.message
|
|
2309
|
+
)
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
async function buildSignedV2OrderPayload(params) {
|
|
2313
|
+
const { signer, depositWalletAddress, input, owner } = params;
|
|
2314
|
+
const builder = new OrderBuilder(
|
|
2315
|
+
toWalletClientLike(signer),
|
|
2316
|
+
POLYGON_CHAIN_ID2,
|
|
2317
|
+
SignatureTypeV2.POLY_1271,
|
|
2318
|
+
depositWalletAddress
|
|
2319
|
+
);
|
|
2320
|
+
const side = input.side === "BUY" ? Side.BUY : Side.SELL;
|
|
2321
|
+
const options = { tickSize: input.tickSize, negRisk: input.negRisk ?? false };
|
|
2322
|
+
const isMarketOrder = input.orderType === "FOK" || input.orderType === "FAK";
|
|
2323
|
+
const builderCode = input.builderCode;
|
|
2324
|
+
const signedOrder = isMarketOrder ? await builder.buildMarketOrder(
|
|
2325
|
+
{
|
|
2326
|
+
tokenID: input.tokenId,
|
|
2327
|
+
price: input.price,
|
|
2328
|
+
// Market order: BUY = collateral to spend, SELL = shares to sell.
|
|
2329
|
+
amount: input.size,
|
|
2330
|
+
side,
|
|
2331
|
+
...builderCode && { builderCode }
|
|
2332
|
+
},
|
|
2333
|
+
options,
|
|
2334
|
+
ORDER_VERSION
|
|
2335
|
+
) : await builder.buildOrder(
|
|
2336
|
+
{
|
|
2337
|
+
tokenID: input.tokenId,
|
|
2338
|
+
price: input.price,
|
|
2339
|
+
// Limit order: size is always shares.
|
|
2340
|
+
size: input.size,
|
|
2341
|
+
side,
|
|
2342
|
+
expiration: input.expiration,
|
|
2343
|
+
...builderCode && { builderCode }
|
|
2344
|
+
},
|
|
2345
|
+
options,
|
|
2346
|
+
ORDER_VERSION
|
|
2347
|
+
);
|
|
2348
|
+
const orderType = OrderType[input.orderType ?? "GTC"];
|
|
2349
|
+
return orderToJsonV2(
|
|
2350
|
+
signedOrder,
|
|
2351
|
+
owner,
|
|
2352
|
+
orderType
|
|
2353
|
+
);
|
|
2354
|
+
}
|
|
2355
|
+
var DEFAULT_CLOB_HOST = "https://clob.polymarket.com";
|
|
2356
|
+
async function updatePolymarketBalanceAllowance(params) {
|
|
2357
|
+
const { signer, credentials, depositWalletAddress, clobHost } = params;
|
|
2358
|
+
const client = new ClobClient({
|
|
2359
|
+
host: clobHost ?? DEFAULT_CLOB_HOST,
|
|
2360
|
+
chain: POLYGON_CHAIN_ID2,
|
|
2361
|
+
signer: toWalletClientLike(signer),
|
|
2362
|
+
creds: {
|
|
2363
|
+
key: credentials.apiKey,
|
|
2364
|
+
secret: credentials.secret,
|
|
2365
|
+
passphrase: credentials.passphrase
|
|
2366
|
+
},
|
|
2367
|
+
signatureType: SignatureTypeV2.POLY_1271,
|
|
2368
|
+
funderAddress: depositWalletAddress
|
|
2369
|
+
});
|
|
2370
|
+
await client.updateBalanceAllowance({
|
|
2371
|
+
asset_type: "COLLATERAL"
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2247
2374
|
|
|
2248
2375
|
// src/hooks/polymarket/useCreatePolymarketOrder.ts
|
|
2249
2376
|
var TX_POLL_INTERVAL2 = 3e3;
|
|
@@ -2258,6 +2385,28 @@ function useCreatePolymarketOrder(mutationOptions = {}) {
|
|
|
2258
2385
|
signer
|
|
2259
2386
|
}) => {
|
|
2260
2387
|
const creds = credentials ?? await authenticate(signer);
|
|
2388
|
+
if (signer.signatureType === 3) {
|
|
2389
|
+
const depositWalletAddress = input.funderAddress ?? signer.address;
|
|
2390
|
+
const v2Payload = await buildSignedV2OrderPayload({
|
|
2391
|
+
signer,
|
|
2392
|
+
depositWalletAddress,
|
|
2393
|
+
input,
|
|
2394
|
+
owner: creds.apiKey
|
|
2395
|
+
});
|
|
2396
|
+
const body2 = JSON.stringify(v2Payload);
|
|
2397
|
+
const headers2 = await buildPolymarketL2Headers(creds.address, {
|
|
2398
|
+
apiKey: creds.apiKey,
|
|
2399
|
+
secret: creds.secret,
|
|
2400
|
+
passphrase: creds.passphrase,
|
|
2401
|
+
method: "POST",
|
|
2402
|
+
requestPath: "/order",
|
|
2403
|
+
body: body2
|
|
2404
|
+
});
|
|
2405
|
+
return client.createPolymarketOrder(
|
|
2406
|
+
v2Payload,
|
|
2407
|
+
headers2
|
|
2408
|
+
);
|
|
2409
|
+
}
|
|
2261
2410
|
if (signer.signTransaction && input.funderAddress) {
|
|
2262
2411
|
const orderCost = computeOrderCost(input);
|
|
2263
2412
|
const buildResult = await client.depositBuild({
|
|
@@ -2444,6 +2593,6 @@ function walkOrderbook({
|
|
|
2444
2593
|
};
|
|
2445
2594
|
}
|
|
2446
2595
|
|
|
2447
|
-
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, feeRateQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, getPolymarketSharesPrecision, hmacSha256Base64, infiniteCommentsQueryKey, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, polymarketSupportedAssetsQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, useEventStats, useEvents, useFeeRate, useInfiniteComments, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useInfiniteTradesMulti, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketSupportedAssets, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
|
|
2596
|
+
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, buildSignedV2OrderPayload, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, getPolymarketSharesPrecision, hmacSha256Base64, infiniteCommentsQueryKey, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, polymarketSupportedAssetsQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, rebateConfigQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, updatePolymarketBalanceAllowance, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useDeployPolymarketDepositWallet, useEvent, useEventStats, useEvents, useFeeRate, useInfiniteComments, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useInfiniteTradesMulti, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketSupportedAssets, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRebateConfig, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
|
|
2448
2597
|
//# sourceMappingURL=index.mjs.map
|
|
2449
2598
|
//# sourceMappingURL=index.mjs.map
|