@triadxyz/triad-protocol 4.2.0 → 4.2.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.
@@ -2,7 +2,7 @@ import { PublicKey } from '@solana/web3.js';
2
2
  import { Program } from '@coral-xyz/anchor';
3
3
  import { TriadProtocol } from './types/triad_protocol';
4
4
  import { RpcOptions } from './types';
5
- import { DepositArgs, WithdrawArgs, Predictor as PredictorType } from './types/predictor';
5
+ import { DepositArgs, WithdrawArgs, CollectRewardsArgs, Predictor as PredictorType } from './types/predictor';
6
6
  export default class Predictor {
7
7
  private program;
8
8
  private rpcOptions;
@@ -13,6 +13,30 @@ export default class Predictor {
13
13
  * @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
14
14
  */
15
15
  getPredictor(authority: PublicKey, customerId?: number): Promise<PredictorType>;
16
+ /**
17
+ * Get User Orders
18
+ * @param wallet - User wallet PublicKey
19
+ */
20
+ getUserOrders(wallet: PublicKey, customerId?: number): Promise<import("./types").PredictorOrder[]>;
21
+ /**
22
+ * Get User Orders By Market ID
23
+ * @param wallet - User wallet PublicKey
24
+ * @param marketId - The ID of the market
25
+ */
26
+ getUserOrdersByMarketId(wallet: PublicKey, marketId: number, customerId?: number): Promise<import("./types").PredictorOrder[]>;
27
+ /**
28
+ * Get all User Book Orders
29
+ * @param wallet - User wallet PublicKey
30
+ * @param customerId - User Customer ID
31
+ */
32
+ getUserBookOrders(wallet: PublicKey, customerId?: number): Promise<import("./types").BookOrder[]>;
33
+ /**
34
+ * Get User Book Orders By Market ID
35
+ * @param wallet - User wallet PublicKey
36
+ * @param marketId - The ID of the market
37
+ * @param customerId - User Customer ID
38
+ */
39
+ getUserBookOrdersByMarketId(wallet: PublicKey, marketId: number, customerId?: number): Promise<import("./types").BookOrder[]>;
16
40
  /**
17
41
  * Deposit
18
42
  * @param args.authority - Authority of the deposit
@@ -28,4 +52,11 @@ export default class Predictor {
28
52
  * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
29
53
  */
30
54
  withdraw({ authority, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
55
+ /**
56
+ * Collect Rewards
57
+ * Claims accumulated TRIAD token rewards for the predictor.
58
+ * @param args.authority - Authority of the predictor
59
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
60
+ */
61
+ collectRewards({ authority, customerId }: CollectRewardsArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
31
62
  }
package/dist/predictor.js CHANGED
@@ -15,10 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const web3_js_1 = require("@solana/web3.js");
16
16
  const bn_js_1 = __importDefault(require("bn.js"));
17
17
  const constants_1 = require("./utils/constants");
18
- const pda_1 = require("./utils/pda");
19
18
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
20
19
  const helpers_1 = require("./utils/helpers");
21
- const spl_token_1 = require("@solana/spl-token");
20
+ const pda_1 = require("./utils/pda");
22
21
  class Predictor {
23
22
  constructor(program, rpcOptions) {
24
23
  this.program = program;
@@ -34,8 +33,7 @@ class Predictor {
34
33
  const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
35
34
  try {
36
35
  const predictor = yield this.program.account.predictor.fetch(predictorPDA);
37
- const balance = yield this.program.provider.connection.getTokenAccountBalance((0, pda_1.getTokenATA)(predictorPDA, constants_1.UNIT_MINT, spl_token_1.TOKEN_PROGRAM_ID));
38
- return (0, helpers_1.formatPredictor)(predictor, predictorPDA, new bn_js_1.default(balance.value.amount));
36
+ return (0, helpers_1.formatPredictor)(predictor, predictorPDA);
39
37
  }
40
38
  catch (e) {
41
39
  return {
@@ -43,11 +41,77 @@ class Predictor {
43
41
  authority: authority.toBase58(),
44
42
  balance: 0,
45
43
  customerId,
46
- refer: '11111111111111111111111111111111'
44
+ refer: '11111111111111111111111111111111',
45
+ rewardsAvailable: 0,
46
+ rewardsClaimed: 0
47
47
  };
48
48
  }
49
49
  });
50
50
  }
51
+ /**
52
+ * Get User Orders
53
+ * @param wallet - User wallet PublicKey
54
+ */
55
+ getUserOrders(wallet, customerId = 7) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, wallet, customerId);
58
+ const orders = yield this.program.account.predictorOrder.all([
59
+ {
60
+ memcmp: {
61
+ offset: 8,
62
+ bytes: predictorPDA.toBase58()
63
+ }
64
+ }
65
+ ]);
66
+ return orders.map(({ account, publicKey }) => (0, helpers_1.formatPredictorOrder)(account, publicKey));
67
+ });
68
+ }
69
+ /**
70
+ * Get User Orders By Market ID
71
+ * @param wallet - User wallet PublicKey
72
+ * @param marketId - The ID of the market
73
+ */
74
+ getUserOrdersByMarketId(wallet, marketId, customerId = 7) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const orders = yield this.getUserOrders(wallet, customerId);
77
+ return orders.filter((order) => order.marketId === marketId.toString());
78
+ });
79
+ }
80
+ /**
81
+ * Get all User Book Orders
82
+ * @param wallet - User wallet PublicKey
83
+ * @param customerId - User Customer ID
84
+ */
85
+ getUserBookOrders(wallet, customerId = 7) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const orderbooks = yield this.program.account.orderBook.all();
88
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, wallet, customerId);
89
+ const bookOrders = orderbooks.map((orderbook) => {
90
+ return [...orderbook.account.hypeOrders, ...orderbook.account.flopOrders]
91
+ .map((order) => (0, helpers_1.formatBookOrder)(order, orderbook.account.marketId.toNumber()))
92
+ .filter((order) => order.authority === predictorPDA.toBase58() &&
93
+ order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
94
+ });
95
+ return bookOrders.flat();
96
+ });
97
+ }
98
+ /**
99
+ * Get User Book Orders By Market ID
100
+ * @param wallet - User wallet PublicKey
101
+ * @param marketId - The ID of the market
102
+ * @param customerId - User Customer ID
103
+ */
104
+ getUserBookOrdersByMarketId(wallet, marketId, customerId = 7) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId), this.rpcOptions.commitment);
107
+ const orders = [...orderBook.hypeOrders, ...orderBook.flopOrders];
108
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, wallet, customerId);
109
+ return orders
110
+ .map((order) => (0, helpers_1.formatBookOrder)(order, marketId))
111
+ .filter((order) => order.authority === predictorPDA.toBase58() &&
112
+ order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
113
+ });
114
+ }
51
115
  /**
52
116
  * Deposit
53
117
  * @param args.authority - Authority of the deposit
@@ -78,7 +142,6 @@ class Predictor {
78
142
  .deposit(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
79
143
  .accounts({
80
144
  signer: authority,
81
- payer: this.rpcOptions.payer,
82
145
  predictor: predictorPDA
83
146
  })
84
147
  .instruction());
@@ -93,16 +156,37 @@ class Predictor {
93
156
  */
