@triadxyz/triad-protocol 4.2.8 → 4.3.0

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/market.js CHANGED
@@ -367,9 +367,7 @@ class Market {
367
367
  ixs.push(yield this.program.methods
368
368
  .closeIdleMarket(new bn_js_1.default(market.id))
369
369
  .accounts({
370
- signer: this.program.provider.publicKey,
371
- mint: market.mint,
372
- tokenProgram: (0, helpers_1.getTokenProgram)(market.mint)
370
+ signer: this.program.provider.publicKey
373
371
  })
374
372
  .instruction());
375
373
  }
@@ -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, CollectRewardsArgs, Predictor as PredictorType } from './types/predictor';
5
+ import { DepositArgs, DepositExtArgs, WithdrawArgs, WithdrawExtArgs, CollectRewardsArgs, Predictor as PredictorType } from './types/predictor';
6
6
  export default class Predictor {
7
7
  private program;
8
8
  private rpcOptions;
@@ -13,6 +13,11 @@ export default class Predictor {
13
13
  * @param customerId - Customer ID
14
14
  */
15
15
  getPredictor(authority: PublicKey, customerId: number): Promise<PredictorType>;
16
+ /**
17
+ * Get predictor by address
18
+ * @param address - Predictor address
19
+ */
20
+ getPredictorByAddress(address: string): Promise<PredictorType>;
16
21
  /**
17
22
  * Get User Orders
18
23
  * @param wallet - User wallet PublicKey
@@ -52,6 +57,26 @@ export default class Predictor {
52
57
  * @param args.customerId - Customer ID
53
58
  */
54
59
  withdraw({ authority, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
60
+ /**
61
+ * Deposit Ext
62
+ * Idempotent deposit with an optional external deposit record.
63
+ * @param args.authority - Authority of the deposit
64
+ * @param args.amount - Amount to deposit
65
+ * @param args.refer - Referral public key (used only when creating the predictor)
66
+ * @param args.customerId - Customer ID
67
+ * @param args.depositId - Optional 12-byte deposit ID used as idempotency key
68
+ */
69
+ depositExt({ authority, amount, refer, customerId, depositId }: DepositExtArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
70
+ /**
71
+ * Withdraw Ext
72
+ * Withdraws to an external ATA owned by the caller-provided account.
73
+ * @param args.authority - Authority of the withdraw
74
+ * @param args.amount - Amount to withdraw
75
+ * @param args.customerId - Customer ID
76
+ * @param args.key - External withdraw key (idempotency / off-chain reference)
77
+ * @param args.extAta - External ATA destination
78
+ */
79
+ withdrawExt({ authority, amount, customerId, key, extAta }: WithdrawExtArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
55
80
  /**
56
81
  * Collect Rewards
57
82
  * Claims accumulated TRIAD token rewards for the predictor.
package/dist/predictor.js CHANGED
@@ -12,6 +12,7 @@ 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 web3_js_1 = require("@solana/web3.js");
15
16
  const bn_js_1 = __importDefault(require("bn.js"));
16
17
  const constants_1 = require("./utils/constants");
17
18
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
@@ -47,6 +48,16 @@ class Predictor {
47
48
  }
48
49
  });
49
50
  }
51
+ /**
52
+ * Get predictor by address
53
+ * @param address - Predictor address
54
+ */
55
+ getPredictorByAddress(address) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const predictor = yield this.program.account.predictor.fetch(new web3_js_1.PublicKey(address), this.rpcOptions.commitment);
58
+ return (0, helpers_1.formatPredictor)(predictor, new web3_js_1.PublicKey(address));
59
+ });
60
+ }
50
61
  /**
51
62
  * Get User Orders
52
63
  * @param wallet - User wallet PublicKey
@@ -170,6 +181,76 @@ class Predictor {
170
181
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
171
182
  });
172
183
  }
184
+ /**
185
+ * Deposit Ext
186
+ * Idempotent deposit with an optional external deposit record.
187
+ * @param args.authority - Authority of the deposit
188
+ * @param args.amount - Amount to deposit
189
+ * @param args.refer - Referral public key (used only when creating the predictor)
190
+ * @param args.customerId - Customer ID
191
+ * @param args.depositId - Optional 12-byte deposit ID used as idempotency key
192
+ */
193
+ depositExt({ authority, amount, refer, customerId, depositId }) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const ixs = [];
196
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
197
+ try {
198
+ yield this.program.account.predictor.fetch(predictorPDA);
199
+ }
200
+ catch (e) {
201
+ ixs.push(yield this.program.methods
202
+ .createPredictor({
203
+ customerId,
204
+ refer
205
+ })
206
+ .accounts({
207
+ signer: authority,
208
+ payer: this.rpcOptions.payer
209
+ })
210
+ .instruction());
211
+ }
212
+ ixs.push(yield this.program.methods
213
+ .depositExt({
214
+ amount: new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)),
215
+ depositId: Array.from(Buffer.from(depositId, 'hex'))
216
+ })
217
+ .accounts({
218
+ signer: authority,
219
+ predictor: predictorPDA,
220
+ predictorDeposit: (0, pda_1.getPredictorDepositPDA)(this.program.programId, depositId)
221
+ })
222
+ .instruction());
223
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
224
+ });
225
+ }
226
+ /**
227
+ * Withdraw Ext
228
+ * Withdraws to an external ATA owned by the caller-provided account.
229
+ * @param args.authority - Authority of the withdraw
230
+ * @param args.amount - Amount to withdraw
231
+ * @param args.customerId - Customer ID
232
+ * @param args.key - External withdraw key (idempotency / off-chain reference)
233
+ * @param args.extAta - External ATA destination
234
+ */
235
+ withdrawExt({ authority, amount, customerId, key, extAta }) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
238
+ const ixs = [
239
+ yield this.program.methods
240
+ .withdrawExt({
241
+ amount: new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)),
242
+ key
243
+ })
244
+ .accounts({
245
+ signer: authority,
246
+ predictor: predictorPDA,
247
+ extAta
248
+ })
249
+ .instruction()
250
+ ];
251
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
252
+ });
253
+ }
173
254
  /**
174
255
  * Collect Rewards
175
256
  * Claims accumulated TRIAD token rewards for the predictor.
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, customerId }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
36
+ placeBidOrder({ orders }: 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, customerId }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
45
+ placeAskOrder({ orders }: 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, customerId }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
52
+ cancelBidOrder({ orders }: 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,7 +57,7 @@ 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, customerId }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
60
+ cancelAskOrder({ orders }: 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
package/dist/trade.js CHANGED
@@ -67,11 +67,11 @@ class Trade {
67
67
  * @param args.orders.price - The price of the Order
68
68
  * @param args.orders.orderDirection - The direction of the Order
69
69
  */
