flash-sdk 11.4.9-alpha.0 → 11.4.10-alpha.0
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.js +491 -703
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
|
@@ -2707,14 +2707,14 @@ var PerpetualsClient = (function () {
|
|
|
2707
2707
|
args_1[_i - 6] = arguments[_i];
|
|
2708
2708
|
}
|
|
2709
2709
|
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, userPublicKey) {
|
|
2710
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports,
|
|
2710
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
|
2711
2711
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2712
2712
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2713
2713
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
2714
2714
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
2715
2715
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2716
|
-
return __generator(this, function (
|
|
2717
|
-
switch (
|
|
2716
|
+
return __generator(this, function (_a) {
|
|
2717
|
+
switch (_a.label) {
|
|
2718
2718
|
case 0:
|
|
2719
2719
|
console.log("close position :::", marketSymbol, poolConfig.getTokenFromSymbol(marketSymbol).mintKey.toBase58());
|
|
2720
2720
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
@@ -2722,43 +2722,33 @@ var PerpetualsClient = (function () {
|
|
|
2722
2722
|
instructions = [];
|
|
2723
2723
|
postInstructions = [];
|
|
2724
2724
|
additionalSigners = [];
|
|
2725
|
-
|
|
2725
|
+
_a.label = 1;
|
|
2726
2726
|
case 1:
|
|
2727
|
-
|
|
2728
|
-
if (
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2727
|
+
_a.trys.push([1, 3, , 4]);
|
|
2728
|
+
if (collateralSymbol == 'SOL') {
|
|
2729
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
2730
|
+
if (!ephemeralSignerPubkey) {
|
|
2731
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
2732
|
+
additionalSigners.push(wrappedSolAccount);
|
|
2733
|
+
}
|
|
2734
|
+
preInstructions = [
|
|
2735
|
+
web3_js_1.SystemProgram.createAccount({
|
|
2736
|
+
fromPubkey: publicKey,
|
|
2737
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2738
|
+
lamports: lamports,
|
|
2739
|
+
space: 165,
|
|
2740
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2741
|
+
}),
|
|
2742
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
2743
|
+
];
|
|
2744
|
+
postInstructions = [
|
|
2745
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2746
|
+
];
|
|
2733
2747
|
}
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2738
|
-
lamports: lamports,
|
|
2739
|
-
space: 165,
|
|
2740
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2741
|
-
}),
|
|
2742
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
2743
|
-
];
|
|
2744
|
-
postInstructions = [
|
|
2745
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2746
|
-
];
|
|
2747
|
-
return [3, 5];
|
|
2748
|
-
case 2:
|
|
2749
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
2750
|
-
_a = createUserATA;
|
|
2751
|
-
if (!_a) return [3, 4];
|
|
2752
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
2753
|
-
case 3:
|
|
2754
|
-
_a = !(_b.sent());
|
|
2755
|
-
_b.label = 4;
|
|
2756
|
-
case 4:
|
|
2757
|
-
if (_a) {
|
|
2758
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
2748
|
+
else {
|
|
2749
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
2750
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
2759
2751
|
}
|
|
2760
|
-
_b.label = 5;
|
|
2761
|
-
case 5:
|
|
2762
2752
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
2763
2753
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
|
|
2764
2754
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -2790,19 +2780,19 @@ var PerpetualsClient = (function () {
|
|
|
2790
2780
|
})
|
|
2791
2781
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2792
2782
|
.instruction()];
|
|
2793
|
-
case
|
|
2794
|
-
instruction =
|
|
2783
|
+
case 2:
|
|
2784
|
+
instruction = _a.sent();
|
|
2795
2785
|
instructions.push(instruction);
|
|
2796
2786
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
|
2797
2787
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
2798
2788
|
postInstructions.push(closeWsolATAIns);
|
|
2799
2789
|
}
|
|
2800
|
-
return [3,
|
|
2801
|
-
case
|
|
2802
|
-
error_1 =
|
|
2790
|
+
return [3, 4];
|
|
2791
|
+
case 3:
|
|
2792
|
+
error_1 = _a.sent();
|
|
2803
2793
|
console.error("perpclient closePosition error:", error_1);
|
|
2804
2794
|
throw error_1;
|
|
2805
|
-
case
|
|
2795
|
+
case 4: return [2, {
|
|
2806
2796
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
2807
2797
|
additionalSigners: additionalSigners
|
|
2808
2798
|
}];
|
|
@@ -2848,7 +2838,7 @@ var PerpetualsClient = (function () {
|
|
|
2848
2838
|
additionalSigners = [];
|
|
2849
2839
|
targetToken = poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol);
|
|
2850
2840
|
userInputToken = poolConfig.getTokenFromSymbol(userInputTokenSymbol);
|
|
2851
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
|
2841
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 3];
|
|
2852
2842
|
console.log("inputSymbol === SOL", userInputTokenSymbol);
|
|
2853
2843
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
2854
2844
|
if (!!skipBalanceChecks) return [3, 2];
|
|
@@ -2878,41 +2868,33 @@ var PerpetualsClient = (function () {
|
|
|
2878
2868
|
postInstructions = [
|
|
2879
2869
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2880
2870
|
];
|
|
2881
|
-
if (
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
case 3:
|
|
2885
|
-
if (!(_c.sent())) {
|
|
2886
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
|
|
2871
|
+
if (!poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey.equals(spl_token_1.NATIVE_MINT)) {
|
|
2872
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
2873
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
2887
2874
|
}
|
|
2888
|
-
|
|
2889
|
-
case
|
|
2890
|
-
case 5:
|
|
2875
|
+
return [3, 7];
|
|
2876
|
+
case 3:
|
|
2891
2877
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
2892
|
-
if (!!skipBalanceChecks) return [3,
|
|
2878
|
+
if (!!skipBalanceChecks) return [3, 6];
|
|
2893
2879
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
2894
|
-
case
|
|
2880
|
+
case 4:
|
|
2895
2881
|
if (!(_c.sent())) {
|
|
2896
2882
|
throw "Insufficient Funds , Token Account doesn't exist";
|
|
2897
2883
|
}
|
|
2898
2884
|
_b = anchor_1.BN.bind;
|
|
2899
2885
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
2900
|
-
case
|
|
2886
|
+
case 5:
|
|
2901
2887
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
|
2902
2888
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
2903
2889
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
2904
2890
|
}
|
|
2905
|
-
_c.label =
|
|
2906
|
-
case
|
|
2891
|
+
_c.label = 6;
|
|
2892
|
+
case 6:
|
|
2907
2893
|
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
}
|
|
2913
|
-
_c.label = 10;
|
|
2914
|
-
case 10:
|
|
2915
|
-
_c.trys.push([10, 12, , 13]);
|
|
2894
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
2895
|
+
_c.label = 7;
|
|
2896
|
+
case 7:
|
|
2897
|
+
_c.trys.push([7, 9, , 10]);
|
|
2916
2898
|
return [4, this.program.methods
|
|
2917
2899
|
.swapAndOpen({
|
|
2918
2900
|
amountIn: amountIn,
|
|
@@ -2948,15 +2930,15 @@ var PerpetualsClient = (function () {
|
|
|
2948
2930
|
})
|
|
2949
2931
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2950
2932
|
.instruction()];
|
|
2951
|
-
case
|
|
2933
|
+
case 8:
|
|
2952
2934
|
inx = _c.sent();
|
|
2953
2935
|
instructions.push(inx);
|
|
2954
|
-
return [3,
|
|
2955
|
-
case
|
|
2936
|
+
return [3, 10];
|
|
2937
|
+
case 9:
|
|
2956
2938
|
err_3 = _c.sent();
|
|
2957
2939
|
console.error("perpClient SwapAndOpen error:: ", err_3);
|
|
2958
2940
|
throw err_3;
|
|
2959
|
-
case
|
|
2941
|
+
case 10: return [2, {
|
|
2960
2942
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
2961
2943
|
additionalSigners: additionalSigners
|
|
2962
2944
|
}];
|
|
@@ -3001,46 +2983,37 @@ var PerpetualsClient = (function () {
|
|
|
3001
2983
|
additionalSigners = [];
|
|
3002
2984
|
collateralToken = poolConfig.getTokenFromSymbol(collateralTokenSymbol);
|
|
3003
2985
|
userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
|
|
3004
|
-
if (
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
2986
|
+
if (userOutputTokenSymbol == 'SOL') {
|
|
2987
|
+
console.log("outputSymbol === SOL", userOutputTokenSymbol);
|
|
2988
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
2989
|
+
if (!ephemeralSignerPubkey) {
|
|
2990
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
2991
|
+
additionalSigners.push(wrappedSolAccount);
|
|
2992
|
+
}
|
|
2993
|
+
preInstructions = [
|
|
2994
|
+
web3_js_1.SystemProgram.createAccount({
|
|
2995
|
+
fromPubkey: publicKey,
|
|
2996
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2997
|
+
lamports: lamports,
|
|
2998
|
+
space: 165,
|
|
2999
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3000
|
+
}),
|
|
3001
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3002
|
+
];
|
|
3003
|
+
postInstructions = [
|
|
3004
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3005
|
+
];
|
|
3009
3006
|
additionalSigners.push(wrappedSolAccount);
|
|
3010
3007
|
}
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3015
|
-
lamports: lamports,
|
|
3016
|
-
space: 165,
|
|
3017
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3018
|
-
}),
|
|
3019
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3020
|
-
];
|
|
3021
|
-
postInstructions = [
|
|
3022
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3023
|
-
];
|
|
3024
|
-
additionalSigners.push(wrappedSolAccount);
|
|
3025
|
-
return [3, 3];
|
|
3026
|
-
case 1:
|
|
3027
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3028
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3029
|
-
case 2:
|
|
3030
|
-
if (!(_a.sent())) {
|
|
3031
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, userOutputToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3008
|
+
else {
|
|
3009
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3010
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, userOutputToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3032
3011
|
}
|
|
3033
|
-
_a.label = 3;
|
|
3034
|
-
case 3:
|
|
3035
3012
|
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralToken.mintKey, publicKey, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
}
|
|
3041
|
-
_a.label = 5;
|
|
3042
|
-
case 5:
|
|
3043
|
-
_a.trys.push([5, 7, , 8]);
|
|
3013
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3014
|
+
_a.label = 1;
|
|
3015
|
+
case 1:
|
|
3016
|
+
_a.trys.push([1, 3, , 4]);
|
|
3044
3017
|
return [4, this.program.methods
|
|
3045
3018
|
.closeAndSwap({
|
|
3046
3019
|
priceWithSlippage: priceWithSlippage,
|
|
@@ -3074,15 +3047,15 @@ var PerpetualsClient = (function () {
|
|
|
3074
3047
|
})
|
|
3075
3048
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3076
3049
|
.instruction()];
|
|
3077
|
-
case
|
|
3050
|
+
case 2:
|
|
3078
3051
|
inx = _a.sent();
|
|
3079
3052
|
instructions.push(inx);
|
|
3080
|
-
return [3,
|
|
3081
|
-
case
|
|
3053
|
+
return [3, 4];
|
|
3054
|
+
case 3:
|
|
3082
3055
|
err_4 = _a.sent();
|
|
3083
3056
|
console.error("perpClient CloseAndSwap error:: ", err_4);
|
|
3084
3057
|
throw err_4;
|
|
3085
|
-
case
|
|
3058
|
+
case 4: return [2, {
|
|
3086
3059
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3087
3060
|
additionalSigners: additionalSigners
|
|
3088
3061
|
}];
|
|
@@ -3269,11 +3242,7 @@ var PerpetualsClient = (function () {
|
|
|
3269
3242
|
_c.label = 6;
|
|
3270
3243
|
case 6:
|
|
3271
3244
|
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3272
|
-
|
|
3273
|
-
case 7:
|
|
3274
|
-
if (!(_c.sent())) {
|
|
3275
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3276
|
-
}
|
|
3245
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3277
3246
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3278
3247
|
return [4, this.program.methods.swapAndAddCollateral({
|
|
3279
3248
|
amountIn: amountIn,
|
|
@@ -3301,7 +3270,7 @@ var PerpetualsClient = (function () {
|
|
|
3301
3270
|
fundingMint: poolConfig.getTokenFromSymbol(inputSymbol).mintKey,
|
|
3302
3271
|
})
|
|
3303
3272
|
.instruction()];
|
|
3304
|
-
case
|
|
3273
|
+
case 7:
|
|
3305
3274
|
instruction = _c.sent();
|
|
3306
3275
|
instructions.push(instruction);
|
|
3307
3276
|
return [2, {
|
|
@@ -3318,12 +3287,12 @@ var PerpetualsClient = (function () {
|
|
|
3318
3287
|
args_1[_i - 6] = arguments[_i];
|
|
3319
3288
|
}
|
|
3320
3289
|
return __awaiter(_this, __spreadArray([collateralDeltaUsd_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralDeltaUsd, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
|
3321
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports,
|
|
3290
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, marketAccount, instruction, closeWsolATAIns, error_2;
|
|
3322
3291
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
3323
3292
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
3324
3293
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3325
|
-
return __generator(this, function (
|
|
3326
|
-
switch (
|
|
3294
|
+
return __generator(this, function (_a) {
|
|
3295
|
+
switch (_a.label) {
|
|
3327
3296
|
case 0:
|
|
3328
3297
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3329
3298
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
@@ -3339,45 +3308,35 @@ var PerpetualsClient = (function () {
|
|
|
3339
3308
|
instructions = [];
|
|
3340
3309
|
postInstructions = [];
|
|
3341
3310
|
additionalSigners = [];
|
|
3342
|
-
|
|
3311
|
+
_a.label = 1;
|
|
3343
3312
|
case 1:
|
|
3344
|
-
|
|
3313
|
+
_a.trys.push([1, 3, , 4]);
|
|
3345
3314
|
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
|
3346
|
-
if (
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3315
|
+
if (collateralSymbol == 'SOL') {
|
|
3316
|
+
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
|
3317
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3318
|
+
if (!ephemeralSignerPubkey) {
|
|
3319
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3320
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3321
|
+
}
|
|
3322
|
+
preInstructions = [
|
|
3323
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3324
|
+
fromPubkey: publicKey,
|
|
3325
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3326
|
+
lamports: lamports,
|
|
3327
|
+
space: 165,
|
|
3328
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3329
|
+
}),
|
|
3330
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3331
|
+
];
|
|
3332
|
+
postInstructions = [
|
|
3333
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3334
|
+
];
|
|
3352
3335
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3357
|
-
lamports: lamports,
|
|
3358
|
-
space: 165,
|
|
3359
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3360
|
-
}),
|
|
3361
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3362
|
-
];
|
|
3363
|
-
postInstructions = [
|
|
3364
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3365
|
-
];
|
|
3366
|
-
return [3, 5];
|
|
3367
|
-
case 2:
|
|
3368
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3369
|
-
_a = createUserATA;
|
|
3370
|
-
if (!_a) return [3, 4];
|
|
3371
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3372
|
-
case 3:
|
|
3373
|
-
_a = !(_b.sent());
|
|
3374
|
-
_b.label = 4;
|
|
3375
|
-
case 4:
|
|
3376
|
-
if (_a) {
|
|
3377
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3336
|
+
else {
|
|
3337
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3338
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3378
3339
|
}
|
|
3379
|
-
_b.label = 5;
|
|
3380
|
-
case 5:
|
|
3381
3340
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3382
3341
|
return [4, this.program.methods
|
|
3383
3342
|
.removeCollateral({
|
|
@@ -3403,19 +3362,19 @@ var PerpetualsClient = (function () {
|
|
|
3403
3362
|
receivingMint: collateralCustodyConfig.mintKey
|
|
3404
3363
|
})
|
|
3405
3364
|
.instruction()];
|
|
3406
|
-
case
|
|
3407
|
-
instruction =
|
|
3365
|
+
case 2:
|
|
3366
|
+
instruction = _a.sent();
|
|
3408
3367
|
instructions.push(instruction);
|
|
3409
3368
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
|
3410
3369
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
3411
3370
|
postInstructions.push(closeWsolATAIns);
|
|
3412
3371
|
}
|
|
3413
|
-
return [3,
|
|
3414
|
-
case
|
|
3415
|
-
error_2 =
|
|
3372
|
+
return [3, 4];
|
|
3373
|
+
case 3:
|
|
3374
|
+
error_2 = _a.sent();
|
|
3416
3375
|
console.error("perpclient removeCollateral error:", error_2);
|
|
3417
3376
|
throw error_2;
|
|
3418
|
-
case
|
|
3377
|
+
case 4: return [2, {
|
|
3419
3378
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3420
3379
|
additionalSigners: additionalSigners
|
|
3421
3380
|
}];
|
|
@@ -3445,42 +3404,33 @@ var PerpetualsClient = (function () {
|
|
|
3445
3404
|
instructions = [];
|
|
3446
3405
|
postInstructions = [];
|
|
3447
3406
|
additionalSigners = [];
|
|
3448
|
-
if (
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3407
|
+
if (outputSymbol == 'SOL') {
|
|
3408
|
+
console.log("outputSymbol === SOL", outputSymbol);
|
|
3409
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3410
|
+
if (!ephemeralSignerPubkey) {
|
|
3411
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3412
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3413
|
+
}
|
|
3414
|
+
preInstructions = [
|
|
3415
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3416
|
+
fromPubkey: publicKey,
|
|
3417
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3418
|
+
lamports: lamports,
|
|
3419
|
+
space: 165,
|
|
3420
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3421
|
+
}),
|
|
3422
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3423
|
+
];
|
|
3424
|
+
postInstructions = [
|
|
3425
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3426
|
+
];
|
|
3454
3427
|
}
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3459
|
-
lamports: lamports,
|
|
3460
|
-
space: 165,
|
|
3461
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3462
|
-
}),
|
|
3463
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3464
|
-
];
|
|
3465
|
-
postInstructions = [
|
|
3466
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3467
|
-
];
|
|
3468
|
-
return [3, 3];
|
|
3469
|
-
case 1:
|
|
3470
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3471
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3472
|
-
case 2:
|
|
3473
|
-
if (!(_a.sent())) {
|
|
3474
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(outputSymbol).mintKey, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3428
|
+
else {
|
|
3429
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3430
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(outputSymbol).mintKey, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3475
3431
|
}
|
|
3476
|
-
_a.label = 3;
|
|
3477
|
-
case 3:
|
|
3478
3432
|
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3479
|
-
|
|
3480
|
-
case 4:
|
|
3481
|
-
if (!(_a.sent())) {
|
|
3482
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3483
|
-
}
|
|
3433
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3484
3434
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3485
3435
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
3486
3436
|
return [4, this.program.methods
|
|
@@ -3514,7 +3464,7 @@ var PerpetualsClient = (function () {
|
|
|
3514
3464
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
3515
3465
|
})
|
|
3516
3466
|
.instruction()];
|
|
3517
|
-
case
|
|
3467
|
+
case 1:
|
|
3518
3468
|
instruction = _a.sent();
|
|
3519
3469
|
instructions.push(instruction);
|
|
3520
3470
|
return [2, {
|
|
@@ -3678,7 +3628,7 @@ var PerpetualsClient = (function () {
|
|
|
3678
3628
|
payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
|
|
3679
3629
|
_g.label = 1;
|
|
3680
3630
|
case 1:
|
|
3681
|
-
_g.trys.push([1,
|
|
3631
|
+
_g.trys.push([1, 9, , 10]);
|
|
3682
3632
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3683
3633
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
|
3684
3634
|
custodyAccountMetas = [];
|
|
@@ -3705,24 +3655,20 @@ var PerpetualsClient = (function () {
|
|
|
3705
3655
|
isWritable: false,
|
|
3706
3656
|
});
|
|
3707
3657
|
}
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
if (!(_g.sent())) {
|
|
3711
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
3712
|
-
}
|
|
3713
|
-
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
|
3658
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
3659
|
+
if (!(payTokenSymbol == 'SOL')) return [3, 4];
|
|
3714
3660
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
|
3715
3661
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
3716
|
-
if (!!skipBalanceChecks) return [3,
|
|
3662
|
+
if (!!skipBalanceChecks) return [3, 3];
|
|
3717
3663
|
_e = anchor_1.BN.bind;
|
|
3718
3664
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
3719
|
-
case
|
|
3665
|
+
case 2:
|
|
3720
3666
|
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
|
3721
3667
|
if (unWrappedSolBalance.lt(lamports)) {
|
|
3722
3668
|
throw "Insufficient SOL Funds";
|
|
3723
3669
|
}
|
|
3724
|
-
_g.label =
|
|
3725
|
-
case
|
|
3670
|
+
_g.label = 3;
|
|
3671
|
+
case 3:
|
|
3726
3672
|
if (!ephemeralSignerPubkey) {
|
|
3727
3673
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3728
3674
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -3740,23 +3686,23 @@ var PerpetualsClient = (function () {
|
|
|
3740
3686
|
postInstructions = [
|
|
3741
3687
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3742
3688
|
];
|
|
3743
|
-
return [3,
|
|
3744
|
-
case
|
|
3745
|
-
if (!!skipBalanceChecks) return [3,
|
|
3689
|
+
return [3, 7];
|
|
3690
|
+
case 4:
|
|
3691
|
+
if (!!skipBalanceChecks) return [3, 7];
|
|
3746
3692
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
|
3747
|
-
case
|
|
3693
|
+
case 5:
|
|
3748
3694
|
if (!(_g.sent())) {
|
|
3749
3695
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
3750
3696
|
}
|
|
3751
3697
|
_f = anchor_1.BN.bind;
|
|
3752
3698
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
|
3753
|
-
case
|
|
3699
|
+
case 6:
|
|
3754
3700
|
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
3755
3701
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
|
3756
3702
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
|
3757
3703
|
}
|
|
3758
|
-
_g.label =
|
|
3759
|
-
case
|
|
3704
|
+
_g.label = 7;
|
|
3705
|
+
case 7:
|
|
3760
3706
|
whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
|
|
3761
3707
|
whitelistMeta = {
|
|
3762
3708
|
pubkey: whitelistPda,
|
|
@@ -3788,15 +3734,15 @@ var PerpetualsClient = (function () {
|
|
|
3788
3734
|
})
|
|
3789
3735
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
3790
3736
|
.instruction()];
|
|
3791
|
-
case
|
|
3737
|
+
case 8:
|
|
3792
3738
|
instruction = _g.sent();
|
|
3793
3739
|
instructions.push(instruction);
|
|
3794
|
-
return [3,
|
|
3795
|
-
case
|
|
3740
|
+
return [3, 10];
|
|
3741
|
+
case 9:
|
|
3796
3742
|
err_5 = _g.sent();
|
|
3797
3743
|
console.error("perpClient addLiquidity error:: ", err_5);
|
|
3798
3744
|
throw err_5;
|
|
3799
|
-
case
|
|
3745
|
+
case 10: return [2, {
|
|
3800
3746
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3801
3747
|
additionalSigners: additionalSigners
|
|
3802
3748
|
}];
|
|
@@ -3829,7 +3775,7 @@ var PerpetualsClient = (function () {
|
|
|
3829
3775
|
inputToken = poolConfig.getTokenFromSymbol(inputSymbol);
|
|
3830
3776
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
3831
3777
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
|
3832
|
-
if (!(inputSymbol == 'SOL')) return [3,
|
|
3778
|
+
if (!(inputSymbol == 'SOL')) return [3, 3];
|
|
3833
3779
|
console.log("inputSymbol === SOL", inputSymbol);
|
|
3834
3780
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
3835
3781
|
console.log("lamports:", lamports.toNumber());
|
|
@@ -3842,11 +3788,8 @@ var PerpetualsClient = (function () {
|
|
|
3842
3788
|
throw "Insufficient SOL Funds";
|
|
3843
3789
|
}
|
|
3844
3790
|
_g.label = 2;
|
|
3845
|
-
case 2:
|
|
3846
|
-
|
|
3847
|
-
if (!(_g.sent())) {
|
|
3848
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
3849
|
-
}
|
|
3791
|
+
case 2:
|
|
3792
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
3850
3793
|
if (!ephemeralSignerPubkey) {
|
|
3851
3794
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3852
3795
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -3864,24 +3807,24 @@ var PerpetualsClient = (function () {
|
|
|
3864
3807
|
postInstructions = [
|
|
3865
3808
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3866
3809
|
];
|
|
3867
|
-
return [3,
|
|
3868
|
-
case
|
|
3810
|
+
return [3, 6];
|
|
3811
|
+
case 3:
|
|
3869
3812
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3870
|
-
if (!!skipBalanceChecks) return [3,
|
|
3813
|
+
if (!!skipBalanceChecks) return [3, 6];
|
|
3871
3814
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
3872
|
-
case
|
|
3815
|
+
case 4:
|
|
3873
3816
|
if (!(_g.sent())) {
|
|
3874
3817
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
3875
3818
|
}
|
|
3876
3819
|
_b = anchor_1.BN.bind;
|
|
3877
3820
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
3878
|
-
case
|
|
3821
|
+
case 5:
|
|
3879
3822
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
3880
3823
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
3881
3824
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
3882
3825
|
}
|
|
3883
|
-
_g.label =
|
|
3884
|
-
case
|
|
3826
|
+
_g.label = 6;
|
|
3827
|
+
case 6:
|
|
3885
3828
|
custodyAccountMetas = [];
|
|
3886
3829
|
custodyOracleAccountMetas = [];
|
|
3887
3830
|
markets = [];
|
|
@@ -3938,7 +3881,7 @@ var PerpetualsClient = (function () {
|
|
|
3938
3881
|
})
|
|
3939
3882
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
3940
3883
|
.instruction()];
|
|
3941
|
-
case
|
|
3884
|
+
case 7:
|
|
3942
3885
|
instruction = _g.sent();
|
|
3943
3886
|
instructions.push(instruction);
|
|
3944
3887
|
return [2, {
|
|
@@ -3955,15 +3898,15 @@ var PerpetualsClient = (function () {
|
|
|
3955
3898
|
args_1[_i - 4] = arguments[_i];
|
|
3956
3899
|
}
|
|
3957
3900
|
return __awaiter(_this, __spreadArray([recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1], args_1, true), void 0, function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey, isWhitelistedUser) {
|
|
3958
|
-
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports,
|
|
3901
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, whitelistPda, whitelistMeta, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
|
|
3959
3902
|
if (closeLpATA === void 0) { closeLpATA = false; }
|
|
3960
3903
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
3961
3904
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
3962
3905
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3963
3906
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
3964
3907
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
3965
|
-
return __generator(this, function (
|
|
3966
|
-
switch (
|
|
3908
|
+
return __generator(this, function (_e) {
|
|
3909
|
+
switch (_e.label) {
|
|
3967
3910
|
case 0:
|
|
3968
3911
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
|
3969
3912
|
if (!recieveTokenCustodyConfig) {
|
|
@@ -3975,9 +3918,9 @@ var PerpetualsClient = (function () {
|
|
|
3975
3918
|
postInstructions = [];
|
|
3976
3919
|
additionalSigners = [];
|
|
3977
3920
|
recieveToken = poolConfig.getTokenFromSymbol(recieveTokenSymbol);
|
|
3978
|
-
|
|
3921
|
+
_e.label = 1;
|
|
3979
3922
|
case 1:
|
|
3980
|
-
|
|
3923
|
+
_e.trys.push([1, 3, , 4]);
|
|
3981
3924
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
|
3982
3925
|
custodyAccountMetas = [];
|
|
3983
3926
|
custodyOracleAccountMetas = [];
|
|
@@ -4003,40 +3946,30 @@ var PerpetualsClient = (function () {
|
|
|
4003
3946
|
isWritable: false,
|
|
4004
3947
|
});
|
|
4005
3948
|
}
|
|
4006
|
-
if (
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
3949
|
+
if (recieveTokenSymbol == 'SOL') {
|
|
3950
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3951
|
+
if (!ephemeralSignerPubkey) {
|
|
3952
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3953
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3954
|
+
}
|
|
3955
|
+
preInstructions = [
|
|
3956
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3957
|
+
fromPubkey: publicKey,
|
|
3958
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3959
|
+
lamports: lamports,
|
|
3960
|
+
space: 165,
|
|
3961
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3962
|
+
}),
|
|
3963
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3964
|
+
];
|
|
3965
|
+
postInstructions = [
|
|
3966
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3967
|
+
];
|
|
4011
3968
|
}
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4016
|
-
lamports: lamports,
|
|
4017
|
-
space: 165,
|
|
4018
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4019
|
-
}),
|
|
4020
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4021
|
-
];
|
|
4022
|
-
postInstructions = [
|
|
4023
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4024
|
-
];
|
|
4025
|
-
return [3, 5];
|
|
4026
|
-
case 2:
|
|
4027
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(recieveToken.mintKey, publicKey, true, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
4028
|
-
_e = createUserATA;
|
|
4029
|
-
if (!_e) return [3, 4];
|
|
4030
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
4031
|
-
case 3:
|
|
4032
|
-
_e = !(_f.sent());
|
|
4033
|
-
_f.label = 4;
|
|
4034
|
-
case 4:
|
|
4035
|
-
if (_e) {
|
|
4036
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, recieveToken.mintKey, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3969
|
+
else {
|
|
3970
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(recieveToken.mintKey, publicKey, true, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3971
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, recieveToken.mintKey, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
4037
3972
|
}
|
|
4038
|
-
_f.label = 5;
|
|
4039
|
-
case 5:
|
|
4040
3973
|
whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
|
|
4041
3974
|
whitelistMeta = {
|
|
4042
3975
|
pubkey: whitelistPda,
|
|
@@ -4068,8 +4001,8 @@ var PerpetualsClient = (function () {
|
|
|
4068
4001
|
})
|
|
4069
4002
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4070
4003
|
.instruction()];
|
|
4071
|
-
case
|
|
4072
|
-
removeLiquidityTx =
|
|
4004
|
+
case 2:
|
|
4005
|
+
removeLiquidityTx = _e.sent();
|
|
4073
4006
|
instructions.push(removeLiquidityTx);
|
|
4074
4007
|
if (closeLpATA) {
|
|
4075
4008
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
|
@@ -4079,12 +4012,12 @@ var PerpetualsClient = (function () {
|
|
|
4079
4012
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
4080
4013
|
postInstructions.push(closeWsolATAIns);
|
|
4081
4014
|
}
|
|
4082
|
-
return [3,
|
|
4083
|
-
case
|
|
4084
|
-
err_6 =
|
|
4015
|
+
return [3, 4];
|
|
4016
|
+
case 3:
|
|
4017
|
+
err_6 = _e.sent();
|
|
4085
4018
|
console.log("perpClient removeLiquidity error:: ", err_6);
|
|
4086
4019
|
throw err_6;
|
|
4087
|
-
case
|
|
4020
|
+
case 4: return [2, {
|
|
4088
4021
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4089
4022
|
additionalSigners: additionalSigners
|
|
4090
4023
|
}];
|
|
@@ -4472,37 +4405,28 @@ var PerpetualsClient = (function () {
|
|
|
4472
4405
|
args_1[_i - 1] = arguments[_i];
|
|
4473
4406
|
}
|
|
4474
4407
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
|
4475
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount,
|
|
4408
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, withdrawStakeInstruction, err_14;
|
|
4476
4409
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
|
4477
4410
|
if (deactivated === void 0) { deactivated = true; }
|
|
4478
4411
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
|
4479
4412
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4480
|
-
return __generator(this, function (
|
|
4481
|
-
switch (
|
|
4413
|
+
return __generator(this, function (_a) {
|
|
4414
|
+
switch (_a.label) {
|
|
4482
4415
|
case 0:
|
|
4483
4416
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
4484
4417
|
preInstructions = [];
|
|
4485
4418
|
instructions = [];
|
|
4486
4419
|
postInstructions = [];
|
|
4487
4420
|
additionalSigners = [];
|
|
4488
|
-
|
|
4421
|
+
_a.label = 1;
|
|
4489
4422
|
case 1:
|
|
4490
|
-
|
|
4423
|
+
_a.trys.push([1, 3, , 4]);
|
|
4491
4424
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
4492
4425
|
pool = poolConfig.poolAddress;
|
|
4493
4426
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), pool.toBuffer(), lpTokenMint.toBuffer()], this.program.programId)[0];
|
|
4494
4427
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
|
4495
4428
|
userLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
|
4496
|
-
|
|
4497
|
-
if (!_a) return [3, 3];
|
|
4498
|
-
return [4, (0, utils_1.checkIfAccountExists)(userLpTokenAccount, this.provider.connection)];
|
|
4499
|
-
case 2:
|
|
4500
|
-
_a = !(_b.sent());
|
|
4501
|
-
_b.label = 3;
|
|
4502
|
-
case 3:
|
|
4503
|
-
if (_a) {
|
|
4504
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userLpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
4505
|
-
}
|
|
4429
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userLpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4506
4430
|
return [4, this.program.methods
|
|
4507
4431
|
.withdrawStake({
|
|
4508
4432
|
pendingActivation: pendingActivation,
|
|
@@ -4523,15 +4447,15 @@ var PerpetualsClient = (function () {
|
|
|
4523
4447
|
lpMint: poolConfig.stakedLpTokenMint,
|
|
4524
4448
|
})
|
|
4525
4449
|
.instruction()];
|
|
4526
|
-
case
|
|
4527
|
-
withdrawStakeInstruction =
|
|
4450
|
+
case 2:
|
|
4451
|
+
withdrawStakeInstruction = _a.sent();
|
|
4528
4452
|
instructions.push(withdrawStakeInstruction);
|
|
4529
|
-
return [3,
|
|
4530
|
-
case
|
|
4531
|
-
err_14 =
|
|
4453
|
+
return [3, 4];
|
|
4454
|
+
case 3:
|
|
4455
|
+
err_14 = _a.sent();
|
|
4532
4456
|
console.log("perpClient withdrawStake error:: ", err_14);
|
|
4533
4457
|
throw err_14;
|
|
4534
|
-
case
|
|
4458
|
+
case 4: return [2, {
|
|
4535
4459
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4536
4460
|
additionalSigners: additionalSigners
|
|
4537
4461
|
}];
|
|
@@ -4545,10 +4469,10 @@ var PerpetualsClient = (function () {
|
|
|
4545
4469
|
args_1[_i - 3] = arguments[_i];
|
|
4546
4470
|
}
|
|
4547
4471
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
|
4548
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount,
|
|
4472
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
|
4549
4473
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4550
|
-
return __generator(this, function (
|
|
4551
|
-
switch (
|
|
4474
|
+
return __generator(this, function (_a) {
|
|
4475
|
+
switch (_a.label) {
|
|
4552
4476
|
case 0:
|
|
4553
4477
|
publicKey = this.provider.wallet.publicKey;
|
|
4554
4478
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
@@ -4557,22 +4481,13 @@ var PerpetualsClient = (function () {
|
|
|
4557
4481
|
instructions = [];
|
|
4558
4482
|
postInstructions = [];
|
|
4559
4483
|
additionalSigners = [];
|
|
4560
|
-
|
|
4484
|
+
_a.label = 1;
|
|
4561
4485
|
case 1:
|
|
4562
|
-
|
|
4486
|
+
_a.trys.push([1, 3, , 4]);
|
|
4563
4487
|
pool = poolConfig.poolAddress;
|
|
4564
4488
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
|
4565
4489
|
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
|
4566
|
-
|
|
4567
|
-
if (!_a) return [3, 3];
|
|
4568
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
4569
|
-
case 2:
|
|
4570
|
-
_a = !(_b.sent());
|
|
4571
|
-
_b.label = 3;
|
|
4572
|
-
case 3:
|
|
4573
|
-
if (_a) {
|
|
4574
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
|
4575
|
-
}
|
|
4490
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4576
4491
|
tokenStakeAccounts = [];
|
|
4577
4492
|
if (tokenStakeAccount) {
|
|
4578
4493
|
tokenStakeAccounts.push({
|
|
@@ -4601,15 +4516,15 @@ var PerpetualsClient = (function () {
|
|
|
4601
4516
|
})
|
|
4602
4517
|
.remainingAccounts(__spreadArray([], tokenStakeAccounts, true))
|
|
4603
4518
|
.instruction()];
|
|
4604
|
-
case
|
|
4605
|
-
withdrawStakeInstruction =
|
|
4519
|
+
case 2:
|
|
4520
|
+
withdrawStakeInstruction = _a.sent();
|
|
4606
4521
|
instructions.push(withdrawStakeInstruction);
|
|
4607
|
-
return [3,
|
|
4608
|
-
case
|
|
4609
|
-
err_15 =
|
|
4522
|
+
return [3, 4];
|
|
4523
|
+
case 3:
|
|
4524
|
+
err_15 = _a.sent();
|
|
4610
4525
|
console.log("perpClient withdrawStake error:: ", err_15);
|
|
4611
4526
|
throw err_15;
|
|
4612
|
-
case
|
|
4527
|
+
case 4: return [2, {
|
|
4613
4528
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4614
4529
|
additionalSigners: additionalSigners
|
|
4615
4530
|
}];
|
|
@@ -4668,29 +4583,21 @@ var PerpetualsClient = (function () {
|
|
|
4668
4583
|
isWritable: false,
|
|
4669
4584
|
});
|
|
4670
4585
|
}
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
if (!(
|
|
4674
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
4675
|
-
}
|
|
4676
|
-
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
|
4677
|
-
case 2:
|
|
4678
|
-
if (!(_f.sent())) {
|
|
4679
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
|
4680
|
-
}
|
|
4681
|
-
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
|
4586
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4587
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4588
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 3];
|
|
4682
4589
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
|
4683
4590
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
4684
|
-
if (!!skipBalanceChecks) return [3,
|
|
4591
|
+
if (!!skipBalanceChecks) return [3, 2];
|
|
4685
4592
|
_e = anchor_1.BN.bind;
|
|
4686
4593
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
4687
|
-
case
|
|
4594
|
+
case 1:
|
|
4688
4595
|
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
4689
4596
|
if (unWrappedSolBalance.lt(lamports)) {
|
|
4690
4597
|
throw "Insufficient SOL Funds";
|
|
4691
4598
|
}
|
|
4692
|
-
_f.label =
|
|
4693
|
-
case
|
|
4599
|
+
_f.label = 2;
|
|
4600
|
+
case 2:
|
|
4694
4601
|
if (!ephemeralSignerPubkey) {
|
|
4695
4602
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
4696
4603
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -4708,17 +4615,17 @@ var PerpetualsClient = (function () {
|
|
|
4708
4615
|
postInstructions = [
|
|
4709
4616
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4710
4617
|
];
|
|
4711
|
-
return [3,
|
|
4712
|
-
case
|
|
4713
|
-
if (!!skipBalanceChecks) return [3,
|
|
4618
|
+
return [3, 5];
|
|
4619
|
+
case 3:
|
|
4620
|
+
if (!!skipBalanceChecks) return [3, 5];
|
|
4714
4621
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
|
4715
|
-
case
|
|
4622
|
+
case 4:
|
|
4716
4623
|
if (!(_f.sent())) {
|
|
4717
4624
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
4718
4625
|
}
|
|
4719
|
-
_f.label =
|
|
4720
|
-
case
|
|
4721
|
-
_f.trys.push([
|
|
4626
|
+
_f.label = 5;
|
|
4627
|
+
case 5:
|
|
4628
|
+
_f.trys.push([5, 7, , 8]);
|
|
4722
4629
|
if (enableHeapSizeIx) {
|
|
4723
4630
|
heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
|
|
4724
4631
|
bytes: 64 * 1024,
|
|
@@ -4760,15 +4667,15 @@ var PerpetualsClient = (function () {
|
|
|
4760
4667
|
})
|
|
4761
4668
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4762
4669
|
.instruction()];
|
|
4763
|
-
case
|
|
4670
|
+
case 6:
|
|
4764
4671
|
addCompoundingLiquidity = _f.sent();
|
|
4765
4672
|
instructions.push(addCompoundingLiquidity);
|
|
4766
|
-
return [3,
|
|
4767
|
-
case
|
|
4673
|
+
return [3, 8];
|
|
4674
|
+
case 7:
|
|
4768
4675
|
err_16 = _f.sent();
|
|
4769
4676
|
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
|
4770
|
-
return [3,
|
|
4771
|
-
case
|
|
4677
|
+
return [3, 8];
|
|
4678
|
+
case 8: return [2, {
|
|
4772
4679
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4773
4680
|
additionalSigners: additionalSigners
|
|
4774
4681
|
}];
|
|
@@ -4782,14 +4689,14 @@ var PerpetualsClient = (function () {
|
|
|
4782
4689
|
args_1[_i - 5] = arguments[_i];
|
|
4783
4690
|
}
|
|
4784
4691
|
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, enableHeapSizeIx, isWhitelistedUser) {
|
|
4785
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports,
|
|
4692
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingTokenAccount, heapSizeIx, whitelistPda, whitelistMeta, removeCompoundingLiquidity, err_17;
|
|
4786
4693
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4787
4694
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4788
4695
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4789
4696
|
if (enableHeapSizeIx === void 0) { enableHeapSizeIx = true; }
|
|
4790
4697
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
4791
|
-
return __generator(this, function (
|
|
4792
|
-
switch (
|
|
4698
|
+
return __generator(this, function (_e) {
|
|
4699
|
+
switch (_e.label) {
|
|
4793
4700
|
case 0:
|
|
4794
4701
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
4795
4702
|
preInstructions = [];
|
|
@@ -4800,45 +4707,35 @@ var PerpetualsClient = (function () {
|
|
|
4800
4707
|
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
|
4801
4708
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
4802
4709
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
|
4803
|
-
if (
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4710
|
+
if (outCustodyConfig.symbol == 'SOL') {
|
|
4711
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
4712
|
+
if (!ephemeralSignerPubkey) {
|
|
4713
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
4714
|
+
additionalSigners.push(wrappedSolAccount);
|
|
4715
|
+
}
|
|
4716
|
+
preInstructions = [
|
|
4717
|
+
web3_js_1.SystemProgram.createAccount({
|
|
4718
|
+
fromPubkey: publicKey,
|
|
4719
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4720
|
+
lamports: lamports,
|
|
4721
|
+
space: 165,
|
|
4722
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4723
|
+
}),
|
|
4724
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4725
|
+
];
|
|
4726
|
+
postInstructions = [
|
|
4727
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4728
|
+
];
|
|
4808
4729
|
}
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4813
|
-
lamports: lamports,
|
|
4814
|
-
space: 165,
|
|
4815
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4816
|
-
}),
|
|
4817
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4818
|
-
];
|
|
4819
|
-
postInstructions = [
|
|
4820
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4821
|
-
];
|
|
4822
|
-
return [3, 4];
|
|
4823
|
-
case 1:
|
|
4824
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
4825
|
-
_a = createUserATA;
|
|
4826
|
-
if (!_a) return [3, 3];
|
|
4827
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
4828
|
-
case 2:
|
|
4829
|
-
_a = !(_f.sent());
|
|
4830
|
-
_f.label = 3;
|
|
4831
|
-
case 3:
|
|
4832
|
-
if (_a) {
|
|
4833
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
4730
|
+
else {
|
|
4731
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
4732
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
4834
4733
|
}
|
|
4835
|
-
_f.label = 4;
|
|
4836
|
-
case 4:
|
|
4837
4734
|
custodyAccountMetas = [];
|
|
4838
4735
|
custodyOracleAccountMetas = [];
|
|
4839
4736
|
markets = [];
|
|
4840
|
-
for (
|
|
4841
|
-
custody =
|
|
4737
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
|
4738
|
+
custody = _b[_a];
|
|
4842
4739
|
custodyAccountMetas.push({
|
|
4843
4740
|
pubkey: custody.custodyAccount,
|
|
4844
4741
|
isSigner: false,
|
|
@@ -4850,8 +4747,8 @@ var PerpetualsClient = (function () {
|
|
|
4850
4747
|
isWritable: false,
|
|
4851
4748
|
});
|
|
4852
4749
|
}
|
|
4853
|
-
for (
|
|
4854
|
-
market =
|
|
4750
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
|
4751
|
+
market = _d[_c];
|
|
4855
4752
|
markets.push({
|
|
4856
4753
|
pubkey: market.marketAccount,
|
|
4857
4754
|
isSigner: false,
|
|
@@ -4859,9 +4756,9 @@ var PerpetualsClient = (function () {
|
|
|
4859
4756
|
});
|
|
4860
4757
|
}
|
|
4861
4758
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
|
4862
|
-
|
|
4863
|
-
case
|
|
4864
|
-
|
|
4759
|
+
_e.label = 1;
|
|
4760
|
+
case 1:
|
|
4761
|
+
_e.trys.push([1, 3, , 4]);
|
|
4865
4762
|
if (enableHeapSizeIx) {
|
|
4866
4763
|
heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
|
|
4867
4764
|
bytes: 64 * 1024,
|
|
@@ -4903,15 +4800,15 @@ var PerpetualsClient = (function () {
|
|
|
4903
4800
|
})
|
|
4904
4801
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4905
4802
|
.instruction()];
|
|
4906
|
-
case
|
|
4907
|
-
removeCompoundingLiquidity =
|
|
4803
|
+
case 2:
|
|
4804
|
+
removeCompoundingLiquidity = _e.sent();
|
|
4908
4805
|
instructions.push(removeCompoundingLiquidity);
|
|
4909
|
-
return [3,
|
|
4910
|
-
case
|
|
4911
|
-
err_17 =
|
|
4806
|
+
return [3, 4];
|
|
4807
|
+
case 3:
|
|
4808
|
+
err_17 = _e.sent();
|
|
4912
4809
|
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
|
4913
|
-
return [3,
|
|
4914
|
-
case
|
|
4810
|
+
return [3, 4];
|
|
4811
|
+
case 4: return [2, {
|
|
4915
4812
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4916
4813
|
additionalSigners: additionalSigners
|
|
4917
4814
|
}];
|
|
@@ -4925,10 +4822,10 @@ var PerpetualsClient = (function () {
|
|
|
4925
4822
|
args_1[_i - 3] = arguments[_i];
|
|
4926
4823
|
}
|
|
4927
4824
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA, userPublicKey) {
|
|
4928
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount,
|
|
4825
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, migrateStake, err_18;
|
|
4929
4826
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4930
|
-
return __generator(this, function (
|
|
4931
|
-
switch (
|
|
4827
|
+
return __generator(this, function (_f) {
|
|
4828
|
+
switch (_f.label) {
|
|
4932
4829
|
case 0:
|
|
4933
4830
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
4934
4831
|
preInstructions = [];
|
|
@@ -4939,27 +4836,18 @@ var PerpetualsClient = (function () {
|
|
|
4939
4836
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
4940
4837
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
|
4941
4838
|
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
|
4942
|
-
|
|
4943
|
-
if (!_a) return [3, 2];
|
|
4944
|
-
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
|
4945
|
-
case 1:
|
|
4946
|
-
_a = !(_g.sent());
|
|
4947
|
-
_g.label = 2;
|
|
4948
|
-
case 2:
|
|
4949
|
-
if (_a) {
|
|
4950
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
|
4951
|
-
}
|
|
4839
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4952
4840
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
4953
4841
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), publicKey.toBuffer()], this.programId)[0];
|
|
4954
4842
|
tokenStakeAccounts = [];
|
|
4955
|
-
|
|
4956
|
-
if (!
|
|
4843
|
+
_a = tokenStakeAccount;
|
|
4844
|
+
if (!_a) return [3, 2];
|
|
4957
4845
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
|
4958
|
-
case
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
case
|
|
4962
|
-
if (
|
|
4846
|
+
case 1:
|
|
4847
|
+
_a = (_f.sent());
|
|
4848
|
+
_f.label = 2;
|
|
4849
|
+
case 2:
|
|
4850
|
+
if (_a) {
|
|
4963
4851
|
tokenStakeAccounts.push({
|
|
4964
4852
|
pubkey: tokenStakeAccount,
|
|
4965
4853
|
isSigner: false,
|
|
@@ -4970,8 +4858,8 @@ var PerpetualsClient = (function () {
|
|
|
4970
4858
|
custodyAccountMetas = [];
|
|
4971
4859
|
custodyOracleAccountMetas = [];
|
|
4972
4860
|
markets = [];
|
|
4973
|
-
for (
|
|
4974
|
-
custody =
|
|
4861
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
|
4862
|
+
custody = _c[_b];
|
|
4975
4863
|
custodyAccountMetas.push({
|
|
4976
4864
|
pubkey: custody.custodyAccount,
|
|
4977
4865
|
isSigner: false,
|
|
@@ -4983,17 +4871,17 @@ var PerpetualsClient = (function () {
|
|
|
4983
4871
|
isWritable: false,
|
|
4984
4872
|
});
|
|
4985
4873
|
}
|
|
4986
|
-
for (
|
|
4987
|
-
market =
|
|
4874
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
|
4875
|
+
market = _e[_d];
|
|
4988
4876
|
markets.push({
|
|
4989
4877
|
pubkey: market.marketAccount,
|
|
4990
4878
|
isSigner: false,
|
|
4991
4879
|
isWritable: false,
|
|
4992
4880
|
});
|
|
4993
4881
|
}
|
|
4994
|
-
|
|
4995
|
-
case
|
|
4996
|
-
|
|
4882
|
+
_f.label = 3;
|
|
4883
|
+
case 3:
|
|
4884
|
+
_f.trys.push([3, 5, , 6]);
|
|
4997
4885
|
return [4, this.program.methods
|
|
4998
4886
|
.migrateStake({
|
|
4999
4887
|
amount: amount
|
|
@@ -5018,15 +4906,15 @@ var PerpetualsClient = (function () {
|
|
|
5018
4906
|
})
|
|
5019
4907
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
|
5020
4908
|
.instruction()];
|
|
5021
|
-
case
|
|
5022
|
-
migrateStake =
|
|
4909
|
+
case 4:
|
|
4910
|
+
migrateStake = _f.sent();
|
|
5023
4911
|
instructions.push(migrateStake);
|
|
5024
|
-
return [3,
|
|
5025
|
-
case
|
|
5026
|
-
err_18 =
|
|
4912
|
+
return [3, 6];
|
|
4913
|
+
case 5:
|
|
4914
|
+
err_18 = _f.sent();
|
|
5027
4915
|
console.log("perpClient migrateStake error:: ", err_18);
|
|
5028
|
-
return [3,
|
|
5029
|
-
case
|
|
4916
|
+
return [3, 6];
|
|
4917
|
+
case 6: return [2, {
|
|
5030
4918
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5031
4919
|
additionalSigners: additionalSigners
|
|
5032
4920
|
}];
|
|
@@ -5203,14 +5091,10 @@ var PerpetualsClient = (function () {
|
|
|
5203
5091
|
additionalSigners = [];
|
|
5204
5092
|
_a.label = 1;
|
|
5205
5093
|
case 1:
|
|
5206
|
-
_a.trys.push([1,
|
|
5094
|
+
_a.trys.push([1, 3, , 4]);
|
|
5207
5095
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5208
5096
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5209
|
-
|
|
5210
|
-
case 2:
|
|
5211
|
-
if (!(_a.sent())) {
|
|
5212
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5213
|
-
}
|
|
5097
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5214
5098
|
return [4, this.program.methods
|
|
5215
5099
|
.depositTokenStake({
|
|
5216
5100
|
depositAmount: depositAmount
|
|
@@ -5230,15 +5114,15 @@ var PerpetualsClient = (function () {
|
|
|
5230
5114
|
tokenMint: poolConfig.tokenMint,
|
|
5231
5115
|
})
|
|
5232
5116
|
.instruction()];
|
|
5233
|
-
case
|
|
5117
|
+
case 2:
|
|
5234
5118
|
depositTokenStakeInstruction = _a.sent();
|
|
5235
5119
|
instructions.push(depositTokenStakeInstruction);
|
|
5236
|
-
return [3,
|
|
5237
|
-
case
|
|
5120
|
+
return [3, 4];
|
|
5121
|
+
case 3:
|
|
5238
5122
|
err_21 = _a.sent();
|
|
5239
5123
|
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
|
5240
5124
|
throw err_21;
|
|
5241
|
-
case
|
|
5125
|
+
case 4: return [2, {
|
|
5242
5126
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5243
5127
|
additionalSigners: additionalSigners
|
|
5244
5128
|
}];
|
|
@@ -5296,14 +5180,10 @@ var PerpetualsClient = (function () {
|
|
|
5296
5180
|
additionalSigners = [];
|
|
5297
5181
|
_a.label = 1;
|
|
5298
5182
|
case 1:
|
|
5299
|
-
_a.trys.push([1,
|
|
5183
|
+
_a.trys.push([1, 3, , 4]);
|
|
5300
5184
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5301
5185
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5302
|
-
|
|
5303
|
-
case 2:
|
|
5304
|
-
if (!(_a.sent())) {
|
|
5305
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5306
|
-
}
|
|
5186
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5307
5187
|
return [4, this.program.methods
|
|
5308
5188
|
.unstakeTokenInstant({
|
|
5309
5189
|
unstakeAmount: unstakeAmount
|
|
@@ -5322,15 +5202,15 @@ var PerpetualsClient = (function () {
|
|
|
5322
5202
|
tokenMint: poolConfig.tokenMint,
|
|
5323
5203
|
})
|
|
5324
5204
|
.instruction()];
|
|
5325
|
-
case
|
|
5205
|
+
case 2:
|
|
5326
5206
|
unstakeTokenInstantInstruction = _a.sent();
|
|
5327
5207
|
instructions.push(unstakeTokenInstantInstruction);
|
|
5328
|
-
return [3,
|
|
5329
|
-
case
|
|
5208
|
+
return [3, 4];
|
|
5209
|
+
case 3:
|
|
5330
5210
|
err_23 = _a.sent();
|
|
5331
5211
|
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
|
5332
5212
|
throw err_23;
|
|
5333
|
-
case
|
|
5213
|
+
case 4: return [2, {
|
|
5334
5214
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5335
5215
|
additionalSigners: additionalSigners
|
|
5336
5216
|
}];
|
|
@@ -5348,14 +5228,10 @@ var PerpetualsClient = (function () {
|
|
|
5348
5228
|
additionalSigners = [];
|
|
5349
5229
|
_a.label = 1;
|
|
5350
5230
|
case 1:
|
|
5351
|
-
_a.trys.push([1,
|
|
5231
|
+
_a.trys.push([1, 3, , 4]);
|
|
5352
5232
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5353
5233
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5354
|
-
|
|
5355
|
-
case 2:
|
|
5356
|
-
if (!(_a.sent())) {
|
|
5357
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5358
|
-
}
|
|
5234
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5359
5235
|
return [4, this.program.methods
|
|
5360
5236
|
.withdrawToken({
|
|
5361
5237
|
withdrawRequestId: withdrawRequestId
|
|
@@ -5374,15 +5250,15 @@ var PerpetualsClient = (function () {
|
|
|
5374
5250
|
tokenMint: poolConfig.tokenMint,
|
|
5375
5251
|
})
|
|
5376
5252
|
.instruction()];
|
|
5377
|
-
case
|
|
5253
|
+
case 2:
|
|
5378
5254
|
withdrawTokenInstruction = _a.sent();
|
|
5379
5255
|
instructions.push(withdrawTokenInstruction);
|
|
5380
|
-
return [3,
|
|
5381
|
-
case
|
|
5256
|
+
return [3, 4];
|
|
5257
|
+
case 3:
|
|
5382
5258
|
err_24 = _a.sent();
|
|
5383
5259
|
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
|
5384
5260
|
throw err_24;
|
|
5385
|
-
case
|
|
5261
|
+
case 4: return [2, {
|
|
5386
5262
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5387
5263
|
additionalSigners: additionalSigners
|
|
5388
5264
|
}];
|
|
@@ -5435,31 +5311,22 @@ var PerpetualsClient = (function () {
|
|
|
5435
5311
|
args_1[_i - 2] = arguments[_i];
|
|
5436
5312
|
}
|
|
5437
5313
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA, userPublicKey) {
|
|
5438
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount,
|
|
5314
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, collectTokenRewardInstruction, err_26;
|
|
5439
5315
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5440
|
-
return __generator(this, function (
|
|
5441
|
-
switch (
|
|
5316
|
+
return __generator(this, function (_a) {
|
|
5317
|
+
switch (_a.label) {
|
|
5442
5318
|
case 0:
|
|
5443
5319
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5444
5320
|
preInstructions = [];
|
|
5445
5321
|
instructions = [];
|
|
5446
5322
|
postInstructions = [];
|
|
5447
5323
|
additionalSigners = [];
|
|
5448
|
-
|
|
5324
|
+
_a.label = 1;
|
|
5449
5325
|
case 1:
|
|
5450
|
-
|
|
5326
|
+
_a.trys.push([1, 3, , 4]);
|
|
5451
5327
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5452
5328
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5453
|
-
|
|
5454
|
-
if (!_a) return [3, 3];
|
|
5455
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5456
|
-
case 2:
|
|
5457
|
-
_a = !(_b.sent());
|
|
5458
|
-
_b.label = 3;
|
|
5459
|
-
case 3:
|
|
5460
|
-
if (_a) {
|
|
5461
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, poolConfig.tokenMint));
|
|
5462
|
-
}
|
|
5329
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userTokenAccount, publicKey, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5463
5330
|
return [4, this.program.methods
|
|
5464
5331
|
.collectTokenReward({})
|
|
5465
5332
|
.accounts({
|
|
@@ -5476,15 +5343,15 @@ var PerpetualsClient = (function () {
|
|
|
5476
5343
|
tokenMint: poolConfig.tokenMint,
|
|
5477
5344
|
})
|
|
5478
5345
|
.instruction()];
|
|
5479
|
-
case
|
|
5480
|
-
collectTokenRewardInstruction =
|
|
5346
|
+
case 2:
|
|
5347
|
+
collectTokenRewardInstruction = _a.sent();
|
|
5481
5348
|
instructions.push(collectTokenRewardInstruction);
|
|
5482
|
-
return [3,
|
|
5483
|
-
case
|
|
5484
|
-
err_26 =
|
|
5349
|
+
return [3, 4];
|
|
5350
|
+
case 3:
|
|
5351
|
+
err_26 = _a.sent();
|
|
5485
5352
|
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
|
5486
5353
|
throw err_26;
|
|
5487
|
-
case
|
|
5354
|
+
case 4: return [2, {
|
|
5488
5355
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5489
5356
|
additionalSigners: additionalSigners
|
|
5490
5357
|
}];
|
|
@@ -5498,32 +5365,23 @@ var PerpetualsClient = (function () {
|
|
|
5498
5365
|
args_1[_i - 3] = arguments[_i];
|
|
5499
5366
|
}
|
|
5500
5367
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
|
5501
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount,
|
|
5368
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, collectRevenueInstruction, err_27;
|
|
5502
5369
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5503
|
-
return __generator(this, function (
|
|
5504
|
-
switch (
|
|
5370
|
+
return __generator(this, function (_a) {
|
|
5371
|
+
switch (_a.label) {
|
|
5505
5372
|
case 0:
|
|
5506
5373
|
publicKey = this.provider.wallet.publicKey;
|
|
5507
5374
|
preInstructions = [];
|
|
5508
5375
|
instructions = [];
|
|
5509
5376
|
postInstructions = [];
|
|
5510
5377
|
additionalSigners = [];
|
|
5511
|
-
|
|
5378
|
+
_a.label = 1;
|
|
5512
5379
|
case 1:
|
|
5513
|
-
|
|
5380
|
+
_a.trys.push([1, 3, , 4]);
|
|
5514
5381
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
5515
5382
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5516
5383
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, owner, true);
|
|
5517
|
-
|
|
5518
|
-
if (!_a) return [3, 3];
|
|
5519
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5520
|
-
case 2:
|
|
5521
|
-
_a = !(_b.sent());
|
|
5522
|
-
_b.label = 3;
|
|
5523
|
-
case 3:
|
|
5524
|
-
if (_a) {
|
|
5525
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rewardCustodyMint));
|
|
5526
|
-
}
|
|
5384
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userTokenAccount, publicKey, rewardCustodyMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5527
5385
|
return [4, this.program.methods
|
|
5528
5386
|
.collectRevenue({})
|
|
5529
5387
|
.accounts({
|
|
@@ -5540,15 +5398,15 @@ var PerpetualsClient = (function () {
|
|
|
5540
5398
|
receivingTokenMint: rewardCustodyMint,
|
|
5541
5399
|
})
|
|
5542
5400
|
.instruction()];
|
|
5543
|
-
case
|
|
5544
|
-
collectRevenueInstruction =
|
|
5401
|
+
case 2:
|
|
5402
|
+
collectRevenueInstruction = _a.sent();
|
|
5545
5403
|
instructions.push(collectRevenueInstruction);
|
|
5546
|
-
return [3,
|
|
5547
|
-
case
|
|
5548
|
-
err_27 =
|
|
5404
|
+
return [3, 4];
|
|
5405
|
+
case 3:
|
|
5406
|
+
err_27 = _a.sent();
|
|
5549
5407
|
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
|
5550
5408
|
throw err_27;
|
|
5551
|
-
case
|
|
5409
|
+
case 4: return [2, {
|
|
5552
5410
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5553
5411
|
additionalSigners: additionalSigners
|
|
5554
5412
|
}];
|
|
@@ -5562,32 +5420,23 @@ var PerpetualsClient = (function () {
|
|
|
5562
5420
|
args_1[_i - 3] = arguments[_i];
|
|
5563
5421
|
}
|
|
5564
5422
|
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
|
|
5565
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount,
|
|
5423
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, collectRebateInstruction, err_28;
|
|
5566
5424
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5567
|
-
return __generator(this, function (
|
|
5568
|
-
switch (
|
|
5425
|
+
return __generator(this, function (_a) {
|
|
5426
|
+
switch (_a.label) {
|
|
5569
5427
|
case 0:
|
|
5570
5428
|
publicKey = this.provider.wallet.publicKey;
|
|
5571
5429
|
preInstructions = [];
|
|
5572
5430
|
instructions = [];
|
|
5573
5431
|
postInstructions = [];
|
|
5574
5432
|
additionalSigners = [];
|
|
5575
|
-
|
|
5433
|
+
_a.label = 1;
|
|
5576
5434
|
case 1:
|
|
5577
|
-
|
|
5435
|
+
_a.trys.push([1, 3, , 4]);
|
|
5578
5436
|
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5579
5437
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5580
5438
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5581
|
-
|
|
5582
|
-
if (!_a) return [3, 3];
|
|
5583
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5584
|
-
case 2:
|
|
5585
|
-
_a = !(_b.sent());
|
|
5586
|
-
_b.label = 3;
|
|
5587
|
-
case 3:
|
|
5588
|
-
if (_a) {
|
|
5589
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5590
|
-
}
|
|
5439
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userTokenAccount, publicKey, rebateMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5591
5440
|
return [4, this.program.methods
|
|
5592
5441
|
.collectRebate()
|
|
5593
5442
|
.accounts({
|
|
@@ -5604,15 +5453,15 @@ var PerpetualsClient = (function () {
|
|
|
5604
5453
|
receivingTokenMint: rebateMint,
|
|
5605
5454
|
})
|
|
5606
5455
|
.instruction()];
|
|
5607
|
-
case
|
|
5608
|
-
collectRebateInstruction =
|
|
5456
|
+
case 2:
|
|
5457
|
+
collectRebateInstruction = _a.sent();
|
|
5609
5458
|
instructions.push(collectRebateInstruction);
|
|
5610
|
-
return [3,
|
|
5611
|
-
case
|
|
5612
|
-
err_28 =
|
|
5459
|
+
return [3, 4];
|
|
5460
|
+
case 3:
|
|
5461
|
+
err_28 = _a.sent();
|
|
5613
5462
|
console.log("perpClient collectRebateInstruction error:: ", err_28);
|
|
5614
5463
|
throw err_28;
|
|
5615
|
-
case
|
|
5464
|
+
case 4: return [2, {
|
|
5616
5465
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5617
5466
|
additionalSigners: additionalSigners
|
|
5618
5467
|
}];
|
|
@@ -5796,11 +5645,11 @@ var PerpetualsClient = (function () {
|
|
|
5796
5645
|
args_1[_i - 11] = arguments[_i];
|
|
5797
5646
|
}
|
|
5798
5647
|
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, userPublicKey) {
|
|
5799
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports,
|
|
5648
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, positionAccount, orderAccount, editLimitOrder, err_31;
|
|
5800
5649
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5801
5650
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5802
|
-
return __generator(this, function (
|
|
5803
|
-
switch (
|
|
5651
|
+
return __generator(this, function (_a) {
|
|
5652
|
+
switch (_a.label) {
|
|
5804
5653
|
case 0:
|
|
5805
5654
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5806
5655
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -5812,43 +5661,33 @@ var PerpetualsClient = (function () {
|
|
|
5812
5661
|
instructions = [];
|
|
5813
5662
|
postInstructions = [];
|
|
5814
5663
|
additionalSigners = [];
|
|
5815
|
-
|
|
5664
|
+
_a.label = 1;
|
|
5816
5665
|
case 1:
|
|
5817
|
-
|
|
5818
|
-
if (
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5666
|
+
_a.trys.push([1, 3, , 4]);
|
|
5667
|
+
if (reserveSymbol == 'SOL') {
|
|
5668
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
5669
|
+
if (!ephemeralSignerPubkey) {
|
|
5670
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
5671
|
+
additionalSigners.push(wrappedSolAccount);
|
|
5672
|
+
}
|
|
5673
|
+
preInstructions = [
|
|
5674
|
+
web3_js_1.SystemProgram.createAccount({
|
|
5675
|
+
fromPubkey: publicKey,
|
|
5676
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
5677
|
+
lamports: lamports,
|
|
5678
|
+
space: 165,
|
|
5679
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5680
|
+
}),
|
|
5681
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
5682
|
+
];
|
|
5683
|
+
postInstructions = [
|
|
5684
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
5685
|
+
];
|
|
5823
5686
|
}
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
5828
|
-
lamports: lamports,
|
|
5829
|
-
space: 165,
|
|
5830
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5831
|
-
}),
|
|
5832
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
5833
|
-
];
|
|
5834
|
-
postInstructions = [
|
|
5835
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
5836
|
-
];
|
|
5837
|
-
return [3, 5];
|
|
5838
|
-
case 2:
|
|
5839
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
5840
|
-
_a = createUserATA;
|
|
5841
|
-
if (!_a) return [3, 4];
|
|
5842
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
5843
|
-
case 3:
|
|
5844
|
-
_a = !(_b.sent());
|
|
5845
|
-
_b.label = 4;
|
|
5846
|
-
case 4:
|
|
5847
|
-
if (_a) {
|
|
5848
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
5687
|
+
else {
|
|
5688
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
5689
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
5849
5690
|
}
|
|
5850
|
-
_b.label = 5;
|
|
5851
|
-
case 5:
|
|
5852
5691
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
5853
5692
|
orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
|
|
5854
5693
|
return [4, this.program.methods
|
|
@@ -5882,15 +5721,15 @@ var PerpetualsClient = (function () {
|
|
|
5882
5721
|
receivingMint: poolConfig.getTokenFromSymbol(reserveSymbol).mintKey
|
|
5883
5722
|
})
|
|
5884
5723
|
.instruction()];
|
|
5885
|
-
case
|
|
5886
|
-
editLimitOrder =
|
|
5724
|
+
case 2:
|
|
5725
|
+
editLimitOrder = _a.sent();
|
|
5887
5726
|
instructions.push(editLimitOrder);
|
|
5888
|
-
return [3,
|
|
5889
|
-
case
|
|
5890
|
-
err_31 =
|
|
5727
|
+
return [3, 4];
|
|
5728
|
+
case 3:
|
|
5729
|
+
err_31 = _a.sent();
|
|
5891
5730
|
console.log("perpClient editLimitOrder error:: ", err_31);
|
|
5892
5731
|
throw err_31;
|
|
5893
|
-
case
|
|
5732
|
+
case 4: return [2, {
|
|
5894
5733
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5895
5734
|
additionalSigners: additionalSigners
|
|
5896
5735
|
}];
|
|
@@ -6248,13 +6087,13 @@ var PerpetualsClient = (function () {
|
|
|
6248
6087
|
args_1[_i - 9] = arguments[_i];
|
|
6249
6088
|
}
|
|
6250
6089
|
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) {
|
|
6251
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken,
|
|
6090
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _a, _b, custody, executeTriggerWithSwap, err_38;
|
|
6252
6091
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6253
6092
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6254
6093
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6255
6094
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6256
|
-
return __generator(this, function (
|
|
6257
|
-
switch (
|
|
6095
|
+
return __generator(this, function (_c) {
|
|
6096
|
+
switch (_c.label) {
|
|
6258
6097
|
case 0:
|
|
6259
6098
|
payerPubkey = this.provider.wallet.publicKey;
|
|
6260
6099
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -6267,42 +6106,23 @@ var PerpetualsClient = (function () {
|
|
|
6267
6106
|
additionalSigners = [];
|
|
6268
6107
|
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
|
6269
6108
|
receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
|
|
6270
|
-
|
|
6109
|
+
_c.label = 1;
|
|
6271
6110
|
case 1:
|
|
6272
|
-
|
|
6273
|
-
if (
|
|
6274
|
-
return [3, 7];
|
|
6275
|
-
case 2:
|
|
6276
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true, receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
6277
|
-
_a = createUserATA;
|
|
6278
|
-
if (!_a) return [3, 4];
|
|
6279
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
6280
|
-
case 3:
|
|
6281
|
-
_a = !(_e.sent());
|
|
6282
|
-
_e.label = 4;
|
|
6283
|
-
case 4:
|
|
6284
|
-
if (_a) {
|
|
6285
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
|
6111
|
+
_c.trys.push([1, 3, , 4]);
|
|
6112
|
+
if (false) {
|
|
6286
6113
|
}
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
_b = !(_e.sent());
|
|
6293
|
-
_e.label = 6;
|
|
6294
|
-
case 6:
|
|
6295
|
-
if (_b) {
|
|
6296
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
|
6114
|
+
else {
|
|
6115
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true, receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
6116
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, spl_token_1.TOKEN_PROGRAM_ID));
|
|
6117
|
+
userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
6118
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
6297
6119
|
}
|
|
6298
|
-
_e.label = 7;
|
|
6299
|
-
case 7:
|
|
6300
6120
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
|
6301
6121
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
|
6302
6122
|
custodyAccountMetas = [];
|
|
6303
6123
|
custodyOracleAccountMetas = [];
|
|
6304
|
-
for (
|
|
6305
|
-
custody =
|
|
6124
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
|
6125
|
+
custody = _b[_a];
|
|
6306
6126
|
custodyAccountMetas.push({
|
|
6307
6127
|
pubkey: custody.custodyAccount,
|
|
6308
6128
|
isSigner: false,
|
|
@@ -6349,15 +6169,15 @@ var PerpetualsClient = (function () {
|
|
|
6349
6169
|
})
|
|
6350
6170
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6351
6171
|
.instruction()];
|
|
6352
|
-
case
|
|
6353
|
-
executeTriggerWithSwap =
|
|
6172
|
+
case 2:
|
|
6173
|
+
executeTriggerWithSwap = _c.sent();
|
|
6354
6174
|
instructions.push(executeTriggerWithSwap);
|
|
6355
|
-
return [3,
|
|
6356
|
-
case
|
|
6357
|
-
err_38 =
|
|
6175
|
+
return [3, 4];
|
|
6176
|
+
case 3:
|
|
6177
|
+
err_38 = _c.sent();
|
|
6358
6178
|
console.log("perpClient executeTriggerWithSwap error:: ", err_38);
|
|
6359
6179
|
throw err_38;
|
|
6360
|
-
case
|
|
6180
|
+
case 4: return [2, {
|
|
6361
6181
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6362
6182
|
additionalSigners: additionalSigners
|
|
6363
6183
|
}];
|
|
@@ -6371,13 +6191,13 @@ var PerpetualsClient = (function () {
|
|
|
6371
6191
|
args_1[_i - 8] = arguments[_i];
|
|
6372
6192
|
}
|
|
6373
6193
|
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) {
|
|
6374
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
|
6194
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeTriggerOrder, err_39;
|
|
6375
6195
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6376
6196
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6377
6197
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6378
6198
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6379
|
-
return __generator(this, function (
|
|
6380
|
-
switch (
|
|
6199
|
+
return __generator(this, function (_a) {
|
|
6200
|
+
switch (_a.label) {
|
|
6381
6201
|
case 0:
|
|
6382
6202
|
payerPubkey = this.provider.wallet.publicKey;
|
|
6383
6203
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -6387,25 +6207,15 @@ var PerpetualsClient = (function () {
|
|
|
6387
6207
|
instructions = [];
|
|
6388
6208
|
postInstructions = [];
|
|
6389
6209
|
additionalSigners = [];
|
|
6390
|
-
|
|
6210
|
+
_a.label = 1;
|
|
6391
6211
|
case 1:
|
|
6392
|
-
|
|
6393
|
-
if (
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
if (!_a) return [3, 4];
|
|
6399
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
6400
|
-
case 3:
|
|
6401
|
-
_a = !(_b.sent());
|
|
6402
|
-
_b.label = 4;
|
|
6403
|
-
case 4:
|
|
6404
|
-
if (_a) {
|
|
6405
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
6212
|
+
_a.trys.push([1, 3, , 4]);
|
|
6213
|
+
if (false) {
|
|
6214
|
+
}
|
|
6215
|
+
else {
|
|
6216
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
6217
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
6406
6218
|
}
|
|
6407
|
-
_b.label = 5;
|
|
6408
|
-
case 5:
|
|
6409
6219
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
|
6410
6220
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
|
6411
6221
|
return [4, this.program.methods
|
|
@@ -6437,15 +6247,15 @@ var PerpetualsClient = (function () {
|
|
|
6437
6247
|
})
|
|
6438
6248
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6439
6249
|
.instruction()];
|
|
6440
|
-
case
|
|
6441
|
-
executeTriggerOrder =
|
|
6250
|
+
case 2:
|
|
6251
|
+
executeTriggerOrder = _a.sent();
|
|
6442
6252
|
instructions.push(executeTriggerOrder);
|
|
6443
|
-
return [3,
|
|
6444
|
-
case
|
|
6445
|
-
err_39 =
|
|
6253
|
+
return [3, 4];
|
|
6254
|
+
case 3:
|
|
6255
|
+
err_39 = _a.sent();
|
|
6446
6256
|
console.log("perpClient executeTriggerOrder error:: ", err_39);
|
|
6447
6257
|
throw err_39;
|
|
6448
|
-
case
|
|
6258
|
+
case 4: return [2, {
|
|
6449
6259
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6450
6260
|
additionalSigners: additionalSigners
|
|
6451
6261
|
}];
|
|
@@ -6459,15 +6269,15 @@ var PerpetualsClient = (function () {
|
|
|
6459
6269
|
args_1[_i - 5] = arguments[_i];
|
|
6460
6270
|
}
|
|
6461
6271
|
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, isWhitelistedUser, userPublicKey) {
|
|
6462
|
-
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount,
|
|
6272
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, custodyAccountMetas, custodyOracleAccountMetas, _d, _e, custody, whitelistPda, whitelistMeta, params, inx, closeWsolATAIns, err_40;
|
|
6463
6273
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
|
6464
6274
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6465
6275
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
|
6466
6276
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
6467
6277
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6468
6278
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
6469
|
-
return __generator(this, function (
|
|
6470
|
-
switch (
|
|
6279
|
+
return __generator(this, function (_f) {
|
|
6280
|
+
switch (_f.label) {
|
|
6471
6281
|
case 0:
|
|
6472
6282
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
|
6473
6283
|
if (!userInputCustodyConfig) {
|
|
@@ -6482,26 +6292,21 @@ var PerpetualsClient = (function () {
|
|
|
6482
6292
|
instructions = [];
|
|
6483
6293
|
postInstructions = [];
|
|
6484
6294
|
additionalSigners = [];
|
|
6485
|
-
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3,
|
|
6295
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 4];
|
|
6486
6296
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
|
6487
6297
|
case 1:
|
|
6488
|
-
wsolAssociatedTokenAccount =
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
wsolATAExist = _g.sent();
|
|
6492
|
-
if (!wsolATAExist) {
|
|
6493
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
|
6494
|
-
}
|
|
6495
|
-
if (!!skipBalanceChecks) return [3, 4];
|
|
6298
|
+
wsolAssociatedTokenAccount = _f.sent();
|
|
6299
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID));
|
|
6300
|
+
if (!!skipBalanceChecks) return [3, 3];
|
|
6496
6301
|
_a = anchor_1.BN.bind;
|
|
6497
6302
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
6498
|
-
case
|
|
6499
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
|
6303
|
+
case 2:
|
|
6304
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
6500
6305
|
if (unWrappedSolBalance.lt(amountIn)) {
|
|
6501
6306
|
throw "Insufficient SOL Funds";
|
|
6502
6307
|
}
|
|
6503
|
-
|
|
6504
|
-
case
|
|
6308
|
+
_f.label = 3;
|
|
6309
|
+
case 3:
|
|
6505
6310
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
|
6506
6311
|
fromPubkey: publicKey,
|
|
6507
6312
|
toPubkey: wsolAssociatedTokenAccount,
|
|
@@ -6511,7 +6316,7 @@ var PerpetualsClient = (function () {
|
|
|
6511
6316
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6512
6317
|
additionalSigners: additionalSigners
|
|
6513
6318
|
}];
|
|
6514
|
-
case
|
|
6319
|
+
case 4:
|
|
6515
6320
|
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
|
6516
6321
|
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
|
6517
6322
|
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
|
@@ -6522,20 +6327,20 @@ var PerpetualsClient = (function () {
|
|
|
6522
6327
|
additionalSigners: additionalSigners
|
|
6523
6328
|
}];
|
|
6524
6329
|
}
|
|
6525
|
-
|
|
6526
|
-
case
|
|
6527
|
-
|
|
6528
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
|
6330
|
+
_f.label = 5;
|
|
6331
|
+
case 5:
|
|
6332
|
+
_f.trys.push([5, 16, , 17]);
|
|
6333
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 8];
|
|
6529
6334
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
|
6530
6335
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
|
6531
|
-
case
|
|
6532
|
-
accCreationLamports = (
|
|
6336
|
+
case 6:
|
|
6337
|
+
accCreationLamports = (_f.sent());
|
|
6533
6338
|
console.log("accCreationLamports:", accCreationLamports);
|
|
6534
6339
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
|
6535
6340
|
_b = anchor_1.BN.bind;
|
|
6536
6341
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
6537
|
-
case
|
|
6538
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
|
6342
|
+
case 7:
|
|
6343
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
6539
6344
|
if (unWrappedSolBalance.lt(amountIn)) {
|
|
6540
6345
|
throw "Insufficient SOL Funds";
|
|
6541
6346
|
}
|
|
@@ -6557,25 +6362,25 @@ var PerpetualsClient = (function () {
|
|
|
6557
6362
|
postInstructions = [
|
|
6558
6363
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
6559
6364
|
];
|
|
6560
|
-
return [3,
|
|
6561
|
-
case
|
|
6365
|
+
return [3, 11];
|
|
6366
|
+
case 8:
|
|
6562
6367
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
6563
6368
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
6564
|
-
case
|
|
6565
|
-
if (!(
|
|
6369
|
+
case 9:
|
|
6370
|
+
if (!(_f.sent())) {
|
|
6566
6371
|
throw "Insufficient Funds , Token Account doesn't exist";
|
|
6567
6372
|
}
|
|
6568
|
-
if (!!skipBalanceChecks) return [3,
|
|
6373
|
+
if (!!skipBalanceChecks) return [3, 11];
|
|
6569
6374
|
_c = anchor_1.BN.bind;
|
|
6570
6375
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
6571
|
-
case
|
|
6572
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
|
6376
|
+
case 10:
|
|
6377
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
|
6573
6378
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
6574
6379
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
6575
6380
|
}
|
|
6576
|
-
|
|
6577
|
-
case
|
|
6578
|
-
if (!(userOutputTokenSymbol == 'SOL')) return [3,
|
|
6381
|
+
_f.label = 11;
|
|
6382
|
+
case 11:
|
|
6383
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 12];
|
|
6579
6384
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
6580
6385
|
if (!ephemeralSignerPubkey) {
|
|
6581
6386
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
@@ -6595,26 +6400,17 @@ var PerpetualsClient = (function () {
|
|
|
6595
6400
|
postInstructions = [
|
|
6596
6401
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
6597
6402
|
];
|
|
6598
|
-
return [3,
|
|
6599
|
-
case
|
|
6403
|
+
return [3, 14];
|
|
6404
|
+
case 12: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID)];
|
|
6405
|
+
case 13:
|
|
6406
|
+
userOutputTokenAccount = _f.sent();
|
|
6407
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
6408
|
+
_f.label = 14;
|
|
6600
6409
|
case 14:
|
|
6601
|
-
userOutputTokenAccount = _g.sent();
|
|
6602
|
-
_d = createUserATA;
|
|
6603
|
-
if (!_d) return [3, 16];
|
|
6604
|
-
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
|
6605
|
-
case 15:
|
|
6606
|
-
_d = !(_g.sent());
|
|
6607
|
-
_g.label = 16;
|
|
6608
|
-
case 16:
|
|
6609
|
-
if (_d) {
|
|
6610
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
6611
|
-
}
|
|
6612
|
-
_g.label = 17;
|
|
6613
|
-
case 17:
|
|
6614
6410
|
custodyAccountMetas = [];
|
|
6615
6411
|
custodyOracleAccountMetas = [];
|
|
6616
|
-
for (
|
|
6617
|
-
custody =
|
|
6412
|
+
for (_d = 0, _e = poolConfig.custodies; _d < _e.length; _d++) {
|
|
6413
|
+
custody = _e[_d];
|
|
6618
6414
|
custodyAccountMetas.push({
|
|
6619
6415
|
pubkey: custody.custodyAccount,
|
|
6620
6416
|
isSigner: false,
|
|
@@ -6662,19 +6458,19 @@ var PerpetualsClient = (function () {
|
|
|
6662
6458
|
})
|
|
6663
6459
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
6664
6460
|
.instruction()];
|
|
6665
|
-
case
|
|
6666
|
-
inx =
|
|
6461
|
+
case 15:
|
|
6462
|
+
inx = _f.sent();
|
|
6667
6463
|
instructions.push(inx);
|
|
6668
6464
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
|
6669
6465
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
|
6670
6466
|
instructions.push(closeWsolATAIns);
|
|
6671
6467
|
}
|
|
6672
|
-
return [3,
|
|
6673
|
-
case
|
|
6674
|
-
err_40 =
|
|
6468
|
+
return [3, 17];
|
|
6469
|
+
case 16:
|
|
6470
|
+
err_40 = _f.sent();
|
|
6675
6471
|
console.error("perpClient Swap error:: ", err_40);
|
|
6676
6472
|
throw err_40;
|
|
6677
|
-
case
|
|
6473
|
+
case 17: return [2, {
|
|
6678
6474
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6679
6475
|
additionalSigners: additionalSigners
|
|
6680
6476
|
}];
|
|
@@ -7716,15 +7512,11 @@ var PerpetualsClient = (function () {
|
|
|
7716
7512
|
additionalSigners = [];
|
|
7717
7513
|
_a.label = 1;
|
|
7718
7514
|
case 1:
|
|
7719
|
-
_a.trys.push([1,
|
|
7515
|
+
_a.trys.push([1, 4, , 5]);
|
|
7720
7516
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7721
7517
|
case 2:
|
|
7722
7518
|
receivingTokenAccount = _a.sent();
|
|
7723
|
-
|
|
7724
|
-
case 3:
|
|
7725
|
-
if (!(_a.sent())) {
|
|
7726
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7727
|
-
}
|
|
7519
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
7728
7520
|
return [4, this.program.methods
|
|
7729
7521
|
.withdrawInstantFees({})
|
|
7730
7522
|
.accounts({
|
|
@@ -7739,15 +7531,15 @@ var PerpetualsClient = (function () {
|
|
|
7739
7531
|
receivingTokenMint: poolConfig.tokenMint,
|
|
7740
7532
|
})
|
|
7741
7533
|
.instruction()];
|
|
7742
|
-
case
|
|
7534
|
+
case 3:
|
|
7743
7535
|
withdrawInstantFeeInstruction = _a.sent();
|
|
7744
7536
|
instructions.push(withdrawInstantFeeInstruction);
|
|
7745
|
-
return [3,
|
|
7746
|
-
case
|
|
7537
|
+
return [3, 5];
|
|
7538
|
+
case 4:
|
|
7747
7539
|
err_57 = _a.sent();
|
|
7748
7540
|
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
|
|
7749
7541
|
throw err_57;
|
|
7750
|
-
case
|
|
7542
|
+
case 5: return [2, {
|
|
7751
7543
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7752
7544
|
additionalSigners: additionalSigners
|
|
7753
7545
|
}];
|
|
@@ -7766,15 +7558,11 @@ var PerpetualsClient = (function () {
|
|
|
7766
7558
|
additionalSigners = [];
|
|
7767
7559
|
_a.label = 1;
|
|
7768
7560
|
case 1:
|
|
7769
|
-
_a.trys.push([1,
|
|
7561
|
+
_a.trys.push([1, 4, , 5]);
|
|
7770
7562
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7771
7563
|
case 2:
|
|
7772
7564
|
receivingTokenAccount = _a.sent();
|
|
7773
|
-
|
|
7774
|
-
case 3:
|
|
7775
|
-
if (!(_a.sent())) {
|
|
7776
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7777
|
-
}
|
|
7565
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
7778
7566
|
return [4, this.program.methods
|
|
7779
7567
|
.withdrawUnclaimedTokens({})
|
|
7780
7568
|
.accounts({
|
|
@@ -7789,15 +7577,15 @@ var PerpetualsClient = (function () {
|
|
|
7789
7577
|
receivingTokenMint: poolConfig.tokenMint,
|
|
7790
7578
|
})
|
|
7791
7579
|
.instruction()];
|
|
7792
|
-
case
|
|
7580
|
+
case 3:
|
|
7793
7581
|
withdrawUnclaimedTokensInstruction = _a.sent();
|
|
7794
7582
|
instructions.push(withdrawUnclaimedTokensInstruction);
|
|
7795
|
-
return [3,
|
|
7796
|
-
case
|
|
7583
|
+
return [3, 5];
|
|
7584
|
+
case 4:
|
|
7797
7585
|
err_58 = _a.sent();
|
|
7798
7586
|
console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
|
|
7799
7587
|
throw err_58;
|
|
7800
|
-
case
|
|
7588
|
+
case 5: return [2, {
|
|
7801
7589
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7802
7590
|
additionalSigners: additionalSigners
|
|
7803
7591
|
}];
|