@triadxyz/triad-protocol 4.2.0 → 4.2.1

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.js CHANGED
@@ -27,14 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const anchor_1 = require("@coral-xyz/anchor");
30
- const spl_token_1 = require("@solana/spl-token");
31
30
  const bn_js_1 = __importDefault(require("bn.js"));
32
- const bs58_1 = __importDefault(require("bs58"));
33
- const helpers_1 = require("./utils/helpers");
34
31
  const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
35
- const types_1 = require("./types");
36
32
  const constants_1 = require("./utils/constants");
37
- const helpers_2 = require("./utils/helpers");
33
+ const helpers_1 = require("./utils/helpers");
38
34
  const pda_1 = require("./utils/pda");
39
35
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
40
36
  const stake_1 = __importDefault(require("./stake"));
@@ -42,6 +38,8 @@ const poseidon_1 = __importDefault(require("./poseidon"));
42
38
  const predictor_1 = __importDefault(require("./predictor"));
43
39
  const trade_1 = __importDefault(require("./trade"));
44
40
  const customer_1 = __importDefault(require("./customer"));
41
+ const market_1 = __importDefault(require("./market"));
42
+ const getPriorityFee_1 = __importDefault(require("./utils/getPriorityFee"));
45
43
  __exportStar(require("./types"), exports);
46
44
  __exportStar(require("./types/predictor"), exports);
47
45
  __exportStar(require("./types/stake"), exports);
@@ -68,6 +66,16 @@ class TriadProtocol {
68
66
  this.predictor = new predictor_1.default(this.program, this.rpcOptions);
69
67
  this.trade = new trade_1.default(this.program, this.rpcOptions);
70
68
  this.customer = new customer_1.default(this.program, this.rpcOptions);
69
+ this.market = new market_1.default(this.program, this.rpcOptions);
70
+ this.getPriorityFee();
71
+ }
72
+ getPriorityFee() {
73
+ var _a;
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ if ((_a = this.rpcOptions) === null || _a === void 0 ? void 0 : _a.microLamports)
76
+ return;
77
+ this.rpcOptions.microLamports = yield (0, getPriorityFee_1.default)();
78
+ });
71
79
  }
