flash-sdk 9.0.3 → 9.9.0-alpha.0

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.
@@ -91,31 +91,35 @@ var PerpetualsClient = (function () {
91
91
  _this.prioritizationFee = fee;
92
92
  };
93
93
  this.loadAddressLookupTable = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
94
- var addresses, _i, _a, address, addressLookupTable, accCreationLamports;
95
- return __generator(this, function (_b) {
96
- switch (_b.label) {
94
+ var addresses, _i, _a, address, addressLookupTable, _b, accCreationLamports;
95
+ return __generator(this, function (_c) {
96
+ switch (_c.label) {
97
97
  case 0:
98
98
  addresses = [];
99
99
  _i = 0, _a = poolConfig.addressLookupTableAddresses;
100
- _b.label = 1;
100
+ _c.label = 1;
101
101
  case 1:
102
102
  if (!(_i < _a.length)) return [3, 4];
103
103
  address = _a[_i];
104
104
  return [4, this.provider.connection.getAddressLookupTable(address)];
105
105
  case 2:
106
- addressLookupTable = (_b.sent()).value;
106
+ addressLookupTable = (_c.sent()).value;
107
107
  if (addressLookupTable) {
108
108
  addresses.push(addressLookupTable);
109
109
  }
110
- _b.label = 3;
110
+ _c.label = 3;
111
111
  case 3:
112
112
  _i++;
113
113
  return [3, 1];
114
114
  case 4:
115
115
  this.addressLookupTables = addresses;
116
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
116
+ _b = this;
117
+ return [4, this.provider.connection.getAddressLookupTable(poolConfig.pusherAddressLookupTableAddress)];
117
118
  case 5:
118
- accCreationLamports = (_b.sent());
119
+ _b.pusherAddressLookupTables = (_c.sent()).value;
120
+ return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
121
+ case 6:
122
+ accCreationLamports = (_c.sent());
119
123
  if (accCreationLamports) {
120
124
  this.minimumBalanceForRentExemptAccountLamports = accCreationLamports;
121
125
  }
@@ -459,16 +463,13 @@ var PerpetualsClient = (function () {
459
463
  };
460
464
  };
461
465
  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
466
  if (!outputTokenPrice.exponent.eq(outputTokenEmaPrice.exponent)) {
466
467
  throw new Error("exponent mistach");
467
468
  }
468
469
  var minMaxPrice = _this.getMinAndMaxOraclePriceSync(outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount);
469
470
  var removeAmountUsd = (poolAumUsdMax.mul(lpAmountIn)).div(lpTokenSupply);
470
471
  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 });
472
+ 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
473
  if (outputTokenCustodyAccount.isStable && minMaxPrice.min != minMaxPrice.max && minMaxPrice.max.price.lt(oneOracle.price)) {
473
474
  removeAmount = oneOracle.getTokenAmount(removeAmountUsd, outputTokenCustodyAccount.decimals);
474
475
  }
@@ -496,15 +497,9 @@ var PerpetualsClient = (function () {
496
497
  case types_1.FeesAction.SwapOut:
497
498
  fees = inputTokenCustodyAccount.fees.swapOut;
498
499
  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
500
  }
506
501
  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)) };
502
+ return { feeBps: fees.minFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.minFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
508
503
  }
509
504
  var newRatio = _this.getNewRatioHelper(amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax);
510
505
  var index = poolAccount.custodies.findIndex(function (c) { return c.equals(inputTokenCustodyAccount.publicKey); });
@@ -569,7 +564,6 @@ var PerpetualsClient = (function () {
569
564
  }
570
565
  else {
571
566
  minPrice.price = maxPrice.price.sub(maxPrice.confidence);
572
- maxPrice.price = maxPrice.price.add(maxPrice.confidence);
573
567
  return {
574
568
  min: minPrice,
575
569
  max: maxPrice
@@ -583,6 +577,38 @@ var PerpetualsClient = (function () {
583
577
  };
584
578
  }
585
579
  };
580
+ this.getMinAndMaxPriceSync = function (price, emaPrice, custodyAccount) {
581
+ var minPrice = price;
582
+ var divergenceBps;
583
+ if (custodyAccount.isStable) {
584
+ 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 }));
585
+ }
586
+ else {
587
+ divergenceBps = price.getDivergenceFactor(emaPrice);
588
+ }
589
+ if (divergenceBps.gte(custodyAccount.oracle.maxDivergenceBps)) {
590
+ var factorBps = custodyAccount.oracle.maxDivergenceBps.isZero ? constants_1.BN_ZERO : (divergenceBps.mul(new anchor_1.BN(constants_1.BPS_POWER))).div(custodyAccount.oracle.maxDivergenceBps);
591
+ var confBps = (price.confidence.muln(constants_1.BPS_POWER)).div(price.price);
592
+ if (confBps.lt(custodyAccount.oracle.maxConfBps)) {
593
+ var confFactor = anchor_1.BN.min(factorBps, new anchor_1.BN(50000));
594
+ var confScale = (price.confidence.mul(confFactor)).div(new anchor_1.BN(constants_1.BPS_POWER));
595
+ minPrice.price = price.price.sub(confScale);
596
+ }
597
+ else {
598
+ minPrice.price = price.price.sub(price.confidence);
599
+ }
600
+ }
601
+ else {
602
+ return {
603
+ min: price.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price,
604
+ max: price.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price
605
+ };
606
+ }
607
+ return {
608
+ min: minPrice.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price,
609
+ max: price.scale_to_exponent(new anchor_1.BN(constants_1.USD_DECIMALS).neg()).price
610
+ };
611
+ };
586
612
  this.checkIfPriceStaleOrCustom = function (price, emaPrice, custodyAccount, timestampInSeconds) {
587
613
  if (timestampInSeconds.lt(price.timestamp)) {
588
614
  throw new Error("current time cannot be timepassed");
@@ -671,9 +697,8 @@ var PerpetualsClient = (function () {
671
697
  return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
672
698
  }
673
699
  };
674
- this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
700
+ this.getEntryPriceAndFeeSync = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps) {
675
701
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
676
- if (enableLogs === void 0) { enableLogs = false; }
677
702
  if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
678
703
  throw new Error("Delta Amounts cannot be negative.");
679
704
  }
@@ -725,6 +750,69 @@ var PerpetualsClient = (function () {
725
750
  feeAmountAfterDiscount = feeAmount;
726
751
  }
727
752
  }
753
+ return {
754
+ entryOraclePrice: entryOraclePrice,
755
+ feeUsd: feeUsd,
756
+ feeAmount: feeAmount,
757
+ feeUsdAfterDiscount: feeUsdAfterDiscount,
758
+ feeAmountAfterDiscount: feeAmountAfterDiscount,
759
+ liquidationPrice: liquidationPrice
760
+ };
761
+ };
762
+ this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
763
+ if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
764
+ if (enableLogs === void 0) { enableLogs = false; }
765
+ if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
766
+ throw new Error("Delta Amounts cannot be negative.");
767
+ }
768
+ var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
769
+ var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
770
+ if (positionAccount === null) {
771
+ var data = __assign({}, types_1.DEFAULT_POSITION);
772
+ positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
773
+ var sizeUsd_2 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
774
+ positionAccount.sizeUsd = sizeUsd_2;
775
+ positionAccount.sizeDecimals = targetCustodyAccount.decimals;
776
+ positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
777
+ positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
778
+ }
779
+ else {
780
+ positionAccount = positionAccount.clone();
781
+ var positionEntryPrice = OraclePrice_1.OraclePrice.from({
782
+ price: positionAccount.entryPrice.price,
783
+ exponent: new anchor_1.BN(positionAccount.entryPrice.exponent),
784
+ confidence: constants_1.BN_ZERO,
785
+ timestamp: constants_1.BN_ZERO
786
+ });
787
+ entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
788
+ var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
789
+ positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
790
+ }
791
+ positionAccount.collateralAmount = positionAccount.collateralAmount.add(collateralDeltaAmount);
792
+ positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
793
+ var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
794
+ var liquidationPrice = _this.getLiquidationPriceSync(positionAccount.collateralAmount, positionAccount.sizeAmount, entryOraclePrice, lockFeeUsd, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, positionAccount);
795
+ var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
796
+ var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
797
+ var feeUsd = constants_1.BN_ZERO;
798
+ var feeAmount = constants_1.BN_ZERO;
799
+ var feeUsdAfterDiscount = constants_1.BN_ZERO;
800
+ var feeAmountAfterDiscount = constants_1.BN_ZERO;
801
+ if (positionAccount !== null && sizeDeltaAmount.isZero()) {
802
+ }
803
+ else {
804
+ feeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.openPosition).div(new anchor_1.BN(constants_1.RATE_POWER));
805
+ feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
806
+ if (discountBps.gt(constants_1.BN_ZERO)) {
807
+ feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
808
+ feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
809
+ feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
810
+ }
811
+ else {
812
+ feeUsdAfterDiscount = feeUsd;
813
+ feeAmountAfterDiscount = feeAmount;
814
+ }
815
+ }
728
816
  var divergenceBps;
729
817
  divergenceBps = targetPrice.getDivergenceFactor(targetEmaPrice);
730
818
  var vbFeeUsd = constants_1.BN_ZERO;
@@ -818,12 +906,13 @@ var PerpetualsClient = (function () {
818
906
  };
819
907
  };
