@triadxyz/triad-protocol 2.0.9-beta → 2.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/trade.d.ts
CHANGED
package/dist/trade.js
CHANGED
|
@@ -557,16 +557,16 @@ class Trade {
|
|
|
557
557
|
const ixs = [];
|
|
558
558
|
const { userTradePDA: buyerTrade, ixs: userTradeIxs } = yield this.getUserTradeIxs();
|
|
559
559
|
const orderBook = yield this.getOrderBook(marketId);
|
|
560
|
-
let remainingUSDC = amount * Math.pow(10, this.decimals);
|
|
560
|
+
let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, this.decimals));
|
|
561
561
|
const orders = Object.keys(direction)[0] === 'hype'
|
|
562
562
|
? orderBook.hype.ask
|
|
563
563
|
: orderBook.flop.ask;
|
|
564
564
|
const sortedOrders = orders.sort((a, b) => Number(a.price) - Number(b.price));
|
|
565
565
|
for (const order of sortedOrders) {
|
|
566
|
-
if (remainingUSDC
|
|
566
|
+
if (remainingUSDC.div(new bn_js_1.default(Math.pow(10, this.decimals))).toString() === '0')
|
|
567
567
|
break;
|
|
568
568
|
if (order.authority === this.program.provider.publicKey.toBase58()) {
|
|
569
|
-
|
|
569
|
+
return;
|
|
570
570
|
}
|
|
571
571
|
let linkedSellerBidTradePDA = null;
|
|
572
572
|
if (order.linkedBidOrderId !== '0') {
|
|
@@ -582,11 +582,17 @@ class Trade {
|
|
|
582
582
|
linkedSellerBidTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
|
-
const orderPrice =
|
|
586
|
-
const
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
585
|
+
const orderPrice = new bn_js_1.default(order.price);
|
|
586
|
+
const availableShares = new bn_js_1.default(order.totalShares);
|
|
587
|
+
const maxSharesForPrice = remainingUSDC
|
|
588
|
+
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
589
|
+
.div(orderPrice);
|
|
590
|
+
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
591
|
+
if (sharesToBuy.lten(0))
|
|
592
|
+
continue;
|
|
593
|
+
const usdcAmount = sharesToBuy
|
|
594
|
+
.mul(orderPrice)
|
|
595
|
+
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
590
596
|
let sellerTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority));
|
|
591
597
|
if (order.userNonce !== '0') {
|
|
592
598
|
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), Number(order.userNonce));
|
|
@@ -612,7 +618,7 @@ class Trade {
|
|
|
612
618
|
linkedSellerBidTrade: linkedSellerBidTradePDA
|
|
613
619
|
})
|
|
614
620
|
.instruction());
|
|
615
|
-
remainingUSDC
|
|
621
|
+
remainingUSDC = remainingUSDC.sub(usdcAmount);
|
|
616
622
|
}
|
|
617
623
|
if (userTradeIxs.length > 0) {
|
|
618
624
|
ixs.unshift(...userTradeIxs);
|
|
@@ -2481,10 +2481,14 @@
|
|
|
2481
2481
|
"name": "payout_fee",
|
|
2482
2482
|
"type": "u16"
|
|
2483
2483
|
},
|
|
2484
|
+
{
|
|
2485
|
+
"name": "version",
|
|
2486
|
+
"type": "u64"
|
|
2487
|
+
},
|
|
2484
2488
|
{
|
|
2485
2489
|
"name": "padding",
|
|
2486
2490
|
"type": {
|
|
2487
|
-
"array": ["u8",
|
|
2491
|
+
"array": ["u8", 80]
|
|
2488
2492
|
}
|
|
2489
2493
|
}
|
|
2490
2494
|
]
|
|
@@ -2551,10 +2555,8 @@
|
|
|
2551
2555
|
"type": "u64"
|
|
2552
2556
|
},
|
|
2553
2557
|
{
|
|
2554
|
-
"name": "
|
|
2555
|
-
"type":
|
|
2556
|
-
"array": ["u8", 8]
|
|
2557
|
-
}
|
|
2558
|
+
"name": "version",
|
|
2559
|
+
"type": "u64"
|
|
2558
2560
|
},
|
|
2559
2561
|
{
|
|
2560
2562
|
"name": "total_shares",
|
package/dist/types/trade.d.ts
CHANGED
|
@@ -3202,10 +3202,14 @@ export type TriadProtocol = {
|
|
|
3202
3202
|
name: 'payoutFee';
|
|
3203
3203
|
type: 'u16';
|
|
3204
3204
|
},
|
|
3205
|
+
{
|
|
3206
|
+
name: 'version';
|
|
3207
|
+
type: 'u64';
|
|
3208
|
+
},
|
|
3205
3209
|
{
|
|
3206
3210
|
name: 'padding';
|
|
3207
3211
|
type: {
|
|
3208
|
-
array: ['u8',
|
|
3212
|
+
array: ['u8', 80];
|
|
3209
3213
|
};
|
|
3210
3214
|
}
|
|
3211
3215
|
];
|
|
@@ -3272,10 +3276,8 @@ export type TriadProtocol = {
|
|
|
3272
3276
|
type: 'u64';
|
|
3273
3277
|
},
|
|
3274
3278
|
{
|
|
3275
|
-
name: '
|
|
3276
|
-
type:
|
|
3277
|
-
array: ['u8', 8];
|
|
3278
|
-
};
|
|
3279
|
+
name: 'version';
|
|
3280
|
+
type: 'u64';
|
|
3279
3281
|
},
|
|
3280
3282
|
{
|
|
3281
3283
|
name: 'totalShares';
|
package/dist/utils/helpers.js
CHANGED
|
@@ -83,7 +83,8 @@ const formatMarket = (account, address) => {
|
|
|
83
83
|
? account.marketLiquidityAtStart.toString()
|
|
84
84
|
: '0',
|
|
85
85
|
payoutFee: account.payoutFee,
|
|
86
|
-
customer: account.customerId === 0 ? 'Triad' : account.customerId.toString()
|
|
86
|
+
customer: account.customerId === 0 ? 'Triad' : account.customerId.toString(),
|
|
87
|
+
version: account.version.toNumber()
|
|
87
88
|
};
|
|
88
89
|
};
|
|
89
90
|
exports.formatMarket = formatMarket;
|