@triadxyz/triad-protocol 2.1.3-beta → 2.1.5-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/trade.d.ts +1 -1
- package/dist/trade.js +11 -20
- package/dist/types/idl_triad_protocol.json +7 -12
- package/dist/types/trade.d.ts +2 -0
- package/dist/types/triad_protocol.d.ts +7 -12
- package/dist/utils/helpers.js +2 -1
- package/package.json +1 -1
package/dist/trade.d.ts
CHANGED
|
@@ -336,7 +336,7 @@ export default class Trade {
|
|
|
336
336
|
*
|
|
337
337
|
* @param options - RPC options
|
|
338
338
|
*/
|
|
339
|
-
marketBidOrder({ marketId, amount, direction, mint }: MarketBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
339
|
+
marketBidOrder({ marketId, amount, direction, mint, feeBps }: MarketBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
340
340
|
/**
|
|
341
341
|
* Get Orders By Market ID
|
|
342
342
|
* @param marketId - The ID of the market
|
package/dist/trade.js
CHANGED
|
@@ -650,7 +650,7 @@ class Trade {
|
|
|
650
650
|
*
|
|
651
651
|
* @param options - RPC options
|
|
652
652
|
*/
|
|
653
|
-
marketBidOrder({ marketId, amount, direction, mint }, options) {
|
|
653
|
+
marketBidOrder({ marketId, amount, direction, mint, feeBps = 0 }, options) {
|
|
654
654
|
return __awaiter(this, void 0, void 0, function* () {
|
|
655
655
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
656
656
|
const ixs = [];
|
|
@@ -662,35 +662,27 @@ class Trade {
|
|
|
662
662
|
: orderBook.flop.ask;
|
|
663
663
|
const sortedOrders = orders.sort((a, b) => Number(a.price) - Number(b.price));
|
|
664
664
|
for (const order of sortedOrders) {
|
|
665
|
-
if (remainingUSDC.div(new bn_js_1.default(Math.pow(10, this.decimals))).
|
|
665
|
+
if (remainingUSDC.div(new bn_js_1.default(Math.pow(10, this.decimals))).toNumber() === 0)
|
|
666
666
|
break;
|
|
667
667
|
if (order.authority === this.program.provider.publicKey.toBase58()) {
|
|
668
668
|
return;
|
|
669
669
|
}
|
|
670
|
-
let linkedSellerBidTradePDA = null;
|
|
671
|
-
if (order.linkedBidOrderId !== '0') {
|
|
672
|
-
const userOrders = yield this.getUserOrders(new web3_js_1.PublicKey(order.authority));
|
|
673
|
-
linkedSellerBidTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority));
|
|
674
|
-
const linkedBidOrder = userOrders.find((item) => item.orderId === order.linkedBidOrderId &&
|
|
675
|
-
item.marketId === marketId.toString());
|
|
676
|
-
if (!linkedBidOrder) {
|
|
677
|
-
throw new Error('Linked bid order not found');
|
|
678
|
-
}
|
|
679
|
-
if (linkedBidOrder.userNonce !== '0') {
|
|
680
|
-
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), Number(linkedBidOrder.userNonce));
|
|
681
|
-
linkedSellerBidTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
670
|
const orderPrice = new bn_js_1.default(order.price);
|
|
685
671
|
const availableShares = new bn_js_1.default(order.totalShares);
|
|
672
|
+
let adjustedPrice = orderPrice;
|
|
673
|
+
if (feeBps > 0) {
|
|
674
|
+
const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
|
|
675
|
+
const fee = priceSpread.mul(new bn_js_1.default(feeBps)).div(new bn_js_1.default(10000));
|
|
676
|
+
adjustedPrice = orderPrice.add(fee);
|
|
677
|
+
}
|
|
686
678
|
const maxSharesForPrice = remainingUSDC
|
|
687
679
|
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
688
|
-
.div(
|
|
680
|
+
.div(adjustedPrice);
|
|
689
681
|
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
690
682
|
if (sharesToBuy.lten(0))
|
|
691
683
|
continue;
|
|
692
684
|
const usdcAmount = sharesToBuy
|
|
693
|
-
.mul(
|
|
685
|
+
.mul(adjustedPrice)
|
|
694
686
|
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
695
687
|
let sellerTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority));
|
|
696
688
|
if (order.userNonce !== '0') {
|
|
@@ -713,8 +705,7 @@ class Trade {
|
|
|
713
705
|
tokenProgram,
|
|
714
706
|
sellerAuthority: new web3_js_1.PublicKey(order.authority),
|
|
715
707
|
marketAta: (0, pda_2.getTokenATA)(marketPDA, mint, tokenProgram),
|
|
716
|
-
buyerAta: (0, pda_2.getTokenATA)(this.program.provider.publicKey, mint, tokenProgram)
|
|
717
|
-
linkedSellerBidTrade: linkedSellerBidTradePDA
|
|
708
|
+
buyerAta: (0, pda_2.getTokenATA)(this.program.provider.publicKey, mint, tokenProgram)
|
|
718
709
|
})
|
|
719
710
|
.instruction());
|
|
720
711
|
remainingUSDC = remainingUSDC.sub(usdcAmount);
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"signer": true
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
|
-
"name": "
|
|
57
|
+
"name": "market",
|
|
58
58
|
"writable": true
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
"name": "
|
|
61
|
+
"name": "bid_user_trade",
|
|
62
62
|
"writable": true
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
"name": "
|
|
65
|
+
"name": "ask_user_trade",
|
|
66
66
|
"writable": true
|
|
67
67
|
},
|
|
68
68
|
{
|
|
@@ -856,6 +856,10 @@
|
|
|
856
856
|
"writable": true,
|
|
857
857
|
"signer": true
|
|
858
858
|
},
|
|
859
|
+
{
|
|
860
|
+
"name": "market",
|
|
861
|
+
"writable": true
|
|
862
|
+
},
|
|
859
863
|
{
|
|
860
864
|
"name": "squads",
|
|
861
865
|
"writable": true,
|
|
@@ -873,15 +877,6 @@
|
|
|
873
877
|
"name": "seller_trade",
|
|
874
878
|
"writable": true
|
|
875
879
|
},
|
|
876
|
-
{
|
|
877
|
-
"name": "linked_seller_bid_trade",
|
|
878
|
-
"writable": true,
|
|
879
|
-
"optional": true
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
"name": "market",
|
|
883
|
-
"writable": true
|
|
884
|
-
},
|
|
885
880
|
{
|
|
886
881
|
"name": "mint",
|
|
887
882
|
"writable": true
|
package/dist/types/trade.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type Market = {
|
|
|
28
28
|
payoutFee: number;
|
|
29
29
|
customer: string;
|
|
30
30
|
version: number;
|
|
31
|
+
poolId: number;
|
|
31
32
|
};
|
|
32
33
|
export type UserTrade = {
|
|
33
34
|
user: string;
|
|
@@ -173,4 +174,5 @@ export type MarketBidOrderArgs = {
|
|
|
173
174
|
flop: {};
|
|
174
175
|
};
|
|
175
176
|
mint: PublicKey;
|
|
177
|
+
feeBps: number;
|
|
176
178
|
};
|
|
@@ -60,15 +60,15 @@ export type TriadProtocol = {
|
|
|
60
60
|
signer: true;
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
name: '
|
|
63
|
+
name: 'market';
|
|
64
64
|
writable: true;
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
|
-
name: '
|
|
67
|
+
name: 'bidUserTrade';
|
|
68
68
|
writable: true;
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
|
-
name: '
|
|
71
|
+
name: 'askUserTrade';
|
|
72
72
|
writable: true;
|
|
73
73
|
},
|
|
74
74
|
{
|
|
@@ -1164,6 +1164,10 @@ export type TriadProtocol = {
|
|
|
1164
1164
|
writable: true;
|
|
1165
1165
|
signer: true;
|
|
1166
1166
|
},
|
|
1167
|
+
{
|
|
1168
|
+
name: 'market';
|
|
1169
|
+
writable: true;
|
|
1170
|
+
},
|
|
1167
1171
|
{
|
|
1168
1172
|
name: 'squads';
|
|
1169
1173
|
writable: true;
|
|
@@ -1181,15 +1185,6 @@ export type TriadProtocol = {
|
|
|
1181
1185
|
name: 'sellerTrade';
|
|
1182
1186
|
writable: true;
|
|
1183
1187
|
},
|
|
1184
|
-
{
|
|
1185
|
-
name: 'linkedSellerBidTrade';
|
|
1186
|
-
writable: true;
|
|
1187
|
-
optional: true;
|
|
1188
|
-
},
|
|
1189
|
-
{
|
|
1190
|
-
name: 'market';
|
|
1191
|
-
writable: true;
|
|
1192
|
-
},
|
|
1193
1188
|
{
|
|
1194
1189
|
name: 'mint';
|
|
1195
1190
|
writable: true;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -83,7 +83,8 @@ const formatMarket = (account, address) => {
|
|
|
83
83
|
: '0',
|
|
84
84
|
payoutFee: account.payoutFee,
|
|
85
85
|
customer: account.customerId === 0 ? 'Triad' : account.customerId.toString(),
|
|
86
|
-
version: account.version.toNumber()
|
|
86
|
+
version: account.version.toNumber(),
|
|
87
|
+
poolId: account.poolId.toNumber()
|
|
87
88
|
};
|
|
88
89
|
};
|
|
89
90
|
exports.formatMarket = formatMarket;
|