flash-sdk 11.9.2-alpha.0 → 11.9.3-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.d.ts +22 -22
- package/dist/PerpetualsClient.js +490 -684
- package/package.json +5 -4
- package/dist/test.d.ts +0 -0
- package/dist/test.js +0 -0
- package/dist/test2.d.ts +0 -0
- package/dist/test2.js +0 -0
- package/dist/testPublkey.d.ts +0 -0
- package/dist/testPublkey.js +0 -0
- package/dist/testSize.d.ts +0 -0
- package/dist/testSize.js +0 -0
- package/dist/testView.d.ts +0 -0
- package/dist/testView.js +0 -0
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/PerpetualsClient.js
CHANGED
|
@@ -2728,7 +2728,7 @@ var PerpetualsClient = (function () {
|
|
|
2728
2728
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
2729
2729
|
args_1[_i - 8] = arguments[_i];
|
|
2730
2730
|
}
|
|
2731
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
2731
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
|
2732
2732
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
|
2733
2733
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2734
2734
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
@@ -2737,7 +2737,7 @@ var PerpetualsClient = (function () {
|
|
|
2737
2737
|
return __generator(this, function (_c) {
|
|
2738
2738
|
switch (_c.label) {
|
|
2739
2739
|
case 0:
|
|
2740
|
-
publicKey = this.provider.wallet.publicKey;
|
|
2740
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
2741
2741
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
2742
2742
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
2743
2743
|
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
|
@@ -2842,59 +2842,48 @@ var PerpetualsClient = (function () {
|
|
|
2842
2842
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
2843
2843
|
args_1[_i - 6] = arguments[_i];
|
|
2844
2844
|
}
|
|
2845
|
-
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) {
|
|
2846
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports,
|
|
2845
|
+
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) {
|
|
2846
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
|
2847
2847
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2848
2848
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2849
2849
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
2850
2850
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
2851
2851
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2852
|
-
return __generator(this, function (
|
|
2853
|
-
switch (
|
|
2852
|
+
return __generator(this, function (_a) {
|
|
2853
|
+
switch (_a.label) {
|
|
2854
2854
|
case 0:
|
|
2855
|
-
|
|
2856
|
-
publicKey = this.provider.wallet.publicKey;
|
|
2855
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
2857
2856
|
preInstructions = [];
|
|
2858
2857
|
instructions = [];
|
|
2859
2858
|
postInstructions = [];
|
|
2860
2859
|
additionalSigners = [];
|
|
2861
|
-
|
|
2860
|
+
_a.label = 1;
|
|
2862
2861
|
case 1:
|
|
2863
|
-
|
|
2864
|
-
if (
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2862
|
+
_a.trys.push([1, 3, , 4]);
|
|
2863
|
+
if (collateralSymbol == 'SOL') {
|
|
2864
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
2865
|
+
if (!ephemeralSignerPubkey) {
|
|
2866
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
2867
|
+
additionalSigners.push(wrappedSolAccount);
|
|
2868
|
+
}
|
|
2869
|
+
preInstructions = [
|
|
2870
|
+
web3_js_1.SystemProgram.createAccount({
|
|
2871
|
+
fromPubkey: publicKey,
|
|
2872
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2873
|
+
lamports: lamports,
|
|
2874
|
+
space: 165,
|
|
2875
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2876
|
+
}),
|
|
2877
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
2878
|
+
];
|
|
2879
|
+
postInstructions = [
|
|
2880
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2881
|
+
];
|
|
2869
2882
|
}
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2874
|
-
lamports: lamports,
|
|
2875
|
-
space: 165,
|
|
2876
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2877
|
-
}),
|
|
2878
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
2879
|
-
];
|
|
2880
|
-
postInstructions = [
|
|
2881
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2882
|
-
];
|
|
2883
|
-
return [3, 5];
|
|
2884
|
-
case 2:
|
|
2885
|
-
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);
|
|
2886
|
-
_a = createUserATA;
|
|
2887
|
-
if (!_a) return [3, 4];
|
|
2888
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
2889
|
-
case 3:
|
|
2890
|
-
_a = !(_b.sent());
|
|
2891
|
-
_b.label = 4;
|
|
2892
|
-
case 4:
|
|
2893
|
-
if (_a) {
|
|
2894
|
-
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));
|
|
2883
|
+
else {
|
|
2884
|
+
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);
|
|
2885
|
+
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));
|
|
2895
2886
|
}
|
|
2896
|
-
_b.label = 5;
|
|
2897
|
-
case 5:
|
|
2898
2887
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
2899
2888
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
|
|
2900
2889
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -2926,19 +2915,19 @@ var PerpetualsClient = (function () {
|
|
|
2926
2915
|
})
|
|
2927
2916
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2928
2917
|
.instruction()];
|
|
2929
|
-
case
|
|
2930
|
-
instruction =
|
|
2918
|
+
case 2:
|
|
2919
|
+
instruction = _a.sent();
|
|
2931
2920
|
instructions.push(instruction);
|
|
2932
2921
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
|
2933
2922
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
2934
2923
|
postInstructions.push(closeWsolATAIns);
|
|
2935
2924
|
}
|
|
2936
|
-
return [3,
|
|
2937
|
-
case
|
|
2938
|
-
error_1 =
|
|
2925
|
+
return [3, 4];
|
|
2926
|
+
case 3:
|
|
2927
|
+
error_1 = _a.sent();
|
|
2939
2928
|
console.error("perpclient closePosition error:", error_1);
|
|
2940
2929
|
throw error_1;
|
|
2941
|
-
case
|
|
2930
|
+
case 4: return [2, {
|
|
2942
2931
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
2943
2932
|
additionalSigners: additionalSigners
|
|
2944
2933
|
}];
|
|
@@ -2951,7 +2940,7 @@ var PerpetualsClient = (function () {
|
|
|
2951
2940
|
for (var _i = 9; _i < arguments.length; _i++) {
|
|
2952
2941
|
args_1[_i - 9] = arguments[_i];
|
|
2953
2942
|
}
|
|
2954
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
2943
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
|
2955
2944
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
|
|
2956
2945
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2957
2946
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
@@ -2960,7 +2949,7 @@ var PerpetualsClient = (function () {
|
|
|
2960
2949
|
return __generator(this, function (_c) {
|
|
2961
2950
|
switch (_c.label) {
|
|
2962
2951
|
case 0:
|
|
2963
|
-
publicKey = this.provider.wallet.publicKey;
|
|
2952
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
2964
2953
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
|
2965
2954
|
if (!userInputCustodyConfig) {
|
|
2966
2955
|
throw "userInputCustodyConfig not found";
|
|
@@ -2984,7 +2973,7 @@ var PerpetualsClient = (function () {
|
|
|
2984
2973
|
additionalSigners = [];
|
|
2985
2974
|
targetToken = poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol);
|
|
2986
2975
|
userInputToken = poolConfig.getTokenFromSymbol(userInputTokenSymbol);
|
|
2987
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
|
2976
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 3];
|
|
2988
2977
|
console.log("inputSymbol === SOL", userInputTokenSymbol);
|
|
2989
2978
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
2990
2979
|
if (!!skipBalanceChecks) return [3, 2];
|
|
@@ -3014,41 +3003,33 @@ var PerpetualsClient = (function () {
|
|
|
3014
3003
|
postInstructions = [
|
|
3015
3004
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3016
3005
|
];
|
|
3017
|
-
if (
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
case 3:
|
|
3021
|
-
if (!(_c.sent())) {
|
|
3022
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
|
|
3006
|
+
if (!poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey.equals(spl_token_1.NATIVE_MINT)) {
|
|
3007
|
+
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);
|
|
3008
|
+
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));
|
|
3023
3009
|
}
|
|
3024
|
-
|
|
3025
|
-
case
|
|
3026
|
-
case 5:
|
|
3010
|
+
return [3, 7];
|
|
3011
|
+
case 3:
|
|
3027
3012
|
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);
|
|
3028
|
-
if (!!skipBalanceChecks) return [3,
|
|
3013
|
+
if (!!skipBalanceChecks) return [3, 6];
|
|
3029
3014
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
3030
|
-
case
|
|
3015
|
+
case 4:
|
|
3031
3016
|
if (!(_c.sent())) {
|
|
3032
3017
|
throw "Insufficient Funds , Token Account doesn't exist";
|
|
3033
3018
|
}
|
|
3034
3019
|
_b = anchor_1.BN.bind;
|
|
3035
3020
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
3036
|
-
case
|
|
3021
|
+
case 5:
|
|
3037
3022
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
|
3038
3023
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
3039
3024
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
3040
3025
|
}
|
|
3041
|
-
_c.label =
|
|
3042
|
-
case
|
|
3026
|
+
_c.label = 6;
|
|
3027
|
+
case 6:
|
|
3043
3028
|
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);
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
}
|
|
3049
|
-
_c.label = 10;
|
|
3050
|
-
case 10:
|
|
3051
|
-
_c.trys.push([10, 12, , 13]);
|
|
3029
|
+
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));
|
|
3030
|
+
_c.label = 7;
|
|
3031
|
+
case 7:
|
|
3032
|
+
_c.trys.push([7, 9, , 10]);
|
|
3052
3033
|
return [4, this.program.methods
|
|
3053
3034
|
.swapAndOpen({
|
|
3054
3035
|
amountIn: amountIn,
|
|
@@ -3084,15 +3065,15 @@ var PerpetualsClient = (function () {
|
|
|
3084
3065
|
})
|
|
3085
3066
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3086
3067
|
.instruction()];
|
|
3087
|
-
case
|
|
3068
|
+
case 8:
|
|
3088
3069
|
inx = _c.sent();
|
|
3089
3070
|
instructions.push(inx);
|
|
3090
|
-
return [3,
|
|
3091
|
-
case
|
|
3071
|
+
return [3, 10];
|
|
3072
|
+
case 9:
|
|
3092
3073
|
err_3 = _c.sent();
|
|
3093
3074
|
console.error("perpClient SwapAndOpen error:: ", err_3);
|
|
3094
3075
|
throw err_3;
|
|
3095
|
-
case
|
|
3076
|
+
case 10: return [2, {
|
|
3096
3077
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3097
3078
|
additionalSigners: additionalSigners
|
|
3098
3079
|
}];
|
|
@@ -3105,7 +3086,7 @@ var PerpetualsClient = (function () {
|
|
|
3105
3086
|
for (var _i = 7; _i < arguments.length; _i++) {
|
|
3106
3087
|
args_1[_i - 7] = arguments[_i];
|
|
3107
3088
|
}
|
|
3108
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey) {
|
|
3089
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey, userPublicKey) {
|
|
3109
3090
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, inx, err_4;
|
|
3110
3091
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3111
3092
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
@@ -3113,7 +3094,7 @@ var PerpetualsClient = (function () {
|
|
|
3113
3094
|
return __generator(this, function (_a) {
|
|
3114
3095
|
switch (_a.label) {
|
|
3115
3096
|
case 0:
|
|
3116
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3097
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3117
3098
|
userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
|
|
3118
3099
|
if (!userOutputCustodyConfig) {
|
|
3119
3100
|
throw "userOutputCustodyConfig not found";
|
|
@@ -3137,46 +3118,37 @@ var PerpetualsClient = (function () {
|
|
|
3137
3118
|
additionalSigners = [];
|
|
3138
3119
|
collateralToken = poolConfig.getTokenFromSymbol(collateralTokenSymbol);
|
|
3139
3120
|
userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
|
|
3140
|
-
if (
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3121
|
+
if (userOutputTokenSymbol == 'SOL') {
|
|
3122
|
+
console.log("outputSymbol === SOL", userOutputTokenSymbol);
|
|
3123
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
3124
|
+
if (!ephemeralSignerPubkey) {
|
|
3125
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3126
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3127
|
+
}
|
|
3128
|
+
preInstructions = [
|
|
3129
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3130
|
+
fromPubkey: publicKey,
|
|
3131
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3132
|
+
lamports: lamports,
|
|
3133
|
+
space: 165,
|
|
3134
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3135
|
+
}),
|
|
3136
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3137
|
+
];
|
|
3138
|
+
postInstructions = [
|
|
3139
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3140
|
+
];
|
|
3145
3141
|
additionalSigners.push(wrappedSolAccount);
|
|
3146
3142
|
}
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3151
|
-
lamports: lamports,
|
|
3152
|
-
space: 165,
|
|
3153
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3154
|
-
}),
|
|
3155
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3156
|
-
];
|
|
3157
|
-
postInstructions = [
|
|
3158
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3159
|
-
];
|
|
3160
|
-
additionalSigners.push(wrappedSolAccount);
|
|
3161
|
-
return [3, 3];
|
|
3162
|
-
case 1:
|
|
3163
|
-
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);
|
|
3164
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3165
|
-
case 2:
|
|
3166
|
-
if (!(_a.sent())) {
|
|
3167
|
-
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));
|
|
3143
|
+
else {
|
|
3144
|
+
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);
|
|
3145
|
+
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));
|
|
3168
3146
|
}
|
|
3169
|
-
_a.label = 3;
|
|
3170
|
-
case 3:
|
|
3171
3147
|
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);
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
}
|
|
3177
|
-
_a.label = 5;
|
|
3178
|
-
case 5:
|
|
3179
|
-
_a.trys.push([5, 7, , 8]);
|
|
3148
|
+
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));
|
|
3149
|
+
_a.label = 1;
|
|
3150
|
+
case 1:
|
|
3151
|
+
_a.trys.push([1, 3, , 4]);
|
|
3180
3152
|
return [4, this.program.methods
|
|
3181
3153
|
.closeAndSwap({
|
|
3182
3154
|
priceWithSlippage: priceWithSlippage,
|
|
@@ -3210,15 +3182,15 @@ var PerpetualsClient = (function () {
|
|
|
3210
3182
|
})
|
|
3211
3183
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3212
3184
|
.instruction()];
|
|
3213
|
-
case
|
|
3185
|
+
case 2:
|
|
3214
3186
|
inx = _a.sent();
|
|
3215
3187
|
instructions.push(inx);
|
|
3216
|
-
return [3,
|
|
3217
|
-
case
|
|
3188
|
+
return [3, 4];
|
|
3189
|
+
case 3:
|
|
3218
3190
|
err_4 = _a.sent();
|
|
3219
3191
|
console.error("perpClient CloseAndSwap error:: ", err_4);
|
|
3220
3192
|
throw err_4;
|
|
3221
|
-
case
|
|
3193
|
+
case 4: return [2, {
|
|
3222
3194
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3223
3195
|
additionalSigners: additionalSigners
|
|
3224
3196
|
}];
|
|
@@ -3231,14 +3203,14 @@ var PerpetualsClient = (function () {
|
|
|
3231
3203
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
3232
3204
|
args_1[_i - 6] = arguments[_i];
|
|
3233
3205
|
}
|
|
3234
|
-
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
3206
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
|
3235
3207
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
|
3236
3208
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
3237
3209
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3238
3210
|
return __generator(this, function (_c) {
|
|
3239
3211
|
switch (_c.label) {
|
|
3240
3212
|
case 0:
|
|
3241
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3213
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3242
3214
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
3243
3215
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
3244
3216
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -3334,14 +3306,14 @@ var PerpetualsClient = (function () {
|
|
|
3334
3306
|
for (var _i = 7; _i < arguments.length; _i++) {
|
|
3335
3307
|
args_1[_i - 7] = arguments[_i];
|
|
3336
3308
|
}
|
|
3337
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
3309
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
|
3338
3310
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
|
3339
3311
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
3340
3312
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3341
3313
|
return __generator(this, function (_c) {
|
|
3342
3314
|
switch (_c.label) {
|
|
3343
3315
|
case 0:
|
|
3344
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3316
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3345
3317
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
3346
3318
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
3347
3319
|
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
|
@@ -3405,11 +3377,7 @@ var PerpetualsClient = (function () {
|
|
|
3405
3377
|
_c.label = 6;
|
|
3406
3378
|
case 6:
|
|
3407
3379
|
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);
|
|
3408
|
-
|
|
3409
|
-
case 7:
|
|
3410
|
-
if (!(_c.sent())) {
|
|
3411
|
-
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));
|
|
3412
|
-
}
|
|
3380
|
+
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));
|
|
3413
3381
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3414
3382
|
return [4, this.program.methods.swapAndAddCollateral({
|
|
3415
3383
|
amountIn: amountIn,
|
|
@@ -3437,7 +3405,7 @@ var PerpetualsClient = (function () {
|
|
|
3437
3405
|
fundingMint: poolConfig.getTokenFromSymbol(inputSymbol).mintKey,
|
|
3438
3406
|
})
|
|
3439
3407
|
.instruction()];
|
|
3440
|
-
case
|
|
3408
|
+
case 7:
|
|
3441
3409
|
instruction = _c.sent();
|
|
3442
3410
|
instructions.push(instruction);
|
|
3443
3411
|
return [2, {
|
|
@@ -3453,15 +3421,15 @@ var PerpetualsClient = (function () {
|
|
|
3453
3421
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
3454
3422
|
args_1[_i - 6] = arguments[_i];
|
|
3455
3423
|
}
|
|
3456
|
-
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) {
|
|
3457
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports,
|
|
3424
|
+
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) {
|
|
3425
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, marketAccount, instruction, closeWsolATAIns, error_2;
|
|
3458
3426
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
3459
3427
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
3460
3428
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3461
|
-
return __generator(this, function (
|
|
3462
|
-
switch (
|
|
3429
|
+
return __generator(this, function (_a) {
|
|
3430
|
+
switch (_a.label) {
|
|
3463
3431
|
case 0:
|
|
3464
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3432
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3465
3433
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
3466
3434
|
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
|
3467
3435
|
});
|
|
@@ -3475,45 +3443,35 @@ var PerpetualsClient = (function () {
|
|
|
3475
3443
|
instructions = [];
|
|
3476
3444
|
postInstructions = [];
|
|
3477
3445
|
additionalSigners = [];
|
|
3478
|
-
|
|
3446
|
+
_a.label = 1;
|
|
3479
3447
|
case 1:
|
|
3480
|
-
|
|
3448
|
+
_a.trys.push([1, 3, , 4]);
|
|
3481
3449
|
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
|
3482
|
-
if (
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3450
|
+
if (collateralSymbol == 'SOL') {
|
|
3451
|
+
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
|
3452
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3453
|
+
if (!ephemeralSignerPubkey) {
|
|
3454
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3455
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3456
|
+
}
|
|
3457
|
+
preInstructions = [
|
|
3458
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3459
|
+
fromPubkey: publicKey,
|
|
3460
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3461
|
+
lamports: lamports,
|
|
3462
|
+
space: 165,
|
|
3463
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3464
|
+
}),
|
|
3465
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3466
|
+
];
|
|
3467
|
+
postInstructions = [
|
|
3468
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3469
|
+
];
|
|
3488
3470
|
}
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3493
|
-
lamports: lamports,
|
|
3494
|
-
space: 165,
|
|
3495
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3496
|
-
}),
|
|
3497
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3498
|
-
];
|
|
3499
|
-
postInstructions = [
|
|
3500
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3501
|
-
];
|
|
3502
|
-
return [3, 5];
|
|
3503
|
-
case 2:
|
|
3504
|
-
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);
|
|
3505
|
-
_a = createUserATA;
|
|
3506
|
-
if (!_a) return [3, 4];
|
|
3507
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3508
|
-
case 3:
|
|
3509
|
-
_a = !(_b.sent());
|
|
3510
|
-
_b.label = 4;
|
|
3511
|
-
case 4:
|
|
3512
|
-
if (_a) {
|
|
3513
|
-
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));
|
|
3471
|
+
else {
|
|
3472
|
+
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);
|
|
3473
|
+
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));
|
|
3514
3474
|
}
|
|
3515
|
-
_b.label = 5;
|
|
3516
|
-
case 5:
|
|
3517
3475
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3518
3476
|
return [4, this.program.methods
|
|
3519
3477
|
.removeCollateral({
|
|
@@ -3539,19 +3497,19 @@ var PerpetualsClient = (function () {
|
|
|
3539
3497
|
receivingMint: collateralCustodyConfig.mintKey
|
|
3540
3498
|
})
|
|
3541
3499
|
.instruction()];
|
|
3542
|
-
case
|
|
3543
|
-
instruction =
|
|
3500
|
+
case 2:
|
|
3501
|
+
instruction = _a.sent();
|
|
3544
3502
|
instructions.push(instruction);
|
|
3545
3503
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
|
3546
3504
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
3547
3505
|
postInstructions.push(closeWsolATAIns);
|
|
3548
3506
|
}
|
|
3549
|
-
return [3,
|
|
3550
|
-
case
|
|
3551
|
-
error_2 =
|
|
3507
|
+
return [3, 4];
|
|
3508
|
+
case 3:
|
|
3509
|
+
error_2 = _a.sent();
|
|
3552
3510
|
console.error("perpclient removeCollateral error:", error_2);
|
|
3553
3511
|
throw error_2;
|
|
3554
|
-
case
|
|
3512
|
+
case 4: return [2, {
|
|
3555
3513
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3556
3514
|
additionalSigners: additionalSigners
|
|
3557
3515
|
}];
|
|
@@ -3564,13 +3522,13 @@ var PerpetualsClient = (function () {
|
|
|
3564
3522
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
3565
3523
|
args_1[_i - 6] = arguments[_i];
|
|
3566
3524
|
}
|
|
3567
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, collateralDeltaUsd_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, collateralDeltaUsd, side, poolConfig, ephemeralSignerPubkey) {
|
|
3525
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, collateralDeltaUsd_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, collateralDeltaUsd, side, poolConfig, ephemeralSignerPubkey, userPublicKey) {
|
|
3568
3526
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
|
3569
3527
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3570
3528
|
return __generator(this, function (_a) {
|
|
3571
3529
|
switch (_a.label) {
|
|
3572
3530
|
case 0:
|
|
3573
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3531
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3574
3532
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
3575
3533
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
3576
3534
|
outputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outputSymbol).mintKey); });
|
|
@@ -3581,42 +3539,33 @@ var PerpetualsClient = (function () {
|
|
|
3581
3539
|
instructions = [];
|
|
3582
3540
|
postInstructions = [];
|
|
3583
3541
|
additionalSigners = [];
|
|
3584
|
-
if (
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3542
|
+
if (outputSymbol == 'SOL') {
|
|
3543
|
+
console.log("outputSymbol === SOL", outputSymbol);
|
|
3544
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3545
|
+
if (!ephemeralSignerPubkey) {
|
|
3546
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3547
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3548
|
+
}
|
|
3549
|
+
preInstructions = [
|
|
3550
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3551
|
+
fromPubkey: publicKey,
|
|
3552
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3553
|
+
lamports: lamports,
|
|
3554
|
+
space: 165,
|
|
3555
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3556
|
+
}),
|
|
3557
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3558
|
+
];
|
|
3559
|
+
postInstructions = [
|
|
3560
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3561
|
+
];
|
|
3590
3562
|
}
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3595
|
-
lamports: lamports,
|
|
3596
|
-
space: 165,
|
|
3597
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3598
|
-
}),
|
|
3599
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3600
|
-
];
|
|
3601
|
-
postInstructions = [
|
|
3602
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3603
|
-
];
|
|
3604
|
-
return [3, 3];
|
|
3605
|
-
case 1:
|
|
3606
|
-
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);
|
|
3607
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3608
|
-
case 2:
|
|
3609
|
-
if (!(_a.sent())) {
|
|
3610
|
-
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));
|
|
3563
|
+
else {
|
|
3564
|
+
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);
|
|
3565
|
+
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));
|
|
3611
3566
|
}
|
|
3612
|
-
_a.label = 3;
|
|
3613
|
-
case 3:
|
|
3614
3567
|
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);
|
|
3615
|
-
|
|
3616
|
-
case 4:
|
|
3617
|
-
if (!(_a.sent())) {
|
|
3618
|
-
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));
|
|
3619
|
-
}
|
|
3568
|
+
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));
|
|
3620
3569
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3621
3570
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
3622
3571
|
return [4, this.program.methods
|
|
@@ -3650,7 +3599,7 @@ var PerpetualsClient = (function () {
|
|
|
3650
3599
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
3651
3600
|
})
|
|
3652
3601
|
.instruction()];
|
|
3653
|
-
case
|
|
3602
|
+
case 1:
|
|
3654
3603
|
instruction = _a.sent();
|
|
3655
3604
|
instructions.push(instruction);
|
|
3656
3605
|
return [2, {
|
|
@@ -3666,14 +3615,14 @@ var PerpetualsClient = (function () {
|
|
|
3666
3615
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3667
3616
|
args_1[_i - 8] = arguments[_i];
|
|
3668
3617
|
}
|
|
3669
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
|
3618
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, userPublicKey) {
|
|
3670
3619
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3671
3620
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3672
3621
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3673
3622
|
return __generator(this, function (_a) {
|
|
3674
3623
|
switch (_a.label) {
|
|
3675
3624
|
case 0:
|
|
3676
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3625
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3677
3626
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
3678
3627
|
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
|
3679
3628
|
});
|
|
@@ -3730,14 +3679,14 @@ var PerpetualsClient = (function () {
|
|
|
3730
3679
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3731
3680
|
args_1[_i - 8] = arguments[_i];
|
|
3732
3681
|
}
|
|
3733
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
|
3682
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, userPublicKey) {
|
|
3734
3683
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3735
3684
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3736
3685
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3737
3686
|
return __generator(this, function (_a) {
|
|
3738
3687
|
switch (_a.label) {
|
|
3739
3688
|
case 0:
|
|
3740
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3689
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3741
3690
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
3742
3691
|
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
|
3743
3692
|
});
|
|
@@ -3794,7 +3743,7 @@ var PerpetualsClient = (function () {
|
|
|
3794
3743
|
for (var _i = 4; _i < arguments.length; _i++) {
|
|
3795
3744
|
args_1[_i - 4] = arguments[_i];
|
|
3796
3745
|
}
|
|
3797
|
-
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser) {
|
|
3746
|
+
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser, userPublicKey) {
|
|
3798
3747
|
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, whitelistPda, whitelistMeta, instruction, err_5;
|
|
3799
3748
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
3800
3749
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
@@ -3802,7 +3751,7 @@ var PerpetualsClient = (function () {
|
|
|
3802
3751
|
return __generator(this, function (_g) {
|
|
3803
3752
|
switch (_g.label) {
|
|
3804
3753
|
case 0:
|
|
3805
|
-
publicKey = this.provider.wallet.publicKey;
|
|
3754
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
3806
3755
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
|
3807
3756
|
if (!payTokenCustodyConfig) {
|
|
3808
3757
|
throw "payTokenCustodyConfig not found";
|
|
@@ -3814,7 +3763,7 @@ var PerpetualsClient = (function () {
|
|
|
3814
3763
|
payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
|
|
3815
3764
|
_g.label = 1;
|
|
3816
3765
|
case 1:
|
|
3817
|
-
_g.trys.push([1,
|
|
3766
|
+
_g.trys.push([1, 9, , 10]);
|
|
3818
3767
|
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);
|
|
3819
3768
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
|
3820
3769
|
custodyAccountMetas = [];
|
|
@@ -3841,24 +3790,20 @@ var PerpetualsClient = (function () {
|
|
|
3841
3790
|
isWritable: false,
|
|
3842
3791
|
});
|
|
3843
3792
|
}
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
if (!(_g.sent())) {
|
|
3847
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
3848
|
-
}
|
|
3849
|
-
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
|
3793
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
3794
|
+
if (!(payTokenSymbol == 'SOL')) return [3, 4];
|
|
3850
3795
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
|
3851
3796
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
3852
|
-
if (!!skipBalanceChecks) return [3,
|
|
3797
|
+
if (!!skipBalanceChecks) return [3, 3];
|
|
3853
3798
|
_e = anchor_1.BN.bind;
|
|
3854
3799
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
3855
|
-
case
|
|
3800
|
+
case 2:
|
|
3856
3801
|
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
|
3857
3802
|
if (unWrappedSolBalance.lt(lamports)) {
|
|
3858
3803
|
throw "Insufficient SOL Funds";
|
|
3859
3804
|
}
|
|
3860
|
-
_g.label =
|
|
3861
|
-
case
|
|
3805
|
+
_g.label = 3;
|
|
3806
|
+
case 3:
|
|
3862
3807
|
if (!ephemeralSignerPubkey) {
|
|
3863
3808
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3864
3809
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -3876,23 +3821,23 @@ var PerpetualsClient = (function () {
|
|
|
3876
3821
|
postInstructions = [
|
|
3877
3822
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3878
3823
|
];
|
|
3879
|
-
return [3,
|
|
3880
|
-
case
|
|
3881
|
-
if (!!skipBalanceChecks) return [3,
|
|
3824
|
+
return [3, 7];
|
|
3825
|
+
case 4:
|
|
3826
|
+
if (!!skipBalanceChecks) return [3, 7];
|
|
3882
3827
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
|
3883
|
-
case
|
|
3828
|
+
case 5:
|
|
3884
3829
|
if (!(_g.sent())) {
|
|
3885
3830
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
3886
3831
|
}
|
|
3887
3832
|
_f = anchor_1.BN.bind;
|
|
3888
3833
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
|
3889
|
-
case
|
|
3834
|
+
case 6:
|
|
3890
3835
|
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
3891
3836
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
|
3892
3837
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
|
3893
3838
|
}
|
|
3894
|
-
_g.label =
|
|
3895
|
-
case
|
|
3839
|
+
_g.label = 7;
|
|
3840
|
+
case 7:
|
|
3896
3841
|
whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
|
|
3897
3842
|
whitelistMeta = {
|
|
3898
3843
|
pubkey: whitelistPda,
|
|
@@ -3924,15 +3869,15 @@ var PerpetualsClient = (function () {
|
|
|
3924
3869
|
})
|
|
3925
3870
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
3926
3871
|
.instruction()];
|
|
3927
|
-
case
|
|
3872
|
+
case 8:
|
|
3928
3873
|
instruction = _g.sent();
|
|
3929
3874
|
instructions.push(instruction);
|
|
3930
|
-
return [3,
|
|
3931
|
-
case
|
|
3875
|
+
return [3, 10];
|
|
3876
|
+
case 9:
|
|
3932
3877
|
err_5 = _g.sent();
|
|
3933
3878
|
console.error("perpClient addLiquidity error:: ", err_5);
|
|
3934
3879
|
throw err_5;
|
|
3935
|
-
case
|
|
3880
|
+
case 10: return [2, {
|
|
3936
3881
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3937
3882
|
additionalSigners: additionalSigners
|
|
3938
3883
|
}];
|
|
@@ -3965,7 +3910,7 @@ var PerpetualsClient = (function () {
|
|
|
3965
3910
|
inputToken = poolConfig.getTokenFromSymbol(inputSymbol);
|
|
3966
3911
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
3967
3912
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
|
3968
|
-
if (!(inputSymbol == 'SOL')) return [3,
|
|
3913
|
+
if (!(inputSymbol == 'SOL')) return [3, 3];
|
|
3969
3914
|
console.log("inputSymbol === SOL", inputSymbol);
|
|
3970
3915
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
3971
3916
|
console.log("lamports:", lamports.toNumber());
|
|
@@ -3978,11 +3923,8 @@ var PerpetualsClient = (function () {
|
|
|
3978
3923
|
throw "Insufficient SOL Funds";
|
|
3979
3924
|
}
|
|
3980
3925
|
_g.label = 2;
|
|
3981
|
-
case 2:
|
|
3982
|
-
|
|
3983
|
-
if (!(_g.sent())) {
|
|
3984
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
3985
|
-
}
|
|
3926
|
+
case 2:
|
|
3927
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
3986
3928
|
if (!ephemeralSignerPubkey) {
|
|
3987
3929
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3988
3930
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -4000,24 +3942,24 @@ var PerpetualsClient = (function () {
|
|
|
4000
3942
|
postInstructions = [
|
|
4001
3943
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4002
3944
|
];
|
|
4003
|
-
return [3,
|
|
4004
|
-
case
|
|
3945
|
+
return [3, 6];
|
|
3946
|
+
case 3:
|
|
4005
3947
|
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);
|
|
4006
|
-
if (!!skipBalanceChecks) return [3,
|
|
3948
|
+
if (!!skipBalanceChecks) return [3, 6];
|
|
4007
3949
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
4008
|
-
case
|
|
3950
|
+
case 4:
|
|
4009
3951
|
if (!(_g.sent())) {
|
|
4010
3952
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
4011
3953
|
}
|
|
4012
3954
|
_b = anchor_1.BN.bind;
|
|
4013
3955
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
4014
|
-
case
|
|
3956
|
+
case 5:
|
|
4015
3957
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
4016
3958
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
4017
3959
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
4018
3960
|
}
|
|
4019
|
-
_g.label =
|
|
4020
|
-
case
|
|
3961
|
+
_g.label = 6;
|
|
3962
|
+
case 6:
|
|
4021
3963
|
custodyAccountMetas = [];
|
|
4022
3964
|
custodyOracleAccountMetas = [];
|
|
4023
3965
|
markets = [];
|
|
@@ -4074,7 +4016,7 @@ var PerpetualsClient = (function () {
|
|
|
4074
4016
|
})
|
|
4075
4017
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4076
4018
|
.instruction()];
|
|
4077
|
-
case
|
|
4019
|
+
case 7:
|
|
4078
4020
|
instruction = _g.sent();
|
|
4079
4021
|
instructions.push(instruction);
|
|
4080
4022
|
return [2, {
|
|
@@ -4557,12 +4499,12 @@ var PerpetualsClient = (function () {
|
|
|
4557
4499
|
}
|
|
4558
4500
|
});
|
|
4559
4501
|
}); };
|
|
4560
|
-
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
4502
|
+
this.unstakeRequest = function (unstakeAmount, poolConfig, userPublicKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
4561
4503
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
|
4562
4504
|
return __generator(this, function (_a) {
|
|
4563
4505
|
switch (_a.label) {
|
|
4564
4506
|
case 0:
|
|
4565
|
-
publicKey = this.provider.wallet.publicKey;
|
|
4507
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
4566
4508
|
preInstructions = [];
|
|
4567
4509
|
instructions = [];
|
|
4568
4510
|
postInstructions = [];
|
|
@@ -4681,10 +4623,10 @@ var PerpetualsClient = (function () {
|
|
|
4681
4623
|
args_1[_i - 3] = arguments[_i];
|
|
4682
4624
|
}
|
|
4683
4625
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
|
4684
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount,
|
|
4626
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
|
4685
4627
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4686
|
-
return __generator(this, function (
|
|
4687
|
-
switch (
|
|
4628
|
+
return __generator(this, function (_a) {
|
|
4629
|
+
switch (_a.label) {
|
|
4688
4630
|
case 0:
|
|
4689
4631
|
publicKey = this.provider.wallet.publicKey;
|
|
4690
4632
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
@@ -4693,22 +4635,13 @@ var PerpetualsClient = (function () {
|
|
|
4693
4635
|
instructions = [];
|
|
4694
4636
|
postInstructions = [];
|
|
4695
4637
|
additionalSigners = [];
|
|
4696
|
-
|
|
4638
|
+
_a.label = 1;
|
|
4697
4639
|
case 1:
|
|
4698
|
-
|
|
4640
|
+
_a.trys.push([1, 3, , 4]);
|
|
4699
4641
|
pool = poolConfig.poolAddress;
|
|
4700
4642
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
|
4701
4643
|
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
|
4702
|
-
|
|
4703
|
-
if (!_a) return [3, 3];
|
|
4704
|
-
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
4705
|
-
case 2:
|
|
4706
|
-
_a = !(_b.sent());
|
|
4707
|
-
_b.label = 3;
|
|
4708
|
-
case 3:
|
|
4709
|
-
if (_a) {
|
|
4710
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
|
4711
|
-
}
|
|
4644
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4712
4645
|
tokenStakeAccounts = [];
|
|
4713
4646
|
if (tokenStakeAccount) {
|
|
4714
4647
|
tokenStakeAccounts.push({
|
|
@@ -4737,15 +4670,15 @@ var PerpetualsClient = (function () {
|
|
|
4737
4670
|
})
|
|
4738
4671
|
.remainingAccounts(__spreadArray([], tokenStakeAccounts, true))
|
|
4739
4672
|
.instruction()];
|
|
4740
|
-
case
|
|
4741
|
-
withdrawStakeInstruction =
|
|
4673
|
+
case 2:
|
|
4674
|
+
withdrawStakeInstruction = _a.sent();
|
|
4742
4675
|
instructions.push(withdrawStakeInstruction);
|
|
4743
|
-
return [3,
|
|
4744
|
-
case
|
|
4745
|
-
err_15 =
|
|
4676
|
+
return [3, 4];
|
|
4677
|
+
case 3:
|
|
4678
|
+
err_15 = _a.sent();
|
|
4746
4679
|
console.log("perpClient withdrawStake error:: ", err_15);
|
|
4747
4680
|
throw err_15;
|
|
4748
|
-
case
|
|
4681
|
+
case 4: return [2, {
|
|
4749
4682
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4750
4683
|
additionalSigners: additionalSigners
|
|
4751
4684
|
}];
|
|
@@ -4804,29 +4737,21 @@ var PerpetualsClient = (function () {
|
|
|
4804
4737
|
isWritable: false,
|
|
4805
4738
|
});
|
|
4806
4739
|
}
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
if (!(
|
|
4810
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
4811
|
-
}
|
|
4812
|
-
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
|
4813
|
-
case 2:
|
|
4814
|
-
if (!(_f.sent())) {
|
|
4815
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
|
4816
|
-
}
|
|
4817
|
-
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
|
4740
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4741
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
4742
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 3];
|
|
4818
4743
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
|
4819
4744
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
4820
|
-
if (!!skipBalanceChecks) return [3,
|
|
4745
|
+
if (!!skipBalanceChecks) return [3, 2];
|
|
4821
4746
|
_e = anchor_1.BN.bind;
|
|
4822
4747
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
4823
|
-
case
|
|
4748
|
+
case 1:
|
|
4824
4749
|
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
4825
4750
|
if (unWrappedSolBalance.lt(lamports)) {
|
|
4826
4751
|
throw "Insufficient SOL Funds";
|
|
4827
4752
|
}
|
|
4828
|
-
_f.label =
|
|
4829
|
-
case
|
|
4753
|
+
_f.label = 2;
|
|
4754
|
+
case 2:
|
|
4830
4755
|
if (!ephemeralSignerPubkey) {
|
|
4831
4756
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
4832
4757
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -4844,17 +4769,17 @@ var PerpetualsClient = (function () {
|
|
|
4844
4769
|
postInstructions = [
|
|
4845
4770
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4846
4771
|
];
|
|
4847
|
-
return [3,
|
|
4848
|
-
case
|
|
4849
|
-
if (!!skipBalanceChecks) return [3,
|
|
4772
|
+
return [3, 5];
|
|
4773
|
+
case 3:
|
|
4774
|
+
if (!!skipBalanceChecks) return [3, 5];
|
|
4850
4775
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
|
4851
|
-
case
|
|
4776
|
+
case 4:
|
|
4852
4777
|
if (!(_f.sent())) {
|
|
4853
4778
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
4854
4779
|
}
|
|
4855
|
-
_f.label =
|
|
4856
|
-
case
|
|
4857
|
-
_f.trys.push([
|
|
4780
|
+
_f.label = 5;
|
|
4781
|
+
case 5:
|
|
4782
|
+
_f.trys.push([5, 7, , 8]);
|
|
4858
4783
|
if (enableHeapSizeIx) {
|
|
4859
4784
|
heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
|
|
4860
4785
|
bytes: 64 * 1024,
|
|
@@ -4896,15 +4821,15 @@ var PerpetualsClient = (function () {
|
|
|
4896
4821
|
})
|
|
4897
4822
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4898
4823
|
.instruction()];
|
|
4899
|
-
case
|
|
4824
|
+
case 6:
|
|
4900
4825
|
addCompoundingLiquidity = _f.sent();
|
|
4901
4826
|
instructions.push(addCompoundingLiquidity);
|
|
4902
|
-
return [3,
|
|
4903
|
-
case
|
|
4827
|
+
return [3, 8];
|
|
4828
|
+
case 7:
|
|
4904
4829
|
err_16 = _f.sent();
|
|
4905
4830
|
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
|
4906
|
-
return [3,
|
|
4907
|
-
case
|
|
4831
|
+
return [3, 8];
|
|
4832
|
+
case 8: return [2, {
|
|
4908
4833
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4909
4834
|
additionalSigners: additionalSigners
|
|
4910
4835
|
}];
|
|
@@ -4918,14 +4843,14 @@ var PerpetualsClient = (function () {
|
|
|
4918
4843
|
args_1[_i - 5] = arguments[_i];
|
|
4919
4844
|
}
|
|
4920
4845
|
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) {
|
|
4921
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports,
|
|
4846
|
+
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;
|
|
4922
4847
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4923
4848
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4924
4849
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4925
4850
|
if (enableHeapSizeIx === void 0) { enableHeapSizeIx = true; }
|
|
4926
4851
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
4927
|
-
return __generator(this, function (
|
|
4928
|
-
switch (
|
|
4852
|
+
return __generator(this, function (_e) {
|
|
4853
|
+
switch (_e.label) {
|
|
4929
4854
|
case 0:
|
|
4930
4855
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
4931
4856
|
preInstructions = [];
|
|
@@ -4936,45 +4861,35 @@ var PerpetualsClient = (function () {
|
|
|
4936
4861
|
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
|
4937
4862
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
4938
4863
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
|
4939
|
-
if (
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4864
|
+
if (outCustodyConfig.symbol == 'SOL') {
|
|
4865
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
4866
|
+
if (!ephemeralSignerPubkey) {
|
|
4867
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
4868
|
+
additionalSigners.push(wrappedSolAccount);
|
|
4869
|
+
}
|
|
4870
|
+
preInstructions = [
|
|
4871
|
+
web3_js_1.SystemProgram.createAccount({
|
|
4872
|
+
fromPubkey: publicKey,
|
|
4873
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4874
|
+
lamports: lamports,
|
|
4875
|
+
space: 165,
|
|
4876
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4877
|
+
}),
|
|
4878
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4879
|
+
];
|
|
4880
|
+
postInstructions = [
|
|
4881
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4882
|
+
];
|
|
4944
4883
|
}
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4949
|
-
lamports: lamports,
|
|
4950
|
-
space: 165,
|
|
4951
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4952
|
-
}),
|
|
4953
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4954
|
-
];
|
|
4955
|
-
postInstructions = [
|
|
4956
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4957
|
-
];
|
|
4958
|
-
return [3, 4];
|
|
4959
|
-
case 1:
|
|
4960
|
-
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);
|
|
4961
|
-
_a = createUserATA;
|
|
4962
|
-
if (!_a) return [3, 3];
|
|
4963
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
4964
|
-
case 2:
|
|
4965
|
-
_a = !(_f.sent());
|
|
4966
|
-
_f.label = 3;
|
|
4967
|
-
case 3:
|
|
4968
|
-
if (_a) {
|
|
4969
|
-
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));
|
|
4884
|
+
else {
|
|
4885
|
+
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);
|
|
4886
|
+
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));
|
|
4970
4887
|
}
|
|
4971
|
-
_f.label = 4;
|
|
4972
|
-
case 4:
|
|
4973
4888
|
custodyAccountMetas = [];
|
|
4974
4889
|
custodyOracleAccountMetas = [];
|
|
4975
4890
|
markets = [];
|
|
4976
|
-
for (
|
|
4977
|
-
custody =
|
|
4891
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
|
4892
|
+
custody = _b[_a];
|
|
4978
4893
|
custodyAccountMetas.push({
|
|
4979
4894
|
pubkey: custody.custodyAccount,
|
|
4980
4895
|
isSigner: false,
|
|
@@ -4986,8 +4901,8 @@ var PerpetualsClient = (function () {
|
|
|
4986
4901
|
isWritable: false,
|
|
4987
4902
|
});
|
|
4988
4903
|
}
|
|
4989
|
-
for (
|
|
4990
|
-
market =
|
|
4904
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
|
4905
|
+
market = _d[_c];
|
|
4991
4906
|
markets.push({
|
|
4992
4907
|
pubkey: market.marketAccount,
|
|
4993
4908
|
isSigner: false,
|
|
@@ -4995,9 +4910,9 @@ var PerpetualsClient = (function () {
|
|
|
4995
4910
|
});
|
|
4996
4911
|
}
|
|
4997
4912
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
|
4998
|
-
|
|
4999
|
-
case
|
|
5000
|
-
|
|
4913
|
+
_e.label = 1;
|
|
4914
|
+
case 1:
|
|
4915
|
+
_e.trys.push([1, 3, , 4]);
|
|
5001
4916
|
if (enableHeapSizeIx) {
|
|
5002
4917
|
heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
|
|
5003
4918
|
bytes: 64 * 1024,
|
|
@@ -5039,15 +4954,15 @@ var PerpetualsClient = (function () {
|
|
|
5039
4954
|
})
|
|
5040
4955
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
5041
4956
|
.instruction()];
|
|
5042
|
-
case
|
|
5043
|
-
removeCompoundingLiquidity =
|
|
4957
|
+
case 2:
|
|
4958
|
+
removeCompoundingLiquidity = _e.sent();
|
|
5044
4959
|
instructions.push(removeCompoundingLiquidity);
|
|
5045
|
-
return [3,
|
|
5046
|
-
case
|
|
5047
|
-
err_17 =
|
|
4960
|
+
return [3, 4];
|
|
4961
|
+
case 3:
|
|
4962
|
+
err_17 = _e.sent();
|
|
5048
4963
|
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
|
5049
|
-
return [3,
|
|
5050
|
-
case
|
|
4964
|
+
return [3, 4];
|
|
4965
|
+
case 4: return [2, {
|
|
5051
4966
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5052
4967
|
additionalSigners: additionalSigners
|
|
5053
4968
|
}];
|
|
@@ -5060,13 +4975,13 @@ var PerpetualsClient = (function () {
|
|
|
5060
4975
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
5061
4976
|
args_1[_i - 3] = arguments[_i];
|
|
5062
4977
|
}
|
|
5063
|
-
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
|
5064
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount,
|
|
4978
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA, userPublicKey) {
|
|
4979
|
+
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;
|
|
5065
4980
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5066
|
-
return __generator(this, function (
|
|
5067
|
-
switch (
|
|
4981
|
+
return __generator(this, function (_f) {
|
|
4982
|
+
switch (_f.label) {
|
|
5068
4983
|
case 0:
|
|
5069
|
-
publicKey = this.provider.wallet.publicKey;
|
|
4984
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5070
4985
|
preInstructions = [];
|
|
5071
4986
|
instructions = [];
|
|
5072
4987
|
postInstructions = [];
|
|
@@ -5075,27 +4990,18 @@ var PerpetualsClient = (function () {
|
|
|
5075
4990
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
5076
4991
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
|
5077
4992
|
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
|
5078
|
-
|
|
5079
|
-
if (!_a) return [3, 2];
|
|
5080
|
-
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
|
5081
|
-
case 1:
|
|
5082
|
-
_a = !(_g.sent());
|
|
5083
|
-
_g.label = 2;
|
|
5084
|
-
case 2:
|
|
5085
|
-
if (_a) {
|
|
5086
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
|
5087
|
-
}
|
|
4993
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5088
4994
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
5089
4995
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), publicKey.toBuffer()], this.programId)[0];
|
|
5090
4996
|
tokenStakeAccounts = [];
|
|
5091
|
-
|
|
5092
|
-
if (!
|
|
4997
|
+
_a = tokenStakeAccount;
|
|
4998
|
+
if (!_a) return [3, 2];
|
|
5093
4999
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
|
5094
|
-
case
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
case
|
|
5098
|
-
if (
|
|
5000
|
+
case 1:
|
|
5001
|
+
_a = (_f.sent());
|
|
5002
|
+
_f.label = 2;
|
|
5003
|
+
case 2:
|
|
5004
|
+
if (_a) {
|
|
5099
5005
|
tokenStakeAccounts.push({
|
|
5100
5006
|
pubkey: tokenStakeAccount,
|
|
5101
5007
|
isSigner: false,
|
|
@@ -5106,8 +5012,8 @@ var PerpetualsClient = (function () {
|
|
|
5106
5012
|
custodyAccountMetas = [];
|
|
5107
5013
|
custodyOracleAccountMetas = [];
|
|
5108
5014
|
markets = [];
|
|
5109
|
-
for (
|
|
5110
|
-
custody =
|
|
5015
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
|
5016
|
+
custody = _c[_b];
|
|
5111
5017
|
custodyAccountMetas.push({
|
|
5112
5018
|
pubkey: custody.custodyAccount,
|
|
5113
5019
|
isSigner: false,
|
|
@@ -5119,17 +5025,17 @@ var PerpetualsClient = (function () {
|
|
|
5119
5025
|
isWritable: false,
|
|
5120
5026
|
});
|
|
5121
5027
|
}
|
|
5122
|
-
for (
|
|
5123
|
-
market =
|
|
5028
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
|
5029
|
+
market = _e[_d];
|
|
5124
5030
|
markets.push({
|
|
5125
5031
|
pubkey: market.marketAccount,
|
|
5126
5032
|
isSigner: false,
|
|
5127
5033
|
isWritable: false,
|
|
5128
5034
|
});
|
|
5129
5035
|
}
|
|
5130
|
-
|
|
5131
|
-
case
|
|
5132
|
-
|
|
5036
|
+
_f.label = 3;
|
|
5037
|
+
case 3:
|
|
5038
|
+
_f.trys.push([3, 5, , 6]);
|
|
5133
5039
|
return [4, this.program.methods
|
|
5134
5040
|
.migrateStake({
|
|
5135
5041
|
amount: amount
|
|
@@ -5154,15 +5060,15 @@ var PerpetualsClient = (function () {
|
|
|
5154
5060
|
})
|
|
5155
5061
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
|
5156
5062
|
.instruction()];
|
|
5157
|
-
case
|
|
5158
|
-
migrateStake =
|
|
5063
|
+
case 4:
|
|
5064
|
+
migrateStake = _f.sent();
|
|
5159
5065
|
instructions.push(migrateStake);
|
|
5160
|
-
return [3,
|
|
5161
|
-
case
|
|
5162
|
-
err_18 =
|
|
5066
|
+
return [3, 6];
|
|
5067
|
+
case 5:
|
|
5068
|
+
err_18 = _f.sent();
|
|
5163
5069
|
console.log("perpClient migrateStake error:: ", err_18);
|
|
5164
|
-
return [3,
|
|
5165
|
-
case
|
|
5070
|
+
return [3, 6];
|
|
5071
|
+
case 6: return [2, {
|
|
5166
5072
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5167
5073
|
additionalSigners: additionalSigners
|
|
5168
5074
|
}];
|
|
@@ -5170,12 +5076,12 @@ var PerpetualsClient = (function () {
|
|
|
5170
5076
|
});
|
|
5171
5077
|
});
|
|
5172
5078
|
};
|
|
5173
|
-
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5079
|
+
this.migrateFlp = function (amount, rewardTokenMint, poolConfig, userPublicKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
5174
5080
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
|
|
5175
5081
|
return __generator(this, function (_d) {
|
|
5176
5082
|
switch (_d.label) {
|
|
5177
5083
|
case 0:
|
|
5178
|
-
publicKey = this.provider.wallet.publicKey;
|
|
5084
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5179
5085
|
preInstructions = [];
|
|
5180
5086
|
instructions = [];
|
|
5181
5087
|
postInstructions = [];
|
|
@@ -5339,14 +5245,10 @@ var PerpetualsClient = (function () {
|
|
|
5339
5245
|
additionalSigners = [];
|
|
5340
5246
|
_a.label = 1;
|
|
5341
5247
|
case 1:
|
|
5342
|
-
_a.trys.push([1,
|
|
5248
|
+
_a.trys.push([1, 3, , 4]);
|
|
5343
5249
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5344
5250
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5345
|
-
|
|
5346
|
-
case 2:
|
|
5347
|
-
if (!(_a.sent())) {
|
|
5348
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5349
|
-
}
|
|
5251
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5350
5252
|
return [4, this.program.methods
|
|
5351
5253
|
.depositTokenStake({
|
|
5352
5254
|
depositAmount: depositAmount
|
|
@@ -5366,15 +5268,15 @@ var PerpetualsClient = (function () {
|
|
|
5366
5268
|
tokenMint: poolConfig.tokenMint,
|
|
5367
5269
|
})
|
|
5368
5270
|
.instruction()];
|
|
5369
|
-
case
|
|
5271
|
+
case 2:
|
|
5370
5272
|
depositTokenStakeInstruction = _a.sent();
|
|
5371
5273
|
instructions.push(depositTokenStakeInstruction);
|
|
5372
|
-
return [3,
|
|
5373
|
-
case
|
|
5274
|
+
return [3, 4];
|
|
5275
|
+
case 3:
|
|
5374
5276
|
err_21 = _a.sent();
|
|
5375
5277
|
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
|
5376
5278
|
throw err_21;
|
|
5377
|
-
case
|
|
5279
|
+
case 4: return [2, {
|
|
5378
5280
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5379
5281
|
additionalSigners: additionalSigners
|
|
5380
5282
|
}];
|
|
@@ -5432,14 +5334,10 @@ var PerpetualsClient = (function () {
|
|
|
5432
5334
|
additionalSigners = [];
|
|
5433
5335
|
_a.label = 1;
|
|
5434
5336
|
case 1:
|
|
5435
|
-
_a.trys.push([1,
|
|
5337
|
+
_a.trys.push([1, 3, , 4]);
|
|
5436
5338
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5437
5339
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5438
|
-
|
|
5439
|
-
case 2:
|
|
5440
|
-
if (!(_a.sent())) {
|
|
5441
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5442
|
-
}
|
|
5340
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5443
5341
|
return [4, this.program.methods
|
|
5444
5342
|
.unstakeTokenInstant({
|
|
5445
5343
|
unstakeAmount: unstakeAmount
|
|
@@ -5458,15 +5356,15 @@ var PerpetualsClient = (function () {
|
|
|
5458
5356
|
tokenMint: poolConfig.tokenMint,
|
|
5459
5357
|
})
|
|
5460
5358
|
.instruction()];
|
|
5461
|
-
case
|
|
5359
|
+
case 2:
|
|
5462
5360
|
unstakeTokenInstantInstruction = _a.sent();
|
|
5463
5361
|
instructions.push(unstakeTokenInstantInstruction);
|
|
5464
|
-
return [3,
|
|
5465
|
-
case
|
|
5362
|
+
return [3, 4];
|
|
5363
|
+
case 3:
|
|
5466
5364
|
err_23 = _a.sent();
|
|
5467
5365
|
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
|
5468
5366
|
throw err_23;
|
|
5469
|
-
case
|
|
5367
|
+
case 4: return [2, {
|
|
5470
5368
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5471
5369
|
additionalSigners: additionalSigners
|
|
5472
5370
|
}];
|
|
@@ -5484,14 +5382,10 @@ var PerpetualsClient = (function () {
|
|
|
5484
5382
|
additionalSigners = [];
|
|
5485
5383
|
_a.label = 1;
|
|
5486
5384
|
case 1:
|
|
5487
|
-
_a.trys.push([1,
|
|
5385
|
+
_a.trys.push([1, 3, , 4]);
|
|
5488
5386
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5489
5387
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5490
|
-
|
|
5491
|
-
case 2:
|
|
5492
|
-
if (!(_a.sent())) {
|
|
5493
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5494
|
-
}
|
|
5388
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5495
5389
|
return [4, this.program.methods
|
|
5496
5390
|
.withdrawToken({
|
|
5497
5391
|
withdrawRequestId: withdrawRequestId
|
|
@@ -5510,15 +5404,15 @@ var PerpetualsClient = (function () {
|
|
|
5510
5404
|
tokenMint: poolConfig.tokenMint,
|
|
5511
5405
|
})
|
|
5512
5406
|
.instruction()];
|
|
5513
|
-
case
|
|
5407
|
+
case 2:
|
|
5514
5408
|
withdrawTokenInstruction = _a.sent();
|
|
5515
5409
|
instructions.push(withdrawTokenInstruction);
|
|
5516
|
-
return [3,
|
|
5517
|
-
case
|
|
5410
|
+
return [3, 4];
|
|
5411
|
+
case 3:
|
|
5518
5412
|
err_24 = _a.sent();
|
|
5519
5413
|
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
|
5520
5414
|
throw err_24;
|
|
5521
|
-
case
|
|
5415
|
+
case 4: return [2, {
|
|
5522
5416
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5523
5417
|
additionalSigners: additionalSigners
|
|
5524
5418
|
}];
|
|
@@ -5570,32 +5464,23 @@ var PerpetualsClient = (function () {
|
|
|
5570
5464
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
5571
5465
|
args_1[_i - 2] = arguments[_i];
|
|
5572
5466
|
}
|
|
5573
|
-
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
|
5574
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount,
|
|
5467
|
+
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA, userPublicKey) {
|
|
5468
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, collectTokenRewardInstruction, err_26;
|
|
5575
5469
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5576
|
-
return __generator(this, function (
|
|
5577
|
-
switch (
|
|
5470
|
+
return __generator(this, function (_a) {
|
|
5471
|
+
switch (_a.label) {
|
|
5578
5472
|
case 0:
|
|
5579
|
-
publicKey = this.provider.wallet.publicKey;
|
|
5473
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5580
5474
|
preInstructions = [];
|
|
5581
5475
|
instructions = [];
|
|
5582
5476
|
postInstructions = [];
|
|
5583
5477
|
additionalSigners = [];
|
|
5584
|
-
|
|
5478
|
+
_a.label = 1;
|
|
5585
5479
|
case 1:
|
|
5586
|
-
|
|
5480
|
+
_a.trys.push([1, 3, , 4]);
|
|
5587
5481
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5588
5482
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5589
|
-
|
|
5590
|
-
if (!_a) return [3, 3];
|
|
5591
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5592
|
-
case 2:
|
|
5593
|
-
_a = !(_b.sent());
|
|
5594
|
-
_b.label = 3;
|
|
5595
|
-
case 3:
|
|
5596
|
-
if (_a) {
|
|
5597
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, poolConfig.tokenMint));
|
|
5598
|
-
}
|
|
5483
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userTokenAccount, publicKey, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5599
5484
|
return [4, this.program.methods
|
|
5600
5485
|
.collectTokenReward({})
|
|
5601
5486
|
.accounts({
|
|
@@ -5612,15 +5497,15 @@ var PerpetualsClient = (function () {
|
|
|
5612
5497
|
tokenMint: poolConfig.tokenMint,
|
|
5613
5498
|
})
|
|
5614
5499
|
.instruction()];
|
|
5615
|
-
case
|
|
5616
|
-
collectTokenRewardInstruction =
|
|
5500
|
+
case 2:
|
|
5501
|
+
collectTokenRewardInstruction = _a.sent();
|
|
5617
5502
|
instructions.push(collectTokenRewardInstruction);
|
|
5618
|
-
return [3,
|
|
5619
|
-
case
|
|
5620
|
-
err_26 =
|
|
5503
|
+
return [3, 4];
|
|
5504
|
+
case 3:
|
|
5505
|
+
err_26 = _a.sent();
|
|
5621
5506
|
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
|
5622
5507
|
throw err_26;
|
|
5623
|
-
case
|
|
5508
|
+
case 4: return [2, {
|
|
5624
5509
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5625
5510
|
additionalSigners: additionalSigners
|
|
5626
5511
|
}];
|
|
@@ -5634,32 +5519,23 @@ var PerpetualsClient = (function () {
|
|
|
5634
5519
|
args_1[_i - 3] = arguments[_i];
|
|
5635
5520
|
}
|
|
5636
5521
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
|
5637
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount,
|
|
5522
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, collectRevenueInstruction, err_27;
|
|
5638
5523
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5639
|
-
return __generator(this, function (
|
|
5640
|
-
switch (
|
|
5524
|
+
return __generator(this, function (_a) {
|
|
5525
|
+
switch (_a.label) {
|
|
5641
5526
|
case 0:
|
|
5642
5527
|
publicKey = this.provider.wallet.publicKey;
|
|
5643
5528
|
preInstructions = [];
|
|
5644
5529
|
instructions = [];
|
|
5645
5530
|
postInstructions = [];
|
|
5646
5531
|
additionalSigners = [];
|
|
5647
|
-
|
|
5532
|
+
_a.label = 1;
|
|
5648
5533
|
case 1:
|
|
5649
|
-
|
|
5534
|
+
_a.trys.push([1, 3, , 4]);
|
|
5650
5535
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
5651
5536
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5652
5537
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, owner, true);
|
|
5653
|
-
|
|
5654
|
-
if (!_a) return [3, 3];
|
|
5655
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5656
|
-
case 2:
|
|
5657
|
-
_a = !(_b.sent());
|
|
5658
|
-
_b.label = 3;
|
|
5659
|
-
case 3:
|
|
5660
|
-
if (_a) {
|
|
5661
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rewardCustodyMint));
|
|
5662
|
-
}
|
|
5538
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userTokenAccount, publicKey, rewardCustodyMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5663
5539
|
return [4, this.program.methods
|
|
5664
5540
|
.collectRevenue({})
|
|
5665
5541
|
.accounts({
|
|
@@ -5676,15 +5552,15 @@ var PerpetualsClient = (function () {
|
|
|
5676
5552
|
receivingTokenMint: rewardCustodyMint,
|
|
5677
5553
|
})
|
|
5678
5554
|
.instruction()];
|
|
5679
|
-
case
|
|
5680
|
-
collectRevenueInstruction =
|
|
5555
|
+
case 2:
|
|
5556
|
+
collectRevenueInstruction = _a.sent();
|
|
5681
5557
|
instructions.push(collectRevenueInstruction);
|
|
5682
|
-
return [3,
|
|
5683
|
-
case
|
|
5684
|
-
err_27 =
|
|
5558
|
+
return [3, 4];
|
|
5559
|
+
case 3:
|
|
5560
|
+
err_27 = _a.sent();
|
|
5685
5561
|
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
|
5686
5562
|
throw err_27;
|
|
5687
|
-
case
|
|
5563
|
+
case 4: return [2, {
|
|
5688
5564
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5689
5565
|
additionalSigners: additionalSigners
|
|
5690
5566
|
}];
|
|
@@ -5698,32 +5574,23 @@ var PerpetualsClient = (function () {
|
|
|
5698
5574
|
args_1[_i - 3] = arguments[_i];
|
|
5699
5575
|
}
|
|
5700
5576
|
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
|
|
5701
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount,
|
|
5577
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, collectRebateInstruction, err_28;
|
|
5702
5578
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5703
|
-
return __generator(this, function (
|
|
5704
|
-
switch (
|
|
5579
|
+
return __generator(this, function (_a) {
|
|
5580
|
+
switch (_a.label) {
|
|
5705
5581
|
case 0:
|
|
5706
5582
|
publicKey = this.provider.wallet.publicKey;
|
|
5707
5583
|
preInstructions = [];
|
|
5708
5584
|
instructions = [];
|
|
5709
5585
|
postInstructions = [];
|
|
5710
5586
|
additionalSigners = [];
|
|
5711
|
-
|
|
5587
|
+
_a.label = 1;
|
|
5712
5588
|
case 1:
|
|
5713
|
-
|
|
5589
|
+
_a.trys.push([1, 3, , 4]);
|
|
5714
5590
|
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5715
5591
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5716
5592
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5717
|
-
|
|
5718
|
-
if (!_a) return [3, 3];
|
|
5719
|
-
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5720
|
-
case 2:
|
|
5721
|
-
_a = !(_b.sent());
|
|
5722
|
-
_b.label = 3;
|
|
5723
|
-
case 3:
|
|
5724
|
-
if (_a) {
|
|
5725
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5726
|
-
}
|
|
5593
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userTokenAccount, publicKey, rebateMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
5727
5594
|
return [4, this.program.methods
|
|
5728
5595
|
.collectRebate()
|
|
5729
5596
|
.accounts({
|
|
@@ -5740,15 +5607,15 @@ var PerpetualsClient = (function () {
|
|
|
5740
5607
|
receivingTokenMint: rebateMint,
|
|
5741
5608
|
})
|
|
5742
5609
|
.instruction()];
|
|
5743
|
-
case
|
|
5744
|
-
collectRebateInstruction =
|
|
5610
|
+
case 2:
|
|
5611
|
+
collectRebateInstruction = _a.sent();
|
|
5745
5612
|
instructions.push(collectRebateInstruction);
|
|
5746
|
-
return [3,
|
|
5747
|
-
case
|
|
5748
|
-
err_28 =
|
|
5613
|
+
return [3, 4];
|
|
5614
|
+
case 3:
|
|
5615
|
+
err_28 = _a.sent();
|
|
5749
5616
|
console.log("perpClient collectRebateInstruction error:: ", err_28);
|
|
5750
5617
|
throw err_28;
|
|
5751
|
-
case
|
|
5618
|
+
case 4: return [2, {
|
|
5752
5619
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5753
5620
|
additionalSigners: additionalSigners
|
|
5754
5621
|
}];
|
|
@@ -5808,14 +5675,14 @@ var PerpetualsClient = (function () {
|
|
|
5808
5675
|
for (var _i = 11; _i < arguments.length; _i++) {
|
|
5809
5676
|
args_1[_i - 11] = arguments[_i];
|
|
5810
5677
|
}
|
|
5811
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
5678
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
|
5812
5679
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_30;
|
|
5813
5680
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
5814
5681
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5815
5682
|
return __generator(this, function (_c) {
|
|
5816
5683
|
switch (_c.label) {
|
|
5817
5684
|
case 0:
|
|
5818
|
-
publicKey = this.provider.wallet.publicKey;
|
|
5685
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5819
5686
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
5820
5687
|
reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
|
|
5821
5688
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
@@ -5931,14 +5798,14 @@ var PerpetualsClient = (function () {
|
|
|
5931
5798
|
for (var _i = 11; _i < arguments.length; _i++) {
|
|
5932
5799
|
args_1[_i - 11] = arguments[_i];
|
|
5933
5800
|
}
|
|
5934
|
-
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) {
|
|
5935
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports,
|
|
5801
|
+
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) {
|
|
5802
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, positionAccount, orderAccount, editLimitOrder, err_31;
|
|
5936
5803
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5937
5804
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5938
|
-
return __generator(this, function (
|
|
5939
|
-
switch (
|
|
5805
|
+
return __generator(this, function (_a) {
|
|
5806
|
+
switch (_a.label) {
|
|
5940
5807
|
case 0:
|
|
5941
|
-
publicKey = this.provider.wallet.publicKey;
|
|
5808
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
5942
5809
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
5943
5810
|
reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
|
|
5944
5811
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
@@ -5948,43 +5815,33 @@ var PerpetualsClient = (function () {
|
|
|
5948
5815
|
instructions = [];
|
|
5949
5816
|
postInstructions = [];
|
|
5950
5817
|
additionalSigners = [];
|
|
5951
|
-
|
|
5818
|
+
_a.label = 1;
|
|
5952
5819
|
case 1:
|
|
5953
|
-
|
|
5954
|
-
if (
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5820
|
+
_a.trys.push([1, 3, , 4]);
|
|
5821
|
+
if (reserveSymbol == 'SOL') {
|
|
5822
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
5823
|
+
if (!ephemeralSignerPubkey) {
|
|
5824
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
5825
|
+
additionalSigners.push(wrappedSolAccount);
|
|
5826
|
+
}
|
|
5827
|
+
preInstructions = [
|
|
5828
|
+
web3_js_1.SystemProgram.createAccount({
|
|
5829
|
+
fromPubkey: publicKey,
|
|
5830
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
5831
|
+
lamports: lamports,
|
|
5832
|
+
space: 165,
|
|
5833
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5834
|
+
}),
|
|
5835
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
5836
|
+
];
|
|
5837
|
+
postInstructions = [
|
|
5838
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
5839
|
+
];
|
|
5959
5840
|
}
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
5964
|
-
lamports: lamports,
|
|
5965
|
-
space: 165,
|
|
5966
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5967
|
-
}),
|
|
5968
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
5969
|
-
];
|
|
5970
|
-
postInstructions = [
|
|
5971
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
5972
|
-
];
|
|
5973
|
-
return [3, 5];
|
|
5974
|
-
case 2:
|
|
5975
|
-
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);
|
|
5976
|
-
_a = createUserATA;
|
|
5977
|
-
if (!_a) return [3, 4];
|
|
5978
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
5979
|
-
case 3:
|
|
5980
|
-
_a = !(_b.sent());
|
|
5981
|
-
_b.label = 4;
|
|
5982
|
-
case 4:
|
|
5983
|
-
if (_a) {
|
|
5984
|
-
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));
|
|
5841
|
+
else {
|
|
5842
|
+
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);
|
|
5843
|
+
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));
|
|
5985
5844
|
}
|
|
5986
|
-
_b.label = 5;
|
|
5987
|
-
case 5:
|
|
5988
5845
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
5989
5846
|
orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
|
|
5990
5847
|
return [4, this.program.methods
|
|
@@ -6018,15 +5875,15 @@ var PerpetualsClient = (function () {
|
|
|
6018
5875
|
receivingMint: poolConfig.getTokenFromSymbol(reserveSymbol).mintKey
|
|
6019
5876
|
})
|
|
6020
5877
|
.instruction()];
|
|
6021
|
-
case
|
|
6022
|
-
editLimitOrder =
|
|
5878
|
+
case 2:
|
|
5879
|
+
editLimitOrder = _a.sent();
|
|
6023
5880
|
instructions.push(editLimitOrder);
|
|
6024
|
-
return [3,
|
|
6025
|
-
case
|
|
6026
|
-
err_31 =
|
|
5881
|
+
return [3, 4];
|
|
5882
|
+
case 3:
|
|
5883
|
+
err_31 = _a.sent();
|
|
6027
5884
|
console.log("perpClient editLimitOrder error:: ", err_31);
|
|
6028
5885
|
throw err_31;
|
|
6029
|
-
case
|
|
5886
|
+
case 4: return [2, {
|
|
6030
5887
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6031
5888
|
additionalSigners: additionalSigners
|
|
6032
5889
|
}];
|
|
@@ -6175,12 +6032,12 @@ var PerpetualsClient = (function () {
|
|
|
6175
6032
|
});
|
|
6176
6033
|
});
|
|
6177
6034
|
};
|
|
6178
|
-
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6035
|
+
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig, userPublicKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
6179
6036
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_34;
|
|
6180
6037
|
return __generator(this, function (_a) {
|
|
6181
6038
|
switch (_a.label) {
|
|
6182
6039
|
case 0:
|
|
6183
|
-
publicKey = this.provider.wallet.publicKey;
|
|
6040
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
6184
6041
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6185
6042
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6186
6043
|
receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
|
|
@@ -6234,12 +6091,12 @@ var PerpetualsClient = (function () {
|
|
|
6234
6091
|
}
|
|
6235
6092
|
});
|
|
6236
6093
|
}); };
|
|
6237
|
-
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6094
|
+
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig, userPublicKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
6238
6095
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_35;
|
|
6239
6096
|
return __generator(this, function (_a) {
|
|
6240
6097
|
switch (_a.label) {
|
|
6241
6098
|
case 0:
|
|
6242
|
-
publicKey = this.provider.wallet.publicKey;
|
|
6099
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
6243
6100
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6244
6101
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6245
6102
|
receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
|
|
@@ -6292,12 +6149,12 @@ var PerpetualsClient = (function () {
|
|
|
6292
6149
|
}
|
|
6293
6150
|
});
|
|
6294
6151
|
}); };
|
|
6295
|
-
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6152
|
+
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig, userPublicKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
6296
6153
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_36;
|
|
6297
6154
|
return __generator(this, function (_a) {
|
|
6298
6155
|
switch (_a.label) {
|
|
6299
6156
|
case 0:
|
|
6300
|
-
publicKey = this.provider.wallet.publicKey;
|
|
6157
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
6301
6158
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6302
6159
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6303
6160
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -6336,12 +6193,12 @@ var PerpetualsClient = (function () {
|
|
|
6336
6193
|
}
|
|
6337
6194
|
});
|
|
6338
6195
|
}); };
|
|
6339
|
-
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6196
|
+
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig, userPublicKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
6340
6197
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_37;
|
|
6341
6198
|
return __generator(this, function (_a) {
|
|
6342
6199
|
switch (_a.label) {
|
|
6343
6200
|
case 0:
|
|
6344
|
-
publicKey = this.provider.wallet.publicKey;
|
|
6201
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
6345
6202
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6346
6203
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6347
6204
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -6384,13 +6241,13 @@ var PerpetualsClient = (function () {
|
|
|
6384
6241
|
args_1[_i - 9] = arguments[_i];
|
|
6385
6242
|
}
|
|
6386
6243
|
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) {
|
|
6387
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken,
|
|
6244
|
+
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;
|
|
6388
6245
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6389
6246
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6390
6247
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6391
6248
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6392
|
-
return __generator(this, function (
|
|
6393
|
-
switch (
|
|
6249
|
+
return __generator(this, function (_c) {
|
|
6250
|
+
switch (_c.label) {
|
|
6394
6251
|
case 0:
|
|
6395
6252
|
payerPubkey = this.provider.wallet.publicKey;
|
|
6396
6253
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -6403,42 +6260,23 @@ var PerpetualsClient = (function () {
|
|
|
6403
6260
|
additionalSigners = [];
|
|
6404
6261
|
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
|
6405
6262
|
receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
|
|
6406
|
-
|
|
6263
|
+
_c.label = 1;
|
|
6407
6264
|
case 1:
|
|
6408
|
-
|
|
6409
|
-
if (
|
|
6410
|
-
return [3, 7];
|
|
6411
|
-
case 2:
|
|
6412
|
-
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);
|
|
6413
|
-
_a = createUserATA;
|
|
6414
|
-
if (!_a) return [3, 4];
|
|
6415
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
6416
|
-
case 3:
|
|
6417
|
-
_a = !(_e.sent());
|
|
6418
|
-
_e.label = 4;
|
|
6419
|
-
case 4:
|
|
6420
|
-
if (_a) {
|
|
6421
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
|
6265
|
+
_c.trys.push([1, 3, , 4]);
|
|
6266
|
+
if (false) {
|
|
6422
6267
|
}
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
_b = !(_e.sent());
|
|
6429
|
-
_e.label = 6;
|
|
6430
|
-
case 6:
|
|
6431
|
-
if (_b) {
|
|
6432
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
|
6268
|
+
else {
|
|
6269
|
+
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);
|
|
6270
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, spl_token_1.TOKEN_PROGRAM_ID));
|
|
6271
|
+
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);
|
|
6272
|
+
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));
|
|
6433
6273
|
}
|
|
6434
|
-
_e.label = 7;
|
|
6435
|
-
case 7:
|
|
6436
6274
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
|
6437
6275
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
|
6438
6276
|
custodyAccountMetas = [];
|
|
6439
6277
|
custodyOracleAccountMetas = [];
|
|
6440
|
-
for (
|
|
6441
|
-
custody =
|
|
6278
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
|
6279
|
+
custody = _b[_a];
|
|
6442
6280
|
custodyAccountMetas.push({
|
|
6443
6281
|
pubkey: custody.custodyAccount,
|
|
6444
6282
|
isSigner: false,
|
|
@@ -6485,15 +6323,15 @@ var PerpetualsClient = (function () {
|
|
|
6485
6323
|
})
|
|
6486
6324
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6487
6325
|
.instruction()];
|
|
6488
|
-
case
|
|
6489
|
-
executeTriggerWithSwap =
|
|
6326
|
+
case 2:
|
|
6327
|
+
executeTriggerWithSwap = _c.sent();
|
|
6490
6328
|
instructions.push(executeTriggerWithSwap);
|
|
6491
|
-
return [3,
|
|
6492
|
-
case
|
|
6493
|
-
err_38 =
|
|
6329
|
+
return [3, 4];
|
|
6330
|
+
case 3:
|
|
6331
|
+
err_38 = _c.sent();
|
|
6494
6332
|
console.log("perpClient executeTriggerWithSwap error:: ", err_38);
|
|
6495
6333
|
throw err_38;
|
|
6496
|
-
case
|
|
6334
|
+
case 4: return [2, {
|
|
6497
6335
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6498
6336
|
additionalSigners: additionalSigners
|
|
6499
6337
|
}];
|
|
@@ -6507,13 +6345,13 @@ var PerpetualsClient = (function () {
|
|
|
6507
6345
|
args_1[_i - 8] = arguments[_i];
|
|
6508
6346
|
}
|
|
6509
6347
|
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) {
|
|
6510
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
|
6348
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeTriggerOrder, err_39;
|
|
6511
6349
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6512
6350
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6513
6351
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6514
6352
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6515
|
-
return __generator(this, function (
|
|
6516
|
-
switch (
|
|
6353
|
+
return __generator(this, function (_a) {
|
|
6354
|
+
switch (_a.label) {
|
|
6517
6355
|
case 0:
|
|
6518
6356
|
payerPubkey = this.provider.wallet.publicKey;
|
|
6519
6357
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -6523,25 +6361,15 @@ var PerpetualsClient = (function () {
|
|
|
6523
6361
|
instructions = [];
|
|
6524
6362
|
postInstructions = [];
|
|
6525
6363
|
additionalSigners = [];
|
|
6526
|
-
|
|
6364
|
+
_a.label = 1;
|
|
6527
6365
|
case 1:
|
|
6528
|
-
|
|
6529
|
-
if (
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
if (!_a) return [3, 4];
|
|
6535
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
6536
|
-
case 3:
|
|
6537
|
-
_a = !(_b.sent());
|
|
6538
|
-
_b.label = 4;
|
|
6539
|
-
case 4:
|
|
6540
|
-
if (_a) {
|
|
6541
|
-
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));
|
|
6366
|
+
_a.trys.push([1, 3, , 4]);
|
|
6367
|
+
if (false) {
|
|
6368
|
+
}
|
|
6369
|
+
else {
|
|
6370
|
+
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);
|
|
6371
|
+
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));
|
|
6542
6372
|
}
|
|
6543
|
-
_b.label = 5;
|
|
6544
|
-
case 5:
|
|
6545
6373
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
|
6546
6374
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
|
6547
6375
|
return [4, this.program.methods
|
|
@@ -6573,15 +6401,15 @@ var PerpetualsClient = (function () {
|
|
|
6573
6401
|
})
|
|
6574
6402
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6575
6403
|
.instruction()];
|
|
6576
|
-
case
|
|
6577
|
-
executeTriggerOrder =
|
|
6404
|
+
case 2:
|
|
6405
|
+
executeTriggerOrder = _a.sent();
|
|
6578
6406
|
instructions.push(executeTriggerOrder);
|
|
6579
|
-
return [3,
|
|
6580
|
-
case
|
|
6581
|
-
err_39 =
|
|
6407
|
+
return [3, 4];
|
|
6408
|
+
case 3:
|
|
6409
|
+
err_39 = _a.sent();
|
|
6582
6410
|
console.log("perpClient executeTriggerOrder error:: ", err_39);
|
|
6583
6411
|
throw err_39;
|
|
6584
|
-
case
|
|
6412
|
+
case 4: return [2, {
|
|
6585
6413
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6586
6414
|
additionalSigners: additionalSigners
|
|
6587
6415
|
}];
|
|
@@ -6594,16 +6422,16 @@ var PerpetualsClient = (function () {
|
|
|
6594
6422
|
for (var _i = 5; _i < arguments.length; _i++) {
|
|
6595
6423
|
args_1[_i - 5] = arguments[_i];
|
|
6596
6424
|
}
|
|
6597
|
-
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) {
|
|
6598
|
-
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount,
|
|
6425
|
+
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) {
|
|
6426
|
+
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;
|
|
6599
6427
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
|
6600
6428
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6601
6429
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
|
6602
6430
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
6603
6431
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6604
6432
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
6605
|
-
return __generator(this, function (
|
|
6606
|
-
switch (
|
|
6433
|
+
return __generator(this, function (_f) {
|
|
6434
|
+
switch (_f.label) {
|
|
6607
6435
|
case 0:
|
|
6608
6436
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
|
6609
6437
|
if (!userInputCustodyConfig) {
|
|
@@ -6613,31 +6441,26 @@ var PerpetualsClient = (function () {
|
|
|
6613
6441
|
if (!userOutputCustodyConfig) {
|
|
6614
6442
|
throw "userOutputCustodyConfig not found";
|
|
6615
6443
|
}
|
|
6616
|
-
publicKey = this.provider.wallet.publicKey;
|
|
6444
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
6617
6445
|
preInstructions = [];
|
|
6618
6446
|
instructions = [];
|
|
6619
6447
|
postInstructions = [];
|
|
6620
6448
|
additionalSigners = [];
|
|
6621
|
-
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3,
|
|
6449
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 4];
|
|
6622
6450
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
|
6623
6451
|
case 1:
|
|
6624
|
-
wsolAssociatedTokenAccount =
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
wsolATAExist = _g.sent();
|
|
6628
|
-
if (!wsolATAExist) {
|
|
6629
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
|
6630
|
-
}
|
|
6631
|
-
if (!!skipBalanceChecks) return [3, 4];
|
|
6452
|
+
wsolAssociatedTokenAccount = _f.sent();
|
|
6453
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID));
|
|
6454
|
+
if (!!skipBalanceChecks) return [3, 3];
|
|
6632
6455
|
_a = anchor_1.BN.bind;
|
|
6633
6456
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
6634
|
-
case
|
|
6635
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
|
6457
|
+
case 2:
|
|
6458
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
6636
6459
|
if (unWrappedSolBalance.lt(amountIn)) {
|
|
6637
6460
|
throw "Insufficient SOL Funds";
|
|
6638
6461
|
}
|
|
6639
|
-
|
|
6640
|
-
case
|
|
6462
|
+
_f.label = 3;
|
|
6463
|
+
case 3:
|
|
6641
6464
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
|
6642
6465
|
fromPubkey: publicKey,
|
|
6643
6466
|
toPubkey: wsolAssociatedTokenAccount,
|
|
@@ -6647,7 +6470,7 @@ var PerpetualsClient = (function () {
|
|
|
6647
6470
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6648
6471
|
additionalSigners: additionalSigners
|
|
6649
6472
|
}];
|
|
6650
|
-
case
|
|
6473
|
+
case 4:
|
|
6651
6474
|
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
|
6652
6475
|
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
|
6653
6476
|
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
|
@@ -6658,20 +6481,20 @@ var PerpetualsClient = (function () {
|
|
|
6658
6481
|
additionalSigners: additionalSigners
|
|
6659
6482
|
}];
|
|
6660
6483
|
}
|
|
6661
|
-
|
|
6662
|
-
case
|
|
6663
|
-
|
|
6664
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
|
6484
|
+
_f.label = 5;
|
|
6485
|
+
case 5:
|
|
6486
|
+
_f.trys.push([5, 16, , 17]);
|
|
6487
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 8];
|
|
6665
6488
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
|
6666
6489
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
|
6667
|
-
case
|
|
6668
|
-
accCreationLamports = (
|
|
6490
|
+
case 6:
|
|
6491
|
+
accCreationLamports = (_f.sent());
|
|
6669
6492
|
console.log("accCreationLamports:", accCreationLamports);
|
|
6670
6493
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
|
6671
6494
|
_b = anchor_1.BN.bind;
|
|
6672
6495
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
6673
|
-
case
|
|
6674
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
|
6496
|
+
case 7:
|
|
6497
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
6675
6498
|
if (unWrappedSolBalance.lt(amountIn)) {
|
|
6676
6499
|
throw "Insufficient SOL Funds";
|
|
6677
6500
|
}
|
|
@@ -6693,25 +6516,25 @@ var PerpetualsClient = (function () {
|
|
|
6693
6516
|
postInstructions = [
|
|
6694
6517
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
6695
6518
|
];
|
|
6696
|
-
return [3,
|
|
6697
|
-
case
|
|
6519
|
+
return [3, 11];
|
|
6520
|
+
case 8:
|
|
6698
6521
|
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);
|
|
6699
6522
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
6700
|
-
case
|
|
6701
|
-
if (!(
|
|
6523
|
+
case 9:
|
|
6524
|
+
if (!(_f.sent())) {
|
|
6702
6525
|
throw "Insufficient Funds , Token Account doesn't exist";
|
|
6703
6526
|
}
|
|
6704
|
-
if (!!skipBalanceChecks) return [3,
|
|
6527
|
+
if (!!skipBalanceChecks) return [3, 11];
|
|
6705
6528
|
_c = anchor_1.BN.bind;
|
|
6706
6529
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
6707
|
-
case
|
|
6708
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
|
6530
|
+
case 10:
|
|
6531
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
|
6709
6532
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
6710
6533
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
6711
6534
|
}
|
|
6712
|
-
|
|
6713
|
-
case
|
|
6714
|
-
if (!(userOutputTokenSymbol == 'SOL')) return [3,
|
|
6535
|
+
_f.label = 11;
|
|
6536
|
+
case 11:
|
|
6537
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 12];
|
|
6715
6538
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
6716
6539
|
if (!ephemeralSignerPubkey) {
|
|
6717
6540
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
@@ -6731,26 +6554,17 @@ var PerpetualsClient = (function () {
|
|
|
6731
6554
|
postInstructions = [
|
|
6732
6555
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
6733
6556
|
];
|
|
6734
|
-
return [3,
|
|
6735
|
-
case
|
|
6557
|
+
return [3, 14];
|
|
6558
|
+
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)];
|
|
6559
|
+
case 13:
|
|
6560
|
+
userOutputTokenAccount = _f.sent();
|
|
6561
|
+
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));
|
|
6562
|
+
_f.label = 14;
|
|
6736
6563
|
case 14:
|
|
6737
|
-
userOutputTokenAccount = _g.sent();
|
|
6738
|
-
_d = createUserATA;
|
|
6739
|
-
if (!_d) return [3, 16];
|
|
6740
|
-
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
|
6741
|
-
case 15:
|
|
6742
|
-
_d = !(_g.sent());
|
|
6743
|
-
_g.label = 16;
|
|
6744
|
-
case 16:
|
|
6745
|
-
if (_d) {
|
|
6746
|
-
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));
|
|
6747
|
-
}
|
|
6748
|
-
_g.label = 17;
|
|
6749
|
-
case 17:
|
|
6750
6564
|
custodyAccountMetas = [];
|
|
6751
6565
|
custodyOracleAccountMetas = [];
|
|
6752
|
-
for (
|
|
6753
|
-
custody =
|
|
6566
|
+
for (_d = 0, _e = poolConfig.custodies; _d < _e.length; _d++) {
|
|
6567
|
+
custody = _e[_d];
|
|
6754
6568
|
custodyAccountMetas.push({
|
|
6755
6569
|
pubkey: custody.custodyAccount,
|
|
6756
6570
|
isSigner: false,
|
|
@@ -6798,19 +6612,19 @@ var PerpetualsClient = (function () {
|
|
|
6798
6612
|
})
|
|
6799
6613
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
6800
6614
|
.instruction()];
|
|
6801
|
-
case
|
|
6802
|
-
inx =
|
|
6615
|
+
case 15:
|
|
6616
|
+
inx = _f.sent();
|
|
6803
6617
|
instructions.push(inx);
|
|
6804
6618
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
|
6805
6619
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
|
6806
6620
|
instructions.push(closeWsolATAIns);
|
|
6807
6621
|
}
|
|
6808
|
-
return [3,
|
|
6809
|
-
case
|
|
6810
|
-
err_40 =
|
|
6622
|
+
return [3, 17];
|
|
6623
|
+
case 16:
|
|
6624
|
+
err_40 = _f.sent();
|
|
6811
6625
|
console.error("perpClient Swap error:: ", err_40);
|
|
6812
6626
|
throw err_40;
|
|
6813
|
-
case
|
|
6627
|
+
case 17: return [2, {
|
|
6814
6628
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6815
6629
|
additionalSigners: additionalSigners
|
|
6816
6630
|
}];
|
|
@@ -7852,15 +7666,11 @@ var PerpetualsClient = (function () {
|
|
|
7852
7666
|
additionalSigners = [];
|
|
7853
7667
|
_a.label = 1;
|
|
7854
7668
|
case 1:
|
|
7855
|
-
_a.trys.push([1,
|
|
7669
|
+
_a.trys.push([1, 4, , 5]);
|
|
7856
7670
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7857
7671
|
case 2:
|
|
7858
7672
|
receivingTokenAccount = _a.sent();
|
|
7859
|
-
|
|
7860
|
-
case 3:
|
|
7861
|
-
if (!(_a.sent())) {
|
|
7862
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7863
|
-
}
|
|
7673
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
7864
7674
|
return [4, this.program.methods
|
|
7865
7675
|
.withdrawInstantFees({})
|
|
7866
7676
|
.accounts({
|
|
@@ -7875,15 +7685,15 @@ var PerpetualsClient = (function () {
|
|
|
7875
7685
|
receivingTokenMint: poolConfig.tokenMint,
|
|
7876
7686
|
})
|
|
7877
7687
|
.instruction()];
|
|
7878
|
-
case
|
|
7688
|
+
case 3:
|
|
7879
7689
|
withdrawInstantFeeInstruction = _a.sent();
|
|
7880
7690
|
instructions.push(withdrawInstantFeeInstruction);
|
|
7881
|
-
return [3,
|
|
7882
|
-
case
|
|
7691
|
+
return [3, 5];
|
|
7692
|
+
case 4:
|
|
7883
7693
|
err_57 = _a.sent();
|
|
7884
7694
|
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
|
|
7885
7695
|
throw err_57;
|
|
7886
|
-
case
|
|
7696
|
+
case 5: return [2, {
|
|
7887
7697
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7888
7698
|
additionalSigners: additionalSigners
|
|
7889
7699
|
}];
|
|
@@ -7902,15 +7712,11 @@ var PerpetualsClient = (function () {
|
|
|
7902
7712
|
additionalSigners = [];
|
|
7903
7713
|
_a.label = 1;
|
|
7904
7714
|
case 1:
|
|
7905
|
-
_a.trys.push([1,
|
|
7715
|
+
_a.trys.push([1, 4, , 5]);
|
|
7906
7716
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7907
7717
|
case 2:
|
|
7908
7718
|
receivingTokenAccount = _a.sent();
|
|
7909
|
-
|
|
7910
|
-
case 3:
|
|
7911
|
-
if (!(_a.sent())) {
|
|
7912
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7913
|
-
}
|
|
7719
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint, spl_token_1.TOKEN_PROGRAM_ID));
|
|
7914
7720
|
return [4, this.program.methods
|
|
7915
7721
|
.withdrawUnclaimedTokens({})
|
|
7916
7722
|
.accounts({
|
|
@@ -7925,15 +7731,15 @@ var PerpetualsClient = (function () {
|
|
|
7925
7731
|
receivingTokenMint: poolConfig.tokenMint,
|
|
7926
7732
|
})
|
|
7927
7733
|
.instruction()];
|
|
7928
|
-
case
|
|
7734
|
+
case 3:
|
|
7929
7735
|
withdrawUnclaimedTokensInstruction = _a.sent();
|
|
7930
7736
|
instructions.push(withdrawUnclaimedTokensInstruction);
|
|
7931
|
-
return [3,
|
|
7932
|
-
case
|
|
7737
|
+
return [3, 5];
|
|
7738
|
+
case 4:
|
|
7933
7739
|
err_58 = _a.sent();
|
|
7934
7740
|
console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
|
|
7935
7741
|
throw err_58;
|
|
7936
|
-
case
|
|
7742
|
+
case 5: return [2, {
|
|
7937
7743
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7938
7744
|
additionalSigners: additionalSigners
|
|
7939
7745
|
}];
|