820
908
  this.getTradeSpread = function (targetCustodyAccount, sizeUsd) {
821
- if (targetCustodyAccount.pricing.tradeSpreadMax.isZero() || sizeUsd.isZero()) {
909
+ if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero()
910
+ ||
911
+ sizeUsd.isZero()) {
822
912
  return constants_1.BN_ZERO;
823
913
  }
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);
914
+ 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)))))
915
+ .div(targetCustodyAccount.pricing.maxPositionLockedUsd);
827
916
  var variable = (slope.mul(sizeUsd)).div(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS))));
828
917
  var finalSpread = targetCustodyAccount.pricing.tradeSpreadMin.add(variable);
829
918
  return finalSpread;
@@ -849,7 +938,7 @@ var PerpetualsClient = (function () {
849
938
  };
850
939
  this.getSizeAmountFromLeverageAndCollateral = function (collateralAmtWithFee, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
851
940
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
852
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min.price;
941
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
853
942
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
854
943
  var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals))
855
944
  .multipliedBy(collateralTokenMinPriceUi);
@@ -876,7 +965,7 @@ var PerpetualsClient = (function () {
876
965
  var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfigSwap).minAmountOut;
877
966
  finalCollateralAmount = swapAmountOut;
878
967
  }
879
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min.price;
968
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
880
969
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
881
970
  var collateralAmtMinUsdUi = new bignumber_js_1.default(finalCollateralAmount.toString()).dividedBy(Math.pow(10, collateralTokenCustodyAccount.decimals))
882
971
  .multipliedBy(collateralTokenMinPriceUi);
