@triadxyz/triad-protocol 3.1.8-beta → 3.1.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/index.d.ts CHANGED
@@ -3,11 +3,10 @@ import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
3
3
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
4
4
  import BN from 'bn.js';
5
5
  import { TriadProtocol } from './types/triad_protocol';
6
- import { OpenOrderArgs, UserTrade, CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, BookOrder, MarketAskOrderArgs, RpcOptions, OrderDirection, CloseOrderArgs } from './types';
6
+ import { OpenOrderArgs, UserTrade, CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, BookOrder, MarketAskOrderArgs, RpcOptions, OrderDirection, CloseOrderArgs, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs } from './types';
7
7
  import Stake from './stake';
8
8
  import Poseidon from './poseidon';
9
9
  import Claim from './claim';
10
- import Market from './market';
11
10
  export * from './types';
12
11
  export * from './utils/helpers';
13
12
  export * from './utils/merkle';
@@ -20,7 +19,6 @@ export default class TriadProtocolClient {
20
19
  stake: Stake;
21
20
  poseidon: Poseidon;
22
21
  claim: Claim;
23
- market: Market;
24
22
  constructor(connection: Connection, wallet: Wallet, rpcOptions: RpcOptions);
25
23
  /**
26
24
  * Get My User Trades from a user authority
@@ -165,6 +163,125 @@ export default class TriadProtocolClient {
165
163
  poseidon: number;
166
164
  padding: number[];
167
165
  }>;
166
+ /**
167
+ * Get All Pools
168
+ */
169
+ getAllPools(): Promise<import("./types").Pool[]>;
170
+ /**
171
+ * Get All Markets
172
+ */
173
+ getAllMarkets(): Promise<import("./types").Market[]>;
174
+ /**
175
+ * Get Pool By ID
176
+ * @param poolId - The ID of the pool
177
+ */
178
+ getPoolById(poolId: number): Promise<import("./types").Pool>;
179
+ /**
180
+ * Get Market By ID
181
+ * @param marketId - The ID of the market
182
+ */
183
+ getMarketById(marketId: number): Promise<import("./types").Market>;
184
+ /**
185
+ * Get Market By Address
186
+ * @param marketAddress - The address of the market
187
+ */
188
+ getMarketByAddress(marketAddress: PublicKey): Promise<import("./types").Market>;
189
+ /**
190
+ * Get Current Market ID
191
+ */
192
+ nextMarketId(): Promise<number>;
193
+ /**
194
+ * Get Next Customer ID
195
+ */
196
+ nextCustomerId(): Promise<number>;
197
+ /**
198
+ * Get Next Pool ID
199
+ */
200
+ nextPoolId(): Promise<number>;
201
+ /**
202
+ * Create Market
203
+ * @param args.markets - Array of markets to create
204
+ * @param args.markets.marketId - Market ID
205
+ * @param args.markets.startTime - start time
206
+ * @param args.markets.endTime - end time
207
+ * @param args.markets.question - question (max 80 characters)
208
+ * @param args.markets.liquidityAtStart - liquidity at start
209
+ * @param args.markets.payoutFee - payout fee (to add affiliate system)
210
+ * @param args.customer - The customer of the market
211
+ * @param args.poolId - The ID of the pool
212
+ */
213
+ createMarket({ markets, customer, poolId }: CreateMarketArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
214
+ /**
215
+ * Create Pool
216
+ * @param poolId - The ID of the pool
217
+ * @param question - The question of the pool
218
+ * @param markets - The markets of the pool
219
+ */
220
+ createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
221
+ /**
222
+ * Resolve Market
223
+ * @param args.marketId - The ID of the Market
224
+ * @param args.poolId - The ID of the Pool
225
+ * @param args.winningDirection - The Winning Direction of the Market
226
+ */
227
+ updateMarketWinningDirection({ marketId, poolId, winningDirection }: UpdateMarketWinningDirectionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
228
+ /**
229
+ * Update Market Payout
230
+ * @param marketId - The ID of the market
231
+ * @param poolId - The ID of the pool
232
+ * @param allowPayout - Whether to allow the market to payout
233
+ */
234
+ updateMarketPayout({ marketId, poolId, allowPayout }: {
235
+ marketId: number;
236
+ poolId?: number;
237
+ allowPayout: boolean;
238
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
239
+ /**
240
+ * Update Market End
241
+ * @param marketId - The ID of the market
242
+ * @param marketEnd - The end time of the market
243
+ */
244
+ updateMarketEnd({ marketId, marketEnd }: {
245
+ marketId: number;
246
+ marketEnd: number;
247
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
248
+ /**
249
+ * Update Market Question
250
+ * @param marketId - The ID of the market
251
+ * @param question - The question of the market
252
+ */
253
+ updateMarketQuestion({ marketId, question }: {
254
+ marketId: number;
255
+ question: string;
256
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
257
+ /**
258
+ * Collect Market Fee
259
+ * @param args.markets - The markets to collect the fee from
260
+ * @param args.markets.marketAddress - The address of the market
261
+ * @param args.markets.customerId - The ID of the customer
262
+ * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
263
+ */
264
+ collectMarketFee(markets: {
265
+ marketAddress: PublicKey;
266
+ customerId: number;
267
+ customerFeeRecipient: PublicKey;
268
+ }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
269
+ /**
270
+ * Collect Market Order Fee
271
+ * @param marketAddress - The address of the market
272
+ */
273
+ collectMarketOrderFee(marketAddress: PublicKey[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
274
+ /**
275
+ * Close Order Book
276
+ * @param marketIds - Market IDs
277
+ */
278
+ closeOrderBook(marketIds: number[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
279
+ /**
280
+ * Update Pool Question
281
+ * @param poolId - Pool ID
282
+ * @param question - Question
283
+ */
284
+ updatePoolQuestion(poolId: number, question: string): Promise<string | import("@solana/web3.js").VersionedTransaction>;
168
285
  /**
169
286
  * Open Order
170
287
  * @param args.marketId - The ID of the Market
package/dist/index.js CHANGED
@@ -30,17 +30,17 @@ const web3_js_1 = require("@solana/web3.js");
30
30
  const anchor_1 = require("@coral-xyz/anchor");
31
31
  const spl_token_1 = require("@solana/spl-token");
32
32
  const bn_js_1 = __importDefault(require("bn.js"));
33
+ const helpers_1 = require("./utils/helpers");
33
34
  const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
34
35
  const types_1 = require("./types");
35
36
  const constants_1 = require("./utils/constants");
36
- const helpers_1 = require("./utils/helpers");
37
+ const helpers_2 = require("./utils/helpers");
37
38
  const pda_1 = require("./utils/pda");
38
39
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
39
40
  const swap_1 = require("./utils/swap");
40
41
  const stake_1 = __importDefault(require("./stake"));
41
42
  const poseidon_1 = __importDefault(require("./poseidon"));
42
43
  const claim_1 = __importDefault(require("./claim"));
43
- const market_1 = __importDefault(require("./market"));
44
44
  __exportStar(require("./types"), exports);
45
45
  __exportStar(require("./utils/helpers"), exports);
46
46
  __exportStar(require("./utils/merkle"), exports);
@@ -59,7 +59,6 @@ class TriadProtocolClient {
59
59
  this.stake = new stake_1.default(this.program, this.rpcOptions);
60
60
  this.poseidon = new poseidon_1.default(this.program, this.rpcOptions);
61
61
  this.claim = new claim_1.default(this.program, this.rpcOptions);
62
- this.market = new market_1.default(this.program, this.rpcOptions);
63
62
  }
64
63
  /**
65
64
  * Get My User Trades from a user authority
@@ -75,7 +74,7 @@ class TriadProtocolClient {
75
74
  }
76
75
  }
77
76
  ]);
78
- return response.map(({ account, publicKey }) => (0, helpers_1.formatUserTrade)(account, publicKey));
77
+ return response.map(({ account, publicKey }) => (0, helpers_2.formatUserTrade)(account, publicKey));
79
78
  });
80
79
  }
81
80
  /**
@@ -107,7 +106,7 @@ class TriadProtocolClient {
107
106
  const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId));
108
107
  const orders = [...orderBook.hypeOrders, ...orderBook.flopOrders];
109
108
  return orders
110
- .map((order) => (0, helpers_1.formatBookOrder)(order))
109
+ .map((order) => (0, helpers_2.formatBookOrder)(order))
111
110
  .filter((order) => order.authority === wallet.toBase58() &&
112
111
  order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
113
112
  });
@@ -126,7 +125,7 @@ class TriadProtocolClient {
126
125
  }
127
126
  }
128
127
  ]);
129
- return (0, helpers_1.formatCustomer)(customer.account, customer.publicKey);
128
+ return (0, helpers_2.formatCustomer)(customer.account, customer.publicKey);
130
129
  });
131
130
  }
132
131
  /**
@@ -137,7 +136,7 @@ class TriadProtocolClient {
137
136
  return __awaiter(this, void 0, void 0, function* () {
138
137
  const customerPDA = (0, pda_1.getCustomerPDA)(this.program.programId, customerId);
139
138
  const customer = yield this.program.account.customer.fetch(customerPDA);
140
- return (0, helpers_1.formatCustomer)(customer, customerPDA);
139
+ return (0, helpers_2.formatCustomer)(customer, customerPDA);
141
140
  });
142
141
  }
143
142
  /**
@@ -164,6 +163,357 @@ class TriadProtocolClient {
164
163
  return this.program.account.userTrade.fetch(userTradePDA);
165
164
  });
166
165
  }
166
+ /**
167
+ * Get All Pools
168
+ */
169
+ getAllPools() {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ const pool = yield this.program.account.pool.all();
172
+ return pool.map(({ account, publicKey }) => (0, helpers_1.formatPool)(account, publicKey));
173
+ });
174
+ }
175
+ /**
176
+ * Get All Markets
177
+ */
178
+ getAllMarkets() {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ const marketV2 = yield this.program.account.marketV2.all();
181
+ return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
182
+ });
183
+ }
184
+ /**
185
+ * Get Pool By ID
186
+ * @param poolId - The ID of the pool
187
+ */
188
+ getPoolById(poolId) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
191
+ const response = yield this.program.account.pool.fetch(poolPDA);
192
+ return (0, helpers_1.formatPool)(response, poolPDA);
193
+ });
194
+ }
195
+ /**
196
+ * Get Market By ID
197
+ * @param marketId - The ID of the market
198
+ */
199
+ getMarketById(marketId) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
202
+ const response = yield this.program.account.marketV2.fetch(marketPDA);
203
+ return (0, helpers_1.formatMarket)(response, marketPDA);
204
+ });
205
+ }
206
+ /**
207
+ * Get Market By Address
208
+ * @param marketAddress - The address of the market
209
+ */
210
+ getMarketByAddress(marketAddress) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ const account = yield this.program.account.marketV2.fetch(marketAddress);
213
+ return (0, helpers_1.formatMarket)(account, marketAddress);
214
+ });
215
+ }
216
+ /**
217
+ * Get Current Market ID
218
+ */
219
+ nextMarketId() {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const markets = yield this.program.account.marketV2.all();
222
+ return markets.length + 10;
223
+ });
224
+ }
225
+ /**
226
+ * Get Next Customer ID
227
+ */
228
+ nextCustomerId() {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ const customers = yield this.program.account.customer.all();
231
+ return customers.length + 1;
232
+ });
233
+ }
234
+ /**
235
+ * Get Next Pool ID
236
+ */
237
+ nextPoolId() {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ const pools = yield this.program.account.pool.all();
240
+ return pools.length + 1;
241
+ });
242
+ }
243
+ /**
244
+ * Create Market
245
+ * @param args.markets - Array of markets to create
246
+ * @param args.markets.marketId - Market ID
247
+ * @param args.markets.startTime - start time
248
+ * @param args.markets.endTime - end time
249
+ * @param args.markets.question - question (max 80 characters)
250
+ * @param args.markets.liquidityAtStart - liquidity at start
251
+ * @param args.markets.payoutFee - payout fee (to add affiliate system)
252
+ * @param args.customer - The customer of the market
253
+ * @param args.poolId - The ID of the pool
254
+ */
255
+ createMarket({ markets, customer, poolId }) {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ const ixs = [];
258
+ let poolPDA = null;
259
+ if (poolId) {
260
+ poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
261
+ }
262
+ for (const market of markets) {
263
+ if (market.question.length > 80) {
264
+ throw new Error('Question must be less than 80 characters');
265
+ }
266
+ ixs.push(yield this.program.methods
267
+ .createMarket({
268
+ marketId: new bn_js_1.default(market.marketId),
269
+ question: (0, helpers_1.encodeString)(market.question, 80),
270
+ marketStart: new bn_js_1.default(market.startTime),
271
+ marketEnd: new bn_js_1.default(market.endTime),
272
+ feeBps: market.feeBps,
273
+ payoutFee: market.payoutFee
274
+ })
275
+ .accounts({
276
+ signer: this.program.provider.publicKey,
277
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
278
+ pool: poolPDA,
279
+ customer
280
+ })
281
+ .instruction());
282
+ ixs.push(yield this.program.methods
283
+ .createOrderBook(new bn_js_1.default(market.marketId))
284
+ .accounts({
285
+ signer: this.program.provider.publicKey,
286
+ market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
287
+ })
288
+ .instruction());
289
+ }
290
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
291
+ });
292
+ }
293
+ /**
294
+ * Create Pool
295
+ * @param poolId - The ID of the pool
296
+ * @param question - The question of the pool
297
+ * @param markets - The markets of the pool
298
+ */
299
+ createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }) {
300
+ return __awaiter(this, void 0, void 0, function* () {
301
+ if (question.length > 80) {
302
+ throw new Error('Pool question must be less than 80 characters');
303
+ }
304
+ const ixs = [];
305
+ const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
306
+ ixs.push(yield this.program.methods
307
+ .createPool({
308
+ poolId: new bn_js_1.default(poolId),
309
+ question: (0, helpers_1.encodeString)(question, 80),
310
+ isFast
311
+ })
312
+ .accounts({
313
+ signer: this.program.provider.publicKey,
314
+ customer
315
+ })
316
+ .instruction());
317
+ for (const market of markets) {
318
+ if (market.question.length > 80) {
319
+ throw new Error('Market question must be less than 80 characters');
320
+ }
321
+ ixs.push(yield this.program.methods
322
+ .createMarket({
323
+ marketId: new bn_js_1.default(market.marketId),
324
+ question: (0, helpers_1.encodeString)(market.question, 80),
325
+ marketStart: new bn_js_1.default(startTime),
326
+ marketEnd: new bn_js_1.default(endTime),
327
+ feeBps,
328
+ payoutFee
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
+ * Resolve Market
350
+ * @param args.marketId - The ID of the Market
351
+ * @param args.poolId - The ID of the Pool
352
+ * @param args.winningDirection - The Winning Direction of the Market
353
+ */
354
+ updateMarketWinningDirection({ marketId, poolId, winningDirection }) {
355
+ return __awaiter(this, void 0, void 0, function* () {
356
+ let poolPDA = null;
357
+ if (poolId) {
358
+ poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
359
+ }
360
+ const ixs = [
361
+ yield this.program.methods
362
+ .updateMarketWinningDirection(winningDirection)
363
+ .accounts({
364
+ signer: this.program.provider.publicKey,
365
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
366
+ pool: poolPDA
367
+ })
368
+ .instruction()
369
+ ];
370
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
371
+ });
372
+ }
373
+ /**
374
+ * Update Market Payout
375
+ * @param marketId - The ID of the market
376
+ * @param poolId - The ID of the pool
377
+ * @param allowPayout - Whether to allow the market to payout
378
+ */
379
+ updateMarketPayout({ marketId, poolId, allowPayout }) {
380
+ return __awaiter(this, void 0, void 0, function* () {
381
+ let poolPDA = null;
382
+ if (poolId) {
383
+ poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
384
+ }
385
+ const ixs = [
386
+ yield this.program.methods
387
+ .updateMarketPayout(allowPayout)
388
+ .accounts({
389
+ signer: this.program.provider.publicKey,
390
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
391
+ })
392
+ .instruction()
393
+ ];
394
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
395
+ });
396
+ }
397
+ /**
398
+ * Update Market End
399
+ * @param marketId - The ID of the market
400
+ * @param marketEnd - The end time of the market
401
+ */
402
+ updateMarketEnd({ marketId, marketEnd }) {
403
+ return __awaiter(this, void 0, void 0, function* () {
404
+ const ixs = [
405
+ yield this.program.methods
406
+ .updateMarketEnd(new bn_js_1.default(marketEnd))
407
+ .accounts({
408
+ signer: this.program.provider.publicKey,
409
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
410
+ })
411
+ .instruction()
412
+ ];
413
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
414
+ });
415
+ }
416
+ /**
417
+ * Update Market Question
418
+ * @param marketId - The ID of the market
419
+ * @param question - The question of the market
420
+ */
421
+ updateMarketQuestion({ marketId, question }) {
422
+ return __awaiter(this, void 0, void 0, function* () {
423
+ const ixs = [
424
+ yield this.program.methods
425
+ .updateMarketQuestion((0, helpers_1.encodeString)(question, 80))
426
+ .accounts({
427
+ signer: this.program.provider.publicKey,
428
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
429
+ })
430
+ .instruction()
431
+ ];
432
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
433
+ });
434
+ }
435
+ /**
436
+ * Collect Market Fee
437
+ * @param args.markets - The markets to collect the fee from
438
+ * @param args.markets.marketAddress - The address of the market
439
+ * @param args.markets.customerId - The ID of the customer
440
+ * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
441
+ */
442
+ collectMarketFee(markets) {
443
+ return __awaiter(this, void 0, void 0, function* () {
444
+ const ixs = [];
445
+ for (const market of markets) {
446
+ ixs.push(yield this.program.methods
447
+ .collectMarketFee()
448
+ .accounts({
449
+ signer: this.program.provider.publicKey,
450
+ market: market.marketAddress,
451
+ customer: (0, pda_1.getCustomerPDA)(this.program.programId, market.customerId),
452
+ customerFeeRecipient: market.customerFeeRecipient
453
+ })
454
+ .instruction());
455
+ }
456
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
457
+ });
458
+ }
459
+ /**
460
+ * Collect Market Order Fee
461
+ * @param marketAddress - The address of the market
462
+ */
463
+ collectMarketOrderFee(marketAddress) {
464
+ return __awaiter(this, void 0, void 0, function* () {
465
+ const ixs = [];
466
+ for (const market of marketAddress) {
467
+ ixs.push(yield this.program.methods
468
+ .collectMarketOrderFee()
469
+ .accounts({
470
+ signer: this.program.provider.publicKey,
471
+ market: market
472
+ })
473
+ .instruction());
474
+ }
475
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
476
+ });
477
+ }
478
+ /**
479
+ * Close Order Book
480
+ * @param marketIds - Market IDs
481
+ */
482
+ closeOrderBook(marketIds) {
483
+ return __awaiter(this, void 0, void 0, function* () {
484
+ const ixs = [];
485
+ for (const marketId of marketIds) {
486
+ ixs.push(yield this.program.methods
487
+ .closeOrderBook()
488
+ .accounts({
489
+ signer: this.program.provider.publicKey,
490
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
491
+ orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId)
492
+ })
493
+ .instruction());
494
+ }
495
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
496
+ });
497
+ }
498
+ /**
499
+ * Update Pool Question
500
+ * @param poolId - Pool ID
501
+ * @param question - Question
502
+ */
503
+ updatePoolQuestion(poolId, question) {
504
+ return __awaiter(this, void 0, void 0, function* () {
505
+ const ixs = [
506
+ yield this.program.methods
507
+ .updatePoolQuestion((0, helpers_1.encodeString)(question, 80))
508
+ .accounts({
509
+ signer: this.program.provider.publicKey,
510
+ pool: (0, pda_1.getPoolPDA)(this.program.programId, poolId)
511
+ })
512
+ .instruction()
513
+ ];
514
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
515
+ });
516
+ }
167
517
  /**
168
518
  * Open Order
169
519
  * @param args.marketId - The ID of the Market
@@ -259,7 +609,7 @@ class TriadProtocolClient {
259
609
  userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce),
260
610
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
261
611
  mint: order.mint,
262
- tokenProgram: (0, helpers_1.getTokenProgram)(order.mint)
612
+ tokenProgram: (0, helpers_2.getTokenProgram)(order.mint)
263
613
  })
264
614
  .instruction());
265
615
  }
@@ -793,11 +1143,11 @@ class TriadProtocolClient {
793
1143
  for (const order of orders) {
794
1144
  if (order.price.eq(new bn_js_1.default(0)))
795
1145
  continue;
796
- if ((0, helpers_1.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.BID) {
797
- data[side].bid.push((0, helpers_1.formatBookOrder)(order));
1146
+ if ((0, helpers_2.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.BID) {
1147
+ data[side].bid.push((0, helpers_2.formatBookOrder)(order));
798
1148
  }
799
- if ((0, helpers_1.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.ASK) {
800
- data[side].ask.push((0, helpers_1.formatBookOrder)(order));
1149
+ if ((0, helpers_2.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.ASK) {
1150
+ data[side].ask.push((0, helpers_2.formatBookOrder)(order));
801
1151
  }
802
1152
  }
803
1153
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "3.1.8-beta",
3
+ "version": "3.1.9-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/dist/market.d.ts DELETED
@@ -1,129 +0,0 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
- import { Program } from '@coral-xyz/anchor';
3
- import { PublicKey } from '@solana/web3.js';
4
- import { TriadProtocol } from './types/triad_protocol';
5
- import { RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs } from './types';
6
- export default class Market {
7
- private program;
8
- private rpcOptions;
9
- constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
10
- /**
11
- * Get All Pools
12
- */
13
- getAllPools(): Promise<import("./types").Pool[]>;
14
- /**
15
- * Get All Markets
16
- */
17
- getAllMarkets(): Promise<import("./types").Market[]>;
18
- /**
19
- * Get Pool By ID
20
- * @param poolId - The ID of the pool
21
- */
22
- getPoolById(poolId: number): Promise<import("./types").Pool>;
23
- /**
24
- * Get Market By ID
25
- * @param marketId - The ID of the market
26
- */
27
- getMarketById(marketId: number): Promise<import("./types").Market>;
28
- /**
29
- * Get Market By Address
30
- * @param marketAddress - The address of the market
31
- */
32
- getMarketByAddress(marketAddress: PublicKey): Promise<import("./types").Market>;
33
- /**
34
- * Get Current Market ID
35
- */
36
- nextMarketId(): Promise<number>;
37
- /**
38
- * Get Next Customer ID
39
- */
40
- nextCustomerId(): Promise<number>;
41
- /**
42
- * Get Next Pool ID
43
- */
44
- nextPoolId(): Promise<number>;
45
- /**
46
- * Create Market
47
- * @param args.markets - Array of markets to create
48
- * @param args.markets.marketId - Market ID
49
- * @param args.markets.startTime - start time
50
- * @param args.markets.endTime - end time
51
- * @param args.markets.question - question (max 80 characters)
52
- * @param args.markets.liquidityAtStart - liquidity at start
53
- * @param args.markets.payoutFee - payout fee (to add affiliate system)
54
- * @param args.customer - The customer of the market
55
- * @param args.poolId - The ID of the pool
56
- */
57
- createMarket({ markets, customer, poolId }: CreateMarketArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
58
- /**
59
- * Create Pool
60
- * @param poolId - The ID of the pool
61
- * @param question - The question of the pool
62
- * @param markets - The markets of the pool
63
- */
64
- createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
65
- /**
66
- * Resolve Market
67
- * @param args.marketId - The ID of the Market
68
- * @param args.poolId - The ID of the Pool
69
- * @param args.winningDirection - The Winning Direction of the Market
70
- */
71
- updateMarketWinningDirection({ marketId, poolId, winningDirection }: UpdateMarketWinningDirectionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
72
- /**
73
- * Update Market Payout
74
- * @param marketId - The ID of the market
75
- * @param poolId - The ID of the pool
76
- * @param allowPayout - Whether to allow the market to payout
77
- */
78
- updateMarketPayout({ marketId, poolId, allowPayout }: {
79
- marketId: number;
80
- poolId?: number;
81
- allowPayout: boolean;
82
- }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
83
- /**
84
- * Update Market End
85
- * @param marketId - The ID of the market
86
- * @param marketEnd - The end time of the market
87
- */
88
- updateMarketEnd({ marketId, marketEnd }: {
89
- marketId: number;
90
- marketEnd: number;
91
- }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
92
- /**
93
- * Update Market Question
94
- * @param marketId - The ID of the market
95
- * @param question - The question of the market
96
- */
97
- updateMarketQuestion({ marketId, question }: {
98
- marketId: number;
99
- question: string;
100
- }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
101
- /**
102
- * Collect Market Fee
103
- * @param args.markets - The markets to collect the fee from
104
- * @param args.markets.marketAddress - The address of the market
105
- * @param args.markets.customerId - The ID of the customer
106
- * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
107
- */
108
- collectMarketFee(markets: {
109
- marketAddress: PublicKey;
110
- customerId: number;
111
- customerFeeRecipient: PublicKey;
112
- }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
113
- /**
114
- * Collect Market Order Fee
115
- * @param marketAddress - The address of the market
116
- */
117
- collectMarketOrderFee(marketAddress: PublicKey[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
118
- /**
119
- * Close Order Book
120
- * @param marketIds - Market IDs
121
- */
122
- closeOrderBook(marketIds: number[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
123
- /**
124
- * Update Pool Question
125
- * @param poolId - Pool ID
126
- * @param question - Question
127
- */
128
- updatePoolQuestion(poolId: number, question: string): Promise<string | import("@solana/web3.js").VersionedTransaction>;
129
- }
package/dist/market.js DELETED
@@ -1,377 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const anchor_1 = require("@coral-xyz/anchor");
16
- const spl_token_1 = require("@solana/spl-token");
17
- const helpers_1 = require("./utils/helpers");
18
- const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
19
- const pda_1 = require("./utils/pda");
20
- class Market {
21
- constructor(program, rpcOptions) {
22
- this.program = program;
23
- this.rpcOptions = rpcOptions;
24
- }
25
- /**
26
- * Get All Pools
27
- */
28
- getAllPools() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const pool = yield this.program.account.pool.all();
31
- return pool.map(({ account, publicKey }) => (0, helpers_1.formatPool)(account, publicKey));
32
- });
33
- }
34
- /**
35
- * Get All Markets
36
- */
37
- getAllMarkets() {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const marketV2 = yield this.program.account.marketV2.all();
40
- return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
41
- });
42
- }
43
- /**
44
- * Get Pool By ID
45
- * @param poolId - The ID of the pool
46
- */
47
- getPoolById(poolId) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
50
- const response = yield this.program.account.pool.fetch(poolPDA);
51
- return (0, helpers_1.formatPool)(response, poolPDA);
52
- });
53
- }
54
- /**
55
- * Get Market By ID
56
- * @param marketId - The ID of the market
57
- */
58
- getMarketById(marketId) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
61
- const response = yield this.program.account.marketV2.fetch(marketPDA);
62
- return (0, helpers_1.formatMarket)(response, marketPDA);
63
- });
64
- }
65
- /**
66
- * Get Market By Address
67
- * @param marketAddress - The address of the market
68
- */
69
- getMarketByAddress(marketAddress) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const account = yield this.program.account.marketV2.fetch(marketAddress);
72
- return (0, helpers_1.formatMarket)(account, marketAddress);
73
- });
74
- }
75
- /**
76
- * Get Current Market ID
77
- */
78
- nextMarketId() {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const markets = yield this.program.account.marketV2.all();
81
- return markets.length + 10;
82
- });
83
- }
84
- /**
85
- * Get Next Customer ID
86
- */
87
- nextCustomerId() {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const customers = yield this.program.account.customer.all();
90
- return customers.length + 1;
91
- });
92
- }
93
- /**
94
- * Get Next Pool ID
95
- */
96
- nextPoolId() {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const pools = yield this.program.account.pool.all();
99
- return pools.length + 1;
100
- });
101
- }
102
- /**
103
- * Create Market
104
- * @param args.markets - Array of markets to create
105
- * @param args.markets.marketId - Market ID
106
- * @param args.markets.startTime - start time
107
- * @param args.markets.endTime - end time
108
- * @param args.markets.question - question (max 80 characters)
109
- * @param args.markets.liquidityAtStart - liquidity at start
110
- * @param args.markets.payoutFee - payout fee (to add affiliate system)
111
- * @param args.customer - The customer of the market
112
- * @param args.poolId - The ID of the pool
113
- */
114
- createMarket({ markets, customer, poolId }) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const ixs = [];
117
- let poolPDA = null;
118
- if (poolId) {
119
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
120
- }
121
- for (const market of markets) {
122
- if (market.question.length > 80) {
123
- throw new Error('Question must be less than 80 characters');
124
- }
125
- ixs.push(yield this.program.methods
126
- .createMarket({
127
- marketId: new anchor_1.BN(market.marketId),
128
- question: (0, helpers_1.encodeString)(market.question, 80),
129
- marketStart: new anchor_1.BN(market.startTime),
130
- marketEnd: new anchor_1.BN(market.endTime),
131
- feeBps: market.feeBps,
132
- payoutFee: market.payoutFee
133
- })
134
- .accounts({
135
- signer: this.program.provider.publicKey,
136
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
137
- pool: poolPDA,
138
- customer
139
- })
140
- .instruction());
141
- ixs.push(yield this.program.methods
142
- .createOrderBook(new anchor_1.BN(market.marketId))
143
- .accounts({
144
- signer: this.program.provider.publicKey,
145
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
146
- })
147
- .instruction());
148
- }
149
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
150
- });
151
- }
152
- /**
153
- * Create Pool
154
- * @param poolId - The ID of the pool
155
- * @param question - The question of the pool
156
- * @param markets - The markets of the pool
157
- */
158
- createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }) {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- if (question.length > 80) {
161
- throw new Error('Pool question must be less than 80 characters');
162
- }
163
- const ixs = [];
164
- const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
165
- ixs.push(yield this.program.methods
166
- .createPool({
167
- poolId: new anchor_1.BN(poolId),
168
- question: (0, helpers_1.encodeString)(question, 80),
169
- isFast
170
- })
171
- .accounts({
172
- signer: this.program.provider.publicKey,
173
- customer
174
- })
175
- .instruction());
176
- for (const market of markets) {
177
- if (market.question.length > 80) {
178
- throw new Error('Market question must be less than 80 characters');
179
- }
180
- ixs.push(yield this.program.methods
181
- .createMarket({
182
- marketId: new anchor_1.BN(market.marketId),
183
- question: (0, helpers_1.encodeString)(market.question, 80),
184
- marketStart: new anchor_1.BN(startTime),
185
- marketEnd: new anchor_1.BN(endTime),
186
- feeBps,
187
- payoutFee
188
- })
189
- .accounts({
190
- signer: this.program.provider.publicKey,
191
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
192
- pool: poolPDA,
193
- customer
194
- })
195
- .instruction());
196
- ixs.push(yield this.program.methods
197
- .createOrderBook(new anchor_1.BN(market.marketId))
198
- .accounts({
199
- signer: this.program.provider.publicKey,
200
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
201
- })
202
- .instruction());
203
- }
204
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
205
- });
206
- }
207
- /**
208
- * Resolve Market
209
- * @param args.marketId - The ID of the Market
210
- * @param args.poolId - The ID of the Pool
211
- * @param args.winningDirection - The Winning Direction of the Market
212
- */
213
- updateMarketWinningDirection({ marketId, poolId, winningDirection }) {
214
- return __awaiter(this, void 0, void 0, function* () {
215
- let poolPDA = null;
216
- if (poolId) {
217
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
218
- }
219
- const ixs = [
220
- yield this.program.methods
221
- .updateMarketWinningDirection(winningDirection)
222
- .accounts({
223
- signer: this.program.provider.publicKey,
224
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
225
- pool: poolPDA
226
- })
227
- .instruction()
228
- ];
229
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
230
- });
231
- }
232
- /**
233
- * Update Market Payout
234
- * @param marketId - The ID of the market
235
- * @param poolId - The ID of the pool
236
- * @param allowPayout - Whether to allow the market to payout
237
- */
238
- updateMarketPayout({ marketId, poolId, allowPayout }) {
239
- return __awaiter(this, void 0, void 0, function* () {
240
- let poolPDA = null;
241
- if (poolId) {
242
- poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
243
- }
244
- const ixs = [
245
- yield this.program.methods
246
- .updateMarketPayout(allowPayout)
247
- .accounts({
248
- signer: this.program.provider.publicKey,
249
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
250
- })
251
- .instruction()
252
- ];
253
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
254
- });
255
- }
256
- /**
257
- * Update Market End
258
- * @param marketId - The ID of the market
259
- * @param marketEnd - The end time of the market
260
- */
261
- updateMarketEnd({ marketId, marketEnd }) {
262
- return __awaiter(this, void 0, void 0, function* () {
263
- const ixs = [
264
- yield this.program.methods
265
- .updateMarketEnd(new anchor_1.BN(marketEnd))
266
- .accounts({
267
- signer: this.program.provider.publicKey,
268
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
269
- })
270
- .instruction()
271
- ];
272
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
273
- });
274
- }
275
- /**
276
- * Update Market Question
277
- * @param marketId - The ID of the market
278
- * @param question - The question of the market
279
- */
280
- updateMarketQuestion({ marketId, question }) {
281
- return __awaiter(this, void 0, void 0, function* () {
282
- const ixs = [
283
- yield this.program.methods
284
- .updateMarketQuestion((0, helpers_1.encodeString)(question, 80))
285
- .accounts({
286
- signer: this.program.provider.publicKey,
287
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
288
- })
289
- .instruction()
290
- ];
291
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
292
- });
293
- }
294
- /**
295
- * Collect Market Fee
296
- * @param args.markets - The markets to collect the fee from
297
- * @param args.markets.marketAddress - The address of the market
298
- * @param args.markets.customerId - The ID of the customer
299
- * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
300
- */
301
- collectMarketFee(markets) {
302
- return __awaiter(this, void 0, void 0, function* () {
303
- const ixs = [];
304
- for (const market of markets) {
305
- ixs.push(yield this.program.methods
306
- .collectMarketFee()
307
- .accounts({
308
- signer: this.program.provider.publicKey,
309
- market: market.marketAddress,
310
- customer: (0, pda_1.getCustomerPDA)(this.program.programId, market.customerId),
311
- customerFeeRecipient: market.customerFeeRecipient
312
- })
313
- .instruction());
314
- }
315
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
316
- });
317
- }
318
- /**
319
- * Collect Market Order Fee
320
- * @param marketAddress - The address of the market
321
- */
322
- collectMarketOrderFee(marketAddress) {
323
- return __awaiter(this, void 0, void 0, function* () {
324
- const ixs = [];
325
- for (const market of marketAddress) {
326
- ixs.push(yield this.program.methods
327
- .collectMarketOrderFee()
328
- .accounts({
329
- signer: this.program.provider.publicKey,
330
- market: market
331
- })
332
- .instruction());
333
- }
334
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
335
- });
336
- }
337
- /**
338
- * Close Order Book
339
- * @param marketIds - Market IDs
340
- */
341
- closeOrderBook(marketIds) {
342
- return __awaiter(this, void 0, void 0, function* () {
343
- const ixs = [];
344
- for (const marketId of marketIds) {
345
- ixs.push(yield this.program.methods
346
- .closeOrderBook()
347
- .accounts({
348
- signer: this.program.provider.publicKey,
349
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
350
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId)
351
- })
352
- .instruction());
353
- }
354
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
355
- });
356
- }
357
- /**
358
- * Update Pool Question
359
- * @param poolId - Pool ID
360
- * @param question - Question
361
- */
362
- updatePoolQuestion(poolId, question) {
363
- return __awaiter(this, void 0, void 0, function* () {
364
- const ixs = [
365
- yield this.program.methods
366
- .updatePoolQuestion((0, helpers_1.encodeString)(question, 80))
367
- .accounts({
368
- signer: this.program.provider.publicKey,
369
- pool: (0, pda_1.getPoolPDA)(this.program.programId, poolId)
370
- })
371
- .instruction()
372
- ];
373
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
374
- });
375
- }
376
- }
377
- exports.default = Market;