flash-sdk 2.25.3 → 2.25.5

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.
@@ -501,7 +501,7 @@ var PerpetualsClient = (function () {
501
501
  }
502
502
  });
503
503
  }); };
504
- this.addCustody = function (poolName, tokenMint, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
504
+ this.addCustody = function (poolName, tokenMint, isStable, isVirtual, token22, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
505
505
  var trx_id, error_1;
506
506
  return __generator(this, function (_a) {
507
507
  switch (_a.label) {
@@ -511,6 +511,7 @@ var PerpetualsClient = (function () {
511
511
  .addCustody({
512
512
  isStable: isStable,
513
513
  isVirtual: isVirtual,
514
+ token22: token22,
514
515
  oracle: oracle,
515
516
  pricing: pricing,
516
517
  permissions: permissions,
@@ -2481,34 +2482,33 @@ var PerpetualsClient = (function () {
2481
2482
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2482
2483
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2483
2484
  return __awaiter(_this, void 0, void 0, function () {
2484
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2485
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, rebateMintAccount, params, instruction;
2485
2486
  return __generator(this, function (_c) {
2486
2487
  switch (_c.label) {
2487
2488
  case 0:
2488
2489
  publicKey = this.provider.wallet.publicKey;
2489
2490
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
2490
2491
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
2492
+ collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
2491
2493
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
2492
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true)];
2493
- case 1:
2494
- userCollateralTokenAccount = _c.sent();
2494
+ userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
2495
2495
  preInstructions = [];
2496
2496
  instructions = [];
2497
2497
  postInstructions = [];
2498
2498
  additionalSigners = [];
2499
- if (!(collateralSymbol == 'SOL')) return [3, 4];
2499
+ if (!(collateralSymbol == 'SOL')) return [3, 3];
2500
2500
  console.log("collateralSymbol === SOL", collateralSymbol);
2501
2501
  lamports = collateralWithfee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
2502
- if (!!skipBalanceChecks) return [3, 3];
2502
+ if (!!skipBalanceChecks) return [3, 2];
2503
2503
  _a = anchor_1.BN.bind;
2504
2504
  return [4, this.provider.connection.getBalance(publicKey)];
2505
- case 2:
2505
+ case 1:
2506
2506
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
2507
2507
  if (unWrappedSolBalance.lt(lamports)) {
2508
2508
  throw "Insufficient SOL Funds";
2509
2509
  }
2510
- _c.label = 3;
2511
- case 3:
2510
+ _c.label = 2;
2511
+ case 2:
2512
2512
  if (!ephemeralSignerPubkey) {
2513
2513
  wrappedSolAccount = new web3_js_1.Keypair();
2514
2514
  additionalSigners.push(wrappedSolAccount);
@@ -2526,24 +2526,29 @@ var PerpetualsClient = (function () {
2526
2526
  postInstructions = [
2527
2527
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2528
2528
  ];
2529
- return [3, 7];
2530
- case 4:
2531
- if (!!skipBalanceChecks) return [3, 7];
2529
+ return [3, 6];
2530
+ case 3:
2531
+ if (!!skipBalanceChecks) return [3, 6];
2532
2532
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
2533
- case 5:
2533
+ case 4:
2534
2534
  if (!(_c.sent())) {
2535
2535
  throw "Insufficient Funds , token Account doesn't exist";
2536
2536
  }
2537
2537
  _b = anchor_1.BN.bind;
2538
2538
  return [4, this.provider.connection.getTokenAccountBalance(userCollateralTokenAccount)];
2539
- case 6:
2539
+ case 5:
2540
2540
  tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
2541
2541
  if (tokenAccountBalance.lt(collateralWithfee)) {
2542
2542
  throw "Insufficient Funds need more ".concat(collateralWithfee.sub(tokenAccountBalance), " tokens");
2543
2543
  }
2544
- _c.label = 7;
2545
- case 7:
2544
+ _c.label = 6;
2545
+ case 6:
2546
2546
  positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
2547
+ rebateMintAccount = {
2548
+ pubkey: collateralCustodyConfig.mintKey,
2549
+ isSigner: false,
2550
+ isWritable: false
2551
+ };
2547
2552
  params = {
2548
2553
  priceWithSlippage: priceWithSlippage,
2549
2554
  collateralAmount: collateralWithfee,
@@ -2570,11 +2575,12 @@ var PerpetualsClient = (function () {
2570
2575
  eventAuthority: this.eventAuthority.publicKey,
2571
2576
  program: this.programId,
2572
2577
  transferAuthority: this.authority.publicKey,
2573
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
2578
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2579
+ fundingMint: collateralCustodyConfig.mintKey
2574
2580
  })
2575
- .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
2581
+ .remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
2576
2582
  .instruction()];
2577
- case 8:
2583
+ case 7:
2578
2584
  instruction = _c.sent();
2579
2585
  instructions.push(instruction);
2580
2586
  return [2, {
@@ -2640,7 +2646,7 @@ var PerpetualsClient = (function () {
2640
2646
  ];
2641
2647
  return [3, 6];
2642
2648
  case 3:
2643
- userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true);
2649
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true, swapPoolConfig.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
2644
2650
  if (!!skipBalanceChecks) return [3, 6];
2645
2651
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
2646
2652
  case 4:
@@ -2656,11 +2662,11 @@ var PerpetualsClient = (function () {
2656
2662
  }
2657
2663
  _d.label = 6;
2658
2664
  case 6:
2659
- userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, publicKey, true);
2665
+ userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, publicKey, true, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
2660
2666
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
2661
2667
  case 7:
2662
2668
  if (!(_d.sent())) {
2663
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey));
2669
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
2664
2670
  }
2665
2671
  marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
2666
2672
  positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
@@ -2735,7 +2741,7 @@ var PerpetualsClient = (function () {
2735
2741
  if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2736
2742
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2737
2743
  return __awaiter(_this, void 0, void 0, function () {
2738
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
2744
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, rebateMintAccount, instruction, closeWsolATAIns, error_2;
2739
2745
  return __generator(this, function (_b) {
2740
2746
  switch (_b.label) {
2741
2747
  case 0:
@@ -2769,7 +2775,7 @@ var PerpetualsClient = (function () {
2769
2775
  ];
2770
2776
  return [3, 5];
2771
2777
  case 2:
2772
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
2778
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
2773
2779
  _a = createUserATA;
2774
2780
  if (!_a) return [3, 4];
2775
2781
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -2778,7 +2784,7 @@ var PerpetualsClient = (function () {
2778
2784
  _b.label = 4;
2779
2785
  case 4:
2780
2786
  if (_a) {
2781
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
2787
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
2782
2788
  }
2783
2789
  _b.label = 5;
2784
2790
  case 5:
@@ -2786,6 +2792,11 @@ var PerpetualsClient = (function () {
2786
2792
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
2787
2793
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
2788
2794
  positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
2795
+ rebateMintAccount = {
2796
+ pubkey: collateralCustodyConfig.mintKey,
2797
+ isSigner: false,
2798
+ isWritable: false
2799
+ };
2789
2800
  return [4, this.program.methods
2790
2801
  .closePosition({
2791
2802
  priceWithSlippage: priceWithSlippage,
@@ -2808,9 +2819,10 @@ var PerpetualsClient = (function () {
2808
2819
  eventAuthority: this.eventAuthority.publicKey,
2809
2820
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
2810
2821
  program: this.programId,
2811
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
2822
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2823
+ receivingMint: collateralCustodyConfig.mintKey
2812
2824
  })
2813
- .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
2825
+ .remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
2814
2826
  .instruction()];
2815
2827
  case 6:
2816
2828
  instruction = _b.sent();
@@ -2875,22 +2887,21 @@ var PerpetualsClient = (function () {
2875
2887
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
2876
2888
  ];
2877
2889
  additionalSigners.push(wrappedSolAccount);
2878
- return [3, 4];
2879
- case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true)];
2880
- case 2:
2881
- userReceivingTokenAccount = _b.sent();
2890
+ return [3, 3];
2891
+ case 1:
2892
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, swapPoolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
2882
2893
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
2883
- case 3:
2894
+ case 2:
2884
2895
  if (!(_b.sent())) {
2885
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey));
2896
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
2886
2897
  }
2887
- _b.label = 4;
2888
- case 4:
2889
- userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
2898
+ _b.label = 3;
2899
+ case 3:
2900
+ userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, positionPoolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
2890
2901
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
2891
- case 5:
2902
+ case 4:
2892
2903
  if (!(_b.sent())) {
2893
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
2904
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
2894
2905
  }
2895
2906
  marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
2896
2907
  positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
@@ -2939,11 +2950,11 @@ var PerpetualsClient = (function () {
2939
2950
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
2940
2951
  eventAuthority: this.eventAuthority.publicKey,
2941
2952
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
2942
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
2953
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2943
2954
  })
2944
2955
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
2945
2956
  .instruction()];
2946
- case 6:
2957
+ case 5:
2947
2958
  instruction = _b.sent();
2948
2959
  instructions.push(instruction);
2949
2960
  return [2, {
@@ -2961,7 +2972,7 @@ var PerpetualsClient = (function () {
2961
2972
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2962
2973
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2963
2974
  return __awaiter(_this, void 0, void 0, function () {
2964
- var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
2975
+ var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_2;
2965
2976
  return __generator(this, function (_c) {
2966
2977
  switch (_c.label) {
2967
2978
  case 0:
@@ -2987,6 +2998,7 @@ var PerpetualsClient = (function () {
2987
2998
  instructions = [];
2988
2999
  postInstructions = [];
2989
3000
  additionalSigners = [];
3001
+ targetToken = poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol);
2990
3002
  if (!(userInputTokenSymbol == 'SOL')) return [3, 3];
2991
3003
  console.log("inputSymbol === SOL", userInputTokenSymbol);
2992
3004
  lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
@@ -3019,7 +3031,7 @@ var PerpetualsClient = (function () {
3019
3031
  ];
3020
3032
  return [3, 6];
3021
3033
  case 3:
3022
- userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3034
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3023
3035
  if (!!skipBalanceChecks) return [3, 6];
3024
3036
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3025
3037
  case 4:
@@ -3035,12 +3047,17 @@ var PerpetualsClient = (function () {
3035
3047
  }
3036
3048
  _c.label = 6;
3037
3049
  case 6:
3038
- userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true);
3050
+ userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(targetToken.mintKey, publicKey, true, targetToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3039
3051
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3040
3052
  case 7:
3041
3053
  if (!(_c.sent())) {
3042
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
3054
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, targetToken.mintKey, targetToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3043
3055
  }
3056
+ rebateMintAccount = {
3057
+ pubkey: collateralCustodyConfig.mintKey,
3058
+ isSigner: false,
3059
+ isWritable: false
3060
+ };
3044
3061
  _c.label = 8;
3045
3062
  case 8:
3046
3063
  _c.trys.push([8, 10, , 11]);
@@ -3073,9 +3090,11 @@ var PerpetualsClient = (function () {
3073
3090
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3074
3091
  eventAuthority: this.eventAuthority.publicKey,
3075
3092
  program: this.programId,
3076
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3093
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3094
+ fundingMint: userInputCustodyConfig.mintKey,
3095
+ fundingTokenProgram: targetToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
3077
3096
  })
3078
- .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
3097
+ .remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
3079
3098
  .instruction()];
3080
3099
  case 9:
3081
3100
  inx = _c.sent();
@@ -3099,7 +3118,7 @@ var PerpetualsClient = (function () {
3099
3118
  if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
3100
3119
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3101
3120
  return __awaiter(_this, void 0, void 0, function () {
3102
- var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
3121
+ var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, rebateMintAccount, inx, err_3;
3103
3122
  return __generator(this, function (_a) {
3104
3123
  switch (_a.label) {
3105
3124
  case 0:
@@ -3125,6 +3144,8 @@ var PerpetualsClient = (function () {
3125
3144
  instructions = [];
3126
3145
  postInstructions = [];
3127
3146
  additionalSigners = [];
3147
+ collateralToken = poolConfig.getTokenFromSymbol(collateralTokenSymbol);
3148
+ userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
3128
3149
  if (!(userOutputTokenSymbol == 'SOL')) return [3, 1];
3129
3150
  console.log("outputSymbol === SOL", userOutputTokenSymbol);
3130
3151
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
@@ -3146,26 +3167,30 @@ var PerpetualsClient = (function () {
3146
3167
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3147
3168
  ];
3148
3169
  additionalSigners.push(wrappedSolAccount);
3149
- return [3, 4];
3150
- case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3151
- case 2:
3152
- userReceivingTokenAccount = _a.sent();
3170
+ return [3, 3];
3171
+ case 1:
3172
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3153
3173
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3154
- case 3:
3174
+ case 2:
3155
3175
  if (!(_a.sent())) {
3156
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3176
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, userOutputToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3157
3177
  }
3158
- _a.label = 4;
3159
- case 4:
3160
- userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey, publicKey, true);
3178
+ _a.label = 3;
3179
+ case 3:
3180
+ userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3161
3181
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
3162
- case 5:
3182
+ case 4:
3163
3183
  if (!(_a.sent())) {
3164
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey));
3184
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3165
3185
  }
3166
- _a.label = 6;
3167
- case 6:
3168
- _a.trys.push([6, 8, , 9]);
3186
+ rebateMintAccount = {
3187
+ pubkey: collateralCustodyConfig.mintKey,
3188
+ isSigner: false,
3189
+ isWritable: false
3190
+ };
3191
+ _a.label = 5;
3192
+ case 5:
3193
+ _a.trys.push([5, 7, , 8]);
3169
3194
  return [4, this.program.methods
3170
3195
  .closeAndSwap({
3171
3196
  priceWithSlippage: priceWithSlippage,
@@ -3190,22 +3215,25 @@ var PerpetualsClient = (function () {
3190
3215
  dispensingCustody: userOutputCustodyConfig.custodyAccount,
3191
3216
  dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
3192
3217
  dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
3193
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3194
3218
  eventAuthority: this.eventAuthority.publicKey,
3195
3219
  program: this.programId,
3196
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3220
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3221
+ receivingMint: userOutputCustodyConfig.mintKey,
3222
+ receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3223
+ collateralMint: collateralCustodyConfig.mintKey,
3224
+ collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
3197
3225
  })
3198
- .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
3226
+ .remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
3199
3227
  .instruction()];
3200
- case 7:
3228
+ case 6:
3201
3229
  inx = _a.sent();
3202
3230
  instructions.push(inx);
3203
- return [3, 9];
3204
- case 8:
3231
+ return [3, 8];
3232
+ case 7:
3205
3233
  err_3 = _a.sent();
3206
3234
  console.error("perpClient CloseAndSwap error:: ", err_3);
3207
3235
  throw err_3;
3208
- case 9: return [2, {
3236
+ case 8: return [2, {
3209
3237
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3210
3238
  additionalSigners: additionalSigners
3211
3239
  }];
@@ -3220,7 +3248,7 @@ var PerpetualsClient = (function () {
3220
3248
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3221
3249
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3222
3250
  return __awaiter(_this, void 0, void 0, function () {
3223
- var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _i, _e, custody, params, inx, closeWsolATAIns, err_4;
3251
+ var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, userOutputToken, userInputToken, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _i, _e, custody, params, inx, closeWsolATAIns, err_4;
3224
3252
  return __generator(this, function (_f) {
3225
3253
  switch (_f.label) {
3226
3254
  case 0:
@@ -3237,26 +3265,26 @@ var PerpetualsClient = (function () {
3237
3265
  instructions = [];
3238
3266
  postInstructions = [];
3239
3267
  additionalSigners = [];
3240
- if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
3241
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
3242
- case 1:
3243
- wsolAssociatedTokenAccount = _f.sent();
3268
+ userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
3269
+ userInputToken = poolConfig.getTokenFromSymbol(userInputTokenSymbol);
3270
+ if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 4];
3271
+ wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
3244
3272
  return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
3245
- case 2:
3273
+ case 1:
3246
3274
  wsolATAExist = _f.sent();
3247
3275
  if (!wsolATAExist) {
3248
3276
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
3249
3277
  }
3250
- if (!!skipBalanceChecks) return [3, 4];
3278
+ if (!!skipBalanceChecks) return [3, 3];
3251
3279
  _a = anchor_1.BN.bind;
3252
3280
  return [4, this.provider.connection.getBalance(publicKey)];
3253
- case 3:
3281
+ case 2:
3254
3282
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3255
3283
  if (unWrappedSolBalance.lt(amountIn)) {
3256
3284
  throw "Insufficient SOL Funds";
3257
3285
  }
3258
- _f.label = 4;
3259
- case 4:
3286
+ _f.label = 3;
3287
+ case 3:
3260
3288
  instructions.push(web3_js_1.SystemProgram.transfer({
3261
3289
  fromPubkey: publicKey,
3262
3290
  toPubkey: wsolAssociatedTokenAccount,
@@ -3266,7 +3294,7 @@ var PerpetualsClient = (function () {
3266
3294
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3267
3295
  additionalSigners: additionalSigners
3268
3296
  }];
3269
- case 5:
3297
+ case 4:
3270
3298
  if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
3271
3299
  console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
3272
3300
  wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
@@ -3277,19 +3305,19 @@ var PerpetualsClient = (function () {
3277
3305
  additionalSigners: additionalSigners
3278
3306
  }];
3279
3307
  }
3280
- _f.label = 6;
3281
- case 6:
3282
- _f.trys.push([6, 19, , 20]);
3283
- if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
3308
+ _f.label = 5;
3309
+ case 5:
3310
+ _f.trys.push([5, 17, , 18]);
3311
+ if (!(userInputTokenSymbol == 'SOL')) return [3, 8];
3284
3312
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
3285
3313
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3286
- case 7:
3314
+ case 6:
3287
3315
  accCreationLamports = (_f.sent());
3288
3316
  console.log("accCreationLamports:", accCreationLamports);
3289
3317
  lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3290
3318
  _b = anchor_1.BN.bind;
3291
3319
  return [4, this.provider.connection.getBalance(publicKey)];
3292
- case 8:
3320
+ case 7:
3293
3321
  unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
3294
3322
  if (unWrappedSolBalance.lt(amountIn)) {
3295
3323
  throw "Insufficient SOL Funds";
@@ -3312,25 +3340,25 @@ var PerpetualsClient = (function () {
3312
3340
  postInstructions = [
3313
3341
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3314
3342
  ];
3315
- return [3, 12];
3316
- case 9:
3317
- userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3343
+ return [3, 11];
3344
+ case 8:
3345
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userInputToken.mintKey, publicKey, true, userInputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3318
3346
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3319
- case 10:
3347
+ case 9:
3320
3348
  if (!(_f.sent())) {
3321
3349
  throw "Insufficient Funds , Token Account doesn't exist";
3322
3350
  }
3323
- if (!!skipBalanceChecks) return [3, 12];
3351
+ if (!!skipBalanceChecks) return [3, 11];
3324
3352
  _c = anchor_1.BN.bind;
3325
3353
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3326
- case 11:
3354
+ case 10:
3327
3355
  tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3328
3356
  if (tokenAccountBalance.lt(amountIn)) {
3329
3357
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3330
3358
  }
3331
- _f.label = 12;
3332
- case 12:
3333
- if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
3359
+ _f.label = 11;
3360
+ case 11:
3361
+ if (!(userOutputTokenSymbol == 'SOL')) return [3, 12];
3334
3362
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
3335
3363
  if (!ephemeralSignerPubkey) {
3336
3364
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -3350,22 +3378,21 @@ var PerpetualsClient = (function () {
3350
3378
  postInstructions = [
3351
3379
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
3352
3380
  ];
3353
- return [3, 17];
3354
- case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3355
- case 14:
3356
- userOutputTokenAccount = _f.sent();
3381
+ return [3, 15];
3382
+ case 12:
3383
+ userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3357
3384
  _d = createUserATA;
3358
- if (!_d) return [3, 16];
3385
+ if (!_d) return [3, 14];
3359
3386
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3360
- case 15:
3387
+ case 13:
3361
3388
  _d = !(_f.sent());
3362
- _f.label = 16;
3363
- case 16:
3389
+ _f.label = 14;
3390
+ case 14:
3364
3391
  if (_d) {
3365
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3392
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, userOutputToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3366
3393
  }
3367
- _f.label = 17;
3368
- case 17:
3394
+ _f.label = 15;
3395
+ case 15:
3369
3396
  custodyAccountMetas = [];
3370
3397
  custodyOracleAccountMetas = [];
3371
3398
  for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
@@ -3402,25 +3429,28 @@ var PerpetualsClient = (function () {
3402
3429
  dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
3403
3430
  dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
3404
3431
  eventAuthority: this.eventAuthority.publicKey,
3405
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3406
3432
  program: this.programId,
3407
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3433
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3434
+ fundingMint: userInputCustodyConfig.mintKey,
3435
+ fundingTokenProgram: userInputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3436
+ receivingMint: userOutputCustodyConfig.mintKey,
3437
+ receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
3408
3438
  })
3409
3439
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
3410
3440
  .instruction()];
3411
- case 18:
3441
+ case 16:
3412
3442
  inx = _f.sent();
3413
3443
  instructions.push(inx);
3414
3444
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
3415
3445
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
3416
3446
  instructions.push(closeWsolATAIns);
3417
3447
  }
3418
- return [3, 20];
3419
- case 19:
3448
+ return [3, 18];
3449
+ case 17:
3420
3450
  err_4 = _f.sent();
3421
3451
  console.error("perpClient Swap error:: ", err_4);
3422
3452
  throw err_4;
3423
- case 20: return [2, {
3453
+ case 18: return [2, {
3424
3454
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
3425
3455
  additionalSigners: additionalSigners
3426
3456
  }];
@@ -3514,7 +3544,7 @@ var PerpetualsClient = (function () {
3514
3544
  if (!collateralCustodyConfig || !targetCustodyConfig) {
3515
3545
  throw "payTokenCustody not found";
3516
3546
  }
3517
- userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
3547
+ userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3518
3548
  preInstructions = [];
3519
3549
  instructions = [];
3520
3550
  postInstructions = [];
@@ -3584,6 +3614,7 @@ var PerpetualsClient = (function () {
3584
3614
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3585
3615
  program: this.programId,
3586
3616
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3617
+ fundingMint: collateralCustodyConfig.mintKey
3587
3618
  })
3588
3619
  .instruction()];
3589
3620
  case 7:
@@ -3653,7 +3684,7 @@ var PerpetualsClient = (function () {
3653
3684
  ];
3654
3685
  return [3, 6];
3655
3686
  case 3:
3656
- userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
3687
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, poolConfigSwap.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3657
3688
  if (!!skipBalanceChecks) return [3, 6];
3658
3689
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3659
3690
  case 4:
@@ -3669,11 +3700,11 @@ var PerpetualsClient = (function () {
3669
3700
  }
3670
3701
  _d.label = 6;
3671
3702
  case 6:
3672
- userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
3703
+ userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3673
3704
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
3674
3705
  case 7:
3675
3706
  if (!(_d.sent())) {
3676
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
3707
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3677
3708
  }
3678
3709
  custodyAccountMetas = [];
3679
3710
  custodyOracleAccountMetas = [];
@@ -3782,7 +3813,7 @@ var PerpetualsClient = (function () {
3782
3813
  ];
3783
3814
  return [3, 5];
3784
3815
  case 2:
3785
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
3816
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3786
3817
  _a = createUserATA;
3787
3818
  if (!_a) return [3, 4];
3788
3819
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -3791,7 +3822,7 @@ var PerpetualsClient = (function () {
3791
3822
  _b.label = 4;
3792
3823
  case 4:
3793
3824
  if (_a) {
3794
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
3825
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3795
3826
  }
3796
3827
  _b.label = 5;
3797
3828
  case 5:
@@ -3816,7 +3847,8 @@ var PerpetualsClient = (function () {
3816
3847
  eventAuthority: this.eventAuthority.publicKey,
3817
3848
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3818
3849
  program: this.programId,
3819
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
3850
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3851
+ receivingMint: collateralCustodyConfig.mintKey
3820
3852
  })
3821
3853
  .instruction()];
3822
3854
  case 6:
@@ -3880,19 +3912,19 @@ var PerpetualsClient = (function () {
3880
3912
  ];
3881
3913
  return [3, 3];
3882
3914
  case 1:
3883
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
3915
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, poolConfigSwap.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3884
3916
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3885
3917
  case 2:
3886
3918
  if (!(_b.sent())) {
3887
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey));
3919
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3888
3920
  }
3889
3921
  _b.label = 3;
3890
3922
  case 3:
3891
- userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
3923
+ userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3892
3924
  return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
3893
3925
  case 4:
3894
3926
  if (!(_b.sent())) {
3895
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey));
3927
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3896
3928
  }
3897
3929
  marketAccount = poolConfigPosition.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
3898
3930
  positionAccount = poolConfigPosition.getPositionFromMarketPk(publicKey, marketAccount);
@@ -3960,7 +3992,7 @@ var PerpetualsClient = (function () {
3960
3992
  if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
3961
3993
  if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
3962
3994
  return __awaiter(_this, void 0, void 0, function () {
3963
- var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3995
+ var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, rebateMintAccount, instruction;
3964
3996
  return __generator(this, function (_a) {
3965
3997
  switch (_a.label) {
3966
3998
  case 0:
@@ -3979,6 +4011,11 @@ var PerpetualsClient = (function () {
3979
4011
  instructions = [];
3980
4012
  postInstructions = [];
3981
4013
  additionalSigners = [];
4014
+ rebateMintAccount = {
4015
+ pubkey: collateralCustodyConfig.mintKey,
4016
+ isSigner: false,
4017
+ isWritable: false
4018
+ };
3982
4019
  return [4, this.program.methods
3983
4020
  .increaseSize({
3984
4021
  priceWithSlippage: priceWithSlippage,
@@ -4002,7 +4039,7 @@ var PerpetualsClient = (function () {
4002
4039
  program: this.programId,
4003
4040
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4004
4041
  })
4005
- .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
4042
+ .remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
4006
4043
  .instruction()];
4007
4044
  case 1:
4008
4045
  instruction = _a.sent();
@@ -4020,7 +4057,7 @@ var PerpetualsClient = (function () {
4020
4057
  if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
4021
4058
  if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
4022
4059
  return __awaiter(_this, void 0, void 0, function () {
4023
- var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
4060
+ var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, rebateMintAccount, instruction;
4024
4061
  return __generator(this, function (_a) {
4025
4062
  switch (_a.label) {
4026
4063
  case 0:
@@ -4039,6 +4076,11 @@ var PerpetualsClient = (function () {
4039
4076
  instructions = [];
4040
4077
  postInstructions = [];
4041
4078
  additionalSigners = [];
4079
+ rebateMintAccount = {
4080
+ pubkey: collateralCustodyConfig.mintKey,
4081
+ isSigner: false,
4082
+ isWritable: false
4083
+ };
4042
4084
  return [4, this.program.methods
4043
4085
  .decreaseSize({
4044
4086
  priceWithSlippage: priceWithSlippage,
@@ -4062,7 +4104,7 @@ var PerpetualsClient = (function () {
4062
4104
  program: this.programId,
4063
4105
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4064
4106
  })
4065
- .remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
4107
+ .remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
4066
4108
  .instruction()];
4067
4109
  case 1:
4068
4110
  instruction = _a.sent();
@@ -4079,7 +4121,7 @@ var PerpetualsClient = (function () {
4079
4121
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4080
4122
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4081
4123
  return __awaiter(_this, void 0, void 0, function () {
4082
- var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_6;
4124
+ var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_6;
4083
4125
  return __generator(this, function (_f) {
4084
4126
  switch (_f.label) {
4085
4127
  case 0:
@@ -4092,10 +4134,11 @@ var PerpetualsClient = (function () {
4092
4134
  instructions = [];
4093
4135
  postInstructions = [];
4094
4136
  additionalSigners = [];
4137
+ payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
4095
4138
  _f.label = 1;
4096
4139
  case 1:
4097
4140
  _f.trys.push([1, 10, , 11]);
4098
- userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
4141
+ userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
4099
4142
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4100
4143
  custodyAccountMetas = [];
4101
4144
  custodyOracleAccountMetas = [];
@@ -4191,7 +4234,9 @@ var PerpetualsClient = (function () {
4191
4234
  eventAuthority: this.eventAuthority.publicKey,
4192
4235
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4193
4236
  program: this.programId,
4194
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4237
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4238
+ fundingMint: payTokenCustodyConfig.mintKey,
4239
+ fundingTokenProgram: payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
4195
4240
  })
4196
4241
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4197
4242
  .instruction()];
@@ -4215,7 +4260,7 @@ var PerpetualsClient = (function () {
4215
4260
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4216
4261
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4217
4262
  return __awaiter(_this, void 0, void 0, function () {
4218
- 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;
4263
+ var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, inputToken, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
4219
4264
  return __generator(this, function (_f) {
4220
4265
  switch (_f.label) {
4221
4266
  case 0:
@@ -4226,6 +4271,7 @@ var PerpetualsClient = (function () {
4226
4271
  additionalSigners = [];
4227
4272
  lpTokenMint = poolConfig.stakedLpTokenMint;
4228
4273
  inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
4274
+ inputToken = poolConfig.getTokenFromSymbol(inputSymbol);
4229
4275
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, publicKey, true);
4230
4276
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
4231
4277
  poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
@@ -4266,7 +4312,7 @@ var PerpetualsClient = (function () {
4266
4312
  ];
4267
4313
  return [3, 7];
4268
4314
  case 4:
4269
- userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
4315
+ userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
4270
4316
  if (!!skipBalanceChecks) return [3, 7];
4271
4317
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
4272
4318
  case 5:
@@ -4326,7 +4372,9 @@ var PerpetualsClient = (function () {
4326
4372
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4327
4373
  eventAuthority: this.eventAuthority.publicKey,
4328
4374
  program: this.programId,
4329
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4375
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4376
+ fundingMint: inputCustodyConfig.mintKey,
4377
+ fundingTokenProgram: inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
4330
4378
  })
4331
4379
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4332
4380
  .instruction()];
@@ -4347,7 +4395,7 @@ var PerpetualsClient = (function () {
4347
4395
  if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4348
4396
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4349
4397
  return __awaiter(_this, void 0, void 0, function () {
4350
- var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
4398
+ var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
4351
4399
  return __generator(this, function (_e) {
4352
4400
  switch (_e.label) {
4353
4401
  case 0:
@@ -4360,6 +4408,7 @@ var PerpetualsClient = (function () {
4360
4408
  instructions = [];
4361
4409
  postInstructions = [];
4362
4410
  additionalSigners = [];
4411
+ recieveToken = poolConfig.getTokenFromSymbol(recieveTokenSymbol);
4363
4412
  _e.label = 1;
4364
4413
  case 1:
4365
4414
  _e.trys.push([1, 7, , 8]);
@@ -4409,7 +4458,7 @@ var PerpetualsClient = (function () {
4409
4458
  ];
4410
4459
  return [3, 5];
4411
4460
  case 2:
4412
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
4461
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(recieveToken.mintKey, publicKey, true, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
4413
4462
  _d = createUserATA;
4414
4463
  if (!_d) return [3, 4];
4415
4464
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -4418,7 +4467,7 @@ var PerpetualsClient = (function () {
4418
4467
  _e.label = 4;
4419
4468
  case 4:
4420
4469
  if (_d) {
4421
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
4470
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, recieveToken.mintKey, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
4422
4471
  }
4423
4472
  _e.label = 5;
4424
4473
  case 5: return [4, this.program.methods
@@ -4440,7 +4489,9 @@ var PerpetualsClient = (function () {
4440
4489
  eventAuthority: this.eventAuthority.publicKey,
4441
4490
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4442
4491
  program: this.programId,
4443
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4492
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4493
+ receivingMint: recieveTokenCustodyConfig.mintKey,
4494
+ receivingTokenProgram: recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
4444
4495
  })
4445
4496
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4446
4497
  .instruction()];
@@ -4567,7 +4618,7 @@ var PerpetualsClient = (function () {
4567
4618
  additionalSigners = [];
4568
4619
  _a.label = 1;
4569
4620
  case 1:
4570
- _a.trys.push([1, 4, , 5]);
4621
+ _a.trys.push([1, 3, , 4]);
4571
4622
  nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
4572
4623
  Buffer.from("trading"),
4573
4624
  nftMint.toBuffer(),
@@ -4576,9 +4627,7 @@ var PerpetualsClient = (function () {
4576
4627
  Buffer.from("referral"),
4577
4628
  publicKey.toBuffer(),
4578
4629
  ], this.programId)[0];
4579
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
4580
- case 2:
4581
- nftTokenAccount = _a.sent();
4630
+ nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
4582
4631
  flpStakeAccountMetas = [];
4583
4632
  for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
4584
4633
  flpStakeAccountPk = flpStakeAccounts_1[_i];
@@ -4601,15 +4650,15 @@ var PerpetualsClient = (function () {
4601
4650
  tradingAccount: nftTradingAccount
4602
4651
  })
4603
4652
  .instruction()];
4604
- case 3:
4653
+ case 2:
4605
4654
  updateNftTradingAccountInstruction = _a.sent();
4606
4655
  instructions.push(updateNftTradingAccountInstruction);
4607
- return [3, 5];
4608
- case 4:
4656
+ return [3, 4];
4657
+ case 3:
4609
4658
  err_10 = _a.sent();
4610
4659
  console.log("perpClient updateNftAccount error:: ", err_10);
4611
4660
  throw err_10;
4612
- case 5: return [2, {
4661
+ case 4: return [2, {
4613
4662
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4614
4663
  additionalSigners: additionalSigners
4615
4664
  }];
@@ -4782,13 +4831,11 @@ var PerpetualsClient = (function () {
4782
4831
  additionalSigners = [];
4783
4832
  _a.label = 1;
4784
4833
  case 1:
4785
- _a.trys.push([1, 4, , 5]);
4834
+ _a.trys.push([1, 3, , 4]);
4786
4835
  lpTokenMint = poolConfig.stakedLpTokenMint;
4787
4836
  poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
4788
4837
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), owner.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
4789
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, owner, true)];
4790
- case 2:
4791
- userLpTokenAccount = _a.sent();
4838
+ userLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, owner, true);
4792
4839
  return [4, this.program.methods
4793
4840
  .depositStake({
4794
4841
  depositAmount: depositAmount
@@ -4805,18 +4852,19 @@ var PerpetualsClient = (function () {
4805
4852
  systemProgram: web3_js_1.SystemProgram.programId,
4806
4853
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4807
4854
  eventAuthority: this.eventAuthority.publicKey,
4808
- program: this.programId
4855
+ program: this.programId,
4856
+ lpTokenMint: poolConfig.stakedLpTokenMint
4809
4857
  })
4810
4858
  .instruction()];
4811
- case 3:
4859
+ case 2:
4812
4860
  depositStakeInstruction = _a.sent();
4813
4861
  instructions.push(depositStakeInstruction);
4814
- return [3, 5];
4815
- case 4:
4862
+ return [3, 4];
4863
+ case 3:
4816
4864
  err_14 = _a.sent();
4817
4865
  console.log("perpClient depositStaking error:: ", err_14);
4818
4866
  throw err_14;
4819
- case 5: return [2, {
4867
+ case 4: return [2, {
4820
4868
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
4821
4869
  additionalSigners: additionalSigners
4822
4870
  }];
@@ -5103,6 +5151,7 @@ var PerpetualsClient = (function () {
5103
5151
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5104
5152
  eventAuthority: this.eventAuthority.publicKey,
5105
5153
  program: this.program.programId,
5154
+ lpMint: poolConfig.stakedLpTokenMint
5106
5155
  })
5107
5156
  .instruction()];
5108
5157
  case 4:
@@ -5140,7 +5189,7 @@ var PerpetualsClient = (function () {
5140
5189
  _b.trys.push([1, 5, , 6]);
5141
5190
  pool = poolConfig.poolAddress;
5142
5191
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
5143
- receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
5192
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, poolConfig.getTokenFromSymbol(rewardSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5144
5193
  _a = createUserATA;
5145
5194
  if (!_a) return [3, 3];
5146
5195
  return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
@@ -5149,7 +5198,7 @@ var PerpetualsClient = (function () {
5149
5198
  _b.label = 3;
5150
5199
  case 3:
5151
5200
  if (_a) {
5152
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
5201
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, poolConfig.getTokenFromSymbol(rewardSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
5153
5202
  }
5154
5203
  tradingAccount = [];
5155
5204
  if (nftTradingAccount) {
@@ -5182,7 +5231,8 @@ var PerpetualsClient = (function () {
5182
5231
  systemProgram: web3_js_1.SystemProgram.programId,
5183
5232
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5184
5233
  eventAuthority: this.eventAuthority.publicKey,
5185
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5234
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5235
+ receivingMint: rewardCustodyMint
5186
5236
  })
5187
5237
  .remainingAccounts(__spreadArray(__spreadArray([], tradingAccount, true), boostingAccount, true))
5188
5238
  .instruction()];
@@ -5251,18 +5301,19 @@ var PerpetualsClient = (function () {
5251
5301
  });
5252
5302
  }); };
5253
5303
  this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
5254
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_22;
5304
+ var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_22;
5255
5305
  return __generator(this, function (_a) {
5256
5306
  switch (_a.label) {
5257
5307
  case 0:
5258
5308
  publicKey = this.provider.wallet.publicKey;
5259
- rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
5309
+ rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
5310
+ rewardCustodyMint = rewardToken.mintKey;
5260
5311
  instructions = [];
5261
5312
  additionalSigners = [];
5262
5313
  _a.label = 1;
5263
5314
  case 1:
5264
5315
  _a.trys.push([1, 3, , 4]);
5265
- fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
5316
+ fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5266
5317
  rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
5267
5318
  rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
5268
5319
  return [4, this.programFbnftReward.methods
@@ -5295,12 +5346,13 @@ var PerpetualsClient = (function () {
5295
5346
  this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5296
5347
  if (createUserATA === void 0) { createUserATA = true; }
5297
5348
  return __awaiter(_this, void 0, void 0, function () {
5298
- var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_23;
5349
+ var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_23;
5299
5350
  return __generator(this, function (_b) {
5300
5351
  switch (_b.label) {
5301
5352
  case 0:
5302
5353
  publicKey = this.provider.wallet.publicKey;
5303
- rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
5354
+ rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
5355
+ rewardCustodyMint = rewardToken.mintKey;
5304
5356
  instructions = [];
5305
5357
  additionalSigners = [];
5306
5358
  _b.label = 1;
@@ -5308,7 +5360,7 @@ var PerpetualsClient = (function () {
5308
5360
  _b.trys.push([1, 5, , 6]);
5309
5361
  nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
5310
5362
  metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
5311
- receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
5363
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5312
5364
  _a = createUserATA;
5313
5365
  if (!_a) return [3, 3];
5314
5366
  return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
@@ -5317,7 +5369,7 @@ var PerpetualsClient = (function () {
5317
5369
  _b.label = 3;
5318
5370
  case 3:
5319
5371
  if (_a) {
5320
- instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
5372
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
5321
5373
  }
5322
5374
  rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
5323
5375
  rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
@@ -5358,13 +5410,14 @@ var PerpetualsClient = (function () {
5358
5410
  this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
5359
5411
  if (createUserATA === void 0) { createUserATA = true; }
5360
5412
  return __awaiter(_this, void 0, void 0, function () {
5361
- var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_24;
5413
+ var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_24;
5362
5414
  return __generator(this, function (_b) {
5363
5415
  switch (_b.label) {
5364
5416
  case 0:
5365
5417
  publicKey = this.provider.wallet.publicKey;
5366
- rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
5367
- rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
5418
+ rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
5419
+ rewardCustodyMint = rewardToken.mintKey;
5420
+ rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
5368
5421
  preInstructions = [];
5369
5422
  instructions = [];
5370
5423
  postInstructions = [];
@@ -5374,7 +5427,7 @@ var PerpetualsClient = (function () {
5374
5427
  _b.trys.push([1, 5, , 6]);
5375
5428
  pool = poolConfig.poolAddress;
5376
5429
  flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
5377
- receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
5430
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5378
5431
  _a = createUserATA;
5379
5432
  if (!_a) return [3, 3];
5380
5433
  return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
@@ -5383,7 +5436,7 @@ var PerpetualsClient = (function () {
5383
5436
  _b.label = 3;
5384
5437
  case 3:
5385
5438
  if (_a) {
5386
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
5439
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
5387
5440
  }
5388
5441
  tradingAccount = [];
5389
5442
  if (nftTradingAccount) {
@@ -5502,19 +5555,17 @@ var PerpetualsClient = (function () {
5502
5555
  additionalSigners = [];
5503
5556
  _b.label = 1;
5504
5557
  case 1:
5505
- _b.trys.push([1, 6, , 7]);
5506
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner)];
5507
- case 2:
5508
- userReceivingTokenAccount = _b.sent();
5558
+ _b.trys.push([1, 5, , 6]);
5559
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, false, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5509
5560
  _a = createUserATA;
5510
- if (!_a) return [3, 4];
5561
+ if (!_a) return [3, 3];
5511
5562
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
5512
- case 3:
5563
+ case 2:
5513
5564
  _a = !(_b.sent());
5514
- _b.label = 4;
5515
- case 4:
5565
+ _b.label = 3;
5566
+ case 3:
5516
5567
  if (_a) {
5517
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
5568
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
5518
5569
  }
5519
5570
  return [4, this.program.methods
5520
5571
  .forceClosePosition({
@@ -5537,22 +5588,23 @@ var PerpetualsClient = (function () {
5537
5588
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5538
5589
  eventAuthority: this.eventAuthority.publicKey,
5539
5590
  program: this.programId,
5540
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5591
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5592
+ receivingMint: collateralCustodyConfig.mintKey
5541
5593
  })
5542
5594
  .instruction()];
5543
- case 5:
5595
+ case 4:
5544
5596
  forceClosePosition = _b.sent();
5545
5597
  instructions.push(forceClosePosition);
5546
5598
  if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
5547
5599
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
5548
5600
  postInstructions.push(closeWsolATAIns);
5549
5601
  }
5550
- return [3, 7];
5551
- case 6:
5602
+ return [3, 6];
5603
+ case 5:
5552
5604
  err_26 = _b.sent();
5553
5605
  console.log("perpClient forceClosePosition error:: ", err_26);
5554
5606
  throw err_26;
5555
- case 7: return [2, {
5607
+ case 6: return [2, {
5556
5608
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5557
5609
  additionalSigners: additionalSigners
5558
5610
  }];
@@ -5573,30 +5625,28 @@ var PerpetualsClient = (function () {
5573
5625
  reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
5574
5626
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
5575
5627
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
5576
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey)];
5577
- case 1:
5578
- userReserveTokenAccount = _c.sent();
5628
+ userReserveTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, false, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5579
5629
  preInstructions = [];
5580
5630
  instructions = [];
5581
5631
  postInstructions = [];
5582
5632
  additionalSigners = [];
5583
- _c.label = 2;
5584
- case 2:
5585
- _c.trys.push([2, 10, , 11]);
5586
- if (!(reserveSymbol == 'SOL')) return [3, 5];
5633
+ _c.label = 1;
5634
+ case 1:
5635
+ _c.trys.push([1, 9, , 10]);
5636
+ if (!(reserveSymbol == 'SOL')) return [3, 4];
5587
5637
  console.log("reserveSymbol === SOL", reserveSymbol);
5588
5638
  accCreationLamports = this.minimumBalanceForRentExemptAccountLamports;
5589
5639
  lamports = reserveAmount.add(new anchor_1.BN(accCreationLamports));
5590
- if (!!skipBalanceChecks) return [3, 4];
5640
+ if (!!skipBalanceChecks) return [3, 3];
5591
5641
  _a = anchor_1.BN.bind;
5592
5642
  return [4, this.provider.connection.getBalance(publicKey)];
5593
- case 3:
5643
+ case 2:
5594
5644
  unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
5595
5645
  if (unWrappedSolBalance.lt(lamports)) {
5596
5646
  throw "Insufficient SOL Funds";
5597
5647
  }
5598
- _c.label = 4;
5599
- case 4:
5648
+ _c.label = 3;
5649
+ case 3:
5600
5650
  if (!ephemeralSignerPubkey) {
5601
5651
  wrappedSolAccount = new web3_js_1.Keypair();
5602
5652
  additionalSigners.push(wrappedSolAccount);
@@ -5615,22 +5665,22 @@ var PerpetualsClient = (function () {
5615
5665
  (0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
5616
5666
  ];
5617
5667
  additionalSigners.push(wrappedSolAccount);
5618
- return [3, 8];
5619
- case 5: return [4, (0, utils_1.checkIfAccountExists)(userReserveTokenAccount, this.provider.connection)];
5620
- case 6:
5668
+ return [3, 7];
5669
+ case 4: return [4, (0, utils_1.checkIfAccountExists)(userReserveTokenAccount, this.provider.connection)];
5670
+ case 5:
5621
5671
  if (!(_c.sent())) {
5622
5672
  throw "Insufficient Funds , token Account doesn't exist";
5623
5673
  }
5624
- if (!!skipBalanceChecks) return [3, 8];
5674
+ if (!!skipBalanceChecks) return [3, 7];
5625
5675
  _b = anchor_1.BN.bind;
5626
5676
  return [4, this.provider.connection.getTokenAccountBalance(userReserveTokenAccount)];
5627
- case 7:
5677
+ case 6:
5628
5678
  tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
5629
5679
  if (tokenAccountBalance.lt(reserveAmount)) {
5630
5680
  throw "Insufficient Funds need more ".concat(reserveAmount.sub(tokenAccountBalance), " tokens");
5631
5681
  }
5632
- _c.label = 8;
5633
- case 8:
5682
+ _c.label = 7;
5683
+ case 7:
5634
5684
  positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
5635
5685
  orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
5636
5686
  return [4, this.program.methods
@@ -5660,18 +5710,19 @@ var PerpetualsClient = (function () {
5660
5710
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5661
5711
  eventAuthority: this.eventAuthority.publicKey,
5662
5712
  program: this.programId,
5663
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5713
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5714
+ fundingMint: reserveCustodyConfig.mintKey
5664
5715
  })
5665
5716
  .instruction()];
5666
- case 9:
5717
+ case 8:
5667
5718
  placeLimitOrder = _c.sent();
5668
5719
  instructions.push(placeLimitOrder);
5669
- return [3, 11];
5670
- case 10:
5720
+ return [3, 10];
5721
+ case 9:
5671
5722
  err_27 = _c.sent();
5672
5723
  console.log("perpClient placeLimitOrder error:: ", err_27);
5673
5724
  throw err_27;
5674
- case 11: return [2, {
5725
+ case 10: return [2, {
5675
5726
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
5676
5727
  additionalSigners: additionalSigners
5677
5728
  }];
@@ -5720,7 +5771,7 @@ var PerpetualsClient = (function () {
5720
5771
  ];
5721
5772
  return [3, 5];
5722
5773
  case 2:
5723
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true);
5774
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
5724
5775
  _a = createUserATA;
5725
5776
  if (!_a) return [3, 4];
5726
5777
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -5729,7 +5780,7 @@ var PerpetualsClient = (function () {
5729
5780
  _b.label = 4;
5730
5781
  case 4:
5731
5782
  if (_a) {
5732
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey));
5783
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
5733
5784
  }
5734
5785
  _b.label = 5;
5735
5786
  case 5:
@@ -5763,6 +5814,7 @@ var PerpetualsClient = (function () {
5763
5814
  eventAuthority: this.eventAuthority.publicKey,
5764
5815
  program: this.programId,
5765
5816
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5817
+ receivingMint: reserveCustodyConfig.mintKey
5766
5818
  })
5767
5819
  .instruction()];
5768
5820
  case 6:
@@ -6085,7 +6137,7 @@ var PerpetualsClient = (function () {
6085
6137
  if (createUserATA === void 0) { createUserATA = true; }
6086
6138
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6087
6139
  return __awaiter(_this, void 0, void 0, function () {
6088
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_34;
6140
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_34;
6089
6141
  return __generator(this, function (_d) {
6090
6142
  switch (_d.label) {
6091
6143
  case 0:
@@ -6098,13 +6150,15 @@ var PerpetualsClient = (function () {
6098
6150
  instructions = [];
6099
6151
  postInstructions = [];
6100
6152
  additionalSigners = [];
6153
+ collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
6154
+ receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
6101
6155
  _d.label = 1;
6102
6156
  case 1:
6103
6157
  _d.trys.push([1, 9, , 10]);
6104
6158
  if (!false) return [3, 2];
6105
6159
  return [3, 7];
6106
6160
  case 2:
6107
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true);
6161
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(receivingToken.mintKey, owner, true, receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
6108
6162
  _a = createUserATA;
6109
6163
  if (!_a) return [3, 4];
6110
6164
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -6113,9 +6167,9 @@ var PerpetualsClient = (function () {
6113
6167
  _d.label = 4;
6114
6168
  case 4:
6115
6169
  if (_a) {
6116
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
6170
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, receivingToken.mintKey, receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
6117
6171
  }
6118
- userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
6172
+ userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralToken.mintKey, owner, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
6119
6173
  _b = createUserATA;
6120
6174
  if (!_b) return [3, 6];
6121
6175
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
@@ -6124,7 +6178,7 @@ var PerpetualsClient = (function () {
6124
6178
  _d.label = 6;
6125
6179
  case 6:
6126
6180
  if (_b) {
6127
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6181
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, collateralToken.mintKey, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
6128
6182
  }
6129
6183
  _d.label = 7;
6130
6184
  case 7:
@@ -6168,10 +6222,13 @@ var PerpetualsClient = (function () {
6168
6222
  dispensingCustody: receivingCustodyConfig.custodyAccount,
6169
6223
  dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
6170
6224
  dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
6171
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6172
6225
  eventAuthority: this.eventAuthority.publicKey,
6173
6226
  program: this.programId,
6174
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6227
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6228
+ receivingMint: receivingCustodyConfig.mintKey,
6229
+ receivingTokenProgram: receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
6230
+ collateralMint: collateralCustodyConfig.mintKey,
6231
+ collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
6175
6232
  })
6176
6233
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
6177
6234
  .instruction()];
@@ -6213,7 +6270,7 @@ var PerpetualsClient = (function () {
6213
6270
  if (!false) return [3, 2];
6214
6271
  return [3, 5];
6215
6272
  case 2:
6216
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
6273
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
6217
6274
  _a = createUserATA;
6218
6275
  if (!_a) return [3, 4];
6219
6276
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -6222,7 +6279,7 @@ var PerpetualsClient = (function () {
6222
6279
  _b.label = 4;
6223
6280
  case 4:
6224
6281
  if (_a) {
6225
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6282
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
6226
6283
  }
6227
6284
  _b.label = 5;
6228
6285
  case 5:
@@ -6250,7 +6307,8 @@ var PerpetualsClient = (function () {
6250
6307
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6251
6308
  eventAuthority: this.eventAuthority.publicKey,
6252
6309
  program: this.programId,
6253
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6310
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6311
+ receivingMint: collateralCustodyConfig.mintKey
6254
6312
  })
6255
6313
  .instruction()];
6256
6314
  case 6:
@@ -6354,14 +6412,12 @@ var PerpetualsClient = (function () {
6354
6412
  case 0:
6355
6413
  publicKey = this.provider.wallet.publicKey;
6356
6414
  custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
6357
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey, publicKey, true)];
6358
- case 1:
6359
- receivingTokenAccount = _a.sent();
6415
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(rewardSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
6360
6416
  instructions = [];
6361
6417
  additionalSigners = [];
6362
- _a.label = 2;
6363
- case 2:
6364
- _a.trys.push([2, 4, , 5]);
6418
+ _a.label = 1;
6419
+ case 1:
6420
+ _a.trys.push([1, 3, , 4]);
6365
6421
  return [4, this.program.methods
6366
6422
  .withdrawFees({})
6367
6423
  .accounts({
@@ -6373,18 +6429,19 @@ var PerpetualsClient = (function () {
6373
6429
  custody: custodyConfig.custodyAccount,
6374
6430
  custodyTokenAccount: custodyConfig.tokenAccount,
6375
6431
  receivingTokenAccount: receivingTokenAccount,
6376
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
6432
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6433
+ receivingMint: custodyConfig.mintKey
6377
6434
  })
6378
6435
  .instruction()];
6379
- case 3:
6436
+ case 2:
6380
6437
  withdrawFeesIx = _a.sent();
6381
6438
  instructions.push(withdrawFeesIx);
6382
- return [3, 5];
6383
- case 4:
6439
+ return [3, 4];
6440
+ case 3:
6384
6441
  err_38 = _a.sent();
6385
6442
  console.log("perpClient setPool error:: ", err_38);
6386
6443
  throw err_38;
6387
- case 5: return [2, {
6444
+ case 4: return [2, {
6388
6445
  instructions: __spreadArray([], instructions, true),
6389
6446
  additionalSigners: additionalSigners
6390
6447
  }];
@@ -6430,10 +6487,9 @@ var PerpetualsClient = (function () {
6430
6487
  });
6431
6488
  }); };
6432
6489
  this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6433
- var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_40;
6434
- var _f;
6435
- return __generator(this, function (_g) {
6436
- switch (_g.label) {
6490
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, err_40;
6491
+ return __generator(this, function (_d) {
6492
+ switch (_d.label) {
6437
6493
  case 0:
6438
6494
  custodyAccountMetas = [];
6439
6495
  custodyOracleAccountMetas = [];
@@ -6462,38 +6518,36 @@ var PerpetualsClient = (function () {
6462
6518
  instructions = [];
6463
6519
  additionalSigners = [];
6464
6520
  custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(tokenMint); });
6465
- _g.label = 1;
6521
+ _d.label = 1;
6466
6522
  case 1:
6467
- _g.trys.push([1, 4, , 5]);
6468
- _e = (_d = this.program.methods
6469
- .reimburse({ amountIn: amountIn }))
6470
- .accounts;
6471
- _f = {
6472
- admin: this.provider.wallet.publicKey,
6473
- multisig: poolConfig.multisig
6474
- };
6475
- return [4, (0, spl_token_1.getAssociatedTokenAddress)(tokenMint, this.provider.wallet.publicKey, true)];
6476
- case 2: return [4, _e.apply(_d, [(_f.fundingAccount = _g.sent(),
6477
- _f.perpetuals = poolConfig.perpetuals,
6478
- _f.pool = poolConfig.poolAddress,
6479
- _f.custody = custodyConfig.custodyAccount,
6480
- _f.custodyOracleAccount = this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
6481
- _f.custodyTokenAccount = custodyConfig.tokenAccount,
6482
- _f.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
6483
- _f.program = poolConfig.programId,
6484
- _f.ixSysvar = web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6485
- _f)])
6486
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
6487
- .instruction()];
6488
- case 3:
6489
- reimburse = _g.sent();
6523
+ _d.trys.push([1, 3, , 4]);
6524
+ return [4, this.program.methods
6525
+ .reimburse({ amountIn: amountIn })
6526
+ .accounts({
6527
+ admin: this.provider.wallet.publicKey,
6528
+ multisig: poolConfig.multisig,
6529
+ fundingAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.provider.wallet.publicKey, true),
6530
+ perpetuals: poolConfig.perpetuals,
6531
+ pool: poolConfig.poolAddress,
6532
+ custody: custodyConfig.custodyAccount,
6533
+ custodyOracleAccount: this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
6534
+ custodyTokenAccount: custodyConfig.tokenAccount,
6535
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6536
+ program: poolConfig.programId,
6537
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6538
+ fundingMint: custodyConfig.mintKey
6539
+ })
6540
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
6541
+ .instruction()];
6542
+ case 2:
6543
+ reimburse = _d.sent();
6490
6544
  instructions.push(reimburse);
6491
- return [3, 5];
6492
- case 4:
6493
- err_40 = _g.sent();
6545
+ return [3, 4];
6546
+ case 3:
6547
+ err_40 = _d.sent();
6494
6548
  console.log("perpClient setPool error:: ", err_40);
6495
6549
  throw err_40;
6496
- case 5: return [2, {
6550
+ case 4: return [2, {
6497
6551
  instructions: __spreadArray([], instructions, true),
6498
6552
  additionalSigners: additionalSigners
6499
6553
  }];
@@ -6548,22 +6602,23 @@ var PerpetualsClient = (function () {
6548
6602
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6549
6603
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6550
6604
  return __awaiter(_this, void 0, void 0, function () {
6551
- var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_42;
6605
+ var publicKey, inToken, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_42;
6552
6606
  return __generator(this, function (_e) {
6553
6607
  switch (_e.label) {
6554
6608
  case 0:
6555
6609
  publicKey = this.provider.wallet.publicKey;
6610
+ inToken = poolConfig.getTokenFromSymbol(inTokenSymbol);
6556
6611
  preInstructions = [];
6557
6612
  instructions = [];
6558
6613
  additionalSigners = [];
6559
6614
  postInstructions = [];
6560
6615
  rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
6561
- inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
6616
+ inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(inToken.mintKey); });
6562
6617
  lpTokenMint = poolConfig.stakedLpTokenMint;
6563
6618
  compoundingTokenMint = poolConfig.compoundingTokenMint;
6564
6619
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
6565
6620
  compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
6566
- fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true);
6621
+ fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true, inToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
6567
6622
  custodyAccountMetas = [];
6568
6623
  custodyOracleAccountMetas = [];
6569
6624
  markets = [];
@@ -6662,7 +6717,9 @@ var PerpetualsClient = (function () {
6662
6717
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6663
6718
  eventAuthority: this.eventAuthority.publicKey,
6664
6719
  program: this.program.programId,
6665
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6720
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6721
+ fundingMint: inCustodyConfig.mintKey,
6722
+ fundingTokenProgram: inToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
6666
6723
  })
6667
6724
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
6668
6725
  .instruction()];
@@ -6686,7 +6743,7 @@ var PerpetualsClient = (function () {
6686
6743
  if (createUserATA === void 0) { createUserATA = true; }
6687
6744
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6688
6745
  return __awaiter(_this, void 0, void 0, function () {
6689
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_43;
6746
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, outToken, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_43;
6690
6747
  return __generator(this, function (_e) {
6691
6748
  switch (_e.label) {
6692
6749
  case 0:
@@ -6699,6 +6756,7 @@ var PerpetualsClient = (function () {
6699
6756
  outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
6700
6757
  lpTokenMint = poolConfig.stakedLpTokenMint;
6701
6758
  compoundingTokenMint = poolConfig.compoundingTokenMint;
6759
+ outToken = poolConfig.getTokenFromSymbol(outTokenSymbol);
6702
6760
  if (!(outCustodyConfig.symbol == 'SOL')) return [3, 1];
6703
6761
  lamports = this.minimumBalanceForRentExemptAccountLamports;
6704
6762
  if (!ephemeralSignerPubkey) {
@@ -6720,7 +6778,7 @@ var PerpetualsClient = (function () {
6720
6778
  ];
6721
6779
  return [3, 4];
6722
6780
  case 1:
6723
- userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true);
6781
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true, outToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
6724
6782
  _a = createUserATA;
6725
6783
  if (!_a) return [3, 3];
6726
6784
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
@@ -6729,7 +6787,7 @@ var PerpetualsClient = (function () {
6729
6787
  _e.label = 3;
6730
6788
  case 3:
6731
6789
  if (_a) {
6732
- preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
6790
+ preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey, outToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
6733
6791
  }
6734
6792
  _e.label = 4;
6735
6793
  case 4:
@@ -6784,7 +6842,9 @@ var PerpetualsClient = (function () {
6784
6842
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6785
6843
  eventAuthority: this.eventAuthority.publicKey,
6786
6844
  program: this.program.programId,
6787
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6845
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6846
+ receivingMint: outCustodyConfig.mintKey,
6847
+ receivingTokenProgram: outToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
6788
6848
  })
6789
6849
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
6790
6850
  .instruction()];
@@ -7182,18 +7242,19 @@ var PerpetualsClient = (function () {
7182
7242
  });
7183
7243
  }); };
7184
7244
  this.rewardDistribution = function (counter, owner, rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7185
- var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_50;
7245
+ var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_50;
7186
7246
  return __generator(this, function (_a) {
7187
7247
  switch (_a.label) {
7188
7248
  case 0:
7189
7249
  publicKey = this.provider.wallet.publicKey;
7190
- rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
7250
+ rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
7251
+ rewardCustodyMint = rewardToken.mintKey;
7191
7252
  instructions = [];
7192
7253
  additionalSigners = [];
7193
7254
  _a.label = 1;
7194
7255
  case 1:
7195
7256
  _a.trys.push([1, 3, , 4]);
7196
- fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
7257
+ fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
7197
7258
  rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
7198
7259
  rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
7199
7260
  rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), owner.toBuffer(), rewardVault.toBuffer(), counter.toArrayLike(Buffer, 'le', 8)], this.programRewardDistribution.programId)[0];
@@ -7234,18 +7295,19 @@ var PerpetualsClient = (function () {
7234
7295
  this.collectReward = function (counter, owner, rewardSymbol, poolConfig, createUserATA) {
7235
7296
  if (createUserATA === void 0) { createUserATA = true; }
7236
7297
  return __awaiter(_this, void 0, void 0, function () {
7237
- var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_51;
7298
+ var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_51;
7238
7299
  return __generator(this, function (_b) {
7239
7300
  switch (_b.label) {
7240
7301
  case 0:
7241
7302
  publicKey = this.provider.wallet.publicKey;
7242
- rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
7303
+ rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
7304
+ rewardCustodyMint = rewardToken.mintKey;
7243
7305
  instructions = [];
7244
7306
  additionalSigners = [];
7245
7307
  _b.label = 1;
7246
7308
  case 1:
7247
7309
  _b.trys.push([1, 5, , 6]);
7248
- receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
7310
+ receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
7249
7311
  _a = createUserATA;
7250
7312
  if (!_a) return [3, 3];
7251
7313
  return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
@@ -7254,7 +7316,7 @@ var PerpetualsClient = (function () {
7254
7316
  _b.label = 3;
7255
7317
  case 3:
7256
7318
  if (_a) {
7257
- instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
7319
+ instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
7258
7320
  }
7259
7321
  rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
7260
7322
  rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];