flash-sdk 9.0.0-alpha.10 → 9.0.0-alpha.12

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.
@@ -862,7 +862,7 @@ var PerpetualsClient = (function () {
862
862
  return constants_1.BN_ZERO;
863
863
  }
864
864
  var slope = ((targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin)).mul(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS)))))
865
- .div(targetCustodyAccount.pricing.maxPositionLockedUsd);
865
+ .div(targetCustodyAccount.pricing.maxPositionSizeUsd);
866
866
  var variable = (slope.mul(sizeUsd)).div(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS))));
867
867
  var finalSpread = targetCustodyAccount.pricing.tradeSpreadMin.add(variable);
868
868
  return finalSpread;
@@ -2686,7 +2686,7 @@ var PerpetualsClient = (function () {
2686
2686
  args_1[_i - 9] = arguments[_i];
2687
2687
  }
2688
2688
  return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2689
- var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_3;
2689
+ var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
2690
2690
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2691
2691
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2692
2692
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
@@ -2782,14 +2782,7 @@ var PerpetualsClient = (function () {
2782
2782
  }
2783
2783
  _c.label = 10;
2784
2784
  case 10:
2785
- rebateMintAccount = {
2786
- pubkey: collateralCustodyConfig.mintKey,
2787
- isSigner: false,
2788
- isWritable: false
2789
- };
2790
- _c.label = 11;
2791
- case 11:
2792
- _c.trys.push([11, 13, , 14]);
2785
+ _c.trys.push([10, 12, , 13]);
2793
2786
  return [4, this.program.methods
2794
2787
  .swapAndOpen({
2795
2788
  amountIn: amountIn,
@@ -2825,15 +2818,15 @@ var PerpetualsClient = (function () {
2825
2818
  })
2826
2819
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
2827
2820
  .instruction()];
2828
- case 12:
2821
+ case 11:
2829
2822
  inx = _c.sent();
2830
2823
  instructions.push(inx);
2831
- return [3, 14];
2832
- case 13:
2824
+ return [3, 13];
2825
+ case 12:
2833
2826
  err_3 = _c.sent();
2834
2827
  console.error("perpClient SwapAndOpen error:: ", err_3);
2835
2828
  throw err_3;
2836
- case 14: return [2, {
2829
+ case 13: return [2, {
2837
2830
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2838
2831
  additionalSigners: additionalSigners
2839
2832
  }];
@@ -5382,13 +5375,143 @@ var PerpetualsClient = (function () {
5382
5375
  });
5383
5376
  });
5384
5377
  };
5378
+ this.collectRebate = function (owner_1, rebateSymbol_1, poolConfig_1) {
5379
+ var args_1 = [];
5380
+ for (var _i = 3; _i < arguments.length; _i++) {
5381
+ args_1[_i - 3] = arguments[_i];
5382
+ }
5383
+ return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
5384
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, _a, collectRebateInstruction, err_28;
5385
+ if (createUserATA === void 0) { createUserATA = true; }
5386
+ return __generator(this, function (_b) {
5387
+ switch (_b.label) {
5388
+ case 0:
5389
+ publicKey = this.provider.wallet.publicKey;
5390
+ preInstructions = [];
5391
+ instructions = [];
5392
+ postInstructions = [];
5393
+ additionalSigners = [];
5394
+ _b.label = 1;
5395
+ case 1:
5396
+ _b.trys.push([1, 5, , 6]);
5397
+ rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
5398
+ tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
5399
+ userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
5400
+ _a = createUserATA;
5401
+ if (!_a) return [3, 3];
5402
+ return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
5403
+ case 2:
5404
+ _a = !(_b.sent());
5405
+ _b.label = 3;
5406
+ case 3:
5407
+ if (_a) {
5408
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
5409
+ }
5410
+ return [4, this.program.methods
5411
+ .collectRebate()
5412
+ .accounts({
5413
+ owner: owner,
5414
+ receivingTokenAccount: userTokenAccount,
5415
+ perpetuals: this.perpetuals.publicKey,
5416
+ transferAuthority: poolConfig.transferAuthority,
5417
+ rebateVault: poolConfig.rebateVault,
5418
+ rebateTokenAccount: poolConfig.rebateTokenAccount,
5419
+ tokenStakeAccount: tokenStakeAccount,
5420
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5421
+ eventAuthority: this.eventAuthority.publicKey,
5422
+ program: this.programId,
5423
+ receivingTokenMint: rebateMint,
5424
+ })
5425
+ .instruction()];
5426
+ case 4:
5427
+ collectRebateInstruction = _b.sent();
5428
+ instructions.push(collectRebateInstruction);
5429
+ return [3, 6];
5430
+ case 5:
5431
+ err_28 = _b.sent();
5432
+ console.log("perpClient collectRebateInstruction error:: ", err_28);
5433
+ throw err_28;
5434
+ case 6: return [2, {
5435
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5436
+ additionalSigners: additionalSigners
5437
+ }];
5438
+ }
5439
+ });
5440
+ });
5441
+ };
5442
+ this.settleRebates = function (owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1) {
5443
+ var args_1 = [];
5444
+ for (var _i = 4; _i < arguments.length; _i++) {
5445
+ args_1[_i - 4] = arguments[_i];
5446
+ }
5447
+ return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, rewardSymbol, poolConfig, createUserATA) {
5448
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, rebateMint, userTokenAccount, _a, settleRebatesInstruction, err_29;
5449
+ if (createUserATA === void 0) { createUserATA = true; }
5450
+ return __generator(this, function (_b) {
5451
+ switch (_b.label) {
5452
+ case 0:
5453
+ publicKey = this.provider.wallet.publicKey;
5454
+ preInstructions = [];
5455
+ instructions = [];
5456
+ postInstructions = [];
5457
+ additionalSigners = [];
5458
+ _b.label = 1;
5459
+ case 1:
5460
+ _b.trys.push([1, 5, , 6]);
5461
+ rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
5462
+ rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
5463
+ userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
5464
+ _a = createUserATA;
5465
+ if (!_a) return [3, 3];
5466
+ return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
5467
+ case 2:
5468
+ _a = !(_b.sent());
5469
+ _b.label = 3;
5470
+ case 3:
5471
+ if (_a) {
5472
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
5473
+ }
5474
+ return [4, this.program.methods
5475
+ .settleRebates()
5476
+ .accounts({
5477
+ transferAuthority: poolConfig.transferAuthority,
5478
+ perpetuals: this.perpetuals.publicKey,
5479
+ pool: poolConfig.poolAddress,
5480
+ rewardCustody: rewardCustody.custodyAccount,
5481
+ rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
5482
+ rewardCustodyTokenAccount: rewardCustody.tokenAccount,
5483
+ rebateVault: poolConfig.rebateVault,
5484
+ rebateTokenAccount: poolConfig.rebateTokenAccount,
5485
+ tokenMint: rebateMint,
5486
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5487
+ eventAuthority: this.eventAuthority.publicKey,
5488
+ program: this.programId,
5489
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5490
+ })
5491
+ .instruction()];
5492
+ case 4:
5493
+ settleRebatesInstruction = _b.sent();
5494
+ instructions.push(settleRebatesInstruction);
5495
+ return [3, 6];
5496
+ case 5:
5497
+ err_29 = _b.sent();
5498
+ console.log("perpClient settleRebatesInstruction error:: ", err_29);
5499
+ throw err_29;
5500
+ case 6: return [2, {
5501
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5502
+ additionalSigners: additionalSigners
5503
+ }];
5504
+ }
5505
+ });
5506
+ });
5507
+ };
5385
5508
  this.placeLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
