flash-sdk 2.23.2 → 2.24.1

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.
@@ -2954,6 +2954,264 @@ var PerpetualsClient = (function () {
2954
2954
  });
2955
2955
  });
2956
2956
  };
2957
+ this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2958
+ if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
2959
+ if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
2960
+ if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
2961
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2962
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2963
+ return __awaiter(_this, void 0, void 0, function () {
2964
+ var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
2965
+ return __generator(this, function (_c) {
2966
+ switch (_c.label) {
2967
+ case 0:
2968
+ publicKey = this.provider.wallet.publicKey;
2969
+ userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
2970
+ if (!userInputCustodyConfig) {
2971
+ throw "userInputCustodyConfig not found";
2972
+ }
2973
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey); });
2974
+ if (!collateralCustodyConfig) {
2975
+ throw "collateralCustodyConfig not found";
2976
+ }
2977
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetTokenSymbol).mintKey); });
2978
+ if (!targetCustodyConfig) {
2979
+ throw "targetCustodyConfig not found";
2980
+ }
2981
+ if (userInputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
2982
+ throw "Don't use Swap, just call Open position";
2983
+ }
2984
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
2985
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
2986
+ preInstructions = [];
2987
+ instructions = [];
2988
+ postInstructions = [];
2989
+ additionalSigners = [];
2990
+ if (!(userInputTokenSymbol == 'SOL')) return [3, 3];
2991
+ console.log("inputSymbol === SOL", userInputTokenSymbol);
2992
+ lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
2993
+ if (!!skipBalanceChecks) return [3, 2];
2994
+ _a = anchor_1.BN.bind;
2995
+ return [4, this.provider.connection.getBalance(publicKey)];
2996
+ case 1:
2997
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
2998
+ if (unWrappedSolBalance.lt(lamports)) {
2999
+ throw "Insufficient SOL Funds";
3000
+ }
3001
+ _c.label = 2;
3002
+ case 2:
3003
+ if (!ephemeralSignerPubkey) {
3004
+ wrappedSolAccount = new web3_js_1.Keypair();
3005
+ additionalSigners.push(wrappedSolAccount);
3006
+ }
3007
+ preInstructions = [
3008
+ web3_js_1.SystemProgram.createAccount({
3009
+ fromPubkey: publicKey,
3010
+ newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
3011
+ lamports: lamports.toNumber(),
3012
+ space: 165,
3013
+ programId: spl_token_1.TOKEN_PROGRAM_ID,
3014
+ }),
3015
+ (0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
3016
+ ];
3017
+ postInstructions = [
3018
+ (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3019
+ ];
3020
+ return [3, 6];
3021
+ case 3:
3022
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3023
+ if (!!skipBalanceChecks) return [3, 6];
3024
+ return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3025
+ case 4:
3026
+ if (!(_c.sent())) {
3027
+ throw "Insufficient Funds , Token Account doesn't exist";
3028
+ }
3029
+ _b = anchor_1.BN.bind;
3030
+ return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3031
+ case 5:
3032
+ tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
3033
+ if (tokenAccountBalance.lt(amountIn)) {
3034
+ throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3035
+ }
3036
+ _c.label = 6;
3037
+ case 6:
3038
+ userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true);
3039
+ return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3040
+ case 7:
3041
+ if (!(_c.sent())) {
3042
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
3043
+ }
3044
+ _c.label = 8;
3045
+ case 8:
3046
+ _c.trys.push([8, 10, , 11]);
3047
+ return [4, this.program.methods
3048
+ .swapAndOpen({
3049
+ amountIn: amountIn,
3050
+ minCollateralAmountOut: minCollateralAmountOut,
3051
+ priceWithSlippage: priceWithSlippage,
3052
+ sizeAmount: sizeAmount,
3053
+ privilege: privilege
3054
+ })
3055
+ .accounts({
3056
+ owner: publicKey,
3057
+ feePayer: publicKey,
3058
+ fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
3059
+ transferAuthority: poolConfig.transferAuthority,
3060
+ perpetuals: poolConfig.perpetuals,
3061
+ pool: poolConfig.poolAddress,
3062
+ receivingCustody: userInputCustodyConfig.custodyAccount,
3063
+ receivingCustodyOracleAccount: this.useExtOracleAccount ? userInputCustodyConfig.extOracleAccount : userInputCustodyConfig.intOracleAccount,
3064
+ receivingCustodyTokenAccount: userInputCustodyConfig.tokenAccount,
3065
+ position: positionAccount,
3066
+ market: marketAccount,
3067
+ targetCustody: targetCustodyConfig.custodyAccount,
3068
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
3069
+ collateralCustody: collateralCustodyConfig.custodyAccount,
3070
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
3071
+ collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3072
+ systemProgram: web3_js_1.SystemProgram.programId,
3073
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3074
+ eventAuthority: this.eventAuthority.publicKey,
3075
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3076
+ })
3077
+ .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
3078
+ .instruction()];
3079
+ case 9:
3080
+ inx = _c.sent();
3081
+ instructions.push(inx);
3082
+ return [3, 11];
3083
+ case 10:
3084
+ err_2 = _c.sent();
3085
+ console.error("perpClient SwapAndOpen error:: ", err_2);
3086
+ throw err_2;
3087
+ case 11: return [2, {
3088
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3089
+ additionalSigners: additionalSigners
3090
+ }];
3091
+ }
3092
+ });
3093
+ });
3094
+ };
3095
+ this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, ephemeralSignerPubkey) {
3096
+ if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
3097
+ if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
3098
+ if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
3099
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3100
+ return __awaiter(_this, void 0, void 0, function () {
3101
+ var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
3102
+ return __generator(this, function (_a) {
3103
+ switch (_a.label) {
3104
+ case 0:
3105
+ publicKey = this.provider.wallet.publicKey;
3106
+ userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
3107
+ if (!userOutputCustodyConfig) {
3108
+ throw "userOutputCustodyConfig not found";
3109
+ }
3110
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey); });
3111
+ if (!collateralCustodyConfig) {
3112
+ throw "collateralCustodyConfig not found";
3113
+ }
3114
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetTokenSymbol).mintKey); });
3115
+ if (!targetCustodyConfig) {
3116
+ throw "targetCustodyConfig not found";
3117
+ }
3118
+ if (userOutputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
3119
+ throw "Dont use swap, just call close position";
3120
+ }
3121
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
3122
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
3123
+ preInstructions = [];
3124
+ instructions = [];
3125
+ postInstructions = [];
3126
+ additionalSigners = [];
3127
+ if (!(userOutputTokenSymbol == 'SOL')) return [3, 1];
3128
+ console.log("outputSymbol === SOL", userOutputTokenSymbol);
3129
+ lamports = (this.minimumBalanceForRentExemptAccountLamports);
3130
+ if (!ephemeralSignerPubkey) {
3131
+ wrappedSolAccount = new web3_js_1.Keypair();
3132
+ additionalSigners.push(wrappedSolAccount);
3133
+ }
3134
+ preInstructions = [
3135
+ web3_js_1.SystemProgram.createAccount({
3136
+ fromPubkey: publicKey,
3137
+ newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
3138
+ lamports: lamports,
3139
+ space: 165,
3140
+ programId: spl_token_1.TOKEN_PROGRAM_ID,
3141
+ }),
3142
+ (0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
3143
+ ];
3144
+ postInstructions = [
3145
+ (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3146
+ ];
3147
+ additionalSigners.push(wrappedSolAccount);
3148
+ return [3, 4];
3149
+ case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3150
+ case 2:
3151
+ userReceivingTokenAccount = _a.sent();
3152
+ return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3153
+ case 3:
3154
+ if (!(_a.sent())) {
3155
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3156
+ }
3157
+ _a.label = 4;
3158
+ case 4:
3159
+ userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey, publicKey, true);
3160
+ return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
3161
+ case 5:
3162
+ if (!(_a.sent())) {
3163
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey));
3164
+ }
3165
+ _a.label = 6;
3166
+ case 6:
3167
+ _a.trys.push([6, 8, , 9]);
3168
+ return [4, this.program.methods
3169
+ .closeAndSwap({
3170
+ priceWithSlippage: priceWithSlippage,
3171
+ minSwapAmountOut: minSwapAmountOut,
3172
+ privilege: privilege
3173
+ })
3174
+ .accounts({
3175
+ owner: publicKey,
3176
+ feePayer: publicKey,
3177
+ receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
3178
+ collateralAccount: userCollateralTokenAccount,
3179
+ transferAuthority: poolConfig.transferAuthority,
3180
+ perpetuals: poolConfig.perpetuals,
3181
+ pool: poolConfig.poolAddress,
3182
+ position: positionAccount,
3183
+ market: marketAccount,
3184
+ targetCustody: targetCustodyConfig.custodyAccount,
3185
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
3186
+ collateralCustody: collateralCustodyConfig.custodyAccount,
3187
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
3188
+ collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3189
+ dispensingCustody: userOutputCustodyConfig.custodyAccount,
3190
+ dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
3191
+ dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
3192
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3193
+ eventAuthority: this.eventAuthority.publicKey,
3194
+ program: this.programId,
3195
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3196
+ })
3197
+ .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
3198
+ .instruction()];
3199
+ case 7:
3200
+ inx = _a.sent();
3201
+ instructions.push(inx);
3202
+ return [3, 9];
3203
+ case 8:
3204
+ err_3 = _a.sent();
3205
+ console.error("perpClient CloseAndSwap error:: ", err_3);
3206
+ throw err_3;
3207
+ case 9: return [2, {
3208
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3209
+ additionalSigners: additionalSigners
3210
+ }];
3211
+ }
3212
+ });
3213
+ });
3214
+ };
2957
3215
  this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
