@triadxyz/triad-protocol 1.6.8-beta-dev → 1.6.9-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.js CHANGED
@@ -12,20 +12,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const trade_1 = require("./types/trade");
16
15
  const bn_js_1 = __importDefault(require("bn.js"));
17
16
  const constants_1 = require("./utils/constants");
18
17
  const helpers_1 = require("./utils/helpers");
19
- const trade_2 = require("./utils/pda/trade");
18
+ const trade_1 = require("./utils/pda/trade");
20
19
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
21
20
  const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
22
- const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
21
+ const swap_1 = require("./utils/swap");
23
22
  class Trade {
24
23
  constructor(program, provider) {
25
24
  this.program = program;
26
25
  this.provider = provider;
27
- this.mint = constants_1.USDC_MINT_DEVNET;
28
- this.decimals = 6;
26
+ this.mint = constants_1.TRD_MINT;
29
27
  }
30
28
  /**
31
29
  * Get All Markets
@@ -67,67 +65,6 @@ class Trade {
67
65
  return orders;
68
66
  });
69
67
  }
70
- /**
71
- * Get Orders By Market ID
72
- * @param marketId - The ID of the market
73
- *
74
- */
75
- getLimitOrdersByMarketId(marketId) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const marketIdBytes = bytes_1.bs58.encode(new bn_js_1.default(marketId).toArrayLike(Buffer, 'le', 8));
78
- const memcmpFilters = Array.from({ length: 10 }).map((_, index) => ({
79
- memcmp: {
80
- offset: 8 + // discriminator
81
- 1 + // bump
82
- 32 + // authority
83
- 8 + // total_deposits
84
- 8 + // total_withdraws
85
- 8 + // opened_orders
86
- // Per order: index * (8 + 8 + 8 + 8 + 1 + 8 + 8 + 8 + 1 + 1 + 4 + 28)
87
- index * (8 + 8 + 8 + 8 + 1 + 8 + 8 + 8 + 1 + 1 + 4 + 1 + 27) +
88
- // Then offset to market_id: 8 + 8 + 8
89
- (8 + 8 + 8),
90
- bytes: marketIdBytes
91
- }
92
- }));
93
- const allResponses = yield Promise.all(memcmpFilters.map((filter) => this.program.account.userTrade.all([filter])));
94
- const uniqueResponses = Array.from(new Map(allResponses.flat().map((item) => [item.publicKey.toString(), item])).values());
95
- const userTrades = uniqueResponses.map(({ account, publicKey }) => (0, helpers_1.formatUserTrade)(account, publicKey));
96
- const orders = userTrades.flatMap((userTrade) => userTrade.orders.map((order) => (Object.assign({}, order))));
97
- const filteredOrders = orders.filter((order) => order.marketId === marketId.toString() &&
98
- order.orderType === trade_1.OrderType.LIMIT &&
99
- order.status === trade_1.OrderStatus.WAITING);
100
- const orderBook = {
101
- hype: {
102
- bid: [],
103
- ask: []
104
- },
105
- flop: {
106
- bid: [],
107
- ask: []
108
- }
109
- };
110
- filteredOrders.forEach((order) => {
111
- if (order.orderSide === trade_1.OrderSide.BID &&
112
- order.direction === trade_1.OrderDirection.HYPE) {
113
- orderBook.hype.bid.push(order);
114
- return;
115
- }
116
- if (order.orderSide === trade_1.OrderSide.ASK &&
117
- order.direction === trade_1.OrderDirection.HYPE) {
118
- orderBook.hype.ask.push(order);
119
- return;
120
- }
121
- if (order.orderSide === trade_1.OrderSide.BID &&
122
- order.direction === trade_1.OrderDirection.FLOP) {
123
- orderBook.flop.bid.push(order);
124
- return;
125
- }
126
- orderBook.flop.ask.push(order);
127
- });
128
- return orderBook;
129
- });
130
- }
131
68
  /**
132
69
  * Get Market By ID
133
70
  * @param marketId - The ID of the market
@@ -135,7 +72,7 @@ class Trade {
135
72
  */
