flash-sdk 9.0.0-alpha.1 → 9.0.0-alpha.11
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 +209 -108
- package/dist/PerpetualsClient.js +608 -993
- package/dist/PoolConfig.d.ts +5 -1
- package/dist/PoolConfig.js +4 -2
- package/dist/PoolConfig.json +272 -10
- package/dist/PositionAccount.d.ts +3 -2
- package/dist/idl/perpetuals.d.ts +2846 -1346
- package/dist/idl/perpetuals.js +2846 -1346
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/testSize.d.ts +0 -0
- package/dist/testSize.js +0 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +3 -2
- package/dist/utils/getReferralAccounts.d.ts +1 -1
- package/dist/utils/getReferralAccounts.js +3 -8
- package/package.json +1 -1
- package/dist/TradingAccount.d.ts +0 -23
- package/dist/TradingAccount.js +0 -17
package/dist/PerpetualsClient.js
CHANGED
|
@@ -638,24 +638,41 @@ var PerpetualsClient = (function () {
|
|
|
638
638
|
var averageEntryPrice = totalValue.div(totalSize);
|
|
639
639
|
return averageEntryPrice;
|
|
640
640
|
};
|
|
641
|
-
this.
|
|
642
|
-
var
|
|
643
|
-
var
|
|
644
|
-
|
|
645
|
-
|
|
641
|
+
this.getLeverageContractHelper = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig) {
|
|
642
|
+
var pnl = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
643
|
+
var exitFee = _this.getExitFeeSync(positionAccount, targetCustodyAccount, collateralCustodyAccount, collateralPrice, collateralEmaPrice);
|
|
644
|
+
var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
645
|
+
var unsettledFeesUsd = exitFee.exitFeeUsd.add(lockFeeUsd);
|
|
646
|
+
var lossUsd = pnl.lossUsd.add(unsettledFeesUsd);
|
|
647
|
+
var currentMarginUsd = constants_1.BN_ZERO;
|
|
648
|
+
if (isInitial) {
|
|
649
|
+
currentMarginUsd = positionAccount.collateralUsd.sub(lossUsd);
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
|
|
653
|
+
}
|
|
654
|
+
if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
|
|
655
|
+
return positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
|
|
646
656
|
}
|
|
647
657
|
else {
|
|
648
658
|
return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
|
|
649
659
|
}
|
|
650
660
|
};
|
|
651
|
-
this.
|
|
661
|
+
this.getLeverageSync = function (positionAccount, finalCollateralUsd, finalSizeUsd, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig) {
|
|
662
|
+
positionAccount = positionAccount.clone();
|
|
663
|
+
positionAccount.sizeUsd = finalSizeUsd;
|
|
664
|
+
positionAccount.sizeAmount = targetPrice.getTokenAmount(finalSizeUsd, targetCustodyAccount.decimals);
|
|
665
|
+
positionAccount.collateralUsd = finalCollateralUsd;
|
|
666
|
+
return _this.getLeverageContractHelper(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, isInitial, poolConfig);
|
|
667
|
+
};
|
|
668
|
+
this.getLeverageAtAmountEntryWithSwapSync = function (positionAccount, inputDeltaAmount, sizeDeltaAmount, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig, pnlUsd) {
|
|
652
669
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
|
653
670
|
if (!inputDeltaAmount.isZero()) {
|
|
654
671
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
|
655
672
|
finalCollateralAmount = inputDeltaAmount;
|
|
656
673
|
}
|
|
657
674
|
else {
|
|
658
|
-
var swapAmountOut = _this.getSwapAmountAndFeesSync(inputDeltaAmount, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
|
675
|
+
var swapAmountOut = _this.getSwapAmountAndFeesSync(inputDeltaAmount, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountOut;
|
|
659
676
|
finalCollateralAmount = swapAmountOut;
|
|
660
677
|
}
|
|
661
678
|
}
|
|
@@ -681,9 +698,8 @@ var PerpetualsClient = (function () {
|
|
|
681
698
|
entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
|
|
682
699
|
}
|
|
683
700
|
var collateralMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
|
684
|
-
var
|
|
685
|
-
var
|
|
686
|
-
var currentCollateralUsdIncludingPnl = currentCollateralUsd.add(pnlUsd).sub(openFeeUsd);
|
|
701
|
+
var finalCollateralUsd = collateralMinOraclePrice.getAssetAmountUsd(finalCollateralAmount, collateralTokenCustodyAccount.decimals);
|
|
702
|
+
var currentCollateralUsdIncludingPnl = finalCollateralUsd.add(pnlUsd).sub(openFeeUsd);
|
|
687
703
|
var sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
|
688
704
|
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
|
689
705
|
if (currentCollateralUsdIncludingPnl.gt(constants_1.BN_ZERO)) {
|
|
@@ -693,68 +709,6 @@ var PerpetualsClient = (function () {
|
|
|
693
709
|
return new anchor_1.BN(Number.MAX_SAFE_INTEGER);
|
|
694
710
|
}
|
|
695
711
|
};
|
|
696
|
-
this.getEntryPriceAndFeeSync = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps) {
|
|
697
|
-
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
|
698
|
-
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
|
699
|
-
throw new Error("Delta Amounts cannot be negative.");
|
|
700
|
-
}
|
|
701
|
-
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
702
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
|
703
|
-
if (positionAccount === null) {
|
|
704
|
-
var data = __assign({}, types_1.DEFAULT_POSITION);
|
|
705
|
-
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
|
706
|
-
var sizeUsd_1 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
707
|
-
positionAccount.sizeUsd = sizeUsd_1;
|
|
708
|
-
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
|
709
|
-
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
|
710
|
-
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
positionAccount = positionAccount.clone();
|
|
714
|
-
var positionEntryPrice = OraclePrice_1.OraclePrice.from({
|
|
715
|
-
price: positionAccount.entryPrice.price,
|
|
716
|
-
exponent: new anchor_1.BN(positionAccount.entryPrice.exponent),
|
|
717
|
-
confidence: constants_1.BN_ZERO,
|
|
718
|
-
timestamp: constants_1.BN_ZERO
|
|
719
|
-
});
|
|
720
|
-
entryOraclePrice.price = _this.getAveragePriceSync(positionEntryPrice.price, positionAccount.sizeAmount, entryOraclePrice.price, sizeDeltaAmount);
|
|
721
|
-
var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
722
|
-
positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
|
|
723
|
-
}
|
|
724
|
-
positionAccount.collateralAmount = positionAccount.collateralAmount.add(collateralDeltaAmount);
|
|
725
|
-
positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
|
726
|
-
var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
727
|
-
var liquidationPrice = _this.getLiquidationPriceSync(positionAccount.collateralAmount, positionAccount.sizeAmount, entryOraclePrice, lockFeeUsd, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, positionAccount);
|
|
728
|
-
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
729
|
-
var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
|
730
|
-
var feeUsd = constants_1.BN_ZERO;
|
|
731
|
-
var feeAmount = constants_1.BN_ZERO;
|
|
732
|
-
var feeUsdAfterDiscount = constants_1.BN_ZERO;
|
|
733
|
-
var feeAmountAfterDiscount = constants_1.BN_ZERO;
|
|
734
|
-
if (positionAccount !== null && sizeDeltaAmount.isZero()) {
|
|
735
|
-
}
|
|
736
|
-
else {
|
|
737
|
-
feeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.openPosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
738
|
-
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
|
|
739
|
-
if (discountBps.gt(constants_1.BN_ZERO)) {
|
|
740
|
-
feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
|
741
|
-
feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
|
|
742
|
-
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralTokenMinOraclePrice.price);
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
feeUsdAfterDiscount = feeUsd;
|
|
746
|
-
feeAmountAfterDiscount = feeAmount;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
return {
|
|
750
|
-
entryOraclePrice: entryOraclePrice,
|
|
751
|
-
feeUsd: feeUsd,
|
|
752
|
-
feeAmount: feeAmount,
|
|
753
|
-
feeUsdAfterDiscount: feeUsdAfterDiscount,
|
|
754
|
-
feeAmountAfterDiscount: feeAmountAfterDiscount,
|
|
755
|
-
liquidationPrice: liquidationPrice
|
|
756
|
-
};
|
|
757
|
-
};
|
|
758
712
|
this.getEntryPriceAndFeeSyncV2 = function (positionAccount, marketCorrelation, collateralDeltaAmount, sizeDeltaAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, discountBps, enableLogs) {
|
|
759
713
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
|
760
714
|
if (enableLogs === void 0) { enableLogs = false; }
|
|
@@ -766,8 +720,8 @@ var PerpetualsClient = (function () {
|
|
|
766
720
|
if (positionAccount === null) {
|
|
767
721
|
var data = __assign({}, types_1.DEFAULT_POSITION);
|
|
768
722
|
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
|
769
|
-
var
|
|
770
|
-
positionAccount.sizeUsd =
|
|
723
|
+
var sizeUsd_1 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
724
|
+
positionAccount.sizeUsd = sizeUsd_1;
|
|
771
725
|
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
|
772
726
|
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
|
773
727
|
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
|
@@ -784,12 +738,13 @@ var PerpetualsClient = (function () {
|
|
|
784
738
|
var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
785
739
|
positionAccount.sizeUsd = positionAccount.sizeUsd.add(sizeDeltaUsd);
|
|
786
740
|
}
|
|
787
|
-
|
|
741
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
742
|
+
var collateralDeltaUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
|
743
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
|
788
744
|
positionAccount.sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
|
|
789
|
-
var
|
|
790
|
-
var liquidationPrice = _this.
|
|
745
|
+
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
746
|
+
var liquidationPrice = _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
|
791
747
|
var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
792
|
-
var collateralTokenMinOraclePrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
|
793
748
|
var feeUsd = constants_1.BN_ZERO;
|
|
794
749
|
var feeAmount = constants_1.BN_ZERO;
|
|
795
750
|
var feeUsdAfterDiscount = constants_1.BN_ZERO;
|
|
@@ -798,11 +753,11 @@ var PerpetualsClient = (function () {
|
|
|
798
753
|
}
|
|
799
754
|
else {
|
|
800
755
|
feeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.openPosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
801
|
-
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(
|
|
756
|
+
feeAmount = feeUsd.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralMinMaxPrice.min.price);
|
|
802
757
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
|
803
758
|
feeUsdAfterDiscount = feeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
|
804
759
|
feeUsdAfterDiscount = feeUsd.sub(feeUsdAfterDiscount);
|
|
805
|
-
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(
|
|
760
|
+
feeAmountAfterDiscount = feeUsdAfterDiscount.mul(new anchor_1.BN(Math.pow(10, collateralCustodyAccount.decimals))).div(collateralMinMaxPrice.min.price);
|
|
806
761
|
}
|
|
807
762
|
else {
|
|
808
763
|
feeUsdAfterDiscount = feeUsd;
|
|
@@ -861,25 +816,26 @@ var PerpetualsClient = (function () {
|
|
|
861
816
|
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
|
862
817
|
throw new Error("Delta Amounts cannot be negative ");
|
|
863
818
|
}
|
|
864
|
-
resultingPositionAccount.collateralAmount = resultingPositionAccount.collateralAmount.sub(collateralDeltaAmount);
|
|
865
|
-
resultingPositionAccount.sizeAmount = resultingPositionAccount.sizeAmount.sub(sizeDeltaAmount);
|
|
866
819
|
if (resultingPositionAccount.collateralAmount.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
|
|
867
820
|
throw new Error("cannot remove/close more than collateral/Size");
|
|
868
821
|
}
|
|
869
822
|
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
870
823
|
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
|
871
|
-
var
|
|
824
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
825
|
+
var collateralDeltaUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
|
826
|
+
resultingPositionAccount.collateralUsd = resultingPositionAccount.collateralUsd.sub(collateralDeltaUsd);
|
|
827
|
+
resultingPositionAccount.sizeAmount = resultingPositionAccount.sizeAmount.sub(sizeDeltaAmount);
|
|
872
828
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(resultingPositionAccount, collateralCustodyAccount, currentTimestamp);
|
|
873
|
-
var lockAndUnsettledFee =
|
|
829
|
+
var lockAndUnsettledFee = collateralMinMaxPrice.min.getTokenAmount(lockAndUnsettledFeeUsd, collateralCustodyAccount.decimals);
|
|
874
830
|
var sizeAmountUsd = exitOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
|
875
831
|
var exitFeeUsd = sizeAmountUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
876
|
-
var exitFeeAmount =
|
|
832
|
+
var exitFeeAmount = collateralMinMaxPrice.max.getTokenAmount(exitFeeUsd, collateralCustodyAccount.decimals);
|
|
877
833
|
var exitFeeUsdAfterDiscount = constants_1.BN_ZERO;
|
|
878
834
|
var exitFeeAmountAfterDiscount = constants_1.BN_ZERO;
|
|
879
835
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
|
880
836
|
exitFeeUsdAfterDiscount = exitFeeUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
|
881
837
|
exitFeeUsdAfterDiscount = exitFeeUsd.sub(exitFeeUsdAfterDiscount);
|
|
882
|
-
exitFeeAmountAfterDiscount =
|
|
838
|
+
exitFeeAmountAfterDiscount = collateralMinMaxPrice.max.getTokenAmount(exitFeeUsdAfterDiscount, collateralCustodyAccount.decimals);
|
|
883
839
|
}
|
|
884
840
|
else {
|
|
885
841
|
exitFeeUsdAfterDiscount = exitFeeUsd;
|
|
@@ -889,7 +845,7 @@ var PerpetualsClient = (function () {
|
|
|
889
845
|
price: positionAccount.entryPrice.price, exponent: new anchor_1.BN(positionAccount.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO
|
|
890
846
|
});
|
|
891
847
|
resultingPositionAccount.sizeUsd = positionEntryOraclePrice.getAssetAmountUsd(resultingPositionAccount.sizeAmount, targetCustodyAccount.decimals);
|
|
892
|
-
var liquidationPrice = _this.
|
|
848
|
+
var liquidationPrice = _this.getLiquidationPriceContractHelper(positionEntryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
|
893
849
|
return {
|
|
894
850
|
exitOraclePrice: exitOraclePrice,
|
|
895
851
|
borrowFeeUsd: lockAndUnsettledFeeUsd,
|
|
@@ -902,13 +858,11 @@ var PerpetualsClient = (function () {
|
|
|
902
858
|
};
|
|
903
859
|
};
|
|
904
860
|
this.getTradeSpread = function (targetCustodyAccount, sizeUsd) {
|
|
905
|
-
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero()
|
|
906
|
-
||
|
|
907
|
-
sizeUsd.isZero()) {
|
|
861
|
+
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero() || sizeUsd.isZero()) {
|
|
908
862
|
return constants_1.BN_ZERO;
|
|
909
863
|
}
|
|
910
864
|
var slope = ((targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin)).mul(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS)))))
|
|
911
|
-
.div(targetCustodyAccount.pricing.
|
|
865
|
+
.div(targetCustodyAccount.pricing.maxPositionSizeUsd);
|
|
912
866
|
var variable = (slope.mul(sizeUsd)).div(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS))));
|
|
913
867
|
var finalSpread = targetCustodyAccount.pricing.tradeSpreadMin.add(variable);
|
|
914
868
|
return finalSpread;
|
|
@@ -923,21 +877,11 @@ var PerpetualsClient = (function () {
|
|
|
923
877
|
var exitOraclePrice = OraclePrice_1.OraclePrice.from({ price: exitPriceBN, exponent: maxPrice.exponent, confidence: maxPrice.confidence, timestamp: maxPrice.timestamp });
|
|
924
878
|
return exitOraclePrice;
|
|
925
879
|
};
|
|
926
|
-
this.getExitOraclePriceWithoutSpreadSync = function (side, targetPrice, targetEmaPrice, targetCustodyAccount) {
|
|
927
|
-
var _a = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount), minPrice = _a.min, maxPrice = _a.max;
|
|
928
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
929
|
-
return minPrice;
|
|
930
|
-
}
|
|
931
|
-
else {
|
|
932
|
-
return maxPrice;
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
880
|
this.getSizeAmountFromLeverageAndCollateral = function (collateralAmtWithFee, leverage, marketToken, collateralToken, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, discountBps) {
|
|
936
881
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
|
937
882
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
|
938
883
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
|
939
|
-
var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals))
|
|
940
|
-
.multipliedBy(collateralTokenMinPriceUi);
|
|
884
|
+
var collateralAmtMinUsdUi = new bignumber_js_1.default(collateralAmtWithFee.toString()).dividedBy(Math.pow(10, collateralToken.decimals)).multipliedBy(collateralTokenMinPriceUi);
|
|
941
885
|
var openPosFeeRateUi = new bignumber_js_1.default(targetCustodyAccount.fees.openPosition.toString()).dividedBy(Math.pow(10, constants_1.RATE_DECIMALS));
|
|
942
886
|
if (!discountBps.isZero()) {
|
|
943
887
|
var discountBpsUi = new bignumber_js_1.default(discountBps.toString()).dividedBy(Math.pow(10, constants_1.BPS_DECIMALS));
|
|
@@ -945,20 +889,20 @@ var PerpetualsClient = (function () {
|
|
|
945
889
|
}
|
|
946
890
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
|
947
891
|
.dividedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage)));
|
|
948
|
-
var
|
|
949
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
|
892
|
+
var sizeUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toString(), constants_1.USD_DECIMALS);
|
|
893
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
|
950
894
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
|
951
895
|
var sizeAmountUi = sizeUsdUi.dividedBy(entryPriceUsdUi);
|
|
952
896
|
return (0, utils_1.uiDecimalsToNative)(sizeAmountUi.toFixed(marketToken.decimals, bignumber_js_1.default.ROUND_DOWN), marketToken.decimals);
|
|
953
897
|
};
|
|
954
|
-
this.getSizeAmountWithSwapSync = function (amountIn, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax,
|
|
898
|
+
this.getSizeAmountWithSwapSync = function (amountIn, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig, discountBps) {
|
|
955
899
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
|
956
900
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
|
957
901
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
|
958
902
|
finalCollateralAmount = amountIn;
|
|
959
903
|
}
|
|
960
904
|
else {
|
|
961
|
-
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
|
905
|
+
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountOut;
|
|
962
906
|
finalCollateralAmount = swapAmountOut;
|
|
963
907
|
}
|
|
964
908
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
|
@@ -972,8 +916,8 @@ var PerpetualsClient = (function () {
|
|
|
972
916
|
}
|
|
973
917
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
|
974
918
|
.dividedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage)));
|
|
975
|
-
var
|
|
976
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount,
|
|
919
|
+
var sizeUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toFixed(constants_1.USD_DECIMALS), constants_1.USD_DECIMALS);
|
|
920
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
|
|
977
921
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
|
978
922
|
var sizeAmountUi = sizeUsdUi.dividedBy(entryPriceUsdUi);
|
|
979
923
|
return (0, utils_1.uiDecimalsToNative)(sizeAmountUi.toFixed(targetTokenCustodyAccount.decimals, bignumber_js_1.default.ROUND_DOWN), targetTokenCustodyAccount.decimals);
|
|
@@ -996,7 +940,7 @@ var PerpetualsClient = (function () {
|
|
|
996
940
|
var collateralAmtWithFeeUi = collateralWithFeeUsdUi.dividedBy(collateralTokenMinPriceUi);
|
|
997
941
|
return (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralToken.decimals, bignumber_js_1.default.ROUND_DOWN), collateralToken.decimals);
|
|
998
942
|
};
|
|
999
|
-
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax,
|
|
943
|
+
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfig) {
|
|
1000
944
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
|
1001
945
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
|
1002
946
|
var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
|
@@ -1013,7 +957,7 @@ var PerpetualsClient = (function () {
|
|
|
1013
957
|
collateralInInputToken = collateralAmountWithFee;
|
|
1014
958
|
}
|
|
1015
959
|
else {
|
|
1016
|
-
collateralInInputToken = _this.getSwapAmountAndFeesSync(constants_1.BN_ZERO, collateralAmountWithFee, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax,
|
|
960
|
+
collateralInInputToken = _this.getSwapAmountAndFeesSync(constants_1.BN_ZERO, collateralAmountWithFee, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfig).minAmountIn;
|
|
1017
961
|
}
|
|
1018
962
|
return collateralInInputToken;
|
|
1019
963
|
};
|
|
@@ -1039,10 +983,10 @@ var PerpetualsClient = (function () {
|
|
|
1039
983
|
var decimalPower = new anchor_1.BN(Math.pow(10, targetCustodyAccount.decimals));
|
|
1040
984
|
var closeRatio = (positionDelta.sizeAmount.mul(decimalPower)).div(positionAccount.sizeAmount);
|
|
1041
985
|
positionDelta.sizeUsd = (positionAccount.sizeUsd.mul(closeRatio)).div(decimalPower);
|
|
1042
|
-
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
|
1043
986
|
positionDelta.lockedAmount = (positionAccount.lockedAmount.mul(closeRatio)).div(decimalPower);
|
|
1044
987
|
positionDelta.lockedUsd = (positionAccount.lockedUsd.mul(closeRatio)).div(decimalPower);
|
|
1045
|
-
positionDelta.
|
|
988
|
+
positionDelta.collateralUsd = (positionAccount.collateralUsd.mul(closeRatio)).div(decimalPower);
|
|
989
|
+
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
|
1046
990
|
positionDelta.degenSizeUsd = positionAccount.degenSizeUsd.mul(closeRatio).div(decimalPower);
|
|
1047
991
|
var newPnl = _this.getPnlSync(positionDelta, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1048
992
|
var exitFeeUsd = positionDelta.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
@@ -1052,29 +996,29 @@ var PerpetualsClient = (function () {
|
|
|
1052
996
|
}
|
|
1053
997
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionDelta, collateralCustodyAccount, currentTimestamp);
|
|
1054
998
|
var totalFeesUsd = (exitFeeUsd.add(lockAndUnsettledFeeUsd));
|
|
1055
|
-
var currentCollateralUsd =
|
|
999
|
+
var currentCollateralUsd = positionDelta.collateralUsd;
|
|
1056
1000
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
|
1057
|
-
var assetsUsd = newPnl.profitUsd.add(currentCollateralUsd);
|
|
1058
|
-
var closeAmount, feesAmount;
|
|
1001
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
|
|
1059
1002
|
if (debugLogs) {
|
|
1060
1003
|
console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
|
|
1061
1004
|
}
|
|
1005
|
+
var closeAmountUsd, feesAmountUsd;
|
|
1062
1006
|
if (assetsUsd.gte(liabilityUsd)) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1007
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
|
1008
|
+
feesAmountUsd = totalFeesUsd;
|
|
1065
1009
|
}
|
|
1066
1010
|
else {
|
|
1067
|
-
|
|
1068
|
-
|
|
1011
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
|
1012
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
|
1069
1013
|
}
|
|
1014
|
+
var closeAmount = collateralMinMaxPrice.max.getTokenAmount(closeAmountUsd, collateralCustodyAccount.decimals);
|
|
1070
1015
|
var newPosition = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
|
1071
1016
|
newPosition.sizeAmount = positionAccount.sizeAmount.sub(positionDelta.sizeAmount);
|
|
1072
1017
|
newPosition.sizeUsd = positionAccount.sizeUsd.sub(positionDelta.sizeUsd);
|
|
1073
1018
|
newPosition.lockedUsd = positionAccount.lockedUsd.sub(positionDelta.lockedUsd);
|
|
1074
1019
|
newPosition.lockedAmount = positionAccount.lockedAmount.sub(positionDelta.lockedAmount);
|
|
1075
|
-
newPosition.
|
|
1020
|
+
newPosition.collateralUsd = positionAccount.collateralUsd.sub(positionDelta.collateralUsd);
|
|
1076
1021
|
newPosition.unsettledFeesUsd = positionAccount.unsettledFeesUsd.sub(positionDelta.unsettledFeesUsd);
|
|
1077
|
-
newPosition.collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(newPosition.collateralAmount, collateralCustodyAccount.decimals);
|
|
1078
1022
|
newPosition.degenSizeUsd = positionAccount.degenSizeUsd.sub(positionDelta.degenSizeUsd);
|
|
1079
1023
|
var feeUsdWithDiscount = constants_1.BN_ZERO;
|
|
1080
1024
|
var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
@@ -1089,8 +1033,8 @@ var PerpetualsClient = (function () {
|
|
|
1089
1033
|
feeUsdWithDiscount = feeUsdWithDiscount.add(lockAndUnsettledFeeUsd);
|
|
1090
1034
|
if (keepLevSame) {
|
|
1091
1035
|
var collateralAmountReceived = closeAmount;
|
|
1092
|
-
var collateralAmountRecievedUsd =
|
|
1093
|
-
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
|
1036
|
+
var collateralAmountRecievedUsd = closeAmountUsd;
|
|
1037
|
+
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmountUsd), maxWithdrawableAmount = _a.maxWithdrawableAmount, diff = _a.diff;
|
|
1094
1038
|
if (debugLogs) {
|
|
1095
1039
|
console.log("maxWithdrawableAmount ", maxWithdrawableAmount.toString(), keepLevSame);
|
|
1096
1040
|
console.log("collateralAmountReceived ", collateralAmountReceived.toString(), keepLevSame);
|
|
@@ -1107,11 +1051,11 @@ var PerpetualsClient = (function () {
|
|
|
1107
1051
|
collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(maxWithdrawableAmount, collateralCustodyAccount.decimals);
|
|
1108
1052
|
}
|
|
1109
1053
|
var entryPrice = OraclePrice_1.OraclePrice.from({ price: newPosition.entryPrice.price, exponent: new anchor_1.BN(newPosition.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
|
|
1110
|
-
var
|
|
1111
|
-
var finalLiquidationPrice = _this.
|
|
1054
|
+
var lockAndUnsettledFeeUsdNew = _this.getLockFeeAndUnsettledUsdForPosition(newPosition, collateralCustodyAccount, currentTimestamp);
|
|
1055
|
+
var finalLiquidationPrice = _this.getLiquidationPriceContractHelper(entryPrice, lockAndUnsettledFeeUsdNew, side, targetCustodyAccount, newPosition);
|
|
1112
1056
|
var finalPnl = _this.getPnlSync(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1113
1057
|
var finalPnlUsd = finalPnl.profitUsd.sub(finalPnl.lossUsd);
|
|
1114
|
-
var newLev = _this.getLeverageSync(newPosition
|
|
1058
|
+
var newLev = _this.getLeverageSync(newPosition, newPosition.collateralUsd, newPosition.sizeUsd, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, false, poolConfig);
|
|
1115
1059
|
return {
|
|
1116
1060
|
newSizeUsd: newPosition.sizeUsd,
|
|
1117
1061
|
feeUsd: feeUsd,
|
|
@@ -1129,8 +1073,8 @@ var PerpetualsClient = (function () {
|
|
|
1129
1073
|
throw "only same leverage is supported for now";
|
|
1130
1074
|
}
|
|
1131
1075
|
};
|
|
1132
|
-
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig,
|
|
1133
|
-
if (
|
|
1076
|
+
this.getMaxWithdrawableAmountSyncInternal = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmountUsd, errorBandwidthPercentageUi) {
|
|
1077
|
+
if (closeAmountUsd === void 0) { closeAmountUsd = constants_1.BN_ZERO; }
|
|
1134
1078
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
|
1135
1079
|
if (errorBandwidthPercentageUi > 100 || errorBandwidthPercentageUi < 0) {
|
|
1136
1080
|
throw new Error("errorBandwidthPercentageUi cannot be >100 or <0");
|
|
@@ -1139,24 +1083,25 @@ var PerpetualsClient = (function () {
|
|
|
1139
1083
|
(new anchor_1.BN(targetCustodyAccount.pricing.maxInitDegenLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100))
|
|
1140
1084
|
: (new anchor_1.BN(targetCustodyAccount.pricing.maxInitLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100));
|
|
1141
1085
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1142
|
-
var
|
|
1086
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1143
1087
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1144
1088
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
1145
1089
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
|
1146
|
-
var currentCollateralUsd =
|
|
1090
|
+
var currentCollateralUsd = positionAccount.collateralUsd.sub(closeAmountUsd);
|
|
1147
1091
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
|
1148
1092
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
|
1149
1093
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
|
1150
1094
|
}
|
|
1151
1095
|
else {
|
|
1152
1096
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
|
1153
|
-
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1097
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1154
1098
|
}
|
|
1155
1099
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
|
1156
1100
|
if (maxRemovableCollateralUsd.isNeg()) {
|
|
1157
|
-
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1101
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1158
1102
|
}
|
|
1159
1103
|
var maxWithdrawableAmount = constants_1.BN_ZERO;
|
|
1104
|
+
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
|
1160
1105
|
var diff = constants_1.BN_ZERO;
|
|
1161
1106
|
var remainingCollateralUsd = availableInitMarginUsd.sub(maxRemovableCollateralUsd);
|
|
1162
1107
|
var isDegenMode = positionAccount.isDegenMode();
|
|
@@ -1164,36 +1109,37 @@ var PerpetualsClient = (function () {
|
|
|
1164
1109
|
diff = (new anchor_1.BN(isDegenMode ? targetCustodyAccount.pricing.minDegenCollateralUsd : targetCustodyAccount.pricing.minCollateralUsd)).sub(remainingCollateralUsd);
|
|
1165
1110
|
var updatedMaxRemovableCollateralUsd = maxRemovableCollateralUsd.sub(diff);
|
|
1166
1111
|
if (updatedMaxRemovableCollateralUsd.isNeg()) {
|
|
1167
|
-
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1112
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1168
1113
|
}
|
|
1169
1114
|
else {
|
|
1170
|
-
maxWithdrawableAmount =
|
|
1115
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(updatedMaxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
|
1116
|
+
maxWithdrawableAmountUsd = updatedMaxRemovableCollateralUsd;
|
|
1171
1117
|
}
|
|
1172
1118
|
}
|
|
1173
1119
|
else {
|
|
1174
|
-
maxWithdrawableAmount =
|
|
1120
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
|
1121
|
+
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
|
1175
1122
|
}
|
|
1176
|
-
return { maxWithdrawableAmount: maxWithdrawableAmount, diff: diff };
|
|
1123
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd, diff: diff };
|
|
1177
1124
|
};
|
|
1178
|
-
this.
|
|
1125
|
+
this.getFinalCloseAmountUsdSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
|
|
1179
1126
|
var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
|
1180
1127
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1181
|
-
var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
|
|
1182
1128
|
var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1183
1129
|
var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
|
|
1184
1130
|
var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
|
|
1185
1131
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
|
1186
|
-
var assetsUsd = newPnl.profitUsd.add(collateralMinMaxPrice.
|
|
1187
|
-
var
|
|
1132
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
|
|
1133
|
+
var closeAmountUsd, feesAmountUsd;
|
|
1188
1134
|
if (assetsUsd.gt(liabilityUsd)) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1135
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
|
1136
|
+
feesAmountUsd = totalFeesUsd;
|
|
1191
1137
|
}
|
|
1192
1138
|
else {
|
|
1193
|
-
|
|
1194
|
-
|
|
1139
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
|
1140
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
|
1195
1141
|
}
|
|
1196
|
-
return {
|
|
1142
|
+
return { closeAmountUsd: closeAmountUsd, feesAmountUsd: feesAmountUsd };
|
|
1197
1143
|
};
|
|
1198
1144
|
this.getMaxWithdrawableAmountSync = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, errorBandwidthPercentageUi) {
|
|
1199
1145
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
|
@@ -1206,34 +1152,37 @@ var PerpetualsClient = (function () {
|
|
|
1206
1152
|
var maxRemoveableCollateralUsdAfterMinRequired = positionAccount.collateralUsd.sub((positionAccount.isDegenMode() ? new anchor_1.BN(targetCustodyAccount.pricing.minDegenCollateralUsd) : new anchor_1.BN(targetCustodyAccount.pricing.minCollateralUsd)).mul(new anchor_1.BN(100 + errorBandwidthPercentageUi)).div(new anchor_1.BN(100)));
|
|
1207
1153
|
if (maxRemoveableCollateralUsdAfterMinRequired.isNeg()) {
|
|
1208
1154
|
console.log("THIS cannot happen but still");
|
|
1209
|
-
return constants_1.BN_ZERO;
|
|
1155
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
|
1210
1156
|
}
|
|
1211
1157
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1212
|
-
var
|
|
1158
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1213
1159
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1214
1160
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
1215
1161
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
|
1216
|
-
var currentCollateralUsd =
|
|
1162
|
+
var currentCollateralUsd = positionAccount.collateralUsd;
|
|
1217
1163
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
|
1218
1164
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
|
1219
1165
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
|
1220
1166
|
}
|
|
1221
1167
|
else {
|
|
1222
1168
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
|
1223
|
-
return constants_1.BN_ZERO;
|
|
1169
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
|
1224
1170
|
}
|
|
1225
1171
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
|
1226
1172
|
if (maxRemovableCollateralUsd.isNeg()) {
|
|
1227
|
-
return constants_1.BN_ZERO;
|
|
1173
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
|
1228
1174
|
}
|
|
1229
1175
|
var maxWithdrawableAmount;
|
|
1176
|
+
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
|
1230
1177
|
if (maxRemoveableCollateralUsdAfterMinRequired.lt(maxRemovableCollateralUsd)) {
|
|
1231
|
-
maxWithdrawableAmount =
|
|
1178
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemoveableCollateralUsdAfterMinRequired, collateralCustodyAccount.decimals);
|
|
1179
|
+
maxWithdrawableAmountUsd = maxRemoveableCollateralUsdAfterMinRequired;
|
|
1232
1180
|
}
|
|
1233
1181
|
else {
|
|
1234
|
-
maxWithdrawableAmount =
|
|
1182
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
|
1183
|
+
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
|
1235
1184
|
}
|
|
1236
|
-
return maxWithdrawableAmount;
|
|
1185
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd };
|
|
1237
1186
|
};
|
|
1238
1187
|
this.getCumulativeLockFeeSync = function (custodyAccount, currentTimestamp) {
|
|
1239
1188
|
var cumulativeLockFee = constants_1.BN_ZERO;
|
|
@@ -1287,185 +1236,138 @@ var PerpetualsClient = (function () {
|
|
|
1287
1236
|
var lockedUsd = (sideUsd.mul(maxPayOffBpsNew)).div(new anchor_1.BN(constants_1.BPS_POWER));
|
|
1288
1237
|
return lockedUsd;
|
|
1289
1238
|
};
|
|
1290
|
-
this.
|
|
1239
|
+
this.getLiquidationPriceContractHelper = function (entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount) {
|
|
1291
1240
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
|
1292
1241
|
price: constants_1.BN_ZERO,
|
|
1293
1242
|
exponent: constants_1.BN_ZERO,
|
|
1294
1243
|
confidence: constants_1.BN_ZERO,
|
|
1295
1244
|
timestamp: constants_1.BN_ZERO
|
|
1296
1245
|
});
|
|
1297
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
|
1298
|
-
return zeroOraclePrice;
|
|
1299
|
-
}
|
|
1300
1246
|
if (positionAccount.entryPrice.exponent && !entryOraclePrice.exponent.eq(new anchor_1.BN(positionAccount.entryPrice.exponent))) {
|
|
1301
1247
|
throw new Error("Exponent mismatch : ".concat(positionAccount.entryPrice.exponent, " & ").concat(entryOraclePrice.exponent.toString(), " ").concat(entryOraclePrice === null || entryOraclePrice === void 0 ? void 0 : entryOraclePrice.toUiPrice(8)));
|
|
1302
1248
|
}
|
|
1303
1249
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1304
1250
|
var unsettledLossUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
|
|
1305
1251
|
var liablitiesUsd = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
|
1306
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
|
1307
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1308
1252
|
var liquidationPrice;
|
|
1309
|
-
if (
|
|
1310
|
-
var
|
|
1311
|
-
|
|
1312
|
-
|
|
1253
|
+
if (positionAccount.collateralUsd.gte(liablitiesUsd)) {
|
|
1254
|
+
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
|
1255
|
+
price: (positionAccount.collateralUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
|
1256
|
+
.div(positionAccount.sizeAmount),
|
|
1257
|
+
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1258
|
+
confidence: constants_1.BN_ZERO,
|
|
1259
|
+
timestamp: constants_1.BN_ZERO
|
|
1260
|
+
}).scale_to_exponent(new anchor_1.BN(entryOraclePrice.exponent));
|
|
1261
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1262
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1263
|
+
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
|
1264
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1265
|
+
confidence: constants_1.BN_ZERO,
|
|
1266
|
+
timestamp: constants_1.BN_ZERO
|
|
1267
|
+
});
|
|
1313
1268
|
}
|
|
1314
1269
|
else {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1270
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1271
|
+
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
|
1272
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1273
|
+
confidence: constants_1.BN_ZERO,
|
|
1274
|
+
timestamp: constants_1.BN_ZERO
|
|
1275
|
+
});
|
|
1318
1276
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1277
|
+
}
|
|
1278
|
+
else {
|
|
1279
|
+
var priceDiffProfitOracle = OraclePrice_1.OraclePrice.from({
|
|
1280
|
+
price: (liablitiesUsd.sub(positionAccount.collateralUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
|
1281
|
+
.div(positionAccount.sizeAmount),
|
|
1322
1282
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1323
1283
|
confidence: constants_1.BN_ZERO,
|
|
1324
1284
|
timestamp: constants_1.BN_ZERO
|
|
1325
|
-
});
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
|
1331
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
|
1332
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
|
1333
|
-
.div(positionAccount.sizeAmount),
|
|
1334
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1285
|
+
}).scale_to_exponent(new anchor_1.BN(entryOraclePrice.exponent));
|
|
1286
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1287
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1288
|
+
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
|
1289
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1335
1290
|
confidence: constants_1.BN_ZERO,
|
|
1336
1291
|
timestamp: constants_1.BN_ZERO
|
|
1337
|
-
})
|
|
1338
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1339
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1340
|
-
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
|
1341
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1342
|
-
confidence: constants_1.BN_ZERO,
|
|
1343
|
-
timestamp: constants_1.BN_ZERO
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
else {
|
|
1347
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1348
|
-
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
|
1349
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1350
|
-
confidence: constants_1.BN_ZERO,
|
|
1351
|
-
timestamp: constants_1.BN_ZERO
|
|
1352
|
-
});
|
|
1353
|
-
}
|
|
1292
|
+
});
|
|
1354
1293
|
}
|
|
1355
1294
|
else {
|
|
1356
|
-
|
|
1357
|
-
price:
|
|
1358
|
-
|
|
1359
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1295
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1296
|
+
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
|
1297
|
+
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1360
1298
|
confidence: constants_1.BN_ZERO,
|
|
1361
1299
|
timestamp: constants_1.BN_ZERO
|
|
1362
|
-
})
|
|
1363
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1364
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1365
|
-
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
|
1366
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1367
|
-
confidence: constants_1.BN_ZERO,
|
|
1368
|
-
timestamp: constants_1.BN_ZERO
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
else {
|
|
1372
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1373
|
-
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
|
1374
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1375
|
-
confidence: constants_1.BN_ZERO,
|
|
1376
|
-
timestamp: constants_1.BN_ZERO
|
|
1377
|
-
});
|
|
1378
|
-
}
|
|
1300
|
+
});
|
|
1379
1301
|
}
|
|
1380
1302
|
}
|
|
1381
1303
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
|
1382
1304
|
};
|
|
1383
|
-
this.
|
|
1305
|
+
this.getLiquidationPriceSync = function (collateralUsd, sizeAmount, entryOraclePrice, lockAndUnsettledFeeUsd, side, targetPrice, targetCustodyAccount, positionAccount) {
|
|
1306
|
+
var newPositionAccount = positionAccount.clone();
|
|
1307
|
+
newPositionAccount.sizeAmount = sizeAmount;
|
|
1308
|
+
newPositionAccount.sizeUsd = targetPrice.getAssetAmountUsd(sizeAmount, targetCustodyAccount.decimals);
|
|
1309
|
+
newPositionAccount.collateralUsd = collateralUsd;
|
|
1310
|
+
return _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, newPositionAccount);
|
|
1311
|
+
};
|
|
1312
|
+
this.getLiquidationPriceWithOrder = function (collateralUsd, sizeAmount, sizeUsd, sizeDecimals, limitOraclePrice, side, targetCustodyAccount) {
|
|
1384
1313
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
|
1385
1314
|
price: constants_1.BN_ZERO,
|
|
1386
1315
|
exponent: constants_1.BN_ZERO,
|
|
1387
1316
|
confidence: constants_1.BN_ZERO,
|
|
1388
1317
|
timestamp: constants_1.BN_ZERO
|
|
1389
1318
|
});
|
|
1390
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
|
1391
|
-
return zeroOraclePrice;
|
|
1392
|
-
}
|
|
1393
1319
|
var exitFeeUsd = sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1394
1320
|
var unsettledLossUsd = exitFeeUsd;
|
|
1395
1321
|
var liablitiesUsd = sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
|
1396
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
|
1397
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1398
1322
|
var liquidationPrice;
|
|
1399
|
-
if (
|
|
1400
|
-
var
|
|
1401
|
-
|
|
1402
|
-
|
|
1323
|
+
if (collateralUsd.gte(liablitiesUsd)) {
|
|
1324
|
+
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
|
1325
|
+
price: (collateralUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
|
1326
|
+
.div(sizeAmount),
|
|
1327
|
+
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1328
|
+
confidence: constants_1.BN_ZERO,
|
|
1329
|
+
timestamp: constants_1.BN_ZERO
|
|
1330
|
+
}).scale_to_exponent(new anchor_1.BN(limitOraclePrice.exponent));
|
|
1331
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1332
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1333
|
+
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
|
1334
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1335
|
+
confidence: constants_1.BN_ZERO,
|
|
1336
|
+
timestamp: constants_1.BN_ZERO
|
|
1337
|
+
});
|
|
1403
1338
|
}
|
|
1404
1339
|
else {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1340
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1341
|
+
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
|
1342
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1343
|
+
confidence: constants_1.BN_ZERO,
|
|
1344
|
+
timestamp: constants_1.BN_ZERO
|
|
1345
|
+
});
|
|
1408
1346
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1347
|
+
}
|
|
1348
|
+
else {
|
|
1349
|
+
var priceDiffProfitOracle = OraclePrice_1.OraclePrice.from({
|
|
1350
|
+
price: (liablitiesUsd.sub(collateralUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
|
1351
|
+
.div(sizeAmount),
|
|
1412
1352
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1413
1353
|
confidence: constants_1.BN_ZERO,
|
|
1414
1354
|
timestamp: constants_1.BN_ZERO
|
|
1415
|
-
});
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
|
1421
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
|
1422
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
|
1423
|
-
.div(sizeAmount),
|
|
1424
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1355
|
+
}).scale_to_exponent(new anchor_1.BN(limitOraclePrice.exponent));
|
|
1356
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1357
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1358
|
+
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
|
1359
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1425
1360
|
confidence: constants_1.BN_ZERO,
|
|
1426
1361
|
timestamp: constants_1.BN_ZERO
|
|
1427
|
-
})
|
|
1428
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1429
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1430
|
-
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
|
1431
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1432
|
-
confidence: constants_1.BN_ZERO,
|
|
1433
|
-
timestamp: constants_1.BN_ZERO
|
|
1434
|
-
});
|
|
1435
|
-
}
|
|
1436
|
-
else {
|
|
1437
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1438
|
-
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
|
1439
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1440
|
-
confidence: constants_1.BN_ZERO,
|
|
1441
|
-
timestamp: constants_1.BN_ZERO
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1362
|
+
});
|
|
1444
1363
|
}
|
|
1445
1364
|
else {
|
|
1446
|
-
|
|
1447
|
-
price:
|
|
1448
|
-
|
|
1449
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1365
|
+
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1366
|
+
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
|
1367
|
+
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1450
1368
|
confidence: constants_1.BN_ZERO,
|
|
1451
1369
|
timestamp: constants_1.BN_ZERO
|
|
1452
|
-
})
|
|
1453
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1454
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1455
|
-
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
|
1456
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1457
|
-
confidence: constants_1.BN_ZERO,
|
|
1458
|
-
timestamp: constants_1.BN_ZERO
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
else {
|
|
1462
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1463
|
-
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
|
1464
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1465
|
-
confidence: constants_1.BN_ZERO,
|
|
1466
|
-
timestamp: constants_1.BN_ZERO
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1370
|
+
});
|
|
1469
1371
|
}
|
|
1470
1372
|
}
|
|
1471
1373
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
|
@@ -1541,8 +1443,8 @@ var PerpetualsClient = (function () {
|
|
|
1541
1443
|
positionAccount.market = marketAccountPk;
|
|
1542
1444
|
positionAccount.lockedUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
|
|
1543
1445
|
positionAccount.lockedAmount = collateralPrice.getTokenAmount(positionAccount.lockedUsd, collateralCustodyAccount.decimals);
|
|
1544
|
-
|
|
1545
|
-
positionAccount.collateralUsd =
|
|
1446
|
+
var collateralDeltaUsd = collateralPrice.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
|
1447
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
|
1546
1448
|
var currentTime = new anchor_1.BN((0, utils_1.getUnixTs)());
|
|
1547
1449
|
var pnl = _this.getPnlSync(positionAccount, userEntrytpSlOraclePrice, userEntrytpSlOraclePrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTime, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1548
1450
|
var pnlUsd = pnl.profitUsd.sub(pnl.lossUsd);
|
|
@@ -1614,6 +1516,9 @@ var PerpetualsClient = (function () {
|
|
|
1614
1516
|
});
|
|
1615
1517
|
};
|
|
1616
1518
|
this.getPnlSync = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig) {
|
|
1519
|
+
return _this.getPnlContractHelper(positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig);
|
|
1520
|
+
};
|
|
1521
|
+
this.getPnlContractHelper = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, delay, poolConfig) {
|
|
1617
1522
|
if (positionAccount.sizeUsd.isZero() || positionAccount.entryPrice.price.isZero()) {
|
|
1618
1523
|
return {
|
|
1619
1524
|
profitUsd: constants_1.BN_ZERO,
|
|
@@ -1672,7 +1577,7 @@ var PerpetualsClient = (function () {
|
|
|
1672
1577
|
}
|
|
1673
1578
|
if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
|
|
1674
1579
|
return {
|
|
1675
|
-
profitUsd:
|
|
1580
|
+
profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
|
|
1676
1581
|
lossUsd: constants_1.BN_ZERO,
|
|
1677
1582
|
};
|
|
1678
1583
|
}
|
|
@@ -1763,6 +1668,9 @@ var PerpetualsClient = (function () {
|
|
|
1763
1668
|
}
|
|
1764
1669
|
};
|
|
1765
1670
|
this.getAssetsUnderManagementUsdSync = function (poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig) {
|
|
1671
|
+
return _this.getAssetsUnderManagementUsdContractHelper(poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig);
|
|
1672
|
+
};
|
|
1673
|
+
this.getAssetsUnderManagementUsdContractHelper = function (poolAccount, tokenPrices, tokenEmaPrices, custodies, markets, aumCalcMode, currentTime, poolConfig) {
|
|
1766
1674
|
var poolAmountUsd = constants_1.BN_ZERO;
|
|
1767
1675
|
for (var index = 0; index < custodies.length; index++) {
|
|
1768
1676
|
if (custodies.length != poolAccount.custodies.length || !custodies[index].publicKey.equals(poolAccount.custodies[index])) {
|
|
@@ -1775,6 +1683,7 @@ var PerpetualsClient = (function () {
|
|
|
1775
1683
|
var token_amount_usd = tokenMinMaxPrice.max.getAssetAmountUsd(custodies[index].assets.owned, custodies[index].decimals);
|
|
1776
1684
|
poolAmountUsd = poolAmountUsd.add(token_amount_usd);
|
|
1777
1685
|
}
|
|
1686
|
+
poolAmountUsd = poolAmountUsd.sub(poolAccount.feesObligationUsd.add(poolAccount.rebateObligationUsd));
|
|
1778
1687
|
if (aumCalcMode === "includePnl") {
|
|
1779
1688
|
var poolEquityUsd = poolAmountUsd;
|
|
1780
1689
|
for (var index = 0; index < markets.length; index++) {
|
|
@@ -1784,11 +1693,12 @@ var PerpetualsClient = (function () {
|
|
|
1784
1693
|
var targetCustodyId = poolAccount.getCustodyId(markets[index].targetCustody);
|
|
1785
1694
|
var collateralCustodyId = poolAccount.getCustodyId(markets[index].collateralCustody);
|
|
1786
1695
|
var position = markets[index].getCollectivePosition();
|
|
1696
|
+
poolEquityUsd = poolEquityUsd.sub(position.collateralUsd);
|
|
1787
1697
|
var collectivePnl = _this.getPnlSync(position, tokenPrices[targetCustodyId], tokenEmaPrices[targetCustodyId], custodies[targetCustodyId], tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId], currentTime, custodies[targetCustodyId].pricing.delaySeconds, poolConfig);
|
|
1788
1698
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId]);
|
|
1789
|
-
var
|
|
1790
|
-
var
|
|
1791
|
-
poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(
|
|
1699
|
+
var collectiveLossUsd = anchor_1.BN.min(collectivePnl.lossUsd, position.collateralUsd);
|
|
1700
|
+
var collectiveProfitUsd = anchor_1.BN.min(collectivePnl.profitUsd, collateralMinMaxPrice.max.getAssetAmountUsd(position.lockedAmount, custodies[collateralCustodyId].decimals).sub(position.collateralUsd));
|
|
1701
|
+
poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(collectiveProfitUsd);
|
|
1792
1702
|
}
|
|
1793
1703
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: poolEquityUsd };
|
|
1794
1704
|
}
|
|
@@ -1796,14 +1706,6 @@ var PerpetualsClient = (function () {
|
|
|
1796
1706
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: constants_1.BN_ZERO };
|
|
1797
1707
|
}
|
|
1798
1708
|
};
|
|
1799
|
-
this.getNftFinalDiscount = function (perpetualsAccount, nftTradingAccount, currentTime) {
|
|
1800
|
-
if (currentTime.sub(nftTradingAccount.timestamp).lt(constants_1.DAY_SECONDS) && nftTradingAccount.counter.gt(new anchor_1.BN(perpetualsAccount.tradeLimit))) {
|
|
1801
|
-
return { discountBn: constants_1.BN_ZERO };
|
|
1802
|
-
}
|
|
1803
|
-
else {
|
|
1804
|
-
return { discountBn: perpetualsAccount.tradingDiscount[nftTradingAccount.level - 1] };
|
|
1805
|
-
}
|
|
1806
|
-
};
|
|
1807
1709
|
this.getFeeDiscount = function (perpetualsAccount, tokenStakeAccount, currentTime) {
|
|
1808
1710
|
if (tokenStakeAccount.level === 0) {
|
|
1809
1711
|
return { discountBn: constants_1.BN_ZERO };
|
|
@@ -1888,7 +1790,7 @@ var PerpetualsClient = (function () {
|
|
|
1888
1790
|
});
|
|
1889
1791
|
};
|
|
1890
1792
|
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
|
1891
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
|
|
1793
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
|
|
1892
1794
|
var _d;
|
|
1893
1795
|
return __generator(this, function (_e) {
|
|
1894
1796
|
switch (_e.label) {
|
|
@@ -1936,6 +1838,8 @@ var PerpetualsClient = (function () {
|
|
|
1936
1838
|
return [4, backUpOracleInstructionPromise];
|
|
1937
1839
|
case 2:
|
|
1938
1840
|
backUpOracleInstruction = _e.sent();
|
|
1841
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
1842
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
1939
1843
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
|
1940
1844
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
|
1941
1845
|
case 3:
|
|
@@ -2002,7 +1906,7 @@ var PerpetualsClient = (function () {
|
|
|
2002
1906
|
args_1[_i - 4] = arguments[_i];
|
|
2003
1907
|
}
|
|
2004
1908
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2005
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
|
1909
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2006
1910
|
var _e;
|
|
2007
1911
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2008
1912
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2053,6 +1957,8 @@ var PerpetualsClient = (function () {
|
|
|
2053
1957
|
.transaction()];
|
|
2054
1958
|
case 1:
|
|
2055
1959
|
transaction = _f.sent();
|
|
1960
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
1961
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2056
1962
|
if (!enableBackupOracle) return [3, 3];
|
|
2057
1963
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2058
1964
|
case 2:
|
|
@@ -2078,7 +1984,7 @@ var PerpetualsClient = (function () {
|
|
|
2078
1984
|
args_1[_i - 4] = arguments[_i];
|
|
2079
1985
|
}
|
|
2080
1986
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2081
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
|
1987
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2082
1988
|
var _e;
|
|
2083
1989
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2084
1990
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2129,6 +2035,8 @@ var PerpetualsClient = (function () {
|
|
|
2129
2035
|
.transaction()];
|
|
2130
2036
|
case 1:
|
|
2131
2037
|
transaction = _f.sent();
|
|
2038
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2039
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2132
2040
|
if (!enableBackupOracle) return [3, 3];
|
|
2133
2041
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2134
2042
|
case 2:
|
|
@@ -2155,7 +2063,7 @@ var PerpetualsClient = (function () {
|
|
|
2155
2063
|
});
|
|
2156
2064
|
};
|
|
2157
2065
|
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
|
2158
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
|
|
2066
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
|
|
2159
2067
|
var _d;
|
|
2160
2068
|
return __generator(this, function (_e) {
|
|
2161
2069
|
switch (_e.label) {
|
|
@@ -2203,6 +2111,8 @@ var PerpetualsClient = (function () {
|
|
|
2203
2111
|
.transaction()];
|
|
2204
2112
|
case 2:
|
|
2205
2113
|
transaction = _e.sent();
|
|
2114
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2115
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2206
2116
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
|
2207
2117
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
|
2208
2118
|
case 3:
|
|
@@ -2219,7 +2129,7 @@ var PerpetualsClient = (function () {
|
|
|
2219
2129
|
args_1[_i - 4] = arguments[_i];
|
|
2220
2130
|
}
|
|
2221
2131
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2222
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
|
2132
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2223
2133
|
var _e;
|
|
2224
2134
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2225
2135
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2274,6 +2184,8 @@ var PerpetualsClient = (function () {
|
|
|
2274
2184
|
.transaction()];
|
|
2275
2185
|
case 1:
|
|
2276
2186
|
transaction = _f.sent();
|
|
2187
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2188
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2277
2189
|
if (!enableBackupOracle) return [3, 3];
|
|
2278
2190
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2279
2191
|
case 2:
|
|
@@ -2299,7 +2211,7 @@ var PerpetualsClient = (function () {
|
|
|
2299
2211
|
args_1[_i - 4] = arguments[_i];
|
|
2300
2212
|
}
|
|
2301
2213
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2302
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
|
2214
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2303
2215
|
var _e;
|
|
2304
2216
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2305
2217
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2354,6 +2266,8 @@ var PerpetualsClient = (function () {
|
|
|
2354
2266
|
.transaction()];
|
|
2355
2267
|
case 1:
|
|
2356
2268
|
transaction = _f.sent();
|
|
2269
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2270
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2357
2271
|
if (!enableBackupOracle) return [3, 3];
|
|
2358
2272
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2359
2273
|
case 2:
|
|
@@ -2548,11 +2462,10 @@ var PerpetualsClient = (function () {
|
|
|
2548
2462
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
2549
2463
|
args_1[_i - 8] = arguments[_i];
|
|
2550
2464
|
}
|
|
2551
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount,
|
|
2465
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
2552
2466
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
|
2553
2467
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2554
2468
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2555
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2556
2469
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
2557
2470
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2558
2471
|
return __generator(this, function (_c) {
|
|
@@ -2645,7 +2558,7 @@ var PerpetualsClient = (function () {
|
|
|
2645
2558
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2646
2559
|
fundingMint: collateralCustodyConfig.mintKey
|
|
2647
2560
|
})
|
|
2648
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2561
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2649
2562
|
.instruction()];
|
|
2650
2563
|
case 7:
|
|
2651
2564
|
instruction = _c.sent();
|
|
@@ -2663,11 +2576,10 @@ var PerpetualsClient = (function () {
|
|
|
2663
2576
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
2664
2577
|
args_1[_i - 6] = arguments[_i];
|
|
2665
2578
|
}
|
|
2666
|
-
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount,
|
|
2579
|
+
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
|
2667
2580
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
|
2668
2581
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2669
2582
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2670
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2671
2583
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
2672
2584
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
2673
2585
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
@@ -2746,7 +2658,7 @@ var PerpetualsClient = (function () {
|
|
|
2746
2658
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
2747
2659
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
2748
2660
|
})
|
|
2749
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2661
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2750
2662
|
.instruction()];
|
|
2751
2663
|
case 6:
|
|
2752
2664
|
instruction = _b.sent();
|
|
@@ -2773,11 +2685,10 @@ var PerpetualsClient = (function () {
|
|
|
2773
2685
|
for (var _i = 9; _i < arguments.length; _i++) {
|
|
2774
2686
|
args_1[_i - 9] = arguments[_i];
|
|
2775
2687
|
}
|
|
2776
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount,
|
|
2688
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
2777
2689
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_3;
|
|
2778
2690
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2779
2691
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2780
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2781
2692
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
2782
2693
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2783
2694
|
return __generator(this, function (_c) {
|
|
@@ -2912,7 +2823,7 @@ var PerpetualsClient = (function () {
|
|
|
2912
2823
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
2913
2824
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
2914
2825
|
})
|
|
2915
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2826
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2916
2827
|
.instruction()];
|
|
2917
2828
|
case 12:
|
|
2918
2829
|
inx = _c.sent();
|
|
@@ -2930,16 +2841,15 @@ var PerpetualsClient = (function () {
|
|
|
2930
2841
|
});
|
|
2931
2842
|
});
|
|
2932
2843
|
};
|
|
2933
|
-
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
|
2844
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
|
2934
2845
|
var args_1 = [];
|
|
2935
|
-
for (var _i =
|
|
2936
|
-
args_1[_i -
|
|
2846
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
|
2847
|
+
args_1[_i - 7] = arguments[_i];
|
|
2937
2848
|
}
|
|
2938
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
|
2939
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount,
|
|
2849
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey) {
|
|
2850
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, inx, err_4;
|
|
2940
2851
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2941
2852
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2942
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2943
2853
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2944
2854
|
return __generator(this, function (_a) {
|
|
2945
2855
|
switch (_a.label) {
|
|
@@ -3005,18 +2915,12 @@ var PerpetualsClient = (function () {
|
|
|
3005
2915
|
if (!(_a.sent())) {
|
|
3006
2916
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3007
2917
|
}
|
|
3008
|
-
rebateMintAccount = {
|
|
3009
|
-
pubkey: collateralCustodyConfig.mintKey,
|
|
3010
|
-
isSigner: false,
|
|
3011
|
-
isWritable: false
|
|
3012
|
-
};
|
|
3013
2918
|
_a.label = 5;
|
|
3014
2919
|
case 5:
|
|
3015
2920
|
_a.trys.push([5, 7, , 8]);
|
|
3016
2921
|
return [4, this.program.methods
|
|
3017
2922
|
.closeAndSwap({
|
|
3018
2923
|
priceWithSlippage: priceWithSlippage,
|
|
3019
|
-
minSwapAmountOut: minSwapAmountOut,
|
|
3020
2924
|
privilege: privilege
|
|
3021
2925
|
})
|
|
3022
2926
|
.accounts({
|
|
@@ -3045,7 +2949,7 @@ var PerpetualsClient = (function () {
|
|
|
3045
2949
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
3046
2950
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
3047
2951
|
})
|
|
3048
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2952
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3049
2953
|
.instruction()];
|
|
3050
2954
|
case 6:
|
|
3051
2955
|
inx = _a.sent();
|
|
@@ -3503,11 +3407,10 @@ var PerpetualsClient = (function () {
|
|
|
3503
3407
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3504
3408
|
args_1[_i - 8] = arguments[_i];
|
|
3505
3409
|
}
|
|
3506
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount
|
|
3410
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
|
3507
3411
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3508
3412
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3509
3413
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3510
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
3511
3414
|
return __generator(this, function (_a) {
|
|
3512
3415
|
switch (_a.label) {
|
|
3513
3416
|
case 0:
|
|
@@ -3550,7 +3453,7 @@ var PerpetualsClient = (function () {
|
|
|
3550
3453
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3551
3454
|
collateralMint: collateralCustodyConfig.mintKey
|
|
3552
3455
|
})
|
|
3553
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
3456
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3554
3457
|
.instruction()];
|
|
3555
3458
|
case 1:
|
|
3556
3459
|
instruction = _a.sent();
|
|
@@ -3568,11 +3471,10 @@ var PerpetualsClient = (function () {
|
|
|
3568
3471
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3569
3472
|
args_1[_i - 8] = arguments[_i];
|
|
3570
3473
|
}
|
|
3571
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount
|
|
3474
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
|
3572
3475
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3573
3476
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3574
3477
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3575
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
3576
3478
|
return __generator(this, function (_a) {
|
|
3577
3479
|
switch (_a.label) {
|
|
3578
3480
|
case 0:
|
|
@@ -3615,7 +3517,7 @@ var PerpetualsClient = (function () {
|
|
|
3615
3517
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3616
3518
|
collateralMint: collateralCustodyConfig.mintKey
|
|
3617
3519
|
})
|
|
3618
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
3520
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3619
3521
|
.instruction()];
|
|
3620
3522
|
case 1:
|
|
3621
3523
|
instruction = _a.sent();
|
|
@@ -4082,119 +3984,8 @@ var PerpetualsClient = (function () {
|
|
|
4082
3984
|
}
|
|
4083
3985
|
});
|
|
4084
3986
|
}); };
|
|
4085
|
-
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
4086
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
|
4087
|
-
return __generator(this, function (_a) {
|
|
4088
|
-
switch (_a.label) {
|
|
4089
|
-
case 0:
|
|
4090
|
-
publicKey = this.provider.wallet.publicKey;
|
|
4091
|
-
preInstructions = [];
|
|
4092
|
-
instructions = [];
|
|
4093
|
-
postInstructions = [];
|
|
4094
|
-
additionalSigners = [];
|
|
4095
|
-
_a.label = 1;
|
|
4096
|
-
case 1:
|
|
4097
|
-
_a.trys.push([1, 4, , 5]);
|
|
4098
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
4099
|
-
Buffer.from("trading"),
|
|
4100
|
-
nftMint.toBuffer(),
|
|
4101
|
-
], this.programId)[0];
|
|
4102
|
-
nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
4103
|
-
Buffer.from("referral"),
|
|
4104
|
-
publicKey.toBuffer(),
|
|
4105
|
-
], this.programId)[0];
|
|
4106
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
|
4107
|
-
case 2:
|
|
4108
|
-
nftTokenAccount = _a.sent();
|
|
4109
|
-
flpStakeAccountMetas = [];
|
|
4110
|
-
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
|
4111
|
-
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
|
4112
|
-
flpStakeAccountMetas.push({
|
|
4113
|
-
pubkey: flpStakeAccountPk,
|
|
4114
|
-
isSigner: false,
|
|
4115
|
-
isWritable: true,
|
|
4116
|
-
});
|
|
4117
|
-
}
|
|
4118
|
-
return [4, this.program.methods
|
|
4119
|
-
.updateTradingAccount({
|
|
4120
|
-
updateReferer: updateReferer,
|
|
4121
|
-
updateBooster: updateBooster
|
|
4122
|
-
})
|
|
4123
|
-
.accounts({
|
|
4124
|
-
owner: publicKey,
|
|
4125
|
-
feePayer: publicKey,
|
|
4126
|
-
nftTokenAccount: nftTokenAccount,
|
|
4127
|
-
referralAccount: nftReferralAccount,
|
|
4128
|
-
tradingAccount: nftTradingAccount
|
|
4129
|
-
})
|
|
4130
|
-
.instruction()];
|
|
4131
|
-
case 3:
|
|
4132
|
-
updateNftTradingAccountInstruction = _a.sent();
|
|
4133
|
-
instructions.push(updateNftTradingAccountInstruction);
|
|
4134
|
-
return [3, 5];
|
|
4135
|
-
case 4:
|
|
4136
|
-
err_8 = _a.sent();
|
|
4137
|
-
console.log("perpClient updateNftAccount error:: ", err_8);
|
|
4138
|
-
throw err_8;
|
|
4139
|
-
case 5: return [2, {
|
|
4140
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4141
|
-
additionalSigners: additionalSigners
|
|
4142
|
-
}];
|
|
4143
|
-
}
|
|
4144
|
-
});
|
|
4145
|
-
}); };
|
|
4146
|
-
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
|
4147
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
|
4148
|
-
return __generator(this, function (_a) {
|
|
4149
|
-
switch (_a.label) {
|
|
4150
|
-
case 0:
|
|
4151
|
-
publicKey = this.provider.wallet.publicKey;
|
|
4152
|
-
preInstructions = [];
|
|
4153
|
-
instructions = [];
|
|
4154
|
-
postInstructions = [];
|
|
4155
|
-
additionalSigners = [];
|
|
4156
|
-
_a.label = 1;
|
|
4157
|
-
case 1:
|
|
4158
|
-
_a.trys.push([1, 3, , 4]);
|
|
4159
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
4160
|
-
Buffer.from("trading"),
|
|
4161
|
-
nftMint.toBuffer(),
|
|
4162
|
-
], this.programId)[0];
|
|
4163
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
4164
|
-
return [4, this.program.methods
|
|
4165
|
-
.levelUp({})
|
|
4166
|
-
.accounts({
|
|
4167
|
-
owner: publicKey,
|
|
4168
|
-
perpetuals: this.perpetuals.publicKey,
|
|
4169
|
-
pool: poolConfig.poolAddress,
|
|
4170
|
-
metadataAccount: metadataAccount,
|
|
4171
|
-
nftMint: nftMint,
|
|
4172
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
|
4173
|
-
tradingAccount: nftTradingAccount,
|
|
4174
|
-
transferAuthority: this.authority.publicKey,
|
|
4175
|
-
authorizationRulesAccount: authorizationRulesAccount,
|
|
4176
|
-
authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
|
|
4177
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
4178
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
4179
|
-
})
|
|
4180
|
-
.instruction()];
|
|
4181
|
-
case 2:
|
|
4182
|
-
levelUpInstruction = _a.sent();
|
|
4183
|
-
instructions.push(levelUpInstruction);
|
|
4184
|
-
return [3, 4];
|
|
4185
|
-
case 3:
|
|
4186
|
-
err_9 = _a.sent();
|
|
4187
|
-
console.log("perpClient levelUp error:: ", err_9);
|
|
4188
|
-
throw err_9;
|
|
4189
|
-
case 4: return [2, {
|
|
4190
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4191
|
-
additionalSigners: additionalSigners
|
|
4192
|
-
}];
|
|
4193
|
-
}
|
|
4194
|
-
});
|
|
4195
|
-
}); };
|
|
4196
3987
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
4197
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
|
3988
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
|
|
4198
3989
|
return __generator(this, function (_a) {
|
|
4199
3990
|
switch (_a.label) {
|
|
4200
3991
|
case 0:
|
|
@@ -4236,9 +4027,9 @@ var PerpetualsClient = (function () {
|
|
|
4236
4027
|
instructions.push(depositStakeInstruction);
|
|
4237
4028
|
return [3, 5];
|
|
4238
4029
|
case 4:
|
|
4239
|
-
|
|
4240
|
-
console.log("perpClient depositStaking error:: ",
|
|
4241
|
-
throw
|
|
4030
|
+
err_8 = _a.sent();
|
|
4031
|
+
console.log("perpClient depositStaking error:: ", err_8);
|
|
4032
|
+
throw err_8;
|
|
4242
4033
|
case 5: return [2, {
|
|
4243
4034
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4244
4035
|
additionalSigners: additionalSigners
|
|
@@ -4247,7 +4038,7 @@ var PerpetualsClient = (function () {
|
|
|
4247
4038
|
});
|
|
4248
4039
|
}); };
|
|
4249
4040
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
|
4250
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
|
4041
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
|
|
4251
4042
|
return __generator(this, function (_c) {
|
|
4252
4043
|
switch (_c.label) {
|
|
4253
4044
|
case 0:
|
|
@@ -4294,9 +4085,9 @@ var PerpetualsClient = (function () {
|
|
|
4294
4085
|
refreshStakeInstruction = _c.sent();
|
|
4295
4086
|
return [2, refreshStakeInstruction];
|
|
4296
4087
|
case 2:
|
|
4297
|
-
|
|
4298
|
-
console.log("perpClient refreshStaking error:: ",
|
|
4299
|
-
throw
|
|
4088
|
+
err_9 = _c.sent();
|
|
4089
|
+
console.log("perpClient refreshStaking error:: ", err_9);
|
|
4090
|
+
throw err_9;
|
|
4300
4091
|
case 3: return [2];
|
|
4301
4092
|
}
|
|
4302
4093
|
});
|
|
@@ -4307,7 +4098,7 @@ var PerpetualsClient = (function () {
|
|
|
4307
4098
|
args_1[_i - 3] = arguments[_i];
|
|
4308
4099
|
}
|
|
4309
4100
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
|
4310
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
|
4101
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
|
|
4311
4102
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4312
4103
|
return __generator(this, function (_c) {
|
|
4313
4104
|
switch (_c.label) {
|
|
@@ -4355,9 +4146,9 @@ var PerpetualsClient = (function () {
|
|
|
4355
4146
|
refreshStakeInstruction = _c.sent();
|
|
4356
4147
|
return [2, refreshStakeInstruction];
|
|
4357
4148
|
case 2:
|
|
4358
|
-
|
|
4359
|
-
console.log("perpClient refreshStaking error:: ",
|
|
4360
|
-
throw
|
|
4149
|
+
err_10 = _c.sent();
|
|
4150
|
+
console.log("perpClient refreshStaking error:: ", err_10);
|
|
4151
|
+
throw err_10;
|
|
4361
4152
|
case 3: return [2];
|
|
4362
4153
|
}
|
|
4363
4154
|
});
|
|
@@ -4369,7 +4160,7 @@ var PerpetualsClient = (function () {
|
|
|
4369
4160
|
args_1[_i - 3] = arguments[_i];
|
|
4370
4161
|
}
|
|
4371
4162
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
|
4372
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
|
4163
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
|
|
4373
4164
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4374
4165
|
return __generator(this, function (_b) {
|
|
4375
4166
|
switch (_b.label) {
|
|
@@ -4421,9 +4212,9 @@ var PerpetualsClient = (function () {
|
|
|
4421
4212
|
instructions.push(unstakeInstantInstruction);
|
|
4422
4213
|
return [3, 6];
|
|
4423
4214
|
case 5:
|
|
4424
|
-
|
|
4425
|
-
console.log("perpClient unstakeInstant error:: ",
|
|
4426
|
-
throw
|
|
4215
|
+
err_11 = _b.sent();
|
|
4216
|
+
console.log("perpClient unstakeInstant error:: ", err_11);
|
|
4217
|
+
throw err_11;
|
|
4427
4218
|
case 6: return [2, {
|
|
4428
4219
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4429
4220
|
additionalSigners: additionalSigners
|
|
@@ -4433,7 +4224,7 @@ var PerpetualsClient = (function () {
|
|
|
4433
4224
|
});
|
|
4434
4225
|
};
|
|
4435
4226
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
|
4436
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
|
4227
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
|
4437
4228
|
return __generator(this, function (_c) {
|
|
4438
4229
|
switch (_c.label) {
|
|
4439
4230
|
case 0:
|
|
@@ -4477,15 +4268,15 @@ var PerpetualsClient = (function () {
|
|
|
4477
4268
|
refreshStakeInstruction = _c.sent();
|
|
4478
4269
|
return [2, refreshStakeInstruction];
|
|
4479
4270
|
case 2:
|
|
4480
|
-
|
|
4481
|
-
console.log("perpClient refreshStaking error:: ",
|
|
4482
|
-
throw
|
|
4271
|
+
err_12 = _c.sent();
|
|
4272
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
|
4273
|
+
throw err_12;
|
|
4483
4274
|
case 3: return [2];
|
|
4484
4275
|
}
|
|
4485
4276
|
});
|
|
4486
4277
|
}); };
|
|
4487
4278
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
4488
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
|
4279
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
|
4489
4280
|
return __generator(this, function (_a) {
|
|
4490
4281
|
switch (_a.label) {
|
|
4491
4282
|
case 0:
|
|
@@ -4519,9 +4310,9 @@ var PerpetualsClient = (function () {
|
|
|
4519
4310
|
instructions.push(unstakeRequestInstruction);
|
|
4520
4311
|
return [3, 4];
|
|
4521
4312
|
case 3:
|
|
4522
|
-
|
|
4523
|
-
console.log("perpClient unstakeRequest error:: ",
|
|
4524
|
-
throw
|
|
4313
|
+
err_13 = _a.sent();
|
|
4314
|
+
console.log("perpClient unstakeRequest error:: ", err_13);
|
|
4315
|
+
throw err_13;
|
|
4525
4316
|
case 4: return [2, {
|
|
4526
4317
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4527
4318
|
additionalSigners: additionalSigners
|
|
@@ -4535,7 +4326,7 @@ var PerpetualsClient = (function () {
|
|
|
4535
4326
|
args_1[_i - 1] = arguments[_i];
|
|
4536
4327
|
}
|
|
4537
4328
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
|
4538
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
|
4329
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
|
|
4539
4330
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
|
4540
4331
|
if (deactivated === void 0) { deactivated = true; }
|
|
4541
4332
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
|
@@ -4591,9 +4382,9 @@ var PerpetualsClient = (function () {
|
|
|
4591
4382
|
instructions.push(withdrawStakeInstruction);
|
|
4592
4383
|
return [3, 6];
|
|
4593
4384
|
case 5:
|
|
4594
|
-
|
|
4595
|
-
console.log("perpClient withdrawStake error:: ",
|
|
4596
|
-
throw
|
|
4385
|
+
err_14 = _b.sent();
|
|
4386
|
+
console.log("perpClient withdrawStake error:: ", err_14);
|
|
4387
|
+
throw err_14;
|
|
4597
4388
|
case 6: return [2, {
|
|
4598
4389
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4599
4390
|
additionalSigners: additionalSigners
|
|
@@ -4608,7 +4399,7 @@ var PerpetualsClient = (function () {
|
|
|
4608
4399
|
args_1[_i - 3] = arguments[_i];
|
|
4609
4400
|
}
|
|
4610
4401
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
|
4611
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
|
4402
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
|
4612
4403
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4613
4404
|
return __generator(this, function (_b) {
|
|
4614
4405
|
switch (_b.label) {
|
|
@@ -4669,9 +4460,9 @@ var PerpetualsClient = (function () {
|
|
|
4669
4460
|
instructions.push(withdrawStakeInstruction);
|
|
4670
4461
|
return [3, 6];
|
|
4671
4462
|
case 5:
|
|
4672
|
-
|
|
4673
|
-
console.log("perpClient withdrawStake error:: ",
|
|
4674
|
-
throw
|
|
4463
|
+
err_15 = _b.sent();
|
|
4464
|
+
console.log("perpClient withdrawStake error:: ", err_15);
|
|
4465
|
+
throw err_15;
|
|
4675
4466
|
case 6: return [2, {
|
|
4676
4467
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4677
4468
|
additionalSigners: additionalSigners
|
|
@@ -4686,7 +4477,7 @@ var PerpetualsClient = (function () {
|
|
|
4686
4477
|
args_1[_i - 5] = arguments[_i];
|
|
4687
4478
|
}
|
|
4688
4479
|
return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
|
4689
|
-
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity,
|
|
4480
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_16;
|
|
4690
4481
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
4691
4482
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4692
4483
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
@@ -4814,8 +4605,8 @@ var PerpetualsClient = (function () {
|
|
|
4814
4605
|
instructions.push(addCompoundingLiquidity);
|
|
4815
4606
|
return [3, 10];
|
|
4816
4607
|
case 9:
|
|
4817
|
-
|
|
4818
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
|
4608
|
+
err_16 = _f.sent();
|
|
4609
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
|
4819
4610
|
return [3, 10];
|
|
4820
4611
|
case 10: return [2, {
|
|
4821
4612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -4831,7 +4622,7 @@ var PerpetualsClient = (function () {
|
|
|
4831
4622
|
args_1[_i - 5] = arguments[_i];
|
|
4832
4623
|
}
|
|
4833
4624
|
return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
|
4834
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity,
|
|
4625
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_17;
|
|
4835
4626
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4836
4627
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4837
4628
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
@@ -4943,8 +4734,8 @@ var PerpetualsClient = (function () {
|
|
|
4943
4734
|
instructions.push(removeCompoundingLiquidity);
|
|
4944
4735
|
return [3, 8];
|
|
4945
4736
|
case 7:
|
|
4946
|
-
|
|
4947
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
|
4737
|
+
err_17 = _f.sent();
|
|
4738
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
|
4948
4739
|
return [3, 8];
|
|
4949
4740
|
case 8: return [2, {
|
|
4950
4741
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -4960,7 +4751,7 @@ var PerpetualsClient = (function () {
|
|
|
4960
4751
|
args_1[_i - 3] = arguments[_i];
|
|
4961
4752
|
}
|
|
4962
4753
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
|
4963
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake,
|
|
4754
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_18;
|
|
4964
4755
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4965
4756
|
return __generator(this, function (_g) {
|
|
4966
4757
|
switch (_g.label) {
|
|
@@ -5058,8 +4849,8 @@ var PerpetualsClient = (function () {
|
|
|
5058
4849
|
instructions.push(migrateStake);
|
|
5059
4850
|
return [3, 8];
|
|
5060
4851
|
case 7:
|
|
5061
|
-
|
|
5062
|
-
console.log("perpClient migrateStake error:: ",
|
|
4852
|
+
err_18 = _g.sent();
|
|
4853
|
+
console.log("perpClient migrateStake error:: ", err_18);
|
|
5063
4854
|
return [3, 8];
|
|
5064
4855
|
case 8: return [2, {
|
|
5065
4856
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -5070,7 +4861,7 @@ var PerpetualsClient = (function () {
|
|
|
5070
4861
|
});
|
|
5071
4862
|
};
|
|
5072
4863
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5073
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
|
4864
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
|
|
5074
4865
|
return __generator(this, function (_d) {
|
|
5075
4866
|
switch (_d.label) {
|
|
5076
4867
|
case 0:
|
|
@@ -5142,8 +4933,8 @@ var PerpetualsClient = (function () {
|
|
|
5142
4933
|
instructions.push(migrateFlp);
|
|
5143
4934
|
return [3, 4];
|
|
5144
4935
|
case 3:
|
|
5145
|
-
|
|
5146
|
-
console.log("perpClient migrateFlp error:: ",
|
|
4936
|
+
err_19 = _d.sent();
|
|
4937
|
+
console.log("perpClient migrateFlp error:: ", err_19);
|
|
5147
4938
|
return [3, 4];
|
|
5148
4939
|
case 4: return [2, {
|
|
5149
4940
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -5158,7 +4949,7 @@ var PerpetualsClient = (function () {
|
|
|
5158
4949
|
args_1[_i - 1] = arguments[_i];
|
|
5159
4950
|
}
|
|
5160
4951
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
|
5161
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee,
|
|
4952
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
|
|
5162
4953
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
|
5163
4954
|
return __generator(this, function (_e) {
|
|
5164
4955
|
switch (_e.label) {
|
|
@@ -5216,8 +5007,8 @@ var PerpetualsClient = (function () {
|
|
|
5216
5007
|
instructions.push(compoundingFee);
|
|
5217
5008
|
return [3, 4];
|
|
5218
5009
|
case 3:
|
|
5219
|
-
|
|
5220
|
-
console.log("perpClient compoundingFee error:: ",
|
|
5010
|
+
err_20 = _e.sent();
|
|
5011
|
+
console.log("perpClient compoundingFee error:: ", err_20);
|
|
5221
5012
|
return [3, 4];
|
|
5222
5013
|
case 4: return [2, {
|
|
5223
5014
|
instructions: __spreadArray([], instructions, true),
|
|
@@ -5227,180 +5018,42 @@ var PerpetualsClient = (function () {
|
|
|
5227
5018
|
});
|
|
5228
5019
|
});
|
|
5229
5020
|
};
|
|
5230
|
-
this.
|
|
5231
|
-
var preInstructions, instructions, postInstructions, additionalSigners,
|
|
5232
|
-
return __generator(this, function (
|
|
5233
|
-
switch (
|
|
5021
|
+
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5022
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_21;
|
|
5023
|
+
return __generator(this, function (_a) {
|
|
5024
|
+
switch (_a.label) {
|
|
5234
5025
|
case 0:
|
|
5235
5026
|
preInstructions = [];
|
|
5236
5027
|
instructions = [];
|
|
5237
5028
|
postInstructions = [];
|
|
5238
5029
|
additionalSigners = [];
|
|
5239
|
-
|
|
5030
|
+
_a.label = 1;
|
|
5240
5031
|
case 1:
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
userTokenAccount = _b.sent();
|
|
5245
|
-
_a = createAta;
|
|
5246
|
-
if (!_a) return [3, 4];
|
|
5032
|
+
_a.trys.push([1, 4, , 5]);
|
|
5033
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5034
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5247
5035
|
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5248
|
-
case
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
case 4:
|
|
5252
|
-
if (_a) {
|
|
5253
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(owner, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5036
|
+
case 2:
|
|
5037
|
+
if (!(_a.sent())) {
|
|
5038
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5254
5039
|
}
|
|
5255
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
|
|
5256
|
-
case 5:
|
|
5257
|
-
nftTokenAccount = _b.sent();
|
|
5258
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
5259
|
-
Buffer.from("trading"),
|
|
5260
|
-
nftMint.toBuffer(),
|
|
5261
|
-
], this.programId)[0];
|
|
5262
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5263
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5264
|
-
edition = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("edition")], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5265
|
-
tokenRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("token_record"), nftTokenAccount.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5266
5040
|
return [4, this.program.methods
|
|
5267
|
-
.
|
|
5041
|
+
.depositTokenStake({
|
|
5042
|
+
depositAmount: depositAmount
|
|
5043
|
+
})
|
|
5268
5044
|
.accounts({
|
|
5269
5045
|
owner: owner,
|
|
5270
|
-
|
|
5046
|
+
feePayer: feePayer,
|
|
5047
|
+
fundingTokenAccount: userTokenAccount,
|
|
5271
5048
|
perpetuals: this.perpetuals.publicKey,
|
|
5272
5049
|
tokenVault: poolConfig.tokenVault,
|
|
5273
5050
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5274
|
-
|
|
5275
|
-
collectionMetadata: collectionMetadata,
|
|
5276
|
-
edition: edition,
|
|
5277
|
-
tokenRecord: tokenRecord,
|
|
5278
|
-
tradingAccount: nftTradingAccount,
|
|
5279
|
-
transferAuthority: poolConfig.transferAuthority,
|
|
5280
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
|
5281
|
-
nftMint: nftMint,
|
|
5282
|
-
nftTokenAccount: nftTokenAccount,
|
|
5051
|
+
tokenStakeAccount: tokenStakeAccount,
|
|
5283
5052
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5284
5053
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5285
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5286
5054
|
eventAuthority: this.eventAuthority.publicKey,
|
|
5287
5055
|
program: this.programId,
|
|
5288
|
-
|
|
5289
|
-
})
|
|
5290
|
-
.instruction()];
|
|
5291
|
-
case 6:
|
|
5292
|
-
burnAndClaimInstruction = _b.sent();
|
|
5293
|
-
instructions.push(burnAndClaimInstruction);
|
|
5294
|
-
return [3, 8];
|
|
5295
|
-
case 7:
|
|
5296
|
-
err_23 = _b.sent();
|
|
5297
|
-
console.log("perpClient burnAndClaimInstruction error:: ", err_23);
|
|
5298
|
-
throw err_23;
|
|
5299
|
-
case 8: return [2, {
|
|
5300
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5301
|
-
additionalSigners: additionalSigners
|
|
5302
|
-
}];
|
|
5303
|
-
}
|
|
5304
|
-
});
|
|
5305
|
-
}); };
|
|
5306
|
-
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5307
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_24;
|
|
5308
|
-
return __generator(this, function (_a) {
|
|
5309
|
-
switch (_a.label) {
|
|
5310
|
-
case 0:
|
|
5311
|
-
preInstructions = [];
|
|
5312
|
-
instructions = [];
|
|
5313
|
-
postInstructions = [];
|
|
5314
|
-
additionalSigners = [];
|
|
5315
|
-
_a.label = 1;
|
|
5316
|
-
case 1:
|
|
5317
|
-
_a.trys.push([1, 3, , 4]);
|
|
5318
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5319
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
|
5320
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
5321
|
-
Buffer.from("trading"),
|
|
5322
|
-
nftMint.toBuffer(),
|
|
5323
|
-
], this.programId)[0];
|
|
5324
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5325
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5326
|
-
edition = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("edition")], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5327
|
-
tokenRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer(), Buffer.from("token_record"), nftTokenAccount.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5328
|
-
return [4, this.program.methods
|
|
5329
|
-
.burnAndStake({})
|
|
5330
|
-
.accounts({
|
|
5331
|
-
owner: owner,
|
|
5332
|
-
feePayer: feePayer,
|
|
5333
|
-
perpetuals: this.perpetuals.publicKey,
|
|
5334
|
-
tokenVault: poolConfig.tokenVault,
|
|
5335
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5336
|
-
tokenStakeAccount: tokenStakeAccount,
|
|
5337
|
-
metadataAccount: metadataAccount,
|
|
5338
|
-
collectionMetadata: collectionMetadata,
|
|
5339
|
-
edition: edition,
|
|
5340
|
-
tokenRecord: tokenRecord,
|
|
5341
|
-
tradingAccount: nftTradingAccount,
|
|
5342
|
-
transferAuthority: poolConfig.transferAuthority,
|
|
5343
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
|
5344
|
-
nftMint: nftMint,
|
|
5345
|
-
nftTokenAccount: nftTokenAccount,
|
|
5346
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5347
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5348
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5349
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5350
|
-
program: this.programId
|
|
5351
|
-
})
|
|
5352
|
-
.instruction()];
|
|
5353
|
-
case 2:
|
|
5354
|
-
burnAndStakeInstruction = _a.sent();
|
|
5355
|
-
instructions.push(burnAndStakeInstruction);
|
|
5356
|
-
return [3, 4];
|
|
5357
|
-
case 3:
|
|
5358
|
-
err_24 = _a.sent();
|
|
5359
|
-
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
|
5360
|
-
throw err_24;
|
|
5361
|
-
case 4: return [2, {
|
|
5362
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5363
|
-
additionalSigners: additionalSigners
|
|
5364
|
-
}];
|
|
5365
|
-
}
|
|
5366
|
-
});
|
|
5367
|
-
}); };
|
|
5368
|
-
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5369
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
|
5370
|
-
return __generator(this, function (_a) {
|
|
5371
|
-
switch (_a.label) {
|
|
5372
|
-
case 0:
|
|
5373
|
-
preInstructions = [];
|
|
5374
|
-
instructions = [];
|
|
5375
|
-
postInstructions = [];
|
|
5376
|
-
additionalSigners = [];
|
|
5377
|
-
_a.label = 1;
|
|
5378
|
-
case 1:
|
|
5379
|
-
_a.trys.push([1, 4, , 5]);
|
|
5380
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5381
|
-
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5382
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5383
|
-
case 2:
|
|
5384
|
-
if (!(_a.sent())) {
|
|
5385
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5386
|
-
}
|
|
5387
|
-
return [4, this.program.methods
|
|
5388
|
-
.depositTokenStake({
|
|
5389
|
-
depositAmount: depositAmount
|
|
5390
|
-
})
|
|
5391
|
-
.accounts({
|
|
5392
|
-
owner: owner,
|
|
5393
|
-
feePayer: feePayer,
|
|
5394
|
-
fundingTokenAccount: userTokenAccount,
|
|
5395
|
-
perpetuals: this.perpetuals.publicKey,
|
|
5396
|
-
tokenVault: poolConfig.tokenVault,
|
|
5397
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5398
|
-
tokenStakeAccount: tokenStakeAccount,
|
|
5399
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5400
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5401
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5402
|
-
program: this.programId,
|
|
5403
|
-
tokenMint: poolConfig.tokenMint,
|
|
5056
|
+
tokenMint: poolConfig.tokenMint,
|
|
5404
5057
|
})
|
|
5405
5058
|
.instruction()];
|
|
5406
5059
|
case 3:
|
|
@@ -5408,9 +5061,9 @@ var PerpetualsClient = (function () {
|
|
|
5408
5061
|
instructions.push(depositTokenStakeInstruction);
|
|
5409
5062
|
return [3, 5];
|
|
5410
5063
|
case 4:
|
|
5411
|
-
|
|
5412
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
|
5413
|
-
throw
|
|
5064
|
+
err_21 = _a.sent();
|
|
5065
|
+
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
|
5066
|
+
throw err_21;
|
|
5414
5067
|
case 5: return [2, {
|
|
5415
5068
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5416
5069
|
additionalSigners: additionalSigners
|
|
@@ -5419,7 +5072,7 @@ var PerpetualsClient = (function () {
|
|
|
5419
5072
|
});
|
|
5420
5073
|
}); };
|
|
5421
5074
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5422
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
|
5075
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
|
|
5423
5076
|
return __generator(this, function (_a) {
|
|
5424
5077
|
switch (_a.label) {
|
|
5425
5078
|
case 0:
|
|
@@ -5448,9 +5101,9 @@ var PerpetualsClient = (function () {
|
|
|
5448
5101
|
instructions.push(unstakeTokenRequestInstruction);
|
|
5449
5102
|
return [3, 4];
|
|
5450
5103
|
case 3:
|
|
5451
|
-
|
|
5452
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
|
5453
|
-
throw
|
|
5104
|
+
err_22 = _a.sent();
|
|
5105
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
|
|
5106
|
+
throw err_22;
|
|
5454
5107
|
case 4: return [2, {
|
|
5455
5108
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5456
5109
|
additionalSigners: additionalSigners
|
|
@@ -5459,7 +5112,7 @@ var PerpetualsClient = (function () {
|
|
|
5459
5112
|
});
|
|
5460
5113
|
}); };
|
|
5461
5114
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5462
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
|
5115
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
|
|
5463
5116
|
return __generator(this, function (_a) {
|
|
5464
5117
|
switch (_a.label) {
|
|
5465
5118
|
case 0:
|
|
@@ -5500,9 +5153,9 @@ var PerpetualsClient = (function () {
|
|
|
5500
5153
|
instructions.push(unstakeTokenInstantInstruction);
|
|
5501
5154
|
return [3, 5];
|
|
5502
5155
|
case 4:
|
|
5503
|
-
|
|
5504
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
|
5505
|
-
throw
|
|
5156
|
+
err_23 = _a.sent();
|
|
5157
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
|
5158
|
+
throw err_23;
|
|
5506
5159
|
case 5: return [2, {
|
|
5507
5160
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5508
5161
|
additionalSigners: additionalSigners
|
|
@@ -5511,7 +5164,7 @@ var PerpetualsClient = (function () {
|
|
|
5511
5164
|
});
|
|
5512
5165
|
}); };
|
|
5513
5166
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5514
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
|
5167
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
|
|
5515
5168
|
return __generator(this, function (_a) {
|
|
5516
5169
|
switch (_a.label) {
|
|
5517
5170
|
case 0:
|
|
@@ -5552,9 +5205,9 @@ var PerpetualsClient = (function () {
|
|
|
5552
5205
|
instructions.push(withdrawTokenInstruction);
|
|
5553
5206
|
return [3, 5];
|
|
5554
5207
|
case 4:
|
|
5555
|
-
|
|
5556
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
|
5557
|
-
throw
|
|
5208
|
+
err_24 = _a.sent();
|
|
5209
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
|
5210
|
+
throw err_24;
|
|
5558
5211
|
case 5: return [2, {
|
|
5559
5212
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5560
5213
|
additionalSigners: additionalSigners
|
|
@@ -5563,7 +5216,7 @@ var PerpetualsClient = (function () {
|
|
|
5563
5216
|
});
|
|
5564
5217
|
}); };
|
|
5565
5218
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5566
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
|
5219
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
|
|
5567
5220
|
return __generator(this, function (_a) {
|
|
5568
5221
|
switch (_a.label) {
|
|
5569
5222
|
case 0:
|
|
@@ -5592,9 +5245,9 @@ var PerpetualsClient = (function () {
|
|
|
5592
5245
|
instructions.push(cancelUnstakeRequestInstruction);
|
|
5593
5246
|
return [3, 4];
|
|
5594
5247
|
case 3:
|
|
5595
|
-
|
|
5596
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
|
5597
|
-
throw
|
|
5248
|
+
err_25 = _a.sent();
|
|
5249
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
|
|
5250
|
+
throw err_25;
|
|
5598
5251
|
case 4: return [2, {
|
|
5599
5252
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5600
5253
|
additionalSigners: additionalSigners
|
|
@@ -5608,7 +5261,7 @@ var PerpetualsClient = (function () {
|
|
|
5608
5261
|
args_1[_i - 2] = arguments[_i];
|
|
5609
5262
|
}
|
|
5610
5263
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
|
5611
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
|
5264
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
|
5612
5265
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5613
5266
|
return __generator(this, function (_b) {
|
|
5614
5267
|
switch (_b.label) {
|
|
@@ -5654,9 +5307,9 @@ var PerpetualsClient = (function () {
|
|
|
5654
5307
|
instructions.push(collectTokenRewardInstruction);
|
|
5655
5308
|
return [3, 6];
|
|
5656
5309
|
case 5:
|
|
5657
|
-
|
|
5658
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
|
5659
|
-
throw
|
|
5310
|
+
err_26 = _b.sent();
|
|
5311
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
|
5312
|
+
throw err_26;
|
|
5660
5313
|
case 6: return [2, {
|
|
5661
5314
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5662
5315
|
additionalSigners: additionalSigners
|
|
@@ -5671,7 +5324,7 @@ var PerpetualsClient = (function () {
|
|
|
5671
5324
|
args_1[_i - 3] = arguments[_i];
|
|
5672
5325
|
}
|
|
5673
5326
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
|
5674
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
|
5327
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
|
|
5675
5328
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5676
5329
|
return __generator(this, function (_b) {
|
|
5677
5330
|
switch (_b.label) {
|
|
@@ -5718,9 +5371,9 @@ var PerpetualsClient = (function () {
|
|
|
5718
5371
|
instructions.push(collectRevenueInstruction);
|
|
5719
5372
|
return [3, 6];
|
|
5720
5373
|
case 5:
|
|
5721
|
-
|
|
5722
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
|
5723
|
-
throw
|
|
5374
|
+
err_27 = _b.sent();
|
|
5375
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
|
5376
|
+
throw err_27;
|
|
5724
5377
|
case 6: return [2, {
|
|
5725
5378
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5726
5379
|
additionalSigners: additionalSigners
|
|
@@ -5729,179 +5382,82 @@ var PerpetualsClient = (function () {
|
|
|
5729
5382
|
});
|
|
5730
5383
|
});
|
|
5731
5384
|
};
|
|
5732
|
-
this.
|
|
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) {
|
|
5385
|
+
this.collectRebate = function (owner_1, rebateSymbol_1, poolConfig_1) {
|
|
5823
5386
|
var args_1 = [];
|
|
5824
5387
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
5825
5388
|
args_1[_i - 3] = arguments[_i];
|
|
5826
5389
|
}
|
|
5827
|
-
return __awaiter(_this, __spreadArray([
|
|
5828
|
-
var publicKey,
|
|
5390
|
+
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
|
|
5391
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, _a, collectRebateInstruction, err_28;
|
|
5829
5392
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5830
5393
|
return __generator(this, function (_b) {
|
|
5831
5394
|
switch (_b.label) {
|
|
5832
5395
|
case 0:
|
|
5833
5396
|
publicKey = this.provider.wallet.publicKey;
|
|
5834
|
-
|
|
5835
|
-
rewardCustodyMint = rewardToken.mintKey;
|
|
5397
|
+
preInstructions = [];
|
|
5836
5398
|
instructions = [];
|
|
5399
|
+
postInstructions = [];
|
|
5837
5400
|
additionalSigners = [];
|
|
5838
5401
|
_b.label = 1;
|
|
5839
5402
|
case 1:
|
|
5840
5403
|
_b.trys.push([1, 5, , 6]);
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5404
|
+
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5405
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5406
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5844
5407
|
_a = createUserATA;
|
|
5845
5408
|
if (!_a) return [3, 3];
|
|
5846
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
|
5409
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5847
5410
|
case 2:
|
|
5848
5411
|
_a = !(_b.sent());
|
|
5849
5412
|
_b.label = 3;
|
|
5850
5413
|
case 3:
|
|
5851
5414
|
if (_a) {
|
|
5852
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey,
|
|
5853
|
-
}
|
|
5854
|
-
|
|
5855
|
-
|
|
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()
|
|
5415
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5416
|
+
}
|
|
5417
|
+
return [4, this.program.methods
|
|
5418
|
+
.collectRebate()
|
|
5860
5419
|
.accounts({
|
|
5861
|
-
owner:
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
5420
|
+
owner: owner,
|
|
5421
|
+
receivingTokenAccount: userTokenAccount,
|
|
5422
|
+
perpetuals: this.perpetuals.publicKey,
|
|
5423
|
+
transferAuthority: poolConfig.transferAuthority,
|
|
5424
|
+
rebateVault: poolConfig.rebateVault,
|
|
5425
|
+
rebateTokenAccount: poolConfig.rebateTokenAccount,
|
|
5426
|
+
tokenStakeAccount: tokenStakeAccount,
|
|
5427
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5428
|
+
eventAuthority: this.eventAuthority.publicKey,
|
|
5429
|
+
program: this.programId,
|
|
5430
|
+
receivingTokenMint: rebateMint,
|
|
5873
5431
|
})
|
|
5874
5432
|
.instruction()];
|
|
5875
5433
|
case 4:
|
|
5876
|
-
|
|
5877
|
-
instructions.push(
|
|
5434
|
+
collectRebateInstruction = _b.sent();
|
|
5435
|
+
instructions.push(collectRebateInstruction);
|
|
5878
5436
|
return [3, 6];
|
|
5879
5437
|
case 5:
|
|
5880
|
-
|
|
5881
|
-
|
|
5438
|
+
err_28 = _b.sent();
|
|
5439
|
+
console.log("perpClient collectRebateInstruction error:: ", err_28);
|
|
5440
|
+
throw err_28;
|
|
5882
5441
|
case 6: return [2, {
|
|
5883
|
-
instructions: __spreadArray([], instructions, true),
|
|
5442
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5884
5443
|
additionalSigners: additionalSigners
|
|
5885
5444
|
}];
|
|
5886
5445
|
}
|
|
5887
5446
|
});
|
|
5888
5447
|
});
|
|
5889
5448
|
};
|
|
5890
|
-
this.
|
|
5449
|
+
this.settleRebates = function (owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1) {
|
|
5891
5450
|
var args_1 = [];
|
|
5892
|
-
for (var _i =
|
|
5893
|
-
args_1[_i -
|
|
5451
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
5452
|
+
args_1[_i - 4] = arguments[_i];
|
|
5894
5453
|
}
|
|
5895
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA
|
|
5896
|
-
var publicKey,
|
|
5454
|
+
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, rewardSymbol, poolConfig, createUserATA) {
|
|
5455
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, rebateMint, userTokenAccount, _a, settleRebatesInstruction, err_29;
|
|
5897
5456
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5898
5457
|
return __generator(this, function (_b) {
|
|
5899
5458
|
switch (_b.label) {
|
|
5900
5459
|
case 0:
|
|
5901
5460
|
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
5461
|
preInstructions = [];
|
|
5906
5462
|
instructions = [];
|
|
5907
5463
|
postInstructions = [];
|
|
@@ -5909,59 +5465,45 @@ var PerpetualsClient = (function () {
|
|
|
5909
5465
|
_b.label = 1;
|
|
5910
5466
|
case 1:
|
|
5911
5467
|
_b.trys.push([1, 5, , 6]);
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5468
|
+
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
|
5469
|
+
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5470
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5915
5471
|
_a = createUserATA;
|
|
5916
5472
|
if (!_a) return [3, 3];
|
|
5917
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
|
5473
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5918
5474
|
case 2:
|
|
5919
5475
|
_a = !(_b.sent());
|
|
5920
5476
|
_b.label = 3;
|
|
5921
5477
|
case 3:
|
|
5922
5478
|
if (_a) {
|
|
5923
|
-
|
|
5924
|
-
}
|
|
5925
|
-
tradingAccount = [];
|
|
5926
|
-
if (nftTradingAccount) {
|
|
5927
|
-
tradingAccount.push({
|
|
5928
|
-
pubkey: nftTradingAccount,
|
|
5929
|
-
isSigner: false,
|
|
5930
|
-
isWritable: true,
|
|
5931
|
-
});
|
|
5479
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5932
5480
|
}
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
return [4, this.programPerpComposability.methods
|
|
5936
|
-
.collectAndDistributeFee()
|
|
5481
|
+
return [4, this.program.methods
|
|
5482
|
+
.settleRebates()
|
|
5937
5483
|
.accounts({
|
|
5938
|
-
perpProgram: this.programId,
|
|
5939
|
-
owner: publicKey,
|
|
5940
|
-
receivingTokenAccount: receivingTokenAccount,
|
|
5941
5484
|
transferAuthority: poolConfig.transferAuthority,
|
|
5942
5485
|
perpetuals: this.perpetuals.publicKey,
|
|
5943
|
-
pool:
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5486
|
+
pool: poolConfig.poolAddress,
|
|
5487
|
+
rewardCustody: rewardCustody.custodyAccount,
|
|
5488
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
|
5489
|
+
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
|
5490
|
+
rebateVault: poolConfig.rebateVault,
|
|
5491
|
+
rebateTokenAccount: poolConfig.rebateTokenAccount,
|
|
5492
|
+
tokenMint: rebateMint,
|
|
5948
5493
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5949
5494
|
eventAuthority: this.eventAuthority.publicKey,
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
rewardVault: rewardVault,
|
|
5953
|
-
rewardTokenAccount: rewardTokenAccount
|
|
5495
|
+
program: this.programId,
|
|
5496
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
5954
5497
|
})
|
|
5955
|
-
.remainingAccounts(tradingAccount)
|
|
5956
5498
|
.instruction()];
|
|
5957
5499
|
case 4:
|
|
5958
|
-
|
|
5959
|
-
instructions.push(
|
|
5500
|
+
settleRebatesInstruction = _b.sent();
|
|
5501
|
+
instructions.push(settleRebatesInstruction);
|
|
5960
5502
|
return [3, 6];
|
|
5961
5503
|
case 5:
|
|
5962
|
-
|
|
5963
|
-
console.log("perpClient
|
|
5964
|
-
throw
|
|
5504
|
+
err_29 = _b.sent();
|
|
5505
|
+
console.log("perpClient settleRebatesInstruction error:: ", err_29);
|
|
5506
|
+
throw err_29;
|
|
5965
5507
|
case 6: return [2, {
|
|
5966
5508
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5967
5509
|
additionalSigners: additionalSigners
|
|
@@ -5976,7 +5518,7 @@ var PerpetualsClient = (function () {
|
|
|
5976
5518
|
args_1[_i - 11] = arguments[_i];
|
|
5977
5519
|
}
|
|
5978
5520
|
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,
|
|
5521
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_30;
|
|
5980
5522
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
5981
5523
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5982
5524
|
return __generator(this, function (_c) {
|
|
@@ -6082,9 +5624,9 @@ var PerpetualsClient = (function () {
|
|
|
6082
5624
|
instructions.push(placeLimitOrder);
|
|
6083
5625
|
return [3, 10];
|
|
6084
5626
|
case 9:
|
|
6085
|
-
|
|
6086
|
-
console.log("perpClient placeLimitOrder error:: ",
|
|
6087
|
-
throw
|
|
5627
|
+
err_30 = _c.sent();
|
|
5628
|
+
console.log("perpClient placeLimitOrder error:: ", err_30);
|
|
5629
|
+
throw err_30;
|
|
6088
5630
|
case 10: return [2, {
|
|
6089
5631
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6090
5632
|
additionalSigners: additionalSigners
|
|
@@ -6099,7 +5641,7 @@ var PerpetualsClient = (function () {
|
|
|
6099
5641
|
args_1[_i - 11] = arguments[_i];
|
|
6100
5642
|
}
|
|
6101
5643
|
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,
|
|
5644
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_31;
|
|
6103
5645
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6104
5646
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6105
5647
|
return __generator(this, function (_b) {
|
|
@@ -6190,9 +5732,9 @@ var PerpetualsClient = (function () {
|
|
|
6190
5732
|
instructions.push(editLimitOrder);
|
|
6191
5733
|
return [3, 8];
|
|
6192
5734
|
case 7:
|
|
6193
|
-
|
|
6194
|
-
console.log("perpClient editLimitOrder error:: ",
|
|
6195
|
-
throw
|
|
5735
|
+
err_31 = _b.sent();
|
|
5736
|
+
console.log("perpClient editLimitOrder error:: ", err_31);
|
|
5737
|
+
throw err_31;
|
|
6196
5738
|
case 8: return [2, {
|
|
6197
5739
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6198
5740
|
additionalSigners: additionalSigners
|
|
@@ -6206,11 +5748,10 @@ var PerpetualsClient = (function () {
|
|
|
6206
5748
|
for (var _i = 7; _i < arguments.length; _i++) {
|
|
6207
5749
|
args_1[_i - 7] = arguments[_i];
|
|
6208
5750
|
}
|
|
6209
|
-
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount
|
|
6210
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder,
|
|
5751
|
+
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) {
|
|
5752
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_32;
|
|
6211
5753
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6212
5754
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6213
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6214
5755
|
return __generator(this, function (_a) {
|
|
6215
5756
|
switch (_a.label) {
|
|
6216
5757
|
case 0:
|
|
@@ -6253,16 +5794,16 @@ var PerpetualsClient = (function () {
|
|
|
6253
5794
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6254
5795
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
6255
5796
|
})
|
|
6256
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
5797
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6257
5798
|
.instruction()];
|
|
6258
5799
|
case 2:
|
|
6259
5800
|
executeLimitOrder = _a.sent();
|
|
6260
5801
|
instructions.push(executeLimitOrder);
|
|
6261
5802
|
return [3, 4];
|
|
6262
5803
|
case 3:
|
|
6263
|
-
|
|
6264
|
-
console.log("perpClient executeLimitOrder error:: ",
|
|
6265
|
-
throw
|
|
5804
|
+
err_32 = _a.sent();
|
|
5805
|
+
console.log("perpClient executeLimitOrder error:: ", err_32);
|
|
5806
|
+
throw err_32;
|
|
6266
5807
|
case 4: return [2, {
|
|
6267
5808
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6268
5809
|
additionalSigners: additionalSigners
|
|
@@ -6276,11 +5817,10 @@ var PerpetualsClient = (function () {
|
|
|
6276
5817
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
6277
5818
|
args_1[_i - 8] = arguments[_i];
|
|
6278
5819
|
}
|
|
6279
|
-
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount
|
|
6280
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap,
|
|
5820
|
+
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) {
|
|
5821
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_33;
|
|
6281
5822
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6282
5823
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6283
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6284
5824
|
return __generator(this, function (_a) {
|
|
6285
5825
|
switch (_a.label) {
|
|
6286
5826
|
case 0:
|
|
@@ -6326,16 +5866,16 @@ var PerpetualsClient = (function () {
|
|
|
6326
5866
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6327
5867
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
6328
5868
|
})
|
|
6329
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
5869
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6330
5870
|
.instruction()];
|
|
6331
5871
|
case 2:
|
|
6332
5872
|
executeLimitWithSwap = _a.sent();
|
|
6333
5873
|
instructions.push(executeLimitWithSwap);
|
|
6334
5874
|
return [3, 4];
|
|
6335
5875
|
case 3:
|
|
6336
|
-
|
|
6337
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
|
6338
|
-
throw
|
|
5876
|
+
err_33 = _a.sent();
|
|
5877
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_33);
|
|
5878
|
+
throw err_33;
|
|
6339
5879
|
case 4: return [2, {
|
|
6340
5880
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6341
5881
|
additionalSigners: additionalSigners
|
|
@@ -6345,7 +5885,7 @@ var PerpetualsClient = (function () {
|
|
|
6345
5885
|
});
|
|
6346
5886
|
};
|
|
6347
5887
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6348
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
|
5888
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_34;
|
|
6349
5889
|
return __generator(this, function (_a) {
|
|
6350
5890
|
switch (_a.label) {
|
|
6351
5891
|
case 0:
|
|
@@ -6393,9 +5933,9 @@ var PerpetualsClient = (function () {
|
|
|
6393
5933
|
instructions.push(placeTriggerOrder);
|
|
6394
5934
|
return [3, 4];
|
|
6395
5935
|
case 3:
|
|
6396
|
-
|
|
6397
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
|
6398
|
-
throw
|
|
5936
|
+
err_34 = _a.sent();
|
|
5937
|
+
console.log("perpClient placeTriggerOrder error:: ", err_34);
|
|
5938
|
+
throw err_34;
|
|
6399
5939
|
case 4: return [2, {
|
|
6400
5940
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6401
5941
|
additionalSigners: additionalSigners
|
|
@@ -6404,7 +5944,7 @@ var PerpetualsClient = (function () {
|
|
|
6404
5944
|
});
|
|
6405
5945
|
}); };
|
|
6406
5946
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6407
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
|
5947
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_35;
|
|
6408
5948
|
return __generator(this, function (_a) {
|
|
6409
5949
|
switch (_a.label) {
|
|
6410
5950
|
case 0:
|
|
@@ -6451,9 +5991,9 @@ var PerpetualsClient = (function () {
|
|
|
6451
5991
|
instructions.push(editTriggerOrder);
|
|
6452
5992
|
return [3, 4];
|
|
6453
5993
|
case 3:
|
|
6454
|
-
|
|
6455
|
-
console.log("perpClient editTriggerOrder error:: ",
|
|
6456
|
-
throw
|
|
5994
|
+
err_35 = _a.sent();
|
|
5995
|
+
console.log("perpClient editTriggerOrder error:: ", err_35);
|
|
5996
|
+
throw err_35;
|
|
6457
5997
|
case 4: return [2, {
|
|
6458
5998
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6459
5999
|
additionalSigners: additionalSigners
|
|
@@ -6462,7 +6002,7 @@ var PerpetualsClient = (function () {
|
|
|
6462
6002
|
});
|
|
6463
6003
|
}); };
|
|
6464
6004
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6465
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
|
6005
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_36;
|
|
6466
6006
|
return __generator(this, function (_a) {
|
|
6467
6007
|
switch (_a.label) {
|
|
6468
6008
|
case 0:
|
|
@@ -6495,9 +6035,9 @@ var PerpetualsClient = (function () {
|
|
|
6495
6035
|
instructions.push(cancelTriggerOrder);
|
|
6496
6036
|
return [3, 4];
|
|
6497
6037
|
case 3:
|
|
6498
|
-
|
|
6499
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
|
6500
|
-
throw
|
|
6038
|
+
err_36 = _a.sent();
|
|
6039
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_36);
|
|
6040
|
+
throw err_36;
|
|
6501
6041
|
case 4: return [2, {
|
|
6502
6042
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6503
6043
|
additionalSigners: additionalSigners
|
|
@@ -6506,7 +6046,7 @@ var PerpetualsClient = (function () {
|
|
|
6506
6046
|
});
|
|
6507
6047
|
}); };
|
|
6508
6048
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6509
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
|
6049
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_37;
|
|
6510
6050
|
return __generator(this, function (_a) {
|
|
6511
6051
|
switch (_a.label) {
|
|
6512
6052
|
case 0:
|
|
@@ -6537,9 +6077,9 @@ var PerpetualsClient = (function () {
|
|
|
6537
6077
|
instructions.push(cancelAllTriggerOrders);
|
|
6538
6078
|
return [3, 4];
|
|
6539
6079
|
case 3:
|
|
6540
|
-
|
|
6541
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
|
6542
|
-
throw
|
|
6080
|
+
err_37 = _a.sent();
|
|
6081
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_37);
|
|
6082
|
+
throw err_37;
|
|
6543
6083
|
case 4: return [2, {
|
|
6544
6084
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6545
6085
|
additionalSigners: additionalSigners
|
|
@@ -6552,13 +6092,12 @@ var PerpetualsClient = (function () {
|
|
|
6552
6092
|
for (var _i = 9; _i < arguments.length; _i++) {
|
|
6553
6093
|
args_1[_i - 9] = arguments[_i];
|
|
6554
6094
|
}
|
|
6555
|
-
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount
|
|
6556
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap,
|
|
6095
|
+
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) {
|
|
6096
|
+
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_38;
|
|
6557
6097
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6558
6098
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6559
6099
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6560
6100
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6561
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6562
6101
|
return __generator(this, function (_e) {
|
|
6563
6102
|
switch (_e.label) {
|
|
6564
6103
|
case 0:
|
|
@@ -6653,16 +6192,16 @@ var PerpetualsClient = (function () {
|
|
|
6653
6192
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
6654
6193
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
6655
6194
|
})
|
|
6656
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
6195
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6657
6196
|
.instruction()];
|
|
6658
6197
|
case 8:
|
|
6659
6198
|
executeTriggerWithSwap = _e.sent();
|
|
6660
6199
|
instructions.push(executeTriggerWithSwap);
|
|
6661
6200
|
return [3, 10];
|
|
6662
6201
|
case 9:
|
|
6663
|
-
|
|
6664
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
|
6665
|
-
throw
|
|
6202
|
+
err_38 = _e.sent();
|
|
6203
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_38);
|
|
6204
|
+
throw err_38;
|
|
6666
6205
|
case 10: return [2, {
|
|
6667
6206
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6668
6207
|
additionalSigners: additionalSigners
|
|
@@ -6676,13 +6215,12 @@ var PerpetualsClient = (function () {
|
|
|
6676
6215
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
6677
6216
|
args_1[_i - 8] = arguments[_i];
|
|
6678
6217
|
}
|
|
6679
|
-
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount
|
|
6680
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder,
|
|
6218
|
+
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) {
|
|
6219
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_39;
|
|
6681
6220
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6682
6221
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6683
6222
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6684
6223
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6685
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6686
6224
|
return __generator(this, function (_b) {
|
|
6687
6225
|
switch (_b.label) {
|
|
6688
6226
|
case 0:
|
|
@@ -6742,16 +6280,16 @@ var PerpetualsClient = (function () {
|
|
|
6742
6280
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6743
6281
|
receivingMint: collateralCustodyConfig.mintKey
|
|
6744
6282
|
})
|
|
6745
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
6283
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6746
6284
|
.instruction()];
|
|
6747
6285
|
case 6:
|
|
6748
6286
|
executeTriggerOrder = _b.sent();
|
|
6749
6287
|
instructions.push(executeTriggerOrder);
|
|
6750
6288
|
return [3, 8];
|
|
6751
6289
|
case 7:
|
|
6752
|
-
|
|
6753
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
|
6754
|
-
throw
|
|
6290
|
+
err_39 = _b.sent();
|
|
6291
|
+
console.log("perpClient executeTriggerOrder error:: ", err_39);
|
|
6292
|
+
throw err_39;
|
|
6755
6293
|
case 8: return [2, {
|
|
6756
6294
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6757
6295
|
additionalSigners: additionalSigners
|
|
@@ -6766,7 +6304,7 @@ var PerpetualsClient = (function () {
|
|
|
6766
6304
|
args_1[_i - 5] = arguments[_i];
|
|
6767
6305
|
}
|
|
6768
6306
|
return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
6769
|
-
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns,
|
|
6307
|
+
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_40;
|
|
6770
6308
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
|
6771
6309
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6772
6310
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
|
@@ -6971,9 +6509,9 @@ var PerpetualsClient = (function () {
|
|
|
6971
6509
|
}
|
|
6972
6510
|
return [3, 20];
|
|
6973
6511
|
case 19:
|
|
6974
|
-
|
|
6975
|
-
console.error("perpClient Swap error:: ",
|
|
6976
|
-
throw
|
|
6512
|
+
err_40 = _g.sent();
|
|
6513
|
+
console.error("perpClient Swap error:: ", err_40);
|
|
6514
|
+
throw err_40;
|
|
6977
6515
|
case 20: return [2, {
|
|
6978
6516
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6979
6517
|
additionalSigners: additionalSigners
|
|
@@ -6983,7 +6521,7 @@ var PerpetualsClient = (function () {
|
|
|
6983
6521
|
});
|
|
6984
6522
|
};
|
|
6985
6523
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6986
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx,
|
|
6524
|
+
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_41;
|
|
6987
6525
|
return __generator(this, function (_b) {
|
|
6988
6526
|
switch (_b.label) {
|
|
6989
6527
|
case 0:
|
|
@@ -7039,9 +6577,9 @@ var PerpetualsClient = (function () {
|
|
|
7039
6577
|
instructions.push(inx);
|
|
7040
6578
|
return [3, 4];
|
|
7041
6579
|
case 3:
|
|
7042
|
-
|
|
7043
|
-
console.error("perpClient Swap error:: ",
|
|
7044
|
-
throw
|
|
6580
|
+
err_41 = _b.sent();
|
|
6581
|
+
console.error("perpClient Swap error:: ", err_41);
|
|
6582
|
+
throw err_41;
|
|
7045
6583
|
case 4: return [2, {
|
|
7046
6584
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7047
6585
|
additionalSigners: additionalSigners
|
|
@@ -7050,7 +6588,7 @@ var PerpetualsClient = (function () {
|
|
|
7050
6588
|
});
|
|
7051
6589
|
}); };
|
|
7052
6590
|
this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7053
|
-
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction,
|
|
6591
|
+
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_42;
|
|
7054
6592
|
return __generator(this, function (_d) {
|
|
7055
6593
|
switch (_d.label) {
|
|
7056
6594
|
case 0:
|
|
@@ -7098,9 +6636,9 @@ var PerpetualsClient = (function () {
|
|
|
7098
6636
|
instructions.push(setLpTokenPriceInstruction);
|
|
7099
6637
|
return [3, 4];
|
|
7100
6638
|
case 3:
|
|
7101
|
-
|
|
7102
|
-
console.log("perpClient setLpTokenPriceInstruction error:: ",
|
|
7103
|
-
throw
|
|
6639
|
+
err_42 = _d.sent();
|
|
6640
|
+
console.log("perpClient setLpTokenPriceInstruction error:: ", err_42);
|
|
6641
|
+
throw err_42;
|
|
7104
6642
|
case 4: return [2, {
|
|
7105
6643
|
instructions: __spreadArray([], instructions, true),
|
|
7106
6644
|
additionalSigners: additionalSigners
|
|
@@ -7148,7 +6686,7 @@ var PerpetualsClient = (function () {
|
|
|
7148
6686
|
});
|
|
7149
6687
|
}); };
|
|
7150
6688
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
|
7151
|
-
var adminMetas, _i, admins_2, admin,
|
|
6689
|
+
var adminMetas, _i, admins_2, admin, err_43;
|
|
7152
6690
|
return __generator(this, function (_a) {
|
|
7153
6691
|
switch (_a.label) {
|
|
7154
6692
|
case 0:
|
|
@@ -7178,11 +6716,11 @@ var PerpetualsClient = (function () {
|
|
|
7178
6716
|
_a.sent();
|
|
7179
6717
|
return [3, 4];
|
|
7180
6718
|
case 3:
|
|
7181
|
-
|
|
6719
|
+
err_43 = _a.sent();
|
|
7182
6720
|
if (this.printErrors) {
|
|
7183
|
-
console.error("setAdminSigners err:",
|
|
6721
|
+
console.error("setAdminSigners err:", err_43);
|
|
7184
6722
|
}
|
|
7185
|
-
throw
|
|
6723
|
+
throw err_43;
|
|
7186
6724
|
case 4: return [2];
|
|
7187
6725
|
}
|
|
7188
6726
|
});
|
|
@@ -7371,7 +6909,7 @@ var PerpetualsClient = (function () {
|
|
|
7371
6909
|
});
|
|
7372
6910
|
}); };
|
|
7373
6911
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7374
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
|
6912
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_44;
|
|
7375
6913
|
return __generator(this, function (_a) {
|
|
7376
6914
|
switch (_a.label) {
|
|
7377
6915
|
case 0:
|
|
@@ -7404,9 +6942,9 @@ var PerpetualsClient = (function () {
|
|
|
7404
6942
|
instructions.push(withdrawFeesIx);
|
|
7405
6943
|
return [3, 5];
|
|
7406
6944
|
case 4:
|
|
7407
|
-
|
|
7408
|
-
console.log("perpClient setPool error:: ",
|
|
7409
|
-
throw
|
|
6945
|
+
err_44 = _a.sent();
|
|
6946
|
+
console.log("perpClient setPool error:: ", err_44);
|
|
6947
|
+
throw err_44;
|
|
7410
6948
|
case 5: return [2, {
|
|
7411
6949
|
instructions: __spreadArray([], instructions, true),
|
|
7412
6950
|
additionalSigners: additionalSigners
|
|
@@ -7415,7 +6953,7 @@ var PerpetualsClient = (function () {
|
|
|
7415
6953
|
});
|
|
7416
6954
|
}); };
|
|
7417
6955
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7418
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
|
6956
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_45;
|
|
7419
6957
|
return __generator(this, function (_a) {
|
|
7420
6958
|
switch (_a.label) {
|
|
7421
6959
|
case 0:
|
|
@@ -7449,9 +6987,9 @@ var PerpetualsClient = (function () {
|
|
|
7449
6987
|
instructions.push(moveProtocolFeesIx);
|
|
7450
6988
|
return [3, 4];
|
|
7451
6989
|
case 3:
|
|
7452
|
-
|
|
7453
|
-
console.log("perpClient setPool error:: ",
|
|
7454
|
-
throw
|
|
6990
|
+
err_45 = _a.sent();
|
|
6991
|
+
console.log("perpClient setPool error:: ", err_45);
|
|
6992
|
+
throw err_45;
|
|
7455
6993
|
case 4: return [2, {
|
|
7456
6994
|
instructions: __spreadArray([], instructions, true),
|
|
7457
6995
|
additionalSigners: additionalSigners
|
|
@@ -7460,7 +6998,7 @@ var PerpetualsClient = (function () {
|
|
|
7460
6998
|
});
|
|
7461
6999
|
}); };
|
|
7462
7000
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7463
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
|
7001
|
+
var publicKey, setProtocolFeeShareBpsIx, err_46;
|
|
7464
7002
|
return __generator(this, function (_a) {
|
|
7465
7003
|
switch (_a.label) {
|
|
7466
7004
|
case 0:
|
|
@@ -7480,15 +7018,15 @@ var PerpetualsClient = (function () {
|
|
|
7480
7018
|
setProtocolFeeShareBpsIx = _a.sent();
|
|
7481
7019
|
return [2, setProtocolFeeShareBpsIx];
|
|
7482
7020
|
case 2:
|
|
7483
|
-
|
|
7484
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
|
7485
|
-
throw
|
|
7021
|
+
err_46 = _a.sent();
|
|
7022
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_46);
|
|
7023
|
+
throw err_46;
|
|
7486
7024
|
case 3: return [2];
|
|
7487
7025
|
}
|
|
7488
7026
|
});
|
|
7489
7027
|
}); };
|
|
7490
7028
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
|
7491
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
|
7029
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_47;
|
|
7492
7030
|
return __generator(this, function (_a) {
|
|
7493
7031
|
switch (_a.label) {
|
|
7494
7032
|
case 0:
|
|
@@ -7515,9 +7053,9 @@ var PerpetualsClient = (function () {
|
|
|
7515
7053
|
instructions.push(setPermissionsInstruction);
|
|
7516
7054
|
return [3, 4];
|
|
7517
7055
|
case 3:
|
|
7518
|
-
|
|
7519
|
-
console.log("perpClient setPool error:: ",
|
|
7520
|
-
throw
|
|
7056
|
+
err_47 = _a.sent();
|
|
7057
|
+
console.log("perpClient setPool error:: ", err_47);
|
|
7058
|
+
throw err_47;
|
|
7521
7059
|
case 4: return [2, {
|
|
7522
7060
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7523
7061
|
additionalSigners: additionalSigners
|
|
@@ -7526,7 +7064,7 @@ var PerpetualsClient = (function () {
|
|
|
7526
7064
|
});
|
|
7527
7065
|
}); };
|
|
7528
7066
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7529
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
|
7067
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_48;
|
|
7530
7068
|
var _f;
|
|
7531
7069
|
return __generator(this, function (_g) {
|
|
7532
7070
|
switch (_g.label) {
|
|
@@ -7587,9 +7125,9 @@ var PerpetualsClient = (function () {
|
|
|
7587
7125
|
instructions.push(reimburse);
|
|
7588
7126
|
return [3, 5];
|
|
7589
7127
|
case 4:
|
|
7590
|
-
|
|
7591
|
-
console.log("perpClient setPool error:: ",
|
|
7592
|
-
throw
|
|
7128
|
+
err_48 = _g.sent();
|
|
7129
|
+
console.log("perpClient setPool error:: ", err_48);
|
|
7130
|
+
throw err_48;
|
|
7593
7131
|
case 5: return [2, {
|
|
7594
7132
|
instructions: __spreadArray([], instructions, true),
|
|
7595
7133
|
additionalSigners: additionalSigners
|
|
@@ -7597,8 +7135,8 @@ var PerpetualsClient = (function () {
|
|
|
7597
7135
|
}
|
|
7598
7136
|
});
|
|
7599
7137
|
}); };
|
|
7600
|
-
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7601
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
|
7138
|
+
this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7139
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_49;
|
|
7602
7140
|
return __generator(this, function (_a) {
|
|
7603
7141
|
switch (_a.label) {
|
|
7604
7142
|
case 0:
|
|
@@ -7610,6 +7148,7 @@ var PerpetualsClient = (function () {
|
|
|
7610
7148
|
_a.trys.push([1, 3, , 4]);
|
|
7611
7149
|
return [4, this.program.methods
|
|
7612
7150
|
.setInternalOraclePrice({
|
|
7151
|
+
useCurrentTime: useCurrentTime,
|
|
7613
7152
|
price: price,
|
|
7614
7153
|
expo: expo,
|
|
7615
7154
|
conf: conf,
|
|
@@ -7631,9 +7170,9 @@ var PerpetualsClient = (function () {
|
|
|
7631
7170
|
instructions.push(setInternalOraclePrice);
|
|
7632
7171
|
return [3, 4];
|
|
7633
7172
|
case 3:
|
|
7634
|
-
|
|
7635
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
|
7636
|
-
throw
|
|
7173
|
+
err_49 = _a.sent();
|
|
7174
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_49);
|
|
7175
|
+
throw err_49;
|
|
7637
7176
|
case 4: return [2, {
|
|
7638
7177
|
instructions: __spreadArray([], instructions, true),
|
|
7639
7178
|
additionalSigners: additionalSigners
|
|
@@ -7641,8 +7180,8 @@ var PerpetualsClient = (function () {
|
|
|
7641
7180
|
}
|
|
7642
7181
|
});
|
|
7643
7182
|
}); };
|
|
7644
|
-
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
|
7645
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
|
7183
|
+
this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
|
7184
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_50;
|
|
7646
7185
|
return __generator(this, function (_a) {
|
|
7647
7186
|
switch (_a.label) {
|
|
7648
7187
|
case 0:
|
|
@@ -7653,11 +7192,6 @@ var PerpetualsClient = (function () {
|
|
|
7653
7192
|
accountMetas = [];
|
|
7654
7193
|
_loop_1 = function (tokenMint) {
|
|
7655
7194
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
|
7656
|
-
accountMetas.push({
|
|
7657
|
-
pubkey: custody.custodyAccount,
|
|
7658
|
-
isSigner: false,
|
|
7659
|
-
isWritable: false,
|
|
7660
|
-
});
|
|
7661
7195
|
accountMetas.push({
|
|
7662
7196
|
pubkey: custody.intOracleAccount,
|
|
7663
7197
|
isSigner: false,
|
|
@@ -7680,6 +7214,7 @@ var PerpetualsClient = (function () {
|
|
|
7680
7214
|
_a.trys.push([1, 3, , 4]);
|
|
7681
7215
|
return [4, this.program.methods
|
|
7682
7216
|
.setInternalCurrentPrice({
|
|
7217
|
+
useCurrentTime: useCurrentTime,
|
|
7683
7218
|
prices: tokenInternalPrices
|
|
7684
7219
|
})
|
|
7685
7220
|
.accounts({
|
|
@@ -7692,9 +7227,9 @@ var PerpetualsClient = (function () {
|
|
|
7692
7227
|
instructions.push(setInternalOraclePrice);
|
|
7693
7228
|
return [3, 4];
|
|
7694
7229
|
case 3:
|
|
7695
|
-
|
|
7696
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
|
7697
|
-
throw
|
|
7230
|
+
err_50 = _a.sent();
|
|
7231
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_50);
|
|
7232
|
+
throw err_50;
|
|
7698
7233
|
case 4: return [2, {
|
|
7699
7234
|
instructions: __spreadArray([], instructions, true),
|
|
7700
7235
|
additionalSigners: additionalSigners
|
|
@@ -7703,7 +7238,7 @@ var PerpetualsClient = (function () {
|
|
|
7703
7238
|
});
|
|
7704
7239
|
}); };
|
|
7705
7240
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
|
7706
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
|
7241
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_51;
|
|
7707
7242
|
return __generator(this, function (_a) {
|
|
7708
7243
|
switch (_a.label) {
|
|
7709
7244
|
case 0:
|
|
@@ -7714,21 +7249,11 @@ var PerpetualsClient = (function () {
|
|
|
7714
7249
|
accountMetas = [];
|
|
7715
7250
|
_loop_2 = function (tokenMint) {
|
|
7716
7251
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
|
7717
|
-
accountMetas.push({
|
|
7718
|
-
pubkey: custody.custodyAccount,
|
|
7719
|
-
isSigner: false,
|
|
7720
|
-
isWritable: false,
|
|
7721
|
-
});
|
|
7722
7252
|
accountMetas.push({
|
|
7723
7253
|
pubkey: custody.intOracleAccount,
|
|
7724
7254
|
isSigner: false,
|
|
7725
7255
|
isWritable: true,
|
|
7726
7256
|
});
|
|
7727
|
-
accountMetas.push({
|
|
7728
|
-
pubkey: custody.extOracleAccount,
|
|
7729
|
-
isSigner: false,
|
|
7730
|
-
isWritable: false,
|
|
7731
|
-
});
|
|
7732
7257
|
};
|
|
7733
7258
|
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
|
7734
7259
|
tokenMint = tokenMintList_2[_i];
|
|
@@ -7753,9 +7278,9 @@ var PerpetualsClient = (function () {
|
|
|
7753
7278
|
instructions.push(setInternalOraclePrice);
|
|
7754
7279
|
return [3, 4];
|
|
7755
7280
|
case 3:
|
|
7756
|
-
|
|
7757
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
|
7758
|
-
throw
|
|
7281
|
+
err_51 = _a.sent();
|
|
7282
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_51);
|
|
7283
|
+
throw err_51;
|
|
7759
7284
|
case 4: return [2, {
|
|
7760
7285
|
instructions: __spreadArray([], instructions, true),
|
|
7761
7286
|
additionalSigners: additionalSigners
|
|
@@ -7764,7 +7289,7 @@ var PerpetualsClient = (function () {
|
|
|
7764
7289
|
});
|
|
7765
7290
|
}); };
|
|
7766
7291
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7767
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
|
7292
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_52;
|
|
7768
7293
|
return __generator(this, function (_a) {
|
|
7769
7294
|
switch (_a.label) {
|
|
7770
7295
|
case 0:
|
|
@@ -7802,8 +7327,8 @@ var PerpetualsClient = (function () {
|
|
|
7802
7327
|
instructions.push(renameFlp);
|
|
7803
7328
|
return [3, 4];
|
|
7804
7329
|
case 3:
|
|
7805
|
-
|
|
7806
|
-
console.log("perpClient renameFlp error:: ",
|
|
7330
|
+
err_52 = _a.sent();
|
|
7331
|
+
console.log("perpClient renameFlp error:: ", err_52);
|
|
7807
7332
|
return [3, 4];
|
|
7808
7333
|
case 4: return [2, {
|
|
7809
7334
|
instructions: __spreadArray([], instructions, true),
|
|
@@ -7813,7 +7338,7 @@ var PerpetualsClient = (function () {
|
|
|
7813
7338
|
});
|
|
7814
7339
|
}); };
|
|
7815
7340
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7816
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
|
7341
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_53;
|
|
7817
7342
|
return __generator(this, function (_a) {
|
|
7818
7343
|
switch (_a.label) {
|
|
7819
7344
|
case 0:
|
|
@@ -7851,9 +7376,9 @@ var PerpetualsClient = (function () {
|
|
|
7851
7376
|
instructions.push(initStakeInstruction);
|
|
7852
7377
|
return [3, 4];
|
|
7853
7378
|
case 3:
|
|
7854
|
-
|
|
7855
|
-
console.log("perpClient InitStaking error:: ",
|
|
7856
|
-
throw
|
|
7379
|
+
err_53 = _a.sent();
|
|
7380
|
+
console.log("perpClient InitStaking error:: ", err_53);
|
|
7381
|
+
throw err_53;
|
|
7857
7382
|
case 4: return [2, {
|
|
7858
7383
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7859
7384
|
additionalSigners: additionalSigners
|
|
@@ -7862,7 +7387,7 @@ var PerpetualsClient = (function () {
|
|
|
7862
7387
|
});
|
|
7863
7388
|
}); };
|
|
7864
7389
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7865
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction,
|
|
7390
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_54;
|
|
7866
7391
|
return __generator(this, function (_a) {
|
|
7867
7392
|
switch (_a.label) {
|
|
7868
7393
|
case 0:
|
|
@@ -7907,9 +7432,9 @@ var PerpetualsClient = (function () {
|
|
|
7907
7432
|
instructions.push(initCompoundingInstruction);
|
|
7908
7433
|
return [3, 4];
|
|
7909
7434
|
case 3:
|
|
7910
|
-
|
|
7911
|
-
console.log("perpClient initCompounding error:: ",
|
|
7912
|
-
throw
|
|
7435
|
+
err_54 = _a.sent();
|
|
7436
|
+
console.log("perpClient initCompounding error:: ", err_54);
|
|
7437
|
+
throw err_54;
|
|
7913
7438
|
case 4: return [2, {
|
|
7914
7439
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7915
7440
|
additionalSigners: additionalSigners
|
|
@@ -7918,7 +7443,7 @@ var PerpetualsClient = (function () {
|
|
|
7918
7443
|
});
|
|
7919
7444
|
}); };
|
|
7920
7445
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7921
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
|
7446
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_55;
|
|
7922
7447
|
return __generator(this, function (_a) {
|
|
7923
7448
|
switch (_a.label) {
|
|
7924
7449
|
case 0:
|
|
@@ -7959,9 +7484,9 @@ var PerpetualsClient = (function () {
|
|
|
7959
7484
|
instructions.push(initTokenVaultInstruction);
|
|
7960
7485
|
return [3, 4];
|
|
7961
7486
|
case 3:
|
|
7962
|
-
|
|
7963
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
|
7964
|
-
throw
|
|
7487
|
+
err_55 = _a.sent();
|
|
7488
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_55);
|
|
7489
|
+
throw err_55;
|
|
7965
7490
|
case 4: return [2, {
|
|
7966
7491
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7967
7492
|
additionalSigners: additionalSigners
|
|
@@ -7970,7 +7495,7 @@ var PerpetualsClient = (function () {
|
|
|
7970
7495
|
});
|
|
7971
7496
|
}); };
|
|
7972
7497
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7973
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
|
7498
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_56;
|
|
7974
7499
|
return __generator(this, function (_a) {
|
|
7975
7500
|
switch (_a.label) {
|
|
7976
7501
|
case 0:
|
|
@@ -8001,9 +7526,9 @@ var PerpetualsClient = (function () {
|
|
|
8001
7526
|
instructions.push(setTokenVaultConfigInstruction);
|
|
8002
7527
|
return [3, 4];
|
|
8003
7528
|
case 3:
|
|
8004
|
-
|
|
8005
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
|
8006
|
-
throw
|
|
7529
|
+
err_56 = _a.sent();
|
|
7530
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_56);
|
|
7531
|
+
throw err_56;
|
|
8007
7532
|
case 4: return [2, {
|
|
8008
7533
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8009
7534
|
additionalSigners: additionalSigners
|
|
@@ -8012,7 +7537,7 @@ var PerpetualsClient = (function () {
|
|
|
8012
7537
|
});
|
|
8013
7538
|
}); };
|
|
8014
7539
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8015
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
|
7540
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_57;
|
|
8016
7541
|
return __generator(this, function (_a) {
|
|
8017
7542
|
switch (_a.label) {
|
|
8018
7543
|
case 0:
|
|
@@ -8051,9 +7576,59 @@ var PerpetualsClient = (function () {
|
|
|
8051
7576
|
instructions.push(withdrawInstantFeeInstruction);
|
|
8052
7577
|
return [3, 6];
|
|
8053
7578
|
case 5:
|
|
8054
|
-
|
|
8055
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
|
8056
|
-
throw
|
|
7579
|
+
err_57 = _a.sent();
|
|
7580
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
|
|
7581
|
+
throw err_57;
|
|
7582
|
+
case 6: return [2, {
|
|
7583
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7584
|
+
additionalSigners: additionalSigners
|
|
7585
|
+
}];
|
|
7586
|
+
}
|
|
7587
|
+
});
|
|
7588
|
+
}); };
|
|
7589
|
+
this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7590
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_58;
|
|
7591
|
+
return __generator(this, function (_a) {
|
|
7592
|
+
switch (_a.label) {
|
|
7593
|
+
case 0:
|
|
7594
|
+
publicKey = this.provider.wallet.publicKey;
|
|
7595
|
+
preInstructions = [];
|
|
7596
|
+
instructions = [];
|
|
7597
|
+
postInstructions = [];
|
|
7598
|
+
additionalSigners = [];
|
|
7599
|
+
_a.label = 1;
|
|
7600
|
+
case 1:
|
|
7601
|
+
_a.trys.push([1, 5, , 6]);
|
|
7602
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7603
|
+
case 2:
|
|
7604
|
+
receivingTokenAccount = _a.sent();
|
|
7605
|
+
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
7606
|
+
case 3:
|
|
7607
|
+
if (!(_a.sent())) {
|
|
7608
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7609
|
+
}
|
|
7610
|
+
return [4, this.program.methods
|
|
7611
|
+
.withdrawUnclaimedTokens({})
|
|
7612
|
+
.accounts({
|
|
7613
|
+
admin: publicKey,
|
|
7614
|
+
multisig: this.multisig.publicKey,
|
|
7615
|
+
perpetuals: this.perpetuals.publicKey,
|
|
7616
|
+
transferAuthority: poolConfig.transferAuthority,
|
|
7617
|
+
tokenVault: poolConfig.tokenVault,
|
|
7618
|
+
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
7619
|
+
receivingTokenAccount: receivingTokenAccount,
|
|
7620
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
7621
|
+
receivingTokenMint: poolConfig.tokenMint,
|
|
7622
|
+
})
|
|
7623
|
+
.instruction()];
|
|
7624
|
+
case 4:
|
|
7625
|
+
withdrawUnclaimedTokensInstruction = _a.sent();
|
|
7626
|
+
instructions.push(withdrawUnclaimedTokensInstruction);
|
|
7627
|
+
return [3, 6];
|
|
7628
|
+
case 5:
|
|
7629
|
+
err_58 = _a.sent();
|
|
7630
|
+
console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
|
|
7631
|
+
throw err_58;
|
|
8057
7632
|
case 6: return [2, {
|
|
8058
7633
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8059
7634
|
additionalSigners: additionalSigners
|
|
@@ -8062,7 +7637,7 @@ var PerpetualsClient = (function () {
|
|
|
8062
7637
|
});
|
|
8063
7638
|
}); };
|
|
8064
7639
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8065
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
|
7640
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_59;
|
|
8066
7641
|
return __generator(this, function (_a) {
|
|
8067
7642
|
switch (_a.label) {
|
|
8068
7643
|
case 0:
|
|
@@ -8099,9 +7674,9 @@ var PerpetualsClient = (function () {
|
|
|
8099
7674
|
instructions.push(initRevenueTokenAccountInstruction);
|
|
8100
7675
|
return [3, 4];
|
|
8101
7676
|
case 3:
|
|
8102
|
-
|
|
8103
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
|
8104
|
-
throw
|
|
7677
|
+
err_59 = _a.sent();
|
|
7678
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_59);
|
|
7679
|
+
throw err_59;
|
|
8105
7680
|
case 4: return [2, {
|
|
8106
7681
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8107
7682
|
additionalSigners: additionalSigners
|
|
@@ -8110,7 +7685,7 @@ var PerpetualsClient = (function () {
|
|
|
8110
7685
|
});
|
|
8111
7686
|
}); };
|
|
8112
7687
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8113
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
|
7688
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_60;
|
|
8114
7689
|
return __generator(this, function (_a) {
|
|
8115
7690
|
switch (_a.label) {
|
|
8116
7691
|
case 0:
|
|
@@ -8149,9 +7724,9 @@ var PerpetualsClient = (function () {
|
|
|
8149
7724
|
instructions.push(distributeTokenRewardInstruction);
|
|
8150
7725
|
return [3, 4];
|
|
8151
7726
|
case 3:
|
|
8152
|
-
|
|
8153
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
|
8154
|
-
throw
|
|
7727
|
+
err_60 = _a.sent();
|
|
7728
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_60);
|
|
7729
|
+
throw err_60;
|
|
8155
7730
|
case 4: return [2, {
|
|
8156
7731
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8157
7732
|
additionalSigners: additionalSigners
|
|
@@ -8160,7 +7735,7 @@ var PerpetualsClient = (function () {
|
|
|
8160
7735
|
});
|
|
8161
7736
|
}); };
|
|
8162
7737
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
|
8163
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
|
7738
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_61;
|
|
8164
7739
|
return __generator(this, function (_a) {
|
|
8165
7740
|
switch (_a.label) {
|
|
8166
7741
|
case 0:
|
|
@@ -8188,9 +7763,9 @@ var PerpetualsClient = (function () {
|
|
|
8188
7763
|
instructions.push(setTokenStakeLevelInstruction);
|
|
8189
7764
|
return [3, 4];
|
|
8190
7765
|
case 3:
|
|
8191
|
-
|
|
8192
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
|
8193
|
-
throw
|
|
7766
|
+
err_61 = _a.sent();
|
|
7767
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_61);
|
|
7768
|
+
throw err_61;
|
|
8194
7769
|
case 4: return [2, {
|
|
8195
7770
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8196
7771
|
additionalSigners: additionalSigners
|
|
@@ -8199,7 +7774,7 @@ var PerpetualsClient = (function () {
|
|
|
8199
7774
|
});
|
|
8200
7775
|
}); };
|
|
8201
7776
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8202
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
|
7777
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_62;
|
|
8203
7778
|
return __generator(this, function (_a) {
|
|
8204
7779
|
switch (_a.label) {
|
|
8205
7780
|
case 0:
|
|
@@ -8231,9 +7806,49 @@ var PerpetualsClient = (function () {
|
|
|
8231
7806
|
instructions.push(setTokenRewardInstruction);
|
|
8232
7807
|
return [3, 4];
|
|
8233
7808
|
case 3:
|
|
8234
|
-
|
|
8235
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
|
8236
|
-
throw
|
|
7809
|
+
err_62 = _a.sent();
|
|
7810
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_62);
|
|
7811
|
+
throw err_62;
|
|
7812
|
+
case 4: return [2, {
|
|
7813
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7814
|
+
additionalSigners: additionalSigners
|
|
7815
|
+
}];
|
|
7816
|
+
}
|
|
7817
|
+
});
|
|
7818
|
+
}); };
|
|
7819
|
+
this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
|
|
7820
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_63;
|
|
7821
|
+
return __generator(this, function (_a) {
|
|
7822
|
+
switch (_a.label) {
|
|
7823
|
+
case 0:
|
|
7824
|
+
publicKey = this.provider.wallet.publicKey;
|
|
7825
|
+
preInstructions = [];
|
|
7826
|
+
instructions = [];
|
|
7827
|
+
postInstructions = [];
|
|
7828
|
+
additionalSigners = [];
|
|
7829
|
+
_a.label = 1;
|
|
7830
|
+
case 1:
|
|
7831
|
+
_a.trys.push([1, 3, , 4]);
|
|
7832
|
+
return [4, this.program.methods
|
|
7833
|
+
.resizeInternalOracle({
|
|
7834
|
+
extOracle: extOracle
|
|
7835
|
+
})
|
|
7836
|
+
.accounts({
|
|
7837
|
+
admin: publicKey,
|
|
7838
|
+
multisig: this.multisig.publicKey,
|
|
7839
|
+
custodyTokenMint: tokenMint,
|
|
7840
|
+
intOracleAccount: intOracleAccount,
|
|
7841
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
7842
|
+
})
|
|
7843
|
+
.instruction()];
|
|
7844
|
+
case 2:
|
|
7845
|
+
resizeInternalOracleInstruction = _a.sent();
|
|
7846
|
+
instructions.push(resizeInternalOracleInstruction);
|
|
7847
|
+
return [3, 4];
|
|
7848
|
+
case 3:
|
|
7849
|
+
err_63 = _a.sent();
|
|
7850
|
+
console.log("perpClient resizeInternalOracleInstruction error:: ", err_63);
|
|
7851
|
+
throw err_63;
|
|
8237
7852
|
case 4: return [2, {
|
|
8238
7853
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8239
7854
|
additionalSigners: additionalSigners
|