@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 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<string>;
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
- for (const order of sortedOrders) {
871
- if (tempRemainingUSDC.lt(new bn_js_1.default(1000000)))
872
- break;
873
- if (order.authority === this.program.provider.publicKey.toBase58()) {
874
- continue;
875
- }
876
- const orderPrice = new bn_js_1.default(order.price);
877
- const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
878
- let adjustedPrice = orderPrice;
879
- if (feeBps > 0) {
880
- const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
881
- const fee = priceSpread
882
- .mul(orderPrice)
883
- .mul(new bn_js_1.default(feeBps))
884
- .div(new bn_js_1.default(10000))
885
- .div(new bn_js_1.default(1000000));
886
- adjustedPrice = orderPrice.add(fee);
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 (0, sendVersionedTransaction_1.default)(this.program, ixs, options, addressLookupTableAccounts);
978
+ // return sendVersionedTransaction(
979
+ // this.program,
980
+ // ixs,
981
+ // options,
982
+ // addressLookupTableAccounts
983
+ // )
974
984
  });
975
985
  }
976
986
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "2.8.7-beta",
3
+ "version": "2.8.8-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",