136
73
  getMarketById(marketId) {
137
74
  return __awaiter(this, void 0, void 0, function* () {
138
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
75
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
139
76
  const response = yield this.program.account.marketV2.fetch(marketPDA);
140
77
  return (0, helpers_1.formatMarket)(response, marketPDA);
141
78
  });
@@ -159,16 +96,16 @@ class Trade {
159
96
  */
160
97
  getUserTrade(user, userNonce = 0) {
161
98
  return __awaiter(this, void 0, void 0, function* () {
162
- let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, user);
99
+ let userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, user);
163
100
  if (userNonce !== 0) {
164
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, user, userNonce);
165
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
101
+ const subUserTradePDA = (0, trade_1.getSubUserTradePDA)(this.program.programId, user, userNonce);
102
+ userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
166
103
  }
167
104
  return this.program.account.userTrade.fetch(userTradePDA);
168
105
  });
169
106
  }
170
107
  /**
171
- * Create Market
108
+ * Initialize Market
172
109
  * @param args.marketId - new markert id - length + 1
173
110
  * @param args.startTime - start time
174
111
  * @param args.endTime - end time
@@ -210,51 +147,44 @@ class Trade {
210
147
  if (nonce !== null) {
211
148
  break;
212
149
  }
213
- let freeSlots = 0;
214
150
  userTrade.orders.forEach((order) => {
215
151
  if (nonce !== null) {
216
152
  return;
217
153
  }
218
- if (order.status !== trade_1.OrderStatus.OPEN &&
219
- order.status !== trade_1.OrderStatus.WAITING &&
220
- freeSlots >= 2) {
154
+ let status = Object.keys(order.status)[0];
155
+ if (status !== 'open') {
221
156
  nonce = userTrade.isSubUser ? Number(userTrade.nonce) : 0;
222
157
  }
223
- if (order.status !== trade_1.OrderStatus.OPEN &&
224
- order.status !== trade_1.OrderStatus.WAITING) {
225
- freeSlots += 1;
226
- }
227
158
  });
228
159
  }
229
160
  if (nonce === null) {
230
161
  throw new Error('No open orders found');
231
162
  }
232
163
  if (nonce === 0) {
233
- return (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
164
+ return (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
234
165
  }
235
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, nonce);
236
- const userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
166
+ const subUserTradePDA = (0, trade_1.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, nonce);
167
+ const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
237
168
  return userTradePDA;
238
169
  });
239
170
  }
240
171
  /**
241
- * Place Order
172
+ * Open Order
242
173
  * @param args.marketId - The ID of the Market
243
174
  * @param args.amount - The amount of the Order
244
175
  * @param args.direction - The direction of the Order
245
- * @param args.orderSide - The side of the Order
246
- * @param args.mint - The mint of the Order
247
- * @param args.price - The price of the Order
176
+ * @param args.token - The token of the Order
248
177
  *
249
178
  * @param options - RPC options
250
179
  *
251
180
  */
