@liberfi.io/react-predict 0.1.40 → 0.1.42

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.js CHANGED
@@ -1862,10 +1862,13 @@ function decimalPlaces(n, d) {
1862
1862
  function toMicroUsdc(amount) {
1863
1863
  return BigInt(Math.round(amount * 1e6));
1864
1864
  }
1865
- function roundMicro(raw, maxDecimals) {
1865
+ function ceilMicro(raw, maxDecimals) {
1866
1866
  const factor = BigInt(10 ** (6 - maxDecimals));
1867
- const half = factor / 2n;
1868
- return (raw + half) / factor * factor;
1867
+ return (raw + factor - 1n) / factor * factor;
1868
+ }
1869
+ function floorMicro(raw, maxDecimals) {
1870
+ const factor = BigInt(10 ** (6 - maxDecimals));
1871
+ return raw / factor * factor;
1869
1872
  }
1870
1873
  function normalizeTokenId(tokenId) {
1871
1874
  if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
@@ -1881,8 +1884,8 @@ function buildOrderMessage(input) {
1881
1884
  const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
1882
1885
  const sizeInMicro = toMicroUsdc(rawSize);
1883
1886
  const amountInMicro = toMicroUsdc(rawAmount);
1884
- const usdcMicro = roundMicro(amountInMicro, 2);
1885
- const sharesMicro = roundMicro(sizeInMicro, 4);
1887
+ const usdcMicro = side === SIDE.BUY ? ceilMicro(amountInMicro, 2) : floorMicro(amountInMicro, 2);
1888
+ const sharesMicro = floorMicro(sizeInMicro, 4);
1886
1889
  const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
1887
1890
  const takerAmount = side === SIDE.BUY ? sharesMicro.toString() : usdcMicro.toString();
1888
1891
  const maker = input.funderAddress ?? input.signerAddress;