@triadxyz/triad-protocol 1.5.3-beta → 1.5.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 @@
1
+ export {};
@@ -0,0 +1,619 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const fs_1 = __importDefault(require("fs"));
16
+ const _1 = __importDefault(require("."));
17
+ const anchor_1 = require("@coral-xyz/anchor");
18
+ const web3_js_1 = require("@solana/web3.js");
19
+ const sdk_1 = require("@shadow-drive/sdk");
20
+ const spl_token_1 = require("@solana/spl-token");
21
+ const constants_1 = require("./utils/constants");
22
+ const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
23
+ const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
24
+ const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
25
+ const connection = new web3_js_1.Connection(rpc_file.toString());
26
+ const wallet = new anchor_1.Wallet(keypair);
27
+ const triadProtocol = new _1.default(connection, wallet);
28
+ const markets = [
29
+ {
30
+ marketId: 90,
31
+ question: 'Real Madrid',
32
+ startTime: 1737963756,
33
+ endTime: 1748131141
34
+ },
35
+ {
36
+ marketId: 91,
37
+ question: 'Barcelona',
38
+ startTime: 1737963756,
39
+ endTime: 1748131141
40
+ },
41
+ {
42
+ marketId: 92,
43
+ question: 'Atletico Madrid',
44
+ startTime: 1737963756,
45
+ endTime: 1748131141
46
+ }
47
+ ];
48
+ const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
49
+ const response = yield triadProtocol.stake.updateStakeVault({
50
+ amount: new anchor_1.BN(1000 * Math.pow(10, 6)),
51
+ isLocked: false
52
+ });
53
+ console.log(response);
54
+ });
55
+ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
56
+ const response = yield triadProtocol.stake.getStakeVaults();
57
+ console.log(response);
58
+ });
59
+ const getStakeByWallet = () => __awaiter(void 0, void 0, void 0, function* () {
60
+ const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('4k8qFA1i7fv6YGWJnoLZPSHj9nhLn3bokAdXWnuAteBV'), 1);
61
+ let sum = 0;
62
+ for (const stake of response) {
63
+ sum += stake.amount / Math.pow(10, 6);
64
+ }
65
+ console.log(sum);
66
+ });
67
+ const getAllStakes = () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const stakes = yield triadProtocol.stake.getStakes();
69
+ console.log(stakes.length);
70
+ });
71
+ const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const stakes = yield triadProtocol.stake.getStakes();
73
+ fs_1.default.writeFileSync('stakes.json', JSON.stringify(stakes, null, 2));
74
+ const stakesJson = JSON.parse(fs_1.default.readFileSync('stakes.json', 'utf8'));
75
+ let amountLocked = 0;
76
+ let amountUnlocked = 0;
77
+ let uniqueStakersLocked = new Set();
78
+ let uniqueStakersUnlocked = new Set();
79
+ let usersUnlocked = [];
80
+ let usersLocked = [];
81
+ for (const stake of stakesJson) {
82
+ if (stake.withdrawTs === 0) {
83
+ amountLocked += stake.amount / Math.pow(10, 6);
84
+ uniqueStakersLocked.add(stake.authority);
85
+ if (!usersLocked.find((user) => user.address === stake.authority)) {
86
+ usersLocked.push({
87
+ address: stake.authority,
88
+ amount: stake.amount / Math.pow(10, 6)
89
+ });
90
+ }
91
+ else {
92
+ const user = usersLocked === null || usersLocked === void 0 ? void 0 : usersLocked.find((user) => user.address === stake.authority);
93
+ if (user) {
94
+ user.amount += stake.amount / Math.pow(10, 6);
95
+ }
96
+ }
97
+ }
98
+ else {
99
+ amountUnlocked += stake.amount / Math.pow(10, 6);
100
+ uniqueStakersUnlocked.add(stake.authority);
101
+ if (!usersUnlocked.find((user) => user.address === stake.authority)) {
102
+ usersUnlocked.push({
103
+ address: stake.authority,
104
+ amount: stake.amount / Math.pow(10, 6)
105
+ });
106
+ }
107
+ else {
108
+ const user = usersUnlocked.find((user) => user.address === stake.authority);
109
+ if (user) {
110
+ user.amount += stake.amount / Math.pow(10, 6);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ const orders = usersLocked.sort((a, b) => b.amount - a.amount);
116
+ const ordersUnlocked = usersUnlocked.sort((a, b) => b.amount - a.amount);
117
+ console.log('Amount locked:', amountLocked);
118
+ console.log('Amount unlocked:', amountUnlocked);
119
+ console.log('Unique stakers:', uniqueStakersLocked.size);
120
+ console.log('Unique stakers unlocked:', uniqueStakersUnlocked.size);
121
+ console.log(JSON.stringify(orders, null, 2));
122
+ console.log('--------------------------------');
123
+ console.log(JSON.stringify(ordersUnlocked, null, 2));
124
+ });
125
+ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
126
+ const markets = yield triadProtocol.trade.getAllMarkets();
127
+ console.log(markets.sort((a, b) => Number(a.marketId) - Number(b.marketId)));
128
+ });
129
+ const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
130
+ const market = yield triadProtocol.trade.getMarketById(9);
131
+ console.log(market);
132
+ });
133
+ const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
134
+ for (const market of markets) {
135
+ try {
136
+ const response = yield triadProtocol.trade.initializeMarket(market, {
137
+ microLamports: 5000
138
+ });
139
+ console.log(`Initialized market ${market.question}:`, response);
140
+ }
141
+ catch (error) {
142
+ console.error(`Error initializing market ${market.question}:`, error);
143
+ }
144
+ }
145
+ });
146
+ const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
147
+ const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
148
+ if (!response) {
149
+ return [];
150
+ }
151
+ let orders = [];
152
+ for (const order of response.account.orders) {
153
+ if (!order.status.open) {
154
+ continue;
155
+ }
156
+ orders.push({
157
+ marketId: order.marketId.toNumber(),
158
+ orderId: order.orderId.toNumber(),
159
+ totalShares: order.totalShares.toString(),
160
+ amount: order.totalAmount.toString(),
161
+ direction: order.direction,
162
+ questionId: order.questionId,
163
+ price: order.price.toString(),
164
+ status: order.status
165
+ });
166
+ }
167
+ console.log(orders);
168
+ return orders;
169
+ });
170
+ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
171
+ const response = yield triadProtocol.program.account.userTrade.all();
172
+ const allMarkets = yield triadProtocol.trade.getAllMarkets();
173
+ const liquidityToRecovery = {};
174
+ for (const market of allMarkets) {
175
+ let currentMarket = liquidityToRecovery[market.marketId];
176
+ if (market.marketId === '58') {
177
+ // market.winningDirection = WinningDirection.FLOP
178
+ }
179
+ if (market.winningDirection.toLowerCase() === 'none') {
180
+ continue;
181
+ }
182
+ if (!currentMarket) {
183
+ currentMarket = {
184
+ address: market.address,
185
+ name: market.question,
186
+ liquidityAvailable: 0,
187
+ openOrders: 0,
188
+ amountInPDA: 0,
189
+ sharesToPay: 0,
190
+ direction: market.winningDirection.toLowerCase()
191
+ };
192
+ liquidityToRecovery[market.marketId] = currentMarket;
193
+ }
194
+ const marketLiquidityAtStart = parseFloat(market.marketLiquidityAtStart.toString()) / Math.pow(10, 6);
195
+ if (currentMarket.direction === 'flop') {
196
+ currentMarket.liquidityAvailable =
197
+ parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
198
+ currentMarket.liquidityAvailable =
199
+ currentMarket.liquidityAvailable - marketLiquidityAtStart / 2;
200
+ }
201
+ if (currentMarket.direction === 'hype') {
202
+ currentMarket.liquidityAvailable =
203
+ parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
204
+ currentMarket.liquidityAvailable =
205
+ currentMarket.liquidityAvailable - marketLiquidityAtStart / 2;
206
+ }
207
+ const token = yield (0, spl_token_1.getAssociatedTokenAddress)(constants_1.TRD_MINT, new web3_js_1.PublicKey(market.address), true, spl_token_1.TOKEN_2022_PROGRAM_ID);
208
+ const account = yield (0, spl_token_1.getAccount)(connection, token, 'finalized', spl_token_1.TOKEN_2022_PROGRAM_ID);
209
+ currentMarket.amountInPDA = Number(account.amount) / Math.pow(10, 6);
210
+ }
211
+ for (const userTrade of response) {
212
+ for (const order of userTrade.account.orders) {
213
+ const market = liquidityToRecovery[order.marketId.toNumber()];
214
+ if (!market) {
215
+ continue;
216
+ }
217
+ if (order.status.open &&
218
+ Object.keys(order.direction)[0] === market.direction) {
219
+ market.openOrders += 1;
220
+ const payout = parseFloat(order.totalShares.toString());
221
+ market.sharesToPay += payout / Math.pow(10, 6);
222
+ }
223
+ }
224
+ }
225
+ console.log(JSON.stringify(liquidityToRecovery, null, 2));
226
+ let amountAllowToWithdraw = 0;
227
+ let amountToPay = 0;
228
+ let amountInPDA = 0;
229
+ for (const market of Object.values(liquidityToRecovery)) {
230
+ amountAllowToWithdraw += market.amountInPDA - market.sharesToPay;
231
+ amountToPay += market.sharesToPay;
232
+ amountInPDA += market.amountInPDA;
233
+ }
234
+ console.log('Amount allow to withdraw:', amountAllowToWithdraw);
235
+ console.log('Amount to pay:', amountToPay);
236
+ console.log('Amount in PDA:', amountInPDA);
237
+ });
238
+ const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
239
+ for (const order of yield getOrders(wallet.publicKey)) {
240
+ try {
241
+ const response = yield triadProtocol.trade.closeOrder({
242
+ marketId: order.marketId,
243
+ orderId: order.orderId
244
+ });
245
+ console.log(response);
246
+ }
247
+ catch (e) {
248
+ console.log(e);
249
+ }
250
+ }
251
+ });
252
+ const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
253
+ const marketsToResolve = [{ marketId: 47, winningDirection: { hype: {} } }];
254
+ for (const market of marketsToResolve) {
255
+ const response = yield triadProtocol.trade.resolveMarket({
256
+ marketId: market.marketId,
257
+ winningDirection: market.winningDirection
258
+ }, {
259
+ microLamports: 5000
260
+ });
261
+ console.log(response);
262
+ }
263
+ });
264
+ const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
265
+ const response = yield triadProtocol.trade.addLiquidity({
266
+ marketId: 5,
267
+ amount: 4729,
268
+ direction: {
269
+ hype: {}
270
+ }
271
+ });
272
+ console.log(response);
273
+ });
274
+ const collectRemainingLiquidityFromAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
275
+ console.log('Collecting fees');
276
+ const allMarkets = yield triadProtocol.trade.getAllMarkets();
277
+ for (const market of allMarkets) {
278
+ console.log(`Collecting fees for market ${market.marketId}`);
279
+ if (market.openedOrders !== '0') {
280
+ continue;
281
+ }
282
+ try {
283
+ const response = yield triadProtocol.trade.collectRemainingLiquidity(Number(market.marketId));
284
+ console.log(response);
285
+ }
286
+ catch (e) {
287
+ console.log(e);
288
+ }
289
+ }
290
+ });
291
+ const burnLP = () => __awaiter(void 0, void 0, void 0, function* () {
292
+ const SOL_LP = new web3_js_1.PublicKey('8yXmXEQh8M1vyjKKhN6L12EZiXCY3cJS4xL45wwQExep');
293
+ const getTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(SOL_LP, wallet.publicKey, true);
294
+ console.log(getTokenAccount);
295
+ const amount = 191.360098123 * Math.pow(10, 9);
296
+ const response = yield (0, spl_token_1.burn)(connection, keypair, getTokenAccount, SOL_LP, wallet.publicKey, amount);
297
+ console.log(response);
298
+ });
299
+ const resolveWithLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
300
+ const response = yield triadProtocol.trade.resolveMarketWithLiquidity({
301
+ marketId: 0,
302
+ winningDirection: { flop: {} },
303
+ marketToAddLiquidity: { hype: {} },
304
+ amount: 0
305
+ });
306
+ console.log(response);
307
+ });
308
+ const mintToken = () => __awaiter(void 0, void 0, void 0, function* () {
309
+ const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
310
+ const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
311
+ try {
312
+ const decimals = 6; // Common decimal places for tokens
313
+ const amount = 1000000 * Math.pow(10, decimals); // 1,000,000 tokens with decimals
314
+ // Calculate space needed for mint account including metadata pointer
315
+ // const mintLen = getMintLen([ExtensionType.MetadataPointer])
316
+ // const mintTransaction = new Transaction().add(
317
+ // // Create mint account
318
+ // SystemProgram.createAccount({
319
+ // fromPubkey: wallet.publicKey,
320
+ // newAccountPubkey: token.publicKey,
321
+ // space: mintLen,
322
+ // lamports: 6786240,
323
+ // programId: TOKEN_2022_PROGRAM_ID
324
+ // }),
325
+ // createInitializeMetadataPointerInstruction(
326
+ // token.publicKey,
327
+ // wallet.publicKey,
328
+ // token.publicKey,
329
+ // TOKEN_2022_PROGRAM_ID
330
+ // ),
331
+ // createInitializeMintInstruction(
332
+ // token.publicKey,
333
+ // decimals,
334
+ // wallet.publicKey,
335
+ // null,
336
+ // TOKEN_2022_PROGRAM_ID
337
+ // ),
338
+ // createInitializeInstruction({
339
+ // programId: TOKEN_2022_PROGRAM_ID,
340
+ // metadata: token.publicKey,
341
+ // updateAuthority: wallet.publicKey,
342
+ // mint: token.publicKey,
343
+ // mintAuthority: wallet.publicKey,
344
+ // name: 'Triad Christmas',
345
+ // symbol: 'tCMAS',
346
+ // uri: 'https://shdw-drive.genesysgo.net/DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M/tCMAS.json'
347
+ // })
348
+ // )
349
+ // const transactionSignature = await sendAndConfirmTransaction(
350
+ // connection,
351
+ // mintTransaction,
352
+ // [keypair, token], // Signers,
353
+ // { skipPreflight: false }
354
+ // )
355
+ // console.log(
356
+ // '\nCreate Mint Account:',
357
+ // `https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana`
358
+ // )
359
+ // const associatedTokenAccount = await getOrCreateAssociatedTokenAccount(
360
+ // connection,
361
+ // keypair,
362
+ // token.publicKey,
363
+ // wallet.publicKey,
364
+ // true,
365
+ // undefined,
366
+ // undefined,
367
+ // TOKEN_2022_PROGRAM_ID
368
+ // )
369
+ // const mintToResponse = await mintTo(
370
+ // connection,
371
+ // keypair,
372
+ // token.publicKey,
373
+ // associatedTokenAccount.address,
374
+ // wallet.publicKey,
375
+ // amount,
376
+ // [keypair, token],
377
+ // undefined,
378
+ // TOKEN_2022_PROGRAM_ID
379
+ // )
380
+ // console.log('Token created:', token.publicKey.toString())
381
+ // console.log('Associated Token Account:', associatedTokenAccount.toString())
382
+ // console.log('Mint tx:', mintToResponse)
383
+ }
384
+ catch (e) {
385
+ console.log(e);
386
+ }
387
+ });
388
+ const removeMintAuthority = () => __awaiter(void 0, void 0, void 0, function* () {
389
+ const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
390
+ const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
391
+ try {
392
+ const response = yield (0, spl_token_1.setAuthority)(connection, keypair, token.publicKey, wallet.publicKey, spl_token_1.AuthorityType.MetadataPointer, null, [], undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
393
+ console.log('Mint authority removed:', response);
394
+ }
395
+ catch (error) {
396
+ console.error('Error removing mint authority:', error);
397
+ }
398
+ });
399
+ const getMinteds = () => __awaiter(void 0, void 0, void 0, function* () {
400
+ const response = yield triadProtocol.program.account.collection.all();
401
+ console.log(response);
402
+ });
403
+ const closeOrder = (market, order) => {
404
+ let currentLiquidity = 0;
405
+ let othersideLiquidity = 0;
406
+ let current_price = 0;
407
+ if (order.direction === 'hype') {
408
+ currentLiquidity = market.hypeLiquidity;
409
+ othersideLiquidity = market.flopLiquidity;
410
+ current_price = market.hypePrice;
411
+ }
412
+ else {
413
+ currentLiquidity = market.flopLiquidity;
414
+ othersideLiquidity = market.hypeLiquidity;
415
+ current_price = market.flopPrice;
416
+ }
417
+ const marketLiquidity = currentLiquidity + othersideLiquidity;
418
+ const shares = order.shares;
419
+ let payout = shares * current_price;
420
+ let newDirectionalLiquidity = currentLiquidity - payout;
421
+ let newMarketLiquidity = marketLiquidity - payout;
422
+ let price_with_impact = Math.min(Math.max((newDirectionalLiquidity * 1000000) / newMarketLiquidity, 1), 999999);
423
+ payout = shares * (price_with_impact / 1000000);
424
+ newDirectionalLiquidity = currentLiquidity - payout;
425
+ newMarketLiquidity = marketLiquidity - payout;
426
+ let price = Math.min(Math.max((newDirectionalLiquidity * 1000000) / newMarketLiquidity, 1), 999999);
427
+ if (order.direction === 'hype') {
428
+ market.hypePrice = price / 1000000;
429
+ market.hypeLiquidity = currentLiquidity - payout;
430
+ market.flopPrice = (1000000 - price) / 1000000;
431
+ market.hypeShares -= shares;
432
+ }
433
+ else {
434
+ market.flopPrice = price / 1000000;
435
+ market.flopLiquidity = currentLiquidity - payout;
436
+ market.hypePrice = (1000000 - price) / 1000000;
437
+ market.flopShares -= shares;
438
+ }
439
+ market.liquidity = newMarketLiquidity;
440
+ return {
441
+ payout,
442
+ shares,
443
+ price: price / 1000000,
444
+ priceWithImpact: price_with_impact / 1000000,
445
+ market
446
+ };
447
+ };
448
+ const openOrder = (market, order) => {
449
+ let currentLiquidity = 0;
450
+ let othersideLiquidity = 0;
451
+ if (order.direction === 'hype') {
452
+ currentLiquidity = market.hypeLiquidity;
453
+ othersideLiquidity = market.flopLiquidity;
454
+ }
455
+ else {
456
+ currentLiquidity = market.flopLiquidity;
457
+ othersideLiquidity = market.hypeLiquidity;
458
+ }
459
+ const newDirectionalLiquidity = currentLiquidity + order.amount;
460
+ const marketsLiquidity = newDirectionalLiquidity + othersideLiquidity;
461
+ let newPrice = (newDirectionalLiquidity * 1000000) / marketsLiquidity;
462
+ if (newPrice > 999999) {
463
+ newPrice = 999999;
464
+ }
465
+ if (newPrice < 1) {
466
+ newPrice = 1;
467
+ }
468
+ const netAmount = order.amount * 1000000;
469
+ const max_shares = netAmount / newPrice;
470
+ let shares = max_shares;
471
+ let improved_shares = market.hypeShares + max_shares;
472
+ const maxValue = improved_shares > market.flopShares ? improved_shares : market.flopShares;
473
+ let correction_factor = marketsLiquidity / maxValue;
474
+ if (order.direction === 'flop') {
475
+ improved_shares = market.flopShares + max_shares;
476
+ const maxValue = market.hypeShares > improved_shares ? market.hypeShares : improved_shares;
477
+ correction_factor = marketsLiquidity / maxValue;
478
+ }
479
+ if (correction_factor > 1) {
480
+ correction_factor = 1;
481
+ }
482
+ if (correction_factor < 1) {
483
+ shares = max_shares + (marketsLiquidity - improved_shares);
484
+ }
485
+ if (order.direction === 'hype') {
486
+ market.hypePrice = newPrice / 1000000;
487
+ market.hypeLiquidity = newDirectionalLiquidity;
488
+ market.flopPrice = (1000000 - newPrice) / 1000000;
489
+ market.hypeShares += shares;
490
+ }
491
+ if (order.direction === 'flop') {
492
+ market.flopPrice = newPrice / 1000000;
493
+ market.flopLiquidity = newDirectionalLiquidity;
494
+ market.hypePrice = (1000000 - newPrice) / 1000000;
495
+ market.flopShares += shares;
496
+ }
497
+ market.liquidity = marketsLiquidity;
498
+ return { market, shares, priceWithImpact: newPrice / 1000000 };
499
+ };
500
+ let i = 0;
501
+ const simulateMarket = () => {
502
+ const market = {
503
+ hypePrice: 0.5,
504
+ flopPrice: 0.5,
505
+ liquidity: 0,
506
+ hypeLiquidity: 500,
507
+ flopLiquidity: 500,
508
+ hypeShares: 0,
509
+ flopShares: 0
510
+ };
511
+ const orders = [
512
+ {
513
+ amount: 10,
514
+ direction: 'hype'
515
+ },
516
+ {
517
+ amount: 1000,
518
+ direction: 'flop'
519
+ }
520
+ ];
521
+ let ordersOpen = [];
522
+ for (const order of orders) {
523
+ const result = openOrder(market, order);
524
+ ordersOpen.push({
525
+ id: ordersOpen.length + 1,
526
+ shares: result.shares,
527
+ amount: order.amount,
528
+ direction: order.direction,
529
+ price: result.priceWithImpact
530
+ });
531
+ market.hypePrice = result.market.hypePrice;
532
+ market.flopPrice = result.market.flopPrice;
533
+ market.liquidity = result.market.liquidity;
534
+ market.hypeLiquidity = result.market.hypeLiquidity;
535
+ market.flopLiquidity = result.market.flopLiquidity;
536
+ market.hypeShares = result.market.hypeShares;
537
+ market.flopShares = result.market.flopShares;
538
+ }
539
+ console.table(ordersOpen);
540
+ console.log(market);
541
+ let ordersClosed = [];
542
+ // for (const order of ordersOpen) {
543
+ // const result = closeOrder(market, order)
544
+ // ordersClosed.push({
545
+ // id: order.id,
546
+ // shares: result.shares,
547
+ // amount: order.amount,
548
+ // direction: order.direction,
549
+ // price: result.price,
550
+ // priceWithImpact: result.priceWithImpact,
551
+ // payout: result.payout
552
+ // })
553
+ // ordersOpen = ordersOpen.filter((o) => o.id !== order.id)
554
+ // market.hypePrice = result.market.hypePrice
555
+ // market.flopPrice = result.market.flopPrice
556
+ // market.liquidity = result.market.liquidity
557
+ // market.hypeLiquidity = result.market.hypeLiquidity
558
+ // market.flopLiquidity = result.market.flopLiquidity
559
+ // market.hypeShares = result.market.hypeShares
560
+ // market.flopShares = result.market.flopShares
561
+ // }
562
+ // console.table(ordersClosed)
563
+ // console.log(market)
564
+ };
565
+ const withdrawPoseidon = () => __awaiter(void 0, void 0, void 0, function* () {
566
+ const response = yield triadProtocol.withdrawPoseidon({
567
+ poseidonAsset: new web3_js_1.PublicKey('9PJNHY7CztR6jGdFW9XtCUfBjhrrVD99d4UpQEoDfd9F'),
568
+ nft: 531
569
+ });
570
+ console.log(response);
571
+ });
572
+ const openOrderTriad = () => __awaiter(void 0, void 0, void 0, function* () {
573
+ const response = yield triadProtocol.trade.openOrder({
574
+ marketId: 42,
575
+ amount: 10,
576
+ direction: {
577
+ hype: {}
578
+ },
579
+ token: constants_1.TRD_MINT.toBase58()
580
+ }, {
581
+ skipPreflight: true
582
+ });
583
+ console.log(response);
584
+ });
585
+ const collectRoyalties = () => __awaiter(void 0, void 0, void 0, function* () {
586
+ const response = yield triadProtocol.collectRoyalty(constants_1.TICKET_COLLECTION_SYMBOL, {
587
+ skipPreflight: true
588
+ });
589
+ console.log(response);
590
+ });
591
+ const collectRemainingLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
592
+ const response = yield triadProtocol.trade.collectRemainingLiquidity(8);
593
+ console.log(response);
594
+ });
595
+ const createShadowDrive = () => __awaiter(void 0, void 0, void 0, function* () {
596
+ const TRIAD_STORAGE_ACCOUNT = new web3_js_1.PublicKey('8Tp66VQmgHXQfd8ui2VZHPLZfkKu8mMwywmRsnVfTRBm');
597
+ const drive = yield new sdk_1.ShdwDrive(connection, wallet).init();
598
+ const images = [];
599
+ for (const image of images) {
600
+ const jsonFile = {
601
+ name: `${image}`,
602
+ file: fs_1.default.readFileSync(`./src/${image}`)
603
+ };
604
+ const file = yield drive.uploadFile(TRIAD_STORAGE_ACCOUNT, jsonFile);
605
+ console.log(file);
606
+ }
607
+ });
608
+ const allowToPayout = () => __awaiter(void 0, void 0, void 0, function* () {
609
+ const markets = yield triadProtocol.trade.getAllMarkets();
610
+ for (const market of markets) {
611
+ try {
612
+ const response = yield triadProtocol.trade.allowMarketPayout(Number(market.marketId));
613
+ console.log(response);
614
+ }
615
+ catch (error) {
616
+ console.log(error);
617
+ }
618
+ }
619
+ });
package/dist/trade.js CHANGED
@@ -30,13 +30,8 @@ class Trade {
30
30
  */
31
31
  getAllMarkets() {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const marketV1 = yield this.program.account.market
34
- .all()
35
- .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.accountToMarketV1)(account, publicKey)));
36
- const marketV2 = yield this.program.account.marketV2
37
- .all()
38
- .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey)));
39
- return [...marketV1, ...marketV2];
33
+ const marketV2 = yield this.program.account.marketV2.all();
34
+ return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
40
35
  });
41
36
  }
42
37
  /**
@@ -240,6 +240,11 @@
240
240
  "writable": true,
241
241
  "signer": true
242
242
  },
243
+ {
244
+ "name": "squads",
245
+ "writable": true,
246
+ "address": "6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq"
247
+ },
243
248
  {
244
249
  "name": "user_trade",
245
250
  "writable": true
@@ -362,6 +362,11 @@ export type TriadProtocol = {
362
362
  writable: true;
363
363
  signer: true;
364
364
  },
365
+ {
366
+ name: 'squads';
367
+ writable: true;
368
+ address: '6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq';
369
+ },
365
370
  {
366
371
  name: 'userTrade';
367
372
  writable: true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.5.3-beta",
3
+ "version": "1.5.4-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "license": "ISC",
33
33
  "dependencies": {
34
34
  "@coral-xyz/anchor": "0.30.1",
35
+ "@shadow-drive/sdk": "^6.0.0",
35
36
  "@solana/spl-token": "0.4.8",
36
37
  "@solana/web3.js": "^1.95.3",
37
38
  "axios": "^1.5.1",