@triadxyz/triad-protocol 2.1.3-beta → 2.1.4-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 +10 -4
- package/dist/types/trade.d.ts +1 -0
- 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,7 +662,7 @@ 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;
|
|
@@ -683,14 +683,20 @@ class Trade {
|
|
|
683
683
|
}
|
|
684
684
|
const orderPrice = new bn_js_1.default(order.price);
|
|
685
685
|
const availableShares = new bn_js_1.default(order.totalShares);
|
|
686
|
+
let adjustedPrice = orderPrice;
|
|
687
|
+
if (feeBps > 0) {
|
|
688
|
+
const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
|
|
689
|
+
const fee = priceSpread.mul(new bn_js_1.default(feeBps)).div(new bn_js_1.default(10000));
|
|
690
|
+
adjustedPrice = orderPrice.add(fee);
|
|
691
|
+
}
|
|
686
692
|
const maxSharesForPrice = remainingUSDC
|
|
687
693
|
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
688
|
-
.div(
|
|
694
|
+
.div(adjustedPrice);
|
|
689
695
|
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
690
696
|
if (sharesToBuy.lten(0))
|
|
691
697
|
continue;
|
|
692
698
|
const usdcAmount = sharesToBuy
|
|
693
|
-
.mul(
|
|
699
|
+
.mul(adjustedPrice)
|
|
694
700
|
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
695
701
|
let sellerTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority));
|
|
696
702
|
if (order.userNonce !== '0') {
|
package/dist/types/trade.d.ts
CHANGED