@liberfi.io/react-predict 0.1.52 → 0.1.54

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.mjs CHANGED
@@ -2006,6 +2006,16 @@ function floorDecimalPlaces(n, d) {
2006
2006
  const factor = 10 ** d;
2007
2007
  return Math.floor(n * factor) / factor;
2008
2008
  }
2009
+ function ceilDecimalPlaces(n, d) {
2010
+ const factor = 10 ** d;
2011
+ return Math.ceil(n * factor) / factor;
2012
+ }
2013
+ function countDecimalPlaces(n) {
2014
+ const s = n.toString();
2015
+ const dot = s.indexOf(".");
2016
+ if (dot === -1) return 0;
2017
+ return s.length - dot - 1;
2018
+ }
2009
2019
  function toMicroUsdc(amount) {
2010
2020
  return BigInt(Math.round(amount * 1e6));
2011
2021
  }
@@ -2015,16 +2025,48 @@ function normalizeTokenId(tokenId) {
2015
2025
  }
2016
2026
  return tokenId;
2017
2027
  }
2018
- function buildOrderMessage(input) {
2019
- const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
2020
- const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
2021
- const rawPrice = decimalPlaces(input.price, rc.price);
2022
- const rawSize = side === SIDE.SELL ? floorDecimalPlaces(input.size, rc.size) : decimalPlaces(input.size, rc.size);
2028
+ var MARKET_MAKER_MAX_DECIMALS = 2;
2029
+ var MARKET_TAKER_MAX_DECIMALS = 4;
2030
+ function getMarketOrderAmounts(side, size, price, rc) {
2031
+ const rawPrice = decimalPlaces(price, rc.price);
2032
+ const makerDecimals = Math.min(rc.size, MARKET_MAKER_MAX_DECIMALS);
2033
+ const takerDecimals = Math.min(rc.amount, MARKET_TAKER_MAX_DECIMALS);
2034
+ if (side === SIDE.BUY) {
2035
+ const rawMakerAmt2 = floorDecimalPlaces(size, makerDecimals);
2036
+ let rawTakerAmt2 = rawMakerAmt2 / rawPrice;
2037
+ if (countDecimalPlaces(rawTakerAmt2) > takerDecimals) {
2038
+ rawTakerAmt2 = floorDecimalPlaces(rawTakerAmt2, takerDecimals);
2039
+ }
2040
+ return {
2041
+ makerAmount: toMicroUsdc(rawMakerAmt2).toString(),
2042
+ takerAmount: toMicroUsdc(rawTakerAmt2).toString()
2043
+ };
2044
+ }
2045
+ const rawMakerAmt = floorDecimalPlaces(size, makerDecimals);
2046
+ let rawTakerAmt = rawMakerAmt * rawPrice;
2047
+ if (countDecimalPlaces(rawTakerAmt) > takerDecimals) {
2048
+ rawTakerAmt = ceilDecimalPlaces(rawTakerAmt, takerDecimals);
2049
+ }
2050
+ return {
2051
+ makerAmount: toMicroUsdc(rawMakerAmt).toString(),
2052
+ takerAmount: toMicroUsdc(rawTakerAmt).toString()
2053
+ };
2054
+ }
2055
+ function getLimitOrderAmounts(side, size, price, rc) {
2056
+ const rawPrice = decimalPlaces(price, rc.price);
2057
+ const rawSize = side === SIDE.SELL ? floorDecimalPlaces(size, rc.size) : decimalPlaces(size, rc.size);
2023
2058
  const sizeInMicro = toMicroUsdc(rawSize);
2024
2059
  const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
2025
2060
  const amountInMicro = toMicroUsdc(rawAmount);
2026
2061
  const makerAmount = side === SIDE.BUY ? amountInMicro.toString() : sizeInMicro.toString();
2027
2062
  const takerAmount = side === SIDE.BUY ? sizeInMicro.toString() : amountInMicro.toString();
2063
+ return { makerAmount, takerAmount };
2064
+ }
2065
+ function buildOrderMessage(input) {
2066
+ const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
2067
+ const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
2068
+ const isMarketOrder = input.orderType === "FOK" || input.orderType === "FAK";
2069
+ const { makerAmount, takerAmount } = isMarketOrder ? getMarketOrderAmounts(side, input.size, input.price, rc) : getLimitOrderAmounts(side, input.size, input.price, rc);
2028
2070
  const maker = input.funderAddress ?? input.signerAddress;
2029
2071
  return {
2030
2072
  salt: Math.floor(Math.random() * 1e15).toString(),
@@ -2139,6 +2181,9 @@ function useCreatePolymarketOrder(mutationOptions = {}) {
2139
2181
  }
2140
2182
  function computeOrderCost(input) {
2141
2183
  if (input.side === "SELL") return "0";
2184
+ if (input.orderType === "FOK" || input.orderType === "FAK") {
2185
+ return input.size.toFixed(6);
2186
+ }
2142
2187
  return (input.price * input.size).toFixed(6);
2143
2188
  }
2144
2189
  async function pollTxConfirmed(fetchStatus, txHash) {