flash-sdk 2.16.3 → 2.17.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.
@@ -4981,7 +4981,7 @@ var PerpetualsClient = (function () {
4981
4981
  if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4982
4982
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4983
4983
  return __awaiter(_this, void 0, void 0, function () {
4984
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, forceClosePosition, closeWsolATAIns, err_24;
4984
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_24;
4985
4985
  return __generator(this, function (_b) {
4986
4986
  switch (_b.label) {
4987
4987
  case 0:
@@ -4995,78 +4995,632 @@ var PerpetualsClient = (function () {
4995
4995
  additionalSigners = [];
4996
4996
  _b.label = 1;
4997
4997
  case 1:
4998
- _b.trys.push([1, 7, , 8]);
4999
- if (!(collateralSymbol == 'SOL')) return [3, 2];
4998
+ _b.trys.push([1, 6, , 7]);
4999
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner)];
5000
+ case 2:
5001
+ userReceivingTokenAccount = _b.sent();
5002
+ _a = createUserATA;
5003
+ if (!_a) return [3, 4];
5004
+ return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5005
+ case 3:
5006
+ _a = !(_b.sent());
5007
+ _b.label = 4;
5008
+ case 4:
5009
+ if (_a) {
5010
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5011
+ }
5012
+ return [4, this.program.methods
5013
+ .forceClosePosition({
5014
+ isStopLoss: isStopLoss
5015
+ })
5016
+ .accounts({
5017
+ owner: positionAccount.owner,
5018
+ receivingAccount: userReceivingTokenAccount,
5019
+ transferAuthority: poolConfig.transferAuthority,
5020
+ perpetuals: this.perpetuals.publicKey,
5021
+ pool: poolConfig.poolAddress,
5022
+ position: positionAccount.publicKey,
5023
+ market: marketAccount,
5024
+ targetCustody: targetCustodyConfig.custodyAccount,
5025
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5026
+ collateralCustody: collateralCustodyConfig.custodyAccount,
5027
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5028
+ collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
5029
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5030
+ eventAuthority: this.eventAuthority.publicKey,
5031
+ program: this.programId,
5032
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5033
+ })
5034
+ .instruction()];
5035
+ case 5:
5036
+ forceClosePosition = _b.sent();
5037
+ instructions.push(forceClosePosition);
5038
+ if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
5039
+ closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
5040
+ postInstructions.push(closeWsolATAIns);
5041
+ }
5042
+ return [3, 7];
5043
+ case 6:
5044
+ err_24 = _b.sent();
5045
+ console.log("perpClient forceClosePosition error:: ", err_24);
5046
+ throw err_24;
5047
+ case 7: return [2, {
5048
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5049
+ additionalSigners: additionalSigners
5050
+ }];
5051
+ }
5052
+ });
5053
+ });
5054
+ };
5055
+ this.forceClosePartial = function (positionAccount, targetSymbol, collateralSymbol, side, priceWithSlippage, sizeDelta, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA) {
5056
+ if (createUserATA === void 0) { createUserATA = true; }
5057
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
5058
+ return __awaiter(_this, void 0, void 0, function () {
5059
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePartial, closeWsolATAIns, err_25;
5060
+ return __generator(this, function (_b) {
5061
+ switch (_b.label) {
5062
+ case 0:
5063
+ payerPubkey = this.provider.wallet.publicKey;
5064
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5065
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5066
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5067
+ preInstructions = [];
5068
+ instructions = [];
5069
+ postInstructions = [];
5070
+ additionalSigners = [];
5071
+ _b.label = 1;
5072
+ case 1:
5073
+ _b.trys.push([1, 6, , 7]);
5074
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner)];
5075
+ case 2:
5076
+ userReceivingTokenAccount = _b.sent();
5077
+ _a = createUserATA;
5078
+ if (!_a) return [3, 4];
5079
+ return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5080
+ case 3:
5081
+ _a = !(_b.sent());
5082
+ _b.label = 4;
5083
+ case 4:
5084
+ if (_a) {
5085
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5086
+ }
5087
+ return [4, this.program.methods
5088
+ .forceClosePartial({
5089
+ priceWithSlippage: priceWithSlippage,
5090
+ sizeDelta: sizeDelta,
5091
+ isStopLoss: isStopLoss
5092
+ })
5093
+ .accounts({
5094
+ owner: positionAccount.owner,
5095
+ receivingAccount: userReceivingTokenAccount,
5096
+ transferAuthority: poolConfig.transferAuthority,
5097
+ perpetuals: this.perpetuals.publicKey,
5098
+ pool: poolConfig.poolAddress,
5099
+ position: positionAccount.publicKey,
5100
+ market: marketAccount,
5101
+ targetCustody: targetCustodyConfig.custodyAccount,
5102
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5103
+ collateralCustody: collateralCustodyConfig.custodyAccount,
5104
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5105
+ collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
5106
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5107
+ eventAuthority: this.eventAuthority.publicKey,
5108
+ program: this.programId,
5109
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5110
+ })
5111
+ .instruction()];
5112
+ case 5:
5113
+ forceClosePartial = _b.sent();
5114
+ instructions.push(forceClosePartial);
5115
+ if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
5116
+ closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
5117
+ postInstructions.push(closeWsolATAIns);
5118
+ }
5119
+ return [3, 7];
5120
+ case 6:
5121
+ err_25 = _b.sent();
5122
+ console.log("perpClient forceClosePartial error:: ", err_25);
5123
+ throw err_25;
5124
+ case 7: return [2, {
5125
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5126
+ additionalSigners: additionalSigners
5127
+ }];
5128
+ }
5129
+ });
5130
+ });
5131
+ };
5132
+ this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, receiveCustodyId, poolConfig, skipBalanceChecks) {
5133
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5134
+ return __awaiter(_this, void 0, void 0, function () {
5135
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_26;
5136
+ return __generator(this, function (_c) {
5137
+ switch (_c.label) {
5138
+ case 0:
5139
+ publicKey = this.provider.wallet.publicKey;
5140
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5141
+ reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
5142
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5143
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5144
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey)];
5145
+ case 1:
5146
+ userReserveTokenAccount = _c.sent();
5147
+ preInstructions = [];
5148
+ instructions = [];
5149
+ postInstructions = [];
5150
+ additionalSigners = [];
5151
+ _c.label = 2;
5152
+ case 2:
5153
+ _c.trys.push([2, 10, , 11]);
5154
+ if (!(reserveSymbol == 'SOL')) return [3, 5];
5155
+ console.log("reserveSymbol === SOL", reserveSymbol);
5156
+ wrappedSolAccount = new web3_js_1.Keypair();
5157
+ return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
5158
+ case 3:
5159
+ accCreationLamports = (_c.sent());
5160
+ console.log("accCreationLamports:", accCreationLamports);
5161
+ lamports = reserveAmount.add(new anchor_1.BN(accCreationLamports));
5162
+ _a = anchor_1.BN.bind;
5163
+ return [4, this.provider.connection.getBalance(publicKey)];
5164
+ case 4:
5165
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
5166
+ if (unWrappedSolBalance.lt(lamports)) {
5167
+ throw "Insufficient SOL Funds";
5168
+ }
5169
+ preInstructions = [
5170
+ web3_js_1.SystemProgram.createAccount({
5171
+ fromPubkey: publicKey,
5172
+ newAccountPubkey: wrappedSolAccount.publicKey,
5173
+ lamports: lamports.toNumber(),
5174
+ space: 165,
5175
+ programId: spl_token_1.TOKEN_PROGRAM_ID,
5176
+ }),
5177
+ (0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
5178
+ ];
5179
+ postInstructions = [
5180
+ (0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
5181
+ ];
5182
+ additionalSigners.push(wrappedSolAccount);
5183
+ return [3, 8];
5184
+ case 5: return [4, (0, utils_1.checkIfAccountExists)(userReserveTokenAccount, this.provider.connection)];
5185
+ case 6:
5186
+ if (!(_c.sent())) {
5187
+ throw "Insufficient Funds , token Account doesn't exist";
5188
+ }
5189
+ if (!!skipBalanceChecks) return [3, 8];
5190
+ _b = anchor_1.BN.bind;
5191
+ return [4, this.provider.connection.getTokenAccountBalance(userReserveTokenAccount)];
5192
+ case 7:
5193
+ tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
5194
+ if (tokenAccountBalance.lt(reserveAmount)) {
5195
+ throw "Insufficient Funds need more ".concat(reserveAmount.sub(tokenAccountBalance), " tokens");
5196
+ }
5197
+ _c.label = 8;
5198
+ case 8:
5199
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5200
+ orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5201
+ return [4, this.program.methods
5202
+ .placeLimitOrder({
5203
+ limitPrice: limitPrice,
5204
+ reserveAmount: reserveAmount,
5205
+ sizeAmount: sizeAmount,
5206
+ stopLossPrice: stopLossPrice,
5207
+ takeProfitPrice: takeProfitPrice,
5208
+ receiveCustodyId: receiveCustodyId
5209
+ })
5210
+ .accounts({
5211
+ owner: publicKey,
5212
+ feePayer: publicKey,
5213
+ fundingAccount: reserveSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReserveTokenAccount,
5214
+ perpetuals: poolConfig.perpetuals,
5215
+ pool: poolConfig.poolAddress,
5216
+ position: positionAccount,
5217
+ order: orderAccount,
5218
+ market: marketAccount,
5219
+ targetCustody: targetCustodyConfig.custodyAccount,
5220
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5221
+ reserveCustody: reserveCustodyConfig.custodyAccount,
5222
+ reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
5223
+ reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
5224
+ systemProgram: web3_js_1.SystemProgram.programId,
5225
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5226
+ eventAuthority: this.eventAuthority.publicKey,
5227
+ program: this.programId,
5228
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5229
+ })
5230
+ .instruction()];
5231
+ case 9:
5232
+ placeLimitOrder = _c.sent();
5233
+ instructions.push(placeLimitOrder);
5234
+ return [3, 11];
5235
+ case 10:
5236
+ err_26 = _c.sent();
5237
+ console.log("perpClient placeLimitOrder error:: ", err_26);
5238
+ throw err_26;
5239
+ case 11: return [2, {
5240
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5241
+ additionalSigners: additionalSigners
5242
+ }];
5243
+ }
5244
+ });
5245
+ });
5246
+ };
5247
+ this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
5248
+ if (createUserATA === void 0) { createUserATA = true; }
5249
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5250
+ return __awaiter(_this, void 0, void 0, function () {
5251
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_27;
5252
+ return __generator(this, function (_b) {
5253
+ switch (_b.label) {
5254
+ case 0:
5255
+ publicKey = this.provider.wallet.publicKey;
5256
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5257
+ reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
5258
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5259
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5260
+ preInstructions = [];
5261
+ instructions = [];
5262
+ postInstructions = [];
5263
+ additionalSigners = [];
5264
+ _b.label = 1;
5265
+ case 1:
5266
+ _b.trys.push([1, 8, , 9]);
5267
+ if (!(collateralSymbol == 'SOL')) return [3, 3];
5000
5268
  console.log("collateralSymbol === SOL", collateralSymbol);
5001
- lamports = this.minimumBalanceForRentExemptAccountLamports;
5269
+ wrappedSolAccount = new web3_js_1.Keypair();
5270
+ return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
5271
+ case 2:
5272
+ accCreationLamports = (_b.sent());
5273
+ console.log("accCreationLamports:", accCreationLamports);
5274
+ lamports = accCreationLamports;
5002
5275
  if (!ephemeralSignerPubkey) {
5003
5276
  wrappedSolAccount = new web3_js_1.Keypair();
5004
5277
  additionalSigners.push(wrappedSolAccount);
5005
5278
  }
5006
5279
  preInstructions = [
5007
5280
  web3_js_1.SystemProgram.createAccount({
5008
- fromPubkey: payerPubkey,
5281
+ fromPubkey: publicKey,
5009
5282
  newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
5010
5283
  lamports: lamports,
5011
5284
  space: 165,
5012
5285
  programId: spl_token_1.TOKEN_PROGRAM_ID,
5013
5286
  }),
5014
- (0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, positionAccount.owner),
5287
+ (0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
5015
5288
  ];
5016
5289
  postInstructions = [
5017
- (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), positionAccount.owner, positionAccount.owner),
5290
+ (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
5018
5291
  ];
5019
- return [3, 5];
5020
- case 2:
5021
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, true);
5292
+ additionalSigners.push(wrappedSolAccount);
5293
+ return [3, 6];
5294
+ case 3:
5295
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
5022
5296
  _a = createUserATA;
5023
- if (!_a) return [3, 4];
5297
+ if (!_a) return [3, 5];
5024
5298
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5025
- case 3:
5026
- _a = !(_b.sent());
5027
- _b.label = 4;
5028
5299
  case 4:
5300
+ _a = !(_b.sent());
5301
+ _b.label = 5;
5302
+ case 5:
5029
5303
  if (_a) {
5030
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5304
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5031
5305
  }
5032
- _b.label = 5;
5033
- case 5: return [4, this.program.methods
5034
- .forceClosePosition({
5035
- privilege: types_1.Privilege.None,
5306
+ _b.label = 6;
5307
+ case 6:
5308
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5309
+ orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5310
+ return [4, this.program.methods
5311
+ .editLimitOrder({
5312
+ orderId: orderId,
5313
+ limitPrice: limitPrice,
5314
+ sizeAmount: sizeAmount,
5315
+ stopLossPrice: stopLossPrice,
5316
+ takeProfitPrice: takeProfitPrice
5317
+ })
5318
+ .accounts({
5319
+ owner: publicKey,
5320
+ feePayer: publicKey,
5321
+ receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
5322
+ transferAuthority: poolConfig.transferAuthority,
5323
+ perpetuals: poolConfig.perpetuals,
5324
+ pool: poolConfig.poolAddress,
5325
+ position: positionAccount,
5326
+ order: orderAccount,
5327
+ market: marketAccount,
5328
+ targetCustody: targetCustodyConfig.custodyAccount,
5329
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5330
+ reserveCustody: reserveCustodyConfig.custodyAccount,
5331
+ reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
5332
+ reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
5333
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5334
+ eventAuthority: this.eventAuthority.publicKey,
5335
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5336
+ })
5337
+ .instruction()];
5338
+ case 7:
5339
+ editLimitOrder = _b.sent();
5340
+ instructions.push(editLimitOrder);
5341
+ return [3, 9];
5342
+ case 8:
5343
+ err_27 = _b.sent();
5344
+ console.log("perpClient editLimitOrder error:: ", err_27);
5345
+ throw err_27;
5346
+ case 9: return [2, {
5347
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5348
+ additionalSigners: additionalSigners
5349
+ }];
5350
+ }
5351
+ });
5352
+ });
5353
+ };
5354
+ this.executeLimitOrder = function (targetSymbol, collateralSymbol, side, orderId, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, poolConfig) {
5355
+ if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
5356
+ if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
5357
+ if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
5358
+ return __awaiter(_this, void 0, void 0, function () {
5359
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_28;
5360
+ return __generator(this, function (_a) {
5361
+ switch (_a.label) {
5362
+ case 0:
5363
+ publicKey = this.provider.wallet.publicKey;
5364
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5365
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5366
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5367
+ preInstructions = [];
5368
+ instructions = [];
5369
+ postInstructions = [];
5370
+ additionalSigners = [];
5371
+ _a.label = 1;
5372
+ case 1:
5373
+ _a.trys.push([1, 3, , 4]);
5374
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5375
+ orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5376
+ return [4, this.program.methods
5377
+ .executeLimitOrder({
5378
+ orderId: orderId,
5379
+ privilege: privilege
5380
+ })
5381
+ .accounts({
5382
+ feePayer: publicKey,
5383
+ perpetuals: poolConfig.perpetuals,
5384
+ pool: poolConfig.poolAddress,
5385
+ position: positionAccount,
5386
+ order: orderAccount,
5387
+ market: marketAccount,
5388
+ targetCustody: targetCustodyConfig.custodyAccount,
5389
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5390
+ collateralCustody: collateralCustodyConfig.custodyAccount,
5391
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5392
+ systemProgram: web3_js_1.SystemProgram.programId,
5393
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5394
+ eventAuthority: this.eventAuthority.publicKey,
5395
+ program: this.programId,
5396
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5397
+ })
5398
+ .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
5399
+ .instruction()];
5400
+ case 2:
5401
+ executeLimitOrder = _a.sent();
5402
+ instructions.push(executeLimitOrder);
5403
+ return [3, 4];
5404
+ case 3:
5405
+ err_28 = _a.sent();
5406
+ console.log("perpClient executeLimitOrder error:: ", err_28);
5407
+ throw err_28;
5408
+ case 4: return [2, {
5409
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5410
+ additionalSigners: additionalSigners
5411
+ }];
5412
+ }
5413
+ });
5414
+ });
5415
+ };
5416
+ this.placeTriggerOrder = function (targetSymbol, collateralSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, receiveCustodyId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5417
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_29;
5418
+ return __generator(this, function (_a) {
5419
+ switch (_a.label) {
5420
+ case 0:
5421
+ publicKey = this.provider.wallet.publicKey;
5422
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5423
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5424
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5425
+ preInstructions = [];
5426
+ instructions = [];
5427
+ postInstructions = [];
5428
+ additionalSigners = [];
5429
+ _a.label = 1;
5430
+ case 1:
5431
+ _a.trys.push([1, 3, , 4]);
5432
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5433
+ orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5434
+ return [4, this.program.methods
5435
+ .placeTriggerOrder({
5436
+ triggerPrice: triggerPrice,
5437
+ deltaSizeAmount: deltaSizeAmount,
5438
+ isStopLoss: isStopLoss,
5439
+ receiveCustodyId: receiveCustodyId
5440
+ })
5441
+ .accounts({
5442
+ owner: publicKey,
5443
+ feePayer: publicKey,
5444
+ perpetuals: poolConfig.perpetuals,
5445
+ pool: poolConfig.poolAddress,
5446
+ position: positionAccount,
5447
+ order: orderAccount,
5448
+ market: marketAccount,
5449
+ targetCustody: targetCustodyConfig.custodyAccount,
5450
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5451
+ collateralCustody: collateralCustodyConfig.custodyAccount,
5452
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5453
+ systemProgram: web3_js_1.SystemProgram.programId,
5454
+ eventAuthority: this.eventAuthority.publicKey,
5455
+ program: this.programId,
5456
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5457
+ })
5458
+ .instruction()];
5459
+ case 2:
5460
+ placeTriggerOrder = _a.sent();
5461
+ instructions.push(placeTriggerOrder);
5462
+ return [3, 4];
5463
+ case 3:
5464
+ err_29 = _a.sent();
5465
+ console.log("perpClient placeTriggerOrder error:: ", err_29);
5466
+ throw err_29;
5467
+ case 4: return [2, {
5468
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5469
+ additionalSigners: additionalSigners
5470
+ }];
5471
+ }
5472
+ });
5473
+ }); };
5474
+ this.editTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5475
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_30;
5476
+ return __generator(this, function (_a) {
5477
+ switch (_a.label) {
5478
+ case 0:
5479
+ publicKey = this.provider.wallet.publicKey;
5480
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5481
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5482
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5483
+ preInstructions = [];
5484
+ instructions = [];
5485
+ postInstructions = [];
5486
+ additionalSigners = [];
5487
+ _a.label = 1;
5488
+ case 1:
5489
+ _a.trys.push([1, 3, , 4]);
5490
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5491
+ orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5492
+ return [4, this.program.methods
5493
+ .editTriggerOrder({
5494
+ orderId: orderId,
5495
+ triggerPrice: triggerPrice,
5496
+ deltaSizeAmount: deltaSizeAmount,
5036
5497
  isStopLoss: isStopLoss
5037
5498
  })
5038
5499
  .accounts({
5039
- owner: positionAccount.owner,
5040
- receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
5041
- transferAuthority: poolConfig.transferAuthority,
5042
- perpetuals: this.perpetuals.publicKey,
5500
+ owner: publicKey,
5501
+ perpetuals: poolConfig.perpetuals,
5043
5502
  pool: poolConfig.poolAddress,
5044
- position: positionAccount.publicKey,
5503
+ position: positionAccount,
5504
+ order: orderAccount,
5045
5505
  market: marketAccount,
5046
5506
  targetCustody: targetCustodyConfig.custodyAccount,
5047
5507
  targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5048
5508
  collateralCustody: collateralCustodyConfig.custodyAccount,
5049
5509
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5050
- collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
5051
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5052
5510
  eventAuthority: this.eventAuthority.publicKey,
5053
5511
  program: this.programId,
5054
5512
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5055
5513
  })
5056
5514
  .instruction()];
5057
- case 6:
5058
- forceClosePosition = _b.sent();
5059
- instructions.push(forceClosePosition);
5060
- if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
5061
- closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
5062
- postInstructions.push(closeWsolATAIns);
5515
+ case 2:
5516
+ editTriggerOrder = _a.sent();
5517
+ instructions.push(editTriggerOrder);
5518
+ return [3, 4];
5519
+ case 3:
5520
+ err_30 = _a.sent();
5521
+ console.log("perpClient editTriggerOrder error:: ", err_30);
5522
+ throw err_30;
5523
+ case 4: return [2, {
5524
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5525
+ additionalSigners: additionalSigners
5526
+ }];
5527
+ }
5528
+ });
5529
+ }); };
5530
+ this.executeTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig, createUserATA, ephemeralSignerPubkey) {
5531
+ if (createUserATA === void 0) { createUserATA = true; }
5532
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5533
+ return __awaiter(_this, void 0, void 0, function () {
5534
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, _a, positionAccount, orderAccount, executeTriggerOrder, err_31;
5535
+ return __generator(this, function (_b) {
5536
+ switch (_b.label) {
5537
+ case 0:
5538
+ publicKey = this.provider.wallet.publicKey;
5539
+ targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
5540
+ collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5541
+ marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5542
+ preInstructions = [];
5543
+ instructions = [];
5544
+ postInstructions = [];
5545
+ additionalSigners = [];
5546
+ _b.label = 1;
5547
+ case 1:
5548
+ _b.trys.push([1, 8, , 9]);
5549
+ if (!(collateralSymbol == 'SOL')) return [3, 3];
5550
+ console.log("collateralSymbol === SOL", collateralSymbol);
5551
+ wrappedSolAccount = new web3_js_1.Keypair();
5552
+ return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
5553
+ case 2:
5554
+ accCreationLamports = (_b.sent());
5555
+ console.log("accCreationLamports:", accCreationLamports);
5556
+ lamports = accCreationLamports;
5557
+ if (!ephemeralSignerPubkey) {
5558
+ wrappedSolAccount = new web3_js_1.Keypair();
5559
+ additionalSigners.push(wrappedSolAccount);
5063
5560
  }
5064
- return [3, 8];
5561
+ preInstructions = [
5562
+ web3_js_1.SystemProgram.createAccount({
5563
+ fromPubkey: publicKey,
5564
+ newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
5565
+ lamports: lamports,
5566
+ space: 165,
5567
+ programId: spl_token_1.TOKEN_PROGRAM_ID,
5568
+ }),
5569
+ (0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
5570
+ ];
5571
+ postInstructions = [
5572
+ (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
5573
+ ];
5574
+ additionalSigners.push(wrappedSolAccount);
5575
+ return [3, 6];
5576
+ case 3:
5577
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
5578
+ _a = createUserATA;
5579
+ if (!_a) return [3, 5];
5580
+ return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5581
+ case 4:
5582
+ _a = !(_b.sent());
5583
+ _b.label = 5;
5584
+ case 5:
5585
+ if (_a) {
5586
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5587
+ }
5588
+ _b.label = 6;
5589
+ case 6:
5590
+ positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5591
+ orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5592
+ return [4, this.program.methods
5593
+ .executeTriggerOrder({
5594
+ isStopLoss: isStopLoss,
5595
+ orderId: orderId
5596
+ })
5597
+ .accounts({
5598
+ feePayer: publicKey,
5599
+ receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
5600
+ transferAuthority: poolConfig.transferAuthority,
5601
+ perpetuals: poolConfig.perpetuals,
5602
+ pool: poolConfig.poolAddress,
5603
+ position: positionAccount,
5604
+ order: orderAccount,
5605
+ market: marketAccount,
5606
+ targetCustody: targetCustodyConfig.custodyAccount,
5607
+ targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
5608
+ collateralCustody: collateralCustodyConfig.custodyAccount,
5609
+ collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5610
+ eventAuthority: this.eventAuthority.publicKey,
5611
+ program: this.programId,
5612
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5613
+ })
5614
+ .instruction()];
5065
5615
  case 7:
5066
- err_24 = _b.sent();
5067
- console.log("perpClient forceClosePosition error:: ", err_24);
5068
- throw err_24;
5069
- case 8: return [2, {
5616
+ executeTriggerOrder = _b.sent();
5617
+ instructions.push(executeTriggerOrder);
5618
+ return [3, 9];
5619
+ case 8:
5620
+ err_31 = _b.sent();
5621
+ console.log("perpClient executeTriggerOrder error:: ", err_31);
5622
+ throw err_31;
5623
+ case 9: return [2, {
5070
5624
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5071
5625
  additionalSigners: additionalSigners
5072
5626
  }];
@@ -5075,7 +5629,7 @@ var PerpetualsClient = (function () {
5075
5629
  });
5076
5630
  };
5077
5631
  this.getPositionData = function (position, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5078
- var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData, err_25;
5632
+ var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData, err_32;
5079
5633
  return __generator(this, function (_a) {
5080
5634
  switch (_a.label) {
5081
5635
  case 0:
@@ -5104,15 +5658,15 @@ var PerpetualsClient = (function () {
5104
5658
  console.log(getPositionData);
5105
5659
  return [2, getPositionData];
5106
5660
  case 3:
5107
- err_25 = _a.sent();
5108
- console.log("perpClient setPool error:: ", err_25);
5109
- throw err_25;
5661
+ err_32 = _a.sent();
5662
+ console.log("perpClient setPool error:: ", err_32);
5663
+ throw err_32;
5110
5664
  case 4: return [2];
5111
5665
  }
5112
5666
  });
5113
5667
  }); };
5114
5668
  this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5115
- var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_26;
5669
+ var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_33;
5116
5670
  return __generator(this, function (_a) {
5117
5671
  switch (_a.label) {
5118
5672
  case 0:
@@ -5145,9 +5699,9 @@ var PerpetualsClient = (function () {
5145
5699
  instructions.push(withdrawFeesIx);
5146
5700
  return [3, 5];
5147
5701
  case 4:
5148
- err_26 = _a.sent();
5149
- console.log("perpClient setPool error:: ", err_26);
5150
- throw err_26;
5702
+ err_33 = _a.sent();
5703
+ console.log("perpClient setPool error:: ", err_33);
5704
+ throw err_33;
5151
5705
  case 5: return [2, {
5152
5706
  instructions: __spreadArray([], instructions, true),
5153
5707
  additionalSigners: additionalSigners
@@ -5156,7 +5710,7 @@ var PerpetualsClient = (function () {
5156
5710
  });
5157
5711
  }); };
5158
5712
  this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
5159
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_27;
5713
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_34;
5160
5714
  return __generator(this, function (_a) {
5161
5715
  switch (_a.label) {
5162
5716
  case 0:
@@ -5183,9 +5737,9 @@ var PerpetualsClient = (function () {
5183
5737
  instructions.push(setPermissionsInstruction);
5184
5738
  return [3, 4];
5185
5739
  case 3:
5186
- err_27 = _a.sent();
5187
- console.log("perpClient setPool error:: ", err_27);
5188
- throw err_27;
5740
+ err_34 = _a.sent();
5741
+ console.log("perpClient setPool error:: ", err_34);
5742
+ throw err_34;
5189
5743
  case 4: return [2, {
5190
5744
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5191
5745
  additionalSigners: additionalSigners
@@ -5194,7 +5748,7 @@ var PerpetualsClient = (function () {
5194
5748
  });
5195
5749
  }); };
5196
5750
  this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5197
- var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_28;
5751
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_35;
5198
5752
  var _f;
5199
5753
  return __generator(this, function (_g) {
5200
5754
  switch (_g.label) {
@@ -5254,9 +5808,9 @@ var PerpetualsClient = (function () {
5254
5808
  instructions.push(reimburse);
5255
5809
  return [3, 5];
5256
5810
  case 4:
5257
- err_28 = _g.sent();
5258
- console.log("perpClient setPool error:: ", err_28);
5259
- throw err_28;
5811
+ err_35 = _g.sent();
5812
+ console.log("perpClient setPool error:: ", err_35);
5813
+ throw err_35;
5260
5814
  case 5: return [2, {
5261
5815
  instructions: __spreadArray([], instructions, true),
5262
5816
  additionalSigners: additionalSigners
@@ -5265,7 +5819,7 @@ var PerpetualsClient = (function () {
5265
5819
  });
5266
5820
  }); };
5267
5821
  this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5268
- var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_29;
5822
+ var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_36;
5269
5823
  return __generator(this, function (_a) {
5270
5824
  switch (_a.label) {
5271
5825
  case 0:
@@ -5298,9 +5852,9 @@ var PerpetualsClient = (function () {
5298
5852
  instructions.push(setInternalOraclePrice);
5299
5853
  return [3, 4];
5300
5854
  case 3:
5301
- err_29 = _a.sent();
5302
- console.log("perpClient setInternalOracleAccount error:: ", err_29);
5303
- throw err_29;
5855
+ err_36 = _a.sent();
5856
+ console.log("perpClient setInternalOracleAccount error:: ", err_36);
5857
+ throw err_36;
5304
5858
  case 4: return [2, {
5305
5859
  instructions: __spreadArray([], instructions, true),
5306
5860
  additionalSigners: additionalSigners
@@ -5312,7 +5866,7 @@ var PerpetualsClient = (function () {
5312
5866
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5313
5867
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5314
5868
  return __awaiter(_this, void 0, void 0, function () {
5315
- 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_30;
5869
+ 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_37;
5316
5870
  return __generator(this, function (_e) {
5317
5871
  switch (_e.label) {
5318
5872
  case 0:
@@ -5435,8 +5989,8 @@ var PerpetualsClient = (function () {
5435
5989
  instructions.push(addCompoundingLiquidity);
5436
5990
  return [3, 10];
5437
5991
  case 9:
5438
- err_30 = _e.sent();
5439
- console.log("perpClient addCompoundingLiquidity error:: ", err_30);
5992
+ err_37 = _e.sent();
5993
+ console.log("perpClient addCompoundingLiquidity error:: ", err_37);
5440
5994
  return [3, 10];
5441
5995
  case 10: return [2, {
5442
5996
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -5450,7 +6004,7 @@ var PerpetualsClient = (function () {
5450
6004
  if (createUserATA === void 0) { createUserATA = true; }
5451
6005
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5452
6006
  return __awaiter(_this, void 0, void 0, function () {
5453
- 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_31;
6007
+ 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_38;
5454
6008
  return __generator(this, function (_e) {
5455
6009
  switch (_e.label) {
5456
6010
  case 0:
@@ -5557,8 +6111,8 @@ var PerpetualsClient = (function () {
5557
6111
  instructions.push(removeCompoundingLiquidity);
5558
6112
  return [3, 8];
5559
6113
  case 7:
5560
- err_31 = _e.sent();
5561
- console.log("perpClient removeCompoundingLiquidity error:: ", err_31);
6114
+ err_38 = _e.sent();
6115
+ console.log("perpClient removeCompoundingLiquidity error:: ", err_38);
5562
6116
  return [3, 8];
5563
6117
  case 8: return [2, {
5564
6118
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -5571,7 +6125,7 @@ var PerpetualsClient = (function () {
5571
6125
  this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
5572
6126
  if (createUserATA === void 0) { createUserATA = true; }
5573
6127
  return __awaiter(_this, void 0, void 0, function () {
5574
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, migrateStake, err_32;
6128
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, migrateStake, err_39;
5575
6129
  return __generator(this, function (_e) {
5576
6130
  switch (_e.label) {
5577
6131
  case 0:
@@ -5652,8 +6206,8 @@ var PerpetualsClient = (function () {
5652
6206
  instructions.push(migrateStake);
5653
6207
  return [3, 6];
5654
6208
  case 5:
5655
- err_32 = _e.sent();
5656
- console.log("perpClient migrateStake error:: ", err_32);
6209
+ err_39 = _e.sent();
6210
+ console.log("perpClient migrateStake error:: ", err_39);
5657
6211
  return [3, 6];
5658
6212
  case 6: return [2, {
5659
6213
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -5664,7 +6218,7 @@ var PerpetualsClient = (function () {
5664
6218
  });
5665
6219
  };
5666
6220
  this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5667
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_33;
6221
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_40;
5668
6222
  return __generator(this, function (_d) {
5669
6223
  switch (_d.label) {
5670
6224
  case 0:
@@ -5736,8 +6290,8 @@ var PerpetualsClient = (function () {
5736
6290
  instructions.push(migrateFlp);
5737
6291
  return [3, 4];
5738
6292
  case 3:
5739
- err_33 = _d.sent();
5740
- console.log("perpClient migrateFlp error:: ", err_33);
6293
+ err_40 = _d.sent();
6294
+ console.log("perpClient migrateFlp error:: ", err_40);
5741
6295
  return [3, 4];
5742
6296
  case 4: return [2, {
5743
6297
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -5749,7 +6303,7 @@ var PerpetualsClient = (function () {
5749
6303
  this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
5750
6304
  if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
5751
6305
  return __awaiter(_this, void 0, void 0, function () {
5752
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_34;
6306
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_41;
5753
6307
  return __generator(this, function (_d) {
5754
6308
  switch (_d.label) {
5755
6309
  case 0:
@@ -5806,8 +6360,8 @@ var PerpetualsClient = (function () {
5806
6360
  instructions.push(compoundingFee);
5807
6361
  return [3, 4];
5808
6362
  case 3:
5809
- err_34 = _d.sent();
5810
- console.log("perpClient compoundingFee error:: ", err_34);
6363
+ err_41 = _d.sent();
6364
+ console.log("perpClient compoundingFee error:: ", err_41);
5811
6365
  return [3, 4];
5812
6366
  case 4: return [2, {
5813
6367
  instructions: __spreadArray([], instructions, true),
@@ -5818,7 +6372,7 @@ var PerpetualsClient = (function () {
5818
6372
  });
5819
6373
  };
5820
6374
  this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5821
- var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_35;
6375
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_42;
5822
6376
  return __generator(this, function (_a) {
5823
6377
  switch (_a.label) {
5824
6378
  case 0:
@@ -5856,8 +6410,8 @@ var PerpetualsClient = (function () {
5856
6410
  instructions.push(renameFlp);
5857
6411
  return [3, 4];
5858
6412
  case 3:
5859
- err_35 = _a.sent();
5860
- console.log("perpClient renameFlp error:: ", err_35);
6413
+ err_42 = _a.sent();
6414
+ console.log("perpClient renameFlp error:: ", err_42);
5861
6415
  return [3, 4];
5862
6416
  case 4: return [2, {
5863
6417
  instructions: __spreadArray([], instructions, true),
@@ -5867,7 +6421,7 @@ var PerpetualsClient = (function () {
5867
6421
  });
5868
6422
  }); };
5869
6423
  this.initRewardDistribution = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5870
- var publicKey, rewardMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, transferAuthority, initRewardVault, err_36;
6424
+ var publicKey, rewardMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, transferAuthority, initRewardVault, err_43;
5871
6425
  return __generator(this, function (_a) {
5872
6426
  switch (_a.label) {
5873
6427
  case 0:
@@ -5901,9 +6455,9 @@ var PerpetualsClient = (function () {
5901
6455
  instructions.push(initRewardVault);
5902
6456
  return [3, 4];
5903
6457
  case 3:
5904
- err_36 = _a.sent();
5905
- console.log("rewardDistribution InitRewardVault error:: ", err_36);
5906
- throw err_36;
6458
+ err_43 = _a.sent();
6459
+ console.log("rewardDistribution InitRewardVault error:: ", err_43);
6460
+ throw err_43;
5907
6461
  case 4: return [2, {
5908
6462
  instructions: __spreadArray([], instructions, true),
5909
6463
  additionalSigners: additionalSigners
@@ -5912,7 +6466,7 @@ var PerpetualsClient = (function () {
5912
6466
  });
5913
6467
  }); };
5914
6468
  this.updateCounterReward = function () { return __awaiter(_this, void 0, void 0, function () {
5915
- var publicKey, instructions, additionalSigners, rewardVault, updateCounter, err_37;
6469
+ var publicKey, instructions, additionalSigners, rewardVault, updateCounter, err_44;
5916
6470
  return __generator(this, function (_a) {
5917
6471
  switch (_a.label) {
5918
6472
  case 0:
@@ -5935,9 +6489,9 @@ var PerpetualsClient = (function () {
5935
6489
  instructions.push(updateCounter);
5936
6490
  return [3, 4];
5937
6491
  case 3:
5938
- err_37 = _a.sent();
5939
- console.log("rewardDistribution updateCounter error:: ", err_37);
5940
- throw err_37;
6492
+ err_44 = _a.sent();
6493
+ console.log("rewardDistribution updateCounter error:: ", err_44);
6494
+ throw err_44;
5941
6495
  case 4: return [2, {
5942
6496
  instructions: __spreadArray([], instructions, true),
5943
6497
  additionalSigners: additionalSigners
@@ -5946,7 +6500,7 @@ var PerpetualsClient = (function () {
5946
6500
  });
5947
6501
  }); };
5948
6502
  this.rewardDistribution = function (counter, owner, rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5949
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_38;
6503
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_45;
5950
6504
  return __generator(this, function (_a) {
5951
6505
  switch (_a.label) {
5952
6506
  case 0:
@@ -5985,9 +6539,9 @@ var PerpetualsClient = (function () {
5985
6539
  instructions.push(distributeReward);
5986
6540
  return [3, 4];
5987
6541
  case 3:
5988
- err_38 = _a.sent();
5989
- console.log("rewardDistribution distributeReward error:: ", err_38);
5990
- throw err_38;
6542
+ err_45 = _a.sent();
6543
+ console.log("rewardDistribution distributeReward error:: ", err_45);
6544
+ throw err_45;
5991
6545
  case 4: return [2, {
5992
6546
  instructions: __spreadArray([], instructions, true),
5993
6547
  additionalSigners: additionalSigners
@@ -5998,7 +6552,7 @@ var PerpetualsClient = (function () {
5998
6552
  this.collectReward = function (counter, owner, rewardSymbol, poolConfig, createUserATA) {
5999
6553
  if (createUserATA === void 0) { createUserATA = true; }
6000
6554
  return __awaiter(_this, void 0, void 0, function () {
6001
- var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectNftReward, err_39;
6555
+ var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectNftReward, err_46;
6002
6556
  return __generator(this, function (_b) {
6003
6557
  switch (_b.label) {
6004
6558
  case 0:
@@ -6044,8 +6598,8 @@ var PerpetualsClient = (function () {
6044
6598
  instructions.push(collectNftReward);
6045
6599
  return [3, 6];
6046
6600
  case 5:
6047
- err_39 = _b.sent();
6048
- throw err_39;
6601
+ err_46 = _b.sent();
6602
+ throw err_46;
6049
6603
  case 6: return [2, {
6050
6604
  instructions: __spreadArray([], instructions, true),
6051
6605
  additionalSigners: additionalSigners