flash-sdk 9.0.3 → 10.0.0-alpha.1

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.
@@ -459,16 +459,13 @@ var PerpetualsClient = (function () {
459
459
  };
460
460
  };
461
461
  this.getRemoveLiquidityAmountAndFeeSync = function (lpAmountIn, poolAccount, outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount, lpTokenSupply, poolAumUsdMax, poolConfig) {
462
- if (outputTokenCustodyAccount.isVirtual) {
463
- throw new Error("Cannot remove liquidity in virtual Custody");
464
- }
465
462
  if (!outputTokenPrice.exponent.eq(outputTokenEmaPrice.exponent)) {
466
463
  throw new Error("exponent mistach");
467
464
  }
468
465
  var minMaxPrice = _this.getMinAndMaxOraclePriceSync(outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount);
469
466
  var removeAmountUsd = (poolAumUsdMax.mul(lpAmountIn)).div(lpTokenSupply);
470
467
  var removeAmount;
471
- var oneOracle = OraclePrice_1.OraclePrice.from({ price: new anchor_1.BN(10).pow(outputTokenPrice.exponent.abs()), exponent: outputTokenPrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
468
+ var oneOracle = OraclePrice_1.OraclePrice.from({ price: new anchor_1.BN(Math.pow(10, 8)), exponent: new anchor_1.BN(-8), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
472
469
  if (outputTokenCustodyAccount.isStable && minMaxPrice.min != minMaxPrice.max && minMaxPrice.max.price.lt(oneOracle.price)) {
473
470
  removeAmount = oneOracle.getTokenAmount(removeAmountUsd, outputTokenCustodyAccount.decimals);
474
471
  }
@@ -496,15 +493,9 @@ var PerpetualsClient = (function () {
496
493
  case types_1.FeesAction.SwapOut:
497
494
  fees = inputTokenCustodyAccount.fees.swapOut;
498
495
  break;
499
- case types_1.FeesAction.StableSwapIn:
500
- fees = inputTokenCustodyAccount.fees.stableSwapIn;
501
- break;
502
- case types_1.FeesAction.StableSwapOut:
503
- fees = inputTokenCustodyAccount.fees.stableSwapOut;
504
- break;
505
496
  }
506
497
  if (inputTokenCustodyAccount.fees.mode == types_1.FeesMode.Fixed) {
507
- return { feeBps: fees.targetFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.targetFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
498
+ return { feeBps: fees.minFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.minFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
508
499
  }
509
500
  var newRatio = _this.getNewRatioHelper(amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax);
510
501
  var index = poolAccount.custodies.findIndex(function (c) { return c.equals(inputTokenCustodyAccount.publicKey); });
@@ -569,7 +560,6 @@ var PerpetualsClient = (function () {
569
560
  }
570
561
  else {
571
562
  minPrice.price = maxPrice.price.sub(maxPrice.confidence);
572
- maxPrice.price = maxPrice.price.add(maxPrice.confidence);
573
563
  return {
574
564
  min: minPrice,
575
565
  max: maxPrice
@@ -583,6 +573,38 @@ var PerpetualsClient = (function () {
583
573
  };
584
574
  }
585
575
  };
576
+ this.getMinAndMaxPriceSync = function (price, emaPrice, custodyAccount) {
577
+ var minPrice = price;
578
+ var divergenceBps;
579
+ if (custodyAccount.isStable) {
580
+ divergenceBps = price.getDivergenceFactor(OraclePrice_1.OraclePrice.from({ price: new anchor_1.BN(10).pow(price.exponent.abs()), exponent: price.exponent, confidence: price.confidence, timestamp: price.timestamp }));
581
+ }
582
+ else {
583
+ divergenceBps = price.getDivergenceFactor(emaPrice);
584
+ }
585
+ if (divergenceBps.gte(custodyAccount.oracle.maxDivergenceBps)) {
586
+ var factorBps = custodyAccount.oracle.maxDivergenceBps.isZero ? constants_1.BN_ZERO : (divergenceBps.mul(new anchor_1.BN(constants_1.BPS_POWER))).div(custodyAccount.oracle.maxDivergenceBps);
587
+ var confBps = (price.confidence.muln(constants_1.BPS_POWER)).div(price.price);
588
+ if (confBps.lt(custodyAccount.oracle.maxConfBps)) {
589
+ var confFactor = anchor_1.BN.min(factorBps, new anchor_1.BN(50000));
590
+ var confScale = (price.confidence.mul(confFactor)).div(new anchor_1.BN(constants_1.BPS_POWER));
591
+ minPrice.price = price.price.sub(confScale);
592
+ }
593
+ else {
594
+ minPrice.price = price.price.sub(price.confidence);
595
+ }
596
+ }
597
+ else {
598
+ return {
599
+ min: price.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price,
600
+ max: price.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price
601
+ };
602
+ }
603
+ return {
604
+ min: minPrice.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price,
605
+ max: price.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price
606
+ };
607
+ };
586
608
  this.checkIfPriceStaleOrCustom = function (price, emaPrice, custodyAccount, timestampInSeconds) {
587
609
  if (timestampInSeconds.lt(price.timestamp)) {
588
610
  throw new Error("current time cannot be timepassed");
@@ -671,9 +693,8 @@ var PerpetualsClient = (function () {
671
693
  return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
672
694
  }
673
695
  };
674
- this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
696
+ this.getEntryPriceAndFeeSync = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps) {
675
697
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
676
- if (enableLogs === void 0) { enableLogs = false; }
677
698
  if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
678
699
  throw new Error("Delta Amounts cannot be negative.");
679
700
  }
@@ -725,6 +746,69 @@ var PerpetualsClient = (function () {
725
746
  feeAmountAfterDiscount = feeAmount;
726
747
  }
727
748
  }
749
+ return {
750
+ entryOraclePrice: entryOraclePrice,
751
+ feeUsd: feeUsd,
752
+ feeAmount: feeAmount,
753
+ feeUsdAfterDiscount: feeUsdAfterDiscount,
754
+ feeAmountAfterDiscount: feeAmountAfterDiscount,
755
+ liquidationPrice: liquidationPrice
756
+ };
757
+ };
758
+ this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
759
+ if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
760
+ if (enableLogs === void 0) { enableLogs = false; }
761
+ if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
762
+ throw new Error("Delta Amounts cannot be negative.");
763
+ }
764
+ var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
765
+ var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
766
+ if (positionAccount === null) {
767
+ var data = __assign({}, types_1.DEFAULT_POSITION);
768
+ positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
769
+ var sizeUsd_2 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
770
+ positionAccount.sizeUsd = sizeUsd_2;
771
+ positionAccount.sizeDecimals = targetCustodyAccount.decimals;
772
+ positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
773
+ positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
774
+ }
775
+ else {
776
+ positionAccount = positionAccount.clone();
777
+ var positionEntryPrice = OraclePrice_1.OraclePrice.from({
778
+ price: positionAccount.entryPrice.price,
779
+ exponent: new anchor_1.BN(positionAccount.entryPrice.exponent),
780
+ confidence: constants_1.BN_ZERO,
781
+ timestamp: constants_1.BN_ZERO
782
+ });
783
+ entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
784
+ var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
785
+ positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
786
+ }
787
+ positionAccount.collateralAmount = positionAccount.collateralAmount.add(collateralDeltaAmount);
788
+ positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
789
+ var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
790
+ var liquidationPrice = _this.getLiquidationPriceSync(positionAccount.collateralAmount, positionAccount.sizeAmount, entryOraclePrice, lockFeeUsd, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, positionAccount);
791
+ var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
792
+ var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
793
+ var feeUsd = constants_1.BN_ZERO;
794
+ var feeAmount = constants_1.BN_ZERO;
795
+ var feeUsdAfterDiscount = constants_1.BN_ZERO;
796
+ var feeAmountAfterDiscount = constants_1.BN_ZERO;
797
+ if (positionAccount !== null && sizeDeltaAmount.isZero()) {
798
+ }
799
+ else {
800
+ feeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.openPosition).div(new anchor_1.BN(constants_1.RATE_POWER));
801
+ feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
802
+ if (discountBps.gt(constants_1.BN_ZERO)) {
803
+ feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
804
+ feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
805
+ feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
806
+ }
807
+ else {
808
+ feeUsdAfterDiscount = feeUsd;
809
+ feeAmountAfterDiscount = feeAmount;
810
+ }
811
+ }
728
812
  var divergenceBps;
729
813
  divergenceBps = targetPrice.getDivergenceFactor(targetEmaPrice);
730
814
  var vbFeeUsd = constants_1.BN_ZERO;
@@ -818,12 +902,13 @@ var PerpetualsClient = (function () {
818
902
  };
819
903
  };
820
904
  this.getTradeSpread = function (targetCustodyAccount, sizeUsd) {
821
- if (targetCustodyAccount.pricing.tradeSpreadMax.isZero() || sizeUsd.isZero()) {
905
+ if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero()
906
+ ||
907
+ sizeUsd.isZero()) {
822
908
  return constants_1.BN_ZERO;
823
909
  }
824
- var slope = (targetCustodyAccount.pricing.tradeSpreadMax
825
- .sub(targetCustodyAccount.pricing.tradeSpreadMin)
826
- .mul(new anchor_1.BN(10).pow(new anchor_1.BN(constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS)))).div(targetCustodyAccount.pricing.maxPositionLockedUsd);
910
+ var slope = ((targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin)).mul(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS)))))
911
+ .div(targetCustodyAccount.pricing.maxPositionLockedUsd);
827
912
  var variable = (slope.mul(sizeUsd)).div(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS))));
828
913
  var finalSpread = targetCustodyAccount.pricing.tradeSpreadMin.add(variable);
829
914
  return finalSpread;
@@ -849,7 +934,7 @@ var PerpetualsClient = (function () {
849
934
  };
850
935
  this.getSizeAmountFromLeverageAndCollateral = function (collateralAmtWithFee, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
851
936
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
852
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min.price;
937
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
853
938
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
854
939
  var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals))
855
940
  .multipliedBy(collateralTokenMinPriceUi);
@@ -876,7 +961,7 @@ var PerpetualsClient = (function () {
876
961
  var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfigSwap).minAmountOut;
877
962
  finalCollateralAmount = swapAmountOut;
878
963
  }
879
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min.price;
964
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
880
965
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
881
966
  var collateralAmtMinUsdUi = new bignumber_js_1.default(finalCollateralAmount.toString()).dividedBy(Math.pow(10, collateralTokenCustodyAccount.decimals))
882
967
  .multipliedBy(collateralTokenMinPriceUi);
@@ -895,7 +980,7 @@ var PerpetualsClient = (function () {
895
980
  };
896
981
  this.getCollateralAmountWithFeeFromLeverageAndSize = function (sizeAmount, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
897
982
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
898
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min.price;
983
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
899
984
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
900
985
  var sizeUsd = targetPrice.getAssetAmountUsd(sizeAmount, targetCustodyAccount.decimals);
901
986
  var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
@@ -912,7 +997,7 @@ var PerpetualsClient = (function () {
912
997
  return (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralToken.decimals, bignumber_js_1.default.ROUND_DOWN), collateralToken.decimals);
913
998
  };
914
999
  this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfigPosition, poolConfigSwap) {
915
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min.price;
1000
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
916
1001
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
917
1002
  var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
918
1003
  var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
@@ -1092,6 +1177,7 @@ var PerpetualsClient = (function () {
1092
1177
  this.getFinalCloseAmountSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
1093
1178
  var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
1094
1179
  var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
1180
+ var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
1095
1181
  var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1096
1182
  var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
1097
1183
  var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
@@ -1534,7 +1620,8 @@ var PerpetualsClient = (function () {
1534
1620
  };
1535
1621
  }
1536
1622
  var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
1537
- var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, positionAccount.sizeUsd);
1623
+ var sizeUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
1624
+ var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, sizeUsd);
1538
1625
  var collateralMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
1539
1626
  var priceDiffProfit, priceDiffLoss;
1540
1627
  var positionEntryPrice = OraclePrice_1.OraclePrice.from({
@@ -1800,7 +1887,7 @@ var PerpetualsClient = (function () {
1800
1887
  });
1801
1888
  };
1802
1889
  this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
1803
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
1890
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
1804
1891
  var _d;
1805
1892
  return __generator(this, function (_e) {
1806
1893
  switch (_e.label) {
@@ -1848,6 +1935,8 @@ var PerpetualsClient = (function () {
1848
1935
  return [4, backUpOracleInstructionPromise];
1849
1936
  case 2:
1850
1937
  backUpOracleInstruction = _e.sent();
1938
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
1939
+ transaction.instructions.unshift(setCULimitIx);
1851
1940
  (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
1852
1941
  return [4, this.viewHelper.simulateTransaction(transaction)];
1853
1942
  case 3:
@@ -1914,7 +2003,7 @@ var PerpetualsClient = (function () {
1914
2003
  args_1[_i - 4] = arguments[_i];
1915
2004
  }
1916
2005
  return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
1917
- var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2006
+ var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
1918
2007
  var _e;
1919
2008
  if (userPublicKey === void 0) { userPublicKey = undefined; }
1920
2009
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -1965,6 +2054,8 @@ var PerpetualsClient = (function () {
1965
2054
  .transaction()];
1966
2055
  case 1:
1967
2056
  transaction = _f.sent();
2057
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2058
+ transaction.instructions.unshift(setCULimitIx);
1968
2059
  if (!enableBackupOracle) return [3, 3];
1969
2060
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
1970
2061
  case 2:
@@ -1990,7 +2081,7 @@ var PerpetualsClient = (function () {
1990
2081
  args_1[_i - 4] = arguments[_i];
1991
2082
  }
1992
2083
  return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
1993
- var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2084
+ var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
1994
2085
  var _e;
1995
2086
  if (userPublicKey === void 0) { userPublicKey = undefined; }
1996
2087
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -2041,6 +2132,8 @@ var PerpetualsClient = (function () {
2041
2132
  .transaction()];
2042
2133
  case 1:
2043
2134
  transaction = _f.sent();
2135
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2136
+ transaction.instructions.unshift(setCULimitIx);
2044
2137
  if (!enableBackupOracle) return [3, 3];
2045
2138
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2046
2139
  case 2:
@@ -2067,7 +2160,7 @@ var PerpetualsClient = (function () {
2067
2160
  });
2068
2161
  };
2069
2162
  this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
2070
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
2163
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
2071
2164
  var _d;
2072
2165
  return __generator(this, function (_e) {
2073
2166
  switch (_e.label) {
@@ -2115,6 +2208,8 @@ var PerpetualsClient = (function () {
2115
2208
  .transaction()];
2116
2209
  case 2:
2117
2210
  transaction = _e.sent();
2211
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2212
+ transaction.instructions.unshift(setCULimitIx);
2118
2213
  (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2119
2214
  return [4, this.viewHelper.simulateTransaction(transaction)];
2120
2215
  case 3:
@@ -2131,7 +2226,7 @@ var PerpetualsClient = (function () {
2131
2226
  args_1[_i - 4] = arguments[_i];
2132
2227
  }
2133
2228
  return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
2134
- var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
2229
+ var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2135
2230
  var _e;
2136
2231
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2137
2232
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -2186,6 +2281,8 @@ var PerpetualsClient = (function () {
2186
2281
  .transaction()];
2187
2282
  case 1:
2188
2283
  transaction = _f.sent();
2284
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2285
+ transaction.instructions.unshift(setCULimitIx);
2189
2286
  if (!enableBackupOracle) return [3, 3];
2190
2287
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2191
2288
  case 2:
@@ -2211,7 +2308,7 @@ var PerpetualsClient = (function () {
2211
2308
  args_1[_i - 4] = arguments[_i];
2212
2309
  }
2213
2310
  return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
2214
- var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
2311
+ var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2215
2312
  var _e;
2216
2313
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2217
2314
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -2266,6 +2363,8 @@ var PerpetualsClient = (function () {
2266
2363
  .transaction()];
2267
2364
  case 1:
2268
2365
  transaction = _f.sent();
2366
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2367
+ transaction.instructions.unshift(setCULimitIx);
2269
2368
  if (!enableBackupOracle) return [3, 3];
2270
2369
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2271
2370
  case 2:
@@ -3997,119 +4096,8 @@ var PerpetualsClient = (function () {
3997
4096
  }
3998
4097
  });
3999
4098
  }); };
4000
- this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
4001
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
4002
- return __generator(this, function (_a) {
4003
- switch (_a.label) {
4004
- case 0:
4005
- publicKey = this.provider.wallet.publicKey;
4006
- preInstructions = [];
4007
- instructions = [];
4008
- postInstructions = [];
4009
- additionalSigners = [];
4010
- _a.label = 1;
4011
- case 1:
4012
- _a.trys.push([1, 4, , 5]);
4013
- nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
4014
- Buffer.from("trading"),
4015
- nftMint.toBuffer(),
4016
- ], this.programId)[0];
4017
- nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
4018
- Buffer.from("referral"),
4019
- publicKey.toBuffer(),
4020
- ], this.programId)[0];
4021
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
4022
- case 2:
4023
- nftTokenAccount = _a.sent();
4024
- flpStakeAccountMetas = [];
4025
- for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
4026
- flpStakeAccountPk = flpStakeAccounts_1[_i];
4027
- flpStakeAccountMetas.push({
4028
- pubkey: flpStakeAccountPk,
4029
- isSigner: false,
4030
- isWritable: true,
4031
- });
4032
- }
4033
- return [4, this.program.methods
4034
- .updateTradingAccount({
4035
- updateReferer: updateReferer,
4036
- updateBooster: updateBooster
4037
- })
4038
- .accounts({
4039
- owner: publicKey,
4040
- feePayer: publicKey,
4041
- nftTokenAccount: nftTokenAccount,
4042
- referralAccount: nftReferralAccount,
4043
- tradingAccount: nftTradingAccount
4044
- })
4045
- .instruction()];
4046
- case 3:
4047
- updateNftTradingAccountInstruction = _a.sent();
4048
- instructions.push(updateNftTradingAccountInstruction);
4049
- return [3, 5];
4050
- case 4:
4051
- err_8 = _a.sent();
4052
- console.log("perpClient updateNftAccount error:: ", err_8);
4053
- throw err_8;
4054
- case 5: return [2, {
4055
- instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4056
- additionalSigners: additionalSigners
4057
- }];
4058
- }
4059
- });
4060
- }); };
4061
- this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
4062
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
4063
- return __generator(this, function (_a) {
4064
- switch (_a.label) {
4065
- case 0:
4066
- publicKey = this.provider.wallet.publicKey;
4067
- preInstructions = [];
4068
- instructions = [];
4069
- postInstructions = [];
4070
- additionalSigners = [];
4071
- _a.label = 1;
4072
- case 1:
4073
- _a.trys.push([1, 3, , 4]);
4074
- nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
4075
- Buffer.from("trading"),
4076
- nftMint.toBuffer(),
4077
- ], this.programId)[0];
4078
- metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
4079
- return [4, this.program.methods
4080
- .levelUp({})
4081
- .accounts({
4082
- owner: publicKey,
4083
- perpetuals: this.perpetuals.publicKey,
4084
- pool: poolConfig.poolAddress,
4085
- metadataAccount: metadataAccount,
4086
- nftMint: nftMint,
4087
- metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
4088
- tradingAccount: nftTradingAccount,
4089
- transferAuthority: this.authority.publicKey,
4090
- authorizationRulesAccount: authorizationRulesAccount,
4091
- authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
4092
- systemProgram: web3_js_1.SystemProgram.programId,
4093
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4094
- })
4095
- .instruction()];
4096
- case 2:
4097
- levelUpInstruction = _a.sent();
4098
- instructions.push(levelUpInstruction);
4099
- return [3, 4];
4100
- case 3:
4101
- err_9 = _a.sent();
4102
- console.log("perpClient levelUp error:: ", err_9);
4103
- throw err_9;
4104
- case 4: return [2, {
4105
- instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4106
- additionalSigners: additionalSigners
4107
- }];
4108
- }
4109
- });
4110
- }); };
4111
4099
  this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4112
- var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_10;
4100
+ var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
4113
4101
  return __generator(this, function (_a) {
4114
4102
  switch (_a.label) {
4115
4103
  case 0:
@@ -4151,9 +4139,9 @@ var PerpetualsClient = (function () {
4151
4139
  instructions.push(depositStakeInstruction);
4152
4140
  return [3, 5];
4153
4141
  case 4:
4154
- err_10 = _a.sent();
4155
- console.log("perpClient depositStaking error:: ", err_10);
4156
- throw err_10;
4142
+ err_8 = _a.sent();
4143
+ console.log("perpClient depositStaking error:: ", err_8);
4144
+ throw err_8;
4157
4145
  case 5: return [2, {
4158
4146
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4159
4147
  additionalSigners: additionalSigners
@@ -4162,7 +4150,7 @@ var PerpetualsClient = (function () {
4162
4150
  });
4163
4151
  }); };
4164
4152
  this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
4165
- var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_11;
4153
+ var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
4166
4154
  return __generator(this, function (_c) {
4167
4155
  switch (_c.label) {
4168
4156
  case 0:
@@ -4209,9 +4197,9 @@ var PerpetualsClient = (function () {
4209
4197
  refreshStakeInstruction = _c.sent();
4210
4198
  return [2, refreshStakeInstruction];
4211
4199
  case 2:
4212
- err_11 = _c.sent();
4213
- console.log("perpClient refreshStaking error:: ", err_11);
4214
- throw err_11;
4200
+ err_9 = _c.sent();
4201
+ console.log("perpClient refreshStaking error:: ", err_9);
4202
+ throw err_9;
4215
4203
  case 3: return [2];
4216
4204
  }
4217
4205
  });
@@ -4222,7 +4210,7 @@ var PerpetualsClient = (function () {
4222
4210
  args_1[_i - 3] = arguments[_i];
4223
4211
  }
4224
4212
  return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4225
- var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_12;
4213
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
4226
4214
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4227
4215
  return __generator(this, function (_c) {
4228
4216
  switch (_c.label) {
@@ -4270,9 +4258,9 @@ var PerpetualsClient = (function () {
4270
4258
  refreshStakeInstruction = _c.sent();
4271
4259
  return [2, refreshStakeInstruction];
4272
4260
  case 2:
4273
- err_12 = _c.sent();
4274
- console.log("perpClient refreshStaking error:: ", err_12);
4275
- throw err_12;
4261
+ err_10 = _c.sent();
4262
+ console.log("perpClient refreshStaking error:: ", err_10);
4263
+ throw err_10;
4276
4264
  case 3: return [2];
4277
4265
  }
4278
4266
  });
@@ -4284,7 +4272,7 @@ var PerpetualsClient = (function () {
4284
4272
  args_1[_i - 3] = arguments[_i];
4285
4273
  }
4286
4274
  return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4287
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_13;
4275
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
4288
4276
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4289
4277
  return __generator(this, function (_b) {
4290
4278
  switch (_b.label) {
@@ -4336,9 +4324,9 @@ var PerpetualsClient = (function () {
4336
4324
  instructions.push(unstakeInstantInstruction);
4337
4325
  return [3, 6];
4338
4326
  case 5:
4339
- err_13 = _b.sent();
4340
- console.log("perpClient unstakeInstant error:: ", err_13);
4341
- throw err_13;
4327
+ err_11 = _b.sent();
4328
+ console.log("perpClient unstakeInstant error:: ", err_11);
4329
+ throw err_11;
4342
4330
  case 6: return [2, {
4343
4331
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4344
4332
  additionalSigners: additionalSigners
@@ -4348,7 +4336,7 @@ var PerpetualsClient = (function () {
4348
4336
  });
4349
4337
  };
4350
4338
  this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
4351
- var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_14;
4339
+ var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
4352
4340
  return __generator(this, function (_c) {
4353
4341
  switch (_c.label) {
4354
4342
  case 0:
@@ -4392,15 +4380,15 @@ var PerpetualsClient = (function () {
4392
4380
  refreshStakeInstruction = _c.sent();
4393
4381
  return [2, refreshStakeInstruction];
4394
4382
  case 2:
4395
- err_14 = _c.sent();
4396
- console.log("perpClient refreshStaking error:: ", err_14);
4397
- throw err_14;
4383
+ err_12 = _c.sent();
4384
+ console.log("perpClient refreshStaking error:: ", err_12);
4385
+ throw err_12;
4398
4386
  case 3: return [2];
4399
4387
  }
4400
4388
  });
4401
4389
  }); };
4402
4390
  this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4403
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_15;
4391
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
4404
4392
  return __generator(this, function (_a) {
4405
4393
  switch (_a.label) {
4406
4394
  case 0:
@@ -4434,9 +4422,9 @@ var PerpetualsClient = (function () {
4434
4422
  instructions.push(unstakeRequestInstruction);
4435
4423
  return [3, 4];
4436
4424
  case 3:
4437
- err_15 = _a.sent();
4438
- console.log("perpClient unstakeRequest error:: ", err_15);
4439
- throw err_15;
4425
+ err_13 = _a.sent();
4426
+ console.log("perpClient unstakeRequest error:: ", err_13);
4427
+ throw err_13;
4440
4428
  case 4: return [2, {
4441
4429
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4442
4430
  additionalSigners: additionalSigners
@@ -4450,7 +4438,7 @@ var PerpetualsClient = (function () {
4450
4438
  args_1[_i - 1] = arguments[_i];
4451
4439
  }
4452
4440
  return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
4453
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_16;
4441
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
4454
4442
  if (pendingActivation === void 0) { pendingActivation = true; }
4455
4443
  if (deactivated === void 0) { deactivated = true; }
4456
4444
  if (createUserLPTA === void 0) { createUserLPTA = true; }
@@ -4506,9 +4494,9 @@ var PerpetualsClient = (function () {
4506
4494
  instructions.push(withdrawStakeInstruction);
4507
4495
  return [3, 6];
4508
4496
  case 5:
4509
- err_16 = _b.sent();
4510
- console.log("perpClient withdrawStake error:: ", err_16);
4511
- throw err_16;
4497
+ err_14 = _b.sent();
4498
+ console.log("perpClient withdrawStake error:: ", err_14);
4499
+ throw err_14;
4512
4500
  case 6: return [2, {
4513
4501
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4514
4502
  additionalSigners: additionalSigners
@@ -4523,7 +4511,7 @@ var PerpetualsClient = (function () {
4523
4511
  args_1[_i - 3] = arguments[_i];
4524
4512
  }
4525
4513
  return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
4526
- var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_17;
4514
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
4527
4515
  if (createUserATA === void 0) { createUserATA = true; }
4528
4516
  return __generator(this, function (_b) {
4529
4517
  switch (_b.label) {
@@ -4584,9 +4572,9 @@ var PerpetualsClient = (function () {
4584
4572
  instructions.push(withdrawStakeInstruction);
4585
4573
  return [3, 6];
4586
4574
  case 5:
4587
- err_17 = _b.sent();
4588
- console.log("perpClient withdrawStake error:: ", err_17);
4589
- throw err_17;
4575
+ err_15 = _b.sent();
4576
+ console.log("perpClient withdrawStake error:: ", err_15);
4577
+ throw err_15;
4590
4578
  case 6: return [2, {
4591
4579
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4592
4580
  additionalSigners: additionalSigners
@@ -4601,7 +4589,7 @@ var PerpetualsClient = (function () {
4601
4589
  args_1[_i - 5] = arguments[_i];
4602
4590
  }
4603
4591
  return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
4604
- var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_18;
4592
+ var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_16;
4605
4593
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4606
4594
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4607
4595
  if (userPublicKey === void 0) { userPublicKey = undefined; }
@@ -4729,8 +4717,8 @@ var PerpetualsClient = (function () {
4729
4717
  instructions.push(addCompoundingLiquidity);
4730
4718
  return [3, 10];
4731
4719
  case 9:
4732
- err_18 = _f.sent();
4733
- console.log("perpClient addCompoundingLiquidity error:: ", err_18);
4720
+ err_16 = _f.sent();
4721
+ console.log("perpClient addCompoundingLiquidity error:: ", err_16);
4734
4722
  return [3, 10];
4735
4723
  case 10: return [2, {
4736
4724
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4746,7 +4734,7 @@ var PerpetualsClient = (function () {
4746
4734
  args_1[_i - 5] = arguments[_i];
4747
4735
  }
4748
4736
  return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
4749
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_19;
4737
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_17;
4750
4738
  if (createUserATA === void 0) { createUserATA = true; }
4751
4739
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4752
4740
  if (userPublicKey === void 0) { userPublicKey = undefined; }
@@ -4858,8 +4846,8 @@ var PerpetualsClient = (function () {
4858
4846
  instructions.push(removeCompoundingLiquidity);
4859
4847
  return [3, 8];
4860
4848
  case 7:
4861
- err_19 = _f.sent();
4862
- console.log("perpClient removeCompoundingLiquidity error:: ", err_19);
4849
+ err_17 = _f.sent();
4850
+ console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
4863
4851
  return [3, 8];
4864
4852
  case 8: return [2, {
4865
4853
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4875,7 +4863,7 @@ var PerpetualsClient = (function () {
4875
4863
  args_1[_i - 3] = arguments[_i];
4876
4864
  }
4877
4865
  return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
4878
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_20;
4866
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_18;
4879
4867
  if (createUserATA === void 0) { createUserATA = true; }
4880
4868
  return __generator(this, function (_g) {
4881
4869
  switch (_g.label) {
@@ -4973,8 +4961,8 @@ var PerpetualsClient = (function () {
4973
4961
  instructions.push(migrateStake);
4974
4962
  return [3, 8];
4975
4963
  case 7:
4976
- err_20 = _g.sent();
4977
- console.log("perpClient migrateStake error:: ", err_20);
4964
+ err_18 = _g.sent();
4965
+ console.log("perpClient migrateStake error:: ", err_18);
4978
4966
  return [3, 8];
4979
4967
  case 8: return [2, {
4980
4968
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4985,7 +4973,7 @@ var PerpetualsClient = (function () {
4985
4973
  });
4986
4974
  };
4987
4975
  this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4988
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_21;
4976
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
4989
4977
  return __generator(this, function (_d) {
4990
4978
  switch (_d.label) {
4991
4979
  case 0:
@@ -5057,8 +5045,8 @@ var PerpetualsClient = (function () {
5057
5045
  instructions.push(migrateFlp);
5058
5046
  return [3, 4];
5059
5047
  case 3:
5060
- err_21 = _d.sent();
5061
- console.log("perpClient migrateFlp error:: ", err_21);
5048
+ err_19 = _d.sent();
5049
+ console.log("perpClient migrateFlp error:: ", err_19);
5062
5050
  return [3, 4];
5063
5051
  case 4: return [2, {
5064
5052
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -5073,7 +5061,7 @@ var PerpetualsClient = (function () {
5073
5061
  args_1[_i - 1] = arguments[_i];
5074
5062
  }
5075
5063
  return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
5076
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_22;
5064
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
5077
5065
  if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
5078
5066
  return __generator(this, function (_e) {
5079
5067
  switch (_e.label) {
@@ -5131,8 +5119,8 @@ var PerpetualsClient = (function () {
5131
5119
  instructions.push(compoundingFee);
5132
5120
  return [3, 4];
5133
5121
  case 3:
5134
- err_22 = _e.sent();
5135
- console.log("perpClient compoundingFee error:: ", err_22);
5122
+ err_20 = _e.sent();
5123
+ console.log("perpClient compoundingFee error:: ", err_20);
5136
5124
  return [3, 4];
5137
5125
  case 4: return [2, {
5138
5126
  instructions: __spreadArray([], instructions, true),
@@ -5142,146 +5130,8 @@ var PerpetualsClient = (function () {
5142
5130
  });
5143
5131
  });
5144
5132
  };
5145
- this.burnAndClaim = function (owner, nftMint, poolConfig, createAta) { return __awaiter(_this, void 0, void 0, function () {
5146
- var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction, err_23;
5147
- return __generator(this, function (_b) {
5148
- switch (_b.label) {
5149
- case 0:
5150
- preInstructions = [];
5151
- instructions = [];
5152
- postInstructions = [];
5153
- additionalSigners = [];
5154
- _b.label = 1;
5155
- case 1:
5156
- _b.trys.push([1, 7, , 8]);
5157
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, owner, true)];
5158
- case 2:
5159
- userTokenAccount = _b.sent();
5160
- _a = createAta;
5161
- if (!_a) return [3, 4];
5162
- return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
5163
- case 3:
5164
- _a = !(_b.sent());
5165
- _b.label = 4;
5166
- case 4:
5167
- if (_a) {
5168
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(owner, userTokenAccount, owner, poolConfig.tokenMint));
5169
- }
5170
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
5171
- case 5:
5172
- nftTokenAccount = _b.sent();
5173
- nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
5174
- Buffer.from("trading"),
5175
- nftMint.toBuffer(),
5176
- ], this.programId)[0];
5177
- metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5178
- collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5179
- edition = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("edition")], constants_1.METAPLEX_PROGRAM_ID)[0];
5180
- tokenRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("token_record"), nftTokenAccount.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5181
- return [4, this.program.methods
5182
- .burnAndClaim({})
5183
- .accounts({
5184
- owner: owner,
5185
- receivingTokenAccount: userTokenAccount,
5186
- perpetuals: this.perpetuals.publicKey,
5187
- tokenVault: poolConfig.tokenVault,
5188
- tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
5189
- metadataAccount: metadataAccount,
5190
- collectionMetadata: collectionMetadata,
5191
- edition: edition,
5192
- tokenRecord: tokenRecord,
5193
- tradingAccount: nftTradingAccount,
5194
- transferAuthority: poolConfig.transferAuthority,
5195
- metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
5196
- nftMint: nftMint,
5197
- nftTokenAccount: nftTokenAccount,
5198
- systemProgram: web3_js_1.SystemProgram.programId,
5199
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5200
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5201
- eventAuthority: this.eventAuthority.publicKey,
5202
- program: this.programId,
5203
- receivingTokenMint: poolConfig.tokenMint,
5204
- })
5205
- .instruction()];
5206
- case 6:
5207
- burnAndClaimInstruction = _b.sent();
5208
- instructions.push(burnAndClaimInstruction);
5209
- return [3, 8];
5210
- case 7:
5211
- err_23 = _b.sent();
5212
- console.log("perpClient burnAndClaimInstruction error:: ", err_23);
5213
- throw err_23;
5214
- case 8: return [2, {
5215
- instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5216
- additionalSigners: additionalSigners
5217
- }];
5218
- }
5219
- });
5220
- }); };
5221
- this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5222
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_24;
5223
- return __generator(this, function (_a) {
5224
- switch (_a.label) {
5225
- case 0:
5226
- preInstructions = [];
5227
- instructions = [];
5228
- postInstructions = [];
5229
- additionalSigners = [];
5230
- _a.label = 1;
5231
- case 1:
5232
- _a.trys.push([1, 3, , 4]);
5233
- tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
5234
- nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
5235
- nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
5236
- Buffer.from("trading"),
5237
- nftMint.toBuffer(),
5238
- ], this.programId)[0];
5239
- metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5240
- collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5241
- edition = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("edition")], constants_1.METAPLEX_PROGRAM_ID)[0];
5242
- tokenRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("token_record"), nftTokenAccount.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5243
- return [4, this.program.methods
5244
- .burnAndStake({})
5245
- .accounts({
5246
- owner: owner,
5247
- feePayer: feePayer,
5248
- perpetuals: this.perpetuals.publicKey,
5249
- tokenVault: poolConfig.tokenVault,
5250
- tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
5251
- tokenStakeAccount: tokenStakeAccount,
5252
- metadataAccount: metadataAccount,
5253
- collectionMetadata: collectionMetadata,
5254
- edition: edition,
5255
- tokenRecord: tokenRecord,
5256
- tradingAccount: nftTradingAccount,
5257
- transferAuthority: poolConfig.transferAuthority,
5258
- metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
5259
- nftMint: nftMint,
5260
- nftTokenAccount: nftTokenAccount,
5261
- systemProgram: web3_js_1.SystemProgram.programId,
5262
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5263
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5264
- eventAuthority: this.eventAuthority.publicKey,
5265
- program: this.programId
5266
- })
5267
- .instruction()];
5268
- case 2:
5269
- burnAndStakeInstruction = _a.sent();
5270
- instructions.push(burnAndStakeInstruction);
5271
- return [3, 4];
5272
- case 3:
5273
- err_24 = _a.sent();
5274
- console.log("perpClient burnAndStakeInstruction error:: ", err_24);
5275
- throw err_24;
5276
- case 4: return [2, {
5277
- instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5278
- additionalSigners: additionalSigners
5279
- }];
5280
- }
5281
- });
5282
- }); };
5283
5133
  this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5284
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
5134
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_21;
5285
5135
  return __generator(this, function (_a) {
5286
5136
  switch (_a.label) {
5287
5137
  case 0:
@@ -5323,9 +5173,9 @@ var PerpetualsClient = (function () {
5323
5173
  instructions.push(depositTokenStakeInstruction);
5324
5174
  return [3, 5];
5325
5175
  case 4:
5326
- err_25 = _a.sent();
5327
- console.log("perpClient depositStakingInstruction error:: ", err_25);
5328
- throw err_25;
5176
+ err_21 = _a.sent();
5177
+ console.log("perpClient depositStakingInstruction error:: ", err_21);
5178
+ throw err_21;
5329
5179
  case 5: return [2, {
5330
5180
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5331
5181
  additionalSigners: additionalSigners
@@ -5334,7 +5184,7 @@ var PerpetualsClient = (function () {
5334
5184
  });
5335
5185
  }); };
5336
5186
  this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5337
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_26;
5187
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
5338
5188
  return __generator(this, function (_a) {
5339
5189
  switch (_a.label) {
5340
5190
  case 0:
@@ -5363,9 +5213,9 @@ var PerpetualsClient = (function () {
5363
5213
  instructions.push(unstakeTokenRequestInstruction);
5364
5214
  return [3, 4];
5365
5215
  case 3:
5366
- err_26 = _a.sent();
5367
- console.log("perpClient unstakeTokenRequestInstruction error:: ", err_26);
5368
- throw err_26;
5216
+ err_22 = _a.sent();
5217
+ console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
5218
+ throw err_22;
5369
5219
  case 4: return [2, {
5370
5220
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5371
5221
  additionalSigners: additionalSigners
@@ -5374,7 +5224,7 @@ var PerpetualsClient = (function () {
5374
5224
  });
5375
5225
  }); };
5376
5226
  this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5377
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_27;
5227
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
5378
5228
  return __generator(this, function (_a) {
5379
5229
  switch (_a.label) {
5380
5230
  case 0:
@@ -5415,9 +5265,9 @@ var PerpetualsClient = (function () {
5415
5265
  instructions.push(unstakeTokenInstantInstruction);
5416
5266
  return [3, 5];
5417
5267
  case 4:
5418
- err_27 = _a.sent();
5419
- console.log("perpClient unstakeTokenInstantInstruction error:: ", err_27);
5420
- throw err_27;
5268
+ err_23 = _a.sent();
5269
+ console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
5270
+ throw err_23;
5421
5271
  case 5: return [2, {
5422
5272
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5423
5273
  additionalSigners: additionalSigners
@@ -5426,7 +5276,7 @@ var PerpetualsClient = (function () {
5426
5276
  });
5427
5277
  }); };
5428
5278
  this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5429
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_28;
5279
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
5430
5280
  return __generator(this, function (_a) {
5431
5281
  switch (_a.label) {
5432
5282
  case 0:
@@ -5467,9 +5317,9 @@ var PerpetualsClient = (function () {
5467
5317
  instructions.push(withdrawTokenInstruction);
5468
5318
  return [3, 5];
5469
5319
  case 4:
5470
- err_28 = _a.sent();
5471
- console.log("perpClient withdrawTokenInstruction error:: ", err_28);
5472
- throw err_28;
5320
+ err_24 = _a.sent();
5321
+ console.log("perpClient withdrawTokenInstruction error:: ", err_24);
5322
+ throw err_24;
5473
5323
  case 5: return [2, {
5474
5324
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5475
5325
  additionalSigners: additionalSigners
@@ -5478,7 +5328,7 @@ var PerpetualsClient = (function () {
5478
5328
  });
5479
5329
  }); };
5480
5330
  this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5481
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_29;
5331
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
5482
5332
  return __generator(this, function (_a) {
5483
5333
  switch (_a.label) {
5484
5334
  case 0:
@@ -5507,9 +5357,9 @@ var PerpetualsClient = (function () {
5507
5357
  instructions.push(cancelUnstakeRequestInstruction);
5508
5358
  return [3, 4];
5509
5359
  case 3:
5510
- err_29 = _a.sent();
5511
- console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_29);
5512
- throw err_29;
5360
+ err_25 = _a.sent();
5361
+ console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
5362
+ throw err_25;
5513
5363
  case 4: return [2, {
5514
5364
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5515
5365
  additionalSigners: additionalSigners
@@ -5523,7 +5373,7 @@ var PerpetualsClient = (function () {
5523
5373
  args_1[_i - 2] = arguments[_i];
5524
5374
  }
5525
5375
  return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
5526
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_30;
5376
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
5527
5377
  if (createUserATA === void 0) { createUserATA = true; }
5528
5378
  return __generator(this, function (_b) {
5529
5379
  switch (_b.label) {
@@ -5569,9 +5419,9 @@ var PerpetualsClient = (function () {
5569
5419
  instructions.push(collectTokenRewardInstruction);
5570
5420
  return [3, 6];
5571
5421
  case 5:
5572
- err_30 = _b.sent();
5573
- console.log("perpClient collectTokenRewardInstruction error:: ", err_30);
5574
- throw err_30;
5422
+ err_26 = _b.sent();
5423
+ console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
5424
+ throw err_26;
5575
5425
  case 6: return [2, {
5576
5426
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5577
5427
  additionalSigners: additionalSigners
@@ -5586,7 +5436,7 @@ var PerpetualsClient = (function () {
5586
5436
  args_1[_i - 3] = arguments[_i];
5587
5437
  }
5588
5438
  return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
5589
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_31;
5439
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
5590
5440
  if (createUserATA === void 0) { createUserATA = true; }
5591
5441
  return __generator(this, function (_b) {
5592
5442
  switch (_b.label) {
@@ -5633,9 +5483,9 @@ var PerpetualsClient = (function () {
5633
5483
  instructions.push(collectRevenueInstruction);
5634
5484
  return [3, 6];
5635
5485
  case 5:
5636
- err_31 = _b.sent();
5637
- console.log("perpClient collectRevenueInstruction error:: ", err_31);
5638
- throw err_31;
5486
+ err_27 = _b.sent();
5487
+ console.log("perpClient collectRevenueInstruction error:: ", err_27);
5488
+ throw err_27;
5639
5489
  case 6: return [2, {
5640
5490
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5641
5491
  additionalSigners: additionalSigners
@@ -5645,7 +5495,7 @@ var PerpetualsClient = (function () {
5645
5495
  });
5646
5496
  };
5647
5497
  this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5648
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
5498
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_28;
5649
5499
  return __generator(this, function (_a) {
5650
5500
  switch (_a.label) {
5651
5501
  case 0:
@@ -5682,9 +5532,9 @@ var PerpetualsClient = (function () {
5682
5532
  instructions.push(initRewardVault);
5683
5533
  return [3, 4];
5684
5534
  case 3:
5685
- err_32 = _a.sent();
5686
- console.log("perpClient InitRewardVault error:: ", err_32);
5687
- throw err_32;
5535
+ err_28 = _a.sent();
5536
+ console.log("perpClient InitRewardVault error:: ", err_28);
5537
+ throw err_28;
5688
5538
  case 4: return [2, {
5689
5539
  instructions: __spreadArray([], instructions, true),
5690
5540
  additionalSigners: additionalSigners
@@ -5693,7 +5543,7 @@ var PerpetualsClient = (function () {
5693
5543
  });
5694
5544
  }); };
5695
5545
  this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5696
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
5546
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_29;
5697
5547
  return __generator(this, function (_a) {
5698
5548
  switch (_a.label) {
5699
5549
  case 0:
@@ -5724,9 +5574,9 @@ var PerpetualsClient = (function () {
5724
5574
  instructions.push(distributeReward);
5725
5575
  return [3, 4];
5726
5576
  case 3:
5727
- err_33 = _a.sent();
5728
- console.log("perpClient distributeReward error:: ", err_33);
5729
- throw err_33;
5577
+ err_29 = _a.sent();
5578
+ console.log("perpClient distributeReward error:: ", err_29);
5579
+ throw err_29;
5730
5580
  case 4: return [2, {
5731
5581
  instructions: __spreadArray([], instructions, true),
5732
5582
  additionalSigners: additionalSigners
@@ -5740,7 +5590,7 @@ var PerpetualsClient = (function () {
5740
5590
  args_1[_i - 3] = arguments[_i];
5741
5591
  }
5742
5592
  return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5743
- var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
5593
+ var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_30;
5744
5594
  if (createUserATA === void 0) { createUserATA = true; }
5745
5595
  return __generator(this, function (_b) {
5746
5596
  switch (_b.label) {
@@ -5792,8 +5642,8 @@ var PerpetualsClient = (function () {
5792
5642
  instructions.push(collectNftReward);
5793
5643
  return [3, 6];
5794
5644
  case 5:
5795
- err_34 = _b.sent();
5796
- throw err_34;
5645
+ err_30 = _b.sent();
5646
+ throw err_30;
5797
5647
  case 6: return [2, {
5798
5648
  instructions: __spreadArray([], instructions, true),
5799
5649
  additionalSigners: additionalSigners
@@ -5808,7 +5658,7 @@ var PerpetualsClient = (function () {
5808
5658
  args_1[_i - 2] = arguments[_i];
5809
5659
  }
5810
5660
  return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
5811
- var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
5661
+ var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_31;
5812
5662
  if (createUserATA === void 0) { createUserATA = true; }
5813
5663
  return __generator(this, function (_b) {
5814
5664
  switch (_b.label) {
@@ -5874,9 +5724,9 @@ var PerpetualsClient = (function () {
5874
5724
  instructions.push(withdrawStakeInstruction);
5875
5725
  return [3, 6];
5876
5726
  case 5:
5877
- err_35 = _b.sent();
5878
- console.log("perpClient withdrawStake error:: ", err_35);
5879
- throw err_35;
5727
+ err_31 = _b.sent();
5728
+ console.log("perpClient withdrawStake error:: ", err_31);
5729
+ throw err_31;
5880
5730
  case 6: return [2, {
5881
5731
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5882
5732
  additionalSigners: additionalSigners
@@ -5891,7 +5741,7 @@ var PerpetualsClient = (function () {
5891
5741
  args_1[_i - 11] = arguments[_i];
5892
5742
  }
5893
5743
  return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
5894
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_36;
5744
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_32;
5895
5745
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5896
5746
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5897
5747
  return __generator(this, function (_c) {
@@ -5997,9 +5847,9 @@ var PerpetualsClient = (function () {
5997
5847
  instructions.push(placeLimitOrder);
5998
5848
  return [3, 10];
5999
5849
  case 9:
6000
- err_36 = _c.sent();
6001
- console.log("perpClient placeLimitOrder error:: ", err_36);
6002
- throw err_36;
5850
+ err_32 = _c.sent();
5851
+ console.log("perpClient placeLimitOrder error:: ", err_32);
5852
+ throw err_32;
6003
5853
  case 10: return [2, {
6004
5854
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6005
5855
  additionalSigners: additionalSigners
@@ -6014,7 +5864,7 @@ var PerpetualsClient = (function () {
6014
5864
  args_1[_i - 11] = arguments[_i];
6015
5865
  }
6016
5866
  return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6017
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_37;
5867
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_33;
6018
5868
  if (createUserATA === void 0) { createUserATA = true; }
6019
5869
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6020
5870
  return __generator(this, function (_b) {
@@ -6105,9 +5955,9 @@ var PerpetualsClient = (function () {
6105
5955
  instructions.push(editLimitOrder);
6106
5956
  return [3, 8];
6107
5957
  case 7:
6108
- err_37 = _b.sent();
6109
- console.log("perpClient editLimitOrder error:: ", err_37);
6110
- throw err_37;
5958
+ err_33 = _b.sent();
5959
+ console.log("perpClient editLimitOrder error:: ", err_33);
5960
+ throw err_33;
6111
5961
  case 8: return [2, {
6112
5962
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6113
5963
  additionalSigners: additionalSigners
@@ -6122,7 +5972,7 @@ var PerpetualsClient = (function () {
6122
5972
  args_1[_i - 7] = arguments[_i];
6123
5973
  }
6124
5974
  return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6125
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_38;
5975
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_34;
6126
5976
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6127
5977
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6128
5978
  if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
@@ -6175,9 +6025,9 @@ var PerpetualsClient = (function () {
6175
6025
  instructions.push(executeLimitOrder);
6176
6026
  return [3, 4];
6177
6027
  case 3:
6178
- err_38 = _a.sent();
6179
- console.log("perpClient executeLimitOrder error:: ", err_38);
6180
- throw err_38;
6028
+ err_34 = _a.sent();
6029
+ console.log("perpClient executeLimitOrder error:: ", err_34);
6030
+ throw err_34;
6181
6031
  case 4: return [2, {
6182
6032
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6183
6033
  additionalSigners: additionalSigners
@@ -6192,7 +6042,7 @@ var PerpetualsClient = (function () {
6192
6042
  args_1[_i - 8] = arguments[_i];
6193
6043
  }
6194
6044
  return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6195
- var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_39;
6045
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_35;
6196
6046
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6197
6047
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6198
6048
  if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
@@ -6248,9 +6098,9 @@ var PerpetualsClient = (function () {
6248
6098
  instructions.push(executeLimitWithSwap);
6249
6099
  return [3, 4];
6250
6100
  case 3:
6251
- err_39 = _a.sent();
6252
- console.log("perpClient executeLimitWithSwap error:: ", err_39);
6253
- throw err_39;
6101
+ err_35 = _a.sent();
6102
+ console.log("perpClient executeLimitWithSwap error:: ", err_35);
6103
+ throw err_35;
6254
6104
  case 4: return [2, {
6255
6105
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6256
6106
  additionalSigners: additionalSigners
@@ -6260,7 +6110,7 @@ var PerpetualsClient = (function () {
6260
6110
  });
6261
6111
  };
6262
6112
  this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6263
- var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_40;
6113
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_36;
6264
6114
  return __generator(this, function (_a) {
6265
6115
  switch (_a.label) {
6266
6116
  case 0:
@@ -6308,9 +6158,9 @@ var PerpetualsClient = (function () {
6308
6158
  instructions.push(placeTriggerOrder);
6309
6159
  return [3, 4];
6310
6160
  case 3:
6311
- err_40 = _a.sent();
6312
- console.log("perpClient placeTriggerOrder error:: ", err_40);
6313
- throw err_40;
6161
+ err_36 = _a.sent();
6162
+ console.log("perpClient placeTriggerOrder error:: ", err_36);
6163
+ throw err_36;
6314
6164
  case 4: return [2, {
6315
6165
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6316
6166
  additionalSigners: additionalSigners
@@ -6319,7 +6169,7 @@ var PerpetualsClient = (function () {
6319
6169
  });
6320
6170
  }); };
6321
6171
  this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6322
- var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_41;
6172
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_37;
6323
6173
  return __generator(this, function (_a) {
6324
6174
  switch (_a.label) {
6325
6175
  case 0:
@@ -6366,9 +6216,9 @@ var PerpetualsClient = (function () {
6366
6216
  instructions.push(editTriggerOrder);
6367
6217
  return [3, 4];
6368
6218
  case 3:
6369
- err_41 = _a.sent();
6370
- console.log("perpClient editTriggerOrder error:: ", err_41);
6371
- throw err_41;
6219
+ err_37 = _a.sent();
6220
+ console.log("perpClient editTriggerOrder error:: ", err_37);
6221
+ throw err_37;
6372
6222
  case 4: return [2, {
6373
6223
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6374
6224
  additionalSigners: additionalSigners
@@ -6377,7 +6227,7 @@ var PerpetualsClient = (function () {
6377
6227
  });
6378
6228
  }); };
6379
6229
  this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6380
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_42;
6230
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_38;
6381
6231
  return __generator(this, function (_a) {
6382
6232
  switch (_a.label) {
6383
6233
  case 0:
@@ -6410,9 +6260,9 @@ var PerpetualsClient = (function () {
6410
6260
  instructions.push(cancelTriggerOrder);
6411
6261
  return [3, 4];
6412
6262
  case 3:
6413
- err_42 = _a.sent();
6414
- console.log("perpClient cancelTriggerOrder error:: ", err_42);
6415
- throw err_42;
6263
+ err_38 = _a.sent();
6264
+ console.log("perpClient cancelTriggerOrder error:: ", err_38);
6265
+ throw err_38;
6416
6266
  case 4: return [2, {
6417
6267
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6418
6268
  additionalSigners: additionalSigners
@@ -6421,7 +6271,7 @@ var PerpetualsClient = (function () {
6421
6271
  });
6422
6272
  }); };
6423
6273
  this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6424
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_43;
6274
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_39;
6425
6275
  return __generator(this, function (_a) {
6426
6276
  switch (_a.label) {
6427
6277
  case 0:
@@ -6452,9 +6302,9 @@ var PerpetualsClient = (function () {
6452
6302
  instructions.push(cancelAllTriggerOrders);
6453
6303
  return [3, 4];
6454
6304
  case 3:
6455
- err_43 = _a.sent();
6456
- console.log("perpClient cancelAllTriggerOrders error:: ", err_43);
6457
- throw err_43;
6305
+ err_39 = _a.sent();
6306
+ console.log("perpClient cancelAllTriggerOrders error:: ", err_39);
6307
+ throw err_39;
6458
6308
  case 4: return [2, {
6459
6309
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6460
6310
  additionalSigners: additionalSigners
@@ -6468,7 +6318,7 @@ var PerpetualsClient = (function () {
6468
6318
  args_1[_i - 9] = arguments[_i];
6469
6319
  }
6470
6320
  return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6471
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_44;
6321
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_40;
6472
6322
  if (createUserATA === void 0) { createUserATA = true; }
6473
6323
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6474
6324
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6575,9 +6425,9 @@ var PerpetualsClient = (function () {
6575
6425
  instructions.push(executeTriggerWithSwap);
6576
6426
  return [3, 10];
6577
6427
  case 9:
6578
- err_44 = _e.sent();
6579
- console.log("perpClient executeTriggerWithSwap error:: ", err_44);
6580
- throw err_44;
6428
+ err_40 = _e.sent();
6429
+ console.log("perpClient executeTriggerWithSwap error:: ", err_40);
6430
+ throw err_40;
6581
6431
  case 10: return [2, {
6582
6432
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6583
6433
  additionalSigners: additionalSigners
@@ -6592,7 +6442,7 @@ var PerpetualsClient = (function () {
6592
6442
  args_1[_i - 8] = arguments[_i];
6593
6443
  }
6594
6444
  return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6595
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_45;
6445
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_41;
6596
6446
  if (createUserATA === void 0) { createUserATA = true; }
6597
6447
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6598
6448
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6664,9 +6514,9 @@ var PerpetualsClient = (function () {
6664
6514
  instructions.push(executeTriggerOrder);
6665
6515
  return [3, 8];
6666
6516
  case 7:
6667
- err_45 = _b.sent();
6668
- console.log("perpClient executeTriggerOrder error:: ", err_45);
6669
- throw err_45;
6517
+ err_41 = _b.sent();
6518
+ console.log("perpClient executeTriggerOrder error:: ", err_41);
6519
+ throw err_41;
6670
6520
  case 8: return [2, {
6671
6521
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6672
6522
  additionalSigners: additionalSigners
@@ -6681,7 +6531,7 @@ var PerpetualsClient = (function () {
6681
6531
  args_1[_i - 5] = arguments[_i];
6682
6532
  }
6683
6533
  return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
6684
- var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_46;
6534
+ var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_42;
6685
6535
  if (useFeesPool === void 0) { useFeesPool = false; }
6686
6536
  if (createUserATA === void 0) { createUserATA = true; }
6687
6537
  if (unWrapSol === void 0) { unWrapSol = false; }
@@ -6886,9 +6736,9 @@ var PerpetualsClient = (function () {
6886
6736
  }
6887
6737
  return [3, 20];
6888
6738
  case 19:
6889
- err_46 = _g.sent();
6890
- console.error("perpClient Swap error:: ", err_46);
6891
- throw err_46;
6739
+ err_42 = _g.sent();
6740
+ console.error("perpClient Swap error:: ", err_42);
6741
+ throw err_42;
6892
6742
  case 20: return [2, {
6893
6743
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6894
6744
  additionalSigners: additionalSigners
@@ -6898,7 +6748,7 @@ var PerpetualsClient = (function () {
6898
6748
  });
6899
6749
  };
6900
6750
  this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6901
- var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_47;
6751
+ var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_43;
6902
6752
  return __generator(this, function (_b) {
6903
6753
  switch (_b.label) {
6904
6754
  case 0:
@@ -6958,9 +6808,9 @@ var PerpetualsClient = (function () {
6958
6808
  instructions.push(inx);
6959
6809
  return [3, 4];
6960
6810
  case 3:
6961
- err_47 = _b.sent();
6962
- console.error("perpClient Swap error:: ", err_47);
6963
- throw err_47;
6811
+ err_43 = _b.sent();
6812
+ console.error("perpClient Swap error:: ", err_43);
6813
+ throw err_43;
6964
6814
  case 4: return [2, {
6965
6815
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6966
6816
  additionalSigners: additionalSigners
@@ -6969,7 +6819,7 @@ var PerpetualsClient = (function () {
6969
6819
  });
6970
6820
  }); };
6971
6821
  this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6972
- var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_48;
6822
+ var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_44;
6973
6823
  return __generator(this, function (_d) {
6974
6824
  switch (_d.label) {
6975
6825
  case 0:
@@ -7017,9 +6867,9 @@ var PerpetualsClient = (function () {
7017
6867
  instructions.push(setLpTokenPriceInstruction);
7018
6868
  return [3, 4];
7019
6869
  case 3:
7020
- err_48 = _d.sent();
7021
- console.log("perpClient setLpTokenPriceInstruction error:: ", err_48);
7022
- throw err_48;
6870
+ err_44 = _d.sent();
6871
+ console.log("perpClient setLpTokenPriceInstruction error:: ", err_44);
6872
+ throw err_44;
7023
6873
  case 4: return [2, {
7024
6874
  instructions: __spreadArray([], instructions, true),
7025
6875
  additionalSigners: additionalSigners
@@ -7067,7 +6917,7 @@ var PerpetualsClient = (function () {
7067
6917
  });
7068
6918
  }); };
7069
6919
  this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
7070
- var adminMetas, _i, admins_2, admin, err_49;
6920
+ var adminMetas, _i, admins_2, admin, err_45;
7071
6921
  return __generator(this, function (_a) {
7072
6922
  switch (_a.label) {
7073
6923
  case 0:
@@ -7097,11 +6947,11 @@ var PerpetualsClient = (function () {
7097
6947
  _a.sent();
7098
6948
  return [3, 4];
7099
6949
  case 3:
7100
- err_49 = _a.sent();
6950
+ err_45 = _a.sent();
7101
6951
  if (this.printErrors) {
7102
- console.error("setAdminSigners err:", err_49);
6952
+ console.error("setAdminSigners err:", err_45);
7103
6953
  }
7104
- throw err_49;
6954
+ throw err_45;
7105
6955
  case 4: return [2];
7106
6956
  }
7107
6957
  });
@@ -7290,7 +7140,7 @@ var PerpetualsClient = (function () {
7290
7140
  });
7291
7141
  }); };
7292
7142
  this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7293
- var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_50;
7143
+ var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_46;
7294
7144
  return __generator(this, function (_a) {
7295
7145
  switch (_a.label) {
7296
7146
  case 0:
@@ -7323,9 +7173,9 @@ var PerpetualsClient = (function () {
7323
7173
  instructions.push(withdrawFeesIx);
7324
7174
  return [3, 5];
7325
7175
  case 4:
7326
- err_50 = _a.sent();
7327
- console.log("perpClient setPool error:: ", err_50);
7328
- throw err_50;
7176
+ err_46 = _a.sent();
7177
+ console.log("perpClient setPool error:: ", err_46);
7178
+ throw err_46;
7329
7179
  case 5: return [2, {
7330
7180
  instructions: __spreadArray([], instructions, true),
7331
7181
  additionalSigners: additionalSigners
@@ -7334,7 +7184,7 @@ var PerpetualsClient = (function () {
7334
7184
  });
7335
7185
  }); };
7336
7186
  this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7337
- var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_51;
7187
+ var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_47;
7338
7188
  return __generator(this, function (_a) {
7339
7189
  switch (_a.label) {
7340
7190
  case 0:
@@ -7368,9 +7218,9 @@ var PerpetualsClient = (function () {
7368
7218
  instructions.push(moveProtocolFeesIx);
7369
7219
  return [3, 4];
7370
7220
  case 3:
7371
- err_51 = _a.sent();
7372
- console.log("perpClient setPool error:: ", err_51);
7373
- throw err_51;
7221
+ err_47 = _a.sent();
7222
+ console.log("perpClient setPool error:: ", err_47);
7223
+ throw err_47;
7374
7224
  case 4: return [2, {
7375
7225
  instructions: __spreadArray([], instructions, true),
7376
7226
  additionalSigners: additionalSigners
@@ -7379,7 +7229,7 @@ var PerpetualsClient = (function () {
7379
7229
  });
7380
7230
  }); };
7381
7231
  this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7382
- var publicKey, setProtocolFeeShareBpsIx, err_52;
7232
+ var publicKey, setProtocolFeeShareBpsIx, err_48;
7383
7233
  return __generator(this, function (_a) {
7384
7234
  switch (_a.label) {
7385
7235
  case 0:
@@ -7399,15 +7249,15 @@ var PerpetualsClient = (function () {
7399
7249
  setProtocolFeeShareBpsIx = _a.sent();
7400
7250
  return [2, setProtocolFeeShareBpsIx];
7401
7251
  case 2:
7402
- err_52 = _a.sent();
7403
- console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_52);
7404
- throw err_52;
7252
+ err_48 = _a.sent();
7253
+ console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_48);
7254
+ throw err_48;
7405
7255
  case 3: return [2];
7406
7256
  }
7407
7257
  });
7408
7258
  }); };
7409
7259
  this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
7410
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_53;
7260
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_49;
7411
7261
  return __generator(this, function (_a) {
7412
7262
  switch (_a.label) {
7413
7263
  case 0:
@@ -7434,9 +7284,9 @@ var PerpetualsClient = (function () {
7434
7284
  instructions.push(setPermissionsInstruction);
7435
7285
  return [3, 4];
7436
7286
  case 3:
7437
- err_53 = _a.sent();
7438
- console.log("perpClient setPool error:: ", err_53);
7439
- throw err_53;
7287
+ err_49 = _a.sent();
7288
+ console.log("perpClient setPool error:: ", err_49);
7289
+ throw err_49;
7440
7290
  case 4: return [2, {
7441
7291
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7442
7292
  additionalSigners: additionalSigners
@@ -7445,7 +7295,7 @@ var PerpetualsClient = (function () {
7445
7295
  });
7446
7296
  }); };
7447
7297
  this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7448
- var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_54;
7298
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_50;
7449
7299
  var _f;
7450
7300
  return __generator(this, function (_g) {
7451
7301
  switch (_g.label) {
@@ -7506,9 +7356,9 @@ var PerpetualsClient = (function () {
7506
7356
  instructions.push(reimburse);
7507
7357
  return [3, 5];
7508
7358
  case 4:
7509
- err_54 = _g.sent();
7510
- console.log("perpClient setPool error:: ", err_54);
7511
- throw err_54;
7359
+ err_50 = _g.sent();
7360
+ console.log("perpClient setPool error:: ", err_50);
7361
+ throw err_50;
7512
7362
  case 5: return [2, {
7513
7363
  instructions: __spreadArray([], instructions, true),
7514
7364
  additionalSigners: additionalSigners
@@ -7516,8 +7366,8 @@ var PerpetualsClient = (function () {
7516
7366
  }
7517
7367
  });
7518
7368
  }); };
7519
- this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7520
- var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_55;
7369
+ this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7370
+ var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_51;
7521
7371
  return __generator(this, function (_a) {
7522
7372
  switch (_a.label) {
7523
7373
  case 0:
@@ -7529,6 +7379,7 @@ var PerpetualsClient = (function () {
7529
7379
  _a.trys.push([1, 3, , 4]);
7530
7380
  return [4, this.program.methods
7531
7381
  .setInternalOraclePrice({
7382
+ useCurrentTime: useCurrentTime,
7532
7383
  price: price,
7533
7384
  expo: expo,
7534
7385
  conf: conf,
@@ -7550,9 +7401,9 @@ var PerpetualsClient = (function () {
7550
7401
  instructions.push(setInternalOraclePrice);
7551
7402
  return [3, 4];
7552
7403
  case 3:
7553
- err_55 = _a.sent();
7554
- console.log("perpClient setInternalOracleAccount error:: ", err_55);
7555
- throw err_55;
7404
+ err_51 = _a.sent();
7405
+ console.log("perpClient setInternalOracleAccount error:: ", err_51);
7406
+ throw err_51;
7556
7407
  case 4: return [2, {
7557
7408
  instructions: __spreadArray([], instructions, true),
7558
7409
  additionalSigners: additionalSigners
@@ -7560,8 +7411,8 @@ var PerpetualsClient = (function () {
7560
7411
  }
7561
7412
  });
7562
7413
  }); };
7563
- this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
7564
- var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_56;
7414
+ this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
7415
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_52;
7565
7416
  return __generator(this, function (_a) {
7566
7417
  switch (_a.label) {
7567
7418
  case 0:
@@ -7572,11 +7423,6 @@ var PerpetualsClient = (function () {
7572
7423
  accountMetas = [];
7573
7424
  _loop_1 = function (tokenMint) {
7574
7425
  var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
7575
- accountMetas.push({
7576
- pubkey: custody.custodyAccount,
7577
- isSigner: false,
7578
- isWritable: false,
7579
- });
7580
7426
  accountMetas.push({
7581
7427
  pubkey: custody.intOracleAccount,
7582
7428
  isSigner: false,
@@ -7599,6 +7445,7 @@ var PerpetualsClient = (function () {
7599
7445
  _a.trys.push([1, 3, , 4]);
7600
7446
  return [4, this.program.methods
7601
7447
  .setInternalCurrentPrice({
7448
+ useCurrentTime: useCurrentTime,
7602
7449
  prices: tokenInternalPrices
7603
7450
  })
7604
7451
  .accounts({
@@ -7611,9 +7458,9 @@ var PerpetualsClient = (function () {
7611
7458
  instructions.push(setInternalOraclePrice);
7612
7459
  return [3, 4];
7613
7460
  case 3:
7614
- err_56 = _a.sent();
7615
- console.log("perpClient setInternalOracleAccount error:: ", err_56);
7616
- throw err_56;
7461
+ err_52 = _a.sent();
7462
+ console.log("perpClient setInternalOracleAccount error:: ", err_52);
7463
+ throw err_52;
7617
7464
  case 4: return [2, {
7618
7465
  instructions: __spreadArray([], instructions, true),
7619
7466
  additionalSigners: additionalSigners
@@ -7622,7 +7469,7 @@ var PerpetualsClient = (function () {
7622
7469
  });
7623
7470
  }); };
7624
7471
  this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
7625
- var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_57;
7472
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_53;
7626
7473
  return __generator(this, function (_a) {
7627
7474
  switch (_a.label) {
7628
7475
  case 0:
@@ -7633,21 +7480,11 @@ var PerpetualsClient = (function () {
7633
7480
  accountMetas = [];
7634
7481
  _loop_2 = function (tokenMint) {
7635
7482
  var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
7636
- accountMetas.push({
7637
- pubkey: custody.custodyAccount,
7638
- isSigner: false,
7639
- isWritable: false,
7640
- });
7641
7483
  accountMetas.push({
7642
7484
  pubkey: custody.intOracleAccount,
7643
7485
  isSigner: false,
7644
7486
  isWritable: true,
7645
7487
  });
7646
- accountMetas.push({
7647
- pubkey: custody.extOracleAccount,
7648
- isSigner: false,
7649
- isWritable: false,
7650
- });
7651
7488
  };
7652
7489
  for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
7653
7490
  tokenMint = tokenMintList_2[_i];
@@ -7672,9 +7509,9 @@ var PerpetualsClient = (function () {
7672
7509
  instructions.push(setInternalOraclePrice);
7673
7510
  return [3, 4];
7674
7511
  case 3:
7675
- err_57 = _a.sent();
7676
- console.log("perpClient setInternalOracleAccount error:: ", err_57);
7677
- throw err_57;
7512
+ err_53 = _a.sent();
7513
+ console.log("perpClient setInternalOracleAccount error:: ", err_53);
7514
+ throw err_53;
7678
7515
  case 4: return [2, {
7679
7516
  instructions: __spreadArray([], instructions, true),
7680
7517
  additionalSigners: additionalSigners
@@ -7683,7 +7520,7 @@ var PerpetualsClient = (function () {
7683
7520
  });
7684
7521
  }); };
7685
7522
  this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7686
- var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_58;
7523
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_54;
7687
7524
  return __generator(this, function (_a) {
7688
7525
  switch (_a.label) {
7689
7526
  case 0:
@@ -7721,8 +7558,8 @@ var PerpetualsClient = (function () {
7721
7558
  instructions.push(renameFlp);
7722
7559
  return [3, 4];
7723
7560
  case 3:
7724
- err_58 = _a.sent();
7725
- console.log("perpClient renameFlp error:: ", err_58);
7561
+ err_54 = _a.sent();
7562
+ console.log("perpClient renameFlp error:: ", err_54);
7726
7563
  return [3, 4];
7727
7564
  case 4: return [2, {
7728
7565
  instructions: __spreadArray([], instructions, true),
@@ -7732,7 +7569,7 @@ var PerpetualsClient = (function () {
7732
7569
  });
7733
7570
  }); };
7734
7571
  this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7735
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_59;
7572
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_55;
7736
7573
  return __generator(this, function (_a) {
7737
7574
  switch (_a.label) {
7738
7575
  case 0:
@@ -7770,9 +7607,9 @@ var PerpetualsClient = (function () {
7770
7607
  instructions.push(initStakeInstruction);
7771
7608
  return [3, 4];
7772
7609
  case 3:
7773
- err_59 = _a.sent();
7774
- console.log("perpClient InitStaking error:: ", err_59);
7775
- throw err_59;
7610
+ err_55 = _a.sent();
7611
+ console.log("perpClient InitStaking error:: ", err_55);
7612
+ throw err_55;
7776
7613
  case 4: return [2, {
7777
7614
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7778
7615
  additionalSigners: additionalSigners
@@ -7781,7 +7618,7 @@ var PerpetualsClient = (function () {
7781
7618
  });
7782
7619
  }); };
7783
7620
  this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7784
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_60;
7621
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_56;
7785
7622
  return __generator(this, function (_a) {
7786
7623
  switch (_a.label) {
7787
7624
  case 0:
@@ -7810,7 +7647,6 @@ var PerpetualsClient = (function () {
7810
7647
  transferAuthority: poolConfig.transferAuthority,
7811
7648
  perpetuals: this.perpetuals.publicKey,
7812
7649
  pool: poolConfig.poolAddress,
7813
- custody: rewardCustodyConfig.custodyAccount,
7814
7650
  lpTokenMint: poolConfig.stakedLpTokenMint,
7815
7651
  compoundingVault: compoundingVault,
7816
7652
  compoundingTokenMint: compoundingTokenMint,
@@ -7826,9 +7662,9 @@ var PerpetualsClient = (function () {
7826
7662
  instructions.push(initCompoundingInstruction);
7827
7663
  return [3, 4];
7828
7664
  case 3:
7829
- err_60 = _a.sent();
7830
- console.log("perpClient initCompounding error:: ", err_60);
7831
- throw err_60;
7665
+ err_56 = _a.sent();
7666
+ console.log("perpClient initCompounding error:: ", err_56);
7667
+ throw err_56;
7832
7668
  case 4: return [2, {
7833
7669
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7834
7670
  additionalSigners: additionalSigners
@@ -7837,7 +7673,7 @@ var PerpetualsClient = (function () {
7837
7673
  });
7838
7674
  }); };
7839
7675
  this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7840
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_61;
7676
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_57;
7841
7677
  return __generator(this, function (_a) {
7842
7678
  switch (_a.label) {
7843
7679
  case 0:
@@ -7878,9 +7714,9 @@ var PerpetualsClient = (function () {
7878
7714
  instructions.push(initTokenVaultInstruction);
7879
7715
  return [3, 4];
7880
7716
  case 3:
7881
- err_61 = _a.sent();
7882
- console.log("perpClient InitTokenVaultInstruction error:: ", err_61);
7883
- throw err_61;
7717
+ err_57 = _a.sent();
7718
+ console.log("perpClient InitTokenVaultInstruction error:: ", err_57);
7719
+ throw err_57;
7884
7720
  case 4: return [2, {
7885
7721
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7886
7722
  additionalSigners: additionalSigners
@@ -7889,7 +7725,7 @@ var PerpetualsClient = (function () {
7889
7725
  });
7890
7726
  }); };
7891
7727
  this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7892
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_62;
7728
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_58;
7893
7729
  return __generator(this, function (_a) {
7894
7730
  switch (_a.label) {
7895
7731
  case 0:
@@ -7920,9 +7756,9 @@ var PerpetualsClient = (function () {
7920
7756
  instructions.push(setTokenVaultConfigInstruction);
7921
7757
  return [3, 4];
7922
7758
  case 3:
7923
- err_62 = _a.sent();
7924
- console.log("perpClient setTokenVaultConfigInstruction error:: ", err_62);
7925
- throw err_62;
7759
+ err_58 = _a.sent();
7760
+ console.log("perpClient setTokenVaultConfigInstruction error:: ", err_58);
7761
+ throw err_58;
7926
7762
  case 4: return [2, {
7927
7763
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7928
7764
  additionalSigners: additionalSigners
@@ -7931,7 +7767,7 @@ var PerpetualsClient = (function () {
7931
7767
  });
7932
7768
  }); };
7933
7769
  this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7934
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_63;
7770
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_59;
7935
7771
  return __generator(this, function (_a) {
7936
7772
  switch (_a.label) {
7937
7773
  case 0:
@@ -7970,9 +7806,59 @@ var PerpetualsClient = (function () {
7970
7806
  instructions.push(withdrawInstantFeeInstruction);
7971
7807
  return [3, 6];
7972
7808
  case 5:
7973
- err_63 = _a.sent();
7974
- console.log("perpClient withdrawInstantFeeInstruction error:: ", err_63);
7975
- throw err_63;
7809
+ err_59 = _a.sent();
7810
+ console.log("perpClient withdrawInstantFeeInstruction error:: ", err_59);
7811
+ throw err_59;
7812
+ case 6: return [2, {
7813
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7814
+ additionalSigners: additionalSigners
7815
+ }];
7816
+ }
7817
+ });
7818
+ }); };
7819
+ this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7820
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_60;
7821
+ return __generator(this, function (_a) {
7822
+ switch (_a.label) {
7823
+ case 0:
7824
+ publicKey = this.provider.wallet.publicKey;
7825
+ preInstructions = [];
7826
+ instructions = [];
7827
+ postInstructions = [];
7828
+ additionalSigners = [];
7829
+ _a.label = 1;
7830
+ case 1:
7831
+ _a.trys.push([1, 5, , 6]);
7832
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
7833
+ case 2:
7834
+ receivingTokenAccount = _a.sent();
7835
+ return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
7836
+ case 3:
7837
+ if (!(_a.sent())) {
7838
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
7839
+ }
7840
+ return [4, this.program.methods
7841
+ .withdrawUnclaimedTokens({})
7842
+ .accounts({
7843
+ admin: publicKey,
7844
+ multisig: this.multisig.publicKey,
7845
+ perpetuals: this.perpetuals.publicKey,
7846
+ transferAuthority: poolConfig.transferAuthority,
7847
+ tokenVault: poolConfig.tokenVault,
7848
+ tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
7849
+ receivingTokenAccount: receivingTokenAccount,
7850
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
7851
+ receivingTokenMint: poolConfig.tokenMint,
7852
+ })
7853
+ .instruction()];
7854
+ case 4:
7855
+ withdrawUnclaimedTokensInstruction = _a.sent();
7856
+ instructions.push(withdrawUnclaimedTokensInstruction);
7857
+ return [3, 6];
7858
+ case 5:
7859
+ err_60 = _a.sent();
7860
+ console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_60);
7861
+ throw err_60;
7976
7862
  case 6: return [2, {
7977
7863
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7978
7864
  additionalSigners: additionalSigners
@@ -7981,7 +7867,7 @@ var PerpetualsClient = (function () {
7981
7867
  });
7982
7868
  }); };
7983
7869
  this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7984
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_64;
7870
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_61;
7985
7871
  return __generator(this, function (_a) {
7986
7872
  switch (_a.label) {
7987
7873
  case 0:
@@ -8018,9 +7904,9 @@ var PerpetualsClient = (function () {
8018
7904
  instructions.push(initRevenueTokenAccountInstruction);
8019
7905
  return [3, 4];
8020
7906
  case 3:
8021
- err_64 = _a.sent();
8022
- console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_64);
8023
- throw err_64;
7907
+ err_61 = _a.sent();
7908
+ console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_61);
7909
+ throw err_61;
8024
7910
  case 4: return [2, {
8025
7911
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8026
7912
  additionalSigners: additionalSigners
@@ -8029,7 +7915,7 @@ var PerpetualsClient = (function () {
8029
7915
  });
8030
7916
  }); };
8031
7917
  this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
8032
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_65;
7918
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_62;
8033
7919
  return __generator(this, function (_a) {
8034
7920
  switch (_a.label) {
8035
7921
  case 0:
@@ -8068,9 +7954,9 @@ var PerpetualsClient = (function () {
8068
7954
  instructions.push(distributeTokenRewardInstruction);
8069
7955
  return [3, 4];
8070
7956
  case 3:
8071
- err_65 = _a.sent();
8072
- console.log("perpClient distributeTokenRewardInstruction error:: ", err_65);
8073
- throw err_65;
7957
+ err_62 = _a.sent();
7958
+ console.log("perpClient distributeTokenRewardInstruction error:: ", err_62);
7959
+ throw err_62;
8074
7960
  case 4: return [2, {
8075
7961
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8076
7962
  additionalSigners: additionalSigners
@@ -8079,7 +7965,7 @@ var PerpetualsClient = (function () {
8079
7965
  });
8080
7966
  }); };
8081
7967
  this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
8082
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_66;
7968
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_63;
8083
7969
  return __generator(this, function (_a) {
8084
7970
  switch (_a.label) {
8085
7971
  case 0:
@@ -8107,9 +7993,9 @@ var PerpetualsClient = (function () {
8107
7993
  instructions.push(setTokenStakeLevelInstruction);
8108
7994
  return [3, 4];
8109
7995
  case 3:
8110
- err_66 = _a.sent();
8111
- console.log("perpClient setTokenStakeLevelInstruction error:: ", err_66);
8112
- throw err_66;
7996
+ err_63 = _a.sent();
7997
+ console.log("perpClient setTokenStakeLevelInstruction error:: ", err_63);
7998
+ throw err_63;
8113
7999
  case 4: return [2, {
8114
8000
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8115
8001
  additionalSigners: additionalSigners
@@ -8118,7 +8004,7 @@ var PerpetualsClient = (function () {
8118
8004
  });
8119
8005
  }); };
8120
8006
  this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
8121
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_67;
8007
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_64;
8122
8008
  return __generator(this, function (_a) {
8123
8009
  switch (_a.label) {
8124
8010
  case 0:
@@ -8150,9 +8036,49 @@ var PerpetualsClient = (function () {
8150
8036
  instructions.push(setTokenRewardInstruction);
8151
8037
  return [3, 4];
8152
8038
  case 3:
8153
- err_67 = _a.sent();
8154
- console.log("perpClient setTokenRewardInstruction error:: ", err_67);
8155
- throw err_67;
8039
+ err_64 = _a.sent();
8040
+ console.log("perpClient setTokenRewardInstruction error:: ", err_64);
8041
+ throw err_64;
8042
+ case 4: return [2, {
8043
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8044
+ additionalSigners: additionalSigners
8045
+ }];
8046
+ }
8047
+ });
8048
+ }); };
8049
+ this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
8050
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_65;
8051
+ return __generator(this, function (_a) {
8052
+ switch (_a.label) {
8053
+ case 0:
8054
+ publicKey = this.provider.wallet.publicKey;
8055
+ preInstructions = [];
8056
+ instructions = [];
8057
+ postInstructions = [];
8058
+ additionalSigners = [];
8059
+ _a.label = 1;
8060
+ case 1:
8061
+ _a.trys.push([1, 3, , 4]);
8062
+ return [4, this.program.methods
8063
+ .resizeInternalOracle({
8064
+ extOracle: extOracle
8065
+ })
8066
+ .accounts({
8067
+ admin: publicKey,
8068
+ multisig: this.multisig.publicKey,
8069
+ custodyTokenMint: tokenMint,
8070
+ intOracleAccount: intOracleAccount,
8071
+ systemProgram: web3_js_1.SystemProgram.programId,
8072
+ })
8073
+ .instruction()];
8074
+ case 2:
8075
+ resizeInternalOracleInstruction = _a.sent();
8076
+ instructions.push(resizeInternalOracleInstruction);
8077
+ return [3, 4];
8078
+ case 3:
8079
+ err_65 = _a.sent();
8080
+ console.log("perpClient resizeInternalOracleInstruction error:: ", err_65);
8081
+ throw err_65;
8156
8082
  case 4: return [2, {
8157
8083
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8158
8084
  additionalSigners: additionalSigners
@@ -8230,13 +8156,13 @@ var PerpetualsClient = (function () {
8230
8156
  PerpetualsClient.prototype.getPriceAfterSlippage = function (isEntry, slippageBps, targetPrice, side) {
8231
8157
  if (isEntry) {
8232
8158
  var currentPrice = targetPrice.price;
8233
- var slippage = (0, utils_1.checkedDecimalCeilMul)(currentPrice, targetPrice.exponent, slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), targetPrice.exponent);
8159
+ var spread_i = (0, utils_1.checkedDecimalCeilMul)(currentPrice, targetPrice.exponent, slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), targetPrice.exponent);
8234
8160
  if ((0, types_1.isVariant)(side, 'long')) {
8235
- return { price: currentPrice.add(slippage), exponent: targetPrice.exponent.toNumber() };
8161
+ return { price: currentPrice.add(spread_i), exponent: targetPrice.exponent.toNumber() };
8236
8162
  }
8237
8163
  else {
8238
- if (slippage.lt(currentPrice)) {
8239
- return { price: currentPrice.sub(slippage), exponent: targetPrice.exponent.toNumber() };
8164
+ if (spread_i.lt(currentPrice)) {
8165
+ return { price: currentPrice.sub(spread_i), exponent: targetPrice.exponent.toNumber() };
8240
8166
  }
8241
8167
  else {
8242
8168
  return { price: constants_1.BN_ZERO, exponent: targetPrice.exponent.toNumber() };
@@ -8246,10 +8172,10 @@ var PerpetualsClient = (function () {
8246
8172
  }
8247
8173
  else {
8248
8174
  var current_price = targetPrice.price;
8249
- var slippage = (0, utils_1.checkedDecimalCeilMul)(current_price, targetPrice.exponent, slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), targetPrice.exponent);
8175
+ var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, targetPrice.exponent, slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), targetPrice.exponent);
8250
8176
  if ((0, types_1.isVariant)(side, 'long')) {
8251
- if (slippage.lt(current_price)) {
8252
- return { price: current_price.sub(slippage), exponent: targetPrice.exponent.toNumber() };
8177
+ if (spread_i.lt(current_price)) {
8178
+ return { price: current_price.sub(spread_i), exponent: targetPrice.exponent.toNumber() };
8253
8179
  }
8254
8180
  else {
8255
8181
  return { price: constants_1.BN_ZERO, exponent: targetPrice.exponent.toNumber() };
@@ -8257,7 +8183,7 @@ var PerpetualsClient = (function () {
8257
8183
  ;
8258
8184
  }
8259
8185
  else {
8260
- return { price: current_price.add(slippage), exponent: targetPrice.exponent.toNumber() };
8186
+ return { price: current_price.add(spread_i), exponent: targetPrice.exponent.toNumber() };
8261
8187
  }
8262
8188
  }
8263
8189
  };