@triadxyz/triad-protocol 1.2.1-beta → 1.2.2-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.
@@ -33,9 +33,11 @@ const markets = [
33
33
  // { name: 'ORE', marketId: 4 }
34
34
  // { name: 'COLETA', marketId: 5 }
35
35
  // { name: 'UNDEADS', marketId: 6 },
36
- { name: 'SOL x ETH', marketId: 7 },
37
- { name: 'PYTH x LINK', marketId: 8 },
38
- { name: 'SOL PRICE', marketId: 9 }
36
+ // { name: 'SOL x ETH', marketId: 7 }
37
+ // { name: 'SOL vs ETH', marketId: 8 }
38
+ { name: 'SOL vs ETH 2', marketId: 9 }
39
+ // { name: 'PYTH x LINK', marketId: 8 },
40
+ // { name: 'SOL PRICE', marketId: 9 }
39
41
  ];
40
42
  const questions = [
41
43
  {
@@ -104,7 +106,8 @@ const ordersHypeAndFloopBot = [
104
106
  const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
105
107
  const response = yield triadProtocol.stake.updateStakeVault({
106
108
  wallet: wallet.publicKey,
107
- amount: new anchor_1.BN(5000 * Math.pow(10, 6))
109
+ amount: new anchor_1.BN(5000 * Math.pow(10, 6)),
110
+ isLocked: false
108
111
  });
109
112
  console.log(response);
110
113
  });
@@ -136,24 +139,23 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
136
139
  const markets = yield triadProtocol.trade.getAllMarkets();
137
140
  console.log(markets);
138
141
  });
139
- getAllMarkets();
140
142
  const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
141
- const market = yield triadProtocol.trade.getMarketById(7);
143
+ const market = yield triadProtocol.trade.getMarketById(9);
142
144
  console.log(market);
143
145
  });
144
- const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
145
- for (const market of markets) {
146
- try {
147
- const response = yield triadProtocol.trade.initializeMarket(market, {
148
- skipPreflight: true
149
- });
150
- console.log(`Initialized market ${market.name}:`, response);
151
- }
152
- catch (error) {
153
- console.error(`Error initializing market ${market.name}:`, error);
154
- }
155
- }
156
- });
146
+ // const initializeAllMarkets = async () => {
147
+ // for (const market of markets) {
148
+ // try {
149
+ // const response = await triadProtocol.trade.initializeMarket(market, {
150
+ // skipPreflight: false,
151
+ // microLamports: 5000
152
+ // })
153
+ // console.log(`Initialized market ${market.name}:`, response)
154
+ // } catch (error) {
155
+ // console.error(`Error initializing market ${market.name}:`, error)
156
+ // }
157
+ // }
158
+ // }
157
159
  const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
158
160
  const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
159
161
  let orders = [];
@@ -176,6 +178,141 @@ const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function*
176
178
  return orders;
177
179
  });
178
180
  // getOrders(new PublicKey('HjJQdfTHgC3EBX3471w4st8BXbBmtbaMyCAXNgcUb7dq'))
