@meteora-ag/zap-sdk 1.2.0 → 1.3.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -88,6 +88,8 @@ __export(index_exports, {
88
88
  ZapIdl: () => idl_default,
89
89
  ZapInDammV2PoolSwapRoute: () => ZapInDammV2PoolSwapRoute,
90
90
  buildJupiterSwapTransaction: () => buildJupiterSwapTransaction,
91
+ buildVersionedJupiterSwapTransaction: () => buildVersionedJupiterSwapTransaction,
92
+ buildVersionedTransaction: () => buildVersionedTransaction,
91
93
  convertAccountTypeToNumber: () => convertAccountTypeToNumber,
92
94
  convertLamportsToUiAmount: () => convertLamportsToUiAmount,
93
95
  convertUiAmountToLamports: () => convertUiAmountToLamports,
@@ -101,6 +103,7 @@ __export(index_exports, {
101
103
  estimateDlmmIndirectSwap: () => estimateDlmmIndirectSwap,
102
104
  estimateDlmmRebalanceSwap: () => estimateDlmmRebalanceSwap,
103
105
  filterOutCloseSplTokenAccountInstructions: () => filterOutCloseSplTokenAccountInstructions,
106
+ getAddressLookupTableAccounts: () => getAddressLookupTableAccounts,
104
107
  getBinArrayBitmapExtension: () => getBinArrayBitmapExtension,
105
108
  getBitFromBinArrayIndexInBitmapExtension: () => getBitFromBinArrayIndexInBitmapExtension,
106
109
  getDammV2Pool: () => getDammV2Pool,
@@ -114,6 +117,8 @@ __export(index_exports, {
114
117
  getOrCreateATAInstruction: () => getOrCreateATAInstruction,
115
118
  getTokenAccountBalance: () => getTokenAccountBalance,
116
119
  getTokenProgramFromMint: () => getTokenProgramFromMint,
120
+ isSingleSidedA: () => isSingleSidedA,
121
+ isSingleSidedB: () => isSingleSidedB,
117
122
  toProgramStrategyType: () => toProgramStrategyType,
118
123
  unwrapSOLInstruction: () => unwrapSOLInstruction,
119
124
  wrapSOLInstruction: () => wrapSOLInstruction
@@ -660,6 +665,9 @@ var idl_default = {
660
665
  {
661
666
  name: "TransferHookMultiReward",
662
667
  fields: ["u8"]
668
+ },
669
+ {
670
+ name: "TransferHookReferral"
663
671
  }
664
672
  ]
665
673
  }
@@ -1779,6 +1787,67 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
1779
1787
  var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
1780
1788
 
1781
1789
  // src/helpers/jupiter.ts
1790
+ var PLACEHOLDER_BLOCKHASH = import_web32.PublicKey.default.toBase58();
1791
+ var DEFAULT_SWAP_COMPUTE_UNIT_LIMIT = 6e5;
1792
+ var MAX_COMPUTE_UNIT_LIMIT = 14e5;
1793
+ function toTransactionInstruction(instruction) {
1794
+ return new import_web32.TransactionInstruction({
1795
+ keys: instruction.accounts.map((item) => ({
1796
+ pubkey: typeof item.pubkey === "string" ? new import_web32.PublicKey(item.pubkey) : item.pubkey,
1797
+ isSigner: item.isSigner,
1798
+ isWritable: item.isWritable
1799
+ })),
1800
+ programId: new import_web32.PublicKey(instruction.programId),
1801
+ data: Buffer.from(instruction.data, "base64")
1802
+ });
1803
+ }
1804
+ function getAddressLookupTableAccounts(connection, addresses) {
1805
+ return __async(this, null, function* () {
1806
+ if (!addresses || addresses.length === 0) {
1807
+ return [];
1808
+ }
1809
+ const accountInfos = yield connection.getMultipleAccountsInfo(
1810
+ addresses.map((address) => new import_web32.PublicKey(address))
1811
+ );
1812
+ const lookupTableAccounts = [];
1813
+ accountInfos.forEach((accountInfo, index) => {
1814
+ if (accountInfo) {
1815
+ lookupTableAccounts.push(
1816
+ new import_web32.AddressLookupTableAccount({
1817
+ key: new import_web32.PublicKey(addresses[index]),
1818
+ state: import_web32.AddressLookupTableAccount.deserialize(accountInfo.data)
1819
+ })
1820
+ );
1821
+ }
1822
+ });
1823
+ return lookupTableAccounts;
1824
+ });
1825
+ }
1826
+ function buildVersionedTransaction(payerKey, instructions, lookupTableAccounts) {
1827
+ const message = new import_web32.TransactionMessage({
1828
+ payerKey,
1829
+ recentBlockhash: PLACEHOLDER_BLOCKHASH,
1830
+ instructions
1831
+ }).compileToV0Message(lookupTableAccounts);
1832
+ return new import_web32.VersionedTransaction(message);
1833
+ }
1834
+ function buildVersionedJupiterSwapTransaction(connection, user, swapInstructionResponse) {
1835
+ return __async(this, null, function* () {
1836
+ const lookupTableAccounts = yield getAddressLookupTableAccounts(
1837
+ connection,
1838
+ swapInstructionResponse.addressLookupTableAddresses
1839
+ );
1840
+ const computeUnitLimit = Math.min(
1841
+ swapInstructionResponse.computeUnitLimit || DEFAULT_SWAP_COMPUTE_UNIT_LIMIT,
1842
+ MAX_COMPUTE_UNIT_LIMIT
1843
+ );
1844
+ const instructions = [
1845
+ import_web32.ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnitLimit }),
1846
+ toTransactionInstruction(swapInstructionResponse.swapInstruction)
1847
+ ];
1848
+ return buildVersionedTransaction(user, instructions, lookupTableAccounts);
1849
+ });
1850
+ }
1782
1851
  function getJupiterQuote(_0, _1, _2, _3, _4) {
1783
1852
  return __async(this, arguments, function* (inputMint, outputMint, amount, maxAccounts, slippageBps, dynamicSlippage = false, onlyDirectRoutes, restrictIntermediateTokens, config = {}) {
1784
1853
  const params = new URLSearchParams({
@@ -1792,9 +1861,8 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
1792
1861
  dynamicSlippage: dynamicSlippage.toString()
1793
1862
  });
1794
1863
  const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/quote?${params.toString()}`;
1795
- let response = null;
1796
1864
  try {
1797
- response = yield fetch(url, {
1865
+ const response = yield fetch(url, {
1798
1866
  method: "GET",
1799
1867
  headers: __spreadValues({
1800
1868
  Accept: "application/json"
@@ -1803,11 +1871,11 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
1803
1871
  if (!response.ok) {
1804
1872
  return null;
1805
1873
  }
1874
+ const result = yield response.json();
1875
+ return result;
1806
1876
  } catch (error) {
1807
1877
  return null;
1808
1878
  }
1809
- const result = yield response.json();
1810
- return result;
1811
1879
  });
1812
1880
  }
1813
1881
  function getJupiterSwapInstruction(_0, _1) {
@@ -1840,8 +1908,8 @@ function getJupiterSwapInstruction(_0, _1) {
1840
1908
  return result;
1841
1909
  });
1842
1910
  }
1843
- function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1844
- return __async(this, arguments, function* (user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
1911
+ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
1912
+ return __async(this, arguments, function* (connection, user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
1845
1913
  const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
1846
1914
  inputMint,
1847
1915
  outputMint,
@@ -1849,7 +1917,7 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1849
1917
  maxAccounts,
1850
1918
  slippageBps,
1851
1919
  false,
1852
- true,
1920
+ false,
1853
1921
  true,
1854
1922
  config
1855
1923
  );
@@ -1863,18 +1931,12 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1863
1931
  quoteResponse,
1864
1932
  config
1865
1933
  );
1866
- const instruction = new import_web32.TransactionInstruction({
1867
- keys: swapInstructionResponse.swapInstruction.accounts.map((item) => {
1868
- return {
1869
- pubkey: new import_web32.PublicKey(item.pubkey),
1870
- isSigner: item.isSigner,
1871
- isWritable: item.isWritable
1872
- };
1873
- }),
1874
- programId: new import_web32.PublicKey(swapInstructionResponse.swapInstruction.programId),
1875
- data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
1876
- });
1877
- return { transaction: new import_web32.Transaction().add(instruction), quoteResponse };
1934
+ const transaction = yield buildVersionedJupiterSwapTransaction(
1935
+ connection,
1936
+ user,
1937
+ swapInstructionResponse
1938
+ );
1939
+ return { transaction, quoteResponse };
1878
1940
  });
1879
1941
  }
1880
1942
 
@@ -1993,6 +2055,12 @@ function getDammV2RemainingAccounts(_0, _1, _2, _3) {
1993
2055
  return remainingAccounts;
1994
2056
  });
1995
2057
  }
2058
+ function isSingleSidedA(poolState) {
2059
+ return poolState.collectFeeMode !== import_cp_amm_sdk.CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMinPrice);
2060
+ }
2061
+ function isSingleSidedB(poolState) {
2062
+ return poolState.collectFeeMode !== import_cp_amm_sdk.CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMaxPrice);
2063
+ }
1996
2064
  function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
1997
2065
  return Buffer.concat([
1998
2066
  Buffer.from(DAMM_V2_SWAP_DISCRIMINATOR),
@@ -2277,7 +2345,7 @@ function getDlmmRemainingAccounts(connection, lbPair, user, userInputTokenAccoun
2277
2345
  },
2278
2346
  {
2279
2347
  isSigner: false,
2280
- isWritable: false,
2348
+ isWritable: true,
2281
2349
  pubkey: binArrayBitmapExtension
2282
2350
  },
2283
2351
  {
@@ -3526,30 +3594,77 @@ var Zap = class {
3526
3594
  tokenBProgram
3527
3595
  );
3528
3596
  const inputTokenDecimal = inputTokenMint.equals(tokenAMint) ? tokenADecimal : tokenBDecimal;
3597
+ const collectFeeMode = poolState.collectFeeMode;
3529
3598
  const poolBalanceTokenA = (0, import_cp_amm_sdk3.getAmountAFromLiquidityDelta)(
3530
3599
  poolState.sqrtPrice,
3531
3600
  poolState.sqrtMaxPrice,
3532
3601
  poolState.liquidity,
3533
- import_cp_amm_sdk3.Rounding.Down
3602
+ import_cp_amm_sdk3.Rounding.Down,
3603
+ collectFeeMode,
3604
+ poolState.tokenAAmount,
3605
+ poolState.liquidity
3534
3606
  );
3535
3607
  const poolBalanceTokenB = (0, import_cp_amm_sdk3.getAmountBFromLiquidityDelta)(
3536
3608
  poolState.sqrtMinPrice,
3537
3609
  poolState.sqrtPrice,
3538
3610
  poolState.liquidity,
3539
- import_cp_amm_sdk3.Rounding.Down
3611
+ import_cp_amm_sdk3.Rounding.Down,
3612
+ collectFeeMode,
3613
+ poolState.tokenBAmount,
3614
+ poolState.liquidity
3540
3615
  );
3616
+ const isInputTokenA = tokenAMint.equals(inputTokenMint);
3617
+ const outputTokenMint = isInputTokenA ? tokenBMint : tokenAMint;
3618
+ const singleSidedA = isSingleSidedA(poolState);
3619
+ const singleSidedB = isSingleSidedB(poolState);
3541
3620
  let amount;
3542
3621
  let swapTransactions = [];
3543
3622
  let maxTransferAmount;
3544
3623
  let swapInAmount;
3545
3624
  let swapRoute;
3546
- if (dammV2Quote === null && jupiterQuote === null) {
3547
- throw new Error("No Jupiter or DAMM v2 quote found, unable to proceed");
3548
- }
3549
- if (jupiterQuote !== null && (dammV2Quote === null || new import_anchor.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
3625
+ if (singleSidedA && isInputTokenA || singleSidedB && !isInputTokenA) {
3626
+ amount = amountIn;
3627
+ swapInAmount = new import_anchor.BN(0);
3628
+ maxTransferAmount = new import_anchor.BN(0);
3629
+ swapRoute = "dammV2" /* DammV2 */;
3630
+ } else if (singleSidedA && !isInputTokenA || singleSidedB && isInputTokenA) {
3631
+ if (jupiterQuote !== null && (dammV2Quote === null || new import_anchor.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
3632
+ swapInAmount = amountIn;
3633
+ amount = new import_anchor.BN(0);
3634
+ const result = yield buildJupiterSwapTransaction(
3635
+ this.connection,
3636
+ user,
3637
+ inputTokenMint,
3638
+ outputTokenMint,
3639
+ swapInAmount,
3640
+ maxAccounts,
3641
+ slippageBps,
3642
+ void 0,
3643
+ {
3644
+ jupiterApiUrl: this.jupiterApiUrl,
3645
+ jupiterApiKey: this.jupiterApiKey
3646
+ }
3647
+ );
3648
+ swapTransactions = [result.transaction];
3649
+ maxTransferAmount = getExtendMaxAmountTransfer(
3650
+ result.quoteResponse.outAmount,
3651
+ maxTransferAmountExtendPercentage
3652
+ );
3653
+ swapRoute = "jupiter" /* Jupiter */;
3654
+ } else if (dammV2Quote !== null) {
3655
+ swapInAmount = new import_anchor.BN(0);
3656
+ amount = amountIn;
3657
+ maxTransferAmount = new import_anchor.BN(0);
3658
+ swapRoute = "dammV2" /* DammV2 */;
3659
+ } else {
3660
+ throw new Error(
3661
+ "No Jupiter or DAMM v2 quote found for single-sided swap, unable to proceed"
3662
+ );
3663
+ }
3664
+ } else if (jupiterQuote !== null && (dammV2Quote === null || new import_anchor.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
3550
3665
  const price = convertLamportsToUiAmount(
3551
3666
  new import_decimal4.default(jupiterQuote.outAmount),
3552
- tokenAMint.equals(inputTokenMint) ? tokenBDecimal : tokenADecimal
3667
+ isInputTokenA ? tokenBDecimal : tokenADecimal
3553
3668
  );
3554
3669
  swapInAmount = calculateDirectPoolSwapAmount(
3555
3670
  amountIn,
@@ -3563,13 +3678,14 @@ var Zap = class {
3563
3678
  new import_decimal4.default(poolBalanceTokenB.toString()),
3564
3679
  tokenBDecimal
3565
3680
  ),
3566
- tokenAMint.equals(inputTokenMint)
3681
+ isInputTokenA
3567
3682
  );
3568
3683
  amount = amountIn.sub(swapInAmount);
3569
3684
  const result = yield buildJupiterSwapTransaction(
3685
+ this.connection,
3570
3686
  user,
3571
3687
  inputTokenMint,
3572
- tokenAMint.equals(inputTokenMint) ? tokenBMint : tokenAMint,
3688
+ outputTokenMint,
3573
3689
  swapInAmount,
3574
3690
  maxAccounts,
3575
3691
  slippageBps,
@@ -3585,7 +3701,7 @@ var Zap = class {
3585
3701
  maxTransferAmountExtendPercentage
3586
3702
  );
3587
3703
  swapRoute = "jupiter" /* Jupiter */;
3588
- } else {
3704
+ } else if (dammV2Quote !== null) {
3589
3705
  const quote = dammV2Quote;
3590
3706
  amount = amountIn;
3591
3707
  const price = convertLamportsToUiAmount(
@@ -3604,13 +3720,15 @@ var Zap = class {
3604
3720
  new import_decimal4.default(poolBalanceTokenB.toString()),
3605
3721
  tokenBDecimal
3606
3722
  ),
3607
- tokenAMint.equals(inputTokenMint)
3723
+ isInputTokenA
3608
3724
  );
3609
3725
  maxTransferAmount = getExtendMaxAmountTransfer(
3610
3726
  quote.swapOutAmount.toString(),
3611
3727
  maxTransferAmountExtendPercentage
3612
3728
  );
3613
3729
  swapRoute = "dammV2" /* DammV2 */;
3730
+ } else {
3731
+ throw new Error("No Jupiter or DAMM v2 quote found, unable to proceed");
3614
3732
  }
3615
3733
  const cleanUpInstructions = [];
3616
3734
  if (tokenAMint.equals(import_spl_token6.NATIVE_MINT) || tokenBMint.equals(import_spl_token6.NATIVE_MINT)) {
@@ -3624,7 +3742,7 @@ var Zap = class {
3624
3742
  position,
3625
3743
  positionNftAccount,
3626
3744
  isDirectPool: true,
3627
- isTokenA: tokenAMint.equals(inputTokenMint),
3745
+ isTokenA: isInputTokenA,
3628
3746
  tokenAMint,
3629
3747
  tokenBMint,
3630
3748
  tokenAVault,
@@ -3735,20 +3853,134 @@ var Zap = class {
3735
3853
  const closewrapSol = unwrapSOLInstruction(user, user, false);
3736
3854
  closewrapSol && cleanUpInstructions.push(closewrapSol);
3737
3855
  }
3856
+ const collectFeeMode = poolState.collectFeeMode;
3738
3857
  const poolBalanceTokenA = (0, import_cp_amm_sdk3.getAmountAFromLiquidityDelta)(
3739
3858
  poolState.sqrtPrice,
3740
3859
  poolState.sqrtMaxPrice,
3741
3860
  poolState.liquidity,
3742
- import_cp_amm_sdk3.Rounding.Down
3861
+ import_cp_amm_sdk3.Rounding.Down,
3862
+ collectFeeMode,
3863
+ poolState.tokenAAmount,
3864
+ poolState.liquidity
3743
3865
  );
3744
3866
  const poolBalanceTokenB = (0, import_cp_amm_sdk3.getAmountBFromLiquidityDelta)(
3745
3867
  poolState.sqrtMinPrice,
3746
3868
  poolState.sqrtPrice,
3747
3869
  poolState.liquidity,
3748
- import_cp_amm_sdk3.Rounding.Down
3870
+ import_cp_amm_sdk3.Rounding.Down,
3871
+ collectFeeMode,
3872
+ poolState.tokenBAmount,
3873
+ poolState.liquidity
3749
3874
  );
3875
+ const singleSidedA = isSingleSidedA(poolState);
3876
+ const singleSidedB = isSingleSidedB(poolState);
3877
+ if (singleSidedA) {
3878
+ if (!jupiterQuoteToA) {
3879
+ throw new Error(
3880
+ "No Jupiter quote for token A found for single-sided pool, unable to proceed"
3881
+ );
3882
+ }
3883
+ const result = yield buildJupiterSwapTransaction(
3884
+ this.connection,
3885
+ user,
3886
+ inputTokenMint,
3887
+ tokenAMint,
3888
+ amountIn,
3889
+ maxAccounts,
3890
+ slippageBps,
3891
+ void 0,
3892
+ {
3893
+ jupiterApiUrl: this.jupiterApiUrl,
3894
+ jupiterApiKey: this.jupiterApiKey
3895
+ }
3896
+ );
3897
+ return {
3898
+ user,
3899
+ pool,
3900
+ position,
3901
+ positionNftAccount,
3902
+ maxSqrtPriceChangeBps,
3903
+ amount: new import_anchor.BN(0),
3904
+ isDirectPool: false,
3905
+ tokenAMint,
3906
+ tokenBMint,
3907
+ tokenAVault,
3908
+ tokenBVault,
3909
+ tokenAProgram,
3910
+ tokenBProgram,
3911
+ maxTransferAmountA: getExtendMaxAmountTransfer(
3912
+ result.quoteResponse.outAmount,
3913
+ maxTransferAmountExtendPercentage
3914
+ ),
3915
+ swapType: 0 /* swapToA */,
3916
+ maxTransferAmountB: new import_anchor.BN(0),
3917
+ preSqrtPrice: poolState.sqrtPrice,
3918
+ preInstructions,
3919
+ swapTransactions: [result.transaction],
3920
+ cleanUpInstructions,
3921
+ swapInEstimate: {
3922
+ inAmountA: amountIn,
3923
+ inAmountB: new import_anchor.BN(0),
3924
+ routeA: "jupiter" /* Jupiter */,
3925
+ routeB: "dammV2" /* DammV2 */
3926
+ }
3927
+ };
3928
+ }
3929
+ if (singleSidedB) {
3930
+ if (!jupiterQuoteToB) {
3931
+ throw new Error(
3932
+ "No Jupiter quote for token B found for single-sided pool, unable to proceed"
3933
+ );
3934
+ }
3935
+ const result = yield buildJupiterSwapTransaction(
3936
+ this.connection,
3937
+ user,
3938
+ inputTokenMint,
3939
+ tokenBMint,
3940
+ amountIn,
3941
+ maxAccounts,
3942
+ slippageBps,
3943
+ void 0,
3944
+ {
3945
+ jupiterApiUrl: this.jupiterApiUrl,
3946
+ jupiterApiKey: this.jupiterApiKey
3947
+ }
3948
+ );
3949
+ return {
3950
+ user,
3951
+ pool,
3952
+ position,
3953
+ positionNftAccount,
3954
+ maxSqrtPriceChangeBps,
3955
+ amount: new import_anchor.BN(0),
3956
+ isDirectPool: false,
3957
+ tokenAMint,
3958
+ tokenBMint,
3959
+ tokenAVault,
3960
+ tokenBVault,
3961
+ tokenAProgram,
3962
+ tokenBProgram,
3963
+ maxTransferAmountA: new import_anchor.BN(0),
3964
+ maxTransferAmountB: getExtendMaxAmountTransfer(
3965
+ result.quoteResponse.outAmount,
3966
+ maxTransferAmountExtendPercentage
3967
+ ),
3968
+ swapType: 1 /* swapToB */,
3969
+ preSqrtPrice: poolState.sqrtPrice,
3970
+ preInstructions,
3971
+ swapTransactions: [result.transaction],
3972
+ cleanUpInstructions,
3973
+ swapInEstimate: {
3974
+ inAmountA: new import_anchor.BN(0),
3975
+ inAmountB: amountIn,
3976
+ routeA: "dammV2" /* DammV2 */,
3977
+ routeB: "jupiter" /* Jupiter */
3978
+ }
3979
+ };
3980
+ }
3750
3981
  if (jupiterQuoteToA && jupiterQuoteToB === null) {
3751
- const { transaction: swapTransaction } = yield buildJupiterSwapTransaction(
3982
+ const result = yield buildJupiterSwapTransaction(
3983
+ this.connection,
3752
3984
  user,
3753
3985
  inputTokenMint,
3754
3986
  tokenAMint,
@@ -3776,14 +4008,14 @@ var Zap = class {
3776
4008
  tokenAProgram,
3777
4009
  tokenBProgram,
3778
4010
  maxTransferAmountA: getExtendMaxAmountTransfer(
3779
- jupiterQuoteToA.outAmount,
4011
+ result.quoteResponse.outAmount,
3780
4012
  maxTransferAmountExtendPercentage
3781
4013
  ),
3782
4014
  swapType: 0 /* swapToA */,
3783
4015
  maxTransferAmountB: new import_anchor.BN(0),
3784
4016
  preSqrtPrice: poolState.sqrtPrice,
3785
4017
  preInstructions,
3786
- swapTransactions: [swapTransaction],
4018
+ swapTransactions: [result.transaction],
3787
4019
  cleanUpInstructions,
3788
4020
  swapInEstimate: {
3789
4021
  inAmountA: amountIn,
@@ -3794,7 +4026,8 @@ var Zap = class {
3794
4026
  };
3795
4027
  }
3796
4028
  if (jupiterQuoteToB && jupiterQuoteToA === null) {
3797
- const { transaction: swapTransaction } = yield buildJupiterSwapTransaction(
4029
+ const result = yield buildJupiterSwapTransaction(
4030
+ this.connection,
3798
4031
  user,
3799
4032
  inputTokenMint,
3800
4033
  tokenBMint,
@@ -3823,13 +4056,13 @@ var Zap = class {
3823
4056
  tokenBProgram,
3824
4057
  maxTransferAmountA: new import_anchor.BN(0),
3825
4058
  maxTransferAmountB: getExtendMaxAmountTransfer(
3826
- jupiterQuoteToB.outAmount,
4059
+ result.quoteResponse.outAmount,
3827
4060
  maxTransferAmountExtendPercentage
3828
4061
  ),
3829
4062
  swapType: 1 /* swapToB */,
3830
4063
  preSqrtPrice: poolState.sqrtPrice,
3831
4064
  preInstructions,
3832
- swapTransactions: [swapTransaction],
4065
+ swapTransactions: [result.transaction],
3833
4066
  cleanUpInstructions,
3834
4067
  swapInEstimate: {
3835
4068
  inAmountA: new import_anchor.BN(0),
@@ -3863,7 +4096,26 @@ var Zap = class {
3863
4096
  )
3864
4097
  );
3865
4098
  const swapAmountToB = amountIn.sub(swapAmountToA);
4099
+ const baseParams = {
4100
+ user,
4101
+ pool,
4102
+ position,
4103
+ positionNftAccount,
4104
+ maxSqrtPriceChangeBps,
4105
+ amount: new import_anchor.BN(0),
4106
+ isDirectPool: false,
4107
+ tokenAMint,
4108
+ tokenBMint,
4109
+ tokenAVault,
4110
+ tokenBVault,
4111
+ tokenAProgram,
4112
+ tokenBProgram,
4113
+ preInstructions,
4114
+ preSqrtPrice: poolState.sqrtPrice,
4115
+ cleanUpInstructions
4116
+ };
3866
4117
  const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
4118
+ this.connection,
3867
4119
  user,
3868
4120
  inputTokenMint,
3869
4121
  tokenAMint,
@@ -3877,6 +4129,7 @@ var Zap = class {
3877
4129
  }
3878
4130
  );
3879
4131
  const { transaction: swapToBTransaction, quoteResponse: swapToBQuote } = yield buildJupiterSwapTransaction(
4132
+ this.connection,
3880
4133
  user,
3881
4134
  inputTokenMint,
3882
4135
  tokenBMint,
@@ -3889,21 +4142,7 @@ var Zap = class {
3889
4142
  jupiterApiKey: this.jupiterApiKey
3890
4143
  }
3891
4144
  );
3892
- return {
3893
- user,
3894
- pool,
3895
- position,
3896
- positionNftAccount,
3897
- maxSqrtPriceChangeBps,
3898
- amount: new import_anchor.BN(0),
3899
- isDirectPool: false,
3900
- tokenAMint,
3901
- tokenBMint,
3902
- tokenAVault,
3903
- tokenBVault,
3904
- tokenAProgram,
3905
- tokenBProgram,
3906
- preInstructions,
4145
+ return __spreadProps(__spreadValues({}, baseParams), {
3907
4146
  maxTransferAmountA: getExtendMaxAmountTransfer(
3908
4147
  swapToAQuote.outAmount,
3909
4148
  maxTransferAmountExtendPercentage
@@ -3913,16 +4152,14 @@ var Zap = class {
3913
4152
  maxTransferAmountExtendPercentage
3914
4153
  ),
3915
4154
  swapType: 2 /* swapToBoth */,
3916
- preSqrtPrice: poolState.sqrtPrice,
3917
4155
  swapTransactions: [swapToATransaction, swapToBTransaction],
3918
- cleanUpInstructions,
3919
4156
  swapInEstimate: {
3920
4157
  inAmountA: swapAmountToA,
3921
4158
  inAmountB: swapAmountToB,
3922
4159
  routeA: "jupiter" /* Jupiter */,
3923
4160
  routeB: "jupiter" /* Jupiter */
3924
4161
  }
3925
- };
4162
+ });
3926
4163
  }
3927
4164
  throw new Error(
3928
4165
  "No Jupiter quote found for both tokens, unable to proceed"
@@ -4000,9 +4237,7 @@ var Zap = class {
4000
4237
  setupTransaction.add(...preInstructions);
4001
4238
  }
4002
4239
  const ledgerTransaction = new import_web38.Transaction();
4003
- const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
4004
- user
4005
- );
4240
+ const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
4006
4241
  ledgerTransaction.add(resetOrInitializeLedgerTx);
4007
4242
  if (isDirectPool) {
4008
4243
  const isTokenA = params.isTokenA;
@@ -4165,6 +4400,7 @@ var Zap = class {
4165
4400
  const swapQuote = directSwapEstimate.quote;
4166
4401
  if (swapQuote.route === 0 /* Jupiter */) {
4167
4402
  const { transaction: swapTx } = yield buildJupiterSwapTransaction(
4403
+ this.connection,
4168
4404
  user,
4169
4405
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
4170
4406
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
@@ -4334,6 +4570,7 @@ var Zap = class {
4334
4570
  const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
4335
4571
  if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
4336
4572
  const { transaction: swapToXTransaction } = yield buildJupiterSwapTransaction(
4573
+ this.connection,
4337
4574
  user,
4338
4575
  inputTokenMint,
4339
4576
  tokenXMint,
@@ -4350,6 +4587,7 @@ var Zap = class {
4350
4587
  }
4351
4588
  if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
4352
4589
  const { transaction: swapToYTransaction } = yield buildJupiterSwapTransaction(
4590
+ this.connection,
4353
4591
  user,
4354
4592
  inputTokenMint,
4355
4593
  tokenYMint,
@@ -4491,9 +4729,7 @@ var Zap = class {
4491
4729
  setupTransaction.add(...preInstructions);
4492
4730
  }
4493
4731
  const ledgerTransaction = new import_web38.Transaction();
4494
- const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
4495
- user
4496
- );
4732
+ const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
4497
4733
  ledgerTransaction.add(resetOrInitializeLedgerTx);
4498
4734
  if (isDirectRoute) {
4499
4735
  const { isTokenX, amount, maxTransferAmount } = params;
@@ -4752,6 +4988,7 @@ var Zap = class {
4752
4988
  const swapQuote = directSwapEstimate.quote;
4753
4989
  if (swapQuote.route === 0 /* Jupiter */) {
4754
4990
  const { transaction: swapTx } = yield buildJupiterSwapTransaction(
4991
+ this.connection,
4755
4992
  user,
4756
4993
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
4757
4994
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
@@ -4796,9 +5033,7 @@ var Zap = class {
4796
5033
  const tokenXAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenXAmount.sub(directSwapEstimate.swapAmount) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenXAmount.add(directSwapEstimate.expectedOutput) : tokenXAmount;
4797
5034
  const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
4798
5035
  const ledgerAddress = deriveLedgerAccount(user);
4799
- const ledgerAccountInfo = yield this.connection.getAccountInfo(
4800
- ledgerAddress
4801
- );
5036
+ const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
4802
5037
  const ledgerTransaction = new import_web38.Transaction();
4803
5038
  if (!ledgerAccountInfo) {
4804
5039
  const initLedgerTx = yield this.initializeLedgerAccount(user, user);
@@ -5000,7 +5235,7 @@ var Zap = class {
5000
5235
  postInstructions.push(unwrapInstructions);
5001
5236
  }
5002
5237
  }
5003
- return yield this.zapOut({
5238
+ const zapOutTransaction = yield this.zapOut({
5004
5239
  userTokenInAccount: inputTokenAccount,
5005
5240
  zapOutParams: {
5006
5241
  percentage: percentageToZapOut,
@@ -5014,6 +5249,22 @@ var Zap = class {
5014
5249
  preInstructions,
5015
5250
  postInstructions
5016
5251
  });
5252
+ const lookupTableAccounts = yield getAddressLookupTableAccounts(
5253
+ this.connection,
5254
+ jupiterSwapResponse.addressLookupTableAddresses
5255
+ );
5256
+ const computeUnitLimit = Math.min(
5257
+ (jupiterSwapResponse.computeUnitLimit || 6e5) + 2e5,
5258
+ 14e5
5259
+ );
5260
+ return buildVersionedTransaction(
5261
+ user,
5262
+ [
5263
+ import_web38.ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnitLimit }),
5264
+ ...zapOutTransaction.instructions
5265
+ ],
5266
+ lookupTableAccounts
5267
+ );
5017
5268
  });
5018
5269
  }
5019
5270
  /**
@@ -5236,6 +5487,8 @@ var Zap = class {
5236
5487
  ZapIdl,
5237
5488
  ZapInDammV2PoolSwapRoute,
5238
5489
  buildJupiterSwapTransaction,
5490
+ buildVersionedJupiterSwapTransaction,
5491
+ buildVersionedTransaction,
5239
5492
  convertAccountTypeToNumber,
5240
5493
  convertLamportsToUiAmount,
5241
5494
  convertUiAmountToLamports,
@@ -5249,6 +5502,7 @@ var Zap = class {
5249
5502
  estimateDlmmIndirectSwap,
5250
5503
  estimateDlmmRebalanceSwap,
5251
5504
  filterOutCloseSplTokenAccountInstructions,
5505
+ getAddressLookupTableAccounts,
5252
5506
  getBinArrayBitmapExtension,
5253
5507
  getBitFromBinArrayIndexInBitmapExtension,
5254
5508
  getDammV2Pool,
@@ -5262,6 +5516,8 @@ var Zap = class {
5262
5516
  getOrCreateATAInstruction,
5263
5517
  getTokenAccountBalance,
5264
5518
  getTokenProgramFromMint,
5519
+ isSingleSidedA,
5520
+ isSingleSidedB,
5265
5521
  toProgramStrategyType,
5266
5522
  unwrapSOLInstruction,
5267
5523
  wrapSOLInstruction