flash-sdk 9.0.0-alpha.1 → 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 +502 -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 +0 -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,
|
@@ -1129,8 +1073,8 @@ var PerpetualsClient = (function () {
|
|
1129
1073
|
throw "only same leverage is supported for now";
|
1130
1074
|
}
|
1131
1075
|
};
|
1132
|
-
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
1133
|
-
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; }
|
1134
1078
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
1135
1079
|
if (errorBandwidthPercentageUi > 100 || errorBandwidthPercentageUi < 0) {
|
1136
1080
|
throw new Error("errorBandwidthPercentageUi cannot be >100 or <0");
|
@@ -1139,24 +1083,25 @@ var PerpetualsClient = (function () {
|
|
1139
1083
|
(new anchor_1.BN(targetCustodyAccount.pricing.maxInitDegenLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100))
|
1140
1084
|
: (new anchor_1.BN(targetCustodyAccount.pricing.maxInitLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100));
|
1141
1085
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1142
|
-
var
|
1086
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1143
1087
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1144
1088
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1145
1089
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
1146
|
-
var currentCollateralUsd =
|
1090
|
+
var currentCollateralUsd = positionAccount.collateralUsd.sub(closeAmountUsd);
|
1147
1091
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
1148
1092
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
1149
1093
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
1150
1094
|
}
|
1151
1095
|
else {
|
1152
1096
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
1153
|
-
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 };
|
1154
1098
|
}
|
1155
1099
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
1156
1100
|
if (maxRemovableCollateralUsd.isNeg()) {
|
1157
|
-
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 };
|
1158
1102
|
}
|
1159
1103
|
var maxWithdrawableAmount = constants_1.BN_ZERO;
|
1104
|
+
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
1160
1105
|
var diff = constants_1.BN_ZERO;
|
1161
1106
|
var remainingCollateralUsd = availableInitMarginUsd.sub(maxRemovableCollateralUsd);
|
1162
1107
|
var isDegenMode = positionAccount.isDegenMode();
|
@@ -1164,36 +1109,37 @@ var PerpetualsClient = (function () {
|
|
1164
1109
|
diff = (new anchor_1.BN(isDegenMode ? targetCustodyAccount.pricing.minDegenCollateralUsd : targetCustodyAccount.pricing.minCollateralUsd)).sub(remainingCollateralUsd);
|
1165
1110
|
var updatedMaxRemovableCollateralUsd = maxRemovableCollateralUsd.sub(diff);
|
1166
1111
|
if (updatedMaxRemovableCollateralUsd.isNeg()) {
|
1167
|
-
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 };
|
1168
1113
|
}
|
1169
1114
|
else {
|
1170
|
-
maxWithdrawableAmount =
|
1115
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(updatedMaxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1116
|
+
maxWithdrawableAmountUsd = updatedMaxRemovableCollateralUsd;
|
1171
1117
|
}
|
1172
1118
|
}
|
1173
1119
|
else {
|
1174
|
-
maxWithdrawableAmount =
|
1120
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1121
|
+
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
1175
1122
|
}
|
1176
|
-
return { maxWithdrawableAmount: maxWithdrawableAmount, diff: diff };
|
1123
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd, diff: diff };
|
1177
1124
|
};
|
1178
|
-
this.
|
1125
|
+
this.getFinalCloseAmountUsdSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
|
1179
1126
|
var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
1180
1127
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1181
|
-
var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
|
1182
1128
|
var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1183
1129
|
var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
|
1184
1130
|
var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
|
1185
1131
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
1186
|
-
var assetsUsd = newPnl.profitUsd.add(collateralMinMaxPrice.
|
1187
|
-
var
|
1132
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
|
1133
|
+
var closeAmountUsd, feesAmountUsd;
|
1188
1134
|
if (assetsUsd.gt(liabilityUsd)) {
|
1189
|
-
|
1190
|
-
|
1135
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
1136
|
+
feesAmountUsd = totalFeesUsd;
|
1191
1137
|
}
|
1192
1138
|
else {
|
1193
|
-
|
1194
|
-
|
1139
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
1140
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
1195
1141
|
}
|
1196
|
-
return {
|
1142
|
+
return { closeAmountUsd: closeAmountUsd, feesAmountUsd: feesAmountUsd };
|
1197
1143
|
};
|
1198
1144
|
this.getMaxWithdrawableAmountSync = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, errorBandwidthPercentageUi) {
|
1199
1145
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
@@ -1206,34 +1152,37 @@ var PerpetualsClient = (function () {
|
|
1206
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)));
|
1207
1153
|
if (maxRemoveableCollateralUsdAfterMinRequired.isNeg()) {
|
1208
1154
|
console.log("THIS cannot happen but still");
|
1209
|
-
return constants_1.BN_ZERO;
|
1155
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1210
1156
|
}
|
1211
1157
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1212
|
-
var
|
1158
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1213
1159
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1214
1160
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1215
1161
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
1216
|
-
var currentCollateralUsd =
|
1162
|
+
var currentCollateralUsd = positionAccount.collateralUsd;
|
1217
1163
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
1218
1164
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
1219
1165
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
1220
1166
|
}
|
1221
1167
|
else {
|
1222
1168
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
1223
|
-
return constants_1.BN_ZERO;
|
1169
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1224
1170
|
}
|
1225
1171
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
1226
1172
|
if (maxRemovableCollateralUsd.isNeg()) {
|
1227
|
-
return constants_1.BN_ZERO;
|
1173
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1228
1174
|
}
|
1229
1175
|
var maxWithdrawableAmount;
|
1176
|
+
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
1230
1177
|
if (maxRemoveableCollateralUsdAfterMinRequired.lt(maxRemovableCollateralUsd)) {
|
1231
|
-
maxWithdrawableAmount =
|
1178
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemoveableCollateralUsdAfterMinRequired, collateralCustodyAccount.decimals);
|
1179
|
+
maxWithdrawableAmountUsd = maxRemoveableCollateralUsdAfterMinRequired;
|
1232
1180
|
}
|
1233
1181
|
else {
|
1234
|
-
maxWithdrawableAmount =
|
1182
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1183
|
+
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
1235
1184
|
}
|
1236
|
-
return maxWithdrawableAmount;
|
1185
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd };
|
1237
1186
|
};
|
1238
1187
|
this.getCumulativeLockFeeSync = function (custodyAccount, currentTimestamp) {
|
1239
1188
|
var cumulativeLockFee = constants_1.BN_ZERO;
|
@@ -1287,185 +1236,138 @@ var PerpetualsClient = (function () {
|
|
1287
1236
|
var lockedUsd = (sideUsd.mul(maxPayOffBpsNew)).div(new anchor_1.BN(constants_1.BPS_POWER));
|
1288
1237
|
return lockedUsd;
|
1289
1238
|
};
|
1290
|
-
this.
|
1239
|
+
this.getLiquidationPriceContractHelper = function (entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount) {
|
1291
1240
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
1292
1241
|
price: constants_1.BN_ZERO,
|
1293
1242
|
exponent: constants_1.BN_ZERO,
|
1294
1243
|
confidence: constants_1.BN_ZERO,
|
1295
1244
|
timestamp: constants_1.BN_ZERO
|
1296
1245
|
});
|
1297
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
1298
|
-
return zeroOraclePrice;
|
1299
|
-
}
|
1300
1246
|
if (positionAccount.entryPrice.exponent && !entryOraclePrice.exponent.eq(new anchor_1.BN(positionAccount.entryPrice.exponent))) {
|
1301
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)));
|
1302
1248
|
}
|
1303
1249
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1304
1250
|
var unsettledLossUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
|
1305
1251
|
var liablitiesUsd = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
1306
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
1307
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1308
1252
|
var liquidationPrice;
|
1309
|
-
if (
|
1310
|
-
var
|
1311
|
-
|
1312
|
-
|
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
|
+
});
|
1313
1268
|
}
|
1314
1269
|
else {
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
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
|
+
});
|
1318
1276
|
}
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
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),
|
1322
1282
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1323
1283
|
confidence: constants_1.BN_ZERO,
|
1324
1284
|
timestamp: constants_1.BN_ZERO
|
1325
|
-
});
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
1331
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1332
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1333
|
-
.div(positionAccount.sizeAmount),
|
1334
|
-
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),
|
1335
1290
|
confidence: constants_1.BN_ZERO,
|
1336
1291
|
timestamp: constants_1.BN_ZERO
|
1337
|
-
})
|
1338
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1339
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1340
|
-
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
1341
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1342
|
-
confidence: constants_1.BN_ZERO,
|
1343
|
-
timestamp: constants_1.BN_ZERO
|
1344
|
-
});
|
1345
|
-
}
|
1346
|
-
else {
|
1347
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1348
|
-
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
1349
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1350
|
-
confidence: constants_1.BN_ZERO,
|
1351
|
-
timestamp: constants_1.BN_ZERO
|
1352
|
-
});
|
1353
|
-
}
|
1292
|
+
});
|
1354
1293
|
}
|
1355
1294
|
else {
|
1356
|
-
|
1357
|
-
price:
|
1358
|
-
|
1359
|
-
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),
|
1360
1298
|
confidence: constants_1.BN_ZERO,
|
1361
1299
|
timestamp: constants_1.BN_ZERO
|
1362
|
-
})
|
1363
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1364
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1365
|
-
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
1366
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1367
|
-
confidence: constants_1.BN_ZERO,
|
1368
|
-
timestamp: constants_1.BN_ZERO
|
1369
|
-
});
|
1370
|
-
}
|
1371
|
-
else {
|
1372
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1373
|
-
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1374
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1375
|
-
confidence: constants_1.BN_ZERO,
|
1376
|
-
timestamp: constants_1.BN_ZERO
|
1377
|
-
});
|
1378
|
-
}
|
1300
|
+
});
|
1379
1301
|
}
|
1380
1302
|
}
|
1381
1303
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
1382
1304
|
};
|
1383
|
-
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) {
|
1384
1313
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
1385
1314
|
price: constants_1.BN_ZERO,
|
1386
1315
|
exponent: constants_1.BN_ZERO,
|
1387
1316
|
confidence: constants_1.BN_ZERO,
|
1388
1317
|
timestamp: constants_1.BN_ZERO
|
1389
1318
|
});
|
1390
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
1391
|
-
return zeroOraclePrice;
|
1392
|
-
}
|
1393
1319
|
var exitFeeUsd = sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1394
1320
|
var unsettledLossUsd = exitFeeUsd;
|
1395
1321
|
var liablitiesUsd = sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
1396
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
1397
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1398
1322
|
var liquidationPrice;
|
1399
|
-
if (
|
1400
|
-
var
|
1401
|
-
|
1402
|
-
|
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
|
+
});
|
1403
1338
|
}
|
1404
1339
|
else {
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
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
|
+
});
|
1408
1346
|
}
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
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),
|
1412
1352
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1413
1353
|
confidence: constants_1.BN_ZERO,
|
1414
1354
|
timestamp: constants_1.BN_ZERO
|
1415
|
-
});
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
1421
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1422
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1423
|
-
.div(sizeAmount),
|
1424
|
-
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),
|
1425
1360
|
confidence: constants_1.BN_ZERO,
|
1426
1361
|
timestamp: constants_1.BN_ZERO
|
1427
|
-
})
|
1428
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1429
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1430
|
-
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
1431
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1432
|
-
confidence: constants_1.BN_ZERO,
|
1433
|
-
timestamp: constants_1.BN_ZERO
|
1434
|
-
});
|
1435
|
-
}
|
1436
|
-
else {
|
1437
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1438
|
-
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
1439
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1440
|
-
confidence: constants_1.BN_ZERO,
|
1441
|
-
timestamp: constants_1.BN_ZERO
|
1442
|
-
});
|
1443
|
-
}
|
1362
|
+
});
|
1444
1363
|
}
|
1445
1364
|
else {
|
1446
|
-
|
1447
|
-
price:
|
1448
|
-
|
1449
|
-
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),
|
1450
1368
|
confidence: constants_1.BN_ZERO,
|
1451
1369
|
timestamp: constants_1.BN_ZERO
|
1452
|
-
})
|
1453
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1454
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1455
|
-
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
1456
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1457
|
-
confidence: constants_1.BN_ZERO,
|
1458
|
-
timestamp: constants_1.BN_ZERO
|
1459
|
-
});
|
1460
|
-
}
|
1461
|
-
else {
|
1462
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1463
|
-
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1464
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1465
|
-
confidence: constants_1.BN_ZERO,
|
1466
|
-
timestamp: constants_1.BN_ZERO
|
1467
|
-
});
|
1468
|
-
}
|
1370
|
+
});
|
1469
1371
|
}
|
1470
1372
|
}
|
1471
1373
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
@@ -1541,8 +1443,8 @@ var PerpetualsClient = (function () {
|
|
1541
1443
|
positionAccount.market = marketAccountPk;
|
1542
1444
|
positionAccount.lockedUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
|
1543
1445
|
positionAccount.lockedAmount = collateralPrice.getTokenAmount(positionAccount.lockedUsd, collateralCustodyAccount.decimals);
|
1544
|
-
|
1545
|
-
positionAccount.collateralUsd =
|
1446
|
+
var collateralDeltaUsd = collateralPrice.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
1447
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
1546
1448
|
var currentTime = new anchor_1.BN((0, utils_1.getUnixTs)());
|
1547
1449
|
var pnl = _this.getPnlSync(positionAccount, userEntrytpSlOraclePrice, userEntrytpSlOraclePrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTime, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1548
1450
|
var pnlUsd = pnl.profitUsd.sub(pnl.lossUsd);
|
@@ -1614,6 +1516,9 @@ var PerpetualsClient = (function () {
|
|
1614
1516
|
});
|
1615
1517
|
};
|
1616
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) {
|
1617
1522
|
if (positionAccount.sizeUsd.isZero() || positionAccount.entryPrice.price.isZero()) {
|
1618
1523
|
return {
|
1619
1524
|
profitUsd: constants_1.BN_ZERO,
|
@@ -1672,7 +1577,7 @@ var PerpetualsClient = (function () {
|
|
1672
1577
|
}
|
1673
1578
|
if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
|
1674
1579
|
return {
|
1675
|
-
profitUsd:
|
1580
|
+
profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
|
1676
1581
|
lossUsd: constants_1.BN_ZERO,
|
1677
1582
|
};
|
1678
1583
|
}
|
@@ -1763,6 +1668,9 @@ var PerpetualsClient = (function () {
|
|
1763
1668
|
}
|
1764
1669
|
};
|
1765
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) {
|
1766
1674
|
var poolAmountUsd = constants_1.BN_ZERO;
|
1767
1675
|
for (var index = 0; index < custodies.length; index++) {
|
1768
1676
|
if (custodies.length != poolAccount.custodies.length || !custodies[index].publicKey.equals(poolAccount.custodies[index])) {
|
@@ -1775,6 +1683,7 @@ var PerpetualsClient = (function () {
|
|
1775
1683
|
var token_amount_usd = tokenMinMaxPrice.max.getAssetAmountUsd(custodies[index].assets.owned, custodies[index].decimals);
|
1776
1684
|
poolAmountUsd = poolAmountUsd.add(token_amount_usd);
|
1777
1685
|
}
|
1686
|
+
poolAmountUsd = poolAmountUsd.sub(poolAccount.feesObligationUsd.add(poolAccount.rebateObligationUsd));
|
1778
1687
|
if (aumCalcMode === "includePnl") {
|
1779
1688
|
var poolEquityUsd = poolAmountUsd;
|
1780
1689
|
for (var index = 0; index < markets.length; index++) {
|
@@ -1784,11 +1693,12 @@ var PerpetualsClient = (function () {
|
|
1784
1693
|
var targetCustodyId = poolAccount.getCustodyId(markets[index].targetCustody);
|
1785
1694
|
var collateralCustodyId = poolAccount.getCustodyId(markets[index].collateralCustody);
|
1786
1695
|
var position = markets[index].getCollectivePosition();
|
1696
|
+
poolEquityUsd = poolEquityUsd.sub(position.collateralUsd);
|
1787
1697
|
var collectivePnl = _this.getPnlSync(position, tokenPrices[targetCustodyId], tokenEmaPrices[targetCustodyId], custodies[targetCustodyId], tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId], currentTime, custodies[targetCustodyId].pricing.delaySeconds, poolConfig);
|
1788
1698
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId]);
|
1789
|
-
var
|
1790
|
-
var
|
1791
|
-
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);
|
1792
1702
|
}
|
1793
1703
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: poolEquityUsd };
|
1794
1704
|
}
|
@@ -1796,14 +1706,6 @@ var PerpetualsClient = (function () {
|
|
1796
1706
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: constants_1.BN_ZERO };
|
1797
1707
|
}
|
1798
1708
|
};
|
1799
|
-
this.getNftFinalDiscount = function (perpetualsAccount, nftTradingAccount, currentTime) {
|
1800
|
-
if (currentTime.sub(nftTradingAccount.timestamp).lt(constants_1.DAY_SECONDS) && nftTradingAccount.counter.gt(new anchor_1.BN(perpetualsAccount.tradeLimit))) {
|
1801
|
-
return { discountBn: constants_1.BN_ZERO };
|
1802
|
-
}
|
1803
|
-
else {
|
1804
|
-
return { discountBn: perpetualsAccount.tradingDiscount[nftTradingAccount.level - 1] };
|
1805
|
-
}
|
1806
|
-
};
|
1807
1709
|
this.getFeeDiscount = function (perpetualsAccount, tokenStakeAccount, currentTime) {
|
1808
1710
|
if (tokenStakeAccount.level === 0) {
|
1809
1711
|
return { discountBn: constants_1.BN_ZERO };
|
@@ -1888,7 +1790,7 @@ var PerpetualsClient = (function () {
|
|
1888
1790
|
});
|
1889
1791
|
};
|
1890
1792
|
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1891
|
-
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;
|
1892
1794
|
var _d;
|
1893
1795
|
return __generator(this, function (_e) {
|
1894
1796
|
switch (_e.label) {
|
@@ -1936,6 +1838,8 @@ var PerpetualsClient = (function () {
|
|
1936
1838
|
return [4, backUpOracleInstructionPromise];
|
1937
1839
|
case 2:
|
1938
1840
|
backUpOracleInstruction = _e.sent();
|
1841
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
1842
|
+
transaction.instructions.unshift(setCULimitIx);
|
1939
1843
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1940
1844
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1941
1845
|
case 3:
|
@@ -2002,7 +1906,7 @@ var PerpetualsClient = (function () {
|
|
2002
1906
|
args_1[_i - 4] = arguments[_i];
|
2003
1907
|
}
|
2004
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) {
|
2005
|
-
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;
|
2006
1910
|
var _e;
|
2007
1911
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2008
1912
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2053,6 +1957,8 @@ var PerpetualsClient = (function () {
|
|
2053
1957
|
.transaction()];
|
2054
1958
|
case 1:
|
2055
1959
|
transaction = _f.sent();
|
1960
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
1961
|
+
transaction.instructions.unshift(setCULimitIx);
|
2056
1962
|
if (!enableBackupOracle) return [3, 3];
|
2057
1963
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2058
1964
|
case 2:
|
@@ -2078,7 +1984,7 @@ var PerpetualsClient = (function () {
|
|
2078
1984
|
args_1[_i - 4] = arguments[_i];
|
2079
1985
|
}
|
2080
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) {
|
2081
|
-
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;
|
2082
1988
|
var _e;
|
2083
1989
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2084
1990
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2129,6 +2035,8 @@ var PerpetualsClient = (function () {
|
|
2129
2035
|
.transaction()];
|
2130
2036
|
case 1:
|
2131
2037
|
transaction = _f.sent();
|
2038
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2039
|
+
transaction.instructions.unshift(setCULimitIx);
|
2132
2040
|
if (!enableBackupOracle) return [3, 3];
|
2133
2041
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2134
2042
|
case 2:
|
@@ -2155,7 +2063,7 @@ var PerpetualsClient = (function () {
|
|
2155
2063
|
});
|
2156
2064
|
};
|
2157
2065
|
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
2158
|
-
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;
|
2159
2067
|
var _d;
|
2160
2068
|
return __generator(this, function (_e) {
|
2161
2069
|
switch (_e.label) {
|
@@ -2203,6 +2111,8 @@ var PerpetualsClient = (function () {
|
|
2203
2111
|
.transaction()];
|
2204
2112
|
case 2:
|
2205
2113
|
transaction = _e.sent();
|
2114
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2115
|
+
transaction.instructions.unshift(setCULimitIx);
|
2206
2116
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2207
2117
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
2208
2118
|
case 3:
|
@@ -2219,7 +2129,7 @@ var PerpetualsClient = (function () {
|
|
2219
2129
|
args_1[_i - 4] = arguments[_i];
|
2220
2130
|
}
|
2221
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) {
|
2222
|
-
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;
|
2223
2133
|
var _e;
|
2224
2134
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2225
2135
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2274,6 +2184,8 @@ var PerpetualsClient = (function () {
|
|
2274
2184
|
.transaction()];
|
2275
2185
|
case 1:
|
2276
2186
|
transaction = _f.sent();
|
2187
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2188
|
+
transaction.instructions.unshift(setCULimitIx);
|
2277
2189
|
if (!enableBackupOracle) return [3, 3];
|
2278
2190
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2279
2191
|
case 2:
|
@@ -2299,7 +2211,7 @@ var PerpetualsClient = (function () {
|
|
2299
2211
|
args_1[_i - 4] = arguments[_i];
|
2300
2212
|
}
|
2301
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) {
|
2302
|
-
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;
|
2303
2215
|
var _e;
|
2304
2216
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2305
2217
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2354,6 +2266,8 @@ var PerpetualsClient = (function () {
|
|
2354
2266
|
.transaction()];
|
2355
2267
|
case 1:
|
2356
2268
|
transaction = _f.sent();
|
2269
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2270
|
+
transaction.instructions.unshift(setCULimitIx);
|
2357
2271
|
if (!enableBackupOracle) return [3, 3];
|
2358
2272
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2359
2273
|
case 2:
|
@@ -2548,11 +2462,10 @@ var PerpetualsClient = (function () {
|
|
2548
2462
|
for (var _i = 8; _i < arguments.length; _i++) {
|
2549
2463
|
args_1[_i - 8] = arguments[_i];
|
2550
2464
|
}
|
2551
|
-
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) {
|
2552
2466
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2553
2467
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2554
2468
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2555
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2556
2469
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2557
2470
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2558
2471
|
return __generator(this, function (_c) {
|
@@ -2645,7 +2558,7 @@ var PerpetualsClient = (function () {
|
|
2645
2558
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2646
2559
|
fundingMint: collateralCustodyConfig.mintKey
|
2647
2560
|
})
|
2648
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2561
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
2649
2562
|
.instruction()];
|
2650
2563
|
case 7:
|
2651
2564
|
instruction = _c.sent();
|
@@ -2663,11 +2576,10 @@ var PerpetualsClient = (function () {
|
|
2663
2576
|
for (var _i = 6; _i < arguments.length; _i++) {
|
2664
2577
|
args_1[_i - 6] = arguments[_i];
|
2665
2578
|
}
|
2666
|
-
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) {
|
2667
2580
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
2668
2581
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2669
2582
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2670
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2671
2583
|
if (createUserATA === void 0) { createUserATA = true; }
|
2672
2584
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2673
2585
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
@@ -2746,7 +2658,7 @@ var PerpetualsClient = (function () {
|
|
2746
2658
|
collateralMint: collateralCustodyConfig.mintKey,
|
2747
2659
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2748
2660
|
})
|
2749
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2661
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
2750
2662
|
.instruction()];
|
2751
2663
|
case 6:
|
2752
2664
|
instruction = _b.sent();
|
@@ -2773,11 +2685,10 @@ var PerpetualsClient = (function () {
|
|
2773
2685
|
for (var _i = 9; _i < arguments.length; _i++) {
|
2774
2686
|
args_1[_i - 9] = arguments[_i];
|
2775
2687
|
}
|
2776
|
-
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) {
|
2777
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;
|
2778
2690
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2779
2691
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2780
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2781
2692
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2782
2693
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2783
2694
|
return __generator(this, function (_c) {
|
@@ -2912,7 +2823,7 @@ var PerpetualsClient = (function () {
|
|
2912
2823
|
collateralMint: collateralCustodyConfig.mintKey,
|
2913
2824
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2914
2825
|
})
|
2915
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2826
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
2916
2827
|
.instruction()];
|
2917
2828
|
case 12:
|
2918
2829
|
inx = _c.sent();
|
@@ -2930,16 +2841,15 @@ var PerpetualsClient = (function () {
|
|
2930
2841
|
});
|
2931
2842
|
});
|
2932
2843
|
};
|
2933
|
-
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) {
|
2934
2845
|
var args_1 = [];
|
2935
|
-
for (var _i =
|
2936
|
-
args_1[_i -
|
2846
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
2847
|
+
args_1[_i - 7] = arguments[_i];
|
2937
2848
|
}
|
2938
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
2939
|
-
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;
|
2940
2851
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2941
2852
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2942
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2943
2853
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2944
2854
|
return __generator(this, function (_a) {
|
2945
2855
|
switch (_a.label) {
|
@@ -3005,18 +2915,12 @@ var PerpetualsClient = (function () {
|
|
3005
2915
|
if (!(_a.sent())) {
|
3006
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));
|
3007
2917
|
}
|
3008
|
-
rebateMintAccount = {
|
3009
|
-
pubkey: collateralCustodyConfig.mintKey,
|
3010
|
-
isSigner: false,
|
3011
|
-
isWritable: false
|
3012
|
-
};
|
3013
2918
|
_a.label = 5;
|
3014
2919
|
case 5:
|
3015
2920
|
_a.trys.push([5, 7, , 8]);
|
3016
2921
|
return [4, this.program.methods
|
3017
2922
|
.closeAndSwap({
|
3018
2923
|
priceWithSlippage: priceWithSlippage,
|
3019
|
-
minSwapAmountOut: minSwapAmountOut,
|
3020
2924
|
privilege: privilege
|
3021
2925
|
})
|
3022
2926
|
.accounts({
|
@@ -3045,7 +2949,7 @@ var PerpetualsClient = (function () {
|
|
3045
2949
|
collateralMint: collateralCustodyConfig.mintKey,
|
3046
2950
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3047
2951
|
})
|
3048
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
2952
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
3049
2953
|
.instruction()];
|
3050
2954
|
case 6:
|
3051
2955
|
inx = _a.sent();
|
@@ -3503,11 +3407,10 @@ var PerpetualsClient = (function () {
|
|
3503
3407
|
for (var _i = 8; _i < arguments.length; _i++) {
|
3504
3408
|
args_1[_i - 8] = arguments[_i];
|
3505
3409
|
}
|
3506
|
-
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) {
|
3507
3411
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3508
3412
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3509
3413
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3510
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3511
3414
|
return __generator(this, function (_a) {
|
3512
3415
|
switch (_a.label) {
|
3513
3416
|
case 0:
|
@@ -3550,7 +3453,7 @@ var PerpetualsClient = (function () {
|
|
3550
3453
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3551
3454
|
collateralMint: collateralCustodyConfig.mintKey
|
3552
3455
|
})
|
3553
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
3456
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
3554
3457
|
.instruction()];
|
3555
3458
|
case 1:
|
3556
3459
|
instruction = _a.sent();
|
@@ -3568,11 +3471,10 @@ var PerpetualsClient = (function () {
|
|
3568
3471
|
for (var _i = 8; _i < arguments.length; _i++) {
|
3569
3472
|
args_1[_i - 8] = arguments[_i];
|
3570
3473
|
}
|
3571
|
-
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) {
|
3572
3475
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3573
3476
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3574
3477
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3575
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3576
3478
|
return __generator(this, function (_a) {
|
3577
3479
|
switch (_a.label) {
|
3578
3480
|
case 0:
|
@@ -3615,7 +3517,7 @@ var PerpetualsClient = (function () {
|
|
3615
3517
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3616
3518
|
collateralMint: collateralCustodyConfig.mintKey
|
3617
3519
|
})
|
3618
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
3520
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
3619
3521
|
.instruction()];
|
3620
3522
|
case 1:
|
3621
3523
|
instruction = _a.sent();
|
@@ -4082,119 +3984,8 @@ var PerpetualsClient = (function () {
|
|
4082
3984
|
}
|
4083
3985
|
});
|
4084
3986
|
}); };
|
4085
|
-
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4086
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
4087
|
-
return __generator(this, function (_a) {
|
4088
|
-
switch (_a.label) {
|
4089
|
-
case 0:
|
4090
|
-
publicKey = this.provider.wallet.publicKey;
|
4091
|
-
preInstructions = [];
|
4092
|
-
instructions = [];
|
4093
|
-
postInstructions = [];
|
4094
|
-
additionalSigners = [];
|
4095
|
-
_a.label = 1;
|
4096
|
-
case 1:
|
4097
|
-
_a.trys.push([1, 4, , 5]);
|
4098
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4099
|
-
Buffer.from("trading"),
|
4100
|
-
nftMint.toBuffer(),
|
4101
|
-
], this.programId)[0];
|
4102
|
-
nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4103
|
-
Buffer.from("referral"),
|
4104
|
-
publicKey.toBuffer(),
|
4105
|
-
], this.programId)[0];
|
4106
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
4107
|
-
case 2:
|
4108
|
-
nftTokenAccount = _a.sent();
|
4109
|
-
flpStakeAccountMetas = [];
|
4110
|
-
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
4111
|
-
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
4112
|
-
flpStakeAccountMetas.push({
|
4113
|
-
pubkey: flpStakeAccountPk,
|
4114
|
-
isSigner: false,
|
4115
|
-
isWritable: true,
|
4116
|
-
});
|
4117
|
-
}
|
4118
|
-
return [4, this.program.methods
|
4119
|
-
.updateTradingAccount({
|
4120
|
-
updateReferer: updateReferer,
|
4121
|
-
updateBooster: updateBooster
|
4122
|
-
})
|
4123
|
-
.accounts({
|
4124
|
-
owner: publicKey,
|
4125
|
-
feePayer: publicKey,
|
4126
|
-
nftTokenAccount: nftTokenAccount,
|
4127
|
-
referralAccount: nftReferralAccount,
|
4128
|
-
tradingAccount: nftTradingAccount
|
4129
|
-
})
|
4130
|
-
.instruction()];
|
4131
|
-
case 3:
|
4132
|
-
updateNftTradingAccountInstruction = _a.sent();
|
4133
|
-
instructions.push(updateNftTradingAccountInstruction);
|
4134
|
-
return [3, 5];
|
4135
|
-
case 4:
|
4136
|
-
err_8 = _a.sent();
|
4137
|
-
console.log("perpClient updateNftAccount error:: ", err_8);
|
4138
|
-
throw err_8;
|
4139
|
-
case 5: return [2, {
|
4140
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4141
|
-
additionalSigners: additionalSigners
|
4142
|
-
}];
|
4143
|
-
}
|
4144
|
-
});
|
4145
|
-
}); };
|
4146
|
-
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4147
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
4148
|
-
return __generator(this, function (_a) {
|
4149
|
-
switch (_a.label) {
|
4150
|
-
case 0:
|
4151
|
-
publicKey = this.provider.wallet.publicKey;
|
4152
|
-
preInstructions = [];
|
4153
|
-
instructions = [];
|
4154
|
-
postInstructions = [];
|
4155
|
-
additionalSigners = [];
|
4156
|
-
_a.label = 1;
|
4157
|
-
case 1:
|
4158
|
-
_a.trys.push([1, 3, , 4]);
|
4159
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4160
|
-
Buffer.from("trading"),
|
4161
|
-
nftMint.toBuffer(),
|
4162
|
-
], this.programId)[0];
|
4163
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4164
|
-
return [4, this.program.methods
|
4165
|
-
.levelUp({})
|
4166
|
-
.accounts({
|
4167
|
-
owner: publicKey,
|
4168
|
-
perpetuals: this.perpetuals.publicKey,
|
4169
|
-
pool: poolConfig.poolAddress,
|
4170
|
-
metadataAccount: metadataAccount,
|
4171
|
-
nftMint: nftMint,
|
4172
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
4173
|
-
tradingAccount: nftTradingAccount,
|
4174
|
-
transferAuthority: this.authority.publicKey,
|
4175
|
-
authorizationRulesAccount: authorizationRulesAccount,
|
4176
|
-
authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
|
4177
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
4178
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4179
|
-
})
|
4180
|
-
.instruction()];
|
4181
|
-
case 2:
|
4182
|
-
levelUpInstruction = _a.sent();
|
4183
|
-
instructions.push(levelUpInstruction);
|
4184
|
-
return [3, 4];
|
4185
|
-
case 3:
|
4186
|
-
err_9 = _a.sent();
|
4187
|
-
console.log("perpClient levelUp error:: ", err_9);
|
4188
|
-
throw err_9;
|
4189
|
-
case 4: return [2, {
|
4190
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4191
|
-
additionalSigners: additionalSigners
|
4192
|
-
}];
|
4193
|
-
}
|
4194
|
-
});
|
4195
|
-
}); };
|
4196
3987
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4197
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
3988
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
|
4198
3989
|
return __generator(this, function (_a) {
|
4199
3990
|
switch (_a.label) {
|
4200
3991
|
case 0:
|
@@ -4236,9 +4027,9 @@ var PerpetualsClient = (function () {
|
|
4236
4027
|
instructions.push(depositStakeInstruction);
|
4237
4028
|
return [3, 5];
|
4238
4029
|
case 4:
|
4239
|
-
|
4240
|
-
console.log("perpClient depositStaking error:: ",
|
4241
|
-
throw
|
4030
|
+
err_8 = _a.sent();
|
4031
|
+
console.log("perpClient depositStaking error:: ", err_8);
|
4032
|
+
throw err_8;
|
4242
4033
|
case 5: return [2, {
|
4243
4034
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4244
4035
|
additionalSigners: additionalSigners
|
@@ -4247,7 +4038,7 @@ var PerpetualsClient = (function () {
|
|
4247
4038
|
});
|
4248
4039
|
}); };
|
4249
4040
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4250
|
-
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;
|
4251
4042
|
return __generator(this, function (_c) {
|
4252
4043
|
switch (_c.label) {
|
4253
4044
|
case 0:
|
@@ -4294,9 +4085,9 @@ var PerpetualsClient = (function () {
|
|
4294
4085
|
refreshStakeInstruction = _c.sent();
|
4295
4086
|
return [2, refreshStakeInstruction];
|
4296
4087
|
case 2:
|
4297
|
-
|
4298
|
-
console.log("perpClient refreshStaking error:: ",
|
4299
|
-
throw
|
4088
|
+
err_9 = _c.sent();
|
4089
|
+
console.log("perpClient refreshStaking error:: ", err_9);
|
4090
|
+
throw err_9;
|
4300
4091
|
case 3: return [2];
|
4301
4092
|
}
|
4302
4093
|
});
|
@@ -4307,7 +4098,7 @@ var PerpetualsClient = (function () {
|
|
4307
4098
|
args_1[_i - 3] = arguments[_i];
|
4308
4099
|
}
|
4309
4100
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4310
|
-
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;
|
4311
4102
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4312
4103
|
return __generator(this, function (_c) {
|
4313
4104
|
switch (_c.label) {
|
@@ -4355,9 +4146,9 @@ var PerpetualsClient = (function () {
|
|
4355
4146
|
refreshStakeInstruction = _c.sent();
|
4356
4147
|
return [2, refreshStakeInstruction];
|
4357
4148
|
case 2:
|
4358
|
-
|
4359
|
-
console.log("perpClient refreshStaking error:: ",
|
4360
|
-
throw
|
4149
|
+
err_10 = _c.sent();
|
4150
|
+
console.log("perpClient refreshStaking error:: ", err_10);
|
4151
|
+
throw err_10;
|
4361
4152
|
case 3: return [2];
|
4362
4153
|
}
|
4363
4154
|
});
|
@@ -4369,7 +4160,7 @@ var PerpetualsClient = (function () {
|
|
4369
4160
|
args_1[_i - 3] = arguments[_i];
|
4370
4161
|
}
|
4371
4162
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4372
|
-
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;
|
4373
4164
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4374
4165
|
return __generator(this, function (_b) {
|
4375
4166
|
switch (_b.label) {
|
@@ -4421,9 +4212,9 @@ var PerpetualsClient = (function () {
|
|
4421
4212
|
instructions.push(unstakeInstantInstruction);
|
4422
4213
|
return [3, 6];
|
4423
4214
|
case 5:
|
4424
|
-
|
4425
|
-
console.log("perpClient unstakeInstant error:: ",
|
4426
|
-
throw
|
4215
|
+
err_11 = _b.sent();
|
4216
|
+
console.log("perpClient unstakeInstant error:: ", err_11);
|
4217
|
+
throw err_11;
|
4427
4218
|
case 6: return [2, {
|
4428
4219
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4429
4220
|
additionalSigners: additionalSigners
|
@@ -4433,7 +4224,7 @@ var PerpetualsClient = (function () {
|
|
4433
4224
|
});
|
4434
4225
|
};
|
4435
4226
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4436
|
-
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;
|
4437
4228
|
return __generator(this, function (_c) {
|
4438
4229
|
switch (_c.label) {
|
4439
4230
|
case 0:
|
@@ -4477,15 +4268,15 @@ var PerpetualsClient = (function () {
|
|
4477
4268
|
refreshStakeInstruction = _c.sent();
|
4478
4269
|
return [2, refreshStakeInstruction];
|
4479
4270
|
case 2:
|
4480
|
-
|
4481
|
-
console.log("perpClient refreshStaking error:: ",
|
4482
|
-
throw
|
4271
|
+
err_12 = _c.sent();
|
4272
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4273
|
+
throw err_12;
|
4483
4274
|
case 3: return [2];
|
4484
4275
|
}
|
4485
4276
|
});
|
4486
4277
|
}); };
|
4487
4278
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4488
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4279
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
4489
4280
|
return __generator(this, function (_a) {
|
4490
4281
|
switch (_a.label) {
|
4491
4282
|
case 0:
|
@@ -4519,9 +4310,9 @@ var PerpetualsClient = (function () {
|
|
4519
4310
|
instructions.push(unstakeRequestInstruction);
|
4520
4311
|
return [3, 4];
|
4521
4312
|
case 3:
|
4522
|
-
|
4523
|
-
console.log("perpClient unstakeRequest error:: ",
|
4524
|
-
throw
|
4313
|
+
err_13 = _a.sent();
|
4314
|
+
console.log("perpClient unstakeRequest error:: ", err_13);
|
4315
|
+
throw err_13;
|
4525
4316
|
case 4: return [2, {
|
4526
4317
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4527
4318
|
additionalSigners: additionalSigners
|
@@ -4535,7 +4326,7 @@ var PerpetualsClient = (function () {
|
|
4535
4326
|
args_1[_i - 1] = arguments[_i];
|
4536
4327
|
}
|
4537
4328
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4538
|
-
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;
|
4539
4330
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
4540
4331
|
if (deactivated === void 0) { deactivated = true; }
|
4541
4332
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
@@ -4591,9 +4382,9 @@ var PerpetualsClient = (function () {
|
|
4591
4382
|
instructions.push(withdrawStakeInstruction);
|
4592
4383
|
return [3, 6];
|
4593
4384
|
case 5:
|
4594
|
-
|
4595
|
-
console.log("perpClient withdrawStake error:: ",
|
4596
|
-
throw
|
4385
|
+
err_14 = _b.sent();
|
4386
|
+
console.log("perpClient withdrawStake error:: ", err_14);
|
4387
|
+
throw err_14;
|
4597
4388
|
case 6: return [2, {
|
4598
4389
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4599
4390
|
additionalSigners: additionalSigners
|
@@ -4608,7 +4399,7 @@ var PerpetualsClient = (function () {
|
|
4608
4399
|
args_1[_i - 3] = arguments[_i];
|
4609
4400
|
}
|
4610
4401
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4611
|
-
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;
|
4612
4403
|
if (createUserATA === void 0) { createUserATA = true; }
|
4613
4404
|
return __generator(this, function (_b) {
|
4614
4405
|
switch (_b.label) {
|
@@ -4669,9 +4460,9 @@ var PerpetualsClient = (function () {
|
|
4669
4460
|
instructions.push(withdrawStakeInstruction);
|
4670
4461
|
return [3, 6];
|
4671
4462
|
case 5:
|
4672
|
-
|
4673
|
-
console.log("perpClient withdrawStake error:: ",
|
4674
|
-
throw
|
4463
|
+
err_15 = _b.sent();
|
4464
|
+
console.log("perpClient withdrawStake error:: ", err_15);
|
4465
|
+
throw err_15;
|
4675
4466
|
case 6: return [2, {
|
4676
4467
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4677
4468
|
additionalSigners: additionalSigners
|
@@ -4686,7 +4477,7 @@ var PerpetualsClient = (function () {
|
|
4686
4477
|
args_1[_i - 5] = arguments[_i];
|
4687
4478
|
}
|
4688
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) {
|
4689
|
-
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;
|
4690
4481
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4691
4482
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4692
4483
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4814,8 +4605,8 @@ var PerpetualsClient = (function () {
|
|
4814
4605
|
instructions.push(addCompoundingLiquidity);
|
4815
4606
|
return [3, 10];
|
4816
4607
|
case 9:
|
4817
|
-
|
4818
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4608
|
+
err_16 = _f.sent();
|
4609
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
4819
4610
|
return [3, 10];
|
4820
4611
|
case 10: return [2, {
|
4821
4612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4831,7 +4622,7 @@ var PerpetualsClient = (function () {
|
|
4831
4622
|
args_1[_i - 5] = arguments[_i];
|
4832
4623
|
}
|
4833
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) {
|
4834
|
-
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;
|
4835
4626
|
if (createUserATA === void 0) { createUserATA = true; }
|
4836
4627
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4837
4628
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4943,8 +4734,8 @@ var PerpetualsClient = (function () {
|
|
4943
4734
|
instructions.push(removeCompoundingLiquidity);
|
4944
4735
|
return [3, 8];
|
4945
4736
|
case 7:
|
4946
|
-
|
4947
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4737
|
+
err_17 = _f.sent();
|
4738
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
4948
4739
|
return [3, 8];
|
4949
4740
|
case 8: return [2, {
|
4950
4741
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4960,7 +4751,7 @@ var PerpetualsClient = (function () {
|
|
4960
4751
|
args_1[_i - 3] = arguments[_i];
|
4961
4752
|
}
|
4962
4753
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
4963
|
-
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;
|
4964
4755
|
if (createUserATA === void 0) { createUserATA = true; }
|
4965
4756
|
return __generator(this, function (_g) {
|
4966
4757
|
switch (_g.label) {
|
@@ -5058,8 +4849,8 @@ var PerpetualsClient = (function () {
|
|
5058
4849
|
instructions.push(migrateStake);
|
5059
4850
|
return [3, 8];
|
5060
4851
|
case 7:
|
5061
|
-
|
5062
|
-
console.log("perpClient migrateStake error:: ",
|
4852
|
+
err_18 = _g.sent();
|
4853
|
+
console.log("perpClient migrateStake error:: ", err_18);
|
5063
4854
|
return [3, 8];
|
5064
4855
|
case 8: return [2, {
|
5065
4856
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5070,7 +4861,7 @@ var PerpetualsClient = (function () {
|
|
5070
4861
|
});
|
5071
4862
|
};
|
5072
4863
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5073
|
-
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;
|
5074
4865
|
return __generator(this, function (_d) {
|
5075
4866
|
switch (_d.label) {
|
5076
4867
|
case 0:
|
@@ -5142,8 +4933,8 @@ var PerpetualsClient = (function () {
|
|
5142
4933
|
instructions.push(migrateFlp);
|
5143
4934
|
return [3, 4];
|
5144
4935
|
case 3:
|
5145
|
-
|
5146
|
-
console.log("perpClient migrateFlp error:: ",
|
4936
|
+
err_19 = _d.sent();
|
4937
|
+
console.log("perpClient migrateFlp error:: ", err_19);
|
5147
4938
|
return [3, 4];
|
5148
4939
|
case 4: return [2, {
|
5149
4940
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5158,7 +4949,7 @@ var PerpetualsClient = (function () {
|
|
5158
4949
|
args_1[_i - 1] = arguments[_i];
|
5159
4950
|
}
|
5160
4951
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5161
|
-
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;
|
5162
4953
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5163
4954
|
return __generator(this, function (_e) {
|
5164
4955
|
switch (_e.label) {
|
@@ -5216,8 +5007,8 @@ var PerpetualsClient = (function () {
|
|
5216
5007
|
instructions.push(compoundingFee);
|
5217
5008
|
return [3, 4];
|
5218
5009
|
case 3:
|
5219
|
-
|
5220
|
-
console.log("perpClient compoundingFee error:: ",
|
5010
|
+
err_20 = _e.sent();
|
5011
|
+
console.log("perpClient compoundingFee error:: ", err_20);
|
5221
5012
|
return [3, 4];
|
5222
5013
|
case 4: return [2, {
|
5223
5014
|
instructions: __spreadArray([], instructions, true),
|
@@ -5227,180 +5018,42 @@ var PerpetualsClient = (function () {
|
|
5227
5018
|
});
|
5228
5019
|
});
|
5229
5020
|
};
|
5230
|
-
this.
|
5231
|
-
var preInstructions, instructions, postInstructions, additionalSigners,
|
5232
|
-
return __generator(this, function (
|
5233
|
-
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) {
|
5234
5025
|
case 0:
|
5235
5026
|
preInstructions = [];
|
5236
5027
|
instructions = [];
|
5237
5028
|
postInstructions = [];
|
5238
5029
|
additionalSigners = [];
|
5239
|
-
|
5030
|
+
_a.label = 1;
|
5240
5031
|
case 1:
|
5241
|
-
|
5242
|
-
|
5243
|
-
|
5244
|
-
userTokenAccount = _b.sent();
|
5245
|
-
_a = createAta;
|
5246
|
-
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);
|
5247
5035
|
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5248
|
-
case
|
5249
|
-
|
5250
|
-
|
5251
|
-
case 4:
|
5252
|
-
if (_a) {
|
5253
|
-
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));
|
5254
5039
|
}
|
5255
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
|
5256
|
-
case 5:
|
5257
|
-
nftTokenAccount = _b.sent();
|
5258
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5259
|
-
Buffer.from("trading"),
|
5260
|
-
nftMint.toBuffer(),
|
5261
|
-
], this.programId)[0];
|
5262
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5263
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5264
|
-
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];
|
5265
|
-
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];
|
5266
5040
|
return [4, this.program.methods
|
5267
|
-
.
|
5041
|
+
.depositTokenStake({
|
5042
|
+
depositAmount: depositAmount
|
5043
|
+
})
|
5268
5044
|
.accounts({
|
5269
5045
|
owner: owner,
|
5270
|
-
|
5046
|
+
feePayer: feePayer,
|
5047
|
+
fundingTokenAccount: userTokenAccount,
|
5271
5048
|
perpetuals: this.perpetuals.publicKey,
|
5272
5049
|
tokenVault: poolConfig.tokenVault,
|
5273
5050
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5274
|
-
|
5275
|
-
collectionMetadata: collectionMetadata,
|
5276
|
-
edition: edition,
|
5277
|
-
tokenRecord: tokenRecord,
|
5278
|
-
tradingAccount: nftTradingAccount,
|
5279
|
-
transferAuthority: poolConfig.transferAuthority,
|
5280
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5281
|
-
nftMint: nftMint,
|
5282
|
-
nftTokenAccount: nftTokenAccount,
|
5051
|
+
tokenStakeAccount: tokenStakeAccount,
|
5283
5052
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5284
5053
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5285
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5286
5054
|
eventAuthority: this.eventAuthority.publicKey,
|
5287
5055
|
program: this.programId,
|
5288
|
-
|
5289
|
-
})
|
5290
|
-
.instruction()];
|
5291
|
-
case 6:
|
5292
|
-
burnAndClaimInstruction = _b.sent();
|
5293
|
-
instructions.push(burnAndClaimInstruction);
|
5294
|
-
return [3, 8];
|
5295
|
-
case 7:
|
5296
|
-
err_23 = _b.sent();
|
5297
|
-
console.log("perpClient burnAndClaimInstruction error:: ", err_23);
|
5298
|
-
throw err_23;
|
5299
|
-
case 8: return [2, {
|
5300
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5301
|
-
additionalSigners: additionalSigners
|
5302
|
-
}];
|
5303
|
-
}
|
5304
|
-
});
|
5305
|
-
}); };
|
5306
|
-
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5307
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_24;
|
5308
|
-
return __generator(this, function (_a) {
|
5309
|
-
switch (_a.label) {
|
5310
|
-
case 0:
|
5311
|
-
preInstructions = [];
|
5312
|
-
instructions = [];
|
5313
|
-
postInstructions = [];
|
5314
|
-
additionalSigners = [];
|
5315
|
-
_a.label = 1;
|
5316
|
-
case 1:
|
5317
|
-
_a.trys.push([1, 3, , 4]);
|
5318
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5319
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
5320
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5321
|
-
Buffer.from("trading"),
|
5322
|
-
nftMint.toBuffer(),
|
5323
|
-
], this.programId)[0];
|
5324
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5325
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5326
|
-
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];
|
5327
|
-
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];
|
5328
|
-
return [4, this.program.methods
|
5329
|
-
.burnAndStake({})
|
5330
|
-
.accounts({
|
5331
|
-
owner: owner,
|
5332
|
-
feePayer: feePayer,
|
5333
|
-
perpetuals: this.perpetuals.publicKey,
|
5334
|
-
tokenVault: poolConfig.tokenVault,
|
5335
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5336
|
-
tokenStakeAccount: tokenStakeAccount,
|
5337
|
-
metadataAccount: metadataAccount,
|
5338
|
-
collectionMetadata: collectionMetadata,
|
5339
|
-
edition: edition,
|
5340
|
-
tokenRecord: tokenRecord,
|
5341
|
-
tradingAccount: nftTradingAccount,
|
5342
|
-
transferAuthority: poolConfig.transferAuthority,
|
5343
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5344
|
-
nftMint: nftMint,
|
5345
|
-
nftTokenAccount: nftTokenAccount,
|
5346
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5347
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5348
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5349
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5350
|
-
program: this.programId
|
5351
|
-
})
|
5352
|
-
.instruction()];
|
5353
|
-
case 2:
|
5354
|
-
burnAndStakeInstruction = _a.sent();
|
5355
|
-
instructions.push(burnAndStakeInstruction);
|
5356
|
-
return [3, 4];
|
5357
|
-
case 3:
|
5358
|
-
err_24 = _a.sent();
|
5359
|
-
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
5360
|
-
throw err_24;
|
5361
|
-
case 4: return [2, {
|
5362
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5363
|
-
additionalSigners: additionalSigners
|
5364
|
-
}];
|
5365
|
-
}
|
5366
|
-
});
|
5367
|
-
}); };
|
5368
|
-
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5369
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
5370
|
-
return __generator(this, function (_a) {
|
5371
|
-
switch (_a.label) {
|
5372
|
-
case 0:
|
5373
|
-
preInstructions = [];
|
5374
|
-
instructions = [];
|
5375
|
-
postInstructions = [];
|
5376
|
-
additionalSigners = [];
|
5377
|
-
_a.label = 1;
|
5378
|
-
case 1:
|
5379
|
-
_a.trys.push([1, 4, , 5]);
|
5380
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5381
|
-
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
5382
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5383
|
-
case 2:
|
5384
|
-
if (!(_a.sent())) {
|
5385
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5386
|
-
}
|
5387
|
-
return [4, this.program.methods
|
5388
|
-
.depositTokenStake({
|
5389
|
-
depositAmount: depositAmount
|
5390
|
-
})
|
5391
|
-
.accounts({
|
5392
|
-
owner: owner,
|
5393
|
-
feePayer: feePayer,
|
5394
|
-
fundingTokenAccount: userTokenAccount,
|
5395
|
-
perpetuals: this.perpetuals.publicKey,
|
5396
|
-
tokenVault: poolConfig.tokenVault,
|
5397
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5398
|
-
tokenStakeAccount: tokenStakeAccount,
|
5399
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5400
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5401
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5402
|
-
program: this.programId,
|
5403
|
-
tokenMint: poolConfig.tokenMint,
|
5056
|
+
tokenMint: poolConfig.tokenMint,
|
5404
5057
|
})
|
5405
5058
|
.instruction()];
|
5406
5059
|
case 3:
|
@@ -5408,9 +5061,9 @@ var PerpetualsClient = (function () {
|
|
5408
5061
|
instructions.push(depositTokenStakeInstruction);
|
5409
5062
|
return [3, 5];
|
5410
5063
|
case 4:
|
5411
|
-
|
5412
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5413
|
-
throw
|
5064
|
+
err_21 = _a.sent();
|
5065
|
+
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
5066
|
+
throw err_21;
|
5414
5067
|
case 5: return [2, {
|
5415
5068
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5416
5069
|
additionalSigners: additionalSigners
|
@@ -5419,7 +5072,7 @@ var PerpetualsClient = (function () {
|
|
5419
5072
|
});
|
5420
5073
|
}); };
|
5421
5074
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5422
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5075
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
|
5423
5076
|
return __generator(this, function (_a) {
|
5424
5077
|
switch (_a.label) {
|
5425
5078
|
case 0:
|
@@ -5448,9 +5101,9 @@ var PerpetualsClient = (function () {
|
|
5448
5101
|
instructions.push(unstakeTokenRequestInstruction);
|
5449
5102
|
return [3, 4];
|
5450
5103
|
case 3:
|
5451
|
-
|
5452
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5453
|
-
throw
|
5104
|
+
err_22 = _a.sent();
|
5105
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
|
5106
|
+
throw err_22;
|
5454
5107
|
case 4: return [2, {
|
5455
5108
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5456
5109
|
additionalSigners: additionalSigners
|
@@ -5459,7 +5112,7 @@ var PerpetualsClient = (function () {
|
|
5459
5112
|
});
|
5460
5113
|
}); };
|
5461
5114
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5462
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5115
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
|
5463
5116
|
return __generator(this, function (_a) {
|
5464
5117
|
switch (_a.label) {
|
5465
5118
|
case 0:
|
@@ -5500,9 +5153,9 @@ var PerpetualsClient = (function () {
|
|
5500
5153
|
instructions.push(unstakeTokenInstantInstruction);
|
5501
5154
|
return [3, 5];
|
5502
5155
|
case 4:
|
5503
|
-
|
5504
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5505
|
-
throw
|
5156
|
+
err_23 = _a.sent();
|
5157
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
5158
|
+
throw err_23;
|
5506
5159
|
case 5: return [2, {
|
5507
5160
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5508
5161
|
additionalSigners: additionalSigners
|
@@ -5511,7 +5164,7 @@ var PerpetualsClient = (function () {
|
|
5511
5164
|
});
|
5512
5165
|
}); };
|
5513
5166
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5514
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5167
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
|
5515
5168
|
return __generator(this, function (_a) {
|
5516
5169
|
switch (_a.label) {
|
5517
5170
|
case 0:
|
@@ -5552,9 +5205,9 @@ var PerpetualsClient = (function () {
|
|
5552
5205
|
instructions.push(withdrawTokenInstruction);
|
5553
5206
|
return [3, 5];
|
5554
5207
|
case 4:
|
5555
|
-
|
5556
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5557
|
-
throw
|
5208
|
+
err_24 = _a.sent();
|
5209
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
5210
|
+
throw err_24;
|
5558
5211
|
case 5: return [2, {
|
5559
5212
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5560
5213
|
additionalSigners: additionalSigners
|
@@ -5563,7 +5216,7 @@ var PerpetualsClient = (function () {
|
|
5563
5216
|
});
|
5564
5217
|
}); };
|
5565
5218
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5566
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5219
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
|
5567
5220
|
return __generator(this, function (_a) {
|
5568
5221
|
switch (_a.label) {
|
5569
5222
|
case 0:
|
@@ -5592,9 +5245,9 @@ var PerpetualsClient = (function () {
|
|
5592
5245
|
instructions.push(cancelUnstakeRequestInstruction);
|
5593
5246
|
return [3, 4];
|
5594
5247
|
case 3:
|
5595
|
-
|
5596
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5597
|
-
throw
|
5248
|
+
err_25 = _a.sent();
|
5249
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
|
5250
|
+
throw err_25;
|
5598
5251
|
case 4: return [2, {
|
5599
5252
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5600
5253
|
additionalSigners: additionalSigners
|
@@ -5608,7 +5261,7 @@ var PerpetualsClient = (function () {
|
|
5608
5261
|
args_1[_i - 2] = arguments[_i];
|
5609
5262
|
}
|
5610
5263
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5611
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
5264
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
5612
5265
|
if (createUserATA === void 0) { createUserATA = true; }
|
5613
5266
|
return __generator(this, function (_b) {
|
5614
5267
|
switch (_b.label) {
|
@@ -5654,9 +5307,9 @@ var PerpetualsClient = (function () {
|
|
5654
5307
|
instructions.push(collectTokenRewardInstruction);
|
5655
5308
|
return [3, 6];
|
5656
5309
|
case 5:
|
5657
|
-
|
5658
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5659
|
-
throw
|
5310
|
+
err_26 = _b.sent();
|
5311
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
5312
|
+
throw err_26;
|
5660
5313
|
case 6: return [2, {
|
5661
5314
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5662
5315
|
additionalSigners: additionalSigners
|
@@ -5671,7 +5324,7 @@ var PerpetualsClient = (function () {
|
|
5671
5324
|
args_1[_i - 3] = arguments[_i];
|
5672
5325
|
}
|
5673
5326
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5674
|
-
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;
|
5675
5328
|
if (createUserATA === void 0) { createUserATA = true; }
|
5676
5329
|
return __generator(this, function (_b) {
|
5677
5330
|
switch (_b.label) {
|
@@ -5718,250 +5371,9 @@ var PerpetualsClient = (function () {
|
|
5718
5371
|
instructions.push(collectRevenueInstruction);
|
5719
5372
|
return [3, 6];
|
5720
5373
|
case 5:
|
5721
|
-
|
5722
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5723
|
-
throw
|
5724
|
-
case 6: return [2, {
|
5725
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5726
|
-
additionalSigners: additionalSigners
|
5727
|
-
}];
|
5728
|
-
}
|
5729
|
-
});
|
5730
|
-
});
|
5731
|
-
};
|
5732
|
-
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5733
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
|
5734
|
-
return __generator(this, function (_a) {
|
5735
|
-
switch (_a.label) {
|
5736
|
-
case 0:
|
5737
|
-
publicKey = this.provider.wallet.publicKey;
|
5738
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5739
|
-
instructions = [];
|
5740
|
-
additionalSigners = [];
|
5741
|
-
_a.label = 1;
|
5742
|
-
case 1:
|
5743
|
-
_a.trys.push([1, 3, , 4]);
|
5744
|
-
fbNftProgramData = web3_js_1.PublicKey.findProgramAddressSync([this.programFbnftReward.programId.toBuffer()], new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"))[0];
|
5745
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5746
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5747
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5748
|
-
return [4, this.programFbnftReward.methods
|
5749
|
-
.initRewardVault({
|
5750
|
-
nftCount: nftCount
|
5751
|
-
})
|
5752
|
-
.accounts({
|
5753
|
-
admin: publicKey,
|
5754
|
-
transferAuthority: nftTransferAuthority,
|
5755
|
-
rewardVault: rewardVault,
|
5756
|
-
rewardMint: rewardCustodyMint,
|
5757
|
-
rewardTokenAccount: rewardTokenAccount,
|
5758
|
-
collectionMint: collectionMint,
|
5759
|
-
programData: fbNftProgramData,
|
5760
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5761
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5762
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
5763
|
-
})
|
5764
|
-
.instruction()];
|
5765
|
-
case 2:
|
5766
|
-
initRewardVault = _a.sent();
|
5767
|
-
instructions.push(initRewardVault);
|
5768
|
-
return [3, 4];
|
5769
|
-
case 3:
|
5770
|
-
err_32 = _a.sent();
|
5771
|
-
console.log("perpClient InitRewardVault error:: ", err_32);
|
5772
|
-
throw err_32;
|
5773
|
-
case 4: return [2, {
|
5774
|
-
instructions: __spreadArray([], instructions, true),
|
5775
|
-
additionalSigners: additionalSigners
|
5776
|
-
}];
|
5777
|
-
}
|
5778
|
-
});
|
5779
|
-
}); };
|
5780
|
-
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5781
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
|
5782
|
-
return __generator(this, function (_a) {
|
5783
|
-
switch (_a.label) {
|
5784
|
-
case 0:
|
5785
|
-
publicKey = this.provider.wallet.publicKey;
|
5786
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5787
|
-
instructions = [];
|
5788
|
-
additionalSigners = [];
|
5789
|
-
_a.label = 1;
|
5790
|
-
case 1:
|
5791
|
-
_a.trys.push([1, 3, , 4]);
|
5792
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5793
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5794
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5795
|
-
return [4, this.programFbnftReward.methods
|
5796
|
-
.distributeRewards({
|
5797
|
-
rewardAmount: rewardAmount
|
5798
|
-
})
|
5799
|
-
.accounts({
|
5800
|
-
admin: publicKey,
|
5801
|
-
fundingAccount: fundingAccount,
|
5802
|
-
rewardVault: rewardVault,
|
5803
|
-
rewardTokenAccount: rewardTokenAccount,
|
5804
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5805
|
-
})
|
5806
|
-
.instruction()];
|
5807
|
-
case 2:
|
5808
|
-
distributeReward = _a.sent();
|
5809
|
-
instructions.push(distributeReward);
|
5810
|
-
return [3, 4];
|
5811
|
-
case 3:
|
5812
|
-
err_33 = _a.sent();
|
5813
|
-
console.log("perpClient distributeReward error:: ", err_33);
|
5814
|
-
throw err_33;
|
5815
|
-
case 4: return [2, {
|
5816
|
-
instructions: __spreadArray([], instructions, true),
|
5817
|
-
additionalSigners: additionalSigners
|
5818
|
-
}];
|
5819
|
-
}
|
5820
|
-
});
|
5821
|
-
}); };
|
5822
|
-
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5823
|
-
var args_1 = [];
|
5824
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
5825
|
-
args_1[_i - 3] = arguments[_i];
|
5826
|
-
}
|
5827
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5828
|
-
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
|
5829
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5830
|
-
return __generator(this, function (_b) {
|
5831
|
-
switch (_b.label) {
|
5832
|
-
case 0:
|
5833
|
-
publicKey = this.provider.wallet.publicKey;
|
5834
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5835
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5836
|
-
instructions = [];
|
5837
|
-
additionalSigners = [];
|
5838
|
-
_b.label = 1;
|
5839
|
-
case 1:
|
5840
|
-
_b.trys.push([1, 5, , 6]);
|
5841
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5842
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5843
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5844
|
-
_a = createUserATA;
|
5845
|
-
if (!_a) return [3, 3];
|
5846
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5847
|
-
case 2:
|
5848
|
-
_a = !(_b.sent());
|
5849
|
-
_b.label = 3;
|
5850
|
-
case 3:
|
5851
|
-
if (_a) {
|
5852
|
-
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));
|
5853
|
-
}
|
5854
|
-
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5855
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5856
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5857
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5858
|
-
return [4, this.programFbnftReward.methods
|
5859
|
-
.collectReward()
|
5860
|
-
.accounts({
|
5861
|
-
owner: publicKey,
|
5862
|
-
feePayer: publicKey,
|
5863
|
-
nftMint: nftMint,
|
5864
|
-
nftTokenAccount: nftTokenAccount,
|
5865
|
-
metadataAccount: metadataAccount,
|
5866
|
-
receivingAccount: receivingTokenAccount,
|
5867
|
-
rewardRecord: rewardRecord,
|
5868
|
-
rewardVault: rewardVault,
|
5869
|
-
rewardTokenAccount: rewardTokenAccount,
|
5870
|
-
transferAuthority: nftTransferAuthority,
|
5871
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5872
|
-
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
5873
|
-
})
|
5874
|
-
.instruction()];
|
5875
|
-
case 4:
|
5876
|
-
collectNftReward = _b.sent();
|
5877
|
-
instructions.push(collectNftReward);
|
5878
|
-
return [3, 6];
|
5879
|
-
case 5:
|
5880
|
-
err_34 = _b.sent();
|
5881
|
-
throw err_34;
|
5882
|
-
case 6: return [2, {
|
5883
|
-
instructions: __spreadArray([], instructions, true),
|
5884
|
-
additionalSigners: additionalSigners
|
5885
|
-
}];
|
5886
|
-
}
|
5887
|
-
});
|
5888
|
-
});
|
5889
|
-
};
|
5890
|
-
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
5891
|
-
var args_1 = [];
|
5892
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
5893
|
-
args_1[_i - 2] = arguments[_i];
|
5894
|
-
}
|
5895
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5896
|
-
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
|
5897
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5898
|
-
return __generator(this, function (_b) {
|
5899
|
-
switch (_b.label) {
|
5900
|
-
case 0:
|
5901
|
-
publicKey = this.provider.wallet.publicKey;
|
5902
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5903
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5904
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5905
|
-
preInstructions = [];
|
5906
|
-
instructions = [];
|
5907
|
-
postInstructions = [];
|
5908
|
-
additionalSigners = [];
|
5909
|
-
_b.label = 1;
|
5910
|
-
case 1:
|
5911
|
-
_b.trys.push([1, 5, , 6]);
|
5912
|
-
pool = poolConfig.poolAddress;
|
5913
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5914
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5915
|
-
_a = createUserATA;
|
5916
|
-
if (!_a) return [3, 3];
|
5917
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5918
|
-
case 2:
|
5919
|
-
_a = !(_b.sent());
|
5920
|
-
_b.label = 3;
|
5921
|
-
case 3:
|
5922
|
-
if (_a) {
|
5923
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5924
|
-
}
|
5925
|
-
tradingAccount = [];
|
5926
|
-
if (nftTradingAccount) {
|
5927
|
-
tradingAccount.push({
|
5928
|
-
pubkey: nftTradingAccount,
|
5929
|
-
isSigner: false,
|
5930
|
-
isWritable: true,
|
5931
|
-
});
|
5932
|
-
}
|
5933
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5934
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5935
|
-
return [4, this.programPerpComposability.methods
|
5936
|
-
.collectAndDistributeFee()
|
5937
|
-
.accounts({
|
5938
|
-
perpProgram: this.programId,
|
5939
|
-
owner: publicKey,
|
5940
|
-
receivingTokenAccount: receivingTokenAccount,
|
5941
|
-
transferAuthority: poolConfig.transferAuthority,
|
5942
|
-
perpetuals: this.perpetuals.publicKey,
|
5943
|
-
pool: pool,
|
5944
|
-
feeCustody: rewardCustodyConfig.custodyAccount,
|
5945
|
-
flpStakeAccount: flpStakeAccount,
|
5946
|
-
feeCustodyTokenAccount: rewardCustodyConfig.tokenAccount,
|
5947
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5948
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5949
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5950
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5951
|
-
fbnftRewardsProgram: this.programFbnftReward.programId,
|
5952
|
-
rewardVault: rewardVault,
|
5953
|
-
rewardTokenAccount: rewardTokenAccount
|
5954
|
-
})
|
5955
|
-
.remainingAccounts(tradingAccount)
|
5956
|
-
.instruction()];
|
5957
|
-
case 4:
|
5958
|
-
withdrawStakeInstruction = _b.sent();
|
5959
|
-
instructions.push(withdrawStakeInstruction);
|
5960
|
-
return [3, 6];
|
5961
|
-
case 5:
|
5962
|
-
err_35 = _b.sent();
|
5963
|
-
console.log("perpClient withdrawStake error:: ", err_35);
|
5964
|
-
throw err_35;
|
5374
|
+
err_27 = _b.sent();
|
5375
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
5376
|
+
throw err_27;
|
5965
5377
|
case 6: return [2, {
|
5966
5378
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5967
5379
|
additionalSigners: additionalSigners
|
@@ -5976,7 +5388,7 @@ var PerpetualsClient = (function () {
|
|
5976
5388
|
args_1[_i - 11] = arguments[_i];
|
5977
5389
|
}
|
5978
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) {
|
5979
|
-
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;
|
5980
5392
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
5981
5393
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5982
5394
|
return __generator(this, function (_c) {
|
@@ -6082,9 +5494,9 @@ var PerpetualsClient = (function () {
|
|
6082
5494
|
instructions.push(placeLimitOrder);
|
6083
5495
|
return [3, 10];
|
6084
5496
|
case 9:
|
6085
|
-
|
6086
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6087
|
-
throw
|
5497
|
+
err_28 = _c.sent();
|
5498
|
+
console.log("perpClient placeLimitOrder error:: ", err_28);
|
5499
|
+
throw err_28;
|
6088
5500
|
case 10: return [2, {
|
6089
5501
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6090
5502
|
additionalSigners: additionalSigners
|
@@ -6099,7 +5511,7 @@ var PerpetualsClient = (function () {
|
|
6099
5511
|
args_1[_i - 11] = arguments[_i];
|
6100
5512
|
}
|
6101
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) {
|
6102
|
-
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;
|
6103
5515
|
if (createUserATA === void 0) { createUserATA = true; }
|
6104
5516
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6105
5517
|
return __generator(this, function (_b) {
|
@@ -6190,9 +5602,9 @@ var PerpetualsClient = (function () {
|
|
6190
5602
|
instructions.push(editLimitOrder);
|
6191
5603
|
return [3, 8];
|
6192
5604
|
case 7:
|
6193
|
-
|
6194
|
-
console.log("perpClient editLimitOrder error:: ",
|
6195
|
-
throw
|
5605
|
+
err_29 = _b.sent();
|
5606
|
+
console.log("perpClient editLimitOrder error:: ", err_29);
|
5607
|
+
throw err_29;
|
6196
5608
|
case 8: return [2, {
|
6197
5609
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6198
5610
|
additionalSigners: additionalSigners
|
@@ -6206,11 +5618,10 @@ var PerpetualsClient = (function () {
|
|
6206
5618
|
for (var _i = 7; _i < arguments.length; _i++) {
|
6207
5619
|
args_1[_i - 7] = arguments[_i];
|
6208
5620
|
}
|
6209
|
-
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
|
6210
|
-
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;
|
6211
5623
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6212
5624
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6213
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6214
5625
|
return __generator(this, function (_a) {
|
6215
5626
|
switch (_a.label) {
|
6216
5627
|
case 0:
|
@@ -6253,16 +5664,16 @@ var PerpetualsClient = (function () {
|
|
6253
5664
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6254
5665
|
collateralMint: collateralCustodyConfig.mintKey,
|
6255
5666
|
})
|
6256
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
5667
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6257
5668
|
.instruction()];
|
6258
5669
|
case 2:
|
6259
5670
|
executeLimitOrder = _a.sent();
|
6260
5671
|
instructions.push(executeLimitOrder);
|
6261
5672
|
return [3, 4];
|
6262
5673
|
case 3:
|
6263
|
-
|
6264
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6265
|
-
throw
|
5674
|
+
err_30 = _a.sent();
|
5675
|
+
console.log("perpClient executeLimitOrder error:: ", err_30);
|
5676
|
+
throw err_30;
|
6266
5677
|
case 4: return [2, {
|
6267
5678
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6268
5679
|
additionalSigners: additionalSigners
|
@@ -6276,11 +5687,10 @@ var PerpetualsClient = (function () {
|
|
6276
5687
|
for (var _i = 8; _i < arguments.length; _i++) {
|
6277
5688
|
args_1[_i - 8] = arguments[_i];
|
6278
5689
|
}
|
6279
|
-
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
|
6280
|
-
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;
|
6281
5692
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6282
5693
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6283
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6284
5694
|
return __generator(this, function (_a) {
|
6285
5695
|
switch (_a.label) {
|
6286
5696
|
case 0:
|
@@ -6326,16 +5736,16 @@ var PerpetualsClient = (function () {
|
|
6326
5736
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6327
5737
|
collateralMint: collateralCustodyConfig.mintKey,
|
6328
5738
|
})
|
6329
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
5739
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6330
5740
|
.instruction()];
|
6331
5741
|
case 2:
|
6332
5742
|
executeLimitWithSwap = _a.sent();
|
6333
5743
|
instructions.push(executeLimitWithSwap);
|
6334
5744
|
return [3, 4];
|
6335
5745
|
case 3:
|
6336
|
-
|
6337
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6338
|
-
throw
|
5746
|
+
err_31 = _a.sent();
|
5747
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_31);
|
5748
|
+
throw err_31;
|
6339
5749
|
case 4: return [2, {
|
6340
5750
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6341
5751
|
additionalSigners: additionalSigners
|
@@ -6345,7 +5755,7 @@ var PerpetualsClient = (function () {
|
|
6345
5755
|
});
|
6346
5756
|
};
|
6347
5757
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6348
|
-
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;
|
6349
5759
|
return __generator(this, function (_a) {
|
6350
5760
|
switch (_a.label) {
|
6351
5761
|
case 0:
|
@@ -6393,9 +5803,9 @@ var PerpetualsClient = (function () {
|
|
6393
5803
|
instructions.push(placeTriggerOrder);
|
6394
5804
|
return [3, 4];
|
6395
5805
|
case 3:
|
6396
|
-
|
6397
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6398
|
-
throw
|
5806
|
+
err_32 = _a.sent();
|
5807
|
+
console.log("perpClient placeTriggerOrder error:: ", err_32);
|
5808
|
+
throw err_32;
|
6399
5809
|
case 4: return [2, {
|
6400
5810
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6401
5811
|
additionalSigners: additionalSigners
|
@@ -6404,7 +5814,7 @@ var PerpetualsClient = (function () {
|
|
6404
5814
|
});
|
6405
5815
|
}); };
|
6406
5816
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6407
|
-
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;
|
6408
5818
|
return __generator(this, function (_a) {
|
6409
5819
|
switch (_a.label) {
|
6410
5820
|
case 0:
|
@@ -6451,9 +5861,9 @@ var PerpetualsClient = (function () {
|
|
6451
5861
|
instructions.push(editTriggerOrder);
|
6452
5862
|
return [3, 4];
|
6453
5863
|
case 3:
|
6454
|
-
|
6455
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6456
|
-
throw
|
5864
|
+
err_33 = _a.sent();
|
5865
|
+
console.log("perpClient editTriggerOrder error:: ", err_33);
|
5866
|
+
throw err_33;
|
6457
5867
|
case 4: return [2, {
|
6458
5868
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6459
5869
|
additionalSigners: additionalSigners
|
@@ -6462,7 +5872,7 @@ var PerpetualsClient = (function () {
|
|
6462
5872
|
});
|
6463
5873
|
}); };
|
6464
5874
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6465
|
-
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;
|
6466
5876
|
return __generator(this, function (_a) {
|
6467
5877
|
switch (_a.label) {
|
6468
5878
|
case 0:
|
@@ -6495,9 +5905,9 @@ var PerpetualsClient = (function () {
|
|
6495
5905
|
instructions.push(cancelTriggerOrder);
|
6496
5906
|
return [3, 4];
|
6497
5907
|
case 3:
|
6498
|
-
|
6499
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6500
|
-
throw
|
5908
|
+
err_34 = _a.sent();
|
5909
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_34);
|
5910
|
+
throw err_34;
|
6501
5911
|
case 4: return [2, {
|
6502
5912
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6503
5913
|
additionalSigners: additionalSigners
|
@@ -6506,7 +5916,7 @@ var PerpetualsClient = (function () {
|
|
6506
5916
|
});
|
6507
5917
|
}); };
|
6508
5918
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6509
|
-
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;
|
6510
5920
|
return __generator(this, function (_a) {
|
6511
5921
|
switch (_a.label) {
|
6512
5922
|
case 0:
|
@@ -6537,9 +5947,9 @@ var PerpetualsClient = (function () {
|
|
6537
5947
|
instructions.push(cancelAllTriggerOrders);
|
6538
5948
|
return [3, 4];
|
6539
5949
|
case 3:
|
6540
|
-
|
6541
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6542
|
-
throw
|
5950
|
+
err_35 = _a.sent();
|
5951
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_35);
|
5952
|
+
throw err_35;
|
6543
5953
|
case 4: return [2, {
|
6544
5954
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6545
5955
|
additionalSigners: additionalSigners
|
@@ -6552,13 +5962,12 @@ var PerpetualsClient = (function () {
|
|
6552
5962
|
for (var _i = 9; _i < arguments.length; _i++) {
|
6553
5963
|
args_1[_i - 9] = arguments[_i];
|
6554
5964
|
}
|
6555
|
-
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
|
6556
|
-
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;
|
6557
5967
|
if (createUserATA === void 0) { createUserATA = true; }
|
6558
5968
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6559
5969
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6560
5970
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6561
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6562
5971
|
return __generator(this, function (_e) {
|
6563
5972
|
switch (_e.label) {
|
6564
5973
|
case 0:
|
@@ -6653,16 +6062,16 @@ var PerpetualsClient = (function () {
|
|
6653
6062
|
collateralMint: collateralCustodyConfig.mintKey,
|
6654
6063
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
6655
6064
|
})
|
6656
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
6065
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6657
6066
|
.instruction()];
|
6658
6067
|
case 8:
|
6659
6068
|
executeTriggerWithSwap = _e.sent();
|
6660
6069
|
instructions.push(executeTriggerWithSwap);
|
6661
6070
|
return [3, 10];
|
6662
6071
|
case 9:
|
6663
|
-
|
6664
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6665
|
-
throw
|
6072
|
+
err_36 = _e.sent();
|
6073
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_36);
|
6074
|
+
throw err_36;
|
6666
6075
|
case 10: return [2, {
|
6667
6076
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6668
6077
|
additionalSigners: additionalSigners
|
@@ -6676,13 +6085,12 @@ var PerpetualsClient = (function () {
|
|
6676
6085
|
for (var _i = 8; _i < arguments.length; _i++) {
|
6677
6086
|
args_1[_i - 8] = arguments[_i];
|
6678
6087
|
}
|
6679
|
-
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
|
6680
|
-
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;
|
6681
6090
|
if (createUserATA === void 0) { createUserATA = true; }
|
6682
6091
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6683
6092
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6684
6093
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6685
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6686
6094
|
return __generator(this, function (_b) {
|
6687
6095
|
switch (_b.label) {
|
6688
6096
|
case 0:
|
@@ -6742,16 +6150,16 @@ var PerpetualsClient = (function () {
|
|
6742
6150
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6743
6151
|
receivingMint: collateralCustodyConfig.mintKey
|
6744
6152
|
})
|
6745
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
6153
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
6746
6154
|
.instruction()];
|
6747
6155
|
case 6:
|
6748
6156
|
executeTriggerOrder = _b.sent();
|
6749
6157
|
instructions.push(executeTriggerOrder);
|
6750
6158
|
return [3, 8];
|
6751
6159
|
case 7:
|
6752
|
-
|
6753
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
6754
|
-
throw
|
6160
|
+
err_37 = _b.sent();
|
6161
|
+
console.log("perpClient executeTriggerOrder error:: ", err_37);
|
6162
|
+
throw err_37;
|
6755
6163
|
case 8: return [2, {
|
6756
6164
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6757
6165
|
additionalSigners: additionalSigners
|
@@ -6766,7 +6174,7 @@ var PerpetualsClient = (function () {
|
|
6766
6174
|
args_1[_i - 5] = arguments[_i];
|
6767
6175
|
}
|
6768
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) {
|
6769
|
-
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;
|
6770
6178
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
6771
6179
|
if (createUserATA === void 0) { createUserATA = true; }
|
6772
6180
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
@@ -6971,9 +6379,9 @@ var PerpetualsClient = (function () {
|
|
6971
6379
|
}
|
6972
6380
|
return [3, 20];
|
6973
6381
|
case 19:
|
6974
|
-
|
6975
|
-
console.error("perpClient Swap error:: ",
|
6976
|
-
throw
|
6382
|
+
err_38 = _g.sent();
|
6383
|
+
console.error("perpClient Swap error:: ", err_38);
|
6384
|
+
throw err_38;
|
6977
6385
|
case 20: return [2, {
|
6978
6386
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6979
6387
|
additionalSigners: additionalSigners
|
@@ -6983,7 +6391,7 @@ var PerpetualsClient = (function () {
|
|
6983
6391
|
});
|
6984
6392
|
};
|
6985
6393
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6986
|
-
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;
|
6987
6395
|
return __generator(this, function (_b) {
|
6988
6396
|
switch (_b.label) {
|
6989
6397
|
case 0:
|
@@ -7039,9 +6447,9 @@ var PerpetualsClient = (function () {
|
|
7039
6447
|
instructions.push(inx);
|
7040
6448
|
return [3, 4];
|
7041
6449
|
case 3:
|
7042
|
-
|
7043
|
-
console.error("perpClient Swap error:: ",
|
7044
|
-
throw
|
6450
|
+
err_39 = _b.sent();
|
6451
|
+
console.error("perpClient Swap error:: ", err_39);
|
6452
|
+
throw err_39;
|
7045
6453
|
case 4: return [2, {
|
7046
6454
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7047
6455
|
additionalSigners: additionalSigners
|
@@ -7050,7 +6458,7 @@ var PerpetualsClient = (function () {
|
|
7050
6458
|
});
|
7051
6459
|
}); };
|
7052
6460
|
this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7053
|
-
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;
|
7054
6462
|
return __generator(this, function (_d) {
|
7055
6463
|
switch (_d.label) {
|
7056
6464
|
case 0:
|
@@ -7098,9 +6506,9 @@ var PerpetualsClient = (function () {
|
|
7098
6506
|
instructions.push(setLpTokenPriceInstruction);
|
7099
6507
|
return [3, 4];
|
7100
6508
|
case 3:
|
7101
|
-
|
7102
|
-
console.log("perpClient setLpTokenPriceInstruction error:: ",
|
7103
|
-
throw
|
6509
|
+
err_40 = _d.sent();
|
6510
|
+
console.log("perpClient setLpTokenPriceInstruction error:: ", err_40);
|
6511
|
+
throw err_40;
|
7104
6512
|
case 4: return [2, {
|
7105
6513
|
instructions: __spreadArray([], instructions, true),
|
7106
6514
|
additionalSigners: additionalSigners
|
@@ -7148,7 +6556,7 @@ var PerpetualsClient = (function () {
|
|
7148
6556
|
});
|
7149
6557
|
}); };
|
7150
6558
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
7151
|
-
var adminMetas, _i, admins_2, admin,
|
6559
|
+
var adminMetas, _i, admins_2, admin, err_41;
|
7152
6560
|
return __generator(this, function (_a) {
|
7153
6561
|
switch (_a.label) {
|
7154
6562
|
case 0:
|
@@ -7178,11 +6586,11 @@ var PerpetualsClient = (function () {
|
|
7178
6586
|
_a.sent();
|
7179
6587
|
return [3, 4];
|
7180
6588
|
case 3:
|
7181
|
-
|
6589
|
+
err_41 = _a.sent();
|
7182
6590
|
if (this.printErrors) {
|
7183
|
-
console.error("setAdminSigners err:",
|
6591
|
+
console.error("setAdminSigners err:", err_41);
|
7184
6592
|
}
|
7185
|
-
throw
|
6593
|
+
throw err_41;
|
7186
6594
|
case 4: return [2];
|
7187
6595
|
}
|
7188
6596
|
});
|
@@ -7371,7 +6779,7 @@ var PerpetualsClient = (function () {
|
|
7371
6779
|
});
|
7372
6780
|
}); };
|
7373
6781
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7374
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
6782
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_42;
|
7375
6783
|
return __generator(this, function (_a) {
|
7376
6784
|
switch (_a.label) {
|
7377
6785
|
case 0:
|
@@ -7404,9 +6812,9 @@ var PerpetualsClient = (function () {
|
|
7404
6812
|
instructions.push(withdrawFeesIx);
|
7405
6813
|
return [3, 5];
|
7406
6814
|
case 4:
|
7407
|
-
|
7408
|
-
console.log("perpClient setPool error:: ",
|
7409
|
-
throw
|
6815
|
+
err_42 = _a.sent();
|
6816
|
+
console.log("perpClient setPool error:: ", err_42);
|
6817
|
+
throw err_42;
|
7410
6818
|
case 5: return [2, {
|
7411
6819
|
instructions: __spreadArray([], instructions, true),
|
7412
6820
|
additionalSigners: additionalSigners
|
@@ -7415,7 +6823,7 @@ var PerpetualsClient = (function () {
|
|
7415
6823
|
});
|
7416
6824
|
}); };
|
7417
6825
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7418
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
6826
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_43;
|
7419
6827
|
return __generator(this, function (_a) {
|
7420
6828
|
switch (_a.label) {
|
7421
6829
|
case 0:
|
@@ -7449,9 +6857,9 @@ var PerpetualsClient = (function () {
|
|
7449
6857
|
instructions.push(moveProtocolFeesIx);
|
7450
6858
|
return [3, 4];
|
7451
6859
|
case 3:
|
7452
|
-
|
7453
|
-
console.log("perpClient setPool error:: ",
|
7454
|
-
throw
|
6860
|
+
err_43 = _a.sent();
|
6861
|
+
console.log("perpClient setPool error:: ", err_43);
|
6862
|
+
throw err_43;
|
7455
6863
|
case 4: return [2, {
|
7456
6864
|
instructions: __spreadArray([], instructions, true),
|
7457
6865
|
additionalSigners: additionalSigners
|
@@ -7460,7 +6868,7 @@ var PerpetualsClient = (function () {
|
|
7460
6868
|
});
|
7461
6869
|
}); };
|
7462
6870
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7463
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
6871
|
+
var publicKey, setProtocolFeeShareBpsIx, err_44;
|
7464
6872
|
return __generator(this, function (_a) {
|
7465
6873
|
switch (_a.label) {
|
7466
6874
|
case 0:
|
@@ -7480,15 +6888,15 @@ var PerpetualsClient = (function () {
|
|
7480
6888
|
setProtocolFeeShareBpsIx = _a.sent();
|
7481
6889
|
return [2, setProtocolFeeShareBpsIx];
|
7482
6890
|
case 2:
|
7483
|
-
|
7484
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
7485
|
-
throw
|
6891
|
+
err_44 = _a.sent();
|
6892
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_44);
|
6893
|
+
throw err_44;
|
7486
6894
|
case 3: return [2];
|
7487
6895
|
}
|
7488
6896
|
});
|
7489
6897
|
}); };
|
7490
6898
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7491
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
6899
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_45;
|
7492
6900
|
return __generator(this, function (_a) {
|
7493
6901
|
switch (_a.label) {
|
7494
6902
|
case 0:
|
@@ -7515,9 +6923,9 @@ var PerpetualsClient = (function () {
|
|
7515
6923
|
instructions.push(setPermissionsInstruction);
|
7516
6924
|
return [3, 4];
|
7517
6925
|
case 3:
|
7518
|
-
|
7519
|
-
console.log("perpClient setPool error:: ",
|
7520
|
-
throw
|
6926
|
+
err_45 = _a.sent();
|
6927
|
+
console.log("perpClient setPool error:: ", err_45);
|
6928
|
+
throw err_45;
|
7521
6929
|
case 4: return [2, {
|
7522
6930
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7523
6931
|
additionalSigners: additionalSigners
|
@@ -7526,7 +6934,7 @@ var PerpetualsClient = (function () {
|
|
7526
6934
|
});
|
7527
6935
|
}); };
|
7528
6936
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7529
|
-
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;
|
7530
6938
|
var _f;
|
7531
6939
|
return __generator(this, function (_g) {
|
7532
6940
|
switch (_g.label) {
|
@@ -7587,9 +6995,9 @@ var PerpetualsClient = (function () {
|
|
7587
6995
|
instructions.push(reimburse);
|
7588
6996
|
return [3, 5];
|
7589
6997
|
case 4:
|
7590
|
-
|
7591
|
-
console.log("perpClient setPool error:: ",
|
7592
|
-
throw
|
6998
|
+
err_46 = _g.sent();
|
6999
|
+
console.log("perpClient setPool error:: ", err_46);
|
7000
|
+
throw err_46;
|
7593
7001
|
case 5: return [2, {
|
7594
7002
|
instructions: __spreadArray([], instructions, true),
|
7595
7003
|
additionalSigners: additionalSigners
|
@@ -7597,8 +7005,8 @@ var PerpetualsClient = (function () {
|
|
7597
7005
|
}
|
7598
7006
|
});
|
7599
7007
|
}); };
|
7600
|
-
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7601
|
-
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;
|
7602
7010
|
return __generator(this, function (_a) {
|
7603
7011
|
switch (_a.label) {
|
7604
7012
|
case 0:
|
@@ -7610,6 +7018,7 @@ var PerpetualsClient = (function () {
|
|
7610
7018
|
_a.trys.push([1, 3, , 4]);
|
7611
7019
|
return [4, this.program.methods
|
7612
7020
|
.setInternalOraclePrice({
|
7021
|
+
useCurrentTime: useCurrentTime,
|
7613
7022
|
price: price,
|
7614
7023
|
expo: expo,
|
7615
7024
|
conf: conf,
|
@@ -7631,9 +7040,9 @@ var PerpetualsClient = (function () {
|
|
7631
7040
|
instructions.push(setInternalOraclePrice);
|
7632
7041
|
return [3, 4];
|
7633
7042
|
case 3:
|
7634
|
-
|
7635
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7636
|
-
throw
|
7043
|
+
err_47 = _a.sent();
|
7044
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_47);
|
7045
|
+
throw err_47;
|
7637
7046
|
case 4: return [2, {
|
7638
7047
|
instructions: __spreadArray([], instructions, true),
|
7639
7048
|
additionalSigners: additionalSigners
|
@@ -7641,8 +7050,8 @@ var PerpetualsClient = (function () {
|
|
7641
7050
|
}
|
7642
7051
|
});
|
7643
7052
|
}); };
|
7644
|
-
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7645
|
-
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;
|
7646
7055
|
return __generator(this, function (_a) {
|
7647
7056
|
switch (_a.label) {
|
7648
7057
|
case 0:
|
@@ -7680,7 +7089,8 @@ var PerpetualsClient = (function () {
|
|
7680
7089
|
_a.trys.push([1, 3, , 4]);
|
7681
7090
|
return [4, this.program.methods
|
7682
7091
|
.setInternalCurrentPrice({
|
7683
|
-
prices: tokenInternalPrices
|
7092
|
+
prices: tokenInternalPrices,
|
7093
|
+
useCurrentTime: useCurrentTime ? 1 : 0
|
7684
7094
|
})
|
7685
7095
|
.accounts({
|
7686
7096
|
authority: POOL_CONFIGS[0].backupOracle,
|
@@ -7692,9 +7102,9 @@ var PerpetualsClient = (function () {
|
|
7692
7102
|
instructions.push(setInternalOraclePrice);
|
7693
7103
|
return [3, 4];
|
7694
7104
|
case 3:
|
7695
|
-
|
7696
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7697
|
-
throw
|
7105
|
+
err_48 = _a.sent();
|
7106
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_48);
|
7107
|
+
throw err_48;
|
7698
7108
|
case 4: return [2, {
|
7699
7109
|
instructions: __spreadArray([], instructions, true),
|
7700
7110
|
additionalSigners: additionalSigners
|
@@ -7703,7 +7113,7 @@ var PerpetualsClient = (function () {
|
|
7703
7113
|
});
|
7704
7114
|
}); };
|
7705
7115
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7706
|
-
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;
|
7707
7117
|
return __generator(this, function (_a) {
|
7708
7118
|
switch (_a.label) {
|
7709
7119
|
case 0:
|
@@ -7714,21 +7124,11 @@ var PerpetualsClient = (function () {
|
|
7714
7124
|
accountMetas = [];
|
7715
7125
|
_loop_2 = function (tokenMint) {
|
7716
7126
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7717
|
-
accountMetas.push({
|
7718
|
-
pubkey: custody.custodyAccount,
|
7719
|
-
isSigner: false,
|
7720
|
-
isWritable: false,
|
7721
|
-
});
|
7722
7127
|
accountMetas.push({
|
7723
7128
|
pubkey: custody.intOracleAccount,
|
7724
7129
|
isSigner: false,
|
7725
7130
|
isWritable: true,
|
7726
7131
|
});
|
7727
|
-
accountMetas.push({
|
7728
|
-
pubkey: custody.extOracleAccount,
|
7729
|
-
isSigner: false,
|
7730
|
-
isWritable: false,
|
7731
|
-
});
|
7732
7132
|
};
|
7733
7133
|
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
7734
7134
|
tokenMint = tokenMintList_2[_i];
|
@@ -7753,9 +7153,9 @@ var PerpetualsClient = (function () {
|
|
7753
7153
|
instructions.push(setInternalOraclePrice);
|
7754
7154
|
return [3, 4];
|
7755
7155
|
case 3:
|
7756
|
-
|
7757
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7758
|
-
throw
|
7156
|
+
err_49 = _a.sent();
|
7157
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_49);
|
7158
|
+
throw err_49;
|
7759
7159
|
case 4: return [2, {
|
7760
7160
|
instructions: __spreadArray([], instructions, true),
|
7761
7161
|
additionalSigners: additionalSigners
|
@@ -7764,7 +7164,7 @@ var PerpetualsClient = (function () {
|
|
7764
7164
|
});
|
7765
7165
|
}); };
|
7766
7166
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7767
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
7167
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_50;
|
7768
7168
|
return __generator(this, function (_a) {
|
7769
7169
|
switch (_a.label) {
|
7770
7170
|
case 0:
|
@@ -7802,8 +7202,8 @@ var PerpetualsClient = (function () {
|
|
7802
7202
|
instructions.push(renameFlp);
|
7803
7203
|
return [3, 4];
|
7804
7204
|
case 3:
|
7805
|
-
|
7806
|
-
console.log("perpClient renameFlp error:: ",
|
7205
|
+
err_50 = _a.sent();
|
7206
|
+
console.log("perpClient renameFlp error:: ", err_50);
|
7807
7207
|
return [3, 4];
|
7808
7208
|
case 4: return [2, {
|
7809
7209
|
instructions: __spreadArray([], instructions, true),
|
@@ -7813,7 +7213,7 @@ var PerpetualsClient = (function () {
|
|
7813
7213
|
});
|
7814
7214
|
}); };
|
7815
7215
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7816
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
7216
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_51;
|
7817
7217
|
return __generator(this, function (_a) {
|
7818
7218
|
switch (_a.label) {
|
7819
7219
|
case 0:
|
@@ -7851,9 +7251,9 @@ var PerpetualsClient = (function () {
|
|
7851
7251
|
instructions.push(initStakeInstruction);
|
7852
7252
|
return [3, 4];
|
7853
7253
|
case 3:
|
7854
|
-
|
7855
|
-
console.log("perpClient InitStaking error:: ",
|
7856
|
-
throw
|
7254
|
+
err_51 = _a.sent();
|
7255
|
+
console.log("perpClient InitStaking error:: ", err_51);
|
7256
|
+
throw err_51;
|
7857
7257
|
case 4: return [2, {
|
7858
7258
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7859
7259
|
additionalSigners: additionalSigners
|
@@ -7862,7 +7262,7 @@ var PerpetualsClient = (function () {
|
|
7862
7262
|
});
|
7863
7263
|
}); };
|
7864
7264
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7865
|
-
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;
|
7866
7266
|
return __generator(this, function (_a) {
|
7867
7267
|
switch (_a.label) {
|
7868
7268
|
case 0:
|
@@ -7907,9 +7307,9 @@ var PerpetualsClient = (function () {
|
|
7907
7307
|
instructions.push(initCompoundingInstruction);
|
7908
7308
|
return [3, 4];
|
7909
7309
|
case 3:
|
7910
|
-
|
7911
|
-
console.log("perpClient initCompounding error:: ",
|
7912
|
-
throw
|
7310
|
+
err_52 = _a.sent();
|
7311
|
+
console.log("perpClient initCompounding error:: ", err_52);
|
7312
|
+
throw err_52;
|
7913
7313
|
case 4: return [2, {
|
7914
7314
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7915
7315
|
additionalSigners: additionalSigners
|
@@ -7918,7 +7318,7 @@ var PerpetualsClient = (function () {
|
|
7918
7318
|
});
|
7919
7319
|
}); };
|
7920
7320
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7921
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
7321
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_53;
|
7922
7322
|
return __generator(this, function (_a) {
|
7923
7323
|
switch (_a.label) {
|
7924
7324
|
case 0:
|
@@ -7959,9 +7359,9 @@ var PerpetualsClient = (function () {
|
|
7959
7359
|
instructions.push(initTokenVaultInstruction);
|
7960
7360
|
return [3, 4];
|
7961
7361
|
case 3:
|
7962
|
-
|
7963
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
7964
|
-
throw
|
7362
|
+
err_53 = _a.sent();
|
7363
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_53);
|
7364
|
+
throw err_53;
|
7965
7365
|
case 4: return [2, {
|
7966
7366
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7967
7367
|
additionalSigners: additionalSigners
|
@@ -7970,7 +7370,7 @@ var PerpetualsClient = (function () {
|
|
7970
7370
|
});
|
7971
7371
|
}); };
|
7972
7372
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7973
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
7373
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_54;
|
7974
7374
|
return __generator(this, function (_a) {
|
7975
7375
|
switch (_a.label) {
|
7976
7376
|
case 0:
|
@@ -8001,9 +7401,9 @@ var PerpetualsClient = (function () {
|
|
8001
7401
|
instructions.push(setTokenVaultConfigInstruction);
|
8002
7402
|
return [3, 4];
|
8003
7403
|
case 3:
|
8004
|
-
|
8005
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
8006
|
-
throw
|
7404
|
+
err_54 = _a.sent();
|
7405
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_54);
|
7406
|
+
throw err_54;
|
8007
7407
|
case 4: return [2, {
|
8008
7408
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8009
7409
|
additionalSigners: additionalSigners
|
@@ -8012,7 +7412,7 @@ var PerpetualsClient = (function () {
|
|
8012
7412
|
});
|
8013
7413
|
}); };
|
8014
7414
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8015
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
7415
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_55;
|
8016
7416
|
return __generator(this, function (_a) {
|
8017
7417
|
switch (_a.label) {
|
8018
7418
|
case 0:
|
@@ -8051,9 +7451,9 @@ var PerpetualsClient = (function () {
|
|
8051
7451
|
instructions.push(withdrawInstantFeeInstruction);
|
8052
7452
|
return [3, 6];
|
8053
7453
|
case 5:
|
8054
|
-
|
8055
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
8056
|
-
throw
|
7454
|
+
err_55 = _a.sent();
|
7455
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_55);
|
7456
|
+
throw err_55;
|
8057
7457
|
case 6: return [2, {
|
8058
7458
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8059
7459
|
additionalSigners: additionalSigners
|
@@ -8062,7 +7462,7 @@ var PerpetualsClient = (function () {
|
|
8062
7462
|
});
|
8063
7463
|
}); };
|
8064
7464
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8065
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
7465
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_56;
|
8066
7466
|
return __generator(this, function (_a) {
|
8067
7467
|
switch (_a.label) {
|
8068
7468
|
case 0:
|
@@ -8099,9 +7499,9 @@ var PerpetualsClient = (function () {
|
|
8099
7499
|
instructions.push(initRevenueTokenAccountInstruction);
|
8100
7500
|
return [3, 4];
|
8101
7501
|
case 3:
|
8102
|
-
|
8103
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
8104
|
-
throw
|
7502
|
+
err_56 = _a.sent();
|
7503
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_56);
|
7504
|
+
throw err_56;
|
8105
7505
|
case 4: return [2, {
|
8106
7506
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8107
7507
|
additionalSigners: additionalSigners
|
@@ -8110,7 +7510,7 @@ var PerpetualsClient = (function () {
|
|
8110
7510
|
});
|
8111
7511
|
}); };
|
8112
7512
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8113
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
7513
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_57;
|
8114
7514
|
return __generator(this, function (_a) {
|
8115
7515
|
switch (_a.label) {
|
8116
7516
|
case 0:
|
@@ -8149,9 +7549,9 @@ var PerpetualsClient = (function () {
|
|
8149
7549
|
instructions.push(distributeTokenRewardInstruction);
|
8150
7550
|
return [3, 4];
|
8151
7551
|
case 3:
|
8152
|
-
|
8153
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
8154
|
-
throw
|
7552
|
+
err_57 = _a.sent();
|
7553
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_57);
|
7554
|
+
throw err_57;
|
8155
7555
|
case 4: return [2, {
|
8156
7556
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8157
7557
|
additionalSigners: additionalSigners
|
@@ -8160,7 +7560,7 @@ var PerpetualsClient = (function () {
|
|
8160
7560
|
});
|
8161
7561
|
}); };
|
8162
7562
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
8163
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
7563
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_58;
|
8164
7564
|
return __generator(this, function (_a) {
|
8165
7565
|
switch (_a.label) {
|
8166
7566
|
case 0:
|
@@ -8188,9 +7588,9 @@ var PerpetualsClient = (function () {
|
|
8188
7588
|
instructions.push(setTokenStakeLevelInstruction);
|
8189
7589
|
return [3, 4];
|
8190
7590
|
case 3:
|
8191
|
-
|
8192
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
8193
|
-
throw
|
7591
|
+
err_58 = _a.sent();
|
7592
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_58);
|
7593
|
+
throw err_58;
|
8194
7594
|
case 4: return [2, {
|
8195
7595
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8196
7596
|
additionalSigners: additionalSigners
|
@@ -8199,7 +7599,7 @@ var PerpetualsClient = (function () {
|
|
8199
7599
|
});
|
8200
7600
|
}); };
|
8201
7601
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8202
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
7602
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_59;
|
8203
7603
|
return __generator(this, function (_a) {
|
8204
7604
|
switch (_a.label) {
|
8205
7605
|
case 0:
|
@@ -8231,9 +7631,49 @@ var PerpetualsClient = (function () {
|
|
8231
7631
|
instructions.push(setTokenRewardInstruction);
|
8232
7632
|
return [3, 4];
|
8233
7633
|
case 3:
|
8234
|
-
|
8235
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
8236
|
-
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;
|
8237
7677
|
case 4: return [2, {
|
8238
7678
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8239
7679
|
additionalSigners: additionalSigners
|