@triadxyz/triad-protocol 2.9.9-beta → 3.0.1-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
@@ -387,10 +387,11 @@ export default class TriadProtocolClient {
387
387
  * @param args.direction - The direction of the Order
388
388
  * @param args.mint - The mint of the Order
389
389
  * @param args.price - The price of the Order
390
+ * @param args.isTrdPayout - Whether to payout in TRD or not
390
391
  *
391
392
  * @param options - RPC options
392
393
  */
393
- placeBidOrder({ marketId, amount, direction, mint, price }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
394
+ placeBidOrder({ marketId, amount, direction, mint, price, isTrdPayout }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
394
395
  /**
395
396
  * Place Ask Order
396
397
  * @param args.marketId - The ID of the Market
@@ -410,10 +411,11 @@ export default class TriadProtocolClient {
410
411
  * @param args.orderId - The ID of the Order
411
412
  * @param args.userNonce - The nonce of the user
412
413
  * @param args.direction - The direction of the Order
414
+ * @param args.isTrdPayout - Whether to payout in TRD or not
413
415
  *
414
416
  * @param options - RPC options
415
417
  */
416
- cancelBidOrder({ marketId, orderId, userNonce, mint, direction }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
418
+ cancelBidOrder({ marketId, orderId, userNonce, mint, direction, isTrdPayout, remainingShares, price }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
417
419
  /**
418
420
  * Cancel Ask Order
419
421
  * @param args.marketId - The ID of the Market
package/dist/index.js CHANGED
@@ -735,21 +735,41 @@ class TriadProtocolClient {
735
735
  * @param args.direction - The direction of the Order
736
736
  * @param args.mint - The mint of the Order
737
737
  * @param args.price - The price of the Order
738
+ * @param args.isTrdPayout - Whether to payout in TRD or not
738
739
  *
739
740
  * @param options - RPC options
740
741
  */
741
- placeBidOrder({ marketId, amount, direction, mint, price }, options) {
742
+ placeBidOrder({ marketId, amount, direction, mint, price, isTrdPayout }, options) {
742
743
  return __awaiter(this, void 0, void 0, function* () {
743
744
  const ixs = [];
745
+ const addressLookupTableAccounts = [];
746
+ let amountInUSDC = new bn_js_1.default(amount * Math.pow(10, this.decimals));
747
+ if (isTrdPayout) {
748
+ const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
749
+ connection: this.program.provider.connection,
750
+ wallet: this.program.provider.publicKey.toBase58(),
751
+ inToken: constants_1.TRD_MINT.toString(),
752
+ outToken: constants_1.USDC_MINT.toString(),
753
+ amount: Math.floor(amount)
754
+ });
755
+ if (swapIxs.length === 0) {
756
+ return;
757
+ }
758
+ amountInUSDC = new bn_js_1.default(outAmount);
759
+ ixs.push(...setupInstructions);
760
+ ixs.push(...swapIxs);
761
+ addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
762
+ }
744
763
  const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(direction)[0]);
745
764
  if (userTradeIxs.length > 0) {
746
765
  ixs.push(...userTradeIxs);
747
766
  }
748
767
  ixs.push(yield this.program.methods
749
768
  .placeBidOrder({
750
- amount: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
769
+ amount: amountInUSDC,
751
770
  price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
752
- orderDirection: direction
771
+ orderDirection: direction,
772
+ isTrdPayout
753
773
  })
754
774
  .accounts({
755
775
  signer: this.program.provider.publicKey,
@@ -802,12 +822,14 @@ class TriadProtocolClient {
802
822
  * @param args.orderId - The ID of the Order
803
823
  * @param args.userNonce - The nonce of the user
804
824
  * @param args.direction - The direction of the Order
825
+ * @param args.isTrdPayout - Whether to payout in TRD or not
805
826
  *
806
827
  * @param options - RPC options
807
828
  */
808
- cancelBidOrder({ marketId, orderId, userNonce, mint, direction }, options) {
829
+ cancelBidOrder({ marketId, orderId, userNonce, mint, direction, isTrdPayout, remainingShares, price }, options) {
809
830
  return __awaiter(this, void 0, void 0, function* () {
810
831
  const ixs = [];
832
+ const addressLookupTableAccounts = [];
811
833
  ixs.push(yield this.program.methods
812
834
  .cancelBidOrder({
813
835
  orderId: new bn_js_1.default(orderId),
@@ -822,6 +844,21 @@ class TriadProtocolClient {
822
844
  tokenProgram: (0, helpers_1.getTokenProgram)(mint)
823
845
  })
824
846
  .instruction());
847
+ if (isTrdPayout) {
848
+ const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, setupInstructions } = yield (0, swap_1.swap)({
849
+ connection: this.program.provider.connection,
850
+ wallet: this.program.provider.publicKey.toBase58(),
851
+ inToken: constants_1.USDC_MINT.toString(),
852
+ outToken: constants_1.TRD_MINT.toString(),
853
+ amount: Math.floor((remainingShares * price) / Math.pow(10, this.decimals))
854
+ });
855
+ if (swapIxs.length === 0) {
856
+ return;
857
+ }
858
+ ixs.push(...setupInstructions);
859
+ ixs.push(...swapIxs);
860
+ addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
861
+ }
825
862
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
826
863
  });
827
864
  }
@@ -3646,6 +3646,10 @@
3646
3646
  "name": "OrderDirection"
3647
3647
  }
3648
3648
  }
3649
+ },
3650
+ {
3651
+ "name": "is_trd_payout",
3652
+ "type": "bool"
3649
3653
  }
3650
3654
  ]
3651
3655
  }
@@ -116,6 +116,7 @@ export type PlaceBidOrderArgs = {
116
116
  flop: {};
117
117
  };
118
118
  mint: PublicKey;
119
+ isTrdPayout: boolean;
119
120
  };
120
121
  export type PlaceAskOrderArgs = {
121
122
  marketId: number;
@@ -195,6 +196,9 @@ export type CancelBidOrderArgs = {
195
196
  } | {
196
197
  flop: {};
197
198
  };
199
+ isTrdPayout: boolean;
200
+ remainingShares: number;
201
+ price: number;
198
202
  };
199
203
  export type CancelAskOrderArgs = {
200
204
  marketId: number;
@@ -4466,6 +4466,10 @@ export type TriadProtocol = {
4466
4466
  name: 'orderDirection';
4467
4467
  };
4468
4468
  };
4469
+ },
4470
+ {
4471
+ name: 'isTrdPayout';
4472
+ type: 'bool';
4469
4473
  }
4470
4474
  ];
4471
4475
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "2.9.9-beta",
3
+ "version": "3.0.1-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",