@triadxyz/triad-protocol 3.3.4-beta → 3.3.5-beta

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.ts CHANGED
@@ -330,7 +330,7 @@ export default class TriadProtocol {
330
330
  /**
331
331
  * Get User Trade Ixs
332
332
  */
333
- getUserTradeIxs(): Promise<{
333
+ getUserTradeIxs(wallet: PublicKey): Promise<{
334
334
  userTradePDA: PublicKey;
335
335
  ixs: TransactionInstruction[];
336
336
  nonce: number;
@@ -344,7 +344,7 @@ export default class TriadProtocol {
344
344
  * @param marketId - The ID of the Market
345
345
  * @param orderDirection - The direction of the Order
346
346
  */
347
- getUserTradeNonce(marketId: number, orderDirection: OrderDirection): Promise<{
347
+ getUserTradeNonce(wallet: PublicKey, marketId: number, orderDirection: OrderDirection): Promise<{
348
348
  userTradePDA: PublicKey;
349
349
  userTradeIxs: TransactionInstruction[];
350
350
  }>;
package/dist/index.js CHANGED
@@ -527,7 +527,7 @@ class TriadProtocol {
527
527
  return __awaiter(this, void 0, void 0, function* () {
528
528
  const ixs = [];
529
529
  const addressLookupTableAccounts = [];
530
- const { userTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs();
530
+ const { userTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs(this.program.provider.publicKey);
531
531
  if (userTradeIxs.length > 0) {
532
532
  ixs.push(...userTradeIxs);
533
533
  }
@@ -660,21 +660,21 @@ class TriadProtocol {
660
660
  /**
661
661
  * Get User Trade Ixs
662
662
  */
663
- getUserTradeIxs() {
663
+ getUserTradeIxs(wallet) {
664
664
  return __awaiter(this, void 0, void 0, function* () {
665
665
  const ixs = [];
666
666
  let myUserTrades = [];
667
- myUserTrades = yield this.getMyUserTrades(this.program.provider.publicKey);
667
+ myUserTrades = yield this.getMyUserTrades(wallet);
668
668
  if (myUserTrades.length === 0) {
669
669
  ixs.push(yield this.program.methods
670
670
  .createUserTrade()
671
671
  .accounts({
672
- signer: this.program.provider.publicKey,
672
+ signer: wallet,
673
673
  payer: this.rpcOptions.payer
674
674
  })
675
675
  .instruction());
676
676
  return {
677
- userTradePDA: this.getUserPDA(this.program.provider.publicKey),
677
+ userTradePDA: this.getUserPDA(wallet),
678
678
  ixs,
679
679
  nonce: 0
680
680
  };
@@ -695,17 +695,17 @@ class TriadProtocol {
695
695
  throw new Error('No open orders found');
696
696
  }
697
697
  return {
698
- userTradePDA: this.getUserPDA(this.program.provider.publicKey, nonce),
698
+ userTradePDA: this.getUserPDA(wallet, nonce),
699
699
  ixs
700
700
  };
701
701
  }
702
702
  catch (_a) {
703
703
  const mainUserTrade = myUserTrades.find((trade) => !trade.isSubUser);
704
- const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, this.program.provider.publicKey, Number(mainUserTrade.nonce) + 1);
704
+ const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, wallet, Number(mainUserTrade.nonce) + 1);
705
705
  ixs.push(yield this.program.methods
706
706
  .createSubUserTrade(subUserTradePDA)
707
707
  .accounts({
708
- signer: this.program.provider.publicKey,
708
+ signer: wallet,
709
709
  payer: this.rpcOptions.payer
710
710
  })
711
711
  .instruction());
@@ -721,20 +721,20 @@ class TriadProtocol {
721
721
  * @param marketId - The ID of the Market
722
722
  * @param orderDirection - The direction of the Order
723
723
  */
724
- getUserTradeNonce(marketId, orderDirection) {
724
+ getUserTradeNonce(wallet, marketId, orderDirection) {
725
725
  var _a;
726
726
  return __awaiter(this, void 0, void 0, function* () {
727
- const userOrders = yield this.getUserOrdersByMarketId(this.program.provider.publicKey, marketId);
727
+ const userOrders = yield this.getUserOrdersByMarketId(wallet, marketId);
728
728
  const userNonce = (_a = userOrders.find((order) => order.orderDirection === orderDirection &&
729
729
  order.orderStatus === types_1.OrderStatus.OPEN &&
730
730
  Number(order.marketId) === marketId)) === null || _a === void 0 ? void 0 : _a.userNonce;
731
731
  let userTradePDA = null;
732
732
  let userTradeIxs = [];
733
733
  if (userNonce) {
734
- userTradePDA = this.getUserPDA(this.program.provider.publicKey, Number(userNonce));
734
+ userTradePDA = this.getUserPDA(wallet, Number(userNonce));
735
735
  }
736
736
  if (!userNonce) {
737
- const { userTradePDA: user, ixs: ixsUser } = yield this.getUserTradeIxs();
737
+ const { userTradePDA: user, ixs: ixsUser } = yield this.getUserTradeIxs(wallet);
738
738
  userTradePDA = user;
739
739
  userTradeIxs = ixsUser;
740
740
  }
@@ -908,7 +908,8 @@ class TriadProtocol {
908
908
  const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
909
909
  const ixs = [];
910
910
  const addressLookupTableAccounts = [];
911
- const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(orderDirection)[0]);
911
+ const sellerTradeIxs = [];
912
+ const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(this.program.provider.publicKey, marketId, Object.keys(orderDirection)[0]);
912
913
  const orderBook = yield this.getOrderBook(marketId);
913
914
  let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
914
915
  if (isTrdPayout) {
@@ -986,6 +987,10 @@ class TriadProtocol {
986
987
  .div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)));
987
988
  if (usdcAmount.lte(new bn_js_1.default(0)))
988
989
  continue;
990
+ const { userTradePDA: sellerTradePDA, userTradeIxs: innerSellerTradeIxs } = yield this.getUserTradeNonce(new web3_js_1.PublicKey(order.authority), marketId, Object.keys(orderDirection)[0]);
991
+ if (innerSellerTradeIxs.length > 0 && sellerTradeIxs.length === 0) {
992
+ sellerTradeIxs.push(...innerSellerTradeIxs);
993
+ }
989
994
  ixs.push(yield this.program.methods
990
995
  .marketBidOrder({
991
996
  amount: new bn_js_1.default(usdcAmount),
@@ -999,13 +1004,16 @@ class TriadProtocol {
999
1004
  buyerTrade: userTradePDA,
1000
1005
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
1001
1006
  sellerAuthority: new web3_js_1.PublicKey(order.authority),
1002
- sellerTrade: this.getUserPDA(new web3_js_1.PublicKey(order.authority), Number(order.userNonce)),
1007
+ sellerTrade: sellerTradePDA,
1003
1008
  marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
1004
1009
  buyerAta: (0, pda_1.getTokenATA)(this.program.provider.publicKey, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID)
1005
1010
  })
1006
1011
  .instruction());
1007
1012
  remainingUSDC = remainingUSDC.sub(usdcAmount);
1008
1013
  }
1014
+ if (sellerTradeIxs.length > 0) {
1015
+ ixs.unshift(...sellerTradeIxs);
1016
+ }
1009
1017
  if (userTradeIxs.length > 0) {
1010
1018
  ixs.unshift(...userTradeIxs);
1011
1019
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "3.3.4-beta",
3
+ "version": "3.3.5-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",