@triadxyz/triad-protocol 1.9.3-beta → 1.9.4-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/trade.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AnchorProvider, Program } from '@coral-xyz/anchor';
2
2
  import { TriadProtocol } from './types/triad_protocol';
3
3
  import { PublicKey, TransactionInstruction } from '@solana/web3.js';
4
- import { CreateMarketArgs, OpenOrderArgs, UserTrade, CreateCustomerArgs, PlaceOrderArgs, CancelOrderArgs, Order, MarketBidOrderArgs, UpdateMarketAdminArgs } from './types/trade';
4
+ import { CreateMarketArgs, OpenOrderArgs, UserTrade, CreateCustomerArgs, Order, MarketBidOrderArgs, UpdateMarketAdminArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs } from './types/trade';
5
5
  import { RpcOptions } from './types';
6
6
  import BN from 'bn.js';
7
7
  export default class Trade {
@@ -277,28 +277,48 @@ export default class Trade {
277
277
  nonce?: undefined;
278
278
  }>;
279
279
  /**
280
- * Place Order
280
+ * Place Bid Order
281
281
  * @param args.marketId - The ID of the Market
282
282
  * @param args.amount - The amount of the Order
283
283
  * @param args.direction - The direction of the Order
284
- * @param args.orderSide - The side of the Order
285
284
  * @param args.mint - The mint of the Order
286
285
  * @param args.price - The price of the Order
287
286
  *
288
287
  * @param options - RPC options
288
+ */
289
+ placeBidOrder({ marketId, amount, direction, mint, price }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
290
+ /**
291
+ * Place Ask Order
292
+ * @param args.marketId - The ID of the Market
293
+ * @param args.amount - The amount of the Order
294
+ * @param args.direction - The direction of the Order
295
+ * @param args.price - The price of the Order
296
+ * @param args.bidOrderId - The ID of the Bid Order
297
+ * @param args.bidNonce - The nonce of the Bid Order
298
+ *
299
+ * @param options - RPC options
289
300
  *
290
301
  */
291
- placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId, bidNonce }: PlaceOrderArgs, options?: RpcOptions): Promise<string>;
302
+ placeAskOrder({ marketId, amount, direction, price, bidOrderId, bidNonce }: PlaceAskOrderArgs, options?: RpcOptions): Promise<string>;
303
+ /**
304
+ * Cancel Bid Order
305
+ * @param args.marketId - The ID of the Market
306
+ * @param args.orderId - The ID of the Order
307
+ * @param args.userNonce - The nonce of the user
308
+ *
309
+ * @param options - RPC options
310
+ */
311
+ cancelBidOrder({ marketId, orderId, userNonce, mint }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
292
312
  /**
293
- * Cancel Order
313
+ * Cancel Ask Order
294
314
  * @param args.marketId - The ID of the Market
295
315
  * @param args.orderId - The ID of the Order
296
316
  * @param args.userNonce - The nonce of the user
297
- * @param args.orderSide - The side of the Order
317
+ * @param args.userNonceBidOrder - The nonce of the bid user
298
318
  *
299
319
  * @param options - RPC options
300
320
  */
301
- cancelOrder({ marketId, orderId, userNonce, orderSide, mint, userNonceBidOrder }: CancelOrderArgs, options?: RpcOptions): Promise<string>;
321
+ cancelAskOrder({ marketId, orderId, userNonce, userNonceBidOrder }: CancelAskOrderArgs, options?: RpcOptions): Promise<string>;
302
322
  /**
303
323
  * Market Bid Order
304
324
  * @param args.marketId - The ID of the Market
package/dist/trade.js CHANGED
@@ -413,18 +413,16 @@ class Trade {
413
413
  });
414
414
  }
415
415
  /**
416
- * Place Order
416
+ * Place Bid Order
417
417
  * @param args.marketId - The ID of the Market
418
418
  * @param args.amount - The amount of the Order
419
419
  * @param args.direction - The direction of the Order
420
- * @param args.orderSide - The side of the Order
421
420
  * @param args.mint - The mint of the Order
422
421
  * @param args.price - The price of the Order
423
422
  *
424
423
  * @param options - RPC options
425
- *
426
424
  */
427
- placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId, bidNonce }, options) {
425
+ placeBidOrder({ marketId, amount, direction, mint, price }, options) {
428
426
  return __awaiter(this, void 0, void 0, function* () {
429
427
  const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
430
428
  const ixs = [];
@@ -432,81 +430,116 @@ class Trade {
432
430
  if (userTradeIxs.length > 0) {
433
431
  ixs.push(...userTradeIxs);
434
432
  }
435
- if (Object.keys(orderSide)[0] === 'bid') {
436
- ixs.push(yield this.program.methods
437
- .placeBidOrder({
438
- amount: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
439
- price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
440
- orderDirection: direction
441
- })
442
- .accounts({
443
- signer: this.provider.publicKey,
444
- market: marketPDA,
445
- userTrade: userTradePDA,
446
- mint,
447
- tokenProgram: (0, helpers_1.getTokenProgram)(mint)
448
- })
449
- .instruction());
433
+ ixs.push(yield this.program.methods
434
+ .placeBidOrder({
435
+ amount: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
436
+ price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
437
+ orderDirection: direction
438
+ })
439
+ .accounts({
440
+ signer: this.provider.publicKey,
441
+ market: marketPDA,
442
+ userTrade: userTradePDA,
443
+ mint,
444
+ tokenProgram: (0, helpers_1.getTokenProgram)(mint)
445
+ })
446
+ .instruction());
447
+ return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
448
+ });
449
+ }
450
+ /**
451
+ * Place Ask Order
452
+ * @param args.marketId - The ID of the Market
453
+ * @param args.amount - The amount of the Order
454
+ * @param args.direction - The direction of the Order
455
+ * @param args.price - The price of the Order
456
+ * @param args.bidOrderId - The ID of the Bid Order
457
+ * @param args.bidNonce - The nonce of the Bid Order
458
+ *
459
+ * @param options - RPC options
460
+ *
461
+ */
462
+ placeAskOrder({ marketId, amount, direction, price, bidOrderId, bidNonce }, options) {
463
+ return __awaiter(this, void 0, void 0, function* () {
464
+ const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
465
+ const ixs = [];
466
+ const { userTradePDA: askUserTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs();
467
+ if (userTradeIxs.length > 0) {
468
+ ixs.push(...userTradeIxs);
450
469
  }
451
- if (Object.keys(orderSide)[0] === 'ask' && bidOrderId) {
452
- let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
453
- if (bidNonce !== 0) {
454
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, bidNonce);
455
- bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
456
- }
457
- ixs.push(yield this.program.methods
458
- .placeAskOrder({
459
- shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
460
- price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
461
- bidOrderId: new bn_js_1.default(bidOrderId),
462
- orderDirection: direction
463
- })
464
- .accounts({
465
- signer: this.provider.publicKey,
466
- market: marketPDA,
467
- askUserTrade: userTradePDA,
468
- bidUserTrade: bidUserTradePDA
469
- })
470
- .instruction());
470
+ let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
471
+ if (bidNonce !== 0) {
472
+ const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, bidNonce);
473
+ bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
471
474
  }
475
+ ixs.push(yield this.program.methods
476
+ .placeAskOrder({
477
+ shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
478
+ price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
479
+ bidOrderId: new bn_js_1.default(bidOrderId),
480
+ orderDirection: direction
481
+ })
482
+ .accounts({
483
+ signer: this.provider.publicKey,
484
+ market: marketPDA,
485
+ askUserTrade: askUserTradePDA,
486
+ bidUserTrade: bidUserTradePDA
487
+ })
488
+ .instruction());
472
489
  return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
473
490
  });
474
491
  }
475
492
  /**
476
- * Cancel Order
493
+ * Cancel Bid Order
477
494
  * @param args.marketId - The ID of the Market
478
495
  * @param args.orderId - The ID of the Order
479
496
  * @param args.userNonce - The nonce of the user
480
- * @param args.orderSide - The side of the Order
481
497
  *
482
498
  * @param options - RPC options
483
499
  */
484
- cancelOrder({ marketId, orderId, userNonce, orderSide, mint, userNonceBidOrder }, options) {
500
+ cancelBidOrder({ marketId, orderId, userNonce, mint }, options) {
485
501
  return __awaiter(this, void 0, void 0, function* () {
486
502
  const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
487
503
  let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
488
- let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
489
504
  if (userNonce !== 0) {
490
505
  const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
491
506
  userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
492
507
  }
493
- if (userNonceBidOrder !== null && userNonceBidOrder !== 0) {
508
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelBidOrder(new bn_js_1.default(orderId)).accounts({
509
+ signer: this.provider.publicKey,
510
+ market: marketPDA,
511
+ userTrade: userTradePDA,
512
+ mint,
513
+ tokenProgram: (0, helpers_1.getTokenProgram)(mint)
514
+ }), options);
515
+ });
516
+ }
517
+ /**
518
+ * Cancel Ask Order
519
+ * @param args.marketId - The ID of the Market
520
+ * @param args.orderId - The ID of the Order
521
+ * @param args.userNonce - The nonce of the user
522
+ * @param args.userNonceBidOrder - The nonce of the bid user
523
+ *
524
+ * @param options - RPC options
525
+ */
526
+ cancelAskOrder({ marketId, orderId, userNonce, userNonceBidOrder }, options) {
527
+ return __awaiter(this, void 0, void 0, function* () {
528
+ const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
529
+ let askUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
530
+ if (userNonce !== 0) {
531
+ const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
532
+ askUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
533
+ }
534
+ let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
535
+ if (userNonceBidOrder !== 0) {
494
536
  const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonceBidOrder);
495
537
  bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
496
538
  }
497
- if (orderSide === trade_1.OrderSide.BID) {
498
- return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelBidOrder(new bn_js_1.default(orderId)).accounts({
499
- signer: this.provider.publicKey,
500
- market: marketPDA,
501
- userTrade: userTradePDA,
502
- mint,
503
- tokenProgram: (0, helpers_1.getTokenProgram)(mint)
504
- }), options);
505
- }
506
539
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelAskOrder(new bn_js_1.default(orderId)).accounts({
507
540
  signer: this.provider.publicKey,
508
541
  market: marketPDA,
509
- askUserTrade: userTradePDA,
542
+ askUserTrade: askUserTradePDA,
510
543
  bidUserTrade: bidUserTradePDA
511
544
  }), options);
512
545
  });
@@ -82,7 +82,7 @@ export declare enum OrderSide {
82
82
  BID = "bid",
83
83
  ASK = "ask"
84
84
  }
85
- export type PlaceOrderArgs = {
85
+ export type PlaceBidOrderArgs = {
86
86
  marketId: number;
87
87
  amount: number;
88
88
  price: number;
@@ -91,15 +91,22 @@ export type PlaceOrderArgs = {
91
91
  } | {
92
92
  flop: {};
93
93
  };
94
- orderSide: {
95
- bid: {};
96
- } | {
97
- ask: {};
98
- };
99
94
  mint: PublicKey;
100
95
  bidOrderId: number | null;
101
96
  bidNonce: number | null;
102
97
  };
98
+ export type PlaceAskOrderArgs = {
99
+ marketId: number;
100
+ amount: number;
101
+ price: number;
102
+ direction: {
103
+ hype: {};
104
+ } | {
105
+ flop: {};
106
+ };
107
+ bidOrderId: number;
108
+ bidNonce: number;
109
+ };
103
110
  export type InitializeMarketArgs = {
104
111
  marketId: number;
105
112
  startTime: number;
@@ -147,13 +154,17 @@ export type CreateMarketArgs = {
147
154
  payoutFee: number;
148
155
  mint: PublicKey;
149
156
  };
150
- export type CancelOrderArgs = {
157
+ export type CancelBidOrderArgs = {
151
158
  marketId: number;
152
159
  orderId: number;
153
160
  userNonce: number;
154
- orderSide: OrderSide;
155
161
  mint: PublicKey;
156
- userNonceBidOrder: number | null;
162
+ };
163
+ export type CancelAskOrderArgs = {
164
+ marketId: number;
165
+ orderId: number;
166
+ userNonce: number;
167
+ userNonceBidOrder: number;
157
168
  };
158
169
  export type MarketBidOrderArgs = {
159
170
  marketId: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.9.3-beta",
3
+ "version": "1.9.4-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",