flash-sdk 9.0.0-alpha.0 → 9.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PerpetualsClient.d.ts +67 -73
- package/dist/PerpetualsClient.js +503 -1062
- package/dist/PoolConfig.d.ts +2 -0
- package/dist/PoolConfig.json +244 -10
- package/dist/idl/perpetuals.d.ts +131 -609
- package/dist/idl/perpetuals.js +128 -606
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/testSize.d.ts +0 -0
- package/dist/testSize.js +0 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/utils/getReferralAccounts.d.ts +1 -1
- package/dist/utils/getReferralAccounts.js +3 -8
- package/package.json +1 -1
- package/dist/TradingAccount.d.ts +0 -23
- package/dist/TradingAccount.js +0 -17
package/dist/PerpetualsClient.js
CHANGED
@@ -638,24 +638,41 @@ var PerpetualsClient = (function () {
|
|
638
638
|
var averageEntryPrice = totalValue.div(totalSize);
|
639
639
|
return averageEntryPrice;
|
640
640
|
};
|
641
|
-
this.
|
642
|
-
var
|
643
|
-
var
|
644
|
-
|
645
|
-
|
641
|
+
this.getLeverageContractHelper = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig) {
|
642
|
+
var pnl = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
643
|
+
var exitFee = _this.getExitFeeSync(positionAccount, targetCustodyAccount, collateralCustodyAccount, collateralPrice, collateralEmaPrice);
|
644
|
+
var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
645
|
+
var unsettledFeesUsd = exitFee.exitFeeUsd.add(lockFeeUsd);
|
646
|
+
var lossUsd = pnl.lossUsd.add(unsettledFeesUsd);
|
647
|
+
var currentMarginUsd = constants_1.BN_ZERO;
|
648
|
+
if (isInitial) {
|
649
|
+
currentMarginUsd = positionAccount.collateralUsd.sub(lossUsd);
|
650
|
+
}
|
651
|
+
else {
|
652
|
+
currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
|
653
|
+
}
|
654
|
+
if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
|
655
|
+
return positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
|
646
656
|
}
|
647
657
|
else {
|
648
658
|
return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
|
649
659
|
}
|
650
660
|
};
|
651
|
-
this.
|
661
|
+
this.getLeverageSync = function (positionAccount, finalCollateralUsd, finalSizeUsd, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig) {
|
662
|
+
positionAccount = positionAccount.clone();
|
663
|
+
positionAccount.sizeUsd = finalSizeUsd;
|
664
|
+
positionAccount.sizeAmount = targetPrice.getTokenAmount(finalSizeUsd, targetCustodyAccount.decimals);
|
665
|
+
positionAccount.collateralUsd = finalCollateralUsd;
|
666
|
+
return _this.getLeverageContractHelper(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig);
|
667
|
+
};
|
668
|
+
this.getLeverageAtAmountEntryWithSwapSync = function (positionAccount, inputDeltaAmount, sizeDeltaAmount, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig, pnlUsd) {
|
652
669
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
653
670
|
if (!inputDeltaAmount.isZero()) {
|
654
671
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
655
672
|
finalCollateralAmount = inputDeltaAmount;
|
656
673
|
}
|
657
674
|
else {
|
658
|
-
var swapAmountOut = _this.getSwapAmountAndFeesSync(inputDeltaAmount, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
675
|
+
var swapAmountOut = _this.getSwapAmountAndFeesSync(inputDeltaAmount, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountOut;
|
659
676
|
finalCollateralAmount = swapAmountOut;
|
660
677
|
}
|
661
678
|
}
|
@@ -681,9 +698,8 @@ var PerpetualsClient = (function () {
|
|
681
698
|
entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
|
682
699
|
}
|
683
700
|
var collateralMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
684
|
-
var
|
685
|
-
var
|
686
|
-
var currentCollateralUsdIncludingPnl = currentCollateralUsd.add(pnlUsd).sub(openFeeUsd);
|
701
|
+
var finalCollateralUsd = collateralMinOraclePrice.getAssetAmountUsd(finalCollateralAmount, collateralTokenCustodyAccount.decimals);
|
702
|
+
var currentCollateralUsdIncludingPnl = finalCollateralUsd.add(pnlUsd).sub(openFeeUsd);
|
687
703
|
var sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
688
704
|
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
689
705
|
if (currentCollateralUsdIncludingPnl.gt(constants_1.BN_ZERO)) {
|
@@ -693,68 +709,6 @@ var PerpetualsClient = (function () {
|
|
693
709
|
return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
|
694
710
|
}
|
695
711
|
};
|
696
|
-
this.getEntryPriceAndFeeSync = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps) {
|
697
|
-
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
698
|
-
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
699
|
-
throw new Error("Delta Amounts cannot be negative.");
|
700
|
-
}
|
701
|
-
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
702
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
703
|
-
if (positionAccount === null) {
|
704
|
-
var data = __assign({}, types_1.DEFAULT_POSITION);
|
705
|
-
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
706
|
-
var sizeUsd_1 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
707
|
-
positionAccount.sizeUsd = sizeUsd_1;
|
708
|
-
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
709
|
-
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
710
|
-
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
711
|
-
}
|
712
|
-
else {
|
713
|
-
positionAccount = positionAccount.clone();
|
714
|
-
var positionEntryPrice = OraclePrice_1.OraclePrice.from({
|
715
|
-
price: positionAccount.entryPrice.price,
|
716
|
-
exponent: new anchor_1.BN(positionAccount.entryPrice.exponent),
|
717
|
-
confidence: constants_1.BN_ZERO,
|
718
|
-
timestamp: constants_1.BN_ZERO
|
719
|
-
});
|
720
|
-
entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
|
721
|
-
var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
722
|
-
positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
|
723
|
-
}
|
724
|
-
positionAccount.collateralAmount = positionAccount.collateralAmount.add(collateralDeltaAmount);
|
725
|
-
positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
726
|
-
var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
727
|
-
var liquidationPrice = _this.getLiquidationPriceSync(positionAccount.collateralAmount, positionAccount.sizeAmount, entryOraclePrice, lockFeeUsd, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, positionAccount);
|
728
|
-
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
729
|
-
var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
730
|
-
var feeUsd = constants_1.BN_ZERO;
|
731
|
-
var feeAmount = constants_1.BN_ZERO;
|
732
|
-
var feeUsdAfterDiscount = constants_1.BN_ZERO;
|
733
|
-
var feeAmountAfterDiscount = constants_1.BN_ZERO;
|
734
|
-
if (positionAccount !== null && sizeDeltaAmount.isZero()) {
|
735
|
-
}
|
736
|
-
else {
|
737
|
-
feeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.openPosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
738
|
-
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
|
739
|
-
if (discountBps.gt(constants_1.BN_ZERO)) {
|
740
|
-
feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
741
|
-
feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
|
742
|
-
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
|
743
|
-
}
|
744
|
-
else {
|
745
|
-
feeUsdAfterDiscount = feeUsd;
|
746
|
-
feeAmountAfterDiscount = feeAmount;
|
747
|
-
}
|
748
|
-
}
|
749
|
-
return {
|
750
|
-
entryOraclePrice: entryOraclePrice,
|
751
|
-
feeUsd: feeUsd,
|
752
|
-
feeAmount: feeAmount,
|
753
|
-
feeUsdAfterDiscount: feeUsdAfterDiscount,
|
754
|
-
feeAmountAfterDiscount: feeAmountAfterDiscount,
|
755
|
-
liquidationPrice: liquidationPrice
|
756
|
-
};
|
757
|
-
};
|
758
712
|
this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
|
759
713
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
760
714
|
if (enableLogs === void 0) { enableLogs = false; }
|
@@ -766,8 +720,8 @@ var PerpetualsClient = (function () {
|
|
766
720
|
if (positionAccount === null) {
|
767
721
|
var data = __assign({}, types_1.DEFAULT_POSITION);
|
768
722
|
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
769
|
-
var
|
770
|
-
positionAccount.sizeUsd =
|
723
|
+
var sizeUsd_1 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
724
|
+
positionAccount.sizeUsd = sizeUsd_1;
|
771
725
|
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
772
726
|
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
773
727
|
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
@@ -784,12 +738,13 @@ var PerpetualsClient = (function () {
|
|
784
738
|
var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
785
739
|
positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
|
786
740
|
}
|
787
|
-
|
741
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
742
|
+
var collateralDeltaUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
743
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
788
744
|
positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
789
|
-
var
|
790
|
-
var liquidationPrice = _this.
|
745
|
+
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
746
|
+
var liquidationPrice = _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
791
747
|
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
792
|
-
var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
793
748
|
var feeUsd = constants_1.BN_ZERO;
|
794
749
|
var feeAmount = constants_1.BN_ZERO;
|
795
750
|
var feeUsdAfterDiscount = constants_1.BN_ZERO;
|
@@ -798,11 +753,11 @@ var PerpetualsClient = (function () {
|
|
798
753
|
}
|
799
754
|
else {
|
800
755
|
feeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.openPosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
801
|
-
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(
|
756
|
+
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralMinMaxPrice.min.price);
|
802
757
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
803
758
|
feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
804
759
|
feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
|
805
|
-
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(
|
760
|
+
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralMinMaxPrice.min.price);
|
806
761
|
}
|
807
762
|
else {
|
808
763
|
feeUsdAfterDiscount = feeUsd;
|
@@ -861,25 +816,26 @@ var PerpetualsClient = (function () {
|
|
861
816
|
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
862
817
|
throw new Error("Delta Amounts cannot be negative ");
|
863
818
|
}
|
864
|
-
resultingPositionAccount.collateralAmount = resultingPositionAccount.collateralAmount.sub(collateralDeltaAmount);
|
865
|
-
resultingPositionAccount.sizeAmount = resultingPositionAccount.sizeAmount.sub(sizeDeltaAmount);
|
866
819
|
if (resultingPositionAccount.collateralAmount.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
|
867
820
|
throw new Error("cannot remove/close more than collateral/Size");
|
868
821
|
}
|
869
822
|
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
870
823
|
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
871
|
-
var
|
824
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
825
|
+
var collateralDeltaUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
826
|
+
resultingPositionAccount.collateralUsd = resultingPositionAccount.collateralUsd.sub(collateralDeltaUsd);
|
827
|
+
resultingPositionAccount.sizeAmount = resultingPositionAccount.sizeAmount.sub(sizeDeltaAmount);
|
872
828
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(resultingPositionAccount, collateralCustodyAccount, currentTimestamp);
|
873
|
-
var lockAndUnsettledFee =
|
829
|
+
var lockAndUnsettledFee = collateralMinMaxPrice.min.getTokenAmount(lockAndUnsettledFeeUsd, collateralCustodyAccount.decimals);
|
874
830
|
var sizeAmountUsd = exitOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
875
831
|
var exitFeeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
876
|
-
var exitFeeAmount =
|
832
|
+
var exitFeeAmount = collateralMinMaxPrice.max.getTokenAmount(exitFeeUsd, collateralCustodyAccount.decimals);
|
877
833
|
var exitFeeUsdAfterDiscount = constants_1.BN_ZERO;
|
878
834
|
var exitFeeAmountAfterDiscount = constants_1.BN_ZERO;
|
879
835
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
880
836
|
exitFeeUsdAfterDiscount = exitFeeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
881
837
|
exitFeeUsdAfterDiscount = exitFeeUsd.sub(exitFeeUsdAfterDiscount);
|
882
|
-
exitFeeAmountAfterDiscount =
|
838
|
+
exitFeeAmountAfterDiscount = collateralMinMaxPrice.max.getTokenAmount(exitFeeUsdAfterDiscount, collateralCustodyAccount.decimals);
|
883
839
|
}
|
884
840
|
else {
|
885
841
|
exitFeeUsdAfterDiscount = exitFeeUsd;
|
@@ -889,7 +845,7 @@ var PerpetualsClient = (function () {
|
|
889
845
|
price: positionAccount.entryPrice.price, exponent: new anchor_1.BN(positionAccount.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO
|
890
846
|
});
|
891
847
|
resultingPositionAccount.sizeUsd = positionEntryOraclePrice.getAssetAmountUsd(resultingPositionAccount.sizeAmount, targetCustodyAccount.decimals);
|
892
|
-
var liquidationPrice = _this.
|
848
|
+
var liquidationPrice = _this.getLiquidationPriceContractHelper(positionEntryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
893
849
|
return {
|
894
850
|
exitOraclePrice: exitOraclePrice,
|
895
851
|
borrowFeeUsd: lockAndUnsettledFeeUsd,
|
@@ -902,9 +858,7 @@ var PerpetualsClient = (function () {
|
|
902
858
|
};
|
903
859
|
};
|
904
860
|
this.getTradeSpread = function (targetCustodyAccount, sizeUsd) {
|
905
|
-
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero()
|
906
|
-
||
|
907
|
-
sizeUsd.isZero()) {
|
861
|
+
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero() || sizeUsd.isZero()) {
|
908
862
|
return constants_1.BN_ZERO;
|
909
863
|
}
|
910
864
|
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)))))
|
@@ -923,21 +877,11 @@ var PerpetualsClient = (function () {
|
|
923
877
|
var exitOraclePrice = OraclePrice_1.OraclePrice.from({ price: exitPriceBN, exponent: maxPrice.exponent, confidence: maxPrice.confidence, timestamp: maxPrice.timestamp });
|
924
878
|
return exitOraclePrice;
|
925
879
|
};
|
926
|
-
this.getExitOraclePriceWithoutSpreadSync = function (side, targetPrice, targetEmaPrice, targetCustodyAccount) {
|
927
|
-
var _a = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount), minPrice = _a.min, maxPrice = _a.max;
|
928
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
929
|
-
return minPrice;
|
930
|
-
}
|
931
|
-
else {
|
932
|
-
return maxPrice;
|
933
|
-
}
|
934
|
-
};
|
935
880
|
this.getSizeAmountFromLeverageAndCollateral = function (collateralAmtWithFee, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
|
936
881
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
937
882
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
938
883
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
939
|
-
var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals))
|
940
|
-
.multipliedBy(collateralTokenMinPriceUi);
|
884
|
+
var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals)).multipliedBy(collateralTokenMinPriceUi);
|
941
885
|
var openPosFeeRateUi = new bignumber_js_1.default(targetCustodyAccount.fees.openPosition.toString()).dividedBy(Math.pow(10, constants_1.RATE_DECIMALS));
|
942
886
|
if (!discountBps.isZero()) {
|
943
887
|
var discountBpsUi = new bignumber_js_1.default(discountBps.toString()).dividedBy(Math.pow(10, constants_1.BPS_DECIMALS));
|
@@ -945,20 +889,20 @@ var PerpetualsClient = (function () {
|
|
945
889
|
}
|
946
890
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
947
891
|
.dividedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage)));
|
948
|
-
var
|
949
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
892
|
+
var sizeUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toString(), constants_1.USD_DECIMALS);
|
893
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
950
894
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
951
895
|
var sizeAmountUi = sizeUsdUi.dividedBy(entryPriceUsdUi);
|
952
896
|
return (0, utils_1.uiDecimalsToNative)(sizeAmountUi.toFixed(marketToken.decimals, bignumber_js_1.default.ROUND_DOWN), marketToken.decimals);
|
953
897
|
};
|
954
|
-
this.getSizeAmountWithSwapSync = function (amountIn, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax,
|
898
|
+
this.getSizeAmountWithSwapSync = function (amountIn, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig, discountBps) {
|
955
899
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
956
900
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
957
901
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
958
902
|
finalCollateralAmount = amountIn;
|
959
903
|
}
|
960
904
|
else {
|
961
|
-
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
905
|
+
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountOut;
|
962
906
|
finalCollateralAmount = swapAmountOut;
|
963
907
|
}
|
964
908
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
@@ -972,8 +916,8 @@ var PerpetualsClient = (function () {
|
|
972
916
|
}
|
973
917
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
974
918
|
.dividedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage)));
|
975
|
-
var
|
976
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount,
|
919
|
+
var sizeUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toFixed(constants_1.USD_DECIMALS), constants_1.USD_DECIMALS);
|
920
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
|
977
921
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
978
922
|
var sizeAmountUi = sizeUsdUi.dividedBy(entryPriceUsdUi);
|
979
923
|
return (0, utils_1.uiDecimalsToNative)(sizeAmountUi.toFixed(targetTokenCustodyAccount.decimals, bignumber_js_1.default.ROUND_DOWN), targetTokenCustodyAccount.decimals);
|
@@ -996,7 +940,7 @@ var PerpetualsClient = (function () {
|
|
996
940
|
var collateralAmtWithFeeUi = collateralWithFeeUsdUi.dividedBy(collateralTokenMinPriceUi);
|
997
941
|
return (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralToken.decimals, bignumber_js_1.default.ROUND_DOWN), collateralToken.decimals);
|
998
942
|
};
|
999
|
-
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax,
|
943
|
+
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig) {
|
1000
944
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
1001
945
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
1002
946
|
var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
@@ -1013,7 +957,7 @@ var PerpetualsClient = (function () {
|
|
1013
957
|
collateralInInputToken = collateralAmountWithFee;
|
1014
958
|
}
|
1015
959
|
else {
|
1016
|
-
collateralInInputToken = _this.getSwapAmountAndFeesSync(constants_1.BN_ZERO, collateralAmountWithFee, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
960
|
+
collateralInInputToken = _this.getSwapAmountAndFeesSync(constants_1.BN_ZERO, collateralAmountWithFee, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountIn;
|
1017
961
|
}
|
1018
962
|
return collateralInInputToken;
|
1019
963
|
};
|
@@ -1039,10 +983,10 @@ var PerpetualsClient = (function () {
|
|
1039
983
|
var decimalPower = new anchor_1.BN(Math.pow(10, targetCustodyAccount.decimals));
|
1040
984
|
var closeRatio = (positionDelta.sizeAmount.mul(decimalPower)).div(positionAccount.sizeAmount);
|
1041
985
|
positionDelta.sizeUsd = (positionAccount.sizeUsd.mul(closeRatio)).div(decimalPower);
|
1042
|
-
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
1043
986
|
positionDelta.lockedAmount = (positionAccount.lockedAmount.mul(closeRatio)).div(decimalPower);
|
1044
987
|
positionDelta.lockedUsd = (positionAccount.lockedUsd.mul(closeRatio)).div(decimalPower);
|
1045
|
-
positionDelta.
|
988
|
+
positionDelta.collateralUsd = (positionAccount.collateralUsd.mul(closeRatio)).div(decimalPower);
|
989
|
+
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
1046
990
|
positionDelta.degenSizeUsd = positionAccount.degenSizeUsd.mul(closeRatio).div(decimalPower);
|
1047
991
|
var newPnl = _this.getPnlSync(positionDelta, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1048
992
|
var exitFeeUsd = positionDelta.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
@@ -1052,29 +996,29 @@ var PerpetualsClient = (function () {
|
|
1052
996
|
}
|
1053
997
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionDelta, collateralCustodyAccount, currentTimestamp);
|
1054
998
|
var totalFeesUsd = (exitFeeUsd.add(lockAndUnsettledFeeUsd));
|
1055
|
-
var currentCollateralUsd =
|
999
|
+
var currentCollateralUsd = positionDelta.collateralUsd;
|
1056
1000
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
1057
|
-
var assetsUsd = newPnl.profitUsd.add(currentCollateralUsd);
|
1058
|
-
var closeAmount, feesAmount;
|
1001
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
|
1059
1002
|
if (debugLogs) {
|
1060
1003
|
console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
|
1061
1004
|
}
|
1005
|
+
var closeAmountUsd, feesAmountUsd;
|
1062
1006
|
if (assetsUsd.gte(liabilityUsd)) {
|
1063
|
-
|
1064
|
-
|
1007
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
1008
|
+
feesAmountUsd = totalFeesUsd;
|
1065
1009
|
}
|
1066
1010
|
else {
|
1067
|
-
|
1068
|
-
|
1011
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
1012
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
1069
1013
|
}
|
1014
|
+
var closeAmount = collateralMinMaxPrice.max.getTokenAmount(closeAmountUsd, collateralCustodyAccount.decimals);
|
1070
1015
|
var newPosition = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
1071
1016
|
newPosition.sizeAmount = positionAccount.sizeAmount.sub(positionDelta.sizeAmount);
|
1072
1017
|
newPosition.sizeUsd = positionAccount.sizeUsd.sub(positionDelta.sizeUsd);
|
1073
1018
|
newPosition.lockedUsd = positionAccount.lockedUsd.sub(positionDelta.lockedUsd);
|
1074
1019
|
newPosition.lockedAmount = positionAccount.lockedAmount.sub(positionDelta.lockedAmount);
|
1075
|
-
newPosition.
|
1020
|
+
newPosition.collateralUsd = positionAccount.collateralUsd.sub(positionDelta.collateralUsd);
|
1076
1021
|
newPosition.unsettledFeesUsd = positionAccount.unsettledFeesUsd.sub(positionDelta.unsettledFeesUsd);
|
1077
|
-
newPosition.collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(newPosition.collateralAmount, collateralCustodyAccount.decimals);
|
1078
1022
|
newPosition.degenSizeUsd = positionAccount.degenSizeUsd.sub(positionDelta.degenSizeUsd);
|
1079
1023
|
var feeUsdWithDiscount = constants_1.BN_ZERO;
|
1080
1024
|
var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
@@ -1089,8 +1033,8 @@ var PerpetualsClient = (function () {
|
|
1089
1033
|
feeUsdWithDiscount = feeUsdWithDiscount.add(lockAndUnsettledFeeUsd);
|
1090
1034
|
if (keepLevSame) {
|
1091
1035
|
var collateralAmountReceived = closeAmount;
|
1092
|
-
var collateralAmountRecievedUsd =
|
1093
|
-
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
1036
|
+
var collateralAmountRecievedUsd = closeAmountUsd;
|
1037
|
+
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmountUsd), maxWithdrawableAmount = _a.maxWithdrawableAmount, diff = _a.diff;
|
1094
1038
|
if (debugLogs) {
|
1095
1039
|
console.log("maxWithdrawableAmount ", maxWithdrawableAmount.toString(), keepLevSame);
|
1096
1040
|
console.log("collateralAmountReceived ", collateralAmountReceived.toString(), keepLevSame);
|
@@ -1107,11 +1051,11 @@ var PerpetualsClient = (function () {
|
|
1107
1051
|
collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(maxWithdrawableAmount, collateralCustodyAccount.decimals);
|
1108
1052
|
}
|
1109
1053
|
var entryPrice = OraclePrice_1.OraclePrice.from({ price: newPosition.entryPrice.price, exponent: new anchor_1.BN(newPosition.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
|
1110
|
-
var
|
1111
|
-
var finalLiquidationPrice = _this.
|
1054
|
+
var lockAndUnsettledFeeUsdNew = _this.getLockFeeAndUnsettledUsdForPosition(newPosition, collateralCustodyAccount, currentTimestamp);
|
1055
|
+
var finalLiquidationPrice = _this.getLiquidationPriceContractHelper(entryPrice, lockAndUnsettledFeeUsdNew, side, targetCustodyAccount, newPosition);
|
1112
1056
|
var finalPnl = _this.getPnlSync(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1113
1057
|
var finalPnlUsd = finalPnl.profitUsd.sub(finalPnl.lossUsd);
|
1114
|
-
var newLev = _this.getLeverageSync(newPosition
|
1058
|
+
var newLev = _this.getLeverageSync(newPosition, newPosition.collateralUsd, newPosition.sizeUsd, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, false, poolConfig);
|
1115
1059
|
return {
|
1116
1060
|
newSizeUsd: newPosition.sizeUsd,
|
1117
1061
|
feeUsd: feeUsd,
|
@@ -1120,6 +1064,7 @@ var PerpetualsClient = (function () {
|
|
1120
1064
|
newLev: newLev,
|
1121
1065
|
liquidationPrice: finalLiquidationPrice,
|
1122
1066
|
collateralAmountRecieved: collateralAmountReceived,
|
1067
|
+
collateralAmountRecievedUsd: collateralAmountRecievedUsd,
|
1123
1068
|
newCollateralAmount: newPosition.collateralAmount.add(diff),
|
1124
1069
|
newPnl: finalPnlUsd
|
1125
1070
|
};
|
@@ -1128,8 +1073,8 @@ var PerpetualsClient = (function () {
|
|
1128
1073
|
throw "only same leverage is supported for now";
|
1129
1074
|
}
|
1130
1075
|
};
|
1131
|
-
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
1132
|
-
if (
|
1076
|
+
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmountUsd, errorBandwidthPercentageUi) {
|
1077
|
+
if (closeAmountUsd === void 0) { closeAmountUsd = constants_1.BN_ZERO; }
|
1133
1078
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
1134
1079
|
if (errorBandwidthPercentageUi > 100 || errorBandwidthPercentageUi < 0) {
|
1135
1080
|
throw new Error("errorBandwidthPercentageUi cannot be >100 or <0");
|
@@ -1138,24 +1083,25 @@ var PerpetualsClient = (function () {
|
|
1138
1083
|
(new anchor_1.BN(targetCustodyAccount.pricing.maxInitDegenLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100))
|
1139
1084
|
: (new anchor_1.BN(targetCustodyAccount.pricing.maxInitLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100));
|
1140
1085
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1141
|
-
var
|
1086
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1142
1087
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1143
1088
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1144
1089
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
1145
|
-
var currentCollateralUsd =
|
1090
|
+
var currentCollateralUsd = positionAccount.collateralUsd.sub(closeAmountUsd);
|
1146
1091
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
1147
1092
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
1148
1093
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
1149
1094
|
}
|
1150
1095
|
else {
|
1151
1096
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
1152
|
-
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1097
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1153
1098
|
}
|
1154
1099
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
1155
1100
|
if (maxRemovableCollateralUsd.isNeg()) {
|
1156
|
-
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1101
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1157
1102
|
}
|
1158
1103
|
var maxWithdrawableAmount = constants_1.BN_ZERO;
|
1104
|
+
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
1159
1105
|
var diff = constants_1.BN_ZERO;
|
1160
1106
|
var remainingCollateralUsd = availableInitMarginUsd.sub(maxRemovableCollateralUsd);
|
1161
1107
|
var isDegenMode = positionAccount.isDegenMode();
|
@@ -1163,36 +1109,37 @@ var PerpetualsClient = (function () {
|
|
1163
1109
|
diff = (new anchor_1.BN(isDegenMode ? targetCustodyAccount.pricing.minDegenCollateralUsd : targetCustodyAccount.pricing.minCollateralUsd)).sub(remainingCollateralUsd);
|
1164
1110
|
var updatedMaxRemovableCollateralUsd = maxRemovableCollateralUsd.sub(diff);
|
1165
1111
|
if (updatedMaxRemovableCollateralUsd.isNeg()) {
|
1166
|
-
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1112
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1167
1113
|
}
|
1168
1114
|
else {
|
1169
|
-
maxWithdrawableAmount =
|
1115
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(updatedMaxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1116
|
+
maxWithdrawableAmountUsd = updatedMaxRemovableCollateralUsd;
|
1170
1117
|
}
|
1171
1118
|
}
|
1172
1119
|
else {
|
1173
|
-
maxWithdrawableAmount =
|
1120
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1121
|
+
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
1174
1122
|
}
|
1175
|
-
return { maxWithdrawableAmount: maxWithdrawableAmount, diff: diff };
|
1123
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd, diff: diff };
|
1176
1124
|
};
|
1177
|
-
this.
|
1125
|
+
this.getFinalCloseAmountUsdSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
|
1178
1126
|
var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
1179
1127
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1180
|
-
var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
|
1181
1128
|
var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1182
1129
|
var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
|
1183
1130
|
var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
|
1184
1131
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
1185
|
-
var assetsUsd = newPnl.profitUsd.add(collateralMinMaxPrice.
|
1186
|
-
var
|
1132
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
|
1133
|
+
var closeAmountUsd, feesAmountUsd;
|
1187
1134
|
if (assetsUsd.gt(liabilityUsd)) {
|
1188
|
-
|
1189
|
-
|
1135
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
1136
|
+
feesAmountUsd = totalFeesUsd;
|
1190
1137
|
}
|
1191
1138
|
else {
|
1192
|
-
|
1193
|
-
|
1139
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
1140
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
1194
1141
|
}
|
1195
|
-
return {
|
1142
|
+
return { closeAmountUsd: closeAmountUsd, feesAmountUsd: feesAmountUsd };
|
1196
1143
|
};
|
1197
1144
|
this.getMaxWithdrawableAmountSync = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, errorBandwidthPercentageUi) {
|
1198
1145
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
@@ -1205,34 +1152,37 @@ var PerpetualsClient = (function () {
|
|
1205
1152
|
var maxRemoveableCollateralUsdAfterMinRequired = positionAccount.collateralUsd.sub((positionAccount.isDegenMode() ? new anchor_1.BN(targetCustodyAccount.pricing.minDegenCollateralUsd) : new anchor_1.BN(targetCustodyAccount.pricing.minCollateralUsd)).mul(new anchor_1.BN(100 + errorBandwidthPercentageUi)).div(new anchor_1.BN(100)));
|
1206
1153
|
if (maxRemoveableCollateralUsdAfterMinRequired.isNeg()) {
|
1207
1154
|
console.log("THIS cannot happen but still");
|
1208
|
-
return constants_1.BN_ZERO;
|
1155
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1209
1156
|
}
|
1210
1157
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1211
|
-
var
|
1158
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1212
1159
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1213
1160
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1214
1161
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
1215
|
-
var currentCollateralUsd =
|
1162
|
+
var currentCollateralUsd = positionAccount.collateralUsd;
|
1216
1163
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
1217
1164
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
1218
1165
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
1219
1166
|
}
|
1220
1167
|
else {
|
1221
1168
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
1222
|
-
return constants_1.BN_ZERO;
|
1169
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1223
1170
|
}
|
1224
1171
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
1225
1172
|
if (maxRemovableCollateralUsd.isNeg()) {
|
1226
|
-
return constants_1.BN_ZERO;
|
1173
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1227
1174
|
}
|
1228
1175
|
var maxWithdrawableAmount;
|
1176
|
+
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
1229
1177
|
if (maxRemoveableCollateralUsdAfterMinRequired.lt(maxRemovableCollateralUsd)) {
|
1230
|
-
maxWithdrawableAmount =
|
1178
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemoveableCollateralUsdAfterMinRequired, collateralCustodyAccount.decimals);
|
1179
|
+
maxWithdrawableAmountUsd = maxRemoveableCollateralUsdAfterMinRequired;
|
1231
1180
|
}
|
1232
1181
|
else {
|
1233
|
-
maxWithdrawableAmount =
|
1182
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1183
|
+
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
1234
1184
|
}
|
1235
|
-
return maxWithdrawableAmount;
|
1185
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd };
|
1236
1186
|
};
|
1237
1187
|
this.getCumulativeLockFeeSync = function (custodyAccount, currentTimestamp) {
|
1238
1188
|
var cumulativeLockFee = constants_1.BN_ZERO;
|
@@ -1286,185 +1236,138 @@ var PerpetualsClient = (function () {
|
|
1286
1236
|
var lockedUsd = (sideUsd.mul(maxPayOffBpsNew)).div(new anchor_1.BN(constants_1.BPS_POWER));
|
1287
1237
|
return lockedUsd;
|
1288
1238
|
};
|
1289
|
-
this.
|
1239
|
+
this.getLiquidationPriceContractHelper = function (entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount) {
|
1290
1240
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
1291
1241
|
price: constants_1.BN_ZERO,
|
1292
1242
|
exponent: constants_1.BN_ZERO,
|
1293
1243
|
confidence: constants_1.BN_ZERO,
|
1294
1244
|
timestamp: constants_1.BN_ZERO
|
1295
1245
|
});
|
1296
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
1297
|
-
return zeroOraclePrice;
|
1298
|
-
}
|
1299
1246
|
if (positionAccount.entryPrice.exponent && !entryOraclePrice.exponent.eq(new anchor_1.BN(positionAccount.entryPrice.exponent))) {
|
1300
1247
|
throw new Error("Exponent mismatch : ".concat(positionAccount.entryPrice.exponent, " & ").concat(entryOraclePrice.exponent.toString(), " ").concat(entryOraclePrice === null || entryOraclePrice === void 0 ? void 0 : entryOraclePrice.toUiPrice(8)));
|
1301
1248
|
}
|
1302
1249
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1303
1250
|
var unsettledLossUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
|
1304
1251
|
var liablitiesUsd = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
1305
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
1306
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1307
1252
|
var liquidationPrice;
|
1308
|
-
if (
|
1309
|
-
var
|
1310
|
-
|
1311
|
-
|
1253
|
+
if (positionAccount.collateralUsd.gte(liablitiesUsd)) {
|
1254
|
+
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1255
|
+
price: (positionAccount.collateralUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1256
|
+
.div(positionAccount.sizeAmount),
|
1257
|
+
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1258
|
+
confidence: constants_1.BN_ZERO,
|
1259
|
+
timestamp: constants_1.BN_ZERO
|
1260
|
+
}).scale_to_exponent(new anchor_1.BN(entryOraclePrice.exponent));
|
1261
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1262
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1263
|
+
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
1264
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1265
|
+
confidence: constants_1.BN_ZERO,
|
1266
|
+
timestamp: constants_1.BN_ZERO
|
1267
|
+
});
|
1312
1268
|
}
|
1313
1269
|
else {
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1270
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1271
|
+
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
1272
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1273
|
+
confidence: constants_1.BN_ZERO,
|
1274
|
+
timestamp: constants_1.BN_ZERO
|
1275
|
+
});
|
1317
1276
|
}
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1277
|
+
}
|
1278
|
+
else {
|
1279
|
+
var priceDiffProfitOracle = OraclePrice_1.OraclePrice.from({
|
1280
|
+
price: (liablitiesUsd.sub(positionAccount.collateralUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1281
|
+
.div(positionAccount.sizeAmount),
|
1321
1282
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1322
1283
|
confidence: constants_1.BN_ZERO,
|
1323
1284
|
timestamp: constants_1.BN_ZERO
|
1324
|
-
});
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
1330
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1331
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1332
|
-
.div(positionAccount.sizeAmount),
|
1333
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1285
|
+
}).scale_to_exponent(new anchor_1.BN(entryOraclePrice.exponent));
|
1286
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1287
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1288
|
+
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
1289
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1334
1290
|
confidence: constants_1.BN_ZERO,
|
1335
1291
|
timestamp: constants_1.BN_ZERO
|
1336
|
-
})
|
1337
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1338
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1339
|
-
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
1340
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1341
|
-
confidence: constants_1.BN_ZERO,
|
1342
|
-
timestamp: constants_1.BN_ZERO
|
1343
|
-
});
|
1344
|
-
}
|
1345
|
-
else {
|
1346
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1347
|
-
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
1348
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1349
|
-
confidence: constants_1.BN_ZERO,
|
1350
|
-
timestamp: constants_1.BN_ZERO
|
1351
|
-
});
|
1352
|
-
}
|
1292
|
+
});
|
1353
1293
|
}
|
1354
1294
|
else {
|
1355
|
-
|
1356
|
-
price:
|
1357
|
-
|
1358
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1295
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1296
|
+
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1297
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1359
1298
|
confidence: constants_1.BN_ZERO,
|
1360
1299
|
timestamp: constants_1.BN_ZERO
|
1361
|
-
})
|
1362
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1363
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1364
|
-
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
1365
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1366
|
-
confidence: constants_1.BN_ZERO,
|
1367
|
-
timestamp: constants_1.BN_ZERO
|
1368
|
-
});
|
1369
|
-
}
|
1370
|
-
else {
|
1371
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1372
|
-
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1373
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1374
|
-
confidence: constants_1.BN_ZERO,
|
1375
|
-
timestamp: constants_1.BN_ZERO
|
1376
|
-
});
|
1377
|
-
}
|
1300
|
+
});
|
1378
1301
|
}
|
1379
1302
|
}
|
1380
1303
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
1381
1304
|
};
|
1382
|
-
this.
|
1305
|
+
this.getLiquidationPriceSync = function (collateralUsd, sizeAmount, entryOraclePrice, lockAndUnsettledFeeUsd, side, targetPrice, targetCustodyAccount, positionAccount) {
|
1306
|
+
var newPositionAccount = positionAccount.clone();
|
1307
|
+
newPositionAccount.sizeAmount = sizeAmount;
|
1308
|
+
newPositionAccount.sizeUsd = targetPrice.getAssetAmountUsd(sizeAmount, targetCustodyAccount.decimals);
|
1309
|
+
newPositionAccount.collateralUsd = collateralUsd;
|
1310
|
+
return _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, newPositionAccount);
|
1311
|
+
};
|
1312
|
+
this.getLiquidationPriceWithOrder = function (collateralUsd, sizeAmount, sizeUsd, sizeDecimals, limitOraclePrice, side, targetCustodyAccount) {
|
1383
1313
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
1384
1314
|
price: constants_1.BN_ZERO,
|
1385
1315
|
exponent: constants_1.BN_ZERO,
|
1386
1316
|
confidence: constants_1.BN_ZERO,
|
1387
1317
|
timestamp: constants_1.BN_ZERO
|
1388
1318
|
});
|
1389
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
1390
|
-
return zeroOraclePrice;
|
1391
|
-
}
|
1392
1319
|
var exitFeeUsd = sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1393
1320
|
var unsettledLossUsd = exitFeeUsd;
|
1394
1321
|
var liablitiesUsd = sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
1395
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
1396
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1397
1322
|
var liquidationPrice;
|
1398
|
-
if (
|
1399
|
-
var
|
1400
|
-
|
1401
|
-
|
1323
|
+
if (collateralUsd.gte(liablitiesUsd)) {
|
1324
|
+
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1325
|
+
price: (collateralUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1326
|
+
.div(sizeAmount),
|
1327
|
+
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1328
|
+
confidence: constants_1.BN_ZERO,
|
1329
|
+
timestamp: constants_1.BN_ZERO
|
1330
|
+
}).scale_to_exponent(new anchor_1.BN(limitOraclePrice.exponent));
|
1331
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1332
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1333
|
+
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
1334
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1335
|
+
confidence: constants_1.BN_ZERO,
|
1336
|
+
timestamp: constants_1.BN_ZERO
|
1337
|
+
});
|
1402
1338
|
}
|
1403
1339
|
else {
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1340
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1341
|
+
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
1342
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1343
|
+
confidence: constants_1.BN_ZERO,
|
1344
|
+
timestamp: constants_1.BN_ZERO
|
1345
|
+
});
|
1407
1346
|
}
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1347
|
+
}
|
1348
|
+
else {
|
1349
|
+
var priceDiffProfitOracle = OraclePrice_1.OraclePrice.from({
|
1350
|
+
price: (liablitiesUsd.sub(collateralUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1351
|
+
.div(sizeAmount),
|
1411
1352
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1412
1353
|
confidence: constants_1.BN_ZERO,
|
1413
1354
|
timestamp: constants_1.BN_ZERO
|
1414
|
-
});
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
1420
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1421
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1422
|
-
.div(sizeAmount),
|
1423
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1355
|
+
}).scale_to_exponent(new anchor_1.BN(limitOraclePrice.exponent));
|
1356
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1357
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1358
|
+
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
1359
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1424
1360
|
confidence: constants_1.BN_ZERO,
|
1425
1361
|
timestamp: constants_1.BN_ZERO
|
1426
|
-
})
|
1427
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1428
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1429
|
-
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
1430
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1431
|
-
confidence: constants_1.BN_ZERO,
|
1432
|
-
timestamp: constants_1.BN_ZERO
|
1433
|
-
});
|
1434
|
-
}
|
1435
|
-
else {
|
1436
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1437
|
-
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
1438
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1439
|
-
confidence: constants_1.BN_ZERO,
|
1440
|
-
timestamp: constants_1.BN_ZERO
|
1441
|
-
});
|
1442
|
-
}
|
1362
|
+
});
|
1443
1363
|
}
|
1444
1364
|
else {
|
1445
|
-
|
1446
|
-
price:
|
1447
|
-
|
1448
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1365
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1366
|
+
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1367
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1449
1368
|
confidence: constants_1.BN_ZERO,
|
1450
1369
|
timestamp: constants_1.BN_ZERO
|
1451
|
-
})
|
1452
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1453
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1454
|
-
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
1455
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1456
|
-
confidence: constants_1.BN_ZERO,
|
1457
|
-
timestamp: constants_1.BN_ZERO
|
1458
|
-
});
|
1459
|
-
}
|
1460
|
-
else {
|
1461
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1462
|
-
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1463
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1464
|
-
confidence: constants_1.BN_ZERO,
|
1465
|
-
timestamp: constants_1.BN_ZERO
|
1466
|
-
});
|
1467
|
-
}
|
1370
|
+
});
|
1468
1371
|
}
|
1469
1372
|
}
|
1470
1373
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
@@ -1540,8 +1443,8 @@ var PerpetualsClient = (function () {
|
|
1540
1443
|
positionAccount.market = marketAccountPk;
|
1541
1444
|
positionAccount.lockedUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
|
1542
1445
|
positionAccount.lockedAmount = collateralPrice.getTokenAmount(positionAccount.lockedUsd, collateralCustodyAccount.decimals);
|
1543
|
-
|
1544
|
-
positionAccount.collateralUsd =
|
1446
|
+
var collateralDeltaUsd = collateralPrice.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
1447
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
1545
1448
|
var currentTime = new anchor_1.BN((0, utils_1.getUnixTs)());
|
1546
1449
|
var pnl = _this.getPnlSync(positionAccount, userEntrytpSlOraclePrice, userEntrytpSlOraclePrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTime, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1547
1450
|
var pnlUsd = pnl.profitUsd.sub(pnl.lossUsd);
|
@@ -1613,6 +1516,9 @@ var PerpetualsClient = (function () {
|
|
1613
1516
|
});
|
1614
1517
|
};
|
1615
1518
|
this.getPnlSync = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig) {
|
1519
|
+
return _this.getPnlContractHelper(positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig);
|
1520
|
+
};
|
1521
|
+
this.getPnlContractHelper = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig) {
|
1616
1522
|
if (positionAccount.sizeUsd.isZero() || positionAccount.entryPrice.price.isZero()) {
|
1617
1523
|
return {
|
1618
1524
|
profitUsd: constants_1.BN_ZERO,
|
@@ -1671,7 +1577,7 @@ var PerpetualsClient = (function () {
|
|
1671
1577
|
}
|
1672
1578
|
if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
|
1673
1579
|
return {
|
1674
|
-
profitUsd:
|
1580
|
+
profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
|
1675
1581
|
lossUsd: constants_1.BN_ZERO,
|
1676
1582
|
};
|
1677
1583
|
}
|
@@ -1762,6 +1668,9 @@ var PerpetualsClient = (function () {
|
|
1762
1668
|
}
|
1763
1669
|
};
|
1764
1670
|
this.getAssetsUnderManagementUsdSync = function (poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig) {
|
1671
|
+
return _this.getAssetsUnderManagementUsdContractHelper(poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig);
|
1672
|
+
};
|
1673
|
+
this.getAssetsUnderManagementUsdContractHelper = function (poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig) {
|
1765
1674
|
var poolAmountUsd = constants_1.BN_ZERO;
|
1766
1675
|
for (var index = 0; index < custodies.length; index++) {
|
1767
1676
|
if (custodies.length != poolAccount.custodies.length || !custodies[index].publicKey.equals(poolAccount.custodies[index])) {
|
@@ -1774,6 +1683,7 @@ var PerpetualsClient = (function () {
|
|
1774
1683
|
var token_amount_usd = tokenMinMaxPrice.max.getAssetAmountUsd(custodies[index].assets.owned, custodies[index].decimals);
|
1775
1684
|
poolAmountUsd = poolAmountUsd.add(token_amount_usd);
|
1776
1685
|
}
|
1686
|
+
poolAmountUsd = poolAmountUsd.sub(poolAccount.feesObligationUsd.add(poolAccount.rebateObligationUsd));
|
1777
1687
|
if (aumCalcMode === "includePnl") {
|
1778
1688
|
var poolEquityUsd = poolAmountUsd;
|
1779
1689
|
for (var index = 0; index < markets.length; index++) {
|
@@ -1783,11 +1693,12 @@ var PerpetualsClient = (function () {
|
|
1783
1693
|
var targetCustodyId = poolAccount.getCustodyId(markets[index].targetCustody);
|
1784
1694
|
var collateralCustodyId = poolAccount.getCustodyId(markets[index].collateralCustody);
|
1785
1695
|
var position = markets[index].getCollectivePosition();
|
1696
|
+
poolEquityUsd = poolEquityUsd.sub(position.collateralUsd);
|
1786
1697
|
var collectivePnl = _this.getPnlSync(position, tokenPrices[targetCustodyId], tokenEmaPrices[targetCustodyId], custodies[targetCustodyId], tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId], currentTime, custodies[targetCustodyId].pricing.delaySeconds, poolConfig);
|
1787
1698
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId]);
|
1788
|
-
var
|
1789
|
-
var
|
1790
|
-
poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(
|
1699
|
+
var collectiveLossUsd = anchor_1.BN.min(collectivePnl.lossUsd, position.collateralUsd);
|
1700
|
+
var collectiveProfitUsd = anchor_1.BN.min(collectivePnl.profitUsd, collateralMinMaxPrice.max.getAssetAmountUsd(position.lockedAmount, custodies[collateralCustodyId].decimals).sub(position.collateralUsd));
|
1701
|
+
poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(collectiveProfitUsd);
|
1791
1702
|
}
|
1792
1703
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: poolEquityUsd };
|
1793
1704
|
}
|
@@ -1795,14 +1706,6 @@ var PerpetualsClient = (function () {
|
|
1795
1706
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: constants_1.BN_ZERO };
|
1796
1707
|
}
|
1797
1708
|
};
|
1798
|
-
this.getNftFinalDiscount = function (perpetualsAccount, nftTradingAccount, currentTime) {
|
1799
|
-
if (currentTime.sub(nftTradingAccount.timestamp).lt(constants_1.DAY_SECONDS) && nftTradingAccount.counter.gt(new anchor_1.BN(perpetualsAccount.tradeLimit))) {
|
1800
|
-
return { discountBn: constants_1.BN_ZERO };
|
1801
|
-
}
|
1802
|
-
else {
|
1803
|
-
return { discountBn: perpetualsAccount.tradingDiscount[nftTradingAccount.level - 1] };
|
1804
|
-
}
|
1805
|
-
};
|
1806
1709
|
this.getFeeDiscount = function (perpetualsAccount, tokenStakeAccount, currentTime) {
|
1807
1710
|
if (tokenStakeAccount.level === 0) {
|
1808
1711
|
return { discountBn: constants_1.BN_ZERO };
|
@@ -1887,7 +1790,7 @@ var PerpetualsClient = (function () {
|
|
1887
1790
|
});
|
1888
1791
|
};
|
1889
1792
|
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1890
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
|
1793
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
|
1891
1794
|
var _d;
|
1892
1795
|
return __generator(this, function (_e) {
|
1893
1796
|
switch (_e.label) {
|
@@ -1935,6 +1838,8 @@ var PerpetualsClient = (function () {
|
|
1935
1838
|
return [4, backUpOracleInstructionPromise];
|
1936
1839
|
case 2:
|
1937
1840
|
backUpOracleInstruction = _e.sent();
|
1841
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
1842
|
+
transaction.instructions.unshift(setCULimitIx);
|
1938
1843
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1939
1844
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1940
1845
|
case 3:
|
@@ -2001,7 +1906,7 @@ var PerpetualsClient = (function () {
|
|
2001
1906
|
args_1[_i - 4] = arguments[_i];
|
2002
1907
|
}
|
2003
1908
|
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) {
|
2004
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
1909
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2005
1910
|
var _e;
|
2006
1911
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2007
1912
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2052,6 +1957,8 @@ var PerpetualsClient = (function () {
|
|
2052
1957
|
.transaction()];
|
2053
1958
|
case 1:
|
2054
1959
|
transaction = _f.sent();
|
1960
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
1961
|
+
transaction.instructions.unshift(setCULimitIx);
|
2055
1962
|
if (!enableBackupOracle) return [3, 3];
|
2056
1963
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2057
1964
|
case 2:
|
@@ -2077,7 +1984,7 @@ var PerpetualsClient = (function () {
|
|
2077
1984
|
args_1[_i - 4] = arguments[_i];
|
2078
1985
|
}
|
2079
1986
|
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) {
|
2080
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
1987
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2081
1988
|
var _e;
|
2082
1989
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2083
1990
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2128,6 +2035,8 @@ var PerpetualsClient = (function () {
|
|
2128
2035
|
.transaction()];
|
2129
2036
|
case 1:
|
2130
2037
|
transaction = _f.sent();
|
2038
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2039
|
+
transaction.instructions.unshift(setCULimitIx);
|
2131
2040
|
if (!enableBackupOracle) return [3, 3];
|
2132
2041
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2133
2042
|
case 2:
|
@@ -2154,7 +2063,7 @@ var PerpetualsClient = (function () {
|
|
2154
2063
|
});
|
2155
2064
|
};
|
2156
2065
|
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
2157
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
|
2066
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
|
2158
2067
|
var _d;
|
2159
2068
|
return __generator(this, function (_e) {
|
2160
2069
|
switch (_e.label) {
|
@@ -2202,6 +2111,8 @@ var PerpetualsClient = (function () {
|
|
2202
2111
|
.transaction()];
|
2203
2112
|
case 2:
|
2204
2113
|
transaction = _e.sent();
|
2114
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2115
|
+
transaction.instructions.unshift(setCULimitIx);
|
2205
2116
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2206
2117
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
2207
2118
|
case 3:
|
@@ -2218,7 +2129,7 @@ var PerpetualsClient = (function () {
|
|
2218
2129
|
args_1[_i - 4] = arguments[_i];
|
2219
2130
|
}
|
2220
2131
|
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) {
|
2221
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
2132
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2222
2133
|
var _e;
|
2223
2134
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2224
2135
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2273,6 +2184,8 @@ var PerpetualsClient = (function () {
|
|
2273
2184
|
.transaction()];
|
2274
2185
|
case 1:
|
2275
2186
|
transaction = _f.sent();
|
2187
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2188
|
+
transaction.instructions.unshift(setCULimitIx);
|
2276
2189
|
if (!enableBackupOracle) return [3, 3];
|
2277
2190
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2278
2191
|
case 2:
|
@@ -2298,7 +2211,7 @@ var PerpetualsClient = (function () {
|
|
2298
2211
|
args_1[_i - 4] = arguments[_i];
|
2299
2212
|
}
|
2300
2213
|
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) {
|
2301
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
2214
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2302
2215
|
var _e;
|
2303
2216
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2304
2217
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2353,6 +2266,8 @@ var PerpetualsClient = (function () {
|
|
2353
2266
|
.transaction()];
|
2354
2267
|
case 1:
|
2355
2268
|
transaction = _f.sent();
|
2269
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2270
|
+
transaction.instructions.unshift(setCULimitIx);
|
2356
2271
|
if (!enableBackupOracle) return [3, 3];
|
2357
2272
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2358
2273
|
case 2:
|
@@ -2547,11 +2462,10 @@ var PerpetualsClient = (function () {
|
|
2547
2462
|
for (var _i = 8; _i < arguments.length; _i++) {
|
2548
2463
|
args_1[_i - 8] = arguments[_i];
|
2549
2464
|
}
|
2550
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount,
|
2465
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2551
2466
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2552
2467
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2553
2468
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2554
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2555
2469
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2556
2470
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2557
2471
|
return __generator(this, function (_c) {
|
@@ -2644,7 +2558,7 @@ var PerpetualsClient = (function () {
|
|
2644
2558
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2645
2559
|
fundingMint: collateralCustodyConfig.mintKey
|
2646
2560
|
})
|
2647
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2561
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
2648
2562
|
.instruction()];
|
2649
2563
|
case 7:
|
2650
2564
|
instruction = _c.sent();
|
@@ -2662,11 +2576,10 @@ var PerpetualsClient = (function () {
|
|
2662
2576
|
for (var _i = 6; _i < arguments.length; _i++) {
|
2663
2577
|
args_1[_i - 6] = arguments[_i];
|
2664
2578
|
}
|
2665
|
-
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount,
|
2579
|
+
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2666
2580
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
2667
2581
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2668
2582
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2669
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2670
2583
|
if (createUserATA === void 0) { createUserATA = true; }
|
2671
2584
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2672
2585
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
@@ -2745,7 +2658,7 @@ var PerpetualsClient = (function () {
|
|
2745
2658
|
collateralMint: collateralCustodyConfig.mintKey,
|
2746
2659
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2747
2660
|
})
|
2748
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2661
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
2749
2662
|
.instruction()];
|
2750
2663
|
case 6:
|
2751
2664
|
instruction = _b.sent();
|
@@ -2772,11 +2685,10 @@ var PerpetualsClient = (function () {
|
|
2772
2685
|
for (var _i = 9; _i < arguments.length; _i++) {
|
2773
2686
|
args_1[_i - 9] = arguments[_i];
|
2774
2687
|
}
|
2775
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount,
|
2688
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2776
2689
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_3;
|
2777
2690
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2778
2691
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2779
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2780
2692
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2781
2693
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2782
2694
|
return __generator(this, function (_c) {
|
@@ -2911,7 +2823,7 @@ var PerpetualsClient = (function () {
|
|
2911
2823
|
collateralMint: collateralCustodyConfig.mintKey,
|
2912
2824
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2913
2825
|
})
|
2914
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2826
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
2915
2827
|
.instruction()];
|
2916
2828
|
case 12:
|
2917
2829
|
inx = _c.sent();
|
@@ -2929,16 +2841,15 @@ var PerpetualsClient = (function () {
|
|
2929
2841
|
});
|
2930
2842
|
});
|
2931
2843
|
};
|
2932
|
-
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
2844
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2933
2845
|
var args_1 = [];
|
2934
|
-
for (var _i =
|
2935
|
-
args_1[_i -
|
2846
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
2847
|
+
args_1[_i - 7] = arguments[_i];
|
2936
2848
|
}
|
2937
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
2938
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount,
|
2849
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey) {
|
2850
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, inx, err_4;
|
2939
2851
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2940
2852
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2941
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2942
2853
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2943
2854
|
return __generator(this, function (_a) {
|
2944
2855
|
switch (_a.label) {
|
@@ -3004,18 +2915,12 @@ var PerpetualsClient = (function () {
|
|
3004
2915
|
if (!(_a.sent())) {
|
3005
2916
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3006
2917
|
}
|
3007
|
-
rebateMintAccount = {
|
3008
|
-
pubkey: collateralCustodyConfig.mintKey,
|
3009
|
-
isSigner: false,
|
3010
|
-
isWritable: false
|
3011
|
-
};
|
3012
2918
|
_a.label = 5;
|
3013
2919
|
case 5:
|
3014
2920
|
_a.trys.push([5, 7, , 8]);
|
3015
2921
|
return [4, this.program.methods
|
3016
2922
|
.closeAndSwap({
|
3017
2923
|
priceWithSlippage: priceWithSlippage,
|
3018
|
-
minSwapAmountOut: minSwapAmountOut,
|
3019
2924
|
privilege: privilege
|
3020
2925
|
})
|
3021
2926
|
.accounts({
|
@@ -3044,7 +2949,7 @@ var PerpetualsClient = (function () {
|
|
3044
2949
|
collateralMint: collateralCustodyConfig.mintKey,
|
3045
2950
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3046
2951
|
})
|
3047
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2952
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
3048
2953
|
.instruction()];
|
3049
2954
|
case 6:
|
3050
2955
|
inx = _a.sent();
|
@@ -3502,11 +3407,10 @@ var PerpetualsClient = (function () {
|
|
3502
3407
|
for (var _i = 8; _i < arguments.length; _i++) {
|
3503
3408
|
args_1[_i - 8] = arguments[_i];
|
3504
3409
|
}
|
3505
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount
|
3410
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
3506
3411
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3507
3412
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3508
3413
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3509
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3510
3414
|
return __generator(this, function (_a) {
|
3511
3415
|
switch (_a.label) {
|
3512
3416
|
case 0:
|
@@ -3549,7 +3453,7 @@ var PerpetualsClient = (function () {
|
|
3549
3453
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3550
3454
|
collateralMint: collateralCustodyConfig.mintKey
|
3551
3455
|
})
|
3552
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
3456
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
3553
3457
|
.instruction()];
|
3554
3458
|
case 1:
|
3555
3459
|
instruction = _a.sent();
|
@@ -3567,11 +3471,10 @@ var PerpetualsClient = (function () {
|
|
3567
3471
|
for (var _i = 8; _i < arguments.length; _i++) {
|
3568
3472
|
args_1[_i - 8] = arguments[_i];
|
3569
3473
|
}
|
3570
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount
|
3474
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
3571
3475
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3572
3476
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3573
3477
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3574
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3575
3478
|
return __generator(this, function (_a) {
|
3576
3479
|
switch (_a.label) {
|
3577
3480
|
case 0:
|
@@ -3614,7 +3517,7 @@ var PerpetualsClient = (function () {
|
|
3614
3517
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3615
3518
|
collateralMint: collateralCustodyConfig.mintKey
|
3616
3519
|
})
|
3617
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
3520
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
3618
3521
|
.instruction()];
|
3619
3522
|
case 1:
|
3620
3523
|
instruction = _a.sent();
|
@@ -4081,119 +3984,8 @@ var PerpetualsClient = (function () {
|
|
4081
3984
|
}
|
4082
3985
|
});
|
4083
3986
|
}); };
|
4084
|
-
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4085
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
4086
|
-
return __generator(this, function (_a) {
|
4087
|
-
switch (_a.label) {
|
4088
|
-
case 0:
|
4089
|
-
publicKey = this.provider.wallet.publicKey;
|
4090
|
-
preInstructions = [];
|
4091
|
-
instructions = [];
|
4092
|
-
postInstructions = [];
|
4093
|
-
additionalSigners = [];
|
4094
|
-
_a.label = 1;
|
4095
|
-
case 1:
|
4096
|
-
_a.trys.push([1, 4, , 5]);
|
4097
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4098
|
-
Buffer.from("trading"),
|
4099
|
-
nftMint.toBuffer(),
|
4100
|
-
], this.programId)[0];
|
4101
|
-
nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4102
|
-
Buffer.from("referral"),
|
4103
|
-
publicKey.toBuffer(),
|
4104
|
-
], this.programId)[0];
|
4105
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
4106
|
-
case 2:
|
4107
|
-
nftTokenAccount = _a.sent();
|
4108
|
-
flpStakeAccountMetas = [];
|
4109
|
-
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
4110
|
-
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
4111
|
-
flpStakeAccountMetas.push({
|
4112
|
-
pubkey: flpStakeAccountPk,
|
4113
|
-
isSigner: false,
|
4114
|
-
isWritable: true,
|
4115
|
-
});
|
4116
|
-
}
|
4117
|
-
return [4, this.program.methods
|
4118
|
-
.updateTradingAccount({
|
4119
|
-
updateReferer: updateReferer,
|
4120
|
-
updateBooster: updateBooster
|
4121
|
-
})
|
4122
|
-
.accounts({
|
4123
|
-
owner: publicKey,
|
4124
|
-
feePayer: publicKey,
|
4125
|
-
nftTokenAccount: nftTokenAccount,
|
4126
|
-
referralAccount: nftReferralAccount,
|
4127
|
-
tradingAccount: nftTradingAccount
|
4128
|
-
})
|
4129
|
-
.instruction()];
|
4130
|
-
case 3:
|
4131
|
-
updateNftTradingAccountInstruction = _a.sent();
|
4132
|
-
instructions.push(updateNftTradingAccountInstruction);
|
4133
|
-
return [3, 5];
|
4134
|
-
case 4:
|
4135
|
-
err_8 = _a.sent();
|
4136
|
-
console.log("perpClient updateNftAccount error:: ", err_8);
|
4137
|
-
throw err_8;
|
4138
|
-
case 5: return [2, {
|
4139
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4140
|
-
additionalSigners: additionalSigners
|
4141
|
-
}];
|
4142
|
-
}
|
4143
|
-
});
|
4144
|
-
}); };
|
4145
|
-
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4146
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
4147
|
-
return __generator(this, function (_a) {
|
4148
|
-
switch (_a.label) {
|
4149
|
-
case 0:
|
4150
|
-
publicKey = this.provider.wallet.publicKey;
|
4151
|
-
preInstructions = [];
|
4152
|
-
instructions = [];
|
4153
|
-
postInstructions = [];
|
4154
|
-
additionalSigners = [];
|
4155
|
-
_a.label = 1;
|
4156
|
-
case 1:
|
4157
|
-
_a.trys.push([1, 3, , 4]);
|
4158
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4159
|
-
Buffer.from("trading"),
|
4160
|
-
nftMint.toBuffer(),
|
4161
|
-
], this.programId)[0];
|
4162
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4163
|
-
return [4, this.program.methods
|
4164
|
-
.levelUp({})
|
4165
|
-
.accounts({
|
4166
|
-
owner: publicKey,
|
4167
|
-
perpetuals: this.perpetuals.publicKey,
|
4168
|
-
pool: poolConfig.poolAddress,
|
4169
|
-
metadataAccount: metadataAccount,
|
4170
|
-
nftMint: nftMint,
|
4171
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
4172
|
-
tradingAccount: nftTradingAccount,
|
4173
|
-
transferAuthority: this.authority.publicKey,
|
4174
|
-
authorizationRulesAccount: authorizationRulesAccount,
|
4175
|
-
authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
|
4176
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
4177
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4178
|
-
})
|
4179
|
-
.instruction()];
|
4180
|
-
case 2:
|
4181
|
-
levelUpInstruction = _a.sent();
|
4182
|
-
instructions.push(levelUpInstruction);
|
4183
|
-
return [3, 4];
|
4184
|
-
case 3:
|
4185
|
-
err_9 = _a.sent();
|
4186
|
-
console.log("perpClient levelUp error:: ", err_9);
|
4187
|
-
throw err_9;
|
4188
|
-
case 4: return [2, {
|
4189
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4190
|
-
additionalSigners: additionalSigners
|
4191
|
-
}];
|
4192
|
-
}
|
4193
|
-
});
|
4194
|
-
}); };
|
4195
3987
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4196
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
3988
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
|
4197
3989
|
return __generator(this, function (_a) {
|
4198
3990
|
switch (_a.label) {
|
4199
3991
|
case 0:
|
@@ -4235,9 +4027,9 @@ var PerpetualsClient = (function () {
|
|
4235
4027
|
instructions.push(depositStakeInstruction);
|
4236
4028
|
return [3, 5];
|
4237
4029
|
case 4:
|
4238
|
-
|
4239
|
-
console.log("perpClient depositStaking error:: ",
|
4240
|
-
throw
|
4030
|
+
err_8 = _a.sent();
|
4031
|
+
console.log("perpClient depositStaking error:: ", err_8);
|
4032
|
+
throw err_8;
|
4241
4033
|
case 5: return [2, {
|
4242
4034
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4243
4035
|
additionalSigners: additionalSigners
|
@@ -4246,7 +4038,7 @@ var PerpetualsClient = (function () {
|
|
4246
4038
|
});
|
4247
4039
|
}); };
|
4248
4040
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4249
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4041
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
|
4250
4042
|
return __generator(this, function (_c) {
|
4251
4043
|
switch (_c.label) {
|
4252
4044
|
case 0:
|
@@ -4293,9 +4085,9 @@ var PerpetualsClient = (function () {
|
|
4293
4085
|
refreshStakeInstruction = _c.sent();
|
4294
4086
|
return [2, refreshStakeInstruction];
|
4295
4087
|
case 2:
|
4296
|
-
|
4297
|
-
console.log("perpClient refreshStaking error:: ",
|
4298
|
-
throw
|
4088
|
+
err_9 = _c.sent();
|
4089
|
+
console.log("perpClient refreshStaking error:: ", err_9);
|
4090
|
+
throw err_9;
|
4299
4091
|
case 3: return [2];
|
4300
4092
|
}
|
4301
4093
|
});
|
@@ -4306,7 +4098,7 @@ var PerpetualsClient = (function () {
|
|
4306
4098
|
args_1[_i - 3] = arguments[_i];
|
4307
4099
|
}
|
4308
4100
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4309
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
4101
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
|
4310
4102
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4311
4103
|
return __generator(this, function (_c) {
|
4312
4104
|
switch (_c.label) {
|
@@ -4354,9 +4146,9 @@ var PerpetualsClient = (function () {
|
|
4354
4146
|
refreshStakeInstruction = _c.sent();
|
4355
4147
|
return [2, refreshStakeInstruction];
|
4356
4148
|
case 2:
|
4357
|
-
|
4358
|
-
console.log("perpClient refreshStaking error:: ",
|
4359
|
-
throw
|
4149
|
+
err_10 = _c.sent();
|
4150
|
+
console.log("perpClient refreshStaking error:: ", err_10);
|
4151
|
+
throw err_10;
|
4360
4152
|
case 3: return [2];
|
4361
4153
|
}
|
4362
4154
|
});
|
@@ -4368,7 +4160,7 @@ var PerpetualsClient = (function () {
|
|
4368
4160
|
args_1[_i - 3] = arguments[_i];
|
4369
4161
|
}
|
4370
4162
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4371
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
4163
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
|
4372
4164
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4373
4165
|
return __generator(this, function (_b) {
|
4374
4166
|
switch (_b.label) {
|
@@ -4420,9 +4212,9 @@ var PerpetualsClient = (function () {
|
|
4420
4212
|
instructions.push(unstakeInstantInstruction);
|
4421
4213
|
return [3, 6];
|
4422
4214
|
case 5:
|
4423
|
-
|
4424
|
-
console.log("perpClient unstakeInstant error:: ",
|
4425
|
-
throw
|
4215
|
+
err_11 = _b.sent();
|
4216
|
+
console.log("perpClient unstakeInstant error:: ", err_11);
|
4217
|
+
throw err_11;
|
4426
4218
|
case 6: return [2, {
|
4427
4219
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4428
4220
|
additionalSigners: additionalSigners
|
@@ -4432,7 +4224,7 @@ var PerpetualsClient = (function () {
|
|
4432
4224
|
});
|
4433
4225
|
};
|
4434
4226
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4435
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4227
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
4436
4228
|
return __generator(this, function (_c) {
|
4437
4229
|
switch (_c.label) {
|
4438
4230
|
case 0:
|
@@ -4476,15 +4268,15 @@ var PerpetualsClient = (function () {
|
|
4476
4268
|
refreshStakeInstruction = _c.sent();
|
4477
4269
|
return [2, refreshStakeInstruction];
|
4478
4270
|
case 2:
|
4479
|
-
|
4480
|
-
console.log("perpClient refreshStaking error:: ",
|
4481
|
-
throw
|
4271
|
+
err_12 = _c.sent();
|
4272
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4273
|
+
throw err_12;
|
4482
4274
|
case 3: return [2];
|
4483
4275
|
}
|
4484
4276
|
});
|
4485
4277
|
}); };
|
4486
4278
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4487
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4279
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
4488
4280
|
return __generator(this, function (_a) {
|
4489
4281
|
switch (_a.label) {
|
4490
4282
|
case 0:
|
@@ -4518,9 +4310,9 @@ var PerpetualsClient = (function () {
|
|
4518
4310
|
instructions.push(unstakeRequestInstruction);
|
4519
4311
|
return [3, 4];
|
4520
4312
|
case 3:
|
4521
|
-
|
4522
|
-
console.log("perpClient unstakeRequest error:: ",
|
4523
|
-
throw
|
4313
|
+
err_13 = _a.sent();
|
4314
|
+
console.log("perpClient unstakeRequest error:: ", err_13);
|
4315
|
+
throw err_13;
|
4524
4316
|
case 4: return [2, {
|
4525
4317
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4526
4318
|
additionalSigners: additionalSigners
|
@@ -4534,7 +4326,7 @@ var PerpetualsClient = (function () {
|
|
4534
4326
|
args_1[_i - 1] = arguments[_i];
|
4535
4327
|
}
|
4536
4328
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4537
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4329
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
|
4538
4330
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
4539
4331
|
if (deactivated === void 0) { deactivated = true; }
|
4540
4332
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
@@ -4590,9 +4382,9 @@ var PerpetualsClient = (function () {
|
|
4590
4382
|
instructions.push(withdrawStakeInstruction);
|
4591
4383
|
return [3, 6];
|
4592
4384
|
case 5:
|
4593
|
-
|
4594
|
-
console.log("perpClient withdrawStake error:: ",
|
4595
|
-
throw
|
4385
|
+
err_14 = _b.sent();
|
4386
|
+
console.log("perpClient withdrawStake error:: ", err_14);
|
4387
|
+
throw err_14;
|
4596
4388
|
case 6: return [2, {
|
4597
4389
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4598
4390
|
additionalSigners: additionalSigners
|
@@ -4607,7 +4399,7 @@ var PerpetualsClient = (function () {
|
|
4607
4399
|
args_1[_i - 3] = arguments[_i];
|
4608
4400
|
}
|
4609
4401
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4610
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
4402
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
4611
4403
|
if (createUserATA === void 0) { createUserATA = true; }
|
4612
4404
|
return __generator(this, function (_b) {
|
4613
4405
|
switch (_b.label) {
|
@@ -4668,9 +4460,9 @@ var PerpetualsClient = (function () {
|
|
4668
4460
|
instructions.push(withdrawStakeInstruction);
|
4669
4461
|
return [3, 6];
|
4670
4462
|
case 5:
|
4671
|
-
|
4672
|
-
console.log("perpClient withdrawStake error:: ",
|
4673
|
-
throw
|
4463
|
+
err_15 = _b.sent();
|
4464
|
+
console.log("perpClient withdrawStake error:: ", err_15);
|
4465
|
+
throw err_15;
|
4674
4466
|
case 6: return [2, {
|
4675
4467
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4676
4468
|
additionalSigners: additionalSigners
|
@@ -4685,7 +4477,7 @@ var PerpetualsClient = (function () {
|
|
4685
4477
|
args_1[_i - 5] = arguments[_i];
|
4686
4478
|
}
|
4687
4479
|
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) {
|
4688
|
-
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,
|
4480
|
+
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;
|
4689
4481
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4690
4482
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4691
4483
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4813,8 +4605,8 @@ var PerpetualsClient = (function () {
|
|
4813
4605
|
instructions.push(addCompoundingLiquidity);
|
4814
4606
|
return [3, 10];
|
4815
4607
|
case 9:
|
4816
|
-
|
4817
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4608
|
+
err_16 = _f.sent();
|
4609
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
4818
4610
|
return [3, 10];
|
4819
4611
|
case 10: return [2, {
|
4820
4612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4830,7 +4622,7 @@ var PerpetualsClient = (function () {
|
|
4830
4622
|
args_1[_i - 5] = arguments[_i];
|
4831
4623
|
}
|
4832
4624
|
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) {
|
4833
|
-
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,
|
4625
|
+
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;
|
4834
4626
|
if (createUserATA === void 0) { createUserATA = true; }
|
4835
4627
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4836
4628
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4942,8 +4734,8 @@ var PerpetualsClient = (function () {
|
|
4942
4734
|
instructions.push(removeCompoundingLiquidity);
|
4943
4735
|
return [3, 8];
|
4944
4736
|
case 7:
|
4945
|
-
|
4946
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4737
|
+
err_17 = _f.sent();
|
4738
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
4947
4739
|
return [3, 8];
|
4948
4740
|
case 8: return [2, {
|
4949
4741
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4959,7 +4751,7 @@ var PerpetualsClient = (function () {
|
|
4959
4751
|
args_1[_i - 3] = arguments[_i];
|
4960
4752
|
}
|
4961
4753
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
4962
|
-
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,
|
4754
|
+
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;
|
4963
4755
|
if (createUserATA === void 0) { createUserATA = true; }
|
4964
4756
|
return __generator(this, function (_g) {
|
4965
4757
|
switch (_g.label) {
|
@@ -5057,8 +4849,8 @@ var PerpetualsClient = (function () {
|
|
5057
4849
|
instructions.push(migrateStake);
|
5058
4850
|
return [3, 8];
|
5059
4851
|
case 7:
|
5060
|
-
|
5061
|
-
console.log("perpClient migrateStake error:: ",
|
4852
|
+
err_18 = _g.sent();
|
4853
|
+
console.log("perpClient migrateStake error:: ", err_18);
|
5062
4854
|
return [3, 8];
|
5063
4855
|
case 8: return [2, {
|
5064
4856
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5069,7 +4861,7 @@ var PerpetualsClient = (function () {
|
|
5069
4861
|
});
|
5070
4862
|
};
|
5071
4863
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5072
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
4864
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
|
5073
4865
|
return __generator(this, function (_d) {
|
5074
4866
|
switch (_d.label) {
|
5075
4867
|
case 0:
|
@@ -5141,8 +4933,8 @@ var PerpetualsClient = (function () {
|
|
5141
4933
|
instructions.push(migrateFlp);
|
5142
4934
|
return [3, 4];
|
5143
4935
|
case 3:
|
5144
|
-
|
5145
|
-
console.log("perpClient migrateFlp error:: ",
|
4936
|
+
err_19 = _d.sent();
|
4937
|
+
console.log("perpClient migrateFlp error:: ", err_19);
|
5146
4938
|
return [3, 4];
|
5147
4939
|
case 4: return [2, {
|
5148
4940
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5157,7 +4949,7 @@ var PerpetualsClient = (function () {
|
|
5157
4949
|
args_1[_i - 1] = arguments[_i];
|
5158
4950
|
}
|
5159
4951
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5160
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee,
|
4952
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
|
5161
4953
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5162
4954
|
return __generator(this, function (_e) {
|
5163
4955
|
switch (_e.label) {
|
@@ -5215,8 +5007,8 @@ var PerpetualsClient = (function () {
|
|
5215
5007
|
instructions.push(compoundingFee);
|
5216
5008
|
return [3, 4];
|
5217
5009
|
case 3:
|
5218
|
-
|
5219
|
-
console.log("perpClient compoundingFee error:: ",
|
5010
|
+
err_20 = _e.sent();
|
5011
|
+
console.log("perpClient compoundingFee error:: ", err_20);
|
5220
5012
|
return [3, 4];
|
5221
5013
|
case 4: return [2, {
|
5222
5014
|
instructions: __spreadArray([], instructions, true),
|
@@ -5226,180 +5018,42 @@ var PerpetualsClient = (function () {
|
|
5226
5018
|
});
|
5227
5019
|
});
|
5228
5020
|
};
|
5229
|
-
this.
|
5230
|
-
var preInstructions, instructions, postInstructions, additionalSigners,
|
5231
|
-
return __generator(this, function (
|
5232
|
-
switch (
|
5021
|
+
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5022
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_21;
|
5023
|
+
return __generator(this, function (_a) {
|
5024
|
+
switch (_a.label) {
|
5233
5025
|
case 0:
|
5234
5026
|
preInstructions = [];
|
5235
5027
|
instructions = [];
|
5236
5028
|
postInstructions = [];
|
5237
5029
|
additionalSigners = [];
|
5238
|
-
|
5030
|
+
_a.label = 1;
|
5239
5031
|
case 1:
|
5240
|
-
|
5241
|
-
|
5242
|
-
|
5243
|
-
userTokenAccount = _b.sent();
|
5244
|
-
_a = createAta;
|
5245
|
-
if (!_a) return [3, 4];
|
5032
|
+
_a.trys.push([1, 4, , 5]);
|
5033
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5034
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
5246
5035
|
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5247
|
-
case
|
5248
|
-
|
5249
|
-
|
5250
|
-
case 4:
|
5251
|
-
if (_a) {
|
5252
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(owner, userTokenAccount, owner, poolConfig.tokenMint));
|
5036
|
+
case 2:
|
5037
|
+
if (!(_a.sent())) {
|
5038
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5253
5039
|
}
|
5254
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
|
5255
|
-
case 5:
|
5256
|
-
nftTokenAccount = _b.sent();
|
5257
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5258
|
-
Buffer.from("trading"),
|
5259
|
-
nftMint.toBuffer(),
|
5260
|
-
], this.programId)[0];
|
5261
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5262
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5263
|
-
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];
|
5264
|
-
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];
|
5265
5040
|
return [4, this.program.methods
|
5266
|
-
.
|
5041
|
+
.depositTokenStake({
|
5042
|
+
depositAmount: depositAmount
|
5043
|
+
})
|
5267
5044
|
.accounts({
|
5268
5045
|
owner: owner,
|
5269
|
-
|
5046
|
+
feePayer: feePayer,
|
5047
|
+
fundingTokenAccount: userTokenAccount,
|
5270
5048
|
perpetuals: this.perpetuals.publicKey,
|
5271
5049
|
tokenVault: poolConfig.tokenVault,
|
5272
5050
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5273
|
-
|
5274
|
-
collectionMetadata: collectionMetadata,
|
5275
|
-
edition: edition,
|
5276
|
-
tokenRecord: tokenRecord,
|
5277
|
-
tradingAccount: nftTradingAccount,
|
5278
|
-
transferAuthority: poolConfig.transferAuthority,
|
5279
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5280
|
-
nftMint: nftMint,
|
5281
|
-
nftTokenAccount: nftTokenAccount,
|
5051
|
+
tokenStakeAccount: tokenStakeAccount,
|
5282
5052
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5283
5053
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5284
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5285
5054
|
eventAuthority: this.eventAuthority.publicKey,
|
5286
5055
|
program: this.programId,
|
5287
|
-
|
5288
|
-
})
|
5289
|
-
.instruction()];
|
5290
|
-
case 6:
|
5291
|
-
burnAndClaimInstruction = _b.sent();
|
5292
|
-
instructions.push(burnAndClaimInstruction);
|
5293
|
-
return [3, 8];
|
5294
|
-
case 7:
|
5295
|
-
err_23 = _b.sent();
|
5296
|
-
console.log("perpClient burnAndClaimInstruction error:: ", err_23);
|
5297
|
-
throw err_23;
|
5298
|
-
case 8: return [2, {
|
5299
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5300
|
-
additionalSigners: additionalSigners
|
5301
|
-
}];
|
5302
|
-
}
|
5303
|
-
});
|
5304
|
-
}); };
|
5305
|
-
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5306
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_24;
|
5307
|
-
return __generator(this, function (_a) {
|
5308
|
-
switch (_a.label) {
|
5309
|
-
case 0:
|
5310
|
-
preInstructions = [];
|
5311
|
-
instructions = [];
|
5312
|
-
postInstructions = [];
|
5313
|
-
additionalSigners = [];
|
5314
|
-
_a.label = 1;
|
5315
|
-
case 1:
|
5316
|
-
_a.trys.push([1, 3, , 4]);
|
5317
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5318
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
5319
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5320
|
-
Buffer.from("trading"),
|
5321
|
-
nftMint.toBuffer(),
|
5322
|
-
], this.programId)[0];
|
5323
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5324
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5325
|
-
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];
|
5326
|
-
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];
|
5327
|
-
return [4, this.program.methods
|
5328
|
-
.burnAndStake({})
|
5329
|
-
.accounts({
|
5330
|
-
owner: owner,
|
5331
|
-
feePayer: feePayer,
|
5332
|
-
perpetuals: this.perpetuals.publicKey,
|
5333
|
-
tokenVault: poolConfig.tokenVault,
|
5334
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5335
|
-
tokenStakeAccount: tokenStakeAccount,
|
5336
|
-
metadataAccount: metadataAccount,
|
5337
|
-
collectionMetadata: collectionMetadata,
|
5338
|
-
edition: edition,
|
5339
|
-
tokenRecord: tokenRecord,
|
5340
|
-
tradingAccount: nftTradingAccount,
|
5341
|
-
transferAuthority: poolConfig.transferAuthority,
|
5342
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5343
|
-
nftMint: nftMint,
|
5344
|
-
nftTokenAccount: nftTokenAccount,
|
5345
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5346
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5347
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5348
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5349
|
-
program: this.programId
|
5350
|
-
})
|
5351
|
-
.instruction()];
|
5352
|
-
case 2:
|
5353
|
-
burnAndStakeInstruction = _a.sent();
|
5354
|
-
instructions.push(burnAndStakeInstruction);
|
5355
|
-
return [3, 4];
|
5356
|
-
case 3:
|
5357
|
-
err_24 = _a.sent();
|
5358
|
-
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
5359
|
-
throw err_24;
|
5360
|
-
case 4: return [2, {
|
5361
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5362
|
-
additionalSigners: additionalSigners
|
5363
|
-
}];
|
5364
|
-
}
|
5365
|
-
});
|
5366
|
-
}); };
|
5367
|
-
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5368
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
5369
|
-
return __generator(this, function (_a) {
|
5370
|
-
switch (_a.label) {
|
5371
|
-
case 0:
|
5372
|
-
preInstructions = [];
|
5373
|
-
instructions = [];
|
5374
|
-
postInstructions = [];
|
5375
|
-
additionalSigners = [];
|
5376
|
-
_a.label = 1;
|
5377
|
-
case 1:
|
5378
|
-
_a.trys.push([1, 4, , 5]);
|
5379
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5380
|
-
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
5381
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5382
|
-
case 2:
|
5383
|
-
if (!(_a.sent())) {
|
5384
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5385
|
-
}
|
5386
|
-
return [4, this.program.methods
|
5387
|
-
.depositTokenStake({
|
5388
|
-
depositAmount: depositAmount
|
5389
|
-
})
|
5390
|
-
.accounts({
|
5391
|
-
owner: owner,
|
5392
|
-
feePayer: feePayer,
|
5393
|
-
fundingTokenAccount: userTokenAccount,
|
5394
|
-
perpetuals: this.perpetuals.publicKey,
|
5395
|
-
tokenVault: poolConfig.tokenVault,
|
5396
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5397
|
-
tokenStakeAccount: tokenStakeAccount,
|
5398
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5399
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5400
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5401
|
-
program: this.programId,
|
5402
|
-
tokenMint: poolConfig.tokenMint,
|
5056
|
+
tokenMint: poolConfig.tokenMint,
|
5403
5057
|
})
|
5404
5058
|
.instruction()];
|
5405
5059
|
case 3:
|
@@ -5407,9 +5061,9 @@ var PerpetualsClient = (function () {
|
|
5407
5061
|
instructions.push(depositTokenStakeInstruction);
|
5408
5062
|
return [3, 5];
|
5409
5063
|
case 4:
|
5410
|
-
|
5411
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5412
|
-
throw
|
5064
|
+
err_21 = _a.sent();
|
5065
|
+
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
5066
|
+
throw err_21;
|
5413
5067
|
case 5: return [2, {
|
5414
5068
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5415
5069
|
additionalSigners: additionalSigners
|
@@ -5418,7 +5072,7 @@ var PerpetualsClient = (function () {
|
|
5418
5072
|
});
|
5419
5073
|
}); };
|
5420
5074
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5421
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5075
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
|
5422
5076
|
return __generator(this, function (_a) {
|
5423
5077
|
switch (_a.label) {
|
5424
5078
|
case 0:
|
@@ -5447,9 +5101,9 @@ var PerpetualsClient = (function () {
|
|
5447
5101
|
instructions.push(unstakeTokenRequestInstruction);
|
5448
5102
|
return [3, 4];
|
5449
5103
|
case 3:
|
5450
|
-
|
5451
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5452
|
-
throw
|
5104
|
+
err_22 = _a.sent();
|
5105
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
|
5106
|
+
throw err_22;
|
5453
5107
|
case 4: return [2, {
|
5454
5108
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5455
5109
|
additionalSigners: additionalSigners
|
@@ -5458,7 +5112,7 @@ var PerpetualsClient = (function () {
|
|
5458
5112
|
});
|
5459
5113
|
}); };
|
5460
5114
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5461
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5115
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
|
5462
5116
|
return __generator(this, function (_a) {
|
5463
5117
|
switch (_a.label) {
|
5464
5118
|
case 0:
|
@@ -5499,9 +5153,9 @@ var PerpetualsClient = (function () {
|
|
5499
5153
|
instructions.push(unstakeTokenInstantInstruction);
|
5500
5154
|
return [3, 5];
|
5501
5155
|
case 4:
|
5502
|
-
|
5503
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5504
|
-
throw
|
5156
|
+
err_23 = _a.sent();
|
5157
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
5158
|
+
throw err_23;
|
5505
5159
|
case 5: return [2, {
|
5506
5160
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5507
5161
|
additionalSigners: additionalSigners
|
@@ -5510,7 +5164,7 @@ var PerpetualsClient = (function () {
|
|
5510
5164
|
});
|
5511
5165
|
}); };
|
5512
5166
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5513
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5167
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
|
5514
5168
|
return __generator(this, function (_a) {
|
5515
5169
|
switch (_a.label) {
|
5516
5170
|
case 0:
|
@@ -5551,9 +5205,9 @@ var PerpetualsClient = (function () {
|
|
5551
5205
|
instructions.push(withdrawTokenInstruction);
|
5552
5206
|
return [3, 5];
|
5553
5207
|
case 4:
|
5554
|
-
|
5555
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5556
|
-
throw
|
5208
|
+
err_24 = _a.sent();
|
5209
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
5210
|
+
throw err_24;
|
5557
5211
|
case 5: return [2, {
|
5558
5212
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5559
5213
|
additionalSigners: additionalSigners
|
@@ -5562,7 +5216,7 @@ var PerpetualsClient = (function () {
|
|
5562
5216
|
});
|
5563
5217
|
}); };
|
5564
5218
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5565
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5219
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
|
5566
5220
|
return __generator(this, function (_a) {
|
5567
5221
|
switch (_a.label) {
|
5568
5222
|
case 0:
|
@@ -5591,9 +5245,9 @@ var PerpetualsClient = (function () {
|
|
5591
5245
|
instructions.push(cancelUnstakeRequestInstruction);
|
5592
5246
|
return [3, 4];
|
5593
5247
|
case 3:
|
5594
|
-
|
5595
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5596
|
-
throw
|
5248
|
+
err_25 = _a.sent();
|
5249
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
|
5250
|
+
throw err_25;
|
5597
5251
|
case 4: return [2, {
|
5598
5252
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5599
5253
|
additionalSigners: additionalSigners
|
@@ -5607,7 +5261,7 @@ var PerpetualsClient = (function () {
|
|
5607
5261
|
args_1[_i - 2] = arguments[_i];
|
5608
5262
|
}
|
5609
5263
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5610
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
5264
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
5611
5265
|
if (createUserATA === void 0) { createUserATA = true; }
|
5612
5266
|
return __generator(this, function (_b) {
|
5613
5267
|
switch (_b.label) {
|
@@ -5653,9 +5307,9 @@ var PerpetualsClient = (function () {
|
|
5653
5307
|
instructions.push(collectTokenRewardInstruction);
|
5654
5308
|
return [3, 6];
|
5655
5309
|
case 5:
|
5656
|
-
|
5657
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5658
|
-
throw
|
5310
|
+
err_26 = _b.sent();
|
5311
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
5312
|
+
throw err_26;
|
5659
5313
|
case 6: return [2, {
|
5660
5314
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5661
5315
|
additionalSigners: additionalSigners
|
@@ -5670,7 +5324,7 @@ var PerpetualsClient = (function () {
|
|
5670
5324
|
args_1[_i - 3] = arguments[_i];
|
5671
5325
|
}
|
5672
5326
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5673
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
5327
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
|
5674
5328
|
if (createUserATA === void 0) { createUserATA = true; }
|
5675
5329
|
return __generator(this, function (_b) {
|
5676
5330
|
switch (_b.label) {
|
@@ -5717,250 +5371,9 @@ var PerpetualsClient = (function () {
|
|
5717
5371
|
instructions.push(collectRevenueInstruction);
|
5718
5372
|
return [3, 6];
|
5719
5373
|
case 5:
|
5720
|
-
|
5721
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5722
|
-
throw
|
5723
|
-
case 6: return [2, {
|
5724
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5725
|
-
additionalSigners: additionalSigners
|
5726
|
-
}];
|
5727
|
-
}
|
5728
|
-
});
|
5729
|
-
});
|
5730
|
-
};
|
5731
|
-
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5732
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
|
5733
|
-
return __generator(this, function (_a) {
|
5734
|
-
switch (_a.label) {
|
5735
|
-
case 0:
|
5736
|
-
publicKey = this.provider.wallet.publicKey;
|
5737
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5738
|
-
instructions = [];
|
5739
|
-
additionalSigners = [];
|
5740
|
-
_a.label = 1;
|
5741
|
-
case 1:
|
5742
|
-
_a.trys.push([1, 3, , 4]);
|
5743
|
-
fbNftProgramData = web3_js_1.PublicKey.findProgramAddressSync([this.programFbnftReward.programId.toBuffer()], new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"))[0];
|
5744
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5745
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5746
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5747
|
-
return [4, this.programFbnftReward.methods
|
5748
|
-
.initRewardVault({
|
5749
|
-
nftCount: nftCount
|
5750
|
-
})
|
5751
|
-
.accounts({
|
5752
|
-
admin: publicKey,
|
5753
|
-
transferAuthority: nftTransferAuthority,
|
5754
|
-
rewardVault: rewardVault,
|
5755
|
-
rewardMint: rewardCustodyMint,
|
5756
|
-
rewardTokenAccount: rewardTokenAccount,
|
5757
|
-
collectionMint: collectionMint,
|
5758
|
-
programData: fbNftProgramData,
|
5759
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5760
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5761
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
5762
|
-
})
|
5763
|
-
.instruction()];
|
5764
|
-
case 2:
|
5765
|
-
initRewardVault = _a.sent();
|
5766
|
-
instructions.push(initRewardVault);
|
5767
|
-
return [3, 4];
|
5768
|
-
case 3:
|
5769
|
-
err_32 = _a.sent();
|
5770
|
-
console.log("perpClient InitRewardVault error:: ", err_32);
|
5771
|
-
throw err_32;
|
5772
|
-
case 4: return [2, {
|
5773
|
-
instructions: __spreadArray([], instructions, true),
|
5774
|
-
additionalSigners: additionalSigners
|
5775
|
-
}];
|
5776
|
-
}
|
5777
|
-
});
|
5778
|
-
}); };
|
5779
|
-
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5780
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
|
5781
|
-
return __generator(this, function (_a) {
|
5782
|
-
switch (_a.label) {
|
5783
|
-
case 0:
|
5784
|
-
publicKey = this.provider.wallet.publicKey;
|
5785
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5786
|
-
instructions = [];
|
5787
|
-
additionalSigners = [];
|
5788
|
-
_a.label = 1;
|
5789
|
-
case 1:
|
5790
|
-
_a.trys.push([1, 3, , 4]);
|
5791
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5792
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5793
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5794
|
-
return [4, this.programFbnftReward.methods
|
5795
|
-
.distributeRewards({
|
5796
|
-
rewardAmount: rewardAmount
|
5797
|
-
})
|
5798
|
-
.accounts({
|
5799
|
-
admin: publicKey,
|
5800
|
-
fundingAccount: fundingAccount,
|
5801
|
-
rewardVault: rewardVault,
|
5802
|
-
rewardTokenAccount: rewardTokenAccount,
|
5803
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5804
|
-
})
|
5805
|
-
.instruction()];
|
5806
|
-
case 2:
|
5807
|
-
distributeReward = _a.sent();
|
5808
|
-
instructions.push(distributeReward);
|
5809
|
-
return [3, 4];
|
5810
|
-
case 3:
|
5811
|
-
err_33 = _a.sent();
|
5812
|
-
console.log("perpClient distributeReward error:: ", err_33);
|
5813
|
-
throw err_33;
|
5814
|
-
case 4: return [2, {
|
5815
|
-
instructions: __spreadArray([], instructions, true),
|
5816
|
-
additionalSigners: additionalSigners
|
5817
|
-
}];
|
5818
|
-
}
|
5819
|
-
});
|
5820
|
-
}); };
|
5821
|
-
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5822
|
-
var args_1 = [];
|
5823
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
5824
|
-
args_1[_i - 3] = arguments[_i];
|
5825
|
-
}
|
5826
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5827
|
-
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
|
5828
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5829
|
-
return __generator(this, function (_b) {
|
5830
|
-
switch (_b.label) {
|
5831
|
-
case 0:
|
5832
|
-
publicKey = this.provider.wallet.publicKey;
|
5833
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5834
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5835
|
-
instructions = [];
|
5836
|
-
additionalSigners = [];
|
5837
|
-
_b.label = 1;
|
5838
|
-
case 1:
|
5839
|
-
_b.trys.push([1, 5, , 6]);
|
5840
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5841
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5842
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5843
|
-
_a = createUserATA;
|
5844
|
-
if (!_a) return [3, 3];
|
5845
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5846
|
-
case 2:
|
5847
|
-
_a = !(_b.sent());
|
5848
|
-
_b.label = 3;
|
5849
|
-
case 3:
|
5850
|
-
if (_a) {
|
5851
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5852
|
-
}
|
5853
|
-
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5854
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5855
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5856
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5857
|
-
return [4, this.programFbnftReward.methods
|
5858
|
-
.collectReward()
|
5859
|
-
.accounts({
|
5860
|
-
owner: publicKey,
|
5861
|
-
feePayer: publicKey,
|
5862
|
-
nftMint: nftMint,
|
5863
|
-
nftTokenAccount: nftTokenAccount,
|
5864
|
-
metadataAccount: metadataAccount,
|
5865
|
-
receivingAccount: receivingTokenAccount,
|
5866
|
-
rewardRecord: rewardRecord,
|
5867
|
-
rewardVault: rewardVault,
|
5868
|
-
rewardTokenAccount: rewardTokenAccount,
|
5869
|
-
transferAuthority: nftTransferAuthority,
|
5870
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5871
|
-
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
5872
|
-
})
|
5873
|
-
.instruction()];
|
5874
|
-
case 4:
|
5875
|
-
collectNftReward = _b.sent();
|
5876
|
-
instructions.push(collectNftReward);
|
5877
|
-
return [3, 6];
|
5878
|
-
case 5:
|
5879
|
-
err_34 = _b.sent();
|
5880
|
-
throw err_34;
|
5881
|
-
case 6: return [2, {
|
5882
|
-
instructions: __spreadArray([], instructions, true),
|
5883
|
-
additionalSigners: additionalSigners
|
5884
|
-
}];
|
5885
|
-
}
|
5886
|
-
});
|
5887
|
-
});
|
5888
|
-
};
|
5889
|
-
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
5890
|
-
var args_1 = [];
|
5891
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
5892
|
-
args_1[_i - 2] = arguments[_i];
|
5893
|
-
}
|
5894
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5895
|
-
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
|
5896
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5897
|
-
return __generator(this, function (_b) {
|
5898
|
-
switch (_b.label) {
|
5899
|
-
case 0:
|
5900
|
-
publicKey = this.provider.wallet.publicKey;
|
5901
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5902
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5903
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5904
|
-
preInstructions = [];
|
5905
|
-
instructions = [];
|
5906
|
-
postInstructions = [];
|
5907
|
-
additionalSigners = [];
|
5908
|
-
_b.label = 1;
|
5909
|
-
case 1:
|
5910
|
-
_b.trys.push([1, 5, , 6]);
|
5911
|
-
pool = poolConfig.poolAddress;
|
5912
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5913
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5914
|
-
_a = createUserATA;
|
5915
|
-
if (!_a) return [3, 3];
|
5916
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5917
|
-
case 2:
|
5918
|
-
_a = !(_b.sent());
|
5919
|
-
_b.label = 3;
|
5920
|
-
case 3:
|
5921
|
-
if (_a) {
|
5922
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5923
|
-
}
|
5924
|
-
tradingAccount = [];
|
5925
|
-
if (nftTradingAccount) {
|
5926
|
-
tradingAccount.push({
|
5927
|
-
pubkey: nftTradingAccount,
|
5928
|
-
isSigner: false,
|
5929
|
-
isWritable: true,
|
5930
|
-
});
|
5931
|
-
}
|
5932
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5933
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5934
|
-
return [4, this.programPerpComposability.methods
|
5935
|
-
.collectAndDistributeFee()
|
5936
|
-
.accounts({
|
5937
|
-
perpProgram: this.programId,
|
5938
|
-
owner: publicKey,
|
5939
|
-
receivingTokenAccount: receivingTokenAccount,
|
5940
|
-
transferAuthority: poolConfig.transferAuthority,
|
5941
|
-
perpetuals: this.perpetuals.publicKey,
|
5942
|
-
pool: pool,
|
5943
|
-
feeCustody: rewardCustodyConfig.custodyAccount,
|
5944
|
-
flpStakeAccount: flpStakeAccount,
|
5945
|
-
feeCustodyTokenAccount: rewardCustodyConfig.tokenAccount,
|
5946
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5947
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5948
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5949
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5950
|
-
fbnftRewardsProgram: this.programFbnftReward.programId,
|
5951
|
-
rewardVault: rewardVault,
|
5952
|
-
rewardTokenAccount: rewardTokenAccount
|
5953
|
-
})
|
5954
|
-
.remainingAccounts(tradingAccount)
|
5955
|
-
.instruction()];
|
5956
|
-
case 4:
|
5957
|
-
withdrawStakeInstruction = _b.sent();
|
5958
|
-
instructions.push(withdrawStakeInstruction);
|
5959
|
-
return [3, 6];
|
5960
|
-
case 5:
|
5961
|
-
err_35 = _b.sent();
|
5962
|
-
console.log("perpClient withdrawStake error:: ", err_35);
|
5963
|
-
throw err_35;
|
5374
|
+
err_27 = _b.sent();
|
5375
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
5376
|
+
throw err_27;
|
5964
5377
|
case 6: return [2, {
|
5965
5378
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5966
5379
|
additionalSigners: additionalSigners
|
@@ -5975,7 +5388,7 @@ var PerpetualsClient = (function () {
|
|
5975
5388
|
args_1[_i - 11] = arguments[_i];
|
5976
5389
|
}
|
5977
5390
|
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) {
|
5978
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder,
|
5391
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_28;
|
5979
5392
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
5980
5393
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5981
5394
|
return __generator(this, function (_c) {
|
@@ -6081,9 +5494,9 @@ var PerpetualsClient = (function () {
|
|
6081
5494
|
instructions.push(placeLimitOrder);
|
6082
5495
|
return [3, 10];
|
6083
5496
|
case 9:
|
6084
|
-
|
6085
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6086
|
-
throw
|
5497
|
+
err_28 = _c.sent();
|
5498
|
+
console.log("perpClient placeLimitOrder error:: ", err_28);
|
5499
|
+
throw err_28;
|
6087
5500
|
case 10: return [2, {
|
6088
5501
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6089
5502
|
additionalSigners: additionalSigners
|
@@ -6098,7 +5511,7 @@ var PerpetualsClient = (function () {
|
|
6098
5511
|
args_1[_i - 11] = arguments[_i];
|
6099
5512
|
}
|
6100
5513
|
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) {
|
6101
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder,
|
5514
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_29;
|
6102
5515
|
if (createUserATA === void 0) { createUserATA = true; }
|
6103
5516
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6104
5517
|
return __generator(this, function (_b) {
|
@@ -6189,9 +5602,9 @@ var PerpetualsClient = (function () {
|
|
6189
5602
|
instructions.push(editLimitOrder);
|
6190
5603
|
return [3, 8];
|
6191
5604
|
case 7:
|
6192
|
-
|
6193
|
-
console.log("perpClient editLimitOrder error:: ",
|
6194
|
-
throw
|
5605
|
+
err_29 = _b.sent();
|
5606
|
+
console.log("perpClient editLimitOrder error:: ", err_29);
|
5607
|
+
throw err_29;
|
6195
5608
|
case 8: return [2, {
|
6196
5609
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6197
5610
|
additionalSigners: additionalSigners
|
@@ -6205,11 +5618,10 @@ var PerpetualsClient = (function () {
|
|
6205
5618
|
for (var _i = 7; _i < arguments.length; _i++) {
|
6206
5619
|
args_1[_i - 7] = arguments[_i];
|
6207
5620
|
}
|
6208
|
-
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
|
6209
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder,
|
5621
|
+
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) {
|
5622
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_30;
|
6210
5623
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6211
5624
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6212
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6213
5625
|
return __generator(this, function (_a) {
|
6214
5626
|
switch (_a.label) {
|
6215
5627
|
case 0:
|
@@ -6252,16 +5664,16 @@ var PerpetualsClient = (function () {
|
|
6252
5664
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6253
5665
|
collateralMint: collateralCustodyConfig.mintKey,
|
6254
5666
|
})
|
6255
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
5667
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6256
5668
|
.instruction()];
|
6257
5669
|
case 2:
|
6258
5670
|
executeLimitOrder = _a.sent();
|
6259
5671
|
instructions.push(executeLimitOrder);
|
6260
5672
|
return [3, 4];
|
6261
5673
|
case 3:
|
6262
|
-
|
6263
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6264
|
-
throw
|
5674
|
+
err_30 = _a.sent();
|
5675
|
+
console.log("perpClient executeLimitOrder error:: ", err_30);
|
5676
|
+
throw err_30;
|
6265
5677
|
case 4: return [2, {
|
6266
5678
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6267
5679
|
additionalSigners: additionalSigners
|
@@ -6275,11 +5687,10 @@ var PerpetualsClient = (function () {
|
|
6275
5687
|
for (var _i = 8; _i < arguments.length; _i++) {
|
6276
5688
|
args_1[_i - 8] = arguments[_i];
|
6277
5689
|
}
|
6278
|
-
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
|
6279
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap,
|
5690
|
+
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) {
|
5691
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_31;
|
6280
5692
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6281
5693
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6282
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6283
5694
|
return __generator(this, function (_a) {
|
6284
5695
|
switch (_a.label) {
|
6285
5696
|
case 0:
|
@@ -6325,16 +5736,16 @@ var PerpetualsClient = (function () {
|
|
6325
5736
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6326
5737
|
collateralMint: collateralCustodyConfig.mintKey,
|
6327
5738
|
})
|
6328
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
5739
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6329
5740
|
.instruction()];
|
6330
5741
|
case 2:
|
6331
5742
|
executeLimitWithSwap = _a.sent();
|
6332
5743
|
instructions.push(executeLimitWithSwap);
|
6333
5744
|
return [3, 4];
|
6334
5745
|
case 3:
|
6335
|
-
|
6336
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6337
|
-
throw
|
5746
|
+
err_31 = _a.sent();
|
5747
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_31);
|
5748
|
+
throw err_31;
|
6338
5749
|
case 4: return [2, {
|
6339
5750
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6340
5751
|
additionalSigners: additionalSigners
|
@@ -6344,7 +5755,7 @@ var PerpetualsClient = (function () {
|
|
6344
5755
|
});
|
6345
5756
|
};
|
6346
5757
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6347
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
5758
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_32;
|
6348
5759
|
return __generator(this, function (_a) {
|
6349
5760
|
switch (_a.label) {
|
6350
5761
|
case 0:
|
@@ -6392,9 +5803,9 @@ var PerpetualsClient = (function () {
|
|
6392
5803
|
instructions.push(placeTriggerOrder);
|
6393
5804
|
return [3, 4];
|
6394
5805
|
case 3:
|
6395
|
-
|
6396
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6397
|
-
throw
|
5806
|
+
err_32 = _a.sent();
|
5807
|
+
console.log("perpClient placeTriggerOrder error:: ", err_32);
|
5808
|
+
throw err_32;
|
6398
5809
|
case 4: return [2, {
|
6399
5810
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6400
5811
|
additionalSigners: additionalSigners
|
@@ -6403,7 +5814,7 @@ var PerpetualsClient = (function () {
|
|
6403
5814
|
});
|
6404
5815
|
}); };
|
6405
5816
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6406
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
5817
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_33;
|
6407
5818
|
return __generator(this, function (_a) {
|
6408
5819
|
switch (_a.label) {
|
6409
5820
|
case 0:
|
@@ -6450,9 +5861,9 @@ var PerpetualsClient = (function () {
|
|
6450
5861
|
instructions.push(editTriggerOrder);
|
6451
5862
|
return [3, 4];
|
6452
5863
|
case 3:
|
6453
|
-
|
6454
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6455
|
-
throw
|
5864
|
+
err_33 = _a.sent();
|
5865
|
+
console.log("perpClient editTriggerOrder error:: ", err_33);
|
5866
|
+
throw err_33;
|
6456
5867
|
case 4: return [2, {
|
6457
5868
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6458
5869
|
additionalSigners: additionalSigners
|
@@ -6461,7 +5872,7 @@ var PerpetualsClient = (function () {
|
|
6461
5872
|
});
|
6462
5873
|
}); };
|
6463
5874
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6464
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
5875
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_34;
|
6465
5876
|
return __generator(this, function (_a) {
|
6466
5877
|
switch (_a.label) {
|
6467
5878
|
case 0:
|
@@ -6494,9 +5905,9 @@ var PerpetualsClient = (function () {
|
|
6494
5905
|
instructions.push(cancelTriggerOrder);
|
6495
5906
|
return [3, 4];
|
6496
5907
|
case 3:
|
6497
|
-
|
6498
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6499
|
-
throw
|
5908
|
+
err_34 = _a.sent();
|
5909
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_34);
|
5910
|
+
throw err_34;
|
6500
5911
|
case 4: return [2, {
|
6501
5912
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6502
5913
|
additionalSigners: additionalSigners
|
@@ -6505,7 +5916,7 @@ var PerpetualsClient = (function () {
|
|
6505
5916
|
});
|
6506
5917
|
}); };
|
6507
5918
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6508
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
5919
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_35;
|
6509
5920
|
return __generator(this, function (_a) {
|
6510
5921
|
switch (_a.label) {
|
6511
5922
|
case 0:
|
@@ -6536,9 +5947,9 @@ var PerpetualsClient = (function () {
|
|
6536
5947
|
instructions.push(cancelAllTriggerOrders);
|
6537
5948
|
return [3, 4];
|
6538
5949
|
case 3:
|
6539
|
-
|
6540
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6541
|
-
throw
|
5950
|
+
err_35 = _a.sent();
|
5951
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_35);
|
5952
|
+
throw err_35;
|
6542
5953
|
case 4: return [2, {
|
6543
5954
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6544
5955
|
additionalSigners: additionalSigners
|
@@ -6551,13 +5962,12 @@ var PerpetualsClient = (function () {
|
|
6551
5962
|
for (var _i = 9; _i < arguments.length; _i++) {
|
6552
5963
|
args_1[_i - 9] = arguments[_i];
|
6553
5964
|
}
|
6554
|
-
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
|
6555
|
-
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,
|
5965
|
+
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) {
|
5966
|
+
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_36;
|
6556
5967
|
if (createUserATA === void 0) { createUserATA = true; }
|
6557
5968
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6558
5969
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6559
5970
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6560
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6561
5971
|
return __generator(this, function (_e) {
|
6562
5972
|
switch (_e.label) {
|
6563
5973
|
case 0:
|
@@ -6652,16 +6062,16 @@ var PerpetualsClient = (function () {
|
|
6652
6062
|
collateralMint: collateralCustodyConfig.mintKey,
|
6653
6063
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
6654
6064
|
})
|
6655
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
6065
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6656
6066
|
.instruction()];
|
6657
6067
|
case 8:
|
6658
6068
|
executeTriggerWithSwap = _e.sent();
|
6659
6069
|
instructions.push(executeTriggerWithSwap);
|
6660
6070
|
return [3, 10];
|
6661
6071
|
case 9:
|
6662
|
-
|
6663
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6664
|
-
throw
|
6072
|
+
err_36 = _e.sent();
|
6073
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_36);
|
6074
|
+
throw err_36;
|
6665
6075
|
case 10: return [2, {
|
6666
6076
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6667
6077
|
additionalSigners: additionalSigners
|
@@ -6675,13 +6085,12 @@ var PerpetualsClient = (function () {
|
|
6675
6085
|
for (var _i = 8; _i < arguments.length; _i++) {
|
6676
6086
|
args_1[_i - 8] = arguments[_i];
|
6677
6087
|
}
|
6678
|
-
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
|
6679
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder,
|
6088
|
+
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) {
|
6089
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_37;
|
6680
6090
|
if (createUserATA === void 0) { createUserATA = true; }
|
6681
6091
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6682
6092
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6683
6093
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6684
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6685
6094
|
return __generator(this, function (_b) {
|
6686
6095
|
switch (_b.label) {
|
6687
6096
|
case 0:
|
@@ -6741,16 +6150,16 @@ var PerpetualsClient = (function () {
|
|
6741
6150
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6742
6151
|
receivingMint: collateralCustodyConfig.mintKey
|
6743
6152
|
})
|
6744
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
6153
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6745
6154
|
.instruction()];
|
6746
6155
|
case 6:
|
6747
6156
|
executeTriggerOrder = _b.sent();
|
6748
6157
|
instructions.push(executeTriggerOrder);
|
6749
6158
|
return [3, 8];
|
6750
6159
|
case 7:
|
6751
|
-
|
6752
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
6753
|
-
throw
|
6160
|
+
err_37 = _b.sent();
|
6161
|
+
console.log("perpClient executeTriggerOrder error:: ", err_37);
|
6162
|
+
throw err_37;
|
6754
6163
|
case 8: return [2, {
|
6755
6164
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6756
6165
|
additionalSigners: additionalSigners
|
@@ -6765,7 +6174,7 @@ var PerpetualsClient = (function () {
|
|
6765
6174
|
args_1[_i - 5] = arguments[_i];
|
6766
6175
|
}
|
6767
6176
|
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) {
|
6768
|
-
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,
|
6177
|
+
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_38;
|
6769
6178
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
6770
6179
|
if (createUserATA === void 0) { createUserATA = true; }
|
6771
6180
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
@@ -6970,9 +6379,9 @@ var PerpetualsClient = (function () {
|
|
6970
6379
|
}
|
6971
6380
|
return [3, 20];
|
6972
6381
|
case 19:
|
6973
|
-
|
6974
|
-
console.error("perpClient Swap error:: ",
|
6975
|
-
throw
|
6382
|
+
err_38 = _g.sent();
|
6383
|
+
console.error("perpClient Swap error:: ", err_38);
|
6384
|
+
throw err_38;
|
6976
6385
|
case 20: return [2, {
|
6977
6386
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6978
6387
|
additionalSigners: additionalSigners
|
@@ -6982,7 +6391,7 @@ var PerpetualsClient = (function () {
|
|
6982
6391
|
});
|
6983
6392
|
};
|
6984
6393
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6985
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx,
|
6394
|
+
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_39;
|
6986
6395
|
return __generator(this, function (_b) {
|
6987
6396
|
switch (_b.label) {
|
6988
6397
|
case 0:
|
@@ -7038,9 +6447,9 @@ var PerpetualsClient = (function () {
|
|
7038
6447
|
instructions.push(inx);
|
7039
6448
|
return [3, 4];
|
7040
6449
|
case 3:
|
7041
|
-
|
7042
|
-
console.error("perpClient Swap error:: ",
|
7043
|
-
throw
|
6450
|
+
err_39 = _b.sent();
|
6451
|
+
console.error("perpClient Swap error:: ", err_39);
|
6452
|
+
throw err_39;
|
7044
6453
|
case 4: return [2, {
|
7045
6454
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7046
6455
|
additionalSigners: additionalSigners
|
@@ -7049,7 +6458,7 @@ var PerpetualsClient = (function () {
|
|
7049
6458
|
});
|
7050
6459
|
}); };
|
7051
6460
|
this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7052
|
-
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction,
|
6461
|
+
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_40;
|
7053
6462
|
return __generator(this, function (_d) {
|
7054
6463
|
switch (_d.label) {
|
7055
6464
|
case 0:
|
@@ -7097,9 +6506,9 @@ var PerpetualsClient = (function () {
|
|
7097
6506
|
instructions.push(setLpTokenPriceInstruction);
|
7098
6507
|
return [3, 4];
|
7099
6508
|
case 3:
|
7100
|
-
|
7101
|
-
console.log("perpClient setLpTokenPriceInstruction error:: ",
|
7102
|
-
throw
|
6509
|
+
err_40 = _d.sent();
|
6510
|
+
console.log("perpClient setLpTokenPriceInstruction error:: ", err_40);
|
6511
|
+
throw err_40;
|
7103
6512
|
case 4: return [2, {
|
7104
6513
|
instructions: __spreadArray([], instructions, true),
|
7105
6514
|
additionalSigners: additionalSigners
|
@@ -7147,7 +6556,7 @@ var PerpetualsClient = (function () {
|
|
7147
6556
|
});
|
7148
6557
|
}); };
|
7149
6558
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
7150
|
-
var adminMetas, _i, admins_2, admin,
|
6559
|
+
var adminMetas, _i, admins_2, admin, err_41;
|
7151
6560
|
return __generator(this, function (_a) {
|
7152
6561
|
switch (_a.label) {
|
7153
6562
|
case 0:
|
@@ -7177,11 +6586,11 @@ var PerpetualsClient = (function () {
|
|
7177
6586
|
_a.sent();
|
7178
6587
|
return [3, 4];
|
7179
6588
|
case 3:
|
7180
|
-
|
6589
|
+
err_41 = _a.sent();
|
7181
6590
|
if (this.printErrors) {
|
7182
|
-
console.error("setAdminSigners err:",
|
6591
|
+
console.error("setAdminSigners err:", err_41);
|
7183
6592
|
}
|
7184
|
-
throw
|
6593
|
+
throw err_41;
|
7185
6594
|
case 4: return [2];
|
7186
6595
|
}
|
7187
6596
|
});
|
@@ -7370,7 +6779,7 @@ var PerpetualsClient = (function () {
|
|
7370
6779
|
});
|
7371
6780
|
}); };
|
7372
6781
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7373
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
6782
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_42;
|
7374
6783
|
return __generator(this, function (_a) {
|
7375
6784
|
switch (_a.label) {
|
7376
6785
|
case 0:
|
@@ -7403,9 +6812,9 @@ var PerpetualsClient = (function () {
|
|
7403
6812
|
instructions.push(withdrawFeesIx);
|
7404
6813
|
return [3, 5];
|
7405
6814
|
case 4:
|
7406
|
-
|
7407
|
-
console.log("perpClient setPool error:: ",
|
7408
|
-
throw
|
6815
|
+
err_42 = _a.sent();
|
6816
|
+
console.log("perpClient setPool error:: ", err_42);
|
6817
|
+
throw err_42;
|
7409
6818
|
case 5: return [2, {
|
7410
6819
|
instructions: __spreadArray([], instructions, true),
|
7411
6820
|
additionalSigners: additionalSigners
|
@@ -7414,7 +6823,7 @@ var PerpetualsClient = (function () {
|
|
7414
6823
|
});
|
7415
6824
|
}); };
|
7416
6825
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7417
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
6826
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_43;
|
7418
6827
|
return __generator(this, function (_a) {
|
7419
6828
|
switch (_a.label) {
|
7420
6829
|
case 0:
|
@@ -7448,9 +6857,9 @@ var PerpetualsClient = (function () {
|
|
7448
6857
|
instructions.push(moveProtocolFeesIx);
|
7449
6858
|
return [3, 4];
|
7450
6859
|
case 3:
|
7451
|
-
|
7452
|
-
console.log("perpClient setPool error:: ",
|
7453
|
-
throw
|
6860
|
+
err_43 = _a.sent();
|
6861
|
+
console.log("perpClient setPool error:: ", err_43);
|
6862
|
+
throw err_43;
|
7454
6863
|
case 4: return [2, {
|
7455
6864
|
instructions: __spreadArray([], instructions, true),
|
7456
6865
|
additionalSigners: additionalSigners
|
@@ -7459,7 +6868,7 @@ var PerpetualsClient = (function () {
|
|
7459
6868
|
});
|
7460
6869
|
}); };
|
7461
6870
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7462
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
6871
|
+
var publicKey, setProtocolFeeShareBpsIx, err_44;
|
7463
6872
|
return __generator(this, function (_a) {
|
7464
6873
|
switch (_a.label) {
|
7465
6874
|
case 0:
|
@@ -7479,15 +6888,15 @@ var PerpetualsClient = (function () {
|
|
7479
6888
|
setProtocolFeeShareBpsIx = _a.sent();
|
7480
6889
|
return [2, setProtocolFeeShareBpsIx];
|
7481
6890
|
case 2:
|
7482
|
-
|
7483
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
7484
|
-
throw
|
6891
|
+
err_44 = _a.sent();
|
6892
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_44);
|
6893
|
+
throw err_44;
|
7485
6894
|
case 3: return [2];
|
7486
6895
|
}
|
7487
6896
|
});
|
7488
6897
|
}); };
|
7489
6898
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7490
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
6899
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_45;
|
7491
6900
|
return __generator(this, function (_a) {
|
7492
6901
|
switch (_a.label) {
|
7493
6902
|
case 0:
|
@@ -7514,9 +6923,9 @@ var PerpetualsClient = (function () {
|
|
7514
6923
|
instructions.push(setPermissionsInstruction);
|
7515
6924
|
return [3, 4];
|
7516
6925
|
case 3:
|
7517
|
-
|
7518
|
-
console.log("perpClient setPool error:: ",
|
7519
|
-
throw
|
6926
|
+
err_45 = _a.sent();
|
6927
|
+
console.log("perpClient setPool error:: ", err_45);
|
6928
|
+
throw err_45;
|
7520
6929
|
case 4: return [2, {
|
7521
6930
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7522
6931
|
additionalSigners: additionalSigners
|
@@ -7525,7 +6934,7 @@ var PerpetualsClient = (function () {
|
|
7525
6934
|
});
|
7526
6935
|
}); };
|
7527
6936
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7528
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
6937
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_46;
|
7529
6938
|
var _f;
|
7530
6939
|
return __generator(this, function (_g) {
|
7531
6940
|
switch (_g.label) {
|
@@ -7586,9 +6995,9 @@ var PerpetualsClient = (function () {
|
|
7586
6995
|
instructions.push(reimburse);
|
7587
6996
|
return [3, 5];
|
7588
6997
|
case 4:
|
7589
|
-
|
7590
|
-
console.log("perpClient setPool error:: ",
|
7591
|
-
throw
|
6998
|
+
err_46 = _g.sent();
|
6999
|
+
console.log("perpClient setPool error:: ", err_46);
|
7000
|
+
throw err_46;
|
7592
7001
|
case 5: return [2, {
|
7593
7002
|
instructions: __spreadArray([], instructions, true),
|
7594
7003
|
additionalSigners: additionalSigners
|
@@ -7596,8 +7005,8 @@ var PerpetualsClient = (function () {
|
|
7596
7005
|
}
|
7597
7006
|
});
|
7598
7007
|
}); };
|
7599
|
-
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7600
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
7008
|
+
this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7009
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_47;
|
7601
7010
|
return __generator(this, function (_a) {
|
7602
7011
|
switch (_a.label) {
|
7603
7012
|
case 0:
|
@@ -7609,6 +7018,7 @@ var PerpetualsClient = (function () {
|
|
7609
7018
|
_a.trys.push([1, 3, , 4]);
|
7610
7019
|
return [4, this.program.methods
|
7611
7020
|
.setInternalOraclePrice({
|
7021
|
+
useCurrentTime: useCurrentTime,
|
7612
7022
|
price: price,
|
7613
7023
|
expo: expo,
|
7614
7024
|
conf: conf,
|
@@ -7630,9 +7040,9 @@ var PerpetualsClient = (function () {
|
|
7630
7040
|
instructions.push(setInternalOraclePrice);
|
7631
7041
|
return [3, 4];
|
7632
7042
|
case 3:
|
7633
|
-
|
7634
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7635
|
-
throw
|
7043
|
+
err_47 = _a.sent();
|
7044
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_47);
|
7045
|
+
throw err_47;
|
7636
7046
|
case 4: return [2, {
|
7637
7047
|
instructions: __spreadArray([], instructions, true),
|
7638
7048
|
additionalSigners: additionalSigners
|
@@ -7640,8 +7050,8 @@ var PerpetualsClient = (function () {
|
|
7640
7050
|
}
|
7641
7051
|
});
|
7642
7052
|
}); };
|
7643
|
-
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7644
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7053
|
+
this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7054
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_48;
|
7645
7055
|
return __generator(this, function (_a) {
|
7646
7056
|
switch (_a.label) {
|
7647
7057
|
case 0:
|
@@ -7679,7 +7089,8 @@ var PerpetualsClient = (function () {
|
|
7679
7089
|
_a.trys.push([1, 3, , 4]);
|
7680
7090
|
return [4, this.program.methods
|
7681
7091
|
.setInternalCurrentPrice({
|
7682
|
-
prices: tokenInternalPrices
|
7092
|
+
prices: tokenInternalPrices,
|
7093
|
+
useCurrentTime: useCurrentTime ? 1 : 0
|
7683
7094
|
})
|
7684
7095
|
.accounts({
|
7685
7096
|
authority: POOL_CONFIGS[0].backupOracle,
|
@@ -7691,9 +7102,9 @@ var PerpetualsClient = (function () {
|
|
7691
7102
|
instructions.push(setInternalOraclePrice);
|
7692
7103
|
return [3, 4];
|
7693
7104
|
case 3:
|
7694
|
-
|
7695
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7696
|
-
throw
|
7105
|
+
err_48 = _a.sent();
|
7106
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_48);
|
7107
|
+
throw err_48;
|
7697
7108
|
case 4: return [2, {
|
7698
7109
|
instructions: __spreadArray([], instructions, true),
|
7699
7110
|
additionalSigners: additionalSigners
|
@@ -7702,7 +7113,7 @@ var PerpetualsClient = (function () {
|
|
7702
7113
|
});
|
7703
7114
|
}); };
|
7704
7115
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7705
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7116
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_49;
|
7706
7117
|
return __generator(this, function (_a) {
|
7707
7118
|
switch (_a.label) {
|
7708
7119
|
case 0:
|
@@ -7713,21 +7124,11 @@ var PerpetualsClient = (function () {
|
|
7713
7124
|
accountMetas = [];
|
7714
7125
|
_loop_2 = function (tokenMint) {
|
7715
7126
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7716
|
-
accountMetas.push({
|
7717
|
-
pubkey: custody.custodyAccount,
|
7718
|
-
isSigner: false,
|
7719
|
-
isWritable: false,
|
7720
|
-
});
|
7721
7127
|
accountMetas.push({
|
7722
7128
|
pubkey: custody.intOracleAccount,
|
7723
7129
|
isSigner: false,
|
7724
7130
|
isWritable: true,
|
7725
7131
|
});
|
7726
|
-
accountMetas.push({
|
7727
|
-
pubkey: custody.extOracleAccount,
|
7728
|
-
isSigner: false,
|
7729
|
-
isWritable: false,
|
7730
|
-
});
|
7731
7132
|
};
|
7732
7133
|
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
7733
7134
|
tokenMint = tokenMintList_2[_i];
|
@@ -7752,9 +7153,9 @@ var PerpetualsClient = (function () {
|
|
7752
7153
|
instructions.push(setInternalOraclePrice);
|
7753
7154
|
return [3, 4];
|
7754
7155
|
case 3:
|
7755
|
-
|
7756
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7757
|
-
throw
|
7156
|
+
err_49 = _a.sent();
|
7157
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_49);
|
7158
|
+
throw err_49;
|
7758
7159
|
case 4: return [2, {
|
7759
7160
|
instructions: __spreadArray([], instructions, true),
|
7760
7161
|
additionalSigners: additionalSigners
|
@@ -7763,7 +7164,7 @@ var PerpetualsClient = (function () {
|
|
7763
7164
|
});
|
7764
7165
|
}); };
|
7765
7166
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7766
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
7167
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_50;
|
7767
7168
|
return __generator(this, function (_a) {
|
7768
7169
|
switch (_a.label) {
|
7769
7170
|
case 0:
|
@@ -7801,8 +7202,8 @@ var PerpetualsClient = (function () {
|
|
7801
7202
|
instructions.push(renameFlp);
|
7802
7203
|
return [3, 4];
|
7803
7204
|
case 3:
|
7804
|
-
|
7805
|
-
console.log("perpClient renameFlp error:: ",
|
7205
|
+
err_50 = _a.sent();
|
7206
|
+
console.log("perpClient renameFlp error:: ", err_50);
|
7806
7207
|
return [3, 4];
|
7807
7208
|
case 4: return [2, {
|
7808
7209
|
instructions: __spreadArray([], instructions, true),
|
@@ -7812,7 +7213,7 @@ var PerpetualsClient = (function () {
|
|
7812
7213
|
});
|
7813
7214
|
}); };
|
7814
7215
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7815
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
7216
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_51;
|
7816
7217
|
return __generator(this, function (_a) {
|
7817
7218
|
switch (_a.label) {
|
7818
7219
|
case 0:
|
@@ -7850,9 +7251,9 @@ var PerpetualsClient = (function () {
|
|
7850
7251
|
instructions.push(initStakeInstruction);
|
7851
7252
|
return [3, 4];
|
7852
7253
|
case 3:
|
7853
|
-
|
7854
|
-
console.log("perpClient InitStaking error:: ",
|
7855
|
-
throw
|
7254
|
+
err_51 = _a.sent();
|
7255
|
+
console.log("perpClient InitStaking error:: ", err_51);
|
7256
|
+
throw err_51;
|
7856
7257
|
case 4: return [2, {
|
7857
7258
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7858
7259
|
additionalSigners: additionalSigners
|
@@ -7861,7 +7262,7 @@ var PerpetualsClient = (function () {
|
|
7861
7262
|
});
|
7862
7263
|
}); };
|
7863
7264
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7864
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction,
|
7265
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_52;
|
7865
7266
|
return __generator(this, function (_a) {
|
7866
7267
|
switch (_a.label) {
|
7867
7268
|
case 0:
|
@@ -7906,9 +7307,9 @@ var PerpetualsClient = (function () {
|
|
7906
7307
|
instructions.push(initCompoundingInstruction);
|
7907
7308
|
return [3, 4];
|
7908
7309
|
case 3:
|
7909
|
-
|
7910
|
-
console.log("perpClient initCompounding error:: ",
|
7911
|
-
throw
|
7310
|
+
err_52 = _a.sent();
|
7311
|
+
console.log("perpClient initCompounding error:: ", err_52);
|
7312
|
+
throw err_52;
|
7912
7313
|
case 4: return [2, {
|
7913
7314
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7914
7315
|
additionalSigners: additionalSigners
|
@@ -7917,7 +7318,7 @@ var PerpetualsClient = (function () {
|
|
7917
7318
|
});
|
7918
7319
|
}); };
|
7919
7320
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7920
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
7321
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_53;
|
7921
7322
|
return __generator(this, function (_a) {
|
7922
7323
|
switch (_a.label) {
|
7923
7324
|
case 0:
|
@@ -7958,9 +7359,9 @@ var PerpetualsClient = (function () {
|
|
7958
7359
|
instructions.push(initTokenVaultInstruction);
|
7959
7360
|
return [3, 4];
|
7960
7361
|
case 3:
|
7961
|
-
|
7962
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
7963
|
-
throw
|
7362
|
+
err_53 = _a.sent();
|
7363
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_53);
|
7364
|
+
throw err_53;
|
7964
7365
|
case 4: return [2, {
|
7965
7366
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7966
7367
|
additionalSigners: additionalSigners
|
@@ -7969,7 +7370,7 @@ var PerpetualsClient = (function () {
|
|
7969
7370
|
});
|
7970
7371
|
}); };
|
7971
7372
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7972
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
7373
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_54;
|
7973
7374
|
return __generator(this, function (_a) {
|
7974
7375
|
switch (_a.label) {
|
7975
7376
|
case 0:
|
@@ -8000,9 +7401,9 @@ var PerpetualsClient = (function () {
|
|
8000
7401
|
instructions.push(setTokenVaultConfigInstruction);
|
8001
7402
|
return [3, 4];
|
8002
7403
|
case 3:
|
8003
|
-
|
8004
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
8005
|
-
throw
|
7404
|
+
err_54 = _a.sent();
|
7405
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_54);
|
7406
|
+
throw err_54;
|
8006
7407
|
case 4: return [2, {
|
8007
7408
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8008
7409
|
additionalSigners: additionalSigners
|
@@ -8011,7 +7412,7 @@ var PerpetualsClient = (function () {
|
|
8011
7412
|
});
|
8012
7413
|
}); };
|
8013
7414
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8014
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
7415
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_55;
|
8015
7416
|
return __generator(this, function (_a) {
|
8016
7417
|
switch (_a.label) {
|
8017
7418
|
case 0:
|
@@ -8050,9 +7451,9 @@ var PerpetualsClient = (function () {
|
|
8050
7451
|
instructions.push(withdrawInstantFeeInstruction);
|
8051
7452
|
return [3, 6];
|
8052
7453
|
case 5:
|
8053
|
-
|
8054
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
8055
|
-
throw
|
7454
|
+
err_55 = _a.sent();
|
7455
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_55);
|
7456
|
+
throw err_55;
|
8056
7457
|
case 6: return [2, {
|
8057
7458
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8058
7459
|
additionalSigners: additionalSigners
|
@@ -8061,7 +7462,7 @@ var PerpetualsClient = (function () {
|
|
8061
7462
|
});
|
8062
7463
|
}); };
|
8063
7464
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8064
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
7465
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_56;
|
8065
7466
|
return __generator(this, function (_a) {
|
8066
7467
|
switch (_a.label) {
|
8067
7468
|
case 0:
|
@@ -8098,9 +7499,9 @@ var PerpetualsClient = (function () {
|
|
8098
7499
|
instructions.push(initRevenueTokenAccountInstruction);
|
8099
7500
|
return [3, 4];
|
8100
7501
|
case 3:
|
8101
|
-
|
8102
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
8103
|
-
throw
|
7502
|
+
err_56 = _a.sent();
|
7503
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_56);
|
7504
|
+
throw err_56;
|
8104
7505
|
case 4: return [2, {
|
8105
7506
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8106
7507
|
additionalSigners: additionalSigners
|
@@ -8109,7 +7510,7 @@ var PerpetualsClient = (function () {
|
|
8109
7510
|
});
|
8110
7511
|
}); };
|
8111
7512
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8112
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
7513
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_57;
|
8113
7514
|
return __generator(this, function (_a) {
|
8114
7515
|
switch (_a.label) {
|
8115
7516
|
case 0:
|
@@ -8148,9 +7549,9 @@ var PerpetualsClient = (function () {
|
|
8148
7549
|
instructions.push(distributeTokenRewardInstruction);
|
8149
7550
|
return [3, 4];
|
8150
7551
|
case 3:
|
8151
|
-
|
8152
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
8153
|
-
throw
|
7552
|
+
err_57 = _a.sent();
|
7553
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_57);
|
7554
|
+
throw err_57;
|
8154
7555
|
case 4: return [2, {
|
8155
7556
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8156
7557
|
additionalSigners: additionalSigners
|
@@ -8159,7 +7560,7 @@ var PerpetualsClient = (function () {
|
|
8159
7560
|
});
|
8160
7561
|
}); };
|
8161
7562
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
8162
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
7563
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_58;
|
8163
7564
|
return __generator(this, function (_a) {
|
8164
7565
|
switch (_a.label) {
|
8165
7566
|
case 0:
|
@@ -8187,9 +7588,9 @@ var PerpetualsClient = (function () {
|
|
8187
7588
|
instructions.push(setTokenStakeLevelInstruction);
|
8188
7589
|
return [3, 4];
|
8189
7590
|
case 3:
|
8190
|
-
|
8191
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
8192
|
-
throw
|
7591
|
+
err_58 = _a.sent();
|
7592
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_58);
|
7593
|
+
throw err_58;
|
8193
7594
|
case 4: return [2, {
|
8194
7595
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8195
7596
|
additionalSigners: additionalSigners
|
@@ -8198,7 +7599,7 @@ var PerpetualsClient = (function () {
|
|
8198
7599
|
});
|
8199
7600
|
}); };
|
8200
7601
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8201
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
7602
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_59;
|
8202
7603
|
return __generator(this, function (_a) {
|
8203
7604
|
switch (_a.label) {
|
8204
7605
|
case 0:
|
@@ -8230,9 +7631,49 @@ var PerpetualsClient = (function () {
|
|
8230
7631
|
instructions.push(setTokenRewardInstruction);
|
8231
7632
|
return [3, 4];
|
8232
7633
|
case 3:
|
8233
|
-
|
8234
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
8235
|
-
throw
|
7634
|
+
err_59 = _a.sent();
|
7635
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_59);
|
7636
|
+
throw err_59;
|
7637
|
+
case 4: return [2, {
|
7638
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7639
|
+
additionalSigners: additionalSigners
|
7640
|
+
}];
|
7641
|
+
}
|
7642
|
+
});
|
7643
|
+
}); };
|
7644
|
+
this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
|
7645
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_60;
|
7646
|
+
return __generator(this, function (_a) {
|
7647
|
+
switch (_a.label) {
|
7648
|
+
case 0:
|
7649
|
+
publicKey = this.provider.wallet.publicKey;
|
7650
|
+
preInstructions = [];
|
7651
|
+
instructions = [];
|
7652
|
+
postInstructions = [];
|
7653
|
+
additionalSigners = [];
|
7654
|
+
_a.label = 1;
|
7655
|
+
case 1:
|
7656
|
+
_a.trys.push([1, 3, , 4]);
|
7657
|
+
return [4, this.program.methods
|
7658
|
+
.resizeInternalOracle({
|
7659
|
+
extOracle: extOracle
|
7660
|
+
})
|
7661
|
+
.accounts({
|
7662
|
+
admin: publicKey,
|
7663
|
+
multisig: this.multisig.publicKey,
|
7664
|
+
custodyTokenMint: tokenMint,
|
7665
|
+
intOracleAccount: intOracleAccount,
|
7666
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7667
|
+
})
|
7668
|
+
.instruction()];
|
7669
|
+
case 2:
|
7670
|
+
resizeInternalOracleInstruction = _a.sent();
|
7671
|
+
instructions.push(resizeInternalOracleInstruction);
|
7672
|
+
return [3, 4];
|
7673
|
+
case 3:
|
7674
|
+
err_60 = _a.sent();
|
7675
|
+
console.log("perpClient resizeInternalOracleInstruction error:: ", err_60);
|
7676
|
+
throw err_60;
|
8236
7677
|
case 4: return [2, {
|
8237
7678
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8238
7679
|
additionalSigners: additionalSigners
|