flash-sdk 9.0.0-alpha.6 → 9.0.0-alpha.7
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 +38 -49
- package/dist/PerpetualsClient.js +468 -1024
- package/dist/PoolConfig.d.ts +2 -0
- package/dist/PoolConfig.json +244 -10
- package/dist/idl/perpetuals.d.ts +70 -490
- package/dist/idl/perpetuals.js +70 -490
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +0 -2
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -638,24 +638,42 @@ 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, finalCollateralAmount, 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.collateralAmount = finalCollateralAmount;
|
666
|
+
positionAccount.collateralUsd = collateralPrice.getAssetAmountUsd(finalCollateralAmount, collateralCustodyAccount.decimals);
|
667
|
+
return _this.getLeverageContractHelper(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig);
|
668
|
+
};
|
669
|
+
this.getLeverageAtAmountEntryWithSwapSync = function (positionAccount, inputDeltaAmount, sizeDeltaAmount, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig, pnlUsd) {
|
652
670
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
653
671
|
if (!inputDeltaAmount.isZero()) {
|
654
672
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
655
673
|
finalCollateralAmount = inputDeltaAmount;
|
656
674
|
}
|
657
675
|
else {
|
658
|
-
var swapAmountOut = _this.getSwapAmountAndFeesSync(inputDeltaAmount, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
676
|
+
var swapAmountOut = _this.getSwapAmountAndFeesSync(inputDeltaAmount, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountOut;
|
659
677
|
finalCollateralAmount = swapAmountOut;
|
660
678
|
}
|
661
679
|
}
|
@@ -681,9 +699,8 @@ var PerpetualsClient = (function () {
|
|
681
699
|
entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
|
682
700
|
}
|
683
701
|
var collateralMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
684
|
-
var
|
685
|
-
var
|
686
|
-
var currentCollateralUsdIncludingPnl = currentCollateralUsd.add(pnlUsd).sub(openFeeUsd);
|
702
|
+
var finalCollateralUsd = collateralMinOraclePrice.getAssetAmountUsd(finalCollateralAmount, collateralTokenCustodyAccount.decimals);
|
703
|
+
var currentCollateralUsdIncludingPnl = finalCollateralUsd.add(pnlUsd).sub(openFeeUsd);
|
687
704
|
var sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
688
705
|
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
689
706
|
if (currentCollateralUsdIncludingPnl.gt(constants_1.BN_ZERO)) {
|
@@ -693,68 +710,6 @@ var PerpetualsClient = (function () {
|
|
693
710
|
return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
|
694
711
|
}
|
695
712
|
};
|
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
713
|
this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
|
759
714
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
760
715
|
if (enableLogs === void 0) { enableLogs = false; }
|
@@ -766,8 +721,8 @@ var PerpetualsClient = (function () {
|
|
766
721
|
if (positionAccount === null) {
|
767
722
|
var data = __assign({}, types_1.DEFAULT_POSITION);
|
768
723
|
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
769
|
-
var
|
770
|
-
positionAccount.sizeUsd =
|
724
|
+
var sizeUsd_1 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
725
|
+
positionAccount.sizeUsd = sizeUsd_1;
|
771
726
|
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
772
727
|
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
773
728
|
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
@@ -784,12 +739,13 @@ var PerpetualsClient = (function () {
|
|
784
739
|
var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
785
740
|
positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
|
786
741
|
}
|
787
|
-
|
742
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
743
|
+
var collateralDeltaUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
744
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
788
745
|
positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
789
|
-
var
|
790
|
-
var liquidationPrice = _this.getLiquidationPriceSync(
|
746
|
+
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
747
|
+
var liquidationPrice = _this.getLiquidationPriceSync(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
791
748
|
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
792
|
-
var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
793
749
|
var feeUsd = constants_1.BN_ZERO;
|
794
750
|
var feeAmount = constants_1.BN_ZERO;
|
795
751
|
var feeUsdAfterDiscount = constants_1.BN_ZERO;
|
@@ -798,11 +754,11 @@ var PerpetualsClient = (function () {
|
|
798
754
|
}
|
799
755
|
else {
|
800
756
|
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(
|
757
|
+
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralMinMaxPrice.min.price);
|
802
758
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
803
759
|
feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
804
760
|
feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
|
805
|
-
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(
|
761
|
+
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralMinMaxPrice.min.price);
|
806
762
|
}
|
807
763
|
else {
|
808
764
|
feeUsdAfterDiscount = feeUsd;
|
@@ -861,25 +817,26 @@ var PerpetualsClient = (function () {
|
|
861
817
|
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
862
818
|
throw new Error("Delta Amounts cannot be negative ");
|
863
819
|
}
|
864
|
-
resultingPositionAccount.collateralAmount = resultingPositionAccount.collateralAmount.sub(collateralDeltaAmount);
|
865
|
-
resultingPositionAccount.sizeAmount = resultingPositionAccount.sizeAmount.sub(sizeDeltaAmount);
|
866
820
|
if (resultingPositionAccount.collateralAmount.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
|
867
821
|
throw new Error("cannot remove/close more than collateral/Size");
|
868
822
|
}
|
869
823
|
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
870
824
|
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
871
|
-
var
|
825
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
826
|
+
var collateralDeltaUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
827
|
+
resultingPositionAccount.collateralUsd = resultingPositionAccount.collateralUsd.sub(collateralDeltaUsd);
|
828
|
+
resultingPositionAccount.sizeAmount = resultingPositionAccount.sizeAmount.sub(sizeDeltaAmount);
|
872
829
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(resultingPositionAccount, collateralCustodyAccount, currentTimestamp);
|
873
|
-
var lockAndUnsettledFee =
|
830
|
+
var lockAndUnsettledFee = collateralMinMaxPrice.min.getTokenAmount(lockAndUnsettledFeeUsd, collateralCustodyAccount.decimals);
|
874
831
|
var sizeAmountUsd = exitOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
875
832
|
var exitFeeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
876
|
-
var exitFeeAmount =
|
833
|
+
var exitFeeAmount = collateralMinMaxPrice.max.getTokenAmount(exitFeeUsd, collateralCustodyAccount.decimals);
|
877
834
|
var exitFeeUsdAfterDiscount = constants_1.BN_ZERO;
|
878
835
|
var exitFeeAmountAfterDiscount = constants_1.BN_ZERO;
|
879
836
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
880
837
|
exitFeeUsdAfterDiscount = exitFeeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
881
838
|
exitFeeUsdAfterDiscount = exitFeeUsd.sub(exitFeeUsdAfterDiscount);
|
882
|
-
exitFeeAmountAfterDiscount =
|
839
|
+
exitFeeAmountAfterDiscount = collateralMinMaxPrice.max.getTokenAmount(exitFeeUsdAfterDiscount, collateralCustodyAccount.decimals);
|
883
840
|
}
|
884
841
|
else {
|
885
842
|
exitFeeUsdAfterDiscount = exitFeeUsd;
|
@@ -889,7 +846,7 @@ var PerpetualsClient = (function () {
|
|
889
846
|
price: positionAccount.entryPrice.price, exponent: new anchor_1.BN(positionAccount.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO
|
890
847
|
});
|
891
848
|
resultingPositionAccount.sizeUsd = positionEntryOraclePrice.getAssetAmountUsd(resultingPositionAccount.sizeAmount, targetCustodyAccount.decimals);
|
892
|
-
var liquidationPrice = _this.getLiquidationPriceSync(
|
849
|
+
var liquidationPrice = _this.getLiquidationPriceSync(positionEntryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
893
850
|
return {
|
894
851
|
exitOraclePrice: exitOraclePrice,
|
895
852
|
borrowFeeUsd: lockAndUnsettledFeeUsd,
|
@@ -902,9 +859,7 @@ var PerpetualsClient = (function () {
|
|
902
859
|
};
|
903
860
|
};
|
904
861
|
this.getTradeSpread = function (targetCustodyAccount, sizeUsd) {
|
905
|
-
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero()
|
906
|
-
||
|
907
|
-
sizeUsd.isZero()) {
|
862
|
+
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero() || sizeUsd.isZero()) {
|
908
863
|
return constants_1.BN_ZERO;
|
909
864
|
}
|
910
865
|
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 +878,11 @@ var PerpetualsClient = (function () {
|
|
923
878
|
var exitOraclePrice = OraclePrice_1.OraclePrice.from({ price: exitPriceBN, exponent: maxPrice.exponent, confidence: maxPrice.confidence, timestamp: maxPrice.timestamp });
|
924
879
|
return exitOraclePrice;
|
925
880
|
};
|
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
881
|
this.getSizeAmountFromLeverageAndCollateral = function (collateralAmtWithFee, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
|
936
882
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
937
883
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
938
884
|
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);
|
885
|
+
var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals)).multipliedBy(collateralTokenMinPriceUi);
|
941
886
|
var openPosFeeRateUi = new bignumber_js_1.default(targetCustodyAccount.fees.openPosition.toString()).dividedBy(Math.pow(10, constants_1.RATE_DECIMALS));
|
942
887
|
if (!discountBps.isZero()) {
|
943
888
|
var discountBpsUi = new bignumber_js_1.default(discountBps.toString()).dividedBy(Math.pow(10, constants_1.BPS_DECIMALS));
|
@@ -945,20 +890,20 @@ var PerpetualsClient = (function () {
|
|
945
890
|
}
|
946
891
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
947
892
|
.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,
|
893
|
+
var sizeUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toString(), constants_1.USD_DECIMALS);
|
894
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
950
895
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
951
896
|
var sizeAmountUi = sizeUsdUi.dividedBy(entryPriceUsdUi);
|
952
897
|
return (0, utils_1.uiDecimalsToNative)(sizeAmountUi.toFixed(marketToken.decimals, bignumber_js_1.default.ROUND_DOWN), marketToken.decimals);
|
953
898
|
};
|
954
|
-
this.getSizeAmountWithSwapSync = function (amountIn, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax,
|
899
|
+
this.getSizeAmountWithSwapSync = function (amountIn, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig, discountBps) {
|
955
900
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
956
901
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
957
902
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
958
903
|
finalCollateralAmount = amountIn;
|
959
904
|
}
|
960
905
|
else {
|
961
|
-
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
906
|
+
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountOut;
|
962
907
|
finalCollateralAmount = swapAmountOut;
|
963
908
|
}
|
964
909
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
@@ -972,8 +917,8 @@ var PerpetualsClient = (function () {
|
|
972
917
|
}
|
973
918
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
974
919
|
.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,
|
920
|
+
var sizeUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toFixed(constants_1.USD_DECIMALS), constants_1.USD_DECIMALS);
|
921
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
|
977
922
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
978
923
|
var sizeAmountUi = sizeUsdUi.dividedBy(entryPriceUsdUi);
|
979
924
|
return (0, utils_1.uiDecimalsToNative)(sizeAmountUi.toFixed(targetTokenCustodyAccount.decimals, bignumber_js_1.default.ROUND_DOWN), targetTokenCustodyAccount.decimals);
|
@@ -996,7 +941,7 @@ var PerpetualsClient = (function () {
|
|
996
941
|
var collateralAmtWithFeeUi = collateralWithFeeUsdUi.dividedBy(collateralTokenMinPriceUi);
|
997
942
|
return (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralToken.decimals, bignumber_js_1.default.ROUND_DOWN), collateralToken.decimals);
|
998
943
|
};
|
999
|
-
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax,
|
944
|
+
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig) {
|
1000
945
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
1001
946
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
1002
947
|
var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
@@ -1013,7 +958,7 @@ var PerpetualsClient = (function () {
|
|
1013
958
|
collateralInInputToken = collateralAmountWithFee;
|
1014
959
|
}
|
1015
960
|
else {
|
1016
|
-
collateralInInputToken = _this.getSwapAmountAndFeesSync(constants_1.BN_ZERO, collateralAmountWithFee, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
961
|
+
collateralInInputToken = _this.getSwapAmountAndFeesSync(constants_1.BN_ZERO, collateralAmountWithFee, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountIn;
|
1017
962
|
}
|
1018
963
|
return collateralInInputToken;
|
1019
964
|
};
|
@@ -1039,10 +984,10 @@ var PerpetualsClient = (function () {
|
|
1039
984
|
var decimalPower = new anchor_1.BN(Math.pow(10, targetCustodyAccount.decimals));
|
1040
985
|
var closeRatio = (positionDelta.sizeAmount.mul(decimalPower)).div(positionAccount.sizeAmount);
|
1041
986
|
positionDelta.sizeUsd = (positionAccount.sizeUsd.mul(closeRatio)).div(decimalPower);
|
1042
|
-
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
1043
987
|
positionDelta.lockedAmount = (positionAccount.lockedAmount.mul(closeRatio)).div(decimalPower);
|
1044
988
|
positionDelta.lockedUsd = (positionAccount.lockedUsd.mul(closeRatio)).div(decimalPower);
|
1045
|
-
positionDelta.
|
989
|
+
positionDelta.collateralUsd = (positionAccount.collateralUsd.mul(closeRatio)).div(decimalPower);
|
990
|
+
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
1046
991
|
positionDelta.degenSizeUsd = positionAccount.degenSizeUsd.mul(closeRatio).div(decimalPower);
|
1047
992
|
var newPnl = _this.getPnlSync(positionDelta, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1048
993
|
var exitFeeUsd = positionDelta.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
@@ -1052,29 +997,29 @@ var PerpetualsClient = (function () {
|
|
1052
997
|
}
|
1053
998
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionDelta, collateralCustodyAccount, currentTimestamp);
|
1054
999
|
var totalFeesUsd = (exitFeeUsd.add(lockAndUnsettledFeeUsd));
|
1055
|
-
var currentCollateralUsd =
|
1000
|
+
var currentCollateralUsd = positionDelta.collateralUsd;
|
1056
1001
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
1057
|
-
var assetsUsd = newPnl.profitUsd.add(currentCollateralUsd);
|
1058
|
-
var closeAmount, feesAmount;
|
1002
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
|
1059
1003
|
if (debugLogs) {
|
1060
1004
|
console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
|
1061
1005
|
}
|
1006
|
+
var closeAmountUsd, feesAmountUsd;
|
1062
1007
|
if (assetsUsd.gte(liabilityUsd)) {
|
1063
|
-
|
1064
|
-
|
1008
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
1009
|
+
feesAmountUsd = totalFeesUsd;
|
1065
1010
|
}
|
1066
1011
|
else {
|
1067
|
-
|
1068
|
-
|
1012
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
1013
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
1069
1014
|
}
|
1015
|
+
var closeAmount = collateralMinMaxPrice.max.getTokenAmount(closeAmountUsd, collateralCustodyAccount.decimals);
|
1070
1016
|
var newPosition = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
1071
1017
|
newPosition.sizeAmount = positionAccount.sizeAmount.sub(positionDelta.sizeAmount);
|
1072
1018
|
newPosition.sizeUsd = positionAccount.sizeUsd.sub(positionDelta.sizeUsd);
|
1073
1019
|
newPosition.lockedUsd = positionAccount.lockedUsd.sub(positionDelta.lockedUsd);
|
1074
1020
|
newPosition.lockedAmount = positionAccount.lockedAmount.sub(positionDelta.lockedAmount);
|
1075
|
-
newPosition.
|
1021
|
+
newPosition.collateralUsd = positionAccount.collateralUsd.sub(positionDelta.collateralUsd);
|
1076
1022
|
newPosition.unsettledFeesUsd = positionAccount.unsettledFeesUsd.sub(positionDelta.unsettledFeesUsd);
|
1077
|
-
newPosition.collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(newPosition.collateralAmount, collateralCustodyAccount.decimals);
|
1078
1023
|
newPosition.degenSizeUsd = positionAccount.degenSizeUsd.sub(positionDelta.degenSizeUsd);
|
1079
1024
|
var feeUsdWithDiscount = constants_1.BN_ZERO;
|
1080
1025
|
var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
@@ -1089,8 +1034,8 @@ var PerpetualsClient = (function () {
|
|
1089
1034
|
feeUsdWithDiscount = feeUsdWithDiscount.add(lockAndUnsettledFeeUsd);
|
1090
1035
|
if (keepLevSame) {
|
1091
1036
|
var collateralAmountReceived = closeAmount;
|
1092
|
-
var collateralAmountRecievedUsd =
|
1093
|
-
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
1037
|
+
var collateralAmountRecievedUsd = closeAmountUsd;
|
1038
|
+
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmountUsd), maxWithdrawableAmount = _a.maxWithdrawableAmount, diff = _a.diff;
|
1094
1039
|
if (debugLogs) {
|
1095
1040
|
console.log("maxWithdrawableAmount ", maxWithdrawableAmount.toString(), keepLevSame);
|
1096
1041
|
console.log("collateralAmountReceived ", collateralAmountReceived.toString(), keepLevSame);
|
@@ -1107,11 +1052,11 @@ var PerpetualsClient = (function () {
|
|
1107
1052
|
collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(maxWithdrawableAmount, collateralCustodyAccount.decimals);
|
1108
1053
|
}
|
1109
1054
|
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.getLiquidationPriceSync(
|
1055
|
+
var lockAndUnsettledFeeUsdNew = _this.getLockFeeAndUnsettledUsdForPosition(newPosition, collateralCustodyAccount, currentTimestamp);
|
1056
|
+
var finalLiquidationPrice = _this.getLiquidationPriceSync(entryPrice, lockAndUnsettledFeeUsdNew, side, targetCustodyAccount, newPosition);
|
1112
1057
|
var finalPnl = _this.getPnlSync(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1113
1058
|
var finalPnlUsd = finalPnl.profitUsd.sub(finalPnl.lossUsd);
|
1114
|
-
var newLev = _this.getLeverageSync(newPosition
|
1059
|
+
var newLev = _this.getLeverageSync(newPosition, newPosition.collateralUsd, newPosition.sizeUsd, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, false, poolConfig);
|
1115
1060
|
return {
|
1116
1061
|
newSizeUsd: newPosition.sizeUsd,
|
1117
1062
|
feeUsd: feeUsd,
|
@@ -1129,8 +1074,8 @@ var PerpetualsClient = (function () {
|
|
1129
1074
|
throw "only same leverage is supported for now";
|
1130
1075
|
}
|
1131
1076
|
};
|
1132
|
-
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
1133
|
-
if (
|
1077
|
+
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmountUsd, errorBandwidthPercentageUi) {
|
1078
|
+
if (closeAmountUsd === void 0) { closeAmountUsd = constants_1.BN_ZERO; }
|
1134
1079
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
1135
1080
|
if (errorBandwidthPercentageUi > 100 || errorBandwidthPercentageUi < 0) {
|
1136
1081
|
throw new Error("errorBandwidthPercentageUi cannot be >100 or <0");
|
@@ -1139,11 +1084,11 @@ var PerpetualsClient = (function () {
|
|
1139
1084
|
(new anchor_1.BN(targetCustodyAccount.pricing.maxInitDegenLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100))
|
1140
1085
|
: (new anchor_1.BN(targetCustodyAccount.pricing.maxInitLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100));
|
1141
1086
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1142
|
-
var
|
1087
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1143
1088
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1144
1089
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1145
1090
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
1146
|
-
var currentCollateralUsd =
|
1091
|
+
var currentCollateralUsd = positionAccount.collateralUsd.sub(closeAmountUsd);
|
1147
1092
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
1148
1093
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
1149
1094
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
@@ -1168,35 +1113,34 @@ var PerpetualsClient = (function () {
|
|
1168
1113
|
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1169
1114
|
}
|
1170
1115
|
else {
|
1171
|
-
maxWithdrawableAmount =
|
1116
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(updatedMaxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1172
1117
|
maxWithdrawableAmountUsd = updatedMaxRemovableCollateralUsd;
|
1173
1118
|
}
|
1174
1119
|
}
|
1175
1120
|
else {
|
1176
|
-
maxWithdrawableAmount =
|
1121
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1177
1122
|
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
1178
1123
|
}
|
1179
1124
|
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd, diff: diff };
|
1180
1125
|
};
|
1181
|
-
this.
|
1126
|
+
this.getFinalCloseAmountUsdSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
|
1182
1127
|
var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
1183
1128
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1184
|
-
var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
|
1185
1129
|
var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1186
1130
|
var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
|
1187
1131
|
var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
|
1188
1132
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
1189
|
-
var assetsUsd = newPnl.profitUsd.add(collateralMinMaxPrice.
|
1190
|
-
var
|
1133
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
|
1134
|
+
var closeAmountUsd, feesAmountUsd;
|
1191
1135
|
if (assetsUsd.gt(liabilityUsd)) {
|
1192
|
-
|
1193
|
-
|
1136
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
1137
|
+
feesAmountUsd = totalFeesUsd;
|
1194
1138
|
}
|
1195
1139
|
else {
|
1196
|
-
|
1197
|
-
|
1140
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
1141
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
1198
1142
|
}
|
1199
|
-
return {
|
1143
|
+
return { closeAmountUsd: closeAmountUsd, feesAmountUsd: feesAmountUsd };
|
1200
1144
|
};
|
1201
1145
|
this.getMaxWithdrawableAmountSync = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, errorBandwidthPercentageUi) {
|
1202
1146
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
@@ -1212,11 +1156,11 @@ var PerpetualsClient = (function () {
|
|
1212
1156
|
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
1213
1157
|
}
|
1214
1158
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1215
|
-
var
|
1159
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1216
1160
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1217
1161
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1218
1162
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
1219
|
-
var currentCollateralUsd =
|
1163
|
+
var currentCollateralUsd = positionAccount.collateralUsd;
|
1220
1164
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
1221
1165
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
1222
1166
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
@@ -1232,11 +1176,11 @@ var PerpetualsClient = (function () {
|
|
1232
1176
|
var maxWithdrawableAmount;
|
1233
1177
|
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
1234
1178
|
if (maxRemoveableCollateralUsdAfterMinRequired.lt(maxRemovableCollateralUsd)) {
|
1235
|
-
maxWithdrawableAmount =
|
1179
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemoveableCollateralUsdAfterMinRequired, collateralCustodyAccount.decimals);
|
1236
1180
|
maxWithdrawableAmountUsd = maxRemoveableCollateralUsdAfterMinRequired;
|
1237
1181
|
}
|
1238
1182
|
else {
|
1239
|
-
maxWithdrawableAmount =
|
1183
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1240
1184
|
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
1241
1185
|
}
|
1242
1186
|
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd };
|
@@ -1293,185 +1237,131 @@ var PerpetualsClient = (function () {
|
|
1293
1237
|
var lockedUsd = (sideUsd.mul(maxPayOffBpsNew)).div(new anchor_1.BN(constants_1.BPS_POWER));
|
1294
1238
|
return lockedUsd;
|
1295
1239
|
};
|
1296
|
-
this.getLiquidationPriceSync = function (
|
1240
|
+
this.getLiquidationPriceSync = function (entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount) {
|
1297
1241
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
1298
1242
|
price: constants_1.BN_ZERO,
|
1299
1243
|
exponent: constants_1.BN_ZERO,
|
1300
1244
|
confidence: constants_1.BN_ZERO,
|
1301
1245
|
timestamp: constants_1.BN_ZERO
|
1302
1246
|
});
|
1303
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
1304
|
-
return zeroOraclePrice;
|
1305
|
-
}
|
1306
1247
|
if (positionAccount.entryPrice.exponent && !entryOraclePrice.exponent.eq(new anchor_1.BN(positionAccount.entryPrice.exponent))) {
|
1307
1248
|
throw new Error("Exponent mismatch : ".concat(positionAccount.entryPrice.exponent, " & ").concat(entryOraclePrice.exponent.toString(), " ").concat(entryOraclePrice === null || entryOraclePrice === void 0 ? void 0 : entryOraclePrice.toUiPrice(8)));
|
1308
1249
|
}
|
1309
1250
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1310
1251
|
var unsettledLossUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
|
1311
1252
|
var liablitiesUsd = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
1312
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
1313
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1314
1253
|
var liquidationPrice;
|
1315
|
-
if (
|
1316
|
-
var
|
1317
|
-
|
1318
|
-
|
1254
|
+
if (positionAccount.collateralUsd.gte(liablitiesUsd)) {
|
1255
|
+
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1256
|
+
price: (positionAccount.collateralUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1257
|
+
.div(positionAccount.sizeAmount),
|
1258
|
+
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1259
|
+
confidence: constants_1.BN_ZERO,
|
1260
|
+
timestamp: constants_1.BN_ZERO
|
1261
|
+
}).scale_to_exponent(new anchor_1.BN(entryOraclePrice.exponent));
|
1262
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1263
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1264
|
+
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
1265
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1266
|
+
confidence: constants_1.BN_ZERO,
|
1267
|
+
timestamp: constants_1.BN_ZERO
|
1268
|
+
});
|
1319
1269
|
}
|
1320
1270
|
else {
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1271
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1272
|
+
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
1273
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1274
|
+
confidence: constants_1.BN_ZERO,
|
1275
|
+
timestamp: constants_1.BN_ZERO
|
1276
|
+
});
|
1324
1277
|
}
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1278
|
+
}
|
1279
|
+
else {
|
1280
|
+
var priceDiffProfitOracle = OraclePrice_1.OraclePrice.from({
|
1281
|
+
price: (liablitiesUsd.sub(positionAccount.collateralUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1282
|
+
.div(positionAccount.sizeAmount),
|
1328
1283
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1329
1284
|
confidence: constants_1.BN_ZERO,
|
1330
1285
|
timestamp: constants_1.BN_ZERO
|
1331
|
-
});
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
1337
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1338
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
1339
|
-
.div(positionAccount.sizeAmount),
|
1340
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1286
|
+
}).scale_to_exponent(new anchor_1.BN(entryOraclePrice.exponent));
|
1287
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1288
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1289
|
+
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
1290
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1341
1291
|
confidence: constants_1.BN_ZERO,
|
1342
1292
|
timestamp: constants_1.BN_ZERO
|
1343
|
-
})
|
1344
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1345
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1346
|
-
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
1347
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1348
|
-
confidence: constants_1.BN_ZERO,
|
1349
|
-
timestamp: constants_1.BN_ZERO
|
1350
|
-
});
|
1351
|
-
}
|
1352
|
-
else {
|
1353
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1354
|
-
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
1355
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1356
|
-
confidence: constants_1.BN_ZERO,
|
1357
|
-
timestamp: constants_1.BN_ZERO
|
1358
|
-
});
|
1359
|
-
}
|
1293
|
+
});
|
1360
1294
|
}
|
1361
1295
|
else {
|
1362
|
-
|
1363
|
-
price:
|
1364
|
-
|
1365
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1296
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1297
|
+
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1298
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1366
1299
|
confidence: constants_1.BN_ZERO,
|
1367
1300
|
timestamp: constants_1.BN_ZERO
|
1368
|
-
})
|
1369
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1370
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1371
|
-
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
1372
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1373
|
-
confidence: constants_1.BN_ZERO,
|
1374
|
-
timestamp: constants_1.BN_ZERO
|
1375
|
-
});
|
1376
|
-
}
|
1377
|
-
else {
|
1378
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1379
|
-
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1380
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
1381
|
-
confidence: constants_1.BN_ZERO,
|
1382
|
-
timestamp: constants_1.BN_ZERO
|
1383
|
-
});
|
1384
|
-
}
|
1301
|
+
});
|
1385
1302
|
}
|
1386
1303
|
}
|
1387
1304
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
1388
1305
|
};
|
1389
|
-
this.getLiquidationPriceWithOrder = function (
|
1306
|
+
this.getLiquidationPriceWithOrder = function (collateralUsd, sizeAmount, sizeUsd, sizeDecimals, limitOraclePrice, side, targetCustodyAccount) {
|
1390
1307
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
1391
1308
|
price: constants_1.BN_ZERO,
|
1392
1309
|
exponent: constants_1.BN_ZERO,
|
1393
1310
|
confidence: constants_1.BN_ZERO,
|
1394
1311
|
timestamp: constants_1.BN_ZERO
|
1395
1312
|
});
|
1396
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
1397
|
-
return zeroOraclePrice;
|
1398
|
-
}
|
1399
1313
|
var exitFeeUsd = sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1400
1314
|
var unsettledLossUsd = exitFeeUsd;
|
1401
1315
|
var liablitiesUsd = sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
1402
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
1403
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
1404
1316
|
var liquidationPrice;
|
1405
|
-
if (
|
1406
|
-
var
|
1407
|
-
|
1408
|
-
|
1317
|
+
if (collateralUsd.gte(liablitiesUsd)) {
|
1318
|
+
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1319
|
+
price: (collateralUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1320
|
+
.div(sizeAmount),
|
1321
|
+
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1322
|
+
confidence: constants_1.BN_ZERO,
|
1323
|
+
timestamp: constants_1.BN_ZERO
|
1324
|
+
}).scale_to_exponent(new anchor_1.BN(limitOraclePrice.exponent));
|
1325
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1326
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1327
|
+
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
1328
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1329
|
+
confidence: constants_1.BN_ZERO,
|
1330
|
+
timestamp: constants_1.BN_ZERO
|
1331
|
+
});
|
1409
1332
|
}
|
1410
1333
|
else {
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1334
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1335
|
+
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
1336
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1337
|
+
confidence: constants_1.BN_ZERO,
|
1338
|
+
timestamp: constants_1.BN_ZERO
|
1339
|
+
});
|
1414
1340
|
}
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1341
|
+
}
|
1342
|
+
else {
|
1343
|
+
var priceDiffProfitOracle = OraclePrice_1.OraclePrice.from({
|
1344
|
+
price: (liablitiesUsd.sub(collateralUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1345
|
+
.div(sizeAmount),
|
1418
1346
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1419
1347
|
confidence: constants_1.BN_ZERO,
|
1420
1348
|
timestamp: constants_1.BN_ZERO
|
1421
|
-
});
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
1427
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
1428
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
1429
|
-
.div(sizeAmount),
|
1430
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1349
|
+
}).scale_to_exponent(new anchor_1.BN(limitOraclePrice.exponent));
|
1350
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
1351
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1352
|
+
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
1353
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1431
1354
|
confidence: constants_1.BN_ZERO,
|
1432
1355
|
timestamp: constants_1.BN_ZERO
|
1433
|
-
})
|
1434
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1435
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1436
|
-
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
1437
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1438
|
-
confidence: constants_1.BN_ZERO,
|
1439
|
-
timestamp: constants_1.BN_ZERO
|
1440
|
-
});
|
1441
|
-
}
|
1442
|
-
else {
|
1443
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1444
|
-
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
1445
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1446
|
-
confidence: constants_1.BN_ZERO,
|
1447
|
-
timestamp: constants_1.BN_ZERO
|
1448
|
-
});
|
1449
|
-
}
|
1356
|
+
});
|
1450
1357
|
}
|
1451
1358
|
else {
|
1452
|
-
|
1453
|
-
price:
|
1454
|
-
|
1455
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
1359
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1360
|
+
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1361
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1456
1362
|
confidence: constants_1.BN_ZERO,
|
1457
1363
|
timestamp: constants_1.BN_ZERO
|
1458
|
-
})
|
1459
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
1460
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1461
|
-
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
1462
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1463
|
-
confidence: constants_1.BN_ZERO,
|
1464
|
-
timestamp: constants_1.BN_ZERO
|
1465
|
-
});
|
1466
|
-
}
|
1467
|
-
else {
|
1468
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
1469
|
-
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
1470
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
1471
|
-
confidence: constants_1.BN_ZERO,
|
1472
|
-
timestamp: constants_1.BN_ZERO
|
1473
|
-
});
|
1474
|
-
}
|
1364
|
+
});
|
1475
1365
|
}
|
1476
1366
|
}
|
1477
1367
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
@@ -1547,8 +1437,8 @@ var PerpetualsClient = (function () {
|
|
1547
1437
|
positionAccount.market = marketAccountPk;
|
1548
1438
|
positionAccount.lockedUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
|
1549
1439
|
positionAccount.lockedAmount = collateralPrice.getTokenAmount(positionAccount.lockedUsd, collateralCustodyAccount.decimals);
|
1550
|
-
|
1551
|
-
positionAccount.collateralUsd =
|
1440
|
+
var collateralDeltaUsd = collateralPrice.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
1441
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
1552
1442
|
var currentTime = new anchor_1.BN((0, utils_1.getUnixTs)());
|
1553
1443
|
var pnl = _this.getPnlSync(positionAccount, userEntrytpSlOraclePrice, userEntrytpSlOraclePrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTime, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1554
1444
|
var pnlUsd = pnl.profitUsd.sub(pnl.lossUsd);
|
@@ -1620,6 +1510,9 @@ var PerpetualsClient = (function () {
|
|
1620
1510
|
});
|
1621
1511
|
};
|
1622
1512
|
this.getPnlSync = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig) {
|
1513
|
+
return _this.getPnlContractHelper(positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig);
|
1514
|
+
};
|
1515
|
+
this.getPnlContractHelper = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig) {
|
1623
1516
|
if (positionAccount.sizeUsd.isZero() || positionAccount.entryPrice.price.isZero()) {
|
1624
1517
|
return {
|
1625
1518
|
profitUsd: constants_1.BN_ZERO,
|
@@ -1678,7 +1571,7 @@ var PerpetualsClient = (function () {
|
|
1678
1571
|
}
|
1679
1572
|
if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
|
1680
1573
|
return {
|
1681
|
-
profitUsd:
|
1574
|
+
profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
|
1682
1575
|
lossUsd: constants_1.BN_ZERO,
|
1683
1576
|
};
|
1684
1577
|
}
|
@@ -1769,6 +1662,9 @@ var PerpetualsClient = (function () {
|
|
1769
1662
|
}
|
1770
1663
|
};
|
1771
1664
|
this.getAssetsUnderManagementUsdSync = function (poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig) {
|
1665
|
+
return _this.getAssetsUnderManagementUsdContractHelper(poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig);
|
1666
|
+
};
|
1667
|
+
this.getAssetsUnderManagementUsdContractHelper = function (poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig) {
|
1772
1668
|
var poolAmountUsd = constants_1.BN_ZERO;
|
1773
1669
|
for (var index = 0; index < custodies.length; index++) {
|
1774
1670
|
if (custodies.length != poolAccount.custodies.length || !custodies[index].publicKey.equals(poolAccount.custodies[index])) {
|
@@ -1781,6 +1677,7 @@ var PerpetualsClient = (function () {
|
|
1781
1677
|
var token_amount_usd = tokenMinMaxPrice.max.getAssetAmountUsd(custodies[index].assets.owned, custodies[index].decimals);
|
1782
1678
|
poolAmountUsd = poolAmountUsd.add(token_amount_usd);
|
1783
1679
|
}
|
1680
|
+
poolAmountUsd = poolAmountUsd.sub(poolAccount.feesObligationUsd.add(poolAccount.rebateObligationUsd));
|
1784
1681
|
if (aumCalcMode === "includePnl") {
|
1785
1682
|
var poolEquityUsd = poolAmountUsd;
|
1786
1683
|
for (var index = 0; index < markets.length; index++) {
|
@@ -1790,11 +1687,12 @@ var PerpetualsClient = (function () {
|
|
1790
1687
|
var targetCustodyId = poolAccount.getCustodyId(markets[index].targetCustody);
|
1791
1688
|
var collateralCustodyId = poolAccount.getCustodyId(markets[index].collateralCustody);
|
1792
1689
|
var position = markets[index].getCollectivePosition();
|
1690
|
+
poolEquityUsd = poolEquityUsd.sub(position.collateralUsd);
|
1793
1691
|
var collectivePnl = _this.getPnlSync(position, tokenPrices[targetCustodyId], tokenEmaPrices[targetCustodyId], custodies[targetCustodyId], tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId], currentTime, custodies[targetCustodyId].pricing.delaySeconds, poolConfig);
|
1794
1692
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId]);
|
1795
|
-
var
|
1796
|
-
var
|
1797
|
-
poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(
|
1693
|
+
var collectiveLossUsd = anchor_1.BN.min(collectivePnl.lossUsd, position.collateralUsd);
|
1694
|
+
var collectiveProfitUsd = anchor_1.BN.min(collectivePnl.profitUsd, collateralMinMaxPrice.max.getAssetAmountUsd(position.lockedAmount, custodies[collateralCustodyId].decimals).sub(position.collateralUsd));
|
1695
|
+
poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(collectiveProfitUsd);
|
1798
1696
|
}
|
1799
1697
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: poolEquityUsd };
|
1800
1698
|
}
|
@@ -1802,14 +1700,6 @@ var PerpetualsClient = (function () {
|
|
1802
1700
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: constants_1.BN_ZERO };
|
1803
1701
|
}
|
1804
1702
|
};
|
1805
|
-
this.getNftFinalDiscount = function (perpetualsAccount, nftTradingAccount, currentTime) {
|
1806
|
-
if (currentTime.sub(nftTradingAccount.timestamp).lt(constants_1.DAY_SECONDS) && nftTradingAccount.counter.gt(new anchor_1.BN(perpetualsAccount.tradeLimit))) {
|
1807
|
-
return { discountBn: constants_1.BN_ZERO };
|
1808
|
-
}
|
1809
|
-
else {
|
1810
|
-
return { discountBn: perpetualsAccount.tradingDiscount[nftTradingAccount.level - 1] };
|
1811
|
-
}
|
1812
|
-
};
|
1813
1703
|
this.getFeeDiscount = function (perpetualsAccount, tokenStakeAccount, currentTime) {
|
1814
1704
|
if (tokenStakeAccount.level === 0) {
|
1815
1705
|
return { discountBn: constants_1.BN_ZERO };
|
@@ -1894,7 +1784,7 @@ var PerpetualsClient = (function () {
|
|
1894
1784
|
});
|
1895
1785
|
};
|
1896
1786
|
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1897
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
|
1787
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
|
1898
1788
|
var _d;
|
1899
1789
|
return __generator(this, function (_e) {
|
1900
1790
|
switch (_e.label) {
|
@@ -1942,6 +1832,8 @@ var PerpetualsClient = (function () {
|
|
1942
1832
|
return [4, backUpOracleInstructionPromise];
|
1943
1833
|
case 2:
|
1944
1834
|
backUpOracleInstruction = _e.sent();
|
1835
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
1836
|
+
transaction.instructions.unshift(setCULimitIx);
|
1945
1837
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1946
1838
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1947
1839
|
case 3:
|
@@ -2008,7 +1900,7 @@ var PerpetualsClient = (function () {
|
|
2008
1900
|
args_1[_i - 4] = arguments[_i];
|
2009
1901
|
}
|
2010
1902
|
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) {
|
2011
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
1903
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2012
1904
|
var _e;
|
2013
1905
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2014
1906
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2059,6 +1951,8 @@ var PerpetualsClient = (function () {
|
|
2059
1951
|
.transaction()];
|
2060
1952
|
case 1:
|
2061
1953
|
transaction = _f.sent();
|
1954
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
1955
|
+
transaction.instructions.unshift(setCULimitIx);
|
2062
1956
|
if (!enableBackupOracle) return [3, 3];
|
2063
1957
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2064
1958
|
case 2:
|
@@ -2084,7 +1978,7 @@ var PerpetualsClient = (function () {
|
|
2084
1978
|
args_1[_i - 4] = arguments[_i];
|
2085
1979
|
}
|
2086
1980
|
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) {
|
2087
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
1981
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2088
1982
|
var _e;
|
2089
1983
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2090
1984
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2135,6 +2029,8 @@ var PerpetualsClient = (function () {
|
|
2135
2029
|
.transaction()];
|
2136
2030
|
case 1:
|
2137
2031
|
transaction = _f.sent();
|
2032
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2033
|
+
transaction.instructions.unshift(setCULimitIx);
|
2138
2034
|
if (!enableBackupOracle) return [3, 3];
|
2139
2035
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2140
2036
|
case 2:
|
@@ -2161,7 +2057,7 @@ var PerpetualsClient = (function () {
|
|
2161
2057
|
});
|
2162
2058
|
};
|
2163
2059
|
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
2164
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
|
2060
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
|
2165
2061
|
var _d;
|
2166
2062
|
return __generator(this, function (_e) {
|
2167
2063
|
switch (_e.label) {
|
@@ -2209,6 +2105,8 @@ var PerpetualsClient = (function () {
|
|
2209
2105
|
.transaction()];
|
2210
2106
|
case 2:
|
2211
2107
|
transaction = _e.sent();
|
2108
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2109
|
+
transaction.instructions.unshift(setCULimitIx);
|
2212
2110
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2213
2111
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
2214
2112
|
case 3:
|
@@ -2225,7 +2123,7 @@ var PerpetualsClient = (function () {
|
|
2225
2123
|
args_1[_i - 4] = arguments[_i];
|
2226
2124
|
}
|
2227
2125
|
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) {
|
2228
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
2126
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2229
2127
|
var _e;
|
2230
2128
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2231
2129
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2280,6 +2178,8 @@ var PerpetualsClient = (function () {
|
|
2280
2178
|
.transaction()];
|
2281
2179
|
case 1:
|
2282
2180
|
transaction = _f.sent();
|
2181
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2182
|
+
transaction.instructions.unshift(setCULimitIx);
|
2283
2183
|
if (!enableBackupOracle) return [3, 3];
|
2284
2184
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2285
2185
|
case 2:
|
@@ -2305,7 +2205,7 @@ var PerpetualsClient = (function () {
|
|
2305
2205
|
args_1[_i - 4] = arguments[_i];
|
2306
2206
|
}
|
2307
2207
|
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) {
|
2308
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
2208
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
2309
2209
|
var _e;
|
2310
2210
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2311
2211
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
@@ -2360,6 +2260,8 @@ var PerpetualsClient = (function () {
|
|
2360
2260
|
.transaction()];
|
2361
2261
|
case 1:
|
2362
2262
|
transaction = _f.sent();
|
2263
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
2264
|
+
transaction.instructions.unshift(setCULimitIx);
|
2363
2265
|
if (!enableBackupOracle) return [3, 3];
|
2364
2266
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
2365
2267
|
case 2:
|
@@ -4076,119 +3978,8 @@ var PerpetualsClient = (function () {
|
|
4076
3978
|
}
|
4077
3979
|
});
|
4078
3980
|
}); };
|
4079
|
-
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4080
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
4081
|
-
return __generator(this, function (_a) {
|
4082
|
-
switch (_a.label) {
|
4083
|
-
case 0:
|
4084
|
-
publicKey = this.provider.wallet.publicKey;
|
4085
|
-
preInstructions = [];
|
4086
|
-
instructions = [];
|
4087
|
-
postInstructions = [];
|
4088
|
-
additionalSigners = [];
|
4089
|
-
_a.label = 1;
|
4090
|
-
case 1:
|
4091
|
-
_a.trys.push([1, 4, , 5]);
|
4092
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4093
|
-
Buffer.from("trading"),
|
4094
|
-
nftMint.toBuffer(),
|
4095
|
-
], this.programId)[0];
|
4096
|
-
nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4097
|
-
Buffer.from("referral"),
|
4098
|
-
publicKey.toBuffer(),
|
4099
|
-
], this.programId)[0];
|
4100
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
4101
|
-
case 2:
|
4102
|
-
nftTokenAccount = _a.sent();
|
4103
|
-
flpStakeAccountMetas = [];
|
4104
|
-
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
4105
|
-
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
4106
|
-
flpStakeAccountMetas.push({
|
4107
|
-
pubkey: flpStakeAccountPk,
|
4108
|
-
isSigner: false,
|
4109
|
-
isWritable: true,
|
4110
|
-
});
|
4111
|
-
}
|
4112
|
-
return [4, this.program.methods
|
4113
|
-
.updateTradingAccount({
|
4114
|
-
updateReferer: updateReferer,
|
4115
|
-
updateBooster: updateBooster
|
4116
|
-
})
|
4117
|
-
.accounts({
|
4118
|
-
owner: publicKey,
|
4119
|
-
feePayer: publicKey,
|
4120
|
-
nftTokenAccount: nftTokenAccount,
|
4121
|
-
referralAccount: nftReferralAccount,
|
4122
|
-
tradingAccount: nftTradingAccount
|
4123
|
-
})
|
4124
|
-
.instruction()];
|
4125
|
-
case 3:
|
4126
|
-
updateNftTradingAccountInstruction = _a.sent();
|
4127
|
-
instructions.push(updateNftTradingAccountInstruction);
|
4128
|
-
return [3, 5];
|
4129
|
-
case 4:
|
4130
|
-
err_8 = _a.sent();
|
4131
|
-
console.log("perpClient updateNftAccount error:: ", err_8);
|
4132
|
-
throw err_8;
|
4133
|
-
case 5: return [2, {
|
4134
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4135
|
-
additionalSigners: additionalSigners
|
4136
|
-
}];
|
4137
|
-
}
|
4138
|
-
});
|
4139
|
-
}); };
|
4140
|
-
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4141
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
4142
|
-
return __generator(this, function (_a) {
|
4143
|
-
switch (_a.label) {
|
4144
|
-
case 0:
|
4145
|
-
publicKey = this.provider.wallet.publicKey;
|
4146
|
-
preInstructions = [];
|
4147
|
-
instructions = [];
|
4148
|
-
postInstructions = [];
|
4149
|
-
additionalSigners = [];
|
4150
|
-
_a.label = 1;
|
4151
|
-
case 1:
|
4152
|
-
_a.trys.push([1, 3, , 4]);
|
4153
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4154
|
-
Buffer.from("trading"),
|
4155
|
-
nftMint.toBuffer(),
|
4156
|
-
], this.programId)[0];
|
4157
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4158
|
-
return [4, this.program.methods
|
4159
|
-
.levelUp({})
|
4160
|
-
.accounts({
|
4161
|
-
owner: publicKey,
|
4162
|
-
perpetuals: this.perpetuals.publicKey,
|
4163
|
-
pool: poolConfig.poolAddress,
|
4164
|
-
metadataAccount: metadataAccount,
|
4165
|
-
nftMint: nftMint,
|
4166
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
4167
|
-
tradingAccount: nftTradingAccount,
|
4168
|
-
transferAuthority: this.authority.publicKey,
|
4169
|
-
authorizationRulesAccount: authorizationRulesAccount,
|
4170
|
-
authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
|
4171
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
4172
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4173
|
-
})
|
4174
|
-
.instruction()];
|
4175
|
-
case 2:
|
4176
|
-
levelUpInstruction = _a.sent();
|
4177
|
-
instructions.push(levelUpInstruction);
|
4178
|
-
return [3, 4];
|
4179
|
-
case 3:
|
4180
|
-
err_9 = _a.sent();
|
4181
|
-
console.log("perpClient levelUp error:: ", err_9);
|
4182
|
-
throw err_9;
|
4183
|
-
case 4: return [2, {
|
4184
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4185
|
-
additionalSigners: additionalSigners
|
4186
|
-
}];
|
4187
|
-
}
|
4188
|
-
});
|
4189
|
-
}); };
|
4190
3981
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4191
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
3982
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
|
4192
3983
|
return __generator(this, function (_a) {
|
4193
3984
|
switch (_a.label) {
|
4194
3985
|
case 0:
|
@@ -4230,9 +4021,9 @@ var PerpetualsClient = (function () {
|
|
4230
4021
|
instructions.push(depositStakeInstruction);
|
4231
4022
|
return [3, 5];
|
4232
4023
|
case 4:
|
4233
|
-
|
4234
|
-
console.log("perpClient depositStaking error:: ",
|
4235
|
-
throw
|
4024
|
+
err_8 = _a.sent();
|
4025
|
+
console.log("perpClient depositStaking error:: ", err_8);
|
4026
|
+
throw err_8;
|
4236
4027
|
case 5: return [2, {
|
4237
4028
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4238
4029
|
additionalSigners: additionalSigners
|
@@ -4241,7 +4032,7 @@ var PerpetualsClient = (function () {
|
|
4241
4032
|
});
|
4242
4033
|
}); };
|
4243
4034
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4244
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4035
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
|
4245
4036
|
return __generator(this, function (_c) {
|
4246
4037
|
switch (_c.label) {
|
4247
4038
|
case 0:
|
@@ -4288,9 +4079,9 @@ var PerpetualsClient = (function () {
|
|
4288
4079
|
refreshStakeInstruction = _c.sent();
|
4289
4080
|
return [2, refreshStakeInstruction];
|
4290
4081
|
case 2:
|
4291
|
-
|
4292
|
-
console.log("perpClient refreshStaking error:: ",
|
4293
|
-
throw
|
4082
|
+
err_9 = _c.sent();
|
4083
|
+
console.log("perpClient refreshStaking error:: ", err_9);
|
4084
|
+
throw err_9;
|
4294
4085
|
case 3: return [2];
|
4295
4086
|
}
|
4296
4087
|
});
|
@@ -4301,7 +4092,7 @@ var PerpetualsClient = (function () {
|
|
4301
4092
|
args_1[_i - 3] = arguments[_i];
|
4302
4093
|
}
|
4303
4094
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4304
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
4095
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
|
4305
4096
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4306
4097
|
return __generator(this, function (_c) {
|
4307
4098
|
switch (_c.label) {
|
@@ -4349,9 +4140,9 @@ var PerpetualsClient = (function () {
|
|
4349
4140
|
refreshStakeInstruction = _c.sent();
|
4350
4141
|
return [2, refreshStakeInstruction];
|
4351
4142
|
case 2:
|
4352
|
-
|
4353
|
-
console.log("perpClient refreshStaking error:: ",
|
4354
|
-
throw
|
4143
|
+
err_10 = _c.sent();
|
4144
|
+
console.log("perpClient refreshStaking error:: ", err_10);
|
4145
|
+
throw err_10;
|
4355
4146
|
case 3: return [2];
|
4356
4147
|
}
|
4357
4148
|
});
|
@@ -4363,7 +4154,7 @@ var PerpetualsClient = (function () {
|
|
4363
4154
|
args_1[_i - 3] = arguments[_i];
|
4364
4155
|
}
|
4365
4156
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4366
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
4157
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
|
4367
4158
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4368
4159
|
return __generator(this, function (_b) {
|
4369
4160
|
switch (_b.label) {
|
@@ -4415,9 +4206,9 @@ var PerpetualsClient = (function () {
|
|
4415
4206
|
instructions.push(unstakeInstantInstruction);
|
4416
4207
|
return [3, 6];
|
4417
4208
|
case 5:
|
4418
|
-
|
4419
|
-
console.log("perpClient unstakeInstant error:: ",
|
4420
|
-
throw
|
4209
|
+
err_11 = _b.sent();
|
4210
|
+
console.log("perpClient unstakeInstant error:: ", err_11);
|
4211
|
+
throw err_11;
|
4421
4212
|
case 6: return [2, {
|
4422
4213
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4423
4214
|
additionalSigners: additionalSigners
|
@@ -4427,7 +4218,7 @@ var PerpetualsClient = (function () {
|
|
4427
4218
|
});
|
4428
4219
|
};
|
4429
4220
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4430
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4221
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
4431
4222
|
return __generator(this, function (_c) {
|
4432
4223
|
switch (_c.label) {
|
4433
4224
|
case 0:
|
@@ -4471,15 +4262,15 @@ var PerpetualsClient = (function () {
|
|
4471
4262
|
refreshStakeInstruction = _c.sent();
|
4472
4263
|
return [2, refreshStakeInstruction];
|
4473
4264
|
case 2:
|
4474
|
-
|
4475
|
-
console.log("perpClient refreshStaking error:: ",
|
4476
|
-
throw
|
4265
|
+
err_12 = _c.sent();
|
4266
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4267
|
+
throw err_12;
|
4477
4268
|
case 3: return [2];
|
4478
4269
|
}
|
4479
4270
|
});
|
4480
4271
|
}); };
|
4481
4272
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4482
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4273
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
4483
4274
|
return __generator(this, function (_a) {
|
4484
4275
|
switch (_a.label) {
|
4485
4276
|
case 0:
|
@@ -4513,9 +4304,9 @@ var PerpetualsClient = (function () {
|
|
4513
4304
|
instructions.push(unstakeRequestInstruction);
|
4514
4305
|
return [3, 4];
|
4515
4306
|
case 3:
|
4516
|
-
|
4517
|
-
console.log("perpClient unstakeRequest error:: ",
|
4518
|
-
throw
|
4307
|
+
err_13 = _a.sent();
|
4308
|
+
console.log("perpClient unstakeRequest error:: ", err_13);
|
4309
|
+
throw err_13;
|
4519
4310
|
case 4: return [2, {
|
4520
4311
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4521
4312
|
additionalSigners: additionalSigners
|
@@ -4529,7 +4320,7 @@ var PerpetualsClient = (function () {
|
|
4529
4320
|
args_1[_i - 1] = arguments[_i];
|
4530
4321
|
}
|
4531
4322
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4532
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4323
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
|
4533
4324
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
4534
4325
|
if (deactivated === void 0) { deactivated = true; }
|
4535
4326
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
@@ -4585,9 +4376,9 @@ var PerpetualsClient = (function () {
|
|
4585
4376
|
instructions.push(withdrawStakeInstruction);
|
4586
4377
|
return [3, 6];
|
4587
4378
|
case 5:
|
4588
|
-
|
4589
|
-
console.log("perpClient withdrawStake error:: ",
|
4590
|
-
throw
|
4379
|
+
err_14 = _b.sent();
|
4380
|
+
console.log("perpClient withdrawStake error:: ", err_14);
|
4381
|
+
throw err_14;
|
4591
4382
|
case 6: return [2, {
|
4592
4383
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4593
4384
|
additionalSigners: additionalSigners
|
@@ -4602,7 +4393,7 @@ var PerpetualsClient = (function () {
|
|
4602
4393
|
args_1[_i - 3] = arguments[_i];
|
4603
4394
|
}
|
4604
4395
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4605
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
4396
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
4606
4397
|
if (createUserATA === void 0) { createUserATA = true; }
|
4607
4398
|
return __generator(this, function (_b) {
|
4608
4399
|
switch (_b.label) {
|
@@ -4663,9 +4454,9 @@ var PerpetualsClient = (function () {
|
|
4663
4454
|
instructions.push(withdrawStakeInstruction);
|
4664
4455
|
return [3, 6];
|
4665
4456
|
case 5:
|
4666
|
-
|
4667
|
-
console.log("perpClient withdrawStake error:: ",
|
4668
|
-
throw
|
4457
|
+
err_15 = _b.sent();
|
4458
|
+
console.log("perpClient withdrawStake error:: ", err_15);
|
4459
|
+
throw err_15;
|
4669
4460
|
case 6: return [2, {
|
4670
4461
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4671
4462
|
additionalSigners: additionalSigners
|
@@ -4680,7 +4471,7 @@ var PerpetualsClient = (function () {
|
|
4680
4471
|
args_1[_i - 5] = arguments[_i];
|
4681
4472
|
}
|
4682
4473
|
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) {
|
4683
|
-
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,
|
4474
|
+
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;
|
4684
4475
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4685
4476
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4686
4477
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4808,8 +4599,8 @@ var PerpetualsClient = (function () {
|
|
4808
4599
|
instructions.push(addCompoundingLiquidity);
|
4809
4600
|
return [3, 10];
|
4810
4601
|
case 9:
|
4811
|
-
|
4812
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4602
|
+
err_16 = _f.sent();
|
4603
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
4813
4604
|
return [3, 10];
|
4814
4605
|
case 10: return [2, {
|
4815
4606
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4825,7 +4616,7 @@ var PerpetualsClient = (function () {
|
|
4825
4616
|
args_1[_i - 5] = arguments[_i];
|
4826
4617
|
}
|
4827
4618
|
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) {
|
4828
|
-
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,
|
4619
|
+
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;
|
4829
4620
|
if (createUserATA === void 0) { createUserATA = true; }
|
4830
4621
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4831
4622
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4937,8 +4728,8 @@ var PerpetualsClient = (function () {
|
|
4937
4728
|
instructions.push(removeCompoundingLiquidity);
|
4938
4729
|
return [3, 8];
|
4939
4730
|
case 7:
|
4940
|
-
|
4941
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4731
|
+
err_17 = _f.sent();
|
4732
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
4942
4733
|
return [3, 8];
|
4943
4734
|
case 8: return [2, {
|
4944
4735
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4954,7 +4745,7 @@ var PerpetualsClient = (function () {
|
|
4954
4745
|
args_1[_i - 3] = arguments[_i];
|
4955
4746
|
}
|
4956
4747
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
4957
|
-
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,
|
4748
|
+
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;
|
4958
4749
|
if (createUserATA === void 0) { createUserATA = true; }
|
4959
4750
|
return __generator(this, function (_g) {
|
4960
4751
|
switch (_g.label) {
|
@@ -5052,8 +4843,8 @@ var PerpetualsClient = (function () {
|
|
5052
4843
|
instructions.push(migrateStake);
|
5053
4844
|
return [3, 8];
|
5054
4845
|
case 7:
|
5055
|
-
|
5056
|
-
console.log("perpClient migrateStake error:: ",
|
4846
|
+
err_18 = _g.sent();
|
4847
|
+
console.log("perpClient migrateStake error:: ", err_18);
|
5057
4848
|
return [3, 8];
|
5058
4849
|
case 8: return [2, {
|
5059
4850
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5064,7 +4855,7 @@ var PerpetualsClient = (function () {
|
|
5064
4855
|
});
|
5065
4856
|
};
|
5066
4857
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5067
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
4858
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
|
5068
4859
|
return __generator(this, function (_d) {
|
5069
4860
|
switch (_d.label) {
|
5070
4861
|
case 0:
|
@@ -5136,8 +4927,8 @@ var PerpetualsClient = (function () {
|
|
5136
4927
|
instructions.push(migrateFlp);
|
5137
4928
|
return [3, 4];
|
5138
4929
|
case 3:
|
5139
|
-
|
5140
|
-
console.log("perpClient migrateFlp error:: ",
|
4930
|
+
err_19 = _d.sent();
|
4931
|
+
console.log("perpClient migrateFlp error:: ", err_19);
|
5141
4932
|
return [3, 4];
|
5142
4933
|
case 4: return [2, {
|
5143
4934
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5152,7 +4943,7 @@ var PerpetualsClient = (function () {
|
|
5152
4943
|
args_1[_i - 1] = arguments[_i];
|
5153
4944
|
}
|
5154
4945
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5155
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee,
|
4946
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
|
5156
4947
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5157
4948
|
return __generator(this, function (_e) {
|
5158
4949
|
switch (_e.label) {
|
@@ -5210,8 +5001,8 @@ var PerpetualsClient = (function () {
|
|
5210
5001
|
instructions.push(compoundingFee);
|
5211
5002
|
return [3, 4];
|
5212
5003
|
case 3:
|
5213
|
-
|
5214
|
-
console.log("perpClient compoundingFee error:: ",
|
5004
|
+
err_20 = _e.sent();
|
5005
|
+
console.log("perpClient compoundingFee error:: ", err_20);
|
5215
5006
|
return [3, 4];
|
5216
5007
|
case 4: return [2, {
|
5217
5008
|
instructions: __spreadArray([], instructions, true),
|
@@ -5221,84 +5012,61 @@ var PerpetualsClient = (function () {
|
|
5221
5012
|
});
|
5222
5013
|
});
|
5223
5014
|
};
|
5224
|
-
this.
|
5225
|
-
var preInstructions, instructions, postInstructions, additionalSigners,
|
5226
|
-
return __generator(this, function (
|
5227
|
-
switch (
|
5015
|
+
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5016
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_21;
|
5017
|
+
return __generator(this, function (_a) {
|
5018
|
+
switch (_a.label) {
|
5228
5019
|
case 0:
|
5229
5020
|
preInstructions = [];
|
5230
5021
|
instructions = [];
|
5231
5022
|
postInstructions = [];
|
5232
5023
|
additionalSigners = [];
|
5233
|
-
|
5024
|
+
_a.label = 1;
|
5234
5025
|
case 1:
|
5235
|
-
|
5236
|
-
|
5237
|
-
|
5238
|
-
userTokenAccount = _b.sent();
|
5239
|
-
_a = createAta;
|
5240
|
-
if (!_a) return [3, 4];
|
5026
|
+
_a.trys.push([1, 4, , 5]);
|
5027
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5028
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
5241
5029
|
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5242
|
-
case
|
5243
|
-
|
5244
|
-
|
5245
|
-
case 4:
|
5246
|
-
if (_a) {
|
5247
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(owner, userTokenAccount, owner, poolConfig.tokenMint));
|
5030
|
+
case 2:
|
5031
|
+
if (!(_a.sent())) {
|
5032
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5248
5033
|
}
|
5249
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
|
5250
|
-
case 5:
|
5251
|
-
nftTokenAccount = _b.sent();
|
5252
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5253
|
-
Buffer.from("trading"),
|
5254
|
-
nftMint.toBuffer(),
|
5255
|
-
], this.programId)[0];
|
5256
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5257
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5258
|
-
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];
|
5259
|
-
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];
|
5260
5034
|
return [4, this.program.methods
|
5261
|
-
.
|
5035
|
+
.depositTokenStake({
|
5036
|
+
depositAmount: depositAmount
|
5037
|
+
})
|
5262
5038
|
.accounts({
|
5263
5039
|
owner: owner,
|
5264
|
-
|
5040
|
+
feePayer: feePayer,
|
5041
|
+
fundingTokenAccount: userTokenAccount,
|
5265
5042
|
perpetuals: this.perpetuals.publicKey,
|
5266
5043
|
tokenVault: poolConfig.tokenVault,
|
5267
5044
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5268
|
-
|
5269
|
-
collectionMetadata: collectionMetadata,
|
5270
|
-
edition: edition,
|
5271
|
-
tokenRecord: tokenRecord,
|
5272
|
-
tradingAccount: nftTradingAccount,
|
5273
|
-
transferAuthority: poolConfig.transferAuthority,
|
5274
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5275
|
-
nftMint: nftMint,
|
5276
|
-
nftTokenAccount: nftTokenAccount,
|
5045
|
+
tokenStakeAccount: tokenStakeAccount,
|
5277
5046
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5278
5047
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5279
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5280
5048
|
eventAuthority: this.eventAuthority.publicKey,
|
5281
5049
|
program: this.programId,
|
5282
|
-
|
5050
|
+
tokenMint: poolConfig.tokenMint,
|
5283
5051
|
})
|
5284
5052
|
.instruction()];
|
5285
|
-
case
|
5286
|
-
|
5287
|
-
instructions.push(
|
5288
|
-
return [3,
|
5289
|
-
case
|
5290
|
-
|
5291
|
-
console.log("perpClient
|
5292
|
-
throw
|
5293
|
-
case
|
5053
|
+
case 3:
|
5054
|
+
depositTokenStakeInstruction = _a.sent();
|
5055
|
+
instructions.push(depositTokenStakeInstruction);
|
5056
|
+
return [3, 5];
|
5057
|
+
case 4:
|
5058
|
+
err_21 = _a.sent();
|
5059
|
+
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
5060
|
+
throw err_21;
|
5061
|
+
case 5: return [2, {
|
5294
5062
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5295
5063
|
additionalSigners: additionalSigners
|
5296
5064
|
}];
|
5297
5065
|
}
|
5298
5066
|
});
|
5299
5067
|
}); };
|
5300
|
-
this.
|
5301
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount,
|
5068
|
+
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5069
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
|
5302
5070
|
return __generator(this, function (_a) {
|
5303
5071
|
switch (_a.label) {
|
5304
5072
|
case 0:
|
@@ -5310,125 +5078,10 @@ var PerpetualsClient = (function () {
|
|
5310
5078
|
case 1:
|
5311
5079
|
_a.trys.push([1, 3, , 4]);
|
5312
5080
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5313
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
5314
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5315
|
-
Buffer.from("trading"),
|
5316
|
-
nftMint.toBuffer(),
|
5317
|
-
], this.programId)[0];
|
5318
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5319
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5320
|
-
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];
|
5321
|
-
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];
|
5322
5081
|
return [4, this.program.methods
|
5323
|
-
.
|
5324
|
-
|
5325
|
-
|
5326
|
-
feePayer: feePayer,
|
5327
|
-
perpetuals: this.perpetuals.publicKey,
|
5328
|
-
tokenVault: poolConfig.tokenVault,
|
5329
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5330
|
-
tokenStakeAccount: tokenStakeAccount,
|
5331
|
-
metadataAccount: metadataAccount,
|
5332
|
-
collectionMetadata: collectionMetadata,
|
5333
|
-
edition: edition,
|
5334
|
-
tokenRecord: tokenRecord,
|
5335
|
-
tradingAccount: nftTradingAccount,
|
5336
|
-
transferAuthority: poolConfig.transferAuthority,
|
5337
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5338
|
-
nftMint: nftMint,
|
5339
|
-
nftTokenAccount: nftTokenAccount,
|
5340
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5341
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5342
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5343
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5344
|
-
program: this.programId
|
5345
|
-
})
|
5346
|
-
.instruction()];
|
5347
|
-
case 2:
|
5348
|
-
burnAndStakeInstruction = _a.sent();
|
5349
|
-
instructions.push(burnAndStakeInstruction);
|
5350
|
-
return [3, 4];
|
5351
|
-
case 3:
|
5352
|
-
err_24 = _a.sent();
|
5353
|
-
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
5354
|
-
throw err_24;
|
5355
|
-
case 4: return [2, {
|
5356
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5357
|
-
additionalSigners: additionalSigners
|
5358
|
-
}];
|
5359
|
-
}
|
5360
|
-
});
|
5361
|
-
}); };
|
5362
|
-
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5363
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
5364
|
-
return __generator(this, function (_a) {
|
5365
|
-
switch (_a.label) {
|
5366
|
-
case 0:
|
5367
|
-
preInstructions = [];
|
5368
|
-
instructions = [];
|
5369
|
-
postInstructions = [];
|
5370
|
-
additionalSigners = [];
|
5371
|
-
_a.label = 1;
|
5372
|
-
case 1:
|
5373
|
-
_a.trys.push([1, 4, , 5]);
|
5374
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5375
|
-
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
5376
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5377
|
-
case 2:
|
5378
|
-
if (!(_a.sent())) {
|
5379
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5380
|
-
}
|
5381
|
-
return [4, this.program.methods
|
5382
|
-
.depositTokenStake({
|
5383
|
-
depositAmount: depositAmount
|
5384
|
-
})
|
5385
|
-
.accounts({
|
5386
|
-
owner: owner,
|
5387
|
-
feePayer: feePayer,
|
5388
|
-
fundingTokenAccount: userTokenAccount,
|
5389
|
-
perpetuals: this.perpetuals.publicKey,
|
5390
|
-
tokenVault: poolConfig.tokenVault,
|
5391
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5392
|
-
tokenStakeAccount: tokenStakeAccount,
|
5393
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5394
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5395
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5396
|
-
program: this.programId,
|
5397
|
-
tokenMint: poolConfig.tokenMint,
|
5398
|
-
})
|
5399
|
-
.instruction()];
|
5400
|
-
case 3:
|
5401
|
-
depositTokenStakeInstruction = _a.sent();
|
5402
|
-
instructions.push(depositTokenStakeInstruction);
|
5403
|
-
return [3, 5];
|
5404
|
-
case 4:
|
5405
|
-
err_25 = _a.sent();
|
5406
|
-
console.log("perpClient depositStakingInstruction error:: ", err_25);
|
5407
|
-
throw err_25;
|
5408
|
-
case 5: return [2, {
|
5409
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5410
|
-
additionalSigners: additionalSigners
|
5411
|
-
}];
|
5412
|
-
}
|
5413
|
-
});
|
5414
|
-
}); };
|
5415
|
-
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5416
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_26;
|
5417
|
-
return __generator(this, function (_a) {
|
5418
|
-
switch (_a.label) {
|
5419
|
-
case 0:
|
5420
|
-
preInstructions = [];
|
5421
|
-
instructions = [];
|
5422
|
-
postInstructions = [];
|
5423
|
-
additionalSigners = [];
|
5424
|
-
_a.label = 1;
|
5425
|
-
case 1:
|
5426
|
-
_a.trys.push([1, 3, , 4]);
|
5427
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5428
|
-
return [4, this.program.methods
|
5429
|
-
.unstakeTokenRequest({
|
5430
|
-
unstakeAmount: unstakeAmount
|
5431
|
-
})
|
5082
|
+
.unstakeTokenRequest({
|
5083
|
+
unstakeAmount: unstakeAmount
|
5084
|
+
})
|
5432
5085
|
.accounts({
|
5433
5086
|
owner: owner,
|
5434
5087
|
tokenVault: poolConfig.tokenVault,
|
@@ -5442,9 +5095,9 @@ var PerpetualsClient = (function () {
|
|
5442
5095
|
instructions.push(unstakeTokenRequestInstruction);
|
5443
5096
|
return [3, 4];
|
5444
5097
|
case 3:
|
5445
|
-
|
5446
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5447
|
-
throw
|
5098
|
+
err_22 = _a.sent();
|
5099
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
|
5100
|
+
throw err_22;
|
5448
5101
|
case 4: return [2, {
|
5449
5102
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5450
5103
|
additionalSigners: additionalSigners
|
@@ -5453,7 +5106,7 @@ var PerpetualsClient = (function () {
|
|
5453
5106
|
});
|
5454
5107
|
}); };
|
5455
5108
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5456
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5109
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
|
5457
5110
|
return __generator(this, function (_a) {
|
5458
5111
|
switch (_a.label) {
|
5459
5112
|
case 0:
|
@@ -5494,9 +5147,9 @@ var PerpetualsClient = (function () {
|
|
5494
5147
|
instructions.push(unstakeTokenInstantInstruction);
|
5495
5148
|
return [3, 5];
|
5496
5149
|
case 4:
|
5497
|
-
|
5498
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5499
|
-
throw
|
5150
|
+
err_23 = _a.sent();
|
5151
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
5152
|
+
throw err_23;
|
5500
5153
|
case 5: return [2, {
|
5501
5154
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5502
5155
|
additionalSigners: additionalSigners
|
@@ -5505,7 +5158,7 @@ var PerpetualsClient = (function () {
|
|
5505
5158
|
});
|
5506
5159
|
}); };
|
5507
5160
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5508
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5161
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
|
5509
5162
|
return __generator(this, function (_a) {
|
5510
5163
|
switch (_a.label) {
|
5511
5164
|
case 0:
|
@@ -5546,9 +5199,9 @@ var PerpetualsClient = (function () {
|
|
5546
5199
|
instructions.push(withdrawTokenInstruction);
|
5547
5200
|
return [3, 5];
|
5548
5201
|
case 4:
|
5549
|
-
|
5550
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5551
|
-
throw
|
5202
|
+
err_24 = _a.sent();
|
5203
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
5204
|
+
throw err_24;
|
5552
5205
|
case 5: return [2, {
|
5553
5206
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5554
5207
|
additionalSigners: additionalSigners
|
@@ -5557,7 +5210,7 @@ var PerpetualsClient = (function () {
|
|
5557
5210
|
});
|
5558
5211
|
}); };
|
5559
5212
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5560
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5213
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
|
5561
5214
|
return __generator(this, function (_a) {
|
5562
5215
|
switch (_a.label) {
|
5563
5216
|
case 0:
|
@@ -5586,9 +5239,9 @@ var PerpetualsClient = (function () {
|
|
5586
5239
|
instructions.push(cancelUnstakeRequestInstruction);
|
5587
5240
|
return [3, 4];
|
5588
5241
|
case 3:
|
5589
|
-
|
5590
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5591
|
-
throw
|
5242
|
+
err_25 = _a.sent();
|
5243
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
|
5244
|
+
throw err_25;
|
5592
5245
|
case 4: return [2, {
|
5593
5246
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5594
5247
|
additionalSigners: additionalSigners
|
@@ -5602,7 +5255,7 @@ var PerpetualsClient = (function () {
|
|
5602
5255
|
args_1[_i - 2] = arguments[_i];
|
5603
5256
|
}
|
5604
5257
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5605
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
5258
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
5606
5259
|
if (createUserATA === void 0) { createUserATA = true; }
|
5607
5260
|
return __generator(this, function (_b) {
|
5608
5261
|
switch (_b.label) {
|
@@ -5648,9 +5301,9 @@ var PerpetualsClient = (function () {
|
|
5648
5301
|
instructions.push(collectTokenRewardInstruction);
|
5649
5302
|
return [3, 6];
|
5650
5303
|
case 5:
|
5651
|
-
|
5652
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5653
|
-
throw
|
5304
|
+
err_26 = _b.sent();
|
5305
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
5306
|
+
throw err_26;
|
5654
5307
|
case 6: return [2, {
|
5655
5308
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5656
5309
|
additionalSigners: additionalSigners
|
@@ -5665,7 +5318,7 @@ var PerpetualsClient = (function () {
|
|
5665
5318
|
args_1[_i - 3] = arguments[_i];
|
5666
5319
|
}
|
5667
5320
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5668
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
5321
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
|
5669
5322
|
if (createUserATA === void 0) { createUserATA = true; }
|
5670
5323
|
return __generator(this, function (_b) {
|
5671
5324
|
switch (_b.label) {
|
@@ -5712,250 +5365,9 @@ var PerpetualsClient = (function () {
|
|
5712
5365
|
instructions.push(collectRevenueInstruction);
|
5713
5366
|
return [3, 6];
|
5714
5367
|
case 5:
|
5715
|
-
|
5716
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5717
|
-
throw
|
5718
|
-
case 6: return [2, {
|
5719
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5720
|
-
additionalSigners: additionalSigners
|
5721
|
-
}];
|
5722
|
-
}
|
5723
|
-
});
|
5724
|
-
});
|
5725
|
-
};
|
5726
|
-
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5727
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
|
5728
|
-
return __generator(this, function (_a) {
|
5729
|
-
switch (_a.label) {
|
5730
|
-
case 0:
|
5731
|
-
publicKey = this.provider.wallet.publicKey;
|
5732
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5733
|
-
instructions = [];
|
5734
|
-
additionalSigners = [];
|
5735
|
-
_a.label = 1;
|
5736
|
-
case 1:
|
5737
|
-
_a.trys.push([1, 3, , 4]);
|
5738
|
-
fbNftProgramData = web3_js_1.PublicKey.findProgramAddressSync([this.programFbnftReward.programId.toBuffer()], new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"))[0];
|
5739
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5740
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5741
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5742
|
-
return [4, this.programFbnftReward.methods
|
5743
|
-
.initRewardVault({
|
5744
|
-
nftCount: nftCount
|
5745
|
-
})
|
5746
|
-
.accounts({
|
5747
|
-
admin: publicKey,
|
5748
|
-
transferAuthority: nftTransferAuthority,
|
5749
|
-
rewardVault: rewardVault,
|
5750
|
-
rewardMint: rewardCustodyMint,
|
5751
|
-
rewardTokenAccount: rewardTokenAccount,
|
5752
|
-
collectionMint: collectionMint,
|
5753
|
-
programData: fbNftProgramData,
|
5754
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5755
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5756
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
5757
|
-
})
|
5758
|
-
.instruction()];
|
5759
|
-
case 2:
|
5760
|
-
initRewardVault = _a.sent();
|
5761
|
-
instructions.push(initRewardVault);
|
5762
|
-
return [3, 4];
|
5763
|
-
case 3:
|
5764
|
-
err_32 = _a.sent();
|
5765
|
-
console.log("perpClient InitRewardVault error:: ", err_32);
|
5766
|
-
throw err_32;
|
5767
|
-
case 4: return [2, {
|
5768
|
-
instructions: __spreadArray([], instructions, true),
|
5769
|
-
additionalSigners: additionalSigners
|
5770
|
-
}];
|
5771
|
-
}
|
5772
|
-
});
|
5773
|
-
}); };
|
5774
|
-
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5775
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
|
5776
|
-
return __generator(this, function (_a) {
|
5777
|
-
switch (_a.label) {
|
5778
|
-
case 0:
|
5779
|
-
publicKey = this.provider.wallet.publicKey;
|
5780
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5781
|
-
instructions = [];
|
5782
|
-
additionalSigners = [];
|
5783
|
-
_a.label = 1;
|
5784
|
-
case 1:
|
5785
|
-
_a.trys.push([1, 3, , 4]);
|
5786
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5787
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5788
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5789
|
-
return [4, this.programFbnftReward.methods
|
5790
|
-
.distributeRewards({
|
5791
|
-
rewardAmount: rewardAmount
|
5792
|
-
})
|
5793
|
-
.accounts({
|
5794
|
-
admin: publicKey,
|
5795
|
-
fundingAccount: fundingAccount,
|
5796
|
-
rewardVault: rewardVault,
|
5797
|
-
rewardTokenAccount: rewardTokenAccount,
|
5798
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5799
|
-
})
|
5800
|
-
.instruction()];
|
5801
|
-
case 2:
|
5802
|
-
distributeReward = _a.sent();
|
5803
|
-
instructions.push(distributeReward);
|
5804
|
-
return [3, 4];
|
5805
|
-
case 3:
|
5806
|
-
err_33 = _a.sent();
|
5807
|
-
console.log("perpClient distributeReward error:: ", err_33);
|
5808
|
-
throw err_33;
|
5809
|
-
case 4: return [2, {
|
5810
|
-
instructions: __spreadArray([], instructions, true),
|
5811
|
-
additionalSigners: additionalSigners
|
5812
|
-
}];
|
5813
|
-
}
|
5814
|
-
});
|
5815
|
-
}); };
|
5816
|
-
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5817
|
-
var args_1 = [];
|
5818
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
5819
|
-
args_1[_i - 3] = arguments[_i];
|
5820
|
-
}
|
5821
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5822
|
-
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
|
5823
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5824
|
-
return __generator(this, function (_b) {
|
5825
|
-
switch (_b.label) {
|
5826
|
-
case 0:
|
5827
|
-
publicKey = this.provider.wallet.publicKey;
|
5828
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5829
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5830
|
-
instructions = [];
|
5831
|
-
additionalSigners = [];
|
5832
|
-
_b.label = 1;
|
5833
|
-
case 1:
|
5834
|
-
_b.trys.push([1, 5, , 6]);
|
5835
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5836
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5837
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5838
|
-
_a = createUserATA;
|
5839
|
-
if (!_a) return [3, 3];
|
5840
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5841
|
-
case 2:
|
5842
|
-
_a = !(_b.sent());
|
5843
|
-
_b.label = 3;
|
5844
|
-
case 3:
|
5845
|
-
if (_a) {
|
5846
|
-
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));
|
5847
|
-
}
|
5848
|
-
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5849
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5850
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5851
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5852
|
-
return [4, this.programFbnftReward.methods
|
5853
|
-
.collectReward()
|
5854
|
-
.accounts({
|
5855
|
-
owner: publicKey,
|
5856
|
-
feePayer: publicKey,
|
5857
|
-
nftMint: nftMint,
|
5858
|
-
nftTokenAccount: nftTokenAccount,
|
5859
|
-
metadataAccount: metadataAccount,
|
5860
|
-
receivingAccount: receivingTokenAccount,
|
5861
|
-
rewardRecord: rewardRecord,
|
5862
|
-
rewardVault: rewardVault,
|
5863
|
-
rewardTokenAccount: rewardTokenAccount,
|
5864
|
-
transferAuthority: nftTransferAuthority,
|
5865
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5866
|
-
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
5867
|
-
})
|
5868
|
-
.instruction()];
|
5869
|
-
case 4:
|
5870
|
-
collectNftReward = _b.sent();
|
5871
|
-
instructions.push(collectNftReward);
|
5872
|
-
return [3, 6];
|
5873
|
-
case 5:
|
5874
|
-
err_34 = _b.sent();
|
5875
|
-
throw err_34;
|
5876
|
-
case 6: return [2, {
|
5877
|
-
instructions: __spreadArray([], instructions, true),
|
5878
|
-
additionalSigners: additionalSigners
|
5879
|
-
}];
|
5880
|
-
}
|
5881
|
-
});
|
5882
|
-
});
|
5883
|
-
};
|
5884
|
-
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
5885
|
-
var args_1 = [];
|
5886
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
5887
|
-
args_1[_i - 2] = arguments[_i];
|
5888
|
-
}
|
5889
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5890
|
-
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
|
5891
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5892
|
-
return __generator(this, function (_b) {
|
5893
|
-
switch (_b.label) {
|
5894
|
-
case 0:
|
5895
|
-
publicKey = this.provider.wallet.publicKey;
|
5896
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5897
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5898
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5899
|
-
preInstructions = [];
|
5900
|
-
instructions = [];
|
5901
|
-
postInstructions = [];
|
5902
|
-
additionalSigners = [];
|
5903
|
-
_b.label = 1;
|
5904
|
-
case 1:
|
5905
|
-
_b.trys.push([1, 5, , 6]);
|
5906
|
-
pool = poolConfig.poolAddress;
|
5907
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5908
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5909
|
-
_a = createUserATA;
|
5910
|
-
if (!_a) return [3, 3];
|
5911
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5912
|
-
case 2:
|
5913
|
-
_a = !(_b.sent());
|
5914
|
-
_b.label = 3;
|
5915
|
-
case 3:
|
5916
|
-
if (_a) {
|
5917
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5918
|
-
}
|
5919
|
-
tradingAccount = [];
|
5920
|
-
if (nftTradingAccount) {
|
5921
|
-
tradingAccount.push({
|
5922
|
-
pubkey: nftTradingAccount,
|
5923
|
-
isSigner: false,
|
5924
|
-
isWritable: true,
|
5925
|
-
});
|
5926
|
-
}
|
5927
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5928
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5929
|
-
return [4, this.programPerpComposability.methods
|
5930
|
-
.collectAndDistributeFee()
|
5931
|
-
.accounts({
|
5932
|
-
perpProgram: this.programId,
|
5933
|
-
owner: publicKey,
|
5934
|
-
receivingTokenAccount: receivingTokenAccount,
|
5935
|
-
transferAuthority: poolConfig.transferAuthority,
|
5936
|
-
perpetuals: this.perpetuals.publicKey,
|
5937
|
-
pool: pool,
|
5938
|
-
feeCustody: rewardCustodyConfig.custodyAccount,
|
5939
|
-
flpStakeAccount: flpStakeAccount,
|
5940
|
-
feeCustodyTokenAccount: rewardCustodyConfig.tokenAccount,
|
5941
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5942
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5943
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5944
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5945
|
-
fbnftRewardsProgram: this.programFbnftReward.programId,
|
5946
|
-
rewardVault: rewardVault,
|
5947
|
-
rewardTokenAccount: rewardTokenAccount
|
5948
|
-
})
|
5949
|
-
.remainingAccounts(tradingAccount)
|
5950
|
-
.instruction()];
|
5951
|
-
case 4:
|
5952
|
-
withdrawStakeInstruction = _b.sent();
|
5953
|
-
instructions.push(withdrawStakeInstruction);
|
5954
|
-
return [3, 6];
|
5955
|
-
case 5:
|
5956
|
-
err_35 = _b.sent();
|
5957
|
-
console.log("perpClient withdrawStake error:: ", err_35);
|
5958
|
-
throw err_35;
|
5368
|
+
err_27 = _b.sent();
|
5369
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
5370
|
+
throw err_27;
|
5959
5371
|
case 6: return [2, {
|
5960
5372
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5961
5373
|
additionalSigners: additionalSigners
|
@@ -5970,7 +5382,7 @@ var PerpetualsClient = (function () {
|
|
5970
5382
|
args_1[_i - 11] = arguments[_i];
|
5971
5383
|
}
|
5972
5384
|
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) {
|
5973
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder,
|
5385
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_28;
|
5974
5386
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
5975
5387
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5976
5388
|
return __generator(this, function (_c) {
|
@@ -6076,9 +5488,9 @@ var PerpetualsClient = (function () {
|
|
6076
5488
|
instructions.push(placeLimitOrder);
|
6077
5489
|
return [3, 10];
|
6078
5490
|
case 9:
|
6079
|
-
|
6080
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6081
|
-
throw
|
5491
|
+
err_28 = _c.sent();
|
5492
|
+
console.log("perpClient placeLimitOrder error:: ", err_28);
|
5493
|
+
throw err_28;
|
6082
5494
|
case 10: return [2, {
|
6083
5495
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6084
5496
|
additionalSigners: additionalSigners
|
@@ -6093,7 +5505,7 @@ var PerpetualsClient = (function () {
|
|
6093
5505
|
args_1[_i - 11] = arguments[_i];
|
6094
5506
|
}
|
6095
5507
|
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) {
|
6096
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder,
|
5508
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_29;
|
6097
5509
|
if (createUserATA === void 0) { createUserATA = true; }
|
6098
5510
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6099
5511
|
return __generator(this, function (_b) {
|
@@ -6184,9 +5596,9 @@ var PerpetualsClient = (function () {
|
|
6184
5596
|
instructions.push(editLimitOrder);
|
6185
5597
|
return [3, 8];
|
6186
5598
|
case 7:
|
6187
|
-
|
6188
|
-
console.log("perpClient editLimitOrder error:: ",
|
6189
|
-
throw
|
5599
|
+
err_29 = _b.sent();
|
5600
|
+
console.log("perpClient editLimitOrder error:: ", err_29);
|
5601
|
+
throw err_29;
|
6190
5602
|
case 8: return [2, {
|
6191
5603
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6192
5604
|
additionalSigners: additionalSigners
|
@@ -6201,7 +5613,7 @@ var PerpetualsClient = (function () {
|
|
6201
5613
|
args_1[_i - 7] = arguments[_i];
|
6202
5614
|
}
|
6203
5615
|
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) {
|
6204
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder,
|
5616
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_30;
|
6205
5617
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6206
5618
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6207
5619
|
return __generator(this, function (_a) {
|
@@ -6253,9 +5665,9 @@ var PerpetualsClient = (function () {
|
|
6253
5665
|
instructions.push(executeLimitOrder);
|
6254
5666
|
return [3, 4];
|
6255
5667
|
case 3:
|
6256
|
-
|
6257
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6258
|
-
throw
|
5668
|
+
err_30 = _a.sent();
|
5669
|
+
console.log("perpClient executeLimitOrder error:: ", err_30);
|
5670
|
+
throw err_30;
|
6259
5671
|
case 4: return [2, {
|
6260
5672
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6261
5673
|
additionalSigners: additionalSigners
|
@@ -6270,7 +5682,7 @@ var PerpetualsClient = (function () {
|
|
6270
5682
|
args_1[_i - 8] = arguments[_i];
|
6271
5683
|
}
|
6272
5684
|
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) {
|
6273
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap,
|
5685
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_31;
|
6274
5686
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6275
5687
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6276
5688
|
return __generator(this, function (_a) {
|
@@ -6325,9 +5737,9 @@ var PerpetualsClient = (function () {
|
|
6325
5737
|
instructions.push(executeLimitWithSwap);
|
6326
5738
|
return [3, 4];
|
6327
5739
|
case 3:
|
6328
|
-
|
6329
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6330
|
-
throw
|
5740
|
+
err_31 = _a.sent();
|
5741
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_31);
|
5742
|
+
throw err_31;
|
6331
5743
|
case 4: return [2, {
|
6332
5744
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6333
5745
|
additionalSigners: additionalSigners
|
@@ -6337,7 +5749,7 @@ var PerpetualsClient = (function () {
|
|
6337
5749
|
});
|
6338
5750
|
};
|
6339
5751
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6340
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
5752
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_32;
|
6341
5753
|
return __generator(this, function (_a) {
|
6342
5754
|
switch (_a.label) {
|
6343
5755
|
case 0:
|
@@ -6385,9 +5797,9 @@ var PerpetualsClient = (function () {
|
|
6385
5797
|
instructions.push(placeTriggerOrder);
|
6386
5798
|
return [3, 4];
|
6387
5799
|
case 3:
|
6388
|
-
|
6389
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6390
|
-
throw
|
5800
|
+
err_32 = _a.sent();
|
5801
|
+
console.log("perpClient placeTriggerOrder error:: ", err_32);
|
5802
|
+
throw err_32;
|
6391
5803
|
case 4: return [2, {
|
6392
5804
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6393
5805
|
additionalSigners: additionalSigners
|
@@ -6396,7 +5808,7 @@ var PerpetualsClient = (function () {
|
|
6396
5808
|
});
|
6397
5809
|
}); };
|
6398
5810
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6399
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
5811
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_33;
|
6400
5812
|
return __generator(this, function (_a) {
|
6401
5813
|
switch (_a.label) {
|
6402
5814
|
case 0:
|
@@ -6443,9 +5855,9 @@ var PerpetualsClient = (function () {
|
|
6443
5855
|
instructions.push(editTriggerOrder);
|
6444
5856
|
return [3, 4];
|
6445
5857
|
case 3:
|
6446
|
-
|
6447
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6448
|
-
throw
|
5858
|
+
err_33 = _a.sent();
|
5859
|
+
console.log("perpClient editTriggerOrder error:: ", err_33);
|
5860
|
+
throw err_33;
|
6449
5861
|
case 4: return [2, {
|
6450
5862
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6451
5863
|
additionalSigners: additionalSigners
|
@@ -6454,7 +5866,7 @@ var PerpetualsClient = (function () {
|
|
6454
5866
|
});
|
6455
5867
|
}); };
|
6456
5868
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6457
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
5869
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_34;
|
6458
5870
|
return __generator(this, function (_a) {
|
6459
5871
|
switch (_a.label) {
|
6460
5872
|
case 0:
|
@@ -6487,9 +5899,9 @@ var PerpetualsClient = (function () {
|
|
6487
5899
|
instructions.push(cancelTriggerOrder);
|
6488
5900
|
return [3, 4];
|
6489
5901
|
case 3:
|
6490
|
-
|
6491
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6492
|
-
throw
|
5902
|
+
err_34 = _a.sent();
|
5903
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_34);
|
5904
|
+
throw err_34;
|
6493
5905
|
case 4: return [2, {
|
6494
5906
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6495
5907
|
additionalSigners: additionalSigners
|
@@ -6498,7 +5910,7 @@ var PerpetualsClient = (function () {
|
|
6498
5910
|
});
|
6499
5911
|
}); };
|
6500
5912
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6501
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
5913
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_35;
|
6502
5914
|
return __generator(this, function (_a) {
|
6503
5915
|
switch (_a.label) {
|
6504
5916
|
case 0:
|
@@ -6529,9 +5941,9 @@ var PerpetualsClient = (function () {
|
|
6529
5941
|
instructions.push(cancelAllTriggerOrders);
|
6530
5942
|
return [3, 4];
|
6531
5943
|
case 3:
|
6532
|
-
|
6533
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6534
|
-
throw
|
5944
|
+
err_35 = _a.sent();
|
5945
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_35);
|
5946
|
+
throw err_35;
|
6535
5947
|
case 4: return [2, {
|
6536
5948
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6537
5949
|
additionalSigners: additionalSigners
|
@@ -6545,7 +5957,7 @@ var PerpetualsClient = (function () {
|
|
6545
5957
|
args_1[_i - 9] = arguments[_i];
|
6546
5958
|
}
|
6547
5959
|
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) {
|
6548
|
-
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,
|
5960
|
+
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;
|
6549
5961
|
if (createUserATA === void 0) { createUserATA = true; }
|
6550
5962
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6551
5963
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -6651,9 +6063,9 @@ var PerpetualsClient = (function () {
|
|
6651
6063
|
instructions.push(executeTriggerWithSwap);
|
6652
6064
|
return [3, 10];
|
6653
6065
|
case 9:
|
6654
|
-
|
6655
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6656
|
-
throw
|
6066
|
+
err_36 = _e.sent();
|
6067
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_36);
|
6068
|
+
throw err_36;
|
6657
6069
|
case 10: return [2, {
|
6658
6070
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6659
6071
|
additionalSigners: additionalSigners
|
@@ -6668,7 +6080,7 @@ var PerpetualsClient = (function () {
|
|
6668
6080
|
args_1[_i - 8] = arguments[_i];
|
6669
6081
|
}
|
6670
6082
|
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) {
|
6671
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder,
|
6083
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_37;
|
6672
6084
|
if (createUserATA === void 0) { createUserATA = true; }
|
6673
6085
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6674
6086
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -6739,9 +6151,9 @@ var PerpetualsClient = (function () {
|
|
6739
6151
|
instructions.push(executeTriggerOrder);
|
6740
6152
|
return [3, 8];
|
6741
6153
|
case 7:
|
6742
|
-
|
6743
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
6744
|
-
throw
|
6154
|
+
err_37 = _b.sent();
|
6155
|
+
console.log("perpClient executeTriggerOrder error:: ", err_37);
|
6156
|
+
throw err_37;
|
6745
6157
|
case 8: return [2, {
|
6746
6158
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6747
6159
|
additionalSigners: additionalSigners
|
@@ -6756,7 +6168,7 @@ var PerpetualsClient = (function () {
|
|
6756
6168
|
args_1[_i - 5] = arguments[_i];
|
6757
6169
|
}
|
6758
6170
|
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) {
|
6759
|
-
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,
|
6171
|
+
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;
|
6760
6172
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
6761
6173
|
if (createUserATA === void 0) { createUserATA = true; }
|
6762
6174
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
@@ -6961,9 +6373,9 @@ var PerpetualsClient = (function () {
|
|
6961
6373
|
}
|
6962
6374
|
return [3, 20];
|
6963
6375
|
case 19:
|
6964
|
-
|
6965
|
-
console.error("perpClient Swap error:: ",
|
6966
|
-
throw
|
6376
|
+
err_38 = _g.sent();
|
6377
|
+
console.error("perpClient Swap error:: ", err_38);
|
6378
|
+
throw err_38;
|
6967
6379
|
case 20: return [2, {
|
6968
6380
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6969
6381
|
additionalSigners: additionalSigners
|
@@ -6973,7 +6385,7 @@ var PerpetualsClient = (function () {
|
|
6973
6385
|
});
|
6974
6386
|
};
|
6975
6387
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6976
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx,
|
6388
|
+
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_39;
|
6977
6389
|
return __generator(this, function (_b) {
|
6978
6390
|
switch (_b.label) {
|
6979
6391
|
case 0:
|
@@ -7029,9 +6441,9 @@ var PerpetualsClient = (function () {
|
|
7029
6441
|
instructions.push(inx);
|
7030
6442
|
return [3, 4];
|
7031
6443
|
case 3:
|
7032
|
-
|
7033
|
-
console.error("perpClient Swap error:: ",
|
7034
|
-
throw
|
6444
|
+
err_39 = _b.sent();
|
6445
|
+
console.error("perpClient Swap error:: ", err_39);
|
6446
|
+
throw err_39;
|
7035
6447
|
case 4: return [2, {
|
7036
6448
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7037
6449
|
additionalSigners: additionalSigners
|
@@ -7040,7 +6452,7 @@ var PerpetualsClient = (function () {
|
|
7040
6452
|
});
|
7041
6453
|
}); };
|
7042
6454
|
this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7043
|
-
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction,
|
6455
|
+
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_40;
|
7044
6456
|
return __generator(this, function (_d) {
|
7045
6457
|
switch (_d.label) {
|
7046
6458
|
case 0:
|
@@ -7088,9 +6500,9 @@ var PerpetualsClient = (function () {
|
|
7088
6500
|
instructions.push(setLpTokenPriceInstruction);
|
7089
6501
|
return [3, 4];
|
7090
6502
|
case 3:
|
7091
|
-
|
7092
|
-
console.log("perpClient setLpTokenPriceInstruction error:: ",
|
7093
|
-
throw
|
6503
|
+
err_40 = _d.sent();
|
6504
|
+
console.log("perpClient setLpTokenPriceInstruction error:: ", err_40);
|
6505
|
+
throw err_40;
|
7094
6506
|
case 4: return [2, {
|
7095
6507
|
instructions: __spreadArray([], instructions, true),
|
7096
6508
|
additionalSigners: additionalSigners
|
@@ -7138,7 +6550,7 @@ var PerpetualsClient = (function () {
|
|
7138
6550
|
});
|
7139
6551
|
}); };
|
7140
6552
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
7141
|
-
var adminMetas, _i, admins_2, admin,
|
6553
|
+
var adminMetas, _i, admins_2, admin, err_41;
|
7142
6554
|
return __generator(this, function (_a) {
|
7143
6555
|
switch (_a.label) {
|
7144
6556
|
case 0:
|
@@ -7168,11 +6580,11 @@ var PerpetualsClient = (function () {
|
|
7168
6580
|
_a.sent();
|
7169
6581
|
return [3, 4];
|
7170
6582
|
case 3:
|
7171
|
-
|
6583
|
+
err_41 = _a.sent();
|
7172
6584
|
if (this.printErrors) {
|
7173
|
-
console.error("setAdminSigners err:",
|
6585
|
+
console.error("setAdminSigners err:", err_41);
|
7174
6586
|
}
|
7175
|
-
throw
|
6587
|
+
throw err_41;
|
7176
6588
|
case 4: return [2];
|
7177
6589
|
}
|
7178
6590
|
});
|
@@ -7361,7 +6773,7 @@ var PerpetualsClient = (function () {
|
|
7361
6773
|
});
|
7362
6774
|
}); };
|
7363
6775
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7364
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
6776
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_42;
|
7365
6777
|
return __generator(this, function (_a) {
|
7366
6778
|
switch (_a.label) {
|
7367
6779
|
case 0:
|
@@ -7394,9 +6806,9 @@ var PerpetualsClient = (function () {
|
|
7394
6806
|
instructions.push(withdrawFeesIx);
|
7395
6807
|
return [3, 5];
|
7396
6808
|
case 4:
|
7397
|
-
|
7398
|
-
console.log("perpClient setPool error:: ",
|
7399
|
-
throw
|
6809
|
+
err_42 = _a.sent();
|
6810
|
+
console.log("perpClient setPool error:: ", err_42);
|
6811
|
+
throw err_42;
|
7400
6812
|
case 5: return [2, {
|
7401
6813
|
instructions: __spreadArray([], instructions, true),
|
7402
6814
|
additionalSigners: additionalSigners
|
@@ -7405,7 +6817,7 @@ var PerpetualsClient = (function () {
|
|
7405
6817
|
});
|
7406
6818
|
}); };
|
7407
6819
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7408
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
6820
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_43;
|
7409
6821
|
return __generator(this, function (_a) {
|
7410
6822
|
switch (_a.label) {
|
7411
6823
|
case 0:
|
@@ -7439,9 +6851,9 @@ var PerpetualsClient = (function () {
|
|
7439
6851
|
instructions.push(moveProtocolFeesIx);
|
7440
6852
|
return [3, 4];
|
7441
6853
|
case 3:
|
7442
|
-
|
7443
|
-
console.log("perpClient setPool error:: ",
|
7444
|
-
throw
|
6854
|
+
err_43 = _a.sent();
|
6855
|
+
console.log("perpClient setPool error:: ", err_43);
|
6856
|
+
throw err_43;
|
7445
6857
|
case 4: return [2, {
|
7446
6858
|
instructions: __spreadArray([], instructions, true),
|
7447
6859
|
additionalSigners: additionalSigners
|
@@ -7450,7 +6862,7 @@ var PerpetualsClient = (function () {
|
|
7450
6862
|
});
|
7451
6863
|
}); };
|
7452
6864
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7453
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
6865
|
+
var publicKey, setProtocolFeeShareBpsIx, err_44;
|
7454
6866
|
return __generator(this, function (_a) {
|
7455
6867
|
switch (_a.label) {
|
7456
6868
|
case 0:
|
@@ -7470,15 +6882,15 @@ var PerpetualsClient = (function () {
|
|
7470
6882
|
setProtocolFeeShareBpsIx = _a.sent();
|
7471
6883
|
return [2, setProtocolFeeShareBpsIx];
|
7472
6884
|
case 2:
|
7473
|
-
|
7474
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
7475
|
-
throw
|
6885
|
+
err_44 = _a.sent();
|
6886
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_44);
|
6887
|
+
throw err_44;
|
7476
6888
|
case 3: return [2];
|
7477
6889
|
}
|
7478
6890
|
});
|
7479
6891
|
}); };
|
7480
6892
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7481
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
6893
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_45;
|
7482
6894
|
return __generator(this, function (_a) {
|
7483
6895
|
switch (_a.label) {
|
7484
6896
|
case 0:
|
@@ -7505,9 +6917,9 @@ var PerpetualsClient = (function () {
|
|
7505
6917
|
instructions.push(setPermissionsInstruction);
|
7506
6918
|
return [3, 4];
|
7507
6919
|
case 3:
|
7508
|
-
|
7509
|
-
console.log("perpClient setPool error:: ",
|
7510
|
-
throw
|
6920
|
+
err_45 = _a.sent();
|
6921
|
+
console.log("perpClient setPool error:: ", err_45);
|
6922
|
+
throw err_45;
|
7511
6923
|
case 4: return [2, {
|
7512
6924
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7513
6925
|
additionalSigners: additionalSigners
|
@@ -7516,7 +6928,7 @@ var PerpetualsClient = (function () {
|
|
7516
6928
|
});
|
7517
6929
|
}); };
|
7518
6930
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7519
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
6931
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_46;
|
7520
6932
|
var _f;
|
7521
6933
|
return __generator(this, function (_g) {
|
7522
6934
|
switch (_g.label) {
|
@@ -7577,9 +6989,9 @@ var PerpetualsClient = (function () {
|
|
7577
6989
|
instructions.push(reimburse);
|
7578
6990
|
return [3, 5];
|
7579
6991
|
case 4:
|
7580
|
-
|
7581
|
-
console.log("perpClient setPool error:: ",
|
7582
|
-
throw
|
6992
|
+
err_46 = _g.sent();
|
6993
|
+
console.log("perpClient setPool error:: ", err_46);
|
6994
|
+
throw err_46;
|
7583
6995
|
case 5: return [2, {
|
7584
6996
|
instructions: __spreadArray([], instructions, true),
|
7585
6997
|
additionalSigners: additionalSigners
|
@@ -7587,8 +6999,8 @@ var PerpetualsClient = (function () {
|
|
7587
6999
|
}
|
7588
7000
|
});
|
7589
7001
|
}); };
|
7590
|
-
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7591
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
7002
|
+
this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7003
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_47;
|
7592
7004
|
return __generator(this, function (_a) {
|
7593
7005
|
switch (_a.label) {
|
7594
7006
|
case 0:
|
@@ -7600,6 +7012,7 @@ var PerpetualsClient = (function () {
|
|
7600
7012
|
_a.trys.push([1, 3, , 4]);
|
7601
7013
|
return [4, this.program.methods
|
7602
7014
|
.setInternalOraclePrice({
|
7015
|
+
useCurrentTime: useCurrentTime,
|
7603
7016
|
price: price,
|
7604
7017
|
expo: expo,
|
7605
7018
|
conf: conf,
|
@@ -7621,9 +7034,9 @@ var PerpetualsClient = (function () {
|
|
7621
7034
|
instructions.push(setInternalOraclePrice);
|
7622
7035
|
return [3, 4];
|
7623
7036
|
case 3:
|
7624
|
-
|
7625
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7626
|
-
throw
|
7037
|
+
err_47 = _a.sent();
|
7038
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_47);
|
7039
|
+
throw err_47;
|
7627
7040
|
case 4: return [2, {
|
7628
7041
|
instructions: __spreadArray([], instructions, true),
|
7629
7042
|
additionalSigners: additionalSigners
|
@@ -7631,8 +7044,8 @@ var PerpetualsClient = (function () {
|
|
7631
7044
|
}
|
7632
7045
|
});
|
7633
7046
|
}); };
|
7634
|
-
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7635
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7047
|
+
this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7048
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_48;
|
7636
7049
|
return __generator(this, function (_a) {
|
7637
7050
|
switch (_a.label) {
|
7638
7051
|
case 0:
|
@@ -7670,7 +7083,8 @@ var PerpetualsClient = (function () {
|
|
7670
7083
|
_a.trys.push([1, 3, , 4]);
|
7671
7084
|
return [4, this.program.methods
|
7672
7085
|
.setInternalCurrentPrice({
|
7673
|
-
prices: tokenInternalPrices
|
7086
|
+
prices: tokenInternalPrices,
|
7087
|
+
useCurrentTime: useCurrentTime ? 1 : 0
|
7674
7088
|
})
|
7675
7089
|
.accounts({
|
7676
7090
|
authority: POOL_CONFIGS[0].backupOracle,
|
@@ -7682,9 +7096,9 @@ var PerpetualsClient = (function () {
|
|
7682
7096
|
instructions.push(setInternalOraclePrice);
|
7683
7097
|
return [3, 4];
|
7684
7098
|
case 3:
|
7685
|
-
|
7686
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7687
|
-
throw
|
7099
|
+
err_48 = _a.sent();
|
7100
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_48);
|
7101
|
+
throw err_48;
|
7688
7102
|
case 4: return [2, {
|
7689
7103
|
instructions: __spreadArray([], instructions, true),
|
7690
7104
|
additionalSigners: additionalSigners
|
@@ -7693,7 +7107,7 @@ var PerpetualsClient = (function () {
|
|
7693
7107
|
});
|
7694
7108
|
}); };
|
7695
7109
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7696
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7110
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_49;
|
7697
7111
|
return __generator(this, function (_a) {
|
7698
7112
|
switch (_a.label) {
|
7699
7113
|
case 0:
|
@@ -7704,21 +7118,11 @@ var PerpetualsClient = (function () {
|
|
7704
7118
|
accountMetas = [];
|
7705
7119
|
_loop_2 = function (tokenMint) {
|
7706
7120
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7707
|
-
accountMetas.push({
|
7708
|
-
pubkey: custody.custodyAccount,
|
7709
|
-
isSigner: false,
|
7710
|
-
isWritable: false,
|
7711
|
-
});
|
7712
7121
|
accountMetas.push({
|
7713
7122
|
pubkey: custody.intOracleAccount,
|
7714
7123
|
isSigner: false,
|
7715
7124
|
isWritable: true,
|
7716
7125
|
});
|
7717
|
-
accountMetas.push({
|
7718
|
-
pubkey: custody.extOracleAccount,
|
7719
|
-
isSigner: false,
|
7720
|
-
isWritable: false,
|
7721
|
-
});
|
7722
7126
|
};
|
7723
7127
|
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
7724
7128
|
tokenMint = tokenMintList_2[_i];
|
@@ -7743,9 +7147,9 @@ var PerpetualsClient = (function () {
|
|
7743
7147
|
instructions.push(setInternalOraclePrice);
|
7744
7148
|
return [3, 4];
|
7745
7149
|
case 3:
|
7746
|
-
|
7747
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7748
|
-
throw
|
7150
|
+
err_49 = _a.sent();
|
7151
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_49);
|
7152
|
+
throw err_49;
|
7749
7153
|
case 4: return [2, {
|
7750
7154
|
instructions: __spreadArray([], instructions, true),
|
7751
7155
|
additionalSigners: additionalSigners
|
@@ -7754,7 +7158,7 @@ var PerpetualsClient = (function () {
|
|
7754
7158
|
});
|
7755
7159
|
}); };
|
7756
7160
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7757
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
7161
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_50;
|
7758
7162
|
return __generator(this, function (_a) {
|
7759
7163
|
switch (_a.label) {
|
7760
7164
|
case 0:
|
@@ -7792,8 +7196,8 @@ var PerpetualsClient = (function () {
|
|
7792
7196
|
instructions.push(renameFlp);
|
7793
7197
|
return [3, 4];
|
7794
7198
|
case 3:
|
7795
|
-
|
7796
|
-
console.log("perpClient renameFlp error:: ",
|
7199
|
+
err_50 = _a.sent();
|
7200
|
+
console.log("perpClient renameFlp error:: ", err_50);
|
7797
7201
|
return [3, 4];
|
7798
7202
|
case 4: return [2, {
|
7799
7203
|
instructions: __spreadArray([], instructions, true),
|
@@ -7803,7 +7207,7 @@ var PerpetualsClient = (function () {
|
|
7803
7207
|
});
|
7804
7208
|
}); };
|
7805
7209
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7806
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
7210
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_51;
|
7807
7211
|
return __generator(this, function (_a) {
|
7808
7212
|
switch (_a.label) {
|
7809
7213
|
case 0:
|
@@ -7841,9 +7245,9 @@ var PerpetualsClient = (function () {
|
|
7841
7245
|
instructions.push(initStakeInstruction);
|
7842
7246
|
return [3, 4];
|
7843
7247
|
case 3:
|
7844
|
-
|
7845
|
-
console.log("perpClient InitStaking error:: ",
|
7846
|
-
throw
|
7248
|
+
err_51 = _a.sent();
|
7249
|
+
console.log("perpClient InitStaking error:: ", err_51);
|
7250
|
+
throw err_51;
|
7847
7251
|
case 4: return [2, {
|
7848
7252
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7849
7253
|
additionalSigners: additionalSigners
|
@@ -7852,7 +7256,7 @@ var PerpetualsClient = (function () {
|
|
7852
7256
|
});
|
7853
7257
|
}); };
|
7854
7258
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7855
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction,
|
7259
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_52;
|
7856
7260
|
return __generator(this, function (_a) {
|
7857
7261
|
switch (_a.label) {
|
7858
7262
|
case 0:
|
@@ -7897,9 +7301,9 @@ var PerpetualsClient = (function () {
|
|
7897
7301
|
instructions.push(initCompoundingInstruction);
|
7898
7302
|
return [3, 4];
|
7899
7303
|
case 3:
|
7900
|
-
|
7901
|
-
console.log("perpClient initCompounding error:: ",
|
7902
|
-
throw
|
7304
|
+
err_52 = _a.sent();
|
7305
|
+
console.log("perpClient initCompounding error:: ", err_52);
|
7306
|
+
throw err_52;
|
7903
7307
|
case 4: return [2, {
|
7904
7308
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7905
7309
|
additionalSigners: additionalSigners
|
@@ -7908,7 +7312,7 @@ var PerpetualsClient = (function () {
|
|
7908
7312
|
});
|
7909
7313
|
}); };
|
7910
7314
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7911
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
7315
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_53;
|
7912
7316
|
return __generator(this, function (_a) {
|
7913
7317
|
switch (_a.label) {
|
7914
7318
|
case 0:
|
@@ -7949,9 +7353,9 @@ var PerpetualsClient = (function () {
|
|
7949
7353
|
instructions.push(initTokenVaultInstruction);
|
7950
7354
|
return [3, 4];
|
7951
7355
|
case 3:
|
7952
|
-
|
7953
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
7954
|
-
throw
|
7356
|
+
err_53 = _a.sent();
|
7357
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_53);
|
7358
|
+
throw err_53;
|
7955
7359
|
case 4: return [2, {
|
7956
7360
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7957
7361
|
additionalSigners: additionalSigners
|
@@ -7960,7 +7364,7 @@ var PerpetualsClient = (function () {
|
|
7960
7364
|
});
|
7961
7365
|
}); };
|
7962
7366
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7963
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
7367
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_54;
|
7964
7368
|
return __generator(this, function (_a) {
|
7965
7369
|
switch (_a.label) {
|
7966
7370
|
case 0:
|
@@ -7991,9 +7395,9 @@ var PerpetualsClient = (function () {
|
|
7991
7395
|
instructions.push(setTokenVaultConfigInstruction);
|
7992
7396
|
return [3, 4];
|
7993
7397
|
case 3:
|
7994
|
-
|
7995
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
7996
|
-
throw
|
7398
|
+
err_54 = _a.sent();
|
7399
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_54);
|
7400
|
+
throw err_54;
|
7997
7401
|
case 4: return [2, {
|
7998
7402
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7999
7403
|
additionalSigners: additionalSigners
|
@@ -8002,7 +7406,7 @@ var PerpetualsClient = (function () {
|
|
8002
7406
|
});
|
8003
7407
|
}); };
|
8004
7408
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8005
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
7409
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_55;
|
8006
7410
|
return __generator(this, function (_a) {
|
8007
7411
|
switch (_a.label) {
|
8008
7412
|
case 0:
|
@@ -8041,9 +7445,9 @@ var PerpetualsClient = (function () {
|
|
8041
7445
|
instructions.push(withdrawInstantFeeInstruction);
|
8042
7446
|
return [3, 6];
|
8043
7447
|
case 5:
|
8044
|
-
|
8045
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
8046
|
-
throw
|
7448
|
+
err_55 = _a.sent();
|
7449
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_55);
|
7450
|
+
throw err_55;
|
8047
7451
|
case 6: return [2, {
|
8048
7452
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8049
7453
|
additionalSigners: additionalSigners
|
@@ -8052,7 +7456,7 @@ var PerpetualsClient = (function () {
|
|
8052
7456
|
});
|
8053
7457
|
}); };
|
8054
7458
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8055
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
7459
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_56;
|
8056
7460
|
return __generator(this, function (_a) {
|
8057
7461
|
switch (_a.label) {
|
8058
7462
|
case 0:
|
@@ -8089,9 +7493,9 @@ var PerpetualsClient = (function () {
|
|
8089
7493
|
instructions.push(initRevenueTokenAccountInstruction);
|
8090
7494
|
return [3, 4];
|
8091
7495
|
case 3:
|
8092
|
-
|
8093
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
8094
|
-
throw
|
7496
|
+
err_56 = _a.sent();
|
7497
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_56);
|
7498
|
+
throw err_56;
|
8095
7499
|
case 4: return [2, {
|
8096
7500
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8097
7501
|
additionalSigners: additionalSigners
|
@@ -8100,7 +7504,7 @@ var PerpetualsClient = (function () {
|
|
8100
7504
|
});
|
8101
7505
|
}); };
|
8102
7506
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8103
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
7507
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_57;
|
8104
7508
|
return __generator(this, function (_a) {
|
8105
7509
|
switch (_a.label) {
|
8106
7510
|
case 0:
|
@@ -8139,9 +7543,9 @@ var PerpetualsClient = (function () {
|
|
8139
7543
|
instructions.push(distributeTokenRewardInstruction);
|
8140
7544
|
return [3, 4];
|
8141
7545
|
case 3:
|
8142
|
-
|
8143
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
8144
|
-
throw
|
7546
|
+
err_57 = _a.sent();
|
7547
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_57);
|
7548
|
+
throw err_57;
|
8145
7549
|
case 4: return [2, {
|
8146
7550
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8147
7551
|
additionalSigners: additionalSigners
|
@@ -8150,7 +7554,7 @@ var PerpetualsClient = (function () {
|
|
8150
7554
|
});
|
8151
7555
|
}); };
|
8152
7556
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
8153
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
7557
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_58;
|
8154
7558
|
return __generator(this, function (_a) {
|
8155
7559
|
switch (_a.label) {
|
8156
7560
|
case 0:
|
@@ -8178,9 +7582,9 @@ var PerpetualsClient = (function () {
|
|
8178
7582
|
instructions.push(setTokenStakeLevelInstruction);
|
8179
7583
|
return [3, 4];
|
8180
7584
|
case 3:
|
8181
|
-
|
8182
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
8183
|
-
throw
|
7585
|
+
err_58 = _a.sent();
|
7586
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_58);
|
7587
|
+
throw err_58;
|
8184
7588
|
case 4: return [2, {
|
8185
7589
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8186
7590
|
additionalSigners: additionalSigners
|
@@ -8189,7 +7593,7 @@ var PerpetualsClient = (function () {
|
|
8189
7593
|
});
|
8190
7594
|
}); };
|
8191
7595
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8192
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
7596
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_59;
|
8193
7597
|
return __generator(this, function (_a) {
|
8194
7598
|
switch (_a.label) {
|
8195
7599
|
case 0:
|
@@ -8221,9 +7625,49 @@ var PerpetualsClient = (function () {
|
|
8221
7625
|
instructions.push(setTokenRewardInstruction);
|
8222
7626
|
return [3, 4];
|
8223
7627
|
case 3:
|
8224
|
-
|
8225
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
8226
|
-
throw
|
7628
|
+
err_59 = _a.sent();
|
7629
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_59);
|
7630
|
+
throw err_59;
|
7631
|
+
case 4: return [2, {
|
7632
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7633
|
+
additionalSigners: additionalSigners
|
7634
|
+
}];
|
7635
|
+
}
|
7636
|
+
});
|
7637
|
+
}); };
|
7638
|
+
this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
|
7639
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_60;
|
7640
|
+
return __generator(this, function (_a) {
|
7641
|
+
switch (_a.label) {
|
7642
|
+
case 0:
|
7643
|
+
publicKey = this.provider.wallet.publicKey;
|
7644
|
+
preInstructions = [];
|
7645
|
+
instructions = [];
|
7646
|
+
postInstructions = [];
|
7647
|
+
additionalSigners = [];
|
7648
|
+
_a.label = 1;
|
7649
|
+
case 1:
|
7650
|
+
_a.trys.push([1, 3, , 4]);
|
7651
|
+
return [4, this.program.methods
|
7652
|
+
.resizeInternalOracle({
|
7653
|
+
extOracle: extOracle
|
7654
|
+
})
|
7655
|
+
.accounts({
|
7656
|
+
admin: publicKey,
|
7657
|
+
multisig: this.multisig.publicKey,
|
7658
|
+
custodyTokenMint: tokenMint,
|
7659
|
+
intOracleAccount: intOracleAccount,
|
7660
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7661
|
+
})
|
7662
|
+
.instruction()];
|
7663
|
+
case 2:
|
7664
|
+
resizeInternalOracleInstruction = _a.sent();
|
7665
|
+
instructions.push(resizeInternalOracleInstruction);
|
7666
|
+
return [3, 4];
|
7667
|
+
case 3:
|
7668
|
+
err_60 = _a.sent();
|
7669
|
+
console.log("perpClient resizeInternalOracleInstruction error:: ", err_60);
|
7670
|
+
throw err_60;
|
8227
7671
|
case 4: return [2, {
|
8228
7672
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8229
7673
|
additionalSigners: additionalSigners
|