@liberfi.io/react-predict 0.1.38 → 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.mjs CHANGED
@@ -1860,6 +1860,10 @@ function decimalPlaces(n, d) {
1860
1860
  function toMicroUsdc(amount) {
1861
1861
  return BigInt(Math.round(amount * 1e6));
1862
1862
  }
1863
+ function truncateMicro(raw, maxDecimals) {
1864
+ const factor = BigInt(10 ** (6 - maxDecimals));
1865
+ return raw / factor * factor;
1866
+ }
1863
1867
  function normalizeTokenId(tokenId) {
1864
1868
  if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
1865
1869
  return BigInt(tokenId).toString(10);
@@ -1874,8 +1878,10 @@ function buildOrderMessage(input) {
1874
1878
  const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
1875
1879
  const sizeInMicro = toMicroUsdc(rawSize);
1876
1880
  const amountInMicro = toMicroUsdc(rawAmount);
1877
- const makerAmount = side === SIDE.BUY ? amountInMicro.toString() : sizeInMicro.toString();
1878
- const takerAmount = side === SIDE.BUY ? sizeInMicro.toString() : amountInMicro.toString();
1881
+ const usdcMicro = truncateMicro(amountInMicro, 2);
1882
+ const sharesMicro = truncateMicro(sizeInMicro, 4);
1883
+ const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
1884
+ const takerAmount = side === SIDE.BUY ? sharesMicro.toString() : usdcMicro.toString();
1879
1885
  const maker = input.funderAddress ?? input.signerAddress;
1880
1886
  return {
1881
1887
  salt: Math.floor(Math.random() * 1e15).toString(),