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