@triadxyz/triad-protocol 3.0.9-beta → 3.1.1-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 +12 -22
- package/dist/index.js +89 -103
- package/dist/types/idl_triad_protocol.json +5 -134
- package/dist/types/index.d.ts +27 -28
- package/dist/types/triad_protocol.d.ts +5 -134
- package/dist/utils/helpers.d.ts +1 -2
- package/dist/utils/helpers.js +1 -11
- package/dist/utils/pda/index.d.ts +0 -1
- package/dist/utils/pda/index.js +1 -5
- 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
|
|
@@ -75,12 +80,6 @@ export default class TriadProtocolClient {
|
|
|
75
80
|
*
|
|
76
81
|
*/
|
|
77
82
|
getCustomerById(customerId: number): Promise<import("./types").Customer>;
|
|
78
|
-
/**
|
|
79
|
-
* Get Refer By Wallet Address
|
|
80
|
-
* @param wallet - The wallet address of the refer
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
getReferByWallet(wallet: PublicKey): Promise<import("./types").Refer>;
|
|
84
83
|
/**
|
|
85
84
|
* Get Current Market ID
|
|
86
85
|
*
|
|
@@ -114,7 +113,7 @@ export default class TriadProtocolClient {
|
|
|
114
113
|
authority: PublicKey;
|
|
115
114
|
totalDeposits: BN;
|
|
116
115
|
totalWithdraws: BN;
|
|
117
|
-
|
|
116
|
+
padding1: number[];
|
|
118
117
|
orders: {
|
|
119
118
|
ts: BN;
|
|
120
119
|
orderId: BN;
|
|
@@ -293,7 +292,8 @@ export default class TriadProtocolClient {
|
|
|
293
292
|
* @param args.marketId - The ID of the Market
|
|
294
293
|
* @param args.orderId - The ID of the Order to Payout
|
|
295
294
|
* @param args.userNonce - The nonce of the user
|
|
296
|
-
* @param args.
|
|
295
|
+
* @param args.mint - The mint of the market
|
|
296
|
+
* @param args.shares - The shares of the order
|
|
297
297
|
*
|
|
298
298
|
* @param options - RPC options
|
|
299
299
|
*
|
|
@@ -304,8 +304,6 @@ export default class TriadProtocolClient {
|
|
|
304
304
|
userNonce: number;
|
|
305
305
|
mint: PublicKey;
|
|
306
306
|
shares: number;
|
|
307
|
-
isTrdPayout: boolean;
|
|
308
|
-
isWinner: boolean;
|
|
309
307
|
}[], options?: RpcOptions): Promise<string>;
|
|
310
308
|
/**
|
|
311
309
|
* Allow Market to Payout
|
|
@@ -359,10 +357,9 @@ export default class TriadProtocolClient {
|
|
|
359
357
|
getUserTradeNonceWithSlots(userTrades: UserTrade[]): PublicKey;
|
|
360
358
|
/**
|
|
361
359
|
* Get User Trade Ixs
|
|
362
|
-
* @param refer - The refer public key
|
|
363
360
|
*
|
|
364
361
|
*/
|
|
365
|
-
getUserTradeIxs(
|
|
362
|
+
getUserTradeIxs(): Promise<{
|
|
366
363
|
userTradePDA: PublicKey;
|
|
367
364
|
ixs: TransactionInstruction[];
|
|
368
365
|
nonce: number;
|
|
@@ -392,7 +389,7 @@ export default class TriadProtocolClient {
|
|
|
392
389
|
*
|
|
393
390
|
* @param options - RPC options
|
|
394
391
|
*/
|
|
395
|
-
placeBidOrder({ marketId,
|
|
392
|
+
placeBidOrder({ marketId, orders, mint, isTrdPayout }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
396
393
|
/**
|
|
397
394
|
* Place Ask Order
|
|
398
395
|
* @param args.marketId - The ID of the Market
|
|
@@ -415,7 +412,7 @@ export default class TriadProtocolClient {
|
|
|
415
412
|
*
|
|
416
413
|
* @param options - RPC options
|
|
417
414
|
*/
|
|
418
|
-
cancelBidOrder({ marketId,
|
|
415
|
+
cancelBidOrder({ marketId, orders, mint }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
419
416
|
/**
|
|
420
417
|
* Cancel Ask Order
|
|
421
418
|
* @param args.marketId - The ID of the Market
|
|
@@ -426,7 +423,7 @@ export default class TriadProtocolClient {
|
|
|
426
423
|
*
|
|
427
424
|
* @param options - RPC options
|
|
428
425
|
*/
|
|
429
|
-
cancelAskOrder({ marketId,
|
|
426
|
+
cancelAskOrder({ marketId, orders }: CancelAskOrderArgs, options?: RpcOptions): Promise<string>;
|
|
430
427
|
/**
|
|
431
428
|
* Market Bid Order
|
|
432
429
|
* @param args.marketId - The ID of the Market
|
|
@@ -491,13 +488,6 @@ export default class TriadProtocolClient {
|
|
|
491
488
|
* @param options - RPC options
|
|
492
489
|
*/
|
|
493
490
|
closeOrderBook(marketIds: number[], options?: RpcOptions): Promise<string>;
|
|
494
|
-
/**
|
|
495
|
-
* Create Refer
|
|
496
|
-
* @param id - The ID of the refer
|
|
497
|
-
*
|
|
498
|
-
* @param options - RPC options
|
|
499
|
-
*/
|
|
500
|
-
createRefer(options?: RpcOptions): Promise<string>;
|
|
501
491
|
/**
|
|
502
492
|
* Update Customer Fee
|
|
503
493
|
* @param feeBps - The fee in basis points
|
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
|
|
@@ -178,18 +192,6 @@ class TriadProtocolClient {
|
|
|
178
192
|
return (0, helpers_1.formatCustomer)(customer, customerPDA);
|
|
179
193
|
});
|
|
180
194
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Get Refer By Wallet Address
|
|
183
|
-
* @param wallet - The wallet address of the refer
|
|
184
|
-
*
|
|
185
|
-
*/
|
|
186
|
-
getReferByWallet(wallet) {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const referPDA = (0, pda_1.getReferPDA)(this.program.programId, wallet);
|
|
189
|
-
const refer = yield this.program.account.refer.fetch(referPDA);
|
|
190
|
-
return (0, helpers_1.formatRefer)(refer);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
195
|
/**
|
|
194
196
|
* Get Current Market ID
|
|
195
197
|
*
|
|
@@ -488,7 +490,8 @@ class TriadProtocolClient {
|
|
|
488
490
|
* @param args.marketId - The ID of the Market
|
|
489
491
|
* @param args.orderId - The ID of the Order to Payout
|
|
490
492
|
* @param args.userNonce - The nonce of the user
|
|
491
|
-
* @param args.
|
|
493
|
+
* @param args.mint - The mint of the market
|
|
494
|
+
* @param args.shares - The shares of the order
|
|
492
495
|
*
|
|
493
496
|
* @param options - RPC options
|
|
494
497
|
*
|
|
@@ -510,21 +513,6 @@ class TriadProtocolClient {
|
|
|
510
513
|
tokenProgram: (0, helpers_1.getTokenProgram)(order.mint)
|
|
511
514
|
})
|
|
512
515
|
.instruction());
|
|
513
|
-
if (order.isTrdPayout && order.isWinner) {
|
|
514
|
-
const { setupInstructions, swapIxs, addressLookupTableAccounts } = yield (0, swap_1.swap)({
|
|
515
|
-
connection: this.program.provider.connection,
|
|
516
|
-
wallet: this.program.provider.publicKey.toBase58(),
|
|
517
|
-
inToken: constants_1.USDC_MINT.toBase58(),
|
|
518
|
-
outToken: constants_1.TRD_MINT.toString(),
|
|
519
|
-
amount: order.shares / Math.pow(10, this.decimals)
|
|
520
|
-
});
|
|
521
|
-
if (swapIxs.length === 0) {
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
ixs.push(...setupInstructions);
|
|
525
|
-
ixs.push(...swapIxs);
|
|
526
|
-
addressLookupTableAccounts.push(...addressLookupTableAccounts);
|
|
527
|
-
}
|
|
528
516
|
}
|
|
529
517
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
530
518
|
});
|
|
@@ -644,8 +632,8 @@ class TriadProtocolClient {
|
|
|
644
632
|
break;
|
|
645
633
|
}
|
|
646
634
|
userTrade.orders.forEach((order) => {
|
|
647
|
-
if (order.orderStatus
|
|
648
|
-
order.orderStatus
|
|
635
|
+
if (order.orderStatus === types_1.OrderStatus.INIT ||
|
|
636
|
+
order.orderStatus === types_1.OrderStatus.CLOSED) {
|
|
649
637
|
nonce = userTrade.isSubUser ? Number(userTrade.nonce) : 0;
|
|
650
638
|
}
|
|
651
639
|
});
|
|
@@ -657,24 +645,18 @@ class TriadProtocolClient {
|
|
|
657
645
|
}
|
|
658
646
|
/**
|
|
659
647
|
* Get User Trade Ixs
|
|
660
|
-
* @param refer - The refer public key
|
|
661
648
|
*
|
|
662
649
|
*/
|
|
663
|
-
getUserTradeIxs(
|
|
650
|
+
getUserTradeIxs() {
|
|
664
651
|
return __awaiter(this, void 0, void 0, function* () {
|
|
665
652
|
const ixs = [];
|
|
666
653
|
let myUserTrades = [];
|
|
667
654
|
myUserTrades = yield this.getMyUserTrades(this.program.provider.publicKey);
|
|
668
|
-
let referPDA = null;
|
|
669
|
-
if (refer) {
|
|
670
|
-
referPDA = (0, pda_1.getReferPDA)(this.program.programId, refer);
|
|
671
|
-
}
|
|
672
655
|
if (myUserTrades.length === 0) {
|
|
673
656
|
ixs.push(yield this.program.methods
|
|
674
657
|
.createUserTrade()
|
|
675
658
|
.accounts({
|
|
676
|
-
signer: this.program.provider.publicKey
|
|
677
|
-
refer: referPDA
|
|
659
|
+
signer: this.program.provider.publicKey
|
|
678
660
|
})
|
|
679
661
|
.instruction());
|
|
680
662
|
return {
|
|
@@ -739,14 +721,21 @@ class TriadProtocolClient {
|
|
|
739
721
|
*
|
|
740
722
|
* @param options - RPC options
|
|
741
723
|
*/
|
|
742
|
-
placeBidOrder({ marketId,
|
|
724
|
+
placeBidOrder({ marketId, orders, mint, isTrdPayout }, options) {
|
|
743
725
|
return __awaiter(this, void 0, void 0, function* () {
|
|
744
726
|
const ixs = [];
|
|
745
727
|
const addressLookupTableAccounts = [];
|
|
728
|
+
if (orders.length > 4) {
|
|
729
|
+
throw new Error('You can only place up to 4 orders at a time');
|
|
730
|
+
}
|
|
746
731
|
let amountInUSDC = new bn_js_1.default(0);
|
|
732
|
+
let totalAmount = 0;
|
|
733
|
+
for (const order of orders) {
|
|
734
|
+
totalAmount += order.amount;
|
|
735
|
+
}
|
|
747
736
|
if (isTrdPayout) {
|
|
748
737
|
const trdPrice = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
749
|
-
const amountInTRD = (
|
|
738
|
+
const amountInTRD = (totalAmount / trdPrice) * 1.06;
|
|
750
739
|
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
751
740
|
connection: this.program.provider.connection,
|
|
752
741
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
@@ -761,29 +750,31 @@ class TriadProtocolClient {
|
|
|
761
750
|
ixs.push(...setupInstructions);
|
|
762
751
|
ixs.push(...swapIxs);
|
|
763
752
|
addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
|
|
764
|
-
if (amountInUSDC.lt(new bn_js_1.default(
|
|
753
|
+
if (amountInUSDC.lt(new bn_js_1.default(totalAmount * Math.pow(10, this.decimals)))) {
|
|
765
754
|
return;
|
|
766
755
|
}
|
|
767
756
|
}
|
|
768
|
-
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(direction)[0]);
|
|
757
|
+
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(orders[0].direction)[0]);
|
|
769
758
|
if (userTradeIxs.length > 0) {
|
|
770
759
|
ixs.push(...userTradeIxs);
|
|
771
760
|
}
|
|
772
|
-
|
|
773
|
-
.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
761
|
+
for (const order of orders) {
|
|
762
|
+
ixs.push(yield this.program.methods
|
|
763
|
+
.placeBidOrder({
|
|
764
|
+
amount: new bn_js_1.default(order.amount * Math.pow(10, this.decimals)),
|
|
765
|
+
price: new bn_js_1.default(order.price * Math.pow(10, this.decimals)),
|
|
766
|
+
orderDirection: order.direction
|
|
767
|
+
})
|
|
768
|
+
.accounts({
|
|
769
|
+
signer: this.program.provider.publicKey,
|
|
770
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
771
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
772
|
+
userTrade: userTradePDA,
|
|
773
|
+
mint,
|
|
774
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
775
|
+
})
|
|
776
|
+
.instruction());
|
|
777
|
+
}
|
|
787
778
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
788
779
|
});
|
|
789
780
|
}
|
|
@@ -802,6 +793,9 @@ class TriadProtocolClient {
|
|
|
802
793
|
placeAskOrder({ marketId, orders }, options) {
|
|
803
794
|
return __awaiter(this, void 0, void 0, function* () {
|
|
804
795
|
const ixs = [];
|
|
796
|
+
if (orders.length > 4) {
|
|
797
|
+
throw new Error('You can only place up to 4 orders at a time');
|
|
798
|
+
}
|
|
805
799
|
for (const order of orders) {
|
|
806
800
|
ixs.push(yield this.program.methods
|
|
807
801
|
.placeAskOrder({
|
|
@@ -829,23 +823,28 @@ class TriadProtocolClient {
|
|
|
829
823
|
*
|
|
830
824
|
* @param options - RPC options
|
|
831
825
|
*/
|
|
832
|
-
cancelBidOrder({ marketId,
|
|
826
|
+
cancelBidOrder({ marketId, orders, mint }, options) {
|
|
833
827
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834
828
|
const ixs = [];
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
829
|
+
if (orders.length > 4) {
|
|
830
|
+
throw new Error('You can only cancel up to 4 orders at a time');
|
|
831
|
+
}
|
|
832
|
+
for (const order of orders) {
|
|
833
|
+
ixs.push(yield this.program.methods
|
|
834
|
+
.cancelBidOrder({
|
|
835
|
+
orderId: new bn_js_1.default(order.orderId),
|
|
836
|
+
orderDirection: order.direction
|
|
837
|
+
})
|
|
838
|
+
.accounts({
|
|
839
|
+
signer: this.program.provider.publicKey,
|
|
840
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
841
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
842
|
+
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce),
|
|
843
|
+
mint,
|
|
844
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
845
|
+
})
|
|
846
|
+
.instruction());
|
|
847
|
+
}
|
|
849
848
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
850
849
|
});
|
|
851
850
|
}
|
|
@@ -859,21 +858,26 @@ class TriadProtocolClient {
|
|
|
859
858
|
*
|
|
860
859
|
* @param options - RPC options
|
|
861
860
|
*/
|
|
862
|
-
cancelAskOrder({ marketId,
|
|
861
|
+
cancelAskOrder({ marketId, orders }, options) {
|
|
863
862
|
return __awaiter(this, void 0, void 0, function* () {
|
|
864
863
|
const ixs = [];
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
864
|
+
if (orders.length > 4) {
|
|
865
|
+
throw new Error('You can only cancel up to 4 orders at a time');
|
|
866
|
+
}
|
|
867
|
+
for (const order of orders) {
|
|
868
|
+
ixs.push(yield this.program.methods
|
|
869
|
+
.cancelAskOrder({
|
|
870
|
+
orderId: new bn_js_1.default(order.orderId),
|
|
871
|
+
orderDirection: order.direction
|
|
872
|
+
})
|
|
873
|
+
.accounts({
|
|
874
|
+
signer: this.program.provider.publicKey,
|
|
875
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
876
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
877
|
+
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
|
|
878
|
+
})
|
|
879
|
+
.instruction());
|
|
880
|
+
}
|
|
877
881
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
878
882
|
});
|
|
879
883
|
}
|
|
@@ -1194,24 +1198,6 @@ class TriadProtocolClient {
|
|
|
1194
1198
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
1195
1199
|
});
|
|
1196
1200
|
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Create Refer
|
|
1199
|
-
* @param id - The ID of the refer
|
|
1200
|
-
*
|
|
1201
|
-
* @param options - RPC options
|
|
1202
|
-
*/
|
|
1203
|
-
createRefer(options) {
|
|
1204
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1205
|
-
const ixs = [];
|
|
1206
|
-
ixs.push(yield this.program.methods
|
|
1207
|
-
.createRefer()
|
|
1208
|
-
.accounts({
|
|
1209
|
-
signer: this.program.provider.publicKey
|
|
1210
|
-
})
|
|
1211
|
-
.instruction());
|
|
1212
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
1201
|
/**
|
|
1216
1202
|
* Update Customer Fee
|
|
1217
1203
|
* @param feeBps - The fee in basis points
|
|
@@ -919,50 +919,6 @@
|
|
|
919
919
|
}
|
|
920
920
|
]
|
|
921
921
|
},
|
|
922
|
-
{
|
|
923
|
-
"name": "create_refer",
|
|
924
|
-
"discriminator": [63, 215, 18, 129, 0, 78, 205, 88],
|
|
925
|
-
"accounts": [
|
|
926
|
-
{
|
|
927
|
-
"name": "signer",
|
|
928
|
-
"writable": true,
|
|
929
|
-
"signer": true
|
|
930
|
-
},
|
|
931
|
-
{
|
|
932
|
-
"name": "global",
|
|
933
|
-
"writable": true,
|
|
934
|
-
"pda": {
|
|
935
|
-
"seeds": [
|
|
936
|
-
{
|
|
937
|
-
"kind": "const",
|
|
938
|
-
"value": [103, 108, 111, 98, 97, 108]
|
|
939
|
-
}
|
|
940
|
-
]
|
|
941
|
-
}
|
|
942
|
-
},
|
|
943
|
-
{
|
|
944
|
-
"name": "refer",
|
|
945
|
-
"writable": true,
|
|
946
|
-
"pda": {
|
|
947
|
-
"seeds": [
|
|
948
|
-
{
|
|
949
|
-
"kind": "const",
|
|
950
|
-
"value": [114, 101, 102, 101, 114]
|
|
951
|
-
},
|
|
952
|
-
{
|
|
953
|
-
"kind": "account",
|
|
954
|
-
"path": "signer"
|
|
955
|
-
}
|
|
956
|
-
]
|
|
957
|
-
}
|
|
958
|
-
},
|
|
959
|
-
{
|
|
960
|
-
"name": "system_program",
|
|
961
|
-
"address": "11111111111111111111111111111111"
|
|
962
|
-
}
|
|
963
|
-
],
|
|
964
|
-
"args": []
|
|
965
|
-
},
|
|
966
922
|
{
|
|
967
923
|
"name": "create_sub_user_trade",
|
|
968
924
|
"discriminator": [77, 201, 111, 73, 47, 229, 244, 161],
|
|
@@ -1041,11 +997,6 @@
|
|
|
1041
997
|
]
|
|
1042
998
|
}
|
|
1043
999
|
},
|
|
1044
|
-
{
|
|
1045
|
-
"name": "refer",
|
|
1046
|
-
"writable": true,
|
|
1047
|
-
"optional": true
|
|
1048
|
-
},
|
|
1049
1000
|
{
|
|
1050
1001
|
"name": "system_program",
|
|
1051
1002
|
"address": "11111111111111111111111111111111"
|
|
@@ -2220,10 +2171,6 @@
|
|
|
2220
2171
|
"name": "Customer",
|
|
2221
2172
|
"discriminator": [112, 147, 140, 31, 93, 186, 103, 18]
|
|
2222
2173
|
},
|
|
2223
|
-
{
|
|
2224
|
-
"name": "Global",
|
|
2225
|
-
"discriminator": [167, 232, 232, 177, 200, 108, 114, 127]
|
|
2226
|
-
},
|
|
2227
2174
|
{
|
|
2228
2175
|
"name": "MarketV2",
|
|
2229
2176
|
"discriminator": [27, 60, 50, 75, 191, 193, 86, 227]
|
|
@@ -2240,10 +2187,6 @@
|
|
|
2240
2187
|
"name": "Pool",
|
|
2241
2188
|
"discriminator": [241, 154, 109, 4, 17, 177, 109, 188]
|
|
2242
2189
|
},
|
|
2243
|
-
{
|
|
2244
|
-
"name": "Refer",
|
|
2245
|
-
"discriminator": [5, 204, 50, 144, 77, 136, 87, 66]
|
|
2246
|
-
},
|
|
2247
2190
|
{
|
|
2248
2191
|
"name": "StakeV3",
|
|
2249
2192
|
"discriminator": [33, 54, 166, 108, 88, 184, 96, 190]
|
|
@@ -2839,9 +2782,7 @@
|
|
|
2839
2782
|
},
|
|
2840
2783
|
{
|
|
2841
2784
|
"name": "fee_bps",
|
|
2842
|
-
"docs": [
|
|
2843
|
-
"Fee in basis points to receive from the market fee available"
|
|
2844
|
-
],
|
|
2785
|
+
"docs": ["Fee in basis points to receive from the market fee"],
|
|
2845
2786
|
"type": "u16"
|
|
2846
2787
|
},
|
|
2847
2788
|
{
|
|
@@ -2857,40 +2798,6 @@
|
|
|
2857
2798
|
]
|
|
2858
2799
|
}
|
|
2859
2800
|
},
|
|
2860
|
-
{
|
|
2861
|
-
"name": "Global",
|
|
2862
|
-
"type": {
|
|
2863
|
-
"kind": "struct",
|
|
2864
|
-
"fields": [
|
|
2865
|
-
{
|
|
2866
|
-
"name": "bump",
|
|
2867
|
-
"type": "u8"
|
|
2868
|
-
},
|
|
2869
|
-
{
|
|
2870
|
-
"name": "authority",
|
|
2871
|
-
"type": "pubkey"
|
|
2872
|
-
},
|
|
2873
|
-
{
|
|
2874
|
-
"name": "next_refer_id",
|
|
2875
|
-
"type": "u64"
|
|
2876
|
-
},
|
|
2877
|
-
{
|
|
2878
|
-
"name": "trd_price",
|
|
2879
|
-
"type": "u64"
|
|
2880
|
-
},
|
|
2881
|
-
{
|
|
2882
|
-
"name": "trd_price_ts",
|
|
2883
|
-
"type": "i64"
|
|
2884
|
-
},
|
|
2885
|
-
{
|
|
2886
|
-
"name": "padding",
|
|
2887
|
-
"type": {
|
|
2888
|
-
"array": ["u8", 428]
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
]
|
|
2892
|
-
}
|
|
2893
|
-
},
|
|
2894
2801
|
{
|
|
2895
2802
|
"name": "Key",
|
|
2896
2803
|
"type": {
|
|
@@ -3744,44 +3651,6 @@
|
|
|
3744
3651
|
]
|
|
3745
3652
|
}
|
|
3746
3653
|
},
|
|
3747
|
-
{
|
|
3748
|
-
"name": "Refer",
|
|
3749
|
-
"type": {
|
|
3750
|
-
"kind": "struct",
|
|
3751
|
-
"fields": [
|
|
3752
|
-
{
|
|
3753
|
-
"name": "bump",
|
|
3754
|
-
"type": "u8"
|
|
3755
|
-
},
|
|
3756
|
-
{
|
|
3757
|
-
"name": "id",
|
|
3758
|
-
"type": "u64"
|
|
3759
|
-
},
|
|
3760
|
-
{
|
|
3761
|
-
"name": "authority",
|
|
3762
|
-
"type": "pubkey"
|
|
3763
|
-
},
|
|
3764
|
-
{
|
|
3765
|
-
"name": "fee_bps",
|
|
3766
|
-
"type": "u16"
|
|
3767
|
-
},
|
|
3768
|
-
{
|
|
3769
|
-
"name": "fee_claimed",
|
|
3770
|
-
"type": "u64"
|
|
3771
|
-
},
|
|
3772
|
-
{
|
|
3773
|
-
"name": "users_referred",
|
|
3774
|
-
"type": "u64"
|
|
3775
|
-
},
|
|
3776
|
-
{
|
|
3777
|
-
"name": "padding",
|
|
3778
|
-
"type": {
|
|
3779
|
-
"array": ["u8", 24]
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
]
|
|
3783
|
-
}
|
|
3784
|
-
},
|
|
3785
3654
|
{
|
|
3786
3655
|
"name": "RequestUnstakeArgs",
|
|
3787
3656
|
"type": {
|
|
@@ -4073,8 +3942,10 @@
|
|
|
4073
3942
|
"type": "u64"
|
|
4074
3943
|
},
|
|
4075
3944
|
{
|
|
4076
|
-
"name": "
|
|
4077
|
-
"type":
|
|
3945
|
+
"name": "padding_1",
|
|
3946
|
+
"type": {
|
|
3947
|
+
"array": ["u8", 8]
|
|
3948
|
+
}
|
|
4078
3949
|
},
|
|
4079
3950
|
{
|
|
4080
3951
|
"name": "orders",
|
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;
|
|
@@ -234,13 +240,6 @@ export type MarketAskOrderArgs = {
|
|
|
234
240
|
isTrdPayout: boolean;
|
|
235
241
|
feeBps: number;
|
|
236
242
|
};
|
|
237
|
-
export type Refer = {
|
|
238
|
-
id: number;
|
|
239
|
-
authority: string;
|
|
240
|
-
feeBps: number;
|
|
241
|
-
feeClaimed: number;
|
|
242
|
-
usersReferred: number;
|
|
243
|
-
};
|
|
244
243
|
export type Customer = {
|
|
245
244
|
id: number;
|
|
246
245
|
authority: string;
|
|
@@ -1285,50 +1285,6 @@ export type TriadProtocol = {
|
|
|
1285
1285
|
}
|
|
1286
1286
|
];
|
|
1287
1287
|
},
|
|
1288
|
-
{
|
|
1289
|
-
name: 'createRefer';
|
|
1290
|
-
discriminator: [63, 215, 18, 129, 0, 78, 205, 88];
|
|
1291
|
-
accounts: [
|
|
1292
|
-
{
|
|
1293
|
-
name: 'signer';
|
|
1294
|
-
writable: true;
|
|
1295
|
-
signer: true;
|
|
1296
|
-
},
|
|
1297
|
-
{
|
|
1298
|
-
name: 'global';
|
|
1299
|
-
writable: true;
|
|
1300
|
-
pda: {
|
|
1301
|
-
seeds: [
|
|
1302
|
-
{
|
|
1303
|
-
kind: 'const';
|
|
1304
|
-
value: [103, 108, 111, 98, 97, 108];
|
|
1305
|
-
}
|
|
1306
|
-
];
|
|
1307
|
-
};
|
|
1308
|
-
},
|
|
1309
|
-
{
|
|
1310
|
-
name: 'refer';
|
|
1311
|
-
writable: true;
|
|
1312
|
-
pda: {
|
|
1313
|
-
seeds: [
|
|
1314
|
-
{
|
|
1315
|
-
kind: 'const';
|
|
1316
|
-
value: [114, 101, 102, 101, 114];
|
|
1317
|
-
},
|
|
1318
|
-
{
|
|
1319
|
-
kind: 'account';
|
|
1320
|
-
path: 'signer';
|
|
1321
|
-
}
|
|
1322
|
-
];
|
|
1323
|
-
};
|
|
1324
|
-
},
|
|
1325
|
-
{
|
|
1326
|
-
name: 'systemProgram';
|
|
1327
|
-
address: '11111111111111111111111111111111';
|
|
1328
|
-
}
|
|
1329
|
-
];
|
|
1330
|
-
args: [];
|
|
1331
|
-
},
|
|
1332
1288
|
{
|
|
1333
1289
|
name: 'createSubUserTrade';
|
|
1334
1290
|
discriminator: [77, 201, 111, 73, 47, 229, 244, 161];
|
|
@@ -1407,11 +1363,6 @@ export type TriadProtocol = {
|
|
|
1407
1363
|
];
|
|
1408
1364
|
};
|
|
1409
1365
|
},
|
|
1410
|
-
{
|
|
1411
|
-
name: 'refer';
|
|
1412
|
-
writable: true;
|
|
1413
|
-
optional: true;
|
|
1414
|
-
},
|
|
1415
1366
|
{
|
|
1416
1367
|
name: 'systemProgram';
|
|
1417
1368
|
address: '11111111111111111111111111111111';
|
|
@@ -3040,10 +2991,6 @@ export type TriadProtocol = {
|
|
|
3040
2991
|
name: 'customer';
|
|
3041
2992
|
discriminator: [112, 147, 140, 31, 93, 186, 103, 18];
|
|
3042
2993
|
},
|
|
3043
|
-
{
|
|
3044
|
-
name: 'global';
|
|
3045
|
-
discriminator: [167, 232, 232, 177, 200, 108, 114, 127];
|
|
3046
|
-
},
|
|
3047
2994
|
{
|
|
3048
2995
|
name: 'marketV2';
|
|
3049
2996
|
discriminator: [27, 60, 50, 75, 191, 193, 86, 227];
|
|
@@ -3060,10 +3007,6 @@ export type TriadProtocol = {
|
|
|
3060
3007
|
name: 'pool';
|
|
3061
3008
|
discriminator: [241, 154, 109, 4, 17, 177, 109, 188];
|
|
3062
3009
|
},
|
|
3063
|
-
{
|
|
3064
|
-
name: 'refer';
|
|
3065
|
-
discriminator: [5, 204, 50, 144, 77, 136, 87, 66];
|
|
3066
|
-
},
|
|
3067
3010
|
{
|
|
3068
3011
|
name: 'stakeV3';
|
|
3069
3012
|
discriminator: [33, 54, 166, 108, 88, 184, 96, 190];
|
|
@@ -3659,9 +3602,7 @@ export type TriadProtocol = {
|
|
|
3659
3602
|
},
|
|
3660
3603
|
{
|
|
3661
3604
|
name: 'feeBps';
|
|
3662
|
-
docs: [
|
|
3663
|
-
'Fee in basis points to receive from the market fee available'
|
|
3664
|
-
];
|
|
3605
|
+
docs: ['Fee in basis points to receive from the market fee'];
|
|
3665
3606
|
type: 'u16';
|
|
3666
3607
|
},
|
|
3667
3608
|
{
|
|
@@ -3677,40 +3618,6 @@ export type TriadProtocol = {
|
|
|
3677
3618
|
];
|
|
3678
3619
|
};
|
|
3679
3620
|
},
|
|
3680
|
-
{
|
|
3681
|
-
name: 'global';
|
|
3682
|
-
type: {
|
|
3683
|
-
kind: 'struct';
|
|
3684
|
-
fields: [
|
|
3685
|
-
{
|
|
3686
|
-
name: 'bump';
|
|
3687
|
-
type: 'u8';
|
|
3688
|
-
},
|
|
3689
|
-
{
|
|
3690
|
-
name: 'authority';
|
|
3691
|
-
type: 'pubkey';
|
|
3692
|
-
},
|
|
3693
|
-
{
|
|
3694
|
-
name: 'nextReferId';
|
|
3695
|
-
type: 'u64';
|
|
3696
|
-
},
|
|
3697
|
-
{
|
|
3698
|
-
name: 'trdPrice';
|
|
3699
|
-
type: 'u64';
|
|
3700
|
-
},
|
|
3701
|
-
{
|
|
3702
|
-
name: 'trdPriceTs';
|
|
3703
|
-
type: 'i64';
|
|
3704
|
-
},
|
|
3705
|
-
{
|
|
3706
|
-
name: 'padding';
|
|
3707
|
-
type: {
|
|
3708
|
-
array: ['u8', 428];
|
|
3709
|
-
};
|
|
3710
|
-
}
|
|
3711
|
-
];
|
|
3712
|
-
};
|
|
3713
|
-
},
|
|
3714
3621
|
{
|
|
3715
3622
|
name: 'key';
|
|
3716
3623
|
type: {
|
|
@@ -4564,44 +4471,6 @@ export type TriadProtocol = {
|
|
|
4564
4471
|
];
|
|
4565
4472
|
};
|
|
4566
4473
|
},
|
|
4567
|
-
{
|
|
4568
|
-
name: 'refer';
|
|
4569
|
-
type: {
|
|
4570
|
-
kind: 'struct';
|
|
4571
|
-
fields: [
|
|
4572
|
-
{
|
|
4573
|
-
name: 'bump';
|
|
4574
|
-
type: 'u8';
|
|
4575
|
-
},
|
|
4576
|
-
{
|
|
4577
|
-
name: 'id';
|
|
4578
|
-
type: 'u64';
|
|
4579
|
-
},
|
|
4580
|
-
{
|
|
4581
|
-
name: 'authority';
|
|
4582
|
-
type: 'pubkey';
|
|
4583
|
-
},
|
|
4584
|
-
{
|
|
4585
|
-
name: 'feeBps';
|
|
4586
|
-
type: 'u16';
|
|
4587
|
-
},
|
|
4588
|
-
{
|
|
4589
|
-
name: 'feeClaimed';
|
|
4590
|
-
type: 'u64';
|
|
4591
|
-
},
|
|
4592
|
-
{
|
|
4593
|
-
name: 'usersReferred';
|
|
4594
|
-
type: 'u64';
|
|
4595
|
-
},
|
|
4596
|
-
{
|
|
4597
|
-
name: 'padding';
|
|
4598
|
-
type: {
|
|
4599
|
-
array: ['u8', 24];
|
|
4600
|
-
};
|
|
4601
|
-
}
|
|
4602
|
-
];
|
|
4603
|
-
};
|
|
4604
|
-
},
|
|
4605
4474
|
{
|
|
4606
4475
|
name: 'requestUnstakeArgs';
|
|
4607
4476
|
type: {
|
|
@@ -4893,8 +4762,10 @@ export type TriadProtocol = {
|
|
|
4893
4762
|
type: 'u64';
|
|
4894
4763
|
},
|
|
4895
4764
|
{
|
|
4896
|
-
name: '
|
|
4897
|
-
type:
|
|
4765
|
+
name: 'padding1';
|
|
4766
|
+
type: {
|
|
4767
|
+
array: ['u8', 8];
|
|
4768
|
+
};
|
|
4898
4769
|
},
|
|
4899
4770
|
{
|
|
4900
4771
|
name: 'orders';
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { IdlAccounts } from '@coral-xyz/anchor';
|
|
3
3
|
import { Stake, StakeVault, Unstake } from './../types/stake';
|
|
4
|
-
import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, UserTrade, Pool, BookOrder,
|
|
4
|
+
import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, UserTrade, Pool, BookOrder, Customer } from '../types';
|
|
5
5
|
import { TriadProtocol } from '../types/triad_protocol';
|
|
6
6
|
export declare const encodeString: (value: string, alloc?: number) => number[];
|
|
7
7
|
export declare const decodeString: (bytes: number[]) => string;
|
|
@@ -45,5 +45,4 @@ export declare const getOrderStatus: (status: {
|
|
|
45
45
|
} | {
|
|
46
46
|
waiting: {};
|
|
47
47
|
}) => OrderStatus;
|
|
48
|
-
export declare const formatRefer: (account: IdlAccounts<TriadProtocol>['refer']) => Refer;
|
|
49
48
|
export declare const formatCustomer: (account: IdlAccounts<TriadProtocol>['customer'], publicKey: PublicKey) => Customer;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatCustomer = exports.
|
|
3
|
+
exports.formatCustomer = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatBookOrder = exports.formatOrder = exports.formatUserTrade = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
6
|
const types_1 = require("../types");
|
|
@@ -227,16 +227,6 @@ const getOrderStatus = (status) => {
|
|
|
227
227
|
}
|
|
228
228
|
};
|
|
229
229
|
exports.getOrderStatus = getOrderStatus;
|
|
230
|
-
const formatRefer = (account) => {
|
|
231
|
-
return {
|
|
232
|
-
id: account.id.toNumber(),
|
|
233
|
-
authority: account.authority.toString(),
|
|
234
|
-
feeBps: account.feeBps,
|
|
235
|
-
feeClaimed: account.feeClaimed.toNumber(),
|
|
236
|
-
usersReferred: account.usersReferred.toNumber()
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
exports.formatRefer = formatRefer;
|
|
240
230
|
const formatCustomer = (account, publicKey) => {
|
|
241
231
|
return {
|
|
242
232
|
id: account.id,
|
|
@@ -6,4 +6,3 @@ export declare const getCustomerPDA: (programId: PublicKey, customerId: number)
|
|
|
6
6
|
export declare const getUserTradePDA: (programId: PublicKey, wallet: PublicKey) => PublicKey;
|
|
7
7
|
export declare const getSubUserTradePDA: (programId: PublicKey, wallet: PublicKey, nonce: number) => PublicKey;
|
|
8
8
|
export declare const getPoolPDA: (programId: PublicKey, poolId: number) => PublicKey;
|
|
9
|
-
export declare const getReferPDA: (programId: PublicKey, refer: PublicKey) => PublicKey;
|
package/dist/utils/pda/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getPoolPDA = exports.getSubUserTradePDA = exports.getUserTradePDA = exports.getCustomerPDA = exports.getOrderBookPDA = exports.getMarketPDA = exports.getTokenATA = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
9
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -39,7 +39,3 @@ const getPoolPDA = (programId, poolId) => {
|
|
|
39
39
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool'), new bn_js_1.default(poolId).toArrayLike(Buffer, 'le', 8)], programId)[0];
|
|
40
40
|
};
|
|
41
41
|
exports.getPoolPDA = getPoolPDA;
|
|
42
|
-
const getReferPDA = (programId, refer) => {
|
|
43
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('refer'), refer.toBuffer()], programId)[0];
|
|
44
|
-
};
|
|
45
|
-
exports.getReferPDA = getReferPDA;
|