@liberfi.io/react-predict 0.1.35 → 0.1.37
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 +8 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -4
- package/dist/index.mjs.map +1 -1
- package/dist/server.js +8 -4
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +8 -4
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1842,6 +1842,10 @@ function roundToTick(price, tickSize) {
|
|
|
1842
1842
|
function toMicroUsdc(amount) {
|
|
1843
1843
|
return BigInt(Math.round(amount * 1e6));
|
|
1844
1844
|
}
|
|
1845
|
+
function truncateToDecimals(raw, maxDecimals) {
|
|
1846
|
+
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1847
|
+
return raw / factor * factor;
|
|
1848
|
+
}
|
|
1845
1849
|
function normalizeTokenId(tokenId) {
|
|
1846
1850
|
if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
|
|
1847
1851
|
return BigInt(tokenId).toString(10);
|
|
@@ -1852,10 +1856,10 @@ function buildOrderMessage(input) {
|
|
|
1852
1856
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
1853
1857
|
const priceStr = roundToTick(input.price, input.tickSize);
|
|
1854
1858
|
const priceNum = parseFloat(priceStr);
|
|
1855
|
-
const
|
|
1856
|
-
const
|
|
1857
|
-
const makerAmount = side === SIDE.BUY ?
|
|
1858
|
-
const takerAmount = side === SIDE.BUY ?
|
|
1859
|
+
const rawShares = toMicroUsdc(input.size);
|
|
1860
|
+
const rawUsdc = toMicroUsdc(input.size * priceNum);
|
|
1861
|
+
const makerAmount = side === SIDE.BUY ? truncateToDecimals(rawUsdc, 2).toString() : truncateToDecimals(rawShares, 4).toString();
|
|
1862
|
+
const takerAmount = side === SIDE.BUY ? truncateToDecimals(rawShares, 4).toString() : truncateToDecimals(rawUsdc, 2).toString();
|
|
1859
1863
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
1860
1864
|
return {
|
|
1861
1865
|
salt: Math.floor(Math.random() * 1e15).toString(),
|