flash-sdk 9.0.0-alpha.2 → 9.0.0-alpha.20
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 +208 -109
- package/dist/PerpetualsClient.js +611 -999
- package/dist/PoolConfig.d.ts +5 -1
- package/dist/PoolConfig.js +4 -2
- package/dist/PoolConfig.json +94 -3160
- package/dist/PositionAccount.d.ts +3 -2
- package/dist/idl/perpetuals.d.ts +3177 -1367
- package/dist/idl/perpetuals.js +3177 -1367
- 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,11 +1083,11 @@ 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);
|
|
@@ -1168,35 +1112,34 @@ var PerpetualsClient = (function () {
|
|
|
1168
1112
|
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
|
1169
1113
|
}
|
|
1170
1114
|
else {
|
|
1171
|
-
maxWithdrawableAmount =
|
|
1115
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(updatedMaxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
|
1172
1116
|
maxWithdrawableAmountUsd = updatedMaxRemovableCollateralUsd;
|
|
1173
1117
|
}
|
|
1174
1118
|
}
|
|
1175
1119
|
else {
|
|
1176
|
-
maxWithdrawableAmount =
|
|
1120
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
|
1177
1121
|
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
|
1178
1122
|
}
|
|
1179
1123
|
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd, diff: diff };
|
|
1180
1124
|
};
|
|
1181
|
-
this.
|
|
1125
|
+
this.getFinalCloseAmountUsdSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
|
|
1182
1126
|
var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
|
1183
1127
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1184
|
-
var collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, collateralCustodyAccount.decimals);
|
|
1185
1128
|
var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1186
1129
|
var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
|
|
1187
1130
|
var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
|
|
1188
1131
|
var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
|
|
1189
|
-
var assetsUsd = newPnl.profitUsd.add(collateralMinMaxPrice.
|
|
1190
|
-
var
|
|
1132
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
|
|
1133
|
+
var closeAmountUsd, feesAmountUsd;
|
|
1191
1134
|
if (assetsUsd.gt(liabilityUsd)) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1135
|
+
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
|
1136
|
+
feesAmountUsd = totalFeesUsd;
|
|
1194
1137
|
}
|
|
1195
1138
|
else {
|
|
1196
|
-
|
|
1197
|
-
|
|
1139
|
+
closeAmountUsd = constants_1.BN_ZERO;
|
|
1140
|
+
feesAmountUsd = assetsUsd.sub(newPnl.lossUsd);
|
|
1198
1141
|
}
|
|
1199
|
-
return {
|
|
1142
|
+
return { closeAmountUsd: closeAmountUsd, feesAmountUsd: feesAmountUsd };
|
|
1200
1143
|
};
|
|
1201
1144
|
this.getMaxWithdrawableAmountSync = function (positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, errorBandwidthPercentageUi) {
|
|
1202
1145
|
if (errorBandwidthPercentageUi === void 0) { errorBandwidthPercentageUi = 5; }
|
|
@@ -1212,11 +1155,11 @@ var PerpetualsClient = (function () {
|
|
|
1212
1155
|
return { maxWithdrawableAmount: constants_1.BN_ZERO, maxWithdrawableAmountUsd: constants_1.BN_ZERO };
|
|
1213
1156
|
}
|
|
1214
1157
|
var profitLoss = _this.getPnlSync(positionAccount, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1215
|
-
var
|
|
1158
|
+
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1216
1159
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1217
1160
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
1218
1161
|
var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
|
1219
|
-
var currentCollateralUsd =
|
|
1162
|
+
var currentCollateralUsd = positionAccount.collateralUsd;
|
|
1220
1163
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
|
1221
1164
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
|
1222
1165
|
availableInitMarginUsd = currentCollateralUsd.sub(lossUsd);
|
|
@@ -1232,11 +1175,11 @@ var PerpetualsClient = (function () {
|
|
|
1232
1175
|
var maxWithdrawableAmount;
|
|
1233
1176
|
var maxWithdrawableAmountUsd = constants_1.BN_ZERO;
|
|
1234
1177
|
if (maxRemoveableCollateralUsdAfterMinRequired.lt(maxRemovableCollateralUsd)) {
|
|
1235
|
-
maxWithdrawableAmount =
|
|
1178
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemoveableCollateralUsdAfterMinRequired, collateralCustodyAccount.decimals);
|
|
1236
1179
|
maxWithdrawableAmountUsd = maxRemoveableCollateralUsdAfterMinRequired;
|
|
1237
1180
|
}
|
|
1238
1181
|
else {
|
|
1239
|
-
maxWithdrawableAmount =
|
|
1182
|
+
maxWithdrawableAmount = collateralMinMaxPrice.max.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
|
1240
1183
|
maxWithdrawableAmountUsd = maxRemovableCollateralUsd;
|
|
1241
1184
|
}
|
|
1242
1185
|
return { maxWithdrawableAmount: maxWithdrawableAmount, maxWithdrawableAmountUsd: maxWithdrawableAmountUsd };
|
|
@@ -1293,185 +1236,138 @@ var PerpetualsClient = (function () {
|
|
|
1293
1236
|
var lockedUsd = (sideUsd.mul(maxPayOffBpsNew)).div(new anchor_1.BN(constants_1.BPS_POWER));
|
|
1294
1237
|
return lockedUsd;
|
|
1295
1238
|
};
|
|
1296
|
-
this.
|
|
1239
|
+
this.getLiquidationPriceContractHelper = function (entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount) {
|
|
1297
1240
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
|
1298
1241
|
price: constants_1.BN_ZERO,
|
|
1299
1242
|
exponent: constants_1.BN_ZERO,
|
|
1300
1243
|
confidence: constants_1.BN_ZERO,
|
|
1301
1244
|
timestamp: constants_1.BN_ZERO
|
|
1302
1245
|
});
|
|
1303
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
|
1304
|
-
return zeroOraclePrice;
|
|
1305
|
-
}
|
|
1306
1246
|
if (positionAccount.entryPrice.exponent && !entryOraclePrice.exponent.eq(new anchor_1.BN(positionAccount.entryPrice.exponent))) {
|
|
1307
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)));
|
|
1308
1248
|
}
|
|
1309
1249
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1310
1250
|
var unsettledLossUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
|
|
1311
1251
|
var liablitiesUsd = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
|
1312
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
|
1313
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1314
1252
|
var liquidationPrice;
|
|
1315
|
-
if (
|
|
1316
|
-
var
|
|
1317
|
-
|
|
1318
|
-
|
|
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
|
+
});
|
|
1319
1268
|
}
|
|
1320
1269
|
else {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
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
|
+
});
|
|
1324
1276
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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),
|
|
1328
1282
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1329
1283
|
confidence: constants_1.BN_ZERO,
|
|
1330
1284
|
timestamp: constants_1.BN_ZERO
|
|
1331
|
-
});
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
|
1337
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
|
1338
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (positionAccount.sizeDecimals + 3))))
|
|
1339
|
-
.div(positionAccount.sizeAmount),
|
|
1340
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
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),
|
|
1341
1290
|
confidence: constants_1.BN_ZERO,
|
|
1342
1291
|
timestamp: constants_1.BN_ZERO
|
|
1343
|
-
})
|
|
1344
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1345
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1346
|
-
price: entryOraclePrice.price.sub(priceDiffLossOracle.price),
|
|
1347
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1348
|
-
confidence: constants_1.BN_ZERO,
|
|
1349
|
-
timestamp: constants_1.BN_ZERO
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
else {
|
|
1353
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1354
|
-
price: entryOraclePrice.price.add(priceDiffLossOracle.price),
|
|
1355
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1356
|
-
confidence: constants_1.BN_ZERO,
|
|
1357
|
-
timestamp: constants_1.BN_ZERO
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1292
|
+
});
|
|
1360
1293
|
}
|
|
1361
1294
|
else {
|
|
1362
|
-
|
|
1363
|
-
price:
|
|
1364
|
-
|
|
1365
|
-
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),
|
|
1366
1298
|
confidence: constants_1.BN_ZERO,
|
|
1367
1299
|
timestamp: constants_1.BN_ZERO
|
|
1368
|
-
})
|
|
1369
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1370
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1371
|
-
price: entryOraclePrice.price.add(priceDiffProfitOracle.price),
|
|
1372
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1373
|
-
confidence: constants_1.BN_ZERO,
|
|
1374
|
-
timestamp: constants_1.BN_ZERO
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
else {
|
|
1378
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1379
|
-
price: entryOraclePrice.price.sub(priceDiffProfitOracle.price),
|
|
1380
|
-
exponent: new anchor_1.BN(entryOraclePrice.exponent),
|
|
1381
|
-
confidence: constants_1.BN_ZERO,
|
|
1382
|
-
timestamp: constants_1.BN_ZERO
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1300
|
+
});
|
|
1385
1301
|
}
|
|
1386
1302
|
}
|
|
1387
1303
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
|
1388
1304
|
};
|
|
1389
|
-
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) {
|
|
1390
1313
|
var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
|
|
1391
1314
|
price: constants_1.BN_ZERO,
|
|
1392
1315
|
exponent: constants_1.BN_ZERO,
|
|
1393
1316
|
confidence: constants_1.BN_ZERO,
|
|
1394
1317
|
timestamp: constants_1.BN_ZERO
|
|
1395
1318
|
});
|
|
1396
|
-
if (collateralAmount.isZero() || sizeAmount.isZero()) {
|
|
1397
|
-
return zeroOraclePrice;
|
|
1398
|
-
}
|
|
1399
1319
|
var exitFeeUsd = sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1400
1320
|
var unsettledLossUsd = exitFeeUsd;
|
|
1401
1321
|
var liablitiesUsd = sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(new anchor_1.BN(targetCustodyAccount.pricing.maxLeverage)).add(unsettledLossUsd);
|
|
1402
|
-
var targetMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount);
|
|
1403
|
-
var collateralMinMaxPriceOracle = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1404
1322
|
var liquidationPrice;
|
|
1405
|
-
if (
|
|
1406
|
-
var
|
|
1407
|
-
|
|
1408
|
-
|
|
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
|
+
});
|
|
1409
1338
|
}
|
|
1410
1339
|
else {
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
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
|
+
});
|
|
1414
1346
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
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),
|
|
1418
1352
|
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
1419
1353
|
confidence: constants_1.BN_ZERO,
|
|
1420
1354
|
timestamp: constants_1.BN_ZERO
|
|
1421
|
-
});
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
if (assetsUsd.gte(liablitiesUsd)) {
|
|
1427
|
-
var priceDiffLossOracle = OraclePrice_1.OraclePrice.from({
|
|
1428
|
-
price: (assetsUsd.sub(liablitiesUsd)).mul(new anchor_1.BN(Math.pow(10, (sizeDecimals + 3))))
|
|
1429
|
-
.div(sizeAmount),
|
|
1430
|
-
exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
|
|
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),
|
|
1431
1360
|
confidence: constants_1.BN_ZERO,
|
|
1432
1361
|
timestamp: constants_1.BN_ZERO
|
|
1433
|
-
})
|
|
1434
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1435
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1436
|
-
price: limitOraclePrice.price.sub(priceDiffLossOracle.price),
|
|
1437
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1438
|
-
confidence: constants_1.BN_ZERO,
|
|
1439
|
-
timestamp: constants_1.BN_ZERO
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
else {
|
|
1443
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1444
|
-
price: limitOraclePrice.price.add(priceDiffLossOracle.price),
|
|
1445
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1446
|
-
confidence: constants_1.BN_ZERO,
|
|
1447
|
-
timestamp: constants_1.BN_ZERO
|
|
1448
|
-
});
|
|
1449
|
-
}
|
|
1362
|
+
});
|
|
1450
1363
|
}
|
|
1451
1364
|
else {
|
|
1452
|
-
|
|
1453
|
-
price:
|
|
1454
|
-
|
|
1455
|
-
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),
|
|
1456
1368
|
confidence: constants_1.BN_ZERO,
|
|
1457
1369
|
timestamp: constants_1.BN_ZERO
|
|
1458
|
-
})
|
|
1459
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
|
1460
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1461
|
-
price: limitOraclePrice.price.add(priceDiffProfitOracle.price),
|
|
1462
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1463
|
-
confidence: constants_1.BN_ZERO,
|
|
1464
|
-
timestamp: constants_1.BN_ZERO
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
else {
|
|
1468
|
-
liquidationPrice = OraclePrice_1.OraclePrice.from({
|
|
1469
|
-
price: limitOraclePrice.price.sub(priceDiffProfitOracle.price),
|
|
1470
|
-
exponent: new anchor_1.BN(limitOraclePrice.exponent),
|
|
1471
|
-
confidence: constants_1.BN_ZERO,
|
|
1472
|
-
timestamp: constants_1.BN_ZERO
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1370
|
+
});
|
|
1475
1371
|
}
|
|
1476
1372
|
}
|
|
1477
1373
|
return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
|
|
@@ -1547,8 +1443,8 @@ var PerpetualsClient = (function () {
|
|
|
1547
1443
|
positionAccount.market = marketAccountPk;
|
|
1548
1444
|
positionAccount.lockedUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
|
|
1549
1445
|
positionAccount.lockedAmount = collateralPrice.getTokenAmount(positionAccount.lockedUsd, collateralCustodyAccount.decimals);
|
|
1550
|
-
|
|
1551
|
-
positionAccount.collateralUsd =
|
|
1446
|
+
var collateralDeltaUsd = collateralPrice.getAssetAmountUsd(collateralDeltaAmount, collateralCustodyAccount.decimals);
|
|
1447
|
+
positionAccount.collateralUsd = positionAccount.collateralUsd.add(collateralDeltaUsd);
|
|
1552
1448
|
var currentTime = new anchor_1.BN((0, utils_1.getUnixTs)());
|
|
1553
1449
|
var pnl = _this.getPnlSync(positionAccount, userEntrytpSlOraclePrice, userEntrytpSlOraclePrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTime, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1554
1450
|
var pnlUsd = pnl.profitUsd.sub(pnl.lossUsd);
|
|
@@ -1620,6 +1516,9 @@ var PerpetualsClient = (function () {
|
|
|
1620
1516
|
});
|
|
1621
1517
|
};
|
|
1622
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) {
|
|
1623
1522
|
if (positionAccount.sizeUsd.isZero() || positionAccount.entryPrice.price.isZero()) {
|
|
1624
1523
|
return {
|
|
1625
1524
|
profitUsd: constants_1.BN_ZERO,
|
|
@@ -1678,7 +1577,7 @@ var PerpetualsClient = (function () {
|
|
|
1678
1577
|
}
|
|
1679
1578
|
if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
|
|
1680
1579
|
return {
|
|
1681
|
-
profitUsd:
|
|
1580
|
+
profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
|
|
1682
1581
|
lossUsd: constants_1.BN_ZERO,
|
|
1683
1582
|
};
|
|
1684
1583
|
}
|
|
@@ -1769,6 +1668,9 @@ var PerpetualsClient = (function () {
|
|
|
1769
1668
|
}
|
|
1770
1669
|
};
|
|
1771
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) {
|
|
1772
1674
|
var poolAmountUsd = constants_1.BN_ZERO;
|
|
1773
1675
|
for (var index = 0; index < custodies.length; index++) {
|
|
1774
1676
|
if (custodies.length != poolAccount.custodies.length || !custodies[index].publicKey.equals(poolAccount.custodies[index])) {
|
|
@@ -1781,6 +1683,7 @@ var PerpetualsClient = (function () {
|
|
|
1781
1683
|
var token_amount_usd = tokenMinMaxPrice.max.getAssetAmountUsd(custodies[index].assets.owned, custodies[index].decimals);
|
|
1782
1684
|
poolAmountUsd = poolAmountUsd.add(token_amount_usd);
|
|
1783
1685
|
}
|
|
1686
|
+
poolAmountUsd = poolAmountUsd.sub(poolAccount.feesObligationUsd.add(poolAccount.rebateObligationUsd));
|
|
1784
1687
|
if (aumCalcMode === "includePnl") {
|
|
1785
1688
|
var poolEquityUsd = poolAmountUsd;
|
|
1786
1689
|
for (var index = 0; index < markets.length; index++) {
|
|
@@ -1790,11 +1693,12 @@ var PerpetualsClient = (function () {
|
|
|
1790
1693
|
var targetCustodyId = poolAccount.getCustodyId(markets[index].targetCustody);
|
|
1791
1694
|
var collateralCustodyId = poolAccount.getCustodyId(markets[index].collateralCustody);
|
|
1792
1695
|
var position = markets[index].getCollectivePosition();
|
|
1696
|
+
poolEquityUsd = poolEquityUsd.sub(position.collateralUsd);
|
|
1793
1697
|
var collectivePnl = _this.getPnlSync(position, tokenPrices[targetCustodyId], tokenEmaPrices[targetCustodyId], custodies[targetCustodyId], tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId], currentTime, custodies[targetCustodyId].pricing.delaySeconds, poolConfig);
|
|
1794
1698
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[collateralCustodyId], tokenEmaPrices[collateralCustodyId], custodies[collateralCustodyId]);
|
|
1795
|
-
var
|
|
1796
|
-
var
|
|
1797
|
-
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);
|
|
1798
1702
|
}
|
|
1799
1703
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: poolEquityUsd };
|
|
1800
1704
|
}
|
|
@@ -1802,14 +1706,6 @@ var PerpetualsClient = (function () {
|
|
|
1802
1706
|
return { poolAmountUsd: poolAmountUsd, poolEquityUsd: constants_1.BN_ZERO };
|
|
1803
1707
|
}
|
|
1804
1708
|
};
|
|
1805
|
-
this.getNftFinalDiscount = function (perpetualsAccount, nftTradingAccount, currentTime) {
|
|
1806
|
-
if (currentTime.sub(nftTradingAccount.timestamp).lt(constants_1.DAY_SECONDS) && nftTradingAccount.counter.gt(new anchor_1.BN(perpetualsAccount.tradeLimit))) {
|
|
1807
|
-
return { discountBn: constants_1.BN_ZERO };
|
|
1808
|
-
}
|
|
1809
|
-
else {
|
|
1810
|
-
return { discountBn: perpetualsAccount.tradingDiscount[nftTradingAccount.level - 1] };
|
|
1811
|
-
}
|
|
1812
|
-
};
|
|
1813
1709
|
this.getFeeDiscount = function (perpetualsAccount, tokenStakeAccount, currentTime) {
|
|
1814
1710
|
if (tokenStakeAccount.level === 0) {
|
|
1815
1711
|
return { discountBn: constants_1.BN_ZERO };
|
|
@@ -1894,7 +1790,7 @@ var PerpetualsClient = (function () {
|
|
|
1894
1790
|
});
|
|
1895
1791
|
};
|
|
1896
1792
|
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
|
1897
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
|
|
1793
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
|
|
1898
1794
|
var _d;
|
|
1899
1795
|
return __generator(this, function (_e) {
|
|
1900
1796
|
switch (_e.label) {
|
|
@@ -1942,6 +1838,8 @@ var PerpetualsClient = (function () {
|
|
|
1942
1838
|
return [4, backUpOracleInstructionPromise];
|
|
1943
1839
|
case 2:
|
|
1944
1840
|
backUpOracleInstruction = _e.sent();
|
|
1841
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
1842
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
1945
1843
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
|
1946
1844
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
|
1947
1845
|
case 3:
|
|
@@ -2008,7 +1906,7 @@ var PerpetualsClient = (function () {
|
|
|
2008
1906
|
args_1[_i - 4] = arguments[_i];
|
|
2009
1907
|
}
|
|
2010
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) {
|
|
2011
|
-
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;
|
|
2012
1910
|
var _e;
|
|
2013
1911
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2014
1912
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2059,6 +1957,8 @@ var PerpetualsClient = (function () {
|
|
|
2059
1957
|
.transaction()];
|
|
2060
1958
|
case 1:
|
|
2061
1959
|
transaction = _f.sent();
|
|
1960
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
1961
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2062
1962
|
if (!enableBackupOracle) return [3, 3];
|
|
2063
1963
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2064
1964
|
case 2:
|
|
@@ -2068,6 +1968,14 @@ var PerpetualsClient = (function () {
|
|
|
2068
1968
|
case 3: return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
|
2069
1969
|
case 4:
|
|
2070
1970
|
result = _f.sent();
|
|
1971
|
+
if (result.value.err) {
|
|
1972
|
+
console.error('error Simulation failed:::', result);
|
|
1973
|
+
return [2, {
|
|
1974
|
+
amount: undefined,
|
|
1975
|
+
fee: undefined,
|
|
1976
|
+
error: 'Simulation failed: ' + JSON.stringify(result.value.err),
|
|
1977
|
+
}];
|
|
1978
|
+
}
|
|
2071
1979
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
|
2072
1980
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
|
2073
1981
|
return [2, {
|
|
@@ -2084,7 +1992,7 @@ var PerpetualsClient = (function () {
|
|
|
2084
1992
|
args_1[_i - 4] = arguments[_i];
|
|
2085
1993
|
}
|
|
2086
1994
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2087
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
|
1995
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2088
1996
|
var _e;
|
|
2089
1997
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2090
1998
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2135,6 +2043,8 @@ var PerpetualsClient = (function () {
|
|
|
2135
2043
|
.transaction()];
|
|
2136
2044
|
case 1:
|
|
2137
2045
|
transaction = _f.sent();
|
|
2046
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2047
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2138
2048
|
if (!enableBackupOracle) return [3, 3];
|
|
2139
2049
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2140
2050
|
case 2:
|
|
@@ -2146,9 +2056,11 @@ var PerpetualsClient = (function () {
|
|
|
2146
2056
|
result = _f.sent();
|
|
2147
2057
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
|
2148
2058
|
if (result.value.err) {
|
|
2059
|
+
console.error('error Simulation failed:', result);
|
|
2149
2060
|
return [2, {
|
|
2150
|
-
amount:
|
|
2151
|
-
fee:
|
|
2061
|
+
amount: undefined,
|
|
2062
|
+
fee: undefined,
|
|
2063
|
+
error: 'Simulation failed: ' + JSON.stringify(result.value.err),
|
|
2152
2064
|
}];
|
|
2153
2065
|
}
|
|
2154
2066
|
res = this.viewHelper.decodeLogs(result, index, 'getRemoveLiquidityAmountAndFee');
|
|
@@ -2161,7 +2073,7 @@ var PerpetualsClient = (function () {
|
|
|
2161
2073
|
});
|
|
2162
2074
|
};
|
|
2163
2075
|
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
|
2164
|
-
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
|
|
2076
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
|
|
2165
2077
|
var _d;
|
|
2166
2078
|
return __generator(this, function (_e) {
|
|
2167
2079
|
switch (_e.label) {
|
|
@@ -2209,6 +2121,8 @@ var PerpetualsClient = (function () {
|
|
|
2209
2121
|
.transaction()];
|
|
2210
2122
|
case 2:
|
|
2211
2123
|
transaction = _e.sent();
|
|
2124
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2125
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2212
2126
|
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
|
2213
2127
|
return [4, this.viewHelper.simulateTransaction(transaction)];
|
|
2214
2128
|
case 3:
|
|
@@ -2225,7 +2139,7 @@ var PerpetualsClient = (function () {
|
|
|
2225
2139
|
args_1[_i - 4] = arguments[_i];
|
|
2226
2140
|
}
|
|
2227
2141
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2228
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
|
2142
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2229
2143
|
var _e;
|
|
2230
2144
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2231
2145
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2280,6 +2194,8 @@ var PerpetualsClient = (function () {
|
|
|
2280
2194
|
.transaction()];
|
|
2281
2195
|
case 1:
|
|
2282
2196
|
transaction = _f.sent();
|
|
2197
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2198
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2283
2199
|
if (!enableBackupOracle) return [3, 3];
|
|
2284
2200
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2285
2201
|
case 2:
|
|
@@ -2305,7 +2221,7 @@ var PerpetualsClient = (function () {
|
|
|
2305
2221
|
args_1[_i - 4] = arguments[_i];
|
|
2306
2222
|
}
|
|
2307
2223
|
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey, enableBackupOracle) {
|
|
2308
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, backUpOracleInstruction, result, index, res;
|
|
2224
|
+
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
|
|
2309
2225
|
var _e;
|
|
2310
2226
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
2311
2227
|
if (enableBackupOracle === void 0) { enableBackupOracle = false; }
|
|
@@ -2360,6 +2276,8 @@ var PerpetualsClient = (function () {
|
|
|
2360
2276
|
.transaction()];
|
|
2361
2277
|
case 1:
|
|
2362
2278
|
transaction = _f.sent();
|
|
2279
|
+
setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
|
|
2280
|
+
transaction.instructions.unshift(setCULimitIx);
|
|
2363
2281
|
if (!enableBackupOracle) return [3, 3];
|
|
2364
2282
|
return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
|
|
2365
2283
|
case 2:
|
|
@@ -2554,11 +2472,10 @@ var PerpetualsClient = (function () {
|
|
|
2554
2472
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
2555
2473
|
args_1[_i - 8] = arguments[_i];
|
|
2556
2474
|
}
|
|
2557
|
-
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,
|
|
2475
|
+
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) {
|
|
2558
2476
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
|
2559
2477
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2560
2478
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2561
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2562
2479
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
2563
2480
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2564
2481
|
return __generator(this, function (_c) {
|
|
@@ -2651,7 +2568,7 @@ var PerpetualsClient = (function () {
|
|
|
2651
2568
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2652
2569
|
fundingMint: collateralCustodyConfig.mintKey
|
|
2653
2570
|
})
|
|
2654
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2571
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2655
2572
|
.instruction()];
|
|
2656
2573
|
case 7:
|
|
2657
2574
|
instruction = _c.sent();
|
|
@@ -2669,11 +2586,10 @@ var PerpetualsClient = (function () {
|
|
|
2669
2586
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
2670
2587
|
args_1[_i - 6] = arguments[_i];
|
|
2671
2588
|
}
|
|
2672
|
-
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,
|
|
2589
|
+
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) {
|
|
2673
2590
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
|
2674
2591
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2675
2592
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2676
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2677
2593
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
2678
2594
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
2679
2595
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
@@ -2752,7 +2668,7 @@ var PerpetualsClient = (function () {
|
|
|
2752
2668
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
2753
2669
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
2754
2670
|
})
|
|
2755
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2671
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2756
2672
|
.instruction()];
|
|
2757
2673
|
case 6:
|
|
2758
2674
|
instruction = _b.sent();
|
|
@@ -2779,11 +2695,10 @@ var PerpetualsClient = (function () {
|
|
|
2779
2695
|
for (var _i = 9; _i < arguments.length; _i++) {
|
|
2780
2696
|
args_1[_i - 9] = arguments[_i];
|
|
2781
2697
|
}
|
|
2782
|
-
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,
|
|
2783
|
-
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount,
|
|
2698
|
+
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) {
|
|
2699
|
+
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
|
|
2784
2700
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2785
2701
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2786
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2787
2702
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
2788
2703
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2789
2704
|
return __generator(this, function (_c) {
|
|
@@ -2877,14 +2792,7 @@ var PerpetualsClient = (function () {
|
|
|
2877
2792
|
}
|
|
2878
2793
|
_c.label = 10;
|
|
2879
2794
|
case 10:
|
|
2880
|
-
|
|
2881
|
-
pubkey: collateralCustodyConfig.mintKey,
|
|
2882
|
-
isSigner: false,
|
|
2883
|
-
isWritable: false
|
|
2884
|
-
};
|
|
2885
|
-
_c.label = 11;
|
|
2886
|
-
case 11:
|
|
2887
|
-
_c.trys.push([11, 13, , 14]);
|
|
2795
|
+
_c.trys.push([10, 12, , 13]);
|
|
2888
2796
|
return [4, this.program.methods
|
|
2889
2797
|
.swapAndOpen({
|
|
2890
2798
|
amountIn: amountIn,
|
|
@@ -2918,17 +2826,17 @@ var PerpetualsClient = (function () {
|
|
|
2918
2826
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
2919
2827
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
2920
2828
|
})
|
|
2921
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2829
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2922
2830
|
.instruction()];
|
|
2923
|
-
case
|
|
2831
|
+
case 11:
|
|
2924
2832
|
inx = _c.sent();
|
|
2925
2833
|
instructions.push(inx);
|
|
2926
|
-
return [3,
|
|
2927
|
-
case
|
|
2834
|
+
return [3, 13];
|
|
2835
|
+
case 12:
|
|
2928
2836
|
err_3 = _c.sent();
|
|
2929
2837
|
console.error("perpClient SwapAndOpen error:: ", err_3);
|
|
2930
2838
|
throw err_3;
|
|
2931
|
-
case
|
|
2839
|
+
case 13: return [2, {
|
|
2932
2840
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
2933
2841
|
additionalSigners: additionalSigners
|
|
2934
2842
|
}];
|
|
@@ -2936,16 +2844,15 @@ var PerpetualsClient = (function () {
|
|
|
2936
2844
|
});
|
|
2937
2845
|
});
|
|
2938
2846
|
};
|
|
2939
|
-
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
|
2847
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
|
2940
2848
|
var args_1 = [];
|
|
2941
|
-
for (var _i =
|
|
2942
|
-
args_1[_i -
|
|
2849
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
|
2850
|
+
args_1[_i - 7] = arguments[_i];
|
|
2943
2851
|
}
|
|
2944
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1,
|
|
2945
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount,
|
|
2852
|
+
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) {
|
|
2853
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, inx, err_4;
|
|
2946
2854
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2947
2855
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2948
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
2949
2856
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2950
2857
|
return __generator(this, function (_a) {
|
|
2951
2858
|
switch (_a.label) {
|
|
@@ -3011,18 +2918,12 @@ var PerpetualsClient = (function () {
|
|
|
3011
2918
|
if (!(_a.sent())) {
|
|
3012
2919
|
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));
|
|
3013
2920
|
}
|
|
3014
|
-
rebateMintAccount = {
|
|
3015
|
-
pubkey: collateralCustodyConfig.mintKey,
|
|
3016
|
-
isSigner: false,
|
|
3017
|
-
isWritable: false
|
|
3018
|
-
};
|
|
3019
2921
|
_a.label = 5;
|
|
3020
2922
|
case 5:
|
|
3021
2923
|
_a.trys.push([5, 7, , 8]);
|
|
3022
2924
|
return [4, this.program.methods
|
|
3023
2925
|
.closeAndSwap({
|
|
3024
2926
|
priceWithSlippage: priceWithSlippage,
|
|
3025
|
-
minSwapAmountOut: minSwapAmountOut,
|
|
3026
2927
|
privilege: privilege
|
|
3027
2928
|
})
|
|
3028
2929
|
.accounts({
|
|
@@ -3051,7 +2952,7 @@ var PerpetualsClient = (function () {
|
|
|
3051
2952
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
3052
2953
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
3053
2954
|
})
|
|
3054
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
2955
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3055
2956
|
.instruction()];
|
|
3056
2957
|
case 6:
|
|
3057
2958
|
inx = _a.sent();
|
|
@@ -3509,11 +3410,10 @@ var PerpetualsClient = (function () {
|
|
|
3509
3410
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3510
3411
|
args_1[_i - 8] = arguments[_i];
|
|
3511
3412
|
}
|
|
3512
|
-
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
|
|
3413
|
+
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) {
|
|
3513
3414
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3514
3415
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3515
3416
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3516
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
3517
3417
|
return __generator(this, function (_a) {
|
|
3518
3418
|
switch (_a.label) {
|
|
3519
3419
|
case 0:
|
|
@@ -3556,7 +3456,7 @@ var PerpetualsClient = (function () {
|
|
|
3556
3456
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3557
3457
|
collateralMint: collateralCustodyConfig.mintKey
|
|
3558
3458
|
})
|
|
3559
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
3459
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3560
3460
|
.instruction()];
|
|
3561
3461
|
case 1:
|
|
3562
3462
|
instruction = _a.sent();
|
|
@@ -3574,11 +3474,10 @@ var PerpetualsClient = (function () {
|
|
|
3574
3474
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3575
3475
|
args_1[_i - 8] = arguments[_i];
|
|
3576
3476
|
}
|
|
3577
|
-
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
|
|
3477
|
+
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) {
|
|
3578
3478
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3579
3479
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3580
3480
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3581
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
3582
3481
|
return __generator(this, function (_a) {
|
|
3583
3482
|
switch (_a.label) {
|
|
3584
3483
|
case 0:
|
|
@@ -3621,7 +3520,7 @@ var PerpetualsClient = (function () {
|
|
|
3621
3520
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3622
3521
|
collateralMint: collateralCustodyConfig.mintKey
|
|
3623
3522
|
})
|
|
3624
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
3523
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3625
3524
|
.instruction()];
|
|
3626
3525
|
case 1:
|
|
3627
3526
|
instruction = _a.sent();
|
|
@@ -4088,119 +3987,8 @@ var PerpetualsClient = (function () {
|
|
|
4088
3987
|
}
|
|
4089
3988
|
});
|
|
4090
3989
|
}); };
|
|
4091
|
-
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
4092
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
|
4093
|
-
return __generator(this, function (_a) {
|
|
4094
|
-
switch (_a.label) {
|
|
4095
|
-
case 0:
|
|
4096
|
-
publicKey = this.provider.wallet.publicKey;
|
|
4097
|
-
preInstructions = [];
|
|
4098
|
-
instructions = [];
|
|
4099
|
-
postInstructions = [];
|
|
4100
|
-
additionalSigners = [];
|
|
4101
|
-
_a.label = 1;
|
|
4102
|
-
case 1:
|
|
4103
|
-
_a.trys.push([1, 4, , 5]);
|
|
4104
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
4105
|
-
Buffer.from("trading"),
|
|
4106
|
-
nftMint.toBuffer(),
|
|
4107
|
-
], this.programId)[0];
|
|
4108
|
-
nftReferralAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
4109
|
-
Buffer.from("referral"),
|
|
4110
|
-
publicKey.toBuffer(),
|
|
4111
|
-
], this.programId)[0];
|
|
4112
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
|
4113
|
-
case 2:
|
|
4114
|
-
nftTokenAccount = _a.sent();
|
|
4115
|
-
flpStakeAccountMetas = [];
|
|
4116
|
-
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
|
4117
|
-
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
|
4118
|
-
flpStakeAccountMetas.push({
|
|
4119
|
-
pubkey: flpStakeAccountPk,
|
|
4120
|
-
isSigner: false,
|
|
4121
|
-
isWritable: true,
|
|
4122
|
-
});
|
|
4123
|
-
}
|
|
4124
|
-
return [4, this.program.methods
|
|
4125
|
-
.updateTradingAccount({
|
|
4126
|
-
updateReferer: updateReferer,
|
|
4127
|
-
updateBooster: updateBooster
|
|
4128
|
-
})
|
|
4129
|
-
.accounts({
|
|
4130
|
-
owner: publicKey,
|
|
4131
|
-
feePayer: publicKey,
|
|
4132
|
-
nftTokenAccount: nftTokenAccount,
|
|
4133
|
-
referralAccount: nftReferralAccount,
|
|
4134
|
-
tradingAccount: nftTradingAccount
|
|
4135
|
-
})
|
|
4136
|
-
.instruction()];
|
|
4137
|
-
case 3:
|
|
4138
|
-
updateNftTradingAccountInstruction = _a.sent();
|
|
4139
|
-
instructions.push(updateNftTradingAccountInstruction);
|
|
4140
|
-
return [3, 5];
|
|
4141
|
-
case 4:
|
|
4142
|
-
err_8 = _a.sent();
|
|
4143
|
-
console.log("perpClient updateNftAccount error:: ", err_8);
|
|
4144
|
-
throw err_8;
|
|
4145
|
-
case 5: return [2, {
|
|
4146
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4147
|
-
additionalSigners: additionalSigners
|
|
4148
|
-
}];
|
|
4149
|
-
}
|
|
4150
|
-
});
|
|
4151
|
-
}); };
|
|
4152
|
-
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
|
4153
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
|
4154
|
-
return __generator(this, function (_a) {
|
|
4155
|
-
switch (_a.label) {
|
|
4156
|
-
case 0:
|
|
4157
|
-
publicKey = this.provider.wallet.publicKey;
|
|
4158
|
-
preInstructions = [];
|
|
4159
|
-
instructions = [];
|
|
4160
|
-
postInstructions = [];
|
|
4161
|
-
additionalSigners = [];
|
|
4162
|
-
_a.label = 1;
|
|
4163
|
-
case 1:
|
|
4164
|
-
_a.trys.push([1, 3, , 4]);
|
|
4165
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
4166
|
-
Buffer.from("trading"),
|
|
4167
|
-
nftMint.toBuffer(),
|
|
4168
|
-
], this.programId)[0];
|
|
4169
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
4170
|
-
return [4, this.program.methods
|
|
4171
|
-
.levelUp({})
|
|
4172
|
-
.accounts({
|
|
4173
|
-
owner: publicKey,
|
|
4174
|
-
perpetuals: this.perpetuals.publicKey,
|
|
4175
|
-
pool: poolConfig.poolAddress,
|
|
4176
|
-
metadataAccount: metadataAccount,
|
|
4177
|
-
nftMint: nftMint,
|
|
4178
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
|
4179
|
-
tradingAccount: nftTradingAccount,
|
|
4180
|
-
transferAuthority: this.authority.publicKey,
|
|
4181
|
-
authorizationRulesAccount: authorizationRulesAccount,
|
|
4182
|
-
authorizationRulesProgram: new web3_js_1.PublicKey('auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'),
|
|
4183
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
4184
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
4185
|
-
})
|
|
4186
|
-
.instruction()];
|
|
4187
|
-
case 2:
|
|
4188
|
-
levelUpInstruction = _a.sent();
|
|
4189
|
-
instructions.push(levelUpInstruction);
|
|
4190
|
-
return [3, 4];
|
|
4191
|
-
case 3:
|
|
4192
|
-
err_9 = _a.sent();
|
|
4193
|
-
console.log("perpClient levelUp error:: ", err_9);
|
|
4194
|
-
throw err_9;
|
|
4195
|
-
case 4: return [2, {
|
|
4196
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4197
|
-
additionalSigners: additionalSigners
|
|
4198
|
-
}];
|
|
4199
|
-
}
|
|
4200
|
-
});
|
|
4201
|
-
}); };
|
|
4202
3990
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
4203
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
|
3991
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_8;
|
|
4204
3992
|
return __generator(this, function (_a) {
|
|
4205
3993
|
switch (_a.label) {
|
|
4206
3994
|
case 0:
|
|
@@ -4242,9 +4030,9 @@ var PerpetualsClient = (function () {
|
|
|
4242
4030
|
instructions.push(depositStakeInstruction);
|
|
4243
4031
|
return [3, 5];
|
|
4244
4032
|
case 4:
|
|
4245
|
-
|
|
4246
|
-
console.log("perpClient depositStaking error:: ",
|
|
4247
|
-
throw
|
|
4033
|
+
err_8 = _a.sent();
|
|
4034
|
+
console.log("perpClient depositStaking error:: ", err_8);
|
|
4035
|
+
throw err_8;
|
|
4248
4036
|
case 5: return [2, {
|
|
4249
4037
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4250
4038
|
additionalSigners: additionalSigners
|
|
@@ -4253,7 +4041,7 @@ var PerpetualsClient = (function () {
|
|
|
4253
4041
|
});
|
|
4254
4042
|
}); };
|
|
4255
4043
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
|
4256
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
|
4044
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_9;
|
|
4257
4045
|
return __generator(this, function (_c) {
|
|
4258
4046
|
switch (_c.label) {
|
|
4259
4047
|
case 0:
|
|
@@ -4300,9 +4088,9 @@ var PerpetualsClient = (function () {
|
|
|
4300
4088
|
refreshStakeInstruction = _c.sent();
|
|
4301
4089
|
return [2, refreshStakeInstruction];
|
|
4302
4090
|
case 2:
|
|
4303
|
-
|
|
4304
|
-
console.log("perpClient refreshStaking error:: ",
|
|
4305
|
-
throw
|
|
4091
|
+
err_9 = _c.sent();
|
|
4092
|
+
console.log("perpClient refreshStaking error:: ", err_9);
|
|
4093
|
+
throw err_9;
|
|
4306
4094
|
case 3: return [2];
|
|
4307
4095
|
}
|
|
4308
4096
|
});
|
|
@@ -4313,7 +4101,7 @@ var PerpetualsClient = (function () {
|
|
|
4313
4101
|
args_1[_i - 3] = arguments[_i];
|
|
4314
4102
|
}
|
|
4315
4103
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
|
4316
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
|
4104
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_10;
|
|
4317
4105
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4318
4106
|
return __generator(this, function (_c) {
|
|
4319
4107
|
switch (_c.label) {
|
|
@@ -4361,9 +4149,9 @@ var PerpetualsClient = (function () {
|
|
|
4361
4149
|
refreshStakeInstruction = _c.sent();
|
|
4362
4150
|
return [2, refreshStakeInstruction];
|
|
4363
4151
|
case 2:
|
|
4364
|
-
|
|
4365
|
-
console.log("perpClient refreshStaking error:: ",
|
|
4366
|
-
throw
|
|
4152
|
+
err_10 = _c.sent();
|
|
4153
|
+
console.log("perpClient refreshStaking error:: ", err_10);
|
|
4154
|
+
throw err_10;
|
|
4367
4155
|
case 3: return [2];
|
|
4368
4156
|
}
|
|
4369
4157
|
});
|
|
@@ -4375,7 +4163,7 @@ var PerpetualsClient = (function () {
|
|
|
4375
4163
|
args_1[_i - 3] = arguments[_i];
|
|
4376
4164
|
}
|
|
4377
4165
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
|
4378
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
|
4166
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_11;
|
|
4379
4167
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4380
4168
|
return __generator(this, function (_b) {
|
|
4381
4169
|
switch (_b.label) {
|
|
@@ -4427,9 +4215,9 @@ var PerpetualsClient = (function () {
|
|
|
4427
4215
|
instructions.push(unstakeInstantInstruction);
|
|
4428
4216
|
return [3, 6];
|
|
4429
4217
|
case 5:
|
|
4430
|
-
|
|
4431
|
-
console.log("perpClient unstakeInstant error:: ",
|
|
4432
|
-
throw
|
|
4218
|
+
err_11 = _b.sent();
|
|
4219
|
+
console.log("perpClient unstakeInstant error:: ", err_11);
|
|
4220
|
+
throw err_11;
|
|
4433
4221
|
case 6: return [2, {
|
|
4434
4222
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4435
4223
|
additionalSigners: additionalSigners
|
|
@@ -4439,7 +4227,7 @@ var PerpetualsClient = (function () {
|
|
|
4439
4227
|
});
|
|
4440
4228
|
};
|
|
4441
4229
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
|
4442
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
|
4230
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
|
4443
4231
|
return __generator(this, function (_c) {
|
|
4444
4232
|
switch (_c.label) {
|
|
4445
4233
|
case 0:
|
|
@@ -4483,15 +4271,15 @@ var PerpetualsClient = (function () {
|
|
|
4483
4271
|
refreshStakeInstruction = _c.sent();
|
|
4484
4272
|
return [2, refreshStakeInstruction];
|
|
4485
4273
|
case 2:
|
|
4486
|
-
|
|
4487
|
-
console.log("perpClient refreshStaking error:: ",
|
|
4488
|
-
throw
|
|
4274
|
+
err_12 = _c.sent();
|
|
4275
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
|
4276
|
+
throw err_12;
|
|
4489
4277
|
case 3: return [2];
|
|
4490
4278
|
}
|
|
4491
4279
|
});
|
|
4492
4280
|
}); };
|
|
4493
4281
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
4494
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
|
4282
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
|
4495
4283
|
return __generator(this, function (_a) {
|
|
4496
4284
|
switch (_a.label) {
|
|
4497
4285
|
case 0:
|
|
@@ -4525,9 +4313,9 @@ var PerpetualsClient = (function () {
|
|
|
4525
4313
|
instructions.push(unstakeRequestInstruction);
|
|
4526
4314
|
return [3, 4];
|
|
4527
4315
|
case 3:
|
|
4528
|
-
|
|
4529
|
-
console.log("perpClient unstakeRequest error:: ",
|
|
4530
|
-
throw
|
|
4316
|
+
err_13 = _a.sent();
|
|
4317
|
+
console.log("perpClient unstakeRequest error:: ", err_13);
|
|
4318
|
+
throw err_13;
|
|
4531
4319
|
case 4: return [2, {
|
|
4532
4320
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4533
4321
|
additionalSigners: additionalSigners
|
|
@@ -4541,7 +4329,7 @@ var PerpetualsClient = (function () {
|
|
|
4541
4329
|
args_1[_i - 1] = arguments[_i];
|
|
4542
4330
|
}
|
|
4543
4331
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
|
4544
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
|
4332
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_14;
|
|
4545
4333
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
|
4546
4334
|
if (deactivated === void 0) { deactivated = true; }
|
|
4547
4335
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
|
@@ -4597,9 +4385,9 @@ var PerpetualsClient = (function () {
|
|
|
4597
4385
|
instructions.push(withdrawStakeInstruction);
|
|
4598
4386
|
return [3, 6];
|
|
4599
4387
|
case 5:
|
|
4600
|
-
|
|
4601
|
-
console.log("perpClient withdrawStake error:: ",
|
|
4602
|
-
throw
|
|
4388
|
+
err_14 = _b.sent();
|
|
4389
|
+
console.log("perpClient withdrawStake error:: ", err_14);
|
|
4390
|
+
throw err_14;
|
|
4603
4391
|
case 6: return [2, {
|
|
4604
4392
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4605
4393
|
additionalSigners: additionalSigners
|
|
@@ -4614,7 +4402,7 @@ var PerpetualsClient = (function () {
|
|
|
4614
4402
|
args_1[_i - 3] = arguments[_i];
|
|
4615
4403
|
}
|
|
4616
4404
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
|
4617
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
|
4405
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
|
4618
4406
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4619
4407
|
return __generator(this, function (_b) {
|
|
4620
4408
|
switch (_b.label) {
|
|
@@ -4675,9 +4463,9 @@ var PerpetualsClient = (function () {
|
|
|
4675
4463
|
instructions.push(withdrawStakeInstruction);
|
|
4676
4464
|
return [3, 6];
|
|
4677
4465
|
case 5:
|
|
4678
|
-
|
|
4679
|
-
console.log("perpClient withdrawStake error:: ",
|
|
4680
|
-
throw
|
|
4466
|
+
err_15 = _b.sent();
|
|
4467
|
+
console.log("perpClient withdrawStake error:: ", err_15);
|
|
4468
|
+
throw err_15;
|
|
4681
4469
|
case 6: return [2, {
|
|
4682
4470
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4683
4471
|
additionalSigners: additionalSigners
|
|
@@ -4692,7 +4480,7 @@ var PerpetualsClient = (function () {
|
|
|
4692
4480
|
args_1[_i - 5] = arguments[_i];
|
|
4693
4481
|
}
|
|
4694
4482
|
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) {
|
|
4695
|
-
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,
|
|
4483
|
+
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;
|
|
4696
4484
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
4697
4485
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4698
4486
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
@@ -4820,8 +4608,8 @@ var PerpetualsClient = (function () {
|
|
|
4820
4608
|
instructions.push(addCompoundingLiquidity);
|
|
4821
4609
|
return [3, 10];
|
|
4822
4610
|
case 9:
|
|
4823
|
-
|
|
4824
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
|
4611
|
+
err_16 = _f.sent();
|
|
4612
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
|
4825
4613
|
return [3, 10];
|
|
4826
4614
|
case 10: return [2, {
|
|
4827
4615
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -4837,7 +4625,7 @@ var PerpetualsClient = (function () {
|
|
|
4837
4625
|
args_1[_i - 5] = arguments[_i];
|
|
4838
4626
|
}
|
|
4839
4627
|
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) {
|
|
4840
|
-
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,
|
|
4628
|
+
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;
|
|
4841
4629
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4842
4630
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4843
4631
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
@@ -4949,8 +4737,8 @@ var PerpetualsClient = (function () {
|
|
|
4949
4737
|
instructions.push(removeCompoundingLiquidity);
|
|
4950
4738
|
return [3, 8];
|
|
4951
4739
|
case 7:
|
|
4952
|
-
|
|
4953
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
|
4740
|
+
err_17 = _f.sent();
|
|
4741
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
|
4954
4742
|
return [3, 8];
|
|
4955
4743
|
case 8: return [2, {
|
|
4956
4744
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -4966,7 +4754,7 @@ var PerpetualsClient = (function () {
|
|
|
4966
4754
|
args_1[_i - 3] = arguments[_i];
|
|
4967
4755
|
}
|
|
4968
4756
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
|
4969
|
-
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,
|
|
4757
|
+
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;
|
|
4970
4758
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4971
4759
|
return __generator(this, function (_g) {
|
|
4972
4760
|
switch (_g.label) {
|
|
@@ -5064,8 +4852,8 @@ var PerpetualsClient = (function () {
|
|
|
5064
4852
|
instructions.push(migrateStake);
|
|
5065
4853
|
return [3, 8];
|
|
5066
4854
|
case 7:
|
|
5067
|
-
|
|
5068
|
-
console.log("perpClient migrateStake error:: ",
|
|
4855
|
+
err_18 = _g.sent();
|
|
4856
|
+
console.log("perpClient migrateStake error:: ", err_18);
|
|
5069
4857
|
return [3, 8];
|
|
5070
4858
|
case 8: return [2, {
|
|
5071
4859
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -5076,7 +4864,7 @@ var PerpetualsClient = (function () {
|
|
|
5076
4864
|
});
|
|
5077
4865
|
};
|
|
5078
4866
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5079
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
|
4867
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
|
|
5080
4868
|
return __generator(this, function (_d) {
|
|
5081
4869
|
switch (_d.label) {
|
|
5082
4870
|
case 0:
|
|
@@ -5148,8 +4936,8 @@ var PerpetualsClient = (function () {
|
|
|
5148
4936
|
instructions.push(migrateFlp);
|
|
5149
4937
|
return [3, 4];
|
|
5150
4938
|
case 3:
|
|
5151
|
-
|
|
5152
|
-
console.log("perpClient migrateFlp error:: ",
|
|
4939
|
+
err_19 = _d.sent();
|
|
4940
|
+
console.log("perpClient migrateFlp error:: ", err_19);
|
|
5153
4941
|
return [3, 4];
|
|
5154
4942
|
case 4: return [2, {
|
|
5155
4943
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
@@ -5164,7 +4952,7 @@ var PerpetualsClient = (function () {
|
|
|
5164
4952
|
args_1[_i - 1] = arguments[_i];
|
|
5165
4953
|
}
|
|
5166
4954
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
|
5167
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee,
|
|
4955
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_20;
|
|
5168
4956
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
|
5169
4957
|
return __generator(this, function (_e) {
|
|
5170
4958
|
switch (_e.label) {
|
|
@@ -5222,8 +5010,8 @@ var PerpetualsClient = (function () {
|
|
|
5222
5010
|
instructions.push(compoundingFee);
|
|
5223
5011
|
return [3, 4];
|
|
5224
5012
|
case 3:
|
|
5225
|
-
|
|
5226
|
-
console.log("perpClient compoundingFee error:: ",
|
|
5013
|
+
err_20 = _e.sent();
|
|
5014
|
+
console.log("perpClient compoundingFee error:: ", err_20);
|
|
5227
5015
|
return [3, 4];
|
|
5228
5016
|
case 4: return [2, {
|
|
5229
5017
|
instructions: __spreadArray([], instructions, true),
|
|
@@ -5233,175 +5021,37 @@ var PerpetualsClient = (function () {
|
|
|
5233
5021
|
});
|
|
5234
5022
|
});
|
|
5235
5023
|
};
|
|
5236
|
-
this.
|
|
5237
|
-
var preInstructions, instructions, postInstructions, additionalSigners,
|
|
5238
|
-
return __generator(this, function (
|
|
5239
|
-
switch (
|
|
5024
|
+
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5025
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_21;
|
|
5026
|
+
return __generator(this, function (_a) {
|
|
5027
|
+
switch (_a.label) {
|
|
5240
5028
|
case 0:
|
|
5241
5029
|
preInstructions = [];
|
|
5242
5030
|
instructions = [];
|
|
5243
5031
|
postInstructions = [];
|
|
5244
5032
|
additionalSigners = [];
|
|
5245
|
-
|
|
5033
|
+
_a.label = 1;
|
|
5246
5034
|
case 1:
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
userTokenAccount = _b.sent();
|
|
5251
|
-
_a = createAta;
|
|
5252
|
-
if (!_a) return [3, 4];
|
|
5035
|
+
_a.trys.push([1, 4, , 5]);
|
|
5036
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5037
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5253
5038
|
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5254
|
-
case
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
case 4:
|
|
5258
|
-
if (_a) {
|
|
5259
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(owner, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5039
|
+
case 2:
|
|
5040
|
+
if (!(_a.sent())) {
|
|
5041
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5260
5042
|
}
|
|
5261
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
|
|
5262
|
-
case 5:
|
|
5263
|
-
nftTokenAccount = _b.sent();
|
|
5264
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
5265
|
-
Buffer.from("trading"),
|
|
5266
|
-
nftMint.toBuffer(),
|
|
5267
|
-
], this.programId)[0];
|
|
5268
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5269
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5270
|
-
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];
|
|
5271
|
-
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];
|
|
5272
5043
|
return [4, this.program.methods
|
|
5273
|
-
.
|
|
5044
|
+
.depositTokenStake({
|
|
5045
|
+
depositAmount: depositAmount
|
|
5046
|
+
})
|
|
5274
5047
|
.accounts({
|
|
5275
5048
|
owner: owner,
|
|
5276
|
-
|
|
5049
|
+
feePayer: feePayer,
|
|
5050
|
+
fundingTokenAccount: userTokenAccount,
|
|
5277
5051
|
perpetuals: this.perpetuals.publicKey,
|
|
5278
5052
|
tokenVault: poolConfig.tokenVault,
|
|
5279
5053
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5280
|
-
|
|
5281
|
-
collectionMetadata: collectionMetadata,
|
|
5282
|
-
edition: edition,
|
|
5283
|
-
tokenRecord: tokenRecord,
|
|
5284
|
-
tradingAccount: nftTradingAccount,
|
|
5285
|
-
transferAuthority: poolConfig.transferAuthority,
|
|
5286
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
|
5287
|
-
nftMint: nftMint,
|
|
5288
|
-
nftTokenAccount: nftTokenAccount,
|
|
5289
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5290
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5291
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5292
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5293
|
-
program: this.programId,
|
|
5294
|
-
receivingTokenMint: poolConfig.tokenMint,
|
|
5295
|
-
})
|
|
5296
|
-
.instruction()];
|
|
5297
|
-
case 6:
|
|
5298
|
-
burnAndClaimInstruction = _b.sent();
|
|
5299
|
-
instructions.push(burnAndClaimInstruction);
|
|
5300
|
-
return [3, 8];
|
|
5301
|
-
case 7:
|
|
5302
|
-
err_23 = _b.sent();
|
|
5303
|
-
console.log("perpClient burnAndClaimInstruction error:: ", err_23);
|
|
5304
|
-
throw err_23;
|
|
5305
|
-
case 8: return [2, {
|
|
5306
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5307
|
-
additionalSigners: additionalSigners
|
|
5308
|
-
}];
|
|
5309
|
-
}
|
|
5310
|
-
});
|
|
5311
|
-
}); };
|
|
5312
|
-
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5313
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_24;
|
|
5314
|
-
return __generator(this, function (_a) {
|
|
5315
|
-
switch (_a.label) {
|
|
5316
|
-
case 0:
|
|
5317
|
-
preInstructions = [];
|
|
5318
|
-
instructions = [];
|
|
5319
|
-
postInstructions = [];
|
|
5320
|
-
additionalSigners = [];
|
|
5321
|
-
_a.label = 1;
|
|
5322
|
-
case 1:
|
|
5323
|
-
_a.trys.push([1, 3, , 4]);
|
|
5324
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5325
|
-
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
|
5326
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
|
5327
|
-
Buffer.from("trading"),
|
|
5328
|
-
nftMint.toBuffer(),
|
|
5329
|
-
], this.programId)[0];
|
|
5330
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5331
|
-
collectionMetadata = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), poolConfig.nftCollectionAddress.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
|
5332
|
-
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];
|
|
5333
|
-
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];
|
|
5334
|
-
return [4, this.program.methods
|
|
5335
|
-
.burnAndStake({})
|
|
5336
|
-
.accounts({
|
|
5337
|
-
owner: owner,
|
|
5338
|
-
feePayer: feePayer,
|
|
5339
|
-
perpetuals: this.perpetuals.publicKey,
|
|
5340
|
-
tokenVault: poolConfig.tokenVault,
|
|
5341
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5342
|
-
tokenStakeAccount: tokenStakeAccount,
|
|
5343
|
-
metadataAccount: metadataAccount,
|
|
5344
|
-
collectionMetadata: collectionMetadata,
|
|
5345
|
-
edition: edition,
|
|
5346
|
-
tokenRecord: tokenRecord,
|
|
5347
|
-
tradingAccount: nftTradingAccount,
|
|
5348
|
-
transferAuthority: poolConfig.transferAuthority,
|
|
5349
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
|
5350
|
-
nftMint: nftMint,
|
|
5351
|
-
nftTokenAccount: nftTokenAccount,
|
|
5352
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5353
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5354
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5355
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5356
|
-
program: this.programId
|
|
5357
|
-
})
|
|
5358
|
-
.instruction()];
|
|
5359
|
-
case 2:
|
|
5360
|
-
burnAndStakeInstruction = _a.sent();
|
|
5361
|
-
instructions.push(burnAndStakeInstruction);
|
|
5362
|
-
return [3, 4];
|
|
5363
|
-
case 3:
|
|
5364
|
-
err_24 = _a.sent();
|
|
5365
|
-
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
|
5366
|
-
throw err_24;
|
|
5367
|
-
case 4: return [2, {
|
|
5368
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5369
|
-
additionalSigners: additionalSigners
|
|
5370
|
-
}];
|
|
5371
|
-
}
|
|
5372
|
-
});
|
|
5373
|
-
}); };
|
|
5374
|
-
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5375
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
|
5376
|
-
return __generator(this, function (_a) {
|
|
5377
|
-
switch (_a.label) {
|
|
5378
|
-
case 0:
|
|
5379
|
-
preInstructions = [];
|
|
5380
|
-
instructions = [];
|
|
5381
|
-
postInstructions = [];
|
|
5382
|
-
additionalSigners = [];
|
|
5383
|
-
_a.label = 1;
|
|
5384
|
-
case 1:
|
|
5385
|
-
_a.trys.push([1, 4, , 5]);
|
|
5386
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5387
|
-
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5388
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5389
|
-
case 2:
|
|
5390
|
-
if (!(_a.sent())) {
|
|
5391
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5392
|
-
}
|
|
5393
|
-
return [4, this.program.methods
|
|
5394
|
-
.depositTokenStake({
|
|
5395
|
-
depositAmount: depositAmount
|
|
5396
|
-
})
|
|
5397
|
-
.accounts({
|
|
5398
|
-
owner: owner,
|
|
5399
|
-
feePayer: feePayer,
|
|
5400
|
-
fundingTokenAccount: userTokenAccount,
|
|
5401
|
-
perpetuals: this.perpetuals.publicKey,
|
|
5402
|
-
tokenVault: poolConfig.tokenVault,
|
|
5403
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5404
|
-
tokenStakeAccount: tokenStakeAccount,
|
|
5054
|
+
tokenStakeAccount: tokenStakeAccount,
|
|
5405
5055
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5406
5056
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5407
5057
|
eventAuthority: this.eventAuthority.publicKey,
|
|
@@ -5414,9 +5064,9 @@ var PerpetualsClient = (function () {
|
|
|
5414
5064
|
instructions.push(depositTokenStakeInstruction);
|
|
5415
5065
|
return [3, 5];
|
|
5416
5066
|
case 4:
|
|
5417
|
-
|
|
5418
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
|
5419
|
-
throw
|
|
5067
|
+
err_21 = _a.sent();
|
|
5068
|
+
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
|
5069
|
+
throw err_21;
|
|
5420
5070
|
case 5: return [2, {
|
|
5421
5071
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5422
5072
|
additionalSigners: additionalSigners
|
|
@@ -5425,7 +5075,7 @@ var PerpetualsClient = (function () {
|
|
|
5425
5075
|
});
|
|
5426
5076
|
}); };
|
|
5427
5077
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5428
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
|
5078
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_22;
|
|
5429
5079
|
return __generator(this, function (_a) {
|
|
5430
5080
|
switch (_a.label) {
|
|
5431
5081
|
case 0:
|
|
@@ -5454,9 +5104,9 @@ var PerpetualsClient = (function () {
|
|
|
5454
5104
|
instructions.push(unstakeTokenRequestInstruction);
|
|
5455
5105
|
return [3, 4];
|
|
5456
5106
|
case 3:
|
|
5457
|
-
|
|
5458
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
|
5459
|
-
throw
|
|
5107
|
+
err_22 = _a.sent();
|
|
5108
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_22);
|
|
5109
|
+
throw err_22;
|
|
5460
5110
|
case 4: return [2, {
|
|
5461
5111
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5462
5112
|
additionalSigners: additionalSigners
|
|
@@ -5465,7 +5115,7 @@ var PerpetualsClient = (function () {
|
|
|
5465
5115
|
});
|
|
5466
5116
|
}); };
|
|
5467
5117
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5468
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
|
5118
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_23;
|
|
5469
5119
|
return __generator(this, function (_a) {
|
|
5470
5120
|
switch (_a.label) {
|
|
5471
5121
|
case 0:
|
|
@@ -5506,9 +5156,9 @@ var PerpetualsClient = (function () {
|
|
|
5506
5156
|
instructions.push(unstakeTokenInstantInstruction);
|
|
5507
5157
|
return [3, 5];
|
|
5508
5158
|
case 4:
|
|
5509
|
-
|
|
5510
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
|
5511
|
-
throw
|
|
5159
|
+
err_23 = _a.sent();
|
|
5160
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
|
5161
|
+
throw err_23;
|
|
5512
5162
|
case 5: return [2, {
|
|
5513
5163
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5514
5164
|
additionalSigners: additionalSigners
|
|
@@ -5517,7 +5167,7 @@ var PerpetualsClient = (function () {
|
|
|
5517
5167
|
});
|
|
5518
5168
|
}); };
|
|
5519
5169
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5520
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
|
5170
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_24;
|
|
5521
5171
|
return __generator(this, function (_a) {
|
|
5522
5172
|
switch (_a.label) {
|
|
5523
5173
|
case 0:
|
|
@@ -5558,9 +5208,9 @@ var PerpetualsClient = (function () {
|
|
|
5558
5208
|
instructions.push(withdrawTokenInstruction);
|
|
5559
5209
|
return [3, 5];
|
|
5560
5210
|
case 4:
|
|
5561
|
-
|
|
5562
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
|
5563
|
-
throw
|
|
5211
|
+
err_24 = _a.sent();
|
|
5212
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
|
5213
|
+
throw err_24;
|
|
5564
5214
|
case 5: return [2, {
|
|
5565
5215
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5566
5216
|
additionalSigners: additionalSigners
|
|
@@ -5569,7 +5219,7 @@ var PerpetualsClient = (function () {
|
|
|
5569
5219
|
});
|
|
5570
5220
|
}); };
|
|
5571
5221
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5572
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
|
5222
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_25;
|
|
5573
5223
|
return __generator(this, function (_a) {
|
|
5574
5224
|
switch (_a.label) {
|
|
5575
5225
|
case 0:
|
|
@@ -5598,9 +5248,9 @@ var PerpetualsClient = (function () {
|
|
|
5598
5248
|
instructions.push(cancelUnstakeRequestInstruction);
|
|
5599
5249
|
return [3, 4];
|
|
5600
5250
|
case 3:
|
|
5601
|
-
|
|
5602
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
|
5603
|
-
throw
|
|
5251
|
+
err_25 = _a.sent();
|
|
5252
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_25);
|
|
5253
|
+
throw err_25;
|
|
5604
5254
|
case 4: return [2, {
|
|
5605
5255
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5606
5256
|
additionalSigners: additionalSigners
|
|
@@ -5614,7 +5264,7 @@ var PerpetualsClient = (function () {
|
|
|
5614
5264
|
args_1[_i - 2] = arguments[_i];
|
|
5615
5265
|
}
|
|
5616
5266
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
|
5617
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
|
5267
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
|
5618
5268
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5619
5269
|
return __generator(this, function (_b) {
|
|
5620
5270
|
switch (_b.label) {
|
|
@@ -5660,9 +5310,9 @@ var PerpetualsClient = (function () {
|
|
|
5660
5310
|
instructions.push(collectTokenRewardInstruction);
|
|
5661
5311
|
return [3, 6];
|
|
5662
5312
|
case 5:
|
|
5663
|
-
|
|
5664
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
|
5665
|
-
throw
|
|
5313
|
+
err_26 = _b.sent();
|
|
5314
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
|
5315
|
+
throw err_26;
|
|
5666
5316
|
case 6: return [2, {
|
|
5667
5317
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5668
5318
|
additionalSigners: additionalSigners
|
|
@@ -5677,7 +5327,7 @@ var PerpetualsClient = (function () {
|
|
|
5677
5327
|
args_1[_i - 3] = arguments[_i];
|
|
5678
5328
|
}
|
|
5679
5329
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
|
5680
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
|
5330
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
|
|
5681
5331
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5682
5332
|
return __generator(this, function (_b) {
|
|
5683
5333
|
switch (_b.label) {
|
|
@@ -5724,9 +5374,9 @@ var PerpetualsClient = (function () {
|
|
|
5724
5374
|
instructions.push(collectRevenueInstruction);
|
|
5725
5375
|
return [3, 6];
|
|
5726
5376
|
case 5:
|
|
5727
|
-
|
|
5728
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
|
5729
|
-
throw
|
|
5377
|
+
err_27 = _b.sent();
|
|
5378
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
|
5379
|
+
throw err_27;
|
|
5730
5380
|
case 6: return [2, {
|
|
5731
5381
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5732
5382
|
additionalSigners: additionalSigners
|
|
@@ -5735,179 +5385,82 @@ var PerpetualsClient = (function () {
|
|
|
5735
5385
|
});
|
|
5736
5386
|
});
|
|
5737
5387
|
};
|
|
5738
|
-
this.
|
|
5739
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
|
|
5740
|
-
return __generator(this, function (_a) {
|
|
5741
|
-
switch (_a.label) {
|
|
5742
|
-
case 0:
|
|
5743
|
-
publicKey = this.provider.wallet.publicKey;
|
|
5744
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
5745
|
-
instructions = [];
|
|
5746
|
-
additionalSigners = [];
|
|
5747
|
-
_a.label = 1;
|
|
5748
|
-
case 1:
|
|
5749
|
-
_a.trys.push([1, 3, , 4]);
|
|
5750
|
-
fbNftProgramData = web3_js_1.PublicKey.findProgramAddressSync([this.programFbnftReward.programId.toBuffer()], new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"))[0];
|
|
5751
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
|
5752
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
|
5753
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
|
5754
|
-
return [4, this.programFbnftReward.methods
|
|
5755
|
-
.initRewardVault({
|
|
5756
|
-
nftCount: nftCount
|
|
5757
|
-
})
|
|
5758
|
-
.accounts({
|
|
5759
|
-
admin: publicKey,
|
|
5760
|
-
transferAuthority: nftTransferAuthority,
|
|
5761
|
-
rewardVault: rewardVault,
|
|
5762
|
-
rewardMint: rewardCustodyMint,
|
|
5763
|
-
rewardTokenAccount: rewardTokenAccount,
|
|
5764
|
-
collectionMint: collectionMint,
|
|
5765
|
-
programData: fbNftProgramData,
|
|
5766
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5767
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5768
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
|
5769
|
-
})
|
|
5770
|
-
.instruction()];
|
|
5771
|
-
case 2:
|
|
5772
|
-
initRewardVault = _a.sent();
|
|
5773
|
-
instructions.push(initRewardVault);
|
|
5774
|
-
return [3, 4];
|
|
5775
|
-
case 3:
|
|
5776
|
-
err_32 = _a.sent();
|
|
5777
|
-
console.log("perpClient InitRewardVault error:: ", err_32);
|
|
5778
|
-
throw err_32;
|
|
5779
|
-
case 4: return [2, {
|
|
5780
|
-
instructions: __spreadArray([], instructions, true),
|
|
5781
|
-
additionalSigners: additionalSigners
|
|
5782
|
-
}];
|
|
5783
|
-
}
|
|
5784
|
-
});
|
|
5785
|
-
}); };
|
|
5786
|
-
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5787
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
|
|
5788
|
-
return __generator(this, function (_a) {
|
|
5789
|
-
switch (_a.label) {
|
|
5790
|
-
case 0:
|
|
5791
|
-
publicKey = this.provider.wallet.publicKey;
|
|
5792
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
5793
|
-
instructions = [];
|
|
5794
|
-
additionalSigners = [];
|
|
5795
|
-
_a.label = 1;
|
|
5796
|
-
case 1:
|
|
5797
|
-
_a.trys.push([1, 3, , 4]);
|
|
5798
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
|
5799
|
-
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
|
5800
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
|
5801
|
-
return [4, this.programFbnftReward.methods
|
|
5802
|
-
.distributeRewards({
|
|
5803
|
-
rewardAmount: rewardAmount
|
|
5804
|
-
})
|
|
5805
|
-
.accounts({
|
|
5806
|
-
admin: publicKey,
|
|
5807
|
-
fundingAccount: fundingAccount,
|
|
5808
|
-
rewardVault: rewardVault,
|
|
5809
|
-
rewardTokenAccount: rewardTokenAccount,
|
|
5810
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5811
|
-
})
|
|
5812
|
-
.instruction()];
|
|
5813
|
-
case 2:
|
|
5814
|
-
distributeReward = _a.sent();
|
|
5815
|
-
instructions.push(distributeReward);
|
|
5816
|
-
return [3, 4];
|
|
5817
|
-
case 3:
|
|
5818
|
-
err_33 = _a.sent();
|
|
5819
|
-
console.log("perpClient distributeReward error:: ", err_33);
|
|
5820
|
-
throw err_33;
|
|
5821
|
-
case 4: return [2, {
|
|
5822
|
-
instructions: __spreadArray([], instructions, true),
|
|
5823
|
-
additionalSigners: additionalSigners
|
|
5824
|
-
}];
|
|
5825
|
-
}
|
|
5826
|
-
});
|
|
5827
|
-
}); };
|
|
5828
|
-
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
|
5388
|
+
this.collectRebate = function (owner_1, rebateSymbol_1, poolConfig_1) {
|
|
5829
5389
|
var args_1 = [];
|
|
5830
5390
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
5831
5391
|
args_1[_i - 3] = arguments[_i];
|
|
5832
5392
|
}
|
|
5833
|
-
return __awaiter(_this, __spreadArray([
|
|
5834
|
-
var publicKey,
|
|
5393
|
+
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
|
|
5394
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, _a, collectRebateInstruction, err_28;
|
|
5835
5395
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5836
5396
|
return __generator(this, function (_b) {
|
|
5837
5397
|
switch (_b.label) {
|
|
5838
5398
|
case 0:
|
|
5839
5399
|
publicKey = this.provider.wallet.publicKey;
|
|
5840
|
-
|
|
5841
|
-
rewardCustodyMint = rewardToken.mintKey;
|
|
5400
|
+
preInstructions = [];
|
|
5842
5401
|
instructions = [];
|
|
5402
|
+
postInstructions = [];
|
|
5843
5403
|
additionalSigners = [];
|
|
5844
5404
|
_b.label = 1;
|
|
5845
5405
|
case 1:
|
|
5846
5406
|
_b.trys.push([1, 5, , 6]);
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5407
|
+
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5408
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5409
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5850
5410
|
_a = createUserATA;
|
|
5851
5411
|
if (!_a) return [3, 3];
|
|
5852
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
|
5412
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5853
5413
|
case 2:
|
|
5854
5414
|
_a = !(_b.sent());
|
|
5855
5415
|
_b.label = 3;
|
|
5856
5416
|
case 3:
|
|
5857
5417
|
if (_a) {
|
|
5858
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey,
|
|
5859
|
-
}
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
|
5863
|
-
nftTransferAuthority = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("transfer_authority")], this.programFbnftReward.programId)[0];
|
|
5864
|
-
return [4, this.programFbnftReward.methods
|
|
5865
|
-
.collectReward()
|
|
5418
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5419
|
+
}
|
|
5420
|
+
return [4, this.program.methods
|
|
5421
|
+
.collectRebate()
|
|
5866
5422
|
.accounts({
|
|
5867
|
-
owner:
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
5423
|
+
owner: owner,
|
|
5424
|
+
receivingTokenAccount: userTokenAccount,
|
|
5425
|
+
perpetuals: this.perpetuals.publicKey,
|
|
5426
|
+
transferAuthority: poolConfig.transferAuthority,
|
|
5427
|
+
rebateVault: poolConfig.rebateVault,
|
|
5428
|
+
rebateTokenAccount: poolConfig.rebateTokenAccount,
|
|
5429
|
+
tokenStakeAccount: tokenStakeAccount,
|
|
5430
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5431
|
+
eventAuthority: this.eventAuthority.publicKey,
|
|
5432
|
+
program: this.programId,
|
|
5433
|
+
receivingTokenMint: rebateMint,
|
|
5879
5434
|
})
|
|
5880
5435
|
.instruction()];
|
|
5881
5436
|
case 4:
|
|
5882
|
-
|
|
5883
|
-
instructions.push(
|
|
5437
|
+
collectRebateInstruction = _b.sent();
|
|
5438
|
+
instructions.push(collectRebateInstruction);
|
|
5884
5439
|
return [3, 6];
|
|
5885
5440
|
case 5:
|
|
5886
|
-
|
|
5887
|
-
|
|
5441
|
+
err_28 = _b.sent();
|
|
5442
|
+
console.log("perpClient collectRebateInstruction error:: ", err_28);
|
|
5443
|
+
throw err_28;
|
|
5888
5444
|
case 6: return [2, {
|
|
5889
|
-
instructions: __spreadArray([], instructions, true),
|
|
5445
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5890
5446
|
additionalSigners: additionalSigners
|
|
5891
5447
|
}];
|
|
5892
5448
|
}
|
|
5893
5449
|
});
|
|
5894
5450
|
});
|
|
5895
5451
|
};
|
|
5896
|
-
this.
|
|
5452
|
+
this.settleRebates = function (owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1) {
|
|
5897
5453
|
var args_1 = [];
|
|
5898
|
-
for (var _i =
|
|
5899
|
-
args_1[_i -
|
|
5454
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
5455
|
+
args_1[_i - 4] = arguments[_i];
|
|
5900
5456
|
}
|
|
5901
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA
|
|
5902
|
-
var publicKey,
|
|
5457
|
+
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, rewardSymbol, poolConfig, createUserATA) {
|
|
5458
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, rebateMint, userTokenAccount, _a, settleRebatesInstruction, err_29;
|
|
5903
5459
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5904
5460
|
return __generator(this, function (_b) {
|
|
5905
5461
|
switch (_b.label) {
|
|
5906
5462
|
case 0:
|
|
5907
5463
|
publicKey = this.provider.wallet.publicKey;
|
|
5908
|
-
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
|
5909
|
-
rewardCustodyMint = rewardToken.mintKey;
|
|
5910
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
|
5911
5464
|
preInstructions = [];
|
|
5912
5465
|
instructions = [];
|
|
5913
5466
|
postInstructions = [];
|
|
@@ -5915,59 +5468,45 @@ var PerpetualsClient = (function () {
|
|
|
5915
5468
|
_b.label = 1;
|
|
5916
5469
|
case 1:
|
|
5917
5470
|
_b.trys.push([1, 5, , 6]);
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5471
|
+
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
|
5472
|
+
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5473
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5921
5474
|
_a = createUserATA;
|
|
5922
5475
|
if (!_a) return [3, 3];
|
|
5923
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
|
5476
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5924
5477
|
case 2:
|
|
5925
5478
|
_a = !(_b.sent());
|
|
5926
5479
|
_b.label = 3;
|
|
5927
5480
|
case 3:
|
|
5928
5481
|
if (_a) {
|
|
5929
|
-
|
|
5930
|
-
}
|
|
5931
|
-
tradingAccount = [];
|
|
5932
|
-
if (nftTradingAccount) {
|
|
5933
|
-
tradingAccount.push({
|
|
5934
|
-
pubkey: nftTradingAccount,
|
|
5935
|
-
isSigner: false,
|
|
5936
|
-
isWritable: true,
|
|
5937
|
-
});
|
|
5482
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5938
5483
|
}
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
return [4, this.programPerpComposability.methods
|
|
5942
|
-
.collectAndDistributeFee()
|
|
5484
|
+
return [4, this.program.methods
|
|
5485
|
+
.settleRebates()
|
|
5943
5486
|
.accounts({
|
|
5944
|
-
perpProgram: this.programId,
|
|
5945
|
-
owner: publicKey,
|
|
5946
|
-
receivingTokenAccount: receivingTokenAccount,
|
|
5947
5487
|
transferAuthority: poolConfig.transferAuthority,
|
|
5948
5488
|
perpetuals: this.perpetuals.publicKey,
|
|
5949
|
-
pool:
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5489
|
+
pool: poolConfig.poolAddress,
|
|
5490
|
+
rewardCustody: rewardCustody.custodyAccount,
|
|
5491
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
|
5492
|
+
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
|
5493
|
+
rebateVault: poolConfig.rebateVault,
|
|
5494
|
+
rebateTokenAccount: poolConfig.rebateTokenAccount,
|
|
5495
|
+
tokenMint: rebateMint,
|
|
5954
5496
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5955
5497
|
eventAuthority: this.eventAuthority.publicKey,
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
rewardVault: rewardVault,
|
|
5959
|
-
rewardTokenAccount: rewardTokenAccount
|
|
5498
|
+
program: this.programId,
|
|
5499
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
5960
5500
|
})
|
|
5961
|
-
.remainingAccounts(tradingAccount)
|
|
5962
5501
|
.instruction()];
|
|
5963
5502
|
case 4:
|
|
5964
|
-
|
|
5965
|
-
instructions.push(
|
|
5503
|
+
settleRebatesInstruction = _b.sent();
|
|
5504
|
+
instructions.push(settleRebatesInstruction);
|
|
5966
5505
|
return [3, 6];
|
|
5967
5506
|
case 5:
|
|
5968
|
-
|
|
5969
|
-
console.log("perpClient
|
|
5970
|
-
throw
|
|
5507
|
+
err_29 = _b.sent();
|
|
5508
|
+
console.log("perpClient settleRebatesInstruction error:: ", err_29);
|
|
5509
|
+
throw err_29;
|
|
5971
5510
|
case 6: return [2, {
|
|
5972
5511
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5973
5512
|
additionalSigners: additionalSigners
|
|
@@ -5982,7 +5521,7 @@ var PerpetualsClient = (function () {
|
|
|
5982
5521
|
args_1[_i - 11] = arguments[_i];
|
|
5983
5522
|
}
|
|
5984
5523
|
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) {
|
|
5985
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder,
|
|
5524
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_30;
|
|
5986
5525
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
5987
5526
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5988
5527
|
return __generator(this, function (_c) {
|
|
@@ -6088,9 +5627,9 @@ var PerpetualsClient = (function () {
|
|
|
6088
5627
|
instructions.push(placeLimitOrder);
|
|
6089
5628
|
return [3, 10];
|
|
6090
5629
|
case 9:
|
|
6091
|
-
|
|
6092
|
-
console.log("perpClient placeLimitOrder error:: ",
|
|
6093
|
-
throw
|
|
5630
|
+
err_30 = _c.sent();
|
|
5631
|
+
console.log("perpClient placeLimitOrder error:: ", err_30);
|
|
5632
|
+
throw err_30;
|
|
6094
5633
|
case 10: return [2, {
|
|
6095
5634
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6096
5635
|
additionalSigners: additionalSigners
|
|
@@ -6105,7 +5644,7 @@ var PerpetualsClient = (function () {
|
|
|
6105
5644
|
args_1[_i - 11] = arguments[_i];
|
|
6106
5645
|
}
|
|
6107
5646
|
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) {
|
|
6108
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder,
|
|
5647
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_31;
|
|
6109
5648
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6110
5649
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6111
5650
|
return __generator(this, function (_b) {
|
|
@@ -6196,9 +5735,9 @@ var PerpetualsClient = (function () {
|
|
|
6196
5735
|
instructions.push(editLimitOrder);
|
|
6197
5736
|
return [3, 8];
|
|
6198
5737
|
case 7:
|
|
6199
|
-
|
|
6200
|
-
console.log("perpClient editLimitOrder error:: ",
|
|
6201
|
-
throw
|
|
5738
|
+
err_31 = _b.sent();
|
|
5739
|
+
console.log("perpClient editLimitOrder error:: ", err_31);
|
|
5740
|
+
throw err_31;
|
|
6202
5741
|
case 8: return [2, {
|
|
6203
5742
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6204
5743
|
additionalSigners: additionalSigners
|
|
@@ -6212,11 +5751,10 @@ var PerpetualsClient = (function () {
|
|
|
6212
5751
|
for (var _i = 7; _i < arguments.length; _i++) {
|
|
6213
5752
|
args_1[_i - 7] = arguments[_i];
|
|
6214
5753
|
}
|
|
6215
|
-
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
|
|
6216
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder,
|
|
5754
|
+
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) {
|
|
5755
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_32;
|
|
6217
5756
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6218
5757
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6219
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6220
5758
|
return __generator(this, function (_a) {
|
|
6221
5759
|
switch (_a.label) {
|
|
6222
5760
|
case 0:
|
|
@@ -6259,16 +5797,16 @@ var PerpetualsClient = (function () {
|
|
|
6259
5797
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6260
5798
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
6261
5799
|
})
|
|
6262
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
5800
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6263
5801
|
.instruction()];
|
|
6264
5802
|
case 2:
|
|
6265
5803
|
executeLimitOrder = _a.sent();
|
|
6266
5804
|
instructions.push(executeLimitOrder);
|
|
6267
5805
|
return [3, 4];
|
|
6268
5806
|
case 3:
|
|
6269
|
-
|
|
6270
|
-
console.log("perpClient executeLimitOrder error:: ",
|
|
6271
|
-
throw
|
|
5807
|
+
err_32 = _a.sent();
|
|
5808
|
+
console.log("perpClient executeLimitOrder error:: ", err_32);
|
|
5809
|
+
throw err_32;
|
|
6272
5810
|
case 4: return [2, {
|
|
6273
5811
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6274
5812
|
additionalSigners: additionalSigners
|
|
@@ -6282,11 +5820,10 @@ var PerpetualsClient = (function () {
|
|
|
6282
5820
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
6283
5821
|
args_1[_i - 8] = arguments[_i];
|
|
6284
5822
|
}
|
|
6285
|
-
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
|
|
6286
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap,
|
|
5823
|
+
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) {
|
|
5824
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_33;
|
|
6287
5825
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6288
5826
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6289
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6290
5827
|
return __generator(this, function (_a) {
|
|
6291
5828
|
switch (_a.label) {
|
|
6292
5829
|
case 0:
|
|
@@ -6332,16 +5869,16 @@ var PerpetualsClient = (function () {
|
|
|
6332
5869
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6333
5870
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
6334
5871
|
})
|
|
6335
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
5872
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6336
5873
|
.instruction()];
|
|
6337
5874
|
case 2:
|
|
6338
5875
|
executeLimitWithSwap = _a.sent();
|
|
6339
5876
|
instructions.push(executeLimitWithSwap);
|
|
6340
5877
|
return [3, 4];
|
|
6341
5878
|
case 3:
|
|
6342
|
-
|
|
6343
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
|
6344
|
-
throw
|
|
5879
|
+
err_33 = _a.sent();
|
|
5880
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_33);
|
|
5881
|
+
throw err_33;
|
|
6345
5882
|
case 4: return [2, {
|
|
6346
5883
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6347
5884
|
additionalSigners: additionalSigners
|
|
@@ -6351,7 +5888,7 @@ var PerpetualsClient = (function () {
|
|
|
6351
5888
|
});
|
|
6352
5889
|
};
|
|
6353
5890
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6354
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
|
5891
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_34;
|
|
6355
5892
|
return __generator(this, function (_a) {
|
|
6356
5893
|
switch (_a.label) {
|
|
6357
5894
|
case 0:
|
|
@@ -6399,9 +5936,9 @@ var PerpetualsClient = (function () {
|
|
|
6399
5936
|
instructions.push(placeTriggerOrder);
|
|
6400
5937
|
return [3, 4];
|
|
6401
5938
|
case 3:
|
|
6402
|
-
|
|
6403
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
|
6404
|
-
throw
|
|
5939
|
+
err_34 = _a.sent();
|
|
5940
|
+
console.log("perpClient placeTriggerOrder error:: ", err_34);
|
|
5941
|
+
throw err_34;
|
|
6405
5942
|
case 4: return [2, {
|
|
6406
5943
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6407
5944
|
additionalSigners: additionalSigners
|
|
@@ -6410,7 +5947,7 @@ var PerpetualsClient = (function () {
|
|
|
6410
5947
|
});
|
|
6411
5948
|
}); };
|
|
6412
5949
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6413
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
|
5950
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_35;
|
|
6414
5951
|
return __generator(this, function (_a) {
|
|
6415
5952
|
switch (_a.label) {
|
|
6416
5953
|
case 0:
|
|
@@ -6457,9 +5994,9 @@ var PerpetualsClient = (function () {
|
|
|
6457
5994
|
instructions.push(editTriggerOrder);
|
|
6458
5995
|
return [3, 4];
|
|
6459
5996
|
case 3:
|
|
6460
|
-
|
|
6461
|
-
console.log("perpClient editTriggerOrder error:: ",
|
|
6462
|
-
throw
|
|
5997
|
+
err_35 = _a.sent();
|
|
5998
|
+
console.log("perpClient editTriggerOrder error:: ", err_35);
|
|
5999
|
+
throw err_35;
|
|
6463
6000
|
case 4: return [2, {
|
|
6464
6001
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6465
6002
|
additionalSigners: additionalSigners
|
|
@@ -6468,7 +6005,7 @@ var PerpetualsClient = (function () {
|
|
|
6468
6005
|
});
|
|
6469
6006
|
}); };
|
|
6470
6007
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6471
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
|
6008
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_36;
|
|
6472
6009
|
return __generator(this, function (_a) {
|
|
6473
6010
|
switch (_a.label) {
|
|
6474
6011
|
case 0:
|
|
@@ -6501,9 +6038,9 @@ var PerpetualsClient = (function () {
|
|
|
6501
6038
|
instructions.push(cancelTriggerOrder);
|
|
6502
6039
|
return [3, 4];
|
|
6503
6040
|
case 3:
|
|
6504
|
-
|
|
6505
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
|
6506
|
-
throw
|
|
6041
|
+
err_36 = _a.sent();
|
|
6042
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_36);
|
|
6043
|
+
throw err_36;
|
|
6507
6044
|
case 4: return [2, {
|
|
6508
6045
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6509
6046
|
additionalSigners: additionalSigners
|
|
@@ -6512,7 +6049,7 @@ var PerpetualsClient = (function () {
|
|
|
6512
6049
|
});
|
|
6513
6050
|
}); };
|
|
6514
6051
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6515
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
|
6052
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_37;
|
|
6516
6053
|
return __generator(this, function (_a) {
|
|
6517
6054
|
switch (_a.label) {
|
|
6518
6055
|
case 0:
|
|
@@ -6543,9 +6080,9 @@ var PerpetualsClient = (function () {
|
|
|
6543
6080
|
instructions.push(cancelAllTriggerOrders);
|
|
6544
6081
|
return [3, 4];
|
|
6545
6082
|
case 3:
|
|
6546
|
-
|
|
6547
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
|
6548
|
-
throw
|
|
6083
|
+
err_37 = _a.sent();
|
|
6084
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_37);
|
|
6085
|
+
throw err_37;
|
|
6549
6086
|
case 4: return [2, {
|
|
6550
6087
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6551
6088
|
additionalSigners: additionalSigners
|
|
@@ -6558,13 +6095,12 @@ var PerpetualsClient = (function () {
|
|
|
6558
6095
|
for (var _i = 9; _i < arguments.length; _i++) {
|
|
6559
6096
|
args_1[_i - 9] = arguments[_i];
|
|
6560
6097
|
}
|
|
6561
|
-
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
|
|
6562
|
-
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,
|
|
6098
|
+
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) {
|
|
6099
|
+
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;
|
|
6563
6100
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6564
6101
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6565
6102
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6566
6103
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6567
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6568
6104
|
return __generator(this, function (_e) {
|
|
6569
6105
|
switch (_e.label) {
|
|
6570
6106
|
case 0:
|
|
@@ -6659,16 +6195,16 @@ var PerpetualsClient = (function () {
|
|
|
6659
6195
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
6660
6196
|
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
6661
6197
|
})
|
|
6662
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
6198
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6663
6199
|
.instruction()];
|
|
6664
6200
|
case 8:
|
|
6665
6201
|
executeTriggerWithSwap = _e.sent();
|
|
6666
6202
|
instructions.push(executeTriggerWithSwap);
|
|
6667
6203
|
return [3, 10];
|
|
6668
6204
|
case 9:
|
|
6669
|
-
|
|
6670
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
|
6671
|
-
throw
|
|
6205
|
+
err_38 = _e.sent();
|
|
6206
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_38);
|
|
6207
|
+
throw err_38;
|
|
6672
6208
|
case 10: return [2, {
|
|
6673
6209
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6674
6210
|
additionalSigners: additionalSigners
|
|
@@ -6682,13 +6218,12 @@ var PerpetualsClient = (function () {
|
|
|
6682
6218
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
6683
6219
|
args_1[_i - 8] = arguments[_i];
|
|
6684
6220
|
}
|
|
6685
|
-
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
|
|
6686
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder,
|
|
6221
|
+
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) {
|
|
6222
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_39;
|
|
6687
6223
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6688
6224
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6689
6225
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6690
6226
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6691
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
|
6692
6227
|
return __generator(this, function (_b) {
|
|
6693
6228
|
switch (_b.label) {
|
|
6694
6229
|
case 0:
|
|
@@ -6748,16 +6283,16 @@ var PerpetualsClient = (function () {
|
|
|
6748
6283
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6749
6284
|
receivingMint: collateralCustodyConfig.mintKey
|
|
6750
6285
|
})
|
|
6751
|
-
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount,
|
|
6286
|
+
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6752
6287
|
.instruction()];
|
|
6753
6288
|
case 6:
|
|
6754
6289
|
executeTriggerOrder = _b.sent();
|
|
6755
6290
|
instructions.push(executeTriggerOrder);
|
|
6756
6291
|
return [3, 8];
|
|
6757
6292
|
case 7:
|
|
6758
|
-
|
|
6759
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
|
6760
|
-
throw
|
|
6293
|
+
err_39 = _b.sent();
|
|
6294
|
+
console.log("perpClient executeTriggerOrder error:: ", err_39);
|
|
6295
|
+
throw err_39;
|
|
6761
6296
|
case 8: return [2, {
|
|
6762
6297
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6763
6298
|
additionalSigners: additionalSigners
|
|
@@ -6772,7 +6307,7 @@ var PerpetualsClient = (function () {
|
|
|
6772
6307
|
args_1[_i - 5] = arguments[_i];
|
|
6773
6308
|
}
|
|
6774
6309
|
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) {
|
|
6775
|
-
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,
|
|
6310
|
+
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;
|
|
6776
6311
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
|
6777
6312
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6778
6313
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
|
@@ -6977,9 +6512,9 @@ var PerpetualsClient = (function () {
|
|
|
6977
6512
|
}
|
|
6978
6513
|
return [3, 20];
|
|
6979
6514
|
case 19:
|
|
6980
|
-
|
|
6981
|
-
console.error("perpClient Swap error:: ",
|
|
6982
|
-
throw
|
|
6515
|
+
err_40 = _g.sent();
|
|
6516
|
+
console.error("perpClient Swap error:: ", err_40);
|
|
6517
|
+
throw err_40;
|
|
6983
6518
|
case 20: return [2, {
|
|
6984
6519
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6985
6520
|
additionalSigners: additionalSigners
|
|
@@ -6989,7 +6524,7 @@ var PerpetualsClient = (function () {
|
|
|
6989
6524
|
});
|
|
6990
6525
|
};
|
|
6991
6526
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6992
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx,
|
|
6527
|
+
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_41;
|
|
6993
6528
|
return __generator(this, function (_b) {
|
|
6994
6529
|
switch (_b.label) {
|
|
6995
6530
|
case 0:
|
|
@@ -7045,9 +6580,9 @@ var PerpetualsClient = (function () {
|
|
|
7045
6580
|
instructions.push(inx);
|
|
7046
6581
|
return [3, 4];
|
|
7047
6582
|
case 3:
|
|
7048
|
-
|
|
7049
|
-
console.error("perpClient Swap error:: ",
|
|
7050
|
-
throw
|
|
6583
|
+
err_41 = _b.sent();
|
|
6584
|
+
console.error("perpClient Swap error:: ", err_41);
|
|
6585
|
+
throw err_41;
|
|
7051
6586
|
case 4: return [2, {
|
|
7052
6587
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7053
6588
|
additionalSigners: additionalSigners
|
|
@@ -7056,7 +6591,7 @@ var PerpetualsClient = (function () {
|
|
|
7056
6591
|
});
|
|
7057
6592
|
}); };
|
|
7058
6593
|
this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7059
|
-
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction,
|
|
6594
|
+
var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_42;
|
|
7060
6595
|
return __generator(this, function (_d) {
|
|
7061
6596
|
switch (_d.label) {
|
|
7062
6597
|
case 0:
|
|
@@ -7104,9 +6639,9 @@ var PerpetualsClient = (function () {
|
|
|
7104
6639
|
instructions.push(setLpTokenPriceInstruction);
|
|
7105
6640
|
return [3, 4];
|
|
7106
6641
|
case 3:
|
|
7107
|
-
|
|
7108
|
-
console.log("perpClient setLpTokenPriceInstruction error:: ",
|
|
7109
|
-
throw
|
|
6642
|
+
err_42 = _d.sent();
|
|
6643
|
+
console.log("perpClient setLpTokenPriceInstruction error:: ", err_42);
|
|
6644
|
+
throw err_42;
|
|
7110
6645
|
case 4: return [2, {
|
|
7111
6646
|
instructions: __spreadArray([], instructions, true),
|
|
7112
6647
|
additionalSigners: additionalSigners
|
|
@@ -7154,7 +6689,7 @@ var PerpetualsClient = (function () {
|
|
|
7154
6689
|
});
|
|
7155
6690
|
}); };
|
|
7156
6691
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
|
7157
|
-
var adminMetas, _i, admins_2, admin,
|
|
6692
|
+
var adminMetas, _i, admins_2, admin, err_43;
|
|
7158
6693
|
return __generator(this, function (_a) {
|
|
7159
6694
|
switch (_a.label) {
|
|
7160
6695
|
case 0:
|
|
@@ -7184,11 +6719,11 @@ var PerpetualsClient = (function () {
|
|
|
7184
6719
|
_a.sent();
|
|
7185
6720
|
return [3, 4];
|
|
7186
6721
|
case 3:
|
|
7187
|
-
|
|
6722
|
+
err_43 = _a.sent();
|
|
7188
6723
|
if (this.printErrors) {
|
|
7189
|
-
console.error("setAdminSigners err:",
|
|
6724
|
+
console.error("setAdminSigners err:", err_43);
|
|
7190
6725
|
}
|
|
7191
|
-
throw
|
|
6726
|
+
throw err_43;
|
|
7192
6727
|
case 4: return [2];
|
|
7193
6728
|
}
|
|
7194
6729
|
});
|
|
@@ -7377,7 +6912,7 @@ var PerpetualsClient = (function () {
|
|
|
7377
6912
|
});
|
|
7378
6913
|
}); };
|
|
7379
6914
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7380
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
|
6915
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_44;
|
|
7381
6916
|
return __generator(this, function (_a) {
|
|
7382
6917
|
switch (_a.label) {
|
|
7383
6918
|
case 0:
|
|
@@ -7410,9 +6945,9 @@ var PerpetualsClient = (function () {
|
|
|
7410
6945
|
instructions.push(withdrawFeesIx);
|
|
7411
6946
|
return [3, 5];
|
|
7412
6947
|
case 4:
|
|
7413
|
-
|
|
7414
|
-
console.log("perpClient setPool error:: ",
|
|
7415
|
-
throw
|
|
6948
|
+
err_44 = _a.sent();
|
|
6949
|
+
console.log("perpClient setPool error:: ", err_44);
|
|
6950
|
+
throw err_44;
|
|
7416
6951
|
case 5: return [2, {
|
|
7417
6952
|
instructions: __spreadArray([], instructions, true),
|
|
7418
6953
|
additionalSigners: additionalSigners
|
|
@@ -7421,7 +6956,7 @@ var PerpetualsClient = (function () {
|
|
|
7421
6956
|
});
|
|
7422
6957
|
}); };
|
|
7423
6958
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7424
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
|
6959
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_45;
|
|
7425
6960
|
return __generator(this, function (_a) {
|
|
7426
6961
|
switch (_a.label) {
|
|
7427
6962
|
case 0:
|
|
@@ -7455,9 +6990,9 @@ var PerpetualsClient = (function () {
|
|
|
7455
6990
|
instructions.push(moveProtocolFeesIx);
|
|
7456
6991
|
return [3, 4];
|
|
7457
6992
|
case 3:
|
|
7458
|
-
|
|
7459
|
-
console.log("perpClient setPool error:: ",
|
|
7460
|
-
throw
|
|
6993
|
+
err_45 = _a.sent();
|
|
6994
|
+
console.log("perpClient setPool error:: ", err_45);
|
|
6995
|
+
throw err_45;
|
|
7461
6996
|
case 4: return [2, {
|
|
7462
6997
|
instructions: __spreadArray([], instructions, true),
|
|
7463
6998
|
additionalSigners: additionalSigners
|
|
@@ -7466,7 +7001,7 @@ var PerpetualsClient = (function () {
|
|
|
7466
7001
|
});
|
|
7467
7002
|
}); };
|
|
7468
7003
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7469
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
|
7004
|
+
var publicKey, setProtocolFeeShareBpsIx, err_46;
|
|
7470
7005
|
return __generator(this, function (_a) {
|
|
7471
7006
|
switch (_a.label) {
|
|
7472
7007
|
case 0:
|
|
@@ -7486,15 +7021,15 @@ var PerpetualsClient = (function () {
|
|
|
7486
7021
|
setProtocolFeeShareBpsIx = _a.sent();
|
|
7487
7022
|
return [2, setProtocolFeeShareBpsIx];
|
|
7488
7023
|
case 2:
|
|
7489
|
-
|
|
7490
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
|
7491
|
-
throw
|
|
7024
|
+
err_46 = _a.sent();
|
|
7025
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_46);
|
|
7026
|
+
throw err_46;
|
|
7492
7027
|
case 3: return [2];
|
|
7493
7028
|
}
|
|
7494
7029
|
});
|
|
7495
7030
|
}); };
|
|
7496
7031
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
|
7497
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
|
7032
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_47;
|
|
7498
7033
|
return __generator(this, function (_a) {
|
|
7499
7034
|
switch (_a.label) {
|
|
7500
7035
|
case 0:
|
|
@@ -7521,9 +7056,9 @@ var PerpetualsClient = (function () {
|
|
|
7521
7056
|
instructions.push(setPermissionsInstruction);
|
|
7522
7057
|
return [3, 4];
|
|
7523
7058
|
case 3:
|
|
7524
|
-
|
|
7525
|
-
console.log("perpClient setPool error:: ",
|
|
7526
|
-
throw
|
|
7059
|
+
err_47 = _a.sent();
|
|
7060
|
+
console.log("perpClient setPool error:: ", err_47);
|
|
7061
|
+
throw err_47;
|
|
7527
7062
|
case 4: return [2, {
|
|
7528
7063
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7529
7064
|
additionalSigners: additionalSigners
|
|
@@ -7532,7 +7067,7 @@ var PerpetualsClient = (function () {
|
|
|
7532
7067
|
});
|
|
7533
7068
|
}); };
|
|
7534
7069
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7535
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
|
7070
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_48;
|
|
7536
7071
|
var _f;
|
|
7537
7072
|
return __generator(this, function (_g) {
|
|
7538
7073
|
switch (_g.label) {
|
|
@@ -7593,9 +7128,9 @@ var PerpetualsClient = (function () {
|
|
|
7593
7128
|
instructions.push(reimburse);
|
|
7594
7129
|
return [3, 5];
|
|
7595
7130
|
case 4:
|
|
7596
|
-
|
|
7597
|
-
console.log("perpClient setPool error:: ",
|
|
7598
|
-
throw
|
|
7131
|
+
err_48 = _g.sent();
|
|
7132
|
+
console.log("perpClient setPool error:: ", err_48);
|
|
7133
|
+
throw err_48;
|
|
7599
7134
|
case 5: return [2, {
|
|
7600
7135
|
instructions: __spreadArray([], instructions, true),
|
|
7601
7136
|
additionalSigners: additionalSigners
|
|
@@ -7603,8 +7138,8 @@ var PerpetualsClient = (function () {
|
|
|
7603
7138
|
}
|
|
7604
7139
|
});
|
|
7605
7140
|
}); };
|
|
7606
|
-
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7607
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
|
7141
|
+
this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7142
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_49;
|
|
7608
7143
|
return __generator(this, function (_a) {
|
|
7609
7144
|
switch (_a.label) {
|
|
7610
7145
|
case 0:
|
|
@@ -7616,6 +7151,7 @@ var PerpetualsClient = (function () {
|
|
|
7616
7151
|
_a.trys.push([1, 3, , 4]);
|
|
7617
7152
|
return [4, this.program.methods
|
|
7618
7153
|
.setInternalOraclePrice({
|
|
7154
|
+
useCurrentTime: useCurrentTime,
|
|
7619
7155
|
price: price,
|
|
7620
7156
|
expo: expo,
|
|
7621
7157
|
conf: conf,
|
|
@@ -7637,9 +7173,9 @@ var PerpetualsClient = (function () {
|
|
|
7637
7173
|
instructions.push(setInternalOraclePrice);
|
|
7638
7174
|
return [3, 4];
|
|
7639
7175
|
case 3:
|
|
7640
|
-
|
|
7641
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
|
7642
|
-
throw
|
|
7176
|
+
err_49 = _a.sent();
|
|
7177
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_49);
|
|
7178
|
+
throw err_49;
|
|
7643
7179
|
case 4: return [2, {
|
|
7644
7180
|
instructions: __spreadArray([], instructions, true),
|
|
7645
7181
|
additionalSigners: additionalSigners
|
|
@@ -7647,8 +7183,8 @@ var PerpetualsClient = (function () {
|
|
|
7647
7183
|
}
|
|
7648
7184
|
});
|
|
7649
7185
|
}); };
|
|
7650
|
-
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
|
7651
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
|
7186
|
+
this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
|
7187
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_50;
|
|
7652
7188
|
return __generator(this, function (_a) {
|
|
7653
7189
|
switch (_a.label) {
|
|
7654
7190
|
case 0:
|
|
@@ -7659,11 +7195,6 @@ var PerpetualsClient = (function () {
|
|
|
7659
7195
|
accountMetas = [];
|
|
7660
7196
|
_loop_1 = function (tokenMint) {
|
|
7661
7197
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
|
7662
|
-
accountMetas.push({
|
|
7663
|
-
pubkey: custody.custodyAccount,
|
|
7664
|
-
isSigner: false,
|
|
7665
|
-
isWritable: false,
|
|
7666
|
-
});
|
|
7667
7198
|
accountMetas.push({
|
|
7668
7199
|
pubkey: custody.intOracleAccount,
|
|
7669
7200
|
isSigner: false,
|
|
@@ -7686,6 +7217,7 @@ var PerpetualsClient = (function () {
|
|
|
7686
7217
|
_a.trys.push([1, 3, , 4]);
|
|
7687
7218
|
return [4, this.program.methods
|
|
7688
7219
|
.setInternalCurrentPrice({
|
|
7220
|
+
useCurrentTime: useCurrentTime,
|
|
7689
7221
|
prices: tokenInternalPrices
|
|
7690
7222
|
})
|
|
7691
7223
|
.accounts({
|
|
@@ -7698,9 +7230,9 @@ var PerpetualsClient = (function () {
|
|
|
7698
7230
|
instructions.push(setInternalOraclePrice);
|
|
7699
7231
|
return [3, 4];
|
|
7700
7232
|
case 3:
|
|
7701
|
-
|
|
7702
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
|
7703
|
-
throw
|
|
7233
|
+
err_50 = _a.sent();
|
|
7234
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_50);
|
|
7235
|
+
throw err_50;
|
|
7704
7236
|
case 4: return [2, {
|
|
7705
7237
|
instructions: __spreadArray([], instructions, true),
|
|
7706
7238
|
additionalSigners: additionalSigners
|
|
@@ -7709,7 +7241,7 @@ var PerpetualsClient = (function () {
|
|
|
7709
7241
|
});
|
|
7710
7242
|
}); };
|
|
7711
7243
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
|
7712
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
|
7244
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_51;
|
|
7713
7245
|
return __generator(this, function (_a) {
|
|
7714
7246
|
switch (_a.label) {
|
|
7715
7247
|
case 0:
|
|
@@ -7720,21 +7252,11 @@ var PerpetualsClient = (function () {
|
|
|
7720
7252
|
accountMetas = [];
|
|
7721
7253
|
_loop_2 = function (tokenMint) {
|
|
7722
7254
|
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
|
7723
|
-
accountMetas.push({
|
|
7724
|
-
pubkey: custody.custodyAccount,
|
|
7725
|
-
isSigner: false,
|
|
7726
|
-
isWritable: false,
|
|
7727
|
-
});
|
|
7728
7255
|
accountMetas.push({
|
|
7729
7256
|
pubkey: custody.intOracleAccount,
|
|
7730
7257
|
isSigner: false,
|
|
7731
7258
|
isWritable: true,
|
|
7732
7259
|
});
|
|
7733
|
-
accountMetas.push({
|
|
7734
|
-
pubkey: custody.extOracleAccount,
|
|
7735
|
-
isSigner: false,
|
|
7736
|
-
isWritable: false,
|
|
7737
|
-
});
|
|
7738
7260
|
};
|
|
7739
7261
|
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
|
7740
7262
|
tokenMint = tokenMintList_2[_i];
|
|
@@ -7759,9 +7281,9 @@ var PerpetualsClient = (function () {
|
|
|
7759
7281
|
instructions.push(setInternalOraclePrice);
|
|
7760
7282
|
return [3, 4];
|
|
7761
7283
|
case 3:
|
|
7762
|
-
|
|
7763
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
|
7764
|
-
throw
|
|
7284
|
+
err_51 = _a.sent();
|
|
7285
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_51);
|
|
7286
|
+
throw err_51;
|
|
7765
7287
|
case 4: return [2, {
|
|
7766
7288
|
instructions: __spreadArray([], instructions, true),
|
|
7767
7289
|
additionalSigners: additionalSigners
|
|
@@ -7770,7 +7292,7 @@ var PerpetualsClient = (function () {
|
|
|
7770
7292
|
});
|
|
7771
7293
|
}); };
|
|
7772
7294
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7773
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
|
7295
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_52;
|
|
7774
7296
|
return __generator(this, function (_a) {
|
|
7775
7297
|
switch (_a.label) {
|
|
7776
7298
|
case 0:
|
|
@@ -7808,8 +7330,8 @@ var PerpetualsClient = (function () {
|
|
|
7808
7330
|
instructions.push(renameFlp);
|
|
7809
7331
|
return [3, 4];
|
|
7810
7332
|
case 3:
|
|
7811
|
-
|
|
7812
|
-
console.log("perpClient renameFlp error:: ",
|
|
7333
|
+
err_52 = _a.sent();
|
|
7334
|
+
console.log("perpClient renameFlp error:: ", err_52);
|
|
7813
7335
|
return [3, 4];
|
|
7814
7336
|
case 4: return [2, {
|
|
7815
7337
|
instructions: __spreadArray([], instructions, true),
|
|
@@ -7819,7 +7341,7 @@ var PerpetualsClient = (function () {
|
|
|
7819
7341
|
});
|
|
7820
7342
|
}); };
|
|
7821
7343
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7822
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
|
7344
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_53;
|
|
7823
7345
|
return __generator(this, function (_a) {
|
|
7824
7346
|
switch (_a.label) {
|
|
7825
7347
|
case 0:
|
|
@@ -7857,9 +7379,9 @@ var PerpetualsClient = (function () {
|
|
|
7857
7379
|
instructions.push(initStakeInstruction);
|
|
7858
7380
|
return [3, 4];
|
|
7859
7381
|
case 3:
|
|
7860
|
-
|
|
7861
|
-
console.log("perpClient InitStaking error:: ",
|
|
7862
|
-
throw
|
|
7382
|
+
err_53 = _a.sent();
|
|
7383
|
+
console.log("perpClient InitStaking error:: ", err_53);
|
|
7384
|
+
throw err_53;
|
|
7863
7385
|
case 4: return [2, {
|
|
7864
7386
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7865
7387
|
additionalSigners: additionalSigners
|
|
@@ -7868,7 +7390,7 @@ var PerpetualsClient = (function () {
|
|
|
7868
7390
|
});
|
|
7869
7391
|
}); };
|
|
7870
7392
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7871
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction,
|
|
7393
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_54;
|
|
7872
7394
|
return __generator(this, function (_a) {
|
|
7873
7395
|
switch (_a.label) {
|
|
7874
7396
|
case 0:
|
|
@@ -7913,9 +7435,9 @@ var PerpetualsClient = (function () {
|
|
|
7913
7435
|
instructions.push(initCompoundingInstruction);
|
|
7914
7436
|
return [3, 4];
|
|
7915
7437
|
case 3:
|
|
7916
|
-
|
|
7917
|
-
console.log("perpClient initCompounding error:: ",
|
|
7918
|
-
throw
|
|
7438
|
+
err_54 = _a.sent();
|
|
7439
|
+
console.log("perpClient initCompounding error:: ", err_54);
|
|
7440
|
+
throw err_54;
|
|
7919
7441
|
case 4: return [2, {
|
|
7920
7442
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7921
7443
|
additionalSigners: additionalSigners
|
|
@@ -7924,7 +7446,7 @@ var PerpetualsClient = (function () {
|
|
|
7924
7446
|
});
|
|
7925
7447
|
}); };
|
|
7926
7448
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7927
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
|
7449
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_55;
|
|
7928
7450
|
return __generator(this, function (_a) {
|
|
7929
7451
|
switch (_a.label) {
|
|
7930
7452
|
case 0:
|
|
@@ -7965,9 +7487,9 @@ var PerpetualsClient = (function () {
|
|
|
7965
7487
|
instructions.push(initTokenVaultInstruction);
|
|
7966
7488
|
return [3, 4];
|
|
7967
7489
|
case 3:
|
|
7968
|
-
|
|
7969
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
|
7970
|
-
throw
|
|
7490
|
+
err_55 = _a.sent();
|
|
7491
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_55);
|
|
7492
|
+
throw err_55;
|
|
7971
7493
|
case 4: return [2, {
|
|
7972
7494
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7973
7495
|
additionalSigners: additionalSigners
|
|
@@ -7976,7 +7498,7 @@ var PerpetualsClient = (function () {
|
|
|
7976
7498
|
});
|
|
7977
7499
|
}); };
|
|
7978
7500
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7979
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
|
7501
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_56;
|
|
7980
7502
|
return __generator(this, function (_a) {
|
|
7981
7503
|
switch (_a.label) {
|
|
7982
7504
|
case 0:
|
|
@@ -8007,9 +7529,9 @@ var PerpetualsClient = (function () {
|
|
|
8007
7529
|
instructions.push(setTokenVaultConfigInstruction);
|
|
8008
7530
|
return [3, 4];
|
|
8009
7531
|
case 3:
|
|
8010
|
-
|
|
8011
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
|
8012
|
-
throw
|
|
7532
|
+
err_56 = _a.sent();
|
|
7533
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_56);
|
|
7534
|
+
throw err_56;
|
|
8013
7535
|
case 4: return [2, {
|
|
8014
7536
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8015
7537
|
additionalSigners: additionalSigners
|
|
@@ -8018,7 +7540,7 @@ var PerpetualsClient = (function () {
|
|
|
8018
7540
|
});
|
|
8019
7541
|
}); };
|
|
8020
7542
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8021
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
|
7543
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_57;
|
|
8022
7544
|
return __generator(this, function (_a) {
|
|
8023
7545
|
switch (_a.label) {
|
|
8024
7546
|
case 0:
|
|
@@ -8057,9 +7579,59 @@ var PerpetualsClient = (function () {
|
|
|
8057
7579
|
instructions.push(withdrawInstantFeeInstruction);
|
|
8058
7580
|
return [3, 6];
|
|
8059
7581
|
case 5:
|
|
8060
|
-
|
|
8061
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
|
8062
|
-
throw
|
|
7582
|
+
err_57 = _a.sent();
|
|
7583
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
|
|
7584
|
+
throw err_57;
|
|
7585
|
+
case 6: return [2, {
|
|
7586
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7587
|
+
additionalSigners: additionalSigners
|
|
7588
|
+
}];
|
|
7589
|
+
}
|
|
7590
|
+
});
|
|
7591
|
+
}); };
|
|
7592
|
+
this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
7593
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_58;
|
|
7594
|
+
return __generator(this, function (_a) {
|
|
7595
|
+
switch (_a.label) {
|
|
7596
|
+
case 0:
|
|
7597
|
+
publicKey = this.provider.wallet.publicKey;
|
|
7598
|
+
preInstructions = [];
|
|
7599
|
+
instructions = [];
|
|
7600
|
+
postInstructions = [];
|
|
7601
|
+
additionalSigners = [];
|
|
7602
|
+
_a.label = 1;
|
|
7603
|
+
case 1:
|
|
7604
|
+
_a.trys.push([1, 5, , 6]);
|
|
7605
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7606
|
+
case 2:
|
|
7607
|
+
receivingTokenAccount = _a.sent();
|
|
7608
|
+
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
7609
|
+
case 3:
|
|
7610
|
+
if (!(_a.sent())) {
|
|
7611
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7612
|
+
}
|
|
7613
|
+
return [4, this.program.methods
|
|
7614
|
+
.withdrawUnclaimedTokens({})
|
|
7615
|
+
.accounts({
|
|
7616
|
+
admin: publicKey,
|
|
7617
|
+
multisig: this.multisig.publicKey,
|
|
7618
|
+
perpetuals: this.perpetuals.publicKey,
|
|
7619
|
+
transferAuthority: poolConfig.transferAuthority,
|
|
7620
|
+
tokenVault: poolConfig.tokenVault,
|
|
7621
|
+
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
7622
|
+
receivingTokenAccount: receivingTokenAccount,
|
|
7623
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
7624
|
+
receivingTokenMint: poolConfig.tokenMint,
|
|
7625
|
+
})
|
|
7626
|
+
.instruction()];
|
|
7627
|
+
case 4:
|
|
7628
|
+
withdrawUnclaimedTokensInstruction = _a.sent();
|
|
7629
|
+
instructions.push(withdrawUnclaimedTokensInstruction);
|
|
7630
|
+
return [3, 6];
|
|
7631
|
+
case 5:
|
|
7632
|
+
err_58 = _a.sent();
|
|
7633
|
+
console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
|
|
7634
|
+
throw err_58;
|
|
8063
7635
|
case 6: return [2, {
|
|
8064
7636
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8065
7637
|
additionalSigners: additionalSigners
|
|
@@ -8068,7 +7640,7 @@ var PerpetualsClient = (function () {
|
|
|
8068
7640
|
});
|
|
8069
7641
|
}); };
|
|
8070
7642
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8071
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
|
7643
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_59;
|
|
8072
7644
|
return __generator(this, function (_a) {
|
|
8073
7645
|
switch (_a.label) {
|
|
8074
7646
|
case 0:
|
|
@@ -8105,9 +7677,9 @@ var PerpetualsClient = (function () {
|
|
|
8105
7677
|
instructions.push(initRevenueTokenAccountInstruction);
|
|
8106
7678
|
return [3, 4];
|
|
8107
7679
|
case 3:
|
|
8108
|
-
|
|
8109
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
|
8110
|
-
throw
|
|
7680
|
+
err_59 = _a.sent();
|
|
7681
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_59);
|
|
7682
|
+
throw err_59;
|
|
8111
7683
|
case 4: return [2, {
|
|
8112
7684
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8113
7685
|
additionalSigners: additionalSigners
|
|
@@ -8116,7 +7688,7 @@ var PerpetualsClient = (function () {
|
|
|
8116
7688
|
});
|
|
8117
7689
|
}); };
|
|
8118
7690
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8119
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
|
7691
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_60;
|
|
8120
7692
|
return __generator(this, function (_a) {
|
|
8121
7693
|
switch (_a.label) {
|
|
8122
7694
|
case 0:
|
|
@@ -8155,9 +7727,9 @@ var PerpetualsClient = (function () {
|
|
|
8155
7727
|
instructions.push(distributeTokenRewardInstruction);
|
|
8156
7728
|
return [3, 4];
|
|
8157
7729
|
case 3:
|
|
8158
|
-
|
|
8159
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
|
8160
|
-
throw
|
|
7730
|
+
err_60 = _a.sent();
|
|
7731
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_60);
|
|
7732
|
+
throw err_60;
|
|
8161
7733
|
case 4: return [2, {
|
|
8162
7734
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8163
7735
|
additionalSigners: additionalSigners
|
|
@@ -8166,7 +7738,7 @@ var PerpetualsClient = (function () {
|
|
|
8166
7738
|
});
|
|
8167
7739
|
}); };
|
|
8168
7740
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
|
8169
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
|
7741
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_61;
|
|
8170
7742
|
return __generator(this, function (_a) {
|
|
8171
7743
|
switch (_a.label) {
|
|
8172
7744
|
case 0:
|
|
@@ -8194,9 +7766,9 @@ var PerpetualsClient = (function () {
|
|
|
8194
7766
|
instructions.push(setTokenStakeLevelInstruction);
|
|
8195
7767
|
return [3, 4];
|
|
8196
7768
|
case 3:
|
|
8197
|
-
|
|
8198
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
|
8199
|
-
throw
|
|
7769
|
+
err_61 = _a.sent();
|
|
7770
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_61);
|
|
7771
|
+
throw err_61;
|
|
8200
7772
|
case 4: return [2, {
|
|
8201
7773
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8202
7774
|
additionalSigners: additionalSigners
|
|
@@ -8205,7 +7777,7 @@ var PerpetualsClient = (function () {
|
|
|
8205
7777
|
});
|
|
8206
7778
|
}); };
|
|
8207
7779
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
8208
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
|
7780
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_62;
|
|
8209
7781
|
return __generator(this, function (_a) {
|
|
8210
7782
|
switch (_a.label) {
|
|
8211
7783
|
case 0:
|
|
@@ -8237,9 +7809,49 @@ var PerpetualsClient = (function () {
|
|
|
8237
7809
|
instructions.push(setTokenRewardInstruction);
|
|
8238
7810
|
return [3, 4];
|
|
8239
7811
|
case 3:
|
|
8240
|
-
|
|
8241
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
|
8242
|
-
throw
|
|
7812
|
+
err_62 = _a.sent();
|
|
7813
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_62);
|
|
7814
|
+
throw err_62;
|
|
7815
|
+
case 4: return [2, {
|
|
7816
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7817
|
+
additionalSigners: additionalSigners
|
|
7818
|
+
}];
|
|
7819
|
+
}
|
|
7820
|
+
});
|
|
7821
|
+
}); };
|
|
7822
|
+
this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
|
|
7823
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_63;
|
|
7824
|
+
return __generator(this, function (_a) {
|
|
7825
|
+
switch (_a.label) {
|
|
7826
|
+
case 0:
|
|
7827
|
+
publicKey = this.provider.wallet.publicKey;
|
|
7828
|
+
preInstructions = [];
|
|
7829
|
+
instructions = [];
|
|
7830
|
+
postInstructions = [];
|
|
7831
|
+
additionalSigners = [];
|
|
7832
|
+
_a.label = 1;
|
|
7833
|
+
case 1:
|
|
7834
|
+
_a.trys.push([1, 3, , 4]);
|
|
7835
|
+
return [4, this.program.methods
|
|
7836
|
+
.resizeInternalOracle({
|
|
7837
|
+
extOracle: extOracle
|
|
7838
|
+
})
|
|
7839
|
+
.accounts({
|
|
7840
|
+
admin: publicKey,
|
|
7841
|
+
multisig: this.multisig.publicKey,
|
|
7842
|
+
custodyTokenMint: tokenMint,
|
|
7843
|
+
intOracleAccount: intOracleAccount,
|
|
7844
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
7845
|
+
})
|
|
7846
|
+
.instruction()];
|
|
7847
|
+
case 2:
|
|
7848
|
+
resizeInternalOracleInstruction = _a.sent();
|
|
7849
|
+
instructions.push(resizeInternalOracleInstruction);
|
|
7850
|
+
return [3, 4];
|
|
7851
|
+
case 3:
|
|
7852
|
+
err_63 = _a.sent();
|
|
7853
|
+
console.log("perpClient resizeInternalOracleInstruction error:: ", err_63);
|
|
7854
|
+
throw err_63;
|
|
8243
7855
|
case 4: return [2, {
|
|
8244
7856
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8245
7857
|
additionalSigners: additionalSigners
|