@triadxyz/triad-protocol 3.1.6-beta → 3.1.8-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.js CHANGED
@@ -40,6 +40,7 @@ const swap_1 = require("./utils/swap");
40
40
  const stake_1 = __importDefault(require("./stake"));
41
41
  const poseidon_1 = __importDefault(require("./poseidon"));
42
42
  const claim_1 = __importDefault(require("./claim"));
43
+ const market_1 = __importDefault(require("./market"));
43
44
  __exportStar(require("./types"), exports);
44
45
  __exportStar(require("./utils/helpers"), exports);
45
46
  __exportStar(require("./utils/merkle"), exports);
@@ -48,6 +49,9 @@ class TriadProtocolClient {
48
49
  this.connection = connection;
49
50
  this.wallet = wallet;
50
51
  this.rpcOptions = rpcOptions;
52
+ if (!this.rpcOptions.payer) {
53
+ this.rpcOptions.payer = this.wallet.publicKey;
54
+ }
51
55
  this.provider = new anchor_1.AnchorProvider(this.connection, this.wallet, {
52
56
  commitment: this.rpcOptions.commitment || 'confirmed'
53
57
  });
@@ -55,24 +59,7 @@ class TriadProtocolClient {
55
59
  this.stake = new stake_1.default(this.program, this.rpcOptions);
56
60
  this.poseidon = new poseidon_1.default(this.program, this.rpcOptions);
57
61
  this.claim = new claim_1.default(this.program, this.rpcOptions);
58
- }
59
- /**
60
- * Get All Pools
61
- */
62
- getAllPools() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const pool = yield this.program.account.pool.all();
65
- return pool.map(({ account, publicKey }) => (0, helpers_1.formatPool)(account, publicKey));
66
- });
67
- }
68
- /**
69
- * Get All Markets
70
- */
71
- getAllMarkets() {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- const marketV2 = yield this.program.account.marketV2.all();
74
- return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
75
- });
62
+ this.market = new market_1.default(this.program, this.rpcOptions);
76
63
  }
77
64
  /**
78
65
  * Get My User Trades from a user authority
@@ -125,38 +112,6 @@ class TriadProtocolClient {
125
112
  order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
126
113
  });
127
114
  }
128
- /**
129
- * Get Pool By ID
130
- * @param poolId - The ID of the pool
131
- */
132
- getPoolById(poolId) {
133
- return __awaiter(this, void 0, void 0, function* () {
134
- const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
135
- const response = yield this.program.account.pool.fetch(poolPDA);
136
- return (0, helpers_1.formatPool)(response, poolPDA);
137
- });
138
- }
139
- /**
140
- * Get Market By ID
141
- * @param marketId - The ID of the market
142
- */
143
- getMarketById(marketId) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
146
- const response = yield this.program.account.marketV2.fetch(marketPDA);
147
- return (0, helpers_1.formatMarket)(response, marketPDA);
148
- });
149
- }
150
- /**
151
- * Get Market By Address
152
- * @param marketAddress - The address of the market
153
- */
154
- getMarketByAddress(marketAddress) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- const account = yield this.program.account.marketV2.fetch(marketAddress);
157
- return (0, helpers_1.formatMarket)(account, marketAddress);
158
- });
159
- }
160
115
  /**
161
116
  * Get Costumer By Wallet Address
162
117
  * @param wallet - The wallet address of the customer
@@ -185,33 +140,6 @@ class TriadProtocolClient {
185
140
  return (0, helpers_1.formatCustomer)(customer, customerPDA);
186
141
  });
187
142
  }
188
- /**
189
- * Get Current Market ID
190
- */
191
- nextMarketId() {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- const markets = yield this.program.account.marketV2.all();
194
- return markets.length + 10;
195
- });
196
- }
197
- /**
198
- * Get Next Customer ID
199
- */
200
- nextCustomerId() {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- const customers = yield this.program.account.customer.all();
203
- return customers.length + 1;
204
- });
205
- }
206
- /**
207
- * Get Next Pool ID
208
- */
209
- nextPoolId() {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- const pools = yield this.program.account.pool.all();
212
- return pools.length + 1;
213
- });
214
- }
215
143
  /**
216
144
  * Get User Trade PDA
217
145
  * @param wallet - User wallet PublicKey
@@ -230,117 +158,12 @@ class TriadProtocolClient {
230
158
  * @param wallet - User wallet PublicKey
231
159
  * @param userNonce - The nonce of the user
232
160
  */
