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