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