233
- getUserTrade(wallet, userNonce = 0) {
161
+ getUserTradeByNonce(wallet, userNonce = 0) {
234
162
  return __awaiter(this, void 0, void 0, function* () {
235
163
  const userTradePDA = this.getUserPDA(wallet, userNonce);
236
164
  return this.program.account.userTrade.fetch(userTradePDA);
237
165
  });
238
166
  }
239
- /**
240
- * Create Market
241
- * @param args.markets - Array of markets to create
242
- * @param args.markets.marketId - Market ID
243
- * @param args.markets.startTime - start time
244
- * @param args.markets.endTime - end time
245
- * @param args.markets.question - question (max 80 characters)
246
- * @param args.markets.liquidityAtStart - liquidity at start
247
- * @param args.markets.payoutFee - payout fee (to add affiliate system)
248
- * @param args.customer - The customer of the market
249
- * @param args.poolId - The ID of the pool
250
- */
251
- createMarket({ markets, customer, poolId }) {
252
- return __awaiter(this, void 0, void 0, function* () {
253
- const ixs = [];
254
- let poolPDA = null;
255
- if (poolId) {
256
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
257
- }
258
- for (const market of markets) {
259
- if (market.question.length > 80) {
260
- throw new Error('Question must be less than 80 characters');
261
- }
262
- ixs.push(yield this.program.methods
263
- .createMarket({
264
- marketId: new bn_js_1.default(market.marketId),
265
- question: (0, helpers_1.encodeString)(market.question, 80),
266
- marketStart: new bn_js_1.default(market.startTime),
267
- marketEnd: new bn_js_1.default(market.endTime),
268
- feeBps: market.feeBps,
269
- payoutFee: market.payoutFee
270
- })
271
- .accounts({
272
- signer: this.program.provider.publicKey,
273
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
274
- pool: poolPDA,
275
- customer
276
- })
277
- .instruction());
278
- ixs.push(yield this.program.methods
279
- .createOrderBook(new bn_js_1.default(market.marketId))
280
- .accounts({
281
- signer: this.program.provider.publicKey,
282
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
283
- })
284
- .instruction());
285
- }
286
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
287
- });
288
- }
289
- /**
290
- * Create Pool
291
- * @param poolId - The ID of the pool
292
- * @param question - The question of the pool
293
- * @param markets - The markets of the pool
294
- */
295
- createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }) {
296
- return __awaiter(this, void 0, void 0, function* () {
297
- if (question.length > 80) {
298
- throw new Error('Pool question must be less than 80 characters');
299
- }
300
- const ixs = [];
301
- const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
302
- ixs.push(yield this.program.methods
303
- .createPool({
304
- poolId: new bn_js_1.default(poolId),
305
- question: (0, helpers_1.encodeString)(question, 80),
306
- isFast
307
- })
308
- .accounts({
309
- signer: this.program.provider.publicKey,
310
- customer
311
- })
312
- .instruction());
313
- for (const market of markets) {
314
- if (market.question.length > 80) {
315
- throw new Error('Market question must be less than 80 characters');
316
- }
317
- ixs.push(yield this.program.methods
318
- .createMarket({
319
- marketId: new bn_js_1.default(market.marketId),
320
- question: (0, helpers_1.encodeString)(market.question, 80),
321
- marketStart: new bn_js_1.default(startTime),
322
- marketEnd: new bn_js_1.default(endTime),
323
- feeBps,
324
- payoutFee
325
- })
326
- .accounts({
327
- signer: this.program.provider.publicKey,
328
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
329
- pool: poolPDA,
330
- customer
331
- })
332
- .instruction());
333
- ixs.push(yield this.program.methods
334
- .createOrderBook(new bn_js_1.default(market.marketId))
335
- .accounts({
336
- signer: this.program.provider.publicKey,
337
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
338
- })
339
- .instruction());
340
- }
341
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
342
- });
343
- }
344
167
  /**
345
168
  * Open Order
346
169
  * @param args.marketId - The ID of the Market
@@ -381,6 +204,7 @@ class TriadProtocolClient {
381
204
  })
382
205
  .accounts({
383
206
  signer: this.program.provider.publicKey,
207
+ payer: this.rpcOptions.payer,
384
208
  market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
385
209
  userTrade: userTradePDA,
386
210
  mint
@@ -397,41 +221,19 @@ class TriadProtocolClient {
397
221
  */
