@triadxyz/triad-protocol 4.0.0 → 4.0.2

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
@@ -26,22 +26,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const web3_js_1 = require("@solana/web3.js");
30
29
  const anchor_1 = require("@coral-xyz/anchor");
31
30
  const spl_token_1 = require("@solana/spl-token");
32
31
  const bn_js_1 = __importDefault(require("bn.js"));
33
32
  const bs58_1 = __importDefault(require("bs58"));
34
33
  const helpers_1 = require("./utils/helpers");
35
34
  const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
36
- const types_1 = require("./types");
37
35
  const constants_1 = require("./utils/constants");
38
36
  const helpers_2 = require("./utils/helpers");
39
37
  const pda_1 = require("./utils/pda");
40
38
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
41
- const feeCalculator_1 = require("./utils/feeCalculator");
42
39
  const stake_1 = __importDefault(require("./stake"));
43
40
  const poseidon_1 = __importDefault(require("./poseidon"));
41
+ const predictor_1 = __importDefault(require("./predictor"));
42
+ const trade_1 = __importDefault(require("./trade"));
43
+ const customer_1 = __importDefault(require("./customer"));
44
44
  __exportStar(require("./types"), exports);
45
+ __exportStar(require("./types/predictor"), exports);
46
+ __exportStar(require("./types/stake"), exports);
47
+ __exportStar(require("./types/trade"), exports);
48
+ __exportStar(require("./types/customer"), exports);
45
49
  __exportStar(require("./utils/helpers"), exports);
46
50
  __exportStar(require("./utils/feeCalculator"), exports);
47
51
  __exportStar(require("./utils/constants"), exports);
@@ -60,6 +64,9 @@ class TriadProtocol {
60
64
  this.program = new anchor_1.Program(idl_triad_protocol_json_1.default, this.provider);
61
65
  this.stake = new stake_1.default(this.program, this.rpcOptions);
62
66
  this.poseidon = new poseidon_1.default(this.program, this.rpcOptions);
67
+ this.predictor = new predictor_1.default(this.program, this.rpcOptions);
68
+ this.trade = new trade_1.default(this.program, this.rpcOptions);
69
+ this.customer = new customer_1.default(this.program, this.rpcOptions);
63
70
  }
64
71
  /**
65
72
  * Get User Orders
@@ -136,34 +143,6 @@ class TriadProtocol {
136
143
  order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
137
144
  });
138
145
  }
139
- /**
140
- * Get Costumer By Wallet Address
141
- * @param wallet - The wallet address of the customer
142
- */
143
- getCustomerByWallet(wallet) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const [customer] = yield this.program.account.customer.all([
146
- {
147
- memcmp: {
148
- offset: 10 + 1,
149
- bytes: wallet.toBase58()
150
- }
151
- }
152
- ]);
153
- return (0, helpers_2.formatCustomer)(customer.account, customer.publicKey);
154
- });
155
- }
156
- /**
157
- * Get Customer By ID
158
- * @param customerId - The ID of the customer
159
- */
160
- getCustomerById(customerId) {
161
- return __awaiter(this, void 0, void 0, function* () {
162
- const customerPDA = (0, pda_1.getCustomerPDA)(this.program.programId, customerId);
163
- const customer = yield this.program.account.customer.fetch(customerPDA, this.provider.opts.commitment);
164
- return (0, helpers_2.formatCustomer)(customer, customerPDA);
165
- });
166
- }
167
146
  /**
168
147
  * Get All Pools
169
148
  */
@@ -223,15 +202,6 @@ class TriadProtocol {
223
202
  return markets.length + 10;
224
203
  });
225
204
  }
226
- /**
227
- * Get Next Customer ID
228
- */
229
- nextCustomerId() {
230
- return __awaiter(this, void 0, void 0, function* () {
231
- const customers = yield this.program.account.customer.all();
232
- return customers.length + 1;
233
- });
234
- }
235
205
  /**
236
206
  * Get Next Pool ID
237
207
  */
@@ -489,358 +459,5 @@ class TriadProtocol {
489
459
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
490
460
  });
491
461
  }
