@triadxyz/triad-protocol 1.4.8-beta → 1.5.0-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/trade.js CHANGED
@@ -12,24 +12,21 @@ 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");
16
15
  const bn_js_1 = __importDefault(require("bn.js"));
17
16
  const constants_1 = require("./utils/constants");
18
17
  const helpers_1 = require("./utils/helpers");
19
18
  const trade_1 = require("./utils/pda/trade");
20
- const pda_1 = require("./utils/pda");
21
19
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
22
20
  const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
23
21
  const swap_1 = require("./utils/swap");
24
- const jup_swap_1 = require("./utils/jup-swap");
25
22
  class Trade {
26
23
  constructor(program, provider) {
27
- this.mint = constants_1.TRD_MINT;
28
- this.provider = provider;
29
24
  this.program = program;
25
+ this.provider = provider;
30
26
  }
31
27
  /**
32
- * Get all Markets
28
+ * Get All Markets
29
+ *
33
30
  */
34
31
  getAllMarkets() {
35
32
  return __awaiter(this, void 0, void 0, function* () {
@@ -43,7 +40,7 @@ class Trade {
43
40
  });
44
41
  }
45
42
  /**
46
- * Get Market by ID
43
+ * Get Market By ID
47
44
  * @param marketId - The ID of the market
48
45
  *
49
46
  */
@@ -55,7 +52,7 @@ class Trade {
55
52
  });
56
53
  }
57
54
  /**
58
- * Get Market by Address
55
+ * Get Market By Address
59
56
  * @param address - The address of the market
60
57
  *
61
58
  */
@@ -67,7 +64,7 @@ class Trade {
67
64
  }
68
65
  /**
69
66
  * Get User Trade
70
- * @param user - The user's public key
67
+ * @param user - User PublicKey
71
68
  *
72
69
  */
73
70
  getUserTrade(user) {
@@ -78,8 +75,10 @@ class Trade {
78
75
  }
79
76
  /**
80
77
  * Initialize Market
81
- * @param market id - new markert id - length + 1
82
- * @param name - PYTH/TRD JUP/TRD DRIFT/TRD
78
+ * @param args.marketId - new markert id - length + 1
79
+ * @param args.startTime - start time
80
+ * @param args.endTime - end time
81
+ * @param args.question - question (max 80 characters)
83
82
  *
84
83
  * @param options - RPC options
85
84
  *
@@ -93,22 +92,21 @@ class Trade {
93
92
  .initializeMarket({
94
93
  marketId: new bn_js_1.default(marketId),
95
94
  question: (0, helpers_1.encodeString)(question, 80),
96
- startTime: new bn_js_1.default(startTime),
97
- endTime: new bn_js_1.default(endTime)
95
+ marketStart: new bn_js_1.default(startTime),
96
+ marketEnd: new bn_js_1.default(endTime)
98
97
  })
99
98
  .accounts({
100
99
  signer: this.provider.publicKey,
101
- mint: this.mint
100
+ mint: constants_1.TRD_MINT
102
101
  }), options);
103
102
  });
104
103
  }
105
104
  /**
106
105
  * Open Order
107
- * @param marketId - The ID of the market
108
- * @param amount - The amount of the order
109
- * @param direction - The direction of the order
110
- * @param token - The token to use for the order
111
- * @param comment - The comment of the order
106
+ * @param args.marketId - The ID of the Market
107
+ * @param args.amount - The amount of the Order
108
+ * @param args.direction - The direction of the Order
109
+ * @param args.token - The token to use for the Order
112
110
  *
113
111
  * @param options - RPC options
114
112
  *
@@ -117,7 +115,6 @@ class Trade {
117
115
  return __awaiter(this, void 0, void 0, function* () {
118
116
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
119
117
  const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
120
- const userPDA = (0, pda_1.getUserPDA)(this.program.programId, this.provider.publicKey);
121
118
  const ixs = [];
122
119
  const addressLookupTableAccounts = [];
123
120
  let amountInTRD = amount * Math.pow(10, constants_1.TRD_DECIMALS);
@@ -156,7 +153,7 @@ class Trade {
156
153
  signer: this.provider.publicKey,
157
154
  market: marketPDA,
158
155
  userTrade: userTradePDA,
159
- mint: this.mint
156
+ mint: constants_1.TRD_MINT
160
157
  })
161
158
  .instruction());
162
159
  return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, addressLookupTableAccounts);
@@ -164,8 +161,8 @@ class Trade {
164
161
  }
165
162
  /**
166
163
  * Close Order
167
- * @param marketId - The ID of the market
168
- * @param orderId - The ID of the order
164
+ * @param args.marketId - The ID of the Market
165
+ * @param args.orderId - The ID of the Order
169
166
  *
170
167
  * @param options - RPC options
171
168
  *
@@ -177,15 +174,15 @@ class Trade {
177
174
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
178
175
  signer: this.provider.publicKey,
179
176
  market: marketPDA,
180
- mint: this.mint,
177
+ mint: constants_1.TRD_MINT,
181
178
  userTrade: userTradePDA
182
179
  }), options);
183
180
  });
184
181
  }
185
182
  /**
186
183
  * Resolve Market
187
- * @param marketId - The ID of the market
188
- * @param winningDirection - The winning direction of the market
184
+ * @param args.marketId - The ID of the Market
185
+ * @param args.winningDirection - The Winning Direction of the Market
189
186
  *
190
187
  * @param options - RPC options
191
188
  *
@@ -204,10 +201,10 @@ class Trade {
204
201
  }
205
202
  /**
206
203
  * Resolve Market With Liquidity
207
- * @param marketId - The ID of the market
208
- * @param winningDirection - The winning direction of the market
209
- * @param marketToAddLiquidity - The market to add liquidity
210
- * @param amount - The amount of the order
204
+ * @param args.marketId - The ID of the Market
205
+ * @param args.winningDirection - The Winning Direction of the Market
206
+ * @param args.marketToAddLiquidity - The Market to Add Liquidity
207
+ * @param args.amount - The amount of the Order
211
208
  *
212
209
  * @param options - RPC options
213
210
  *
@@ -231,29 +228,31 @@ class Trade {
231
228
  .accounts({
232
229
  signer: this.provider.publicKey,
233
230
  market: marketPDA,
234
- mint: this.mint
231
+ mint: constants_1.TRD_MINT
235
232
  })
236
233
  .instruction());
237
234
  return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
238
235
  });
239
236
  }
240
237
  /**
241
- * Settle an order
242
- * @param marketId - The ID of the market
243
- * @param orderId - The ID of the order to settle
238
+ * Settle an Order for a V1 Market
239
+ * @param args.marketId - The ID of the Market
240
+ * @param args.orderId - The ID of the Order to Settle
241
+ * @param args.user - The user to settle the order for
244
242
  *
245
243
  * @param options - RPC options
246
244
  *
247
245
  */
248
- settleOrder({ marketId, orderId }, options) {
246
+ settleOrder({ marketId, orderId, user }, options) {
249
247
  return __awaiter(this, void 0, void 0, function* () {
250
248
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
251
- const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
249
+ const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, user);
252
250
  return (0, sendTransactionWithOptions_1.default)(this.program.methods.settleOrder(new bn_js_1.default(orderId)).accounts({
253
251
  signer: this.provider.publicKey,
252
+ user: user,
254
253
  userTrade: userTradePDA,
255
254
  market: marketPDA,
256
- mint: this.mint
255
+ mint: constants_1.TRD_MINT
257
256
  }), options);
258
257
  });
259
258
  }
@@ -277,67 +276,31 @@ class Trade {
277
276
  .accounts({
278
277
  signer: this.provider.publicKey,
279
278
  market: marketPDA,
280
- mint: this.mint
279
+ mint: constants_1.TRD_MINT
281
280
  }), options);
282
281
  });
