@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.mjs
CHANGED
|
@@ -1875,20 +1875,35 @@ ${logs.join("\n")}`);
|
|
|
1875
1875
|
} else {
|
|
1876
1876
|
throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
|
|
1877
1877
|
}
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1878
|
+
const budget = BigInt(buySignedOrder.order.makerAmount.toString());
|
|
1879
|
+
const totalAsk = sellCandidates.reduce(
|
|
1880
|
+
(s, m) => s + BigInt(m.order.takerAmount.toString()),
|
|
1881
|
+
BigInt(0)
|
|
1882
|
+
);
|
|
1883
|
+
let finalSells;
|
|
1884
|
+
if (budget >= totalAsk) {
|
|
1885
|
+
finalSells = sellCandidates;
|
|
1886
|
+
} else {
|
|
1887
|
+
const sorted = [...sellCandidates].sort((a, b) => {
|
|
1888
|
+
const pa = BigInt(a.order.takerAmount.toString()) * BigInt(b.order.makerAmount.toString());
|
|
1889
|
+
const pb = BigInt(b.order.takerAmount.toString()) * BigInt(a.order.makerAmount.toString());
|
|
1890
|
+
return pa < pb ? -1 : pa > pb ? 1 : 0;
|
|
1891
|
+
});
|
|
1892
|
+
finalSells = [];
|
|
1893
|
+
let remaining = budget;
|
|
1894
|
+
for (const s of sorted) {
|
|
1895
|
+
const cost = BigInt(s.order.takerAmount.toString());
|
|
1896
|
+
if (remaining >= cost) {
|
|
1897
|
+
finalSells.push(s);
|
|
1898
|
+
remaining -= cost;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
if (finalSells.length === 0) {
|
|
1902
|
+
throw new InvalidParamError("COMPLEMENTARY: taker budget insufficient for any maker");
|
|
1903
|
+
}
|
|
1904
|
+
console.warn(`[matchOrders] budget ${budget} < totalAsk ${totalAsk}: matched ${finalSells.length}/${sellCandidates.length} makers`);
|
|
1890
1905
|
}
|
|
1891
|
-
return this.matchComplementary(buySignedOrder,
|
|
1906
|
+
return this.matchComplementary(buySignedOrder, finalSells, collateralMint, feeRecipient, operatorWallet, alt, opts);
|
|
1892
1907
|
}
|
|
1893
1908
|
const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
|
|
1894
1909
|
const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
|