@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.
package/dist/index.d.ts CHANGED
@@ -4,11 +4,13 @@ import { TriadProtocol } from './types/triad_protocol';
4
4
  import Trade from './trade';
5
5
  import Stake from './stake';
6
6
  import { RpcOptions, TransferPoseidonArgs } from './types';
7
+ import Wheel from './wheel';
7
8
  export default class TriadProtocolClient {
8
9
  program: Program<TriadProtocol>;
9
10
  provider: AnchorProvider;
10
11
  trade: Trade;
11
12
  stake: Stake;
13
+ wheel: Wheel;
12
14
  constructor(connection: Connection, wallet: Wallet);
13
15
  /**
14
16
  * Transfer Poseidon
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ const stake_1 = __importDefault(require("./stake"));
20
20
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
21
21
  const constants_1 = require("./utils/constants");
22
22
  const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
23
+ const wheel_1 = __importDefault(require("./wheel"));
23
24
  class TriadProtocolClient {
24
25
  constructor(connection, wallet) {
25
26
  this.provider = new anchor_1.AnchorProvider(connection, wallet, {
@@ -28,6 +29,7 @@ class TriadProtocolClient {
28
29
  this.program = new anchor_1.Program(idl_triad_protocol_json_1.default, this.provider);
29
30
  this.trade = new trade_1.default(this.program, this.provider);
30
31
  this.stake = new stake_1.default(this.program, this.provider);
32
+ this.wheel = new wheel_1.default(this.program, this.provider);
31
33
  }
32
34
  /**
33
35
  * Transfer Poseidon
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,524 @@
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 trade_1 = require("../types/trade");
20
+ const spl_token_1 = require("@solana/spl-token");
21
+ const constants_1 = require("../utils/constants");
22
+ const simulate_market_1 = require("./simulate-market");
23
+ const init_market_1 = require("./init-market");
24
+ const sdk_1 = require("@shadow-drive/sdk");
25
+ const pda_1 = require("../utils/pda");
26
+ const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
27
+ const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
28
+ const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
29
+ const connection = new web3_js_1.Connection(rpc_file.toString());
30
+ const wallet = new anchor_1.Wallet(keypair);
31
+ const triadProtocol = new __1.default(connection, wallet);
32
+ const marketId = 1001;
33
+ const simulateMarket = new simulate_market_1.SimulateMarket(triadProtocol);
34
+ const initMarket = new init_market_1.InitMarket(triadProtocol);
35
+ const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
36
+ const response = yield triadProtocol.stake.updateStakeVault({
37
+ amount: new anchor_1.BN(1000 * Math.pow(10, 6)),
38
+ isLocked: false
39
+ });
40
+ console.log(response);
41
+ });
42
+ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const response = yield triadProtocol.stake.getStakeVaults();
44
+ console.log(response);
45
+ });
46
+ const getStakeByWallet = () => __awaiter(void 0, void 0, void 0, function* () {
47
+ const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('4k8qFA1i7fv6YGWJnoLZPSHj9nhLn3bokAdXWnuAteBV'), 1);
48
+ let sum = 0;
49
+ for (const stake of response) {
50
+ sum += stake.amount / Math.pow(10, 6);
51
+ }
52
+ console.log(sum);
53
+ });
54
+ const getAllStakes = () => __awaiter(void 0, void 0, void 0, function* () {
55
+ const stakes = yield triadProtocol.stake.getStakes();
56
+ console.log(stakes.length);
57
+ });
58
+ const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
59
+ const stakes = yield triadProtocol.stake.getStakes();
60
+ fs_1.default.writeFileSync('stakes.json', JSON.stringify(stakes, null, 2));
61
+ const stakesJson = JSON.parse(fs_1.default.readFileSync('stakes.json', 'utf8'));
62
+ let amountLocked = 0;
63
+ let amountUnlocked = 0;
64
+ let uniqueStakersLocked = new Set();
65
+ let uniqueStakersUnlocked = new Set();
66
+ let usersUnlocked = [];
67
+ let usersLocked = [];
68
+ for (const stake of stakesJson) {
69
+ if (stake.withdrawTs === 0) {
70
+ amountLocked += stake.amount / Math.pow(10, 6);
71
+ uniqueStakersLocked.add(stake.authority);
72
+ if (!usersLocked.find((user) => user.address === stake.authority)) {
73
+ usersLocked.push({
74
+ address: stake.authority,
75
+ amount: stake.amount / Math.pow(10, 6)
76
+ });
77
+ }
78
+ else {
79
+ const user = usersLocked === null || usersLocked === void 0 ? void 0 : usersLocked.find((user) => user.address === stake.authority);
80
+ if (user) {
81
+ user.amount += stake.amount / Math.pow(10, 6);
82
+ }
83
+ }
84
+ }
85
+ else {
86
+ amountUnlocked += stake.amount / Math.pow(10, 6);
87
+ uniqueStakersUnlocked.add(stake.authority);
88
+ if (!usersUnlocked.find((user) => user.address === stake.authority)) {
89
+ usersUnlocked.push({
90
+ address: stake.authority,
91
+ amount: stake.amount / Math.pow(10, 6)
92
+ });
93
+ }
94
+ else {
95
+ const user = usersUnlocked.find((user) => user.address === stake.authority);
96
+ if (user) {
97
+ user.amount += stake.amount / Math.pow(10, 6);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ const orders = usersLocked.sort((a, b) => b.amount - a.amount);
103
+ const ordersUnlocked = usersUnlocked.sort((a, b) => b.amount - a.amount);
104
+ console.log('Amount locked:', amountLocked);
105
+ console.log('Amount unlocked:', amountUnlocked);
106
+ console.log('Unique stakers:', uniqueStakersLocked.size);
107
+ console.log('Unique stakers unlocked:', uniqueStakersUnlocked.size);
108
+ console.log(JSON.stringify(orders, null, 2));
109
+ console.log('--------------------------------');
110
+ console.log(JSON.stringify(ordersUnlocked, null, 2));
111
+ });
112
+ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
113
+ let markets = yield triadProtocol.trade.getAllMarkets();
114
+ markets = markets.sort((a, b) => Number(a.marketId) - Number(b.marketId));
115
+ let totalFlopToPay = 0;
116
+ let totalHypeToPay = 0;
117
+ let totalLiquidity = 0;
118
+ let profit = 0;
119
+ const items = {};
120
+ for (const market of markets) {
121
+ if (Number(market.marketId) < 39) {
122
+ continue;
123
+ }
124
+ let liquidity = (Number(market.hypeLiquidity) + Number(market.flopLiquidity)) / Math.pow(10, 6);
125
+ // liquidity -= Number(market.marketLiquidityAtStart) / 10 ** 6
126
+ console.log('Market ID:', market.question);
127
+ console.log('Liquidity:', liquidity);
128
+ console.log('Hype Shares:', Number(market.hypeShares) / Math.pow(10, 6));
129
+ console.log('Flop Shares:', Number(market.flopShares) / Math.pow(10, 6));
130
+ let innerProfit = 0;
131
+ if (market.winningDirection === trade_1.WinningDirection.HYPE ||
132
+ Number(market.hypePrice) > Number(market.flopPrice)) {
133
+ innerProfit += liquidity - Number(market.hypeShares) / Math.pow(10, 6);
134
+ console.log('Profit:', innerProfit);
135
+ }
136
+ if (market.winningDirection === trade_1.WinningDirection.FLOP ||
137
+ Number(market.hypePrice) < Number(market.flopPrice)) {
138
+ innerProfit += liquidity - Number(market.flopShares) / Math.pow(10, 6);
139
+ console.log('Profit:', profit);
140
+ }
141
+ totalFlopToPay += Number(market.flopShares) / Math.pow(10, 6);
142
+ totalHypeToPay += Number(market.hypeShares) / Math.pow(10, 6);
143
+ totalLiquidity += liquidity;
144
+ profit += innerProfit;
145
+ items[market.marketId] = {
146
+ question: market.question,
147
+ liquidity: liquidity,
148
+ hypeShares: Number(market.hypeShares) / Math.pow(10, 6),
149
+ flopShares: Number(market.flopShares) / Math.pow(10, 6),
150
+ profit: innerProfit
151
+ };
152
+ console.log('--------------------------------');
153
+ }
154
+ console.log('Total Liquidity:', totalLiquidity);
155
+ console.log('Total Hype to Pay:', totalHypeToPay);
156
+ console.log('Total Flop to Pay:', totalFlopToPay);
157
+ console.log('Triad Profit:', profit);
158
+ console.table(items);
159
+ });
160
+ const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
161
+ const market = yield triadProtocol.trade.getMarketById(marketId);
162
+ console.log(market);
163
+ });
164
+ const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
165
+ const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
166
+ if (!response) {
167
+ return [];
168
+ }
169
+ let orders = [];
170
+ for (const order of response.account.orders) {
171
+ console.log(order);
172
+ if (!order.status.open) {
173
+ continue;
174
+ }
175
+ orders.push({
176
+ marketId: order.marketId.toNumber(),
177
+ orderId: order.orderId.toNumber(),
178
+ totalShares: order.totalShares.toString(),
179
+ amount: order.totalAmount.toString(),
180
+ direction: order.direction,
181
+ questionId: order.questionId,
182
+ price: order.price.toString(),
183
+ status: order.status
184
+ });
185
+ }
186
+ console.log(orders);
187
+ return orders;
188
+ });
189
+ const getAllTraders = () => __awaiter(void 0, void 0, void 0, function* () {
190
+ const response = yield triadProtocol.program.account.userTrade.all();
191
+ console.log(response);
192
+ });
193
+ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
194
+ const response = yield triadProtocol.program.account.userTrade.all();
195
+ const allMarkets = yield triadProtocol.trade.getAllMarkets();
196
+ const liquidityToRecovery = {};
197
+ for (const market of allMarkets) {
198
+ let currentMarket = liquidityToRecovery[market.marketId];
199
+ if (market.marketId === '58') {
200
+ // market.winningDirection = WinningDirection.FLOP
201
+ }
202
+ if (market.winningDirection.toLowerCase() === 'none') {
203
+ continue;
204
+ }
205
+ if (!currentMarket) {
206
+ currentMarket = {
207
+ address: market.address,
208
+ name: market.question,
209
+ liquidityAvailable: 0,
210
+ openOrders: 0,
211
+ amountInPDA: 0,
212
+ sharesToPay: 0,
213
+ direction: market.winningDirection.toLowerCase()
214
+ };
215
+ liquidityToRecovery[market.marketId] = currentMarket;
216
+ }
217
+ const marketLiquidityAtStart = parseFloat(market.marketLiquidityAtStart.toString()) / Math.pow(10, 6);
218
+ if (currentMarket.direction === 'flop') {
219
+ currentMarket.liquidityAvailable =
220
+ parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
221
+ currentMarket.liquidityAvailable =
222
+ currentMarket.liquidityAvailable - marketLiquidityAtStart / 2;
223
+ }
224
+ if (currentMarket.direction === 'hype') {
225
+ currentMarket.liquidityAvailable =
226
+ parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
227
+ currentMarket.liquidityAvailable =
228
+ currentMarket.liquidityAvailable - marketLiquidityAtStart / 2;
229
+ }
230
+ 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);
231
+ const account = yield (0, spl_token_1.getAccount)(connection, token, 'finalized', spl_token_1.TOKEN_2022_PROGRAM_ID);
232
+ currentMarket.amountInPDA = Number(account.amount) / Math.pow(10, 6);
233
+ }
234
+ for (const userTrade of response) {
235
+ for (const order of userTrade.account.orders) {
236
+ const market = liquidityToRecovery[order.marketId.toNumber()];
237
+ if (!market) {
238
+ continue;
239
+ }
240
+ if (order.status.open &&
241
+ Object.keys(order.direction)[0] === market.direction) {
242
+ market.openOrders += 1;
243
+ const payout = parseFloat(order.totalShares.toString());
244
+ market.sharesToPay += payout / Math.pow(10, 6);
245
+ }
246
+ }
247
+ }
248
+ console.log(JSON.stringify(liquidityToRecovery, null, 2));
249
+ let amountAllowToWithdraw = 0;
250
+ let amountToPay = 0;
251
+ let amountInPDA = 0;
252
+ for (const market of Object.values(liquidityToRecovery)) {
253
+ amountAllowToWithdraw += market.amountInPDA - market.sharesToPay;
254
+ amountToPay += market.sharesToPay;
255
+ amountInPDA += market.amountInPDA;
256
+ }
257
+ console.log('Amount allow to withdraw:', amountAllowToWithdraw);
258
+ console.log('Amount to pay:', amountToPay);
259
+ console.log('Amount in PDA:', amountInPDA);
260
+ });
261
+ const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
262
+ for (const order of yield getOrders(wallet.publicKey)) {
263
+ try {
264
+ const response = yield triadProtocol.trade.closeOrder({
265
+ marketId: order.marketId,
266
+ orderId: order.orderId,
267
+ userNonce: 0
268
+ });
269
+ console.log(response);
270
+ }
271
+ catch (e) {
272
+ console.log(e);
273
+ }
274
+ }
275
+ });
276
+ const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
277
+ const marketsToResolve = [{ marketId: 130, winningDirection: { hype: {} } }];
278
+ for (const market of marketsToResolve) {
279
+ const response = yield triadProtocol.trade.resolveMarket({
280
+ marketId: market.marketId,
281
+ winningDirection: market.winningDirection
282
+ });
283
+ console.log(response);
284
+ }
285
+ });
286
+ const collectRemainingLiquidityFromAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
287
+ console.log('Collecting fees');
288
+ const allMarkets = yield triadProtocol.trade.getAllMarkets();
289
+ for (const market of allMarkets) {
290
+ console.log(`Collecting fees for market ${market.marketId}`);
291
+ console.log(market);
292
+ if (market.openedOrders !== '0') {
293
+ continue;
294
+ }
295
+ try {
296
+ const response = yield triadProtocol.trade.collectRemainingLiquidity(Number(market.marketId));
297
+ console.log(response);
298
+ }
299
+ catch (_a) { }
300
+ }
301
+ });
302
+ const burnLP = () => __awaiter(void 0, void 0, void 0, function* () {
303
+ const SOL_LP = new web3_js_1.PublicKey('8yXmXEQh8M1vyjKKhN6L12EZiXCY3cJS4xL45wwQExep');
304
+ const getTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(SOL_LP, wallet.publicKey, true);
305
+ console.log(getTokenAccount);
306
+ const amount = 191.360098123 * Math.pow(10, 9);
307
+ const response = yield (0, spl_token_1.burn)(connection, keypair, getTokenAccount, SOL_LP, wallet.publicKey, amount);
308
+ console.log(response);
309
+ });
310
+ const mintToken = () => __awaiter(void 0, void 0, void 0, function* () {
311
+ const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
312
+ const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
313
+ try {
314
+ const decimals = 6; // Common decimal places for tokens
315
+ const amount = 1000000 * Math.pow(10, decimals); // 1,000,000 tokens with decimals
316
+ // Calculate space needed for mint account including metadata pointer
317
+ // const mintLen = getMintLen([ExtensionType.MetadataPointer])
318
+ // const mintTransaction = new Transaction().add(
319
+ // // Create mint account
320
+ // SystemProgram.createAccount({
321
+ // fromPubkey: wallet.publicKey,
322
+ // newAccountPubkey: token.publicKey,
323
+ // space: mintLen,
324
+ // lamports: 6786240,
325
+ // programId: TOKEN_2022_PROGRAM_ID
326
+ // }),
327
+ // createInitializeMetadataPointerInstruction(
328
+ // token.publicKey,
329
+ // wallet.publicKey,
330
+ // token.publicKey,
331
+ // TOKEN_2022_PROGRAM_ID
332
+ // ),
333
+ // createInitializeMintInstruction(
334
+ // token.publicKey,
335
+ // decimals,
336
+ // wallet.publicKey,
337
+ // null,
338
+ // TOKEN_2022_PROGRAM_ID
339
+ // ),
340
+ // createInitializeInstruction({
341
+ // programId: TOKEN_2022_PROGRAM_ID,
342
+ // metadata: token.publicKey,
343
+ // updateAuthority: wallet.publicKey,
344
+ // mint: token.publicKey,
345
+ // mintAuthority: wallet.publicKey,
346
+ // name: 'Triad Christmas',
347
+ // symbol: 'tCMAS',
348
+ // uri: 'https://shdw-drive.genesysgo.net/DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M/tCMAS.json'
349
+ // })
350
+ // )
351
+ // const transactionSignature = await sendAndConfirmTransaction(
352
+ // connection,
353
+ // mintTransaction,
354
+ // [keypair, token], // Signers,
355
+ // { skipPreflight: false }
356
+ // )
357
+ // console.log(
358
+ // '\nCreate Mint Account:',
359
+ // `https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana`
360
+ // )
361
+ // const associatedTokenAccount = await getOrCreateAssociatedTokenAccount(
362
+ // connection,
363
+ // keypair,
364
+ // token.publicKey,
365
+ // wallet.publicKey,
366
+ // true,
367
+ // undefined,
368
+ // undefined,
369
+ // TOKEN_2022_PROGRAM_ID
370
+ // )
371
+ // const mintToResponse = await mintTo(
372
+ // connection,
373
+ // keypair,
374
+ // token.publicKey,
375
+ // associatedTokenAccount.address,
376
+ // wallet.publicKey,
377
+ // amount,
378
+ // [keypair, token],
379
+ // undefined,
380
+ // TOKEN_2022_PROGRAM_ID
381
+ // )
382
+ // console.log('Token created:', token.publicKey.toString())
383
+ // console.log('Associated Token Account:', associatedTokenAccount.toString())
384
+ // console.log('Mint tx:', mintToResponse)
385
+ }
386
+ catch (e) {
387
+ console.log(e);
388
+ }
389
+ });
390
+ const updateTokenMetadata = () => __awaiter(void 0, void 0, void 0, function* () {
391
+ const mintTransaction = new web3_js_1.Transaction().add((0, spl_token_1.createUpdateFieldInstruction)({
392
+ programId: spl_token_1.TOKEN_2022_PROGRAM_ID,
393
+ metadata: new web3_js_1.PublicKey('tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2'),
394
+ updateAuthority: wallet.publicKey,
395
+ field: 'uri',
396
+ value: 'https://shdw-drive.genesysgo.net/DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M/tEVENT.json'
397
+ }));
398
+ const transactionSignature = yield (0, web3_js_1.sendAndConfirmTransaction)(connection, mintTransaction, [keypair] // Signers,
399
+ );
400
+ console.log(transactionSignature);
401
+ });
402
+ const withdrawPoseidon = () => __awaiter(void 0, void 0, void 0, function* () {
403
+ const response = yield triadProtocol.withdrawPoseidon({
404
+ poseidonAsset: new web3_js_1.PublicKey('DMoyQ6pAj9bGu3WoMcVeYv4rgrU96Xjzyzudfs4fkJw3'),
405
+ nft: 430
406
+ });
407
+ console.log(response);
408
+ });
409
+ const openOrderTriad = () => __awaiter(void 0, void 0, void 0, function* () {
410
+ const response3 = yield triadProtocol.trade.openOrder({
411
+ marketId: marketId,
412
+ amount: 1000,
413
+ direction: {
414
+ hype: {}
415
+ },
416
+ token: constants_1.TRD_MINT.toBase58()
417
+ });
418
+ console.log(response3);
419
+ yield getMarket();
420
+ });
421
+ const closeOrderTriad = () => __awaiter(void 0, void 0, void 0, function* () {
422
+ const response = yield triadProtocol.trade.closeOrder({
423
+ marketId: marketId,
424
+ orderId: 1,
425
+ userNonce: 8
426
+ });
427
+ console.log(response);
428
+ });
429
+ const collectRoyalties = () => __awaiter(void 0, void 0, void 0, function* () {
430
+ const response = yield triadProtocol.collectRoyalty(constants_1.POSEIDON_COLLECTION_SYMBOL, {
431
+ skipPreflight: false
432
+ });
433
+ console.log(response);
434
+ });
435
+ const collectRemainingLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
436
+ const markets = [105];
437
+ for (const market of markets) {
438
+ const response = yield triadProtocol.trade.collectRemainingLiquidity(market);
439
+ console.log(response);
440
+ }
441
+ });
442
+ const allowMarketToPayout = () => __awaiter(void 0, void 0, void 0, function* () {
443
+ const markets = [130];
444
+ for (const market of markets) {
445
+ try {
446
+ const response = yield triadProtocol.trade.allowMarketToPayout(Number(market));
447
+ console.log(response);
448
+ }
449
+ catch (error) {
450
+ console.log(error);
451
+ }
452
+ }
453
+ });
454
+ const getUserOrders = () => __awaiter(void 0, void 0, void 0, function* () {
455
+ const response = yield triadProtocol.trade.getUserOrders(wallet.publicKey);
456
+ const filteredResponse = response.filter((order) => order.marketId === marketId.toString());
457
+ console.log(response);
458
+ });
459
+ const updateMarket = () => __awaiter(void 0, void 0, void 0, function* () {
460
+ const response = yield triadProtocol.trade.updateMarket(128, 1751327940);
461
+ console.log(response);
462
+ });
463
+ const getStorage = () => __awaiter(void 0, void 0, void 0, function* () {
464
+ const drive = yield new sdk_1.ShdwDrive(triadProtocol.provider.connection, triadProtocol.provider.wallet).init();
465
+ console.log(yield drive.getStorageAccount(new web3_js_1.PublicKey('DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M')));
466
+ const jsonFile = {
467
+ name: `tCMAS.json`,
468
+ file: fs_1.default.readFileSync(`./src/tCMAS.json`)
469
+ };
470
+ const file = yield drive.editFile(new web3_js_1.PublicKey('DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M'), jsonFile);
471
+ console.log(file);
472
+ return file;
473
+ });
474
+ const deployImage = (image) => __awaiter(void 0, void 0, void 0, function* () {
475
+ const TRIAD_STORAGE_ACCOUNT = new web3_js_1.PublicKey('DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M');
476
+ const drive = yield new sdk_1.ShdwDrive(triadProtocol.provider.connection, triadProtocol.provider.wallet).init();
477
+ const jsonFile = {
478
+ name: `${image}`,
479
+ file: fs_1.default.readFileSync(`./src/${image}`)
480
+ };
481
+ const file = yield drive.uploadFile(TRIAD_STORAGE_ACCOUNT, jsonFile);
482
+ console.log(file);
483
+ return file;
484
+ });
485
+ // 1 - TRD 10k - 10,000 / 1 to 20
486
+ // 2 - TRD 50 - 10,000 / 21 to 2021
487
+ // 3 - TRD 5 - 50,000 / 2022 to 102022
488
+ // 4 - Honeyland NFT - 30 NFT / 102023 to 132023
489
+ // 5 - Poseidon NFT - 20 NFT / 132024 to 152024
490
+ // 6 - SMB 3 - 2 NFT / 152025 to 157025
491
+ // 7 - 500 tridents / 157026 to 657026
492
+ // 8 - 2k tridents / 657027 to 857027
493
+ // 9 - 50 HXD - 10,000 / 857028 to 864008
494
+ // 10 - 0.01 ORE - 10 ORE / 864009 to 924009
495
+ // 11 - TRD 100 - 5,000 / 924010 to 925010
496
+ // 12 - 10 STREAM - 15K STREAM / 925011 to 1000000
497
+ const addWheelPrize = () => __awaiter(void 0, void 0, void 0, function* () {
498
+ const response = yield triadProtocol.wheel.addWheelPrize({
499
+ prize: 11,
500
+ amount: 20,
501
+ rangeMin: 924010,
502
+ rangeMax: 925010,
503
+ availableQuantity: 50
504
+ });
505
+ console.log(response);
506
+ });
507
+ const getWheel = () => __awaiter(void 0, void 0, void 0, function* () {
508
+ const [response] = yield triadProtocol.program.account.wheel.all();
509
+ const prizes = response.account.prizes
510
+ .filter((prize) => prize.status.claimed)
511
+ .map((prize) => ({
512
+ prize: prize.prize.toString(),
513
+ amount: prize.amount.toString(),
514
+ rangeMin: prize.rangeMin.toString(),
515
+ rangeMax: prize.rangeMax.toString(),
516
+ availableQuantity: prize.availableQuantity.toString()
517
+ }));
518
+ console.log(prizes);
519
+ });
520
+ const spinWheel = () => __awaiter(void 0, void 0, void 0, function* () {
521
+ const spin = (0, pda_1.getWheelPDA)(triadProtocol.program.programId, constants_1.VALENT_SPIN_NAME);
522
+ console.log(spin);
523
+ });
524
+ spinWheel();
@@ -0,0 +1,8 @@
1
+ import TriadProtocol from '..';
2
+ export declare class InitMarket {
3
+ private triadProtocol;
4
+ markets: Partial<any>[];
5
+ constructor(triadProtocol: TriadProtocol);
6
+ initializeMarkets: () => Promise<void>;
7
+ deployImage: (image: string) => Promise<import("@shadow-drive/sdk").ShadowUploadResponse>;
8
+ }
@@ -0,0 +1,63 @@
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
+ exports.InitMarket = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const web3_js_1 = require("@solana/web3.js");
18
+ const sdk_1 = require("@shadow-drive/sdk");
19
+ class InitMarket {
20
+ constructor(triadProtocol) {
21
+ this.triadProtocol = triadProtocol;
22
+ this.markets = [
23
+ {
24
+ marketId: 1001,
25
+ question: 'Will PHOTOM flip TRON in 7D revenue by february 15?',
26
+ startTime: 1239663940,
27
+ endTime: 1739663940,
28
+ image: ''
29
+ }
30
+ ];
31
+ this.initializeMarkets = () => __awaiter(this, void 0, void 0, function* () {
32
+ for (const market of this.markets) {
33
+ try {
34
+ const response = yield this.triadProtocol.trade.initializeMarket({
35
+ marketId: market.marketId,
36
+ question: market.question,
37
+ startTime: market.startTime,
38
+ endTime: market.endTime
39
+ });
40
+ if (market.image) {
41
+ yield this.deployImage(market.image);
42
+ }
43
+ console.log(`Initialized market ${market.question}:`, response);
44
+ }
45
+ catch (error) {
46
+ console.error(`Error initializing market ${market.question}:`, error);
47
+ }
48
+ }
49
+ });
50
+ this.deployImage = (image) => __awaiter(this, void 0, void 0, function* () {
51
+ const TRIAD_STORAGE_ACCOUNT = new web3_js_1.PublicKey('8Tp66VQmgHXQfd8ui2VZHPLZfkKu8mMwywmRsnVfTRBm');
52
+ const drive = yield new sdk_1.ShdwDrive(this.triadProtocol.provider.connection, this.triadProtocol.provider.wallet).init();
53
+ const jsonFile = {
54
+ name: `${image}`,
55
+ file: fs_1.default.readFileSync(`./src/${image}`)
56
+ };
57
+ const file = yield drive.uploadFile(TRIAD_STORAGE_ACCOUNT, jsonFile);
58
+ console.log(file);
59
+ return file;
60
+ });
61
+ }
62
+ }
63
+ exports.InitMarket = InitMarket;
@@ -0,0 +1,54 @@
1
+ import TriadProtocol from '..';
2
+ export declare class SimulateMarket {
3
+ private triadProtocol;
4
+ market: {
5
+ hypePrice: number;
6
+ flopPrice: number;
7
+ liquidity: number;
8
+ hypeLiquidity: number;
9
+ flopLiquidity: number;
10
+ hypeShares: number;
11
+ flopShares: number;
12
+ };
13
+ ordersOpen: {
14
+ id: number;
15
+ shares: number;
16
+ amount: number;
17
+ direction: 'hype' | 'flop';
18
+ price: number;
19
+ marketPrice: number;
20
+ }[];
21
+ ordersClosed: {
22
+ id: number;
23
+ shares: number;
24
+ amount: number;
25
+ direction: 'hype' | 'flop';
26
+ price: number;
27
+ priceWithImpact: number;
28
+ payout: number;
29
+ }[];
30
+ orders: {
31
+ amount: number;
32
+ direction: 'hype' | 'flop';
33
+ }[];
34
+ constructor(triadProtocol: TriadProtocol);
35
+ simulate: () => void;
36
+ openOrder: (order: {
37
+ amount: number;
38
+ direction: 'hype' | 'flop';
39
+ }) => {
40
+ shares: number;
41
+ priceWithImpact: number;
42
+ marketPrice: number;
43
+ };
44
+ closeOrder: (order: {
45
+ amount: number;
46
+ shares: number;
47
+ direction: 'hype' | 'flop';
48
+ }) => {
49
+ payout: number;
50
+ shares: number;
51
+ price: number;
52
+ priceWithImpact: number;
53
+ };
54
+ }