181
+ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
182
+ const response = yield triadProtocol.program.account.userTrade.all();
183
+ const allMarkets = yield triadProtocol.trade.getAllMarkets();
184
+ const liquidityToRecovery = {
185
+ 0: {
186
+ name: 'triad',
187
+ liquidityToPay: 0,
188
+ sharesToPay: 0,
189
+ openOrders: 0,
190
+ medPrice: 0,
191
+ direction: {
192
+ flop: {}
193
+ }
194
+ },
195
+ 1: {
196
+ name: 'pyth',
197
+ liquidityToPay: 0,
198
+ sharesToPay: 0,
199
+ openOrders: 0,
200
+ medPrice: 0,
201
+ direction: {
202
+ flop: {}
203
+ }
204
+ },
205
+ 2: {
206
+ name: 'drift',
207
+ liquidityToPay: 0,
208
+ sharesToPay: 0,
209
+ openOrders: 0,
210
+ medPrice: 0,
211
+ direction: {
212
+ flop: {}
213
+ }
214
+ },
215
+ 3: {
216
+ name: 'symmetry',
217
+ liquidityToPay: 0,
218
+ sharesToPay: 0,
219
+ openOrders: 0,
220
+ medPrice: 0,
221
+ direction: {
222
+ flop: {}
223
+ }
224
+ },
225
+ 4: {
226
+ name: 'ore',
227
+ liquidityToPay: 0,
228
+ sharesToPay: 0,
229
+ openOrders: 0,
230
+ medPrice: 0,
231
+ direction: {
232
+ hype: {}
233
+ }
234
+ },
235
+ 5: {
236
+ name: 'coleta',
237
+ liquidityToPay: 0,
238
+ sharesToPay: 0,
239
+ openOrders: 0,
240
+ medPrice: 0,
241
+ direction: {
242
+ flop: {}
243
+ }
244
+ },
245
+ 6: {
246
+ name: 'undead',
247
+ liquidityToPay: 0,
248
+ sharesToPay: 0,
249
+ openOrders: 0,
250
+ medPrice: 0,
251
+ direction: {
252
+ hype: {}
253
+ }
254
+ },
255
+ 7: {
256
+ name: 'solxeth',
257
+ liquidityToPay: 0,
258
+ sharesToPay: 0,
259
+ openOrders: 0,
260
+ medPrice: 0,
261
+ direction: {
262
+ flop: {}
263
+ }
264
+ },
265
+ 8: {
266
+ name: 'solxeth2',
267
+ liquidityToPay: 0,
268
+ sharesToPay: 0,
269
+ openOrders: 0,
270
+ medPrice: 0,
271
+ direction: {
272
+ flop: {}
273
+ }
274
+ },
275
+ 9: {
276
+ name: 'solxeth3',
277
+ liquidityToPay: 0,
278
+ sharesToPay: 0,
279
+ openOrders: 0,
280
+ medPrice: 0,
281
+ direction: {
282
+ flop: {}
283
+ }
284
+ }
285
+ };
286
+ for (const market of allMarkets) {
287
+ let currentMarket = liquidityToRecovery[market.marketId];
288
+ if ('flop' in currentMarket.direction) {
289
+ let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
290
+ currentMarket.medPrice =
291
+ parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6) / shares;
292
+ currentMarket.sharesToPay = shares;
293
+ currentMarket.liquidityToPay =
294
+ parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
295
+ }
296
+ else {
297
+ let shares = parseFloat(market.hypeShares.toString()) / Math.pow(10, 6);
298
+ currentMarket.medPrice =
299
+ parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6) / shares;
300
+ currentMarket.sharesToPay = shares;
301
+ currentMarket.liquidityToPay =
302
+ parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
303
+ }
304
+ }
305
+ for (const userTrade of response) {
306
+ for (const order of userTrade.account.orders) {
307
+ const market = liquidityToRecovery[order.marketId.toNumber()];
308
+ if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0]) {
309
+ market.openOrders += 1;
310
+ }
311
+ }
312
+ }
313
+ console.log(liquidityToRecovery);
314
+ });
315
+ getLiquidityToRecovery();
179
316
  const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
180
317
  yield getMarket();
