@triadxyz/triad-protocol 4.1.9 → 4.2.1
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/customer.d.ts +8 -1
- package/dist/customer.js +23 -0
- package/dist/index.d.ts +4 -138
- package/dist/index.js +15 -441
- package/dist/market.d.ts +163 -0
- package/dist/market.js +571 -0
- package/dist/poseidon.d.ts +2 -4
- package/dist/poseidon.js +10 -16
- package/dist/predictor.d.ts +8 -1
- package/dist/predictor.js +34 -14
- package/dist/stake.d.ts +0 -15
- package/dist/stake.js +0 -60
- package/dist/trade.d.ts +7 -6
- package/dist/trade.js +44 -54
- package/dist/types/customer.d.ts +5 -0
- package/dist/types/idl_triad_protocol.json +515 -901
- package/dist/types/index.d.ts +1 -4
- package/dist/types/predictor.d.ts +6 -0
- package/dist/types/trade.d.ts +7 -2
- package/dist/types/triad_protocol.d.ts +623 -1389
- package/dist/utils/feeCalculator.d.ts +0 -8
- package/dist/utils/feeCalculator.js +3 -32
- package/dist/utils/helpers.d.ts +2 -2
- package/dist/utils/helpers.js +6 -7
- package/dist/utils/sendVersionedTransaction.js +3 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,13 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
30
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
31
30
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
32
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
33
|
-
const helpers_1 = require("./utils/helpers");
|
|
34
31
|
const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
|
|
35
32
|
const constants_1 = require("./utils/constants");
|
|
36
|
-
const
|
|
33
|
+
const helpers_1 = require("./utils/helpers");
|
|
37
34
|
const pda_1 = require("./utils/pda");
|
|
38
35
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
39
36
|
const stake_1 = __importDefault(require("./stake"));
|
|
@@ -41,6 +38,8 @@ const poseidon_1 = __importDefault(require("./poseidon"));
|
|
|
41
38
|
const predictor_1 = __importDefault(require("./predictor"));
|
|
42
39
|
const trade_1 = __importDefault(require("./trade"));
|
|
43
40
|
const customer_1 = __importDefault(require("./customer"));
|
|
41
|
+
const market_1 = __importDefault(require("./market"));
|
|
42
|
+
const getPriorityFee_1 = __importDefault(require("./utils/getPriorityFee"));
|
|
44
43
|
__exportStar(require("./types"), exports);
|
|
45
44
|
__exportStar(require("./types/predictor"), exports);
|
|
46
45
|
__exportStar(require("./types/stake"), exports);
|
|
@@ -67,6 +66,16 @@ class TriadProtocol {
|
|
|
67
66
|
this.predictor = new predictor_1.default(this.program, this.rpcOptions);
|
|
68
67
|
this.trade = new trade_1.default(this.program, this.rpcOptions);
|
|
69
68
|
this.customer = new customer_1.default(this.program, this.rpcOptions);
|
|
69
|
+
this.market = new market_1.default(this.program, this.rpcOptions);
|
|
70
|
+
this.getPriorityFee();
|
|
71
|
+
}
|
|
72
|
+
getPriorityFee() {
|
|
73
|
+
var _a;
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
if ((_a = this.rpcOptions) === null || _a === void 0 ? void 0 : _a.microLamports)
|
|
76
|
+
return;
|
|
77
|
+
this.rpcOptions.microLamports = yield (0, getPriorityFee_1.default)();
|
|
78
|
+
});
|
|
70
79
|
}
|
|
71
80
|
/**
|
|
72
81
|
* Get User Orders
|
|
@@ -85,24 +94,6 @@ class TriadProtocol {
|
|
|
85
94
|
return orders.map(({ account, publicKey }) => (0, helpers_1.formatOrder)(account, publicKey));
|
|
86
95
|
});
|
|
87
96
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Get Orders By Market ID
|
|
90
|
-
* @param marketId - The ID of the market
|
|
91
|
-
*/
|
|
92
|
-
getOrdersByMarketId(marketId) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const marketIdBytes = new bn_js_1.default(marketId).toArray('le', 8);
|
|
95
|
-
const orders = yield this.program.account.orderV2.all([
|
|
96
|
-
{
|
|
97
|
-
memcmp: {
|
|
98
|
-
offset: 8 + 32,
|
|
99
|
-
bytes: bs58_1.default.encode(marketIdBytes)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
]);
|
|
103
|
-
return orders.map(({ account, publicKey }) => (0, helpers_1.formatOrder)(account, publicKey));
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
97
|
/**
|
|
107
98
|
* Get User Orders By Market ID
|
|
108
99
|
* @param wallet - User wallet PublicKey
|
|
@@ -123,7 +114,7 @@ class TriadProtocol {
|
|
|
123
114
|
const orderbooks = yield this.program.account.orderBook.all();
|
|
124
115
|
const bookOrders = orderbooks.map((orderbook) => {
|
|
125
116
|
return [...orderbook.account.hypeOrders, ...orderbook.account.flopOrders]
|
|
126
|
-
.map((order) => (0,
|
|
117
|
+
.map((order) => (0, helpers_1.formatBookOrder)(order, orderbook.account.marketId.toNumber()))
|
|
127
118
|
.filter((order) => order.authority === wallet.toBase58() &&
|
|
128
119
|
order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
|
|
129
120
|
});
|
|
@@ -138,428 +129,11 @@ class TriadProtocol {
|
|
|
138
129
|
const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId), this.provider.opts.commitment);
|
|
139
130
|
const orders = [...orderBook.hypeOrders, ...orderBook.flopOrders];
|
|
140
131
|
return orders
|
|
141
|
-
.map((order) => (0,
|
|
132
|
+
.map((order) => (0, helpers_1.formatBookOrder)(order, marketId))
|
|
142
133
|
.filter((order) => order.authority === wallet.toBase58() &&
|
|
143
134
|
order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
|
|
144
135
|
});
|
|
145
136
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Get All Pools
|
|
148
|
-
*/
|
|
149
|
-
getAllPools() {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const pool = yield this.program.account.pool.all();
|
|
152
|
-
return pool.map(({ account, publicKey }) => (0, helpers_1.formatPool)(account, publicKey));
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Get All Markets
|
|
157
|
-
*/
|
|
158
|
-
getAllMarkets() {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const marketV2 = yield this.program.account.marketV2.all();
|
|
161
|
-
return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get Pool By ID
|
|
166
|
-
* @param poolId - The ID of the pool
|
|
167
|
-
*/
|
|
168
|
-
getPoolById(poolId) {
|
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
|
|
171
|
-
const response = yield this.program.account.pool.fetch(poolPDA, this.provider.opts.commitment);
|
|
172
|
-
return (0, helpers_1.formatPool)(response, poolPDA);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get Market By ID
|
|
177
|
-
* @param marketId - The ID of the market
|
|
178
|
-
*/
|
|
179
|
-
getMarketById(marketId) {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
182
|
-
const response = yield this.program.account.marketV2.fetch(marketPDA, this.provider.opts.commitment);
|
|
183
|
-
return (0, helpers_1.formatMarket)(response, marketPDA);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Get Market By Address
|
|
188
|
-
* @param marketAddress - The address of the market
|
|
189
|
-
*/
|
|
190
|
-
getMarketByAddress(marketAddress) {
|
|
191
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
const account = yield this.program.account.marketV2.fetch(marketAddress, this.provider.opts.commitment);
|
|
193
|
-
return (0, helpers_1.formatMarket)(account, marketAddress);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Get Current Market ID
|
|
198
|
-
*/
|
|
199
|
-
nextMarketId() {
|
|
200
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
let validId = null;
|
|
202
|
-
while (!validId) {
|
|
203
|
-
const marketId = Math.floor(Math.random() * 1000000000000000);
|
|
204
|
-
try {
|
|
205
|
-
yield this.program.account.marketV2.fetch((0, pda_1.getMarketPDA)(this.program.programId, marketId));
|
|
206
|
-
}
|
|
207
|
-
catch (_a) {
|
|
208
|
-
validId = marketId;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return validId;
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Get Next Pool ID
|
|
216
|
-
*/
|
|
217
|
-
nextPoolId() {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
const pools = yield this.program.account.pool.all();
|
|
220
|
-
return pools.length + 1;
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Create Market
|
|
225
|
-
* @param args.markets - Array of markets to create
|
|
226
|
-
* @param args.markets.marketId - Market ID
|
|
227
|
-
* @param args.markets.startTime - start time
|
|
228
|
-
* @param args.markets.endTime - end time
|
|
229
|
-
* @param args.markets.question - question (max 80 characters)
|
|
230
|
-
* @param args.markets.liquidityAtStart - liquidity at start
|
|
231
|
-
* @param args.markets.payoutFee - payout fee (to add affiliate system)
|
|
232
|
-
* @param args.customer - The customer of the market
|
|
233
|
-
* @param args.poolId - The ID of the pool
|
|
234
|
-
*/
|
|
235
|
-
createMarket({ markets, customer, poolId }) {
|
|
236
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
const ixs = [];
|
|
238
|
-
let poolPDA = null;
|
|
239
|
-
if (poolId) {
|
|
240
|
-
poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
|
|
241
|
-
}
|
|
242
|
-
for (const market of markets) {
|
|
243
|
-
if (market.question.length > 80) {
|
|
244
|
-
throw new Error('Question must be less than 80 characters');
|
|
245
|
-
}
|
|
246
|
-
ixs.push(yield this.program.methods
|
|
247
|
-
.createMarket({
|
|
248
|
-
marketId: new bn_js_1.default(market.marketId),
|
|
249
|
-
question: (0, helpers_1.encodeString)(market.question, 80),
|
|
250
|
-
marketStart: new bn_js_1.default(market.startTime),
|
|
251
|
-
marketEnd: new bn_js_1.default(market.endTime),
|
|
252
|
-
feeBps: market.feeBps,
|
|
253
|
-
payoutFee: market.payoutFee,
|
|
254
|
-
preMarketEndTs: new bn_js_1.default(0),
|
|
255
|
-
preOrdersAvailable: new bn_js_1.default(0)
|
|
256
|
-
})
|
|
257
|
-
.accounts({
|
|
258
|
-
signer: this.program.provider.publicKey,
|
|
259
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
260
|
-
pool: poolPDA,
|
|
261
|
-
customer
|
|
262
|
-
})
|
|
263
|
-
.instruction());
|
|
264
|
-
ixs.push(yield this.program.methods
|
|
265
|
-
.createOrderBook(new bn_js_1.default(market.marketId))
|
|
266
|
-
.accounts({
|
|
267
|
-
signer: this.program.provider.publicKey,
|
|
268
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
|
|
269
|
-
})
|
|
270
|
-
.instruction());
|
|
271
|
-
}
|
|
272
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Create Pool
|
|
277
|
-
* @param poolId - The ID of the pool
|
|
278
|
-
* @param question - The question of the pool
|
|
279
|
-
* @param markets - The markets of the pool
|
|
280
|
-
* @param customer - The customer of the pool
|
|
281
|
-
* @param startTime - The start time of the pool
|
|
282
|
-
* @param endTime - The end time of the pool
|
|
283
|
-
* @param feeBps - The fee in basis points of the pool
|
|
284
|
-
* @param payoutFee - The payout fee of the pool
|
|
285
|
-
* @param isFast - Whether the pool is fast
|
|
286
|
-
* @param isPyth - Whether the pool is pyth
|
|
287
|
-
* @param feedId - The feed ID of the pool
|
|
288
|
-
*/
|
|
289
|
-
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }) {
|
|
290
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
if (question.length > 80) {
|
|
292
|
-
throw new Error('Pool question must be less than 80 characters');
|
|
293
|
-
}
|
|
294
|
-
const ixs = [];
|
|
295
|
-
let feedPDA = null;
|
|
296
|
-
if (isPyth) {
|
|
297
|
-
feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(feedId);
|
|
298
|
-
}
|
|
299
|
-
const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
|
|
300
|
-
ixs.push(yield this.program.methods
|
|
301
|
-
.createPool({
|
|
302
|
-
poolId: new bn_js_1.default(poolId),
|
|
303
|
-
question: (0, helpers_1.encodeString)(question, 80),
|
|
304
|
-
isFast,
|
|
305
|
-
isPyth
|
|
306
|
-
})
|
|
307
|
-
.accounts({
|
|
308
|
-
signer: this.program.provider.publicKey,
|
|
309
|
-
priceUpdate: feedPDA,
|
|
310
|
-
customer,
|
|
311
|
-
feed: (0, helpers_1.getFeedIdFromHex)(feedId)
|
|
312
|
-
})
|
|
313
|
-
.instruction());
|
|
314
|
-
for (const market of markets) {
|
|
315
|
-
if (market.question.length > 80) {
|
|
316
|
-
throw new Error('Market question must be less than 80 characters');
|
|
317
|
-
}
|
|
318
|
-
ixs.push(yield this.program.methods
|
|
319
|
-
.createMarket({
|
|
320
|
-
marketId: new bn_js_1.default(market.marketId),
|
|
321
|
-
question: (0, helpers_1.encodeString)(market.question, 80),
|
|
322
|
-
marketStart: new bn_js_1.default(startTime),
|
|
323
|
-
marketEnd: new bn_js_1.default(endTime),
|
|
324
|
-
feeBps,
|
|
325
|
-
payoutFee,
|
|
326
|
-
preMarketEndTs: new bn_js_1.default(0),
|
|
327
|
-
preOrdersAvailable: new bn_js_1.default(0)
|
|
328
|
-
})
|
|
329
|
-
.accounts({
|
|
330
|
-
signer: this.program.provider.publicKey,
|
|
331
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
332
|
-
pool: poolPDA,
|
|
333
|
-
customer
|
|
334
|
-
})
|
|
335
|
-
.instruction());
|
|
336
|
-
ixs.push(yield this.program.methods
|
|
337
|
-
.createOrderBook(new bn_js_1.default(market.marketId))
|
|
338
|
-
.accounts({
|
|
339
|
-
signer: this.program.provider.publicKey,
|
|
340
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
|
|
341
|
-
})
|
|
342
|
-
.instruction());
|
|
343
|
-
}
|
|
344
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Update Market Winning Direction
|
|
349
|
-
* @param args.marketId - The ID of the Market
|
|
350
|
-
* @param args.winningDirection - The Winning Direction of the Market
|
|
351
|
-
* @param args.poolId - The ID of the Pool
|
|
352
|
-
* @param args.withPayout - Whether to allow the market to payout
|
|
353
|
-
*/
|
|
354
|
-
updateMarketWinningDirection({ markets }) {
|
|
355
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
-
const ixs = [];
|
|
357
|
-
for (const market of markets) {
|
|
358
|
-
ixs.push(yield this.program.methods
|
|
359
|
-
.updateMarketWinningDirection(market.winningDirection)
|
|
360
|
-
.accounts({
|
|
361
|
-
signer: this.program.provider.publicKey,
|
|
362
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId),
|
|
363
|
-
pool: market.poolId
|
|
364
|
-
? (0, pda_1.getPoolPDA)(this.program.programId, market.poolId)
|
|
365
|
-
: null
|
|
366
|
-
})
|
|
367
|
-
.instruction());
|
|
368
|
-
if (market.withPayout) {
|
|
369
|
-
ixs.push(yield this.program.methods
|
|
370
|
-
.updateMarketPayout(true)
|
|
371
|
-
.accounts({
|
|
372
|
-
signer: this.program.provider.publicKey,
|
|
373
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
|
|
374
|
-
})
|
|
375
|
-
.instruction());
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Update Market Payout
|
|
383
|
-
* @param args.marketId - The ID of the market
|
|
384
|
-
* @param args.allowPayout - Whether to allow the market to payout
|
|
385
|
-
*/
|
|
386
|
-
updateMarketPayout({ marketId, allowPayout }) {
|
|
387
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
388
|
-
const ixs = [
|
|
389
|
-
yield this.program.methods
|
|
390
|
-
.updateMarketPayout(allowPayout)
|
|
391
|
-
.accounts({
|
|
392
|
-
signer: this.program.provider.publicKey,
|
|
393
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
394
|
-
})
|
|
395
|
-
.instruction()
|
|
396
|
-
];
|
|
397
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Update Market End
|
|
402
|
-
* @param args.marketId - The ID of the market
|
|
403
|
-
* @param args.marketEnd - The end time of the market
|
|
404
|
-
*/
|
|
405
|
-
updateMarketEnd({ marketId, marketEnd }) {
|
|
406
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
407
|
-
const ixs = [
|
|
408
|
-
yield this.program.methods
|
|
409
|
-
.updateMarketEnd(new bn_js_1.default(marketEnd))
|
|
410
|
-
.accounts({
|
|
411
|
-
signer: this.program.provider.publicKey,
|
|
412
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
413
|
-
})
|
|
414
|
-
.instruction()
|
|
415
|
-
];
|
|
416
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Update Market Question
|
|
421
|
-
* @param args.marketId - The ID of the market
|
|
422
|
-
* @param args.question - The question of the market
|
|
423
|
-
*/
|
|
424
|
-
updateMarketQuestion({ marketId, question }) {
|
|
425
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
426
|
-
const ixs = [
|
|
427
|
-
yield this.program.methods
|
|
428
|
-
.updateMarketQuestion((0, helpers_1.encodeString)(question, 80))
|
|
429
|
-
.accounts({
|
|
430
|
-
signer: this.program.provider.publicKey,
|
|
431
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
432
|
-
})
|
|
433
|
-
.instruction()
|
|
434
|
-
];
|
|
435
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Collect Market Fee
|
|
440
|
-
* @param args.markets - The markets to collect the fee from
|
|
441
|
-
* @param args.markets.marketAddress - The address of the market
|
|
442
|
-
* @param args.markets.customerId - The ID of the customer
|
|
443
|
-
* @param args.markets.customerFeeRecipient - The address of the customer fee recipient
|
|
444
|
-
*/
|
|
445
|
-
collectMarketFee(markets) {
|
|
446
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
447
|
-
const ixs = [];
|
|
448
|
-
for (const market of markets) {
|
|
449
|
-
ixs.push(yield this.program.methods
|
|
450
|
-
.collectMarketFee()
|
|
451
|
-
.accounts({
|
|
452
|
-
signer: this.program.provider.publicKey,
|
|
453
|
-
market: market.marketAddress,
|
|
454
|
-
customer: (0, pda_1.getCustomerPDA)(this.program.programId, market.customerId),
|
|
455
|
-
customerFeeRecipient: market.customerFeeRecipient
|
|
456
|
-
})
|
|
457
|
-
.instruction());
|
|
458
|
-
}
|
|
459
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Close Order Book
|
|
464
|
-
* @param markets.id - Market IDs
|
|
465
|
-
* @param markets.authority - The authority of the market
|
|
466
|
-
*/
|
|
467
|
-
closeOrderBook(markets) {
|
|
468
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
469
|
-
const ixs = [];
|
|
470
|
-
for (const market of markets) {
|
|
471
|
-
ixs.push(yield this.program.methods
|
|
472
|
-
.closeOrderBook()
|
|
473
|
-
.accounts({
|
|
474
|
-
authority: market.authority,
|
|
475
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, market.id),
|
|
476
|
-
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, market.id)
|
|
477
|
-
})
|
|
478
|
-
.instruction());
|
|
479
|
-
}
|
|
480
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Close IDLE Market
|
|
485
|
-
* @param markets.id - Market ID
|
|
486
|
-
* @param markets.authority - Market authority
|
|
487
|
-
* @param markets.mint - Market mint
|
|
488
|
-
*/
|
|
489
|
-
closeIdleMarket(markets) {
|
|
490
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
-
const ixs = [];
|
|
492
|
-
for (const market of markets) {
|
|
493
|
-
ixs.push(yield this.program.methods
|
|
494
|
-
.closeIdleMarket(new bn_js_1.default(market.id))
|
|
495
|
-
.accounts({
|
|
496
|
-
signer: this.program.provider.publicKey,
|
|
497
|
-
mint: market.mint,
|
|
498
|
-
tokenProgram: (0, helpers_1.getTokenProgram)(market.mint)
|
|
499
|
-
})
|
|
500
|
-
.instruction());
|
|
501
|
-
}
|
|
502
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Update Pool Question
|
|
507
|
-
* @param poolId - Pool ID
|
|
508
|
-
* @param question - Question
|
|
509
|
-
*/
|
|
510
|
-
updatePoolQuestion(poolId, question) {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
const ixs = [
|
|
513
|
-
yield this.program.methods
|
|
514
|
-
.updatePoolQuestion((0, helpers_1.encodeString)(question, 80))
|
|
515
|
-
.accounts({
|
|
516
|
-
signer: this.program.provider.publicKey,
|
|
517
|
-
pool: (0, pda_1.getPoolPDA)(this.program.programId, poolId)
|
|
518
|
-
})
|
|
519
|
-
.instruction()
|
|
520
|
-
];
|
|
521
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* Create Market Pyth
|
|
526
|
-
* @param args.markets - Array of markets to create
|
|
527
|
-
* @param args.markets.marketId - Market ID
|
|
528
|
-
* @param args.markets.resolveIn - Time to add for resolver the market in seconds
|
|
529
|
-
* @param args.customer - The customer of the market
|
|
530
|
-
* @param args.poolId - The ID of the pool
|
|
531
|
-
*/
|
|
532
|
-
createMarketPyth({ markets }) {
|
|
533
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
534
|
-
const ixs = [];
|
|
535
|
-
for (const market of markets) {
|
|
536
|
-
let poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, market.poolId);
|
|
537
|
-
const feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(market.feedId);
|
|
538
|
-
ixs.push(yield this.program.methods
|
|
539
|
-
.createMarketPyth({
|
|
540
|
-
marketId: new bn_js_1.default(market.marketId),
|
|
541
|
-
resolveIn: new bn_js_1.default(market.resolveIn),
|
|
542
|
-
direction: market.direction
|
|
543
|
-
})
|
|
544
|
-
.accounts({
|
|
545
|
-
signer: this.program.provider.publicKey,
|
|
546
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
547
|
-
pool: poolPDA,
|
|
548
|
-
customer: market.customer,
|
|
549
|
-
priceUpdate: feedPDA
|
|
550
|
-
})
|
|
551
|
-
.instruction());
|
|
552
|
-
ixs.push(yield this.program.methods
|
|
553
|
-
.createOrderBook(new bn_js_1.default(market.marketId))
|
|
554
|
-
.accounts({
|
|
555
|
-
signer: this.program.provider.publicKey,
|
|
556
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
|
|
557
|
-
})
|
|
558
|
-
.instruction());
|
|
559
|
-
}
|
|
560
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
137
|
/**
|
|
564
138
|
* Burn Triad
|
|
565
139
|
* @param amount - Amount to burn
|
package/dist/market.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Program } from '@coral-xyz/anchor';
|
|
3
|
+
import { TriadProtocol } from './types/triad_protocol';
|
|
4
|
+
import { RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs, UpdateMarketPayoutArgs, UpdateMarketQuestionArgs, UpdateMarketEndArgs, CreateMarketPythArgs } from './types';
|
|
5
|
+
export default class Market {
|
|
6
|
+
private program;
|
|
7
|
+
private rpcOptions;
|
|
8
|
+
constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Get Orders By Market ID
|
|
11
|
+
* @param marketId - The ID of the market
|
|
12
|
+
*/
|
|
13
|
+
getOrdersByMarketId(marketId: number): Promise<import("./types").Order[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Get All Pools
|
|
16
|
+
*/
|
|
17
|
+
getAllPools(): Promise<import("./types").Pool[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Get All Markets
|
|
20
|
+
*/
|
|
21
|
+
getAllMarkets(): Promise<import("./types").Market[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get Pool By ID
|
|
24
|
+
* @param poolId - The ID of the pool
|
|
25
|
+
*/
|
|
26
|
+
getPoolById(poolId: number): Promise<import("./types").Pool>;
|
|
27
|
+
/**
|
|
28
|
+
* Get Market By ID
|
|
29
|
+
* @param marketId - The ID of the market
|
|
30
|
+
*/
|
|
31
|
+
getMarketById(marketId: number): Promise<import("./types").Market>;
|
|
32
|
+
/**
|
|
33
|
+
* Get Market By Address
|
|
34
|
+
* @param marketAddress - The address of the market
|
|
35
|
+
*/
|
|
36
|
+
getMarketByAddress(marketAddress: PublicKey): Promise<import("./types").Market>;
|
|
37
|
+
/**
|
|
38
|
+
* Get Current Market ID
|
|
39
|
+
*/
|
|
40
|
+
nextMarketId(): Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Get Next Pool ID
|
|
43
|
+
*/
|
|
44
|
+
nextPoolId(): Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Create Market
|
|
47
|
+
* @param args.markets - Array of markets to create
|
|
48
|
+
* @param args.markets.marketId - Market ID
|
|
49
|
+
* @param args.markets.startTime - start time
|
|
50
|
+
* @param args.markets.endTime - end time
|
|
51
|
+
* @param args.markets.question - question (max 80 characters)
|
|
52
|
+
* @param args.markets.liquidityAtStart - liquidity at start
|
|
53
|
+
* @param args.markets.payoutFee - payout fee (to add affiliate system)
|
|
54
|
+
* @param args.customer - The customer of the market
|
|
55
|
+
* @param args.poolId - The ID of the pool
|
|
56
|
+
*/
|
|
57
|
+
createMarket({ markets, customer, poolId }: CreateMarketArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
58
|
+
/**
|
|
59
|
+
* Create Pool
|
|
60
|
+
* @param poolId - The ID of the pool
|
|
61
|
+
* @param question - The question of the pool
|
|
62
|
+
* @param markets - The markets of the pool
|
|
63
|
+
* @param customer - The customer of the pool
|
|
64
|
+
* @param startTime - The start time of the pool
|
|
65
|
+
* @param endTime - The end time of the pool
|
|
66
|
+
* @param feeBps - The fee in basis points of the pool
|
|
67
|
+
* @param payoutFee - The payout fee of the pool
|
|
68
|
+
* @param isFast - Whether the pool is fast
|
|
69
|
+
* @param isPyth - Whether the pool is pyth
|
|
70
|
+
* @param feedId - The feed ID of the pool
|
|
71
|
+
*/
|
|
72
|
+
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
73
|
+
/**
|
|
74
|
+
* Update Market Winning Direction
|
|
75
|
+
* @param args.marketId - The ID of the Market
|
|
76
|
+
* @param args.winningDirection - The Winning Direction of the Market
|
|
77
|
+
* @param args.poolId - The ID of the Pool
|
|
78
|
+
* @param args.withPayout - Whether to allow the market to payout
|
|
79
|
+
*/
|
|
80
|
+
updateMarketWinningDirection({ markets }: UpdateMarketWinningDirectionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
81
|
+
/**
|
|
82
|
+
* Update Market Payout
|
|
83
|
+
* @param args.marketId - The ID of the market
|
|
84
|
+
* @param args.allowPayout - Whether to allow the market to payout
|
|
85
|
+
*/
|
|
86
|
+
updateMarketPayout({ marketId, allowPayout }: UpdateMarketPayoutArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
87
|
+
/**
|
|
88
|
+
* Update Market End
|
|
89
|
+
* @param args.marketId - The ID of the market
|
|
90
|
+
* @param args.marketEnd - The end time of the market
|
|
91
|
+
*/
|
|
92
|
+
updateMarketEnd({ marketId, marketEnd }: UpdateMarketEndArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
93
|
+
/**
|
|
94
|
+
* Update Market Question
|
|
95
|
+
* @param args.marketId - The ID of the market
|
|
96
|
+
* @param args.question - The question of the market
|
|
97
|
+
*/
|
|
98
|
+
updateMarketQuestion({ marketId, question }: UpdateMarketQuestionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
99
|
+
/**
|
|
100
|
+
* Close Order Book
|
|
101
|
+
* @param markets.id - Market IDs
|
|
102
|
+
* @param markets.authority - The authority of the market
|
|
103
|
+
*/
|
|
104
|
+
closeOrderBook(markets: {
|
|
105
|
+
id: number;
|
|
106
|
+
authority: PublicKey;
|
|
107
|
+
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
108
|
+
/**
|
|
109
|
+
* Close IDLE Market
|
|
110
|
+
* @param markets.id - Market ID
|
|
111
|
+
* @param markets.authority - Market authority
|
|
112
|
+
* @param markets.mint - Market mint
|
|
113
|
+
*/
|
|
114
|
+
closeIdleMarket(markets: {
|
|
115
|
+
id: number;
|
|
116
|
+
authority: PublicKey;
|
|
117
|
+
mint: PublicKey;
|
|
118
|
+
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
119
|
+
/**
|
|
120
|
+
* Update Pool Question
|
|
121
|
+
* @param poolId - Pool ID
|
|
122
|
+
* @param question - Question
|
|
123
|
+
*/
|
|
124
|
+
updatePoolQuestion(poolId: number, question: string): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
125
|
+
/**
|
|
126
|
+
* Create Market Pyth
|
|
127
|
+
* @param args.markets - Array of markets to create
|
|
128
|
+
* @param args.markets.marketId - Market ID
|
|
129
|
+
* @param args.markets.resolveIn - Time to add for resolver the market in seconds
|
|
130
|
+
* @param args.customer - The customer of the market
|
|
131
|
+
* @param args.poolId - The ID of the pool
|
|
132
|
+
*/
|
|
133
|
+
createMarketPyth({ markets }: CreateMarketPythArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
134
|
+
/**
|
|
135
|
+
* Create and Resolve Pyth Market
|
|
136
|
+
* @param toResolve - Market to resolve
|
|
137
|
+
* @param toResolve.marketId - Market ID
|
|
138
|
+
* @param toResolve.winningDirection - Winning direction
|
|
139
|
+
* @param toResolve.poolId - Pool ID
|
|
140
|
+
* @param toResolve.withPayout - Whether to update market payout
|
|
141
|
+
* @param market - Market to create
|
|
142
|
+
* @param market.marketId - Market ID
|
|
143
|
+
* @param market.resolveIn - Time to add for resolver the market in seconds
|
|
144
|
+
* @param market.direction - Direction of the market
|
|
145
|
+
* @param market.customer - The customer of the market
|
|
146
|
+
* @param market.poolId - The ID of the pool
|
|
147
|
+
*/
|
|
148
|
+
createAndResolvePythMarket(toResolve: UpdateMarketWinningDirectionArgs['markets'][0], market: CreateMarketPythArgs['markets'][0]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
149
|
+
/**
|
|
150
|
+
* Create and Resolve Market
|
|
151
|
+
* @param toResolve - Market to resolve
|
|
152
|
+
* @param toResolve.marketId - Market ID
|
|
153
|
+
* @param toResolve.winningDirection - Winning direction
|
|
154
|
+
* @param toResolve.withPayout - Whether to update market payout
|
|
155
|
+
* @param market - Market to create
|
|
156
|
+
* @param market.marketId - Market ID
|
|
157
|
+
* @param market.resolveIn - Time to add for resolver the market in seconds
|
|
158
|
+
* @param market.direction - Direction of the market
|
|
159
|
+
* @param market.customer - The customer of the market
|
|
160
|
+
* @param market.poolId - The ID of the pool
|
|
161
|
+
*/
|
|
162
|
+
createAndResolveMarket(toResolve: UpdateMarketWinningDirectionArgs['markets'][0], market: CreateMarketArgs['markets'][0], customer: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
163
|
+
}
|