@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
|
@@ -674,6 +674,10 @@ interface WsDataMessage<T extends WsChannelEvent = WsChannelEvent> {
|
|
|
674
674
|
}
|
|
675
675
|
/** Union of all messages the server can send. */
|
|
676
676
|
type WsServerMessage = WsPongMessage | WsSubscribedMessage | WsErrorMessage | WsDataMessage;
|
|
677
|
+
/** Response from the Polymarket tick-size endpoint. */
|
|
678
|
+
interface TickSizeResponse {
|
|
679
|
+
minimum_tick_size: number;
|
|
680
|
+
}
|
|
677
681
|
|
|
678
682
|
/**
|
|
679
683
|
* HTTP client for the prediction-server REST API.
|
|
@@ -795,6 +799,8 @@ declare class PredictClient {
|
|
|
795
799
|
* @param headers - Polymarket CLOB auth headers (`POLY_*`).
|
|
796
800
|
*/
|
|
797
801
|
createPolymarketOrder(input: CreateOrderInput, headers: Record<string, string>): Promise<PredictOrder>;
|
|
802
|
+
/** Maps to `GET /api/v1/polymarket/tick-size?token_id=xxx`. */
|
|
803
|
+
getPolymarketTickSize(tokenId: string): Promise<TickSizeResponse>;
|
|
798
804
|
/** Maps to `POST /api/v1/orders/kalshi/quote`. */
|
|
799
805
|
createDFlowQuote(body: DFlowQuoteRequest): Promise<DFlowQuoteResponse>;
|
|
800
806
|
/** Maps to `POST /api/v1/orders/kalshi/submit`. */
|
|
@@ -1346,6 +1352,12 @@ interface OrderMessage {
|
|
|
1346
1352
|
* For a SELL order:
|
|
1347
1353
|
* - `makerAmount` = shares sold (= size)
|
|
1348
1354
|
* - `takerAmount` = USDC received (cost = size × price)
|
|
1355
|
+
*
|
|
1356
|
+
* Amount rounding follows the official Polymarket CLOB client to guarantee
|
|
1357
|
+
* that `makerAmount / takerAmount` produces a tick-aligned price.
|
|
1358
|
+
* The key invariant: `amountDecimals = sizeDecimals + priceDecimals`, so
|
|
1359
|
+
* `round(size × price, amountDecimals) / round(size, sizeDecimals)` has
|
|
1360
|
+
* exactly `priceDecimals` decimal places.
|
|
1349
1361
|
*/
|
|
1350
1362
|
declare function buildOrderMessage(input: BuildOrderMessageInput): OrderMessage;
|
|
1351
1363
|
interface SignedOrder extends OrderMessage {
|
|
@@ -1398,4 +1410,4 @@ interface ClobOrderPayload {
|
|
|
1398
1410
|
*/
|
|
1399
1411
|
declare function buildClobPayload(signedOrder: SignedOrder, owner: string): ClobOrderPayload;
|
|
1400
1412
|
|
|
1401
|
-
export { type
|
|
1413
|
+
export { type PredictTag as $, type WithdrawSubmitResponse as A, type BalanceResponse as B, type Candlestick as C, type DFlowQuoteRequest as D, type EventStatus as E, type WithdrawSubmitRequest as F, type WithdrawStatusResponse as G, type PolymarketDepositAddresses as H, type PolymarketWithdrawResponse as I, type PolymarketWithdrawRequest as J, type WsConnectionStatus as K, type ListEventsParams as L, type MatchesParams as M, type WsDataMessage as N, type Orderbook as O, PredictClient as P, type WsPriceEvent as Q, type WsOrderbookEvent as R, type SimilarEventsParams as S, type TickSizeResponse as T, type WsTradeEvent as U, type CreateOrderInput as V, type WithdrawBuildResponse as W, createPredictClient as X, createPredictWsClient as Y, type PredictWsClientConfig as Z, type ProviderMeta as _, PredictWsClient as a, NEG_RISK_CTF_EXCHANGE_ADDRESS as a$, type SettlementSource as a0, type MarketStatus as a1, type MarketResult as a2, type MarketOutcome as a3, type OrderbookLevel as a4, type TradeType as a5, type EventSummary as a6, type MarketSummary as a7, type PricePoint as a8, type PredictPosition as a9, type WsErrorMessage as aA, eventQueryKey as aB, fetchEvent as aC, resolveTagSlug as aD, resolveEventsParams as aE, infiniteEventsQueryKey as aF, fetchEventsPage as aG, type ResolveEventsParamsInput as aH, type TagSlugSelection as aI, marketQueryKey as aJ, fetchMarket as aK, matchesQueryKey as aL, matchQueryKey as aM, fetchMatchesPage as aN, matchMarketsQueryKey as aO, fetchMatchMarketsPage as aP, CLOB_AUTH_DOMAIN as aQ, CLOB_AUTH_TYPES as aR, buildClobAuthMessage as aS, hmacSha256Base64 as aT, buildPolymarketL2Headers as aU, derivePolymarketApiKey as aV, type HttpMethod as aW, type PolymarketL2HeadersInput as aX, type PolymarketL2Headers as aY, type BuildClobAuthMessageInput as aZ, CTF_EXCHANGE_ADDRESS as a_, type OrderStatus as aa, type OrderSide as ab, type DFlowOrderContext as ac, type PolymarketOrderType as ad, type DepositBuildRequest as ae, type DepositBuildResponse as af, type DepositSubmitRequest as ag, type DepositSubmitResponse as ah, type DepositStatusResponse as ai, type UnsignedTx as aj, type MatchStatus as ak, type MatchGroupEntry as al, type MatchGroupMarket as am, type MatchSortField as an, type MatchesStats as ao, type MatchConfidenceTier as ap, type MatchMarketFlat as aq, type WsChannel as ar, type WsChannelEvent as as, type WsClientMessage as at, type WsSubscribeMessage as au, type WsPingMessage as av, type WsServerMessage as aw, type WsPongMessage as ax, type WsSubscribedMessage as ay, type WsErrorCode as az, type PredictPage as b, USDC_ADDRESS as b0, POLYGON_CHAIN_ID as b1, buildCtfExchangeDomain as b2, CTF_ORDER_TYPES as b3, ORDER_TYPE as b4, SIDE as b5, buildOrderMessage as b6, buildSignedOrder as b7, buildClobPayload as b8, type ClobOrderPayload as b9, type BuildOrderMessageInput as ba, type OrderMessage as bb, type SignedOrder as bc, DEFAULT_PAGE_SIZE as bd, type PredictEvent as c, type ProviderSource as d, type EventSortField as e, type PredictMarket as f, type ListMarketTradesParams as g, type PredictTrade as h, type PriceHistoryRange as i, type PriceHistoryResponse as j, type ListCandlesticksParams as k, type PositionsResponse as l, type ListOrdersParams as m, type PredictOrder as n, type CancelOrderResult as o, type MatchGroupPage as p, type MatchGroup as q, type MatchMarketParams as r, type MatchMarketPage as s, type ListTradesParams as t, type DFlowQuoteResponse as u, type DFlowSubmitResponse as v, type DFlowSubmitRequest as w, type DFlowKYCStatus as x, type PolymarketSetupStatus as y, type WithdrawBuildRequest as z };
|
|
@@ -674,6 +674,10 @@ interface WsDataMessage<T extends WsChannelEvent = WsChannelEvent> {
|
|
|
674
674
|
}
|
|
675
675
|
/** Union of all messages the server can send. */
|
|
676
676
|
type WsServerMessage = WsPongMessage | WsSubscribedMessage | WsErrorMessage | WsDataMessage;
|
|
677
|
+
/** Response from the Polymarket tick-size endpoint. */
|
|
678
|
+
interface TickSizeResponse {
|
|
679
|
+
minimum_tick_size: number;
|
|
680
|
+
}
|
|
677
681
|
|
|
678
682
|
/**
|
|
679
683
|
* HTTP client for the prediction-server REST API.
|
|
@@ -795,6 +799,8 @@ declare class PredictClient {
|
|
|
795
799
|
* @param headers - Polymarket CLOB auth headers (`POLY_*`).
|
|
796
800
|
*/
|
|
797
801
|
createPolymarketOrder(input: CreateOrderInput, headers: Record<string, string>): Promise<PredictOrder>;
|
|
802
|
+
/** Maps to `GET /api/v1/polymarket/tick-size?token_id=xxx`. */
|
|
803
|
+
getPolymarketTickSize(tokenId: string): Promise<TickSizeResponse>;
|
|
798
804
|
/** Maps to `POST /api/v1/orders/kalshi/quote`. */
|
|
799
805
|
createDFlowQuote(body: DFlowQuoteRequest): Promise<DFlowQuoteResponse>;
|
|
800
806
|
/** Maps to `POST /api/v1/orders/kalshi/submit`. */
|
|
@@ -1346,6 +1352,12 @@ interface OrderMessage {
|
|
|
1346
1352
|
* For a SELL order:
|
|
1347
1353
|
* - `makerAmount` = shares sold (= size)
|
|
1348
1354
|
* - `takerAmount` = USDC received (cost = size × price)
|
|
1355
|
+
*
|
|
1356
|
+
* Amount rounding follows the official Polymarket CLOB client to guarantee
|
|
1357
|
+
* that `makerAmount / takerAmount` produces a tick-aligned price.
|
|
1358
|
+
* The key invariant: `amountDecimals = sizeDecimals + priceDecimals`, so
|
|
1359
|
+
* `round(size × price, amountDecimals) / round(size, sizeDecimals)` has
|
|
1360
|
+
* exactly `priceDecimals` decimal places.
|
|
1349
1361
|
*/
|
|
1350
1362
|
declare function buildOrderMessage(input: BuildOrderMessageInput): OrderMessage;
|
|
1351
1363
|
interface SignedOrder extends OrderMessage {
|
|
@@ -1398,4 +1410,4 @@ interface ClobOrderPayload {
|
|
|
1398
1410
|
*/
|
|
1399
1411
|
declare function buildClobPayload(signedOrder: SignedOrder, owner: string): ClobOrderPayload;
|
|
1400
1412
|
|
|
1401
|
-
export { type
|
|
1413
|
+
export { type PredictTag as $, type WithdrawSubmitResponse as A, type BalanceResponse as B, type Candlestick as C, type DFlowQuoteRequest as D, type EventStatus as E, type WithdrawSubmitRequest as F, type WithdrawStatusResponse as G, type PolymarketDepositAddresses as H, type PolymarketWithdrawResponse as I, type PolymarketWithdrawRequest as J, type WsConnectionStatus as K, type ListEventsParams as L, type MatchesParams as M, type WsDataMessage as N, type Orderbook as O, PredictClient as P, type WsPriceEvent as Q, type WsOrderbookEvent as R, type SimilarEventsParams as S, type TickSizeResponse as T, type WsTradeEvent as U, type CreateOrderInput as V, type WithdrawBuildResponse as W, createPredictClient as X, createPredictWsClient as Y, type PredictWsClientConfig as Z, type ProviderMeta as _, PredictWsClient as a, NEG_RISK_CTF_EXCHANGE_ADDRESS as a$, type SettlementSource as a0, type MarketStatus as a1, type MarketResult as a2, type MarketOutcome as a3, type OrderbookLevel as a4, type TradeType as a5, type EventSummary as a6, type MarketSummary as a7, type PricePoint as a8, type PredictPosition as a9, type WsErrorMessage as aA, eventQueryKey as aB, fetchEvent as aC, resolveTagSlug as aD, resolveEventsParams as aE, infiniteEventsQueryKey as aF, fetchEventsPage as aG, type ResolveEventsParamsInput as aH, type TagSlugSelection as aI, marketQueryKey as aJ, fetchMarket as aK, matchesQueryKey as aL, matchQueryKey as aM, fetchMatchesPage as aN, matchMarketsQueryKey as aO, fetchMatchMarketsPage as aP, CLOB_AUTH_DOMAIN as aQ, CLOB_AUTH_TYPES as aR, buildClobAuthMessage as aS, hmacSha256Base64 as aT, buildPolymarketL2Headers as aU, derivePolymarketApiKey as aV, type HttpMethod as aW, type PolymarketL2HeadersInput as aX, type PolymarketL2Headers as aY, type BuildClobAuthMessageInput as aZ, CTF_EXCHANGE_ADDRESS as a_, type OrderStatus as aa, type OrderSide as ab, type DFlowOrderContext as ac, type PolymarketOrderType as ad, type DepositBuildRequest as ae, type DepositBuildResponse as af, type DepositSubmitRequest as ag, type DepositSubmitResponse as ah, type DepositStatusResponse as ai, type UnsignedTx as aj, type MatchStatus as ak, type MatchGroupEntry as al, type MatchGroupMarket as am, type MatchSortField as an, type MatchesStats as ao, type MatchConfidenceTier as ap, type MatchMarketFlat as aq, type WsChannel as ar, type WsChannelEvent as as, type WsClientMessage as at, type WsSubscribeMessage as au, type WsPingMessage as av, type WsServerMessage as aw, type WsPongMessage as ax, type WsSubscribedMessage as ay, type WsErrorCode as az, type PredictPage as b, USDC_ADDRESS as b0, POLYGON_CHAIN_ID as b1, buildCtfExchangeDomain as b2, CTF_ORDER_TYPES as b3, ORDER_TYPE as b4, SIDE as b5, buildOrderMessage as b6, buildSignedOrder as b7, buildClobPayload as b8, type ClobOrderPayload as b9, type BuildOrderMessageInput as ba, type OrderMessage as bb, type SignedOrder as bc, DEFAULT_PAGE_SIZE as bd, type PredictEvent as c, type ProviderSource as d, type EventSortField as e, type PredictMarket as f, type ListMarketTradesParams as g, type PredictTrade as h, type PriceHistoryRange as i, type PriceHistoryResponse as j, type ListCandlesticksParams as k, type PositionsResponse as l, type ListOrdersParams as m, type PredictOrder as n, type CancelOrderResult as o, type MatchGroupPage as p, type MatchGroup as q, type MatchMarketParams as r, type MatchMarketPage as s, type ListTradesParams as t, type DFlowQuoteResponse as u, type DFlowSubmitResponse as v, type DFlowSubmitRequest as w, type DFlowKYCStatus as x, type PolymarketSetupStatus as y, type WithdrawBuildRequest as z };
|
package/dist/server.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { B as BalanceResponse,
|
|
1
|
+
export { B as BalanceResponse, aZ as BuildClobAuthMessageInput, ba as BuildOrderMessageInput, aQ as CLOB_AUTH_DOMAIN, aR as CLOB_AUTH_TYPES, a_ as CTF_EXCHANGE_ADDRESS, b3 as CTF_ORDER_TYPES, o as CancelOrderResult, C as Candlestick, b9 as ClobOrderPayload, V as CreateOrderInput, bd as DEFAULT_PAGE_SIZE, ac as DFlowOrderContext, D as DFlowQuoteRequest, u as DFlowQuoteResponse, w as DFlowSubmitRequest, v as DFlowSubmitResponse, ae as DepositBuildRequest, af as DepositBuildResponse, ai as DepositStatusResponse, ag as DepositSubmitRequest, ah as DepositSubmitResponse, e as EventSortField, E as EventStatus, a6 as EventSummary, aW as HttpMethod, k as ListCandlesticksParams, L as ListEventsParams, g as ListMarketTradesParams, m as ListOrdersParams, t as ListTradesParams, a3 as MarketOutcome, a2 as MarketResult, a1 as MarketStatus, a7 as MarketSummary, ap as MatchConfidenceTier, q as MatchGroup, al as MatchGroupEntry, am as MatchGroupMarket, p as MatchGroupPage, aq as MatchMarketFlat, s as MatchMarketPage, r as MatchMarketParams, an as MatchSortField, ak as MatchStatus, M as MatchesParams, ao as MatchesStats, a$ as NEG_RISK_CTF_EXCHANGE_ADDRESS, b4 as ORDER_TYPE, bb as OrderMessage, ab as OrderSide, aa as OrderStatus, O as Orderbook, a4 as OrderbookLevel, b1 as POLYGON_CHAIN_ID, aY as PolymarketL2Headers, aX as PolymarketL2HeadersInput, ad as PolymarketOrderType, l as PositionsResponse, P as PredictClient, c as PredictEvent, f as PredictMarket, n as PredictOrder, b as PredictPage, a9 as PredictPosition, $ as PredictTag, h as PredictTrade, a as PredictWsClient, Z as PredictWsClientConfig, i as PriceHistoryRange, j as PriceHistoryResponse, a8 as PricePoint, _ as ProviderMeta, d as ProviderSource, aH as ResolveEventsParamsInput, b5 as SIDE, a0 as SettlementSource, bc as SignedOrder, S as SimilarEventsParams, aI as TagSlugSelection, a5 as TradeType, b0 as USDC_ADDRESS, aj as UnsignedTx, ar as WsChannel, as as WsChannelEvent, at as WsClientMessage, K as WsConnectionStatus, N as WsDataMessage, az as WsErrorCode, aA as WsErrorMessage, R as WsOrderbookEvent, av as WsPingMessage, ax as WsPongMessage, Q as WsPriceEvent, aw as WsServerMessage, au as WsSubscribeMessage, ay as WsSubscribedMessage, U as WsTradeEvent, aS as buildClobAuthMessage, b8 as buildClobPayload, b2 as buildCtfExchangeDomain, b6 as buildOrderMessage, aU as buildPolymarketL2Headers, b7 as buildSignedOrder, X as createPredictClient, Y as createPredictWsClient, aV as derivePolymarketApiKey, aB as eventQueryKey, aC as fetchEvent, aG as fetchEventsPage, aK as fetchMarket, aP as fetchMatchMarketsPage, aN as fetchMatchesPage, aT as hmacSha256Base64, aF as infiniteEventsQueryKey, aJ as marketQueryKey, aO as matchMarketsQueryKey, aM as matchQueryKey, aL as matchesQueryKey, aE as resolveEventsParams, aD as resolveTagSlug } from './server-CYqs2N2z.mjs';
|
package/dist/server.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { B as BalanceResponse,
|
|
1
|
+
export { B as BalanceResponse, aZ as BuildClobAuthMessageInput, ba as BuildOrderMessageInput, aQ as CLOB_AUTH_DOMAIN, aR as CLOB_AUTH_TYPES, a_ as CTF_EXCHANGE_ADDRESS, b3 as CTF_ORDER_TYPES, o as CancelOrderResult, C as Candlestick, b9 as ClobOrderPayload, V as CreateOrderInput, bd as DEFAULT_PAGE_SIZE, ac as DFlowOrderContext, D as DFlowQuoteRequest, u as DFlowQuoteResponse, w as DFlowSubmitRequest, v as DFlowSubmitResponse, ae as DepositBuildRequest, af as DepositBuildResponse, ai as DepositStatusResponse, ag as DepositSubmitRequest, ah as DepositSubmitResponse, e as EventSortField, E as EventStatus, a6 as EventSummary, aW as HttpMethod, k as ListCandlesticksParams, L as ListEventsParams, g as ListMarketTradesParams, m as ListOrdersParams, t as ListTradesParams, a3 as MarketOutcome, a2 as MarketResult, a1 as MarketStatus, a7 as MarketSummary, ap as MatchConfidenceTier, q as MatchGroup, al as MatchGroupEntry, am as MatchGroupMarket, p as MatchGroupPage, aq as MatchMarketFlat, s as MatchMarketPage, r as MatchMarketParams, an as MatchSortField, ak as MatchStatus, M as MatchesParams, ao as MatchesStats, a$ as NEG_RISK_CTF_EXCHANGE_ADDRESS, b4 as ORDER_TYPE, bb as OrderMessage, ab as OrderSide, aa as OrderStatus, O as Orderbook, a4 as OrderbookLevel, b1 as POLYGON_CHAIN_ID, aY as PolymarketL2Headers, aX as PolymarketL2HeadersInput, ad as PolymarketOrderType, l as PositionsResponse, P as PredictClient, c as PredictEvent, f as PredictMarket, n as PredictOrder, b as PredictPage, a9 as PredictPosition, $ as PredictTag, h as PredictTrade, a as PredictWsClient, Z as PredictWsClientConfig, i as PriceHistoryRange, j as PriceHistoryResponse, a8 as PricePoint, _ as ProviderMeta, d as ProviderSource, aH as ResolveEventsParamsInput, b5 as SIDE, a0 as SettlementSource, bc as SignedOrder, S as SimilarEventsParams, aI as TagSlugSelection, a5 as TradeType, b0 as USDC_ADDRESS, aj as UnsignedTx, ar as WsChannel, as as WsChannelEvent, at as WsClientMessage, K as WsConnectionStatus, N as WsDataMessage, az as WsErrorCode, aA as WsErrorMessage, R as WsOrderbookEvent, av as WsPingMessage, ax as WsPongMessage, Q as WsPriceEvent, aw as WsServerMessage, au as WsSubscribeMessage, ay as WsSubscribedMessage, U as WsTradeEvent, aS as buildClobAuthMessage, b8 as buildClobPayload, b2 as buildCtfExchangeDomain, b6 as buildOrderMessage, aU as buildPolymarketL2Headers, b7 as buildSignedOrder, X as createPredictClient, Y as createPredictWsClient, aV as derivePolymarketApiKey, aB as eventQueryKey, aC as fetchEvent, aG as fetchEventsPage, aK as fetchMarket, aP as fetchMatchMarketsPage, aN as fetchMatchesPage, aT as hmacSha256Base64, aF as infiniteEventsQueryKey, aJ as marketQueryKey, aO as matchMarketsQueryKey, aM as matchQueryKey, aL as matchesQueryKey, aE as resolveEventsParams, aD as resolveTagSlug } from './server-CYqs2N2z.js';
|
package/dist/server.js
CHANGED
|
@@ -281,6 +281,11 @@ var PredictClient = class {
|
|
|
281
281
|
const url = `${this.endpoint}/api/v1/orders/polymarket`;
|
|
282
282
|
return await utils.httpPost(url, input, { headers });
|
|
283
283
|
}
|
|
284
|
+
/** Maps to `GET /api/v1/polymarket/tick-size?token_id=xxx`. */
|
|
285
|
+
async getPolymarketTickSize(tokenId) {
|
|
286
|
+
const url = `${this.endpoint}/api/v1/polymarket/tick-size?token_id=${encodeURIComponent(tokenId)}`;
|
|
287
|
+
return await utils.httpGet(url);
|
|
288
|
+
}
|
|
284
289
|
// -------------------------------------------------------------------------
|
|
285
290
|
// DFlow trading
|
|
286
291
|
// -------------------------------------------------------------------------
|
|
@@ -921,20 +926,20 @@ var ORDER_TYPE = {
|
|
|
921
926
|
// Fill-And-Kill
|
|
922
927
|
};
|
|
923
928
|
var SIDE = { BUY: 0, SELL: 1 };
|
|
924
|
-
var
|
|
925
|
-
"0.1": 1,
|
|
926
|
-
"0.01": 2,
|
|
927
|
-
"0.001": 3,
|
|
928
|
-
"0.0001": 4
|
|
929
|
+
var ROUNDING_CONFIG = {
|
|
930
|
+
"0.1": { size: 2, price: 1, amount: 3 },
|
|
931
|
+
"0.01": { size: 2, price: 2, amount: 4 },
|
|
932
|
+
"0.001": { size: 3, price: 3, amount: 6 },
|
|
933
|
+
"0.0001": { size: 4, price: 4, amount: 8 }
|
|
929
934
|
};
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
return
|
|
935
|
+
var DEFAULT_ROUNDING = { size: 2, price: 2, amount: 4 };
|
|
936
|
+
function decimalPlaces(n, d) {
|
|
937
|
+
return parseFloat(n.toFixed(d));
|
|
933
938
|
}
|
|
934
939
|
function toMicroUsdc(amount) {
|
|
935
940
|
return BigInt(Math.round(amount * 1e6));
|
|
936
941
|
}
|
|
937
|
-
function
|
|
942
|
+
function truncateMicro(raw, maxDecimals) {
|
|
938
943
|
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
939
944
|
return raw / factor * factor;
|
|
940
945
|
}
|
|
@@ -946,12 +951,16 @@ function normalizeTokenId(tokenId) {
|
|
|
946
951
|
}
|
|
947
952
|
function buildOrderMessage(input) {
|
|
948
953
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
949
|
-
const
|
|
950
|
-
const
|
|
951
|
-
const
|
|
952
|
-
const
|
|
953
|
-
const
|
|
954
|
-
const
|
|
954
|
+
const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
|
|
955
|
+
const rawPrice = decimalPlaces(input.price, rc.price);
|
|
956
|
+
const rawSize = decimalPlaces(input.size, rc.size);
|
|
957
|
+
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
958
|
+
const sizeInMicro = toMicroUsdc(rawSize);
|
|
959
|
+
const amountInMicro = toMicroUsdc(rawAmount);
|
|
960
|
+
const usdcMicro = truncateMicro(amountInMicro, 2);
|
|
961
|
+
const sharesMicro = truncateMicro(sizeInMicro, 4);
|
|
962
|
+
const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
|
|
963
|
+
const takerAmount = side === SIDE.BUY ? sharesMicro.toString() : usdcMicro.toString();
|
|
955
964
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
956
965
|
return {
|
|
957
966
|
salt: Math.floor(Math.random() * 1e15).toString(),
|