flash-sdk 2.15.2 → 2.15.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2227,7 +2227,7 @@ var PerpetualsClient = (function () {
2227
2227
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2228
2228
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2229
2229
  return __awaiter(_this, void 0, void 0, function () {
2230
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2230
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2231
2231
  return __generator(this, function (_c) {
2232
2232
  switch (_c.label) {
2233
2233
  case 0:
@@ -2244,18 +2244,17 @@ var PerpetualsClient = (function () {
2244
2244
  additionalSigners = [];
2245
2245
  if (!(collateralSymbol == 'SOL')) return [3, 4];
2246
2246
  console.log("collateralSymbol === SOL", collateralSymbol);
2247
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
2248
- case 2:
2249
- accCreationLamports = (_c.sent());
2250
- console.log("accCreationLamports:", accCreationLamports);
2251
- lamports = collateralWithfee.add(new anchor_1.BN(accCreationLamports));
2247
+ lamports = collateralWithfee.add(new anchor_1.BN(1e7));
2248
+ if (!!skipBalanceChecks) return [3, 3];
2252
2249
  _a = anchor_1.BN.bind;
2253
2250
  return [4, this.provider.connection.getBalance(publicKey)];
2254
- case 3:
2251
+ case 2:
2255
2252
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
2256
2253
  if (unWrappedSolBalance.lt(lamports)) {
2257
2254
  throw "Insufficient SOL Funds";
2258
2255
  }
2256
+ _c.label = 3;
2257
+ case 3:
2259
2258
  if (!ephemeralSignerPubkey) {
2260
2259
  wrappedSolAccount = new web3_js_1.Keypair();
2261
2260
  additionalSigners.push(wrappedSolAccount);
@@ -2274,12 +2273,13 @@ var PerpetualsClient = (function () {
2274
2273
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2275
2274
  ];
2276
2275
  return [3, 7];
2277
- case 4: return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
2276
+ case 4:
2277
+ if (!!skipBalanceChecks) return [3, 7];
2278
+ return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
2278
2279
  case 5:
2279
2280
  if (!(_c.sent())) {
2280
2281
  throw "Insufficient Funds , token Account doesn't exist";
2281
2282
  }
2282
- if (!!skipBalanceChecks) return [3, 7];
2283
2283
  _b = anchor_1.BN.bind;
2284
2284
  return [4, this.provider.connection.getTokenAccountBalance(userCollateralTokenAccount)];
2285
2285
  case 6:
@@ -2338,7 +2338,7 @@ var PerpetualsClient = (function () {
2338
2338
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2339
2339
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2340
2340
  return __awaiter(_this, void 0, void 0, function () {
2341
- var publicKey, targetCustodyConfig, collateralCustodyConfig, swapOutCustodyConfig, swapInCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, instruction;
2341
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, swapOutCustodyConfig, swapInCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, instruction;
2342
2342
  return __generator(this, function (_d) {
2343
2343
  switch (_d.label) {
2344
2344
  case 0:
@@ -2356,18 +2356,17 @@ var PerpetualsClient = (function () {
2356
2356
  additionalSigners = [];
2357
2357
  if (!(inputSymbol == 'SOL')) return [3, 3];
2358
2358
  console.log("inputSymbol === SOL", inputSymbol);
2359
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
2360
- case 1:
2361
- accCreationLamports = (_d.sent());
2362
- console.log("accCreationLamports:", accCreationLamports);
2363
- lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
2359
+ lamports = amountIn.add(new anchor_1.BN(1e7));
2360
+ if (!!skipBalanceChecks) return [3, 2];
2364
2361
  _a = anchor_1.BN.bind;
2365
2362
  return [4, this.provider.connection.getBalance(publicKey)];
2366
- case 2:
2363
+ case 1:
2367
2364
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _d.sent()]))();
2368
2365
  if (unWrappedSolBalance.lt(lamports)) {
2369
2366
  throw "Insufficient SOL Funds";
2370
2367
  }
2368
+ _d.label = 2;
2369
+ case 2:
2371
2370
  if (!ephemeralSignerPubkey) {
2372
2371
  wrappedSolAccount = new web3_js_1.Keypair();
2373
2372
  additionalSigners.push(wrappedSolAccount);
@@ -2388,12 +2387,12 @@ var PerpetualsClient = (function () {
2388
2387
  return [3, 6];
2389
2388
  case 3:
2390
2389
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true);
2390
+ if (!!skipBalanceChecks) return [3, 6];
2391
2391
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
2392
2392
  case 4:
2393
2393
  if (!(_d.sent())) {
2394
2394
  throw "Insufficient Funds , Token Account doesn't exist";
2395
2395
  }
2396
- if (!!skipBalanceChecks) return [3, 6];
2397
2396
  _b = anchor_1.BN.bind;
2398
2397
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
2399
2398
  case 5:
@@ -2410,7 +2409,6 @@ var PerpetualsClient = (function () {
2410
2409
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey));
2411
2410
  }
2412
2411
  marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
2413
- console.log('marketAccount :>> ', marketAccount.toBase58(), targetCustodyConfig.custodyAccount.toBase58(), collateralCustodyConfig.custodyAccount.toBase58());
2414
2412
  positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
2415
2413
  custodyAccountMetas = [];
2416
2414
  custodyOracleAccountMetas = [];
@@ -2495,11 +2493,9 @@ var PerpetualsClient = (function () {
2495
2493
  additionalSigners = [];
2496
2494
  _b.label = 1;
2497
2495
  case 1:
2498
- _b.trys.push([1, 9, , 10]);
2499
- if (!(collateralSymbol == 'SOL')) return [3, 3];
2500
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
2501
- case 2:
2502
- lamports = (_b.sent());
2496
+ _b.trys.push([1, 7, , 8]);
2497
+ if (!(collateralSymbol == 'SOL')) return [3, 2];
2498
+ lamports = (1e7);
2503
2499
  if (!ephemeralSignerPubkey) {
2504
2500
  wrappedSolAccount = new web3_js_1.Keypair();
2505
2501
  additionalSigners.push(wrappedSolAccount);
@@ -2517,22 +2513,21 @@ var PerpetualsClient = (function () {
2517
2513
  postInstructions = [
2518
2514
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2519
2515
  ];
2520
- return [3, 7];
2521
- case 3: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true)];
2522
- case 4:
2523
- userReceivingTokenAccount = _b.sent();
2516
+ return [3, 5];
2517
+ case 2:
2518
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
2524
2519
  _a = createUserATA;
2525
- if (!_a) return [3, 6];
2520
+ if (!_a) return [3, 4];
2526
2521
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
2527
- case 5:
2522
+ case 3:
2528
2523
  _a = !(_b.sent());
2529
- _b.label = 6;
2530
- case 6:
2524
+ _b.label = 4;
2525
+ case 4:
2531
2526
  if (_a) {
2532
2527
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
2533
2528
  }
2534
- _b.label = 7;
2535
- case 7:
2529
+ _b.label = 5;
2530
+ case 5:
2536
2531
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
2537
2532
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
2538
2533
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
@@ -2563,19 +2558,19 @@ var PerpetualsClient = (function () {
2563
2558
  })
2564
2559
  .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
2565
2560
  .instruction()];
2566
- case 8:
2561
+ case 6:
2567
2562
  instruction = _b.sent();
2568
2563
  instructions.push(instruction);
2569
2564
  if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
2570
2565
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
2571
2566
  postInstructions.push(closeWsolATAIns);
2572
2567
  }
2573
- return [3, 10];
2574
- case 9:
2568
+ return [3, 8];
2569
+ case 7:
2575
2570
  error_2 = _b.sent();
2576
2571
  console.error("perpclient closePosition error:", error_2);
2577
- return [3, 10];
2578
- case 10: return [2, {
2572
+ return [3, 8];
2573
+ case 8: return [2, {
2579
2574
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2580
2575
  additionalSigners: additionalSigners
2581
2576
  }];
@@ -2605,11 +2600,9 @@ var PerpetualsClient = (function () {
2605
2600
  instructions = [];
2606
2601
  postInstructions = [];
2607
2602
  additionalSigners = [];
2608
- if (!(outputSymbol == 'SOL')) return [3, 2];
2603
+ if (!(outputSymbol == 'SOL')) return [3, 1];
2609
2604
  console.log("outputSymbol === SOL", outputSymbol);
2610
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
2611
- case 1:
2612
- lamports = (_b.sent());
2605
+ lamports = (1e7);
2613
2606
  if (!ephemeralSignerPubkey) {
2614
2607
  wrappedSolAccount = new web3_js_1.Keypair();
2615
2608
  additionalSigners.push(wrappedSolAccount);
@@ -2628,20 +2621,20 @@ var PerpetualsClient = (function () {
2628
2621
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2629
2622
  ];
2630
2623
  additionalSigners.push(wrappedSolAccount);
2631
- return [3, 5];
2632
- case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true)];
2633
- case 3:
2624
+ return [3, 4];
2625
+ case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true)];
2626
+ case 2:
2634
2627
  userReceivingTokenAccount = _b.sent();
2635
2628
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
2636
- case 4:
2629
+ case 3:
2637
2630
  if (!(_b.sent())) {
2638
2631
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey));
2639
2632
  }
2640
- _b.label = 5;
2641
- case 5:
2633
+ _b.label = 4;
2634
+ case 4:
2642
2635
  userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
2643
2636
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
2644
- case 6:
2637
+ case 5:
2645
2638
  if (!(_b.sent())) {
2646
2639
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
2647
2640
  }
@@ -2696,7 +2689,7 @@ var PerpetualsClient = (function () {
2696
2689
  })
2697
2690
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
2698
2691
  .instruction()];
2699
- case 7:
2692
+ case 6:
2700
2693
  instruction = _b.sent();
2701
2694
  instructions.push(instruction);
2702
2695
  return [2, {
@@ -2731,7 +2724,7 @@ var PerpetualsClient = (function () {
2731
2724
  instructions = [];
2732
2725
  postInstructions = [];
2733
2726
  additionalSigners = [];
2734
- if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 4];
2727
+ if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
2735
2728
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
2736
2729
  case 1:
2737
2730
  wsolAssociatedTokenAccount = _f.sent();
@@ -2741,6 +2734,7 @@ var PerpetualsClient = (function () {
2741
2734
  if (!wsolATAExist) {
2742
2735
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
2743
2736
  }
2737
+ if (!!skipBalanceChecks) return [3, 4];
2744
2738
  _a = anchor_1.BN.bind;
2745
2739
  return [4, this.provider.connection.getBalance(publicKey)];
2746
2740
  case 3:
@@ -2748,6 +2742,8 @@ var PerpetualsClient = (function () {
2748
2742
  if (unWrappedSolBalance.lt(amountIn)) {
2749
2743
  throw "Insufficient SOL Funds";
2750
2744
  }
2745
+ _f.label = 4;
2746
+ case 4:
2751
2747
  instructions.push(web3_js_1.SystemProgram.transfer({
2752
2748
  fromPubkey: publicKey,
2753
2749
  toPubkey: wsolAssociatedTokenAccount,
@@ -2757,20 +2753,20 @@ var PerpetualsClient = (function () {
2757
2753
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2758
2754
  additionalSigners: additionalSigners
2759
2755
  }];
2760
- case 4:
2761
- if (!(userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL')) return [3, 6];
2762
- console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
2763
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
2764
2756
  case 5:
2765
- wsolAssociatedTokenAccount = _f.sent();
2766
- closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
2767
- instructions.push(closeWsolATAIns);
2768
- return [2, {
2769
- instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2770
- additionalSigners: additionalSigners
2771
- }];
2757
+ if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
2758
+ console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
2759
+ wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
2760
+ closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
2761
+ instructions.push(closeWsolATAIns);
2762
+ return [2, {
2763
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2764
+ additionalSigners: additionalSigners
2765
+ }];
2766
+ }
2767
+ _f.label = 6;
2772
2768
  case 6:
2773
- _f.trys.push([6, 21, , 22]);
2769
+ _f.trys.push([6, 19, , 20]);
2774
2770
  if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
2775
2771
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
2776
2772
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
@@ -2803,29 +2799,26 @@ var PerpetualsClient = (function () {
2803
2799
  postInstructions = [
2804
2800
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2805
2801
  ];
2806
- return [3, 13];
2807
- case 9: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true)];
2808
- case 10:
2809
- userInputTokenAccount = _f.sent();
2802
+ return [3, 12];
2803
+ case 9:
2804
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
2810
2805
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
2811
- case 11:
2806
+ case 10:
2812
2807
  if (!(_f.sent())) {
2813
2808
  throw "Insufficient Funds , Token Account doesn't exist";
2814
2809
  }
2815
- if (!!skipBalanceChecks) return [3, 13];
2810
+ if (!!skipBalanceChecks) return [3, 12];
2816
2811
  _c = anchor_1.BN.bind;
2817
2812
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
2818
- case 12:
2813
+ case 11:
2819
2814
  tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
2820
2815
  if (tokenAccountBalance.lt(amountIn)) {
2821
2816
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
2822
2817
  }
2823
- _f.label = 13;
2824
- case 13:
2825
- if (!(userOutputTokenSymbol == 'SOL')) return [3, 15];
2826
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
2827
- case 14:
2828
- lamports = (_f.sent());
2818
+ _f.label = 12;
2819
+ case 12:
2820
+ if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
2821
+ lamports = (1e7);
2829
2822
  if (!ephemeralSignerPubkey) {
2830
2823
  wrappedSolAccount = new web3_js_1.Keypair();
2831
2824
  additionalSigners.push(wrappedSolAccount);
@@ -2844,22 +2837,22 @@ var PerpetualsClient = (function () {
2844
2837
  postInstructions = [
2845
2838
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2846
2839
  ];
2847
- return [3, 19];
2848
- case 15: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
2849
- case 16:
2840
+ return [3, 17];
2841
+ case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
2842
+ case 14:
2850
2843
  userOutputTokenAccount = _f.sent();
2851
2844
  _d = createUserATA;
2852
- if (!_d) return [3, 18];
2845
+ if (!_d) return [3, 16];
2853
2846
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
2854
- case 17:
2847
+ case 15:
2855
2848
  _d = !(_f.sent());
2856
- _f.label = 18;
2857
- case 18:
2849
+ _f.label = 16;
2850
+ case 16:
2858
2851
  if (_d) {
2859
2852
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
2860
2853
  }
2861
- _f.label = 19;
2862
- case 19:
2854
+ _f.label = 17;
2855
+ case 17:
2863
2856
  custodyAccountMetas = [];
2864
2857
  custodyOracleAccountMetas = [];
2865
2858
  for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
@@ -2902,19 +2895,19 @@ var PerpetualsClient = (function () {
2902
2895
  })
2903
2896
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
2904
2897
  .instruction()];
2905
- case 20:
2898
+ case 18:
2906
2899
  inx = _f.sent();
2907
2900
  instructions.push(inx);
2908
2901
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
2909
2902
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
2910
2903
  instructions.push(closeWsolATAIns);
2911
2904
  }
2912
- return [3, 22];
2913
- case 21:
2905
+ return [3, 20];
2906
+ case 19:
2914
2907
  err_2 = _f.sent();
2915
2908
  console.error("perpClient Swap error:: ", err_2);
2916
2909
  throw err_2;
2917
- case 22: return [2, {
2910
+ case 20: return [2, {
2918
2911
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
2919
2912
  additionalSigners: additionalSigners
2920
2913
  }];
@@ -2997,7 +2990,7 @@ var PerpetualsClient = (function () {
2997
2990
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2998
2991
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2999
2992
  return __awaiter(_this, void 0, void 0, function () {
3000
- var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, solBal, tokenAccountBalance, _b, instruction;
2993
+ var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
3001
2994
  return __generator(this, function (_c) {
3002
2995
  switch (_c.label) {
3003
2996
  case 0:
@@ -3013,25 +3006,20 @@ var PerpetualsClient = (function () {
3013
3006
  instructions = [];
3014
3007
  postInstructions = [];
3015
3008
  additionalSigners = [];
3016
- if (!(collateralSymbol == 'SOL')) return [3, 4];
3009
+ if (!(collateralSymbol == 'SOL')) return [3, 3];
3017
3010
  console.log("collateralSymbol === SOL", collateralSymbol);
3018
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3019
- case 1:
3020
- accCreationLamports = (_c.sent());
3021
- console.log("accCreationLamports:", accCreationLamports);
3022
- lamports = collateralWithFee.add(new anchor_1.BN(accCreationLamports));
3011
+ lamports = collateralWithFee.add(new anchor_1.BN(1e7));
3023
3012
  console.log("lamports:", lamports.toNumber());
3013
+ if (!!skipBalanceChecks) return [3, 2];
3024
3014
  _a = anchor_1.BN.bind;
3025
3015
  return [4, this.provider.connection.getBalance(publicKey)];
3026
- case 2:
3016
+ case 1:
3027
3017
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
3028
3018
  if (unWrappedSolBalance.lt(lamports)) {
3029
3019
  throw "Insufficient SOL Funds";
3030
3020
  }
3031
- return [4, this.provider.connection.getBalance(publicKey)];
3032
- case 3:
3033
- solBal = _c.sent();
3034
- console.log("solBal>>:", solBal);
3021
+ _c.label = 2;
3022
+ case 2:
3035
3023
  if (!ephemeralSignerPubkey) {
3036
3024
  wrappedSolAccount = new web3_js_1.Keypair();
3037
3025
  additionalSigners.push(wrappedSolAccount);
@@ -3049,22 +3037,23 @@ var PerpetualsClient = (function () {
3049
3037
  postInstructions = [
3050
3038
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3051
3039
  ];
3052
- return [3, 7];
3053
- case 4: return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
3054
- case 5:
3040
+ return [3, 6];
3041
+ case 3:
3042
+ if (!!skipBalanceChecks) return [3, 6];
3043
+ return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
3044
+ case 4:
3055
3045
  if (!(_c.sent())) {
3056
3046
  throw "Insufficient Funds , token Account doesn't exist";
3057
3047
  }
3058
- if (!!skipBalanceChecks) return [3, 7];
3059
3048
  _b = anchor_1.BN.bind;
3060
3049
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
3061
- case 6:
3050
+ case 5:
3062
3051
  tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
3063
3052
  if (tokenAccountBalance.lt(collateralWithFee)) {
3064
3053
  throw "Insufficient Funds need more ".concat(collateralWithFee.sub(tokenAccountBalance), " tokens");
3065
3054
  }
3066
- _c.label = 7;
3067
- case 7: return [4, this.program.methods.addCollateral({
3055
+ _c.label = 6;
3056
+ case 6: return [4, this.program.methods.addCollateral({
3068
3057
  collateralDelta: collateralWithFee
3069
3058
  }).accounts({
3070
3059
  owner: publicKey,
@@ -3084,7 +3073,7 @@ var PerpetualsClient = (function () {
3084
3073
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3085
3074
  })
3086
3075
  .instruction()];
3087
- case 8:
3076
+ case 7:
3088
3077
  instruction = _c.sent();
3089
3078
  instructions.push(instruction);
3090
3079
  return [2, {
@@ -3099,7 +3088,7 @@ var PerpetualsClient = (function () {
3099
3088
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3100
3089
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3101
3090
  return __awaiter(_this, void 0, void 0, function () {
3102
- var publicKey, collateralCustodyConfig, targetCustodyConfig, outputCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, marketAccount, instruction;
3091
+ var publicKey, collateralCustodyConfig, targetCustodyConfig, outputCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, marketAccount, instruction;
3103
3092
  return __generator(this, function (_d) {
3104
3093
  switch (_d.label) {
3105
3094
  case 0:
@@ -3120,19 +3109,18 @@ var PerpetualsClient = (function () {
3120
3109
  additionalSigners = [];
3121
3110
  if (!(inputSymbol == 'SOL')) return [3, 3];
3122
3111
  console.log("inputSymbol === SOL", inputSymbol);
3123
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3124
- case 1:
3125
- accCreationLamports = (_d.sent());
3126
- console.log("accCreationLamports:", accCreationLamports);
3127
- lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3112
+ lamports = amountIn.add(new anchor_1.BN(1e7));
3128
3113
  console.log("lamports:", lamports.toNumber());
3114
+ if (!!skipBalanceChecks) return [3, 2];
3129
3115
  _a = anchor_1.BN.bind;
3130
3116
  return [4, this.provider.connection.getBalance(publicKey)];
3131
- case 2:
3117
+ case 1:
3132
3118
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _d.sent()]))();
3133
3119
  if (unWrappedSolBalance.lt(lamports)) {
3134
3120
  throw "Insufficient SOL Funds";
3135
3121
  }
3122
+ _d.label = 2;
3123
+ case 2:
3136
3124
  if (!ephemeralSignerPubkey) {
3137
3125
  wrappedSolAccount = new web3_js_1.Keypair();
3138
3126
  additionalSigners.push(wrappedSolAccount);
@@ -3153,12 +3141,12 @@ var PerpetualsClient = (function () {
3153
3141
  return [3, 6];
3154
3142
  case 3:
3155
3143
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
3144
+ if (!!skipBalanceChecks) return [3, 6];
3156
3145
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3157
3146
  case 4:
3158
3147
  if (!(_d.sent())) {
3159
3148
  throw "Insufficient Funds , token Account doesn't exist";
3160
3149
  }
3161
- if (!!skipBalanceChecks) return [3, 6];
3162
3150
  _b = anchor_1.BN.bind;
3163
3151
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3164
3152
  case 5:
@@ -3257,14 +3245,12 @@ var PerpetualsClient = (function () {
3257
3245
  additionalSigners = [];
3258
3246
  _b.label = 1;
3259
3247
  case 1:
3260
- _b.trys.push([1, 9, , 10]);
3248
+ _b.trys.push([1, 7, , 8]);
3261
3249
  console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
3262
- if (!(collateralSymbol == 'SOL')) return [3, 3];
3250
+ if (!(collateralSymbol == 'SOL')) return [3, 2];
3263
3251
  console.log("remove collateral in SOL ...create WSOL temp and close it ");
3264
3252
  userReceivingTokenAccount = wrappedSolAccount.publicKey;
3265
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3266
- case 2:
3267
- lamports = (_b.sent());
3253
+ lamports = 1e7;
3268
3254
  if (!ephemeralSignerPubkey) {
3269
3255
  wrappedSolAccount = new web3_js_1.Keypair();
3270
3256
  additionalSigners.push(wrappedSolAccount);
@@ -3282,22 +3268,21 @@ var PerpetualsClient = (function () {
3282
3268
  postInstructions = [
3283
3269
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3284
3270
  ];
3285
- return [3, 7];
3286
- case 3: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true)];
3287
- case 4:
3288
- userReceivingTokenAccount = _b.sent();
3271
+ return [3, 5];
3272
+ case 2:
3273
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
3289
3274
  _a = createUserATA;
3290
- if (!_a) return [3, 6];
3275
+ if (!_a) return [3, 4];
3291
3276
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3292
- case 5:
3277
+ case 3:
3293
3278
  _a = !(_b.sent());
3294
- _b.label = 6;
3295
- case 6:
3279
+ _b.label = 4;
3280
+ case 4:
3296
3281
  if (_a) {
3297
3282
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
3298
3283
  }
3299
- _b.label = 7;
3300
- case 7:
3284
+ _b.label = 5;
3285
+ case 5:
3301
3286
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
3302
3287
  return [4, this.program.methods
3303
3288
  .removeCollateral({
@@ -3322,19 +3307,19 @@ var PerpetualsClient = (function () {
3322
3307
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3323
3308
  })
3324
3309
  .instruction()];
3325
- case 8:
3310
+ case 6:
3326
3311
  instruction = _b.sent();
3327
3312
  instructions.push(instruction);
3328
3313
  if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
3329
3314
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
3330
3315
  postInstructions.push(closeWsolATAIns);
3331
3316
  }
3332
- return [3, 10];
3333
- case 9:
3317
+ return [3, 8];
3318
+ case 7:
3334
3319
  error_3 = _b.sent();
3335
3320
  console.error("perpclient removeCollateral error:", error_3);
3336
- return [3, 10];
3337
- case 10: return [2, {
3321
+ return [3, 8];
3322
+ case 8: return [2, {
3338
3323
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3339
3324
  additionalSigners: additionalSigners
3340
3325
  }];
@@ -3361,11 +3346,9 @@ var PerpetualsClient = (function () {
3361
3346
  instructions = [];
3362
3347
  postInstructions = [];
3363
3348
  additionalSigners = [];
3364
- if (!(outputSymbol == 'SOL')) return [3, 2];
3349
+ if (!(outputSymbol == 'SOL')) return [3, 1];
3365
3350
  console.log("outputSymbol === SOL", outputSymbol);
3366
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3367
- case 1:
3368
- lamports = (_b.sent());
3351
+ lamports = 1e7;
3369
3352
  if (!ephemeralSignerPubkey) {
3370
3353
  wrappedSolAccount = new web3_js_1.Keypair();
3371
3354
  additionalSigners.push(wrappedSolAccount);
@@ -3383,20 +3366,19 @@ var PerpetualsClient = (function () {
3383
3366
  postInstructions = [
3384
3367
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3385
3368
  ];
3386
- return [3, 5];
3387
- case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true)];
3388
- case 3:
3389
- userReceivingTokenAccount = _b.sent();
3369
+ return [3, 3];
3370
+ case 1:
3371
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
3390
3372
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3391
- case 4:
3373
+ case 2:
3392
3374
  if (!(_b.sent())) {
3393
3375
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey));
3394
3376
  }
3395
- _b.label = 5;
3396
- case 5:
3377
+ _b.label = 3;
3378
+ case 3:
3397
3379
  userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
3398
3380
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
3399
- case 6:
3381
+ case 4:
3400
3382
  if (!(_b.sent())) {
3401
3383
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey));
3402
3384
  }
@@ -3450,7 +3432,7 @@ var PerpetualsClient = (function () {
3450
3432
  })
3451
3433
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
3452
3434
  .instruction()];
3453
- case 7:
3435
+ case 5:
3454
3436
  instruction = _b.sent();
3455
3437
  instructions.push(instruction);
3456
3438
  return [2, {
@@ -3585,7 +3567,7 @@ var PerpetualsClient = (function () {
3585
3567
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3586
3568
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3587
3569
  return __awaiter(_this, void 0, void 0, function () {
3588
- var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, accCreationLamports, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_4;
3570
+ var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_4;
3589
3571
  return __generator(this, function (_f) {
3590
3572
  switch (_f.label) {
3591
3573
  case 0:
@@ -3600,13 +3582,9 @@ var PerpetualsClient = (function () {
3600
3582
  additionalSigners = [];
3601
3583
  _f.label = 1;
3602
3584
  case 1:
3603
- _f.trys.push([1, 12, , 13]);
3604
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(payTokenCustodyConfig.mintKey, publicKey, true)];
3605
- case 2:
3606
- userPayingTokenAccount = _f.sent();
3607
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, publicKey, true)];
3608
- case 3:
3609
- lpTokenAccount = _f.sent();
3585
+ _f.trys.push([1, 10, , 11]);
3586
+ userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
3587
+ lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3610
3588
  custodyAccountMetas = [];
3611
3589
  custodyOracleAccountMetas = [];
3612
3590
  markets = [];
@@ -3632,24 +3610,23 @@ var PerpetualsClient = (function () {
3632
3610
  });
3633
3611
  }
3634
3612
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3635
- case 4:
3613
+ case 2:
3636
3614
  if (!(_f.sent())) {
3637
3615
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
3638
3616
  }
3639
- if (!(payTokenSymbol == 'SOL')) return [3, 7];
3617
+ if (!(payTokenSymbol == 'SOL')) return [3, 5];
3640
3618
  console.log("payTokenSymbol === SOL", payTokenSymbol);
3641
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3642
- case 5:
3643
- accCreationLamports = (_f.sent());
3644
- console.log("accCreationLamports:", accCreationLamports);
3645
- lamports = tokenAmountIn.add(new anchor_1.BN(accCreationLamports));
3619
+ lamports = tokenAmountIn.add(new anchor_1.BN(1e7));
3620
+ if (!!skipBalanceChecks) return [3, 4];
3646
3621
  _d = anchor_1.BN.bind;
3647
3622
  return [4, this.provider.connection.getBalance(publicKey)];
3648
- case 6:
3623
+ case 3:
3649
3624
  unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
3650
3625
  if (unWrappedSolBalance.lt(lamports)) {
3651
3626
  throw "Insufficient SOL Funds";
3652
3627
  }
3628
+ _f.label = 4;
3629
+ case 4:
3653
3630
  if (!ephemeralSignerPubkey) {
3654
3631
  wrappedSolAccount = new web3_js_1.Keypair();
3655
3632
  additionalSigners.push(wrappedSolAccount);
@@ -3667,22 +3644,23 @@ var PerpetualsClient = (function () {
3667
3644
  postInstructions = [
3668
3645
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3669
3646
  ];
3670
- return [3, 10];
3671
- case 7: return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
3672
- case 8:
3647
+ return [3, 8];
3648
+ case 5:
3649
+ if (!!skipBalanceChecks) return [3, 8];
3650
+ return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
3651
+ case 6:
3673
3652
  if (!(_f.sent())) {
3674
3653
  throw "Insufficient Funds , token Account doesn't exist";
3675
3654
  }
3676
- if (!!skipBalanceChecks) return [3, 10];
3677
3655
  _e = anchor_1.BN.bind;
3678
3656
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
3679
- case 9:
3657
+ case 7:
3680
3658
  tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3681
3659
  if (tokenAccountBalance.lt(tokenAmountIn)) {
3682
3660
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
3683
3661
  }
3684
- _f.label = 10;
3685
- case 10: return [4, this.program.methods
3662
+ _f.label = 8;
3663
+ case 8: return [4, this.program.methods
3686
3664
  .addLiquidity({
3687
3665
  amountIn: tokenAmountIn,
3688
3666
  minLpAmountOut: minLpAmountOut
@@ -3705,15 +3683,15 @@ var PerpetualsClient = (function () {
3705
3683
  })
3706
3684
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3707
3685
  .instruction()];
3708
- case 11:
3686
+ case 9:
3709
3687
  instruction = _f.sent();
3710
3688
  instructions.push(instruction);
3711
- return [3, 13];
3712
- case 12:
3689
+ return [3, 11];
3690
+ case 10:
3713
3691
  err_4 = _f.sent();
3714
3692
  console.error("perpClient addLiquidity error:: ", err_4);
3715
3693
  throw err_4;
3716
- case 13: return [2, {
3694
+ case 11: return [2, {
3717
3695
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3718
3696
  additionalSigners: additionalSigners
3719
3697
  }];
@@ -3725,7 +3703,7 @@ var PerpetualsClient = (function () {
3725
3703
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3726
3704
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3727
3705
  return __awaiter(_this, void 0, void 0, function () {
3728
- var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
3706
+ var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
3729
3707
  return __generator(this, function (_f) {
3730
3708
  switch (_f.label) {
3731
3709
  case 0:
@@ -3736,28 +3714,24 @@ var PerpetualsClient = (function () {
3736
3714
  additionalSigners = [];
3737
3715
  lpTokenMint = poolConfig.stakedLpTokenMint;
3738
3716
  inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
3739
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(lpTokenMint, publicKey, true)];
3740
- case 1:
3741
- lpTokenAccount = _f.sent();
3717
+ lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, publicKey, true);
3742
3718
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
3743
3719
  poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
3744
- if (!(inputSymbol == 'SOL')) return [3, 5];
3720
+ if (!(inputSymbol == 'SOL')) return [3, 4];
3745
3721
  console.log("inputSymbol === SOL", inputSymbol);
3746
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3747
- case 2:
3748
- accCreationLamports = (_f.sent());
3749
- console.log("accCreationLamports:", accCreationLamports);
3750
- lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3722
+ lamports = amountIn.add(new anchor_1.BN(1e7));
3751
3723
  console.log("lamports:", lamports.toNumber());
3724
+ if (!!skipBalanceChecks) return [3, 2];
3752
3725
  _a = anchor_1.BN.bind;
3753
3726
  return [4, this.provider.connection.getBalance(publicKey)];
3754
- case 3:
3727
+ case 1:
3755
3728
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3756
3729
  if (unWrappedSolBalance.lt(lamports)) {
3757
3730
  throw "Insufficient SOL Funds";
3758
3731
  }
3759
- return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3760
- case 4:
3732
+ _f.label = 2;
3733
+ case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3734
+ case 3:
3761
3735
  if (!(_f.sent())) {
3762
3736
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
3763
3737
  }
@@ -3778,24 +3752,24 @@ var PerpetualsClient = (function () {
3778
3752
  postInstructions = [
3779
3753
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3780
3754
  ];
3781
- return [3, 8];
3782
- case 5:
3755
+ return [3, 7];
3756
+ case 4:
3783
3757
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
3758
+ if (!!skipBalanceChecks) return [3, 7];
3784
3759
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3785
- case 6:
3760
+ case 5:
3786
3761
  if (!(_f.sent())) {
3787
3762
  throw "Insufficient Funds , token Account doesn't exist";
3788
3763
  }
3789
- if (!!skipBalanceChecks) return [3, 8];
3790
3764
  _b = anchor_1.BN.bind;
3791
3765
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3792
- case 7:
3766
+ case 6:
3793
3767
  tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3794
3768
  if (tokenAccountBalance.lt(amountIn)) {
3795
3769
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3796
3770
  }
3797
- _f.label = 8;
3798
- case 8:
3771
+ _f.label = 7;
3772
+ case 7:
3799
3773
  custodyAccountMetas = [];
3800
3774
  custodyOracleAccountMetas = [];
3801
3775
  markets = [];
@@ -3844,7 +3818,7 @@ var PerpetualsClient = (function () {
3844
3818
  })
3845
3819
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3846
3820
  .instruction()];
3847
- case 9:
3821
+ case 8:
3848
3822
  instruction = _f.sent();
3849
3823
  instructions.push(instruction);
3850
3824
  return [2, {
@@ -3876,10 +3850,8 @@ var PerpetualsClient = (function () {
3876
3850
  additionalSigners = [];
3877
3851
  _e.label = 1;
3878
3852
  case 1:
3879
- _e.trys.push([1, 10, , 11]);
3880
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, publicKey, true)];
3881
- case 2:
3882
- stakedLpTokenAccount = _e.sent();
3853
+ _e.trys.push([1, 7, , 8]);
3854
+ stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3883
3855
  custodyAccountMetas = [];
3884
3856
  custodyOracleAccountMetas = [];
3885
3857
  markets = [];
@@ -3904,10 +3876,8 @@ var PerpetualsClient = (function () {
3904
3876
  isWritable: false,
3905
3877
  });
3906
3878
  }
3907
- if (!(recieveTokenSymbol == 'SOL')) return [3, 4];
3908
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3909
- case 3:
3910
- lamports = (_e.sent());
3879
+ if (!(recieveTokenSymbol == 'SOL')) return [3, 2];
3880
+ lamports = 1e7;
3911
3881
  if (!ephemeralSignerPubkey) {
3912
3882
  wrappedSolAccount = new web3_js_1.Keypair();
3913
3883
  additionalSigners.push(wrappedSolAccount);
@@ -3925,47 +3895,44 @@ var PerpetualsClient = (function () {
3925
3895
  postInstructions = [
3926
3896
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3927
3897
  ];
3928
- return [3, 8];
3929
- case 4: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true)];
3930
- case 5:
3931
- userReceivingTokenAccount = _e.sent();
3898
+ return [3, 5];
3899
+ case 2:
3900
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
3932
3901
  _d = createUserATA;
3933
- if (!_d) return [3, 7];
3902
+ if (!_d) return [3, 4];
3934
3903
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3935
- case 6:
3904
+ case 3:
3936
3905
  _d = !(_e.sent());
3937
- _e.label = 7;
3938
- case 7:
3906
+ _e.label = 4;
3907
+ case 4:
3939
3908
  if (_d) {
3940
3909
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
3941
3910
  }
3942
- _e.label = 8;
3943
- case 8:
3944
- console.log("liquidityAmountIn", liquidityAmountIn.toString());
3945
- return [4, this.program.methods
3946
- .removeLiquidity({
3947
- lpAmountIn: liquidityAmountIn,
3948
- minAmountOut: minTokenAmountOut
3949
- })
3950
- .accounts({
3951
- owner: publicKey,
3952
- receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
3953
- lpTokenAccount: stakedLpTokenAccount,
3954
- transferAuthority: poolConfig.transferAuthority,
3955
- perpetuals: poolConfig.perpetuals,
3956
- pool: poolConfig.poolAddress,
3957
- custody: recieveTokenCustodyConfig.custodyAccount,
3958
- custodyOracleAccount: this.useExtOracleAccount ? recieveTokenCustodyConfig.extOracleAccount : recieveTokenCustodyConfig.intOracleAccount,
3959
- custodyTokenAccount: recieveTokenCustodyConfig.tokenAccount,
3960
- lpTokenMint: poolConfig.stakedLpTokenMint,
3961
- eventAuthority: this.eventAuthority.publicKey,
3962
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3963
- program: this.programId,
3964
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3965
- })
3966
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3967
- .instruction()];
3968
- case 9:
3911
+ _e.label = 5;
3912
+ case 5: return [4, this.program.methods
3913
+ .removeLiquidity({
3914
+ lpAmountIn: liquidityAmountIn,
3915
+ minAmountOut: minTokenAmountOut
3916
+ })
3917
+ .accounts({
3918
+ owner: publicKey,
3919
+ receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
3920
+ lpTokenAccount: stakedLpTokenAccount,
3921
+ transferAuthority: poolConfig.transferAuthority,
3922
+ perpetuals: poolConfig.perpetuals,
3923
+ pool: poolConfig.poolAddress,
3924
+ custody: recieveTokenCustodyConfig.custodyAccount,
3925
+ custodyOracleAccount: this.useExtOracleAccount ? recieveTokenCustodyConfig.extOracleAccount : recieveTokenCustodyConfig.intOracleAccount,
3926
+ custodyTokenAccount: recieveTokenCustodyConfig.tokenAccount,
3927
+ lpTokenMint: poolConfig.stakedLpTokenMint,
3928
+ eventAuthority: this.eventAuthority.publicKey,
3929
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3930
+ program: this.programId,
3931
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3932
+ })
3933
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3934
+ .instruction()];
3935
+ case 6:
3969
3936
  removeLiquidityTx = _e.sent();
3970
3937
  instructions.push(removeLiquidityTx);
3971
3938
  if (closeLpATA) {
@@ -3976,12 +3943,12 @@ var PerpetualsClient = (function () {
3976
3943
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
3977
3944
  postInstructions.push(closeWsolATAIns);
3978
3945
  }
3979
- return [3, 11];
3980
- case 10:
3946
+ return [3, 8];
3947
+ case 7:
3981
3948
  err_5 = _e.sent();
3982
3949
  console.log("perpClient removeLiquidity error:: ", err_5);
3983
3950
  throw err_5;
3984
- case 11: return [2, {
3951
+ case 8: return [2, {
3985
3952
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3986
3953
  additionalSigners: additionalSigners
3987
3954
  }];
@@ -4039,15 +4006,13 @@ var PerpetualsClient = (function () {
4039
4006
  additionalSigners = [];
4040
4007
  _a.label = 1;
4041
4008
  case 1:
4042
- _a.trys.push([1, 4, , 5]);
4009
+ _a.trys.push([1, 3, , 4]);
4043
4010
  nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
4044
4011
  Buffer.from("trading"),
4045
4012
  nftMint.toBuffer(),
4046
4013
  ], this.programId)[0];
4047
4014
  metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
4048
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, owner, true)];
4049
- case 2:
4050
- nftTokenAccount = _a.sent();
4015
+ nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
4051
4016
  return [4, this.program.methods
4052
4017
  .createTradingAccount({
4053
4018
  collectionIndex: 0
@@ -4063,15 +4028,15 @@ var PerpetualsClient = (function () {
4063
4028
  systemProgram: web3_js_1.SystemProgram.programId
4064
4029
  })
4065
4030
  .instruction()];
4066
- case 3:
4031
+ case 2:
4067
4032
  createNftTradingAccountInstruction = _a.sent();
4068
4033
  instructions.push(createNftTradingAccountInstruction);
4069
- return [3, 5];
4070
- case 4:
4034
+ return [3, 4];
4035
+ case 3:
4071
4036
  err_7 = _a.sent();
4072
4037
  console.log("perpClient createNftAccount error:: ", err_7);
4073
4038
  throw err_7;
4074
- case 5: return [2, {
4039
+ case 4: return [2, {
4075
4040
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4076
4041
  additionalSigners: additionalSigners
4077
4042
  }];
@@ -4436,7 +4401,7 @@ var PerpetualsClient = (function () {
4436
4401
  });
4437
4402
  }); };
4438
4403
  this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
4439
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, flpStakeAccount, unstakeInstantInstruction, err_14;
4404
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, unstakeInstantInstruction, err_14;
4440
4405
  return __generator(this, function (_a) {
4441
4406
  switch (_a.label) {
4442
4407
  case 0:
@@ -4448,10 +4413,8 @@ var PerpetualsClient = (function () {
4448
4413
  _a.label = 1;
4449
4414
  case 1:
4450
4415
  _a.trys.push([1, 3, , 4]);
4451
- rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
4452
4416
  rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
4453
4417
  pool = poolConfig.poolAddress;
4454
- feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
4455
4418
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.programId)[0];
4456
4419
  return [4, this.program.methods
4457
4420
  .unstakeInstant({
@@ -4595,21 +4558,19 @@ var PerpetualsClient = (function () {
4595
4558
  additionalSigners = [];
4596
4559
  _b.label = 1;
4597
4560
  case 1:
4598
- _b.trys.push([1, 6, , 7]);
4561
+ _b.trys.push([1, 5, , 6]);
4599
4562
  lpTokenMint = poolConfig.stakedLpTokenMint;
4600
4563
  pool = poolConfig.poolAddress;
4601
4564
  poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), pool.toBuffer(), lpTokenMint.toBuffer()], this.program.programId)[0];
4602
4565
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
4603
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, publicKey, true)];
4604
- case 2:
4605
- userLpTokenAccount = _b.sent();
4566
+ userLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4606
4567
  _a = createUserLPTA;
4607
- if (!_a) return [3, 4];
4568
+ if (!_a) return [3, 3];
4608
4569
  return [4, (0, utils_1.checkIfAccountExists)(userLpTokenAccount, this.provider.connection)];
4609
- case 3:
4570
+ case 2:
4610
4571
  _a = !(_b.sent());
4611
- _b.label = 4;
4612
- case 4:
4572
+ _b.label = 3;
4573
+ case 3:
4613
4574
  if (_a) {
4614
4575
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userLpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4615
4576
  }
@@ -4632,15 +4593,15 @@ var PerpetualsClient = (function () {
4632
4593
  program: this.program.programId,
4633
4594
  })
4634
4595
  .instruction()];
4635
- case 5:
4596
+ case 4:
4636
4597
  withdrawStakeInstruction = _b.sent();
4637
4598
  instructions.push(withdrawStakeInstruction);
4638
- return [3, 7];
4639
- case 6:
4599
+ return [3, 6];
4600
+ case 5:
4640
4601
  err_17 = _b.sent();
4641
4602
  console.log("perpClient withdrawStake error:: ", err_17);
4642
4603
  throw err_17;
4643
- case 7: return [2, {
4604
+ case 6: return [2, {
4644
4605
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4645
4606
  additionalSigners: additionalSigners
4646
4607
  }];
@@ -4788,10 +4749,8 @@ var PerpetualsClient = (function () {
4788
4749
  additionalSigners = [];
4789
4750
  _a.label = 1;
4790
4751
  case 1:
4791
- _a.trys.push([1, 4, , 5]);
4792
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(rewardCustodyMint, publicKey, true)];
4793
- case 2:
4794
- fundingAccount = _a.sent();
4752
+ _a.trys.push([1, 3, , 4]);
4753
+ fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
4795
4754
  rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
4796
4755
  rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
4797
4756
  return [4, this.programFbnftReward.methods
@@ -4806,15 +4765,15 @@ var PerpetualsClient = (function () {
4806
4765
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4807
4766
  })
4808
4767
  .instruction()];
4809
- case 3:
4768
+ case 2:
4810
4769
  distributeReward = _a.sent();
4811
4770
  instructions.push(distributeReward);
4812
- return [3, 5];
4813
- case 4:
4771
+ return [3, 4];
4772
+ case 3:
4814
4773
  err_20 = _a.sent();
4815
4774
  console.log("perpClient distributeReward error:: ", err_20);
4816
4775
  throw err_20;
4817
- case 5: return [2, {
4776
+ case 4: return [2, {
4818
4777
  instructions: __spreadArray([], instructions, true),
4819
4778
  additionalSigners: additionalSigners
4820
4779
  }];
@@ -4834,21 +4793,17 @@ var PerpetualsClient = (function () {
4834
4793
  additionalSigners = [];
4835
4794
  _b.label = 1;
4836
4795
  case 1:
4837
- _b.trys.push([1, 7, , 8]);
4838
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
4839
- case 2:
4840
- nftTokenAccount = _b.sent();
4796
+ _b.trys.push([1, 5, , 6]);
4797
+ nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
4841
4798
  metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
4842
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(rewardCustodyMint, publicKey, true)];
4843
- case 3:
4844
- receivingTokenAccount = _b.sent();
4799
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
4845
4800
  _a = createUserATA;
4846
- if (!_a) return [3, 5];
4801
+ if (!_a) return [3, 3];
4847
4802
  return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
4848
- case 4:
4803
+ case 2:
4849
4804
  _a = !(_b.sent());
4850
- _b.label = 5;
4851
- case 5:
4805
+ _b.label = 3;
4806
+ case 3:
4852
4807
  if (_a) {
4853
4808
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
4854
4809
  }
@@ -4873,14 +4828,14 @@ var PerpetualsClient = (function () {
4873
4828
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4874
4829
  })
4875
4830
  .instruction()];
4876
- case 6:
4831
+ case 4:
4877
4832
  collectNftReward = _b.sent();
4878
4833
  instructions.push(collectNftReward);
4879
- return [3, 8];
4880
- case 7:
4834
+ return [3, 6];
4835
+ case 5:
4881
4836
  err_21 = _b.sent();
4882
4837
  throw err_21;
4883
- case 8: return [2, {
4838
+ case 6: return [2, {
4884
4839
  instructions: __spreadArray([], instructions, true),
4885
4840
  additionalSigners: additionalSigners
4886
4841
  }];
@@ -5035,12 +4990,10 @@ var PerpetualsClient = (function () {
5035
4990
  additionalSigners = [];
5036
4991
  _b.label = 1;
5037
4992
  case 1:
5038
- _b.trys.push([1, 9, , 10]);
5039
- if (!(collateralSymbol == 'SOL')) return [3, 3];
4993
+ _b.trys.push([1, 7, , 8]);
4994
+ if (!(collateralSymbol == 'SOL')) return [3, 2];
5040
4995
  console.log("collateralSymbol === SOL", collateralSymbol);
5041
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
5042
- case 2:
5043
- lamports = (_b.sent());
4996
+ lamports = 1e7;
5044
4997
  if (!ephemeralSignerPubkey) {
5045
4998
  wrappedSolAccount = new web3_js_1.Keypair();
5046
4999
  additionalSigners.push(wrappedSolAccount);
@@ -5058,22 +5011,21 @@ var PerpetualsClient = (function () {
5058
5011
  postInstructions = [
5059
5012
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), positionAccount.owner, positionAccount.owner),
5060
5013
  ];
5061
- return [3, 7];
5062
- case 3: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, true)];
5063
- case 4:
5064
- userReceivingTokenAccount = _b.sent();
5014
+ return [3, 5];
5015
+ case 2:
5016
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, true);
5065
5017
  _a = createUserATA;
5066
- if (!_a) return [3, 6];
5018
+ if (!_a) return [3, 4];
5067
5019
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5068
- case 5:
5020
+ case 3:
5069
5021
  _a = !(_b.sent());
5070
- _b.label = 6;
5071
- case 6:
5022
+ _b.label = 4;
5023
+ case 4:
5072
5024
  if (_a) {
5073
5025
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5074
5026
  }
5075
- _b.label = 7;
5076
- case 7: return [4, this.program.methods
5027
+ _b.label = 5;
5028
+ case 5: return [4, this.program.methods
5077
5029
  .forceClosePosition({
5078
5030
  privilege: types_1.Privilege.None,
5079
5031
  isStopLoss: isStopLoss
@@ -5097,19 +5049,19 @@ var PerpetualsClient = (function () {
5097
5049
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5098
5050
  })
5099
5051
  .instruction()];
5100
- case 8:
5052
+ case 6:
5101
5053
  forceClosePosition = _b.sent();
5102
5054
  instructions.push(forceClosePosition);
5103
5055
  if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
5104
5056
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
5105
5057
  postInstructions.push(closeWsolATAIns);
5106
5058
  }
5107
- return [3, 10];
5108
- case 9:
5059
+ return [3, 8];
5060
+ case 7:
5109
5061
  err_24 = _b.sent();
5110
5062
  console.log("perpClient forceClosePosition error:: ", err_24);
5111
5063
  throw err_24;
5112
- case 10: return [2, {
5064
+ case 8: return [2, {
5113
5065
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5114
5066
  additionalSigners: additionalSigners
5115
5067
  }];
@@ -5269,7 +5221,6 @@ var PerpetualsClient = (function () {
5269
5221
  instructions = [];
5270
5222
  additionalSigners = [];
5271
5223
  custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(tokenMint); });
5272
- console.log("custodyConfig: ", custodyConfig);
5273
5224
  _g.label = 1;
5274
5225
  case 1:
5275
5226
  _g.trys.push([1, 4, , 5]);
@@ -5352,10 +5303,11 @@ var PerpetualsClient = (function () {
5352
5303
  }
5353
5304
  });
5354
5305
  }); };
5355
- this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, ephemeralSignerPubkey) {
5306
+ this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
5307
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5356
5308
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5357
5309
  return __awaiter(_this, void 0, void 0, function () {
5358
- var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, accCreationLamports, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_30;
5310
+ var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_30;
5359
5311
  return __generator(this, function (_e) {
5360
5312
  switch (_e.label) {
5361
5313
  case 0:
@@ -5368,15 +5320,9 @@ var PerpetualsClient = (function () {
5368
5320
  inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
5369
5321
  lpTokenMint = poolConfig.stakedLpTokenMint;
5370
5322
  compoundingTokenMint = poolConfig.compoundingTokenMint;
5371
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, publicKey, true)];
5372
- case 1:
5373
- lpTokenAccount = _e.sent();
5374
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey, true)];
5375
- case 2:
5376
- compoundingTokenAccount = _e.sent();
5377
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(inCustodyConfig.mintKey, publicKey, true)];
5378
- case 3:
5379
- fundingAccount = _e.sent();
5323
+ lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
5324
+ compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
5325
+ fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true);
5380
5326
  custodyAccountMetas = [];
5381
5327
  custodyOracleAccountMetas = [];
5382
5328
  markets = [];
@@ -5402,29 +5348,28 @@ var PerpetualsClient = (function () {
5402
5348
  });
5403
5349
  }
5404
5350
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
5405
- case 4:
5351
+ case 1:
5406
5352
  if (!(_e.sent())) {
5407
5353
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
5408
5354
  }
5409
5355
  return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
5410
- case 5:
5356
+ case 2:
5411
5357
  if (!(_e.sent())) {
5412
5358
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
5413
5359
  }
5414
- if (!(inTokenSymbol == 'SOL')) return [3, 8];
5360
+ if (!(inTokenSymbol == 'SOL')) return [3, 5];
5415
5361
  console.log("inTokenSymbol === SOL", inTokenSymbol);
5416
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
5417
- case 6:
5418
- accCreationLamports = (_e.sent());
5419
- console.log("accCreationLamports:", accCreationLamports);
5420
- lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
5362
+ lamports = amountIn.add(new anchor_1.BN(1e7));
5363
+ if (!!skipBalanceChecks) return [3, 4];
5421
5364
  _d = anchor_1.BN.bind;
5422
5365
  return [4, this.provider.connection.getBalance(publicKey)];
5423
- case 7:
5366
+ case 3:
5424
5367
  unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
5425
5368
  if (unWrappedSolBalance.lt(lamports)) {
5426
5369
  throw "Insufficient SOL Funds";
5427
5370
  }
5371
+ _e.label = 4;
5372
+ case 4:
5428
5373
  if (!ephemeralSignerPubkey) {
5429
5374
  wrappedSolAccount = new web3_js_1.Keypair();
5430
5375
  additionalSigners.push(wrappedSolAccount);
@@ -5442,15 +5387,17 @@ var PerpetualsClient = (function () {
5442
5387
  postInstructions = [
5443
5388
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
5444
5389
  ];
5445
- return [3, 10];
5446
- case 8: return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
5447
- case 9:
5390
+ return [3, 7];
5391
+ case 5:
5392
+ if (!!skipBalanceChecks) return [3, 7];
5393
+ return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
5394
+ case 6:
5448
5395
  if (!(_e.sent())) {
5449
5396
  throw "Insufficient Funds , token Account doesn't exist";
5450
5397
  }
5451
- _e.label = 10;
5452
- case 10:
5453
- _e.trys.push([10, 12, , 13]);
5398
+ _e.label = 7;
5399
+ case 7:
5400
+ _e.trys.push([7, 9, , 10]);
5454
5401
  return [4, this.program.methods
5455
5402
  .addCompoundingLiquidity({
5456
5403
  amountIn: amountIn,
@@ -5478,15 +5425,15 @@ var PerpetualsClient = (function () {
5478
5425
  })
5479
5426
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
5480
5427
  .instruction()];
5481
- case 11:
5428
+ case 8:
5482
5429
  addCompoundingLiquidity = _e.sent();
5483
5430
  instructions.push(addCompoundingLiquidity);
5484
- return [3, 13];
5485
- case 12:
5431
+ return [3, 10];
5432
+ case 9:
5486
5433
  err_30 = _e.sent();
5487
5434
  console.log("perpClient addCompoundingLiquidity error:: ", err_30);
5488
- return [3, 13];
5489
- case 13: return [2, {
5435
+ return [3, 10];
5436
+ case 10: return [2, {
5490
5437
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5491
5438
  additionalSigners: additionalSigners
5492
5439
  }];
@@ -5498,7 +5445,7 @@ var PerpetualsClient = (function () {
5498
5445
  if (createUserATA === void 0) { createUserATA = true; }
5499
5446
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5500
5447
  return __awaiter(_this, void 0, void 0, function () {
5501
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, receivingAccount, removeCompoundingLiquidity, err_31;
5448
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_31;
5502
5449
  return __generator(this, function (_e) {
5503
5450
  switch (_e.label) {
5504
5451
  case 0:
@@ -5511,10 +5458,8 @@ var PerpetualsClient = (function () {
5511
5458
  outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
5512
5459
  lpTokenMint = poolConfig.stakedLpTokenMint;
5513
5460
  compoundingTokenMint = poolConfig.compoundingTokenMint;
5514
- if (!(outCustodyConfig.symbol == 'SOL')) return [3, 2];
5515
- return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
5516
- case 1:
5517
- lamports = (_e.sent());
5461
+ if (!(outCustodyConfig.symbol == 'SOL')) return [3, 1];
5462
+ lamports = 1e7;
5518
5463
  if (!ephemeralSignerPubkey) {
5519
5464
  wrappedSolAccount = new web3_js_1.Keypair();
5520
5465
  additionalSigners.push(wrappedSolAccount);
@@ -5532,22 +5477,21 @@ var PerpetualsClient = (function () {
5532
5477
  postInstructions = [
5533
5478
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
5534
5479
  ];
5535
- return [3, 6];
5536
- case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(outCustodyConfig.mintKey, publicKey, true)];
5537
- case 3:
5538
- userReceivingTokenAccount = _e.sent();
5480
+ return [3, 4];
5481
+ case 1:
5482
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true);
5539
5483
  _a = createUserATA;
5540
- if (!_a) return [3, 5];
5484
+ if (!_a) return [3, 3];
5541
5485
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5542
- case 4:
5486
+ case 2:
5543
5487
  _a = !(_e.sent());
5544
- _e.label = 5;
5545
- case 5:
5488
+ _e.label = 3;
5489
+ case 3:
5546
5490
  if (_a) {
5547
5491
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
5548
5492
  }
5549
- _e.label = 6;
5550
- case 6:
5493
+ _e.label = 4;
5494
+ case 4:
5551
5495
  custodyAccountMetas = [];
5552
5496
  custodyOracleAccountMetas = [];
5553
5497
  markets = [];
@@ -5572,15 +5516,10 @@ var PerpetualsClient = (function () {
5572
5516
  isWritable: false,
5573
5517
  });
5574
5518
  }
5575
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey, true)];
5576
- case 7:
5577
- compoundingTokenAccount = _e.sent();
5578
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(outCustodyConfig.mintKey, publicKey, true)];
5579
- case 8:
5580
- receivingAccount = _e.sent();
5581
- _e.label = 9;
5582
- case 9:
5583
- _e.trys.push([9, 11, , 12]);
5519
+ compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
5520
+ _e.label = 5;
5521
+ case 5:
5522
+ _e.trys.push([5, 7, , 8]);
5584
5523
  return [4, this.program.methods
5585
5524
  .removeCompoundingLiquidity({
5586
5525
  compoundingAmountIn: compoundingAmountIn,
@@ -5608,15 +5547,15 @@ var PerpetualsClient = (function () {
5608
5547
  })
5609
5548
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
5610
5549
  .instruction()];
5611
- case 10:
5550
+ case 6:
5612
5551
  removeCompoundingLiquidity = _e.sent();
5613
5552
  instructions.push(removeCompoundingLiquidity);
5614
- return [3, 12];
5615
- case 11:
5553
+ return [3, 8];
5554
+ case 7:
5616
5555
  err_31 = _e.sent();
5617
5556
  console.log("perpClient removeCompoundingLiquidity error:: ", err_31);
5618
- return [3, 12];
5619
- case 12: return [2, {
5557
+ return [3, 8];
5558
+ case 8: return [2, {
5620
5559
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5621
5560
  additionalSigners: additionalSigners
5622
5561
  }];
@@ -5639,16 +5578,14 @@ var PerpetualsClient = (function () {
5639
5578
  rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
5640
5579
  lpTokenMint = poolConfig.stakedLpTokenMint;
5641
5580
  compoundingTokenMint = poolConfig.compoundingTokenMint;
5642
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey, true)];
5643
- case 1:
5644
- compoudingTokenAccount = _e.sent();
5581
+ compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
5645
5582
  _a = createUserATA;
5646
- if (!_a) return [3, 3];
5583
+ if (!_a) return [3, 2];
5647
5584
  return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
5648
- case 2:
5585
+ case 1:
5649
5586
  _a = !(_e.sent());
5650
- _e.label = 3;
5651
- case 3:
5587
+ _e.label = 2;
5588
+ case 2:
5652
5589
  if (_a) {
5653
5590
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
5654
5591
  }
@@ -5678,9 +5615,9 @@ var PerpetualsClient = (function () {
5678
5615
  isWritable: false,
5679
5616
  });
5680
5617
  }
5681
- _e.label = 4;
5682
- case 4:
5683
- _e.trys.push([4, 6, , 7]);
5618
+ _e.label = 3;
5619
+ case 3:
5620
+ _e.trys.push([3, 5, , 6]);
5684
5621
  return [4, this.program.methods
5685
5622
  .migrateStake({
5686
5623
  amount: amount
@@ -5705,15 +5642,15 @@ var PerpetualsClient = (function () {
5705
5642
  })
5706
5643
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
5707
5644
  .instruction()];
5708
- case 5:
5645
+ case 4:
5709
5646
  migrateStake = _e.sent();
5710
5647
  instructions.push(migrateStake);
5711
- return [3, 7];
5712
- case 6:
5648
+ return [3, 6];
5649
+ case 5:
5713
5650
  err_32 = _e.sent();
5714
5651
  console.log("perpClient migrateStake error:: ", err_32);
5715
- return [3, 7];
5716
- case 7: return [2, {
5652
+ return [3, 6];
5653
+ case 6: return [2, {
5717
5654
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5718
5655
  additionalSigners: additionalSigners
5719
5656
  }];
@@ -5734,9 +5671,7 @@ var PerpetualsClient = (function () {
5734
5671
  rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
5735
5672
  lpTokenMint = poolConfig.stakedLpTokenMint;
5736
5673
  compoundingTokenMint = poolConfig.compoundingTokenMint;
5737
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey, true)];
5738
- case 1:
5739
- compoudingTokenAccount = _d.sent();
5674
+ compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
5740
5675
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
5741
5676
  poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
5742
5677
  custodyAccountMetas = [];
@@ -5763,9 +5698,9 @@ var PerpetualsClient = (function () {
5763
5698
  isWritable: false,
5764
5699
  });
5765
5700
  }
5766
- _d.label = 2;
5767
- case 2:
5768
- _d.trys.push([2, 4, , 5]);
5701
+ _d.label = 1;
5702
+ case 1:
5703
+ _d.trys.push([1, 3, , 4]);
5769
5704
  return [4, this.program.methods
5770
5705
  .migrateFlp({
5771
5706
  compoundingTokenAmount: amount
@@ -5791,15 +5726,15 @@ var PerpetualsClient = (function () {
5791
5726
  })
5792
5727
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
5793
5728
  .instruction()];
5794
- case 3:
5729
+ case 2:
5795
5730
  migrateFlp = _d.sent();
5796
5731
  instructions.push(migrateFlp);
5797
- return [3, 5];
5798
- case 4:
5732
+ return [3, 4];
5733
+ case 3:
5799
5734
  err_33 = _d.sent();
5800
5735
  console.log("perpClient migrateFlp error:: ", err_33);
5801
- return [3, 5];
5802
- case 5: return [2, {
5736
+ return [3, 4];
5737
+ case 4: return [2, {
5803
5738
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5804
5739
  additionalSigners: additionalSigners
5805
5740
  }];
@@ -6016,10 +5951,8 @@ var PerpetualsClient = (function () {
6016
5951
  additionalSigners = [];
6017
5952
  _a.label = 1;
6018
5953
  case 1:
6019
- _a.trys.push([1, 4, , 5]);
6020
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(rewardCustodyMint, publicKey, true)];
6021
- case 2:
6022
- fundingAccount = _a.sent();
5954
+ _a.trys.push([1, 3, , 4]);
5955
+ fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
6023
5956
  rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
6024
5957
  rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
6025
5958
  rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), owner.toBuffer(), rewardVault.toBuffer(), counter.toArrayLike(Buffer, 'le', 8)], this.programRewardDistribution.programId)[0];
@@ -6042,15 +5975,15 @@ var PerpetualsClient = (function () {
6042
5975
  program: this.programRewardDistribution.programId
6043
5976
  })
6044
5977
  .instruction()];
6045
- case 3:
5978
+ case 2:
6046
5979
  distributeReward = _a.sent();
6047
5980
  instructions.push(distributeReward);
6048
- return [3, 5];
6049
- case 4:
5981
+ return [3, 4];
5982
+ case 3:
6050
5983
  err_38 = _a.sent();
6051
5984
  console.log("rewardDistribution distributeReward error:: ", err_38);
6052
5985
  throw err_38;
6053
- case 5: return [2, {
5986
+ case 4: return [2, {
6054
5987
  instructions: __spreadArray([], instructions, true),
6055
5988
  additionalSigners: additionalSigners
6056
5989
  }];
@@ -6070,17 +6003,15 @@ var PerpetualsClient = (function () {
6070
6003
  additionalSigners = [];
6071
6004
  _b.label = 1;
6072
6005
  case 1:
6073
- _b.trys.push([1, 6, , 7]);
6074
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(rewardCustodyMint, publicKey, true)];
6075
- case 2:
6076
- receivingTokenAccount = _b.sent();
6006
+ _b.trys.push([1, 5, , 6]);
6007
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
6077
6008
  _a = createUserATA;
6078
- if (!_a) return [3, 4];
6009
+ if (!_a) return [3, 3];
6079
6010
  return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
6080
- case 3:
6011
+ case 2:
6081
6012
  _a = !(_b.sent());
6082
- _b.label = 4;
6083
- case 4:
6013
+ _b.label = 3;
6014
+ case 3:
6084
6015
  if (_a) {
6085
6016
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
6086
6017
  }
@@ -6103,14 +6034,14 @@ var PerpetualsClient = (function () {
6103
6034
  program: this.programRewardDistribution.programId
6104
6035
  })
6105
6036
  .instruction()];
6106
- case 5:
6037
+ case 4:
6107
6038
  collectNftReward = _b.sent();
6108
6039
  instructions.push(collectNftReward);
6109
- return [3, 7];
6110
- case 6:
6040
+ return [3, 6];
6041
+ case 5:
6111
6042
  err_39 = _b.sent();
6112
6043
  throw err_39;
6113
- case 7: return [2, {
6044
+ case 6: return [2, {
6114
6045
  instructions: __spreadArray([], instructions, true),
6115
6046
  additionalSigners: additionalSigners
6116
6047
  }];