398
222
  closeOrder({ marketId, orderId, userNonce }) {
399
223
  return __awaiter(this, void 0, void 0, function* () {
400
- const ixs = [];
401
224
  const userTrade = this.getUserPDA(this.program.provider.publicKey, userNonce);
402
- ixs.push(yield this.program.methods
403
- .closeOrder(new bn_js_1.default(orderId))
404
- .accounts({
405
- signer: this.program.provider.publicKey,
406
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
407
- mint: constants_1.TRD_MINT,
408
- userTrade
409
- })
410
- .instruction());
411
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
412
- });
413
- }
414
- /**
415
- * Resolve Market
416
- * @param args.marketId - The ID of the Market
417
- * @param args.poolId - The ID of the Pool
418
- * @param args.winningDirection - The Winning Direction of the Market
419
- */
420
- updateMarketWinningDirection({ marketId, poolId, winningDirection }) {
421
- return __awaiter(this, void 0, void 0, function* () {
422
- const ixs = [];
423
- let poolPDA = null;
424
- if (poolId) {
425
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
426
- }
427
- ixs.push(yield this.program.methods
428
- .updateMarketWinningDirection(winningDirection)
429
- .accounts({
430
- signer: this.program.provider.publicKey,
431
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
432
- pool: poolPDA
433
- })
434
- .instruction());
225
+ const ixs = [
226
+ yield this.program.methods
227
+ .closeOrder(new bn_js_1.default(orderId))
228
+ .accounts({
229
+ signer: this.program.provider.publicKey,
230
+ payer: this.rpcOptions.payer,
231
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
232
+ mint: constants_1.TRD_MINT,
233
+ userTrade
234
+ })
235
+ .instruction()
236
+ ];
435
237
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
436
238
  });
437
239
  }
@@ -453,6 +255,7 @@ class TriadProtocolClient {
453
255
  .payoutOrder(new bn_js_1.default(order.orderId))
454
256
  .accounts({
455
257
  signer: this.program.provider.publicKey,
258
+ payer: this.rpcOptions.payer,
456
259
  userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce),
457
260
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
458
261
  mint: order.mint,
@@ -463,29 +266,6 @@ class TriadProtocolClient {
463
266
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
464
267
  });
465
268
  }
