flash-sdk 9.0.0-alpha.9 → 9.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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;
@@ -1968,6 +1968,14 @@ var PerpetualsClient = (function () {
1968
1968
  case 3: return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
1969
1969
  case 4:
1970
1970
  result = _f.sent();
1971
+ if (result.value.err) {
1972
+ console.error('error Simulation failed:::', result);
1973
+ return [2, {
1974
+ amount: undefined,
1975
+ fee: undefined,
1976
+ error: 'Simulation failed: ' + JSON.stringify(result.value.err),
1977
+ }];
1978
+ }
1971
1979
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
1972
1980
  res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
1973
1981
  return [2, {
@@ -2048,9 +2056,11 @@ var PerpetualsClient = (function () {
2048
2056
  result = _f.sent();
2049
2057
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
2050
2058
  if (result.value.err) {
2059
+ console.error('error Simulation failed:', result);
2051
2060
  return [2, {
2052
- amount: new anchor_1.BN(0),
2053
- fee: new anchor_1.BN(0),
2061
+ amount: undefined,
2062
+ fee: undefined,
2063
+ error: 'Simulation failed: ' + JSON.stringify(result.value.err),
2054
2064
  }];
2055
2065
  }
2056
2066
  res = this.viewHelper.decodeLogs(result, index, 'getRemoveLiquidityAmountAndFee');
@@ -2686,7 +2696,7 @@ var PerpetualsClient = (function () {
2686
2696
  args_1[_i - 9] = arguments[_i];
2687
2697
  }
2688
2698
  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;
2699
+ 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
2700
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2691
2701
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2692
2702
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
@@ -2782,14 +2792,7 @@ var PerpetualsClient = (function () {
2782
2792
  }
2783
2793
  _c.label = 10;
2784
2794
  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]);
2795
+ _c.trys.push([10, 12, , 13]);
2793
2796
  return [4, this.program.methods
2794
2797
  .swapAndOpen({
2795
2798
  amountIn: amountIn,
@@ -2825,15 +2828,15 @@ var PerpetualsClient = (function () {
2825
2828
  })
2826
2829
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
2827
2830
  .instruction()];
2828
- case 12:
2831
+ case 11:
2829
2832
  inx = _c.sent();
2830
2833
  instructions.push(inx);
2831
- return [3, 14];
2832
- case 13:
2834
+ return [3, 13];
2835
+ case 12:
2833
2836
  err_3 = _c.sent();
2834
2837
  console.error("perpClient SwapAndOpen error:: ", err_3);
2835
2838
  throw err_3;
2836
- case 14: return [2, {
2839
+ case 13: return [2, {
2837
2840
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2838
2841
  additionalSigners: additionalSigners
2839
2842
  }];
@@ -5382,13 +5385,143 @@ var PerpetualsClient = (function () {
5382
5385
  });
5383
5386
  });
5384
5387
  };
5388
+ this.collectRebate = function (owner_1, rebateSymbol_1, poolConfig_1) {
5389
+ var args_1 = [];
5390
+ for (var _i = 3; _i < arguments.length; _i++) {
5391
+ args_1[_i - 3] = arguments[_i];
5392
+ }
5393
+ return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
5394
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, _a, collectRebateInstruction, err_28;
5395
+ if (createUserATA === void 0) { createUserATA = true; }
5396
+ return __generator(this, function (_b) {
5397
+ switch (_b.label) {
5398
+ case 0:
5399
+ publicKey = this.provider.wallet.publicKey;
5400
+ preInstructions = [];
5401
+ instructions = [];
5402
+ postInstructions = [];
5403
+ additionalSigners = [];
5404
+ _b.label = 1;
5405
+ case 1:
5406
+ _b.trys.push([1, 5, , 6]);
5407
+ rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
5408
+ tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
5409
+ userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
5410
+ _a = createUserATA;
5411
+ if (!_a) return [3, 3];
5412
+ return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
5413
+ case 2:
5414
+ _a = !(_b.sent());
5415
+ _b.label = 3;
5416
+ case 3:
5417
+ if (_a) {
5418
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
5419
+ }
5420
+ return [4, this.program.methods
5421
+ .collectRebate()
5422
+ .accounts({
5423
+ owner: owner,
5424
+ receivingTokenAccount: userTokenAccount,
5425
+ perpetuals: this.perpetuals.publicKey,
5426
+ transferAuthority: poolConfig.transferAuthority,
5427
+ rebateVault: poolConfig.rebateVault,
5428
+ rebateTokenAccount: poolConfig.rebateTokenAccount,
5429
+ tokenStakeAccount: tokenStakeAccount,
5430
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5431
+ eventAuthority: this.eventAuthority.publicKey,
5432
+ program: this.programId,
5433
+ receivingTokenMint: rebateMint,
5434
+ })
5435
+ .instruction()];
5436
+ case 4:
5437
+ collectRebateInstruction = _b.sent();
5438
+ instructions.push(collectRebateInstruction);
5439
+ return [3, 6];
5440
+ case 5:
5441
+ err_28 = _b.sent();
5442
+ console.log("perpClient collectRebateInstruction error:: ", err_28);
5443
+ throw err_28;
5444
+ case 6: return [2, {
5445
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5446
+ additionalSigners: additionalSigners
5447
+ }];
5448
+ }
5449
+ });
5450
+ });
5451
+ };
5452
+ this.settleRebates = function (owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1) {
5453
+ var args_1 = [];
5454
+ for (var _i = 4; _i < arguments.length; _i++) {
5455
+ args_1[_i - 4] = arguments[_i];
5456
+ }
5457
+ return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, rewardSymbol, poolConfig, createUserATA) {
5458
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, rebateMint, userTokenAccount, _a, settleRebatesInstruction, err_29;
5459
+ if (createUserATA === void 0) { createUserATA = true; }
5460
+ return __generator(this, function (_b) {
5461
+ switch (_b.label) {
5462
+ case 0:
5463
+ publicKey = this.provider.wallet.publicKey;
5464
+ preInstructions = [];
5465
+ instructions = [];
5466
+ postInstructions = [];
5467
+ additionalSigners = [];
5468
+ _b.label = 1;
5469
+ case 1:
5470
+ _b.trys.push([1, 5, , 6]);
5471
+ rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
5472
+ rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
5473
+ userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
5474
+ _a = createUserATA;
5475
+ if (!_a) return [3, 3];
5476
+ return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
5477
+ case 2:
5478
+ _a = !(_b.sent());
5479
+ _b.label = 3;
5480
+ case 3:
5481
+ if (_a) {
5482
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
5483
+ }
5484
+ return [4, this.program.methods
5485
+ .settleRebates()
5486
+ .accounts({
5487
+ transferAuthority: poolConfig.transferAuthority,
5488
+ perpetuals: this.perpetuals.publicKey,
5489
+ pool: poolConfig.poolAddress,
5490
+ rewardCustody: rewardCustody.custodyAccount,
5491
+ rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
5492
+ rewardCustodyTokenAccount: rewardCustody.tokenAccount,
5493
+ rebateVault: poolConfig.rebateVault,
5494
+ rebateTokenAccount: poolConfig.rebateTokenAccount,
5495
+ tokenMint: rebateMint,
5496
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5497
+ eventAuthority: this.eventAuthority.publicKey,
5498
+ program: this.programId,
5499
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5500
+ })
5501
+ .instruction()];
5502
+ case 4:
5503
+ settleRebatesInstruction = _b.sent();
5504
+ instructions.push(settleRebatesInstruction);
5505
+ return [3, 6];
5506
+ case 5:
5507
+ err_29 = _b.sent();
5508
+ console.log("perpClient settleRebatesInstruction error:: ", err_29);
5509
+ throw err_29;
5510
+ case 6: return [2, {
5511
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5512
+ additionalSigners: additionalSigners
5513
+ }];
5514
+ }
5515
+ });
5516
+ });
5517
+ };
5385
5518
  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
5519
  var args_1 = [];
5387
5520
  for (var _i = 11; _i < arguments.length; _i++) {
5388
5521
  args_1[_i - 11] = arguments[_i];
5389
5522
  }
5390
5523
  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;
5524
+ 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
5525
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5393
5526
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5394
5527
  return __generator(this, function (_c) {
@@ -5494,9 +5627,9 @@ var PerpetualsClient = (function () {
5494
5627
  instructions.push(placeLimitOrder);
5495
5628
  return [3, 10];
5496
5629
  case 9:
5497
- err_28 = _c.sent();
5498
- console.log("perpClient placeLimitOrder error:: ", err_28);
5499
- throw err_28;
5630
+ err_30 = _c.sent();
5631
+ console.log("perpClient placeLimitOrder error:: ", err_30);
5632
+ throw err_30;
5500
5633
  case 10: return [2, {
5501
5634
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5502
5635
  additionalSigners: additionalSigners
@@ -5511,7 +5644,7 @@ var PerpetualsClient = (function () {
5511
5644
  args_1[_i - 11] = arguments[_i];
5512
5645
  }
5513
5646
  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;
5647
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_31;
5515
5648
  if (createUserATA === void 0) { createUserATA = true; }
5516
5649
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5517
5650
  return __generator(this, function (_b) {
@@ -5602,9 +5735,9 @@ var PerpetualsClient = (function () {
5602
5735
  instructions.push(editLimitOrder);
5603
5736
  return [3, 8];
5604
5737
  case 7:
5605
- err_29 = _b.sent();
5606
- console.log("perpClient editLimitOrder error:: ", err_29);
5607
- throw err_29;
5738
+ err_31 = _b.sent();
5739
+ console.log("perpClient editLimitOrder error:: ", err_31);
5740
+ throw err_31;
5608
5741
  case 8: return [2, {
5609
5742
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5610
5743
  additionalSigners: additionalSigners
@@ -5619,7 +5752,7 @@ var PerpetualsClient = (function () {
5619
5752
  args_1[_i - 7] = arguments[_i];
5620
5753
  }
5621
5754
  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;
5755
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_32;
5623
5756
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
5624
5757
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
5625
5758
  return __generator(this, function (_a) {
@@ -5671,9 +5804,9 @@ var PerpetualsClient = (function () {
5671
5804
  instructions.push(executeLimitOrder);
5672
5805
  return [3, 4];
5673
5806
  case 3:
5674
- err_30 = _a.sent();
5675
- console.log("perpClient executeLimitOrder error:: ", err_30);
5676
- throw err_30;
5807
+ err_32 = _a.sent();
5808
+ console.log("perpClient executeLimitOrder error:: ", err_32);
5809
+ throw err_32;
5677
5810
  case 4: return [2, {
5678
5811
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5679
5812
  additionalSigners: additionalSigners
@@ -5688,7 +5821,7 @@ var PerpetualsClient = (function () {
5688
5821
  args_1[_i - 8] = arguments[_i];
5689
5822
  }
5690
5823
  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;
5824
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_33;
5692
5825
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
5693
5826
  if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
5694
5827
  return __generator(this, function (_a) {
@@ -5743,9 +5876,9 @@ var PerpetualsClient = (function () {
5743
5876
  instructions.push(executeLimitWithSwap);
5744
5877
  return [3, 4];
5745
5878
  case 3:
5746
- err_31 = _a.sent();
5747
- console.log("perpClient executeLimitWithSwap error:: ", err_31);
5748
- throw err_31;
5879
+ err_33 = _a.sent();
5880
+ console.log("perpClient executeLimitWithSwap error:: ", err_33);
5881
+ throw err_33;
5749
5882
  case 4: return [2, {
5750
5883
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5751
5884
  additionalSigners: additionalSigners
@@ -5755,7 +5888,7 @@ var PerpetualsClient = (function () {
5755
5888
  });
5756
5889
  };
5757
5890
  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;
5891
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_34;
5759
5892
  return __generator(this, function (_a) {
5760
5893
  switch (_a.label) {
5761
5894
  case 0:
@@ -5803,9 +5936,9 @@ var PerpetualsClient = (function () {
5803
5936
  instructions.push(placeTriggerOrder);
5804
5937
  return [3, 4];
5805
5938
  case 3:
5806
- err_32 = _a.sent();
5807
- console.log("perpClient placeTriggerOrder error:: ", err_32);
5808
- throw err_32;
5939
+ err_34 = _a.sent();
5940
+ console.log("perpClient placeTriggerOrder error:: ", err_34);
5941
+ throw err_34;
5809
5942
  case 4: return [2, {
5810
5943
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5811
5944
  additionalSigners: additionalSigners
@@ -5814,7 +5947,7 @@ var PerpetualsClient = (function () {
5814
5947
  });
5815
5948
  }); };
5816
5949
  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;
5950
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_35;
5818
5951
  return __generator(this, function (_a) {
5819
5952
  switch (_a.label) {
5820
5953
  case 0:
@@ -5861,9 +5994,9 @@ var PerpetualsClient = (function () {
5861
5994
  instructions.push(editTriggerOrder);
5862
5995
  return [3, 4];
5863
5996
  case 3:
5864
- err_33 = _a.sent();
5865
- console.log("perpClient editTriggerOrder error:: ", err_33);
5866
- throw err_33;
5997
+ err_35 = _a.sent();
5998
+ console.log("perpClient editTriggerOrder error:: ", err_35);
5999
+ throw err_35;
5867
6000
  case 4: return [2, {
5868
6001
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5869
6002
  additionalSigners: additionalSigners
@@ -5872,7 +6005,7 @@ var PerpetualsClient = (function () {
5872
6005
  });
5873
6006
  }); };
5874
6007
  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;
6008
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_36;
5876
6009
  return __generator(this, function (_a) {
5877
6010
  switch (_a.label) {
5878
6011
  case 0:
@@ -5905,9 +6038,9 @@ var PerpetualsClient = (function () {
5905
6038
  instructions.push(cancelTriggerOrder);
5906
6039
  return [3, 4];
5907
6040
  case 3:
5908
- err_34 = _a.sent();
5909
- console.log("perpClient cancelTriggerOrder error:: ", err_34);
5910
- throw err_34;
6041
+ err_36 = _a.sent();
6042
+ console.log("perpClient cancelTriggerOrder error:: ", err_36);
6043
+ throw err_36;
5911
6044
  case 4: return [2, {
5912
6045
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5913
6046
  additionalSigners: additionalSigners
@@ -5916,7 +6049,7 @@ var PerpetualsClient = (function () {
5916
6049
  });
5917
6050
  }); };
5918
6051
  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;
6052
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_37;
5920
6053
  return __generator(this, function (_a) {
5921
6054
  switch (_a.label) {
5922
6055
  case 0:
@@ -5947,9 +6080,9 @@ var PerpetualsClient = (function () {
5947
6080
  instructions.push(cancelAllTriggerOrders);
5948
6081
  return [3, 4];
5949
6082
  case 3:
5950
- err_35 = _a.sent();
5951
- console.log("perpClient cancelAllTriggerOrders error:: ", err_35);
5952
- throw err_35;
6083
+ err_37 = _a.sent();
6084
+ console.log("perpClient cancelAllTriggerOrders error:: ", err_37);
6085
+ throw err_37;
5953
6086
  case 4: return [2, {
5954
6087
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5955
6088
  additionalSigners: additionalSigners
@@ -5963,7 +6096,7 @@ var PerpetualsClient = (function () {
5963
6096
  args_1[_i - 9] = arguments[_i];
5964
6097
  }
5965
6098
  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;
6099
+ 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
6100
  if (createUserATA === void 0) { createUserATA = true; }
5968
6101
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5969
6102
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6069,9 +6202,9 @@ var PerpetualsClient = (function () {
6069
6202
  instructions.push(executeTriggerWithSwap);
6070
6203
  return [3, 10];
6071
6204
  case 9:
6072
- err_36 = _e.sent();
6073
- console.log("perpClient executeTriggerWithSwap error:: ", err_36);
6074
- throw err_36;
6205
+ err_38 = _e.sent();
6206
+ console.log("perpClient executeTriggerWithSwap error:: ", err_38);
6207
+ throw err_38;
6075
6208
  case 10: return [2, {
6076
6209
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6077
6210
  additionalSigners: additionalSigners
@@ -6086,7 +6219,7 @@ var PerpetualsClient = (function () {
6086
6219
  args_1[_i - 8] = arguments[_i];
6087
6220
  }
6088
6221
  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;
6222
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_39;
6090
6223
  if (createUserATA === void 0) { createUserATA = true; }
6091
6224
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6092
6225
  if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
@@ -6157,9 +6290,9 @@ var PerpetualsClient = (function () {
6157
6290
  instructions.push(executeTriggerOrder);
6158
6291
  return [3, 8];
6159
6292
  case 7:
6160
- err_37 = _b.sent();
6161
- console.log("perpClient executeTriggerOrder error:: ", err_37);
6162
- throw err_37;
6293
+ err_39 = _b.sent();
6294
+ console.log("perpClient executeTriggerOrder error:: ", err_39);
6295
+ throw err_39;
6163
6296
  case 8: return [2, {
6164
6297
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6165
6298
  additionalSigners: additionalSigners
@@ -6174,7 +6307,7 @@ var PerpetualsClient = (function () {
6174
6307
  args_1[_i - 5] = arguments[_i];
6175
6308
  }
6176
6309
  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;
6310
+ 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
6311
  if (useFeesPool === void 0) { useFeesPool = false; }
6179
6312
  if (createUserATA === void 0) { createUserATA = true; }
6180
6313
  if (unWrapSol === void 0) { unWrapSol = false; }
@@ -6379,9 +6512,9 @@ var PerpetualsClient = (function () {
6379
6512
  }
6380
6513
  return [3, 20];
6381
6514
  case 19:
6382
- err_38 = _g.sent();
6383
- console.error("perpClient Swap error:: ", err_38);
6384
- throw err_38;
6515
+ err_40 = _g.sent();
6516
+ console.error("perpClient Swap error:: ", err_40);
6517
+ throw err_40;
6385
6518
  case 20: return [2, {
6386
6519
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6387
6520
  additionalSigners: additionalSigners
@@ -6391,7 +6524,7 @@ var PerpetualsClient = (function () {
6391
6524
  });
6392
6525
  };
6393
6526
  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;
6527
+ var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_41;
6395
6528
  return __generator(this, function (_b) {
6396
6529
  switch (_b.label) {
6397
6530
  case 0:
@@ -6447,9 +6580,9 @@ var PerpetualsClient = (function () {
6447
6580
  instructions.push(inx);
6448
6581
  return [3, 4];
6449
6582
  case 3:
6450
- err_39 = _b.sent();
6451
- console.error("perpClient Swap error:: ", err_39);
6452
- throw err_39;
6583
+ err_41 = _b.sent();
6584
+ console.error("perpClient Swap error:: ", err_41);
6585
+ throw err_41;
6453
6586
  case 4: return [2, {
6454
6587
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6455
6588
  additionalSigners: additionalSigners
@@ -6458,7 +6591,7 @@ var PerpetualsClient = (function () {
6458
6591
  });
6459
6592
  }); };
6460
6593
  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;
6594
+ var instructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, setLpTokenPriceInstruction, err_42;
6462
6595
  return __generator(this, function (_d) {
6463
6596
  switch (_d.label) {
6464
6597
  case 0:
@@ -6506,9 +6639,9 @@ var PerpetualsClient = (function () {
6506
6639
  instructions.push(setLpTokenPriceInstruction);
6507
6640
  return [3, 4];
6508
6641
  case 3:
6509
- err_40 = _d.sent();
6510
- console.log("perpClient setLpTokenPriceInstruction error:: ", err_40);
6511
- throw err_40;
6642
+ err_42 = _d.sent();
6643
+ console.log("perpClient setLpTokenPriceInstruction error:: ", err_42);
6644
+ throw err_42;
6512
6645
  case 4: return [2, {
6513
6646
  instructions: __spreadArray([], instructions, true),
6514
6647
  additionalSigners: additionalSigners
@@ -6556,7 +6689,7 @@ var PerpetualsClient = (function () {
6556
6689
  });
6557
6690
  }); };
6558
6691
  this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
6559
- var adminMetas, _i, admins_2, admin, err_41;
6692
+ var adminMetas, _i, admins_2, admin, err_43;
6560
6693
  return __generator(this, function (_a) {
6561
6694
  switch (_a.label) {
6562
6695
  case 0:
@@ -6586,11 +6719,11 @@ var PerpetualsClient = (function () {
6586
6719
  _a.sent();
6587
6720
  return [3, 4];
6588
6721
  case 3:
6589
- err_41 = _a.sent();
6722
+ err_43 = _a.sent();
6590
6723
  if (this.printErrors) {
6591
- console.error("setAdminSigners err:", err_41);
6724
+ console.error("setAdminSigners err:", err_43);
6592
6725
  }
6593
- throw err_41;
6726
+ throw err_43;
6594
6727
  case 4: return [2];
6595
6728
  }
6596
6729
  });
@@ -6779,7 +6912,7 @@ var PerpetualsClient = (function () {
6779
6912
  });
6780
6913
  }); };
6781
6914
  this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6782
- var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_42;
6915
+ var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_44;
6783
6916
  return __generator(this, function (_a) {
6784
6917
  switch (_a.label) {
6785
6918
  case 0:
@@ -6812,9 +6945,9 @@ var PerpetualsClient = (function () {
6812
6945
  instructions.push(withdrawFeesIx);
6813
6946
  return [3, 5];
6814
6947
  case 4:
6815
- err_42 = _a.sent();
6816
- console.log("perpClient setPool error:: ", err_42);
6817
- throw err_42;
6948
+ err_44 = _a.sent();
6949
+ console.log("perpClient setPool error:: ", err_44);
6950
+ throw err_44;
6818
6951
  case 5: return [2, {
6819
6952
  instructions: __spreadArray([], instructions, true),
6820
6953
  additionalSigners: additionalSigners
@@ -6823,7 +6956,7 @@ var PerpetualsClient = (function () {
6823
6956
  });
6824
6957
  }); };
6825
6958
  this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6826
- var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_43;
6959
+ var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_45;
6827
6960
  return __generator(this, function (_a) {
6828
6961
  switch (_a.label) {
6829
6962
  case 0:
@@ -6857,9 +6990,9 @@ var PerpetualsClient = (function () {
6857
6990
  instructions.push(moveProtocolFeesIx);
6858
6991
  return [3, 4];
6859
6992
  case 3:
6860
- err_43 = _a.sent();
6861
- console.log("perpClient setPool error:: ", err_43);
6862
- throw err_43;
6993
+ err_45 = _a.sent();
6994
+ console.log("perpClient setPool error:: ", err_45);
6995
+ throw err_45;
6863
6996
  case 4: return [2, {
6864
6997
  instructions: __spreadArray([], instructions, true),
6865
6998
  additionalSigners: additionalSigners
@@ -6868,7 +7001,7 @@ var PerpetualsClient = (function () {
6868
7001
  });
6869
7002
  }); };
6870
7003
  this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6871
- var publicKey, setProtocolFeeShareBpsIx, err_44;
7004
+ var publicKey, setProtocolFeeShareBpsIx, err_46;
6872
7005
  return __generator(this, function (_a) {
6873
7006
  switch (_a.label) {
6874
7007
  case 0:
@@ -6888,15 +7021,15 @@ var PerpetualsClient = (function () {
6888
7021
  setProtocolFeeShareBpsIx = _a.sent();
6889
7022
  return [2, setProtocolFeeShareBpsIx];
6890
7023
  case 2:
6891
- err_44 = _a.sent();
6892
- console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_44);
6893
- throw err_44;
7024
+ err_46 = _a.sent();
7025
+ console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_46);
7026
+ throw err_46;
6894
7027
  case 3: return [2];
6895
7028
  }
6896
7029
  });
6897
7030
  }); };
6898
7031
  this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
6899
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_45;
7032
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_47;
6900
7033
  return __generator(this, function (_a) {
6901
7034
  switch (_a.label) {
6902
7035
  case 0:
@@ -6923,9 +7056,9 @@ var PerpetualsClient = (function () {
6923
7056
  instructions.push(setPermissionsInstruction);
6924
7057
  return [3, 4];
6925
7058
  case 3:
6926
- err_45 = _a.sent();
6927
- console.log("perpClient setPool error:: ", err_45);
6928
- throw err_45;
7059
+ err_47 = _a.sent();
7060
+ console.log("perpClient setPool error:: ", err_47);
7061
+ throw err_47;
6929
7062
  case 4: return [2, {
6930
7063
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
6931
7064
  additionalSigners: additionalSigners
@@ -6934,7 +7067,7 @@ var PerpetualsClient = (function () {
6934
7067
  });
6935
7068
  }); };
6936
7069
  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;
7070
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_48;
6938
7071
  var _f;
6939
7072
  return __generator(this, function (_g) {
6940
7073
  switch (_g.label) {
@@ -6995,9 +7128,9 @@ var PerpetualsClient = (function () {
6995
7128
  instructions.push(reimburse);
6996
7129
  return [3, 5];
6997
7130
  case 4:
6998
- err_46 = _g.sent();
6999
- console.log("perpClient setPool error:: ", err_46);
7000
- throw err_46;
7131
+ err_48 = _g.sent();
7132
+ console.log("perpClient setPool error:: ", err_48);
7133
+ throw err_48;
7001
7134
  case 5: return [2, {
7002
7135
  instructions: __spreadArray([], instructions, true),
7003
7136
  additionalSigners: additionalSigners
@@ -7006,7 +7139,7 @@ var PerpetualsClient = (function () {
7006
7139
  });
7007
7140
  }); };
7008
7141
  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;
7142
+ var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_49;
7010
7143
  return __generator(this, function (_a) {
7011
7144
  switch (_a.label) {
7012
7145
  case 0:
@@ -7040,9 +7173,9 @@ var PerpetualsClient = (function () {
7040
7173
  instructions.push(setInternalOraclePrice);
7041
7174
  return [3, 4];
7042
7175
  case 3:
7043
- err_47 = _a.sent();
7044
- console.log("perpClient setInternalOracleAccount error:: ", err_47);
7045
- throw err_47;
7176
+ err_49 = _a.sent();
7177
+ console.log("perpClient setInternalOracleAccount error:: ", err_49);
7178
+ throw err_49;
7046
7179
  case 4: return [2, {
7047
7180
  instructions: __spreadArray([], instructions, true),
7048
7181
  additionalSigners: additionalSigners
@@ -7051,7 +7184,7 @@ var PerpetualsClient = (function () {
7051
7184
  });
7052
7185
  }); };
7053
7186
  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;
7187
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_50;
7055
7188
  return __generator(this, function (_a) {
7056
7189
  switch (_a.label) {
7057
7190
  case 0:
@@ -7062,11 +7195,6 @@ var PerpetualsClient = (function () {
7062
7195
  accountMetas = [];
7063
7196
  _loop_1 = function (tokenMint) {
7064
7197
  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
7198
  accountMetas.push({
7071
7199
  pubkey: custody.intOracleAccount,
7072
7200
  isSigner: false,
@@ -7089,8 +7217,8 @@ var PerpetualsClient = (function () {
7089
7217
  _a.trys.push([1, 3, , 4]);
7090
7218
  return [4, this.program.methods
7091
7219
  .setInternalCurrentPrice({
7092
- prices: tokenInternalPrices,
7093
- useCurrentTime: useCurrentTime ? 1 : 0
7220
+ useCurrentTime: useCurrentTime,
7221
+ prices: tokenInternalPrices
7094
7222
  })
7095
7223
  .accounts({
7096
7224
  authority: POOL_CONFIGS[0].backupOracle,
@@ -7102,9 +7230,9 @@ var PerpetualsClient = (function () {
7102
7230
  instructions.push(setInternalOraclePrice);
7103
7231
  return [3, 4];
7104
7232
  case 3:
7105
- err_48 = _a.sent();
7106
- console.log("perpClient setInternalOracleAccount error:: ", err_48);
7107
- throw err_48;
7233
+ err_50 = _a.sent();
7234
+ console.log("perpClient setInternalOracleAccount error:: ", err_50);
7235
+ throw err_50;
7108
7236
  case 4: return [2, {
7109
7237
  instructions: __spreadArray([], instructions, true),
7110
7238
  additionalSigners: additionalSigners
@@ -7113,7 +7241,7 @@ var PerpetualsClient = (function () {
7113
7241
  });
7114
7242
  }); };
7115
7243
  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;
7244
+ var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_51;
7117
7245
  return __generator(this, function (_a) {
7118
7246
  switch (_a.label) {
7119
7247
  case 0:
@@ -7153,9 +7281,9 @@ var PerpetualsClient = (function () {
7153
7281
  instructions.push(setInternalOraclePrice);
7154
7282
  return [3, 4];
7155
7283
  case 3:
7156
- err_49 = _a.sent();
7157
- console.log("perpClient setInternalOracleAccount error:: ", err_49);
7158
- throw err_49;
7284
+ err_51 = _a.sent();
7285
+ console.log("perpClient setInternalOracleAccount error:: ", err_51);
7286
+ throw err_51;
7159
7287
  case 4: return [2, {
7160
7288
  instructions: __spreadArray([], instructions, true),
7161
7289
  additionalSigners: additionalSigners
@@ -7164,7 +7292,7 @@ var PerpetualsClient = (function () {
7164
7292
  });
7165
7293
  }); };
7166
7294
  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;
7295
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_52;
7168
7296
  return __generator(this, function (_a) {
7169
7297
  switch (_a.label) {
7170
7298
  case 0:
@@ -7202,8 +7330,8 @@ var PerpetualsClient = (function () {
7202
7330
  instructions.push(renameFlp);
7203
7331
  return [3, 4];
7204
7332
  case 3:
7205
- err_50 = _a.sent();
7206
- console.log("perpClient renameFlp error:: ", err_50);
7333
+ err_52 = _a.sent();
7334
+ console.log("perpClient renameFlp error:: ", err_52);
7207
7335
  return [3, 4];
7208
7336
  case 4: return [2, {
7209
7337
  instructions: __spreadArray([], instructions, true),
@@ -7213,7 +7341,7 @@ var PerpetualsClient = (function () {
7213
7341
  });
7214
7342
  }); };
7215
7343
  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;
7344
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_53;
7217
7345
  return __generator(this, function (_a) {
7218
7346
  switch (_a.label) {
7219
7347
  case 0:
@@ -7251,9 +7379,9 @@ var PerpetualsClient = (function () {
7251
7379
  instructions.push(initStakeInstruction);
7252
7380
  return [3, 4];
7253
7381
  case 3:
7254
- err_51 = _a.sent();
7255
- console.log("perpClient InitStaking error:: ", err_51);
7256
- throw err_51;
7382
+ err_53 = _a.sent();
7383
+ console.log("perpClient InitStaking error:: ", err_53);
7384
+ throw err_53;
7257
7385
  case 4: return [2, {
7258
7386
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7259
7387
  additionalSigners: additionalSigners
@@ -7262,7 +7390,7 @@ var PerpetualsClient = (function () {
7262
7390
  });
7263
7391
  }); };
7264
7392
  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;
7393
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_54;
7266
7394
  return __generator(this, function (_a) {
7267
7395
  switch (_a.label) {
7268
7396
  case 0:
@@ -7307,9 +7435,9 @@ var PerpetualsClient = (function () {
7307
7435
  instructions.push(initCompoundingInstruction);
7308
7436
  return [3, 4];
7309
7437
  case 3:
7310
- err_52 = _a.sent();
7311
- console.log("perpClient initCompounding error:: ", err_52);
7312
- throw err_52;
7438
+ err_54 = _a.sent();
7439
+ console.log("perpClient initCompounding error:: ", err_54);
7440
+ throw err_54;
7313
7441
  case 4: return [2, {
7314
7442
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7315
7443
  additionalSigners: additionalSigners
@@ -7318,7 +7446,7 @@ var PerpetualsClient = (function () {
7318
7446
  });
7319
7447
  }); };
7320
7448
  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;
7449
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_55;
7322
7450
  return __generator(this, function (_a) {
7323
7451
  switch (_a.label) {
7324
7452
  case 0:
@@ -7359,9 +7487,9 @@ var PerpetualsClient = (function () {
7359
7487
  instructions.push(initTokenVaultInstruction);
7360
7488
  return [3, 4];
7361
7489
  case 3:
7362
- err_53 = _a.sent();
7363
- console.log("perpClient InitTokenVaultInstruction error:: ", err_53);
7364
- throw err_53;
7490
+ err_55 = _a.sent();
7491
+ console.log("perpClient InitTokenVaultInstruction error:: ", err_55);
7492
+ throw err_55;
7365
7493
  case 4: return [2, {
7366
7494
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7367
7495
  additionalSigners: additionalSigners
@@ -7370,7 +7498,7 @@ var PerpetualsClient = (function () {
7370
7498
  });
7371
7499
  }); };
7372
7500
  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;
7501
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_56;
7374
7502
  return __generator(this, function (_a) {
7375
7503
  switch (_a.label) {
7376
7504
  case 0:
@@ -7401,9 +7529,9 @@ var PerpetualsClient = (function () {
7401
7529
  instructions.push(setTokenVaultConfigInstruction);
7402
7530
  return [3, 4];
7403
7531
  case 3:
7404
- err_54 = _a.sent();
7405
- console.log("perpClient setTokenVaultConfigInstruction error:: ", err_54);
7406
- throw err_54;
7532
+ err_56 = _a.sent();
7533
+ console.log("perpClient setTokenVaultConfigInstruction error:: ", err_56);
7534
+ throw err_56;
7407
7535
  case 4: return [2, {
7408
7536
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7409
7537
  additionalSigners: additionalSigners
@@ -7412,7 +7540,7 @@ var PerpetualsClient = (function () {
7412
7540
  });
7413
7541
  }); };
7414
7542
  this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7415
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_55;
7543
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_57;
7416
7544
  return __generator(this, function (_a) {
7417
7545
  switch (_a.label) {
7418
7546
  case 0:
@@ -7451,9 +7579,59 @@ var PerpetualsClient = (function () {
7451
7579
  instructions.push(withdrawInstantFeeInstruction);
7452
7580
  return [3, 6];
7453
7581
  case 5:
7454
- err_55 = _a.sent();
7455
- console.log("perpClient withdrawInstantFeeInstruction error:: ", err_55);
7456
- throw err_55;
7582
+ err_57 = _a.sent();
7583
+ console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
7584
+ throw err_57;
7585
+ case 6: return [2, {
7586
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7587
+ additionalSigners: additionalSigners
7588
+ }];
7589
+ }
7590
+ });
7591
+ }); };
7592
+ this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7593
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_58;
7594
+ return __generator(this, function (_a) {
7595
+ switch (_a.label) {
7596
+ case 0:
7597
+ publicKey = this.provider.wallet.publicKey;
7598
+ preInstructions = [];
7599
+ instructions = [];
7600
+ postInstructions = [];
7601
+ additionalSigners = [];
7602
+ _a.label = 1;
7603
+ case 1:
7604
+ _a.trys.push([1, 5, , 6]);
7605
+ return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
7606
+ case 2:
7607
+ receivingTokenAccount = _a.sent();
7608
+ return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
7609
+ case 3:
7610
+ if (!(_a.sent())) {
7611
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
7612
+ }
7613
+ return [4, this.program.methods
7614
+ .withdrawUnclaimedTokens({})
7615
+ .accounts({
7616
+ admin: publicKey,
7617
+ multisig: this.multisig.publicKey,
7618
+ perpetuals: this.perpetuals.publicKey,
7619
+ transferAuthority: poolConfig.transferAuthority,
7620
+ tokenVault: poolConfig.tokenVault,
7621
+ tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
7622
+ receivingTokenAccount: receivingTokenAccount,
7623
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
7624
+ receivingTokenMint: poolConfig.tokenMint,
7625
+ })
7626
+ .instruction()];
7627
+ case 4:
7628
+ withdrawUnclaimedTokensInstruction = _a.sent();
7629
+ instructions.push(withdrawUnclaimedTokensInstruction);
7630
+ return [3, 6];
7631
+ case 5:
7632
+ err_58 = _a.sent();
7633
+ console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
7634
+ throw err_58;
7457
7635
  case 6: return [2, {
7458
7636
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7459
7637
  additionalSigners: additionalSigners
@@ -7462,7 +7640,7 @@ var PerpetualsClient = (function () {
7462
7640
  });
7463
7641
  }); };
7464
7642
  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;
7643
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_59;
7466
7644
  return __generator(this, function (_a) {
7467
7645
  switch (_a.label) {
7468
7646
  case 0:
@@ -7499,9 +7677,9 @@ var PerpetualsClient = (function () {
7499
7677
  instructions.push(initRevenueTokenAccountInstruction);
7500
7678
  return [3, 4];
7501
7679
  case 3:
7502
- err_56 = _a.sent();
7503
- console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_56);
7504
- throw err_56;
7680
+ err_59 = _a.sent();
7681
+ console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_59);
7682
+ throw err_59;
7505
7683
  case 4: return [2, {
7506
7684
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7507
7685
  additionalSigners: additionalSigners
@@ -7510,7 +7688,7 @@ var PerpetualsClient = (function () {
7510
7688
  });
7511
7689
  }); };
7512
7690
  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;
7691
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_60;
7514
7692
  return __generator(this, function (_a) {
7515
7693
  switch (_a.label) {
7516
7694
  case 0:
@@ -7549,9 +7727,9 @@ var PerpetualsClient = (function () {
7549
7727
  instructions.push(distributeTokenRewardInstruction);
7550
7728
  return [3, 4];
7551
7729
  case 3:
7552
- err_57 = _a.sent();
7553
- console.log("perpClient distributeTokenRewardInstruction error:: ", err_57);
7554
- throw err_57;
7730
+ err_60 = _a.sent();
7731
+ console.log("perpClient distributeTokenRewardInstruction error:: ", err_60);
7732
+ throw err_60;
7555
7733
  case 4: return [2, {
7556
7734
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7557
7735
  additionalSigners: additionalSigners
@@ -7560,7 +7738,7 @@ var PerpetualsClient = (function () {
7560
7738
  });
7561
7739
  }); };
7562
7740
  this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
7563
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_58;
7741
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_61;
7564
7742
  return __generator(this, function (_a) {
7565
7743
  switch (_a.label) {
7566
7744
  case 0:
@@ -7588,9 +7766,9 @@ var PerpetualsClient = (function () {
7588
7766
  instructions.push(setTokenStakeLevelInstruction);
7589
7767
  return [3, 4];
7590
7768
  case 3:
7591
- err_58 = _a.sent();
7592
- console.log("perpClient setTokenStakeLevelInstruction error:: ", err_58);
7593
- throw err_58;
7769
+ err_61 = _a.sent();
7770
+ console.log("perpClient setTokenStakeLevelInstruction error:: ", err_61);
7771
+ throw err_61;
7594
7772
  case 4: return [2, {
7595
7773
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7596
7774
  additionalSigners: additionalSigners
@@ -7599,7 +7777,7 @@ var PerpetualsClient = (function () {
7599
7777
  });
7600
7778
  }); };
7601
7779
  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;
7780
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_62;
7603
7781
  return __generator(this, function (_a) {
7604
7782
  switch (_a.label) {
7605
7783
  case 0:
@@ -7631,9 +7809,9 @@ var PerpetualsClient = (function () {
7631
7809
  instructions.push(setTokenRewardInstruction);
7632
7810
  return [3, 4];
7633
7811
  case 3:
7634
- err_59 = _a.sent();
7635
- console.log("perpClient setTokenRewardInstruction error:: ", err_59);
7636
- throw err_59;
7812
+ err_62 = _a.sent();
7813
+ console.log("perpClient setTokenRewardInstruction error:: ", err_62);
7814
+ throw err_62;
7637
7815
  case 4: return [2, {
7638
7816
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7639
7817
  additionalSigners: additionalSigners
@@ -7642,7 +7820,7 @@ var PerpetualsClient = (function () {
7642
7820
  });
7643
7821
  }); };
7644
7822
  this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
7645
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_60;
7823
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_63;
7646
7824
  return __generator(this, function (_a) {
7647
7825
  switch (_a.label) {
7648
7826
  case 0:
@@ -7671,9 +7849,9 @@ var PerpetualsClient = (function () {
7671
7849
  instructions.push(resizeInternalOracleInstruction);
7672
7850
  return [3, 4];
7673
7851
  case 3:
7674
- err_60 = _a.sent();
7675
- console.log("perpClient resizeInternalOracleInstruction error:: ", err_60);
7676
- throw err_60;
7852
+ err_63 = _a.sent();
7853
+ console.log("perpClient resizeInternalOracleInstruction error:: ", err_63);
7854
+ throw err_63;
7677
7855
  case 4: return [2, {
7678
7856
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7679
7857
  additionalSigners: additionalSigners