72
80
  /**
73
81
  * Get User Orders
@@ -86,24 +94,6 @@ class TriadProtocol {
86
94
  return orders.map(({ account, publicKey }) => (0, helpers_1.formatOrder)(account, publicKey));
87
95
  });
88
96
  }
89
- /**
90
- * Get Orders By Market ID
91
- * @param marketId - The ID of the market
92
- */
93
- getOrdersByMarketId(marketId) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- const marketIdBytes = new bn_js_1.default(marketId).toArray('le', 8);
96
- const orders = yield this.program.account.orderV2.all([
97
- {
98
- memcmp: {
99
- offset: 8 + 32,
100
- bytes: bs58_1.default.encode(marketIdBytes)
101
- }
102
- }
103
- ]);
104
- return orders.map(({ account, publicKey }) => (0, helpers_1.formatOrder)(account, publicKey));
105
- });
106
- }
107
97
  /**
108
98
  * Get User Orders By Market ID
109
99
  * @param wallet - User wallet PublicKey
@@ -124,7 +114,7 @@ class TriadProtocol {
124
114
  const orderbooks = yield this.program.account.orderBook.all();
125
115
  const bookOrders = orderbooks.map((orderbook) => {
126
116
  return [...orderbook.account.hypeOrders, ...orderbook.account.flopOrders]
127
- .map((order) => (0, helpers_2.formatBookOrder)(order, orderbook.account.marketId.toNumber()))
117
+ .map((order) => (0, helpers_1.formatBookOrder)(order, orderbook.account.marketId.toNumber()))
128
118
  .filter((order) => order.authority === wallet.toBase58() &&
129
119
  order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
130
120
  });
@@ -139,428 +129,11 @@ class TriadProtocol {
139
129
  const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId), this.provider.opts.commitment);
140
130
  const orders = [...orderBook.hypeOrders, ...orderBook.flopOrders];
141
131
  return orders
142
- .map((order) => (0, helpers_2.formatBookOrder)(order, marketId))
132
+ .map((order) => (0, helpers_1.formatBookOrder)(order, marketId))
143
133
  .filter((order) => order.authority === wallet.toBase58() &&
144
134
  order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
145
135
  });
146
136
  }
147
- /**
148
- * Get All Pools
149
- */
150
- getAllPools() {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const pool = yield this.program.account.pool.all();
153
- return pool.map(({ account, publicKey }) => (0, helpers_1.formatPool)(account, publicKey));
154
- });
155
- }
156
- /**
157
- * Get All Markets
158
- */
159
- getAllMarkets() {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- const marketV2 = yield this.program.account.marketV2.all();
162
- return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
163
- });
164
- }
165
- /**
166
- * Get Pool By ID
167
- * @param poolId - The ID of the pool
168
- */
169
- getPoolById(poolId) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
172
- const response = yield this.program.account.pool.fetch(poolPDA, this.provider.opts.commitment);
173
- return (0, helpers_1.formatPool)(response, poolPDA);
174
- });
175
- }
176
- /**
177
- * Get Market By ID
178
- * @param marketId - The ID of the market
179
- */
180
- getMarketById(marketId) {
181
- return __awaiter(this, void 0, void 0, function* () {
182
- const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
183
- const response = yield this.program.account.marketV2.fetch(marketPDA, this.provider.opts.commitment);
184
- return (0, helpers_1.formatMarket)(response, marketPDA);
185
- });
186
- }
187
- /**
188
- * Get Market By Address
189
- * @param marketAddress - The address of the market
190
- */
191
- getMarketByAddress(marketAddress) {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- const account = yield this.program.account.marketV2.fetch(marketAddress, this.provider.opts.commitment);
194
- return (0, helpers_1.formatMarket)(account, marketAddress);
195
- });
196
- }
197
- /**
198
- * Get Current Market ID
199
- */
200
- nextMarketId() {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- let validId = null;
203
- while (!validId) {
204
- const marketId = Math.floor(Math.random() * 1000000000000000);
205
- try {
206
- yield this.program.account.marketV2.fetch((0, pda_1.getMarketPDA)(this.program.programId, marketId));
207
- }
208
- catch (_a) {
209
- validId = marketId;
210
- }
211
- }
212
- return validId;
213
- });
214
- }
215
- /**
216
- * Get Next Pool ID
217
- */
218
- nextPoolId() {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- const pools = yield this.program.account.pool.all();
221
- return pools.length + 1;
222
- });
223
- }
224
- /**
225
- * Create Market
226
- * @param args.markets - Array of markets to create
227
- * @param args.markets.marketId - Market ID
228
- * @param args.markets.startTime - start time
229
- * @param args.markets.endTime - end time
230
- * @param args.markets.question - question (max 80 characters)
231
- * @param args.markets.liquidityAtStart - liquidity at start
232
- * @param args.markets.payoutFee - payout fee (to add affiliate system)
233
- * @param args.customer - The customer of the market
234
- * @param args.poolId - The ID of the pool
235
- */
236
- createMarket({ markets, customer, poolId }) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- const ixs = [];
239
- let poolPDA = null;
240
- if (poolId) {
241
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
242
- }
243
- for (const market of markets) {
244
- if (market.question.length > 80) {
245
- throw new Error('Question must be less than 80 characters');
246
- }
247
- ixs.push(yield this.program.methods
248
- .createMarket({
249
- marketId: new bn_js_1.default(market.marketId),
250
- question: (0, helpers_1.encodeString)(market.question, 80),
251
- marketStart: new bn_js_1.default(market.startTime),
252
- marketEnd: new bn_js_1.default(market.endTime),
253
- feeBps: market.feeBps,
254
- payoutFee: market.payoutFee,
255
- preMarketEndTs: new bn_js_1.default(0),
256
- preOrdersAvailable: new bn_js_1.default(0)
257
- })
258
- .accounts({
259
- signer: this.program.provider.publicKey,
260
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
261
- pool: poolPDA,
262
- customer
263
- })
264
- .instruction());
265
- ixs.push(yield this.program.methods
266
- .createOrderBook(new bn_js_1.default(market.marketId))
267
- .accounts({
268
- signer: this.program.provider.publicKey,
269
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
270
- })
271
- .instruction());
272
- }
273
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
274
- });
275
- }
276
- /**
277
- * Create Pool
278
- * @param poolId - The ID of the pool
279
- * @param question - The question of the pool
280
- * @param markets - The markets of the pool
281
- * @param customer - The customer of the pool
282
- * @param startTime - The start time of the pool
283
- * @param endTime - The end time of the pool
284
- * @param feeBps - The fee in basis points of the pool
285
- * @param payoutFee - The payout fee of the pool
286
- * @param isFast - Whether the pool is fast
287
- * @param isPyth - Whether the pool is pyth
288
- * @param feedId - The feed ID of the pool
289
- */
290
- createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }) {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- if (question.length > 80) {
293
- throw new Error('Pool question must be less than 80 characters');
294
- }
295
- const ixs = [];
296
- let feedPDA = null;
297
- if (isPyth) {
298
- feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(feedId);
299
- }
300
- const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
301
- ixs.push(yield this.program.methods
302
- .createPool({
303
- poolId: new bn_js_1.default(poolId),
304
- question: (0, helpers_1.encodeString)(question, 80),
305
- isFast,
306
- isPyth
307
- })
308
- .accounts({
309
- signer: this.program.provider.publicKey,
310
- priceUpdate: feedPDA,
311
- customer,
312
- feed: (0, helpers_1.getFeedIdFromHex)(feedId)
313
- })
314
- .instruction());
315
- for (const market of markets) {
316
- if (market.question.length > 80) {
317
- throw new Error('Market question must be less than 80 characters');
318
- }
319
- ixs.push(yield this.program.methods
320
- .createMarket({
321
- marketId: new bn_js_1.default(market.marketId),
322
- question: (0, helpers_1.encodeString)(market.question, 80),
323
- marketStart: new bn_js_1.default(startTime),
324
- marketEnd: new bn_js_1.default(endTime),
325
- feeBps,
326
- payoutFee,
327
- preMarketEndTs: new bn_js_1.default(0),
328
- preOrdersAvailable: new bn_js_1.default(0)
329
- })
330
- .accounts({
331
- signer: this.program.provider.publicKey,
332
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
333
- pool: poolPDA,
334
- customer
335
- })
336
- .instruction());
337
- ixs.push(yield this.program.methods
338
- .createOrderBook(new bn_js_1.default(market.marketId))
339
- .accounts({
340
- signer: this.program.provider.publicKey,
341
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
342
- })
343
- .instruction());
344
- }
345
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
346
- });
347
- }
348
- /**
349
- * Update Market Winning Direction
350
- * @param args.marketId - The ID of the Market
351
- * @param args.winningDirection - The Winning Direction of the Market
352
- * @param args.poolId - The ID of the Pool
353
- * @param args.withPayout - Whether to allow the market to payout
354
- */
355
- updateMarketWinningDirection({ markets }) {
356
- return __awaiter(this, void 0, void 0, function* () {
357
- const ixs = [];
358
- for (const market of markets) {
359
- ixs.push(yield this.program.methods
360
- .updateMarketWinningDirection(market.winningDirection)
361
- .accounts({
362
- signer: this.program.provider.publicKey,
363
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId),
364
- pool: market.poolId
365
- ? (0, pda_1.getPoolPDA)(this.program.programId, market.poolId)
366
- : null
367
- })
368
- .instruction());
369
- if (market.withPayout) {
370
- ixs.push(yield this.program.methods
371
- .updateMarketPayout(true)
372
- .accounts({
373
- signer: this.program.provider.publicKey,
374
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
375
- })
376
- .instruction());
377
- }
378
- }
379
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
380
- });
381
- }
382
- /**
383
- * Update Market Payout
384
- * @param args.marketId - The ID of the market
385
- * @param args.allowPayout - Whether to allow the market to payout
386
- */
387
- updateMarketPayout({ marketId, allowPayout }) {
388
- return __awaiter(this, void 0, void 0, function* () {
389
- const ixs = [
390
- yield this.program.methods
391
- .updateMarketPayout(allowPayout)
392
- .accounts({
393
- signer: this.program.provider.publicKey,
394
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
395
- })
396
- .instruction()
397
- ];
398
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
399
- });
400
- }
401
- /**
402
- * Update Market End
403
- * @param args.marketId - The ID of the market
404
- * @param args.marketEnd - The end time of the market
405
- */
406
- updateMarketEnd({ marketId, marketEnd }) {
407
- return __awaiter(this, void 0, void 0, function* () {
408
- const ixs = [
409
- yield this.program.methods
410
- .updateMarketEnd(new bn_js_1.default(marketEnd))
411
- .accounts({
412
- signer: this.program.provider.publicKey,
413
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
414
- })
415
- .instruction()
416
- ];
417
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
418
- });
419
- }
420
- /**
421
- * Update Market Question
422
- * @param args.marketId - The ID of the market
423
- * @param args.question - The question of the market
424
- */
425
- updateMarketQuestion({ marketId, question }) {
426
- return __awaiter(this, void 0, void 0, function* () {
427
- const ixs = [
428
- yield this.program.methods
429
- .updateMarketQuestion((0, helpers_1.encodeString)(question, 80))
430
- .accounts({
431
- signer: this.program.provider.publicKey,
432
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
433
- })
434
- .instruction()
435
- ];
436
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
437
- });
438
- }
439
- /**
440
- * Collect Market Fee
441
- * @param args.markets - The markets to collect the fee from
442
- * @param args.markets.marketAddress - The address of the market
443
- * @param args.markets.customerId - The ID of the customer
444
- * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
445
- */
446
- collectMarketFee(markets) {
447
- return __awaiter(this, void 0, void 0, function* () {
448
- const ixs = [];
449
- for (const market of markets) {
450
- ixs.push(yield this.program.methods
451
- .collectMarketFee()
452
- .accounts({
453
- signer: this.program.provider.publicKey,
454
- market: market.marketAddress,
455
- customer: (0, pda_1.getCustomerPDA)(this.program.programId, market.customerId),
456
- customerFeeRecipient: market.customerFeeRecipient
457
- })
458
- .instruction());
459
- }
460
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
461
- });
462
- }
463
- /**
464
- * Close Order Book
465
- * @param markets.id - Market IDs
466
- * @param markets.authority - The authority of the market
467
- */
468
- closeOrderBook(markets) {
469
- return __awaiter(this, void 0, void 0, function* () {
470
- const ixs = [];
471
- for (const market of markets) {
472
- ixs.push(yield this.program.methods
473
- .closeOrderBook()
474
- .accounts({
475
- authority: market.authority,
476
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.id),
477
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, market.id)
478
- })
479
- .instruction());
480
- }
481
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
482
- });
483
- }
484
- /**
485
- * Close IDLE Market
486
- * @param markets.id - Market ID
487
- * @param markets.authority - Market authority
488
- * @param markets.mint - Market mint
489
- */
490
- closeIdleMarket(markets) {
491
- return __awaiter(this, void 0, void 0, function* () {
492
- const ixs = [];
493
- for (const market of markets) {
494
- ixs.push(yield this.program.methods
495
- .closeIdleMarket(new bn_js_1.default(market.id))
496
- .accounts({
497
- signer: this.program.provider.publicKey,
498
- mint: market.mint,
499
- tokenProgram: (0, helpers_1.getTokenProgram)(market.mint)
500
- })
501
- .instruction());
502
- }
503
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
504
- });
505
- }
506
- /**
507
- * Update Pool Question
508
- * @param poolId - Pool ID
509
- * @param question - Question
510
- */
511
- updatePoolQuestion(poolId, question) {
512
- return __awaiter(this, void 0, void 0, function* () {
513
- const ixs = [
514
- yield this.program.methods
515
- .updatePoolQuestion((0, helpers_1.encodeString)(question, 80))
516
- .accounts({
517
- signer: this.program.provider.publicKey,
518
- pool: (0, pda_1.getPoolPDA)(this.program.programId, poolId)
519
- })
520
- .instruction()
521
- ];
522
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
523
- });
524
- }
525
- /**
526
- * Create Market Pyth
527
- * @param args.markets - Array of markets to create
528
- * @param args.markets.marketId - Market ID
529
- * @param args.markets.resolveIn - Time to add for resolver the market in seconds
530
- * @param args.customer - The customer of the market
531
- * @param args.poolId - The ID of the pool
532
- */
533
- createMarketPyth({ markets }) {
534
- return __awaiter(this, void 0, void 0, function* () {
535
- const ixs = [];
536
- for (const market of markets) {
537
- let poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, market.poolId);
538
- const feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(market.feedId);
539
- ixs.push(yield this.program.methods
540
- .createMarketPyth({
541
- marketId: new bn_js_1.default(market.marketId),
542
- resolveIn: new bn_js_1.default(market.resolveIn),
543
- direction: market.direction
544
- })
545
- .accounts({
546
- signer: this.program.provider.publicKey,
547
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
548
- pool: poolPDA,
549
- customer: market.customer,
550
- priceUpdate: feedPDA
551
- })
552
- .instruction());
553
- ixs.push(yield this.program.methods
554
- .createOrderBook(new bn_js_1.default(market.marketId))
555
- .accounts({
556
- signer: this.program.provider.publicKey,
557
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
558
- })
559
- .instruction());
560
- }
561
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
562
- });
563
- }
564
137
  /**
565
138
  * Burn Triad
566
139
  * @param amount - Amount to burn
@@ -578,139 +151,5 @@ class TriadProtocol {
578
151
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
579
152
  });
580
153
  }
581
- /**
582
- * Create and Resolve Pyth Market
583
- * @param toResolve - Market to resolve
584
- * @param toResolve.marketId - Market ID
585
- * @param toResolve.winningDirection - Winning direction
586
- * @param toResolve.poolId - Pool ID
587
- * @param toResolve.withPayout - Whether to update market payout
588
- * @param market - Market to create
589
- * @param market.marketId - Market ID
590
- * @param market.resolveIn - Time to add for resolver the market in seconds
591
- * @param market.direction - Direction of the market
592
- * @param market.customer - The customer of the market
593
- * @param market.poolId - The ID of the pool
594
- */
595
- createAndResolvePythMarket(toResolve, market) {
596
- return __awaiter(this, void 0, void 0, function* () {
597
- const ixs = [];
598
- const marketInfo = yield this.getMarketById(toResolve.marketId);
599
- if (marketInfo.winningDirection === types_1.WinningDirection.NONE) {
600
- ixs.push(yield this.program.methods
601
- .updateMarketWinningDirection(toResolve.winningDirection)
602
- .accounts({
603
- signer: this.program.provider.publicKey,
604
- pool: toResolve.poolId
605
- ? (0, pda_1.getPoolPDA)(this.program.programId, toResolve.poolId)
606
- : null,
607
- market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
608
- })
609
- .instruction());
610
- if (toResolve.withPayout) {
611
- ixs.push(yield this.program.methods
612
- .updateMarketPayout(true)
613
- .accounts({
614
- signer: this.program.provider.publicKey,
615
- market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
616
- })
617
- .instruction());
618
- }
619
- }
620
- const feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(market.feedId);
621
- ixs.push(yield this.program.methods
622
- .createMarketPyth({
623
- marketId: new bn_js_1.default(market.marketId),
624
- resolveIn: new bn_js_1.default(market.resolveIn),
625
- direction: market.direction
626
- })
627
- .accounts({
628
- signer: this.program.provider.publicKey,
629
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
630
- pool: market.poolId
631
- ? (0, pda_1.getPoolPDA)(this.program.programId, market.poolId)
632
- : null,
633
- customer: market.customer,
634
- priceUpdate: feedPDA
635
- })
636
- .instruction());
637
- ixs.push(yield this.program.methods
638
- .createOrderBook(new bn_js_1.default(market.marketId))
639
- .accounts({
640
- signer: this.program.provider.publicKey,
641
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
642
- })
643
- .instruction());
644
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
645
- });
646
- }
647
- /**
648
- * Create and Resolve Market
649
- * @param toResolve - Market to resolve
650
- * @param toResolve.marketId - Market ID
651
- * @param toResolve.winningDirection - Winning direction
652
- * @param toResolve.withPayout - Whether to update market payout
653
- * @param market - Market to create
654
- * @param market.marketId - Market ID
655
- * @param market.resolveIn - Time to add for resolver the market in seconds
656
- * @param market.direction - Direction of the market
657
- * @param market.customer - The customer of the market
658
- * @param market.poolId - The ID of the pool
659
- */
660
- createAndResolveMarket(toResolve, market, customer) {
661
- return __awaiter(this, void 0, void 0, function* () {
662
- const ixs = [];
663
- const marketInfo = yield this.getMarketById(toResolve.marketId);
664
- if (marketInfo.winningDirection === types_1.WinningDirection.NONE) {
665
- ixs.push(yield this.program.methods
666
- .updateMarketWinningDirection(toResolve.winningDirection)
667
- .accounts({
668
- signer: this.program.provider.publicKey,
669
- pool: toResolve.poolId
670
- ? (0, pda_1.getPoolPDA)(this.program.programId, toResolve.poolId)
671
- : null,
672
- market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
673
- })
674
- .instruction());
675
- if (toResolve.withPayout) {
676
- ixs.push(yield this.program.methods
677
- .updateMarketPayout(true)
678
- .accounts({
679
- signer: this.program.provider.publicKey,
680
- market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
681
- })
682
- .instruction());
683
- }
684
- }
685
- ixs.push(yield this.program.methods
686
- .createMarket({
687
- marketId: new bn_js_1.default(market.marketId),
688
- question: (0, helpers_1.encodeString)(market.question, 80),
689
- marketStart: new bn_js_1.default(market.startTime),
690
- marketEnd: new bn_js_1.default(market.endTime),
691
- feeBps: market.feeBps,
692
- payoutFee: market.payoutFee,
693
- preMarketEndTs: new bn_js_1.default(0),
694
- preOrdersAvailable: new bn_js_1.default(0)
695
- })
696
- .accounts({
697
- signer: this.program.provider.publicKey,
698
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
699
- pool: toResolve.poolId
700
- ? (0, pda_1.getPoolPDA)(this.program.programId, toResolve.poolId)
701
- : null,
702
- customer
703
- })
704
- .instruction());
705
- ixs.push(yield this.program.methods
706
- .createOrderBook(new bn_js_1.default(market.marketId))
707
- .accounts({
708
- signer: this.program.provider.publicKey,
709
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
710
- })
711
- .instruction());
712
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
713
- });
714
- }
715
154
  }
716
155
  exports.default = TriadProtocol;