@triadxyz/triad-protocol 3.0.8-beta → 3.1.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -4
- package/dist/index.js +90 -57
- package/dist/types/index.d.ts +27 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,11 @@ export default class TriadProtocolClient {
|
|
|
45
45
|
*
|
|
46
46
|
*/
|
|
47
47
|
getUserOrdersByMarketId(wallet: PublicKey, marketId: number): Promise<import("./types").Order[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Get User Book Orders
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
getUserBookOrders(wallet: PublicKey, marketId: number): Promise<BookOrder[]>;
|
|
48
53
|
/**
|
|
49
54
|
* Get Pool By ID
|
|
50
55
|
* @param poolId - The ID of the pool
|
|
@@ -305,6 +310,7 @@ export default class TriadProtocolClient {
|
|
|
305
310
|
mint: PublicKey;
|
|
306
311
|
shares: number;
|
|
307
312
|
isTrdPayout: boolean;
|
|
313
|
+
isWinner: boolean;
|
|
308
314
|
}[], options?: RpcOptions): Promise<string>;
|
|
309
315
|
/**
|
|
310
316
|
* Allow Market to Payout
|
|
@@ -361,7 +367,7 @@ export default class TriadProtocolClient {
|
|
|
361
367
|
* @param refer - The refer public key
|
|
362
368
|
*
|
|
363
369
|
*/
|
|
364
|
-
getUserTradeIxs(
|
|
370
|
+
getUserTradeIxs(): Promise<{
|
|
365
371
|
userTradePDA: PublicKey;
|
|
366
372
|
ixs: TransactionInstruction[];
|
|
367
373
|
nonce: number;
|
|
@@ -391,7 +397,7 @@ export default class TriadProtocolClient {
|
|
|
391
397
|
*
|
|
392
398
|
* @param options - RPC options
|
|
393
399
|
*/
|
|
394
|
-
placeBidOrder({ marketId,
|
|
400
|
+
placeBidOrder({ marketId, orders, mint, isTrdPayout }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
395
401
|
/**
|
|
396
402
|
* Place Ask Order
|
|
397
403
|
* @param args.marketId - The ID of the Market
|
|
@@ -414,7 +420,7 @@ export default class TriadProtocolClient {
|
|
|
414
420
|
*
|
|
415
421
|
* @param options - RPC options
|
|
416
422
|
*/
|
|
417
|
-
cancelBidOrder({ marketId,
|
|
423
|
+
cancelBidOrder({ marketId, orders, mint }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
418
424
|
/**
|
|
419
425
|
* Cancel Ask Order
|
|
420
426
|
* @param args.marketId - The ID of the Market
|
|
@@ -425,7 +431,7 @@ export default class TriadProtocolClient {
|
|
|
425
431
|
*
|
|
426
432
|
* @param options - RPC options
|
|
427
433
|
*/
|
|
428
|
-
cancelAskOrder({ marketId,
|
|
434
|
+
cancelAskOrder({ marketId, orders }: CancelAskOrderArgs, options?: RpcOptions): Promise<string>;
|
|
429
435
|
/**
|
|
430
436
|
* Market Bid Order
|
|
431
437
|
* @param args.marketId - The ID of the Market
|
package/dist/index.js
CHANGED
|
@@ -113,6 +113,20 @@ class TriadProtocolClient {
|
|
|
113
113
|
return userTrades.flatMap((userTrade) => userTrade.orders.filter((order) => order.marketId === marketId.toString()));
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Get User Book Orders
|
|
118
|
+
*
|
|
119
|
+
*/
|
|
120
|
+
getUserBookOrders(wallet, marketId) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId));
|
|
123
|
+
const orders = [...orderBook.hypeOrders, ...orderBook.flopOrders];
|
|
124
|
+
return orders
|
|
125
|
+
.map((order) => (0, helpers_1.formatBookOrder)(order))
|
|
126
|
+
.filter((order) => order.authority === wallet.toBase58() &&
|
|
127
|
+
order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
|
|
128
|
+
});
|
|
129
|
+
}
|
|
116
130
|
/**
|
|
117
131
|
* Get Pool By ID
|
|
118
132
|
* @param poolId - The ID of the pool
|
|
@@ -496,8 +510,8 @@ class TriadProtocolClient {
|
|
|
496
510
|
payoutOrder(orders, options) {
|
|
497
511
|
return __awaiter(this, void 0, void 0, function* () {
|
|
498
512
|
const ixs = [];
|
|
499
|
-
if (orders.length >
|
|
500
|
-
throw new Error('Max
|
|
513
|
+
if (orders.length > 6) {
|
|
514
|
+
throw new Error('Max 6 orders per transaction');
|
|
501
515
|
}
|
|
502
516
|
for (const order of orders) {
|
|
503
517
|
ixs.push(yield this.program.methods
|
|
@@ -510,13 +524,13 @@ class TriadProtocolClient {
|
|
|
510
524
|
tokenProgram: (0, helpers_1.getTokenProgram)(order.mint)
|
|
511
525
|
})
|
|
512
526
|
.instruction());
|
|
513
|
-
if (order.isTrdPayout) {
|
|
527
|
+
if (order.isTrdPayout && order.isWinner) {
|
|
514
528
|
const { setupInstructions, swapIxs, addressLookupTableAccounts } = yield (0, swap_1.swap)({
|
|
515
529
|
connection: this.program.provider.connection,
|
|
516
530
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
517
531
|
inToken: constants_1.USDC_MINT.toBase58(),
|
|
518
532
|
outToken: constants_1.TRD_MINT.toString(),
|
|
519
|
-
amount: order.shares / Math.pow(10, this.decimals)
|
|
533
|
+
amount: Math.floor(order.shares / Math.pow(10, this.decimals))
|
|
520
534
|
});
|
|
521
535
|
if (swapIxs.length === 0) {
|
|
522
536
|
return;
|
|
@@ -644,8 +658,8 @@ class TriadProtocolClient {
|
|
|
644
658
|
break;
|
|
645
659
|
}
|
|
646
660
|
userTrade.orders.forEach((order) => {
|
|
647
|
-
if (order.orderStatus
|
|
648
|
-
order.orderStatus
|
|
661
|
+
if (order.orderStatus === types_1.OrderStatus.INIT ||
|
|
662
|
+
order.orderStatus === types_1.OrderStatus.CLOSED) {
|
|
649
663
|
nonce = userTrade.isSubUser ? Number(userTrade.nonce) : 0;
|
|
650
664
|
}
|
|
651
665
|
});
|
|
@@ -660,15 +674,12 @@ class TriadProtocolClient {
|
|
|
660
674
|
* @param refer - The refer public key
|
|
661
675
|
*
|
|
662
676
|
*/
|
|
663
|
-
getUserTradeIxs(
|
|
677
|
+
getUserTradeIxs() {
|
|
664
678
|
return __awaiter(this, void 0, void 0, function* () {
|
|
665
679
|
const ixs = [];
|
|
666
680
|
let myUserTrades = [];
|
|
667
681
|
myUserTrades = yield this.getMyUserTrades(this.program.provider.publicKey);
|
|
668
682
|
let referPDA = null;
|
|
669
|
-
if (refer) {
|
|
670
|
-
referPDA = (0, pda_1.getReferPDA)(this.program.programId, refer);
|
|
671
|
-
}
|
|
672
683
|
if (myUserTrades.length === 0) {
|
|
673
684
|
ixs.push(yield this.program.methods
|
|
674
685
|
.createUserTrade()
|
|
@@ -739,14 +750,21 @@ class TriadProtocolClient {
|
|
|
739
750
|
*
|
|
740
751
|
* @param options - RPC options
|
|
741
752
|
*/
|
|
742
|
-
placeBidOrder({ marketId,
|
|
753
|
+
placeBidOrder({ marketId, orders, mint, isTrdPayout }, options) {
|
|
743
754
|
return __awaiter(this, void 0, void 0, function* () {
|
|
744
755
|
const ixs = [];
|
|
745
756
|
const addressLookupTableAccounts = [];
|
|
757
|
+
if (orders.length > 4) {
|
|
758
|
+
throw new Error('You can only place up to 4 orders at a time');
|
|
759
|
+
}
|
|
746
760
|
let amountInUSDC = new bn_js_1.default(0);
|
|
761
|
+
let totalAmount = 0;
|
|
762
|
+
for (const order of orders) {
|
|
763
|
+
totalAmount += order.amount;
|
|
764
|
+
}
|
|
747
765
|
if (isTrdPayout) {
|
|
748
766
|
const trdPrice = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
749
|
-
const amountInTRD = (
|
|
767
|
+
const amountInTRD = (totalAmount / trdPrice) * 1.06;
|
|
750
768
|
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
751
769
|
connection: this.program.provider.connection,
|
|
752
770
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
@@ -761,29 +779,31 @@ class TriadProtocolClient {
|
|
|
761
779
|
ixs.push(...setupInstructions);
|
|
762
780
|
ixs.push(...swapIxs);
|
|
763
781
|
addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
|
|
764
|
-
if (amountInUSDC.lt(new bn_js_1.default(
|
|
782
|
+
if (amountInUSDC.lt(new bn_js_1.default(totalAmount * Math.pow(10, this.decimals)))) {
|
|
765
783
|
return;
|
|
766
784
|
}
|
|
767
785
|
}
|
|
768
|
-
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(direction)[0]);
|
|
786
|
+
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(orders[0].direction)[0]);
|
|
769
787
|
if (userTradeIxs.length > 0) {
|
|
770
788
|
ixs.push(...userTradeIxs);
|
|
771
789
|
}
|
|
772
|
-
|
|
773
|
-
.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
790
|
+
for (const order of orders) {
|
|
791
|
+
ixs.push(yield this.program.methods
|
|
792
|
+
.placeBidOrder({
|
|
793
|
+
amount: new bn_js_1.default(order.amount * Math.pow(10, this.decimals)),
|
|
794
|
+
price: new bn_js_1.default(order.price * Math.pow(10, this.decimals)),
|
|
795
|
+
orderDirection: order.direction
|
|
796
|
+
})
|
|
797
|
+
.accounts({
|
|
798
|
+
signer: this.program.provider.publicKey,
|
|
799
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
800
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
801
|
+
userTrade: userTradePDA,
|
|
802
|
+
mint,
|
|
803
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
804
|
+
})
|
|
805
|
+
.instruction());
|
|
806
|
+
}
|
|
787
807
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
788
808
|
});
|
|
789
809
|
}
|
|
@@ -802,6 +822,9 @@ class TriadProtocolClient {
|
|
|
802
822
|
placeAskOrder({ marketId, orders }, options) {
|
|
803
823
|
return __awaiter(this, void 0, void 0, function* () {
|
|
804
824
|
const ixs = [];
|
|
825
|
+
if (orders.length > 4) {
|
|
826
|
+
throw new Error('You can only place up to 4 orders at a time');
|
|
827
|
+
}
|
|
805
828
|
for (const order of orders) {
|
|
806
829
|
ixs.push(yield this.program.methods
|
|
807
830
|
.placeAskOrder({
|
|
@@ -829,23 +852,28 @@ class TriadProtocolClient {
|
|
|
829
852
|
*
|
|
830
853
|
* @param options - RPC options
|
|
831
854
|
*/
|
|
832
|
-
cancelBidOrder({ marketId,
|
|
855
|
+
cancelBidOrder({ marketId, orders, mint }, options) {
|
|
833
856
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834
857
|
const ixs = [];
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
858
|
+
if (orders.length > 4) {
|
|
859
|
+
throw new Error('You can only cancel up to 4 orders at a time');
|
|
860
|
+
}
|
|
861
|
+
for (const order of orders) {
|
|
862
|
+
ixs.push(yield this.program.methods
|
|
863
|
+
.cancelBidOrder({
|
|
864
|
+
orderId: new bn_js_1.default(order.orderId),
|
|
865
|
+
orderDirection: order.direction
|
|
866
|
+
})
|
|
867
|
+
.accounts({
|
|
868
|
+
signer: this.program.provider.publicKey,
|
|
869
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
870
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
871
|
+
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce),
|
|
872
|
+
mint,
|
|
873
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
874
|
+
})
|
|
875
|
+
.instruction());
|
|
876
|
+
}
|
|
849
877
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
850
878
|
});
|
|
851
879
|
}
|
|
@@ -859,21 +887,26 @@ class TriadProtocolClient {
|
|
|
859
887
|
*
|
|
860
888
|
* @param options - RPC options
|
|
861
889
|
*/
|
|
862
|
-
cancelAskOrder({ marketId,
|
|
890
|
+
cancelAskOrder({ marketId, orders }, options) {
|
|
863
891
|
return __awaiter(this, void 0, void 0, function* () {
|
|
864
892
|
const ixs = [];
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
893
|
+
if (orders.length > 4) {
|
|
894
|
+
throw new Error('You can only cancel up to 4 orders at a time');
|
|
895
|
+
}
|
|
896
|
+
for (const order of orders) {
|
|
897
|
+
ixs.push(yield this.program.methods
|
|
898
|
+
.cancelAskOrder({
|
|
899
|
+
orderId: new bn_js_1.default(order.orderId),
|
|
900
|
+
orderDirection: order.direction
|
|
901
|
+
})
|
|
902
|
+
.accounts({
|
|
903
|
+
signer: this.program.provider.publicKey,
|
|
904
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
905
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
906
|
+
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
|
|
907
|
+
})
|
|
908
|
+
.instruction());
|
|
909
|
+
}
|
|
877
910
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
878
911
|
});
|
|
879
912
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -108,13 +108,15 @@ export declare enum OrderSide {
|
|
|
108
108
|
}
|
|
109
109
|
export type PlaceBidOrderArgs = {
|
|
110
110
|
marketId: number;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
orders: {
|
|
112
|
+
amount: number;
|
|
113
|
+
price: number;
|
|
114
|
+
direction: {
|
|
115
|
+
hype: {};
|
|
116
|
+
} | {
|
|
117
|
+
flop: {};
|
|
118
|
+
};
|
|
119
|
+
}[];
|
|
118
120
|
mint: PublicKey;
|
|
119
121
|
isTrdPayout: boolean;
|
|
120
122
|
};
|
|
@@ -188,24 +190,28 @@ export type CreatePoolArgs = {
|
|
|
188
190
|
};
|
|
189
191
|
export type CancelBidOrderArgs = {
|
|
190
192
|
marketId: number;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
orders: {
|
|
194
|
+
orderId: number;
|
|
195
|
+
userNonce: number;
|
|
196
|
+
direction: {
|
|
197
|
+
hype: {};
|
|
198
|
+
} | {
|
|
199
|
+
flop: {};
|
|
200
|
+
};
|
|
201
|
+
}[];
|
|
193
202
|
mint: PublicKey;
|
|
194
|
-
direction: {
|
|
195
|
-
hype: {};
|
|
196
|
-
} | {
|
|
197
|
-
flop: {};
|
|
198
|
-
};
|
|
199
203
|
};
|
|
200
204
|
export type CancelAskOrderArgs = {
|
|
201
205
|
marketId: number;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
orders: {
|
|
207
|
+
orderId: number;
|
|
208
|
+
userNonce: number;
|
|
209
|
+
direction: {
|
|
210
|
+
hype: {};
|
|
211
|
+
} | {
|
|
212
|
+
flop: {};
|
|
213
|
+
};
|
|
214
|
+
}[];
|
|
209
215
|
};
|
|
210
216
|
export type MarketBidOrderArgs = {
|
|
211
217
|
marketId: number;
|