@triadxyz/triad-protocol 1.7.2-beta ā 1.7.3-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/local-test/index.d.ts +1 -0
- package/dist/local-test/index.js +419 -0
- package/dist/local-test/init-market.d.ts +8 -0
- package/dist/local-test/init-market.js +58 -0
- package/dist/local-test/order-book.d.ts +9 -0
- package/dist/local-test/order-book.js +46 -0
- package/dist/local-test/simulate-market.d.ts +5 -0
- package/dist/local-test/simulate-market.js +9 -0
- package/dist/trade.d.ts +3 -2
- package/dist/trade.js +10 -6
- package/dist/types/trade.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,419 @@
|
|
|
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 anchor_2 = require("@coral-xyz/anchor");
|
|
19
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
+
const trade_1 = require("../types/trade");
|
|
21
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
22
|
+
const constants_1 = require("../utils/constants");
|
|
23
|
+
// import { InitMarket } from './init-market'
|
|
24
|
+
const sdk_1 = require("@shadow-drive/sdk");
|
|
25
|
+
const init_market_1 = require("./init-market");
|
|
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 = 133;
|
|
33
|
+
const initMarket = new init_market_1.InitMarket(triadProtocol);
|
|
34
|
+
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const response = yield triadProtocol.stake.updateStakeVault({
|
|
36
|
+
amount: new anchor_2.BN(200 * Math.pow(10, 6)),
|
|
37
|
+
isLocked: false
|
|
38
|
+
});
|
|
39
|
+
console.log(response);
|
|
40
|
+
});
|
|
41
|
+
const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const response = yield triadProtocol.stake.getStakeVaults();
|
|
43
|
+
console.log(response);
|
|
44
|
+
});
|
|
45
|
+
const getStakeByWallet = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('Fua99qprDG3YGijFDoGfWPnUjBqufgPPQgJTZEGKHFFL'), 1);
|
|
47
|
+
let sum = 0;
|
|
48
|
+
for (const stake of response) {
|
|
49
|
+
sum += stake.amount / Math.pow(10, 6);
|
|
50
|
+
}
|
|
51
|
+
console.log(sum);
|
|
52
|
+
});
|
|
53
|
+
const getAllStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const stakes = yield triadProtocol.stake.getStakes();
|
|
55
|
+
console.log(stakes.length);
|
|
56
|
+
});
|
|
57
|
+
const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const stakes = yield triadProtocol.stake.getStakes();
|
|
59
|
+
fs_1.default.writeFileSync('stakes.json', JSON.stringify(stakes, null, 2));
|
|
60
|
+
const stakesJson = JSON.parse(fs_1.default.readFileSync('stakes.json', 'utf8'));
|
|
61
|
+
let amountLocked = 0;
|
|
62
|
+
let amountUnlocked = 0;
|
|
63
|
+
let uniqueStakersLocked = new Set();
|
|
64
|
+
let uniqueStakersUnlocked = new Set();
|
|
65
|
+
let usersUnlocked = [];
|
|
66
|
+
let usersLocked = [];
|
|
67
|
+
for (const stake of stakesJson) {
|
|
68
|
+
if (stake.withdrawTs === 0) {
|
|
69
|
+
amountLocked += stake.amount / Math.pow(10, 6);
|
|
70
|
+
uniqueStakersLocked.add(stake.authority);
|
|
71
|
+
const existingUser = usersLocked.find((user) => user.address === stake.authority);
|
|
72
|
+
if (!existingUser) {
|
|
73
|
+
usersLocked.push({
|
|
74
|
+
address: stake.authority,
|
|
75
|
+
amount: stake.amount / Math.pow(10, 6)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
existingUser.amount += stake.amount / Math.pow(10, 6);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
amountUnlocked += stake.amount / Math.pow(10, 6);
|
|
84
|
+
uniqueStakersUnlocked.add(stake.authority);
|
|
85
|
+
const existingUser = usersUnlocked.find((user) => user.address === stake.authority);
|
|
86
|
+
if (!existingUser) {
|
|
87
|
+
usersUnlocked.push({
|
|
88
|
+
address: stake.authority,
|
|
89
|
+
amount: stake.amount / Math.pow(10, 6)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
existingUser.amount += stake.amount / Math.pow(10, 6);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const orders = usersLocked.sort((a, b) => b.amount - a.amount);
|
|
98
|
+
const ordersUnlocked = usersUnlocked.sort((a, b) => b.amount - a.amount);
|
|
99
|
+
console.log('Amount locked:', amountLocked);
|
|
100
|
+
console.log('Amount unlocked:', amountUnlocked);
|
|
101
|
+
console.log('Unique stakers:', uniqueStakersLocked.size);
|
|
102
|
+
console.log('Unique stakers unlocked:', uniqueStakersUnlocked.size);
|
|
103
|
+
console.log(JSON.stringify(orders, null, 2));
|
|
104
|
+
console.log('--------------------------------');
|
|
105
|
+
console.log(JSON.stringify(ordersUnlocked, null, 2));
|
|
106
|
+
});
|
|
107
|
+
const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
let markets = yield triadProtocol.trade.getAllMarkets();
|
|
109
|
+
markets = markets.sort((a, b) => Number(a.marketId) - Number(b.marketId));
|
|
110
|
+
let totalFlopToPay = 0;
|
|
111
|
+
let totalHypeToPay = 0;
|
|
112
|
+
let totalLiquidity = 0;
|
|
113
|
+
let profit = 0;
|
|
114
|
+
const items = {};
|
|
115
|
+
for (const market of markets) {
|
|
116
|
+
if (Number(market.marketId) < 39 ||
|
|
117
|
+
market.winningDirection !== trade_1.WinningDirection.NONE) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
let liquidity = (Number(market.hypeLiquidity) + Number(market.flopLiquidity)) /
|
|
121
|
+
Math.pow(10, 6);
|
|
122
|
+
liquidity =
|
|
123
|
+
liquidity - Number(market.marketLiquidityAtStart) / Math.pow(10, 6);
|
|
124
|
+
console.log('Market ID:', market.question);
|
|
125
|
+
console.log('Liquidity:', liquidity);
|
|
126
|
+
console.log('Hype Shares:', Number(market.hypeShares) / Math.pow(10, 6));
|
|
127
|
+
console.log('Flop Shares:', Number(market.flopShares) / Math.pow(10, 6));
|
|
128
|
+
let innerProfit = 0;
|
|
129
|
+
if (Number(market.hypePrice) > Number(market.flopPrice)) {
|
|
130
|
+
innerProfit += liquidity - Number(market.hypeShares) / Math.pow(10, 6);
|
|
131
|
+
console.log('Profit:', innerProfit);
|
|
132
|
+
}
|
|
133
|
+
if (Number(market.hypePrice) < Number(market.flopPrice)) {
|
|
134
|
+
innerProfit += liquidity - Number(market.flopShares) / Math.pow(10, 6);
|
|
135
|
+
console.log('Profit:', profit);
|
|
136
|
+
}
|
|
137
|
+
totalFlopToPay += Number(market.flopShares) / Math.pow(10, 6);
|
|
138
|
+
totalHypeToPay += Number(market.hypeShares) / Math.pow(10, 6);
|
|
139
|
+
totalLiquidity += liquidity;
|
|
140
|
+
profit += innerProfit;
|
|
141
|
+
items[market.marketId] = {
|
|
142
|
+
question: market.question,
|
|
143
|
+
liquidity: liquidity,
|
|
144
|
+
hypeShares: Number(market.hypeShares) / Math.pow(10, 6),
|
|
145
|
+
flopShares: Number(market.flopShares) / Math.pow(10, 6),
|
|
146
|
+
profit: innerProfit
|
|
147
|
+
};
|
|
148
|
+
console.log('--------------------------------');
|
|
149
|
+
}
|
|
150
|
+
console.log('Total Liquidity:', totalLiquidity);
|
|
151
|
+
console.log('Total Hype to Pay:', totalHypeToPay);
|
|
152
|
+
console.log('Total Flop to Pay:', totalFlopToPay);
|
|
153
|
+
console.log('Triad Profit:', profit);
|
|
154
|
+
console.table(items);
|
|
155
|
+
});
|
|
156
|
+
const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
+
const market = yield triadProtocol.trade.getMarketById(marketId);
|
|
158
|
+
console.log(market);
|
|
159
|
+
});
|
|
160
|
+
const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
|
|
162
|
+
if (!response) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
let orders = [];
|
|
166
|
+
for (const order of response.account.orders) {
|
|
167
|
+
console.log(order);
|
|
168
|
+
if (!order.status.open) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
orders.push({
|
|
172
|
+
marketId: order.marketId.toNumber(),
|
|
173
|
+
orderId: order.orderId.toNumber(),
|
|
174
|
+
totalShares: order.totalShares.toString(),
|
|
175
|
+
amount: order.totalAmount.toString(),
|
|
176
|
+
direction: order.direction,
|
|
177
|
+
questionId: order.questionId.toString(),
|
|
178
|
+
price: order.price.toString(),
|
|
179
|
+
status: order.status
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
console.log(orders);
|
|
183
|
+
return orders;
|
|
184
|
+
});
|
|
185
|
+
const getAllTraders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
186
|
+
const response = yield triadProtocol.program.account.userTrade.all();
|
|
187
|
+
console.log(response);
|
|
188
|
+
});
|
|
189
|
+
const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
190
|
+
const response = yield triadProtocol.program.account.userTrade.all();
|
|
191
|
+
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
192
|
+
const liquidityToRecovery = {};
|
|
193
|
+
for (const market of allMarkets) {
|
|
194
|
+
let currentMarket = liquidityToRecovery[market.marketId];
|
|
195
|
+
if (market.marketId === '58') {
|
|
196
|
+
// market.winningDirection = WinningDirection.FLOP
|
|
197
|
+
}
|
|
198
|
+
if (market.winningDirection.toLowerCase() === 'none') {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (!currentMarket) {
|
|
202
|
+
currentMarket = {
|
|
203
|
+
address: market.address,
|
|
204
|
+
name: market.question,
|
|
205
|
+
liquidityAvailable: 0,
|
|
206
|
+
openOrders: 0,
|
|
207
|
+
amountInPDA: 0,
|
|
208
|
+
sharesToPay: 0,
|
|
209
|
+
direction: market.winningDirection.toLowerCase()
|
|
210
|
+
};
|
|
211
|
+
liquidityToRecovery[market.marketId] = currentMarket;
|
|
212
|
+
}
|
|
213
|
+
const liquidityAtStart = parseFloat(market.marketLiquidityAtStart.toString()) / Math.pow(10, 6);
|
|
214
|
+
if (currentMarket.direction === 'flop') {
|
|
215
|
+
currentMarket.liquidityAvailable =
|
|
216
|
+
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
217
|
+
currentMarket.liquidityAvailable =
|
|
218
|
+
currentMarket.liquidityAvailable - liquidityAtStart / 2;
|
|
219
|
+
}
|
|
220
|
+
if (currentMarket.direction === 'hype') {
|
|
221
|
+
currentMarket.liquidityAvailable =
|
|
222
|
+
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
223
|
+
currentMarket.liquidityAvailable =
|
|
224
|
+
currentMarket.liquidityAvailable - liquidityAtStart / 2;
|
|
225
|
+
}
|
|
226
|
+
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);
|
|
227
|
+
const account = yield (0, spl_token_1.getAccount)(connection, token, 'finalized', spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
228
|
+
currentMarket.amountInPDA = Number(account.amount) / Math.pow(10, 6);
|
|
229
|
+
}
|
|
230
|
+
for (const userTrade of response) {
|
|
231
|
+
for (const order of userTrade.account.orders) {
|
|
232
|
+
const market = liquidityToRecovery[order.marketId.toNumber()];
|
|
233
|
+
if (!market) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (order.status.open &&
|
|
237
|
+
Object.keys(order.direction)[0] === market.direction) {
|
|
238
|
+
market.openOrders += 1;
|
|
239
|
+
const payout = parseFloat(order.totalShares.toString());
|
|
240
|
+
market.sharesToPay += payout / Math.pow(10, 6);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
console.log(JSON.stringify(liquidityToRecovery, null, 2));
|
|
245
|
+
let amountAllowToWithdraw = 0;
|
|
246
|
+
let amountToPay = 0;
|
|
247
|
+
let amountInPDA = 0;
|
|
248
|
+
for (const market of Object.values(liquidityToRecovery)) {
|
|
249
|
+
amountAllowToWithdraw += market.amountInPDA - market.sharesToPay;
|
|
250
|
+
amountToPay += market.sharesToPay;
|
|
251
|
+
amountInPDA += market.amountInPDA;
|
|
252
|
+
}
|
|
253
|
+
console.log('Amount allow to withdraw:', amountAllowToWithdraw);
|
|
254
|
+
console.log('Amount to pay:', amountToPay);
|
|
255
|
+
console.log('Amount in PDA:', amountInPDA);
|
|
256
|
+
});
|
|
257
|
+
// Order functions
|
|
258
|
+
const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
259
|
+
for (const order of yield getOrders(wallet.publicKey)) {
|
|
260
|
+
try {
|
|
261
|
+
const response = yield triadProtocol.trade.closeOrder({
|
|
262
|
+
marketId: order.marketId,
|
|
263
|
+
orderId: order.orderId,
|
|
264
|
+
userNonce: 0
|
|
265
|
+
});
|
|
266
|
+
console.log(response);
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
console.log(e);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
+
const marketsToResolve = [
|
|
275
|
+
{ marketId: 163, winningDirection: { flop: {} } },
|
|
276
|
+
{ marketId: 164, winningDirection: { flop: {} } },
|
|
277
|
+
{ marketId: 165, winningDirection: { flop: {} } } // Atletico Madrid
|
|
278
|
+
];
|
|
279
|
+
for (const market of marketsToResolve) {
|
|
280
|
+
const response = yield triadProtocol.trade.resolveMarket({
|
|
281
|
+
marketId: market.marketId,
|
|
282
|
+
winningDirection: market.winningDirection
|
|
283
|
+
});
|
|
284
|
+
console.log(response);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
const collectRemainingLiquidityFromAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
|
+
console.log('Collecting fees');
|
|
289
|
+
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
290
|
+
for (const market of allMarkets) {
|
|
291
|
+
console.log(`Collecting fees for market ${market.marketId}`);
|
|
292
|
+
console.log(market);
|
|
293
|
+
if (market.openedOrders !== '0') {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
const response = yield triadProtocol.trade.collectRemainingLiquidity(Number(market.marketId));
|
|
298
|
+
console.log(response);
|
|
299
|
+
}
|
|
300
|
+
catch (_) { }
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
const burnLP = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
304
|
+
const SOL_LP = new web3_js_1.PublicKey('8yXmXEQh8M1vyjKKhN6L12EZiXCY3cJS4xL45wwQExep');
|
|
305
|
+
const getTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(SOL_LP, wallet.publicKey, true);
|
|
306
|
+
console.log(getTokenAccount);
|
|
307
|
+
const amount = 191.360098123 * Math.pow(10, 9);
|
|
308
|
+
const response = yield (0, spl_token_1.burn)(connection, keypair, getTokenAccount, SOL_LP, wallet.publicKey, amount);
|
|
309
|
+
console.log(response);
|
|
310
|
+
});
|
|
311
|
+
const mintToken = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
|
+
const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
|
|
313
|
+
const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
|
|
314
|
+
try {
|
|
315
|
+
const decimals = 6; // Common decimal places for tokens
|
|
316
|
+
const amount = 1000000 * Math.pow(10, decimals); // 1,000,000 tokens with decimals
|
|
317
|
+
// Token creation code is commented out in the original
|
|
318
|
+
// Keeping it commented out here as well
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
console.log(e);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
const updateTokenMetadata = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
325
|
+
const mintTransaction = new web3_js_1.Transaction().add((0, spl_token_1.createUpdateFieldInstruction)({
|
|
326
|
+
programId: spl_token_1.TOKEN_2022_PROGRAM_ID,
|
|
327
|
+
metadata: new web3_js_1.PublicKey('tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2'),
|
|
328
|
+
updateAuthority: wallet.publicKey,
|
|
329
|
+
field: 'uri',
|
|
330
|
+
value: 'https://shdw-drive.genesysgo.net/DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M/tEVENT.json'
|
|
331
|
+
}));
|
|
332
|
+
const transactionSignature = yield (0, web3_js_1.sendAndConfirmTransaction)(connection, mintTransaction, [keypair] // Signers
|
|
333
|
+
);
|
|
334
|
+
console.log(transactionSignature);
|
|
335
|
+
});
|
|
336
|
+
const withdrawPoseidon = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
337
|
+
const response = yield triadProtocol.withdrawPoseidon({
|
|
338
|
+
poseidonAsset: new web3_js_1.PublicKey('DMoyQ6pAj9bGu3WoMcVeYv4rgrU96Xjzyzudfs4fkJw3'),
|
|
339
|
+
nft: 430
|
|
340
|
+
});
|
|
341
|
+
console.log(response);
|
|
342
|
+
});
|
|
343
|
+
const openOrderTriad = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
344
|
+
const response3 = yield triadProtocol.trade.openOrder({
|
|
345
|
+
marketId: marketId,
|
|
346
|
+
amount: 1000,
|
|
347
|
+
direction: {
|
|
348
|
+
hype: {}
|
|
349
|
+
},
|
|
350
|
+
token: constants_1.TRD_MINT.toBase58()
|
|
351
|
+
});
|
|
352
|
+
console.log(response3);
|
|
353
|
+
yield getMarket();
|
|
354
|
+
});
|
|
355
|
+
const closeOrderTriad = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
356
|
+
const response = yield triadProtocol.trade.closeOrder({
|
|
357
|
+
marketId: marketId,
|
|
358
|
+
orderId: 1,
|
|
359
|
+
userNonce: 8
|
|
360
|
+
});
|
|
361
|
+
console.log(response);
|
|
362
|
+
});
|
|
363
|
+
const collectRoyalties = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
364
|
+
const response = yield triadProtocol.collectRoyalty(constants_1.POSEIDON_COLLECTION_SYMBOL, {
|
|
365
|
+
skipPreflight: false
|
|
366
|
+
});
|
|
367
|
+
console.log(response);
|
|
368
|
+
});
|
|
369
|
+
const collectRemainingLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
370
|
+
const markets = [160, 162, 164];
|
|
371
|
+
for (const market of markets) {
|
|
372
|
+
const response = yield triadProtocol.trade.collectRemainingLiquidity(market);
|
|
373
|
+
console.log(response);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
collectRemainingLiquidity();
|
|
377
|
+
const allowMarketToPayout = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
378
|
+
const markets = [163, 164, 165];
|
|
379
|
+
for (const market of markets) {
|
|
380
|
+
try {
|
|
381
|
+
const response = yield triadProtocol.trade.allowMarketToPayout(Number(market));
|
|
382
|
+
console.log(response);
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
console.log(error);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
const getUserOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
390
|
+
const response = yield triadProtocol.trade.getUserOrders(wallet.publicKey);
|
|
391
|
+
const filteredResponse = response.filter((order) => order.marketId === marketId.toString());
|
|
392
|
+
console.log(response);
|
|
393
|
+
});
|
|
394
|
+
const updateMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
395
|
+
const response = yield triadProtocol.trade.updateMarket(128, 1751327940);
|
|
396
|
+
console.log(response);
|
|
397
|
+
});
|
|
398
|
+
const getStorage = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
399
|
+
const drive = yield new sdk_1.ShdwDrive(triadProtocol.provider.connection, triadProtocol.provider.wallet).init();
|
|
400
|
+
console.log(yield drive.getStorageAccount(new web3_js_1.PublicKey('DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M')));
|
|
401
|
+
const jsonFile = {
|
|
402
|
+
name: `tCMAS.json`,
|
|
403
|
+
file: fs_1.default.readFileSync(`./src/tCMAS.json`)
|
|
404
|
+
};
|
|
405
|
+
const file = yield drive.editFile(new web3_js_1.PublicKey('DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M'), jsonFile);
|
|
406
|
+
console.log(file);
|
|
407
|
+
return file;
|
|
408
|
+
});
|
|
409
|
+
const deployImage = (image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
410
|
+
const TRIAD_STORAGE_ACCOUNT = new web3_js_1.PublicKey('DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M');
|
|
411
|
+
const drive = yield new sdk_1.ShdwDrive(triadProtocol.provider.connection, triadProtocol.provider.wallet).init();
|
|
412
|
+
const jsonFile = {
|
|
413
|
+
name: `${image}`,
|
|
414
|
+
file: fs_1.default.readFileSync(`./src/${image}`)
|
|
415
|
+
};
|
|
416
|
+
const file = yield drive.uploadFile(TRIAD_STORAGE_ACCOUNT, jsonFile);
|
|
417
|
+
console.log(file);
|
|
418
|
+
return file;
|
|
419
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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.markets = [];
|
|
22
|
+
this.initializeMarkets = () => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
for (const market of this.markets) {
|
|
24
|
+
try {
|
|
25
|
+
const response = yield this.triadProtocol.trade.createMarket({
|
|
26
|
+
marketId: market.marketId,
|
|
27
|
+
question: market.question,
|
|
28
|
+
startTime: market.startTime,
|
|
29
|
+
endTime: market.endTime,
|
|
30
|
+
feeBps: 0,
|
|
31
|
+
customer: null,
|
|
32
|
+
mint: new web3_js_1.PublicKey('2222222222222222222222222222222222222222')
|
|
33
|
+
});
|
|
34
|
+
if (market.image) {
|
|
35
|
+
yield this.deployImage(market.image);
|
|
36
|
+
}
|
|
37
|
+
console.log(`Initialized market ${market.question}:`, response);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`Error initializing market ${market.question}:`, error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.deployImage = (image) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const TRIAD_STORAGE_ACCOUNT = new web3_js_1.PublicKey('8Tp66VQmgHXQfd8ui2VZHPLZfkKu8mMwywmRsnVfTRBm');
|
|
46
|
+
const drive = yield new sdk_1.ShdwDrive(this.triadProtocol.provider.connection, this.triadProtocol.provider.wallet).init();
|
|
47
|
+
const jsonFile = {
|
|
48
|
+
name: `${image}`,
|
|
49
|
+
file: fs_1.default.readFileSync(`./src/${image}`)
|
|
50
|
+
};
|
|
51
|
+
const file = yield drive.uploadFile(TRIAD_STORAGE_ACCOUNT, jsonFile);
|
|
52
|
+
console.log(file);
|
|
53
|
+
return file;
|
|
54
|
+
});
|
|
55
|
+
this.triadProtocol = triadProtocol;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.InitMarket = InitMarket;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrderBook = void 0;
|
|
4
|
+
class OrderBook {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.bids = [];
|
|
7
|
+
this.asks = [];
|
|
8
|
+
this.bids = []; // Lista de compras (bids)
|
|
9
|
+
this.asks = []; // Lista de vendas (asks)
|
|
10
|
+
}
|
|
11
|
+
addBid(price, quantity) {
|
|
12
|
+
this.bids.push({ price, quantity });
|
|
13
|
+
this.bids.sort((a, b) => b.price - a.price);
|
|
14
|
+
this.matchOrders();
|
|
15
|
+
}
|
|
16
|
+
addAsk(price, quantity) {
|
|
17
|
+
this.asks.push({ price, quantity });
|
|
18
|
+
this.asks.sort((a, b) => a.price - b.price);
|
|
19
|
+
this.matchOrders();
|
|
20
|
+
}
|
|
21
|
+
matchOrders() {
|
|
22
|
+
while (this.bids.length > 0 && this.asks.length > 0) {
|
|
23
|
+
let highestBid = this.bids[0];
|
|
24
|
+
let lowestAsk = this.asks[0];
|
|
25
|
+
if (highestBid.price >= lowestAsk.price) {
|
|
26
|
+
let tradeQuantity = Math.min(highestBid.quantity, lowestAsk.quantity);
|
|
27
|
+
console.log(`š„ Trade Executado: ${tradeQuantity} unidades a ${lowestAsk.price}`);
|
|
28
|
+
highestBid.quantity -= tradeQuantity;
|
|
29
|
+
lowestAsk.quantity -= tradeQuantity;
|
|
30
|
+
if (highestBid.quantity === 0)
|
|
31
|
+
this.bids.shift();
|
|
32
|
+
if (lowestAsk.quantity === 0)
|
|
33
|
+
this.asks.shift();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
printOrderBook() {
|
|
41
|
+
console.log('\nš ORDER BOOK:');
|
|
42
|
+
console.log('BIDS (Compradores):', this.bids);
|
|
43
|
+
console.log('ASKS (Vendedores):', this.asks);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.OrderBook = OrderBook;
|
package/dist/trade.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ export default class Trade {
|
|
|
130
130
|
* @param options - RPC options
|
|
131
131
|
*
|
|
132
132
|
*/
|
|
133
|
-
createMarket({ marketId, startTime, endTime, question, feeBps, customer, }: CreateMarketArgs, options?: RpcOptions): Promise<string>;
|
|
133
|
+
createMarket({ marketId, startTime, endTime, question, feeBps, customer, mint }: CreateMarketArgs, options?: RpcOptions): Promise<string>;
|
|
134
134
|
/**
|
|
135
135
|
* Get User Trade Nonce With Slots
|
|
136
136
|
* @param userTrades - User Trades
|
|
@@ -199,10 +199,11 @@ export default class Trade {
|
|
|
199
199
|
* @param options - RPC options
|
|
200
200
|
*
|
|
201
201
|
*/
|
|
202
|
-
payoutOrder({ marketId, orderId, userNonce }: {
|
|
202
|
+
payoutOrder({ marketId, orderId, userNonce, mint }: {
|
|
203
203
|
marketId: number;
|
|
204
204
|
orderId: number;
|
|
205
205
|
userNonce: number;
|
|
206
|
+
mint: PublicKey;
|
|
206
207
|
}, options?: RpcOptions): Promise<string>;
|
|
207
208
|
/**
|
|
208
209
|
* Allow Market to Payout
|
package/dist/trade.js
CHANGED
|
@@ -114,7 +114,7 @@ class Trade {
|
|
|
114
114
|
* @param options - RPC options
|
|
115
115
|
*
|
|
116
116
|
*/
|
|
117
|
-
createMarket({ marketId, startTime, endTime, question, feeBps, customer, }, options) {
|
|
117
|
+
createMarket({ marketId, startTime, endTime, question, feeBps, customer, mint }, options) {
|
|
118
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
119
|
if (question.length > 80) {
|
|
120
120
|
throw new Error('Question must be less than 80 characters');
|
|
@@ -129,8 +129,8 @@ class Trade {
|
|
|
129
129
|
})
|
|
130
130
|
.accounts({
|
|
131
131
|
signer: this.provider.publicKey,
|
|
132
|
-
mint
|
|
133
|
-
tokenProgram: (0, helpers_1.getTokenProgram)(
|
|
132
|
+
mint,
|
|
133
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint),
|
|
134
134
|
customer
|
|
135
135
|
}), options);
|
|
136
136
|
});
|
|
@@ -296,10 +296,14 @@ class Trade {
|
|
|
296
296
|
collectRemainingLiquidity(marketId, options) {
|
|
297
297
|
return __awaiter(this, void 0, void 0, function* () {
|
|
298
298
|
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
299
|
+
const market = yield this.getMarketByAddress(marketPDA);
|
|
300
|
+
if (market.isAllowedToPayout) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
299
303
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods.collectRemainingLiquidity().accounts({
|
|
300
304
|
signer: this.provider.publicKey,
|
|
301
305
|
market: marketPDA,
|
|
302
|
-
mint:
|
|
306
|
+
mint: market.mint
|
|
303
307
|
}), options);
|
|
304
308
|
});
|
|
305
309
|
}
|
|
@@ -312,7 +316,7 @@ class Trade {
|
|
|
312
316
|
* @param options - RPC options
|
|
313
317
|
*
|
|
314
318
|
*/
|
|
315
|
-
payoutOrder({ marketId, orderId, userNonce }, options) {
|
|
319
|
+
payoutOrder({ marketId, orderId, userNonce, mint }, options) {
|
|
316
320
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
321
|
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
318
322
|
let userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
@@ -324,7 +328,7 @@ class Trade {
|
|
|
324
328
|
signer: this.provider.publicKey,
|
|
325
329
|
userTrade: userTradePDA,
|
|
326
330
|
market: marketPDA,
|
|
327
|
-
mint
|
|
331
|
+
mint
|
|
328
332
|
}), options);
|
|
329
333
|
});
|
|
330
334
|
}
|
package/dist/types/trade.d.ts
CHANGED