492
- /**
493
- * Payout Order
494
- * @param args.marketId - The ID of the Market
495
- * @param args.authority - The authority of the order
496
- * @param args.orderDirection - The direction of the Order to Payout
497
- */
498
- payoutOrder(orders) {
499
- return __awaiter(this, void 0, void 0, function* () {
500
- const ixs = [];
501
- if (orders.length > 4) {
502
- throw new Error('Max 4 orders per transaction');
503
- }
504
- for (const order of orders) {
505
- ixs.push(yield this.program.methods
506
- .payoutOrder()
507
- .accounts({
508
- signer: order.authority,
509
- payer: this.rpcOptions.payer,
510
- market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
511
- tokenProgram: (0, helpers_2.getTokenProgram)(constants_1.USDC_MINT),
512
- order: (0, pda_1.getOrderPDA)(this.program.programId, order.authority, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
513
- })
514
- .instruction());
515
- }
516
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
517
- });
518
- }
519
- /**
520
- * Create Customer
521
- * @param args.id - The ID of the customer
522
- * @param args.name - The name of the customer
523
- * @param args.authority - The authority of the customer
524
- * @param args.feeRecipient - The fee recipient of the customer
525
- */
526
- createCustomer({ id, name, authority, feeRecipient }) {
527
- return __awaiter(this, void 0, void 0, function* () {
528
- const ixs = [
529
- yield this.program.methods
530
- .createCustomer({ id, name, authority, feeRecipient })
531
- .accounts({
532
- signer: this.program.provider.publicKey
533
- })
534
- .instruction()
535
- ];
536
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
537
- });
538
- }
539
- /**
540
- * Place Bid Order
541
- * @param args.orders - Array of orders to execute
542
- * @param args.orders.marketId - The ID of the Market
543
- * @param args.orders.amount - The amount of the Order
544
- * @param args.orders.price - The price of the Order
545
- * @param args.orders.orderDirection - The direction of the Order
546
- */
547
- placeBidOrder({ orders }) {
548
- return __awaiter(this, void 0, void 0, function* () {
549
- const ixs = [];
550
- if (orders.length > 6) {
551
- throw new Error('Max 6 orders per transaction');
552
- }
553
- for (const order of orders) {
554
- ixs.push(yield this.program.methods
555
- .placeBidOrder({
556
- amount: new bn_js_1.default(order.amount * Math.pow(10, constants_1.BASE_DECIMALS)),
557
- price: new bn_js_1.default(order.price * Math.pow(10, constants_1.BASE_DECIMALS)),
558
- marketId: new bn_js_1.default(order.marketId),
559
- orderDirection: order.orderDirection
560
- })
561
- .accounts({
562
- signer: this.program.provider.publicKey,
563
- payer: this.rpcOptions.payer,
564
- market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
565
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
566
- order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
567
- })
568
- .instruction());
569
- }
570
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
571
- });
572
- }
573
- /**
574
- * Place Ask Order
575
- * @param args.orders - Array of orders to execute
576
- * @param args.orders.amount - The amount of the Order
577
- * @param args.orders.price - The price of the Order
578
- * @param args.orders.marketId - The Id from the market
579
- * @param args.orders.orderDirection - The direction of the Order
580
- */
581
- placeAskOrder({ orders }) {
582
- return __awaiter(this, void 0, void 0, function* () {
583
- const ixs = [];
584
- if (orders.length > 6) {
585
- throw new Error('Max 6 orders per transaction');
586
- }
587
- for (const order of orders) {
588
- ixs.push(yield this.program.methods
589
- .placeAskOrder({
590
- shares: new bn_js_1.default(order.amount * Math.pow(10, constants_1.BASE_DECIMALS)),
591
- price: new bn_js_1.default(order.price * Math.pow(10, constants_1.BASE_DECIMALS)),
592
- orderDirection: order.orderDirection
593
- })
594
- .accounts({
595
- signer: this.program.provider.publicKey,
596
- market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
597
- order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection)),
598
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
599
- })
600
- .instruction());
601
- }
602
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
603
- });
604
- }
605
- /**
606
- * Cancel Bid Order
607
- * @param args.orders.bookOrderId - The ID of the Book Order
608
- * @param args.orders.marketId - The ID of the Market
609
- * @param args.orders.orderDirection - The direction of the Order
610
- */
611
- cancelBidOrder({ orders }) {
612
- return __awaiter(this, void 0, void 0, function* () {
613
- const ixs = [];
614
- if (orders.length > 6) {
615
- throw new Error('You can only cancel up to 6 orders at a time');
616
- }
617
- for (const order of orders) {
618
- ixs.push(yield this.program.methods
619
- .cancelBidOrder({
620
- marketId: new bn_js_1.default(order.marketId),
621
- bookOrderId: new bn_js_1.default(order.bookOrderId),
622
- orderDirection: order.orderDirection
623
- })
624
- .accounts({
625
- signer: new web3_js_1.PublicKey(order.authority),
626
- payer: this.rpcOptions.payer,
627
- market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
628
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
629
- })
630
- .instruction());
631
- }
632
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
633
- });
634
- }
635
- /**
636
- * Cancel Ask Order
637
- * @param args.orders.marketId - The ID of the Market
638
- * @param args.orders.authority - The authority of the order
639
- * @param args.orders.bookOrderId - The ID of the Book Order
640
- * @param args.orders.orderDirection - The direction of the Order
641
- */
642
- cancelAskOrder({ orders }) {
643
- return __awaiter(this, void 0, void 0, function* () {
644
- const ixs = [];
645
- if (orders.length > 5) {
646
- throw new Error('Max 5 orders per transaction');
647
- }
648
- for (const order of orders) {
649
- ixs.push(yield this.program.methods
650
- .cancelAskOrder({
651
- marketId: new bn_js_1.default(order.marketId),
652
- bookOrderId: new bn_js_1.default(order.bookOrderId),
653
- orderDirection: order.orderDirection
654
- })
655
- .accounts({
656
- signer: order.authority,
657
- payer: this.rpcOptions.payer,
658
- market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
659
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
660
- order: (0, pda_1.getOrderPDA)(this.program.programId, order.authority, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
661
- })
662
- .instruction());
663
- }
664
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
665
- });
666
- }
667
- /**
668
- * Market Bid Order
669
- * @param args.marketId - The ID of the Market
670
- * @param args.amount - The amount of the Order
671
- * @param args.orderDirection - The direction of the Order
672
- */
673
- marketBidOrder({ marketId, amount, orderDirection }) {
674
- return __awaiter(this, void 0, void 0, function* () {
675
- const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
676
- const ixs = [];
677
- const addressLookupTableAccounts = [];
678
- const orderBook = yield this.getOrderBook(marketId);
679
- let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
680
- const orders = Object.keys(orderDirection)[0] === 'hype'
681
- ? orderBook.hype.ask
682
- : orderBook.flop.ask;
683
- const sortedOrders = orders.sort((a, b) => Number(a.price) - Number(b.price));
684
- for (const order of sortedOrders) {
685
- if (remainingUSDC.lte(new bn_js_1.default(0)))
686
- break;
687
- if (order.authority === this.program.provider.publicKey.toBase58()) {
688
- continue;
689
- }
690
- const orderPrice = new bn_js_1.default(order.price);
691
- const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
692
- const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 700);
693
- const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
694
- const maxSharesForPrice = remainingUSDC
695
- .mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
696
- .div(adjustedPrice);
697
- const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
698
- if (sharesToBuy.lte(new bn_js_1.default(0)))
699
- continue;
700
- const usdcAmount = sharesToBuy
701
- .mul(adjustedPrice)
702
- .div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)));
703
- if (usdcAmount.lte(new bn_js_1.default(0)))
704
- continue;
705
- const oppositeOrderDirection = (0, helpers_1.getOppositeOrderDirectionEncoded)(orderDirection);
706
- ixs.push(yield this.program.methods
707
- .marketBidOrder({
708
- amount: new bn_js_1.default(usdcAmount),
709
- marketId: new bn_js_1.default(marketId),
710
- orderDirection,
711
- bookOrderAskId: new bn_js_1.default(order.id),
712
- oppositeOrderDirection
713
- })
714
- .accounts({
715
- signer: this.program.provider.publicKey,
716
- payer: this.rpcOptions.payer,
717
- market: marketPDA,
718
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
719
- bookOrderAskAuthority: new web3_js_1.PublicKey(order.authority),
720
- order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
721
- oppositeOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection))
722
- })
723
- .instruction());
724
- remainingUSDC = remainingUSDC.sub(usdcAmount);
725
- }
726
- if (ixs.length === 0) {
727
- throw new Error('No matching orders found to fill the requested amount');
728
- }
729
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions, addressLookupTableAccounts);
730
- });
731
- }
732
- /**
733
- * Market Ask Order
734
- * @param args.marketId - The ID of the Market
735
- * @param args.shares - The amount of shares to sell
736
- * @param args.bookOrderBidId - The ID of the Bid Order
737
- * @param args.orderDirection - The direction of the Order
738
- */
739
- marketAskOrder({ marketId, shares, orderDirection }) {
740
- return __awaiter(this, void 0, void 0, function* () {
741
- const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
742
- const ixs = [];
743
- const addressLookupTableAccounts = [];
744
- const orderBook = yield this.getOrderBook(marketId);
745
- const bidOrders = Object.keys(orderDirection)[0] === 'hype'
746
- ? orderBook.hype.bid
747
- : orderBook.flop.bid;
748
- const sortedOrders = bidOrders.sort((a, b) => Number(b.price) - Number(a.price));
749
- let amountOfUSDC = new bn_js_1.default(0);
750
- let remainingShares = new bn_js_1.default(shares * Math.pow(10, constants_1.BASE_DECIMALS));
751
- for (const order of sortedOrders) {
752
- if (remainingShares.lte(new bn_js_1.default(0)))
753
- break;
754
- if (order.authority === this.program.provider.publicKey.toBase58() ||
755
- order.linkedBookOrderId !== constants_1.BOOK_ORDER_NULL.toString()) {
756
- continue;
757
- }
758
- const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
759
- const sharesToSell = bn_js_1.default.min(remainingShares, availableShares);
760
- if (sharesToSell.lt(new bn_js_1.default(0)))
761
- continue;
762
- remainingShares = remainingShares.sub(sharesToSell);
763
- const orderPrice = new bn_js_1.default(order.price);
764
- const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 700);
765
- const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
766
- amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
767
- ixs.push(yield this.program.methods
768
- .marketAskOrder({
769
- shares: new bn_js_1.default(sharesToSell),
770
- orderDirection,
771
- bookOrderBidId: new bn_js_1.default(order.id)
772
- })
773
- .accounts({
774
- signer: this.program.provider.publicKey,
775
- payer: this.rpcOptions.payer,
776
- market: marketPDA,
777
- buyerAuthority: new web3_js_1.PublicKey(order.authority),
778
- orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
779
- marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
780
- bidOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
781
- askOrder: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection))
782
- })
783
- .instruction());
784
- }
785
- if (ixs.length === 0) {
786
- throw new Error('No matching orders found to fill the requested amount');
787
- }
788
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions, addressLookupTableAccounts);
789
- });
790
- }
791
- /**
792
- * Get Orders By Market ID
793
- * @param marketId - Market ID
794
- */
795
- getOrderBook(marketId) {
796
- return __awaiter(this, void 0, void 0, function* () {
797
- const data = {
798
- marketId: marketId,
799
- rewardsAvailable: '0',
800
- rewardsClaimed: '0',
801
- spreadToReward: '0',
802
- hype: { bid: [], ask: [] },
803
- flop: { bid: [], ask: [] }
804
- };
805
- const orderBookPDA = (0, pda_1.getOrderBookPDA)(this.program.programId, marketId);
806
- const orderBook = yield this.program.account.orderBook.fetch(orderBookPDA);
807
- data.rewardsAvailable = orderBook.rewardsAvailable.toString();
808
- data.rewardsClaimed = orderBook.rewardsClaimed.toString();
809
- data.spreadToReward = orderBook.spreadToReward.toString();
810
- const processOrders = (orders, side) => {
811
- for (const order of orders) {
812
- if (order.price.eq(new bn_js_1.default(0)))
813
- continue;
814
- if ((0, helpers_2.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.BID) {
815
- data[side].bid.push((0, helpers_2.formatBookOrder)(order, marketId));
816
- }
817
- if ((0, helpers_2.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.ASK) {
818
- data[side].ask.push((0, helpers_2.formatBookOrder)(order, marketId));
819
- }
820
- }
821
- };
822
- processOrders(orderBook.hypeOrders, 'hype');
823
- processOrders(orderBook.flopOrders, 'flop');
824
- return data;
825
- });
826
- }
827
- /**
828
- * Update Customer Fee
829
- * @param customerId - Customer ID
830
- * @param feeBps - Fee in basis points
831
- */
832
- updateCustomerFee({ customerId, feeBps }) {
833
- return __awaiter(this, void 0, void 0, function* () {
834
- const ixs = [
835
- yield this.program.methods
836
- .updateCustomerFee({ id: customerId, feeBps })
837
- .accounts({
838
- signer: this.program.provider.publicKey
839
- })
840
- .instruction()
841
- ];
842
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
843
- });
844
- }
845
462
  }
846
463
  exports.default = TriadProtocol;
@@ -0,0 +1,25 @@
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { Program } from '@coral-xyz/anchor';
3
+ import { TriadProtocol } from './types/triad_protocol';
4
+ import { RpcOptions } from './types';
5
+ import { DepositArgs, WithdrawArgs } from './types/predictor';
6
+ export default class Predictor {
7
+ private program;
8
+ private rpcOptions;
9
+ constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
10
+ /**
11
+ * Deposit
12
+ * @param args.authority - Authority of the deposit
13
+ * @param args.amount - Amount to deposit
14
+ * @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
15
+ * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
16
+ */
17
+ deposit({ authority, amount, refer, customer }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
18
+ /**
19
+ * Withdraw
20
+ * @param args.authority - Authority of the withdraw
21
+ * @param args.amount - Amount to deposit
22
+ * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
23
+ */
24
+ withdraw({ authority, amount, customer }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
25
+ }
@@ -0,0 +1,84 @@
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 web3_js_1 = require("@solana/web3.js");
16
+ const bn_js_1 = __importDefault(require("bn.js"));
17
+ const constants_1 = require("./utils/constants");
18
+ const pda_1 = require("./utils/pda");
19
+ const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
20
+ class Predictor {
21
+ constructor(program, rpcOptions) {
22
+ this.program = program;
23
+ this.rpcOptions = rpcOptions;
24
+ }
25
+ /**
26
+ * Deposit
27
+ * @param args.authority - Authority of the deposit
28
+ * @param args.amount - Amount to deposit
29
+ * @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
30
+ * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
31
+ */
32
+ deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'), customer = 7 }) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const ixs = [];
35
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
36
+ try {
37
+ yield this.program.account.predictor.fetch(predictorPDA);
38
+ }
39
+ catch (e) {
40
+ ixs.push(yield this.program.methods
41
+ .createPredictor({
42
+ customer,
43
+ refer
44
+ })
45
+ .accounts({
46
+ signer: authority,
47
+ payer: this.rpcOptions.payer
48
+ })
49
+ .instruction());
50
+ }
51
+ ixs.push(yield this.program.methods
52
+ .deposit(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
53
+ .accounts({
54
+ signer: authority,
55
+ payer: this.rpcOptions.payer,
56
+ predictor: predictorPDA
57
+ })
58
+ .instruction());
59
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
60
+ });
61
+ }
62
+ /**
63
+ * Withdraw
64
+ * @param args.authority - Authority of the withdraw
65
+ * @param args.amount - Amount to deposit
66
+ * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
67
+ */
68
+ withdraw({ authority, amount, customer = 7 }) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const ixs = [];
71
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
72
+ ixs.push(yield this.program.methods
73
+ .withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
74
+ .accounts({
75
+ signer: authority,
76
+ payer: this.rpcOptions.payer,
77
+ predictor: predictorPDA
78
+ })
79
+ .instruction());
80
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
81
+ });
82
+ }
83
+ }
84
+ exports.default = Predictor;
package/dist/stake.d.ts CHANGED
@@ -10,11 +10,11 @@ export default class Stake {
10
10
  /**
11
11
  * Get all Stake Vaults
12
12
  */
13
- getStakeVaults(): Promise<import("./types").StakeVault[]>;
13
+ getStakeVaults(): Promise<import(".").StakeVault[]>;
14
14
  /**
15
15
  * Get all Stakes
16
16
  */
17
- getStakes(): Promise<import("./types").Stake[]>;
17
+ getStakes(): Promise<import(".").Stake[]>;
18
18
  /**
19
19
  * Get Stake By Wallet
20
20
  * @param wallet - User wallet
@@ -35,7 +35,7 @@ export default class Stake {
35
35
  * Get Unstake By Wallet
36
36
  * @param wallet - User wallet
37
37
  */
38
- getUnstakeByWallet(wallet: PublicKey): Promise<import("./types").Unstake[]>;
38
+ getUnstakeByWallet(wallet: PublicKey): Promise<import(".").Unstake[]>;
39
39
  /**
40
40
  * Stake Token
41
41
  * @param amount - Amount to stake
@@ -0,0 +1,88 @@
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { TriadProtocol } from './types/triad_protocol';
5
+ import { RpcOptions, OrderDirectionEncoded, BookOrder } from './types';
6
+ import { MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, MarketAskOrderArgs } from './types/trade';
7
+ export default class Trade {
8
+ private program;
9
+ private rpcOptions;
10
+ constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
11
+ /**
12
+ * Get Orders By Market ID
13
+ * @param marketId - Market ID
14
+ */
15
+ getOrderBook(marketId: number): Promise<{
16
+ marketId: number;
17
+ rewardsAvailable: string;
18
+ rewardsClaimed: string;
19
+ spreadToReward: string;
20
+ hype: {
21
+ bid: BookOrder[];
22
+ ask: BookOrder[];
23
+ };
24
+ flop: {
25
+ bid: BookOrder[];
26
+ ask: BookOrder[];
27
+ };
28
+ }>;
29
+ /**
30
+ * Place Bid Order
31
+ * @param args.orders - Array of orders to execute
32
+ * @param args.orders.marketId - The ID of the Market
33
+ * @param args.orders.amount - The amount of the Order
34
+ * @param args.orders.price - The price of the Order
35
+ * @param args.orders.orderDirection - The direction of the Order
36
+ */
37
+ placeBidOrder({ orders }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
38
+ /**
39
+ * Place Ask Order
40
+ * @param args.orders - Array of orders to execute
41
+ * @param args.orders.amount - The amount of the Order
42
+ * @param args.orders.price - The price of the Order
43
+ * @param args.orders.marketId - The Id from the market
44
+ * @param args.orders.orderDirection - The direction of the Order
45
+ */
46
+ placeAskOrder({ orders }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
47
+ /**
48
+ * Cancel Bid Order
49
+ * @param args.orders.bookOrderId - The ID of the Book Order
50
+ * @param args.orders.marketId - The ID of the Market
51
+ * @param args.orders.orderDirection - The direction of the Order
52
+ */
53
+ cancelBidOrder({ orders }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
54
+ /**
55
+ * Cancel Ask Order
56
+ * @param args.orders.marketId - The ID of the Market
57
+ * @param args.orders.authority - The authority of the order
58
+ * @param args.orders.bookOrderId - The ID of the Book Order
59
+ * @param args.orders.orderDirection - The direction of the Order
60
+ */
61
+ cancelAskOrder({ orders }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
62
+ /**
63
+ * Market Bid Order
64
+ * @param args.marketId - The ID of the Market
65
+ * @param args.amount - The amount of the Order
66
+ * @param args.orderDirection - The direction of the Order
67
+ */
68
+ marketBidOrder({ marketId, amount, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
69
+ /**
70
+ * Market Ask Order
71
+ * @param args.marketId - The ID of the Market
72
+ * @param args.shares - The amount of shares to sell
73
+ * @param args.bookOrderBidId - The ID of the Bid Order
74
+ * @param args.orderDirection - The direction of the Order
75
+ */
76
+ marketAskOrder({ marketId, shares, orderDirection }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
77
+ /**
78
+ * Payout Order
79
+ * @param args.marketId - The ID of the Market
80
+ * @param args.authority - The authority of the order
81
+ * @param args.orderDirection - The direction of the Order to Payout
82
+ */
83
+ payoutOrder(orders: {
84
+ marketId: number;
85
+ orderDirection: OrderDirectionEncoded;
86
+ authority: PublicKey;
87
+ }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
88
+ }