181
318
  for (const order of ordersHypeAndFloopBot) {
@@ -230,15 +367,13 @@ const mintTokens = () => __awaiter(void 0, void 0, void 0, function* () {
230
367
  const mintTx = yield (0, spl_token_1.mintTo)(connection, keypair, mint, ata, keypair, 1000000 * Math.pow(10, 6), [keypair], undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
231
368
  console.log(mintTx);
232
369
  });
233
- const resolveQuestion = () => __awaiter(void 0, void 0, void 0, function* () {
370
+ const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
234
371
  const marketsToResolve = [
235
- { marketId: 1, winningDirection: { flop: {} } },
236
- { marketId: 2, winningDirection: { flop: {} } },
237
- { marketId: 3, winningDirection: { flop: {} } },
238
- { marketId: 5, winningDirection: { flop: {} } }
372
+ { marketId: 8, winningDirection: { flop: {} } },
373
+ { marketId: 9, winningDirection: { flop: {} } }
239
374
  ];
240
375
  for (const market of marketsToResolve) {
241
- const response = yield triadProtocol.trade.resolveQuestion({
376
+ const response = yield triadProtocol.trade.resolveMarket({
242
377
  marketId: market.marketId,
243
378
  winningDirection: market.winningDirection
244
379
  }, {
@@ -247,3 +382,32 @@ const resolveQuestion = () => __awaiter(void 0, void 0, void 0, function* () {
247
382
  console.log(response);
248
383
  }
249
384
  });
385
+ const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
386
+ const response = yield triadProtocol.trade.addLiquidity({
387
+ marketId: 5,
388
+ amount: 4729,
389
+ direction: {
390
+ hype: {}
391
+ }
392
+ });
393
+ console.log(response);
394
+ });
395
+ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
396
+ console.log('Collecting fees');
397
+ const allMarkets = yield triadProtocol.trade.getAllMarkets();
398
+ for (const market of allMarkets) {
399
+ if (Number(market.marketId) === 0 || Number(market.marketId) === 7) {
400
+ continue;
401
+ }
402
+ console.log(`Collecting fees for market ${market.marketId}`);
403
+ try {
404
+ const response = yield triadProtocol.trade.collectFee({
405
+ marketId: Number(market.marketId)
406
+ });
407
+ console.log(response);
408
+ }
409
+ catch (e) {
410
+ console.log(e);
411
+ }
412
+ }
413
+ });
package/dist/trade.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AnchorProvider, Program } from '@coral-xyz/anchor';
2
2
  import { TriadProtocol } from './types/triad_protocol';
3
3
  import { PublicKey } from '@solana/web3.js';
4
- import { FeeVault, InitializeQuestionArgs, Market, OpenOrderArgs, OrderDirection } from './types/trade';
4
+ import { InitializeMarketArgs, Market, OpenOrderArgs, OrderDirection } from './types/trade';
5
5
  import { RpcOptions } from './types';
6
6
  import BN from 'bn.js';
7
7
  export default class Trade {
@@ -13,7 +13,6 @@ export default class Trade {
13
13
  * Get all Markets
14
14
  */
15
15
  getAllMarkets(): Promise<Market[]>;
16
- getFeeVault(marketId: number): Promise<FeeVault>;
17
16
  /**
18
17
  * Get Market by ID
19
18
  * @param marketId - The ID of the market
@@ -111,10 +110,7 @@ export default class Trade {
111
110
  * @param options - RPC options
112
111
  *
113
112
  */
114
- initializeMarket({ marketId, name }: {
115
- marketId: number;
116
- name: string;
117
- }, options?: RpcOptions): Promise<any>;
113
+ initializeMarket({ marketId, name, startTime, endTime, question }: InitializeMarketArgs, options?: RpcOptions): Promise<any>;
118
114
  /**
119
115
  * Open Order
120
116
  * @param marketId - The ID of the market
@@ -140,24 +136,14 @@ export default class Trade {
140
136
  orderId: number;
141
137
  }, options?: RpcOptions): Promise<string>;
142
138
  /**
143
- * Initialize a new question for a market
144
- * @param marketId - The ID of the market
145
- * @param question - The question to initialize
146
- * @param startTime - The start time of the question
147
- * @param endTime - The end time of the question
148
- *
149
- * @param options - RPC options
150
- *
151
- */
152
- initializeQuestion({ marketId, question, startTime, endTime }: InitializeQuestionArgs, options?: RpcOptions): Promise<string>;
153
- /**
154
- * Resolve the current question for a market
139
+ * Resolve Market
155
140
  * @param marketId - The ID of the market
141
+ * @param winningDirection - The winning direction of the market
156
142
  *
157
143
  * @param options - RPC options
158
144
  *
159
145
  */
160
- resolveQuestion({ marketId, winningDirection }: {
146
+ resolveMarket({ marketId, winningDirection }: {
161
147
  marketId: number;
162
148
  winningDirection: {
163
149
  hype: {};
@@ -193,4 +179,14 @@ export default class Trade {
193
179
  amount: number;
194
180
  direction: OrderDirection;
195
181
  }, options?: RpcOptions): Promise<string>;
182
+ /**
183
+ * Collect Fee
184
+ * @param marketId - The ID of the market
185
+ *
186
+ * @param options - RPC options
187
+ *
188
+ */
189
+ collectFee({ marketId }: {
190
+ marketId: number;
191
+ }, options?: RpcOptions): Promise<string>;
196
192
  }
package/dist/trade.js CHANGED
@@ -31,29 +31,13 @@ class Trade {
31
31
  */
32
32
  getAllMarkets() {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
- return this.program.account.market
34
+ const marketV1 = yield this.program.account.market
35
35
  .all()
36
- .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.accountToMarket)(account, publicKey)));
37
- });
38
- }
39
- getFeeVault(marketId) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const feeVaultPDA = (0, trade_1.getFeeVaultPDA)(this.program.programId, marketId);
42
- const response = yield this.program.account.feeVault.fetch(feeVaultPDA);
43
- return {
44
- bump: response.bump,
45
- authority: response.authority,
46
- market: response.market,
47
- deposited: response.deposited.toString(),
48
- withdrawn: response.withdrawn.toString(),
49
- netBalance: response.netBalance.toString(),
50
- projectAvailable: response.projectAvailable.toString(),
51
- projectClaimed: response.projectClaimed.toString(),
52
- nftHoldersAvailable: response.nftHoldersAvailable.toString(),
53
- nftHoldersClaimed: response.nftHoldersClaimed.toString(),
54
- marketAvailable: response.marketAvailable.toString(),
55
- marketClaimed: response.marketClaimed.toString()
56
- };
36
+ .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.accountToMarketV1)(account, publicKey)));
37
+ const marketV2 = yield this.program.account.marketV2
38
+ .all()
39
+ .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey)));
40
+ return [...marketV1, ...marketV2];
57
41
  });
