@triadxyz/triad-protocol 2.8.7-beta → 2.8.9-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.
Files changed (2) hide show
  1. package/dist/index.js +35 -30
  2. package/package.json +1 -1
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)({
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.9-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",