466
- /**
467
- * Update Market Payout
468
- * @param marketId - The ID of the market
469
- * @param poolId - The ID of the pool
470
- * @param allowPayout - Whether to allow the market to payout
471
- */
472
- updateMarketPayout({ marketId, poolId, allowPayout }) {
473
- return __awaiter(this, void 0, void 0, function* () {
474
- const ixs = [];
475
- let poolPDA = null;
476
- if (poolId) {
477
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
478
- }
479
- ixs.push(yield this.program.methods
480
- .updateMarketPayout(allowPayout)
481
- .accounts({
482
- signer: this.program.provider.publicKey,
483
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
484
- })
485
- .instruction());
486
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
487
- });
488
- }
489
269
  /**
490
270
  * Create Sub User Trade
491
271
  * @param user - User PublicKey the main user
@@ -493,48 +273,13 @@ class TriadProtocolClient {
493
273
  createSubUserTrade(user) {
494
274
  return __awaiter(this, void 0, void 0, function* () {
495
275
  const ixs = [];
496
- const userTrade = yield this.getUserTrade(user);
276
+ const userTrade = yield this.getUserTradeByNonce(user);
497
277
  const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, user, userTrade.nonce + 1);
498
278
  ixs.push(yield this.program.methods
499
279
  .createSubUserTrade(subUserTradePDA)
500
280
  .accounts({
501
- signer: this.program.provider.publicKey
502
- })
503
- .instruction());
504
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
505
- });
506
- }
507
- /**
508
- * Update Market End
509
- * @param marketId - The ID of the market
510
- * @param marketEnd - The end time of the market
511
- */
512
- updateMarketEnd({ marketId, marketEnd }) {
513
- return __awaiter(this, void 0, void 0, function* () {
514
- const ixs = [];
515
- ixs.push(yield this.program.methods
516
- .updateMarketEnd(new bn_js_1.default(marketEnd))
517
- .accounts({
518
- signer: this.program.provider.publicKey,
519
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
520
- })
521
- .instruction());
522
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
523
- });
524
- }
525
- /**
526
- * Update Market Question
527
- * @param marketId - The ID of the market
528
- * @param question - The question of the market
529
- */
530
- updateMarketQuestion({ marketId, question }) {
531
- return __awaiter(this, void 0, void 0, function* () {
532
- const ixs = [];
533
- ixs.push(yield this.program.methods
534
- .updateMarketQuestion((0, helpers_1.encodeString)(question, 80))
535
- .accounts({
536
281
  signer: this.program.provider.publicKey,
537
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
282
+ payer: this.rpcOptions.payer
538
283
  })
539
284
  .instruction());
540
285
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
@@ -560,28 +305,6 @@ class TriadProtocolClient {
560
305
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
561
306
  });
562
307
  }
563
- /**
564
- * Get User Trade Nonce With Slots
565
- * @param userTrades - User Trades
566
- */
567
- getUserTradeNonceWithSlots(userTrades) {
568
- let nonce = null;
569
- for (const userTrade of userTrades) {
570
- if (nonce !== null) {
571
- break;
572
- }
573
- userTrade.orders.forEach((order) => {
574
- if (order.orderStatus === types_1.OrderStatus.INIT ||
575
- order.orderStatus === types_1.OrderStatus.CLOSED) {
576
- nonce = userTrade.isSubUser ? Number(userTrade.nonce) : 0;
577
- }
578
- });
579
- }
580
- if (nonce === null) {
581
- throw new Error('No open orders found');
582
- }
583
- return this.getUserPDA(this.program.provider.publicKey, nonce);
584
- }
585
308
  /**
586
309
  * Get User Trade Ixs
587
310
  */
@@ -594,7 +317,8 @@ class TriadProtocolClient {
594
317
  ixs.push(yield this.program.methods
595
318
  .createUserTrade()
596
319
  .accounts({
597
- signer: this.program.provider.publicKey
320
+ signer: this.program.provider.publicKey,
321
+ payer: this.rpcOptions.payer
598
322
  })
599
323
  .instruction());
600
324
  return {
@@ -604,8 +328,25 @@ class TriadProtocolClient {
604
328
  };
605
329
  }
606
330
  try {
607
- const userTradePDA = this.getUserTradeNonceWithSlots(myUserTrades);
608
- return { userTradePDA, ixs };
331
+ let nonce = null;
332
+ for (const userTrade of myUserTrades) {
333
+ if (nonce !== null) {
334
+ break;
335
+ }
336
+ userTrade.orders.forEach((order) => {
337
+ if (order.orderStatus === types_1.OrderStatus.INIT ||
338
+ order.orderStatus === types_1.OrderStatus.CLOSED) {
339
+ nonce = userTrade.isSubUser ? Number(userTrade.nonce) : 0;
340
+ }
341
+ });
342
+ }
343
+ if (nonce === null) {
344
+ throw new Error('No open orders found');
345
+ }
346
+ return {
347
+ userTradePDA: this.getUserPDA(this.program.provider.publicKey, nonce),
348
+ ixs
349
+ };
609
350
  }
610
351
  catch (_a) {
611
352
  const mainUserTrade = myUserTrades.find((trade) => !trade.isSubUser);
@@ -613,7 +354,8 @@ class TriadProtocolClient {
613
354
  ixs.push(yield this.program.methods
614
355
  .createSubUserTrade(subUserTradePDA)
615
356
  .accounts({
616
- signer: this.program.provider.publicKey
357
+ signer: this.program.provider.publicKey,
358
+ payer: this.rpcOptions.payer
617
359
  })
618
360
  .instruction());
619
361
  return {
@@ -633,7 +375,8 @@ class TriadProtocolClient {
633
375
  return __awaiter(this, void 0, void 0, function* () {
634
376
  const userOrders = yield this.getUserOrdersByMarketId(this.program.provider.publicKey, marketId);
635
377
  const userNonce = (_a = userOrders.find((order) => order.orderDirection === orderDirection &&
636
- order.orderStatus === types_1.OrderStatus.OPEN)) === null || _a === void 0 ? void 0 : _a.userNonce;
378
+ order.orderStatus === types_1.OrderStatus.OPEN &&
379
+ Number(order.marketId) === marketId)) === null || _a === void 0 ? void 0 : _a.userNonce;
637
380
  let userTradePDA = null;
638
381
  let userTradeIxs = [];
639
382
  if (userNonce) {
@@ -690,11 +433,11 @@ class TriadProtocolClient {
690
433
  return;
691
434
  }
692
435
  }
693
- const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(orders[0].orderDirection)[0]);
694
- if (userTradeIxs.length > 0) {
695
- ixs.push(...userTradeIxs);
696
- }
697
436
  for (const order of orders) {
437
+ const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(order.orderDirection)[0]);
438
+ if (userTradeIxs.length > 0) {
439
+ ixs.push(...userTradeIxs);
440
+ }
698
441
  ixs.push(yield this.program.methods
699
442
  .placeBidOrder({
700
443
  amount: new bn_js_1.default(order.amount * Math.pow(10, constants_1.BASE_DECIMALS)),
@@ -766,6 +509,7 @@ class TriadProtocolClient {
766
509
  })
767
510
  .accounts({
768
511
  signer: this.program.provider.publicKey,
512
+ payer: this.rpcOptions.payer,
769
513
  market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
770
514
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
771
515
  userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
@@ -810,10 +554,9 @@ class TriadProtocolClient {
810
554
  * @param args.marketId - The ID of the Market
811
555
  * @param args.amount - The amount of the Order
812
556
  * @param args.orderDirection - The direction of the Order
813
- * @param args.feeBps - The fee in basis points
814
557
  * @param args.isTrdPayout - Whether to payout in TRD or not
815
558
  */
816
- marketBidOrder({ marketId, amount, orderDirection, feeBps = 0, isTrdPayout }) {
559
+ marketBidOrder({ marketId, amount, orderDirection, isTrdPayout }) {
817
560
  return __awaiter(this, void 0, void 0, function* () {
818
561
  const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
819
562
  const ixs = [];
@@ -842,15 +585,13 @@ class TriadProtocolClient {
842
585
  const orderPrice = new bn_js_1.default(order.price);
843
586
  const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
844
587
  let adjustedPrice = orderPrice;
845
- if (feeBps > 0) {
846
- const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
847
- const fee = priceSpread
848
- .mul(orderPrice)
849
- .mul(new bn_js_1.default(feeBps))
850
- .div(new bn_js_1.default(10000))
851
- .div(new bn_js_1.default(1000000));
852
- adjustedPrice = orderPrice.add(fee);
853
- }
588
+ const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
589
+ const fee = priceSpread
590
+ .mul(orderPrice)
591
+ .mul(new bn_js_1.default(700))
592
+ .div(new bn_js_1.default(10000))
593
+ .div(new bn_js_1.default(1000000));
594
+ adjustedPrice = orderPrice.add(fee);
854
595
  const maxSharesForPrice = tempRemainingUSDC
855
596
  .mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
856
597
  .div(adjustedPrice);
@@ -891,15 +632,13 @@ class TriadProtocolClient {
891
632
  const orderPrice = new bn_js_1.default(order.price);
892
633
  const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
893
634
  let adjustedPrice = orderPrice;
894
- if (feeBps > 0) {
895
- const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
896
- const fee = priceSpread
897
- .mul(orderPrice)
898
- .mul(new bn_js_1.default(feeBps))
899
- .div(new bn_js_1.default(10000))
900
- .div(new bn_js_1.default(1000000));
901
- adjustedPrice = orderPrice.add(fee);
902
- }
635
+ const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
636
+ const fee = priceSpread
637
+ .mul(orderPrice)
638
+ .mul(new bn_js_1.default(700))
639
+ .div(new bn_js_1.default(10000))
640
+ .div(new bn_js_1.default(1000000));
641
+ adjustedPrice = orderPrice.add(fee);
903
642
  const maxSharesForPrice = remainingUSDC
904
643
  .mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
905
644
  .div(adjustedPrice);
@@ -920,15 +659,14 @@ class TriadProtocolClient {
920
659
  })
921
660
  .accounts({
922
661
  signer: this.program.provider.publicKey,
662
+ payer: this.rpcOptions.payer,
923
663
  market: marketPDA,
924
664
  buyerTrade: userTradePDA,
925
665
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
926
666
  sellerAuthority: new web3_js_1.PublicKey(order.authority),
927
667
  sellerTrade: this.getUserPDA(new web3_js_1.PublicKey(order.authority), Number(order.userNonce)),
928
668
  marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
929
- buyerAta: (0, pda_1.getTokenATA)(this.program.provider.publicKey, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
930
- mint: constants_1.USDC_MINT,
931
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
669
+ buyerAta: (0, pda_1.getTokenATA)(this.program.provider.publicKey, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID)
932
670
  })
933
671
  .instruction());
934
672
  remainingUSDC = remainingUSDC.sub(usdcAmount);
@@ -999,6 +737,7 @@ class TriadProtocolClient {
999
737
  })
1000
738
  .accounts({
1001
739
  signer: this.program.provider.publicKey,
740
+ payer: this.rpcOptions.payer,
1002
741
  market: marketPDA,
1003
742
  buyerAuthority: new web3_js_1.PublicKey(order.authority),
1004
743
  buyerTrade: this.getUserPDA(new web3_js_1.PublicKey(order.authority), Number(order.userNonce)),
@@ -1067,87 +806,6 @@ class TriadProtocolClient {
1067
806
  return data;
1068
807
  });
1069
808
  }
1070
- /**
1071
- * Collect Market Fee
1072
- * @param args.markets - The markets to collect the fee from
1073
- * @param args.markets.marketAddress - The address of the market
1074
- * @param args.markets.customerId - The ID of the customer
1075
- * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
1076
- */
1077
- collectMarketFee({ markets }) {
1078
- return __awaiter(this, void 0, void 0, function* () {
1079
- const ixs = [];
1080
- for (const market of markets) {
1081
- ixs.push(yield this.program.methods
1082
- .collectMarketFee()
1083
- .accounts({
1084
- signer: this.program.provider.publicKey,
1085
- market: market.marketAddress,
1086
- customer: (0, pda_1.getCustomerPDA)(this.program.programId, market.customerId),
1087
- customerFeeRecipient: market.customerFeeRecipient
1088
- })
1089
- .instruction());
1090
- }
1091
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
1092
- });
1093
- }
1094
- /**
1095
- * Collect Market Order Fee
1096
- * @param marketAddress - The address of the market
1097
- */
1098
- collectMarketOrderFee(marketAddress) {
1099
- return __awaiter(this, void 0, void 0, function* () {
1100
- const ixs = [];
1101
- for (const market of marketAddress) {
1102
- ixs.push(yield this.program.methods
1103
- .collectMarketOrderFee()
1104
- .accounts({
1105
- signer: this.program.provider.publicKey,
1106
- market: market
1107
- })
1108
- .instruction());
1109
- }
1110
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
1111
- });
1112
- }
1113
- /**
1114
- * Close Order Book
1115
- * @param marketIds - Market IDs
1116
- */
1117
- closeOrderBook(marketIds) {
1118
- return __awaiter(this, void 0, void 0, function* () {
1119
- const ixs = [];
1120
- for (const marketId of marketIds) {
1121
- ixs.push(yield this.program.methods
1122
- .closeOrderBook()
1123
- .accounts({
1124
- signer: this.program.provider.publicKey,
1125
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
1126
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId)
1127
- })
1128
- .instruction());
1129
- }
1130
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
1131
- });
1132
- }
1133
- /**
1134
- * Update Pool Question
1135
- * @param poolId - Pool ID
1136
- * @param question - Question
1137
- */
1138
- updatePoolQuestion(poolId, question) {
1139
- return __awaiter(this, void 0, void 0, function* () {
1140
- const ixs = [];
1141
- ixs.push(yield this.program.methods
1142
- .updatePoolQuestion((0, helpers_1.encodeString)(question, 80))
1143
- .accounts({
1144
- signer: this.program.provider.publicKey,
1145
- pool: (0, pda_1.getPoolPDA)(this.program.programId, poolId)
1146
- })
1147
- .instruction());
1148
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
1149
- });
1150
- }
1151
809
  /**
1152
810
  * Update Customer Fee
1153
811
  * @param customerId - Customer ID
@@ -1155,13 +813,14 @@ class TriadProtocolClient {
1155
813
  */
1156
814
  updateCustomerFee({ customerId, feeBps }) {
1157
815
  return __awaiter(this, void 0, void 0, function* () {
1158
- const ixs = [];
1159
- ixs.push(yield this.program.methods
1160
- .updateCustomerFee({ id: customerId, feeBps })
1161
- .accounts({
1162
- signer: this.program.provider.publicKey
1163
- })
1164
- .instruction());
816
+ const ixs = [
817
+ yield this.program.methods
818
+ .updateCustomerFee({ id: customerId, feeBps })
819
+ .accounts({
820
+ signer: this.program.provider.publicKey
821
+ })
822
+ .instruction()
823
+ ];
1165
824
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
1166
825
  });
1167
826
  }