58
42
  }
59
43
  /**
@@ -64,8 +48,8 @@ class Trade {
64
48
  getMarketById(marketId) {
65
49
  return __awaiter(this, void 0, void 0, function* () {
66
50
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
67
- const response = yield this.program.account.market.fetch(marketPDA);
68
- return (0, helpers_1.accountToMarket)(response, marketPDA);
51
+ const response = yield this.program.account.marketV2.fetch(marketPDA);
52
+ return (0, helpers_1.formatMarket)(response, marketPDA);
69
53
  });
70
54
  }
71
55
  /**
@@ -75,8 +59,8 @@ class Trade {
75
59
  */
76
60
  getMarketByAddress(address) {
77
61
  return __awaiter(this, void 0, void 0, function* () {
78
- const account = yield this.program.account.market.fetch(address);
79
- return (0, helpers_1.accountToMarket)(account, address);
62
+ const account = yield this.program.account.marketV2.fetch(address);
63
+ return (0, helpers_1.formatMarket)(account, address);
80
64
  });
81
65
  }
82
66
  /**
@@ -98,12 +82,15 @@ class Trade {
98
82
  * @param options - RPC options
99
83
  *
100
84
  */
101
- initializeMarket({ marketId, name }, options) {
85
+ initializeMarket({ marketId, name, startTime, endTime, question }, options) {
102
86
  return __awaiter(this, void 0, void 0, function* () {
103
87
  return (0, sendTransactionWithOptions_1.default)(this.program.methods
104
88
  .initializeMarket({
105
89
  marketId: new bn_js_1.default(marketId),
106
- name: name
90
+ name: name,
91
+ question: (0, helpers_1.encodeString)(question, 80),
92
+ startTime: new bn_js_1.default(startTime),
93
+ endTime: new bn_js_1.default(endTime)
107
94
  })
108
95
  .accounts({
109
96
  signer: this.provider.publicKey,
@@ -125,7 +112,6 @@ class Trade {
125
112
  openOrder({ marketId, amount, direction, token, comment }, options) {
126
113
  return __awaiter(this, void 0, void 0, function* () {
127
114
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
128
- const feeVualtPDA = (0, trade_1.getFeeVaultPDA)(this.program.programId, marketId);
129
115
  const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
130
116
  const userPDA = (0, pda_1.getUserPDA)(this.program.programId, this.provider.publicKey);
131
117
  const ixs = [];
@@ -167,7 +153,6 @@ class Trade {
167
153
  .accounts({
168
154
  signer: this.provider.publicKey,
169
155
  market: marketPDA,
170
- feeVault: feeVualtPDA,
171
156
  userTrade: userTradePDA,
172
157
  mint: this.mint
173
158
  })
@@ -196,42 +181,18 @@ class Trade {
196
181
  });
197
182
  }
198
183
  /**
199
- * Initialize a new question for a market
184
+ * Resolve Market
200
185
  * @param marketId - The ID of the market
201
- * @param question - The question to initialize
202
- * @param startTime - The start time of the question
203
- * @param endTime - The end time of the question
186
+ * @param winningDirection - The winning direction of the market
204
187
  *
205
188
  * @param options - RPC options
206
189
  *
207
190
  */
208
- initializeQuestion({ marketId, question, startTime, endTime }, options) {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
211
- return (0, sendTransactionWithOptions_1.default)(this.program.methods
212
- .initializeQuestion({
213
- question: (0, helpers_1.encodeString)(question, 80),
214
- startTime: new bn_js_1.default(startTime),
215
- endTime: new bn_js_1.default(endTime)
216
- })
217
- .accounts({
218
- signer: this.provider.publicKey,
219
- market: marketPDA
220
- }), options);
221
- });
222
- }
223
- /**
224
- * Resolve the current question for a market
225
- * @param marketId - The ID of the market
226
- *
227
- * @param options - RPC options
228
- *
229
- */
230
- resolveQuestion({ marketId, winningDirection }, options) {
191
+ resolveMarket({ marketId, winningDirection }, options) {
231
192
  return __awaiter(this, void 0, void 0, function* () {
232
193
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
233
194
  const method = this.program.methods
234
- .resolveQuestion(winningDirection)
195
+ .resolveMarket(winningDirection)
235
196
  .accounts({
236
197
  signer: this.provider.publicKey,
237
198
  market: marketPDA
@@ -271,7 +232,7 @@ class Trade {
271
232
  addLiquidity({ marketId, amount, direction }, options) {
272
233
  return __awaiter(this, void 0, void 0, function* () {
273
234
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
274
- const method = this.program.methods
235
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods
275
236
  .addLiquidity({
276
237
  amount: new bn_js_1.default(amount * Math.pow(10, constants_1.TRD_DECIMALS)),
277
238
  direction: direction
@@ -280,8 +241,24 @@ class Trade {
280
241
  signer: this.provider.publicKey,
281
242
  market: marketPDA,
282
243
  mint: this.mint
283
- });
284
- return (0, sendTransactionWithOptions_1.default)(method, options);
244
+ }), options);
245
+ });
246
+ }
247
+ /**
248
+ * Collect Fee
249
+ * @param marketId - The ID of the market
250
+ *
251
+ * @param options - RPC options
252
+ *
253
+ */
254
+ collectFee({ marketId }, options) {
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
257
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.collectFee().accounts({
258
+ signer: this.provider.publicKey,
259
+ market: marketPDA,
260
+ mint: this.mint
261
+ }), options);
285
262
  });
286
263
  }
287
264
  }