@theliem/xmarket-sdk 3.4.1 → 3.4.2
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 +28 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1901,20 +1901,35 @@ ${logs.join("\n")}`);
|
|
|
1901
1901
|
} else {
|
|
1902
1902
|
throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
|
|
1903
1903
|
}
|
|
1904
|
-
const
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1904
|
+
const budget = BigInt(buySignedOrder.order.makerAmount.toString());
|
|
1905
|
+
const totalAsk = sellCandidates.reduce(
|
|
1906
|
+
(s, m) => s + BigInt(m.order.takerAmount.toString()),
|
|
1907
|
+
BigInt(0)
|
|
1908
|
+
);
|
|
1909
|
+
let finalSells;
|
|
1910
|
+
if (budget >= totalAsk) {
|
|
1911
|
+
finalSells = sellCandidates;
|
|
1912
|
+
} else {
|
|
1913
|
+
const sorted = [...sellCandidates].sort((a, b) => {
|
|
1914
|
+
const pa = BigInt(a.order.takerAmount.toString()) * BigInt(b.order.makerAmount.toString());
|
|
1915
|
+
const pb = BigInt(b.order.takerAmount.toString()) * BigInt(a.order.makerAmount.toString());
|
|
1916
|
+
return pa < pb ? -1 : pa > pb ? 1 : 0;
|
|
1917
|
+
});
|
|
1918
|
+
finalSells = [];
|
|
1919
|
+
let remaining = budget;
|
|
1920
|
+
for (const s of sorted) {
|
|
1921
|
+
const cost = BigInt(s.order.takerAmount.toString());
|
|
1922
|
+
if (remaining >= cost) {
|
|
1923
|
+
finalSells.push(s);
|
|
1924
|
+
remaining -= cost;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
if (finalSells.length === 0) {
|
|
1928
|
+
throw new InvalidParamError("COMPLEMENTARY: taker budget insufficient for any maker");
|
|
1929
|
+
}
|
|
1930
|
+
console.warn(`[matchOrders] budget ${budget} < totalAsk ${totalAsk}: matched ${finalSells.length}/${sellCandidates.length} makers`);
|
|
1916
1931
|
}
|
|
1917
|
-
return this.matchComplementary(buySignedOrder,
|
|
1932
|
+
return this.matchComplementary(buySignedOrder, finalSells, collateralMint, feeRecipient, operatorWallet, alt, opts);
|
|
1918
1933
|
}
|
|
1919
1934
|
const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
|
|
1920
1935
|
const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
|