@@ -895,7 +984,7 @@ var PerpetualsClient = (function () {
895
984
  };
896
985
  this.getCollateralAmountWithFeeFromLeverageAndSize = function (sizeAmount, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
897
986
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
898
- var collateralTokenMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min.price;
987
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
899
988
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
900
989
  var sizeUsd = targetPrice.getAssetAmountUsd(sizeAmount, targetCustodyAccount.decimals);
901
990
  var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
@@ -912,7 +1001,7 @@ var PerpetualsClient = (function () {
912
1001
  return (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralToken.decimals, bignumber_js_1.default.ROUND_DOWN), collateralToken.decimals);
913
1002
  };
914
1003
  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;
1004
+ var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
916
1005
  var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
917
1006
  var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
918
1007
  var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
@@ -1092,6 +1181,7 @@ var PerpetualsClient = (function () {
1092
1181
  this.getFinalCloseAmountSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
1093
1182
  var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
1094
1183
  var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
1184
+ var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
1095
1185
  var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1096
1186
  var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
1097
1187
  var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
@@ -1534,7 +1624,8 @@ var PerpetualsClient = (function () {
1534
1624
  };
1535
1625
  }
1536
1626
  var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
1537
- var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, positionAccount.sizeUsd);
1627
+ var sizeUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
1628
+ var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, sizeUsd);
1538
1629
  var collateralMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
1539
1630
  var priceDiffProfit, priceDiffLoss;
1540
1631
  var positionEntryPrice = OraclePrice_1.OraclePrice.from({
@@ -1800,7 +1891,7 @@ var PerpetualsClient = (function () {
1800
1891
  });
1801
1892
  };
1802
1893
  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;
1894
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
1804
1895
  var _d;
1805
1896
  return __generator(this, function (_e) {
1806
1897
  switch (_e.label) {
@@ -1848,6 +1939,8 @@ var PerpetualsClient = (function () {
1848
1939
  return [4, backUpOracleInstructionPromise];
1849
1940
  case 2:
1850
1941
  backUpOracleInstruction = _e.sent();
1942
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
1943
+ transaction.instructions.unshift(setCULimitIx);
1851
1944
  (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
1852
1945
  return [4, this.viewHelper.simulateTransaction(transaction)];
1853
1946
  case 3:
@@ -1914,7 +2007,7 @@ var PerpetualsClient = (function () {
1914
2007
  args_1[_i - 4] = arguments[_i];
1915
2008
  }
1916
2009
  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;
2010
+ var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
1918
2011
  var _e;
1919
2012
  if (userPublicKey === void 0) { userPublicKey = undefined; }
1920
2013
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -1965,6 +2058,8 @@ var PerpetualsClient = (function () {
1965
2058
  .transaction()];
1966
2059
  case 1:
1967
2060
  transaction = _f.sent();
2061
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2062
+ transaction.instructions.unshift(setCULimitIx);
1968
2063
  if (!enableBackupOracle) return [3, 3];
1969
2064
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
1970
2065
  case 2:
@@ -1990,7 +2085,7 @@ var PerpetualsClient = (function () {
1990
2085
  args_1[_i - 4] = arguments[_i];
1991
2086
  }
1992
2087
  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;
2088
+ var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
1994
2089
  var _e;
1995
2090
  if (userPublicKey === void 0) { userPublicKey = undefined; }
1996
2091
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -2041,6 +2136,8 @@ var PerpetualsClient = (function () {
2041
2136
  .transaction()];
2042
2137
  case 1:
2043
2138
  transaction = _f.sent();
2139
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2140
+ transaction.instructions.unshift(setCULimitIx);
2044
2141
  if (!enableBackupOracle) return [3, 3];
2045
2142
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2046
2143
  case 2:
@@ -2067,7 +2164,7 @@ var PerpetualsClient = (function () {
2067
2164
  });
2068
2165
  };
2069
2166
  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;
2167
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
2071
2168
  var _d;
2072
2169
  return __generator(this, function (_e) {
2073
2170
  switch (_e.label) {
@@ -2115,6 +2212,8 @@ var PerpetualsClient = (function () {
2115
2212
  .transaction()];
2116
2213
  case 2:
2117
2214
  transaction = _e.sent();
2215
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2216
+ transaction.instructions.unshift(setCULimitIx);
2118
2217
  (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2119
2218
  return [4, this.viewHelper.simulateTransaction(transaction)];
2120
2219
  case 3:
@@ -2131,7 +2230,7 @@ var PerpetualsClient = (function () {
2131
2230
  args_1[_i - 4] = arguments[_i];
2132
2231
  }
2133
2232
  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;
2233
+ var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2135
2234
  var _e;
2136
2235
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2137
2236
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -2186,6 +2285,8 @@ var PerpetualsClient = (function () {
2186
2285
  .transaction()];
2187
2286
  case 1:
2188
2287
  transaction = _f.sent();
2288
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2289
+ transaction.instructions.unshift(setCULimitIx);
2189
2290
  if (!enableBackupOracle) return [3, 3];
2190
2291
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2191
2292
  case 2:
@@ -2211,7 +2312,7 @@ var PerpetualsClient = (function () {
2211
2312
  args_1[_i - 4] = arguments[_i];
2212
2313
  }
2213
2314
  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;
2315
+ var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2215
2316
  var _e;
2216
2317
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2217
2318
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
@@ -2266,6 +2367,8 @@ var PerpetualsClient = (function () {
2266
2367
  .transaction()];
2267
2368
  case 1:
2268
2369
  transaction = _f.sent();
2370
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2371
+ transaction.instructions.unshift(setCULimitIx);
2269
2372
  if (!enableBackupOracle) return [3, 3];
2270
2373
  return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2271
2374
  case 2:
@@ -3997,119 +4100,8 @@ var PerpetualsClient = (function () {
3997
4100
  }
3998
4101
  });
3999
4102
  }); };
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
4103
  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;
4104
+ var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
4113
4105
  return __generator(this, function (_a) {
4114
4106
  switch (_a.label) {
4115
4107
  case 0:
@@ -4151,9 +4143,9 @@ var PerpetualsClient = (function () {
4151
4143
  instructions.push(depositStakeInstruction);
4152
4144
  return [3, 5];
4153
4145
  case 4:
4154
- err_10 = _a.sent();
4155
- console.log("perpClient depositStaking error:: ", err_10);
4156
- throw err_10;
4146
+ err_8 = _a.sent();
4147
+ console.log("perpClient depositStaking error:: ", err_8);
4148
+ throw err_8;
4157
4149
  case 5: return [2, {
4158
4150
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4159
4151
  additionalSigners: additionalSigners
@@ -4162,7 +4154,7 @@ var PerpetualsClient = (function () {
4162
4154
  });
4163
4155
  }); };
4164
4156
  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;
4157
+ var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
4166
4158
  return __generator(this, function (_c) {
4167
4159
  switch (_c.label) {
4168
4160
  case 0:
@@ -4209,9 +4201,9 @@ var PerpetualsClient = (function () {
4209
4201
  refreshStakeInstruction = _c.sent();
4210
4202
  return [2, refreshStakeInstruction];
4211
4203
  case 2:
4212
- err_11 = _c.sent();
4213
- console.log("perpClient refreshStaking error:: ", err_11);
4214
- throw err_11;
4204
+ err_9 = _c.sent();
4205
+ console.log("perpClient refreshStaking error:: ", err_9);
4206
+ throw err_9;
4215
4207
  case 3: return [2];
4216
4208
  }
4217
4209
  });
@@ -4222,7 +4214,7 @@ var PerpetualsClient = (function () {
4222
4214
  args_1[_i - 3] = arguments[_i];
4223
4215
  }
4224
4216
  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;
4217
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
4226
4218
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4227
4219
  return __generator(this, function (_c) {
4228
4220
  switch (_c.label) {
@@ -4270,9 +4262,9 @@ var PerpetualsClient = (function () {
4270
4262
  refreshStakeInstruction = _c.sent();
4271
4263
  return [2, refreshStakeInstruction];
4272
4264
  case 2:
4273
- err_12 = _c.sent();
4274
- console.log("perpClient refreshStaking error:: ", err_12);
4275
- throw err_12;
4265
+ err_10 = _c.sent();
4266
+ console.log("perpClient refreshStaking error:: ", err_10);
4267
+ throw err_10;
4276
4268
  case 3: return [2];
4277
4269
  }
4278
4270
  });
@@ -4284,7 +4276,7 @@ var PerpetualsClient = (function () {
4284
4276
  args_1[_i - 3] = arguments[_i];
4285
4277
  }
4286
4278
  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;
4279
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
4288
4280
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4289
4281
  return __generator(this, function (_b) {
4290
4282
  switch (_b.label) {
@@ -4336,9 +4328,9 @@ var PerpetualsClient = (function () {
4336
4328
  instructions.push(unstakeInstantInstruction);
4337
4329
  return [3, 6];
4338
4330
  case 5:
4339
- err_13 = _b.sent();
4340
- console.log("perpClient unstakeInstant error:: ", err_13);
4341
- throw err_13;
4331
+ err_11 = _b.sent();
4332
+ console.log("perpClient unstakeInstant error:: ", err_11);
4333
+ throw err_11;
4342
4334
  case 6: return [2, {
4343
4335
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4344
4336
  additionalSigners: additionalSigners
@@ -4348,7 +4340,7 @@ var PerpetualsClient = (function () {
4348
4340
  });
4349
4341
  };
4350
4342
  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;
4343
+ var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
4352
4344
  return __generator(this, function (_c) {
4353
4345
  switch (_c.label) {
4354
4346
  case 0:
@@ -4392,15 +4384,15 @@ var PerpetualsClient = (function () {
4392
4384
  refreshStakeInstruction = _c.sent();
4393
4385
  return [2, refreshStakeInstruction];
4394
4386
  case 2:
4395
- err_14 = _c.sent();
4396
- console.log("perpClient refreshStaking error:: ", err_14);
4397
- throw err_14;
4387
+ err_12 = _c.sent();
4388
+ console.log("perpClient refreshStaking error:: ", err_12);
4389
+ throw err_12;
4398
4390
  case 3: return [2];
4399
4391
  }
4400
4392
  });
4401
4393
  }); };
4402
4394
  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;
4395
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
4404
4396
  return __generator(this, function (_a) {
4405
4397
  switch (_a.label) {
4406
4398
  case 0:
@@ -4434,9 +4426,9 @@ var PerpetualsClient = (function () {
4434
4426
  instructions.push(unstakeRequestInstruction);
4435
4427
  return [3, 4];
4436
4428
  case 3:
4437
- err_15 = _a.sent();
4438
- console.log("perpClient unstakeRequest error:: ", err_15);
4439
- throw err_15;
4429
+ err_13 = _a.sent();
4430
+ console.log("perpClient unstakeRequest error:: ", err_13);
4431
+ throw err_13;
4440
4432
  case 4: return [2, {
4441
4433
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4442
4434
  additionalSigners: additionalSigners
@@ -4450,7 +4442,7 @@ var PerpetualsClient = (function () {
4450
4442
  args_1[_i - 1] = arguments[_i];
4451
4443
  }
4452
4444
  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;
4445
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
4454
4446
  if (pendingActivation === void 0) { pendingActivation = true; }
4455
4447
  if (deactivated === void 0) { deactivated = true; }
4456
4448
  if (createUserLPTA === void 0) { createUserLPTA = true; }
@@ -4506,9 +4498,9 @@ var PerpetualsClient = (function () {
4506
4498
  instructions.push(withdrawStakeInstruction);
4507
4499
  return [3, 6];
4508
4500
  case 5:
4509
- err_16 = _b.sent();
4510
- console.log("perpClient withdrawStake error:: ", err_16);
4511
- throw err_16;
4501
+ err_14 = _b.sent();
4502
+ console.log("perpClient withdrawStake error:: ", err_14);
4503
+ throw err_14;
4512
4504
  case 6: return [2, {
4513
4505
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4514
4506
  additionalSigners: additionalSigners
@@ -4523,7 +4515,7 @@ var PerpetualsClient = (function () {
4523
4515
  args_1[_i - 3] = arguments[_i];
4524
4516
  }
4525
4517
  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;
4518
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
4527
4519
  if (createUserATA === void 0) { createUserATA = true; }
4528
4520
  return __generator(this, function (_b) {
4529
4521
  switch (_b.label) {
@@ -4584,9 +4576,9 @@ var PerpetualsClient = (function () {
4584
4576
  instructions.push(withdrawStakeInstruction);
4585
4577
  return [3, 6];
4586
4578
  case 5:
4587
- err_17 = _b.sent();
4588
- console.log("perpClient withdrawStake error:: ", err_17);
4589
- throw err_17;
4579
+ err_15 = _b.sent();
4580
+ console.log("perpClient withdrawStake error:: ", err_15);
4581
+ throw err_15;
4590
4582
  case 6: return [2, {
4591
4583
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4592
4584
  additionalSigners: additionalSigners
@@ -4601,7 +4593,7 @@ var PerpetualsClient = (function () {
4601
4593
  args_1[_i - 5] = arguments[_i];
4602
4594
  }
4603
4595
  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;
4596
+ 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
4597
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4606
4598
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4607
4599
  if (userPublicKey === void 0) { userPublicKey = undefined; }
@@ -4729,8 +4721,8 @@ var PerpetualsClient = (function () {
4729
4721
  instructions.push(addCompoundingLiquidity);
4730
4722
  return [3, 10];
4731
4723
  case 9:
4732
- err_18 = _f.sent();
4733
- console.log("perpClient addCompoundingLiquidity error:: ", err_18);
4724
+ err_16 = _f.sent();
4725
+ console.log("perpClient addCompoundingLiquidity error:: ", err_16);
4734
4726
  return [3, 10];
4735
4727
  case 10: return [2, {
4736
4728
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4746,7 +4738,7 @@ var PerpetualsClient = (function () {
4746
4738
  args_1[_i - 5] = arguments[_i];
4747
4739
  }
4748
4740
  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;
4741
+ 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
4742
  if (createUserATA === void 0) { createUserATA = true; }
4751
4743
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4752
4744
  if (userPublicKey === void 0) { userPublicKey = undefined; }
@@ -4858,8 +4850,8 @@ var PerpetualsClient = (function () {
4858
4850
  instructions.push(removeCompoundingLiquidity);
4859
4851
  return [3, 8];
4860
4852
  case 7:
4861
- err_19 = _f.sent();
4862
- console.log("perpClient removeCompoundingLiquidity error:: ", err_19);
4853
+ err_17 = _f.sent();
4854
+ console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
4863
4855
  return [3, 8];
4864
4856
  case 8: return [2, {
4865
4857
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4875,7 +4867,7 @@ var PerpetualsClient = (function () {
4875
4867
  args_1[_i - 3] = arguments[_i];
4876
4868
  }
4877
4869
  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;
4870
+ 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
4871
  if (createUserATA === void 0) { createUserATA = true; }
4880
4872
  return __generator(this, function (_g) {
4881
4873
  switch (_g.label) {
@@ -4973,8 +4965,8 @@ var PerpetualsClient = (function () {
4973
4965
  instructions.push(migrateStake);
4974
4966
  return [3, 8];
4975
4967
  case 7:
4976
- err_20 = _g.sent();
4977
- console.log("perpClient migrateStake error:: ", err_20);
4968
+ err_18 = _g.sent();
4969
+ console.log("perpClient migrateStake error:: ", err_18);
4978
4970
  return [3, 8];
4979
4971
  case 8: return [2, {
4980
4972
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4985,7 +4977,7 @@ var PerpetualsClient = (function () {
4985
4977
  });
4986
4978
  };
4987
4979
  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;
4980
+ 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
4981
  return __generator(this, function (_d) {
4990
4982
  switch (_d.label) {
4991
4983
  case 0:
@@ -5057,8 +5049,8 @@ var PerpetualsClient = (function () {
5057
5049
  instructions.push(migrateFlp);
5058
5050
  return [3, 4];
5059
5051
  case 3:
5060
- err_21 = _d.sent();
5061
- console.log("perpClient migrateFlp error:: ", err_21);
5052
+ err_19 = _d.sent();
5053
+ console.log("perpClient migrateFlp error:: ", err_19);
5062
5054
  return [3, 4];
5063
5055
  case 4: return [2, {
5064
5056
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -5073,7 +5065,7 @@ var PerpetualsClient = (function () {
5073
5065
  args_1[_i - 1] = arguments[_i];
5074
5066
  }
5075
5067
  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;
5068
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
5077
5069
  if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
5078
5070
  return __generator(this, function (_e) {
5079
5071
  switch (_e.label) {
@@ -5131,8 +5123,8 @@ var PerpetualsClient = (function () {
5131
5123
  instructions.push(compoundingFee);
5132
5124
  return [3, 4];
5133
5125
  case 3:
5134
- err_22 = _e.sent();
5135
- console.log("perpClient compoundingFee error:: ", err_22);
5126
+ err_20 = _e.sent();
5127
+ console.log("perpClient compoundingFee error:: ", err_20);
5136
5128
  return [3, 4];
5137
5129
  case 4: return [2, {
5138
5130
  instructions: __spreadArray([], instructions, true),
@@ -5142,146 +5134,8 @@ var PerpetualsClient = (function () {
5142
5134
  });
5143
5135
  });
5144
5136
  };
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
5137
  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;
5138
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_21;
5285
5139
  return __generator(this, function (_a) {
5286
5140
  switch (_a.label) {
5287
5141
  case 0:
@@ -5323,9 +5177,9 @@ var PerpetualsClient = (function () {
5323
5177
  instructions.push(depositTokenStakeInstruction);
5324
5178
  return [3, 5];
5325
5179
  case 4:
5326
- err_25 = _a.sent();
5327
- console.log("perpClient depositStakingInstruction error:: ", err_25);
5328
- throw err_25;
5180
+ err_21 = _a.sent();
5181
+ console.log("perpClient depositStakingInstruction error:: ", err_21);
5182
+ throw err_21;
5329
5183
  case 5: return [2, {
5330
5184
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5331
5185
  additionalSigners: additionalSigners
@@ -5334,7 +5188,7 @@ var PerpetualsClient = (function () {
5334
5188
  });
5335
5189
  }); };
5336
5190
  this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5337
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_26;
5191
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
5338
5192
  return __generator(this, function (_a) {
5339
5193
  switch (_a.label) {
5340
5194
  case 0:
@@ -5363,9 +5217,9 @@ var PerpetualsClient = (function () {
5363
5217
  instructions.push(unstakeTokenRequestInstruction);
5364
5218
  return [3, 4];
5365
5219
  case 3:
5366
- err_26 = _a.sent();
5367
- console.log("perpClient unstakeTokenRequestInstruction error:: ", err_26);
5368
- throw err_26;
5220
+ err_22 = _a.sent();
5221
+ console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
5222
+ throw err_22;
5369
5223
  case 4: return [2, {
5370
5224
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5371
5225
  additionalSigners: additionalSigners
@@ -5374,7 +5228,7 @@ var PerpetualsClient = (function () {
5374
5228
  });
5375
5229
  }); };
5376
5230
  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;
5231
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
5378
5232
  return __generator(this, function (_a) {
5379
5233
  switch (_a.label) {
5380
5234
  case 0:
@@ -5415,9 +5269,9 @@ var PerpetualsClient = (function () {
5415
5269
  instructions.push(unstakeTokenInstantInstruction);
5416
5270
  return [3, 5];
5417
5271
  case 4:
5418
- err_27 = _a.sent();
5419
- console.log("perpClient unstakeTokenInstantInstruction error:: ", err_27);
5420
- throw err_27;
5272
+ err_23 = _a.sent();
5273
+ console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
5274
+ throw err_23;
5421
5275
  case 5: return [2, {
5422
5276
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5423
5277
  additionalSigners: additionalSigners
@@ -5426,7 +5280,7 @@ var PerpetualsClient = (function () {
5426
5280
  });
5427
5281
  }); };
5428
5282
  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;
5283
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
5430
5284
  return __generator(this, function (_a) {
5431
5285
  switch (_a.label) {
5432
5286
  case 0:
@@ -5467,9 +5321,9 @@ var PerpetualsClient = (function () {
5467
5321
  instructions.push(withdrawTokenInstruction);
5468
5322
  return [3, 5];
5469
5323
  case 4:
5470
- err_28 = _a.sent();
5471
- console.log("perpClient withdrawTokenInstruction error:: ", err_28);
5472
- throw err_28;
5324
+ err_24 = _a.sent();
5325
+ console.log("perpClient withdrawTokenInstruction error:: ", err_24);
5326
+ throw err_24;
5473
5327
  case 5: return [2, {
5474
5328
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5475
5329
  additionalSigners: additionalSigners
@@ -5478,7 +5332,7 @@ var PerpetualsClient = (function () {
5478
5332
  });
5479
5333
  }); };
5480
5334
  this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5481
- var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_29;
5335
+ var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
5482
5336
  return __generator(this, function (_a) {
5483
5337
  switch (_a.label) {
5484
5338
  case 0:
@@ -5507,9 +5361,9 @@ var PerpetualsClient = (function () {
5507
5361
  instructions.push(cancelUnstakeRequestInstruction);
5508
5362
  return [3, 4];
5509
5363
  case 3:
5510
- err_29 = _a.sent();
5511
- console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_29);
5512
- throw err_29;
5364
+ err_25 = _a.sent();
5365
+ console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
5366
+ throw err_25;
5513
5367
  case 4: return [2, {
5514
5368
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5515
5369
  additionalSigners: additionalSigners
@@ -5523,7 +5377,7 @@ var PerpetualsClient = (function () {
5523
5377
  args_1[_i - 2] = arguments[_i];
5524
5378
  }
5525
5379
  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;
5380
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
5527
5381
  if (createUserATA === void 0) { createUserATA = true; }
5528
5382
  return __generator(this, function (_b) {
5529
5383
  switch (_b.label) {
@@ -5569,9 +5423,9 @@ var PerpetualsClient = (function () {
5569
5423
  instructions.push(collectTokenRewardInstruction);
5570
5424
  return [3, 6];
5571
5425
  case 5:
5572
- err_30 = _b.sent();
5573
- console.log("perpClient collectTokenRewardInstruction error:: ", err_30);
5574
- throw err_30;
5426
+ err_26 = _b.sent();
5427
+ console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
5428
+ throw err_26;
5575
5429
  case 6: return [2, {
5576
5430
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5577
5431
  additionalSigners: additionalSigners
@@ -5586,7 +5440,7 @@ var PerpetualsClient = (function () {
5586
5440
  args_1[_i - 3] = arguments[_i];
5587
5441
  }
5588
5442
  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;
5443
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
5590
5444
  if (createUserATA === void 0) { createUserATA = true; }
5591
5445
  return __generator(this, function (_b) {
5592
5446
  switch (_b.label) {
@@ -5633,9 +5487,9 @@ var PerpetualsClient = (function () {
5633
5487
  instructions.push(collectRevenueInstruction);
5634
5488
  return [3, 6];
5635
5489
  case 5:
5636
- err_31 = _b.sent();
5637
- console.log("perpClient collectRevenueInstruction error:: ", err_31);
5638
- throw err_31;
5490
+ err_27 = _b.sent();
5491
+ console.log("perpClient collectRevenueInstruction error:: ", err_27);
5492
+ throw err_27;
5639
5493
  case 6: return [2, {
5640
5494
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5641
5495
  additionalSigners: additionalSigners
@@ -5645,7 +5499,7 @@ var PerpetualsClient = (function () {
5645
5499
  });
5646
5500
  };
5647
5501
  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;
5502
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_28;
5649
5503
  return __generator(this, function (_a) {
5650
5504
  switch (_a.label) {
5651
5505
  case 0:
@@ -5682,9 +5536,9 @@ var PerpetualsClient = (function () {
5682
5536
  instructions.push(initRewardVault);
5683
5537
  return [3, 4];
5684
5538
  case 3:
5685
- err_32 = _a.sent();
5686
- console.log("perpClient InitRewardVault error:: ", err_32);
5687
- throw err_32;
5539
+ err_28 = _a.sent();
5540
+ console.log("perpClient InitRewardVault error:: ", err_28);
5541
+ throw err_28;
5688
5542
  case 4: return [2, {
5689
5543
  instructions: __spreadArray([], instructions, true),
5690
5544
  additionalSigners: additionalSigners
@@ -5693,7 +5547,7 @@ var PerpetualsClient = (function () {
5693
5547
  });
5694
5548
  }); };
5695
5549
  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;
5550
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_29;
5697
5551
  return __generator(this, function (_a) {
5698
5552
  switch (_a.label) {
5699
5553
  case 0:
@@ -5724,9 +5578,9 @@ var PerpetualsClient = (function () {
5724
5578
  instructions.push(distributeReward);
5725
5579
  return [3, 4];
5726
5580
  case 3:
5727
- err_33 = _a.sent();
5728
- console.log("perpClient distributeReward error:: ", err_33);
5729
- throw err_33;
5581
+ err_29 = _a.sent();
5582
+ console.log("perpClient distributeReward error:: ", err_29);
5583
+ throw err_29;
5730
5584
  case 4: return [2, {
5731
5585
  instructions: __spreadArray([], instructions, true),
5732
5586
  additionalSigners: additionalSigners
@@ -5740,7 +5594,7 @@ var PerpetualsClient = (function () {
5740
5594
  args_1[_i - 3] = arguments[_i];
5741
5595
  }
5742
5596
  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;
5597
+ var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_30;
5744
5598
  if (createUserATA === void 0) { createUserATA = true; }
5745
5599
  return __generator(this, function (_b) {
5746
5600
  switch (_b.label) {
@@ -5792,8 +5646,8 @@ var PerpetualsClient = (function () {
5792
5646
  instructions.push(collectNftReward);
5793
5647
  return [3, 6];
5794
5648
  case 5:
5795
- err_34 = _b.sent();
5796
- throw err_34;
5649
+ err_30 = _b.sent();
5650
+ throw err_30;
5797
5651
  case 6: return [2, {
5798
5652
  instructions: __spreadArray([], instructions, true),
5799
5653
  additionalSigners: additionalSigners
@@ -5808,7 +5662,7 @@ var PerpetualsClient = (function () {
5808
5662
  args_1[_i - 2] = arguments[_i];
5809
5663
  }
5810
5664
  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;
5665
+ var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_31;
5812
5666
  if (createUserATA === void 0) { createUserATA = true; }
5813
5667
  return __generator(this, function (_b) {
5814
5668
  switch (_b.label) {
@@ -5874,9 +5728,9 @@ var PerpetualsClient = (function () {
5874
5728
  instructions.push(withdrawStakeInstruction);
5875
5729
  return [3, 6];
5876
5730
  case 5:
5877
- err_35 = _b.sent();
5878
- console.log("perpClient withdrawStake error:: ", err_35);
5879
- throw err_35;
5731
+ err_31 = _b.sent();
5732
+ console.log("perpClient withdrawStake error:: ", err_31);
5733
+ throw err_31;
5880
5734
  case 6: return [2, {
5881
5735
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5882
5736
  additionalSigners: additionalSigners
@@ -5891,7 +5745,7 @@ var PerpetualsClient = (function () {
5891
5745
  args_1[_i - 11] = arguments[_i];
5892
5746
  }
5893
5747
  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;
5748
+ 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
5749
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5896
5750
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5897
5751
  return __generator(this, function (_c) {
@@ -5997,9 +5851,9 @@ var PerpetualsClient = (function () {
5997
5851
  instructions.push(placeLimitOrder);
5998
5852
  return [3, 10];
5999
5853
  case 9:
6000
- err_36 = _c.sent();
6001
- console.log("perpClient placeLimitOrder error:: ", err_36);
6002
- throw err_36;
5854
+ err_32 = _c.sent();
5855
+ console.log("perpClient placeLimitOrder error:: ", err_32);
5856
+ throw err_32;
6003
5857
  case 10: return [2, {
6004
5858
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6005
5859
  additionalSigners: additionalSigners
@@ -6014,7 +5868,7 @@ var PerpetualsClient = (function () {
6014
5868
  args_1[_i - 11] = arguments[_i];
6015
5869
  }
6016
5870
  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;
5871
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_33;
6018
5872
  if (createUserATA === void 0) { createUserATA = true; }
6019
5873
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6020
5874
  return __generator(this, function (_b) {
@@ -6105,9 +5959,9 @@ var PerpetualsClient = (function () {
6105
5959
  instructions.push(editLimitOrder);
6106
5960
  return [3, 8];
6107
5961
  case 7:
6108
- err_37 = _b.sent();
6109
- console.log("perpClient editLimitOrder error:: ", err_37);
6110
- throw err_37;
5962
+ err_33 = _b.sent();
5963
+ console.log("perpClient editLimitOrder error:: ", err_33);
5964
+ throw err_33;
6111
5965
  case 8: return [2, {
6112
5966
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6113
5967
  additionalSigners: additionalSigners
@@ -6122,7 +5976,7 @@ var PerpetualsClient = (function () {
6122
5976
  args_1[_i - 7] = arguments[_i];
6123
5977
  }
6124
5978
  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;
5979
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_34;
6126
5980
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6127
5981
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6128
5982
  if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
@@ -6175,9 +6029,9 @@ var PerpetualsClient = (function () {
6175
6029
  instructions.push(executeLimitOrder);
6176
6030
  return [3, 4];
6177
6031
  case 3:
6178
- err_38 = _a.sent();
6179
- console.log("perpClient executeLimitOrder error:: ", err_38);
6180
- throw err_38;
6032
+ err_34 = _a.sent();
6033
+ console.log("perpClient executeLimitOrder error:: ", err_34);
6034
+ throw err_34;
6181
6035
  case 4: return [2, {
6182
6036
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6183
6037
  additionalSigners: additionalSigners
@@ -6192,7 +6046,7 @@ var PerpetualsClient = (function () {
6192
6046
  args_1[_i - 8] = arguments[_i];
6193
6047
  }
6194
6048
  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;
6049
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_35;
6196
6050
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6197
6051
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6198
6052
  if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
@@ -6248,9 +6102,9 @@ var PerpetualsClient = (function () {
6248
6102
  instructions.push(executeLimitWithSwap);
6249
6103
  return [3, 4];
6250
6104
  case 3:
6251
- err_39 = _a.sent();
6252
- console.log("perpClient executeLimitWithSwap error:: ", err_39);
6253
- throw err_39;
6105
+ err_35 = _a.sent();
6106
+ console.log("perpClient executeLimitWithSwap error:: ", err_35);
6107
+ throw err_35;
6254
6108
  case 4: return [2, {
6255
6109
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6256
6110
  additionalSigners: additionalSigners
@@ -6260,7 +6114,7 @@ var PerpetualsClient = (function () {
6260
6114
  });
6261
6115
  };
6262
6116
  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;
6117
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_36;
6264
6118
  return __generator(this, function (_a) {
6265
6119
  switch (_a.label) {
6266
6120
  case 0:
@@ -6308,9 +6162,9 @@ var PerpetualsClient = (function () {
6308
6162
  instructions.push(placeTriggerOrder);
6309
6163
  return [3, 4];
6310
6164
  case 3:
6311
- err_40 = _a.sent();
6312
- console.log("perpClient placeTriggerOrder error:: ", err_40);
6313
- throw err_40;
6165
+ err_36 = _a.sent();
6166
+ console.log("perpClient placeTriggerOrder error:: ", err_36);
6167
+ throw err_36;
6314
6168
  case 4: return [2, {
6315
6169
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6316
6170
  additionalSigners: additionalSigners
@@ -6319,7 +6173,7 @@ var PerpetualsClient = (function () {
6319
6173
  });
6320
6174
  }); };
6321
6175
  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;
6176
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_37;
6323
6177
  return __generator(this, function (_a) {
6324
6178
  switch (_a.label) {
6325
6179
  case 0:
@@ -6366,9 +6220,9 @@ var PerpetualsClient = (function () {
6366
6220
  instructions.push(editTriggerOrder);
6367
6221
  return [3, 4];
6368
6222
  case 3:
6369
- err_41 = _a.sent();
6370
- console.log("perpClient editTriggerOrder error:: ", err_41);
6371
- throw err_41;
6223
+ err_37 = _a.sent();
6224
+ console.log("perpClient editTriggerOrder error:: ", err_37);
6225
+ throw err_37;
6372
6226
  case 4: return [2, {
6373
6227
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6374
6228
  additionalSigners: additionalSigners
@@ -6377,7 +6231,7 @@ var PerpetualsClient = (function () {
6377
6231
  });
6378
6232
  }); };
6379
6233
  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;
6234
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_38;
6381
6235
  return __generator(this, function (_a) {
6382
6236
  switch (_a.label) {
6383
6237
  case 0:
@@ -6410,9 +6264,9 @@ var PerpetualsClient = (function () {
6410
6264
  instructions.push(cancelTriggerOrder);
6411
6265
  return [3, 4];
6412
6266
  case 3:
6413
- err_42 = _a.sent();
6414
- console.log("perpClient cancelTriggerOrder error:: ", err_42);
6415
- throw err_42;
6267
+ err_38 = _a.sent();
6268
+ console.log("perpClient cancelTriggerOrder error:: ", err_38);
6269
+ throw err_38;
6416
6270
  case 4: return [2, {
6417
6271
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6418
6272
  additionalSigners: additionalSigners
@@ -6421,7 +6275,7 @@ var PerpetualsClient = (function () {
6421
6275
  });
6422
6276
  }); };
6423
6277
  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;
6278
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_39;
6425
6279
  return __generator(this, function (_a) {
6426
6280
  switch (_a.label) {
6427
6281
  case 0:
@@ -6452,9 +6306,9 @@ var PerpetualsClient = (function () {
6452
6306
  instructions.push(cancelAllTriggerOrders);
6453
6307
  return [3, 4];
6454
6308
  case 3:
6455
- err_43 = _a.sent();
6456
- console.log("perpClient cancelAllTriggerOrders error:: ", err_43);
6457
- throw err_43;
6309
+ err_39 = _a.sent();
6310
+ console.log("perpClient cancelAllTriggerOrders error:: ", err_39);
6311
+ throw err_39;
6458
6312
  case 4: return [2, {
6459
6313
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6460
6314
  additionalSigners: additionalSigners
@@ -6468,7 +6322,7 @@ var PerpetualsClient = (function () {
6468
6322
  args_1[_i - 9] = arguments[_i];
6469
6323
  }
6470
6324
  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;
6325
+ 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
6326
  if (createUserATA === void 0) { createUserATA = true; }
6473
6327
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6474
6328
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6575,9 +6429,9 @@ var PerpetualsClient = (function () {
6575
6429
  instructions.push(executeTriggerWithSwap);
6576
6430
  return [3, 10];
6577
6431
  case 9:
6578
- err_44 = _e.sent();
6579
- console.log("perpClient executeTriggerWithSwap error:: ", err_44);
6580
- throw err_44;
6432
+ err_40 = _e.sent();
6433
+ console.log("perpClient executeTriggerWithSwap error:: ", err_40);
6434
+ throw err_40;
6581
6435
  case 10: return [2, {
6582
6436
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6583
6437
  additionalSigners: additionalSigners
@@ -6592,7 +6446,7 @@ var PerpetualsClient = (function () {
6592
6446
  args_1[_i - 8] = arguments[_i];
6593
6447
  }
6594
6448
  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;
6449
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_41;
6596
6450
  if (createUserATA === void 0) { createUserATA = true; }
6597
6451
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6598
6452
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6664,9 +6518,9 @@ var PerpetualsClient = (function () {
6664
6518
  instructions.push(executeTriggerOrder);
6665
6519
  return [3, 8];
6666
6520
  case 7:
6667
- err_45 = _b.sent();
6668
- console.log("perpClient executeTriggerOrder error:: ", err_45);
6669
- throw err_45;
6521
+ err_41 = _b.sent();
6522
+ console.log("perpClient executeTriggerOrder error:: ", err_41);
6523
+ throw err_41;
6670
6524
  case 8: return [2, {
6671
6525
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6672
6526
  additionalSigners: additionalSigners
@@ -6681,7 +6535,7 @@ var PerpetualsClient = (function () {
6681
6535
  args_1[_i - 5] = arguments[_i];
6682
6536
  }
6683
6537
  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;
6538
+ 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
6539
  if (useFeesPool === void 0) { useFeesPool = false; }
6686
6540
  if (createUserATA === void 0) { createUserATA = true; }
6687
6541
  if (unWrapSol === void 0) { unWrapSol = false; }
@@ -6828,7 +6682,7 @@ var PerpetualsClient = (function () {
6828
6682
  _g.label = 16;
6829
6683
  case 16:
6830
6684
  if (_d) {
6831
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
6685
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
6832
6686
  }
6833
6687
  _g.label = 17;
6834
6688
  case 17:
@@ -6886,9 +6740,9 @@ var PerpetualsClient = (function () {
6886
6740
  }
6887
6741
  return [3, 20];
6888
6742
  case 19:
6889
- err_46 = _g.sent();
6890
- console.error("perpClient Swap error:: ", err_46);
6891
- throw err_46;
6743
+ err_42 = _g.sent();
6744
+ console.error("perpClient Swap error:: ", err_42);
6745
+ throw err_42;
6892
6746
  case 20: return [2, {
6893
6747
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6894
6748
  additionalSigners: additionalSigners
@@ -6898,7 +6752,7 @@ var PerpetualsClient = (function () {
6898
6752
  });
6899
6753
  };
6900
6754
  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;
6755
+ var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_43;
6902
6756
  return __generator(this, function (_b) {
6903
6757
  switch (_b.label) {
6904
6758
  case 0:
@@ -6958,9 +6812,9 @@ var PerpetualsClient = (function () {
6958
6812
  instructions.push(inx);
6959
6813
  return [3, 4];
6960
6814
  case 3:
6961
- err_47 = _b.sent();
6962
- console.error("perpClient Swap error:: ", err_47);
6963
- throw err_47;
6815
+ err_43 = _b.sent();
6816
+ console.error("perpClient Swap error:: ", err_43);
6817
+ throw err_43;
6964
6818
  case 4: return [2, {
6965
6819
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6966
6820
  additionalSigners: additionalSigners
@@ -6969,7 +6823,7 @@ var PerpetualsClient = (function () {
6969
6823
  });
6970
6824
  }); };
6971
6825
  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;
6826
+ var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_44;
6973
6827
  return __generator(this, function (_d) {
6974
6828
  switch (_d.label) {
6975
6829
  case 0:
@@ -7017,9 +6871,9 @@ var PerpetualsClient = (function () {
7017
6871
  instructions.push(setLpTokenPriceInstruction);
7018
6872
  return [3, 4];
7019
6873
  case 3:
7020
- err_48 = _d.sent();
7021
- console.log("perpClient setLpTokenPriceInstruction error:: ", err_48);
7022
- throw err_48;
6874
+ err_44 = _d.sent();
6875
+ console.log("perpClient setLpTokenPriceInstruction error:: ", err_44);
6876
+ throw err_44;
7023
6877
  case 4: return [2, {
7024
6878
  instructions: __spreadArray([], instructions, true),
7025
6879
  additionalSigners: additionalSigners
@@ -7067,7 +6921,7 @@ var PerpetualsClient = (function () {
7067
6921
  });
7068
6922
  }); };
7069
6923
  this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
7070
- var adminMetas, _i, admins_2, admin, err_49;
6924
+ var adminMetas, _i, admins_2, admin, err_45;
7071
6925
  return __generator(this, function (_a) {
7072
6926
  switch (_a.label) {
7073
6927
  case 0:
@@ -7097,11 +6951,11 @@ var PerpetualsClient = (function () {
7097
6951
  _a.sent();
7098
6952
  return [3, 4];
7099
6953
  case 3:
7100
- err_49 = _a.sent();
6954
+ err_45 = _a.sent();
7101
6955
  if (this.printErrors) {
7102
- console.error("setAdminSigners err:", err_49);
6956
+ console.error("setAdminSigners err:", err_45);
7103
6957
  }
7104
- throw err_49;
6958
+ throw err_45;
7105
6959
  case 4: return [2];
7106
6960
  }
7107
6961
  });
@@ -7290,7 +7144,7 @@ var PerpetualsClient = (function () {
7290
7144
  });
7291
7145
  }); };
7292
7146
  this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7293
- var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_50;
7147
+ var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_46;
7294
7148
  return __generator(this, function (_a) {
7295
7149
  switch (_a.label) {
7296
7150
  case 0:
@@ -7323,9 +7177,9 @@ var PerpetualsClient = (function () {
7323
7177
  instructions.push(withdrawFeesIx);
7324
7178
  return [3, 5];
7325
7179
  case 4:
7326
- err_50 = _a.sent();
7327
- console.log("perpClient setPool error:: ", err_50);
7328
- throw err_50;
7180
+ err_46 = _a.sent();
7181
+ console.log("perpClient setPool error:: ", err_46);
7182
+ throw err_46;
7329
7183
  case 5: return [2, {
7330
7184
  instructions: __spreadArray([], instructions, true),
7331
7185
  additionalSigners: additionalSigners
@@ -7334,7 +7188,7 @@ var PerpetualsClient = (function () {
7334
7188
  });
7335
7189
  }); };
7336
7190
  this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7337
- var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_51;
7191
+ var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_47;
7338
7192
  return __generator(this, function (_a) {
7339
7193
  switch (_a.label) {
7340
7194
  case 0:
@@ -7368,9 +7222,9 @@ var PerpetualsClient = (function () {
7368
7222
  instructions.push(moveProtocolFeesIx);
7369
7223
  return [3, 4];
7370
7224
  case 3:
7371
- err_51 = _a.sent();
7372
- console.log("perpClient setPool error:: ", err_51);
7373
- throw err_51;
7225
+ err_47 = _a.sent();
7226
+ console.log("perpClient setPool error:: ", err_47);
7227
+ throw err_47;
7374
7228
  case 4: return [2, {
7375
7229
  instructions: __spreadArray([], instructions, true),
7376
7230
  additionalSigners: additionalSigners
@@ -7379,7 +7233,7 @@ var PerpetualsClient = (function () {
7379
7233
  });
7380
7234
  }); };
7381
7235
  this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7382
- var publicKey, setProtocolFeeShareBpsIx, err_52;
7236
+ var publicKey, setProtocolFeeShareBpsIx, err_48;
7383
7237
  return __generator(this, function (_a) {
7384
7238
  switch (_a.label) {
7385
7239
  case 0:
@@ -7399,15 +7253,15 @@ var PerpetualsClient = (function () {
7399
7253
  setProtocolFeeShareBpsIx = _a.sent();
7400
7254
  return [2, setProtocolFeeShareBpsIx];
7401
7255
  case 2:
7402
- err_52 = _a.sent();
7403
- console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_52);
7404
- throw err_52;
7256
+ err_48 = _a.sent();
7257
+ console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_48);
7258
+ throw err_48;
7405
7259
  case 3: return [2];
7406
7260
  }
7407
7261
  });
7408
7262
  }); };
7409
7263
  this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
7410
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_53;
7264
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_49;
7411
7265
  return __generator(this, function (_a) {
7412
7266
  switch (_a.label) {
7413
7267
  case 0:
@@ -7434,9 +7288,9 @@ var PerpetualsClient = (function () {
7434
7288
  instructions.push(setPermissionsInstruction);
7435
7289
  return [3, 4];
7436
7290
  case 3:
7437
- err_53 = _a.sent();
7438
- console.log("perpClient setPool error:: ", err_53);
7439
- throw err_53;
7291
+ err_49 = _a.sent();
7292
+ console.log("perpClient setPool error:: ", err_49);
7293
+ throw err_49;
7440
7294
  case 4: return [2, {
7441
7295
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7442
7296
  additionalSigners: additionalSigners
@@ -7445,7 +7299,7 @@ var PerpetualsClient = (function () {
7445
7299
  });
7446
7300
  }); };
7447
7301
  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;
7302
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_50;
7449
7303
  var _f;
7450
7304
  return __generator(this, function (_g) {
7451
7305
  switch (_g.label) {
@@ -7506,9 +7360,9 @@ var PerpetualsClient = (function () {
7506
7360
  instructions.push(reimburse);
7507
7361
  return [3, 5];
7508
7362
  case 4:
7509
- err_54 = _g.sent();
7510
- console.log("perpClient setPool error:: ", err_54);
7511
- throw err_54;
7363
+ err_50 = _g.sent();
7364
+ console.log("perpClient setPool error:: ", err_50);
7365
+ throw err_50;
7512
7366
  case 5: return [2, {
7513
7367
  instructions: __spreadArray([], instructions, true),
7514
7368
  additionalSigners: additionalSigners
@@ -7516,8 +7370,8 @@ var PerpetualsClient = (function () {
7516
7370
  }
7517
7371
  });
7518
7372
  }); };
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;
7373
+ this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7374
+ var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_51;
7521
7375
  return __generator(this, function (_a) {
7522
7376
  switch (_a.label) {
7523
7377
  case 0:
@@ -7529,6 +7383,7 @@ var PerpetualsClient = (function () {
7529
7383
  _a.trys.push([1, 3, , 4]);
7530
7384
  return [4, this.program.methods
7531
7385
  .setInternalOraclePrice({
7386
+ useCurrentTime: useCurrentTime,
7532
7387
  price: price,
7533
7388
  expo: expo,
7534
7389
  conf: conf,
@@ -7550,9 +7405,9 @@ var PerpetualsClient = (function () {
7550
7405
  instructions.push(setInternalOraclePrice);
7551
7406
  return [3, 4];
7552
7407
  case 3:
7553
- err_55 = _a.sent();
7554
- console.log("perpClient setInternalOracleAccount error:: ", err_55);
7555
- throw err_55;
7408
+ err_51 = _a.sent();
7409
+ console.log("perpClient setInternalOracleAccount error:: ", err_51);
7410
+ throw err_51;
7556
7411
  case 4: return [2, {
7557
7412
  instructions: __spreadArray([], instructions, true),
7558
7413
  additionalSigners: additionalSigners
@@ -7560,8 +7415,8 @@ var PerpetualsClient = (function () {
7560
7415
  }
7561
7416
  });
7562
7417
  }); };
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;
7418
+ this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
7419
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_52;
7565
7420
  return __generator(this, function (_a) {
7566
7421
  switch (_a.label) {
7567
7422
  case 0:
@@ -7572,11 +7427,6 @@ var PerpetualsClient = (function () {
7572
7427
  accountMetas = [];
7573
7428
  _loop_1 = function (tokenMint) {
7574
7429
  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
7430
  accountMetas.push({
7581
7431
  pubkey: custody.intOracleAccount,
7582
7432
  isSigner: false,
@@ -7599,6 +7449,7 @@ var PerpetualsClient = (function () {
7599
7449
  _a.trys.push([1, 3, , 4]);
7600
7450
  return [4, this.program.methods
7601
7451
  .setInternalCurrentPrice({
7452
+ useCurrentTime: useCurrentTime,
7602
7453
  prices: tokenInternalPrices
7603
7454
  })
7604
7455
  .accounts({
@@ -7611,9 +7462,9 @@ var PerpetualsClient = (function () {
7611
7462
  instructions.push(setInternalOraclePrice);
7612
7463
  return [3, 4];
7613
7464
  case 3:
7614
- err_56 = _a.sent();
7615
- console.log("perpClient setInternalOracleAccount error:: ", err_56);
7616
- throw err_56;
7465
+ err_52 = _a.sent();
7466
+ console.log("perpClient setInternalOracleAccount error:: ", err_52);
7467
+ throw err_52;
7617
7468
  case 4: return [2, {
7618
7469
  instructions: __spreadArray([], instructions, true),
7619
7470
  additionalSigners: additionalSigners
@@ -7622,7 +7473,7 @@ var PerpetualsClient = (function () {
7622
7473
  });
7623
7474
  }); };
7624
7475
  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;
7476
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_53;
7626
7477
  return __generator(this, function (_a) {
7627
7478
  switch (_a.label) {
7628
7479
  case 0:
@@ -7633,21 +7484,11 @@ var PerpetualsClient = (function () {
7633
7484
  accountMetas = [];
7634
7485
  _loop_2 = function (tokenMint) {
7635
7486
  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
7487
  accountMetas.push({
7642
7488
  pubkey: custody.intOracleAccount,
7643
7489
  isSigner: false,
7644
7490
  isWritable: true,
7645
7491
  });
7646
- accountMetas.push({
7647
- pubkey: custody.extOracleAccount,
7648
- isSigner: false,
7649
- isWritable: false,
7650
- });
7651
7492
  };
7652
7493
  for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
7653
7494
  tokenMint = tokenMintList_2[_i];
@@ -7672,9 +7513,9 @@ var PerpetualsClient = (function () {
7672
7513
  instructions.push(setInternalOraclePrice);
7673
7514
  return [3, 4];
7674
7515
  case 3:
7675
- err_57 = _a.sent();
7676
- console.log("perpClient setInternalOracleAccount error:: ", err_57);
7677
- throw err_57;
7516
+ err_53 = _a.sent();
7517
+ console.log("perpClient setInternalOracleAccount error:: ", err_53);
7518
+ throw err_53;
7678
7519
  case 4: return [2, {
7679
7520
  instructions: __spreadArray([], instructions, true),
7680
7521
  additionalSigners: additionalSigners
@@ -7683,7 +7524,7 @@ var PerpetualsClient = (function () {
7683
7524
  });
7684
7525
  }); };
7685
7526
  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;
7527
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_54;
7687
7528
  return __generator(this, function (_a) {
7688
7529
  switch (_a.label) {
7689
7530
  case 0:
@@ -7721,8 +7562,8 @@ var PerpetualsClient = (function () {
7721
7562
  instructions.push(renameFlp);
7722
7563
  return [3, 4];
7723
7564
  case 3:
7724
- err_58 = _a.sent();
7725
- console.log("perpClient renameFlp error:: ", err_58);
7565
+ err_54 = _a.sent();
7566
+ console.log("perpClient renameFlp error:: ", err_54);
7726
7567
  return [3, 4];
7727
7568
  case 4: return [2, {
7728
7569
  instructions: __spreadArray([], instructions, true),
@@ -7732,7 +7573,7 @@ var PerpetualsClient = (function () {
7732
7573
  });
7733
7574
  }); };
7734
7575
  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;
7576
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_55;
7736
7577
  return __generator(this, function (_a) {
7737
7578
  switch (_a.label) {
7738
7579
  case 0:
@@ -7770,9 +7611,9 @@ var PerpetualsClient = (function () {
7770
7611
  instructions.push(initStakeInstruction);
7771
7612
  return [3, 4];
7772
7613
  case 3:
7773
- err_59 = _a.sent();
7774
- console.log("perpClient InitStaking error:: ", err_59);
7775
- throw err_59;
7614
+ err_55 = _a.sent();
7615
+ console.log("perpClient InitStaking error:: ", err_55);
7616
+ throw err_55;
7776
7617
  case 4: return [2, {
7777
7618
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7778
7619
  additionalSigners: additionalSigners
@@ -7781,7 +7622,7 @@ var PerpetualsClient = (function () {
7781
7622
  });
7782
7623
  }); };
7783
7624
  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;
7625
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_56;
7785
7626
  return __generator(this, function (_a) {
7786
7627
  switch (_a.label) {
7787
7628
  case 0:
@@ -7810,7 +7651,6 @@ var PerpetualsClient = (function () {
7810
7651
  transferAuthority: poolConfig.transferAuthority,
7811
7652
  perpetuals: this.perpetuals.publicKey,
7812
7653
  pool: poolConfig.poolAddress,
7813
- custody: rewardCustodyConfig.custodyAccount,
7814
7654
  lpTokenMint: poolConfig.stakedLpTokenMint,
7815
7655
  compoundingVault: compoundingVault,
7816
7656
  compoundingTokenMint: compoundingTokenMint,
@@ -7826,9 +7666,9 @@ var PerpetualsClient = (function () {
7826
7666
  instructions.push(initCompoundingInstruction);
7827
7667
  return [3, 4];
7828
7668
  case 3:
7829
- err_60 = _a.sent();
7830
- console.log("perpClient initCompounding error:: ", err_60);
7831
- throw err_60;
7669
+ err_56 = _a.sent();
7670
+ console.log("perpClient initCompounding error:: ", err_56);
7671
+ throw err_56;
7832
7672
  case 4: return [2, {
7833
7673
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7834
7674
  additionalSigners: additionalSigners
@@ -7837,7 +7677,7 @@ var PerpetualsClient = (function () {
7837
7677
  });
7838
7678
  }); };
7839
7679
  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;
7680
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_57;
7841
7681
  return __generator(this, function (_a) {
7842
7682
  switch (_a.label) {
7843
7683
  case 0:
@@ -7878,9 +7718,9 @@ var PerpetualsClient = (function () {
7878
7718
  instructions.push(initTokenVaultInstruction);
7879
7719
  return [3, 4];
7880
7720
  case 3:
7881
- err_61 = _a.sent();
7882
- console.log("perpClient InitTokenVaultInstruction error:: ", err_61);
7883
- throw err_61;
7721
+ err_57 = _a.sent();
7722
+ console.log("perpClient InitTokenVaultInstruction error:: ", err_57);
7723
+ throw err_57;
7884
7724
  case 4: return [2, {
7885
7725
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7886
7726
  additionalSigners: additionalSigners
@@ -7889,7 +7729,7 @@ var PerpetualsClient = (function () {
7889
7729
  });
7890
7730
  }); };
7891
7731
  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;
7732
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_58;
7893
7733
  return __generator(this, function (_a) {
7894
7734
  switch (_a.label) {
7895
7735
  case 0:
@@ -7920,9 +7760,9 @@ var PerpetualsClient = (function () {
7920
7760
  instructions.push(setTokenVaultConfigInstruction);
7921
7761
  return [3, 4];
7922
7762
  case 3:
7923
- err_62 = _a.sent();
7924
- console.log("perpClient setTokenVaultConfigInstruction error:: ", err_62);
7925
- throw err_62;
7763
+ err_58 = _a.sent();
7764
+ console.log("perpClient setTokenVaultConfigInstruction error:: ", err_58);
7765
+ throw err_58;
7926
7766
  case 4: return [2, {
7927
7767
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7928
7768
  additionalSigners: additionalSigners
@@ -7931,7 +7771,7 @@ var PerpetualsClient = (function () {
7931
7771
  });
7932
7772
  }); };
7933
7773
  this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7934
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_63;
7774
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_59;
7935
7775
  return __generator(this, function (_a) {
7936
7776
  switch (_a.label) {
7937
7777
  case 0:
@@ -7970,9 +7810,59 @@ var PerpetualsClient = (function () {
7970
7810
  instructions.push(withdrawInstantFeeInstruction);
7971
7811
  return [3, 6];
7972
7812
  case 5:
7973
- err_63 = _a.sent();
7974
- console.log("perpClient withdrawInstantFeeInstruction error:: ", err_63);
7975
- throw err_63;
7813
+ err_59 = _a.sent();
7814
+ console.log("perpClient withdrawInstantFeeInstruction error:: ", err_59);
7815
+ throw err_59;
7816
+ case 6: return [2, {
7817
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7818
+ additionalSigners: additionalSigners
7819
+ }];
7820
+ }
7821
+ });
7822
+ }); };
7823
+ this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7824
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_60;
7825
+ return __generator(this, function (_a) {
7826
+ switch (_a.label) {
7827
+ case 0:
7828
+ publicKey = this.provider.wallet.publicKey;
7829
+ preInstructions = [];
7830
+ instructions = [];
7831
+ postInstructions = [];
7832
+ additionalSigners = [];
7833
+ _a.label = 1;
7834
+ case 1:
7835
+ _a.trys.push([1, 5, , 6]);
7836
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
7837
+ case 2:
7838
+ receivingTokenAccount = _a.sent();
7839
+ return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
7840
+ case 3:
7841
+ if (!(_a.sent())) {
7842
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
7843
+ }
7844
+ return [4, this.program.methods
7845
+ .withdrawUnclaimedTokens({})
7846
+ .accounts({
7847
+ admin: publicKey,
7848
+ multisig: this.multisig.publicKey,
7849
+ perpetuals: this.perpetuals.publicKey,
7850
+ transferAuthority: poolConfig.transferAuthority,
7851
+ tokenVault: poolConfig.tokenVault,
7852
+ tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
7853
+ receivingTokenAccount: receivingTokenAccount,
7854
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
7855
+ receivingTokenMint: poolConfig.tokenMint,
7856
+ })
7857
+ .instruction()];
7858
+ case 4:
7859
+ withdrawUnclaimedTokensInstruction = _a.sent();
7860
+ instructions.push(withdrawUnclaimedTokensInstruction);
7861
+ return [3, 6];
7862
+ case 5:
7863
+ err_60 = _a.sent();
7864
+ console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_60);
7865
+ throw err_60;
7976
7866
  case 6: return [2, {
7977
7867
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7978
7868
  additionalSigners: additionalSigners
@@ -7981,7 +7871,7 @@ var PerpetualsClient = (function () {
7981
7871
  });
7982
7872
  }); };
7983
7873
  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;
7874
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_61;
7985
7875
  return __generator(this, function (_a) {
7986
7876
  switch (_a.label) {
7987
7877
  case 0:
@@ -8018,9 +7908,9 @@ var PerpetualsClient = (function () {
8018
7908
  instructions.push(initRevenueTokenAccountInstruction);
8019
7909
  return [3, 4];
8020
7910
  case 3:
8021
- err_64 = _a.sent();
8022
- console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_64);
8023
- throw err_64;
7911
+ err_61 = _a.sent();
7912
+ console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_61);
7913
+ throw err_61;
8024
7914
  case 4: return [2, {
8025
7915
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8026
7916
  additionalSigners: additionalSigners
@@ -8029,7 +7919,7 @@ var PerpetualsClient = (function () {
8029
7919
  });
8030
7920
  }); };
8031
7921
  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;
7922
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_62;
8033
7923
  return __generator(this, function (_a) {
8034
7924
  switch (_a.label) {
8035
7925
  case 0:
@@ -8068,9 +7958,9 @@ var PerpetualsClient = (function () {
8068
7958
  instructions.push(distributeTokenRewardInstruction);
8069
7959
  return [3, 4];
8070
7960
  case 3:
8071
- err_65 = _a.sent();
8072
- console.log("perpClient distributeTokenRewardInstruction error:: ", err_65);
8073
- throw err_65;
7961
+ err_62 = _a.sent();
7962
+ console.log("perpClient distributeTokenRewardInstruction error:: ", err_62);
7963
+ throw err_62;
8074
7964
  case 4: return [2, {
8075
7965
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8076
7966
  additionalSigners: additionalSigners
@@ -8079,7 +7969,7 @@ var PerpetualsClient = (function () {
8079
7969
  });
8080
7970
  }); };
8081
7971
  this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
8082
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_66;
7972
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_63;
8083
7973
  return __generator(this, function (_a) {
8084
7974
  switch (_a.label) {
8085
7975
  case 0:
@@ -8107,9 +7997,9 @@ var PerpetualsClient = (function () {
8107
7997
  instructions.push(setTokenStakeLevelInstruction);
8108
7998
  return [3, 4];
8109
7999
  case 3:
8110
- err_66 = _a.sent();
8111
- console.log("perpClient setTokenStakeLevelInstruction error:: ", err_66);
8112
- throw err_66;
8000
+ err_63 = _a.sent();
8001
+ console.log("perpClient setTokenStakeLevelInstruction error:: ", err_63);
8002
+ throw err_63;
8113
8003
  case 4: return [2, {
8114
8004
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8115
8005
  additionalSigners: additionalSigners
@@ -8118,7 +8008,7 @@ var PerpetualsClient = (function () {
8118
8008
  });
8119
8009
  }); };
8120
8010
  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;
8011
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_64;
8122
8012
  return __generator(this, function (_a) {
8123
8013
  switch (_a.label) {
8124
8014
  case 0:
@@ -8150,9 +8040,49 @@ var PerpetualsClient = (function () {
8150
8040
  instructions.push(setTokenRewardInstruction);
8151
8041
  return [3, 4];
8152
8042
  case 3:
8153
- err_67 = _a.sent();
8154
- console.log("perpClient setTokenRewardInstruction error:: ", err_67);
8155
- throw err_67;
8043
+ err_64 = _a.sent();
8044
+ console.log("perpClient setTokenRewardInstruction error:: ", err_64);
8045
+ throw err_64;
8046
+ case 4: return [2, {
8047
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8048
+ additionalSigners: additionalSigners
8049
+ }];
8050
+ }
8051
+ });
8052
+ }); };
8053
+ this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
8054
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_65;
8055
+ return __generator(this, function (_a) {
8056
+ switch (_a.label) {
8057
+ case 0:
8058
+ publicKey = this.provider.wallet.publicKey;
8059
+ preInstructions = [];
8060
+ instructions = [];
8061
+ postInstructions = [];
8062
+ additionalSigners = [];
8063
+ _a.label = 1;
8064
+ case 1:
8065
+ _a.trys.push([1, 3, , 4]);
8066
+ return [4, this.program.methods
8067
+ .resizeInternalOracle({
8068
+ extOracle: extOracle
8069
+ })
8070
+ .accounts({
8071
+ admin: publicKey,
8072
+ multisig: this.multisig.publicKey,
8073
+ custodyTokenMint: tokenMint,
8074
+ intOracleAccount: intOracleAccount,
8075
+ systemProgram: web3_js_1.SystemProgram.programId,
8076
+ })
8077
+ .instruction()];
8078
+ case 2:
8079
+ resizeInternalOracleInstruction = _a.sent();
8080
+ instructions.push(resizeInternalOracleInstruction);
8081
+ return [3, 4];
8082
+ case 3:
8083
+ err_65 = _a.sent();
8084
+ console.log("perpClient resizeInternalOracleInstruction error:: ", err_65);
8085
+ throw err_65;
8156
8086
  case 4: return [2, {
8157
8087
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8158
8088
  additionalSigners: additionalSigners
@@ -8230,13 +8160,13 @@ var PerpetualsClient = (function () {
8230
8160
  PerpetualsClient.prototype.getPriceAfterSlippage = function (isEntry, slippageBps, targetPrice, side) {
8231
8161
  if (isEntry) {
8232
8162
  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);
8163
+ var spread_i = (0, utils_1.checkedDecimalCeilMul)(currentPrice, targetPrice.exponent, slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), targetPrice.exponent);
8234
8164
  if ((0, types_1.isVariant)(side, 'long')) {
8235
- return { price: currentPrice.add(slippage), exponent: targetPrice.exponent.toNumber() };
8165
+ return { price: currentPrice.add(spread_i), exponent: targetPrice.exponent.toNumber() };
8236
8166
  }
8237
8167
  else {
8238
- if (slippage.lt(currentPrice)) {
8239
- return { price: currentPrice.sub(slippage), exponent: targetPrice.exponent.toNumber() };
8168
+ if (spread_i.lt(currentPrice)) {
8169
+ return { price: currentPrice.sub(spread_i), exponent: targetPrice.exponent.toNumber() };
8240
8170
  }
8241
8171
  else {
8242
8172
  return { price: constants_1.BN_ZERO, exponent: targetPrice.exponent.toNumber() };
@@ -8246,10 +8176,10 @@ var PerpetualsClient = (function () {
8246
8176
  }
8247
8177
  else {
8248
8178
  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);
8179
+ var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, targetPrice.exponent, slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), targetPrice.exponent);
8250
8180
  if ((0, types_1.isVariant)(side, 'long')) {
8251
- if (slippage.lt(current_price)) {
8252
- return { price: current_price.sub(slippage), exponent: targetPrice.exponent.toNumber() };
8181
+ if (spread_i.lt(current_price)) {
8182
+ return { price: current_price.sub(spread_i), exponent: targetPrice.exponent.toNumber() };
8253
8183
  }
8254
8184
  else {
8255
8185
  return { price: constants_1.BN_ZERO, exponent: targetPrice.exponent.toNumber() };
@@ -8257,7 +8187,7 @@ var PerpetualsClient = (function () {
8257
8187
  ;
8258
8188
  }
8259
8189
  else {
8260
- return { price: current_price.add(slippage), exponent: targetPrice.exponent.toNumber() };
8190
+ return { price: current_price.add(spread_i), exponent: targetPrice.exponent.toNumber() };
8261
8191
  }
8262
8192
  }
8263
8193
  };