@theliem/xmarket-sdk 3.6.1 → 3.8.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.mjs CHANGED
@@ -1750,7 +1750,7 @@ ${logs.join("\n")}`);
1750
1750
  * [extraAccountMetaList, hookConfig, hookProgram]
1751
1751
  * [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
1752
1752
  */
1753
- async buildMatchComplementaryIxs(takerSigned, makersSigned, collateralMint, feeRecipient, operator, opts, useTakerPrice = false) {
1753
+ async buildMatchComplementaryIxs(takerSigned, makersSigned, collateralMint, feeRecipient, operator, opts, useTakerPrice = false, skipCrossingCheck = true) {
1754
1754
  const condition = takerSigned.order.condition;
1755
1755
  const tokenId = takerSigned.order.tokenId;
1756
1756
  const taker = takerSigned.order.maker;
@@ -1790,17 +1790,21 @@ ${logs.join("\n")}`);
1790
1790
  if (takerSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1791
1791
  const companyAddr = await this.companyAddress();
1792
1792
  if (companyAddr) {
1793
- const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1794
- feeAccounts = [
1795
- { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1796
- { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1797
- { pubkey: PDA.marketFeeOverride(condition, this.programIds)[0], isSigner: false, isWritable: false },
1798
- { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1799
- { pubkey: oracleVault, isSigner: false, isWritable: true }
1800
- ];
1793
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
1794
+ const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
1795
+ if (feeOverrideExists) {
1796
+ const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1797
+ feeAccounts = [
1798
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1799
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1800
+ { pubkey: feeOverridePda, isSigner: false, isWritable: false },
1801
+ { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1802
+ { pubkey: oracleVault, isSigner: false, isWritable: true }
1803
+ ];
1804
+ }
1801
1805
  }
1802
1806
  }
1803
- const matchIx = await this.program.methods.matchComplementary(takerNonce, fillAmount, useTakerPrice).accounts({
1807
+ const matchIx = await this.program.methods.matchComplementary(takerNonce, fillAmount, useTakerPrice, skipCrossingCheck).accounts({
1804
1808
  operator,
1805
1809
  payer: this.walletPubkey,
1806
1810
  clobConfig: this.configPda(),
@@ -1843,19 +1847,14 @@ ${logs.join("\n")}`);
1843
1847
  }
1844
1848
  /**
1845
1849
  * 1 SELL taker vs N BUY makers.
1846
- * Rust program only supports BUY-as-taker, so we decompose into N instructions
1847
- * (BUY_i as taker, SELL as single maker) combined into one atomic transaction.
1848
- * Engine must use limitPrice for BUY.makerAmount to pass per-pair crossing check.
1850
+ * Program now supports SELL-as-taker natively 1 instruction with all BUY makers
1851
+ * in remaining_accounts (same structure as BUY taker case).
1849
1852
  */
1850
1853
  async matchComplementarySellVsMultiBuy(sellTaker, buyMakers, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1851
- await Promise.all([
1852
- this.registerOrderIfNeeded(sellTaker),
1853
- ...buyMakers.map((m) => this.registerOrderIfNeeded(m))
1854
- ]);
1855
- const sell = sellTaker.order;
1856
1854
  if (buyMakers.length === 0) {
1857
1855
  throw new InvalidParamError("COMPLEMENTARY: no BUY maker orders provided");
1858
1856
  }
1857
+ const sell = sellTaker.order;
1859
1858
  const totalBuyPayment = buyMakers.reduce(
1860
1859
  (acc, b) => acc + BigInt(b.order.makerAmount.toString()),
1861
1860
  BigInt(0)
@@ -1866,24 +1865,20 @@ ${logs.join("\n")}`);
1866
1865
  `COMPLEMENTARY: total buyer payments ${totalBuyPayment} < seller expected ${sellExpected}`
1867
1866
  );
1868
1867
  }
1869
- const crossingBuys = buyMakers;
1870
- const allIxs = [];
1871
- for (const buyMaker of crossingBuys) {
1872
- const ixs = await this.buildMatchComplementaryIxs(
1873
- buyMaker,
1874
- // BUY as taker
1875
- [sellTaker],
1876
- // SELL as maker
1877
- collateralMint,
1878
- feeRecipient,
1879
- operatorWallet.publicKey,
1880
- opts,
1881
- true
1882
- // useTakerPrice: SELL gets filled at BUY's price (maker's price per doc)
1883
- );
1884
- allIxs.push(...ixs);
1885
- }
1886
- const sig = await this.sendMatchTx(allIxs, lookupTable, operatorWallet);
1868
+ await Promise.all([
1869
+ this.registerOrderIfNeeded(sellTaker),
1870
+ ...buyMakers.map((m) => this.registerOrderIfNeeded(m))
1871
+ ]);
1872
+ const ixs = await this.buildMatchComplementaryIxs(
1873
+ sellTaker,
1874
+ buyMakers,
1875
+ collateralMint,
1876
+ feeRecipient,
1877
+ operatorWallet.publicKey,
1878
+ opts,
1879
+ false
1880
+ );
1881
+ const sig = await this.sendMatchTx(ixs, lookupTable, operatorWallet);
1887
1882
  return { signature: sig };
1888
1883
  }
1889
1884
  /**
@@ -2125,19 +2120,7 @@ ${logs.join("\n")}`);
2125
2120
  } else {
2126
2121
  throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
2127
2122
  }
2128
- const buy = buySignedOrder.order;
2129
- const finalSells = sellCandidates.filter((s) => {
2130
- const sell = s.order;
2131
- const lhs = BigInt(buy.makerAmount.toString()) * BigInt(sell.makerAmount.toString());
2132
- const rhs = BigInt(buy.takerAmount.toString()) * BigInt(sell.takerAmount.toString());
2133
- return lhs >= rhs;
2134
- });
2135
- if (finalSells.length === 0) {
2136
- throw new InvalidParamError("COMPLEMENTARY: no maker orders cross with the buy order");
2137
- }
2138
- if (finalSells.length < sellCandidates.length) {
2139
- console.warn(`[matchOrders] filtered ${sellCandidates.length - finalSells.length} non-crossing maker(s)`);
2140
- }
2123
+ const finalSells = sellCandidates;
2141
2124
  return this.matchComplementary(buySignedOrder, finalSells, collateralMint, feeRecipient, operatorWallet, alt, opts);
2142
2125
  }
2143
2126
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
@@ -8838,6 +8821,10 @@ var clob_exchange_default = {
8838
8821
  {
8839
8822
  name: "use_taker_price",
8840
8823
  type: "bool"
8824
+ },
8825
+ {
8826
+ name: "skip_crossing_check",
8827
+ type: "bool"
8841
8828
  }
8842
8829
  ]
8843
8830
  },