flash-sdk 2.52.1 → 2.52.3
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 +8 -8
- package/dist/PerpetualsClient.js +691 -691
- package/dist/PoolConfig.json +16 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -2995,96 +2995,48 @@ var PerpetualsClient = (function () {
|
|
2995
2995
|
});
|
2996
2996
|
});
|
2997
2997
|
};
|
2998
|
-
this.
|
2998
|
+
this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
2999
2999
|
var args_1 = [];
|
3000
|
-
for (var _i =
|
3001
|
-
args_1[_i -
|
3000
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3001
|
+
args_1[_i - 6] = arguments[_i];
|
3002
3002
|
}
|
3003
|
-
return __awaiter(_this, __spreadArray([
|
3004
|
-
var
|
3005
|
-
if (useFeesPool === void 0) { useFeesPool = false; }
|
3006
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
3007
|
-
if (unWrapSol === void 0) { unWrapSol = false; }
|
3003
|
+
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) {
|
3004
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3008
3005
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3009
3006
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3010
|
-
return __generator(this, function (
|
3011
|
-
switch (
|
3007
|
+
return __generator(this, function (_c) {
|
3008
|
+
switch (_c.label) {
|
3012
3009
|
case 0:
|
3013
|
-
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
3014
|
-
if (!userInputCustodyConfig) {
|
3015
|
-
throw "userInputCustodyConfig not found";
|
3016
|
-
}
|
3017
|
-
userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
|
3018
|
-
if (!userOutputCustodyConfig) {
|
3019
|
-
throw "userOutputCustodyConfig not found";
|
3020
|
-
}
|
3021
3010
|
publicKey = this.provider.wallet.publicKey;
|
3011
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3012
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3013
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3014
|
+
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3015
|
+
throw "payTokenCustody not found";
|
3016
|
+
}
|
3017
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3022
3018
|
preInstructions = [];
|
3023
3019
|
instructions = [];
|
3024
3020
|
postInstructions = [];
|
3025
3021
|
additionalSigners = [];
|
3026
|
-
if (!(
|
3027
|
-
|
3028
|
-
|
3029
|
-
|
3030
|
-
return [
|
3031
|
-
case 2:
|
3032
|
-
wsolATAExist = _g.sent();
|
3033
|
-
if (!wsolATAExist) {
|
3034
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3035
|
-
}
|
3036
|
-
if (!!skipBalanceChecks) return [3, 4];
|
3022
|
+
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
3023
|
+
console.log("collateralSymbol === SOL", collateralSymbol);
|
3024
|
+
lamports = collateralWithFee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3025
|
+
console.log("lamports:", lamports.toNumber());
|
3026
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3037
3027
|
_a = anchor_1.BN.bind;
|
3038
3028
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3039
|
-
case
|
3040
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3041
|
-
if (unWrappedSolBalance.lt(
|
3042
|
-
throw "Insufficient SOL Funds";
|
3043
|
-
}
|
3044
|
-
_g.label = 4;
|
3045
|
-
case 4:
|
3046
|
-
instructions.push(web3_js_1.SystemProgram.transfer({
|
3047
|
-
fromPubkey: publicKey,
|
3048
|
-
toPubkey: wsolAssociatedTokenAccount,
|
3049
|
-
lamports: amountIn.toNumber(),
|
3050
|
-
}), (0, spl_token_1.createSyncNativeInstruction)(wsolAssociatedTokenAccount));
|
3051
|
-
return [2, {
|
3052
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3053
|
-
additionalSigners: additionalSigners
|
3054
|
-
}];
|
3055
|
-
case 5:
|
3056
|
-
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
3057
|
-
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
3058
|
-
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
3059
|
-
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
|
3060
|
-
instructions.push(closeWsolATAIns);
|
3061
|
-
return [2, {
|
3062
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3063
|
-
additionalSigners: additionalSigners
|
3064
|
-
}];
|
3065
|
-
}
|
3066
|
-
_g.label = 6;
|
3067
|
-
case 6:
|
3068
|
-
_g.trys.push([6, 19, , 20]);
|
3069
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3070
|
-
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3071
|
-
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3072
|
-
case 7:
|
3073
|
-
accCreationLamports = (_g.sent());
|
3074
|
-
console.log("accCreationLamports:", accCreationLamports);
|
3075
|
-
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3076
|
-
_b = anchor_1.BN.bind;
|
3077
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
3078
|
-
case 8:
|
3079
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3080
|
-
if (unWrappedSolBalance.lt(amountIn)) {
|
3029
|
+
case 1:
|
3030
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3031
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
3081
3032
|
throw "Insufficient SOL Funds";
|
3082
3033
|
}
|
3034
|
+
_c.label = 2;
|
3035
|
+
case 2:
|
3083
3036
|
if (!ephemeralSignerPubkey) {
|
3084
3037
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3085
3038
|
additionalSigners.push(wrappedSolAccount);
|
3086
3039
|
}
|
3087
|
-
;
|
3088
3040
|
preInstructions = [
|
3089
3041
|
web3_js_1.SystemProgram.createAccount({
|
3090
3042
|
fromPubkey: publicKey,
|
@@ -3098,36 +3050,102 @@ var PerpetualsClient = (function () {
|
|
3098
3050
|
postInstructions = [
|
3099
3051
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3100
3052
|
];
|
3101
|
-
return [3,
|
3102
|
-
case
|
3103
|
-
|
3104
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
3105
|
-
case
|
3106
|
-
if (!(
|
3107
|
-
throw "Insufficient Funds ,
|
3053
|
+
return [3, 6];
|
3054
|
+
case 3:
|
3055
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3056
|
+
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3057
|
+
case 4:
|
3058
|
+
if (!(_c.sent())) {
|
3059
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
3108
3060
|
}
|
3109
|
-
|
3110
|
-
|
3111
|
-
|
3112
|
-
|
3113
|
-
|
3114
|
-
|
3115
|
-
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3061
|
+
_b = anchor_1.BN.bind;
|
3062
|
+
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3063
|
+
case 5:
|
3064
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3065
|
+
if (tokenAccountBalance.lt(collateralWithFee)) {
|
3066
|
+
throw "Insufficient Funds need more ".concat(collateralWithFee.sub(tokenAccountBalance), " tokens");
|
3116
3067
|
}
|
3117
|
-
|
3118
|
-
case
|
3119
|
-
|
3120
|
-
|
3068
|
+
_c.label = 6;
|
3069
|
+
case 6: return [4, this.program.methods.addCollateral({
|
3070
|
+
collateralDelta: collateralWithFee
|
3071
|
+
}).accounts({
|
3072
|
+
owner: publicKey,
|
3073
|
+
position: positionPubKey,
|
3074
|
+
market: marketAccount,
|
3075
|
+
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
3076
|
+
perpetuals: poolConfig.perpetuals,
|
3077
|
+
pool: poolConfig.poolAddress,
|
3078
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3079
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3080
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3081
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3082
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3083
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3084
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3085
|
+
program: this.programId,
|
3086
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3087
|
+
})
|
3088
|
+
.instruction()];
|
3089
|
+
case 7:
|
3090
|
+
instruction = _c.sent();
|
3091
|
+
instructions.push(instruction);
|
3092
|
+
return [2, {
|
3093
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3094
|
+
additionalSigners: additionalSigners
|
3095
|
+
}];
|
3096
|
+
}
|
3097
|
+
});
|
3098
|
+
});
|
3099
|
+
};
|
3100
|
+
this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
|
3101
|
+
var args_1 = [];
|
3102
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3103
|
+
args_1[_i - 8] = arguments[_i];
|
3104
|
+
}
|
3105
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3106
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3107
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3108
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3109
|
+
return __generator(this, function (_c) {
|
3110
|
+
switch (_c.label) {
|
3111
|
+
case 0:
|
3112
|
+
publicKey = this.provider.wallet.publicKey;
|
3113
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3114
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3115
|
+
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3116
|
+
if (!collateralCustodyConfig || !targetCustodyConfig || !inputCustodyConfig) {
|
3117
|
+
throw "payTokenCustody not found";
|
3118
|
+
}
|
3119
|
+
if (inputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
3120
|
+
throw "Use Simple Swap";
|
3121
|
+
}
|
3122
|
+
preInstructions = [];
|
3123
|
+
instructions = [];
|
3124
|
+
postInstructions = [];
|
3125
|
+
additionalSigners = [];
|
3126
|
+
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3127
|
+
console.log("inputSymbol === SOL", inputSymbol);
|
3128
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3129
|
+
console.log("lamports:", lamports.toNumber());
|
3130
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3131
|
+
_a = anchor_1.BN.bind;
|
3132
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
3133
|
+
case 1:
|
3134
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3135
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
3136
|
+
throw "Insufficient SOL Funds";
|
3137
|
+
}
|
3138
|
+
_c.label = 2;
|
3139
|
+
case 2:
|
3121
3140
|
if (!ephemeralSignerPubkey) {
|
3122
3141
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3123
3142
|
additionalSigners.push(wrappedSolAccount);
|
3124
3143
|
}
|
3125
|
-
;
|
3126
3144
|
preInstructions = [
|
3127
3145
|
web3_js_1.SystemProgram.createAccount({
|
3128
3146
|
fromPubkey: publicKey,
|
3129
3147
|
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3130
|
-
lamports: lamports,
|
3148
|
+
lamports: lamports.toNumber(),
|
3131
3149
|
space: 165,
|
3132
3150
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3133
3151
|
}),
|
@@ -3136,193 +3154,102 @@ var PerpetualsClient = (function () {
|
|
3136
3154
|
postInstructions = [
|
3137
3155
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3138
3156
|
];
|
3139
|
-
return [3,
|
3140
|
-
case
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
_d = !(_g.sent());
|
3148
|
-
_g.label = 16;
|
3149
|
-
case 16:
|
3150
|
-
if (_d) {
|
3151
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3157
|
+
return [3, 6];
|
3158
|
+
case 3:
|
3159
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3160
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3161
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3162
|
+
case 4:
|
3163
|
+
if (!(_c.sent())) {
|
3164
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
3152
3165
|
}
|
3153
|
-
|
3154
|
-
|
3155
|
-
|
3156
|
-
|
3157
|
-
|
3158
|
-
|
3159
|
-
custodyAccountMetas.push({
|
3160
|
-
pubkey: custody.custodyAccount,
|
3161
|
-
isSigner: false,
|
3162
|
-
isWritable: false,
|
3163
|
-
});
|
3164
|
-
custodyOracleAccountMetas.push({
|
3165
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
3166
|
-
isSigner: false,
|
3167
|
-
isWritable: false,
|
3168
|
-
});
|
3166
|
+
_b = anchor_1.BN.bind;
|
3167
|
+
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3168
|
+
case 5:
|
3169
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3170
|
+
if (tokenAccountBalance.lt(amountIn)) {
|
3171
|
+
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3169
3172
|
}
|
3170
|
-
|
3171
|
-
|
3172
|
-
|
3173
|
-
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3173
|
+
_c.label = 6;
|
3174
|
+
case 6:
|
3175
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3176
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3177
|
+
case 7:
|
3178
|
+
if (!(_c.sent())) {
|
3179
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3180
|
+
}
|
3181
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3182
|
+
return [4, this.program.methods.swapAndAddCollateral({
|
3183
|
+
amountIn: amountIn,
|
3184
|
+
minCollateralAmountOut: minCollateralAmountOut,
|
3185
|
+
}).accounts({
|
3186
|
+
owner: publicKey,
|
3187
|
+
feePayer: publicKey,
|
3188
|
+
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3189
|
+
transferAuthority: poolConfig.transferAuthority,
|
3182
3190
|
perpetuals: poolConfig.perpetuals,
|
3183
3191
|
pool: poolConfig.poolAddress,
|
3184
|
-
receivingCustody:
|
3185
|
-
receivingCustodyOracleAccount: this.useExtOracleAccount ?
|
3186
|
-
receivingCustodyTokenAccount:
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3192
|
+
receivingCustody: inputCustodyConfig.custodyAccount,
|
3193
|
+
receivingCustodyOracleAccount: this.useExtOracleAccount ? inputCustodyConfig.extOracleAccount : inputCustodyConfig.intOracleAccount,
|
3194
|
+
receivingCustodyTokenAccount: inputCustodyConfig.tokenAccount,
|
3195
|
+
position: positionPubKey,
|
3196
|
+
market: marketAccount,
|
3197
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3198
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3199
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3200
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3201
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3190
3202
|
eventAuthority: this.eventAuthority.publicKey,
|
3191
3203
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3192
3204
|
program: this.programId,
|
3193
3205
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3194
3206
|
})
|
3195
|
-
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3196
3207
|
.instruction()];
|
3197
|
-
case
|
3198
|
-
|
3199
|
-
instructions.push(
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
return [3, 20];
|
3205
|
-
case 19:
|
3206
|
-
err_5 = _g.sent();
|
3207
|
-
console.error("perpClient Swap error:: ", err_5);
|
3208
|
-
throw err_5;
|
3209
|
-
case 20: return [2, {
|
3210
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3211
|
-
additionalSigners: additionalSigners
|
3212
|
-
}];
|
3208
|
+
case 8:
|
3209
|
+
instruction = _c.sent();
|
3210
|
+
instructions.push(instruction);
|
3211
|
+
return [2, {
|
3212
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3213
|
+
additionalSigners: additionalSigners
|
3214
|
+
}];
|
3213
3215
|
}
|
3214
3216
|
});
|
3215
3217
|
});
|
3216
3218
|
};
|
3217
|
-
this.
|
3218
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_6;
|
3219
|
-
return __generator(this, function (_b) {
|
3220
|
-
switch (_b.label) {
|
3221
|
-
case 0:
|
3222
|
-
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
3223
|
-
if (!rewardCustody) {
|
3224
|
-
throw "rewardCustody not found";
|
3225
|
-
}
|
3226
|
-
custody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(swapTokenSymbol).mintKey); });
|
3227
|
-
if (!custody) {
|
3228
|
-
throw "custody not found";
|
3229
|
-
}
|
3230
|
-
publicKey = this.provider.wallet.publicKey;
|
3231
|
-
preInstructions = [];
|
3232
|
-
instructions = [];
|
3233
|
-
postInstructions = [];
|
3234
|
-
additionalSigners = [];
|
3235
|
-
_b.label = 1;
|
3236
|
-
case 1:
|
3237
|
-
_b.trys.push([1, 3, , 4]);
|
3238
|
-
custodyAccountMetas = [];
|
3239
|
-
custodyOracleAccountMetas = [];
|
3240
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
3241
|
-
custody_1 = _a[_i];
|
3242
|
-
custodyAccountMetas.push({
|
3243
|
-
pubkey: custody_1.custodyAccount,
|
3244
|
-
isSigner: false,
|
3245
|
-
isWritable: false,
|
3246
|
-
});
|
3247
|
-
custodyOracleAccountMetas.push({
|
3248
|
-
pubkey: this.useExtOracleAccount ? custody_1.extOracleAccount : custody_1.intOracleAccount,
|
3249
|
-
isSigner: false,
|
3250
|
-
isWritable: false,
|
3251
|
-
});
|
3252
|
-
}
|
3253
|
-
params = {};
|
3254
|
-
return [4, this.program.methods
|
3255
|
-
.swapFeeInternal(params)
|
3256
|
-
.accounts({
|
3257
|
-
owner: publicKey,
|
3258
|
-
perpetuals: poolConfig.perpetuals,
|
3259
|
-
pool: poolConfig.poolAddress,
|
3260
|
-
rewardCustody: rewardCustody.custodyAccount,
|
3261
|
-
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
3262
|
-
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
3263
|
-
custody: custody.custodyAccount,
|
3264
|
-
custodyOracleAccount: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
3265
|
-
custodyTokenAccount: custody.tokenAccount,
|
3266
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3267
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3268
|
-
program: this.programId,
|
3269
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3270
|
-
})
|
3271
|
-
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3272
|
-
.instruction()];
|
3273
|
-
case 2:
|
3274
|
-
inx = _b.sent();
|
3275
|
-
instructions.push(inx);
|
3276
|
-
return [3, 4];
|
3277
|
-
case 3:
|
3278
|
-
err_6 = _b.sent();
|
3279
|
-
console.error("perpClient Swap error:: ", err_6);
|
3280
|
-
throw err_6;
|
3281
|
-
case 4: return [2, {
|
3282
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3283
|
-
additionalSigners: additionalSigners
|
3284
|
-
}];
|
3285
|
-
}
|
3286
|
-
});
|
3287
|
-
}); };
|
3288
|
-
this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3219
|
+
this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3289
3220
|
var args_1 = [];
|
3290
3221
|
for (var _i = 6; _i < arguments.length; _i++) {
|
3291
3222
|
args_1[_i - 6] = arguments[_i];
|
3292
3223
|
}
|
3293
|
-
return __awaiter(_this, __spreadArray([collateralWithFee_1,
|
3294
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig,
|
3295
|
-
if (
|
3224
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3225
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
|
3226
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3227
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3296
3228
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3297
|
-
return __generator(this, function (
|
3298
|
-
switch (
|
3229
|
+
return __generator(this, function (_b) {
|
3230
|
+
switch (_b.label) {
|
3299
3231
|
case 0:
|
3300
3232
|
publicKey = this.provider.wallet.publicKey;
|
3301
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
3302
|
-
|
3303
|
-
|
3233
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
3234
|
+
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
3235
|
+
});
|
3236
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) {
|
3237
|
+
return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey);
|
3238
|
+
});
|
3304
3239
|
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3305
|
-
throw "
|
3240
|
+
throw "collateralCustodyConfig/marketCustodyConfig not found";
|
3306
3241
|
}
|
3307
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3308
3242
|
preInstructions = [];
|
3309
3243
|
instructions = [];
|
3310
3244
|
postInstructions = [];
|
3311
3245
|
additionalSigners = [];
|
3312
|
-
|
3313
|
-
console.log("collateralSymbol === SOL", collateralSymbol);
|
3314
|
-
lamports = collateralWithFee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3315
|
-
console.log("lamports:", lamports.toNumber());
|
3316
|
-
if (!!skipBalanceChecks) return [3, 2];
|
3317
|
-
_a = anchor_1.BN.bind;
|
3318
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
3246
|
+
_b.label = 1;
|
3319
3247
|
case 1:
|
3320
|
-
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
|
3325
|
-
case 2:
|
3248
|
+
_b.trys.push([1, 7, , 8]);
|
3249
|
+
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
3250
|
+
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
3251
|
+
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
3252
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
3326
3253
|
if (!ephemeralSignerPubkey) {
|
3327
3254
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3328
3255
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3331,7 +3258,7 @@ var PerpetualsClient = (function () {
|
|
3331
3258
|
web3_js_1.SystemProgram.createAccount({
|
3332
3259
|
fromPubkey: publicKey,
|
3333
3260
|
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3334
|
-
lamports: lamports
|
3261
|
+
lamports: lamports,
|
3335
3262
|
space: 165,
|
3336
3263
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3337
3264
|
}),
|
@@ -3340,278 +3267,61 @@ var PerpetualsClient = (function () {
|
|
3340
3267
|
postInstructions = [
|
3341
3268
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3342
3269
|
];
|
3343
|
-
return [3,
|
3270
|
+
return [3, 5];
|
3271
|
+
case 2:
|
3272
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3273
|
+
_a = createUserATA;
|
3274
|
+
if (!_a) return [3, 4];
|
3275
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3344
3276
|
case 3:
|
3345
|
-
|
3346
|
-
|
3277
|
+
_a = !(_b.sent());
|
3278
|
+
_b.label = 4;
|
3347
3279
|
case 4:
|
3348
|
-
if (
|
3349
|
-
|
3280
|
+
if (_a) {
|
3281
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3350
3282
|
}
|
3351
|
-
_b =
|
3352
|
-
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3283
|
+
_b.label = 5;
|
3353
3284
|
case 5:
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3285
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3286
|
+
return [4, this.program.methods
|
3287
|
+
.removeCollateral({
|
3288
|
+
collateralDelta: collateralWithFee,
|
3289
|
+
})
|
3290
|
+
.accounts({
|
3291
|
+
owner: publicKey,
|
3292
|
+
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
3293
|
+
transferAuthority: poolConfig.transferAuthority,
|
3294
|
+
perpetuals: poolConfig.perpetuals,
|
3295
|
+
pool: poolConfig.poolAddress,
|
3296
|
+
position: positionPubKey,
|
3297
|
+
market: marketAccount,
|
3298
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3299
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3300
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3301
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3302
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3303
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3304
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3305
|
+
program: this.programId,
|
3306
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3307
|
+
})
|
3308
|
+
.instruction()];
|
3309
|
+
case 6:
|
3310
|
+
instruction = _b.sent();
|
3311
|
+
instructions.push(instruction);
|
3312
|
+
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
3313
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
3314
|
+
postInstructions.push(closeWsolATAIns);
|
3357
3315
|
}
|
3358
|
-
|
3359
|
-
case 6: return [4, this.program.methods.addCollateral({
|
3360
|
-
collateralDelta: collateralWithFee
|
3361
|
-
}).accounts({
|
3362
|
-
owner: publicKey,
|
3363
|
-
position: positionPubKey,
|
3364
|
-
market: marketAccount,
|
3365
|
-
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
3366
|
-
perpetuals: poolConfig.perpetuals,
|
3367
|
-
pool: poolConfig.poolAddress,
|
3368
|
-
targetCustody: targetCustodyConfig.custodyAccount,
|
3369
|
-
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3370
|
-
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3371
|
-
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3372
|
-
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3373
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3374
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3375
|
-
program: this.programId,
|
3376
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3377
|
-
})
|
3378
|
-
.instruction()];
|
3316
|
+
return [3, 8];
|
3379
3317
|
case 7:
|
3380
|
-
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3384
|
-
|
3385
|
-
|
3386
|
-
|
3387
|
-
});
|
3388
|
-
});
|
3389
|
-
};
|
3390
|
-
this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
|
3391
|
-
var args_1 = [];
|
3392
|
-
for (var _i = 8; _i < arguments.length; _i++) {
|
3393
|
-
args_1[_i - 8] = arguments[_i];
|
3394
|
-
}
|
3395
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3396
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3397
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3398
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3399
|
-
return __generator(this, function (_c) {
|
3400
|
-
switch (_c.label) {
|
3401
|
-
case 0:
|
3402
|
-
publicKey = this.provider.wallet.publicKey;
|
3403
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3404
|
-
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3405
|
-
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3406
|
-
if (!collateralCustodyConfig || !targetCustodyConfig || !inputCustodyConfig) {
|
3407
|
-
throw "payTokenCustody not found";
|
3408
|
-
}
|
3409
|
-
if (inputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
3410
|
-
throw "Use Simple Swap";
|
3411
|
-
}
|
3412
|
-
preInstructions = [];
|
3413
|
-
instructions = [];
|
3414
|
-
postInstructions = [];
|
3415
|
-
additionalSigners = [];
|
3416
|
-
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3417
|
-
console.log("inputSymbol === SOL", inputSymbol);
|
3418
|
-
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3419
|
-
console.log("lamports:", lamports.toNumber());
|
3420
|
-
if (!!skipBalanceChecks) return [3, 2];
|
3421
|
-
_a = anchor_1.BN.bind;
|
3422
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
3423
|
-
case 1:
|
3424
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3425
|
-
if (unWrappedSolBalance.lt(lamports)) {
|
3426
|
-
throw "Insufficient SOL Funds";
|
3427
|
-
}
|
3428
|
-
_c.label = 2;
|
3429
|
-
case 2:
|
3430
|
-
if (!ephemeralSignerPubkey) {
|
3431
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3432
|
-
additionalSigners.push(wrappedSolAccount);
|
3433
|
-
}
|
3434
|
-
preInstructions = [
|
3435
|
-
web3_js_1.SystemProgram.createAccount({
|
3436
|
-
fromPubkey: publicKey,
|
3437
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3438
|
-
lamports: lamports.toNumber(),
|
3439
|
-
space: 165,
|
3440
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3441
|
-
}),
|
3442
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3443
|
-
];
|
3444
|
-
postInstructions = [
|
3445
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3446
|
-
];
|
3447
|
-
return [3, 6];
|
3448
|
-
case 3:
|
3449
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3450
|
-
if (!!skipBalanceChecks) return [3, 6];
|
3451
|
-
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3452
|
-
case 4:
|
3453
|
-
if (!(_c.sent())) {
|
3454
|
-
throw "Insufficient Funds , token Account doesn't exist";
|
3455
|
-
}
|
3456
|
-
_b = anchor_1.BN.bind;
|
3457
|
-
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3458
|
-
case 5:
|
3459
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3460
|
-
if (tokenAccountBalance.lt(amountIn)) {
|
3461
|
-
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3462
|
-
}
|
3463
|
-
_c.label = 6;
|
3464
|
-
case 6:
|
3465
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3466
|
-
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3467
|
-
case 7:
|
3468
|
-
if (!(_c.sent())) {
|
3469
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3470
|
-
}
|
3471
|
-
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3472
|
-
return [4, this.program.methods.swapAndAddCollateral({
|
3473
|
-
amountIn: amountIn,
|
3474
|
-
minCollateralAmountOut: minCollateralAmountOut,
|
3475
|
-
}).accounts({
|
3476
|
-
owner: publicKey,
|
3477
|
-
feePayer: publicKey,
|
3478
|
-
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3479
|
-
transferAuthority: poolConfig.transferAuthority,
|
3480
|
-
perpetuals: poolConfig.perpetuals,
|
3481
|
-
pool: poolConfig.poolAddress,
|
3482
|
-
receivingCustody: inputCustodyConfig.custodyAccount,
|
3483
|
-
receivingCustodyOracleAccount: this.useExtOracleAccount ? inputCustodyConfig.extOracleAccount : inputCustodyConfig.intOracleAccount,
|
3484
|
-
receivingCustodyTokenAccount: inputCustodyConfig.tokenAccount,
|
3485
|
-
position: positionPubKey,
|
3486
|
-
market: marketAccount,
|
3487
|
-
targetCustody: targetCustodyConfig.custodyAccount,
|
3488
|
-
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3489
|
-
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3490
|
-
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3491
|
-
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3492
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3493
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3494
|
-
program: this.programId,
|
3495
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3496
|
-
})
|
3497
|
-
.instruction()];
|
3498
|
-
case 8:
|
3499
|
-
instruction = _c.sent();
|
3500
|
-
instructions.push(instruction);
|
3501
|
-
return [2, {
|
3502
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3503
|
-
additionalSigners: additionalSigners
|
3504
|
-
}];
|
3505
|
-
}
|
3506
|
-
});
|
3507
|
-
});
|
3508
|
-
};
|
3509
|
-
this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3510
|
-
var args_1 = [];
|
3511
|
-
for (var _i = 6; _i < arguments.length; _i++) {
|
3512
|
-
args_1[_i - 6] = arguments[_i];
|
3513
|
-
}
|
3514
|
-
return __awaiter(_this, __spreadArray([collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3515
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
|
3516
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
3517
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3518
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3519
|
-
return __generator(this, function (_b) {
|
3520
|
-
switch (_b.label) {
|
3521
|
-
case 0:
|
3522
|
-
publicKey = this.provider.wallet.publicKey;
|
3523
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
3524
|
-
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
3525
|
-
});
|
3526
|
-
targetCustodyConfig = poolConfig.custodies.find(function (i) {
|
3527
|
-
return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey);
|
3528
|
-
});
|
3529
|
-
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3530
|
-
throw "collateralCustodyConfig/marketCustodyConfig not found";
|
3531
|
-
}
|
3532
|
-
preInstructions = [];
|
3533
|
-
instructions = [];
|
3534
|
-
postInstructions = [];
|
3535
|
-
additionalSigners = [];
|
3536
|
-
_b.label = 1;
|
3537
|
-
case 1:
|
3538
|
-
_b.trys.push([1, 7, , 8]);
|
3539
|
-
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
3540
|
-
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
3541
|
-
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
3542
|
-
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
3543
|
-
if (!ephemeralSignerPubkey) {
|
3544
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3545
|
-
additionalSigners.push(wrappedSolAccount);
|
3546
|
-
}
|
3547
|
-
preInstructions = [
|
3548
|
-
web3_js_1.SystemProgram.createAccount({
|
3549
|
-
fromPubkey: publicKey,
|
3550
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3551
|
-
lamports: lamports,
|
3552
|
-
space: 165,
|
3553
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3554
|
-
}),
|
3555
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3556
|
-
];
|
3557
|
-
postInstructions = [
|
3558
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3559
|
-
];
|
3560
|
-
return [3, 5];
|
3561
|
-
case 2:
|
3562
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3563
|
-
_a = createUserATA;
|
3564
|
-
if (!_a) return [3, 4];
|
3565
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3566
|
-
case 3:
|
3567
|
-
_a = !(_b.sent());
|
3568
|
-
_b.label = 4;
|
3569
|
-
case 4:
|
3570
|
-
if (_a) {
|
3571
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3572
|
-
}
|
3573
|
-
_b.label = 5;
|
3574
|
-
case 5:
|
3575
|
-
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3576
|
-
return [4, this.program.methods
|
3577
|
-
.removeCollateral({
|
3578
|
-
collateralDelta: collateralWithFee,
|
3579
|
-
})
|
3580
|
-
.accounts({
|
3581
|
-
owner: publicKey,
|
3582
|
-
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
3583
|
-
transferAuthority: poolConfig.transferAuthority,
|
3584
|
-
perpetuals: poolConfig.perpetuals,
|
3585
|
-
pool: poolConfig.poolAddress,
|
3586
|
-
position: positionPubKey,
|
3587
|
-
market: marketAccount,
|
3588
|
-
targetCustody: targetCustodyConfig.custodyAccount,
|
3589
|
-
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3590
|
-
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3591
|
-
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3592
|
-
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3593
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3594
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3595
|
-
program: this.programId,
|
3596
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3597
|
-
})
|
3598
|
-
.instruction()];
|
3599
|
-
case 6:
|
3600
|
-
instruction = _b.sent();
|
3601
|
-
instructions.push(instruction);
|
3602
|
-
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
3603
|
-
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
3604
|
-
postInstructions.push(closeWsolATAIns);
|
3605
|
-
}
|
3606
|
-
return [3, 8];
|
3607
|
-
case 7:
|
3608
|
-
error_2 = _b.sent();
|
3609
|
-
console.error("perpclient removeCollateral error:", error_2);
|
3610
|
-
throw error_2;
|
3611
|
-
case 8: return [2, {
|
3612
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3613
|
-
additionalSigners: additionalSigners
|
3614
|
-
}];
|
3318
|
+
error_2 = _b.sent();
|
3319
|
+
console.error("perpclient removeCollateral error:", error_2);
|
3320
|
+
throw error_2;
|
3321
|
+
case 8: return [2, {
|
3322
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3323
|
+
additionalSigners: additionalSigners
|
3324
|
+
}];
|
3615
3325
|
}
|
3616
3326
|
});
|
3617
3327
|
});
|
@@ -3850,7 +3560,7 @@ var PerpetualsClient = (function () {
|
|
3850
3560
|
args_1[_i - 4] = arguments[_i];
|
3851
3561
|
}
|
3852
3562
|
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3853
|
-
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction,
|
3563
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_5;
|
3854
3564
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3855
3565
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3856
3566
|
return __generator(this, function (_g) {
|
@@ -3973,9 +3683,9 @@ var PerpetualsClient = (function () {
|
|
3973
3683
|
instructions.push(instruction);
|
3974
3684
|
return [3, 11];
|
3975
3685
|
case 10:
|
3976
|
-
|
3977
|
-
console.error("perpClient addLiquidity error:: ",
|
3978
|
-
throw
|
3686
|
+
err_5 = _g.sent();
|
3687
|
+
console.error("perpClient addLiquidity error:: ", err_5);
|
3688
|
+
throw err_5;
|
3979
3689
|
case 11: return [2, {
|
3980
3690
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3981
3691
|
additionalSigners: additionalSigners
|
@@ -4125,7 +3835,7 @@ var PerpetualsClient = (function () {
|
|
4125
3835
|
args_1[_i - 4] = arguments[_i];
|
4126
3836
|
}
|
4127
3837
|
return __awaiter(_this, __spreadArray([recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1], args_1, true), void 0, function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
4128
|
-
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns,
|
3838
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
|
4129
3839
|
if (closeLpATA === void 0) { closeLpATA = false; }
|
4130
3840
|
if (createUserATA === void 0) { createUserATA = true; }
|
4131
3841
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
@@ -4240,9 +3950,9 @@ var PerpetualsClient = (function () {
|
|
4240
3950
|
}
|
4241
3951
|
return [3, 8];
|
4242
3952
|
case 7:
|
4243
|
-
|
4244
|
-
console.log("perpClient removeLiquidity error:: ",
|
4245
|
-
throw
|
3953
|
+
err_6 = _f.sent();
|
3954
|
+
console.log("perpClient removeLiquidity error:: ", err_6);
|
3955
|
+
throw err_6;
|
4246
3956
|
case 8: return [2, {
|
4247
3957
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4248
3958
|
additionalSigners: additionalSigners
|
@@ -4252,7 +3962,7 @@ var PerpetualsClient = (function () {
|
|
4252
3962
|
});
|
4253
3963
|
};
|
4254
3964
|
this.addReferral = function (tokenStakeAccount, nftReferralAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4255
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addReferralInstruction,
|
3965
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addReferralInstruction, err_7;
|
4256
3966
|
return __generator(this, function (_a) {
|
4257
3967
|
switch (_a.label) {
|
4258
3968
|
case 0:
|
@@ -4279,9 +3989,9 @@ var PerpetualsClient = (function () {
|
|
4279
3989
|
instructions.push(addReferralInstruction);
|
4280
3990
|
return [3, 4];
|
4281
3991
|
case 3:
|
4282
|
-
|
4283
|
-
console.log("perpClient addReferral error:: ",
|
4284
|
-
throw
|
3992
|
+
err_7 = _a.sent();
|
3993
|
+
console.log("perpClient addReferral error:: ", err_7);
|
3994
|
+
throw err_7;
|
4285
3995
|
case 4: return [2, {
|
4286
3996
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4287
3997
|
additionalSigners: additionalSigners
|
@@ -4290,7 +4000,7 @@ var PerpetualsClient = (function () {
|
|
4290
4000
|
});
|
4291
4001
|
}); };
|
4292
4002
|
this.createNftTradingAccount = function (nftMint, owner, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4293
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, createNftTradingAccountInstruction,
|
4003
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, createNftTradingAccountInstruction, err_8;
|
4294
4004
|
return __generator(this, function (_a) {
|
4295
4005
|
switch (_a.label) {
|
4296
4006
|
case 0:
|
@@ -4325,9 +4035,9 @@ var PerpetualsClient = (function () {
|
|
4325
4035
|
instructions.push(createNftTradingAccountInstruction);
|
4326
4036
|
return [3, 4];
|
4327
4037
|
case 3:
|
4328
|
-
|
4329
|
-
console.log("perpClient createNftAccount error:: ",
|
4330
|
-
throw
|
4038
|
+
err_8 = _a.sent();
|
4039
|
+
console.log("perpClient createNftAccount error:: ", err_8);
|
4040
|
+
throw err_8;
|
4331
4041
|
case 4: return [2, {
|
4332
4042
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4333
4043
|
additionalSigners: additionalSigners
|
@@ -4336,7 +4046,7 @@ var PerpetualsClient = (function () {
|
|
4336
4046
|
});
|
4337
4047
|
}); };
|
4338
4048
|
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4339
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction,
|
4049
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_9;
|
4340
4050
|
return __generator(this, function (_a) {
|
4341
4051
|
switch (_a.label) {
|
4342
4052
|
case 0:
|
@@ -4386,9 +4096,9 @@ var PerpetualsClient = (function () {
|
|
4386
4096
|
instructions.push(updateNftTradingAccountInstruction);
|
4387
4097
|
return [3, 5];
|
4388
4098
|
case 4:
|
4389
|
-
|
4390
|
-
console.log("perpClient updateNftAccount error:: ",
|
4391
|
-
throw
|
4099
|
+
err_9 = _a.sent();
|
4100
|
+
console.log("perpClient updateNftAccount error:: ", err_9);
|
4101
|
+
throw err_9;
|
4392
4102
|
case 5: return [2, {
|
4393
4103
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4394
4104
|
additionalSigners: additionalSigners
|
@@ -4397,7 +4107,7 @@ var PerpetualsClient = (function () {
|
|
4397
4107
|
});
|
4398
4108
|
}); };
|
4399
4109
|
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4400
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction,
|
4110
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_10;
|
4401
4111
|
return __generator(this, function (_a) {
|
4402
4112
|
switch (_a.label) {
|
4403
4113
|
case 0:
|
@@ -4436,9 +4146,9 @@ var PerpetualsClient = (function () {
|
|
4436
4146
|
instructions.push(levelUpInstruction);
|
4437
4147
|
return [3, 4];
|
4438
4148
|
case 3:
|
4439
|
-
|
4440
|
-
console.log("perpClient levelUp error:: ",
|
4441
|
-
throw
|
4149
|
+
err_10 = _a.sent();
|
4150
|
+
console.log("perpClient levelUp error:: ", err_10);
|
4151
|
+
throw err_10;
|
4442
4152
|
case 4: return [2, {
|
4443
4153
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4444
4154
|
additionalSigners: additionalSigners
|
@@ -4447,7 +4157,7 @@ var PerpetualsClient = (function () {
|
|
4447
4157
|
});
|
4448
4158
|
}); };
|
4449
4159
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4450
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
4160
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_11;
|
4451
4161
|
return __generator(this, function (_a) {
|
4452
4162
|
switch (_a.label) {
|
4453
4163
|
case 0:
|
@@ -4488,9 +4198,9 @@ var PerpetualsClient = (function () {
|
|
4488
4198
|
instructions.push(depositStakeInstruction);
|
4489
4199
|
return [3, 5];
|
4490
4200
|
case 4:
|
4491
|
-
|
4492
|
-
console.log("perpClient depositStaking error:: ",
|
4493
|
-
throw
|
4201
|
+
err_11 = _a.sent();
|
4202
|
+
console.log("perpClient depositStaking error:: ", err_11);
|
4203
|
+
throw err_11;
|
4494
4204
|
case 5: return [2, {
|
4495
4205
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4496
4206
|
additionalSigners: additionalSigners
|
@@ -4499,7 +4209,7 @@ var PerpetualsClient = (function () {
|
|
4499
4209
|
});
|
4500
4210
|
}); };
|
4501
4211
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4502
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4212
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
4503
4213
|
return __generator(this, function (_c) {
|
4504
4214
|
switch (_c.label) {
|
4505
4215
|
case 0:
|
@@ -4546,9 +4256,9 @@ var PerpetualsClient = (function () {
|
|
4546
4256
|
refreshStakeInstruction = _c.sent();
|
4547
4257
|
return [2, refreshStakeInstruction];
|
4548
4258
|
case 2:
|
4549
|
-
|
4550
|
-
console.log("perpClient refreshStaking error:: ",
|
4551
|
-
throw
|
4259
|
+
err_12 = _c.sent();
|
4260
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4261
|
+
throw err_12;
|
4552
4262
|
case 3: return [2];
|
4553
4263
|
}
|
4554
4264
|
});
|
@@ -4559,7 +4269,7 @@ var PerpetualsClient = (function () {
|
|
4559
4269
|
args_1[_i - 3] = arguments[_i];
|
4560
4270
|
}
|
4561
4271
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4562
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
4272
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_13;
|
4563
4273
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4564
4274
|
return __generator(this, function (_c) {
|
4565
4275
|
switch (_c.label) {
|
@@ -4607,9 +4317,9 @@ var PerpetualsClient = (function () {
|
|
4607
4317
|
refreshStakeInstruction = _c.sent();
|
4608
4318
|
return [2, refreshStakeInstruction];
|
4609
4319
|
case 2:
|
4610
|
-
|
4611
|
-
console.log("perpClient refreshStaking error:: ",
|
4612
|
-
throw
|
4320
|
+
err_13 = _c.sent();
|
4321
|
+
console.log("perpClient refreshStaking error:: ", err_13);
|
4322
|
+
throw err_13;
|
4613
4323
|
case 3: return [2];
|
4614
4324
|
}
|
4615
4325
|
});
|
@@ -4621,7 +4331,7 @@ var PerpetualsClient = (function () {
|
|
4621
4331
|
args_1[_i - 3] = arguments[_i];
|
4622
4332
|
}
|
4623
4333
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4624
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
4334
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_14;
|
4625
4335
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4626
4336
|
return __generator(this, function (_b) {
|
4627
4337
|
switch (_b.label) {
|
@@ -4673,9 +4383,9 @@ var PerpetualsClient = (function () {
|
|
4673
4383
|
instructions.push(unstakeInstantInstruction);
|
4674
4384
|
return [3, 6];
|
4675
4385
|
case 5:
|
4676
|
-
|
4677
|
-
console.log("perpClient unstakeInstant error:: ",
|
4678
|
-
throw
|
4386
|
+
err_14 = _b.sent();
|
4387
|
+
console.log("perpClient unstakeInstant error:: ", err_14);
|
4388
|
+
throw err_14;
|
4679
4389
|
case 6: return [2, {
|
4680
4390
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4681
4391
|
additionalSigners: additionalSigners
|
@@ -4685,7 +4395,7 @@ var PerpetualsClient = (function () {
|
|
4685
4395
|
});
|
4686
4396
|
};
|
4687
4397
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4688
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4398
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_15;
|
4689
4399
|
return __generator(this, function (_c) {
|
4690
4400
|
switch (_c.label) {
|
4691
4401
|
case 0:
|
@@ -4729,15 +4439,15 @@ var PerpetualsClient = (function () {
|
|
4729
4439
|
refreshStakeInstruction = _c.sent();
|
4730
4440
|
return [2, refreshStakeInstruction];
|
4731
4441
|
case 2:
|
4732
|
-
|
4733
|
-
console.log("perpClient refreshStaking error:: ",
|
4734
|
-
throw
|
4442
|
+
err_15 = _c.sent();
|
4443
|
+
console.log("perpClient refreshStaking error:: ", err_15);
|
4444
|
+
throw err_15;
|
4735
4445
|
case 3: return [2];
|
4736
4446
|
}
|
4737
4447
|
});
|
4738
4448
|
}); };
|
4739
4449
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4740
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4450
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_16;
|
4741
4451
|
return __generator(this, function (_a) {
|
4742
4452
|
switch (_a.label) {
|
4743
4453
|
case 0:
|
@@ -4771,9 +4481,9 @@ var PerpetualsClient = (function () {
|
|
4771
4481
|
instructions.push(unstakeRequestInstruction);
|
4772
4482
|
return [3, 4];
|
4773
4483
|
case 3:
|
4774
|
-
|
4775
|
-
console.log("perpClient unstakeRequest error:: ",
|
4776
|
-
throw
|
4484
|
+
err_16 = _a.sent();
|
4485
|
+
console.log("perpClient unstakeRequest error:: ", err_16);
|
4486
|
+
throw err_16;
|
4777
4487
|
case 4: return [2, {
|
4778
4488
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4779
4489
|
additionalSigners: additionalSigners
|
@@ -4787,7 +4497,7 @@ var PerpetualsClient = (function () {
|
|
4787
4497
|
args_1[_i - 1] = arguments[_i];
|
4788
4498
|
}
|
4789
4499
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4790
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4500
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_17;
|
4791
4501
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
4792
4502
|
if (deactivated === void 0) { deactivated = true; }
|
4793
4503
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
@@ -4842,9 +4552,9 @@ var PerpetualsClient = (function () {
|
|
4842
4552
|
instructions.push(withdrawStakeInstruction);
|
4843
4553
|
return [3, 6];
|
4844
4554
|
case 5:
|
4845
|
-
|
4846
|
-
console.log("perpClient withdrawStake error:: ",
|
4847
|
-
throw
|
4555
|
+
err_17 = _b.sent();
|
4556
|
+
console.log("perpClient withdrawStake error:: ", err_17);
|
4557
|
+
throw err_17;
|
4848
4558
|
case 6: return [2, {
|
4849
4559
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4850
4560
|
additionalSigners: additionalSigners
|
@@ -4859,7 +4569,7 @@ var PerpetualsClient = (function () {
|
|
4859
4569
|
args_1[_i - 3] = arguments[_i];
|
4860
4570
|
}
|
4861
4571
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4862
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
4572
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_18;
|
4863
4573
|
if (createUserATA === void 0) { createUserATA = true; }
|
4864
4574
|
return __generator(this, function (_b) {
|
4865
4575
|
switch (_b.label) {
|
@@ -4919,9 +4629,9 @@ var PerpetualsClient = (function () {
|
|
4919
4629
|
instructions.push(withdrawStakeInstruction);
|
4920
4630
|
return [3, 6];
|
4921
4631
|
case 5:
|
4922
|
-
|
4923
|
-
console.log("perpClient withdrawStake error:: ",
|
4924
|
-
throw
|
4632
|
+
err_18 = _b.sent();
|
4633
|
+
console.log("perpClient withdrawStake error:: ", err_18);
|
4634
|
+
throw err_18;
|
4925
4635
|
case 6: return [2, {
|
4926
4636
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4927
4637
|
additionalSigners: additionalSigners
|
@@ -4936,7 +4646,7 @@ var PerpetualsClient = (function () {
|
|
4936
4646
|
args_1[_i - 5] = arguments[_i];
|
4937
4647
|
}
|
4938
4648
|
return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4939
|
-
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity,
|
4649
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_19;
|
4940
4650
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4941
4651
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4942
4652
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -5062,8 +4772,8 @@ var PerpetualsClient = (function () {
|
|
5062
4772
|
instructions.push(addCompoundingLiquidity);
|
5063
4773
|
return [3, 10];
|
5064
4774
|
case 9:
|
5065
|
-
|
5066
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4775
|
+
err_19 = _f.sent();
|
4776
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_19);
|
5067
4777
|
return [3, 10];
|
5068
4778
|
case 10: return [2, {
|
5069
4779
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5079,7 +4789,7 @@ var PerpetualsClient = (function () {
|
|
5079
4789
|
args_1[_i - 5] = arguments[_i];
|
5080
4790
|
}
|
5081
4791
|
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) {
|
5082
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity,
|
4792
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_20;
|
5083
4793
|
if (createUserATA === void 0) { createUserATA = true; }
|
5084
4794
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5085
4795
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
@@ -5189,8 +4899,8 @@ var PerpetualsClient = (function () {
|
|
5189
4899
|
instructions.push(removeCompoundingLiquidity);
|
5190
4900
|
return [3, 8];
|
5191
4901
|
case 7:
|
5192
|
-
|
5193
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4902
|
+
err_20 = _f.sent();
|
4903
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_20);
|
5194
4904
|
return [3, 8];
|
5195
4905
|
case 8: return [2, {
|
5196
4906
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5206,7 +4916,7 @@ var PerpetualsClient = (function () {
|
|
5206
4916
|
args_1[_i - 3] = arguments[_i];
|
5207
4917
|
}
|
5208
4918
|
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
5209
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake,
|
4919
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_21;
|
5210
4920
|
if (createUserATA === void 0) { createUserATA = true; }
|
5211
4921
|
return __generator(this, function (_g) {
|
5212
4922
|
switch (_g.label) {
|
@@ -5304,8 +5014,8 @@ var PerpetualsClient = (function () {
|
|
5304
5014
|
instructions.push(migrateStake);
|
5305
5015
|
return [3, 8];
|
5306
5016
|
case 7:
|
5307
|
-
|
5308
|
-
console.log("perpClient migrateStake error:: ",
|
5017
|
+
err_21 = _g.sent();
|
5018
|
+
console.log("perpClient migrateStake error:: ", err_21);
|
5309
5019
|
return [3, 8];
|
5310
5020
|
case 8: return [2, {
|
5311
5021
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5316,7 +5026,7 @@ var PerpetualsClient = (function () {
|
|
5316
5026
|
});
|
5317
5027
|
};
|
5318
5028
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5319
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
5029
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_22;
|
5320
5030
|
return __generator(this, function (_d) {
|
5321
5031
|
switch (_d.label) {
|
5322
5032
|
case 0:
|
@@ -5388,8 +5098,8 @@ var PerpetualsClient = (function () {
|
|
5388
5098
|
instructions.push(migrateFlp);
|
5389
5099
|
return [3, 4];
|
5390
5100
|
case 3:
|
5391
|
-
|
5392
|
-
console.log("perpClient migrateFlp error:: ",
|
5101
|
+
err_22 = _d.sent();
|
5102
|
+
console.log("perpClient migrateFlp error:: ", err_22);
|
5393
5103
|
return [3, 4];
|
5394
5104
|
case 4: return [2, {
|
5395
5105
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5404,7 +5114,7 @@ var PerpetualsClient = (function () {
|
|
5404
5114
|
args_1[_i - 1] = arguments[_i];
|
5405
5115
|
}
|
5406
5116
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5407
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee,
|
5117
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_23;
|
5408
5118
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5409
5119
|
return __generator(this, function (_e) {
|
5410
5120
|
switch (_e.label) {
|
@@ -5462,8 +5172,8 @@ var PerpetualsClient = (function () {
|
|
5462
5172
|
instructions.push(compoundingFee);
|
5463
5173
|
return [3, 4];
|
5464
5174
|
case 3:
|
5465
|
-
|
5466
|
-
console.log("perpClient compoundingFee error:: ",
|
5175
|
+
err_23 = _e.sent();
|
5176
|
+
console.log("perpClient compoundingFee error:: ", err_23);
|
5467
5177
|
return [3, 4];
|
5468
5178
|
case 4: return [2, {
|
5469
5179
|
instructions: __spreadArray([], instructions, true),
|
@@ -5474,7 +5184,7 @@ var PerpetualsClient = (function () {
|
|
5474
5184
|
});
|
5475
5185
|
};
|
5476
5186
|
this.burnAndClaim = function (owner, nftMint, poolConfig, createAta) { return __awaiter(_this, void 0, void 0, function () {
|
5477
|
-
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction,
|
5187
|
+
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction, err_24;
|
5478
5188
|
return __generator(this, function (_b) {
|
5479
5189
|
switch (_b.label) {
|
5480
5190
|
case 0:
|
@@ -5538,9 +5248,9 @@ var PerpetualsClient = (function () {
|
|
5538
5248
|
instructions.push(burnAndClaimInstruction);
|
5539
5249
|
return [3, 8];
|
5540
5250
|
case 7:
|
5541
|
-
|
5542
|
-
console.log("perpClient burnAndClaimInstruction error:: ",
|
5543
|
-
throw
|
5251
|
+
err_24 = _b.sent();
|
5252
|
+
console.log("perpClient burnAndClaimInstruction error:: ", err_24);
|
5253
|
+
throw err_24;
|
5544
5254
|
case 8: return [2, {
|
5545
5255
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5546
5256
|
additionalSigners: additionalSigners
|
@@ -5549,7 +5259,7 @@ var PerpetualsClient = (function () {
|
|
5549
5259
|
});
|
5550
5260
|
}); };
|
5551
5261
|
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5552
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction,
|
5262
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_25;
|
5553
5263
|
return __generator(this, function (_a) {
|
5554
5264
|
switch (_a.label) {
|
5555
5265
|
case 0:
|
@@ -5600,9 +5310,9 @@ var PerpetualsClient = (function () {
|
|
5600
5310
|
instructions.push(burnAndStakeInstruction);
|
5601
5311
|
return [3, 4];
|
5602
5312
|
case 3:
|
5603
|
-
|
5604
|
-
console.log("perpClient burnAndStakeInstruction error:: ",
|
5605
|
-
throw
|
5313
|
+
err_25 = _a.sent();
|
5314
|
+
console.log("perpClient burnAndStakeInstruction error:: ", err_25);
|
5315
|
+
throw err_25;
|
5606
5316
|
case 4: return [2, {
|
5607
5317
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5608
5318
|
additionalSigners: additionalSigners
|
@@ -5611,7 +5321,7 @@ var PerpetualsClient = (function () {
|
|
5611
5321
|
});
|
5612
5322
|
}); };
|
5613
5323
|
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5614
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction,
|
5324
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_26;
|
5615
5325
|
return __generator(this, function (_a) {
|
5616
5326
|
switch (_a.label) {
|
5617
5327
|
case 0:
|
@@ -5652,9 +5362,9 @@ var PerpetualsClient = (function () {
|
|
5652
5362
|
instructions.push(depositTokenStakeInstruction);
|
5653
5363
|
return [3, 5];
|
5654
5364
|
case 4:
|
5655
|
-
|
5656
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5657
|
-
throw
|
5365
|
+
err_26 = _a.sent();
|
5366
|
+
console.log("perpClient depositStakingInstruction error:: ", err_26);
|
5367
|
+
throw err_26;
|
5658
5368
|
case 5: return [2, {
|
5659
5369
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5660
5370
|
additionalSigners: additionalSigners
|
@@ -5663,7 +5373,7 @@ var PerpetualsClient = (function () {
|
|
5663
5373
|
});
|
5664
5374
|
}); };
|
5665
5375
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5666
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5376
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_27;
|
5667
5377
|
return __generator(this, function (_a) {
|
5668
5378
|
switch (_a.label) {
|
5669
5379
|
case 0:
|
@@ -5692,9 +5402,9 @@ var PerpetualsClient = (function () {
|
|
5692
5402
|
instructions.push(unstakeTokenRequestInstruction);
|
5693
5403
|
return [3, 4];
|
5694
5404
|
case 3:
|
5695
|
-
|
5696
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5697
|
-
throw
|
5405
|
+
err_27 = _a.sent();
|
5406
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_27);
|
5407
|
+
throw err_27;
|
5698
5408
|
case 4: return [2, {
|
5699
5409
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5700
5410
|
additionalSigners: additionalSigners
|
@@ -5703,7 +5413,7 @@ var PerpetualsClient = (function () {
|
|
5703
5413
|
});
|
5704
5414
|
}); };
|
5705
5415
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5706
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5416
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_28;
|
5707
5417
|
return __generator(this, function (_a) {
|
5708
5418
|
switch (_a.label) {
|
5709
5419
|
case 0:
|
@@ -5743,9 +5453,9 @@ var PerpetualsClient = (function () {
|
|
5743
5453
|
instructions.push(unstakeTokenInstantInstruction);
|
5744
5454
|
return [3, 5];
|
5745
5455
|
case 4:
|
5746
|
-
|
5747
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5748
|
-
throw
|
5456
|
+
err_28 = _a.sent();
|
5457
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_28);
|
5458
|
+
throw err_28;
|
5749
5459
|
case 5: return [2, {
|
5750
5460
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5751
5461
|
additionalSigners: additionalSigners
|
@@ -5754,7 +5464,7 @@ var PerpetualsClient = (function () {
|
|
5754
5464
|
});
|
5755
5465
|
}); };
|
5756
5466
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5757
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5467
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_29;
|
5758
5468
|
return __generator(this, function (_a) {
|
5759
5469
|
switch (_a.label) {
|
5760
5470
|
case 0:
|
@@ -5794,9 +5504,9 @@ var PerpetualsClient = (function () {
|
|
5794
5504
|
instructions.push(withdrawTokenInstruction);
|
5795
5505
|
return [3, 5];
|
5796
5506
|
case 4:
|
5797
|
-
|
5798
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5799
|
-
throw
|
5507
|
+
err_29 = _a.sent();
|
5508
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_29);
|
5509
|
+
throw err_29;
|
5800
5510
|
case 5: return [2, {
|
5801
5511
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5802
5512
|
additionalSigners: additionalSigners
|
@@ -5805,7 +5515,7 @@ var PerpetualsClient = (function () {
|
|
5805
5515
|
});
|
5806
5516
|
}); };
|
5807
5517
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5808
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5518
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_30;
|
5809
5519
|
return __generator(this, function (_a) {
|
5810
5520
|
switch (_a.label) {
|
5811
5521
|
case 0:
|
@@ -5834,9 +5544,9 @@ var PerpetualsClient = (function () {
|
|
5834
5544
|
instructions.push(cancelUnstakeRequestInstruction);
|
5835
5545
|
return [3, 4];
|
5836
5546
|
case 3:
|
5837
|
-
|
5838
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5839
|
-
throw
|
5547
|
+
err_30 = _a.sent();
|
5548
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_30);
|
5549
|
+
throw err_30;
|
5840
5550
|
case 4: return [2, {
|
5841
5551
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5842
5552
|
additionalSigners: additionalSigners
|
@@ -5850,7 +5560,7 @@ var PerpetualsClient = (function () {
|
|
5850
5560
|
args_1[_i - 2] = arguments[_i];
|
5851
5561
|
}
|
5852
5562
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5853
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
5563
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_31;
|
5854
5564
|
if (createUserATA === void 0) { createUserATA = true; }
|
5855
5565
|
return __generator(this, function (_b) {
|
5856
5566
|
switch (_b.label) {
|
@@ -5895,9 +5605,9 @@ var PerpetualsClient = (function () {
|
|
5895
5605
|
instructions.push(collectTokenRewardInstruction);
|
5896
5606
|
return [3, 6];
|
5897
5607
|
case 5:
|
5898
|
-
|
5899
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5900
|
-
throw
|
5608
|
+
err_31 = _b.sent();
|
5609
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_31);
|
5610
|
+
throw err_31;
|
5901
5611
|
case 6: return [2, {
|
5902
5612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5903
5613
|
additionalSigners: additionalSigners
|
@@ -5912,7 +5622,7 @@ var PerpetualsClient = (function () {
|
|
5912
5622
|
args_1[_i - 3] = arguments[_i];
|
5913
5623
|
}
|
5914
5624
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5915
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
5625
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_32;
|
5916
5626
|
if (createUserATA === void 0) { createUserATA = true; }
|
5917
5627
|
return __generator(this, function (_b) {
|
5918
5628
|
switch (_b.label) {
|
@@ -5958,9 +5668,9 @@ var PerpetualsClient = (function () {
|
|
5958
5668
|
instructions.push(collectRevenueInstruction);
|
5959
5669
|
return [3, 6];
|
5960
5670
|
case 5:
|
5961
|
-
|
5962
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5963
|
-
throw
|
5671
|
+
err_32 = _b.sent();
|
5672
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_32);
|
5673
|
+
throw err_32;
|
5964
5674
|
case 6: return [2, {
|
5965
5675
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5966
5676
|
additionalSigners: additionalSigners
|
@@ -5970,7 +5680,7 @@ var PerpetualsClient = (function () {
|
|
5970
5680
|
});
|
5971
5681
|
};
|
5972
5682
|
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5973
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault,
|
5683
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_33;
|
5974
5684
|
return __generator(this, function (_a) {
|
5975
5685
|
switch (_a.label) {
|
5976
5686
|
case 0:
|
@@ -6007,9 +5717,9 @@ var PerpetualsClient = (function () {
|
|
6007
5717
|
instructions.push(initRewardVault);
|
6008
5718
|
return [3, 4];
|
6009
5719
|
case 3:
|
6010
|
-
|
6011
|
-
console.log("perpClient InitRewardVault error:: ",
|
6012
|
-
throw
|
5720
|
+
err_33 = _a.sent();
|
5721
|
+
console.log("perpClient InitRewardVault error:: ", err_33);
|
5722
|
+
throw err_33;
|
6013
5723
|
case 4: return [2, {
|
6014
5724
|
instructions: __spreadArray([], instructions, true),
|
6015
5725
|
additionalSigners: additionalSigners
|
@@ -6018,7 +5728,7 @@ var PerpetualsClient = (function () {
|
|
6018
5728
|
});
|
6019
5729
|
}); };
|
6020
5730
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6021
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward,
|
5731
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_34;
|
6022
5732
|
return __generator(this, function (_a) {
|
6023
5733
|
switch (_a.label) {
|
6024
5734
|
case 0:
|
@@ -6049,9 +5759,9 @@ var PerpetualsClient = (function () {
|
|
6049
5759
|
instructions.push(distributeReward);
|
6050
5760
|
return [3, 4];
|
6051
5761
|
case 3:
|
6052
|
-
|
6053
|
-
console.log("perpClient distributeReward error:: ",
|
6054
|
-
throw
|
5762
|
+
err_34 = _a.sent();
|
5763
|
+
console.log("perpClient distributeReward error:: ", err_34);
|
5764
|
+
throw err_34;
|
6055
5765
|
case 4: return [2, {
|
6056
5766
|
instructions: __spreadArray([], instructions, true),
|
6057
5767
|
additionalSigners: additionalSigners
|
@@ -6065,7 +5775,7 @@ var PerpetualsClient = (function () {
|
|
6065
5775
|
args_1[_i - 3] = arguments[_i];
|
6066
5776
|
}
|
6067
5777
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
6068
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward,
|
5778
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_35;
|
6069
5779
|
if (createUserATA === void 0) { createUserATA = true; }
|
6070
5780
|
return __generator(this, function (_b) {
|
6071
5781
|
switch (_b.label) {
|
@@ -6116,8 +5826,8 @@ var PerpetualsClient = (function () {
|
|
6116
5826
|
instructions.push(collectNftReward);
|
6117
5827
|
return [3, 6];
|
6118
5828
|
case 5:
|
6119
|
-
|
6120
|
-
throw
|
5829
|
+
err_35 = _b.sent();
|
5830
|
+
throw err_35;
|
6121
5831
|
case 6: return [2, {
|
6122
5832
|
instructions: __spreadArray([], instructions, true),
|
6123
5833
|
additionalSigners: additionalSigners
|
@@ -6132,7 +5842,7 @@ var PerpetualsClient = (function () {
|
|
6132
5842
|
args_1[_i - 2] = arguments[_i];
|
6133
5843
|
}
|
6134
5844
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6135
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction,
|
5845
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_36;
|
6136
5846
|
if (createUserATA === void 0) { createUserATA = true; }
|
6137
5847
|
return __generator(this, function (_b) {
|
6138
5848
|
switch (_b.label) {
|
@@ -6197,9 +5907,9 @@ var PerpetualsClient = (function () {
|
|
6197
5907
|
instructions.push(withdrawStakeInstruction);
|
6198
5908
|
return [3, 6];
|
6199
5909
|
case 5:
|
6200
|
-
|
6201
|
-
console.log("perpClient withdrawStake error:: ",
|
6202
|
-
throw
|
5910
|
+
err_36 = _b.sent();
|
5911
|
+
console.log("perpClient withdrawStake error:: ", err_36);
|
5912
|
+
throw err_36;
|
6203
5913
|
case 6: return [2, {
|
6204
5914
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6205
5915
|
additionalSigners: additionalSigners
|
@@ -6209,7 +5919,7 @@ var PerpetualsClient = (function () {
|
|
6209
5919
|
});
|
6210
5920
|
};
|
6211
5921
|
this.setTriggerPrice = function (targetSymbol, collateralSymbol, side, triggerPrice, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6212
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice,
|
5922
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_37;
|
6213
5923
|
return __generator(this, function (_a) {
|
6214
5924
|
switch (_a.label) {
|
6215
5925
|
case 0:
|
@@ -6248,9 +5958,9 @@ var PerpetualsClient = (function () {
|
|
6248
5958
|
instructions.push(setTriggerPrice);
|
6249
5959
|
return [3, 4];
|
6250
5960
|
case 3:
|
6251
|
-
|
6252
|
-
console.log("perpClient setTriggerPrice error:: ",
|
6253
|
-
throw
|
5961
|
+
err_37 = _a.sent();
|
5962
|
+
console.log("perpClient setTriggerPrice error:: ", err_37);
|
5963
|
+
throw err_37;
|
6254
5964
|
case 4: return [2, {
|
6255
5965
|
instructions: __spreadArray([], instructions, true),
|
6256
5966
|
additionalSigners: additionalSigners
|
@@ -6264,7 +5974,7 @@ var PerpetualsClient = (function () {
|
|
6264
5974
|
args_1[_i - 6] = arguments[_i];
|
6265
5975
|
}
|
6266
5976
|
return __awaiter(_this, __spreadArray([positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6267
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns,
|
5977
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_38;
|
6268
5978
|
if (createUserATA === void 0) { createUserATA = true; }
|
6269
5979
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6270
5980
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
@@ -6328,9 +6038,9 @@ var PerpetualsClient = (function () {
|
|
6328
6038
|
}
|
6329
6039
|
return [3, 7];
|
6330
6040
|
case 6:
|
6331
|
-
|
6332
|
-
console.log("perpClient forceClosePosition error:: ",
|
6333
|
-
throw
|
6041
|
+
err_38 = _b.sent();
|
6042
|
+
console.log("perpClient forceClosePosition error:: ", err_38);
|
6043
|
+
throw err_38;
|
6334
6044
|
case 7: return [2, {
|
6335
6045
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6336
6046
|
additionalSigners: additionalSigners
|
@@ -6345,7 +6055,7 @@ var PerpetualsClient = (function () {
|
|
6345
6055
|
args_1[_i - 11] = arguments[_i];
|
6346
6056
|
}
|
6347
6057
|
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) {
|
6348
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder,
|
6058
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_39;
|
6349
6059
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6350
6060
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6351
6061
|
return __generator(this, function (_c) {
|
@@ -6452,9 +6162,9 @@ var PerpetualsClient = (function () {
|
|
6452
6162
|
instructions.push(placeLimitOrder);
|
6453
6163
|
return [3, 11];
|
6454
6164
|
case 10:
|
6455
|
-
|
6456
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6457
|
-
throw
|
6165
|
+
err_39 = _c.sent();
|
6166
|
+
console.log("perpClient placeLimitOrder error:: ", err_39);
|
6167
|
+
throw err_39;
|
6458
6168
|
case 11: return [2, {
|
6459
6169
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6460
6170
|
additionalSigners: additionalSigners
|
@@ -6469,7 +6179,7 @@ var PerpetualsClient = (function () {
|
|
6469
6179
|
args_1[_i - 11] = arguments[_i];
|
6470
6180
|
}
|
6471
6181
|
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) {
|
6472
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder,
|
6182
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_40;
|
6473
6183
|
if (createUserATA === void 0) { createUserATA = true; }
|
6474
6184
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6475
6185
|
return __generator(this, function (_b) {
|
@@ -6559,9 +6269,9 @@ var PerpetualsClient = (function () {
|
|
6559
6269
|
instructions.push(editLimitOrder);
|
6560
6270
|
return [3, 8];
|
6561
6271
|
case 7:
|
6562
|
-
|
6563
|
-
console.log("perpClient editLimitOrder error:: ",
|
6564
|
-
throw
|
6272
|
+
err_40 = _b.sent();
|
6273
|
+
console.log("perpClient editLimitOrder error:: ", err_40);
|
6274
|
+
throw err_40;
|
6565
6275
|
case 8: return [2, {
|
6566
6276
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6567
6277
|
additionalSigners: additionalSigners
|
@@ -6576,7 +6286,7 @@ var PerpetualsClient = (function () {
|
|
6576
6286
|
args_1[_i - 7] = arguments[_i];
|
6577
6287
|
}
|
6578
6288
|
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6579
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder,
|
6289
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_41;
|
6580
6290
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6581
6291
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6582
6292
|
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
@@ -6628,9 +6338,9 @@ var PerpetualsClient = (function () {
|
|
6628
6338
|
instructions.push(executeLimitOrder);
|
6629
6339
|
return [3, 4];
|
6630
6340
|
case 3:
|
6631
|
-
|
6632
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6633
|
-
throw
|
6341
|
+
err_41 = _a.sent();
|
6342
|
+
console.log("perpClient executeLimitOrder error:: ", err_41);
|
6343
|
+
throw err_41;
|
6634
6344
|
case 4: return [2, {
|
6635
6345
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6636
6346
|
additionalSigners: additionalSigners
|
@@ -6645,7 +6355,7 @@ var PerpetualsClient = (function () {
|
|
6645
6355
|
args_1[_i - 8] = arguments[_i];
|
6646
6356
|
}
|
6647
6357
|
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6648
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap,
|
6358
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_42;
|
6649
6359
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6650
6360
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6651
6361
|
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
@@ -6700,9 +6410,9 @@ var PerpetualsClient = (function () {
|
|
6700
6410
|
instructions.push(executeLimitWithSwap);
|
6701
6411
|
return [3, 4];
|
6702
6412
|
case 3:
|
6703
|
-
|
6704
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6705
|
-
throw
|
6413
|
+
err_42 = _a.sent();
|
6414
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_42);
|
6415
|
+
throw err_42;
|
6706
6416
|
case 4: return [2, {
|
6707
6417
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6708
6418
|
additionalSigners: additionalSigners
|
@@ -6712,7 +6422,7 @@ var PerpetualsClient = (function () {
|
|
6712
6422
|
});
|
6713
6423
|
};
|
6714
6424
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6715
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
6425
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_43;
|
6716
6426
|
return __generator(this, function (_a) {
|
6717
6427
|
switch (_a.label) {
|
6718
6428
|
case 0:
|
@@ -6760,9 +6470,9 @@ var PerpetualsClient = (function () {
|
|
6760
6470
|
instructions.push(placeTriggerOrder);
|
6761
6471
|
return [3, 4];
|
6762
6472
|
case 3:
|
6763
|
-
|
6764
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6765
|
-
throw
|
6473
|
+
err_43 = _a.sent();
|
6474
|
+
console.log("perpClient placeTriggerOrder error:: ", err_43);
|
6475
|
+
throw err_43;
|
6766
6476
|
case 4: return [2, {
|
6767
6477
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6768
6478
|
additionalSigners: additionalSigners
|
@@ -6771,7 +6481,7 @@ var PerpetualsClient = (function () {
|
|
6771
6481
|
});
|
6772
6482
|
}); };
|
6773
6483
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6774
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
6484
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_44;
|
6775
6485
|
return __generator(this, function (_a) {
|
6776
6486
|
switch (_a.label) {
|
6777
6487
|
case 0:
|
@@ -6818,9 +6528,9 @@ var PerpetualsClient = (function () {
|
|
6818
6528
|
instructions.push(editTriggerOrder);
|
6819
6529
|
return [3, 4];
|
6820
6530
|
case 3:
|
6821
|
-
|
6822
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6823
|
-
throw
|
6531
|
+
err_44 = _a.sent();
|
6532
|
+
console.log("perpClient editTriggerOrder error:: ", err_44);
|
6533
|
+
throw err_44;
|
6824
6534
|
case 4: return [2, {
|
6825
6535
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6826
6536
|
additionalSigners: additionalSigners
|
@@ -6829,7 +6539,7 @@ var PerpetualsClient = (function () {
|
|
6829
6539
|
});
|
6830
6540
|
}); };
|
6831
6541
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6832
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
6542
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_45;
|
6833
6543
|
return __generator(this, function (_a) {
|
6834
6544
|
switch (_a.label) {
|
6835
6545
|
case 0:
|
@@ -6862,9 +6572,9 @@ var PerpetualsClient = (function () {
|
|
6862
6572
|
instructions.push(cancelTriggerOrder);
|
6863
6573
|
return [3, 4];
|
6864
6574
|
case 3:
|
6865
|
-
|
6866
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6867
|
-
throw
|
6575
|
+
err_45 = _a.sent();
|
6576
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_45);
|
6577
|
+
throw err_45;
|
6868
6578
|
case 4: return [2, {
|
6869
6579
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6870
6580
|
additionalSigners: additionalSigners
|
@@ -6873,7 +6583,7 @@ var PerpetualsClient = (function () {
|
|
6873
6583
|
});
|
6874
6584
|
}); };
|
6875
6585
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6876
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
6586
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_46;
|
6877
6587
|
return __generator(this, function (_a) {
|
6878
6588
|
switch (_a.label) {
|
6879
6589
|
case 0:
|
@@ -6904,9 +6614,9 @@ var PerpetualsClient = (function () {
|
|
6904
6614
|
instructions.push(cancelAllTriggerOrders);
|
6905
6615
|
return [3, 4];
|
6906
6616
|
case 3:
|
6907
|
-
|
6908
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6909
|
-
throw
|
6617
|
+
err_46 = _a.sent();
|
6618
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_46);
|
6619
|
+
throw err_46;
|
6910
6620
|
case 4: return [2, {
|
6911
6621
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6912
6622
|
additionalSigners: additionalSigners
|
@@ -6920,7 +6630,7 @@ var PerpetualsClient = (function () {
|
|
6920
6630
|
args_1[_i - 9] = arguments[_i];
|
6921
6631
|
}
|
6922
6632
|
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, rebateTokenAccount) {
|
6923
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap,
|
6633
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_47;
|
6924
6634
|
if (createUserATA === void 0) { createUserATA = true; }
|
6925
6635
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6926
6636
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -7022,9 +6732,9 @@ var PerpetualsClient = (function () {
|
|
7022
6732
|
instructions.push(executeTriggerWithSwap);
|
7023
6733
|
return [3, 10];
|
7024
6734
|
case 9:
|
7025
|
-
|
7026
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
7027
|
-
throw
|
6735
|
+
err_47 = _e.sent();
|
6736
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_47);
|
6737
|
+
throw err_47;
|
7028
6738
|
case 10: return [2, {
|
7029
6739
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7030
6740
|
additionalSigners: additionalSigners
|
@@ -7039,7 +6749,7 @@ var PerpetualsClient = (function () {
|
|
7039
6749
|
args_1[_i - 8] = arguments[_i];
|
7040
6750
|
}
|
7041
6751
|
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, rebateTokenAccount) {
|
7042
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder,
|
6752
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_48;
|
7043
6753
|
if (createUserATA === void 0) { createUserATA = true; }
|
7044
6754
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7045
6755
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -7110,9 +6820,9 @@ var PerpetualsClient = (function () {
|
|
7110
6820
|
instructions.push(executeTriggerOrder);
|
7111
6821
|
return [3, 8];
|
7112
6822
|
case 7:
|
7113
|
-
|
7114
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
7115
|
-
throw
|
6823
|
+
err_48 = _b.sent();
|
6824
|
+
console.log("perpClient executeTriggerOrder error:: ", err_48);
|
6825
|
+
throw err_48;
|
7116
6826
|
case 8: return [2, {
|
7117
6827
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7118
6828
|
additionalSigners: additionalSigners
|
@@ -7122,7 +6832,7 @@ var PerpetualsClient = (function () {
|
|
7122
6832
|
});
|
7123
6833
|
};
|
7124
6834
|
this.migrateTriggerOrder = function (owner, marketAccount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7125
|
-
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder,
|
6835
|
+
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_49;
|
7126
6836
|
return __generator(this, function (_a) {
|
7127
6837
|
switch (_a.label) {
|
7128
6838
|
case 0:
|
@@ -7152,8 +6862,298 @@ var PerpetualsClient = (function () {
|
|
7152
6862
|
instructions.push(migrateTriggerOrder);
|
7153
6863
|
return [3, 4];
|
7154
6864
|
case 3:
|
7155
|
-
|
7156
|
-
console.log("perpClient migrateTriggerOrder error:: ",
|
6865
|
+
err_49 = _a.sent();
|
6866
|
+
console.log("perpClient migrateTriggerOrder error:: ", err_49);
|
6867
|
+
throw err_49;
|
6868
|
+
case 4: return [2, {
|
6869
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6870
|
+
additionalSigners: additionalSigners
|
6871
|
+
}];
|
6872
|
+
}
|
6873
|
+
});
|
6874
|
+
}); };
|
6875
|
+
this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
|
6876
|
+
var args_1 = [];
|
6877
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
6878
|
+
args_1[_i - 5] = arguments[_i];
|
6879
|
+
}
|
6880
|
+
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) {
|
6881
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_50;
|
6882
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
6883
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6884
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
6885
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6886
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6887
|
+
return __generator(this, function (_g) {
|
6888
|
+
switch (_g.label) {
|
6889
|
+
case 0:
|
6890
|
+
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
6891
|
+
if (!userInputCustodyConfig) {
|
6892
|
+
throw "userInputCustodyConfig not found";
|
6893
|
+
}
|
6894
|
+
userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
|
6895
|
+
if (!userOutputCustodyConfig) {
|
6896
|
+
throw "userOutputCustodyConfig not found";
|
6897
|
+
}
|
6898
|
+
publicKey = this.provider.wallet.publicKey;
|
6899
|
+
preInstructions = [];
|
6900
|
+
instructions = [];
|
6901
|
+
postInstructions = [];
|
6902
|
+
additionalSigners = [];
|
6903
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
6904
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
6905
|
+
case 1:
|
6906
|
+
wsolAssociatedTokenAccount = _g.sent();
|
6907
|
+
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
6908
|
+
case 2:
|
6909
|
+
wsolATAExist = _g.sent();
|
6910
|
+
if (!wsolATAExist) {
|
6911
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
6912
|
+
}
|
6913
|
+
if (!!skipBalanceChecks) return [3, 4];
|
6914
|
+
_a = anchor_1.BN.bind;
|
6915
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
6916
|
+
case 3:
|
6917
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
6918
|
+
if (unWrappedSolBalance.lt(amountIn)) {
|
6919
|
+
throw "Insufficient SOL Funds";
|
6920
|
+
}
|
6921
|
+
_g.label = 4;
|
6922
|
+
case 4:
|
6923
|
+
instructions.push(web3_js_1.SystemProgram.transfer({
|
6924
|
+
fromPubkey: publicKey,
|
6925
|
+
toPubkey: wsolAssociatedTokenAccount,
|
6926
|
+
lamports: amountIn.toNumber(),
|
6927
|
+
}), (0, spl_token_1.createSyncNativeInstruction)(wsolAssociatedTokenAccount));
|
6928
|
+
return [2, {
|
6929
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6930
|
+
additionalSigners: additionalSigners
|
6931
|
+
}];
|
6932
|
+
case 5:
|
6933
|
+
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
6934
|
+
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
6935
|
+
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
6936
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
|
6937
|
+
instructions.push(closeWsolATAIns);
|
6938
|
+
return [2, {
|
6939
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6940
|
+
additionalSigners: additionalSigners
|
6941
|
+
}];
|
6942
|
+
}
|
6943
|
+
_g.label = 6;
|
6944
|
+
case 6:
|
6945
|
+
_g.trys.push([6, 19, , 20]);
|
6946
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
6947
|
+
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
6948
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
6949
|
+
case 7:
|
6950
|
+
accCreationLamports = (_g.sent());
|
6951
|
+
console.log("accCreationLamports:", accCreationLamports);
|
6952
|
+
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
6953
|
+
_b = anchor_1.BN.bind;
|
6954
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
6955
|
+
case 8:
|
6956
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
6957
|
+
if (unWrappedSolBalance.lt(amountIn)) {
|
6958
|
+
throw "Insufficient SOL Funds";
|
6959
|
+
}
|
6960
|
+
if (!ephemeralSignerPubkey) {
|
6961
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
6962
|
+
additionalSigners.push(wrappedSolAccount);
|
6963
|
+
}
|
6964
|
+
;
|
6965
|
+
preInstructions = [
|
6966
|
+
web3_js_1.SystemProgram.createAccount({
|
6967
|
+
fromPubkey: publicKey,
|
6968
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
6969
|
+
lamports: lamports.toNumber(),
|
6970
|
+
space: 165,
|
6971
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
6972
|
+
}),
|
6973
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
6974
|
+
];
|
6975
|
+
postInstructions = [
|
6976
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
6977
|
+
];
|
6978
|
+
return [3, 12];
|
6979
|
+
case 9:
|
6980
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
6981
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
6982
|
+
case 10:
|
6983
|
+
if (!(_g.sent())) {
|
6984
|
+
throw "Insufficient Funds , Token Account doesn't exist";
|
6985
|
+
}
|
6986
|
+
if (!!skipBalanceChecks) return [3, 12];
|
6987
|
+
_c = anchor_1.BN.bind;
|
6988
|
+
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
6989
|
+
case 11:
|
6990
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
6991
|
+
if (tokenAccountBalance.lt(amountIn)) {
|
6992
|
+
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
6993
|
+
}
|
6994
|
+
_g.label = 12;
|
6995
|
+
case 12:
|
6996
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
6997
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
6998
|
+
if (!ephemeralSignerPubkey) {
|
6999
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
7000
|
+
additionalSigners.push(wrappedSolAccount);
|
7001
|
+
}
|
7002
|
+
;
|
7003
|
+
preInstructions = [
|
7004
|
+
web3_js_1.SystemProgram.createAccount({
|
7005
|
+
fromPubkey: publicKey,
|
7006
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
7007
|
+
lamports: lamports,
|
7008
|
+
space: 165,
|
7009
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
7010
|
+
}),
|
7011
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
7012
|
+
];
|
7013
|
+
postInstructions = [
|
7014
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
7015
|
+
];
|
7016
|
+
return [3, 17];
|
7017
|
+
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
7018
|
+
case 14:
|
7019
|
+
userOutputTokenAccount = _g.sent();
|
7020
|
+
_d = createUserATA;
|
7021
|
+
if (!_d) return [3, 16];
|
7022
|
+
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
7023
|
+
case 15:
|
7024
|
+
_d = !(_g.sent());
|
7025
|
+
_g.label = 16;
|
7026
|
+
case 16:
|
7027
|
+
if (_d) {
|
7028
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
7029
|
+
}
|
7030
|
+
_g.label = 17;
|
7031
|
+
case 17:
|
7032
|
+
custodyAccountMetas = [];
|
7033
|
+
custodyOracleAccountMetas = [];
|
7034
|
+
for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
|
7035
|
+
custody = _f[_e];
|
7036
|
+
custodyAccountMetas.push({
|
7037
|
+
pubkey: custody.custodyAccount,
|
7038
|
+
isSigner: false,
|
7039
|
+
isWritable: false,
|
7040
|
+
});
|
7041
|
+
custodyOracleAccountMetas.push({
|
7042
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
7043
|
+
isSigner: false,
|
7044
|
+
isWritable: false,
|
7045
|
+
});
|
7046
|
+
}
|
7047
|
+
params = {
|
7048
|
+
amountIn: amountIn,
|
7049
|
+
minAmountOut: minAmountOut,
|
7050
|
+
useFeesPool: useFeesPool
|
7051
|
+
};
|
7052
|
+
return [4, this.program.methods
|
7053
|
+
.swap(params)
|
7054
|
+
.accounts({
|
7055
|
+
owner: publicKey,
|
7056
|
+
fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
7057
|
+
receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userOutputTokenAccount,
|
7058
|
+
transferAuthority: poolConfig.transferAuthority,
|
7059
|
+
perpetuals: poolConfig.perpetuals,
|
7060
|
+
pool: poolConfig.poolAddress,
|
7061
|
+
receivingCustody: userInputCustodyConfig.custodyAccount,
|
7062
|
+
receivingCustodyOracleAccount: this.useExtOracleAccount ? userInputCustodyConfig.extOracleAccount : userInputCustodyConfig.intOracleAccount,
|
7063
|
+
receivingCustodyTokenAccount: userInputCustodyConfig.tokenAccount,
|
7064
|
+
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
7065
|
+
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
7066
|
+
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
7067
|
+
eventAuthority: this.eventAuthority.publicKey,
|
7068
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7069
|
+
program: this.programId,
|
7070
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7071
|
+
})
|
7072
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
7073
|
+
.instruction()];
|
7074
|
+
case 18:
|
7075
|
+
inx = _g.sent();
|
7076
|
+
instructions.push(inx);
|
7077
|
+
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
7078
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
7079
|
+
instructions.push(closeWsolATAIns);
|
7080
|
+
}
|
7081
|
+
return [3, 20];
|
7082
|
+
case 19:
|
7083
|
+
err_50 = _g.sent();
|
7084
|
+
console.error("perpClient Swap error:: ", err_50);
|
7085
|
+
throw err_50;
|
7086
|
+
case 20: return [2, {
|
7087
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7088
|
+
additionalSigners: additionalSigners
|
7089
|
+
}];
|
7090
|
+
}
|
7091
|
+
});
|
7092
|
+
});
|
7093
|
+
};
|
7094
|
+
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7095
|
+
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_51;
|
7096
|
+
return __generator(this, function (_b) {
|
7097
|
+
switch (_b.label) {
|
7098
|
+
case 0:
|
7099
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
7100
|
+
if (!rewardCustody) {
|
7101
|
+
throw "rewardCustody not found";
|
7102
|
+
}
|
7103
|
+
custody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(swapTokenSymbol).mintKey); });
|
7104
|
+
if (!custody) {
|
7105
|
+
throw "custody not found";
|
7106
|
+
}
|
7107
|
+
publicKey = this.provider.wallet.publicKey;
|
7108
|
+
preInstructions = [];
|
7109
|
+
instructions = [];
|
7110
|
+
postInstructions = [];
|
7111
|
+
additionalSigners = [];
|
7112
|
+
_b.label = 1;
|
7113
|
+
case 1:
|
7114
|
+
_b.trys.push([1, 3, , 4]);
|
7115
|
+
custodyAccountMetas = [];
|
7116
|
+
custodyOracleAccountMetas = [];
|
7117
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
7118
|
+
custody_1 = _a[_i];
|
7119
|
+
custodyAccountMetas.push({
|
7120
|
+
pubkey: custody_1.custodyAccount,
|
7121
|
+
isSigner: false,
|
7122
|
+
isWritable: false,
|
7123
|
+
});
|
7124
|
+
custodyOracleAccountMetas.push({
|
7125
|
+
pubkey: this.useExtOracleAccount ? custody_1.extOracleAccount : custody_1.intOracleAccount,
|
7126
|
+
isSigner: false,
|
7127
|
+
isWritable: false,
|
7128
|
+
});
|
7129
|
+
}
|
7130
|
+
params = {};
|
7131
|
+
return [4, this.program.methods
|
7132
|
+
.swapFeeInternal(params)
|
7133
|
+
.accounts({
|
7134
|
+
owner: publicKey,
|
7135
|
+
perpetuals: poolConfig.perpetuals,
|
7136
|
+
pool: poolConfig.poolAddress,
|
7137
|
+
rewardCustody: rewardCustody.custodyAccount,
|
7138
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
7139
|
+
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
7140
|
+
custody: custody.custodyAccount,
|
7141
|
+
custodyOracleAccount: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
7142
|
+
custodyTokenAccount: custody.tokenAccount,
|
7143
|
+
eventAuthority: this.eventAuthority.publicKey,
|
7144
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7145
|
+
program: this.programId,
|
7146
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7147
|
+
})
|
7148
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
7149
|
+
.instruction()];
|
7150
|
+
case 2:
|
7151
|
+
inx = _b.sent();
|
7152
|
+
instructions.push(inx);
|
7153
|
+
return [3, 4];
|
7154
|
+
case 3:
|
7155
|
+
err_51 = _b.sent();
|
7156
|
+
console.error("perpClient Swap error:: ", err_51);
|
7157
7157
|
throw err_51;
|
7158
7158
|
case 4: return [2, {
|
7159
7159
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|