283
282
  }
284
283
  /**
285
- * Collect Fee
284
+ * Collect Remaining Liquidity
286
285
  * @param marketId - The ID of the market
287
286
  *
288
287
  * @param options - RPC options
289
288
  *
290
289
  */
291
- collectFee({ marketId, vault }, options) {
290
+ collectRemainingLiquidity(marketId, options) {
292
291
  return __awaiter(this, void 0, void 0, function* () {
293
292
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
294
- const ixs = [];
295
- ixs.push(yield this.program.methods
296
- .collectFee()
297
- .accounts({
293
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.collectRemainingLiquidity().accounts({
298
294
  signer: this.provider.publicKey,
299
295
  market: marketPDA,
300
- mint: this.mint
301
- })
302
- .instruction());
303
- const market = yield this.getMarketById(marketId);
304
- const marketFee = parseFloat(market.marketFeeAvailable) -
305
- parseFloat(market.marketFeeClaimed);
306
- const nftFee = parseFloat(market.nftHoldersFeeAvailable) -
307
- parseFloat(market.nftHoldersFeeClaimed);
308
- const totalFee = marketFee + nftFee;
309
- if (totalFee / Math.pow(10, constants_1.TRD_DECIMALS) < 100) {
310
- return;
311
- }
312
- const { setupInstructions, swapIxs, addressLookupTableAccounts, cleanupInstruction, otherAmountThreshold } = yield (0, jup_swap_1.jupSwap)({
313
- connection: this.provider.connection,
314
- wallet: this.provider.publicKey.toBase58(),
315
- inToken: constants_1.TRD_MINT.toBase58(),
316
- outToken: constants_1.SOL_MINT.toBase58(),
317
- amount: parseInt(totalFee.toFixed())
318
- });
319
- ixs.push(...setupInstructions);
320
- ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
321
- units: 500000
322
- }));
323
- ixs.push(...swapIxs);
324
- ixs.push(cleanupInstruction);
325
- ixs.push(web3_js_1.SystemProgram.transfer({
326
- fromPubkey: this.provider.publicKey,
327
- toPubkey: vault,
328
- lamports: otherAmountThreshold
329
- }));
330
- yield (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, addressLookupTableAccounts);
331
- return {
332
- feeToSwap: totalFee,
333
- lamport: otherAmountThreshold
334
- };
296
+ mint: constants_1.TRD_MINT
297
+ }), options);
335
298
  });
336
299
  }
337
300
  /**
338
- * Payout an order
339
- * @param marketId - The ID of the market
340
- * @param orderId - The ID of the order to payout
301
+ * Payout Order
302
+ * @param args.marketId - The ID of the Market
303
+ * @param args.orderId - The ID of the Order to Payout
341
304
  *
342
305
  * @param options - RPC options
343
306
  *
@@ -350,7 +313,16 @@ class Trade {
350
313
  signer: this.provider.publicKey,
351
314
  userTrade: userTradePDA,
352
315
  market: marketPDA,
353
- mint: this.mint
316
+ mint: constants_1.TRD_MINT
317
+ }), options);
318
+ });
319
+ }
320
+ allowMarketPayout(marketId, options) {
321
+ return __awaiter(this, void 0, void 0, function* () {
322
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
323
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.allowMarketPayout().accounts({
324
+ signer: this.provider.publicKey,
325
+ market: marketPDA
354
326
  }), options);
355
327
  });
356
328
  }