@theliem/xmarket-sdk 3.6.0 → 3.7.0
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.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +36 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -605,9 +605,8 @@ declare class ClobClient {
|
|
|
605
605
|
private matchComplementary;
|
|
606
606
|
/**
|
|
607
607
|
* 1 SELL taker vs N BUY makers.
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
* Engine must use limitPrice for BUY.makerAmount to pass per-pair crossing check.
|
|
608
|
+
* Program now supports SELL-as-taker natively → 1 instruction with all BUY makers
|
|
609
|
+
* in remaining_accounts (same structure as BUY taker case).
|
|
611
610
|
*/
|
|
612
611
|
private matchComplementarySellVsMultiBuy;
|
|
613
612
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -605,9 +605,8 @@ declare class ClobClient {
|
|
|
605
605
|
private matchComplementary;
|
|
606
606
|
/**
|
|
607
607
|
* 1 SELL taker vs N BUY makers.
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
* Engine must use limitPrice for BUY.makerAmount to pass per-pair crossing check.
|
|
608
|
+
* Program now supports SELL-as-taker natively → 1 instruction with all BUY makers
|
|
609
|
+
* in remaining_accounts (same structure as BUY taker case).
|
|
611
610
|
*/
|
|
612
611
|
private matchComplementarySellVsMultiBuy;
|
|
613
612
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1869,45 +1869,38 @@ ${logs.join("\n")}`);
|
|
|
1869
1869
|
}
|
|
1870
1870
|
/**
|
|
1871
1871
|
* 1 SELL taker vs N BUY makers.
|
|
1872
|
-
*
|
|
1873
|
-
*
|
|
1874
|
-
* Engine must use limitPrice for BUY.makerAmount to pass per-pair crossing check.
|
|
1872
|
+
* Program now supports SELL-as-taker natively → 1 instruction with all BUY makers
|
|
1873
|
+
* in remaining_accounts (same structure as BUY taker case).
|
|
1875
1874
|
*/
|
|
1876
1875
|
async matchComplementarySellVsMultiBuy(sellTaker, buyMakers, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
|
|
1876
|
+
if (buyMakers.length === 0) {
|
|
1877
|
+
throw new InvalidParamError("COMPLEMENTARY: no BUY maker orders provided");
|
|
1878
|
+
}
|
|
1879
|
+
const sell = sellTaker.order;
|
|
1880
|
+
const totalBuyPayment = buyMakers.reduce(
|
|
1881
|
+
(acc, b) => acc + BigInt(b.order.makerAmount.toString()),
|
|
1882
|
+
BigInt(0)
|
|
1883
|
+
);
|
|
1884
|
+
const sellExpected = BigInt(sell.takerAmount.toString());
|
|
1885
|
+
if (totalBuyPayment < sellExpected) {
|
|
1886
|
+
throw new InvalidParamError(
|
|
1887
|
+
`COMPLEMENTARY: total buyer payments ${totalBuyPayment} < seller expected ${sellExpected}`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1877
1890
|
await Promise.all([
|
|
1878
1891
|
this.registerOrderIfNeeded(sellTaker),
|
|
1879
1892
|
...buyMakers.map((m) => this.registerOrderIfNeeded(m))
|
|
1880
1893
|
]);
|
|
1881
|
-
const
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
if (crossingBuys.length < buyMakers.length) {
|
|
1892
|
-
console.warn(`[matchOrders] SELL+BUY: filtered ${buyMakers.length - crossingBuys.length} non-crossing BUY(s)`);
|
|
1893
|
-
}
|
|
1894
|
-
const allIxs = [];
|
|
1895
|
-
for (const buyMaker of crossingBuys) {
|
|
1896
|
-
const ixs = await this.buildMatchComplementaryIxs(
|
|
1897
|
-
buyMaker,
|
|
1898
|
-
// BUY as taker
|
|
1899
|
-
[sellTaker],
|
|
1900
|
-
// SELL as maker
|
|
1901
|
-
collateralMint,
|
|
1902
|
-
feeRecipient,
|
|
1903
|
-
operatorWallet.publicKey,
|
|
1904
|
-
opts,
|
|
1905
|
-
true
|
|
1906
|
-
// useTakerPrice: SELL gets filled at BUY's price (maker's price per doc)
|
|
1907
|
-
);
|
|
1908
|
-
allIxs.push(...ixs);
|
|
1909
|
-
}
|
|
1910
|
-
const sig = await this.sendMatchTx(allIxs, lookupTable, operatorWallet);
|
|
1894
|
+
const ixs = await this.buildMatchComplementaryIxs(
|
|
1895
|
+
sellTaker,
|
|
1896
|
+
buyMakers,
|
|
1897
|
+
collateralMint,
|
|
1898
|
+
feeRecipient,
|
|
1899
|
+
operatorWallet.publicKey,
|
|
1900
|
+
opts,
|
|
1901
|
+
false
|
|
1902
|
+
);
|
|
1903
|
+
const sig = await this.sendMatchTx(ixs, lookupTable, operatorWallet);
|
|
1911
1904
|
return { signature: sig };
|
|
1912
1905
|
}
|
|
1913
1906
|
/**
|
|
@@ -2150,18 +2143,17 @@ ${logs.join("\n")}`);
|
|
|
2150
2143
|
throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
|
|
2151
2144
|
}
|
|
2152
2145
|
const buy = buySignedOrder.order;
|
|
2153
|
-
const
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
if (finalSells.length < sellCandidates.length) {
|
|
2163
|
-
console.warn(`[matchOrders] filtered ${sellCandidates.length - finalSells.length} non-crossing maker(s)`);
|
|
2146
|
+
const totalSellDemand = sellCandidates.reduce(
|
|
2147
|
+
(acc, s) => acc + BigInt(s.order.takerAmount.toString()),
|
|
2148
|
+
BigInt(0)
|
|
2149
|
+
);
|
|
2150
|
+
const buyBudget = BigInt(buy.makerAmount.toString());
|
|
2151
|
+
if (buyBudget < totalSellDemand) {
|
|
2152
|
+
throw new InvalidParamError(
|
|
2153
|
+
`COMPLEMENTARY: total sell demand ${totalSellDemand} > buy budget ${buyBudget}. Build taker order with limitPrice, not averageMatchedPrice.`
|
|
2154
|
+
);
|
|
2164
2155
|
}
|
|
2156
|
+
const finalSells = sellCandidates;
|
|
2165
2157
|
return this.matchComplementary(buySignedOrder, finalSells, collateralMint, feeRecipient, operatorWallet, alt, opts);
|
|
2166
2158
|
}
|
|
2167
2159
|
const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
|