94
157
  withdraw({ authority, amount, customerId = 7 }) {
95
158
  return __awaiter(this, void 0, void 0, function* () {
96
- const ixs = [];
97
159
  const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
98
- ixs.push(yield this.program.methods
99
- .withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
100
- .accounts({
101
- signer: authority,
102
- payer: this.rpcOptions.payer,
103
- predictor: predictorPDA
104
- })
105
- .instruction());
160
+ const ixs = [
161
+ yield this.program.methods
162
+ .withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
163
+ .accounts({
164
+ signer: authority,
165
+ predictor: predictorPDA
166
+ })
167
+ .instruction()
168
+ ];
169
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
170
+ });
171
+ }
172
+ /**
173
+ * Collect Rewards
174
+ * Claims accumulated TRIAD token rewards for the predictor.
175
+ * @param args.authority - Authority of the predictor
176
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
177
+ */
178
+ collectRewards({ authority, customerId = 7 }) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
181
+ const ixs = [
182
+ yield this.program.methods
183
+ .collectRewards()
184
+ .accounts({
185
+ signer: authority,
186
+ predictor: predictorPDA
187
+ })
188
+ .instruction()
189
+ ];
106
190
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
107
191
  });
108
192
  }
package/dist/stake.d.ts CHANGED
@@ -35,21 +35,6 @@ export default class Stake {
35
35
  * @param wallet - User wallet
36
36
  */
37
37
  getUnstakeByWallet(wallet: PublicKey): Promise<import(".").Unstake[]>;
38
- /**
39
- * Stake Token
40
- * @param amount - Amount to stake
41
- */
42
- stakeToken(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
43
- /**
44
- * Update Stake Vault
45
- * @param amount - Reward amount to deposit
46
- */
47
- addStakeVaultRewards(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
48
- /**
49
- * Request Unstake
50
- * @param amount - Amount to unstake
51
- */
52
- requestUnstake(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
53
38
  /**
54
39
  * Unstake Token
55
40
  * @param unstakePDA - Unstake Public Key
package/dist/stake.js CHANGED
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const anchor_1 = require("@coral-xyz/anchor");
16
15
  const helpers_1 = require("./utils/helpers");
17
16
  const pda_1 = require("./utils/pda");
18
17
  const constants_1 = require("./utils/constants");
@@ -69,65 +68,6 @@ class Stake {
69
68
  return stake.map((stake) => (0, helpers_1.formatUnstake)(stake.account, stake.publicKey));
70
69
  });
71
70
  }
72
- /**
73
- * Stake Token
74
- * @param amount - Amount to stake
75
- */
76
- stakeToken(amount) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const ixs = [
79
- yield this.program.methods
80
- .stakeToken({
81
- amount: new anchor_1.BN(amount * Math.pow(10, 6))
82
- })
83
- .accounts({
84
- signer: this.program.provider.publicKey,
85
- mint: constants_1.TRD_MINT
86
- })
87
- .instruction()
88
- ];
89
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
90
- });
91
- }
92
- /**
93
- * Update Stake Vault
94
- * @param amount - Reward amount to deposit
95
- */
96
- addStakeVaultRewards(amount) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const ixs = [
99
- yield this.program.methods
100
- .addStakeVaultRewards(new anchor_1.BN(amount * Math.pow(10, 6)))
101
- .accounts({
102
- signer: this.program.provider.publicKey,
103
- mint: constants_1.TRD_MINT
104
- })
105
- .instruction()
106
- ];
107
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
108
- });
109
- }
110
- /**
111
- * Request Unstake
112
- * @param amount - Amount to unstake
113
- */
114
- requestUnstake(amount) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const ixs = [
117
- yield this.program.methods
118
- .requestUnstake({
119
- amount: new anchor_1.BN(amount * Math.pow(10, 6)),
120
- ts: new anchor_1.BN(Date.now())
121
- })
122
- .accounts({
123
- signer: this.program.provider.publicKey,
124
- mint: constants_1.TRD_MINT
125
- })
126
- .instruction()
127
- ];
128
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
129
- });
130
- }
131
71
  /**
132
72
  * Unstake Token
133
73
  * @param unstakePDA - Unstake Public Key
package/dist/trade.d.ts CHANGED
@@ -33,7 +33,7 @@ export default class Trade {
33
33
  * @param args.orders.price - The price of the Order
34
34
  * @param args.orders.orderDirection - The direction of the Order
35
35
  */