70
- placeBidOrder({ orders, customerId }) {
70
+ placeBidOrder({ orders }) {
71
71
  return __awaiter(this, void 0, void 0, function* () {
72
72
  const ixs = [];
73
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
74
73
  for (const order of orders) {
74
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, order.customerId);
75
75
  ixs.push(yield this.program.methods
76
76
  .placeBidOrder({
77
77
  amount: new bn_js_1.default(order.amount * Math.pow(10, constants_1.BASE_DECIMALS)),
@@ -100,11 +100,11 @@ class Trade {
100
100
  * @param args.orders.marketId - The Id from the market
101
101
  * @param args.orders.orderDirection - The direction of the Order
102
102
  */
103
- placeAskOrder({ orders, customerId }) {
103
+ placeAskOrder({ orders }) {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  const ixs = [];
106
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
107
106
  for (const order of orders) {
107
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, order.customerId);
108
108
  ixs.push(yield this.program.methods
109
109
  .placeAskOrder({
110
110
  shares: new bn_js_1.default(order.amount * Math.pow(10, constants_1.BASE_DECIMALS)),
@@ -129,7 +129,7 @@ class Trade {
129
129
  * @param args.orders.marketId - The ID of the Market
130
130
  * @param args.orders.orderDirection - The direction of the Order
131
131
  */
132
- cancelBidOrder({ orders, customerId }) {
132
+ cancelBidOrder({ orders }) {
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
134
  const ixs = [];
135
135
  for (const order of orders) {
@@ -140,8 +140,8 @@ class Trade {
140
140
  orderDirection: order.orderDirection
141
141
  })
142
142
  .accounts({
143
- signer: new web3_js_1.PublicKey(order.authority),
144
- predictor: (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customerId),
143
+ signer: order.authority,
144
+ predictor: order.predictor,
145
145
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
146
146
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
147
147
  })
@@ -157,10 +157,9 @@ class Trade {
157
157
  * @param args.orders.bookOrderId - The ID of the Book Order
158
158
  * @param args.orders.orderDirection - The direction of the Order
159
159
  */
160
- cancelAskOrder({ orders, customerId }) {
160
+ cancelAskOrder({ orders }) {
161
161
  return __awaiter(this, void 0, void 0, function* () {
162
162
  const ixs = [];
163
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
164
163
  for (const order of orders) {
165
164
  ixs.push(yield this.program.methods
166
165
  .cancelAskOrder({
@@ -171,10 +170,10 @@ class Trade {
171
170
  .accounts({
172
171
  signer: order.authority,
173
172
  payer: this.rpcOptions.payer,
174
- predictor: predictorPDA,
173
+ predictor: order.predictor,
175
174
  market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
176
175
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
177
- predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
176
+ predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, order.predictor, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
178
177
  })
179
178
  .instruction());
180
179
  }
@@ -320,7 +319,7 @@ class Trade {
320
319
  return __awaiter(this, void 0, void 0, function* () {
321
320
  const ixs = [];
322
321
  for (const order of orders) {
323
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, order.customerId);
322
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, order.authority, order.customerId);
324
323
  ixs.push(yield this.program.methods
325
324
  .payoutOrder()
326
325
  .accounts({