@triadxyz/triad-protocol 3.5.3-beta → 4.0.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/index.d.ts +28 -49
- package/dist/index.js +73 -189
- package/dist/stake.d.ts +0 -5
- package/dist/stake.js +0 -17
- package/dist/types/idl_triad_protocol.json +547 -1103
- package/dist/types/index.d.ts +8 -72
- package/dist/types/triad_protocol.d.ts +784 -1543
- package/dist/utils/feeCalculator.d.ts +5 -13
- package/dist/utils/feeCalculator.js +13 -29
- package/dist/utils/helpers.d.ts +1 -3
- package/dist/utils/helpers.js +2 -34
- package/dist/utils/pda.d.ts +2 -0
- package/dist/utils/pda.js +13 -1
- package/package.json +1 -1
- package/dist/claim.d.ts +0 -59
- package/dist/claim.js +0 -193
- package/dist/utils/merkle.d.ts +0 -35
- package/dist/utils/merkle.js +0 -176
- package/dist/utils/swap.d.ts +0 -15
- package/dist/utils/swap.js +0 -93
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
4
4
|
import { TriadProtocol as TriadProtocolIDL } from './types/triad_protocol';
|
|
5
|
-
import {
|
|
5
|
+
import { CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, BookOrder, MarketAskOrderArgs, RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs, OrderDirectionEncoded, UpdateMarketPayoutArgs, UpdateMarketQuestionArgs, UpdateMarketEndArgs } from './types';
|
|
6
6
|
import Stake from './stake';
|
|
7
7
|
import Poseidon from './poseidon';
|
|
8
|
-
import Claim from './claim';
|
|
9
8
|
export * from './types';
|
|
10
9
|
export * from './utils/helpers';
|
|
11
|
-
export * from './utils/merkle';
|
|
12
10
|
export * from './utils/feeCalculator';
|
|
13
11
|
export * from './utils/constants';
|
|
14
12
|
export * from './utils/pda';
|
|
@@ -20,7 +18,6 @@ export default class TriadProtocol {
|
|
|
20
18
|
provider: AnchorProvider;
|
|
21
19
|
stake: Stake;
|
|
22
20
|
poseidon: Poseidon;
|
|
23
|
-
claim: Claim;
|
|
24
21
|
constructor(connection: Connection, wallet: Wallet, rpcOptions: RpcOptions);
|
|
25
22
|
/**
|
|
26
23
|
* Get User Orders
|
|
@@ -113,41 +110,29 @@ export default class TriadProtocol {
|
|
|
113
110
|
*/
|
|
114
111
|
createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
115
112
|
/**
|
|
116
|
-
*
|
|
113
|
+
* Update Market Winning Direction
|
|
117
114
|
* @param args.marketId - The ID of the Market
|
|
118
|
-
* @param args.poolId - The ID of the Pool
|
|
119
115
|
* @param args.winningDirection - The Winning Direction of the Market
|
|
120
116
|
*/
|
|
121
|
-
updateMarketWinningDirection({ marketId,
|
|
117
|
+
updateMarketWinningDirection({ marketId, winningDirection }: UpdateMarketWinningDirectionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
122
118
|
/**
|
|
123
119
|
* Update Market Payout
|
|
124
|
-
* @param marketId - The ID of the market
|
|
125
|
-
* @param
|
|
126
|
-
* @param allowPayout - Whether to allow the market to payout
|
|
120
|
+
* @param args.marketId - The ID of the market
|
|
121
|
+
* @param args.allowPayout - Whether to allow the market to payout
|
|
127
122
|
*/
|
|
128
|
-
updateMarketPayout({ marketId,
|
|
129
|
-
marketId: number;
|
|
130
|
-
poolId?: number;
|
|
131
|
-
allowPayout: boolean;
|
|
132
|
-
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
123
|
+
updateMarketPayout({ marketId, allowPayout }: UpdateMarketPayoutArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
133
124
|
/**
|
|
134
125
|
* Update Market End
|
|
135
|
-
* @param marketId - The ID of the market
|
|
136
|
-
* @param marketEnd - The end time of the market
|
|
126
|
+
* @param args.marketId - The ID of the market
|
|
127
|
+
* @param args.marketEnd - The end time of the market
|
|
137
128
|
*/
|
|
138
|
-
updateMarketEnd({ marketId, marketEnd }:
|
|
139
|
-
marketId: number;
|
|
140
|
-
marketEnd: number;
|
|
141
|
-
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
129
|
+
updateMarketEnd({ marketId, marketEnd }: UpdateMarketEndArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
142
130
|
/**
|
|
143
131
|
* Update Market Question
|
|
144
|
-
* @param marketId - The ID of the market
|
|
145
|
-
* @param question - The question of the market
|
|
132
|
+
* @param args.marketId - The ID of the market
|
|
133
|
+
* @param args.question - The question of the market
|
|
146
134
|
*/
|
|
147
|
-
updateMarketQuestion({ marketId, question }:
|
|
148
|
-
marketId: number;
|
|
149
|
-
question: string;
|
|
150
|
-
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
135
|
+
updateMarketQuestion({ marketId, question }: UpdateMarketQuestionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
151
136
|
/**
|
|
152
137
|
* Collect Market Fee
|
|
153
138
|
* @param args.markets - The markets to collect the fee from
|
|
@@ -171,31 +156,15 @@ export default class TriadProtocol {
|
|
|
171
156
|
* @param question - Question
|
|
172
157
|
*/
|
|
173
158
|
updatePoolQuestion(poolId: number, question: string): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
174
|
-
/**
|
|
175
|
-
* Open Order
|
|
176
|
-
* @param args.marketId - The ID of the Market
|
|
177
|
-
* @param args.amount - The amount of the Order
|
|
178
|
-
* @param args.orderDirection - The direction of the Order
|
|
179
|
-
* @param args.mint - The mint of the Order
|
|
180
|
-
* @param args.token - The token to use for the Order
|
|
181
|
-
*/
|
|
182
|
-
openOrder({ marketId, amount, orderDirection, mint, token }: OpenOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
183
|
-
/**
|
|
184
|
-
* Close Order
|
|
185
|
-
* @param args.marketId - The ID of the Market
|
|
186
|
-
* @param args.orderDirection - The direction of the Order
|
|
187
|
-
*/
|
|
188
|
-
closeOrder({ marketId, orderDirection }: CloseOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
189
159
|
/**
|
|
190
160
|
* Payout Order
|
|
191
161
|
* @param args.marketId - The ID of the Market
|
|
162
|
+
* @param args.authority - The authority of the order
|
|
192
163
|
* @param args.orderDirection - The direction of the Order to Payout
|
|
193
|
-
* @param args.mint - The mint of the market
|
|
194
164
|
*/
|
|
195
165
|
payoutOrder(orders: {
|
|
196
166
|
marketId: number;
|
|
197
167
|
orderDirection: OrderDirectionEncoded;
|
|
198
|
-
mint: PublicKey;
|
|
199
168
|
authority: PublicKey;
|
|
200
169
|
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
201
170
|
/**
|
|
@@ -213,9 +182,8 @@ export default class TriadProtocol {
|
|
|
213
182
|
* @param args.orders.amount - The amount of the Order
|
|
214
183
|
* @param args.orders.price - The price of the Order
|
|
215
184
|
* @param args.orders.orderDirection - The direction of the Order
|
|
216
|
-
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
217
185
|
*/
|
|
218
|
-
placeBidOrder({ orders
|
|
186
|
+
placeBidOrder({ orders }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
219
187
|
/**
|
|
220
188
|
* Place Ask Order
|
|
221
189
|
* @param args.orders - Array of orders to execute
|
|
@@ -245,9 +213,8 @@ export default class TriadProtocol {
|
|
|
245
213
|
* @param args.marketId - The ID of the Market
|
|
246
214
|
* @param args.amount - The amount of the Order
|
|
247
215
|
* @param args.orderDirection - The direction of the Order
|
|
248
|
-
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
249
216
|
*/
|
|
250
|
-
marketBidOrder({ marketId, amount, orderDirection
|
|
217
|
+
marketBidOrder({ marketId, amount, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
251
218
|
/**
|
|
252
219
|
* Market Ask Order
|
|
253
220
|
* @param args.marketId - The ID of the Market
|
|
@@ -279,8 +246,20 @@ export default class TriadProtocol {
|
|
|
279
246
|
* @param customerId - Customer ID
|
|
280
247
|
* @param feeBps - Fee in basis points
|
|
281
248
|
*/
|
|
282
|
-
updateCustomerFee({ customerId, feeBps }: {
|
|
249
|
+
updateCustomerFee({ customerId, feeBps, feeRecipient }: {
|
|
283
250
|
customerId: number;
|
|
284
251
|
feeBps: number;
|
|
252
|
+
feeRecipient: PublicKey | null;
|
|
253
|
+
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
254
|
+
deposit({ authority, amount, refer, customer }: {
|
|
255
|
+
authority: PublicKey;
|
|
256
|
+
amount: number;
|
|
257
|
+
refer?: PublicKey;
|
|
258
|
+
customer?: number;
|
|
259
|
+
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
260
|
+
withdraw({ authority, amount, customer }: {
|
|
261
|
+
authority: PublicKey;
|
|
262
|
+
amount: number;
|
|
263
|
+
customer?: number;
|
|
285
264
|
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
286
265
|
}
|
package/dist/index.js
CHANGED
|
@@ -38,14 +38,11 @@ const constants_1 = require("./utils/constants");
|
|
|
38
38
|
const helpers_2 = require("./utils/helpers");
|
|
39
39
|
const pda_1 = require("./utils/pda");
|
|
40
40
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
41
|
-
const swap_1 = require("./utils/swap");
|
|
42
41
|
const feeCalculator_1 = require("./utils/feeCalculator");
|
|
43
42
|
const stake_1 = __importDefault(require("./stake"));
|
|
44
43
|
const poseidon_1 = __importDefault(require("./poseidon"));
|
|
45
|
-
const claim_1 = __importDefault(require("./claim"));
|
|
46
44
|
__exportStar(require("./types"), exports);
|
|
47
45
|
__exportStar(require("./utils/helpers"), exports);
|
|
48
|
-
__exportStar(require("./utils/merkle"), exports);
|
|
49
46
|
__exportStar(require("./utils/feeCalculator"), exports);
|
|
50
47
|
__exportStar(require("./utils/constants"), exports);
|
|
51
48
|
__exportStar(require("./utils/pda"), exports);
|
|
@@ -63,7 +60,6 @@ class TriadProtocol {
|
|
|
63
60
|
this.program = new anchor_1.Program(idl_triad_protocol_json_1.default, this.provider);
|
|
64
61
|
this.stake = new stake_1.default(this.program, this.rpcOptions);
|
|
65
62
|
this.poseidon = new poseidon_1.default(this.program, this.rpcOptions);
|
|
66
|
-
this.claim = new claim_1.default(this.program, this.rpcOptions);
|
|
67
63
|
}
|
|
68
64
|
/**
|
|
69
65
|
* Get User Orders
|
|
@@ -275,7 +271,9 @@ class TriadProtocol {
|
|
|
275
271
|
marketStart: new bn_js_1.default(market.startTime),
|
|
276
272
|
marketEnd: new bn_js_1.default(market.endTime),
|
|
277
273
|
feeBps: market.feeBps,
|
|
278
|
-
payoutFee: market.payoutFee
|
|
274
|
+
payoutFee: market.payoutFee,
|
|
275
|
+
preMarketEndTs: new bn_js_1.default(0),
|
|
276
|
+
preOrdersAvailable: new bn_js_1.default(0)
|
|
279
277
|
})
|
|
280
278
|
.accounts({
|
|
281
279
|
signer: this.program.provider.publicKey,
|
|
@@ -330,7 +328,9 @@ class TriadProtocol {
|
|
|
330
328
|
marketStart: new bn_js_1.default(startTime),
|
|
331
329
|
marketEnd: new bn_js_1.default(endTime),
|
|
332
330
|
feeBps,
|
|
333
|
-
payoutFee
|
|
331
|
+
payoutFee,
|
|
332
|
+
preMarketEndTs: new bn_js_1.default(0),
|
|
333
|
+
preOrdersAvailable: new bn_js_1.default(0)
|
|
334
334
|
})
|
|
335
335
|
.accounts({
|
|
336
336
|
signer: this.program.provider.publicKey,
|
|
@@ -351,24 +351,18 @@ class TriadProtocol {
|
|
|
351
351
|
});
|
|
352
352
|
}
|
|
353
353
|
/**
|
|
354
|
-
*
|
|
354
|
+
* Update Market Winning Direction
|
|
355
355
|
* @param args.marketId - The ID of the Market
|
|
356
|
-
* @param args.poolId - The ID of the Pool
|
|
357
356
|
* @param args.winningDirection - The Winning Direction of the Market
|
|
358
357
|
*/
|
|
359
|
-
updateMarketWinningDirection({ marketId,
|
|
358
|
+
updateMarketWinningDirection({ marketId, winningDirection }) {
|
|
360
359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
-
let poolPDA = null;
|
|
362
|
-
if (poolId) {
|
|
363
|
-
poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
|
|
364
|
-
}
|
|
365
360
|
const ixs = [
|
|
366
361
|
yield this.program.methods
|
|
367
362
|
.updateMarketWinningDirection(winningDirection)
|
|
368
363
|
.accounts({
|
|
369
364
|
signer: this.program.provider.publicKey,
|
|
370
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
371
|
-
pool: poolPDA
|
|
365
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
372
366
|
})
|
|
373
367
|
.instruction()
|
|
374
368
|
];
|
|
@@ -377,16 +371,11 @@ class TriadProtocol {
|
|
|
377
371
|
}
|
|
378
372
|
/**
|
|
379
373
|
* Update Market Payout
|
|
380
|
-
* @param marketId - The ID of the market
|
|
381
|
-
* @param
|
|
382
|
-
* @param allowPayout - Whether to allow the market to payout
|
|
374
|
+
* @param args.marketId - The ID of the market
|
|
375
|
+
* @param args.allowPayout - Whether to allow the market to payout
|
|
383
376
|
*/
|
|
384
|
-
updateMarketPayout({ marketId,
|
|
377
|
+
updateMarketPayout({ marketId, allowPayout }) {
|
|
385
378
|
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
-
let poolPDA = null;
|
|
387
|
-
if (poolId) {
|
|
388
|
-
poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
|
|
389
|
-
}
|
|
390
379
|
const ixs = [
|
|
391
380
|
yield this.program.methods
|
|
392
381
|
.updateMarketPayout(allowPayout)
|
|
@@ -401,8 +390,8 @@ class TriadProtocol {
|
|
|
401
390
|
}
|
|
402
391
|
/**
|
|
403
392
|
* Update Market End
|
|
404
|
-
* @param marketId - The ID of the market
|
|
405
|
-
* @param marketEnd - The end time of the market
|
|
393
|
+
* @param args.marketId - The ID of the market
|
|
394
|
+
* @param args.marketEnd - The end time of the market
|
|
406
395
|
*/
|
|
407
396
|
updateMarketEnd({ marketId, marketEnd }) {
|
|
408
397
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -420,8 +409,8 @@ class TriadProtocol {
|
|
|
420
409
|
}
|
|
421
410
|
/**
|
|
422
411
|
* Update Market Question
|
|
423
|
-
* @param marketId - The ID of the market
|
|
424
|
-
* @param question - The question of the market
|
|
412
|
+
* @param args.marketId - The ID of the market
|
|
413
|
+
* @param args.question - The question of the market
|
|
425
414
|
*/
|
|
426
415
|
updateMarketQuestion({ marketId, question }) {
|
|
427
416
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -500,80 +489,11 @@ class TriadProtocol {
|
|
|
500
489
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
501
490
|
});
|
|
502
491
|
}
|
|
503
|
-
/**
|
|
504
|
-
* Open Order
|
|
505
|
-
* @param args.marketId - The ID of the Market
|
|
506
|
-
* @param args.amount - The amount of the Order
|
|
507
|
-
* @param args.orderDirection - The direction of the Order
|
|
508
|
-
* @param args.mint - The mint of the Order
|
|
509
|
-
* @param args.token - The token to use for the Order
|
|
510
|
-
*/
|
|
511
|
-
openOrder({ marketId, amount, orderDirection, mint, token }) {
|
|
512
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
513
|
-
const ixs = [];
|
|
514
|
-
const addressLookupTableAccounts = [];
|
|
515
|
-
let amountInTRD = amount * Math.pow(10, constants_1.BASE_DECIMALS);
|
|
516
|
-
if (token !== constants_1.TRD_MINT.toBase58()) {
|
|
517
|
-
const { setupInstructions, swapIxs, addressLookupTableAccounts, outAmount } = yield (0, swap_1.swap)({
|
|
518
|
-
connection: this.program.provider.connection,
|
|
519
|
-
wallet: this.program.provider.publicKey.toBase58(),
|
|
520
|
-
inToken: token,
|
|
521
|
-
outToken: constants_1.TRD_MINT.toString(),
|
|
522
|
-
amount,
|
|
523
|
-
payer: this.rpcOptions.payer.toBase58()
|
|
524
|
-
});
|
|
525
|
-
amountInTRD = outAmount;
|
|
526
|
-
if (swapIxs.length === 0) {
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
ixs.push(...setupInstructions);
|
|
530
|
-
ixs.push(...swapIxs);
|
|
531
|
-
addressLookupTableAccounts.push(...addressLookupTableAccounts);
|
|
532
|
-
}
|
|
533
|
-
ixs.push(yield this.program.methods
|
|
534
|
-
.openOrder({
|
|
535
|
-
amount: new bn_js_1.default(amountInTRD),
|
|
536
|
-
marketId: new bn_js_1.default(marketId),
|
|
537
|
-
orderDirection
|
|
538
|
-
})
|
|
539
|
-
.accounts({
|
|
540
|
-
signer: this.program.provider.publicKey,
|
|
541
|
-
payer: this.rpcOptions.payer,
|
|
542
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
543
|
-
mint,
|
|
544
|
-
order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection))
|
|
545
|
-
})
|
|
546
|
-
.instruction());
|
|
547
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions, addressLookupTableAccounts);
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Close Order
|
|
552
|
-
* @param args.marketId - The ID of the Market
|
|
553
|
-
* @param args.orderDirection - The direction of the Order
|
|
554
|
-
*/
|
|
555
|
-
closeOrder({ marketId, orderDirection }) {
|
|
556
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
557
|
-
const ixs = [
|
|
558
|
-
yield this.program.methods
|
|
559
|
-
.closeOrder(orderDirection)
|
|
560
|
-
.accounts({
|
|
561
|
-
signer: this.program.provider.publicKey,
|
|
562
|
-
payer: this.rpcOptions.payer,
|
|
563
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
564
|
-
mint: constants_1.TRD_MINT,
|
|
565
|
-
order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection))
|
|
566
|
-
})
|
|
567
|
-
.instruction()
|
|
568
|
-
];
|
|
569
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
492
|
/**
|
|
573
493
|
* Payout Order
|
|
574
494
|
* @param args.marketId - The ID of the Market
|
|
495
|
+
* @param args.authority - The authority of the order
|
|
575
496
|
* @param args.orderDirection - The direction of the Order to Payout
|
|
576
|
-
* @param args.mint - The mint of the market
|
|
577
497
|
*/
|
|
578
498
|
payoutOrder(orders) {
|
|
579
499
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -588,8 +508,7 @@ class TriadProtocol {
|
|
|
588
508
|
signer: order.authority,
|
|
589
509
|
payer: this.rpcOptions.payer,
|
|
590
510
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
591
|
-
|
|
592
|
-
tokenProgram: (0, helpers_2.getTokenProgram)(order.mint),
|
|
511
|
+
tokenProgram: (0, helpers_2.getTokenProgram)(constants_1.USDC_MINT),
|
|
593
512
|
order: (0, pda_1.getOrderPDA)(this.program.programId, order.authority, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
594
513
|
})
|
|
595
514
|
.instruction());
|
|
@@ -624,41 +543,12 @@ class TriadProtocol {
|
|
|
624
543
|
* @param args.orders.amount - The amount of the Order
|
|
625
544
|
* @param args.orders.price - The price of the Order
|
|
626
545
|
* @param args.orders.orderDirection - The direction of the Order
|
|
627
|
-
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
628
546
|
*/
|
|
629
|
-
placeBidOrder({ orders
|
|
547
|
+
placeBidOrder({ orders }) {
|
|
630
548
|
return __awaiter(this, void 0, void 0, function* () {
|
|
631
549
|
const ixs = [];
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
throw new Error('Max 5 orders per transaction');
|
|
635
|
-
}
|
|
636
|
-
let amountInUSDC = new bn_js_1.default(0);
|
|
637
|
-
let totalAmount = 0;
|
|
638
|
-
for (const order of orders) {
|
|
639
|
-
totalAmount += order.amount;
|
|
640
|
-
}
|
|
641
|
-
if (isTrdPayout) {
|
|
642
|
-
const trdPrice = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
643
|
-
const amountInTRD = (totalAmount / trdPrice) * 1.06;
|
|
644
|
-
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
645
|
-
connection: this.program.provider.connection,
|
|
646
|
-
wallet: this.program.provider.publicKey.toBase58(),
|
|
647
|
-
inToken: constants_1.TRD_MINT.toString(),
|
|
648
|
-
outToken: constants_1.USDC_MINT.toString(),
|
|
649
|
-
amount: Math.floor(amountInTRD),
|
|
650
|
-
payer: this.rpcOptions.payer.toBase58()
|
|
651
|
-
});
|
|
652
|
-
if (swapIxs.length === 0) {
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
amountInUSDC = new bn_js_1.default(outAmount);
|
|
656
|
-
ixs.push(...setupInstructions);
|
|
657
|
-
ixs.push(...swapIxs);
|
|
658
|
-
addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
|
|
659
|
-
if (amountInUSDC.lt(new bn_js_1.default(totalAmount * Math.pow(10, constants_1.BASE_DECIMALS)))) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
550
|
+
if (orders.length > 6) {
|
|
551
|
+
throw new Error('Max 6 orders per transaction');
|
|
662
552
|
}
|
|
663
553
|
for (const order of orders) {
|
|
664
554
|
ixs.push(yield this.program.methods
|
|
@@ -691,8 +581,8 @@ class TriadProtocol {
|
|
|
691
581
|
placeAskOrder({ orders }) {
|
|
692
582
|
return __awaiter(this, void 0, void 0, function* () {
|
|
693
583
|
const ixs = [];
|
|
694
|
-
if (orders.length >
|
|
695
|
-
throw new Error('Max
|
|
584
|
+
if (orders.length > 6) {
|
|
585
|
+
throw new Error('Max 6 orders per transaction');
|
|
696
586
|
}
|
|
697
587
|
for (const order of orders) {
|
|
698
588
|
ixs.push(yield this.program.methods
|
|
@@ -779,69 +669,18 @@ class TriadProtocol {
|
|
|
779
669
|
* @param args.marketId - The ID of the Market
|
|
780
670
|
* @param args.amount - The amount of the Order
|
|
781
671
|
* @param args.orderDirection - The direction of the Order
|
|
782
|
-
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
783
672
|
*/
|
|
784
|
-
marketBidOrder({ marketId, amount, orderDirection
|
|
673
|
+
marketBidOrder({ marketId, amount, orderDirection }) {
|
|
785
674
|
return __awaiter(this, void 0, void 0, function* () {
|
|
786
675
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
787
676
|
const ixs = [];
|
|
788
677
|
const addressLookupTableAccounts = [];
|
|
789
678
|
const orderBook = yield this.getOrderBook(marketId);
|
|
790
679
|
let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
|
|
791
|
-
if (isTrdPayout) {
|
|
792
|
-
const price = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
793
|
-
const trdToUsdc = amount * price;
|
|
794
|
-
remainingUSDC = new bn_js_1.default(trdToUsdc * Math.pow(10, constants_1.BASE_DECIMALS));
|
|
795
|
-
}
|
|
796
680
|
const orders = Object.keys(orderDirection)[0] === 'hype'
|
|
797
681
|
? orderBook.hype.ask
|
|
798
682
|
: orderBook.flop.ask;
|
|
799
683
|
const sortedOrders = orders.sort((a, b) => Number(a.price) - Number(b.price));
|
|
800
|
-
let totalUSDCNeeded = new bn_js_1.default(0);
|
|
801
|
-
let tempRemainingUSDC = remainingUSDC.clone();
|
|
802
|
-
if (isTrdPayout) {
|
|
803
|
-
for (const order of sortedOrders) {
|
|
804
|
-
if (tempRemainingUSDC.lte(new bn_js_1.default(0)))
|
|
805
|
-
break;
|
|
806
|
-
if (order.authority === this.program.provider.publicKey.toBase58()) {
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
const orderPrice = new bn_js_1.default(order.price);
|
|
810
|
-
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
811
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000);
|
|
812
|
-
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
813
|
-
const maxSharesForPrice = tempRemainingUSDC
|
|
814
|
-
.mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
815
|
-
.div(adjustedPrice);
|
|
816
|
-
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
817
|
-
if (sharesToBuy.lte(new bn_js_1.default(0)))
|
|
818
|
-
continue;
|
|
819
|
-
const usdcAmount = sharesToBuy
|
|
820
|
-
.mul(adjustedPrice)
|
|
821
|
-
.div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)));
|
|
822
|
-
if (usdcAmount.lte(new bn_js_1.default(0)))
|
|
823
|
-
continue;
|
|
824
|
-
totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
|
|
825
|
-
tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
|
|
826
|
-
}
|
|
827
|
-
const price = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
828
|
-
const amountInTRD = totalUSDCNeeded.toNumber() / (price * Math.pow(10, constants_1.BASE_DECIMALS));
|
|
829
|
-
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
830
|
-
connection: this.program.provider.connection,
|
|
831
|
-
wallet: this.program.provider.publicKey.toBase58(),
|
|
832
|
-
inToken: constants_1.TRD_MINT.toString(),
|
|
833
|
-
outToken: constants_1.USDC_MINT.toString(),
|
|
834
|
-
amount: Math.floor(amountInTRD),
|
|
835
|
-
payer: this.rpcOptions.payer.toBase58()
|
|
836
|
-
});
|
|
837
|
-
if (swapIxs.length === 0) {
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
remainingUSDC = new bn_js_1.default(outAmount);
|
|
841
|
-
ixs.push(...setupInstructions);
|
|
842
|
-
ixs.push(...swapIxs);
|
|
843
|
-
addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
|
|
844
|
-
}
|
|
845
684
|
for (const order of sortedOrders) {
|
|
846
685
|
if (remainingUSDC.lte(new bn_js_1.default(0)))
|
|
847
686
|
break;
|
|
@@ -850,7 +689,7 @@ class TriadProtocol {
|
|
|
850
689
|
}
|
|
851
690
|
const orderPrice = new bn_js_1.default(order.price);
|
|
852
691
|
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
853
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000);
|
|
692
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 700);
|
|
854
693
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
855
694
|
const maxSharesForPrice = remainingUSDC
|
|
856
695
|
.mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
@@ -922,7 +761,7 @@ class TriadProtocol {
|
|
|
922
761
|
continue;
|
|
923
762
|
remainingShares = remainingShares.sub(sharesToSell);
|
|
924
763
|
const orderPrice = new bn_js_1.default(order.price);
|
|
925
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000);
|
|
764
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 700);
|
|
926
765
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
927
766
|
amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
|
|
928
767
|
ixs.push(yield this.program.methods
|
|
@@ -990,11 +829,11 @@ class TriadProtocol {
|
|
|
990
829
|
* @param customerId - Customer ID
|
|
991
830
|
* @param feeBps - Fee in basis points
|
|
992
831
|
*/
|
|
993
|
-
updateCustomerFee({ customerId, feeBps }) {
|
|
832
|
+
updateCustomerFee({ customerId, feeBps, feeRecipient }) {
|
|
994
833
|
return __awaiter(this, void 0, void 0, function* () {
|
|
995
834
|
const ixs = [
|
|
996
835
|
yield this.program.methods
|
|
997
|
-
.updateCustomerFee({ id: customerId, feeBps })
|
|
836
|
+
.updateCustomerFee({ id: customerId, feeBps, feeRecipient })
|
|
998
837
|
.accounts({
|
|
999
838
|
signer: this.program.provider.publicKey
|
|
1000
839
|
})
|
|
@@ -1003,5 +842,50 @@ class TriadProtocol {
|
|
|
1003
842
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
1004
843
|
});
|
|
1005
844
|
}
|
|
845
|
+
deposit({ authority, amount, refer = new web3_js_1.PublicKey('EJL7PeGFTAxMY67XrAJfHM8A2euwcjcBAmK94sew61rG'), customer = 7 }) {
|
|
846
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
847
|
+
const ixs = [];
|
|
848
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
|
|
849
|
+
try {
|
|
850
|
+
yield this.program.account.predictor.fetch(predictorPDA);
|
|
851
|
+
}
|
|
852
|
+
catch (e) {
|
|
853
|
+
ixs.push(yield this.program.methods
|
|
854
|
+
.createPredictor({
|
|
855
|
+
customer,
|
|
856
|
+
refer
|
|
857
|
+
})
|
|
858
|
+
.accounts({
|
|
859
|
+
signer: authority,
|
|
860
|
+
payer: this.rpcOptions.payer
|
|
861
|
+
})
|
|
862
|
+
.instruction());
|
|
863
|
+
}
|
|
864
|
+
ixs.push(yield this.program.methods
|
|
865
|
+
.deposit(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
866
|
+
.accounts({
|
|
867
|
+
signer: authority,
|
|
868
|
+
payer: this.rpcOptions.payer,
|
|
869
|
+
predictor: predictorPDA
|
|
870
|
+
})
|
|
871
|
+
.instruction());
|
|
872
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
withdraw({ authority, amount, customer = 7 }) {
|
|
876
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
877
|
+
const ixs = [];
|
|
878
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
|
|
879
|
+
ixs.push(yield this.program.methods
|
|
880
|
+
.withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
881
|
+
.accounts({
|
|
882
|
+
signer: authority,
|
|
883
|
+
payer: this.rpcOptions.payer,
|
|
884
|
+
predictor: predictorPDA
|
|
885
|
+
})
|
|
886
|
+
.instruction());
|
|
887
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
888
|
+
});
|
|
889
|
+
}
|
|
1006
890
|
}
|
|
1007
891
|
exports.default = TriadProtocol;
|
package/dist/stake.d.ts
CHANGED
|
@@ -46,11 +46,6 @@ export default class Stake {
|
|
|
46
46
|
* @param amount - Reward amount to deposit
|
|
47
47
|
*/
|
|
48
48
|
addStakeVaultRewards(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
49
|
-
/**
|
|
50
|
-
* Update Stake Vault Is Locked
|
|
51
|
-
* @param isLocked - Whether the stake vault is locked
|
|
52
|
-
*/
|
|
53
|
-
updateStakeVaultIsLocked(isLocked: boolean): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
54
49
|
/**
|
|
55
50
|
* Request Unstake
|
|
56
51
|
* @param amount - Amount to unstake
|
package/dist/stake.js
CHANGED
|
@@ -107,23 +107,6 @@ class Stake {
|
|
|
107
107
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Update Stake Vault Is Locked
|
|
112
|
-
* @param isLocked - Whether the stake vault is locked
|
|
113
|
-
*/
|
|
114
|
-
updateStakeVaultIsLocked(isLocked) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const ixs = [
|
|
117
|
-
yield this.program.methods
|
|
118
|
-
.updateStakeVaultIsLocked(isLocked)
|
|
119
|
-
.accounts({
|
|
120
|
-
signer: this.program.provider.publicKey
|
|
121
|
-
})
|
|
122
|
-
.instruction()
|
|
123
|
-
];
|
|
124
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
110
|
/**
|
|
128
111
|
* Request Unstake
|
|
129
112
|
* @param amount - Amount to unstake
|