@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.mjs CHANGED
@@ -40,10 +40,10 @@ var __async = (__this, __arguments, generator) => {
40
40
 
41
41
  // src/zap.ts
42
42
  import {
43
- ComputeBudgetProgram,
43
+ ComputeBudgetProgram as ComputeBudgetProgram2,
44
44
  PublicKey as PublicKey8,
45
45
  SystemProgram as SystemProgram2,
46
- Transaction as Transaction2
46
+ Transaction
47
47
  } from "@solana/web3.js";
48
48
  import invariant2 from "invariant";
49
49
  import { BN as BN5, Program } from "@coral-xyz/anchor";
@@ -583,6 +583,9 @@ var idl_default = {
583
583
  {
584
584
  name: "TransferHookMultiReward",
585
585
  fields: ["u8"]
586
+ },
587
+ {
588
+ name: "TransferHookReferral"
586
589
  }
587
590
  ]
588
591
  }
@@ -1648,9 +1651,12 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
1648
1651
 
1649
1652
  // src/helpers/jupiter.ts
1650
1653
  import {
1654
+ AddressLookupTableAccount,
1655
+ ComputeBudgetProgram,
1651
1656
  PublicKey as PublicKey2,
1652
- Transaction,
1653
- TransactionInstruction
1657
+ TransactionInstruction,
1658
+ TransactionMessage,
1659
+ VersionedTransaction
1654
1660
  } from "@solana/web3.js";
1655
1661
 
1656
1662
  // src/constants.ts
@@ -1709,6 +1715,67 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
1709
1715
  var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
1710
1716
 
1711
1717
  // src/helpers/jupiter.ts
