@triadxyz/triad-protocol 2.8.7-beta → 2.8.8-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 +1 -1
- package/dist/index.js +41 -31
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -430,7 +430,7 @@ export default class TriadProtocolClient {
|
|
|
430
430
|
*
|
|
431
431
|
* @param options - RPC options
|
|
432
432
|
*/
|
|
433
|
-
marketBidOrder({ marketId, amount, direction, mint, feeBps, isTrdPayout }: MarketBidOrderArgs, options?: RpcOptions): Promise<
|
|
433
|
+
marketBidOrder({ marketId, amount, direction, mint, feeBps, isTrdPayout }: MarketBidOrderArgs, options?: RpcOptions): Promise<void>;
|
|
434
434
|
/**
|
|
435
435
|
* Market Ask Order
|
|
436
436
|
* @param args.marketId - The ID of the Market
|
package/dist/index.js
CHANGED
|
@@ -860,6 +860,11 @@ class TriadProtocolClient {
|
|
|
860
860
|
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(direction)[0]);
|
|
861
861
|
const orderBook = yield this.getOrderBook(marketId);
|
|
862
862
|
let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, this.decimals));
|
|
863
|
+
if (isTrdPayout) {
|
|
864
|
+
const price = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
865
|
+
const trdToUsdc = amount * price;
|
|
866
|
+
remainingUSDC = new bn_js_1.default(trdToUsdc * Math.pow(10, this.decimals));
|
|
867
|
+
}
|
|
863
868
|
const orders = Object.keys(direction)[0] === 'hype'
|
|
864
869
|
? orderBook.hype.ask
|
|
865
870
|
: orderBook.flop.ask;
|
|
@@ -867,37 +872,37 @@ class TriadProtocolClient {
|
|
|
867
872
|
const tokenProgram = (0, helpers_1.getTokenProgram)(mint);
|
|
868
873
|
let totalUSDCNeeded = new bn_js_1.default(0);
|
|
869
874
|
let tempRemainingUSDC = remainingUSDC.clone();
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
875
|
+
if (isTrdPayout) {
|
|
876
|
+
for (const order of sortedOrders) {
|
|
877
|
+
if (tempRemainingUSDC.lt(new bn_js_1.default(1000000)))
|
|
878
|
+
break;
|
|
879
|
+
if (order.authority === this.program.provider.publicKey.toBase58()) {
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
const orderPrice = new bn_js_1.default(order.price);
|
|
883
|
+
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
884
|
+
let adjustedPrice = orderPrice;
|
|
885
|
+
if (feeBps > 0) {
|
|
886
|
+
const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
|
|
887
|
+
const fee = priceSpread
|
|
888
|
+
.mul(orderPrice)
|
|
889
|
+
.mul(new bn_js_1.default(feeBps))
|
|
890
|
+
.div(new bn_js_1.default(10000))
|
|
891
|
+
.div(new bn_js_1.default(1000000));
|
|
892
|
+
adjustedPrice = orderPrice.add(fee);
|
|
893
|
+
}
|
|
894
|
+
const maxSharesForPrice = tempRemainingUSDC
|
|
895
|
+
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
896
|
+
.div(adjustedPrice);
|
|
897
|
+
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
898
|
+
if (sharesToBuy.lte(new bn_js_1.default(0)))
|
|
899
|
+
continue;
|
|
900
|
+
const usdcAmount = sharesToBuy
|
|
901
|
+
.mul(adjustedPrice)
|
|
902
|
+
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
903
|
+
totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
|
|
904
|
+
tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
|
|
887
905
|
}
|
|
888
|
-
const maxSharesForPrice = tempRemainingUSDC
|
|
889
|
-
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
890
|
-
.div(adjustedPrice);
|
|
891
|
-
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
892
|
-
if (sharesToBuy.lte(new bn_js_1.default(0)))
|
|
893
|
-
continue;
|
|
894
|
-
const usdcAmount = sharesToBuy
|
|
895
|
-
.mul(adjustedPrice)
|
|
896
|
-
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
897
|
-
totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
|
|
898
|
-
tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
|
|
899
|
-
}
|
|
900
|
-
if (isTrdPayout && totalUSDCNeeded.gt(new bn_js_1.default(0))) {
|
|
901
906
|
const price = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
902
907
|
const amountInTRD = totalUSDCNeeded.toNumber() / (price * Math.pow(10, this.decimals));
|
|
903
908
|
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
@@ -970,7 +975,12 @@ class TriadProtocolClient {
|
|
|
970
975
|
if (ixs.length === 0) {
|
|
971
976
|
throw new Error('No matching orders found to fill the requested amount');
|
|
972
977
|
}
|
|
973
|
-
return (
|
|
978
|
+
// return sendVersionedTransaction(
|
|
979
|
+
// this.program,
|
|
980
|
+
// ixs,
|
|
981
|
+
// options,
|
|
982
|
+
// addressLookupTableAccounts
|
|
983
|
+
// )
|
|
974
984
|
});
|
|
975
985
|
}
|
|
976
986
|
/**
|