@triadxyz/triad-protocol 1.6.2-beta → 1.6.4-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.
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimulateMarket = void 0;
4
+ const MAKER_FEE = 0.035; // 1% fee
5
+ const TAKER_FEE = 0.035; // 1% fee
6
+ class SimulateMarket {
7
+ constructor(triadProtocol) {
8
+ this.triadProtocol = triadProtocol;
9
+ this.market = {
10
+ hypePrice: 0.55283,
11
+ flopPrice: 0.447170,
12
+ liquidity: 2236.286652,
13
+ hypeLiquidity: 1236.286652,
14
+ flopLiquidity: 1000,
15
+ hypeShares: 0,
16
+ flopShares: 0
17
+ };
18
+ this.ordersOpen = [];
19
+ this.ordersClosed = [];
20
+ this.orders = [];
21
+ this.simulate = () => {
22
+ for (const order of this.orders) {
23
+ const result = this.openOrder(order);
24
+ this.ordersOpen.push({
25
+ id: this.ordersOpen.length + 1,
26
+ shares: result.shares,
27
+ amount: order.amount,
28
+ direction: order.direction,
29
+ price: result.priceWithImpact,
30
+ marketPrice: result.marketPrice
31
+ });
32
+ }
33
+ console.table(this.ordersOpen);
34
+ const ordersToClose = [];
35
+ for (const order of this.ordersOpen) {
36
+ if (ordersToClose.includes(order.id)) {
37
+ const result = this.closeOrder(order);
38
+ this.ordersClosed.push({
39
+ id: order.id,
40
+ shares: result.shares,
41
+ amount: order.amount,
42
+ direction: order.direction,
43
+ price: result.price,
44
+ priceWithImpact: result.priceWithImpact,
45
+ payout: result.payout
46
+ });
47
+ this.ordersOpen = this.ordersOpen.filter((o) => o.id !== order.id);
48
+ }
49
+ }
50
+ if (this.ordersClosed.length > 0) {
51
+ console.table(this.ordersClosed);
52
+ }
53
+ console.table(this.market);
54
+ };
55
+ this.openOrder = (order) => {
56
+ let currentPool = order.direction === 'hype'
57
+ ? this.market.hypeLiquidity
58
+ : this.market.flopLiquidity;
59
+ let otherPool = order.direction === 'hype'
60
+ ? this.market.flopLiquidity
61
+ : this.market.hypeLiquidity;
62
+ const newCurrentPool = currentPool + order.amount;
63
+ const marketsLiquidity = newCurrentPool + otherPool;
64
+ let marketPrice = newCurrentPool / marketsLiquidity;
65
+ let orderPrice = marketPrice * (1 + MAKER_FEE);
66
+ const shares = order.amount / orderPrice;
67
+ if (marketPrice < 0.000001) {
68
+ marketPrice = 0.000001;
69
+ }
70
+ if (marketPrice > 0.999999) {
71
+ marketPrice = 0.999999;
72
+ }
73
+ if (orderPrice < 0.000001) {
74
+ orderPrice = 0.000001;
75
+ }
76
+ if (orderPrice > 0.999999) {
77
+ orderPrice = 0.999999;
78
+ }
79
+ if (order.direction === 'hype') {
80
+ this.market.hypeLiquidity = newCurrentPool;
81
+ this.market.flopLiquidity = otherPool;
82
+ this.market.hypePrice = marketPrice;
83
+ this.market.flopPrice = 1 - marketPrice;
84
+ this.market.hypeShares += shares;
85
+ }
86
+ else {
87
+ this.market.flopLiquidity = newCurrentPool;
88
+ this.market.hypeLiquidity = otherPool;
89
+ this.market.flopPrice = marketPrice;
90
+ this.market.hypePrice = 1 - marketPrice;
91
+ this.market.flopShares += shares;
92
+ }
93
+ this.market.liquidity = marketsLiquidity;
94
+ return {
95
+ shares,
96
+ priceWithImpact: orderPrice,
97
+ marketPrice
98
+ };
99
+ };
100
+ this.closeOrder = (order) => {
101
+ let currentPool = order.direction === 'hype'
102
+ ? this.market.hypeLiquidity
103
+ : this.market.flopLiquidity;
104
+ let otherPool = order.direction === 'hype'
105
+ ? this.market.flopLiquidity
106
+ : this.market.hypeLiquidity;
107
+ let currentShares = order.direction === 'hype'
108
+ ? this.market.hypeShares
109
+ : this.market.flopShares;
110
+ let otherShares = order.direction === 'hype'
111
+ ? this.market.flopShares
112
+ : this.market.hypeShares;
113
+ const k = currentPool * otherPool;
114
+ const currentPrice = currentPool / (currentPool + otherPool);
115
+ const tokensOut = order.shares * currentPrice;
116
+ const tokensOutAfterFee = tokensOut * (1 - TAKER_FEE);
117
+ const newCurrentPool = currentPool - tokensOutAfterFee;
118
+ const newOtherPool = k / newCurrentPool;
119
+ const newPrice = newCurrentPool / (newCurrentPool + newOtherPool);
120
+ if (newPrice < 0.000001) {
121
+ throw new Error('Price too low');
122
+ }
123
+ if (newPrice > 0.999999) {
124
+ throw new Error('Price too high');
125
+ }
126
+ if (order.direction === 'hype') {
127
+ this.market.hypeLiquidity = newCurrentPool;
128
+ this.market.flopLiquidity = newOtherPool;
129
+ this.market.hypePrice = newPrice;
130
+ this.market.flopPrice = 1 - newPrice;
131
+ this.market.hypeShares -= order.shares;
132
+ }
133
+ else {
134
+ this.market.flopLiquidity = newCurrentPool;
135
+ this.market.hypeLiquidity = newOtherPool;
136
+ this.market.flopPrice = newPrice;
137
+ this.market.hypePrice = 1 - newPrice;
138
+ this.market.flopShares -= order.shares;
139
+ }
140
+ this.market.liquidity = newCurrentPool + newOtherPool;
141
+ return {
142
+ payout: tokensOutAfterFee,
143
+ shares: order.shares,
144
+ price: newPrice,
145
+ priceWithImpact: tokensOutAfterFee / order.shares
146
+ };
147
+ };
148
+ for (let i = 0; i < 1; i++) {
149
+ this.orders.push({
150
+ amount: 1000,
151
+ direction: 'hype'
152
+ });
153
+ }
154
+ }
155
+ }
156
+ exports.SimulateMarket = SimulateMarket;
package/dist/stake.js CHANGED
@@ -16,7 +16,6 @@ const anchor_1 = require("@coral-xyz/anchor");
16
16
  const helpers_1 = require("./utils/helpers");
