@triadxyz/triad-protocol 1.2.8-beta → 1.3.0-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 +90 -69
- package/dist/stake.js +3 -1
- package/dist/types/idl_triad_protocol.json +4 -0
- package/dist/types/triad_protocol.d.ts +4 -0
- 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,49 @@ 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
|
-
const connection = new web3_js_1.Connection(
|
|
24
|
+
const connection = new web3_js_1.Connection("");
|
|
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: 31,
|
|
30
|
+
question: 'Will $ETH hit new ATH before 2025?',
|
|
31
|
+
startTime: 1733508000,
|
|
32
|
+
endTime: 1735603200
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
marketId: 32,
|
|
36
|
+
question: 'Will $ME price be above $3.20 on December 11?',
|
|
37
|
+
startTime: 1733508000,
|
|
38
|
+
endTime: 1733788800
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
marketId: 33,
|
|
42
|
+
question: 'Will $SOL be above $245.00 on December 12?',
|
|
43
|
+
startTime: 1733508000,
|
|
44
|
+
endTime: 1733875200
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
marketId: 34,
|
|
48
|
+
question: 'Will $SOL flip $XRP again in 2024?',
|
|
49
|
+
startTime: 1733508000,
|
|
50
|
+
endTime: 1735603200
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
marketId: 35,
|
|
54
|
+
question: 'Will $XRP be above $USDT in MKC on December 31?',
|
|
55
|
+
startTime: 1733508000,
|
|
56
|
+
endTime: 1735603200
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
marketId: 36,
|
|
60
|
+
question: 'Will DOGE be above $0.45 on December 12?',
|
|
61
|
+
startTime: 1733508000,
|
|
62
|
+
endTime: 1733875200
|
|
33
63
|
}
|
|
34
64
|
];
|
|
35
65
|
const ordersHypeAndFloopBot = [
|
|
@@ -44,7 +74,7 @@ const ordersHypeAndFloopBot = [
|
|
|
44
74
|
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
75
|
const response = yield triadProtocol.stake.updateStakeVault({
|
|
46
76
|
wallet: wallet.publicKey,
|
|
47
|
-
amount: new anchor_1.BN(
|
|
77
|
+
amount: new anchor_1.BN(2000 * Math.pow(10, 6)),
|
|
48
78
|
isLocked: false
|
|
49
79
|
});
|
|
50
80
|
console.log(response);
|
|
@@ -54,9 +84,7 @@ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
54
84
|
console.log(response);
|
|
55
85
|
});
|
|
56
86
|
const getStaked = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
const user = yield triadProtocol.getUser(new web3_js_1.PublicKey('3umHQwkz2r8E6K6xWJuSDziDoWgkWwRckDPGEYzD8TPf'));
|
|
58
87
|
const response = yield triadProtocol.stake.getUserStakes(new web3_js_1.PublicKey('3umHQwkz2r8E6K6xWJuSDziDoWgkWwRckDPGEYzD8TPf'));
|
|
59
|
-
console.log(user);
|
|
60
88
|
console.log(response);
|
|
61
89
|
});
|
|
62
90
|
const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -64,7 +92,7 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
64
92
|
console.log(markets);
|
|
65
93
|
});
|
|
66
94
|
const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
-
const market = yield triadProtocol.trade.getMarketById(
|
|
95
|
+
const market = yield triadProtocol.trade.getMarketById(9);
|
|
68
96
|
console.log(market);
|
|
69
97
|
});
|
|
70
98
|
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -107,6 +135,9 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
107
135
|
const liquidityToRecovery = {};
|
|
108
136
|
for (const market of allMarkets) {
|
|
109
137
|
let currentMarket = liquidityToRecovery[market.marketId];
|
|
138
|
+
if (market.winningDirection.toLowerCase() === 'none') {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
110
141
|
if (!currentMarket) {
|
|
111
142
|
currentMarket = {
|
|
112
143
|
address: market.address,
|
|
@@ -114,6 +145,9 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
114
145
|
liquidityToPay: 0,
|
|
115
146
|
sharesToPay: 0,
|
|
116
147
|
openOrders: 0,
|
|
148
|
+
amountInPDA: 0,
|
|
149
|
+
amountToPay: 0,
|
|
150
|
+
liquidityCoeficient: 0,
|
|
117
151
|
direction: market.winningDirection.toLowerCase() === 'flop'
|
|
118
152
|
? { flop: {} }
|
|
119
153
|
: { hype: {} },
|
|
@@ -125,18 +159,33 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
125
159
|
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
126
160
|
currentMarket.totalLiquidity +=
|
|
127
161
|
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
162
|
+
const marketLiquidityAtStart = parseFloat(market.marketLiquidityAtStart.toString()) / Math.pow(10, 6);
|
|
163
|
+
currentMarket.totalLiquidity -= marketLiquidityAtStart;
|
|
164
|
+
let liquidity_coeficient = 1;
|
|
128
165
|
if ('flop' in currentMarket.direction) {
|
|
129
166
|
let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
|
|
130
|
-
currentMarket.sharesToPay = shares;
|
|
167
|
+
currentMarket.sharesToPay = shares + 10000;
|
|
131
168
|
currentMarket.liquidityToPay =
|
|
132
169
|
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
170
|
+
currentMarket.liquidityToPay =
|
|
171
|
+
currentMarket.liquidityToPay - marketLiquidityAtStart / 2;
|
|
133
172
|
}
|
|
134
173
|
else {
|
|
135
174
|
let shares = parseFloat(market.hypeShares.toString()) / Math.pow(10, 6);
|
|
136
|
-
currentMarket.sharesToPay = shares;
|
|
175
|
+
currentMarket.sharesToPay = shares + 10000;
|
|
137
176
|
currentMarket.liquidityToPay =
|
|
138
177
|
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
178
|
+
currentMarket.liquidityToPay =
|
|
179
|
+
currentMarket.liquidityToPay - marketLiquidityAtStart / 2;
|
|
180
|
+
}
|
|
181
|
+
if (currentMarket.sharesToPay > currentMarket.totalLiquidity) {
|
|
182
|
+
liquidity_coeficient =
|
|
183
|
+
currentMarket.totalLiquidity / currentMarket.sharesToPay;
|
|
139
184
|
}
|
|
185
|
+
currentMarket.liquidityCoeficient = liquidity_coeficient;
|
|
186
|
+
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);
|
|
187
|
+
const account = yield (0, spl_token_1.getAccount)(connection, token, 'finalized', spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
188
|
+
currentMarket.amountInPDA = Number(account.amount) / Math.pow(10, 6);
|
|
140
189
|
}
|
|
141
190
|
for (const userTrade of response) {
|
|
142
191
|
for (const order of userTrade.account.orders) {
|
|
@@ -144,35 +193,32 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
144
193
|
if (!market) {
|
|
145
194
|
continue;
|
|
146
195
|
}
|
|
147
|
-
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0]
|
|
196
|
+
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0] &&
|
|
197
|
+
order.status.open) {
|
|
148
198
|
market.openOrders += 1;
|
|
199
|
+
const sharesRatio = parseFloat(order.totalShares.toString()) / market.sharesToPay;
|
|
200
|
+
const additionalPayout = Math.round(sharesRatio * market.liquidityToPay);
|
|
201
|
+
let payout = additionalPayout + parseFloat(order.totalAmount.toString());
|
|
202
|
+
if (payout > parseFloat(order.totalShares.toString())) {
|
|
203
|
+
payout = parseFloat(order.totalShares.toString());
|
|
204
|
+
}
|
|
205
|
+
payout = payout;
|
|
206
|
+
market.amountToPay += payout / Math.pow(10, 6);
|
|
149
207
|
}
|
|
150
208
|
}
|
|
151
209
|
}
|
|
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);
|
|
210
|
+
console.log(JSON.stringify(liquidityToRecovery, null, 2));
|
|
211
|
+
let amountAllowToWithdraw = 0;
|
|
212
|
+
let amountToPay = 0;
|
|
213
|
+
let amountInPDA = 0;
|
|
214
|
+
for (const market of Object.values(liquidityToRecovery)) {
|
|
215
|
+
amountAllowToWithdraw += market.amountInPDA - market.amountToPay;
|
|
216
|
+
amountToPay += market.amountToPay;
|
|
217
|
+
amountInPDA += market.amountInPDA;
|
|
166
218
|
}
|
|
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);
|
|
219
|
+
console.log('Amount allow to withdraw:', amountAllowToWithdraw);
|
|
220
|
+
console.log('Amount to pay:', amountToPay);
|
|
221
|
+
console.log('Amount in PDA:', amountInPDA);
|
|
176
222
|
});
|
|
177
223
|
const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
224
|
for (const order of yield getOrders(wallet.publicKey)) {
|
|
@@ -188,26 +234,8 @@ const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
188
234
|
}
|
|
189
235
|
}
|
|
190
236
|
});
|
|
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
237
|
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
-
const marketsToResolve = [{ marketId:
|
|
238
|
+
const marketsToResolve = [{ marketId: 32, winningDirection: { hype: {} } }];
|
|
211
239
|
for (const market of marketsToResolve) {
|
|
212
240
|
const response = yield triadProtocol.trade.resolveMarket({
|
|
213
241
|
marketId: market.marketId,
|
|
@@ -231,7 +259,6 @@ const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
231
259
|
const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
260
|
console.log('Collecting fees');
|
|
233
261
|
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
234
|
-
let currentFees = {};
|
|
235
262
|
for (const market of allMarkets) {
|
|
236
263
|
console.log(`Collecting fees for market ${market.marketId}`);
|
|
237
264
|
try {
|
|
@@ -239,8 +266,7 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
239
266
|
marketId: Number(market.marketId),
|
|
240
267
|
vault: new web3_js_1.PublicKey('Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4')
|
|
241
268
|
}, {
|
|
242
|
-
microLamports:
|
|
243
|
-
skipPreflight: true
|
|
269
|
+
microLamports: 32000
|
|
244
270
|
});
|
|
245
271
|
console.log(response);
|
|
246
272
|
}
|
|
@@ -249,16 +275,11 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
249
275
|
}
|
|
250
276
|
}
|
|
251
277
|
});
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
verifier: '43bkRb3xj4Vv77Y76TjQuNiPGUsnun4tFSMYXY2Y2K5LfRT79YDpHhc7jruWmDGdygUBPXYQQZntCQz6V6cRGz8F',
|
|
259
|
-
nftMint: new web3_js_1.PublicKey('A5dk1WqN9qcq1ZaWEh1UaMJR3SQeAsMirEEnLWbpp6fu')
|
|
260
|
-
}, {
|
|
261
|
-
skipPreflight: true
|
|
262
|
-
});
|
|
278
|
+
const burnLP = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
279
|
+
const SOL_LP = new web3_js_1.PublicKey('8yXmXEQh8M1vyjKKhN6L12EZiXCY3cJS4xL45wwQExep');
|
|
280
|
+
const getTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(SOL_LP, wallet.publicKey, true);
|
|
281
|
+
console.log(getTokenAccount);
|
|
282
|
+
const amount = 191.360098123 * Math.pow(10, 9);
|
|
283
|
+
const response = yield (0, spl_token_1.burn)(connection, keypair, getTokenAccount, SOL_LP, wallet.publicKey, amount);
|
|
263
284
|
console.log(response);
|
|
264
285
|
});
|
package/dist/stake.js
CHANGED
|
@@ -166,6 +166,7 @@ class Stake {
|
|
|
166
166
|
requestWithdraw({ wallet, nfts }, options) {
|
|
167
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
168
168
|
const ixs = [];
|
|
169
|
+
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
169
170
|
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, wallet);
|
|
170
171
|
for (const nft of nfts) {
|
|
171
172
|
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, nft.name);
|
|
@@ -175,7 +176,8 @@ class Stake {
|
|
|
175
176
|
signer: wallet,
|
|
176
177
|
mint: nft.mint,
|
|
177
178
|
user: userPDA,
|
|
178
|
-
stake: stakePDA
|
|
179
|
+
stake: stakePDA,
|
|
180
|
+
stakeVault: stakeVaultPDA
|
|
179
181
|
})
|
|
180
182
|
.instruction());
|
|
181
183
|
}
|