@triadxyz/triad-protocol 1.2.3-beta → 1.2.6-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 +16 -10
- package/dist/index.js +45 -0
- package/dist/local-test.js +36 -9
- package/dist/trade.d.ts +12 -0
- package/dist/trade.js +20 -0
- package/dist/types/idl_triad_protocol.json +505 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/trade.d.ts +1 -0
- package/dist/types/triad_protocol.d.ts +592 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +2 -1
- package/dist/utils/helpers.js +6 -2
- package/dist/utils/jup-swap.js +1 -1
- package/dist/utils/sendVersionedTransaction.d.ts +1 -1
- package/dist/utils/sendVersionedTransaction.js +8 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
2
|
+
import { AnchorProvider, BN, Program, Wallet } from '@coral-xyz/anchor';
|
|
3
3
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { TriadProtocol } from './types/triad_protocol';
|
|
5
5
|
import Trade from './trade';
|
|
6
6
|
import Stake from './stake';
|
|
7
|
-
import { CreateUserArgs, RpcOptions } from './types';
|
|
7
|
+
import { CreateUserArgs, MintTicketArgs, RpcOptions } from './types';
|
|
8
8
|
export default class TriadProtocolClient {
|
|
9
9
|
program: Program<TriadProtocol>;
|
|
10
10
|
provider: AnchorProvider;
|
|
@@ -51,21 +51,21 @@ export default class TriadProtocolClient {
|
|
|
51
51
|
*
|
|
52
52
|
*/
|
|
53
53
|
getUserPositionsWithAmount(wallet: PublicKey): Promise<{
|
|
54
|
-
ts:
|
|
54
|
+
ts: BN;
|
|
55
55
|
bump: number;
|
|
56
|
-
totalDeposited:
|
|
57
|
-
totalWithdrawn:
|
|
58
|
-
lpShare:
|
|
56
|
+
totalDeposited: BN;
|
|
57
|
+
totalWithdrawn: BN;
|
|
58
|
+
lpShare: BN;
|
|
59
59
|
totalPositions: number;
|
|
60
60
|
ticker: PublicKey;
|
|
61
61
|
authority: PublicKey;
|
|
62
62
|
positions: {
|
|
63
|
-
amount:
|
|
64
|
-
entryPrice:
|
|
65
|
-
ts:
|
|
63
|
+
amount: BN;
|
|
64
|
+
entryPrice: BN;
|
|
65
|
+
ts: BN;
|
|
66
66
|
isLong: boolean;
|
|
67
67
|
isOpen: boolean;
|
|
68
|
-
pnl:
|
|
68
|
+
pnl: BN;
|
|
69
69
|
}[];
|
|
70
70
|
}[]>;
|
|
71
71
|
withdrawV1({ wallet, ticker, positionIndex }: {
|
|
@@ -73,4 +73,10 @@ export default class TriadProtocolClient {
|
|
|
73
73
|
ticker: PublicKey;
|
|
74
74
|
positionIndex: number;
|
|
75
75
|
}, options?: RpcOptions): Promise<any>;
|
|
76
|
+
createCollection(args: {
|
|
77
|
+
collectionName: string;
|
|
78
|
+
collectionSymbol: string;
|
|
79
|
+
supply: number;
|
|
80
|
+
}, options?: RpcOptions): Promise<string>;
|
|
81
|
+
mintTicket({ collectionSymbol, number, discount, isBoosted, rarity, verifier, nftMint }: MintTicketArgs, options?: RpcOptions): Promise<string>;
|
|
76
82
|
}
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,9 @@ const pda_1 = require("./utils/pda");
|
|
|
22
22
|
const stake_1 = __importDefault(require("./stake"));
|
|
23
23
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
24
24
|
const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
25
|
+
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
26
|
+
const constants_1 = require("./utils/constants");
|
|
27
|
+
const convertSecretKeyToKeypair_1 = require("./utils/convertSecretKeyToKeypair");
|
|
25
28
|
class TriadProtocolClient {
|
|
26
29
|
constructor(connection, wallet) {
|
|
27
30
|
this.provider = new anchor_1.AnchorProvider(connection, wallet, {
|
|
@@ -150,5 +153,47 @@ class TriadProtocolClient {
|
|
|
150
153
|
}), options);
|
|
151
154
|
});
|
|
152
155
|
}
|
|
156
|
+
createCollection(args, options) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
const keyPair = web3_js_1.Keypair.generate();
|
|
159
|
+
const ix = yield this.program.methods
|
|
160
|
+
.createCollection({
|
|
161
|
+
supply: new anchor_1.BN(args.supply),
|
|
162
|
+
name: args.collectionName,
|
|
163
|
+
symbol: args.collectionSymbol
|
|
164
|
+
})
|
|
165
|
+
.accounts({
|
|
166
|
+
signer: this.provider.wallet.publicKey,
|
|
167
|
+
coreCollection: keyPair.publicKey
|
|
168
|
+
})
|
|
169
|
+
.instruction();
|
|
170
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, keyPair);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
mintTicket({ collectionSymbol, number, discount, isBoosted, rarity, verifier, nftMint }, options) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const asset = web3_js_1.Keypair.generate();
|
|
176
|
+
const userNftAta = (0, pda_1.getTokenATA)(this.provider.wallet.publicKey, nftMint);
|
|
177
|
+
const ix = yield this.program.methods
|
|
178
|
+
.mintTicket({
|
|
179
|
+
number: new anchor_1.BN(number),
|
|
180
|
+
collectionSymbol,
|
|
181
|
+
discount: new anchor_1.BN(discount),
|
|
182
|
+
isBoosted,
|
|
183
|
+
rarity
|
|
184
|
+
})
|
|
185
|
+
.accounts({
|
|
186
|
+
signer: this.provider.wallet.publicKey,
|
|
187
|
+
asset: asset.publicKey,
|
|
188
|
+
nftMint,
|
|
189
|
+
userNftAta,
|
|
190
|
+
trdMint: constants_1.TRD_MINT,
|
|
191
|
+
verifier: constants_1.VERIFIER,
|
|
192
|
+
coreCollection: constants_1.TICKET_CORE_COLLECTION
|
|
193
|
+
})
|
|
194
|
+
.instruction();
|
|
195
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, asset, [], (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)(verifier));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
153
198
|
}
|
|
154
199
|
exports.default = TriadProtocolClient;
|
package/dist/local-test.js
CHANGED
|
@@ -25,7 +25,15 @@ const connection = new web3_js_1.Connection('https://triad-solanam-a5ee.mainnet.
|
|
|
25
25
|
const wallet = new anchor_1.Wallet(keypair);
|
|
26
26
|
const triadProtocol = new _1.default(connection, wallet);
|
|
27
27
|
const mint = new web3_js_1.PublicKey('X41iRJUPkKaEvhqWdxqrS5P7M5d8A9oathki5sT47KR');
|
|
28
|
-
const markets = [
|
|
28
|
+
const markets = [
|
|
29
|
+
{
|
|
30
|
+
marketId: 16,
|
|
31
|
+
name: 'MIKExJAKE',
|
|
32
|
+
question: 'Jake Paul vs. Mike Tyson: Who wins today?',
|
|
33
|
+
startTime: 1731682800,
|
|
34
|
+
endTime: 1731715200
|
|
35
|
+
}
|
|
36
|
+
];
|
|
29
37
|
const ordersHypeAndFloopBot = [
|
|
30
38
|
{
|
|
31
39
|
marketId: 7,
|
|
@@ -38,7 +46,7 @@ const ordersHypeAndFloopBot = [
|
|
|
38
46
|
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
47
|
const response = yield triadProtocol.stake.updateStakeVault({
|
|
40
48
|
wallet: wallet.publicKey,
|
|
41
|
-
amount: new anchor_1.BN(
|
|
49
|
+
amount: new anchor_1.BN(8000 * Math.pow(10, 6)),
|
|
42
50
|
isLocked: false
|
|
43
51
|
});
|
|
44
52
|
console.log(response);
|
|
@@ -96,7 +104,7 @@ const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function*
|
|
|
96
104
|
continue;
|
|
97
105
|
}
|
|
98
106
|
orders.push({
|
|
99
|
-
marketId: order.marketId,
|
|
107
|
+
marketId: order.marketId.toNumber(),
|
|
100
108
|
orderId: order.orderId.toNumber(),
|
|
101
109
|
totalShares: order.totalShares.toString(),
|
|
102
110
|
amount: order.totalAmount.toString(),
|
|
@@ -109,7 +117,6 @@ const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function*
|
|
|
109
117
|
console.log(orders);
|
|
110
118
|
return orders;
|
|
111
119
|
});
|
|
112
|
-
// getOrders(new PublicKey('HjJQdfTHgC3EBX3471w4st8BXbBmtbaMyCAXNgcUb7dq'))
|
|
113
120
|
const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
121
|
const response = yield triadProtocol.program.account.userTrade.all();
|
|
115
122
|
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
@@ -217,6 +224,9 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
217
224
|
};
|
|
218
225
|
for (const market of allMarkets) {
|
|
219
226
|
let currentMarket = liquidityToRecovery[market.marketId];
|
|
227
|
+
if (!currentMarket) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
220
230
|
if ('flop' in currentMarket.direction) {
|
|
221
231
|
let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
|
|
222
232
|
currentMarket.medPrice =
|
|
@@ -237,6 +247,9 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
237
247
|
for (const userTrade of response) {
|
|
238
248
|
for (const order of userTrade.account.orders) {
|
|
239
249
|
const market = liquidityToRecovery[order.marketId.toNumber()];
|
|
250
|
+
if (!market) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
240
253
|
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0]) {
|
|
241
254
|
market.openOrders += 1;
|
|
242
255
|
}
|
|
@@ -299,10 +312,7 @@ const mintTokens = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
299
312
|
console.log(mintTx);
|
|
300
313
|
});
|
|
301
314
|
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
|
-
const marketsToResolve = [
|
|
303
|
-
{ marketId: 8, winningDirection: { flop: {} } },
|
|
304
|
-
{ marketId: 9, winningDirection: { flop: {} } }
|
|
305
|
-
];
|
|
315
|
+
const marketsToResolve = [{ marketId: 16, winningDirection: { flop: {} } }];
|
|
306
316
|
for (const market of marketsToResolve) {
|
|
307
317
|
const response = yield triadProtocol.trade.resolveMarket({
|
|
308
318
|
marketId: market.marketId,
|
|
@@ -334,7 +344,8 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
334
344
|
marketId: Number(market.marketId),
|
|
335
345
|
vault: new web3_js_1.PublicKey('6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq')
|
|
336
346
|
}, {
|
|
337
|
-
microLamports:
|
|
347
|
+
microLamports: 90000,
|
|
348
|
+
skipPreflight: true
|
|
338
349
|
});
|
|
339
350
|
console.log(response);
|
|
340
351
|
}
|
|
@@ -344,3 +355,19 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
344
355
|
}
|
|
345
356
|
fs_1.default.writeFileSync(`fees-collected.json`, JSON.stringify(currentFees, null, 2));
|
|
346
357
|
});
|
|
358
|
+
const mintTicket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
359
|
+
console.log(wallet.publicKey.toBase58());
|
|
360
|
+
const response = yield triadProtocol.mintTicket({
|
|
361
|
+
number: 0,
|
|
362
|
+
collectionSymbol: 'PTCKT',
|
|
363
|
+
discount: 0,
|
|
364
|
+
isBoosted: false,
|
|
365
|
+
rarity: { uncommon: {} },
|
|
366
|
+
verifier: '43bkRb3xj4Vv77Y76TjQuNiPGUsnun4tFSMYXY2Y2K5LfRT79YDpHhc7jruWmDGdygUBPXYQQZntCQz6V6cRGz8F',
|
|
367
|
+
nftMint: new web3_js_1.PublicKey('A5dk1WqN9qcq1ZaWEh1UaMJR3SQeAsMirEEnLWbpp6fu')
|
|
368
|
+
}, {
|
|
369
|
+
skipPreflight: true
|
|
370
|
+
});
|
|
371
|
+
console.log(response);
|
|
372
|
+
});
|
|
373
|
+
mintTicket();
|
package/dist/trade.d.ts
CHANGED
|
@@ -193,4 +193,16 @@ export default class Trade {
|
|
|
193
193
|
feeToSwap: number;
|
|
194
194
|
lamport: number;
|
|
195
195
|
}>;
|
|
196
|
+
/**
|
|
197
|
+
* Payout an order
|
|
198
|
+
* @param marketId - The ID of the market
|
|
199
|
+
* @param orderId - The ID of the order to payout
|
|
200
|
+
*
|
|
201
|
+
* @param options - RPC options
|
|
202
|
+
*
|
|
203
|
+
*/
|
|
204
|
+
payoutOrder({ marketId, orderId }: {
|
|
205
|
+
marketId: number;
|
|
206
|
+
orderId: number;
|
|
207
|
+
}, options?: RpcOptions): Promise<string>;
|
|
196
208
|
}
|
package/dist/trade.js
CHANGED
|
@@ -298,5 +298,25 @@ class Trade {
|
|
|
298
298
|
};
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Payout an order
|
|
303
|
+
* @param marketId - The ID of the market
|
|
304
|
+
* @param orderId - The ID of the order to payout
|
|
305
|
+
*
|
|
306
|
+
* @param options - RPC options
|
|
307
|
+
*
|
|
308
|
+
*/
|
|
309
|
+
payoutOrder({ marketId, orderId }, options) {
|
|
310
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
311
|
+
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
312
|
+
const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
313
|
+
return (0, sendTransactionWithOptions_1.default)(this.program.methods.payoutOrder(new bn_js_1.default(orderId)).accounts({
|
|
314
|
+
signer: this.provider.publicKey,
|
|
315
|
+
userTrade: userTradePDA,
|
|
316
|
+
market: marketPDA,
|
|
317
|
+
mint: this.mint
|
|
318
|
+
}), options);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
301
321
|
}
|
|
302
322
|
exports.default = Trade;
|