flash-sdk 9.0.0-alpha.5 → 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 +52 -63
- package/dist/PerpetualsClient.js +470 -1032
- package/dist/PoolConfig.d.ts +2 -0
- package/dist/PoolConfig.json +244 -10
- package/dist/idl/perpetuals.d.ts +73 -497
- package/dist/idl/perpetuals.js +73 -497
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +0 -2
- package/package.json +1 -1
- package/dist/TradingAccount.d.ts +0 -23
- package/dist/TradingAccount.js +0 -17
package/dist/PerpetualsClient.js
CHANGED
@@ -638,24 +638,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:
|
@@ -2933,13 +2835,13 @@ var PerpetualsClient = (function () {
|
|
2933
2835
|
});
|
2934
2836
|
});
|
2935
2837
|
};
|
2936
|
-
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
2838
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2937
2839
|
var args_1 = [];
|
2938
|
-
for (var _i =
|
2939
|
-
args_1[_i -
|
2840
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
2841
|
+
args_1[_i - 7] = arguments[_i];
|
2940
2842
|
}
|
2941
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
2942
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount,
|
2843
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey) {
|
2844
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, inx, err_4;
|
2943
2845
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2944
2846
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2945
2847
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
@@ -3007,18 +2909,12 @@ var PerpetualsClient = (function () {
|
|
3007
2909
|
if (!(_a.sent())) {
|
3008
2910
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3009
2911
|
}
|
3010
|
-
rebateMintAccount = {
|
3011
|
-
pubkey: collateralCustodyConfig.mintKey,
|
3012
|
-
isSigner: false,
|
3013
|
-
isWritable: false
|
3014
|
-
};
|
3015
2912
|
_a.label = 5;
|
3016
2913
|
case 5:
|
3017
2914
|
_a.trys.push([5, 7, , 8]);
|
3018
2915
|
return [4, this.program.methods
|
3019
2916
|
.closeAndSwap({
|
3020
2917
|
priceWithSlippage: priceWithSlippage,
|
3021
|
-
minSwapAmountOut: minSwapAmountOut,
|
3022
2918
|
privilege: privilege
|
3023
2919
|
})
|
3024
2920
|
.accounts({
|
@@ -4082,119 +3978,8 @@ var PerpetualsClient = (function () {
|
|
4082
3978
|
}
|
4083
3979
|
});
|
4084
3980
|
}); };
|
4085
|
-
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4086
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
4087
|
-
return __generator(this, function (_a) {
|
4088
|
-
switch (_a.label) {
|
4089
|
-
case 0:
|
4090
|
-
publicKey = this.provider.wallet.publicKey;
|
4091
|
-
preInstructions = [];
|
4092
|
-
instructions = [];
|
4093
|
-
postInstructions = [];
|
4094
|
-
additionalSigners = [];
|
4095
|
-
_a.label = 1;
|
4096
|
-
case 1:
|
4097
|
-
_a.trys.push([1, 4, , 5]);
|
4098
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4099
|
-
Buffer.from("trading"),
|
4100
|
-
nftMint.toBuffer(),
|
4101
|
-
], this.programId)[0];
|
4102
|
-
nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4103
|
-
Buffer.from("referral"),
|
4104
|
-
publicKey.toBuffer(),
|
4105
|
-
], this.programId)[0];
|
4106
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
4107
|
-
case 2:
|
4108
|
-
nftTokenAccount = _a.sent();
|
4109
|
-
flpStakeAccountMetas = [];
|
4110
|
-
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
4111
|
-
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
4112
|
-
flpStakeAccountMetas.push({
|
4113
|
-
pubkey: flpStakeAccountPk,
|
4114
|
-
isSigner: false,
|
4115
|
-
isWritable: true,
|
4116
|
-
});
|
4117
|
-
}
|
4118
|
-
return [4, this.program.methods
|
4119
|
-
.updateTradingAccount({
|
4120
|
-
updateReferer: updateReferer,
|
4121
|
-
updateBooster: updateBooster
|
4122
|
-
})
|
4123
|
-
.accounts({
|
4124
|
-
owner: publicKey,
|
4125
|
-
feePayer: publicKey,
|
4126
|
-
nftTokenAccount: nftTokenAccount,
|
4127
|
-
referralAccount: nftReferralAccount,
|
4128
|
-
tradingAccount: nftTradingAccount
|
4129
|
-
})
|
4130
|
-
.instruction()];
|
4131
|
-
case 3:
|
4132
|
-
updateNftTradingAccountInstruction = _a.sent();
|
4133
|
-
instructions.push(updateNftTradingAccountInstruction);
|
4134
|
-
return [3, 5];
|
4135
|
-
case 4:
|
4136
|
-
err_8 = _a.sent();
|
4137
|
-
console.log("perpClient updateNftAccount error:: ", err_8);
|
4138
|
-
throw err_8;
|
4139
|
-
case 5: return [2, {
|
4140
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4141
|
-
additionalSigners: additionalSigners
|
4142
|
-
}];
|
4143
|
-
}
|
4144
|
-
});
|
4145
|
-
}); };
|
4146
|
-
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4147
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
4148
|
-
return __generator(this, function (_a) {
|
4149
|
-
switch (_a.label) {
|
4150
|
-
case 0:
|
4151
|
-
publicKey = this.provider.wallet.publicKey;
|
4152
|
-
preInstructions = [];
|
4153
|
-
instructions = [];
|
4154
|
-
postInstructions = [];
|
4155
|
-
additionalSigners = [];
|
4156
|
-
_a.label = 1;
|
4157
|
-
case 1:
|
4158
|
-
_a.trys.push([1, 3, , 4]);
|
4159
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4160
|
-
Buffer.from("trading"),
|
4161
|
-
nftMint.toBuffer(),
|
4162
|
-
], this.programId)[0];
|
4163
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4164
|
-
return [4, this.program.methods
|
4165
|
-
.levelUp({})
|
4166
|
-
.accounts({
|
4167
|
-
owner: publicKey,
|
4168
|
-
perpetuals: this.perpetuals.publicKey,
|
4169
|
-
pool: poolConfig.poolAddress,
|
4170
|
-
metadataAccount: metadataAccount,
|
4171
|
-
nftMint: nftMint,
|
4172
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
4173
|
-
tradingAccount: nftTradingAccount,
|
4174
|
-
transferAuthority: this.authority.publicKey,
|
4175
|
-
authorizationRulesAccount: authorizationRulesAccount,
|
4176
|
-
authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
|
4177
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
4178
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4179
|
-
})
|
4180
|
-
.instruction()];
|
4181
|
-
case 2:
|
4182
|
-
levelUpInstruction = _a.sent();
|
4183
|
-
instructions.push(levelUpInstruction);
|
4184
|
-
return [3, 4];
|
4185
|
-
case 3:
|
4186
|
-
err_9 = _a.sent();
|
4187
|
-
console.log("perpClient levelUp error:: ", err_9);
|
4188
|
-
throw err_9;
|
4189
|
-
case 4: return [2, {
|
4190
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4191
|
-
additionalSigners: additionalSigners
|
4192
|
-
}];
|
4193
|
-
}
|
4194
|
-
});
|
4195
|
-
}); };
|
4196
3981
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4197
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
3982
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
|
4198
3983
|
return __generator(this, function (_a) {
|
4199
3984
|
switch (_a.label) {
|
4200
3985
|
case 0:
|
@@ -4236,9 +4021,9 @@ var PerpetualsClient = (function () {
|
|
4236
4021
|
instructions.push(depositStakeInstruction);
|
4237
4022
|
return [3, 5];
|
4238
4023
|
case 4:
|
4239
|
-
|
4240
|
-
console.log("perpClient depositStaking error:: ",
|
4241
|
-
throw
|
4024
|
+
err_8 = _a.sent();
|
4025
|
+
console.log("perpClient depositStaking error:: ", err_8);
|
4026
|
+
throw err_8;
|
4242
4027
|
case 5: return [2, {
|
4243
4028
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4244
4029
|
additionalSigners: additionalSigners
|
@@ -4247,7 +4032,7 @@ var PerpetualsClient = (function () {
|
|
4247
4032
|
});
|
4248
4033
|
}); };
|
4249
4034
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4250
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4035
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
|
4251
4036
|
return __generator(this, function (_c) {
|
4252
4037
|
switch (_c.label) {
|
4253
4038
|
case 0:
|
@@ -4294,9 +4079,9 @@ var PerpetualsClient = (function () {
|
|
4294
4079
|
refreshStakeInstruction = _c.sent();
|
4295
4080
|
return [2, refreshStakeInstruction];
|
4296
4081
|
case 2:
|
4297
|
-
|
4298
|
-
console.log("perpClient refreshStaking error:: ",
|
4299
|
-
throw
|
4082
|
+
err_9 = _c.sent();
|
4083
|
+
console.log("perpClient refreshStaking error:: ", err_9);
|
4084
|
+
throw err_9;
|
4300
4085
|
case 3: return [2];
|
4301
4086
|
}
|
4302
4087
|
});
|
@@ -4307,7 +4092,7 @@ var PerpetualsClient = (function () {
|
|
4307
4092
|
args_1[_i - 3] = arguments[_i];
|
4308
4093
|
}
|
4309
4094
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4310
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
4095
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
|
4311
4096
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4312
4097
|
return __generator(this, function (_c) {
|
4313
4098
|
switch (_c.label) {
|
@@ -4355,9 +4140,9 @@ var PerpetualsClient = (function () {
|
|
4355
4140
|
refreshStakeInstruction = _c.sent();
|
4356
4141
|
return [2, refreshStakeInstruction];
|
4357
4142
|
case 2:
|
4358
|
-
|
4359
|
-
console.log("perpClient refreshStaking error:: ",
|
4360
|
-
throw
|
4143
|
+
err_10 = _c.sent();
|
4144
|
+
console.log("perpClient refreshStaking error:: ", err_10);
|
4145
|
+
throw err_10;
|
4361
4146
|
case 3: return [2];
|
4362
4147
|
}
|
4363
4148
|
});
|
@@ -4369,7 +4154,7 @@ var PerpetualsClient = (function () {
|
|
4369
4154
|
args_1[_i - 3] = arguments[_i];
|
4370
4155
|
}
|
4371
4156
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4372
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
4157
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
|
4373
4158
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4374
4159
|
return __generator(this, function (_b) {
|
4375
4160
|
switch (_b.label) {
|
@@ -4421,9 +4206,9 @@ var PerpetualsClient = (function () {
|
|
4421
4206
|
instructions.push(unstakeInstantInstruction);
|
4422
4207
|
return [3, 6];
|
4423
4208
|
case 5:
|
4424
|
-
|
4425
|
-
console.log("perpClient unstakeInstant error:: ",
|
4426
|
-
throw
|
4209
|
+
err_11 = _b.sent();
|
4210
|
+
console.log("perpClient unstakeInstant error:: ", err_11);
|
4211
|
+
throw err_11;
|
4427
4212
|
case 6: return [2, {
|
4428
4213
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4429
4214
|
additionalSigners: additionalSigners
|
@@ -4433,7 +4218,7 @@ var PerpetualsClient = (function () {
|
|
4433
4218
|
});
|
4434
4219
|
};
|
4435
4220
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4436
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4221
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
4437
4222
|
return __generator(this, function (_c) {
|
4438
4223
|
switch (_c.label) {
|
4439
4224
|
case 0:
|
@@ -4477,15 +4262,15 @@ var PerpetualsClient = (function () {
|
|
4477
4262
|
refreshStakeInstruction = _c.sent();
|
4478
4263
|
return [2, refreshStakeInstruction];
|
4479
4264
|
case 2:
|
4480
|
-
|
4481
|
-
console.log("perpClient refreshStaking error:: ",
|
4482
|
-
throw
|
4265
|
+
err_12 = _c.sent();
|
4266
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4267
|
+
throw err_12;
|
4483
4268
|
case 3: return [2];
|
4484
4269
|
}
|
4485
4270
|
});
|
4486
4271
|
}); };
|
4487
4272
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4488
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4273
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
4489
4274
|
return __generator(this, function (_a) {
|
4490
4275
|
switch (_a.label) {
|
4491
4276
|
case 0:
|
@@ -4519,9 +4304,9 @@ var PerpetualsClient = (function () {
|
|
4519
4304
|
instructions.push(unstakeRequestInstruction);
|
4520
4305
|
return [3, 4];
|
4521
4306
|
case 3:
|
4522
|
-
|
4523
|
-
console.log("perpClient unstakeRequest error:: ",
|
4524
|
-
throw
|
4307
|
+
err_13 = _a.sent();
|
4308
|
+
console.log("perpClient unstakeRequest error:: ", err_13);
|
4309
|
+
throw err_13;
|
4525
4310
|
case 4: return [2, {
|
4526
4311
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4527
4312
|
additionalSigners: additionalSigners
|
@@ -4535,7 +4320,7 @@ var PerpetualsClient = (function () {
|
|
4535
4320
|
args_1[_i - 1] = arguments[_i];
|
4536
4321
|
}
|
4537
4322
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4538
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4323
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
|
4539
4324
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
4540
4325
|
if (deactivated === void 0) { deactivated = true; }
|
4541
4326
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
@@ -4591,9 +4376,9 @@ var PerpetualsClient = (function () {
|
|
4591
4376
|
instructions.push(withdrawStakeInstruction);
|
4592
4377
|
return [3, 6];
|
4593
4378
|
case 5:
|
4594
|
-
|
4595
|
-
console.log("perpClient withdrawStake error:: ",
|
4596
|
-
throw
|
4379
|
+
err_14 = _b.sent();
|
4380
|
+
console.log("perpClient withdrawStake error:: ", err_14);
|
4381
|
+
throw err_14;
|
4597
4382
|
case 6: return [2, {
|
4598
4383
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4599
4384
|
additionalSigners: additionalSigners
|
@@ -4608,7 +4393,7 @@ var PerpetualsClient = (function () {
|
|
4608
4393
|
args_1[_i - 3] = arguments[_i];
|
4609
4394
|
}
|
4610
4395
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4611
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
4396
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
4612
4397
|
if (createUserATA === void 0) { createUserATA = true; }
|
4613
4398
|
return __generator(this, function (_b) {
|
4614
4399
|
switch (_b.label) {
|
@@ -4669,9 +4454,9 @@ var PerpetualsClient = (function () {
|
|
4669
4454
|
instructions.push(withdrawStakeInstruction);
|
4670
4455
|
return [3, 6];
|
4671
4456
|
case 5:
|
4672
|
-
|
4673
|
-
console.log("perpClient withdrawStake error:: ",
|
4674
|
-
throw
|
4457
|
+
err_15 = _b.sent();
|
4458
|
+
console.log("perpClient withdrawStake error:: ", err_15);
|
4459
|
+
throw err_15;
|
4675
4460
|
case 6: return [2, {
|
4676
4461
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4677
4462
|
additionalSigners: additionalSigners
|
@@ -4686,7 +4471,7 @@ var PerpetualsClient = (function () {
|
|
4686
4471
|
args_1[_i - 5] = arguments[_i];
|
4687
4472
|
}
|
4688
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) {
|
4689
|
-
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity,
|
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;
|
4690
4475
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4691
4476
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4692
4477
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4814,8 +4599,8 @@ var PerpetualsClient = (function () {
|
|
4814
4599
|
instructions.push(addCompoundingLiquidity);
|
4815
4600
|
return [3, 10];
|
4816
4601
|
case 9:
|
4817
|
-
|
4818
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4602
|
+
err_16 = _f.sent();
|
4603
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
4819
4604
|
return [3, 10];
|
4820
4605
|
case 10: return [2, {
|
4821
4606
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4831,7 +4616,7 @@ var PerpetualsClient = (function () {
|
|
4831
4616
|
args_1[_i - 5] = arguments[_i];
|
4832
4617
|
}
|
4833
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) {
|
4834
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity,
|
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;
|
4835
4620
|
if (createUserATA === void 0) { createUserATA = true; }
|
4836
4621
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4837
4622
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -4943,8 +4728,8 @@ var PerpetualsClient = (function () {
|
|
4943
4728
|
instructions.push(removeCompoundingLiquidity);
|
4944
4729
|
return [3, 8];
|
4945
4730
|
case 7:
|
4946
|
-
|
4947
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4731
|
+
err_17 = _f.sent();
|
4732
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
4948
4733
|
return [3, 8];
|
4949
4734
|
case 8: return [2, {
|
4950
4735
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4960,7 +4745,7 @@ var PerpetualsClient = (function () {
|
|
4960
4745
|
args_1[_i - 3] = arguments[_i];
|
4961
4746
|
}
|
4962
4747
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
4963
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake,
|
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;
|
4964
4749
|
if (createUserATA === void 0) { createUserATA = true; }
|
4965
4750
|
return __generator(this, function (_g) {
|
4966
4751
|
switch (_g.label) {
|
@@ -5058,8 +4843,8 @@ var PerpetualsClient = (function () {
|
|
5058
4843
|
instructions.push(migrateStake);
|
5059
4844
|
return [3, 8];
|
5060
4845
|
case 7:
|
5061
|
-
|
5062
|
-
console.log("perpClient migrateStake error:: ",
|
4846
|
+
err_18 = _g.sent();
|
4847
|
+
console.log("perpClient migrateStake error:: ", err_18);
|
5063
4848
|
return [3, 8];
|
5064
4849
|
case 8: return [2, {
|
5065
4850
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5070,7 +4855,7 @@ var PerpetualsClient = (function () {
|
|
5070
4855
|
});
|
5071
4856
|
};
|
5072
4857
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5073
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
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;
|
5074
4859
|
return __generator(this, function (_d) {
|
5075
4860
|
switch (_d.label) {
|
5076
4861
|
case 0:
|
@@ -5142,8 +4927,8 @@ var PerpetualsClient = (function () {
|
|
5142
4927
|
instructions.push(migrateFlp);
|
5143
4928
|
return [3, 4];
|
5144
4929
|
case 3:
|
5145
|
-
|
5146
|
-
console.log("perpClient migrateFlp error:: ",
|
4930
|
+
err_19 = _d.sent();
|
4931
|
+
console.log("perpClient migrateFlp error:: ", err_19);
|
5147
4932
|
return [3, 4];
|
5148
4933
|
case 4: return [2, {
|
5149
4934
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5158,7 +4943,7 @@ var PerpetualsClient = (function () {
|
|
5158
4943
|
args_1[_i - 1] = arguments[_i];
|
5159
4944
|
}
|
5160
4945
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5161
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee,
|
4946
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
|
5162
4947
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5163
4948
|
return __generator(this, function (_e) {
|
5164
4949
|
switch (_e.label) {
|
@@ -5216,8 +5001,8 @@ var PerpetualsClient = (function () {
|
|
5216
5001
|
instructions.push(compoundingFee);
|
5217
5002
|
return [3, 4];
|
5218
5003
|
case 3:
|
5219
|
-
|
5220
|
-
console.log("perpClient compoundingFee error:: ",
|
5004
|
+
err_20 = _e.sent();
|
5005
|
+
console.log("perpClient compoundingFee error:: ", err_20);
|
5221
5006
|
return [3, 4];
|
5222
5007
|
case 4: return [2, {
|
5223
5008
|
instructions: __spreadArray([], instructions, true),
|
@@ -5227,199 +5012,61 @@ var PerpetualsClient = (function () {
|
|
5227
5012
|
});
|
5228
5013
|
});
|
5229
5014
|
};
|
5230
|
-
this.
|
5231
|
-
var preInstructions, instructions, postInstructions, additionalSigners,
|
5232
|
-
return __generator(this, function (
|
5233
|
-
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) {
|
5234
5019
|
case 0:
|
5235
5020
|
preInstructions = [];
|
5236
5021
|
instructions = [];
|
5237
5022
|
postInstructions = [];
|
5238
5023
|
additionalSigners = [];
|
5239
|
-
|
5024
|
+
_a.label = 1;
|
5240
5025
|
case 1:
|
5241
|
-
|
5242
|
-
|
5243
|
-
|
5244
|
-
userTokenAccount = _b.sent();
|
5245
|
-
_a = createAta;
|
5246
|
-
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);
|
5247
5029
|
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5248
|
-
case
|
5249
|
-
|
5250
|
-
|
5251
|
-
case 4:
|
5252
|
-
if (_a) {
|
5253
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(owner, userTokenAccount, owner, poolConfig.tokenMint));
|
5030
|
+
case 2:
|
5031
|
+
if (!(_a.sent())) {
|
5032
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5254
5033
|
}
|
5255
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
|
5256
|
-
case 5:
|
5257
|
-
nftTokenAccount = _b.sent();
|
5258
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5259
|
-
Buffer.from("trading"),
|
5260
|
-
nftMint.toBuffer(),
|
5261
|
-
], this.programId)[0];
|
5262
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5263
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5264
|
-
edition = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("edition")], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5265
|
-
tokenRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("token_record"), nftTokenAccount.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5266
5034
|
return [4, this.program.methods
|
5267
|
-
.
|
5035
|
+
.depositTokenStake({
|
5036
|
+
depositAmount: depositAmount
|
5037
|
+
})
|
5268
5038
|
.accounts({
|
5269
5039
|
owner: owner,
|
5270
|
-
|
5040
|
+
feePayer: feePayer,
|
5041
|
+
fundingTokenAccount: userTokenAccount,
|
5271
5042
|
perpetuals: this.perpetuals.publicKey,
|
5272
5043
|
tokenVault: poolConfig.tokenVault,
|
5273
5044
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5274
|
-
|
5275
|
-
collectionMetadata: collectionMetadata,
|
5276
|
-
edition: edition,
|
5277
|
-
tokenRecord: tokenRecord,
|
5278
|
-
tradingAccount: nftTradingAccount,
|
5279
|
-
transferAuthority: poolConfig.transferAuthority,
|
5280
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5281
|
-
nftMint: nftMint,
|
5282
|
-
nftTokenAccount: nftTokenAccount,
|
5045
|
+
tokenStakeAccount: tokenStakeAccount,
|
5283
5046
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5284
5047
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5285
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5286
5048
|
eventAuthority: this.eventAuthority.publicKey,
|
5287
5049
|
program: this.programId,
|
5288
|
-
|
5050
|
+
tokenMint: poolConfig.tokenMint,
|
5289
5051
|
})
|
5290
5052
|
.instruction()];
|
5291
|
-
case
|
5292
|
-
|
5293
|
-
instructions.push(
|
5294
|
-
return [3,
|
5295
|
-
case
|
5296
|
-
|
5297
|
-
console.log("perpClient
|
5298
|
-
throw
|
5299
|
-
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, {
|
5300
5062
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5301
5063
|
additionalSigners: additionalSigners
|
5302
5064
|
}];
|
5303
5065
|
}
|
5304
5066
|
});
|
5305
5067
|
}); };
|
5306
|
-
this.
|
5307
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount,
|
5308
|
-
return __generator(this, function (_a) {
|
5309
|
-
switch (_a.label) {
|
5310
|
-
case 0:
|
5311
|
-
preInstructions = [];
|
5312
|
-
instructions = [];
|
5313
|
-
postInstructions = [];
|
5314
|
-
additionalSigners = [];
|
5315
|
-
_a.label = 1;
|
5316
|
-
case 1:
|
5317
|
-
_a.trys.push([1, 3, , 4]);
|
5318
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5319
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
5320
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
5321
|
-
Buffer.from("trading"),
|
5322
|
-
nftMint.toBuffer(),
|
5323
|
-
], this.programId)[0];
|
5324
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5325
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5326
|
-
edition = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("edition")], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5327
|
-
tokenRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("token_record"), nftTokenAccount.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5328
|
-
return [4, this.program.methods
|
5329
|
-
.burnAndStake({})
|
5330
|
-
.accounts({
|
5331
|
-
owner: owner,
|
5332
|
-
feePayer: feePayer,
|
5333
|
-
perpetuals: this.perpetuals.publicKey,
|
5334
|
-
tokenVault: poolConfig.tokenVault,
|
5335
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5336
|
-
tokenStakeAccount: tokenStakeAccount,
|
5337
|
-
metadataAccount: metadataAccount,
|
5338
|
-
collectionMetadata: collectionMetadata,
|
5339
|
-
edition: edition,
|
5340
|
-
tokenRecord: tokenRecord,
|
5341
|
-
tradingAccount: nftTradingAccount,
|
5342
|
-
transferAuthority: poolConfig.transferAuthority,
|
5343
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
5344
|
-
nftMint: nftMint,
|
5345
|
-
nftTokenAccount: nftTokenAccount,
|
5346
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5347
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5348
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5349
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5350
|
-
program: this.programId
|
5351
|
-
})
|
5352
|
-
.instruction()];
|
5353
|
-
case 2:
|
5354
|
-
burnAndStakeInstruction = _a.sent();
|
5355
|
-
instructions.push(burnAndStakeInstruction);
|
5356
|
-
return [3, 4];
|
5357
|
-
case 3:
|
5358
|
-
err_24 = _a.sent();
|
5359
|
-
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
5360
|
-
throw err_24;
|
5361
|
-
case 4: return [2, {
|
5362
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5363
|
-
additionalSigners: additionalSigners
|
5364
|
-
}];
|
5365
|
-
}
|
5366
|
-
});
|
5367
|
-
}); };
|
5368
|
-
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5369
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
5370
|
-
return __generator(this, function (_a) {
|
5371
|
-
switch (_a.label) {
|
5372
|
-
case 0:
|
5373
|
-
preInstructions = [];
|
5374
|
-
instructions = [];
|
5375
|
-
postInstructions = [];
|
5376
|
-
additionalSigners = [];
|
5377
|
-
_a.label = 1;
|
5378
|
-
case 1:
|
5379
|
-
_a.trys.push([1, 4, , 5]);
|
5380
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5381
|
-
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
5382
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5383
|
-
case 2:
|
5384
|
-
if (!(_a.sent())) {
|
5385
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
5386
|
-
}
|
5387
|
-
return [4, this.program.methods
|
5388
|
-
.depositTokenStake({
|
5389
|
-
depositAmount: depositAmount
|
5390
|
-
})
|
5391
|
-
.accounts({
|
5392
|
-
owner: owner,
|
5393
|
-
feePayer: feePayer,
|
5394
|
-
fundingTokenAccount: userTokenAccount,
|
5395
|
-
perpetuals: this.perpetuals.publicKey,
|
5396
|
-
tokenVault: poolConfig.tokenVault,
|
5397
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5398
|
-
tokenStakeAccount: tokenStakeAccount,
|
5399
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5400
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5401
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5402
|
-
program: this.programId,
|
5403
|
-
tokenMint: poolConfig.tokenMint,
|
5404
|
-
})
|
5405
|
-
.instruction()];
|
5406
|
-
case 3:
|
5407
|
-
depositTokenStakeInstruction = _a.sent();
|
5408
|
-
instructions.push(depositTokenStakeInstruction);
|
5409
|
-
return [3, 5];
|
5410
|
-
case 4:
|
5411
|
-
err_25 = _a.sent();
|
5412
|
-
console.log("perpClient depositStakingInstruction error:: ", err_25);
|
5413
|
-
throw err_25;
|
5414
|
-
case 5: return [2, {
|
5415
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5416
|
-
additionalSigners: additionalSigners
|
5417
|
-
}];
|
5418
|
-
}
|
5419
|
-
});
|
5420
|
-
}); };
|
5421
|
-
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5422
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_26;
|
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;
|
5423
5070
|
return __generator(this, function (_a) {
|
5424
5071
|
switch (_a.label) {
|
5425
5072
|
case 0:
|
@@ -5448,9 +5095,9 @@ var PerpetualsClient = (function () {
|
|
5448
5095
|
instructions.push(unstakeTokenRequestInstruction);
|
5449
5096
|
return [3, 4];
|
5450
5097
|
case 3:
|
5451
|
-
|
5452
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5453
|
-
throw
|
5098
|
+
err_22 = _a.sent();
|
5099
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
|
5100
|
+
throw err_22;
|
5454
5101
|
case 4: return [2, {
|
5455
5102
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5456
5103
|
additionalSigners: additionalSigners
|
@@ -5459,7 +5106,7 @@ var PerpetualsClient = (function () {
|
|
5459
5106
|
});
|
5460
5107
|
}); };
|
5461
5108
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5462
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5109
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
|
5463
5110
|
return __generator(this, function (_a) {
|
5464
5111
|
switch (_a.label) {
|
5465
5112
|
case 0:
|
@@ -5500,9 +5147,9 @@ var PerpetualsClient = (function () {
|
|
5500
5147
|
instructions.push(unstakeTokenInstantInstruction);
|
5501
5148
|
return [3, 5];
|
5502
5149
|
case 4:
|
5503
|
-
|
5504
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5505
|
-
throw
|
5150
|
+
err_23 = _a.sent();
|
5151
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
5152
|
+
throw err_23;
|
5506
5153
|
case 5: return [2, {
|
5507
5154
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5508
5155
|
additionalSigners: additionalSigners
|
@@ -5511,7 +5158,7 @@ var PerpetualsClient = (function () {
|
|
5511
5158
|
});
|
5512
5159
|
}); };
|
5513
5160
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5514
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5161
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
|
5515
5162
|
return __generator(this, function (_a) {
|
5516
5163
|
switch (_a.label) {
|
5517
5164
|
case 0:
|
@@ -5552,9 +5199,9 @@ var PerpetualsClient = (function () {
|
|
5552
5199
|
instructions.push(withdrawTokenInstruction);
|
5553
5200
|
return [3, 5];
|
5554
5201
|
case 4:
|
5555
|
-
|
5556
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5557
|
-
throw
|
5202
|
+
err_24 = _a.sent();
|
5203
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
5204
|
+
throw err_24;
|
5558
5205
|
case 5: return [2, {
|
5559
5206
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5560
5207
|
additionalSigners: additionalSigners
|
@@ -5563,7 +5210,7 @@ var PerpetualsClient = (function () {
|
|
5563
5210
|
});
|
5564
5211
|
}); };
|
5565
5212
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5566
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5213
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
|
5567
5214
|
return __generator(this, function (_a) {
|
5568
5215
|
switch (_a.label) {
|
5569
5216
|
case 0:
|
@@ -5592,9 +5239,9 @@ var PerpetualsClient = (function () {
|
|
5592
5239
|
instructions.push(cancelUnstakeRequestInstruction);
|
5593
5240
|
return [3, 4];
|
5594
5241
|
case 3:
|
5595
|
-
|
5596
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5597
|
-
throw
|
5242
|
+
err_25 = _a.sent();
|
5243
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
|
5244
|
+
throw err_25;
|
5598
5245
|
case 4: return [2, {
|
5599
5246
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5600
5247
|
additionalSigners: additionalSigners
|
@@ -5608,7 +5255,7 @@ var PerpetualsClient = (function () {
|
|
5608
5255
|
args_1[_i - 2] = arguments[_i];
|
5609
5256
|
}
|
5610
5257
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5611
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
5258
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
5612
5259
|
if (createUserATA === void 0) { createUserATA = true; }
|
5613
5260
|
return __generator(this, function (_b) {
|
5614
5261
|
switch (_b.label) {
|
@@ -5654,9 +5301,9 @@ var PerpetualsClient = (function () {
|
|
5654
5301
|
instructions.push(collectTokenRewardInstruction);
|
5655
5302
|
return [3, 6];
|
5656
5303
|
case 5:
|
5657
|
-
|
5658
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5659
|
-
throw
|
5304
|
+
err_26 = _b.sent();
|
5305
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
5306
|
+
throw err_26;
|
5660
5307
|
case 6: return [2, {
|
5661
5308
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5662
5309
|
additionalSigners: additionalSigners
|
@@ -5671,7 +5318,7 @@ var PerpetualsClient = (function () {
|
|
5671
5318
|
args_1[_i - 3] = arguments[_i];
|
5672
5319
|
}
|
5673
5320
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5674
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
5321
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
|
5675
5322
|
if (createUserATA === void 0) { createUserATA = true; }
|
5676
5323
|
return __generator(this, function (_b) {
|
5677
5324
|
switch (_b.label) {
|
@@ -5718,250 +5365,9 @@ var PerpetualsClient = (function () {
|
|
5718
5365
|
instructions.push(collectRevenueInstruction);
|
5719
5366
|
return [3, 6];
|
5720
5367
|
case 5:
|
5721
|
-
|
5722
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5723
|
-
throw
|
5724
|
-
case 6: return [2, {
|
5725
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5726
|
-
additionalSigners: additionalSigners
|
5727
|
-
}];
|
5728
|
-
}
|
5729
|
-
});
|
5730
|
-
});
|
5731
|
-
};
|
5732
|
-
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5733
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
|
5734
|
-
return __generator(this, function (_a) {
|
5735
|
-
switch (_a.label) {
|
5736
|
-
case 0:
|
5737
|
-
publicKey = this.provider.wallet.publicKey;
|
5738
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5739
|
-
instructions = [];
|
5740
|
-
additionalSigners = [];
|
5741
|
-
_a.label = 1;
|
5742
|
-
case 1:
|
5743
|
-
_a.trys.push([1, 3, , 4]);
|
5744
|
-
fbNftProgramData = web3_js_1.PublicKey.findProgramAddressSync([this.programFbnftReward.programId.toBuffer()], new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"))[0];
|
5745
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5746
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5747
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5748
|
-
return [4, this.programFbnftReward.methods
|
5749
|
-
.initRewardVault({
|
5750
|
-
nftCount: nftCount
|
5751
|
-
})
|
5752
|
-
.accounts({
|
5753
|
-
admin: publicKey,
|
5754
|
-
transferAuthority: nftTransferAuthority,
|
5755
|
-
rewardVault: rewardVault,
|
5756
|
-
rewardMint: rewardCustodyMint,
|
5757
|
-
rewardTokenAccount: rewardTokenAccount,
|
5758
|
-
collectionMint: collectionMint,
|
5759
|
-
programData: fbNftProgramData,
|
5760
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5761
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5762
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
5763
|
-
})
|
5764
|
-
.instruction()];
|
5765
|
-
case 2:
|
5766
|
-
initRewardVault = _a.sent();
|
5767
|
-
instructions.push(initRewardVault);
|
5768
|
-
return [3, 4];
|
5769
|
-
case 3:
|
5770
|
-
err_32 = _a.sent();
|
5771
|
-
console.log("perpClient InitRewardVault error:: ", err_32);
|
5772
|
-
throw err_32;
|
5773
|
-
case 4: return [2, {
|
5774
|
-
instructions: __spreadArray([], instructions, true),
|
5775
|
-
additionalSigners: additionalSigners
|
5776
|
-
}];
|
5777
|
-
}
|
5778
|
-
});
|
5779
|
-
}); };
|
5780
|
-
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5781
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
|
5782
|
-
return __generator(this, function (_a) {
|
5783
|
-
switch (_a.label) {
|
5784
|
-
case 0:
|
5785
|
-
publicKey = this.provider.wallet.publicKey;
|
5786
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5787
|
-
instructions = [];
|
5788
|
-
additionalSigners = [];
|
5789
|
-
_a.label = 1;
|
5790
|
-
case 1:
|
5791
|
-
_a.trys.push([1, 3, , 4]);
|
5792
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5793
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5794
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5795
|
-
return [4, this.programFbnftReward.methods
|
5796
|
-
.distributeRewards({
|
5797
|
-
rewardAmount: rewardAmount
|
5798
|
-
})
|
5799
|
-
.accounts({
|
5800
|
-
admin: publicKey,
|
5801
|
-
fundingAccount: fundingAccount,
|
5802
|
-
rewardVault: rewardVault,
|
5803
|
-
rewardTokenAccount: rewardTokenAccount,
|
5804
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5805
|
-
})
|
5806
|
-
.instruction()];
|
5807
|
-
case 2:
|
5808
|
-
distributeReward = _a.sent();
|
5809
|
-
instructions.push(distributeReward);
|
5810
|
-
return [3, 4];
|
5811
|
-
case 3:
|
5812
|
-
err_33 = _a.sent();
|
5813
|
-
console.log("perpClient distributeReward error:: ", err_33);
|
5814
|
-
throw err_33;
|
5815
|
-
case 4: return [2, {
|
5816
|
-
instructions: __spreadArray([], instructions, true),
|
5817
|
-
additionalSigners: additionalSigners
|
5818
|
-
}];
|
5819
|
-
}
|
5820
|
-
});
|
5821
|
-
}); };
|
5822
|
-
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5823
|
-
var args_1 = [];
|
5824
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
5825
|
-
args_1[_i - 3] = arguments[_i];
|
5826
|
-
}
|
5827
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5828
|
-
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
|
5829
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5830
|
-
return __generator(this, function (_b) {
|
5831
|
-
switch (_b.label) {
|
5832
|
-
case 0:
|
5833
|
-
publicKey = this.provider.wallet.publicKey;
|
5834
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5835
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5836
|
-
instructions = [];
|
5837
|
-
additionalSigners = [];
|
5838
|
-
_b.label = 1;
|
5839
|
-
case 1:
|
5840
|
-
_b.trys.push([1, 5, , 6]);
|
5841
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5842
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5843
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5844
|
-
_a = createUserATA;
|
5845
|
-
if (!_a) return [3, 3];
|
5846
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5847
|
-
case 2:
|
5848
|
-
_a = !(_b.sent());
|
5849
|
-
_b.label = 3;
|
5850
|
-
case 3:
|
5851
|
-
if (_a) {
|
5852
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5853
|
-
}
|
5854
|
-
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5855
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5856
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5857
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
5858
|
-
return [4, this.programFbnftReward.methods
|
5859
|
-
.collectReward()
|
5860
|
-
.accounts({
|
5861
|
-
owner: publicKey,
|
5862
|
-
feePayer: publicKey,
|
5863
|
-
nftMint: nftMint,
|
5864
|
-
nftTokenAccount: nftTokenAccount,
|
5865
|
-
metadataAccount: metadataAccount,
|
5866
|
-
receivingAccount: receivingTokenAccount,
|
5867
|
-
rewardRecord: rewardRecord,
|
5868
|
-
rewardVault: rewardVault,
|
5869
|
-
rewardTokenAccount: rewardTokenAccount,
|
5870
|
-
transferAuthority: nftTransferAuthority,
|
5871
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5872
|
-
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
5873
|
-
})
|
5874
|
-
.instruction()];
|
5875
|
-
case 4:
|
5876
|
-
collectNftReward = _b.sent();
|
5877
|
-
instructions.push(collectNftReward);
|
5878
|
-
return [3, 6];
|
5879
|
-
case 5:
|
5880
|
-
err_34 = _b.sent();
|
5881
|
-
throw err_34;
|
5882
|
-
case 6: return [2, {
|
5883
|
-
instructions: __spreadArray([], instructions, true),
|
5884
|
-
additionalSigners: additionalSigners
|
5885
|
-
}];
|
5886
|
-
}
|
5887
|
-
});
|
5888
|
-
});
|
5889
|
-
};
|
5890
|
-
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
5891
|
-
var args_1 = [];
|
5892
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
5893
|
-
args_1[_i - 2] = arguments[_i];
|
5894
|
-
}
|
5895
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5896
|
-
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
|
5897
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5898
|
-
return __generator(this, function (_b) {
|
5899
|
-
switch (_b.label) {
|
5900
|
-
case 0:
|
5901
|
-
publicKey = this.provider.wallet.publicKey;
|
5902
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5903
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5904
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5905
|
-
preInstructions = [];
|
5906
|
-
instructions = [];
|
5907
|
-
postInstructions = [];
|
5908
|
-
additionalSigners = [];
|
5909
|
-
_b.label = 1;
|
5910
|
-
case 1:
|
5911
|
-
_b.trys.push([1, 5, , 6]);
|
5912
|
-
pool = poolConfig.poolAddress;
|
5913
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5914
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5915
|
-
_a = createUserATA;
|
5916
|
-
if (!_a) return [3, 3];
|
5917
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
5918
|
-
case 2:
|
5919
|
-
_a = !(_b.sent());
|
5920
|
-
_b.label = 3;
|
5921
|
-
case 3:
|
5922
|
-
if (_a) {
|
5923
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5924
|
-
}
|
5925
|
-
tradingAccount = [];
|
5926
|
-
if (nftTradingAccount) {
|
5927
|
-
tradingAccount.push({
|
5928
|
-
pubkey: nftTradingAccount,
|
5929
|
-
isSigner: false,
|
5930
|
-
isWritable: true,
|
5931
|
-
});
|
5932
|
-
}
|
5933
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5934
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5935
|
-
return [4, this.programPerpComposability.methods
|
5936
|
-
.collectAndDistributeFee()
|
5937
|
-
.accounts({
|
5938
|
-
perpProgram: this.programId,
|
5939
|
-
owner: publicKey,
|
5940
|
-
receivingTokenAccount: receivingTokenAccount,
|
5941
|
-
transferAuthority: poolConfig.transferAuthority,
|
5942
|
-
perpetuals: this.perpetuals.publicKey,
|
5943
|
-
pool: pool,
|
5944
|
-
feeCustody: rewardCustodyConfig.custodyAccount,
|
5945
|
-
flpStakeAccount: flpStakeAccount,
|
5946
|
-
feeCustodyTokenAccount: rewardCustodyConfig.tokenAccount,
|
5947
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5948
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5949
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5950
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5951
|
-
fbnftRewardsProgram: this.programFbnftReward.programId,
|
5952
|
-
rewardVault: rewardVault,
|
5953
|
-
rewardTokenAccount: rewardTokenAccount
|
5954
|
-
})
|
5955
|
-
.remainingAccounts(tradingAccount)
|
5956
|
-
.instruction()];
|
5957
|
-
case 4:
|
5958
|
-
withdrawStakeInstruction = _b.sent();
|
5959
|
-
instructions.push(withdrawStakeInstruction);
|
5960
|
-
return [3, 6];
|
5961
|
-
case 5:
|
5962
|
-
err_35 = _b.sent();
|
5963
|
-
console.log("perpClient withdrawStake error:: ", err_35);
|
5964
|
-
throw err_35;
|
5368
|
+
err_27 = _b.sent();
|
5369
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
5370
|
+
throw err_27;
|
5965
5371
|
case 6: return [2, {
|
5966
5372
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5967
5373
|
additionalSigners: additionalSigners
|
@@ -5976,7 +5382,7 @@ var PerpetualsClient = (function () {
|
|
5976
5382
|
args_1[_i - 11] = arguments[_i];
|
5977
5383
|
}
|
5978
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) {
|
5979
|
-
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;
|
5980
5386
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
5981
5387
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5982
5388
|
return __generator(this, function (_c) {
|
@@ -6082,9 +5488,9 @@ var PerpetualsClient = (function () {
|
|
6082
5488
|
instructions.push(placeLimitOrder);
|
6083
5489
|
return [3, 10];
|
6084
5490
|
case 9:
|
6085
|
-
|
6086
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6087
|
-
throw
|
5491
|
+
err_28 = _c.sent();
|
5492
|
+
console.log("perpClient placeLimitOrder error:: ", err_28);
|
5493
|
+
throw err_28;
|
6088
5494
|
case 10: return [2, {
|
6089
5495
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6090
5496
|
additionalSigners: additionalSigners
|
@@ -6099,7 +5505,7 @@ var PerpetualsClient = (function () {
|
|
6099
5505
|
args_1[_i - 11] = arguments[_i];
|
6100
5506
|
}
|
6101
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) {
|
6102
|
-
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;
|
6103
5509
|
if (createUserATA === void 0) { createUserATA = true; }
|
6104
5510
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6105
5511
|
return __generator(this, function (_b) {
|
@@ -6190,9 +5596,9 @@ var PerpetualsClient = (function () {
|
|
6190
5596
|
instructions.push(editLimitOrder);
|
6191
5597
|
return [3, 8];
|
6192
5598
|
case 7:
|
6193
|
-
|
6194
|
-
console.log("perpClient editLimitOrder error:: ",
|
6195
|
-
throw
|
5599
|
+
err_29 = _b.sent();
|
5600
|
+
console.log("perpClient editLimitOrder error:: ", err_29);
|
5601
|
+
throw err_29;
|
6196
5602
|
case 8: return [2, {
|
6197
5603
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6198
5604
|
additionalSigners: additionalSigners
|
@@ -6207,7 +5613,7 @@ var PerpetualsClient = (function () {
|
|
6207
5613
|
args_1[_i - 7] = arguments[_i];
|
6208
5614
|
}
|
6209
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) {
|
6210
|
-
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;
|
6211
5617
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6212
5618
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6213
5619
|
return __generator(this, function (_a) {
|
@@ -6259,9 +5665,9 @@ var PerpetualsClient = (function () {
|
|
6259
5665
|
instructions.push(executeLimitOrder);
|
6260
5666
|
return [3, 4];
|
6261
5667
|
case 3:
|
6262
|
-
|
6263
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6264
|
-
throw
|
5668
|
+
err_30 = _a.sent();
|
5669
|
+
console.log("perpClient executeLimitOrder error:: ", err_30);
|
5670
|
+
throw err_30;
|
6265
5671
|
case 4: return [2, {
|
6266
5672
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6267
5673
|
additionalSigners: additionalSigners
|
@@ -6276,7 +5682,7 @@ var PerpetualsClient = (function () {
|
|
6276
5682
|
args_1[_i - 8] = arguments[_i];
|
6277
5683
|
}
|
6278
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) {
|
6279
|
-
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;
|
6280
5686
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6281
5687
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6282
5688
|
return __generator(this, function (_a) {
|
@@ -6331,9 +5737,9 @@ var PerpetualsClient = (function () {
|
|
6331
5737
|
instructions.push(executeLimitWithSwap);
|
6332
5738
|
return [3, 4];
|
6333
5739
|
case 3:
|
6334
|
-
|
6335
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6336
|
-
throw
|
5740
|
+
err_31 = _a.sent();
|
5741
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_31);
|
5742
|
+
throw err_31;
|
6337
5743
|
case 4: return [2, {
|
6338
5744
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6339
5745
|
additionalSigners: additionalSigners
|
@@ -6343,7 +5749,7 @@ var PerpetualsClient = (function () {
|
|
6343
5749
|
});
|
6344
5750
|
};
|
6345
5751
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6346
|
-
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;
|
6347
5753
|
return __generator(this, function (_a) {
|
6348
5754
|
switch (_a.label) {
|
6349
5755
|
case 0:
|
@@ -6391,9 +5797,9 @@ var PerpetualsClient = (function () {
|
|
6391
5797
|
instructions.push(placeTriggerOrder);
|
6392
5798
|
return [3, 4];
|
6393
5799
|
case 3:
|
6394
|
-
|
6395
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6396
|
-
throw
|
5800
|
+
err_32 = _a.sent();
|
5801
|
+
console.log("perpClient placeTriggerOrder error:: ", err_32);
|
5802
|
+
throw err_32;
|
6397
5803
|
case 4: return [2, {
|
6398
5804
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6399
5805
|
additionalSigners: additionalSigners
|
@@ -6402,7 +5808,7 @@ var PerpetualsClient = (function () {
|
|
6402
5808
|
});
|
6403
5809
|
}); };
|
6404
5810
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6405
|
-
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;
|
6406
5812
|
return __generator(this, function (_a) {
|
6407
5813
|
switch (_a.label) {
|
6408
5814
|
case 0:
|
@@ -6449,9 +5855,9 @@ var PerpetualsClient = (function () {
|
|
6449
5855
|
instructions.push(editTriggerOrder);
|
6450
5856
|
return [3, 4];
|
6451
5857
|
case 3:
|
6452
|
-
|
6453
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6454
|
-
throw
|
5858
|
+
err_33 = _a.sent();
|
5859
|
+
console.log("perpClient editTriggerOrder error:: ", err_33);
|
5860
|
+
throw err_33;
|
6455
5861
|
case 4: return [2, {
|
6456
5862
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6457
5863
|
additionalSigners: additionalSigners
|
@@ -6460,7 +5866,7 @@ var PerpetualsClient = (function () {
|
|
6460
5866
|
});
|
6461
5867
|
}); };
|
6462
5868
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6463
|
-
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;
|
6464
5870
|
return __generator(this, function (_a) {
|
6465
5871
|
switch (_a.label) {
|
6466
5872
|
case 0:
|
@@ -6493,9 +5899,9 @@ var PerpetualsClient = (function () {
|
|
6493
5899
|
instructions.push(cancelTriggerOrder);
|
6494
5900
|
return [3, 4];
|
6495
5901
|
case 3:
|
6496
|
-
|
6497
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6498
|
-
throw
|
5902
|
+
err_34 = _a.sent();
|
5903
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_34);
|
5904
|
+
throw err_34;
|
6499
5905
|
case 4: return [2, {
|
6500
5906
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6501
5907
|
additionalSigners: additionalSigners
|
@@ -6504,7 +5910,7 @@ var PerpetualsClient = (function () {
|
|
6504
5910
|
});
|
6505
5911
|
}); };
|
6506
5912
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6507
|
-
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;
|
6508
5914
|
return __generator(this, function (_a) {
|
6509
5915
|
switch (_a.label) {
|
6510
5916
|
case 0:
|
@@ -6535,9 +5941,9 @@ var PerpetualsClient = (function () {
|
|
6535
5941
|
instructions.push(cancelAllTriggerOrders);
|
6536
5942
|
return [3, 4];
|
6537
5943
|
case 3:
|
6538
|
-
|
6539
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6540
|
-
throw
|
5944
|
+
err_35 = _a.sent();
|
5945
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_35);
|
5946
|
+
throw err_35;
|
6541
5947
|
case 4: return [2, {
|
6542
5948
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6543
5949
|
additionalSigners: additionalSigners
|
@@ -6551,7 +5957,7 @@ var PerpetualsClient = (function () {
|
|
6551
5957
|
args_1[_i - 9] = arguments[_i];
|
6552
5958
|
}
|
6553
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) {
|
6554
|
-
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;
|
6555
5961
|
if (createUserATA === void 0) { createUserATA = true; }
|
6556
5962
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6557
5963
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -6657,9 +6063,9 @@ var PerpetualsClient = (function () {
|
|
6657
6063
|
instructions.push(executeTriggerWithSwap);
|
6658
6064
|
return [3, 10];
|
6659
6065
|
case 9:
|
6660
|
-
|
6661
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6662
|
-
throw
|
6066
|
+
err_36 = _e.sent();
|
6067
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_36);
|
6068
|
+
throw err_36;
|
6663
6069
|
case 10: return [2, {
|
6664
6070
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6665
6071
|
additionalSigners: additionalSigners
|
@@ -6674,7 +6080,7 @@ var PerpetualsClient = (function () {
|
|
6674
6080
|
args_1[_i - 8] = arguments[_i];
|
6675
6081
|
}
|
6676
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) {
|
6677
|
-
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;
|
6678
6084
|
if (createUserATA === void 0) { createUserATA = true; }
|
6679
6085
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6680
6086
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -6745,9 +6151,9 @@ var PerpetualsClient = (function () {
|
|
6745
6151
|
instructions.push(executeTriggerOrder);
|
6746
6152
|
return [3, 8];
|
6747
6153
|
case 7:
|
6748
|
-
|
6749
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
6750
|
-
throw
|
6154
|
+
err_37 = _b.sent();
|
6155
|
+
console.log("perpClient executeTriggerOrder error:: ", err_37);
|
6156
|
+
throw err_37;
|
6751
6157
|
case 8: return [2, {
|
6752
6158
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6753
6159
|
additionalSigners: additionalSigners
|
@@ -6762,7 +6168,7 @@ var PerpetualsClient = (function () {
|
|
6762
6168
|
args_1[_i - 5] = arguments[_i];
|
6763
6169
|
}
|
6764
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) {
|
6765
|
-
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;
|
6766
6172
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
6767
6173
|
if (createUserATA === void 0) { createUserATA = true; }
|
6768
6174
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
@@ -6967,9 +6373,9 @@ var PerpetualsClient = (function () {
|
|
6967
6373
|
}
|
6968
6374
|
return [3, 20];
|
6969
6375
|
case 19:
|
6970
|
-
|
6971
|
-
console.error("perpClient Swap error:: ",
|
6972
|
-
throw
|
6376
|
+
err_38 = _g.sent();
|
6377
|
+
console.error("perpClient Swap error:: ", err_38);
|
6378
|
+
throw err_38;
|
6973
6379
|
case 20: return [2, {
|
6974
6380
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6975
6381
|
additionalSigners: additionalSigners
|
@@ -6979,7 +6385,7 @@ var PerpetualsClient = (function () {
|
|
6979
6385
|
});
|
6980
6386
|
};
|
6981
6387
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6982
|
-
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;
|
6983
6389
|
return __generator(this, function (_b) {
|
6984
6390
|
switch (_b.label) {
|
6985
6391
|
case 0:
|
@@ -7035,9 +6441,9 @@ var PerpetualsClient = (function () {
|
|
7035
6441
|
instructions.push(inx);
|
7036
6442
|
return [3, 4];
|
7037
6443
|
case 3:
|
7038
|
-
|
7039
|
-
console.error("perpClient Swap error:: ",
|
7040
|
-
throw
|
6444
|
+
err_39 = _b.sent();
|
6445
|
+
console.error("perpClient Swap error:: ", err_39);
|
6446
|
+
throw err_39;
|
7041
6447
|
case 4: return [2, {
|
7042
6448
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7043
6449
|
additionalSigners: additionalSigners
|
@@ -7046,7 +6452,7 @@ var PerpetualsClient = (function () {
|
|
7046
6452
|
});
|
7047
6453
|
}); };
|
7048
6454
|
this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7049
|
-
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;
|
7050
6456
|
return __generator(this, function (_d) {
|
7051
6457
|
switch (_d.label) {
|
7052
6458
|
case 0:
|
@@ -7094,9 +6500,9 @@ var PerpetualsClient = (function () {
|
|
7094
6500
|
instructions.push(setLpTokenPriceInstruction);
|
7095
6501
|
return [3, 4];
|
7096
6502
|
case 3:
|
7097
|
-
|
7098
|
-
console.log("perpClient setLpTokenPriceInstruction error:: ",
|
7099
|
-
throw
|
6503
|
+
err_40 = _d.sent();
|
6504
|
+
console.log("perpClient setLpTokenPriceInstruction error:: ", err_40);
|
6505
|
+
throw err_40;
|
7100
6506
|
case 4: return [2, {
|
7101
6507
|
instructions: __spreadArray([], instructions, true),
|
7102
6508
|
additionalSigners: additionalSigners
|
@@ -7144,7 +6550,7 @@ var PerpetualsClient = (function () {
|
|
7144
6550
|
});
|
7145
6551
|
}); };
|
7146
6552
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
7147
|
-
var adminMetas, _i, admins_2, admin,
|
6553
|
+
var adminMetas, _i, admins_2, admin, err_41;
|
7148
6554
|
return __generator(this, function (_a) {
|
7149
6555
|
switch (_a.label) {
|
7150
6556
|
case 0:
|
@@ -7174,11 +6580,11 @@ var PerpetualsClient = (function () {
|
|
7174
6580
|
_a.sent();
|
7175
6581
|
return [3, 4];
|
7176
6582
|
case 3:
|
7177
|
-
|
6583
|
+
err_41 = _a.sent();
|
7178
6584
|
if (this.printErrors) {
|
7179
|
-
console.error("setAdminSigners err:",
|
6585
|
+
console.error("setAdminSigners err:", err_41);
|
7180
6586
|
}
|
7181
|
-
throw
|
6587
|
+
throw err_41;
|
7182
6588
|
case 4: return [2];
|
7183
6589
|
}
|
7184
6590
|
});
|
@@ -7367,7 +6773,7 @@ var PerpetualsClient = (function () {
|
|
7367
6773
|
});
|
7368
6774
|
}); };
|
7369
6775
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7370
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
6776
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_42;
|
7371
6777
|
return __generator(this, function (_a) {
|
7372
6778
|
switch (_a.label) {
|
7373
6779
|
case 0:
|
@@ -7400,9 +6806,9 @@ var PerpetualsClient = (function () {
|
|
7400
6806
|
instructions.push(withdrawFeesIx);
|
7401
6807
|
return [3, 5];
|
7402
6808
|
case 4:
|
7403
|
-
|
7404
|
-
console.log("perpClient setPool error:: ",
|
7405
|
-
throw
|
6809
|
+
err_42 = _a.sent();
|
6810
|
+
console.log("perpClient setPool error:: ", err_42);
|
6811
|
+
throw err_42;
|
7406
6812
|
case 5: return [2, {
|
7407
6813
|
instructions: __spreadArray([], instructions, true),
|
7408
6814
|
additionalSigners: additionalSigners
|
@@ -7411,7 +6817,7 @@ var PerpetualsClient = (function () {
|
|
7411
6817
|
});
|
7412
6818
|
}); };
|
7413
6819
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7414
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
6820
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_43;
|
7415
6821
|
return __generator(this, function (_a) {
|
7416
6822
|
switch (_a.label) {
|
7417
6823
|
case 0:
|
@@ -7445,9 +6851,9 @@ var PerpetualsClient = (function () {
|
|
7445
6851
|
instructions.push(moveProtocolFeesIx);
|
7446
6852
|
return [3, 4];
|
7447
6853
|
case 3:
|
7448
|
-
|
7449
|
-
console.log("perpClient setPool error:: ",
|
7450
|
-
throw
|
6854
|
+
err_43 = _a.sent();
|
6855
|
+
console.log("perpClient setPool error:: ", err_43);
|
6856
|
+
throw err_43;
|
7451
6857
|
case 4: return [2, {
|
7452
6858
|
instructions: __spreadArray([], instructions, true),
|
7453
6859
|
additionalSigners: additionalSigners
|
@@ -7456,7 +6862,7 @@ var PerpetualsClient = (function () {
|
|
7456
6862
|
});
|
7457
6863
|
}); };
|
7458
6864
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7459
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
6865
|
+
var publicKey, setProtocolFeeShareBpsIx, err_44;
|
7460
6866
|
return __generator(this, function (_a) {
|
7461
6867
|
switch (_a.label) {
|
7462
6868
|
case 0:
|
@@ -7476,15 +6882,15 @@ var PerpetualsClient = (function () {
|
|
7476
6882
|
setProtocolFeeShareBpsIx = _a.sent();
|
7477
6883
|
return [2, setProtocolFeeShareBpsIx];
|
7478
6884
|
case 2:
|
7479
|
-
|
7480
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
7481
|
-
throw
|
6885
|
+
err_44 = _a.sent();
|
6886
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_44);
|
6887
|
+
throw err_44;
|
7482
6888
|
case 3: return [2];
|
7483
6889
|
}
|
7484
6890
|
});
|
7485
6891
|
}); };
|
7486
6892
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7487
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
6893
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_45;
|
7488
6894
|
return __generator(this, function (_a) {
|
7489
6895
|
switch (_a.label) {
|
7490
6896
|
case 0:
|
@@ -7511,9 +6917,9 @@ var PerpetualsClient = (function () {
|
|
7511
6917
|
instructions.push(setPermissionsInstruction);
|
7512
6918
|
return [3, 4];
|
7513
6919
|
case 3:
|
7514
|
-
|
7515
|
-
console.log("perpClient setPool error:: ",
|
7516
|
-
throw
|
6920
|
+
err_45 = _a.sent();
|
6921
|
+
console.log("perpClient setPool error:: ", err_45);
|
6922
|
+
throw err_45;
|
7517
6923
|
case 4: return [2, {
|
7518
6924
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7519
6925
|
additionalSigners: additionalSigners
|
@@ -7522,7 +6928,7 @@ var PerpetualsClient = (function () {
|
|
7522
6928
|
});
|
7523
6929
|
}); };
|
7524
6930
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7525
|
-
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;
|
7526
6932
|
var _f;
|
7527
6933
|
return __generator(this, function (_g) {
|
7528
6934
|
switch (_g.label) {
|
@@ -7583,9 +6989,9 @@ var PerpetualsClient = (function () {
|
|
7583
6989
|
instructions.push(reimburse);
|
7584
6990
|
return [3, 5];
|
7585
6991
|
case 4:
|
7586
|
-
|
7587
|
-
console.log("perpClient setPool error:: ",
|
7588
|
-
throw
|
6992
|
+
err_46 = _g.sent();
|
6993
|
+
console.log("perpClient setPool error:: ", err_46);
|
6994
|
+
throw err_46;
|
7589
6995
|
case 5: return [2, {
|
7590
6996
|
instructions: __spreadArray([], instructions, true),
|
7591
6997
|
additionalSigners: additionalSigners
|
@@ -7593,8 +6999,8 @@ var PerpetualsClient = (function () {
|
|
7593
6999
|
}
|
7594
7000
|
});
|
7595
7001
|
}); };
|
7596
|
-
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7597
|
-
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;
|
7598
7004
|
return __generator(this, function (_a) {
|
7599
7005
|
switch (_a.label) {
|
7600
7006
|
case 0:
|
@@ -7606,6 +7012,7 @@ var PerpetualsClient = (function () {
|
|
7606
7012
|
_a.trys.push([1, 3, , 4]);
|
7607
7013
|
return [4, this.program.methods
|
7608
7014
|
.setInternalOraclePrice({
|
7015
|
+
useCurrentTime: useCurrentTime,
|
7609
7016
|
price: price,
|
7610
7017
|
expo: expo,
|
7611
7018
|
conf: conf,
|
@@ -7627,9 +7034,9 @@ var PerpetualsClient = (function () {
|
|
7627
7034
|
instructions.push(setInternalOraclePrice);
|
7628
7035
|
return [3, 4];
|
7629
7036
|
case 3:
|
7630
|
-
|
7631
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7632
|
-
throw
|
7037
|
+
err_47 = _a.sent();
|
7038
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_47);
|
7039
|
+
throw err_47;
|
7633
7040
|
case 4: return [2, {
|
7634
7041
|
instructions: __spreadArray([], instructions, true),
|
7635
7042
|
additionalSigners: additionalSigners
|
@@ -7637,8 +7044,8 @@ var PerpetualsClient = (function () {
|
|
7637
7044
|
}
|
7638
7045
|
});
|
7639
7046
|
}); };
|
7640
|
-
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7641
|
-
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;
|
7642
7049
|
return __generator(this, function (_a) {
|
7643
7050
|
switch (_a.label) {
|
7644
7051
|
case 0:
|
@@ -7676,7 +7083,8 @@ var PerpetualsClient = (function () {
|
|
7676
7083
|
_a.trys.push([1, 3, , 4]);
|
7677
7084
|
return [4, this.program.methods
|
7678
7085
|
.setInternalCurrentPrice({
|
7679
|
-
prices: tokenInternalPrices
|
7086
|
+
prices: tokenInternalPrices,
|
7087
|
+
useCurrentTime: useCurrentTime ? 1 : 0
|
7680
7088
|
})
|
7681
7089
|
.accounts({
|
7682
7090
|
authority: POOL_CONFIGS[0].backupOracle,
|
@@ -7688,9 +7096,9 @@ var PerpetualsClient = (function () {
|
|
7688
7096
|
instructions.push(setInternalOraclePrice);
|
7689
7097
|
return [3, 4];
|
7690
7098
|
case 3:
|
7691
|
-
|
7692
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7693
|
-
throw
|
7099
|
+
err_48 = _a.sent();
|
7100
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_48);
|
7101
|
+
throw err_48;
|
7694
7102
|
case 4: return [2, {
|
7695
7103
|
instructions: __spreadArray([], instructions, true),
|
7696
7104
|
additionalSigners: additionalSigners
|
@@ -7699,7 +7107,7 @@ var PerpetualsClient = (function () {
|
|
7699
7107
|
});
|
7700
7108
|
}); };
|
7701
7109
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7702
|
-
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;
|
7703
7111
|
return __generator(this, function (_a) {
|
7704
7112
|
switch (_a.label) {
|
7705
7113
|
case 0:
|
@@ -7710,21 +7118,11 @@ var PerpetualsClient = (function () {
|
|
7710
7118
|
accountMetas = [];
|
7711
7119
|
_loop_2 = function (tokenMint) {
|
7712
7120
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7713
|
-
accountMetas.push({
|
7714
|
-
pubkey: custody.custodyAccount,
|
7715
|
-
isSigner: false,
|
7716
|
-
isWritable: false,
|
7717
|
-
});
|
7718
7121
|
accountMetas.push({
|
7719
7122
|
pubkey: custody.intOracleAccount,
|
7720
7123
|
isSigner: false,
|
7721
7124
|
isWritable: true,
|
7722
7125
|
});
|
7723
|
-
accountMetas.push({
|
7724
|
-
pubkey: custody.extOracleAccount,
|
7725
|
-
isSigner: false,
|
7726
|
-
isWritable: false,
|
7727
|
-
});
|
7728
7126
|
};
|
7729
7127
|
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
7730
7128
|
tokenMint = tokenMintList_2[_i];
|
@@ -7749,9 +7147,9 @@ var PerpetualsClient = (function () {
|
|
7749
7147
|
instructions.push(setInternalOraclePrice);
|
7750
7148
|
return [3, 4];
|
7751
7149
|
case 3:
|
7752
|
-
|
7753
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7754
|
-
throw
|
7150
|
+
err_49 = _a.sent();
|
7151
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_49);
|
7152
|
+
throw err_49;
|
7755
7153
|
case 4: return [2, {
|
7756
7154
|
instructions: __spreadArray([], instructions, true),
|
7757
7155
|
additionalSigners: additionalSigners
|
@@ -7760,7 +7158,7 @@ var PerpetualsClient = (function () {
|
|
7760
7158
|
});
|
7761
7159
|
}); };
|
7762
7160
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7763
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
7161
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_50;
|
7764
7162
|
return __generator(this, function (_a) {
|
7765
7163
|
switch (_a.label) {
|
7766
7164
|
case 0:
|
@@ -7798,8 +7196,8 @@ var PerpetualsClient = (function () {
|
|
7798
7196
|
instructions.push(renameFlp);
|
7799
7197
|
return [3, 4];
|
7800
7198
|
case 3:
|
7801
|
-
|
7802
|
-
console.log("perpClient renameFlp error:: ",
|
7199
|
+
err_50 = _a.sent();
|
7200
|
+
console.log("perpClient renameFlp error:: ", err_50);
|
7803
7201
|
return [3, 4];
|
7804
7202
|
case 4: return [2, {
|
7805
7203
|
instructions: __spreadArray([], instructions, true),
|
@@ -7809,7 +7207,7 @@ var PerpetualsClient = (function () {
|
|
7809
7207
|
});
|
7810
7208
|
}); };
|
7811
7209
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7812
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
7210
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_51;
|
7813
7211
|
return __generator(this, function (_a) {
|
7814
7212
|
switch (_a.label) {
|
7815
7213
|
case 0:
|
@@ -7847,9 +7245,9 @@ var PerpetualsClient = (function () {
|
|
7847
7245
|
instructions.push(initStakeInstruction);
|
7848
7246
|
return [3, 4];
|
7849
7247
|
case 3:
|
7850
|
-
|
7851
|
-
console.log("perpClient InitStaking error:: ",
|
7852
|
-
throw
|
7248
|
+
err_51 = _a.sent();
|
7249
|
+
console.log("perpClient InitStaking error:: ", err_51);
|
7250
|
+
throw err_51;
|
7853
7251
|
case 4: return [2, {
|
7854
7252
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7855
7253
|
additionalSigners: additionalSigners
|
@@ -7858,7 +7256,7 @@ var PerpetualsClient = (function () {
|
|
7858
7256
|
});
|
7859
7257
|
}); };
|
7860
7258
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7861
|
-
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;
|
7862
7260
|
return __generator(this, function (_a) {
|
7863
7261
|
switch (_a.label) {
|
7864
7262
|
case 0:
|
@@ -7903,9 +7301,9 @@ var PerpetualsClient = (function () {
|
|
7903
7301
|
instructions.push(initCompoundingInstruction);
|
7904
7302
|
return [3, 4];
|
7905
7303
|
case 3:
|
7906
|
-
|
7907
|
-
console.log("perpClient initCompounding error:: ",
|
7908
|
-
throw
|
7304
|
+
err_52 = _a.sent();
|
7305
|
+
console.log("perpClient initCompounding error:: ", err_52);
|
7306
|
+
throw err_52;
|
7909
7307
|
case 4: return [2, {
|
7910
7308
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7911
7309
|
additionalSigners: additionalSigners
|
@@ -7914,7 +7312,7 @@ var PerpetualsClient = (function () {
|
|
7914
7312
|
});
|
7915
7313
|
}); };
|
7916
7314
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7917
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
7315
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_53;
|
7918
7316
|
return __generator(this, function (_a) {
|
7919
7317
|
switch (_a.label) {
|
7920
7318
|
case 0:
|
@@ -7955,9 +7353,9 @@ var PerpetualsClient = (function () {
|
|
7955
7353
|
instructions.push(initTokenVaultInstruction);
|
7956
7354
|
return [3, 4];
|
7957
7355
|
case 3:
|
7958
|
-
|
7959
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
7960
|
-
throw
|
7356
|
+
err_53 = _a.sent();
|
7357
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_53);
|
7358
|
+
throw err_53;
|
7961
7359
|
case 4: return [2, {
|
7962
7360
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7963
7361
|
additionalSigners: additionalSigners
|
@@ -7966,7 +7364,7 @@ var PerpetualsClient = (function () {
|
|
7966
7364
|
});
|
7967
7365
|
}); };
|
7968
7366
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7969
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
7367
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_54;
|
7970
7368
|
return __generator(this, function (_a) {
|
7971
7369
|
switch (_a.label) {
|
7972
7370
|
case 0:
|
@@ -7997,9 +7395,9 @@ var PerpetualsClient = (function () {
|
|
7997
7395
|
instructions.push(setTokenVaultConfigInstruction);
|
7998
7396
|
return [3, 4];
|
7999
7397
|
case 3:
|
8000
|
-
|
8001
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
8002
|
-
throw
|
7398
|
+
err_54 = _a.sent();
|
7399
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_54);
|
7400
|
+
throw err_54;
|
8003
7401
|
case 4: return [2, {
|
8004
7402
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8005
7403
|
additionalSigners: additionalSigners
|
@@ -8008,7 +7406,7 @@ var PerpetualsClient = (function () {
|
|
8008
7406
|
});
|
8009
7407
|
}); };
|
8010
7408
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8011
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
7409
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_55;
|
8012
7410
|
return __generator(this, function (_a) {
|
8013
7411
|
switch (_a.label) {
|
8014
7412
|
case 0:
|
@@ -8047,9 +7445,9 @@ var PerpetualsClient = (function () {
|
|
8047
7445
|
instructions.push(withdrawInstantFeeInstruction);
|
8048
7446
|
return [3, 6];
|
8049
7447
|
case 5:
|
8050
|
-
|
8051
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
8052
|
-
throw
|
7448
|
+
err_55 = _a.sent();
|
7449
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_55);
|
7450
|
+
throw err_55;
|
8053
7451
|
case 6: return [2, {
|
8054
7452
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8055
7453
|
additionalSigners: additionalSigners
|
@@ -8058,7 +7456,7 @@ var PerpetualsClient = (function () {
|
|
8058
7456
|
});
|
8059
7457
|
}); };
|
8060
7458
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8061
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
7459
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_56;
|
8062
7460
|
return __generator(this, function (_a) {
|
8063
7461
|
switch (_a.label) {
|
8064
7462
|
case 0:
|
@@ -8095,9 +7493,9 @@ var PerpetualsClient = (function () {
|
|
8095
7493
|
instructions.push(initRevenueTokenAccountInstruction);
|
8096
7494
|
return [3, 4];
|
8097
7495
|
case 3:
|
8098
|
-
|
8099
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
8100
|
-
throw
|
7496
|
+
err_56 = _a.sent();
|
7497
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_56);
|
7498
|
+
throw err_56;
|
8101
7499
|
case 4: return [2, {
|
8102
7500
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8103
7501
|
additionalSigners: additionalSigners
|
@@ -8106,7 +7504,7 @@ var PerpetualsClient = (function () {
|
|
8106
7504
|
});
|
8107
7505
|
}); };
|
8108
7506
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8109
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
7507
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_57;
|
8110
7508
|
return __generator(this, function (_a) {
|
8111
7509
|
switch (_a.label) {
|
8112
7510
|
case 0:
|
@@ -8145,9 +7543,9 @@ var PerpetualsClient = (function () {
|
|
8145
7543
|
instructions.push(distributeTokenRewardInstruction);
|
8146
7544
|
return [3, 4];
|
8147
7545
|
case 3:
|
8148
|
-
|
8149
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
8150
|
-
throw
|
7546
|
+
err_57 = _a.sent();
|
7547
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_57);
|
7548
|
+
throw err_57;
|
8151
7549
|
case 4: return [2, {
|
8152
7550
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8153
7551
|
additionalSigners: additionalSigners
|
@@ -8156,7 +7554,7 @@ var PerpetualsClient = (function () {
|
|
8156
7554
|
});
|
8157
7555
|
}); };
|
8158
7556
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
8159
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
7557
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_58;
|
8160
7558
|
return __generator(this, function (_a) {
|
8161
7559
|
switch (_a.label) {
|
8162
7560
|
case 0:
|
@@ -8184,9 +7582,9 @@ var PerpetualsClient = (function () {
|
|
8184
7582
|
instructions.push(setTokenStakeLevelInstruction);
|
8185
7583
|
return [3, 4];
|
8186
7584
|
case 3:
|
8187
|
-
|
8188
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
8189
|
-
throw
|
7585
|
+
err_58 = _a.sent();
|
7586
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_58);
|
7587
|
+
throw err_58;
|
8190
7588
|
case 4: return [2, {
|
8191
7589
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8192
7590
|
additionalSigners: additionalSigners
|
@@ -8195,7 +7593,7 @@ var PerpetualsClient = (function () {
|
|
8195
7593
|
});
|
8196
7594
|
}); };
|
8197
7595
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8198
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
7596
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_59;
|
8199
7597
|
return __generator(this, function (_a) {
|
8200
7598
|
switch (_a.label) {
|
8201
7599
|
case 0:
|
@@ -8227,9 +7625,49 @@ var PerpetualsClient = (function () {
|
|
8227
7625
|
instructions.push(setTokenRewardInstruction);
|
8228
7626
|
return [3, 4];
|
8229
7627
|
case 3:
|
8230
|
-
|
8231
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
8232
|
-
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;
|
8233
7671
|
case 4: return [2, {
|
8234
7672
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8235
7673
|
additionalSigners: additionalSigners
|