252
- placeOrder({ marketId, amount, direction, orderSide, mint, price }, options) {
181
+ openOrder({ marketId, amount, direction, token }, options) {
253
182
  return __awaiter(this, void 0, void 0, function* () {
254
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
255
- let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
183
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
184
+ let userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
256
185
  const ixs = [];
257
186
  const addressLookupTableAccounts = [];
187
+ let amountInTRD = amount * Math.pow(10, constants_1.TRD_DECIMALS);
258
188
  let myUserTrades = [];
259
189
  myUserTrades = yield this.getMyUserTrades(this.provider.publicKey);
260
190
  if (myUserTrades.length === 0) {
@@ -268,31 +198,11 @@ class Trade {
268
198
  if (myUserTrades.length > 0) {
269
199
  try {
270
200
  userTradePDA = yield this.getUserTradeNonceWithSlots(myUserTrades);
271
- console.log(userTradePDA);
272
- // Check if we need to create a new sub user trade
273
- // This happens when all existing slots have open orders
274
- const allSlotsHaveOpenOrders = myUserTrades.every((trade) => trade.orders.some((order) => Object.keys(order.status)[0] === 'open' ||
275
- Object.keys(order.status)[0] === 'waiting'));
276
- if (allSlotsHaveOpenOrders) {
277
- // Find the main user trade to get the current nonce
278
- const mainUserTrade = myUserTrades.find((userTrade) => !userTrade.isSubUser);
279
- if (!mainUserTrade) {
280
- throw new Error('No main user trade found');
281
- }
282
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
283
- ixs.push(yield this.program.methods
284
- .createSubUserTrade(subUserTradePDA)
285
- .accounts({
286
- signer: this.provider.publicKey
287
- })
288
- .instruction());
289
- }
290
201
  }
291
- catch (error) {
292
- console.log(error);
202
+ catch (_a) {
293
203
  const mainUserTrade = myUserTrades.find((userTrade) => !userTrade.isSubUser);
294
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
295
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
204
+ const subUserTradePDA = (0, trade_1.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
205
+ userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
296
206
  ixs.push(yield this.program.methods
297
207
  .createSubUserTrade(subUserTradePDA)
298
208
  .accounts({
@@ -301,41 +211,38 @@ class Trade {
301
211
  .instruction());
302
212
  }
303
213
  }
304
- if (Object.keys(orderSide)[0] === 'bid') {
305
- ixs.push(yield this.program.methods
306
- .placeBidOrder({
307
- amount: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
308
- price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
309
- orderDirection: direction
310
- })
311
- .accounts({
312
- signer: this.provider.publicKey,
313
- market: marketPDA,
314
- userTrade: userTradePDA,
315
- mint,
316
- tokenProgram: (0, helpers_1.getTokenProgram)(mint)
317
- })
318
- .instruction());
319
- }
320
- if (Object.keys(orderSide)[0] === 'ask') {
321
- ixs.push(yield this.program.methods
322
- .placeAskOrder({
323
- shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
324
- price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
325
- orderDirection: direction
326
- })
327
- .accounts({
328
- signer: this.provider.publicKey,
329
- market: marketPDA,
330
- userTrade: userTradePDA
331
- })
332
- .instruction());
214
+ if (token !== constants_1.TRD_MINT.toBase58()) {
215
+ const { setupInstructions, swapIxs, addressLookupTableAccounts, trdAmount } = yield (0, swap_1.swap)({
216
+ connection: this.provider.connection,
217
+ wallet: this.provider.publicKey.toBase58(),
218
+ inToken: token,
219
+ amount
220
+ });
221
+ amountInTRD = trdAmount;
222
+ if (swapIxs.length === 0) {
223
+ return;
224
+ }
225
+ ixs.push(...setupInstructions);
226
+ ixs.push(...swapIxs);
227
+ addressLookupTableAccounts.push(...addressLookupTableAccounts);
333
228
  }
229
+ ixs.push(yield this.program.methods
230
+ .openOrder({
231
+ amount: new bn_js_1.default(amountInTRD),
232
+ direction: direction
233
+ })
234
+ .accounts({
235
+ signer: this.provider.publicKey,
236
+ market: marketPDA,
237
+ userTrade: userTradePDA,
238
+ mint: this.mint
239
+ })
240
+ .instruction());
334
241
  return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, addressLookupTableAccounts);
335
242
  });
336
243
  }
337
244
  /**
338
- * Cancel Order
245
+ * Close Order
339
246
  * @param args.marketId - The ID of the Market
340
247
  * @param args.orderId - The ID of the Order
341
248
  * @param args.userNonce - The nonce of the user
@@ -343,23 +250,42 @@ class Trade {
343
250
  * @param options - RPC options
344
251
  *
345
252
  */
346
- cancelOrder({ marketId, orderId, userNonce }, options) {
253
+ closeOrder({ marketId, orderId, userNonce }, options) {
347
254
  return __awaiter(this, void 0, void 0, function* () {
348
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
349
- let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
255
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
256
+ let userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
350
257
  if (userNonce !== 0) {
351
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
352
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
258
+ const subUserTradePDA = (0, trade_1.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
259
+ userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
353
260
  }
354
- return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelOrder(new bn_js_1.default(orderId)).accounts({
261
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
355
262
  signer: this.provider.publicKey,
356
263
  market: marketPDA,
357
264
  mint: this.mint,
358
- userTrade: userTradePDA,
359
- tokenProgram: (0, helpers_1.getTokenProgram)(this.mint)
265
+ userTrade: userTradePDA
360
266
  }), options);
361
267
  });
362
268
  }
269
+ /**
270
+ * Resolve Market
271
+ * @param args.marketId - The ID of the Market
272
+ * @param args.winningDirection - The Winning Direction of the Market
273
+ *
274
+ * @param options - RPC options
275
+ *
276
+ */
277
+ resolveMarket({ marketId, winningDirection }, options) {
278
+ return __awaiter(this, void 0, void 0, function* () {
279
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
280
+ const method = this.program.methods
281
+ .resolveMarket(winningDirection)
282
+ .accounts({
283
+ signer: this.provider.publicKey,
284
+ market: marketPDA
285
+ });
286
+ return (0, sendTransactionWithOptions_1.default)(method, options);
287
+ });
288
+ }
363
289
  /**
364
290
  * Collect Remaining Liquidity
365
291
  * @param marketId - The ID of the market
@@ -369,7 +295,7 @@ class Trade {
369
295
  */
370
296
  collectRemainingLiquidity(marketId, options) {
371
297
  return __awaiter(this, void 0, void 0, function* () {
372
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
298
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
373
299
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.collectRemainingLiquidity().accounts({
374
300
  signer: this.provider.publicKey,
375
301
  market: marketPDA,
@@ -388,11 +314,11 @@ class Trade {
388
314
  */
389
315
  payoutOrder({ marketId, orderId, userNonce }, options) {
390
316
  return __awaiter(this, void 0, void 0, function* () {
391
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
392
- let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
317
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
318
+ let userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
393
319
  if (userNonce !== 0) {
394
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
395
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
320
+ const subUserTradePDA = (0, trade_1.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
321
+ userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
396
322
  }
397
323
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.payoutOrder(new bn_js_1.default(orderId)).accounts({
398
324
  signer: this.provider.publicKey,
@@ -411,7 +337,7 @@ class Trade {
411
337
  */
412
338
  allowMarketToPayout(marketId, options) {
413
339
  return __awaiter(this, void 0, void 0, function* () {
414
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
340
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
415
341
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.allowMarketToPayout().accounts({
416
342
  signer: this.provider.publicKey,
417
343
  market: marketPDA
@@ -428,7 +354,7 @@ class Trade {
428
354
  createSubUserTrade(user, options) {
429
355
  return __awaiter(this, void 0, void 0, function* () {
430
356
  const userTrade = yield this.getUserTrade(user);
431
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, user, userTrade.nonce + 1);
357
+ const subUserTradePDA = (0, trade_1.getSubUserTradePDA)(this.program.programId, user, userTrade.nonce + 1);
432
358
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.createSubUserTrade(subUserTradePDA).accounts({
433
359
  signer: this.provider.publicKey
434
360
  }), options);
@@ -438,20 +364,14 @@ class Trade {
438
364
  * Update Market
439
365
  * @param marketId - The ID of the market
440
366
  * @param marketEnd - The end time of the market
441
- * @param winningDirection - The winning direction of the market
442
367
  *
443
368
  * @param options - RPC options
444
369
  *
445
370
  */
446
- updateMarket({ marketId, marketEnd, winningDirection }, options) {
371
+ updateMarket(marketId, marketEnd, options) {
447
372
  return __awaiter(this, void 0, void 0, function* () {
448
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
449
- return (0, sendTransactionWithOptions_1.default)(this.program.methods
450
- .updateMarket({
451
- marketEnd: marketEnd ? new bn_js_1.default(marketEnd) : undefined,
452
- winningDirection
453
- })
454
- .accounts({
373
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
374
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.updateMarket(new bn_js_1.default(marketEnd)).accounts({
455
375
  signer: this.provider.publicKey,
456
376
  market: marketPDA
457
377
  }), options);
@@ -462,101 +382,16 @@ class Trade {
462
382
  * @param args.id - The ID of the customer
463
383
  * @param args.name - The name of the customer
464
384
  * @param args.authority - The authority of the customer
465
- * @param args.shadowStorage - The shadow storage of the customer
466
385
  *
467
386
  * @param options - RPC options
468
387
  *
469
388
  */
470
- createCustomer({ id, name, authority, shadowStorage }, options) {
389
+ createCustomer({ id, name, authority }, options) {
471
390
  return __awaiter(this, void 0, void 0, function* () {
472
- return (0, sendTransactionWithOptions_1.default)(this.program.methods
473
- .createCustomer({ id, name, authority, shadowStorage })
474
- .accounts({
391
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.createCustomer({ id, name, authority }).accounts({
475
392
  signer: this.provider.publicKey
476
393
  }), options);
477
394
  });
478
395
  }
479
- /**
480
- * Open Order
481
- * @param args.marketId - The ID of the Market
482
- * @param args.amount - The amount of the Order
483
- * @param args.direction - The direction of the Order
484
- *
485
- * @param options - RPC options
486
- *
487
- */
488
- openOrder({ marketId, amount, direction }, options) {
489
- return __awaiter(this, void 0, void 0, function* () {
490
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
491
- let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
492
- const ixs = [];
493
- const addressLookupTableAccounts = [];
494
- let amountInTRD = amount * Math.pow(10, constants_1.TRD_DECIMALS);
495
- let myUserTrades = [];
496
- myUserTrades = yield this.getMyUserTrades(this.provider.publicKey);
497
- if (myUserTrades.length === 0) {
498
- ixs.push(yield this.program.methods
499
- .createUserTrade()
500
- .accounts({
501
- signer: this.provider.publicKey
502
- })
503
- .instruction());
504
- }
505
- if (myUserTrades.length > 0) {
506
- try {
507
- userTradePDA = yield this.getUserTradeNonceWithSlots(myUserTrades);
508
- }
509
- catch (_a) {
510
- const mainUserTrade = myUserTrades.find((userTrade) => !userTrade.isSubUser);
511
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
512
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
513
- ixs.push(yield this.program.methods
514
- .createSubUserTrade(subUserTradePDA)
515
- .accounts({
516
- signer: this.provider.publicKey
517
- })
518
- .instruction());
519
- }
520
- }
521
- ixs.push(yield this.program.methods
522
- .openOrder({
523
- amount: new bn_js_1.default(amountInTRD),
524
- direction: direction
525
- })
526
- .accounts({
527
- signer: this.provider.publicKey,
528
- market: marketPDA,
529
- userTrade: userTradePDA,
530
- mint: this.mint
531
- })
532
- .instruction());
533
- return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, addressLookupTableAccounts);
534
- });
535
- }
536
- /**
537
- * Close Order
538
- * @param args.marketId - The ID of the Market
539
- * @param args.orderId - The ID of the Order
540
- * @param args.userNonce - The nonce of the user
541
- *
542
- * @param options - RPC options
543
- *
544
- */
545
- closeOrder({ marketId, orderId, userNonce }, options) {
546
- return __awaiter(this, void 0, void 0, function* () {
547
- const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
548
- let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
549
- if (userNonce !== 0) {
550
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
551
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
552
- }
553
- return (0, sendTransactionWithOptions_1.default)(this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
554
- signer: this.provider.publicKey,
555
- market: marketPDA,
556
- mint: this.mint,
557
- userTrade: userTradePDA
558
- }), options);
559
- });
560
- }
561
396
  }
562
397
  exports.default = Trade;