@triadxyz/triad-protocol 1.2.9-beta → 1.3.1-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.js +9 -3
- package/dist/local-test.js +64 -68
- package/dist/stake.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -176,7 +176,8 @@ class TriadProtocolClient {
|
|
|
176
176
|
const userNftAta = (0, pda_1.getTokenATA)(this.provider.wallet.publicKey, nftMint);
|
|
177
177
|
const collectionSymbol = 'PTCKT';
|
|
178
178
|
const [collection] = yield this.program.account.collection.all();
|
|
179
|
-
const
|
|
179
|
+
const ixs = [];
|
|
180
|
+
ixs.push(yield this.program.methods
|
|
180
181
|
.mintTicket({
|
|
181
182
|
number: new anchor_1.BN(collection.account.minted),
|
|
182
183
|
collectionSymbol,
|
|
@@ -193,8 +194,13 @@ class TriadProtocolClient {
|
|
|
193
194
|
verifier: constants_1.VERIFIER,
|
|
194
195
|
coreCollection: constants_1.TICKET_CORE_COLLECTION
|
|
195
196
|
})
|
|
196
|
-
.instruction();
|
|
197
|
-
|
|
197
|
+
.instruction());
|
|
198
|
+
ixs.push(web3_js_1.SystemProgram.transfer({
|
|
199
|
+
fromPubkey: this.provider.wallet.publicKey,
|
|
200
|
+
toPubkey: new web3_js_1.PublicKey('6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq'),
|
|
201
|
+
lamports: 100000000
|
|
202
|
+
}));
|
|
203
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, asset, [], (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)(verifier));
|
|
198
204
|
});
|
|
199
205
|
}
|
|
200
206
|
}
|
package/dist/local-test.js
CHANGED
|
@@ -17,19 +17,19 @@ const _1 = __importDefault(require("./"));
|
|
|
17
17
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
19
|
const spl_token_1 = require("@solana/spl-token");
|
|
20
|
+
const constants_1 = require("./utils/constants");
|
|
20
21
|
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/triad.json');
|
|
21
22
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
22
23
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
23
24
|
const connection = new web3_js_1.Connection(rpc_file.toString());
|
|
24
25
|
const wallet = new anchor_1.Wallet(keypair);
|
|
25
26
|
const triadProtocol = new _1.default(connection, wallet);
|
|
26
|
-
const mint = new web3_js_1.PublicKey('X41iRJUPkKaEvhqWdxqrS5P7M5d8A9oathki5sT47KR');
|
|
27
27
|
const markets = [
|
|
28
28
|
{
|
|
29
|
-
marketId:
|
|
30
|
-
question: 'Will $
|
|
31
|
-
startTime:
|
|
32
|
-
endTime:
|
|
29
|
+
marketId: 37,
|
|
30
|
+
question: 'Will $STREAM price be above $1 on December 17?',
|
|
31
|
+
startTime: 1733940000,
|
|
32
|
+
endTime: 1734404340
|
|
33
33
|
}
|
|
34
34
|
];
|
|
35
35
|
const ordersHypeAndFloopBot = [
|
|
@@ -44,7 +44,7 @@ const ordersHypeAndFloopBot = [
|
|
|
44
44
|
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
45
|
const response = yield triadProtocol.stake.updateStakeVault({
|
|
46
46
|
wallet: wallet.publicKey,
|
|
47
|
-
amount: new anchor_1.BN(
|
|
47
|
+
amount: new anchor_1.BN(2000 * Math.pow(10, 6)),
|
|
48
48
|
isLocked: false
|
|
49
49
|
});
|
|
50
50
|
console.log(response);
|
|
@@ -54,9 +54,7 @@ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
54
54
|
console.log(response);
|
|
55
55
|
});
|
|
56
56
|
const getStaked = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
const user = yield triadProtocol.getUser(new web3_js_1.PublicKey('3umHQwkz2r8E6K6xWJuSDziDoWgkWwRckDPGEYzD8TPf'));
|
|
58
57
|
const response = yield triadProtocol.stake.getUserStakes(new web3_js_1.PublicKey('3umHQwkz2r8E6K6xWJuSDziDoWgkWwRckDPGEYzD8TPf'));
|
|
59
|
-
console.log(user);
|
|
60
58
|
console.log(response);
|
|
61
59
|
});
|
|
62
60
|
const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -64,7 +62,7 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
64
62
|
console.log(markets);
|
|
65
63
|
});
|
|
66
64
|
const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
-
const market = yield triadProtocol.trade.getMarketById(
|
|
65
|
+
const market = yield triadProtocol.trade.getMarketById(9);
|
|
68
66
|
console.log(market);
|
|
69
67
|
});
|
|
70
68
|
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -107,6 +105,9 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
107
105
|
const liquidityToRecovery = {};
|
|
108
106
|
for (const market of allMarkets) {
|
|
109
107
|
let currentMarket = liquidityToRecovery[market.marketId];
|
|
108
|
+
if (market.winningDirection.toLowerCase() === 'none') {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
110
111
|
if (!currentMarket) {
|
|
111
112
|
currentMarket = {
|
|
112
113
|
address: market.address,
|
|
@@ -114,6 +115,9 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
114
115
|
liquidityToPay: 0,
|
|
115
116
|
sharesToPay: 0,
|
|
116
117
|
openOrders: 0,
|
|
118
|
+
amountInPDA: 0,
|
|
119
|
+
amountToPay: 0,
|
|
120
|
+
liquidityCoeficient: 0,
|
|
117
121
|
direction: market.winningDirection.toLowerCase() === 'flop'
|
|
118
122
|
? { flop: {} }
|
|
119
123
|
: { hype: {} },
|
|
@@ -125,18 +129,33 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
125
129
|
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
126
130
|
currentMarket.totalLiquidity +=
|
|
127
131
|
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
132
|
+
const marketLiquidityAtStart = parseFloat(market.marketLiquidityAtStart.toString()) / Math.pow(10, 6);
|
|
133
|
+
currentMarket.totalLiquidity -= marketLiquidityAtStart;
|
|
134
|
+
let liquidity_coeficient = 1;
|
|
128
135
|
if ('flop' in currentMarket.direction) {
|
|
129
136
|
let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
|
|
130
|
-
currentMarket.sharesToPay = shares;
|
|
137
|
+
currentMarket.sharesToPay = shares + 10000;
|
|
131
138
|
currentMarket.liquidityToPay =
|
|
132
139
|
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
140
|
+
currentMarket.liquidityToPay =
|
|
141
|
+
currentMarket.liquidityToPay - marketLiquidityAtStart / 2;
|
|
133
142
|
}
|
|
134
143
|
else {
|
|
135
144
|
let shares = parseFloat(market.hypeShares.toString()) / Math.pow(10, 6);
|
|
136
|
-
currentMarket.sharesToPay = shares;
|
|
145
|
+
currentMarket.sharesToPay = shares + 10000;
|
|
137
146
|
currentMarket.liquidityToPay =
|
|
138
147
|
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
148
|
+
currentMarket.liquidityToPay =
|
|
149
|
+
currentMarket.liquidityToPay - marketLiquidityAtStart / 2;
|
|
150
|
+
}
|
|
151
|
+
if (currentMarket.sharesToPay > currentMarket.totalLiquidity) {
|
|
152
|
+
liquidity_coeficient =
|
|
153
|
+
currentMarket.totalLiquidity / currentMarket.sharesToPay;
|
|
139
154
|
}
|
|
155
|
+
currentMarket.liquidityCoeficient = liquidity_coeficient;
|
|
156
|
+
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);
|
|
157
|
+
const account = yield (0, spl_token_1.getAccount)(connection, token, 'finalized', spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
158
|
+
currentMarket.amountInPDA = Number(account.amount) / Math.pow(10, 6);
|
|
140
159
|
}
|
|
141
160
|
for (const userTrade of response) {
|
|
142
161
|
for (const order of userTrade.account.orders) {
|
|
@@ -144,35 +163,32 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
144
163
|
if (!market) {
|
|
145
164
|
continue;
|
|
146
165
|
}
|
|
147
|
-
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0]
|
|
166
|
+
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0] &&
|
|
167
|
+
order.status.open) {
|
|
148
168
|
market.openOrders += 1;
|
|
169
|
+
const sharesRatio = parseFloat(order.totalShares.toString()) / market.sharesToPay;
|
|
170
|
+
const additionalPayout = Math.round(sharesRatio * market.liquidityToPay);
|
|
171
|
+
let payout = additionalPayout + parseFloat(order.totalAmount.toString());
|
|
172
|
+
if (payout > parseFloat(order.totalShares.toString())) {
|
|
173
|
+
payout = parseFloat(order.totalShares.toString());
|
|
174
|
+
}
|
|
175
|
+
payout = payout;
|
|
176
|
+
market.amountToPay += payout / Math.pow(10, 6);
|
|
149
177
|
}
|
|
150
178
|
}
|
|
151
179
|
}
|
|
152
|
-
console.log(liquidityToRecovery);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
amount: order.amount,
|
|
161
|
-
direction: order.direction,
|
|
162
|
-
token: mint.toBase58(),
|
|
163
|
-
comment: `hype/flop bot ${order.amount} - ${order.direction}`
|
|
164
|
-
});
|
|
165
|
-
console.log(response);
|
|
180
|
+
console.log(JSON.stringify(liquidityToRecovery, null, 2));
|
|
181
|
+
let amountAllowToWithdraw = 0;
|
|
182
|
+
let amountToPay = 0;
|
|
183
|
+
let amountInPDA = 0;
|
|
184
|
+
for (const market of Object.values(liquidityToRecovery)) {
|
|
185
|
+
amountAllowToWithdraw += market.amountInPDA - market.amountToPay;
|
|
186
|
+
amountToPay += market.amountToPay;
|
|
187
|
+
amountInPDA += market.amountInPDA;
|
|
166
188
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const closeOrder = (orderId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
171
|
-
const response = yield triadProtocol.trade.closeOrder({
|
|
172
|
-
marketId: 7,
|
|
173
|
-
orderId: orderId
|
|
174
|
-
});
|
|
175
|
-
console.log(response);
|
|
189
|
+
console.log('Amount allow to withdraw:', amountAllowToWithdraw);
|
|
190
|
+
console.log('Amount to pay:', amountToPay);
|
|
191
|
+
console.log('Amount in PDA:', amountInPDA);
|
|
176
192
|
});
|
|
177
193
|
const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
194
|
for (const order of yield getOrders(wallet.publicKey)) {
|
|
@@ -188,26 +204,8 @@ const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
188
204
|
}
|
|
189
205
|
}
|
|
190
206
|
});
|
|
191
|
-
const mintTokens = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
-
// const mint = await createMint(
|
|
193
|
-
// connection,
|
|
194
|
-
// keypair,
|
|
195
|
-
// keypair.publicKey,
|
|
196
|
-
// null,
|
|
197
|
-
// 6,
|
|
198
|
-
// undefined,
|
|
199
|
-
// undefined,
|
|
200
|
-
// TOKEN_2022_PROGRAM_ID
|
|
201
|
-
// )
|
|
202
|
-
// console.log(mint)
|
|
203
|
-
const ataAddress = yield (0, spl_token_1.getAssociatedTokenAddress)(keypair.publicKey, mint);
|
|
204
|
-
console.log(ataAddress);
|
|
205
|
-
const ata = yield (0, spl_token_1.createAssociatedTokenAccount)(connection, keypair, mint, keypair.publicKey, undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
206
|
-
const mintTx = yield (0, spl_token_1.mintTo)(connection, keypair, mint, ata, keypair, 1000000 * Math.pow(10, 6), [keypair], undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
207
|
-
console.log(mintTx);
|
|
208
|
-
});
|
|
209
207
|
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
-
const marketsToResolve = [{ marketId:
|
|
208
|
+
const marketsToResolve = [{ marketId: 33, winningDirection: { flop: {} } }];
|
|
211
209
|
for (const market of marketsToResolve) {
|
|
212
210
|
const response = yield triadProtocol.trade.resolveMarket({
|
|
213
211
|
marketId: market.marketId,
|
|
@@ -218,6 +216,7 @@ const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
218
216
|
console.log(response);
|
|
219
217
|
}
|
|
220
218
|
});
|
|
219
|
+
resolveMarket();
|
|
221
220
|
const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
221
|
const response = yield triadProtocol.trade.addLiquidity({
|
|
223
222
|
marketId: 5,
|
|
@@ -231,7 +230,6 @@ const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
231
230
|
const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
231
|
console.log('Collecting fees');
|
|
233
232
|
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
234
|
-
let currentFees = {};
|
|
235
233
|
for (const market of allMarkets) {
|
|
236
234
|
console.log(`Collecting fees for market ${market.marketId}`);
|
|
237
235
|
try {
|
|
@@ -239,8 +237,7 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
239
237
|
marketId: Number(market.marketId),
|
|
240
238
|
vault: new web3_js_1.PublicKey('Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4')
|
|
241
239
|
}, {
|
|
242
|
-
microLamports:
|
|
243
|
-
skipPreflight: true
|
|
240
|
+
microLamports: 32000
|
|
244
241
|
});
|
|
245
242
|
console.log(response);
|
|
246
243
|
}
|
|
@@ -249,16 +246,15 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
249
246
|
}
|
|
250
247
|
}
|
|
251
248
|
});
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
249
|
+
const burnLP = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
|
+
const SOL_LP = new web3_js_1.PublicKey('8yXmXEQh8M1vyjKKhN6L12EZiXCY3cJS4xL45wwQExep');
|
|
251
|
+
const getTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(SOL_LP, wallet.publicKey, true);
|
|
252
|
+
console.log(getTokenAccount);
|
|
253
|
+
const amount = 191.360098123 * Math.pow(10, 9);
|
|
254
|
+
const response = yield (0, spl_token_1.burn)(connection, keypair, getTokenAccount, SOL_LP, wallet.publicKey, amount);
|
|
255
|
+
console.log(response);
|
|
256
|
+
});
|
|
257
|
+
const getReferral = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
const response = yield triadProtocol.getUser(new web3_js_1.PublicKey('in6cFcFF2eawkdtrGvV4mM33dRhBymJcf1Fk8mrqGJt'));
|
|
263
259
|
console.log(response);
|
|
264
260
|
});
|
package/dist/stake.js
CHANGED
|
@@ -97,13 +97,13 @@ class Stake {
|
|
|
97
97
|
const response = yield this.getUserStakes(wallet);
|
|
98
98
|
const data = [];
|
|
99
99
|
for (const stake of response) {
|
|
100
|
-
|
|
100
|
+
yield new Promise((resolve) => setTimeout(resolve, 5000));
|
|
101
101
|
let available = 0;
|
|
102
102
|
try {
|
|
103
103
|
available = yield this.getStakeRewards({
|
|
104
104
|
wallet,
|
|
105
105
|
nftName: stake.name,
|
|
106
|
-
rank,
|
|
106
|
+
rank: 963,
|
|
107
107
|
collections
|
|
108
108
|
});
|
|
109
109
|
}
|