17
17
  const stake_1 = require("./utils/pda/stake");
18
18
  const constants_1 = require("./utils/constants");
19
- const getRarityRank_1 = __importDefault(require("./utils/getRarityRank"));
20
19
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
21
20
  const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
22
21
  const convertSecretKeyToKeypair_1 = require("./utils/convertSecretKeyToKeypair");
@@ -194,7 +193,6 @@ class Stake {
194
193
  items.push(stake);
195
194
  });
196
195
  for (const stake of items) {
197
- const rank = (0, getRarityRank_1.default)(ranks, stake.mint, stake.name);
198
196
  if (ixs.length >= 10) {
199
197
  break;
200
198
  }
@@ -203,7 +201,7 @@ class Stake {
203
201
  ixs.push(yield this.program.methods
204
202
  .claimStakeRewards({
205
203
  collections,
206
- rank
204
+ rank: 963
207
205
  })
208
206
  .accounts({
209
207
  signer: wallet,
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 { InitializeMarketArgs, OpenOrderArgs, OrderDirection, UserTrade } from './types/trade';
4
+ import { InitializeMarketArgs, OpenOrderArgs, UserTrade } from './types/trade';
5
5
  import { RpcOptions } from './types';
6
6
  import BN from 'bn.js';
7
7
  export default class Trade {
@@ -180,36 +180,6 @@ export default class Trade {
180
180
  draw: {};
181
181
  };
182
182
  }, options?: RpcOptions): Promise<string>;
183
- /**
184
- * Resolve Market With Liquidity
185
- * @param args.marketId - The ID of the Market
186
- * @param args.winningDirection - The Winning Direction of the Market
187
- * @param args.marketToAddLiquidity - The Market to Add Liquidity
188
- * @param args.amount - The amount of the Order
189
- *
190
- * @param options - RPC options
191
- *
192
- */
193
- resolveMarketWithLiquidity({ marketId, winningDirection, marketToAddLiquidity, amount }: {
194
- marketId: number;
195
- winningDirection: OrderDirection;
196
- marketToAddLiquidity: OrderDirection;
197
- amount: number;
198
- }, options?: RpcOptions): Promise<string>;
199
- /**
200
- * Add Liquidity
201
- * @param marketId - The ID of the market
202
- * @param amount - The amount of the order
203
- * @param direction - The direction of the order
204
- *
205
- * @param options - RPC options
206
- *
207
- */
208
- addLiquidity({ marketId, amount, direction }: {
209
- marketId: number;
210
- amount: number;
211
- direction: OrderDirection;
212
- }, options?: RpcOptions): Promise<string>;
213
183
  /**
214
184
  * Collect Remaining Liquidity
215
185
  * @param marketId - The ID of the market
@@ -248,4 +218,13 @@ export default class Trade {
248
218
  *
249
219
  */
250
220
  createSubUserTrade(user: PublicKey, options?: RpcOptions): Promise<string>;
221
+ /**
222
+ * Update Market
223
+ * @param marketId - The ID of the market
224
+ * @param marketEnd - The end time of the market
225
+ *
226
+ * @param options - RPC options
227
+ *
228
+ */
229
+ updateMarket(marketId: number, marketEnd: number, options?: RpcOptions): Promise<string>;
251
230
  }
package/dist/trade.js CHANGED
@@ -282,65 +282,6 @@ class Trade {
282
282
  return (0, sendTransactionWithOptions_1.default)(method, options);
283
283
  });
284
284
  }
285
- /**
286
- * Resolve Market With Liquidity
287
- * @param args.marketId - The ID of the Market
288
- * @param args.winningDirection - The Winning Direction of the Market
289
- * @param args.marketToAddLiquidity - The Market to Add Liquidity
290
- * @param args.amount - The amount of the Order
291
- *
292
- * @param options - RPC options
293
- *
294
- */
295
- resolveMarketWithLiquidity({ marketId, winningDirection, marketToAddLiquidity, amount }, options) {
296
- return __awaiter(this, void 0, void 0, function* () {
297
- const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
298
- const ixs = [];
299
- ixs.push(yield this.program.methods
300
- .resolveMarket(winningDirection)
301
- .accounts({
302
- signer: this.provider.publicKey,
303
- market: marketPDA
304
- })
305
- .instruction());
306
- ixs.push(yield this.program.methods
307
- .addLiquidity({
308
- amount: new bn_js_1.default(amount * Math.pow(10, constants_1.TRD_DECIMALS)),
309
- direction: marketToAddLiquidity
310
- })
311
- .accounts({
312
- signer: this.provider.publicKey,
313
- market: marketPDA,
314
- mint: constants_1.TRD_MINT
315
- })
316
- .instruction());
317
- return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
318
- });
319
- }
320
- /**
321
- * Add Liquidity
322
- * @param marketId - The ID of the market
323
- * @param amount - The amount of the order
324
- * @param direction - The direction of the order
325
- *
326
- * @param options - RPC options
327
- *
328
- */
329
- addLiquidity({ marketId, amount, direction }, options) {
330
- return __awaiter(this, void 0, void 0, function* () {
331
- const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
332
- return (0, sendTransactionWithOptions_1.default)(this.program.methods
333
- .addLiquidity({
334
- amount: new bn_js_1.default(amount * Math.pow(10, constants_1.TRD_DECIMALS)),
335
- direction: direction
336
- })
337
- .accounts({
338
- signer: this.provider.publicKey,
339
- market: marketPDA,
340
- mint: constants_1.TRD_MINT
341
- }), options);
342
- });
343
- }
344
285
  /**
345
286
  * Collect Remaining Liquidity
346
287
  * @param marketId - The ID of the market
@@ -415,5 +356,22 @@ class Trade {
415
356
  }), options);
416
357
  });
417
358
  }
359
+ /**
360
+ * Update Market
361
+ * @param marketId - The ID of the market
362
+ * @param marketEnd - The end time of the market
363
+ *
364
+ * @param options - RPC options
365
+ *
366
+ */
367
+ updateMarket(marketId, marketEnd, options) {
368
+ return __awaiter(this, void 0, void 0, function* () {
369
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
370
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.updateMarket(new bn_js_1.default(marketEnd)).accounts({
371
+ signer: this.provider.publicKey,
372
+ market: marketPDA
373
+ }), options);
374
+ });
375
+ }
418
376
  }
419
377
  exports.default = Trade;