@liberfi.io/react-predict 0.1.52 → 0.1.53

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.
@@ -597,13 +597,26 @@ interface DFlowSubmitResponse {
597
597
  }
598
598
  /** Order type for Polymarket CLOB. */
599
599
  type PolymarketOrderType = "GTC" | "FOK" | "GTD" | "FAK";
600
- /** Input for creating a Polymarket limit order. */
600
+ /**
601
+ * Input for creating a Polymarket order (limit or market).
602
+ * @see https://docs.polymarket.com/trading/orders/create
603
+ */
601
604
  interface CreateOrderInput {
602
605
  /** Token ID (outcome asset ID) from market provider_meta. */
603
606
  tokenId: string;
604
607
  /** Price in range [0.01, 0.99]. */
605
608
  price: number;
606
- /** Order size in USDC. */
609
+ /**
610
+ * Order size — meaning depends on order type:
611
+ * - **Market BUY (FOK/FAK)**: USDC dollar amount to spend.
612
+ * - **Market SELL (FOK/FAK)**: Number of shares to sell.
613
+ * - **Limit BUY/SELL (GTC/GTD)**: Number of shares.
614
+ *
615
+ * This matches the official Polymarket SDK where `createMarketOrder` takes
616
+ * `amount` (USDC for buy, shares for sell), while `createOrder` (limit)
617
+ * takes `size` (always shares).
618
+ * @see https://docs.polymarket.com/trading/orders/create#market-orders
619
+ */
607
620
  size: number;
608
621
  side: OrderSide;
609
622
  orderType?: PolymarketOrderType;
@@ -1329,9 +1342,22 @@ declare function derivePolymarketApiKey(address: string, signature: string, time
1329
1342
  * Neg-Risk CTF Exchange contracts (Polygon mainnet).
1330
1343
  *
1331
1344
  * References:
1332
- * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/builder.ts
1333
- * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/helpers.ts
1334
- * https://docs.polymarket.com/#create-order
1345
+ * - Official docs (order creation):
1346
+ * https://docs.polymarket.com/trading/orders/create
1347
+ * - Official TS CLOB client (order builder / helpers):
1348
+ * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/builder.ts
1349
+ * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/helpers.ts
1350
+ * - Official Python CLOB client (order builder — has `get_market_order_amounts`):
1351
+ * https://github.com/Polymarket/py-clob-client/blob/main/py_clob_client/order_builder/builder.py
1352
+ *
1353
+ * Market order (FOK/FAK) precision limits — NOT documented in official docs,
1354
+ * enforced server-side and discovered via API error messages:
1355
+ * - makerAmount: max 2 decimal places (human-readable)
1356
+ * - takerAmount: max 4 decimal places (human-readable)
1357
+ * - GitHub issues tracking this undocumented constraint:
1358
+ * https://github.com/Polymarket/py-clob-client/issues/121
1359
+ * https://github.com/Polymarket/py-clob-client/issues/253
1360
+ * https://github.com/Polymarket/rs-clob-client/issues/261
1335
1361
  */
1336
1362
 
1337
1363
  /** Polymarket CTF Exchange contract (standard markets). */
@@ -1413,36 +1439,55 @@ interface BuildOrderMessageInput extends CreateOrderInput {
1413
1439
  }
1414
1440
  interface OrderMessage {
1415
1441
  salt: string;
1442
+ /** Funder address that holds the collateral (USDC.e or outcome tokens). */
1416
1443
  maker: string;
1444
+ /** Signer address that signs the EIP-712 order. */
1417
1445
  signer: string;
1446
+ /** Taker address (0x0 = any counterparty). */
1418
1447
  taker: string;
1419
1448
  tokenId: string;
1449
+ /**
1450
+ * Amount the maker provides (micro-USDC, 6 decimals).
1451
+ * BUY: USDC spent. SELL: shares sold.
1452
+ */
1420
1453
  makerAmount: string;
1454
+ /**
1455
+ * Amount the taker provides (micro-USDC, 6 decimals).
1456
+ * BUY: shares received. SELL: USDC received.
1457
+ */
1421
1458
  takerAmount: string;
1422
1459
  expiration: string;
1423
1460
  nonce: string;
1424
1461
  feeRateBps: string;
1462
+ /** 0 = BUY, 1 = SELL (matches CTFExchange.sol). */
1425
1463
  side: number;
1464
+ /** 0 = EOA, 1 = POLY_PROXY, 2 = POLY_GNOSIS_SAFE. */
1426
1465
  signatureType: number;
1427
1466
  }
1428
1467
  /**
1429
- * Build the EIP-712 typed data value for a Polymarket limit order.
1468
+ * Build the EIP-712 typed data value for a Polymarket order.
1469
+ *
1470
+ * All amounts are in micro-USDC / micro-shares (1 unit = 1 000 000).
1430
1471
  *
1431
- * All amounts are in micro-USDC (1 USDC = 1 000 000).
1472
+ * Maker/taker semantics:
1473
+ * BUY: makerAmount = USDC spent, takerAmount = shares received
1474
+ * SELL: makerAmount = shares sold, takerAmount = USDC received
1432
1475
  *
1433
- * For a BUY order:
1434
- * - `makerAmount` = USDC spent (cost = size × price)
1435
- * - `takerAmount` = shares received (= size)
1476
+ * Input `size` semantics depend on order type:
1477
+ * Market BUY (FOK/FAK): size = USDC dollar amount to spend
1478
+ * Market SELL (FOK/FAK): size = number of shares to sell
1479
+ * Limit BUY (GTC/GTD): size = number of shares to buy
1480
+ * Limit SELL (GTC/GTD): size = number of shares to sell
1436
1481
  *
1437
- * For a SELL order:
1438
- * - `makerAmount` = shares sold (= size)
1439
- * - `takerAmount` = USDC received (cost = size × price)
1482
+ * Precision:
1483
+ * Market orders → makerAmount 2 decimals, takerAmount ≤ 4 decimals
1484
+ * Limit orders determined by tick-size ROUNDING_CONFIG (no API cap)
1440
1485
  *
1441
- * Amount rounding follows the official Polymarket CLOB client to guarantee
1442
- * that `makerAmount / takerAmount` produces a tick-aligned price.
1443
- * The key invariant: `amountDecimals = sizeDecimals + priceDecimals`, so
1444
- * `round(size × price, amountDecimals) / round(size, sizeDecimals)` has
1445
- * exactly `priceDecimals` decimal places.
1486
+ * Rounding direction:
1487
+ * Market BUY: maker = floor (spend less), taker = floor (fewer shares)
1488
+ * Market SELL: maker = floor (sell fewer), taker = ceil (receive more)
1489
+ * Limit BUY: size = round (tick-align), amount = round
1490
+ * Limit SELL: size = floor (avoid overselling), amount = round
1446
1491
  */
1447
1492
  declare function buildOrderMessage(input: BuildOrderMessageInput): OrderMessage;
1448
1493
  interface SignedOrder extends OrderMessage {
@@ -597,13 +597,26 @@ interface DFlowSubmitResponse {
597
597
  }
598
598
  /** Order type for Polymarket CLOB. */
599
599
  type PolymarketOrderType = "GTC" | "FOK" | "GTD" | "FAK";
600
- /** Input for creating a Polymarket limit order. */
600
+ /**
601
+ * Input for creating a Polymarket order (limit or market).
602
+ * @see https://docs.polymarket.com/trading/orders/create
603
+ */
601
604
  interface CreateOrderInput {
602
605
  /** Token ID (outcome asset ID) from market provider_meta. */
603
606
  tokenId: string;
604
607
  /** Price in range [0.01, 0.99]. */
605
608
  price: number;
606
- /** Order size in USDC. */
609
+ /**
610
+ * Order size — meaning depends on order type:
611
+ * - **Market BUY (FOK/FAK)**: USDC dollar amount to spend.
612
+ * - **Market SELL (FOK/FAK)**: Number of shares to sell.
613
+ * - **Limit BUY/SELL (GTC/GTD)**: Number of shares.
614
+ *
615
+ * This matches the official Polymarket SDK where `createMarketOrder` takes
616
+ * `amount` (USDC for buy, shares for sell), while `createOrder` (limit)
617
+ * takes `size` (always shares).
618
+ * @see https://docs.polymarket.com/trading/orders/create#market-orders
619
+ */
607
620
  size: number;
608
621
  side: OrderSide;
609
622
  orderType?: PolymarketOrderType;
@@ -1329,9 +1342,22 @@ declare function derivePolymarketApiKey(address: string, signature: string, time
1329
1342
  * Neg-Risk CTF Exchange contracts (Polygon mainnet).
1330
1343
  *
1331
1344
  * References:
1332
- * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/builder.ts
1333
- * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/helpers.ts
1334
- * https://docs.polymarket.com/#create-order
1345
+ * - Official docs (order creation):
1346
+ * https://docs.polymarket.com/trading/orders/create
1347
+ * - Official TS CLOB client (order builder / helpers):
1348
+ * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/builder.ts
1349
+ * https://github.com/Polymarket/clob-client/blob/main/src/order-builder/helpers.ts
1350
+ * - Official Python CLOB client (order builder — has `get_market_order_amounts`):
1351
+ * https://github.com/Polymarket/py-clob-client/blob/main/py_clob_client/order_builder/builder.py
1352
+ *
1353
+ * Market order (FOK/FAK) precision limits — NOT documented in official docs,
1354
+ * enforced server-side and discovered via API error messages:
1355
+ * - makerAmount: max 2 decimal places (human-readable)
1356
+ * - takerAmount: max 4 decimal places (human-readable)
1357
+ * - GitHub issues tracking this undocumented constraint:
1358
+ * https://github.com/Polymarket/py-clob-client/issues/121
1359
+ * https://github.com/Polymarket/py-clob-client/issues/253
1360
+ * https://github.com/Polymarket/rs-clob-client/issues/261
1335
1361
  */
1336
1362
 
1337
1363
  /** Polymarket CTF Exchange contract (standard markets). */
@@ -1413,36 +1439,55 @@ interface BuildOrderMessageInput extends CreateOrderInput {
1413
1439
  }
1414
1440
  interface OrderMessage {
1415
1441
  salt: string;
1442
+ /** Funder address that holds the collateral (USDC.e or outcome tokens). */
1416
1443
  maker: string;
1444
+ /** Signer address that signs the EIP-712 order. */
1417
1445
  signer: string;
1446
+ /** Taker address (0x0 = any counterparty). */
1418
1447
  taker: string;
1419
1448
  tokenId: string;
1449
+ /**
1450
+ * Amount the maker provides (micro-USDC, 6 decimals).
1451
+ * BUY: USDC spent. SELL: shares sold.
1452
+ */
1420
1453
  makerAmount: string;
1454
+ /**
1455
+ * Amount the taker provides (micro-USDC, 6 decimals).
1456
+ * BUY: shares received. SELL: USDC received.
1457
+ */
1421
1458
  takerAmount: string;
1422
1459
  expiration: string;
1423
1460
  nonce: string;
1424
1461
  feeRateBps: string;
1462
+ /** 0 = BUY, 1 = SELL (matches CTFExchange.sol). */
1425
1463
  side: number;
1464
+ /** 0 = EOA, 1 = POLY_PROXY, 2 = POLY_GNOSIS_SAFE. */
1426
1465
  signatureType: number;
1427
1466
  }
1428
1467
  /**
1429
- * Build the EIP-712 typed data value for a Polymarket limit order.
1468
+ * Build the EIP-712 typed data value for a Polymarket order.
1469
+ *
1470
+ * All amounts are in micro-USDC / micro-shares (1 unit = 1 000 000).
1430
1471
  *
1431
- * All amounts are in micro-USDC (1 USDC = 1 000 000).
1472
+ * Maker/taker semantics:
1473
+ * BUY: makerAmount = USDC spent, takerAmount = shares received
1474
+ * SELL: makerAmount = shares sold, takerAmount = USDC received
1432
1475
  *
1433
- * For a BUY order:
1434
- * - `makerAmount` = USDC spent (cost = size × price)
1435
- * - `takerAmount` = shares received (= size)
1476
+ * Input `size` semantics depend on order type:
1477
+ * Market BUY (FOK/FAK): size = USDC dollar amount to spend
1478
+ * Market SELL (FOK/FAK): size = number of shares to sell
1479
+ * Limit BUY (GTC/GTD): size = number of shares to buy
1480
+ * Limit SELL (GTC/GTD): size = number of shares to sell
1436
1481
  *
1437
- * For a SELL order:
1438
- * - `makerAmount` = shares sold (= size)
1439
- * - `takerAmount` = USDC received (cost = size × price)
1482
+ * Precision:
1483
+ * Market orders → makerAmount 2 decimals, takerAmount ≤ 4 decimals
1484
+ * Limit orders determined by tick-size ROUNDING_CONFIG (no API cap)
1440
1485
  *
1441
- * Amount rounding follows the official Polymarket CLOB client to guarantee
1442
- * that `makerAmount / takerAmount` produces a tick-aligned price.
1443
- * The key invariant: `amountDecimals = sizeDecimals + priceDecimals`, so
1444
- * `round(size × price, amountDecimals) / round(size, sizeDecimals)` has
1445
- * exactly `priceDecimals` decimal places.
1486
+ * Rounding direction:
1487
+ * Market BUY: maker = floor (spend less), taker = floor (fewer shares)
1488
+ * Market SELL: maker = floor (sell fewer), taker = ceil (receive more)
1489
+ * Limit BUY: size = round (tick-align), amount = round
1490
+ * Limit SELL: size = floor (avoid overselling), amount = round
1446
1491
  */
1447
1492
  declare function buildOrderMessage(input: BuildOrderMessageInput): OrderMessage;
1448
1493
  interface SignedOrder extends OrderMessage {
package/dist/server.d.mts CHANGED
@@ -1 +1 @@
1
- export { B as BalanceResponse, b2 as BuildClobAuthMessageInput, bf as BuildOrderMessageInput, aV as CLOB_AUTH_DOMAIN, aW as CLOB_AUTH_TYPES, b3 as CTF_EXCHANGE_ADDRESS, b8 as CTF_ORDER_TYPES, r as CancelOrderResult, C as Candlestick, be as ClobOrderPayload, $ as CreateOrderInput, bi as DEFAULT_PAGE_SIZE, ah as DFlowOrderContext, D as DFlowQuoteRequest, y as DFlowQuoteResponse, F as DFlowSubmitRequest, z as DFlowSubmitResponse, aj as DepositBuildRequest, ak as DepositBuildResponse, an as DepositStatusResponse, al as DepositSubmitRequest, am as DepositSubmitResponse, f as EventSortField, e as EventStatus, ab as EventSummary, a$ as HttpMethod, l as ListCandlesticksParams, L as ListEventsParams, h as ListMarketTradesParams, n as ListOrdersParams, w as ListTradesParams, a8 as MarketOutcome, a7 as MarketResult, a6 as MarketStatus, ac as MarketSummary, au as MatchConfidenceTier, t as MatchGroup, aq as MatchGroupEntry, ar as MatchGroupMarket, s as MatchGroupPage, av as MatchMarketFlat, v as MatchMarketPage, u as MatchMarketParams, as as MatchSortField, ap as MatchStatus, M as MatchesParams, at as MatchesStats, b4 as NEG_RISK_CTF_EXCHANGE_ADDRESS, b9 as ORDER_TYPE, bg as OrderMessage, ag as OrderSide, af as OrderStatus, O as Orderbook, a9 as OrderbookLevel, b6 as POLYGON_CHAIN_ID, b1 as PolymarketL2Headers, b0 as PolymarketL2HeadersInput, ai as PolymarketOrderType, m as PositionsResponse, P as PredictClient, c as PredictEvent, g as PredictMarket, o as PredictOrder, b as PredictPage, ae as PredictPosition, a4 as PredictTag, i as PredictTrade, a as PredictWsClient, a2 as PredictWsClientConfig, j as PriceHistoryRange, k as PriceHistoryResponse, ad as PricePoint, a3 as ProviderMeta, d as ProviderSource, aM as ResolveEventsParamsInput, ba as SIDE, a5 as SettlementSource, bh as SignedOrder, S as SimilarEventsParams, aN as TagSlugSelection, aa as TradeType, b5 as USDC_ADDRESS, ao as UnsignedTx, aw as WsChannel, ax as WsChannelEvent, ay as WsClientMessage, V as WsConnectionStatus, X as WsDataMessage, aE as WsErrorCode, aF as WsErrorMessage, Z as WsOrderbookEvent, aA as WsPingMessage, aC as WsPongMessage, Y as WsPriceEvent, aB as WsServerMessage, az as WsSubscribeMessage, aD as WsSubscribedMessage, _ as WsTradeEvent, aX as buildClobAuthMessage, bd as buildClobPayload, b7 as buildCtfExchangeDomain, bb as buildOrderMessage, aZ as buildPolymarketL2Headers, bc as buildSignedOrder, a0 as createPredictClient, a1 as createPredictWsClient, a_ as derivePolymarketApiKey, aG as eventQueryKey, aH as fetchEvent, aL as fetchEventsPage, aP as fetchMarket, aU as fetchMatchMarketsPage, aS as fetchMatchesPage, aY as hmacSha256Base64, aK as infiniteEventsQueryKey, aO as marketQueryKey, aT as matchMarketsQueryKey, aR as matchQueryKey, aQ as matchesQueryKey, aJ as resolveEventsParams, aI as resolveTagSlug } from './server-BPTOChEG.mjs';
1
+ export { B as BalanceResponse, b2 as BuildClobAuthMessageInput, bf as BuildOrderMessageInput, aV as CLOB_AUTH_DOMAIN, aW as CLOB_AUTH_TYPES, b3 as CTF_EXCHANGE_ADDRESS, b8 as CTF_ORDER_TYPES, r as CancelOrderResult, C as Candlestick, be as ClobOrderPayload, $ as CreateOrderInput, bi as DEFAULT_PAGE_SIZE, ah as DFlowOrderContext, D as DFlowQuoteRequest, y as DFlowQuoteResponse, F as DFlowSubmitRequest, z as DFlowSubmitResponse, aj as DepositBuildRequest, ak as DepositBuildResponse, an as DepositStatusResponse, al as DepositSubmitRequest, am as DepositSubmitResponse, f as EventSortField, e as EventStatus, ab as EventSummary, a$ as HttpMethod, l as ListCandlesticksParams, L as ListEventsParams, h as ListMarketTradesParams, n as ListOrdersParams, w as ListTradesParams, a8 as MarketOutcome, a7 as MarketResult, a6 as MarketStatus, ac as MarketSummary, au as MatchConfidenceTier, t as MatchGroup, aq as MatchGroupEntry, ar as MatchGroupMarket, s as MatchGroupPage, av as MatchMarketFlat, v as MatchMarketPage, u as MatchMarketParams, as as MatchSortField, ap as MatchStatus, M as MatchesParams, at as MatchesStats, b4 as NEG_RISK_CTF_EXCHANGE_ADDRESS, b9 as ORDER_TYPE, bg as OrderMessage, ag as OrderSide, af as OrderStatus, O as Orderbook, a9 as OrderbookLevel, b6 as POLYGON_CHAIN_ID, b1 as PolymarketL2Headers, b0 as PolymarketL2HeadersInput, ai as PolymarketOrderType, m as PositionsResponse, P as PredictClient, c as PredictEvent, g as PredictMarket, o as PredictOrder, b as PredictPage, ae as PredictPosition, a4 as PredictTag, i as PredictTrade, a as PredictWsClient, a2 as PredictWsClientConfig, j as PriceHistoryRange, k as PriceHistoryResponse, ad as PricePoint, a3 as ProviderMeta, d as ProviderSource, aM as ResolveEventsParamsInput, ba as SIDE, a5 as SettlementSource, bh as SignedOrder, S as SimilarEventsParams, aN as TagSlugSelection, aa as TradeType, b5 as USDC_ADDRESS, ao as UnsignedTx, aw as WsChannel, ax as WsChannelEvent, ay as WsClientMessage, V as WsConnectionStatus, X as WsDataMessage, aE as WsErrorCode, aF as WsErrorMessage, Z as WsOrderbookEvent, aA as WsPingMessage, aC as WsPongMessage, Y as WsPriceEvent, aB as WsServerMessage, az as WsSubscribeMessage, aD as WsSubscribedMessage, _ as WsTradeEvent, aX as buildClobAuthMessage, bd as buildClobPayload, b7 as buildCtfExchangeDomain, bb as buildOrderMessage, aZ as buildPolymarketL2Headers, bc as buildSignedOrder, a0 as createPredictClient, a1 as createPredictWsClient, a_ as derivePolymarketApiKey, aG as eventQueryKey, aH as fetchEvent, aL as fetchEventsPage, aP as fetchMarket, aU as fetchMatchMarketsPage, aS as fetchMatchesPage, aY as hmacSha256Base64, aK as infiniteEventsQueryKey, aO as marketQueryKey, aT as matchMarketsQueryKey, aR as matchQueryKey, aQ as matchesQueryKey, aJ as resolveEventsParams, aI as resolveTagSlug } from './server-DUc4MoLH.mjs';
package/dist/server.d.ts CHANGED
@@ -1 +1 @@
1
- export { B as BalanceResponse, b2 as BuildClobAuthMessageInput, bf as BuildOrderMessageInput, aV as CLOB_AUTH_DOMAIN, aW as CLOB_AUTH_TYPES, b3 as CTF_EXCHANGE_ADDRESS, b8 as CTF_ORDER_TYPES, r as CancelOrderResult, C as Candlestick, be as ClobOrderPayload, $ as CreateOrderInput, bi as DEFAULT_PAGE_SIZE, ah as DFlowOrderContext, D as DFlowQuoteRequest, y as DFlowQuoteResponse, F as DFlowSubmitRequest, z as DFlowSubmitResponse, aj as DepositBuildRequest, ak as DepositBuildResponse, an as DepositStatusResponse, al as DepositSubmitRequest, am as DepositSubmitResponse, f as EventSortField, e as EventStatus, ab as EventSummary, a$ as HttpMethod, l as ListCandlesticksParams, L as ListEventsParams, h as ListMarketTradesParams, n as ListOrdersParams, w as ListTradesParams, a8 as MarketOutcome, a7 as MarketResult, a6 as MarketStatus, ac as MarketSummary, au as MatchConfidenceTier, t as MatchGroup, aq as MatchGroupEntry, ar as MatchGroupMarket, s as MatchGroupPage, av as MatchMarketFlat, v as MatchMarketPage, u as MatchMarketParams, as as MatchSortField, ap as MatchStatus, M as MatchesParams, at as MatchesStats, b4 as NEG_RISK_CTF_EXCHANGE_ADDRESS, b9 as ORDER_TYPE, bg as OrderMessage, ag as OrderSide, af as OrderStatus, O as Orderbook, a9 as OrderbookLevel, b6 as POLYGON_CHAIN_ID, b1 as PolymarketL2Headers, b0 as PolymarketL2HeadersInput, ai as PolymarketOrderType, m as PositionsResponse, P as PredictClient, c as PredictEvent, g as PredictMarket, o as PredictOrder, b as PredictPage, ae as PredictPosition, a4 as PredictTag, i as PredictTrade, a as PredictWsClient, a2 as PredictWsClientConfig, j as PriceHistoryRange, k as PriceHistoryResponse, ad as PricePoint, a3 as ProviderMeta, d as ProviderSource, aM as ResolveEventsParamsInput, ba as SIDE, a5 as SettlementSource, bh as SignedOrder, S as SimilarEventsParams, aN as TagSlugSelection, aa as TradeType, b5 as USDC_ADDRESS, ao as UnsignedTx, aw as WsChannel, ax as WsChannelEvent, ay as WsClientMessage, V as WsConnectionStatus, X as WsDataMessage, aE as WsErrorCode, aF as WsErrorMessage, Z as WsOrderbookEvent, aA as WsPingMessage, aC as WsPongMessage, Y as WsPriceEvent, aB as WsServerMessage, az as WsSubscribeMessage, aD as WsSubscribedMessage, _ as WsTradeEvent, aX as buildClobAuthMessage, bd as buildClobPayload, b7 as buildCtfExchangeDomain, bb as buildOrderMessage, aZ as buildPolymarketL2Headers, bc as buildSignedOrder, a0 as createPredictClient, a1 as createPredictWsClient, a_ as derivePolymarketApiKey, aG as eventQueryKey, aH as fetchEvent, aL as fetchEventsPage, aP as fetchMarket, aU as fetchMatchMarketsPage, aS as fetchMatchesPage, aY as hmacSha256Base64, aK as infiniteEventsQueryKey, aO as marketQueryKey, aT as matchMarketsQueryKey, aR as matchQueryKey, aQ as matchesQueryKey, aJ as resolveEventsParams, aI as resolveTagSlug } from './server-BPTOChEG.js';
1
+ export { B as BalanceResponse, b2 as BuildClobAuthMessageInput, bf as BuildOrderMessageInput, aV as CLOB_AUTH_DOMAIN, aW as CLOB_AUTH_TYPES, b3 as CTF_EXCHANGE_ADDRESS, b8 as CTF_ORDER_TYPES, r as CancelOrderResult, C as Candlestick, be as ClobOrderPayload, $ as CreateOrderInput, bi as DEFAULT_PAGE_SIZE, ah as DFlowOrderContext, D as DFlowQuoteRequest, y as DFlowQuoteResponse, F as DFlowSubmitRequest, z as DFlowSubmitResponse, aj as DepositBuildRequest, ak as DepositBuildResponse, an as DepositStatusResponse, al as DepositSubmitRequest, am as DepositSubmitResponse, f as EventSortField, e as EventStatus, ab as EventSummary, a$ as HttpMethod, l as ListCandlesticksParams, L as ListEventsParams, h as ListMarketTradesParams, n as ListOrdersParams, w as ListTradesParams, a8 as MarketOutcome, a7 as MarketResult, a6 as MarketStatus, ac as MarketSummary, au as MatchConfidenceTier, t as MatchGroup, aq as MatchGroupEntry, ar as MatchGroupMarket, s as MatchGroupPage, av as MatchMarketFlat, v as MatchMarketPage, u as MatchMarketParams, as as MatchSortField, ap as MatchStatus, M as MatchesParams, at as MatchesStats, b4 as NEG_RISK_CTF_EXCHANGE_ADDRESS, b9 as ORDER_TYPE, bg as OrderMessage, ag as OrderSide, af as OrderStatus, O as Orderbook, a9 as OrderbookLevel, b6 as POLYGON_CHAIN_ID, b1 as PolymarketL2Headers, b0 as PolymarketL2HeadersInput, ai as PolymarketOrderType, m as PositionsResponse, P as PredictClient, c as PredictEvent, g as PredictMarket, o as PredictOrder, b as PredictPage, ae as PredictPosition, a4 as PredictTag, i as PredictTrade, a as PredictWsClient, a2 as PredictWsClientConfig, j as PriceHistoryRange, k as PriceHistoryResponse, ad as PricePoint, a3 as ProviderMeta, d as ProviderSource, aM as ResolveEventsParamsInput, ba as SIDE, a5 as SettlementSource, bh as SignedOrder, S as SimilarEventsParams, aN as TagSlugSelection, aa as TradeType, b5 as USDC_ADDRESS, ao as UnsignedTx, aw as WsChannel, ax as WsChannelEvent, ay as WsClientMessage, V as WsConnectionStatus, X as WsDataMessage, aE as WsErrorCode, aF as WsErrorMessage, Z as WsOrderbookEvent, aA as WsPingMessage, aC as WsPongMessage, Y as WsPriceEvent, aB as WsServerMessage, az as WsSubscribeMessage, aD as WsSubscribedMessage, _ as WsTradeEvent, aX as buildClobAuthMessage, bd as buildClobPayload, b7 as buildCtfExchangeDomain, bb as buildOrderMessage, aZ as buildPolymarketL2Headers, bc as buildSignedOrder, a0 as createPredictClient, a1 as createPredictWsClient, a_ as derivePolymarketApiKey, aG as eventQueryKey, aH as fetchEvent, aL as fetchEventsPage, aP as fetchMarket, aU as fetchMatchMarketsPage, aS as fetchMatchesPage, aY as hmacSha256Base64, aK as infiniteEventsQueryKey, aO as marketQueryKey, aT as matchMarketsQueryKey, aR as matchQueryKey, aQ as matchesQueryKey, aJ as resolveEventsParams, aI as resolveTagSlug } from './server-DUc4MoLH.js';
package/dist/server.js CHANGED
@@ -995,6 +995,16 @@ function floorDecimalPlaces(n, d) {
995
995
  const factor = 10 ** d;
996
996
  return Math.floor(n * factor) / factor;
997
997
  }
998
+ function ceilDecimalPlaces(n, d) {
999
+ const factor = 10 ** d;
1000
+ return Math.ceil(n * factor) / factor;
1001
+ }
1002
+ function countDecimalPlaces(n) {
1003
+ const s = n.toString();
1004
+ const dot = s.indexOf(".");
1005
+ if (dot === -1) return 0;
1006
+ return s.length - dot - 1;
1007
+ }
998
1008
  function toMicroUsdc(amount) {
999
1009
  return BigInt(Math.round(amount * 1e6));
1000
1010
  }
@@ -1004,16 +1014,48 @@ function normalizeTokenId(tokenId) {
1004
1014
  }
1005
1015
  return tokenId;
1006
1016
  }
1007
- function buildOrderMessage(input) {
1008
- const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
1009
- const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
1010
- const rawPrice = decimalPlaces(input.price, rc.price);
1011
- const rawSize = side === SIDE.SELL ? floorDecimalPlaces(input.size, rc.size) : decimalPlaces(input.size, rc.size);
1017
+ var MARKET_MAKER_MAX_DECIMALS = 2;
1018
+ var MARKET_TAKER_MAX_DECIMALS = 4;
1019
+ function getMarketOrderAmounts(side, size, price, rc) {
1020
+ const rawPrice = decimalPlaces(price, rc.price);
1021
+ const makerDecimals = Math.min(rc.size, MARKET_MAKER_MAX_DECIMALS);
1022
+ const takerDecimals = Math.min(rc.amount, MARKET_TAKER_MAX_DECIMALS);
1023
+ if (side === SIDE.BUY) {
1024
+ const rawMakerAmt2 = floorDecimalPlaces(size, makerDecimals);
1025
+ let rawTakerAmt2 = rawMakerAmt2 / rawPrice;
1026
+ if (countDecimalPlaces(rawTakerAmt2) > takerDecimals) {
1027
+ rawTakerAmt2 = floorDecimalPlaces(rawTakerAmt2, takerDecimals);
1028
+ }
1029
+ return {
1030
+ makerAmount: toMicroUsdc(rawMakerAmt2).toString(),
1031
+ takerAmount: toMicroUsdc(rawTakerAmt2).toString()
1032
+ };
1033
+ }
1034
+ const rawMakerAmt = floorDecimalPlaces(size, makerDecimals);
1035
+ let rawTakerAmt = rawMakerAmt * rawPrice;
1036
+ if (countDecimalPlaces(rawTakerAmt) > takerDecimals) {
1037
+ rawTakerAmt = ceilDecimalPlaces(rawTakerAmt, takerDecimals);
1038
+ }
1039
+ return {
1040
+ makerAmount: toMicroUsdc(rawMakerAmt).toString(),
1041
+ takerAmount: toMicroUsdc(rawTakerAmt).toString()
1042
+ };
1043
+ }
1044
+ function getLimitOrderAmounts(side, size, price, rc) {
1045
+ const rawPrice = decimalPlaces(price, rc.price);
1046
+ const rawSize = side === SIDE.SELL ? floorDecimalPlaces(size, rc.size) : decimalPlaces(size, rc.size);
1012
1047
  const sizeInMicro = toMicroUsdc(rawSize);
1013
1048
  const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
1014
1049
  const amountInMicro = toMicroUsdc(rawAmount);
1015
1050
  const makerAmount = side === SIDE.BUY ? amountInMicro.toString() : sizeInMicro.toString();
1016
1051
  const takerAmount = side === SIDE.BUY ? sizeInMicro.toString() : amountInMicro.toString();
1052
+ return { makerAmount, takerAmount };
1053
+ }
1054
+ function buildOrderMessage(input) {
1055
+ const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
1056
+ const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
1057
+ const isMarketOrder = input.orderType === "FOK" || input.orderType === "FAK";
1058
+ const { makerAmount, takerAmount } = isMarketOrder ? getMarketOrderAmounts(side, input.size, input.price, rc) : getLimitOrderAmounts(side, input.size, input.price, rc);
1017
1059
  const maker = input.funderAddress ?? input.signerAddress;
1018
1060
  return {
1019
1061
  salt: Math.floor(Math.random() * 1e15).toString(),