2958
3216
  if (useFeesPool === void 0) { useFeesPool = false; }
2959
3217
  if (createUserATA === void 0) { createUserATA = true; }
@@ -2961,7 +3219,7 @@ var PerpetualsClient = (function () {
2961
3219
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2962
3220
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2963
3221
  return __awaiter(_this, void 0, void 0, function () {
2964
- 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, _i, _e, custody, params, inx, closeWsolATAIns, err_2;
3222
+ 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, _i, _e, custody, params, inx, closeWsolATAIns, err_4;
2965
3223
  return __generator(this, function (_f) {
2966
3224
  switch (_f.label) {
2967
3225
  case 0:
@@ -3158,9 +3416,9 @@ var PerpetualsClient = (function () {
3158
3416
  }
3159
3417
  return [3, 20];
3160
3418
  case 19:
3161
- err_2 = _f.sent();
3162
- console.error("perpClient Swap error:: ", err_2);
3163
- throw err_2;
3419
+ err_4 = _f.sent();
3420
+ console.error("perpClient Swap error:: ", err_4);
3421
+ throw err_4;
3164
3422
  case 20: return [2, {
3165
3423
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3166
3424
  additionalSigners: additionalSigners
@@ -3170,7 +3428,7 @@ var PerpetualsClient = (function () {
3170
3428
  });
3171
3429
  };
3172
3430
  this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
3173
- var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_3;
3431
+ var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_5;
3174
3432
  return __generator(this, function (_b) {
3175
3433
  switch (_b.label) {
3176
3434
  case 0:
@@ -3230,9 +3488,9 @@ var PerpetualsClient = (function () {
3230
3488
  instructions.push(inx);
3231
3489
  return [3, 4];
3232
3490
  case 3:
3233
- err_3 = _b.sent();
3234
- console.error("perpClient Swap error:: ", err_3);
3235
- throw err_3;
3491
+ err_5 = _b.sent();
3492
+ console.error("perpClient Swap error:: ", err_5);
3493
+ throw err_5;
3236
3494
  case 4: return [2, {
3237
3495
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3238
3496
  additionalSigners: additionalSigners
@@ -3820,7 +4078,7 @@ var PerpetualsClient = (function () {
3820
4078
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3821
4079
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3822
4080
  return __awaiter(_this, void 0, void 0, function () {
3823
- var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_4;
4081
+ var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_6;
3824
4082
  return __generator(this, function (_f) {
3825
4083
  switch (_f.label) {
3826
4084
  case 0:
@@ -3941,9 +4199,9 @@ var PerpetualsClient = (function () {
3941
4199
  instructions.push(instruction);
3942
4200
  return [3, 11];
3943
4201
  case 10:
3944
- err_4 = _f.sent();
3945
- console.error("perpClient addLiquidity error:: ", err_4);
3946
- throw err_4;
4202
+ err_6 = _f.sent();
4203
+ console.error("perpClient addLiquidity error:: ", err_6);
4204
+ throw err_6;
3947
4205
  case 11: return [2, {
3948
4206
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3949
4207
  additionalSigners: additionalSigners
@@ -4088,7 +4346,7 @@ var PerpetualsClient = (function () {
4088
4346
  if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4089
4347
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4090
4348
  return __awaiter(_this, void 0, void 0, function () {
4091
- var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_5;
4349
+ var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
4092
4350
  return __generator(this, function (_e) {
4093
4351
  switch (_e.label) {
4094
4352
  case 0:
@@ -4198,9 +4456,9 @@ var PerpetualsClient = (function () {
4198
4456
  }
4199
4457
  return [3, 8];
4200
4458
  case 7:
4201
- err_5 = _e.sent();
4202
- console.log("perpClient removeLiquidity error:: ", err_5);
4203
- throw err_5;
4459
+ err_7 = _e.sent();
4460
+ console.log("perpClient removeLiquidity error:: ", err_7);
4461
+ throw err_7;
4204
4462
  case 8: return [2, {
4205
4463
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4206
4464
  additionalSigners: additionalSigners
@@ -4210,7 +4468,7 @@ var PerpetualsClient = (function () {
4210
4468
  });
4211
4469
  };
4212
4470
  this.addReferral = function (nftTradingAccount, nftReferralAccount) { return __awaiter(_this, void 0, void 0, function () {
4213
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addReferralInstruction, err_6;
4471
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addReferralInstruction, err_8;
4214
4472
  return __generator(this, function (_a) {
4215
4473
  switch (_a.label) {
4216
4474
  case 0:
@@ -4237,9 +4495,9 @@ var PerpetualsClient = (function () {
4237
4495
  instructions.push(addReferralInstruction);
4238
4496
  return [3, 4];
4239
4497
  case 3:
4240
- err_6 = _a.sent();
4241
- console.log("perpClient addReferral error:: ", err_6);
4242
- throw err_6;
4498
+ err_8 = _a.sent();
4499
+ console.log("perpClient addReferral error:: ", err_8);
4500
+ throw err_8;
4243
4501
  case 4: return [2, {
4244
4502
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4245
4503
  additionalSigners: additionalSigners
@@ -4248,7 +4506,7 @@ var PerpetualsClient = (function () {
4248
4506
  });
4249
4507
  }); };
4250
4508
  this.createNftTradingAccount = function (nftMint, owner, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4251
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, nftTokenAccount, createNftTradingAccountInstruction, err_7;
4509
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, nftTokenAccount, createNftTradingAccountInstruction, err_9;
4252
4510
  return __generator(this, function (_a) {
4253
4511
  switch (_a.label) {
4254
4512
  case 0:
@@ -4286,9 +4544,9 @@ var PerpetualsClient = (function () {
4286
4544
  instructions.push(createNftTradingAccountInstruction);
4287
4545
  return [3, 4];
4288
4546
  case 3:
4289
- err_7 = _a.sent();
4290
- console.log("perpClient createNftAccount error:: ", err_7);
4291
- throw err_7;
4547
+ err_9 = _a.sent();
4548
+ console.log("perpClient createNftAccount error:: ", err_9);
4549
+ throw err_9;
4292
4550
  case 4: return [2, {
4293
4551
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4294
4552
  additionalSigners: additionalSigners
@@ -4297,7 +4555,7 @@ var PerpetualsClient = (function () {
4297
4555
  });
4298
4556
  }); };
4299
4557
  this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
4300
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
4558
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_10;
4301
4559
  return __generator(this, function (_a) {
4302
4560
  switch (_a.label) {
4303
4561
  case 0:
@@ -4347,9 +4605,9 @@ var PerpetualsClient = (function () {
4347
4605
  instructions.push(updateNftTradingAccountInstruction);
4348
4606
  return [3, 5];
4349
4607
  case 4:
4350
- err_8 = _a.sent();
4351
- console.log("perpClient updateNftAccount error:: ", err_8);
4352
- throw err_8;
4608
+ err_10 = _a.sent();
4609
+ console.log("perpClient updateNftAccount error:: ", err_10);
4610
+ throw err_10;
4353
4611
  case 5: return [2, {
4354
4612
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4355
4613
  additionalSigners: additionalSigners
@@ -4358,7 +4616,7 @@ var PerpetualsClient = (function () {
4358
4616
  });
4359
4617
  }); };
4360
4618
  this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
4361
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
4619
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_11;
4362
4620
  return __generator(this, function (_a) {
4363
4621
  switch (_a.label) {
4364
4622
  case 0:
@@ -4397,9 +4655,9 @@ var PerpetualsClient = (function () {
4397
4655
  instructions.push(levelUpInstruction);
4398
4656
  return [3, 4];
4399
4657
  case 3:
4400
- err_9 = _a.sent();
4401
- console.log("perpClient levelUp error:: ", err_9);
4402
- throw err_9;
4658
+ err_11 = _a.sent();
4659
+ console.log("perpClient levelUp error:: ", err_11);
4660
+ throw err_11;
4403
4661
  case 4: return [2, {
4404
4662
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4405
4663
  additionalSigners: additionalSigners
@@ -4408,7 +4666,7 @@ var PerpetualsClient = (function () {
4408
4666
  });
4409
4667
  }); };
4410
4668
  this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4411
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_10;
4669
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_12;
4412
4670
  return __generator(this, function (_a) {
4413
4671
  switch (_a.label) {
4414
4672
  case 0:
@@ -4446,9 +4704,9 @@ var PerpetualsClient = (function () {
4446
4704
  instructions.push(initStakeInstruction);
4447
4705
  return [3, 4];
4448
4706
  case 3:
4449
- err_10 = _a.sent();
4450
- console.log("perpClient InitStaking error:: ", err_10);
4451
- throw err_10;
4707
+ err_12 = _a.sent();
4708
+ console.log("perpClient InitStaking error:: ", err_12);
4709
+ throw err_12;
4452
4710
  case 4: return [2, {
4453
4711
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4454
4712
  additionalSigners: additionalSigners
@@ -4457,7 +4715,7 @@ var PerpetualsClient = (function () {
4457
4715
  });
4458
4716
  }); };
4459
4717
  this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4460
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_11;
4718
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_13;
4461
4719
  return __generator(this, function (_a) {
4462
4720
  switch (_a.label) {
4463
4721
  case 0:
@@ -4502,9 +4760,9 @@ var PerpetualsClient = (function () {
4502
4760
  instructions.push(initCompoundingInstruction);
4503
4761
  return [3, 4];
4504
4762
  case 3:
4505
- err_11 = _a.sent();
4506
- console.log("perpClient initCompounding error:: ", err_11);
4507
- throw err_11;
4763
+ err_13 = _a.sent();
4764
+ console.log("perpClient initCompounding error:: ", err_13);
4765
+ throw err_13;
4508
4766
  case 4: return [2, {
4509
4767
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4510
4768
  additionalSigners: additionalSigners
@@ -4513,7 +4771,7 @@ var PerpetualsClient = (function () {
4513
4771
  });
4514
4772
  }); };
4515
4773
  this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4516
- var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_12;
4774
+ var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_14;
4517
4775
  return __generator(this, function (_a) {
4518
4776
  switch (_a.label) {
4519
4777
  case 0:
@@ -4554,9 +4812,9 @@ var PerpetualsClient = (function () {
4554
4812
  instructions.push(depositStakeInstruction);
4555
4813
  return [3, 5];
4556
4814
  case 4:
4557
- err_12 = _a.sent();
4558
- console.log("perpClient depositStaking error:: ", err_12);
4559
- throw err_12;
4815
+ err_14 = _a.sent();
4816
+ console.log("perpClient depositStaking error:: ", err_14);
4817
+ throw err_14;
4560
4818
  case 5: return [2, {
4561
4819
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4562
4820
  additionalSigners: additionalSigners
@@ -4599,7 +4857,7 @@ var PerpetualsClient = (function () {
4599
4857
  });
4600
4858
  }); };
4601
4859
  this.refreshStake = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
4602
- var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_13;
4860
+ var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_15;
4603
4861
  return __generator(this, function (_c) {
4604
4862
  switch (_c.label) {
4605
4863
  case 0:
@@ -4646,15 +4904,15 @@ var PerpetualsClient = (function () {
4646
4904
  refreshStakeInstruction = _c.sent();
4647
4905
  return [2, refreshStakeInstruction];
4648
4906
  case 2:
4649
- err_13 = _c.sent();
4650
- console.log("perpClient refreshStaking error:: ", err_13);
4651
- throw err_13;
4907
+ err_15 = _c.sent();
4908
+ console.log("perpClient refreshStaking error:: ", err_15);
4909
+ throw err_15;
4652
4910
  case 3: return [2];
4653
4911
  }
4654
4912
  });
4655
4913
  }); };
4656
4914
  this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4657
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, unstakeInstantInstruction, err_14;
4915
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, unstakeInstantInstruction, err_16;
4658
4916
  return __generator(this, function (_a) {
4659
4917
  switch (_a.label) {
4660
4918
  case 0:
@@ -4688,9 +4946,9 @@ var PerpetualsClient = (function () {
4688
4946
  instructions.push(unstakeInstantInstruction);
4689
4947
  return [3, 4];
4690
4948
  case 3:
4691
- err_14 = _a.sent();
4692
- console.log("perpClient unstakeInstant error:: ", err_14);
4693
- throw err_14;
4949
+ err_16 = _a.sent();
4950
+ console.log("perpClient unstakeInstant error:: ", err_16);
4951
+ throw err_16;
4694
4952
  case 4: return [2, {
4695
4953
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4696
4954
  additionalSigners: additionalSigners
@@ -4699,7 +4957,7 @@ var PerpetualsClient = (function () {
4699
4957
  });
4700
4958
  }); };
4701
4959
  this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
4702
- var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_15;
4960
+ var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_17;
4703
4961
  return __generator(this, function (_c) {
4704
4962
  switch (_c.label) {
4705
4963
  case 0:
@@ -4743,15 +5001,15 @@ var PerpetualsClient = (function () {
4743
5001
  refreshStakeInstruction = _c.sent();
4744
5002
  return [2, refreshStakeInstruction];
4745
5003
  case 2:
4746
- err_15 = _c.sent();
4747
- console.log("perpClient refreshStaking error:: ", err_15);
4748
- throw err_15;
5004
+ err_17 = _c.sent();
5005
+ console.log("perpClient refreshStaking error:: ", err_17);
5006
+ throw err_17;
4749
5007
  case 3: return [2];
4750
5008
  }
4751
5009
  });
4752
5010
  }); };
4753
5011
  this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4754
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_16;
5012
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_18;
4755
5013
  return __generator(this, function (_a) {
4756
5014
  switch (_a.label) {
4757
5015
  case 0:
@@ -4785,9 +5043,9 @@ var PerpetualsClient = (function () {
4785
5043
  instructions.push(unstakeRequestInstruction);
4786
5044
  return [3, 4];
4787
5045
  case 3:
4788
- err_16 = _a.sent();
4789
- console.log("perpClient unstakeRequest error:: ", err_16);
4790
- throw err_16;
5046
+ err_18 = _a.sent();
5047
+ console.log("perpClient unstakeRequest error:: ", err_18);
5048
+ throw err_18;
4791
5049
  case 4: return [2, {
4792
5050
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4793
5051
  additionalSigners: additionalSigners
@@ -4800,7 +5058,7 @@ var PerpetualsClient = (function () {
4800
5058
  if (deactivated === void 0) { deactivated = true; }
4801
5059
  if (createUserLPTA === void 0) { createUserLPTA = true; }
4802
5060
  return __awaiter(_this, void 0, void 0, function () {
4803
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_17;
5061
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_19;
4804
5062
  return __generator(this, function (_b) {
4805
5063
  switch (_b.label) {
4806
5064
  case 0:
@@ -4851,9 +5109,9 @@ var PerpetualsClient = (function () {
4851
5109
  instructions.push(withdrawStakeInstruction);
4852
5110
  return [3, 6];
4853
5111
  case 5:
4854
- err_17 = _b.sent();
4855
- console.log("perpClient withdrawStake error:: ", err_17);
4856
- throw err_17;
5112
+ err_19 = _b.sent();
5113
+ console.log("perpClient withdrawStake error:: ", err_19);
5114
+ throw err_19;
4857
5115
  case 6: return [2, {
4858
5116
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4859
5117
  additionalSigners: additionalSigners
@@ -4865,7 +5123,7 @@ var PerpetualsClient = (function () {
4865
5123
  this.collectStakeFees = function (rewardSymbol, poolConfig, nftTradingAccount, nftBoostingAccount, createUserATA) {
4866
5124
  if (createUserATA === void 0) { createUserATA = true; }
4867
5125
  return __awaiter(_this, void 0, void 0, function () {
4868
- var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, boostingAccount, withdrawStakeInstruction, err_18;
5126
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, boostingAccount, withdrawStakeInstruction, err_20;
4869
5127
  return __generator(this, function (_b) {
4870
5128
  switch (_b.label) {
4871
5129
  case 0:
@@ -4932,9 +5190,9 @@ var PerpetualsClient = (function () {
4932
5190
  instructions.push(withdrawStakeInstruction);
4933
5191
  return [3, 6];
4934
5192
  case 5:
4935
- err_18 = _b.sent();
4936
- console.log("perpClient withdrawStake error:: ", err_18);
4937
- throw err_18;
5193
+ err_20 = _b.sent();
5194
+ console.log("perpClient withdrawStake error:: ", err_20);
5195
+ throw err_20;
4938
5196
  case 6: return [2, {
4939
5197
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4940
5198
  additionalSigners: additionalSigners
@@ -4944,7 +5202,7 @@ var PerpetualsClient = (function () {
4944
5202
  });
4945
5203
  };
4946
5204
  this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4947
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_19;
5205
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_21;
4948
5206
  return __generator(this, function (_a) {
4949
5207
  switch (_a.label) {
4950
5208
  case 0:
@@ -4981,9 +5239,9 @@ var PerpetualsClient = (function () {
4981
5239
  instructions.push(initRewardVault);
4982
5240
  return [3, 4];
4983
5241
  case 3:
4984
- err_19 = _a.sent();
4985
- console.log("perpClient InitRewardVault error:: ", err_19);
4986
- throw err_19;
5242
+ err_21 = _a.sent();
5243
+ console.log("perpClient InitRewardVault error:: ", err_21);
5244
+ throw err_21;
4987
5245
  case 4: return [2, {
4988
5246
  instructions: __spreadArray([], instructions, true),
4989
5247
  additionalSigners: additionalSigners
@@ -4992,7 +5250,7 @@ var PerpetualsClient = (function () {
4992
5250
  });
4993
5251
  }); };
4994
5252
  this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4995
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_20;
5253
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_22;
4996
5254
  return __generator(this, function (_a) {
4997
5255
  switch (_a.label) {
4998
5256
  case 0:
@@ -5023,9 +5281,9 @@ var PerpetualsClient = (function () {
5023
5281
  instructions.push(distributeReward);
5024
5282
  return [3, 4];
5025
5283
  case 3:
5026
- err_20 = _a.sent();
5027
- console.log("perpClient distributeReward error:: ", err_20);
5028
- throw err_20;
5284
+ err_22 = _a.sent();
5285
+ console.log("perpClient distributeReward error:: ", err_22);
5286
+ throw err_22;
5029
5287
  case 4: return [2, {
5030
5288
  instructions: __spreadArray([], instructions, true),
5031
5289
  additionalSigners: additionalSigners
@@ -5036,7 +5294,7 @@ var PerpetualsClient = (function () {
5036
5294
  this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5037
5295
  if (createUserATA === void 0) { createUserATA = true; }
5038
5296
  return __awaiter(_this, void 0, void 0, function () {
5039
- var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_21;
5297
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_23;
5040
5298
  return __generator(this, function (_b) {
5041
5299
  switch (_b.label) {
5042
5300
  case 0:
@@ -5086,8 +5344,8 @@ var PerpetualsClient = (function () {
5086
5344
  instructions.push(collectNftReward);
5087
5345
  return [3, 6];
5088
5346
  case 5:
5089
- err_21 = _b.sent();
5090
- throw err_21;
5347
+ err_23 = _b.sent();
5348
+ throw err_23;
5091
5349
  case 6: return [2, {
5092
5350
  instructions: __spreadArray([], instructions, true),
5093
5351
  additionalSigners: additionalSigners
@@ -5099,7 +5357,7 @@ var PerpetualsClient = (function () {
5099
5357
  this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
5100
5358
  if (createUserATA === void 0) { createUserATA = true; }
5101
5359
  return __awaiter(_this, void 0, void 0, function () {
5102
- var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_22;
5360
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_24;
5103
5361
  return __generator(this, function (_b) {
5104
5362
  switch (_b.label) {
5105
5363
  case 0:
@@ -5163,9 +5421,9 @@ var PerpetualsClient = (function () {
5163
5421
  instructions.push(withdrawStakeInstruction);
5164
5422
  return [3, 6];
5165
5423
  case 5:
5166
- err_22 = _b.sent();
5167
- console.log("perpClient withdrawStake error:: ", err_22);
5168
- throw err_22;
5424
+ err_24 = _b.sent();
5425
+ console.log("perpClient withdrawStake error:: ", err_24);
5426
+ throw err_24;
5169
5427
  case 6: return [2, {
5170
5428
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5171
5429
  additionalSigners: additionalSigners
@@ -5175,7 +5433,7 @@ var PerpetualsClient = (function () {
5175
5433
  });
5176
5434
  };
5177
5435
  this.setTriggerPrice = function (targetSymbol, collateralSymbol, side, triggerPrice, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5178
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_23;
5436
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_25;
5179
5437
  return __generator(this, function (_a) {
5180
5438
  switch (_a.label) {
5181
5439
  case 0:
@@ -5214,9 +5472,9 @@ var PerpetualsClient = (function () {
5214
5472
  instructions.push(setTriggerPrice);
5215
5473
  return [3, 4];
5216
5474
  case 3:
5217
- err_23 = _a.sent();
5218
- console.log("perpClient setTriggerPrice error:: ", err_23);
5219
- throw err_23;
5475
+ err_25 = _a.sent();
5476
+ console.log("perpClient setTriggerPrice error:: ", err_25);
5477
+ throw err_25;
5220
5478
  case 4: return [2, {
5221
5479
  instructions: __spreadArray([], instructions, true),
5222
5480
  additionalSigners: additionalSigners
@@ -5229,7 +5487,7 @@ var PerpetualsClient = (function () {
5229
5487
  if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
5230
5488
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5231
5489
  return __awaiter(_this, void 0, void 0, function () {
5232
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_24;
5490
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_26;
5233
5491
  return __generator(this, function (_b) {
5234
5492
  switch (_b.label) {
5235
5493
  case 0:
@@ -5290,9 +5548,9 @@ var PerpetualsClient = (function () {
5290
5548
  }
5291
5549
  return [3, 7];
5292
5550
  case 6:
5293
- err_24 = _b.sent();
5294
- console.log("perpClient forceClosePosition error:: ", err_24);
5295
- throw err_24;
5551
+ err_26 = _b.sent();
5552
+ console.log("perpClient forceClosePosition error:: ", err_26);
5553
+ throw err_26;
5296
5554
  case 7: return [2, {
5297
5555
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5298
5556
  additionalSigners: additionalSigners
@@ -5305,7 +5563,7 @@ var PerpetualsClient = (function () {
5305
5563
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5306
5564
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5307
5565
  return __awaiter(_this, void 0, void 0, function () {
5308
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_25;
5566
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_27;
5309
5567
  return __generator(this, function (_c) {
5310
5568
  switch (_c.label) {
5311
5569
  case 0:
@@ -5409,9 +5667,9 @@ var PerpetualsClient = (function () {
5409
5667
  instructions.push(placeLimitOrder);
5410
5668
  return [3, 11];
5411
5669
  case 10:
5412
- err_25 = _c.sent();
5413
- console.log("perpClient placeLimitOrder error:: ", err_25);
5414
- throw err_25;
5670
+ err_27 = _c.sent();
5671
+ console.log("perpClient placeLimitOrder error:: ", err_27);
5672
+ throw err_27;
5415
5673
  case 11: return [2, {
5416
5674
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5417
5675
  additionalSigners: additionalSigners
@@ -5420,11 +5678,11 @@ var PerpetualsClient = (function () {
5420
5678
  });
5421
5679
  });
5422
5680
  };
5423
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
5681
+ this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, receiveCustodyId, poolConfig, createUserATA, ephemeralSignerPubkey) {
5424
5682
  if (createUserATA === void 0) { createUserATA = true; }
5425
5683
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5426
5684
  return __awaiter(_this, void 0, void 0, function () {
5427
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_26;
5685
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_28;
5428
5686
  return __generator(this, function (_b) {
5429
5687
  switch (_b.label) {
5430
5688
  case 0:
@@ -5440,7 +5698,7 @@ var PerpetualsClient = (function () {
5440
5698
  _b.label = 1;
5441
5699
  case 1:
5442
5700
  _b.trys.push([1, 7, , 8]);
5443
- if (!(collateralSymbol == 'SOL')) return [3, 2];
5701
+ if (!(reserveSymbol == 'SOL')) return [3, 2];
5444
5702
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
5445
5703
  if (!ephemeralSignerPubkey) {
5446
5704
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -5461,7 +5719,7 @@ var PerpetualsClient = (function () {
5461
5719
  ];
5462
5720
  return [3, 5];
5463
5721
  case 2:
5464
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
5722
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true);
5465
5723
  _a = createUserATA;
5466
5724
  if (!_a) return [3, 4];
5467
5725
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -5470,7 +5728,7 @@ var PerpetualsClient = (function () {
5470
5728
  _b.label = 4;
5471
5729
  case 4:
5472
5730
  if (_a) {
5473
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5731
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey));
5474
5732
  }
5475
5733
  _b.label = 5;
5476
5734
  case 5:
@@ -5482,7 +5740,8 @@ var PerpetualsClient = (function () {
5482
5740
  limitPrice: limitPrice,
5483
5741
  sizeAmount: sizeAmount,
5484
5742
  stopLossPrice: stopLossPrice,
5485
- takeProfitPrice: takeProfitPrice
5743
+ takeProfitPrice: takeProfitPrice,
5744
+ receiveCustodyId: receiveCustodyId
5486
5745
  })
5487
5746
  .accounts({
5488
5747
  owner: publicKey,
@@ -5498,7 +5757,7 @@ var PerpetualsClient = (function () {
5498
5757
  reserveCustody: reserveCustodyConfig.custodyAccount,
5499
5758
  reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
5500
5759
  reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
5501
- receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
5760
+ receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
5502
5761
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5503
5762
  eventAuthority: this.eventAuthority.publicKey,
5504
5763
  program: this.programId,
@@ -5510,9 +5769,9 @@ var PerpetualsClient = (function () {
5510
5769
  instructions.push(editLimitOrder);
5511
5770
  return [3, 8];
5512
5771
  case 7:
5513
- err_26 = _b.sent();
5514
- console.log("perpClient editLimitOrder error:: ", err_26);
5515
- throw err_26;
5772
+ err_28 = _b.sent();
5773
+ console.log("perpClient editLimitOrder error:: ", err_28);
5774
+ throw err_28;
5516
5775
  case 8: return [2, {
5517
5776
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5518
5777
  additionalSigners: additionalSigners
@@ -5526,7 +5785,7 @@ var PerpetualsClient = (function () {
5526
5785
  if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
5527
5786
  if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
5528
5787
  return __awaiter(_this, void 0, void 0, function () {
5529
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_27;
5788
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_29;
5530
5789
  return __generator(this, function (_a) {
5531
5790
  switch (_a.label) {
5532
5791
  case 0:
@@ -5572,9 +5831,89 @@ var PerpetualsClient = (function () {
5572
5831
  instructions.push(executeLimitOrder);
5573
5832
  return [3, 4];
5574
5833
  case 3:
5575
- err_27 = _a.sent();
5576
- console.log("perpClient executeLimitOrder error:: ", err_27);
5577
- throw err_27;
5834
+ err_29 = _a.sent();
5835
+ console.log("perpClient executeLimitOrder error:: ", err_29);
5836
+ throw err_29;
5837
+ case 4: return [2, {
5838
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5839
+ additionalSigners: additionalSigners
5840
+ }];
5841
+ }
5842
+ });
5843
+ });
5844
+ };
5845
+ this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
5846
+ if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
5847
+ if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
5848
+ if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
5849
+ return __awaiter(_this, void 0, void 0, function () {
5850
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody, positionAccount, orderAccount, executeLimitWithSwap, err_30;
5851
+ return __generator(this, function (_b) {
5852
+ switch (_b.label) {
5853
+ case 0:
5854
+ publicKey = this.provider.wallet.publicKey;
5855
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5856
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5857
+ reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
5858
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5859
+ preInstructions = [];
5860
+ instructions = [];
5861
+ postInstructions = [];
5862
+ additionalSigners = [];
5863
+ custodyAccountMetas = [];
5864
+ custodyOracleAccountMetas = [];
5865
+ for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
5866
+ custody = _a[_i];
5867
+ custodyAccountMetas.push({
5868
+ pubkey: custody.custodyAccount,
5869
+ isSigner: false,
5870
+ isWritable: false,
5871
+ });
5872
+ custodyOracleAccountMetas.push({
5873
+ pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
5874
+ isSigner: false,
5875
+ isWritable: false,
5876
+ });
5877
+ }
5878
+ _b.label = 1;
5879
+ case 1:
5880
+ _b.trys.push([1, 3, , 4]);
5881
+ positionAccount = poolConfig.getPositionFromMarketPk(userPubkey, marketAccount);
5882
+ orderAccount = poolConfig.getOrderFromMarketPk(userPubkey, marketAccount);
5883
+ return [4, this.program.methods
5884
+ .executeLimitWithSwap({
5885
+ orderId: orderId,
5886
+ privilege: privilege
5887
+ })
5888
+ .accounts({
5889
+ feePayer: publicKey,
5890
+ perpetuals: poolConfig.perpetuals,
5891
+ pool: poolConfig.poolAddress,
5892
+ reserveCustody: reserveCustodyConfig.custodyAccount,
5893
+ reserveCustodyOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
5894
+ position: positionAccount,
5895
+ order: orderAccount,
5896
+ market: marketAccount,
5897
+ targetCustody: targetCustodyConfig.custodyAccount,
5898
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5899
+ collateralCustody: collateralCustodyConfig.custodyAccount,
5900
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5901
+ systemProgram: web3_js_1.SystemProgram.programId,
5902
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5903
+ eventAuthority: this.eventAuthority.publicKey,
5904
+ program: this.programId,
5905
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5906
+ })
5907
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
5908
+ .instruction()];
5909
+ case 2:
5910
+ executeLimitWithSwap = _b.sent();
5911
+ instructions.push(executeLimitWithSwap);
5912
+ return [3, 4];
5913
+ case 3:
5914
+ err_30 = _b.sent();
5915
+ console.log("perpClient executeLimitWithSwap error:: ", err_30);
5916
+ throw err_30;
5578
5917
  case 4: return [2, {
5579
5918
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5580
5919
  additionalSigners: additionalSigners
@@ -5584,7 +5923,7 @@ var PerpetualsClient = (function () {
5584
5923
  });
5585
5924
  };
5586
5925
  this.placeTriggerOrder = function (targetSymbol, collateralSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, receiveCustodyId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5587
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_28;
5926
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_31;
5588
5927
  return __generator(this, function (_a) {
5589
5928
  switch (_a.label) {
5590
5929
  case 0:
@@ -5631,9 +5970,9 @@ var PerpetualsClient = (function () {
5631
5970
  instructions.push(placeTriggerOrder);
5632
5971
  return [3, 4];
5633
5972
  case 3:
5634
- err_28 = _a.sent();
5635
- console.log("perpClient placeTriggerOrder error:: ", err_28);
5636
- throw err_28;
5973
+ err_31 = _a.sent();
5974
+ console.log("perpClient placeTriggerOrder error:: ", err_31);
5975
+ throw err_31;
5637
5976
  case 4: return [2, {
5638
5977
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5639
5978
  additionalSigners: additionalSigners
@@ -5642,7 +5981,7 @@ var PerpetualsClient = (function () {
5642
5981
  });
5643
5982
  }); };
5644
5983
  this.editTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5645
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_29;
5984
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_32;
5646
5985
  return __generator(this, function (_a) {
5647
5986
  switch (_a.label) {
5648
5987
  case 0:
@@ -5687,9 +6026,9 @@ var PerpetualsClient = (function () {
5687
6026
  instructions.push(editTriggerOrder);
5688
6027
  return [3, 4];
5689
6028
  case 3:
5690
- err_29 = _a.sent();
5691
- console.log("perpClient editTriggerOrder error:: ", err_29);
5692
- throw err_29;
6029
+ err_32 = _a.sent();
6030
+ console.log("perpClient editTriggerOrder error:: ", err_32);
6031
+ throw err_32;
5693
6032
  case 4: return [2, {
5694
6033
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5695
6034
  additionalSigners: additionalSigners
@@ -5698,7 +6037,7 @@ var PerpetualsClient = (function () {
5698
6037
  });
5699
6038
  }); };
5700
6039
  this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5701
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_30;
6040
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_33;
5702
6041
  return __generator(this, function (_a) {
5703
6042
  switch (_a.label) {
5704
6043
  case 0:
@@ -5731,9 +6070,9 @@ var PerpetualsClient = (function () {
5731
6070
  instructions.push(cancelTriggerOrder);
5732
6071
  return [3, 4];
5733
6072
  case 3:
5734
- err_30 = _a.sent();
5735
- console.log("perpClient cancelTriggerOrder error:: ", err_30);
5736
- throw err_30;
6073
+ err_33 = _a.sent();
6074
+ console.log("perpClient cancelTriggerOrder error:: ", err_33);
6075
+ throw err_33;
5737
6076
  case 4: return [2, {
5738
6077
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5739
6078
  additionalSigners: additionalSigners
@@ -5741,11 +6080,121 @@ var PerpetualsClient = (function () {
5741
6080
  }
5742
6081
  });
5743
6082
  }); };
6083
+ this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, poolConfig, createUserATA, ephemeralSignerPubkey) {
6084
+ if (createUserATA === void 0) { createUserATA = true; }
6085
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6086
+ return __awaiter(_this, void 0, void 0, function () {
6087
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_34;
6088
+ return __generator(this, function (_d) {
6089
+ switch (_d.label) {
6090
+ case 0:
6091
+ payerPubkey = this.provider.wallet.publicKey;
6092
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
6093
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
6094
+ receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey); });
6095
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
6096
+ preInstructions = [];
6097
+ instructions = [];
6098
+ postInstructions = [];
6099
+ additionalSigners = [];
6100
+ _d.label = 1;
6101
+ case 1:
6102
+ _d.trys.push([1, 9, , 10]);
6103
+ if (!false) return [3, 2];
6104
+ return [3, 7];
6105
+ case 2:
6106
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true);
6107
+ _a = createUserATA;
6108
+ if (!_a) return [3, 4];
6109
+ return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
6110
+ case 3:
6111
+ _a = !(_d.sent());
6112
+ _d.label = 4;
6113
+ case 4:
6114
+ if (_a) {
6115
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
6116
+ }
6117
+ userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
6118
+ _b = createUserATA;
6119
+ if (!_b) return [3, 6];
6120
+ return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
6121
+ case 5:
6122
+ _b = !(_d.sent());
6123
+ _d.label = 6;
6124
+ case 6:
6125
+ if (_b) {
6126
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6127
+ }
6128
+ _d.label = 7;
6129
+ case 7:
6130
+ positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
6131
+ orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
6132
+ custodyAccountMetas = [];
6133
+ custodyOracleAccountMetas = [];
6134
+ for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
6135
+ custody = _c[_i];
6136
+ custodyAccountMetas.push({
6137
+ pubkey: custody.custodyAccount,
6138
+ isSigner: false,
6139
+ isWritable: false,
6140
+ });
6141
+ custodyOracleAccountMetas.push({
6142
+ pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
6143
+ isSigner: false,
6144
+ isWritable: false,
6145
+ });
6146
+ }
6147
+ return [4, this.program.methods
6148
+ .executeTriggerWithSwap({
6149
+ isStopLoss: isStopLoss,
6150
+ orderId: orderId
6151
+ })
6152
+ .accounts({
6153
+ feePayer: payerPubkey,
6154
+ receivingAccount: userReceivingTokenAccount,
6155
+ collateralAccount: userReceivingTokenAccountCollateral,
6156
+ transferAuthority: poolConfig.transferAuthority,
6157
+ perpetuals: poolConfig.perpetuals,
6158
+ pool: poolConfig.poolAddress,
6159
+ position: positionAccount,
6160
+ order: orderAccount,
6161
+ market: marketAccount,
6162
+ targetCustody: targetCustodyConfig.custodyAccount,
6163
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
6164
+ collateralCustody: collateralCustodyConfig.custodyAccount,
6165
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
6166
+ collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
6167
+ dispensingCustody: receivingCustodyConfig.custodyAccount,
6168
+ dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
6169
+ dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
6170
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6171
+ eventAuthority: this.eventAuthority.publicKey,
6172
+ program: this.programId,
6173
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6174
+ })
6175
+ .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
6176
+ .instruction()];
6177
+ case 8:
6178
+ executeTriggerWithSwap = _d.sent();
6179
+ instructions.push(executeTriggerWithSwap);
6180
+ return [3, 10];
6181
+ case 9:
6182
+ err_34 = _d.sent();
6183
+ console.log("perpClient executeTriggerWithSwap error:: ", err_34);
6184
+ throw err_34;
6185
+ case 10: return [2, {
6186
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6187
+ additionalSigners: additionalSigners
6188
+ }];
6189
+ }
6190
+ });
6191
+ });
6192
+ };
5744
6193
  this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig, createUserATA, ephemeralSignerPubkey) {
5745
6194
  if (createUserATA === void 0) { createUserATA = true; }
5746
6195
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5747
6196
  return __awaiter(_this, void 0, void 0, function () {
5748
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_31;
6197
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_35;
5749
6198
  return __generator(this, function (_b) {
5750
6199
  switch (_b.label) {
5751
6200
  case 0:
@@ -5808,9 +6257,9 @@ var PerpetualsClient = (function () {
5808
6257
  instructions.push(executeTriggerOrder);
5809
6258
  return [3, 8];
5810
6259
  case 7:
5811
- err_31 = _b.sent();
5812
- console.log("perpClient executeTriggerOrder error:: ", err_31);
5813
- throw err_31;
6260
+ err_35 = _b.sent();
6261
+ console.log("perpClient executeTriggerOrder error:: ", err_35);
6262
+ throw err_35;
5814
6263
  case 8: return [2, {
5815
6264
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5816
6265
  additionalSigners: additionalSigners
@@ -5819,15 +6268,12 @@ var PerpetualsClient = (function () {
5819
6268
  });
5820
6269
  });
5821
6270
  };
5822
- this.migrateTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5823
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_32;
6271
+ this.migrateTriggerOrder = function (owner, marketAccount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6272
+ var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_36;
5824
6273
  return __generator(this, function (_a) {
5825
6274
  switch (_a.label) {
5826
6275
  case 0:
5827
6276
  payerPubkey = this.provider.wallet.publicKey;
5828
- targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5829
- collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5830
- marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5831
6277
  preInstructions = [];
5832
6278
  instructions = [];
5833
6279
  postInstructions = [];
@@ -5853,9 +6299,9 @@ var PerpetualsClient = (function () {
5853
6299
  instructions.push(migrateTriggerOrder);
5854
6300
  return [3, 4];
5855
6301
  case 3:
5856
- err_32 = _a.sent();
5857
- console.log("perpClient migrateTriggerOrder error:: ", err_32);
5858
- throw err_32;
6302
+ err_36 = _a.sent();
6303
+ console.log("perpClient migrateTriggerOrder error:: ", err_36);
6304
+ throw err_36;
5859
6305
  case 4: return [2, {
5860
6306
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5861
6307
  additionalSigners: additionalSigners
@@ -5864,7 +6310,7 @@ var PerpetualsClient = (function () {
5864
6310
  });
5865
6311
  }); };
5866
6312
  this.getPositionData = function (position, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5867
- var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData, err_33;
6313
+ var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData, err_37;
5868
6314
  return __generator(this, function (_a) {
5869
6315
  switch (_a.label) {
5870
6316
  case 0:
@@ -5893,15 +6339,15 @@ var PerpetualsClient = (function () {
5893
6339
  console.log(getPositionData);
5894
6340
  return [2, getPositionData];
5895
6341
  case 3:
5896
- err_33 = _a.sent();
5897
- console.log("perpClient setPool error:: ", err_33);
5898
- throw err_33;
6342
+ err_37 = _a.sent();
6343
+ console.log("perpClient setPool error:: ", err_37);
6344
+ throw err_37;
5899
6345
  case 4: return [2];
5900
6346
  }
5901
6347
  });
5902
6348
  }); };
5903
6349
  this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5904
- var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_34;
6350
+ var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_38;
5905
6351
  return __generator(this, function (_a) {
5906
6352
  switch (_a.label) {
5907
6353
  case 0:
@@ -5934,9 +6380,9 @@ var PerpetualsClient = (function () {
5934
6380
  instructions.push(withdrawFeesIx);
5935
6381
  return [3, 5];
5936
6382
  case 4:
5937
- err_34 = _a.sent();
5938
- console.log("perpClient setPool error:: ", err_34);
5939
- throw err_34;
6383
+ err_38 = _a.sent();
6384
+ console.log("perpClient setPool error:: ", err_38);
6385
+ throw err_38;
5940
6386
  case 5: return [2, {
5941
6387
  instructions: __spreadArray([], instructions, true),
5942
6388
  additionalSigners: additionalSigners
@@ -5945,7 +6391,7 @@ var PerpetualsClient = (function () {
5945
6391
  });
5946
6392
  }); };
5947
6393
  this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
5948
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_35;
6394
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_39;
5949
6395
  return __generator(this, function (_a) {
5950
6396
  switch (_a.label) {
5951
6397
  case 0:
@@ -5972,9 +6418,9 @@ var PerpetualsClient = (function () {
5972
6418
  instructions.push(setPermissionsInstruction);
5973
6419
  return [3, 4];
5974
6420
  case 3:
5975
- err_35 = _a.sent();
5976
- console.log("perpClient setPool error:: ", err_35);
5977
- throw err_35;
6421
+ err_39 = _a.sent();
6422
+ console.log("perpClient setPool error:: ", err_39);
6423
+ throw err_39;
5978
6424
  case 4: return [2, {
5979
6425
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5980
6426
  additionalSigners: additionalSigners
@@ -5983,7 +6429,7 @@ var PerpetualsClient = (function () {
5983
6429
  });
5984
6430
  }); };
5985
6431
  this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5986
- var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_36;
6432
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_40;
5987
6433
  var _f;
5988
6434
  return __generator(this, function (_g) {
5989
6435
  switch (_g.label) {
@@ -6043,9 +6489,9 @@ var PerpetualsClient = (function () {
6043
6489
  instructions.push(reimburse);
6044
6490
  return [3, 5];
6045
6491
  case 4:
6046
- err_36 = _g.sent();
6047
- console.log("perpClient setPool error:: ", err_36);
6048
- throw err_36;
6492
+ err_40 = _g.sent();
6493
+ console.log("perpClient setPool error:: ", err_40);
6494
+ throw err_40;
6049
6495
  case 5: return [2, {
6050
6496
  instructions: __spreadArray([], instructions, true),
6051
6497
  additionalSigners: additionalSigners
@@ -6054,7 +6500,7 @@ var PerpetualsClient = (function () {
6054
6500
  });
6055
6501
  }); };
6056
6502
  this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6057
- var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_37;
6503
+ var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_41;
6058
6504
  return __generator(this, function (_a) {
6059
6505
  switch (_a.label) {
6060
6506
  case 0:
@@ -6087,9 +6533,9 @@ var PerpetualsClient = (function () {
6087
6533
  instructions.push(setInternalOraclePrice);
6088
6534
  return [3, 4];
6089
6535
  case 3:
6090
- err_37 = _a.sent();
6091
- console.log("perpClient setInternalOracleAccount error:: ", err_37);
6092
- throw err_37;
6536
+ err_41 = _a.sent();
6537
+ console.log("perpClient setInternalOracleAccount error:: ", err_41);
6538
+ throw err_41;
6093
6539
  case 4: return [2, {
6094
6540
  instructions: __spreadArray([], instructions, true),
6095
6541
  additionalSigners: additionalSigners
@@ -6101,7 +6547,7 @@ var PerpetualsClient = (function () {
6101
6547
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6102
6548
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6103
6549
  return __awaiter(_this, void 0, void 0, function () {
6104
- var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_38;
6550
+ var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_42;
6105
6551
  return __generator(this, function (_e) {
6106
6552
  switch (_e.label) {
6107
6553
  case 0:
@@ -6224,8 +6670,8 @@ var PerpetualsClient = (function () {
6224
6670
  instructions.push(addCompoundingLiquidity);
6225
6671
  return [3, 10];
6226
6672
  case 9:
6227
- err_38 = _e.sent();
6228
- console.log("perpClient addCompoundingLiquidity error:: ", err_38);
6673
+ err_42 = _e.sent();
6674
+ console.log("perpClient addCompoundingLiquidity error:: ", err_42);
6229
6675
  return [3, 10];
6230
6676
  case 10: return [2, {
6231
6677
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -6239,7 +6685,7 @@ var PerpetualsClient = (function () {
6239
6685
  if (createUserATA === void 0) { createUserATA = true; }
6240
6686
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6241
6687
  return __awaiter(_this, void 0, void 0, function () {
6242
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_39;
6688
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_43;
6243
6689
  return __generator(this, function (_e) {
6244
6690
  switch (_e.label) {
6245
6691
  case 0:
@@ -6346,8 +6792,8 @@ var PerpetualsClient = (function () {
6346
6792
  instructions.push(removeCompoundingLiquidity);
6347
6793
  return [3, 8];
6348
6794
  case 7:
6349
- err_39 = _e.sent();
6350
- console.log("perpClient removeCompoundingLiquidity error:: ", err_39);
6795
+ err_43 = _e.sent();
6796
+ console.log("perpClient removeCompoundingLiquidity error:: ", err_43);
6351
6797
  return [3, 8];
6352
6798
  case 8: return [2, {
6353
6799
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -6360,7 +6806,7 @@ var PerpetualsClient = (function () {
6360
6806
  this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
6361
6807
  if (createUserATA === void 0) { createUserATA = true; }
6362
6808
  return __awaiter(_this, void 0, void 0, function () {
6363
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, migrateStake, err_40;
6809
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, migrateStake, err_44;
6364
6810
  return __generator(this, function (_e) {
6365
6811
  switch (_e.label) {
6366
6812
  case 0:
@@ -6441,8 +6887,8 @@ var PerpetualsClient = (function () {
6441
6887
  instructions.push(migrateStake);
6442
6888
  return [3, 6];
6443
6889
  case 5:
6444
- err_40 = _e.sent();
6445
- console.log("perpClient migrateStake error:: ", err_40);
6890
+ err_44 = _e.sent();
6891
+ console.log("perpClient migrateStake error:: ", err_44);
6446
6892
  return [3, 6];
6447
6893
  case 6: return [2, {
6448
6894
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -6453,7 +6899,7 @@ var PerpetualsClient = (function () {
6453
6899
  });
6454
6900
  };
6455
6901
  this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6456
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_41;
6902
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_45;
6457
6903
  return __generator(this, function (_d) {
6458
6904
  switch (_d.label) {
6459
6905
  case 0:
@@ -6525,8 +6971,8 @@ var PerpetualsClient = (function () {
6525
6971
  instructions.push(migrateFlp);
6526
6972
  return [3, 4];
6527
6973
  case 3:
6528
- err_41 = _d.sent();
6529
- console.log("perpClient migrateFlp error:: ", err_41);
6974
+ err_45 = _d.sent();
6975
+ console.log("perpClient migrateFlp error:: ", err_45);
6530
6976
  return [3, 4];
6531
6977
  case 4: return [2, {
6532
6978
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -6538,7 +6984,7 @@ var PerpetualsClient = (function () {
6538
6984
  this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
6539
6985
  if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
6540
6986
  return __awaiter(_this, void 0, void 0, function () {
6541
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_42;
6987
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_46;
6542
6988
  return __generator(this, function (_d) {
6543
6989
  switch (_d.label) {
6544
6990
  case 0:
@@ -6595,8 +7041,8 @@ var PerpetualsClient = (function () {
6595
7041
  instructions.push(compoundingFee);
6596
7042
  return [3, 4];
6597
7043
  case 3:
6598
- err_42 = _d.sent();
6599
- console.log("perpClient compoundingFee error:: ", err_42);
7044
+ err_46 = _d.sent();
7045
+ console.log("perpClient compoundingFee error:: ", err_46);
6600
7046
  return [3, 4];
6601
7047
  case 4: return [2, {
6602
7048
  instructions: __spreadArray([], instructions, true),
@@ -6607,7 +7053,7 @@ var PerpetualsClient = (function () {
6607
7053
  });
6608
7054
  };
6609
7055
  this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6610
- var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_43;
7056
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_47;
6611
7057
  return __generator(this, function (_a) {
6612
7058
  switch (_a.label) {
6613
7059
  case 0:
@@ -6645,8 +7091,8 @@ var PerpetualsClient = (function () {
6645
7091
  instructions.push(renameFlp);
6646
7092
  return [3, 4];
6647
7093
  case 3:
6648
- err_43 = _a.sent();
6649
- console.log("perpClient renameFlp error:: ", err_43);
7094
+ err_47 = _a.sent();
7095
+ console.log("perpClient renameFlp error:: ", err_47);
6650
7096
  return [3, 4];
6651
7097
  case 4: return [2, {
6652
7098
  instructions: __spreadArray([], instructions, true),
@@ -6656,7 +7102,7 @@ var PerpetualsClient = (function () {
6656
7102
  });
6657
7103
  }); };
6658
7104
  this.initRewardDistribution = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6659
- var publicKey, rewardMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, transferAuthority, initRewardVault, err_44;
7105
+ var publicKey, rewardMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, transferAuthority, initRewardVault, err_48;
6660
7106
  return __generator(this, function (_a) {
6661
7107
  switch (_a.label) {
6662
7108
  case 0:
@@ -6690,9 +7136,9 @@ var PerpetualsClient = (function () {
6690
7136
  instructions.push(initRewardVault);
6691
7137
  return [3, 4];
6692
7138
  case 3:
6693
- err_44 = _a.sent();
6694
- console.log("rewardDistribution InitRewardVault error:: ", err_44);
6695
- throw err_44;
7139
+ err_48 = _a.sent();
7140
+ console.log("rewardDistribution InitRewardVault error:: ", err_48);
7141
+ throw err_48;
6696
7142
  case 4: return [2, {
6697
7143
  instructions: __spreadArray([], instructions, true),
6698
7144
  additionalSigners: additionalSigners
@@ -6701,7 +7147,7 @@ var PerpetualsClient = (function () {
6701
7147
  });
6702
7148
  }); };
6703
7149
  this.updateCounterReward = function () { return __awaiter(_this, void 0, void 0, function () {
6704
- var publicKey, instructions, additionalSigners, rewardVault, updateCounter, err_45;
7150
+ var publicKey, instructions, additionalSigners, rewardVault, updateCounter, err_49;
6705
7151
  return __generator(this, function (_a) {
6706
7152
  switch (_a.label) {
6707
7153
  case 0:
@@ -6724,9 +7170,9 @@ var PerpetualsClient = (function () {
6724
7170
  instructions.push(updateCounter);
6725
7171
  return [3, 4];
6726
7172
  case 3:
6727
- err_45 = _a.sent();
6728
- console.log("rewardDistribution updateCounter error:: ", err_45);
6729
- throw err_45;
7173
+ err_49 = _a.sent();
7174
+ console.log("rewardDistribution updateCounter error:: ", err_49);
7175
+ throw err_49;
6730
7176
  case 4: return [2, {
6731
7177
  instructions: __spreadArray([], instructions, true),
6732
7178
  additionalSigners: additionalSigners
@@ -6735,7 +7181,7 @@ var PerpetualsClient = (function () {
6735
7181
  });
6736
7182
  }); };
6737
7183
  this.rewardDistribution = function (counter, owner, rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6738
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_46;
7184
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_50;
6739
7185
  return __generator(this, function (_a) {
6740
7186
  switch (_a.label) {
6741
7187
  case 0:
@@ -6774,9 +7220,9 @@ var PerpetualsClient = (function () {
6774
7220
  instructions.push(distributeReward);
6775
7221
  return [3, 4];
6776
7222
  case 3:
6777
- err_46 = _a.sent();
6778
- console.log("rewardDistribution distributeReward error:: ", err_46);
6779
- throw err_46;
7223
+ err_50 = _a.sent();
7224
+ console.log("rewardDistribution distributeReward error:: ", err_50);
7225
+ throw err_50;
6780
7226
  case 4: return [2, {
6781
7227
  instructions: __spreadArray([], instructions, true),
6782
7228
  additionalSigners: additionalSigners
@@ -6787,7 +7233,7 @@ var PerpetualsClient = (function () {
6787
7233
  this.collectReward = function (counter, owner, rewardSymbol, poolConfig, createUserATA) {
6788
7234
  if (createUserATA === void 0) { createUserATA = true; }
6789
7235
  return __awaiter(_this, void 0, void 0, function () {
6790
- var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_47;
7236
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_51;
6791
7237
  return __generator(this, function (_b) {
6792
7238
  switch (_b.label) {
6793
7239
  case 0:
@@ -6835,8 +7281,8 @@ var PerpetualsClient = (function () {
6835
7281
  instructions.push(collectRaffleReward);
6836
7282
  return [3, 6];
6837
7283
  case 5:
6838
- err_47 = _b.sent();
6839
- throw err_47;
7284
+ err_51 = _b.sent();
7285
+ throw err_51;
6840
7286
  case 6: return [2, {
6841
7287
  instructions: __spreadArray([], instructions, true),
6842
7288
  additionalSigners: additionalSigners