1718
+ var PLACEHOLDER_BLOCKHASH = PublicKey2.default.toBase58();
1719
+ var DEFAULT_SWAP_COMPUTE_UNIT_LIMIT = 6e5;
1720
+ var MAX_COMPUTE_UNIT_LIMIT = 14e5;
1721
+ function toTransactionInstruction(instruction) {
1722
+ return new TransactionInstruction({
1723
+ keys: instruction.accounts.map((item) => ({
1724
+ pubkey: typeof item.pubkey === "string" ? new PublicKey2(item.pubkey) : item.pubkey,
1725
+ isSigner: item.isSigner,
1726
+ isWritable: item.isWritable
1727
+ })),
1728
+ programId: new PublicKey2(instruction.programId),
1729
+ data: Buffer.from(instruction.data, "base64")
1730
+ });
1731
+ }
1732
+ function getAddressLookupTableAccounts(connection, addresses) {
1733
+ return __async(this, null, function* () {
1734
+ if (!addresses || addresses.length === 0) {
1735
+ return [];
1736
+ }
1737
+ const accountInfos = yield connection.getMultipleAccountsInfo(
1738
+ addresses.map((address) => new PublicKey2(address))
1739
+ );
1740
+ const lookupTableAccounts = [];
1741
+ accountInfos.forEach((accountInfo, index) => {
1742
+ if (accountInfo) {
1743
+ lookupTableAccounts.push(
1744
+ new AddressLookupTableAccount({
1745
+ key: new PublicKey2(addresses[index]),
1746
+ state: AddressLookupTableAccount.deserialize(accountInfo.data)
1747
+ })
1748
+ );
1749
+ }
1750
+ });
1751
+ return lookupTableAccounts;
1752
+ });
1753
+ }
1754
+ function buildVersionedTransaction(payerKey, instructions, lookupTableAccounts) {
1755
+ const message = new TransactionMessage({
1756
+ payerKey,
1757
+ recentBlockhash: PLACEHOLDER_BLOCKHASH,
1758
+ instructions
1759
+ }).compileToV0Message(lookupTableAccounts);
1760
+ return new VersionedTransaction(message);
1761
+ }
1762
+ function buildVersionedJupiterSwapTransaction(connection, user, swapInstructionResponse) {
1763
+ return __async(this, null, function* () {
1764
+ const lookupTableAccounts = yield getAddressLookupTableAccounts(
1765
+ connection,
1766
+ swapInstructionResponse.addressLookupTableAddresses
1767
+ );
1768
+ const computeUnitLimit = Math.min(
1769
+ swapInstructionResponse.computeUnitLimit || DEFAULT_SWAP_COMPUTE_UNIT_LIMIT,
1770
+ MAX_COMPUTE_UNIT_LIMIT
1771
+ );
1772
+ const instructions = [
1773
+ ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnitLimit }),
1774
+ toTransactionInstruction(swapInstructionResponse.swapInstruction)
1775
+ ];
1776
+ return buildVersionedTransaction(user, instructions, lookupTableAccounts);
1777
+ });
1778
+ }
1712
1779
  function getJupiterQuote(_0, _1, _2, _3, _4) {
1713
1780
  return __async(this, arguments, function* (inputMint, outputMint, amount, maxAccounts, slippageBps, dynamicSlippage = false, onlyDirectRoutes, restrictIntermediateTokens, config = {}) {
1714
1781
  const params = new URLSearchParams({
@@ -1722,9 +1789,8 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
1722
1789
  dynamicSlippage: dynamicSlippage.toString()
1723
1790
  });
1724
1791
  const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/quote?${params.toString()}`;
1725
- let response = null;
1726
1792
  try {
1727
- response = yield fetch(url, {
1793
+ const response = yield fetch(url, {
1728
1794
  method: "GET",
1729
1795
  headers: __spreadValues({
1730
1796
  Accept: "application/json"
@@ -1733,11 +1799,11 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
1733
1799
  if (!response.ok) {
1734
1800
  return null;
1735
1801
  }
1802
+ const result = yield response.json();
1803
+ return result;
1736
1804
  } catch (error) {
1737
1805
  return null;
1738
1806
  }
1739
- const result = yield response.json();
1740
- return result;
1741
1807
  });
1742
1808
  }
1743
1809
  function getJupiterSwapInstruction(_0, _1) {
@@ -1770,8 +1836,8 @@ function getJupiterSwapInstruction(_0, _1) {
1770
1836
  return result;
1771
1837
  });
1772
1838
  }
1773
- function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1774
- return __async(this, arguments, function* (user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
1839
+ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
1840
+ return __async(this, arguments, function* (connection, user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
1775
1841
  const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
1776
1842
  inputMint,
1777
1843
  outputMint,
@@ -1779,7 +1845,7 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1779
1845
  maxAccounts,
1780
1846
  slippageBps,
1781
1847
  false,
1782
- true,
1848
+ false,
1783
1849
  true,
1784
1850
  config
1785
1851
  );
@@ -1793,24 +1859,22 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1793
1859
  quoteResponse,
1794
1860
  config
1795
1861
  );
1796
- const instruction = new TransactionInstruction({
1797
- keys: swapInstructionResponse.swapInstruction.accounts.map((item) => {
1798
- return {
1799
- pubkey: new PublicKey2(item.pubkey),
1800
- isSigner: item.isSigner,
1801
- isWritable: item.isWritable
1802
- };
1803
- }),
1804
- programId: new PublicKey2(swapInstructionResponse.swapInstruction.programId),
1805
- data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
1806
- });
1807
- return { transaction: new Transaction().add(instruction), quoteResponse };
1862
+ const transaction = yield buildVersionedJupiterSwapTransaction(
1863
+ connection,
1864
+ user,
1865
+ swapInstructionResponse
1866
+ );
1867
+ return { transaction, quoteResponse };
1808
1868
  });
1809
1869
  }
1810
1870
 
1811
1871
  // src/helpers/dammV2.ts
1812
1872
  import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
1813
- import { CpAmm, derivePoolAuthority } from "@meteora-ag/cp-amm-sdk";
1873
+ import {
1874
+ CollectFeeMode,
1875
+ CpAmm,
1876
+ derivePoolAuthority
1877
+ } from "@meteora-ag/cp-amm-sdk";
1814
1878
 
1815
1879
  // src/helpers/pda.ts
1816
1880
  import { PublicKey as PublicKey3 } from "@solana/web3.js";
@@ -1923,6 +1987,12 @@ function getDammV2RemainingAccounts(_0, _1, _2, _3) {
1923
1987
  return remainingAccounts;
1924
1988
  });
1925
1989
  }
1990
+ function isSingleSidedA(poolState) {
1991
+ return poolState.collectFeeMode !== CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMinPrice);
1992
+ }
1993
+ function isSingleSidedB(poolState) {
1994
+ return poolState.collectFeeMode !== CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMaxPrice);
1995
+ }
1926
1996
  function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
1927
1997
  return Buffer.concat([
1928
1998
  Buffer.from(DAMM_V2_SWAP_DISCRIMINATOR),
@@ -2233,7 +2303,7 @@ function getDlmmRemainingAccounts(connection, lbPair, user, userInputTokenAccoun
2233
2303
  },
2234
2304
  {
2235
2305
  isSigner: false,
2236
- isWritable: false,
2306
+ isWritable: true,
2237
2307
  pubkey: binArrayBitmapExtension
2238
2308
  },
2239
2309
  {
@@ -3286,7 +3356,7 @@ var Zap = class {
3286
3356
  if (accountInfo) {
3287
3357
  const closeLedger = yield this.closeLedgerAccount(user, user);
3288
3358
  const reInitializeLedger = yield this.initializeLedgerAccount(user, user);
3289
- return new Transaction2().add(closeLedger).add(reInitializeLedger);
3359
+ return new Transaction().add(closeLedger).add(reInitializeLedger);
3290
3360
  }
3291
3361
  return yield this.initializeLedgerAccount(user, user);
3292
3362
  });
@@ -3505,30 +3575,77 @@ var Zap = class {
3505
3575
  tokenBProgram
3506
3576
  );
3507
3577
  const inputTokenDecimal = inputTokenMint.equals(tokenAMint) ? tokenADecimal : tokenBDecimal;
3578
+ const collectFeeMode = poolState.collectFeeMode;
3508
3579
  const poolBalanceTokenA = getAmountAFromLiquidityDelta(
3509
3580
  poolState.sqrtPrice,
3510
3581
  poolState.sqrtMaxPrice,
3511
3582
  poolState.liquidity,
3512
- Rounding.Down
3583
+ Rounding.Down,
3584
+ collectFeeMode,
3585
+ poolState.tokenAAmount,
3586
+ poolState.liquidity
3513
3587
  );
3514
3588
  const poolBalanceTokenB = getAmountBFromLiquidityDelta(
3515
3589
  poolState.sqrtMinPrice,
3516
3590
  poolState.sqrtPrice,
3517
3591
  poolState.liquidity,
3518
- Rounding.Down
3592
+ Rounding.Down,
3593
+ collectFeeMode,
3594
+ poolState.tokenBAmount,
3595
+ poolState.liquidity
3519
3596
  );
3597
+ const isInputTokenA = tokenAMint.equals(inputTokenMint);
3598
+ const outputTokenMint = isInputTokenA ? tokenBMint : tokenAMint;
3599
+ const singleSidedA = isSingleSidedA(poolState);
3600
+ const singleSidedB = isSingleSidedB(poolState);
3520
3601
  let amount;
3521
3602
  let swapTransactions = [];
3522
3603
  let maxTransferAmount;
3523
3604
  let swapInAmount;
3524
3605
  let swapRoute;
3525
- if (dammV2Quote === null && jupiterQuote === null) {
3526
- throw new Error("No Jupiter or DAMM v2 quote found, unable to proceed");
3527
- }
3528
- if (jupiterQuote !== null && (dammV2Quote === null || new BN5(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
3606
+ if (singleSidedA && isInputTokenA || singleSidedB && !isInputTokenA) {
3607
+ amount = amountIn;
3608
+ swapInAmount = new BN5(0);
3609
+ maxTransferAmount = new BN5(0);
3610
+ swapRoute = "dammV2" /* DammV2 */;
3611
+ } else if (singleSidedA && !isInputTokenA || singleSidedB && isInputTokenA) {
3612
+ if (jupiterQuote !== null && (dammV2Quote === null || new BN5(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
3613
+ swapInAmount = amountIn;
3614
+ amount = new BN5(0);
3615
+ const result = yield buildJupiterSwapTransaction(
3616
+ this.connection,
3617
+ user,
3618
+ inputTokenMint,
3619
+ outputTokenMint,
3620
+ swapInAmount,
3621
+ maxAccounts,
3622
+ slippageBps,
3623
+ void 0,
3624
+ {
3625
+ jupiterApiUrl: this.jupiterApiUrl,
3626
+ jupiterApiKey: this.jupiterApiKey
3627
+ }
3628
+ );
3629
+ swapTransactions = [result.transaction];
3630
+ maxTransferAmount = getExtendMaxAmountTransfer(
3631
+ result.quoteResponse.outAmount,
3632
+ maxTransferAmountExtendPercentage
3633
+ );
3634
+ swapRoute = "jupiter" /* Jupiter */;
3635
+ } else if (dammV2Quote !== null) {
3636
+ swapInAmount = new BN5(0);
3637
+ amount = amountIn;
3638
+ maxTransferAmount = new BN5(0);
3639
+ swapRoute = "dammV2" /* DammV2 */;
3640
+ } else {
3641
+ throw new Error(
3642
+ "No Jupiter or DAMM v2 quote found for single-sided swap, unable to proceed"
3643
+ );
3644
+ }
3645
+ } else if (jupiterQuote !== null && (dammV2Quote === null || new BN5(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
3529
3646
  const price = convertLamportsToUiAmount(
3530
3647
  new Decimal4(jupiterQuote.outAmount),
3531
- tokenAMint.equals(inputTokenMint) ? tokenBDecimal : tokenADecimal
3648
+ isInputTokenA ? tokenBDecimal : tokenADecimal
3532
3649
  );
3533
3650
  swapInAmount = calculateDirectPoolSwapAmount(
3534
3651
  amountIn,
@@ -3542,13 +3659,14 @@ var Zap = class {
3542
3659
  new Decimal4(poolBalanceTokenB.toString()),
3543
3660
  tokenBDecimal
3544
3661
  ),
3545
- tokenAMint.equals(inputTokenMint)
3662
+ isInputTokenA
3546
3663
  );
3547
3664
  amount = amountIn.sub(swapInAmount);
3548
3665
  const result = yield buildJupiterSwapTransaction(
3666
+ this.connection,
3549
3667
  user,
3550
3668
  inputTokenMint,
3551
- tokenAMint.equals(inputTokenMint) ? tokenBMint : tokenAMint,
3669
+ outputTokenMint,
3552
3670
  swapInAmount,
3553
3671
  maxAccounts,
3554
3672
  slippageBps,
@@ -3564,7 +3682,7 @@ var Zap = class {
3564
3682
  maxTransferAmountExtendPercentage
3565
3683
  );
3566
3684
  swapRoute = "jupiter" /* Jupiter */;
3567
- } else {
3685
+ } else if (dammV2Quote !== null) {
3568
3686
  const quote = dammV2Quote;
3569
3687
  amount = amountIn;
3570
3688
  const price = convertLamportsToUiAmount(
@@ -3583,13 +3701,15 @@ var Zap = class {
3583
3701
  new Decimal4(poolBalanceTokenB.toString()),
3584
3702
  tokenBDecimal
3585
3703
  ),
3586
- tokenAMint.equals(inputTokenMint)
3704
+ isInputTokenA
3587
3705
  );
3588
3706
  maxTransferAmount = getExtendMaxAmountTransfer(
3589
3707
  quote.swapOutAmount.toString(),
3590
3708
  maxTransferAmountExtendPercentage
3591
3709
  );
3592
3710
  swapRoute = "dammV2" /* DammV2 */;
3711
+ } else {
3712
+ throw new Error("No Jupiter or DAMM v2 quote found, unable to proceed");
3593
3713
  }
3594
3714
  const cleanUpInstructions = [];
3595
3715
  if (tokenAMint.equals(NATIVE_MINT3) || tokenBMint.equals(NATIVE_MINT3)) {
@@ -3603,7 +3723,7 @@ var Zap = class {
3603
3723
  position,
3604
3724
  positionNftAccount,
3605
3725
  isDirectPool: true,
3606
- isTokenA: tokenAMint.equals(inputTokenMint),
3726
+ isTokenA: isInputTokenA,
3607
3727
  tokenAMint,
3608
3728
  tokenBMint,
3609
3729
  tokenAVault,
@@ -3714,20 +3834,134 @@ var Zap = class {
3714
3834
  const closewrapSol = unwrapSOLInstruction(user, user, false);
3715
3835
  closewrapSol && cleanUpInstructions.push(closewrapSol);
3716
3836
  }
3837
+ const collectFeeMode = poolState.collectFeeMode;
3717
3838
  const poolBalanceTokenA = getAmountAFromLiquidityDelta(
3718
3839
  poolState.sqrtPrice,
3719
3840
  poolState.sqrtMaxPrice,
3720
3841
  poolState.liquidity,
3721
- Rounding.Down
3842
+ Rounding.Down,
3843
+ collectFeeMode,
3844
+ poolState.tokenAAmount,
3845
+ poolState.liquidity
3722
3846
  );
3723
3847
  const poolBalanceTokenB = getAmountBFromLiquidityDelta(
3724
3848
  poolState.sqrtMinPrice,
3725
3849
  poolState.sqrtPrice,
3726
3850
  poolState.liquidity,
3727
- Rounding.Down
3851
+ Rounding.Down,
3852
+ collectFeeMode,
3853
+ poolState.tokenBAmount,
3854
+ poolState.liquidity
3728
3855
  );
3856
+ const singleSidedA = isSingleSidedA(poolState);
3857
+ const singleSidedB = isSingleSidedB(poolState);
3858
+ if (singleSidedA) {
3859
+ if (!jupiterQuoteToA) {
3860
+ throw new Error(
3861
+ "No Jupiter quote for token A found for single-sided pool, unable to proceed"
3862
+ );
3863
+ }
3864
+ const result = yield buildJupiterSwapTransaction(
3865
+ this.connection,
3866
+ user,
3867
+ inputTokenMint,
3868
+ tokenAMint,
3869
+ amountIn,
3870
+ maxAccounts,
3871
+ slippageBps,
3872
+ void 0,
3873
+ {
3874
+ jupiterApiUrl: this.jupiterApiUrl,
3875
+ jupiterApiKey: this.jupiterApiKey
3876
+ }
3877
+ );
3878
+ return {
3879
+ user,
3880
+ pool,
3881
+ position,
3882
+ positionNftAccount,
3883
+ maxSqrtPriceChangeBps,
3884
+ amount: new BN5(0),
3885
+ isDirectPool: false,
3886
+ tokenAMint,
3887
+ tokenBMint,
3888
+ tokenAVault,
3889
+ tokenBVault,
3890
+ tokenAProgram,
3891
+ tokenBProgram,
3892
+ maxTransferAmountA: getExtendMaxAmountTransfer(
3893
+ result.quoteResponse.outAmount,
3894
+ maxTransferAmountExtendPercentage
3895
+ ),
3896
+ swapType: 0 /* swapToA */,
3897
+ maxTransferAmountB: new BN5(0),
3898
+ preSqrtPrice: poolState.sqrtPrice,
3899
+ preInstructions,
3900
+ swapTransactions: [result.transaction],
3901
+ cleanUpInstructions,
3902
+ swapInEstimate: {
3903
+ inAmountA: amountIn,
3904
+ inAmountB: new BN5(0),
3905
+ routeA: "jupiter" /* Jupiter */,
3906
+ routeB: "dammV2" /* DammV2 */
3907
+ }
3908
+ };
3909
+ }
3910
+ if (singleSidedB) {
3911
+ if (!jupiterQuoteToB) {
3912
+ throw new Error(
3913
+ "No Jupiter quote for token B found for single-sided pool, unable to proceed"
3914
+ );
3915
+ }
3916
+ const result = yield buildJupiterSwapTransaction(
3917
+ this.connection,
3918
+ user,
3919
+ inputTokenMint,
3920
+ tokenBMint,
3921
+ amountIn,
3922
+ maxAccounts,
3923
+ slippageBps,
3924
+ void 0,
3925
+ {
3926
+ jupiterApiUrl: this.jupiterApiUrl,
3927
+ jupiterApiKey: this.jupiterApiKey
3928
+ }
3929
+ );
3930
+ return {
3931
+ user,
3932
+ pool,
3933
+ position,
3934
+ positionNftAccount,
3935
+ maxSqrtPriceChangeBps,
3936
+ amount: new BN5(0),
3937
+ isDirectPool: false,
3938
+ tokenAMint,
3939
+ tokenBMint,
3940
+ tokenAVault,
3941
+ tokenBVault,
3942
+ tokenAProgram,
3943
+ tokenBProgram,
3944
+ maxTransferAmountA: new BN5(0),
3945
+ maxTransferAmountB: getExtendMaxAmountTransfer(
3946
+ result.quoteResponse.outAmount,
3947
+ maxTransferAmountExtendPercentage
3948
+ ),
3949
+ swapType: 1 /* swapToB */,
3950
+ preSqrtPrice: poolState.sqrtPrice,
3951
+ preInstructions,
3952
+ swapTransactions: [result.transaction],
3953
+ cleanUpInstructions,
3954
+ swapInEstimate: {
3955
+ inAmountA: new BN5(0),
3956
+ inAmountB: amountIn,
3957
+ routeA: "dammV2" /* DammV2 */,
3958
+ routeB: "jupiter" /* Jupiter */
3959
+ }
3960
+ };
3961
+ }
3729
3962
  if (jupiterQuoteToA && jupiterQuoteToB === null) {
3730
- const { transaction: swapTransaction } = yield buildJupiterSwapTransaction(
3963
+ const result = yield buildJupiterSwapTransaction(
3964
+ this.connection,
3731
3965
  user,
3732
3966
  inputTokenMint,
3733
3967
  tokenAMint,
@@ -3755,14 +3989,14 @@ var Zap = class {
3755
3989
  tokenAProgram,
3756
3990
  tokenBProgram,
3757
3991
  maxTransferAmountA: getExtendMaxAmountTransfer(
3758
- jupiterQuoteToA.outAmount,
3992
+ result.quoteResponse.outAmount,
3759
3993
  maxTransferAmountExtendPercentage
3760
3994
  ),
3761
3995
  swapType: 0 /* swapToA */,
3762
3996
  maxTransferAmountB: new BN5(0),
3763
3997
  preSqrtPrice: poolState.sqrtPrice,
3764
3998
  preInstructions,
3765
- swapTransactions: [swapTransaction],
3999
+ swapTransactions: [result.transaction],
3766
4000
  cleanUpInstructions,
3767
4001
  swapInEstimate: {
3768
4002
  inAmountA: amountIn,
@@ -3773,7 +4007,8 @@ var Zap = class {
3773
4007
  };
3774
4008
  }
3775
4009
  if (jupiterQuoteToB && jupiterQuoteToA === null) {
3776
- const { transaction: swapTransaction } = yield buildJupiterSwapTransaction(
4010
+ const result = yield buildJupiterSwapTransaction(
4011
+ this.connection,
3777
4012
  user,
3778
4013
  inputTokenMint,
3779
4014
  tokenBMint,
@@ -3802,13 +4037,13 @@ var Zap = class {
3802
4037
  tokenBProgram,
3803
4038
  maxTransferAmountA: new BN5(0),
3804
4039
  maxTransferAmountB: getExtendMaxAmountTransfer(
3805
- jupiterQuoteToB.outAmount,
4040
+ result.quoteResponse.outAmount,
3806
4041
  maxTransferAmountExtendPercentage
3807
4042
  ),
3808
4043
  swapType: 1 /* swapToB */,
3809
4044
  preSqrtPrice: poolState.sqrtPrice,
3810
4045
  preInstructions,
3811
- swapTransactions: [swapTransaction],
4046
+ swapTransactions: [result.transaction],
3812
4047
  cleanUpInstructions,
3813
4048
  swapInEstimate: {
3814
4049
  inAmountA: new BN5(0),
@@ -3842,7 +4077,26 @@ var Zap = class {
3842
4077
  )
3843
4078
  );
3844
4079
  const swapAmountToB = amountIn.sub(swapAmountToA);
4080
+ const baseParams = {
4081
+ user,
4082
+ pool,
4083
+ position,
4084
+ positionNftAccount,
4085
+ maxSqrtPriceChangeBps,
4086
+ amount: new BN5(0),
4087
+ isDirectPool: false,
4088
+ tokenAMint,
4089
+ tokenBMint,
4090
+ tokenAVault,
4091
+ tokenBVault,
4092
+ tokenAProgram,
4093
+ tokenBProgram,
4094
+ preInstructions,
4095
+ preSqrtPrice: poolState.sqrtPrice,
4096
+ cleanUpInstructions
4097
+ };
3845
4098
  const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
4099
+ this.connection,
3846
4100
  user,
3847
4101
  inputTokenMint,
3848
4102
  tokenAMint,
@@ -3856,6 +4110,7 @@ var Zap = class {
3856
4110
  }
3857
4111
  );
3858
4112
  const { transaction: swapToBTransaction, quoteResponse: swapToBQuote } = yield buildJupiterSwapTransaction(
4113
+ this.connection,
3859
4114
  user,
3860
4115
  inputTokenMint,
3861
4116
  tokenBMint,
@@ -3868,21 +4123,7 @@ var Zap = class {
3868
4123
  jupiterApiKey: this.jupiterApiKey
3869
4124
  }
3870
4125
  );
3871
- return {
3872
- user,
3873
- pool,
3874
- position,
3875
- positionNftAccount,
3876
- maxSqrtPriceChangeBps,
3877
- amount: new BN5(0),
3878
- isDirectPool: false,
3879
- tokenAMint,
3880
- tokenBMint,
3881
- tokenAVault,
3882
- tokenBVault,
3883
- tokenAProgram,
3884
- tokenBProgram,
3885
- preInstructions,
4126
+ return __spreadProps(__spreadValues({}, baseParams), {
3886
4127
  maxTransferAmountA: getExtendMaxAmountTransfer(
3887
4128
  swapToAQuote.outAmount,
3888
4129
  maxTransferAmountExtendPercentage
@@ -3892,16 +4133,14 @@ var Zap = class {
3892
4133
  maxTransferAmountExtendPercentage
3893
4134
  ),
3894
4135
  swapType: 2 /* swapToBoth */,
3895
- preSqrtPrice: poolState.sqrtPrice,
3896
4136
  swapTransactions: [swapToATransaction, swapToBTransaction],
3897
- cleanUpInstructions,
3898
4137
  swapInEstimate: {
3899
4138
  inAmountA: swapAmountToA,
3900
4139
  inAmountB: swapAmountToB,
3901
4140
  routeA: "jupiter" /* Jupiter */,
3902
4141
  routeB: "jupiter" /* Jupiter */
3903
4142
  }
3904
- };
4143
+ });
3905
4144
  }
3906
4145
  throw new Error(
3907
4146
  "No Jupiter quote found for both tokens, unable to proceed"
@@ -3972,16 +4211,14 @@ var Zap = class {
3972
4211
  tokenBProgram
3973
4212
  )
3974
4213
  ]);
3975
- const setupTransaction = new Transaction2();
4214
+ const setupTransaction = new Transaction();
3976
4215
  initializeTokenAIx && setupTransaction.add(initializeTokenAIx);
3977
4216
  initializeTokenBIx && setupTransaction.add(initializeTokenBIx);
3978
4217
  if (preInstructions.length > 0) {
3979
4218
  setupTransaction.add(...preInstructions);
3980
4219
  }
3981
- const ledgerTransaction = new Transaction2();
3982
- const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
3983
- user
3984
- );
4220
+ const ledgerTransaction = new Transaction();
4221
+ const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
3985
4222
  ledgerTransaction.add(resetOrInitializeLedgerTx);
3986
4223
  if (isDirectPool) {
3987
4224
  const isTokenA = params.isTokenA;
@@ -4056,7 +4293,7 @@ var Zap = class {
4056
4293
  tokenAAccount,
4057
4294
  tokenBAccount
4058
4295
  });
4059
- const cleanUpTransaction = new Transaction2();
4296
+ const cleanUpTransaction = new Transaction();
4060
4297
  const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
4061
4298
  cleanUpTransaction.add(closeLedgerTransaction);
4062
4299
  if (cleanUpInstructions.length > 0) {
@@ -4144,6 +4381,7 @@ var Zap = class {
4144
4381
  const swapQuote = directSwapEstimate.quote;
4145
4382
  if (swapQuote.route === 0 /* Jupiter */) {
4146
4383
  const { transaction: swapTx } = yield buildJupiterSwapTransaction(
4384
+ this.connection,
4147
4385
  user,
4148
4386
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
4149
4387
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
@@ -4313,6 +4551,7 @@ var Zap = class {
4313
4551
  const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
4314
4552
  if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
4315
4553
  const { transaction: swapToXTransaction } = yield buildJupiterSwapTransaction(
4554
+ this.connection,
4316
4555
  user,
4317
4556
  inputTokenMint,
4318
4557
  tokenXMint,
@@ -4329,6 +4568,7 @@ var Zap = class {
4329
4568
  }
4330
4569
  if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
4331
4570
  const { transaction: swapToYTransaction } = yield buildJupiterSwapTransaction(
4571
+ this.connection,
4332
4572
  user,
4333
4573
  inputTokenMint,
4334
4574
  tokenYMint,
@@ -4463,16 +4703,14 @@ var Zap = class {
4463
4703
  tokenYProgram
4464
4704
  )
4465
4705
  ]);
4466
- const setupTransaction = new Transaction2();
4706
+ const setupTransaction = new Transaction();
4467
4707
  initializeTokenXIx && setupTransaction.add(initializeTokenXIx);
4468
4708
  initializeTokenYIx && setupTransaction.add(initializeTokenYIx);
4469
4709
  if (preInstructions.length > 0) {
4470
4710
  setupTransaction.add(...preInstructions);
4471
4711
  }
4472
- const ledgerTransaction = new Transaction2();
4473
- const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
4474
- user
4475
- );
4712
+ const ledgerTransaction = new Transaction();
4713
+ const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
4476
4714
  ledgerTransaction.add(resetOrInitializeLedgerTx);
4477
4715
  if (isDirectRoute) {
4478
4716
  const { isTokenX, amount, maxTransferAmount } = params;
@@ -4592,7 +4830,7 @@ var Zap = class {
4592
4830
  strategy,
4593
4831
  remainingAccountInfo
4594
4832
  });
4595
- const cleanUpTransaction = new Transaction2();
4833
+ const cleanUpTransaction = new Transaction();
4596
4834
  const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
4597
4835
  cleanUpTransaction.add(closeLedgerTransaction);
4598
4836
  if (cleanUpInstructions.length > 0) {
@@ -4665,7 +4903,7 @@ var Zap = class {
4665
4903
  tokenYProgram
4666
4904
  )
4667
4905
  ]);
4668
- const setupTransaction = new Transaction2();
4906
+ const setupTransaction = new Transaction();
4669
4907
  userTokenXIx && setupTransaction.add(userTokenXIx);
4670
4908
  userTokenYIx && setupTransaction.add(userTokenYIx);
4671
4909
  const strategyParamBuilder = getLiquidityStrategyParameterBuilder(strategy);
@@ -4731,6 +4969,7 @@ var Zap = class {
4731
4969
  const swapQuote = directSwapEstimate.quote;
4732
4970
  if (swapQuote.route === 0 /* Jupiter */) {
4733
4971
  const { transaction: swapTx } = yield buildJupiterSwapTransaction(
4972
+ this.connection,
4734
4973
  user,
4735
4974
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
4736
4975
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
@@ -4775,10 +5014,8 @@ var Zap = class {
4775
5014
  const tokenXAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenXAmount.sub(directSwapEstimate.swapAmount) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenXAmount.add(directSwapEstimate.expectedOutput) : tokenXAmount;
4776
5015
  const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
4777
5016
  const ledgerAddress = deriveLedgerAccount(user);
4778
- const ledgerAccountInfo = yield this.connection.getAccountInfo(
4779
- ledgerAddress
4780
- );
4781
- const ledgerTransaction = new Transaction2();
5017
+ const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
5018
+ const ledgerTransaction = new Transaction();
4782
5019
  if (!ledgerAccountInfo) {
4783
5020
  const initLedgerTx = yield this.initializeLedgerAccount(user, user);
4784
5021
  ledgerTransaction.add(...initLedgerTx.instructions);
@@ -4835,9 +5072,9 @@ var Zap = class {
4835
5072
  zapInTransaction.instructions.unshift(
4836
5073
  // based on 1 tx that consumed 462_610. Add 20% for safety and round up to nearest 100,000
4837
5074
  // 462_610 * 1.2 = 555_132 => 600_000
4838
- ComputeBudgetProgram.setComputeUnitLimit({ units: 6e5 })
5075
+ ComputeBudgetProgram2.setComputeUnitLimit({ units: 6e5 })
4839
5076
  );
4840
- const cleanUpTransaction = new Transaction2();
5077
+ const cleanUpTransaction = new Transaction();
4841
5078
  const closeLedgerTx = yield this.closeLedgerAccount(user, user);
4842
5079
  cleanUpTransaction.add(closeLedgerTx);
4843
5080
  if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
@@ -4848,8 +5085,8 @@ var Zap = class {
4848
5085
  }
4849
5086
  return {
4850
5087
  setupTransaction,
4851
- initBinArrayTransaction: initBinArrayInstructions.length > 0 ? new Transaction2().add(...initBinArrayInstructions) : void 0,
4852
- rebalancePositionTransaction: rebalancePositionInstruction.length > 0 ? new Transaction2().add(...rebalancePositionInstruction) : void 0,
5088
+ initBinArrayTransaction: initBinArrayInstructions.length > 0 ? new Transaction().add(...initBinArrayInstructions) : void 0,
5089
+ rebalancePositionTransaction: rebalancePositionInstruction.length > 0 ? new Transaction().add(...rebalancePositionInstruction) : void 0,
4853
5090
  swapTransaction,
4854
5091
  ledgerTransaction,
4855
5092
  zapInTransaction,
@@ -4979,7 +5216,7 @@ var Zap = class {
4979
5216
  postInstructions.push(unwrapInstructions);
4980
5217
  }
4981
5218
  }
4982
- return yield this.zapOut({
5219
+ const zapOutTransaction = yield this.zapOut({
4983
5220
  userTokenInAccount: inputTokenAccount,
4984
5221
  zapOutParams: {
4985
5222
  percentage: percentageToZapOut,
@@ -4993,6 +5230,22 @@ var Zap = class {
4993
5230
  preInstructions,
4994
5231
  postInstructions
4995
5232
  });
5233
+ const lookupTableAccounts = yield getAddressLookupTableAccounts(
5234
+ this.connection,
5235
+ jupiterSwapResponse.addressLookupTableAddresses
5236
+ );
5237
+ const computeUnitLimit = Math.min(
5238
+ (jupiterSwapResponse.computeUnitLimit || 6e5) + 2e5,
5239
+ 14e5
5240
+ );
5241
+ return buildVersionedTransaction(
5242
+ user,
5243
+ [
5244
+ ComputeBudgetProgram2.setComputeUnitLimit({ units: computeUnitLimit }),
5245
+ ...zapOutTransaction.instructions
5246
+ ],
5247
+ lookupTableAccounts
5248
+ );
4996
5249
  });
4997
5250
  }
4998
5251
  /**
@@ -5214,6 +5467,8 @@ export {
5214
5467
  idl_default as ZapIdl,
5215
5468
  ZapInDammV2PoolSwapRoute,
5216
5469
  buildJupiterSwapTransaction,
5470
+ buildVersionedJupiterSwapTransaction,
5471
+ buildVersionedTransaction,
5217
5472
  convertAccountTypeToNumber,
5218
5473
  convertLamportsToUiAmount,
5219
5474
  convertUiAmountToLamports,
@@ -5227,6 +5482,7 @@ export {
5227
5482
  estimateDlmmIndirectSwap,
5228
5483
  estimateDlmmRebalanceSwap,
5229
5484
  filterOutCloseSplTokenAccountInstructions,
5485
+ getAddressLookupTableAccounts,
5230
5486
  getBinArrayBitmapExtension,
5231
5487
  getBitFromBinArrayIndexInBitmapExtension,
5232
5488
  getDammV2Pool,
@@ -5240,6 +5496,8 @@ export {
5240
5496
  getOrCreateATAInstruction,
5241
5497
  getTokenAccountBalance,
5242
5498
  getTokenProgramFromMint,
5499
+ isSingleSidedA,
5500
+ isSingleSidedB,
5243
5501
  toProgramStrategyType,
5244
5502
  unwrapSOLInstruction,
5245
5503
  wrapSOLInstruction