5386
5509
  var args_1 = [];
5387
5510
  for (var _i = 11; _i < arguments.length; _i++) {
5388
5511
  args_1[_i - 11] = arguments[_i];
5389
5512
  }
5390
5513
  return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
5391
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_28;
5514
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_30;
5392
5515
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5393
5516
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5394
5517
  return __generator(this, function (_c) {
@@ -5494,9 +5617,9 @@ var PerpetualsClient = (function () {
5494
5617
  instructions.push(placeLimitOrder);
5495
5618
  return [3, 10];
5496
5619
  case 9:
5497
- err_28 = _c.sent();
5498
- console.log("perpClient placeLimitOrder error:: ", err_28);
5499
- throw err_28;
5620
+ err_30 = _c.sent();
5621
+ console.log("perpClient placeLimitOrder error:: ", err_30);
5622
+ throw err_30;
5500
5623
  case 10: return [2, {
5501
5624
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5502
5625
  additionalSigners: additionalSigners
@@ -5511,7 +5634,7 @@ var PerpetualsClient = (function () {
5511
5634
  args_1[_i - 11] = arguments[_i];
5512
5635
  }
5513
5636
  return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
5514
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_29;
5637
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_31;
5515
5638
  if (createUserATA === void 0) { createUserATA = true; }
5516
5639
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5517
5640
  return __generator(this, function (_b) {
@@ -5602,9 +5725,9 @@ var PerpetualsClient = (function () {
5602
5725
  instructions.push(editLimitOrder);
5603
5726
  return [3, 8];
5604
5727
  case 7:
5605
- err_29 = _b.sent();
5606
- console.log("perpClient editLimitOrder error:: ", err_29);
5607
- throw err_29;
5728
+ err_31 = _b.sent();
5729
+ console.log("perpClient editLimitOrder error:: ", err_31);
5730
+ throw err_31;
5608
5731
  case 8: return [2, {
5609
5732
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5610
5733
  additionalSigners: additionalSigners
@@ -5619,7 +5742,7 @@ var PerpetualsClient = (function () {
5619
5742
  args_1[_i - 7] = arguments[_i];
5620
5743
  }
5621
5744
  return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount) {
5622
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_30;
5745
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_32;
5623
5746
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
5624
5747
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
5625
5748
  return __generator(this, function (_a) {
@@ -5671,9 +5794,9 @@ var PerpetualsClient = (function () {
5671
5794
  instructions.push(executeLimitOrder);
5672
5795
  return [3, 4];
5673
5796
  case 3:
5674
- err_30 = _a.sent();
5675
- console.log("perpClient executeLimitOrder error:: ", err_30);
5676
- throw err_30;
5797
+ err_32 = _a.sent();
5798
+ console.log("perpClient executeLimitOrder error:: ", err_32);
5799
+ throw err_32;
5677
5800
  case 4: return [2, {
5678
5801
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5679
5802
  additionalSigners: additionalSigners
@@ -5688,7 +5811,7 @@ var PerpetualsClient = (function () {
5688
5811
  args_1[_i - 8] = arguments[_i];
5689
5812
  }
5690
5813
  return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount) {
5691
- var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_31;
5814
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_33;
5692
5815
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
5693
5816
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
5694
5817
  return __generator(this, function (_a) {
@@ -5743,9 +5866,9 @@ var PerpetualsClient = (function () {
5743
5866
  instructions.push(executeLimitWithSwap);
5744
5867
  return [3, 4];
5745
5868
  case 3:
5746
- err_31 = _a.sent();
5747
- console.log("perpClient executeLimitWithSwap error:: ", err_31);
5748
- throw err_31;
5869
+ err_33 = _a.sent();
5870
+ console.log("perpClient executeLimitWithSwap error:: ", err_33);
5871
+ throw err_33;
5749
5872
  case 4: return [2, {
5750
5873
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5751
5874
  additionalSigners: additionalSigners
@@ -5755,7 +5878,7 @@ var PerpetualsClient = (function () {
5755
5878
  });
5756
5879
  };
5757
5880
  this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5758
- var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_32;
5881
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_34;
5759
5882
  return __generator(this, function (_a) {
5760
5883
  switch (_a.label) {
5761
5884
  case 0:
@@ -5803,9 +5926,9 @@ var PerpetualsClient = (function () {
5803
5926
  instructions.push(placeTriggerOrder);
5804
5927
  return [3, 4];
5805
5928
  case 3:
5806
- err_32 = _a.sent();
5807
- console.log("perpClient placeTriggerOrder error:: ", err_32);
5808
- throw err_32;
5929
+ err_34 = _a.sent();
5930
+ console.log("perpClient placeTriggerOrder error:: ", err_34);
5931
+ throw err_34;
5809
5932
  case 4: return [2, {
5810
5933
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5811
5934
  additionalSigners: additionalSigners
@@ -5814,7 +5937,7 @@ var PerpetualsClient = (function () {
5814
5937
  });
5815
5938
  }); };
5816
5939
  this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5817
- var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_33;
5940
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_35;
5818
5941
  return __generator(this, function (_a) {
5819
5942
  switch (_a.label) {
5820
5943
  case 0:
@@ -5861,9 +5984,9 @@ var PerpetualsClient = (function () {
5861
5984
  instructions.push(editTriggerOrder);
5862
5985
  return [3, 4];
5863
5986
  case 3:
5864
- err_33 = _a.sent();
5865
- console.log("perpClient editTriggerOrder error:: ", err_33);
5866
- throw err_33;
5987
+ err_35 = _a.sent();
5988
+ console.log("perpClient editTriggerOrder error:: ", err_35);
5989
+ throw err_35;
5867
5990
  case 4: return [2, {
5868
5991
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5869
5992
  additionalSigners: additionalSigners
@@ -5872,7 +5995,7 @@ var PerpetualsClient = (function () {
5872
5995
  });
5873
5996
  }); };
5874
5997
  this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5875
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_34;
5998
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_36;
5876
5999
  return __generator(this, function (_a) {
5877
6000
  switch (_a.label) {
5878
6001
  case 0:
@@ -5905,9 +6028,9 @@ var PerpetualsClient = (function () {
5905
6028
  instructions.push(cancelTriggerOrder);
5906
6029
  return [3, 4];
5907
6030
  case 3:
5908
- err_34 = _a.sent();
5909
- console.log("perpClient cancelTriggerOrder error:: ", err_34);
5910
- throw err_34;
6031
+ err_36 = _a.sent();
6032
+ console.log("perpClient cancelTriggerOrder error:: ", err_36);
6033
+ throw err_36;
5911
6034
  case 4: return [2, {
5912
6035
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5913
6036
  additionalSigners: additionalSigners
@@ -5916,7 +6039,7 @@ var PerpetualsClient = (function () {
5916
6039
  });
5917
6040
  }); };
5918
6041
  this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5919
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_35;
6042
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_37;
5920
6043
  return __generator(this, function (_a) {
5921
6044
  switch (_a.label) {
5922
6045
  case 0:
@@ -5947,9 +6070,9 @@ var PerpetualsClient = (function () {
5947
6070
  instructions.push(cancelAllTriggerOrders);
5948
6071
  return [3, 4];
5949
6072
  case 3:
5950
- err_35 = _a.sent();
5951
- console.log("perpClient cancelAllTriggerOrders error:: ", err_35);
5952
- throw err_35;
6073
+ err_37 = _a.sent();
6074
+ console.log("perpClient cancelAllTriggerOrders error:: ", err_37);
6075
+ throw err_37;
5953
6076
  case 4: return [2, {
5954
6077
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5955
6078
  additionalSigners: additionalSigners
@@ -5963,7 +6086,7 @@ var PerpetualsClient = (function () {
5963
6086
  args_1[_i - 9] = arguments[_i];
5964
6087
  }
5965
6088
  return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount) {
5966
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_36;
6089
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_38;
5967
6090
  if (createUserATA === void 0) { createUserATA = true; }
5968
6091
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5969
6092
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6069,9 +6192,9 @@ var PerpetualsClient = (function () {
6069
6192
  instructions.push(executeTriggerWithSwap);
6070
6193
  return [3, 10];
6071
6194
  case 9:
6072
- err_36 = _e.sent();
6073
- console.log("perpClient executeTriggerWithSwap error:: ", err_36);
6074
- throw err_36;
6195
+ err_38 = _e.sent();
6196
+ console.log("perpClient executeTriggerWithSwap error:: ", err_38);
6197
+ throw err_38;
6075
6198
  case 10: return [2, {
6076
6199
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6077
6200
  additionalSigners: additionalSigners
@@ -6086,7 +6209,7 @@ var PerpetualsClient = (function () {
6086
6209
  args_1[_i - 8] = arguments[_i];
6087
6210
  }
6088
6211
  return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount) {
6089
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_37;
6212
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_39;
6090
6213
  if (createUserATA === void 0) { createUserATA = true; }
6091
6214
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6092
6215
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6157,9 +6280,9 @@ var PerpetualsClient = (function () {
6157
6280
  instructions.push(executeTriggerOrder);
6158
6281
  return [3, 8];
6159
6282
  case 7:
6160
- err_37 = _b.sent();
6161
- console.log("perpClient executeTriggerOrder error:: ", err_37);
6162
- throw err_37;
6283
+ err_39 = _b.sent();
6284
+ console.log("perpClient executeTriggerOrder error:: ", err_39);
6285
+ throw err_39;
6163
6286
  case 8: return [2, {
6164
6287
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6165
6288
  additionalSigners: additionalSigners
@@ -6174,7 +6297,7 @@ var PerpetualsClient = (function () {
6174
6297
  args_1[_i - 5] = arguments[_i];
6175
6298
  }
6176
6299
  return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
6177
- var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_38;
6300
+ var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_40;
6178
6301
  if (useFeesPool === void 0) { useFeesPool = false; }
6179
6302
  if (createUserATA === void 0) { createUserATA = true; }
6180
6303
  if (unWrapSol === void 0) { unWrapSol = false; }
@@ -6379,9 +6502,9 @@ var PerpetualsClient = (function () {
6379
6502
  }
6380
6503
  return [3, 20];
6381
6504
  case 19:
6382
- err_38 = _g.sent();
6383
- console.error("perpClient Swap error:: ", err_38);
6384
- throw err_38;
6505
+ err_40 = _g.sent();
6506
+ console.error("perpClient Swap error:: ", err_40);
6507
+ throw err_40;
6385
6508
  case 20: return [2, {
6386
6509
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6387
6510
  additionalSigners: additionalSigners
@@ -6391,7 +6514,7 @@ var PerpetualsClient = (function () {
6391
6514
  });
6392
6515
  };
6393
6516
  this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6394
- var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_39;
6517
+ var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_41;
6395
6518
  return __generator(this, function (_b) {
6396
6519
  switch (_b.label) {
6397
6520
  case 0:
@@ -6447,9 +6570,9 @@ var PerpetualsClient = (function () {
6447
6570
  instructions.push(inx);
6448
6571
  return [3, 4];
6449
6572
  case 3:
6450
- err_39 = _b.sent();
6451
- console.error("perpClient Swap error:: ", err_39);
6452
- throw err_39;
6573
+ err_41 = _b.sent();
6574
+ console.error("perpClient Swap error:: ", err_41);
6575
+ throw err_41;
6453
6576
  case 4: return [2, {
6454
6577
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6455
6578
  additionalSigners: additionalSigners
@@ -6458,7 +6581,7 @@ var PerpetualsClient = (function () {
6458
6581
  });
6459
6582
  }); };
6460
6583
  this.setLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6461
- var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_40;
6584
+ var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_42;
6462
6585
  return __generator(this, function (_d) {
6463
6586
  switch (_d.label) {
6464
6587
  case 0:
@@ -6506,9 +6629,9 @@ var PerpetualsClient = (function () {
6506
6629
  instructions.push(setLpTokenPriceInstruction);
6507
6630
  return [3, 4];
6508
6631
  case 3:
6509
- err_40 = _d.sent();
6510
- console.log("perpClient setLpTokenPriceInstruction error:: ", err_40);
6511
- throw err_40;
6632
+ err_42 = _d.sent();
6633
+ console.log("perpClient setLpTokenPriceInstruction error:: ", err_42);
6634
+ throw err_42;
6512
6635
  case 4: return [2, {
6513
6636
  instructions: __spreadArray([], instructions, true),
6514
6637
  additionalSigners: additionalSigners
@@ -6556,7 +6679,7 @@ var PerpetualsClient = (function () {
6556
6679
  });
6557
6680
  }); };
6558
6681
  this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
6559
- var adminMetas, _i, admins_2, admin, err_41;
6682
+ var adminMetas, _i, admins_2, admin, err_43;
6560
6683
  return __generator(this, function (_a) {
6561
6684
  switch (_a.label) {
6562
6685
  case 0:
@@ -6586,11 +6709,11 @@ var PerpetualsClient = (function () {
6586
6709
  _a.sent();
6587
6710
  return [3, 4];
6588
6711
  case 3:
6589
- err_41 = _a.sent();
6712
+ err_43 = _a.sent();
6590
6713
  if (this.printErrors) {
6591
- console.error("setAdminSigners err:", err_41);
6714
+ console.error("setAdminSigners err:", err_43);
6592
6715
  }
6593
- throw err_41;
6716
+ throw err_43;
6594
6717
  case 4: return [2];
6595
6718
  }
6596
6719
  });
@@ -6779,7 +6902,7 @@ var PerpetualsClient = (function () {
6779
6902
  });
6780
6903
  }); };
6781
6904
  this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6782
- var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_42;
6905
+ var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_44;
6783
6906
  return __generator(this, function (_a) {
6784
6907
  switch (_a.label) {
6785
6908
  case 0:
@@ -6812,9 +6935,9 @@ var PerpetualsClient = (function () {
6812
6935
  instructions.push(withdrawFeesIx);
6813
6936
  return [3, 5];
6814
6937
  case 4:
6815
- err_42 = _a.sent();
6816
- console.log("perpClient setPool error:: ", err_42);
6817
- throw err_42;
6938
+ err_44 = _a.sent();
6939
+ console.log("perpClient setPool error:: ", err_44);
6940
+ throw err_44;
6818
6941
  case 5: return [2, {
6819
6942
  instructions: __spreadArray([], instructions, true),
6820
6943
  additionalSigners: additionalSigners
@@ -6823,7 +6946,7 @@ var PerpetualsClient = (function () {
6823
6946
  });
6824
6947
  }); };
6825
6948
  this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6826
- var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_43;
6949
+ var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_45;
6827
6950
  return __generator(this, function (_a) {
6828
6951
  switch (_a.label) {
6829
6952
  case 0:
@@ -6857,9 +6980,9 @@ var PerpetualsClient = (function () {
6857
6980
  instructions.push(moveProtocolFeesIx);
6858
6981
  return [3, 4];
6859
6982
  case 3:
6860
- err_43 = _a.sent();
6861
- console.log("perpClient setPool error:: ", err_43);
6862
- throw err_43;
6983
+ err_45 = _a.sent();
6984
+ console.log("perpClient setPool error:: ", err_45);
6985
+ throw err_45;
6863
6986
  case 4: return [2, {
6864
6987
  instructions: __spreadArray([], instructions, true),
6865
6988
  additionalSigners: additionalSigners
@@ -6868,7 +6991,7 @@ var PerpetualsClient = (function () {
6868
6991
  });
6869
6992
  }); };
6870
6993
  this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6871
- var publicKey, setProtocolFeeShareBpsIx, err_44;
6994
+ var publicKey, setProtocolFeeShareBpsIx, err_46;
6872
6995
  return __generator(this, function (_a) {
6873
6996
  switch (_a.label) {
6874
6997
  case 0:
@@ -6888,15 +7011,15 @@ var PerpetualsClient = (function () {
6888
7011
  setProtocolFeeShareBpsIx = _a.sent();
6889
7012
  return [2, setProtocolFeeShareBpsIx];
6890
7013
  case 2:
6891
- err_44 = _a.sent();
6892
- console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_44);
6893
- throw err_44;
7014
+ err_46 = _a.sent();
7015
+ console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_46);
7016
+ throw err_46;
6894
7017
  case 3: return [2];
6895
7018
  }
6896
7019
  });
6897
7020
  }); };
6898
7021
  this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
6899
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_45;
7022
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_47;
6900
7023
  return __generator(this, function (_a) {
6901
7024
  switch (_a.label) {
6902
7025
  case 0:
@@ -6923,9 +7046,9 @@ var PerpetualsClient = (function () {
6923
7046
  instructions.push(setPermissionsInstruction);
6924
7047
  return [3, 4];
6925
7048
  case 3:
6926
- err_45 = _a.sent();
6927
- console.log("perpClient setPool error:: ", err_45);
6928
- throw err_45;
7049
+ err_47 = _a.sent();
7050
+ console.log("perpClient setPool error:: ", err_47);
7051
+ throw err_47;
6929
7052
  case 4: return [2, {
6930
7053
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6931
7054
  additionalSigners: additionalSigners
@@ -6934,7 +7057,7 @@ var PerpetualsClient = (function () {
6934
7057
  });
6935
7058
  }); };
6936
7059
  this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6937
- var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_46;
7060
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_48;
6938
7061
  var _f;
6939
7062
  return __generator(this, function (_g) {
6940
7063
  switch (_g.label) {
@@ -6995,9 +7118,9 @@ var PerpetualsClient = (function () {
6995
7118
  instructions.push(reimburse);
6996
7119
  return [3, 5];
6997
7120
  case 4:
6998
- err_46 = _g.sent();
6999
- console.log("perpClient setPool error:: ", err_46);
7000
- throw err_46;
7121
+ err_48 = _g.sent();
7122
+ console.log("perpClient setPool error:: ", err_48);
7123
+ throw err_48;
7001
7124
  case 5: return [2, {
7002
7125
  instructions: __spreadArray([], instructions, true),
7003
7126
  additionalSigners: additionalSigners
@@ -7006,7 +7129,7 @@ var PerpetualsClient = (function () {
7006
7129
  });
7007
7130
  }); };
7008
7131
  this.setInternalOraclePrice = function (tokenMint, useCurrentTime, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7009
- var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_47;
7132
+ var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_49;
7010
7133
  return __generator(this, function (_a) {
7011
7134
  switch (_a.label) {
7012
7135
  case 0:
@@ -7040,9 +7163,9 @@ var PerpetualsClient = (function () {
7040
7163
  instructions.push(setInternalOraclePrice);
7041
7164
  return [3, 4];
7042
7165
  case 3:
7043
- err_47 = _a.sent();
7044
- console.log("perpClient setInternalOracleAccount error:: ", err_47);
7045
- throw err_47;
7166
+ err_49 = _a.sent();
7167
+ console.log("perpClient setInternalOracleAccount error:: ", err_49);
7168
+ throw err_49;
7046
7169
  case 4: return [2, {
7047
7170
  instructions: __spreadArray([], instructions, true),
7048
7171
  additionalSigners: additionalSigners
@@ -7051,7 +7174,7 @@ var PerpetualsClient = (function () {
7051
7174
  });
7052
7175
  }); };
7053
7176
  this.setInternalOraclePriceBatch = function (useCurrentTime, tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
7054
- var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_48;
7177
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_50;
7055
7178
  return __generator(this, function (_a) {
7056
7179
  switch (_a.label) {
7057
7180
  case 0:
@@ -7062,11 +7185,6 @@ var PerpetualsClient = (function () {
7062
7185
  accountMetas = [];
7063
7186
  _loop_1 = function (tokenMint) {
7064
7187
  var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
7065
- accountMetas.push({
7066
- pubkey: custody.custodyAccount,
7067
- isSigner: false,
7068
- isWritable: false,
7069
- });
7070
7188
  accountMetas.push({
7071
7189
  pubkey: custody.intOracleAccount,
7072
7190
  isSigner: false,
@@ -7089,8 +7207,8 @@ var PerpetualsClient = (function () {
7089
7207
  _a.trys.push([1, 3, , 4]);
7090
7208
  return [4, this.program.methods
7091
7209
  .setInternalCurrentPrice({
7092
- prices: tokenInternalPrices,
7093
- useCurrentTime: useCurrentTime ? 1 : 0
7210
+ useCurrentTime: useCurrentTime,
7211
+ prices: tokenInternalPrices
7094
7212
  })
7095
7213
  .accounts({
7096
7214
  authority: POOL_CONFIGS[0].backupOracle,
@@ -7102,9 +7220,9 @@ var PerpetualsClient = (function () {
7102
7220
  instructions.push(setInternalOraclePrice);
7103
7221
  return [3, 4];
7104
7222
  case 3:
7105
- err_48 = _a.sent();
7106
- console.log("perpClient setInternalOracleAccount error:: ", err_48);
7107
- throw err_48;
7223
+ err_50 = _a.sent();
7224
+ console.log("perpClient setInternalOracleAccount error:: ", err_50);
7225
+ throw err_50;
7108
7226
  case 4: return [2, {
7109
7227
  instructions: __spreadArray([], instructions, true),
7110
7228
  additionalSigners: additionalSigners
@@ -7113,7 +7231,7 @@ var PerpetualsClient = (function () {
7113
7231
  });
7114
7232
  }); };
7115
7233
  this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
7116
- var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_49;
7234
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_51;
7117
7235
  return __generator(this, function (_a) {
7118
7236
  switch (_a.label) {
7119
7237
  case 0:
@@ -7153,9 +7271,9 @@ var PerpetualsClient = (function () {
7153
7271
  instructions.push(setInternalOraclePrice);
7154
7272
  return [3, 4];
7155
7273
  case 3:
7156
- err_49 = _a.sent();
7157
- console.log("perpClient setInternalOracleAccount error:: ", err_49);
7158
- throw err_49;
7274
+ err_51 = _a.sent();
7275
+ console.log("perpClient setInternalOracleAccount error:: ", err_51);
7276
+ throw err_51;
7159
7277
  case 4: return [2, {
7160
7278
  instructions: __spreadArray([], instructions, true),
7161
7279
  additionalSigners: additionalSigners
@@ -7164,7 +7282,7 @@ var PerpetualsClient = (function () {
7164
7282
  });
7165
7283
  }); };
7166
7284
  this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7167
- var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_50;
7285
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_52;
7168
7286
  return __generator(this, function (_a) {
7169
7287
  switch (_a.label) {
7170
7288
  case 0:
@@ -7202,8 +7320,8 @@ var PerpetualsClient = (function () {
7202
7320
  instructions.push(renameFlp);
7203
7321
  return [3, 4];
7204
7322
  case 3:
7205
- err_50 = _a.sent();
7206
- console.log("perpClient renameFlp error:: ", err_50);
7323
+ err_52 = _a.sent();
7324
+ console.log("perpClient renameFlp error:: ", err_52);
7207
7325
  return [3, 4];
7208
7326
  case 4: return [2, {
7209
7327
  instructions: __spreadArray([], instructions, true),
@@ -7213,7 +7331,7 @@ var PerpetualsClient = (function () {
7213
7331
  });
7214
7332
  }); };
7215
7333
  this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7216
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_51;
7334
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_53;
7217
7335
  return __generator(this, function (_a) {
7218
7336
  switch (_a.label) {
7219
7337
  case 0:
@@ -7251,9 +7369,9 @@ var PerpetualsClient = (function () {
7251
7369
  instructions.push(initStakeInstruction);
7252
7370
  return [3, 4];
7253
7371
  case 3:
7254
- err_51 = _a.sent();
7255
- console.log("perpClient InitStaking error:: ", err_51);
7256
- throw err_51;
7372
+ err_53 = _a.sent();
7373
+ console.log("perpClient InitStaking error:: ", err_53);
7374
+ throw err_53;
7257
7375
  case 4: return [2, {
7258
7376
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7259
7377
  additionalSigners: additionalSigners
@@ -7262,7 +7380,7 @@ var PerpetualsClient = (function () {
7262
7380
  });
7263
7381
  }); };
7264
7382
  this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7265
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_52;
7383
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_54;
7266
7384
  return __generator(this, function (_a) {
7267
7385
  switch (_a.label) {
7268
7386
  case 0:
@@ -7307,9 +7425,9 @@ var PerpetualsClient = (function () {
7307
7425
  instructions.push(initCompoundingInstruction);
7308
7426
  return [3, 4];
7309
7427
  case 3:
7310
- err_52 = _a.sent();
7311
- console.log("perpClient initCompounding error:: ", err_52);
7312
- throw err_52;
7428
+ err_54 = _a.sent();
7429
+ console.log("perpClient initCompounding error:: ", err_54);
7430
+ throw err_54;
7313
7431
  case 4: return [2, {
7314
7432
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7315
7433
  additionalSigners: additionalSigners
@@ -7318,7 +7436,7 @@ var PerpetualsClient = (function () {
7318
7436
  });
7319
7437
  }); };
7320
7438
  this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7321
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_53;
7439
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_55;
7322
7440
  return __generator(this, function (_a) {
7323
7441
  switch (_a.label) {
7324
7442
  case 0:
@@ -7359,9 +7477,9 @@ var PerpetualsClient = (function () {
7359
7477
  instructions.push(initTokenVaultInstruction);
7360
7478
  return [3, 4];
7361
7479
  case 3:
7362
- err_53 = _a.sent();
7363
- console.log("perpClient InitTokenVaultInstruction error:: ", err_53);
7364
- throw err_53;
7480
+ err_55 = _a.sent();
7481
+ console.log("perpClient InitTokenVaultInstruction error:: ", err_55);
7482
+ throw err_55;
7365
7483
  case 4: return [2, {
7366
7484
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7367
7485
  additionalSigners: additionalSigners
@@ -7370,7 +7488,7 @@ var PerpetualsClient = (function () {
7370
7488
  });
7371
7489
  }); };
7372
7490
  this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7373
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_54;
7491
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_56;
7374
7492
  return __generator(this, function (_a) {
7375
7493
  switch (_a.label) {
7376
7494
  case 0:
@@ -7401,9 +7519,9 @@ var PerpetualsClient = (function () {
7401
7519
  instructions.push(setTokenVaultConfigInstruction);
7402
7520
  return [3, 4];
7403
7521
  case 3:
7404
- err_54 = _a.sent();
7405
- console.log("perpClient setTokenVaultConfigInstruction error:: ", err_54);
7406
- throw err_54;
7522
+ err_56 = _a.sent();
7523
+ console.log("perpClient setTokenVaultConfigInstruction error:: ", err_56);
7524
+ throw err_56;
7407
7525
  case 4: return [2, {
7408
7526
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7409
7527
  additionalSigners: additionalSigners
@@ -7412,7 +7530,7 @@ var PerpetualsClient = (function () {
7412
7530
  });
7413
7531
  }); };
7414
7532
  this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7415
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_55;
7533
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_57;
7416
7534
  return __generator(this, function (_a) {
7417
7535
  switch (_a.label) {
7418
7536
  case 0:
@@ -7451,9 +7569,59 @@ var PerpetualsClient = (function () {
7451
7569
  instructions.push(withdrawInstantFeeInstruction);
7452
7570
  return [3, 6];
7453
7571
  case 5:
7454
- err_55 = _a.sent();
7455
- console.log("perpClient withdrawInstantFeeInstruction error:: ", err_55);
7456
- throw err_55;
7572
+ err_57 = _a.sent();
7573
+ console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
7574
+ throw err_57;
7575
+ case 6: return [2, {
7576
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7577
+ additionalSigners: additionalSigners
7578
+ }];
7579
+ }
7580
+ });
7581
+ }); };
7582
+ this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7583
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_58;
7584
+ return __generator(this, function (_a) {
7585
+ switch (_a.label) {
7586
+ case 0:
7587
+ publicKey = this.provider.wallet.publicKey;
7588
+ preInstructions = [];
7589
+ instructions = [];
7590
+ postInstructions = [];
7591
+ additionalSigners = [];
7592
+ _a.label = 1;
7593
+ case 1:
7594
+ _a.trys.push([1, 5, , 6]);
7595
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
7596
+ case 2:
7597
+ receivingTokenAccount = _a.sent();
7598
+ return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
7599
+ case 3:
7600
+ if (!(_a.sent())) {
7601
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
7602
+ }
7603
+ return [4, this.program.methods
7604
+ .withdrawUnclaimedTokens({})
7605
+ .accounts({
7606
+ admin: publicKey,
7607
+ multisig: this.multisig.publicKey,
7608
+ perpetuals: this.perpetuals.publicKey,
7609
+ transferAuthority: poolConfig.transferAuthority,
7610
+ tokenVault: poolConfig.tokenVault,
7611
+ tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
7612
+ receivingTokenAccount: receivingTokenAccount,
7613
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
7614
+ receivingTokenMint: poolConfig.tokenMint,
7615
+ })
7616
+ .instruction()];
7617
+ case 4:
7618
+ withdrawUnclaimedTokensInstruction = _a.sent();
7619
+ instructions.push(withdrawUnclaimedTokensInstruction);
7620
+ return [3, 6];
7621
+ case 5:
7622
+ err_58 = _a.sent();
7623
+ console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
7624
+ throw err_58;
7457
7625
  case 6: return [2, {
7458
7626
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7459
7627
  additionalSigners: additionalSigners
@@ -7462,7 +7630,7 @@ var PerpetualsClient = (function () {
7462
7630
  });
7463
7631
  }); };
7464
7632
  this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7465
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_56;
7633
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_59;
7466
7634
  return __generator(this, function (_a) {
7467
7635
  switch (_a.label) {
7468
7636
  case 0:
@@ -7499,9 +7667,9 @@ var PerpetualsClient = (function () {
7499
7667
  instructions.push(initRevenueTokenAccountInstruction);
7500
7668
  return [3, 4];
7501
7669
  case 3:
7502
- err_56 = _a.sent();
7503
- console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_56);
7504
- throw err_56;
7670
+ err_59 = _a.sent();
7671
+ console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_59);
7672
+ throw err_59;
7505
7673
  case 4: return [2, {
7506
7674
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7507
7675
  additionalSigners: additionalSigners
@@ -7510,7 +7678,7 @@ var PerpetualsClient = (function () {
7510
7678
  });
7511
7679
  }); };
7512
7680
  this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7513
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_57;
7681
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_60;
7514
7682
  return __generator(this, function (_a) {
7515
7683
  switch (_a.label) {
7516
7684
  case 0:
@@ -7549,9 +7717,9 @@ var PerpetualsClient = (function () {
7549
7717
  instructions.push(distributeTokenRewardInstruction);
7550
7718
  return [3, 4];
7551
7719
  case 3:
7552
- err_57 = _a.sent();
7553
- console.log("perpClient distributeTokenRewardInstruction error:: ", err_57);
7554
- throw err_57;
7720
+ err_60 = _a.sent();
7721
+ console.log("perpClient distributeTokenRewardInstruction error:: ", err_60);
7722
+ throw err_60;
7555
7723
  case 4: return [2, {
7556
7724
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7557
7725
  additionalSigners: additionalSigners
@@ -7560,7 +7728,7 @@ var PerpetualsClient = (function () {
7560
7728
  });
7561
7729
  }); };
7562
7730
  this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
7563
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_58;
7731
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_61;
7564
7732
  return __generator(this, function (_a) {
7565
7733
  switch (_a.label) {
7566
7734
  case 0:
@@ -7588,9 +7756,9 @@ var PerpetualsClient = (function () {
7588
7756
  instructions.push(setTokenStakeLevelInstruction);
7589
7757
  return [3, 4];
7590
7758
  case 3:
7591
- err_58 = _a.sent();
7592
- console.log("perpClient setTokenStakeLevelInstruction error:: ", err_58);
7593
- throw err_58;
7759
+ err_61 = _a.sent();
7760
+ console.log("perpClient setTokenStakeLevelInstruction error:: ", err_61);
7761
+ throw err_61;
7594
7762
  case 4: return [2, {
7595
7763
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7596
7764
  additionalSigners: additionalSigners
@@ -7599,7 +7767,7 @@ var PerpetualsClient = (function () {
7599
7767
  });
7600
7768
  }); };
7601
7769
  this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7602
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_59;
7770
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_62;
7603
7771
  return __generator(this, function (_a) {
7604
7772
  switch (_a.label) {
7605
7773
  case 0:
@@ -7631,9 +7799,9 @@ var PerpetualsClient = (function () {
7631
7799
  instructions.push(setTokenRewardInstruction);
7632
7800
  return [3, 4];
7633
7801
  case 3:
7634
- err_59 = _a.sent();
7635
- console.log("perpClient setTokenRewardInstruction error:: ", err_59);
7636
- throw err_59;
7802
+ err_62 = _a.sent();
7803
+ console.log("perpClient setTokenRewardInstruction error:: ", err_62);
7804
+ throw err_62;
7637
7805
  case 4: return [2, {
7638
7806
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7639
7807
  additionalSigners: additionalSigners
@@ -7642,7 +7810,7 @@ var PerpetualsClient = (function () {
7642
7810
  });
7643
7811
  }); };
7644
7812
  this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
7645
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_60;
7813
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_63;
7646
7814
  return __generator(this, function (_a) {
7647
7815
  switch (_a.label) {
7648
7816
  case 0:
@@ -7671,9 +7839,9 @@ var PerpetualsClient = (function () {
7671
7839
  instructions.push(resizeInternalOracleInstruction);
7672
7840
  return [3, 4];
7673
7841
  case 3:
7674
- err_60 = _a.sent();
7675
- console.log("perpClient resizeInternalOracleInstruction error:: ", err_60);
7676
- throw err_60;
7842
+ err_63 = _a.sent();
7843
+ console.log("perpClient resizeInternalOracleInstruction error:: ", err_63);
7844
+ throw err_63;
7677
7845
  case 4: return [2, {
7678
7846
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7679
7847
  additionalSigners: additionalSigners