36
- placeBidOrder({ orders }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
36
+ placeBidOrder({ orders, customerId }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
37
37
  /**
38
38
  * Place Ask Order
39
39
  * @param args.orders - Array of orders to execute
@@ -42,14 +42,14 @@ export default class Trade {
42
42
  * @param args.orders.marketId - The Id from the market
43
43
  * @param args.orders.orderDirection - The direction of the Order
44
44
  */
45
- placeAskOrder({ orders }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
45
+ placeAskOrder({ orders, customerId }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
46
46
  /**
47
47
  * Cancel Bid Order
48
48
  * @param args.orders.bookOrderId - The ID of the Book Order
49
49
  * @param args.orders.marketId - The ID of the Market
50
50
  * @param args.orders.orderDirection - The direction of the Order
51
51
  */
52
- cancelBidOrder({ orders }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
52
+ cancelBidOrder({ orders, customerId }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
53
53
  /**
54
54
  * Cancel Ask Order
55
55
  * @param args.orders.marketId - The ID of the Market
@@ -57,14 +57,14 @@ export default class Trade {
57
57
  * @param args.orders.bookOrderId - The ID of the Book Order
58
58
  * @param args.orders.orderDirection - The direction of the Order
59
59
  */
60
- cancelAskOrder({ orders }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
60
+ cancelAskOrder({ orders, customerId }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
61
61
  /**
62
62
  * Market Bid Order
63
63
  * @param args.marketId - The ID of the Market
64
64
  * @param args.amount - The amount of the Order
65
65
  * @param args.orderDirection - The direction of the Order
66
66
  */
67
- marketBidOrder({ marketId, amount, customerId, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
67
+ marketBidOrder({ marketId, amount, orderDirection, customer }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
68
68
  /**
69
69
  * Market Ask Order
70
70
  * @param args.marketId - The ID of the Market
@@ -72,7 +72,7 @@ export default class Trade {
72
72
  * @param args.bookOrderBidId - The ID of the Bid Order
73
73
  * @param args.orderDirection - The direction of the Order
74
74
  */
75
- marketAskOrder({ marketId, shares, orderDirection, customerId }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
75
+ marketAskOrder({ marketId, shares, orderDirection, customer }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
76
76
  /**
77
77
  * Payout Order
78
78
  * @param args.marketId - The ID of the Market
@@ -83,5 +83,6 @@ export default class Trade {
83
83
  marketId: number;
84
84
  orderDirection: OrderDirectionEncoded;
85
85
  authority: PublicKey;
86
+ customerId: number;
86
87
  }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
87
88
  }
package/dist/trade.js CHANGED
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const web3_js_1 = require("@solana/web3.js");
16
- const spl_token_1 = require("@solana/spl-token");
17
16
  const bn_js_1 = __importDefault(require("bn.js"));
18
17
  const helpers_1 = require("./utils/helpers");
19
18
  const types_1 = require("./types");
@@ -40,20 +39,18 @@ class Trade {
40
39
  hype: { bid: [], ask: [] },
41
40
  flop: { bid: [], ask: [] }
42
41
  };
43
- const orderBookPDA = (0, pda_1.getOrderBookPDA)(this.program.programId, marketId);
44
- const orderBook = yield this.program.account.orderBook.fetch(orderBookPDA);
45
- data.rewardsAvailable = orderBook.rewardsAvailable.toString();
46
- data.rewardsClaimed = orderBook.rewardsClaimed.toString();
47
- data.spreadToReward = orderBook.spreadToReward.toString();
42
+ const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId), 'processed');
48
43
  const processOrders = (orders, side) => {
44
+ const { bid, ask } = data[side];
49
45
  for (const order of orders) {
50
- if (order.price.eq(new bn_js_1.default(0)))
46
+ if (order.price.isZero())
51
47
  continue;
48
+ const formatted = (0, helpers_1.formatBookOrder)(order, marketId);
52
49
  if ((0, helpers_1.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.BID) {
53
- data[side].bid.push((0, helpers_1.formatBookOrder)(order, marketId));
50
+ bid.push(formatted);
54
51
  }
55
- if ((0, helpers_1.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.ASK) {
56
- data[side].ask.push((0, helpers_1.formatBookOrder)(order, marketId));
52
+ else {
53
+ ask.push(formatted);
57
54
  }
58
55
  }
59
56
  };
@@ -70,12 +67,10 @@ class Trade {
70
67
  * @param args.orders.price - The price of the Order
71
68
  * @param args.orders.orderDirection - The direction of the Order
72
69
  */
73
- placeBidOrder({ orders }) {
70
+ placeBidOrder({ orders, customerId = 7 }) {
74
71
  return __awaiter(this, void 0, void 0, function* () {
75
72
  const ixs = [];
76
- if (orders.length > 6) {
77
- throw new Error('Max 6 orders per transaction');
78
- }
73
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
79
74
  for (const order of orders) {
80
75
  ixs.push(yield this.program.methods
81
76
  .placeBidOrder({
@@ -87,9 +82,10 @@ class Trade {
87
82
  .accounts({
88
83
  signer: this.program.provider.publicKey,
89
84
  payer: this.rpcOptions.payer,
85
+ predictor: predictorPDA,
90
86
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
91
87
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
92
- order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
88
+ predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
93
89
  })
94
90
  .instruction());
95
91
  }
@@ -104,12 +100,10 @@ class Trade {
104
100
  * @param args.orders.marketId - The Id from the market
105
101
  * @param args.orders.orderDirection - The direction of the Order
106
102
  */
107
- placeAskOrder({ orders }) {
103
+ placeAskOrder({ orders, customerId = 7 }) {
108
104
  return __awaiter(this, void 0, void 0, function* () {
109
105
  const ixs = [];
110
- if (orders.length > 6) {
111
- throw new Error('Max 6 orders per transaction');
112
- }
106
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
113
107
  for (const order of orders) {
114
108
  ixs.push(yield this.program.methods
115
109
  .placeAskOrder({
@@ -120,7 +114,8 @@ class Trade {
120
114
  .accounts({
121
115
  signer: this.program.provider.publicKey,
122
116
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
123
- order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection)),
117
+ predictor: predictorPDA,
118
+ predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection)),
124
119
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
125
120
  })
126
121
  .instruction());
@@ -134,12 +129,9 @@ class Trade {
134
129
  * @param args.orders.marketId - The ID of the Market
135
130
  * @param args.orders.orderDirection - The direction of the Order
136
131
  */
137
- cancelBidOrder({ orders }) {
132
+ cancelBidOrder({ orders, customerId = 7 }) {
138
133
  return __awaiter(this, void 0, void 0, function* () {
139
134
  const ixs = [];
140
- if (orders.length > 6) {
141
- throw new Error('You can only cancel up to 6 orders at a time');
142
- }
143
135
  for (const order of orders) {
144
136
  ixs.push(yield this.program.methods
145
137
  .cancelBidOrder({
@@ -149,7 +141,7 @@ class Trade {
149
141
  })
150
142
  .accounts({
151
143
  signer: new web3_js_1.PublicKey(order.authority),
152
- payer: this.rpcOptions.payer,
144
+ predictor: (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customerId),
153
145
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
154
146
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
155
147
  })
@@ -165,12 +157,10 @@ class Trade {
165
157
  * @param args.orders.bookOrderId - The ID of the Book Order
166
158
  * @param args.orders.orderDirection - The direction of the Order
167
159
  */
168
- cancelAskOrder({ orders }) {
160
+ cancelAskOrder({ orders, customerId = 7 }) {
169
161
  return __awaiter(this, void 0, void 0, function* () {
170
162
  const ixs = [];
171
- if (orders.length > 5) {
172
- throw new Error('Max 5 orders per transaction');
173
- }
163
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
174
164
  for (const order of orders) {
175
165
  ixs.push(yield this.program.methods
176
166
  .cancelAskOrder({
@@ -181,9 +171,10 @@ class Trade {
181
171
  .accounts({
182
172
  signer: order.authority,
183
173
  payer: this.rpcOptions.payer,
174
+ predictor: predictorPDA,
184
175
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
185
176
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
186
- order: (0, pda_1.getOrderPDA)(this.program.programId, order.authority, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
177
+ predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
187
178
  })
188
179
  .instruction());
189
180
  }
@@ -196,12 +187,11 @@ class Trade {
196
187
  * @param args.amount - The amount of the Order
197
188
  * @param args.orderDirection - The direction of the Order
198
189
  */
199
- marketBidOrder({ marketId, amount, customerId, orderDirection }) {
190
+ marketBidOrder({ marketId, amount, orderDirection, customer }) {
200
191
  return __awaiter(this, void 0, void 0, function* () {
201
192
  const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
202
193
  const ixs = [];
203
- const addressLookupTableAccounts = [];
204
- const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
194
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customer.id);
205
195
  const orderBook = yield this.getOrderBook(marketId);
206
196
  let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
207
197
  const orders = Object.keys(orderDirection)[0] === 'hype'
@@ -211,7 +201,7 @@ class Trade {
211
201
  for (const order of sortedOrders) {
212
202
  if (remainingUSDC.lte(new bn_js_1.default(0)))
213
203
  break;
214
- if (order.authority === this.program.provider.publicKey.toBase58()) {
204
+ if (order.authority === predictorPDA.toBase58()) {
215
205
  continue;
216
206
  }
217
207
  const orderPrice = new bn_js_1.default(order.price);
@@ -241,12 +231,14 @@ class Trade {
241
231
  .accounts({
242
232
  signer: this.program.provider.publicKey,
243
233
  payer: this.rpcOptions.payer,
234
+ predictor: predictorPDA,
235
+ oppositePredictor: (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customer.id),
236
+ central: (0, pda_1.getCentralPDA)(this.program.programId),
244
237
  market: marketPDA,
245
238
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
246
- bookOrderAskAuthority: new web3_js_1.PublicKey(order.authority),
247
- order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
248
- oppositeOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection)),
249
- customer: (0, pda_1.getCustomerPDA)(this.program.programId, customerId)
239
+ customer: customer.address,
240
+ predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
241
+ oppositePredictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection))
250
242
  })
251
243
  .instruction());
252
244
  remainingUSDC = remainingUSDC.sub(usdcAmount);
@@ -254,7 +246,7 @@ class Trade {
254
246
  if (ixs.length === 0) {
255
247
  throw new Error('No matching orders found to fill the requested amount');
256
248
  }
257
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions, addressLookupTableAccounts);
249
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
258
250
  });
259
251
  }
260
252
  /**
@@ -264,12 +256,12 @@ class Trade {
264
256
  * @param args.bookOrderBidId - The ID of the Bid Order
265
257
  * @param args.orderDirection - The direction of the Order
266
258
  */
267
- marketAskOrder({ marketId, shares, orderDirection, customerId }) {
259
+ marketAskOrder({ marketId, shares, orderDirection, customer }) {
268
260
  return __awaiter(this, void 0, void 0, function* () {
269
261
  const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
270
262
  const ixs = [];
271
263
  const addressLookupTableAccounts = [];
272
- const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
264
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customer.id);
273
265
  const orderBook = yield this.getOrderBook(marketId);
274
266
  const bidOrders = Object.keys(orderDirection)[0] === 'hype'
275
267
  ? orderBook.hype.bid
@@ -280,7 +272,7 @@ class Trade {
280
272
  for (const order of sortedOrders) {
281
273
  if (remainingShares.lte(new bn_js_1.default(0)))
282
274
  break;
283
- if (order.authority === this.program.provider.publicKey.toBase58() ||
275
+ if (order.authority === predictorPDA.toBase58() ||
284
276
  order.linkedBookOrderId !== constants_1.BOOK_ORDER_NULL.toString()) {
285
277
  continue;
286
278
  }
@@ -301,14 +293,13 @@ class Trade {
301
293
  })
302
294
  .accounts({
303
295
  signer: this.program.provider.publicKey,
304
- payer: this.rpcOptions.payer,
296
+ predictor: predictorPDA,
305
297
  market: marketPDA,
306
- buyerAuthority: new web3_js_1.PublicKey(order.authority),
307
298
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
308
- marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
309
- bidOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
310
- askOrder: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
311
- customer: customer.address
299
+ customer: customer.address,
300
+ central: (0, pda_1.getCentralPDA)(this.program.programId),
301
+ predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
302
+ oppositePredictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(orderDirection))
312
303
  })
313
304
  .instruction());
314
305
  }
@@ -327,18 +318,17 @@ class Trade {
327
318
  payoutOrder(orders) {
328
319
  return __awaiter(this, void 0, void 0, function* () {
329
320
  const ixs = [];
330
- if (orders.length > 4) {
331
- throw new Error('Max 4 orders per transaction');
332
- }
333
321
  for (const order of orders) {
322
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, order.customerId);
334
323
  ixs.push(yield this.program.methods
335
324
  .payoutOrder()
336
325
  .accounts({
337
326
  signer: order.authority,
338
- payer: this.rpcOptions.payer,
339
327
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
340
- tokenProgram: (0, helpers_1.getTokenProgram)(constants_1.USDC_MINT),
341
- order: (0, pda_1.getOrderPDA)(this.program.programId, order.authority, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
328
+ predictor: predictorPDA,
329
+ customer: (0, pda_1.getCustomerPDA)(this.program.programId, order.customerId),
330
+ central: (0, pda_1.getCentralPDA)(this.program.programId),
331
+ predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
342
332
  })
343
333
  .instruction());
344
334
  }