@theliem/xmarket-sdk 3.6.0 → 3.6.1

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 CHANGED
@@ -1879,18 +1879,20 @@ ${logs.join("\n")}`);
1879
1879
  ...buyMakers.map((m) => this.registerOrderIfNeeded(m))
1880
1880
  ]);
1881
1881
  const sell = sellTaker.order;
1882
- const crossingBuys = buyMakers.filter((b) => {
1883
- const buy = b.order;
1884
- const lhs = BigInt(buy.makerAmount.toString()) * BigInt(sell.makerAmount.toString());
1885
- const rhs = BigInt(buy.takerAmount.toString()) * BigInt(sell.takerAmount.toString());
1886
- return lhs >= rhs;
1887
- });
1888
- if (crossingBuys.length === 0) {
1889
- throw new InvalidParamError("COMPLEMENTARY: no BUY maker orders cross with the SELL taker");
1882
+ if (buyMakers.length === 0) {
1883
+ throw new InvalidParamError("COMPLEMENTARY: no BUY maker orders provided");
1890
1884
  }
1891
- if (crossingBuys.length < buyMakers.length) {
1892
- console.warn(`[matchOrders] SELL+BUY: filtered ${buyMakers.length - crossingBuys.length} non-crossing BUY(s)`);
1885
+ const totalBuyPayment = buyMakers.reduce(
1886
+ (acc, b) => acc + BigInt(b.order.makerAmount.toString()),
1887
+ BigInt(0)
1888
+ );
1889
+ const sellExpected = BigInt(sell.takerAmount.toString());
1890
+ if (totalBuyPayment < sellExpected) {
1891
+ throw new InvalidParamError(
1892
+ `COMPLEMENTARY: total buyer payments ${totalBuyPayment} < seller expected ${sellExpected}`
1893
+ );
1893
1894
  }
1895
+ const crossingBuys = buyMakers;
1894
1896
  const allIxs = [];
1895
1897
  for (const buyMaker of crossingBuys) {
1896
1898
  const ixs = await this.buildMatchComplementaryIxs(