@meteora-ag/cp-amm-sdk 1.0.0-rc.4 → 1.0.0-rc.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.
package/dist/index.d.mts CHANGED
@@ -5293,6 +5293,22 @@ type AddLiquidityParams = {
5293
5293
  tokenAProgram: PublicKey;
5294
5294
  tokenBProgram: PublicKey;
5295
5295
  };
5296
+ type CreatePositionAndAddLiquidity = {
5297
+ owner: PublicKey;
5298
+ pool: PublicKey;
5299
+ positionNft: PublicKey;
5300
+ liquidityDelta: BN;
5301
+ maxAmountTokenA: BN;
5302
+ maxAmountTokenB: BN;
5303
+ tokenAAmountThreshold: BN;
5304
+ tokenBAmountThreshold: BN;
5305
+ tokenAMint: PublicKey;
5306
+ tokenBMint: PublicKey;
5307
+ tokenAVault: PublicKey;
5308
+ tokenBVault: PublicKey;
5309
+ tokenAProgram: PublicKey;
5310
+ tokenBProgram: PublicKey;
5311
+ };
5296
5312
  type LiquidityDeltaParams = {
5297
5313
  maxAmountTokenA: BN;
5298
5314
  maxAmountTokenB: BN;
@@ -5674,6 +5690,12 @@ declare class CpAmm {
5674
5690
  * @private
5675
5691
  */
5676
5692
  private buildLiquidatePositionInstruction;
5693
+ /**
5694
+ * Builds a instruction to create a position.
5695
+ * @param {CreatePositionParams} params - Parameters for position creation.
5696
+ * @returns Transaction instruction.
5697
+ */
5698
+ private buildCreatePositionInstruction;
5677
5699
  /**
5678
5700
  * Fetches the Config state of the program.
5679
5701
  * @param config - Public key of the config account.
@@ -5776,6 +5798,13 @@ declare class CpAmm {
5776
5798
  reason?: string;
5777
5799
  };
5778
5800
  isPoolExist(pool: PublicKey): Promise<boolean>;
5801
+ /**
5802
+ * Computes the liquidity delta based on the provided token amounts and sqrt price
5803
+ *
5804
+ * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
5805
+ * @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
5806
+ */
5807
+ getLiquidityDelta(params: LiquidityDeltaParams): BN;
5779
5808
  /**
5780
5809
  * Calculates swap quote based on input amount and pool state.
5781
5810
  * @param params - Swap parameters including input amount, pool state, slippage, etc.
@@ -5856,6 +5885,16 @@ declare class CpAmm {
5856
5885
  * @returns Transaction builder.
5857
5886
  */
5858
5887
  addLiquidity(params: AddLiquidityParams): TxBuilder;
5888
+ /**
5889
+ * Creates a new position and add liquidity to position it in a single transaction.
5890
+ * Handles both native SOL and other tokens, automatically wrapping/unwrapping SOL as needed.
5891
+ *
5892
+ * @param {CreatePositionAndAddLiquidity} params - Parameters for creating position and adding liquidity
5893
+ *
5894
+ * @returns {Transaction} A transaction that creates a position and adds liquidity
5895
+ *
5896
+ **/
5897
+ createPositionAndAddLiquidity(params: CreatePositionAndAddLiquidity): TxBuilder;
5859
5898
  /**
5860
5899
  * Builds a transaction to remove liquidity from a position.
5861
5900
  * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
@@ -5998,6 +6037,10 @@ declare function getAllUserPositionNftAccount(connection: Connection, user: Publ
5998
6037
  positionNft: PublicKey;
5999
6038
  positionNftAccount: PublicKey;
6000
6039
  }>>;
6040
+ declare function getAllPositionNftAccountByOwner(connection: Connection, user: PublicKey): Promise<Array<{
6041
+ positionNft: PublicKey;
6042
+ positionNftAccount: PublicKey;
6043
+ }>>;
6001
6044
 
6002
6045
  declare function getBaseFeeNumerator(feeSchedulerMode: FeeSchedulerMode, cliffFeeNumerator: BN, period: BN, reductionFactor: BN): BN;
6003
6046
  /**
@@ -12494,4 +12537,4 @@ var CpAmmIDL = {
12494
12537
  types: types
12495
12538
  };
12496
12539
 
12497
- export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
12540
+ export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionAndAddLiquidity, type CreatePositionParams, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAllPositionNftAccountByOwner, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
package/dist/index.d.ts CHANGED
@@ -5293,6 +5293,22 @@ type AddLiquidityParams = {
5293
5293
  tokenAProgram: PublicKey;
5294
5294
  tokenBProgram: PublicKey;
5295
5295
  };
5296
+ type CreatePositionAndAddLiquidity = {
5297
+ owner: PublicKey;
5298
+ pool: PublicKey;
5299
+ positionNft: PublicKey;
5300
+ liquidityDelta: BN;
5301
+ maxAmountTokenA: BN;
5302
+ maxAmountTokenB: BN;
5303
+ tokenAAmountThreshold: BN;
5304
+ tokenBAmountThreshold: BN;
5305
+ tokenAMint: PublicKey;
5306
+ tokenBMint: PublicKey;
5307
+ tokenAVault: PublicKey;
5308
+ tokenBVault: PublicKey;
5309
+ tokenAProgram: PublicKey;
5310
+ tokenBProgram: PublicKey;
5311
+ };
5296
5312
  type LiquidityDeltaParams = {
5297
5313
  maxAmountTokenA: BN;
5298
5314
  maxAmountTokenB: BN;
@@ -5674,6 +5690,12 @@ declare class CpAmm {
5674
5690
  * @private
5675
5691
  */
5676
5692
  private buildLiquidatePositionInstruction;
5693
+ /**
5694
+ * Builds a instruction to create a position.
5695
+ * @param {CreatePositionParams} params - Parameters for position creation.
5696
+ * @returns Transaction instruction.
5697
+ */
5698
+ private buildCreatePositionInstruction;
5677
5699
  /**
5678
5700
  * Fetches the Config state of the program.
5679
5701
  * @param config - Public key of the config account.
@@ -5776,6 +5798,13 @@ declare class CpAmm {
5776
5798
  reason?: string;
5777
5799
  };
5778
5800
  isPoolExist(pool: PublicKey): Promise<boolean>;
5801
+ /**
5802
+ * Computes the liquidity delta based on the provided token amounts and sqrt price
5803
+ *
5804
+ * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
5805
+ * @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
5806
+ */
5807
+ getLiquidityDelta(params: LiquidityDeltaParams): BN;
5779
5808
  /**
5780
5809
  * Calculates swap quote based on input amount and pool state.
5781
5810
  * @param params - Swap parameters including input amount, pool state, slippage, etc.
@@ -5856,6 +5885,16 @@ declare class CpAmm {
5856
5885
  * @returns Transaction builder.
5857
5886
  */
5858
5887
  addLiquidity(params: AddLiquidityParams): TxBuilder;
5888
+ /**
5889
+ * Creates a new position and add liquidity to position it in a single transaction.
5890
+ * Handles both native SOL and other tokens, automatically wrapping/unwrapping SOL as needed.
5891
+ *
5892
+ * @param {CreatePositionAndAddLiquidity} params - Parameters for creating position and adding liquidity
5893
+ *
5894
+ * @returns {Transaction} A transaction that creates a position and adds liquidity
5895
+ *
5896
+ **/
5897
+ createPositionAndAddLiquidity(params: CreatePositionAndAddLiquidity): TxBuilder;
5859
5898
  /**
5860
5899
  * Builds a transaction to remove liquidity from a position.
5861
5900
  * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
@@ -5998,6 +6037,10 @@ declare function getAllUserPositionNftAccount(connection: Connection, user: Publ
5998
6037
  positionNft: PublicKey;
5999
6038
  positionNftAccount: PublicKey;
6000
6039
  }>>;
6040
+ declare function getAllPositionNftAccountByOwner(connection: Connection, user: PublicKey): Promise<Array<{
6041
+ positionNft: PublicKey;
6042
+ positionNftAccount: PublicKey;
6043
+ }>>;
6001
6044
 
6002
6045
  declare function getBaseFeeNumerator(feeSchedulerMode: FeeSchedulerMode, cliffFeeNumerator: BN, period: BN, reductionFactor: BN): BN;
6003
6046
  /**
@@ -12494,4 +12537,4 @@ var CpAmmIDL = {
12494
12537
  types: types
12495
12538
  };
12496
12539
 
12497
- export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
12540
+ export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, type BuildAddLiquidityParams, type BuildLiquidatePositionInstructionParams, type BuildRemoveAllLiquidityInstructionParams, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeInstructionParams, type ClaimPositionFeeParams, type ClaimRewardParams, type ClosePositionInstructionParams, type ClosePositionParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionAndAddLiquidity, type CreatePositionParams, type DepositQuote, type DynamicFee, type DynamicFeeParams, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetDepositQuoteParams, type GetQuoteParams, type GetWithdrawQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, LIQUIDITY_SCALE, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type MergePositionParams, ONE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparePoolCreationSingleSide, type PreparedPoolCreation, type RefreshVestingParams, type RemoveAllLiquidityAndClosePositionParams, type RemoveAllLiquidityParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, type WithdrawQuote, calculateInitSqrtPrice, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, decimalToQ64, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAllPositionNftAccountByOwner, getAllUserPositionNftAccount, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getAvailableVestingLiquidity, getBaseFeeNumerator, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getOrCreateATAInstruction, getPriceFromSqrtPrice, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSqrtPriceFromPrice, getSwapAmount, getTokenDecimals, getTokenProgram, getTotalLockedLiquidity, getUnClaimReward, isVestingComplete, mulDiv, positionByPoolFilter, pow, q64ToDecimal, unwrapSOLInstruction, vestingByPositionFilter, wrapSOLInstruction };
package/dist/index.js CHANGED
@@ -6616,6 +6616,24 @@ function getAllUserPositionNftAccount(connection, user) {
6616
6616
  return userPositionNftAccount;
6617
6617
  });
6618
6618
  }
6619
+ function getAllPositionNftAccountByOwner(connection, user) {
6620
+ return __async(this, null, function* () {
6621
+ const tokenAccounts = yield connection.getTokenAccountsByOwner(user, {
6622
+ programId: _spltoken.TOKEN_2022_PROGRAM_ID
6623
+ });
6624
+ const userPositionNftAccount = [];
6625
+ for (const { account, pubkey } of tokenAccounts.value) {
6626
+ const tokenAccountData = _spltoken.AccountLayout.decode(account.data);
6627
+ if (tokenAccountData.amount.toString() === "1") {
6628
+ userPositionNftAccount.push({
6629
+ positionNft: tokenAccountData.mint,
6630
+ positionNftAccount: pubkey
6631
+ });
6632
+ }
6633
+ }
6634
+ return userPositionNftAccount;
6635
+ });
6636
+ }
6619
6637
 
6620
6638
  // src/helpers/fee.ts
6621
6639
 
@@ -6748,7 +6766,8 @@ function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
6748
6766
  if (aToB) {
6749
6767
  const product = amount.mul(sqrtPrice);
6750
6768
  const denominator = liquidity.add(product);
6751
- result = mulDiv(liquidity, sqrtPrice, denominator, 0 /* Up */);
6769
+ const numerator = liquidity.mul(sqrtPrice);
6770
+ result = numerator.add(denominator.sub(new (0, _anchor.BN)(1))).div(denominator);
6752
6771
  } else {
6753
6772
  const quotient = amount.shln(SCALE_OFFSET * 2).div(liquidity);
6754
6773
  result = sqrtPrice.add(quotient);
@@ -7485,6 +7504,34 @@ var CpAmm = class {
7485
7504
  return instructions;
7486
7505
  });
7487
7506
  }
7507
+ /**
7508
+ * Builds a instruction to create a position.
7509
+ * @param {CreatePositionParams} params - Parameters for position creation.
7510
+ * @returns Transaction instruction.
7511
+ */
7512
+ buildCreatePositionInstruction(params) {
7513
+ return __async(this, null, function* () {
7514
+ const { owner, payer, pool, positionNft } = params;
7515
+ const position = derivePositionAddress(positionNft);
7516
+ const positionNftAccount = derivePositionNftAccount(positionNft);
7517
+ const ix = yield this._program.methods.createPosition().accountsPartial({
7518
+ owner,
7519
+ positionNftMint: positionNft,
7520
+ poolAuthority: this.poolAuthority,
7521
+ positionNftAccount,
7522
+ payer,
7523
+ pool,
7524
+ position,
7525
+ tokenProgram: _spltoken.TOKEN_2022_PROGRAM_ID,
7526
+ systemProgram: _web3js.SystemProgram.programId
7527
+ }).instruction();
7528
+ return {
7529
+ ix,
7530
+ position,
7531
+ positionNftAccount
7532
+ };
7533
+ });
7534
+ }
7488
7535
  /**
7489
7536
  * Fetches the Config state of the program.
7490
7537
  * @param config - Public key of the config account.
@@ -7588,7 +7635,7 @@ var CpAmm = class {
7588
7635
  */
7589
7636
  getPositionsByUser(user) {
7590
7637
  return __async(this, null, function* () {
7591
- const userPositionAccounts = yield getAllUserPositionNftAccount(
7638
+ const userPositionAccounts = yield getAllPositionNftAccountByOwner(
7592
7639
  this._program.provider.connection,
7593
7640
  user
7594
7641
  );
@@ -7676,6 +7723,32 @@ var CpAmm = class {
7676
7723
  return poolState !== null;
7677
7724
  });
7678
7725
  }
7726
+ /**
7727
+ * Computes the liquidity delta based on the provided token amounts and sqrt price
7728
+ *
7729
+ * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
7730
+ * @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
7731
+ */
7732
+ getLiquidityDelta(params) {
7733
+ const {
7734
+ maxAmountTokenA,
7735
+ maxAmountTokenB,
7736
+ sqrtMaxPrice,
7737
+ sqrtMinPrice,
7738
+ sqrtPrice
7739
+ } = params;
7740
+ const liquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA(
7741
+ maxAmountTokenA,
7742
+ sqrtPrice,
7743
+ sqrtMaxPrice
7744
+ );
7745
+ const liquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB(
7746
+ maxAmountTokenB,
7747
+ sqrtMinPrice,
7748
+ sqrtPrice
7749
+ );
7750
+ return _bnjs.min.call(void 0, liquidityDeltaFromAmountA, liquidityDeltaFromAmountB);
7751
+ }
7679
7752
  /**
7680
7753
  * Calculates swap quote based on input amount and pool state.
7681
7754
  * @param params - Swap parameters including input amount, pool state, slippage, etc.
@@ -8151,20 +8224,8 @@ var CpAmm = class {
8151
8224
  */
8152
8225
  createPosition(params) {
8153
8226
  return __async(this, null, function* () {
8154
- const { owner, payer, pool, positionNft } = params;
8155
- const position = derivePositionAddress(positionNft);
8156
- const positionNftAccount = derivePositionNftAccount(positionNft);
8157
- return yield this._program.methods.createPosition().accountsPartial({
8158
- owner,
8159
- positionNftMint: positionNft,
8160
- poolAuthority: this.poolAuthority,
8161
- positionNftAccount,
8162
- payer,
8163
- pool,
8164
- position,
8165
- tokenProgram: _spltoken.TOKEN_2022_PROGRAM_ID,
8166
- systemProgram: _web3js.SystemProgram.programId
8167
- }).transaction();
8227
+ const { ix } = yield this.buildCreatePositionInstruction(params);
8228
+ return new (0, _web3js.Transaction)().add(ix);
8168
8229
  });
8169
8230
  }
8170
8231
  /**
@@ -8251,6 +8312,104 @@ var CpAmm = class {
8251
8312
  return transaction;
8252
8313
  });
8253
8314
  }
8315
+ /**
8316
+ * Creates a new position and add liquidity to position it in a single transaction.
8317
+ * Handles both native SOL and other tokens, automatically wrapping/unwrapping SOL as needed.
8318
+ *
8319
+ * @param {CreatePositionAndAddLiquidity} params - Parameters for creating position and adding liquidity
8320
+ *
8321
+ * @returns {Transaction} A transaction that creates a position and adds liquidity
8322
+ *
8323
+ **/
8324
+ createPositionAndAddLiquidity(params) {
8325
+ return __async(this, null, function* () {
8326
+ const {
8327
+ owner,
8328
+ pool,
8329
+ positionNft,
8330
+ liquidityDelta,
8331
+ maxAmountTokenA,
8332
+ maxAmountTokenB,
8333
+ tokenAAmountThreshold,
8334
+ tokenBAmountThreshold,
8335
+ tokenAMint,
8336
+ tokenBMint,
8337
+ tokenAVault,
8338
+ tokenBVault,
8339
+ tokenAProgram,
8340
+ tokenBProgram
8341
+ } = params;
8342
+ const {
8343
+ tokenAAta: tokenAAccount,
8344
+ tokenBAta: tokenBAccount,
8345
+ instructions: preInstructions
8346
+ } = yield this.prepareTokenAccounts(
8347
+ owner,
8348
+ tokenAMint,
8349
+ tokenBMint,
8350
+ tokenAProgram,
8351
+ tokenBProgram
8352
+ );
8353
+ if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
8354
+ const wrapSOLIx = wrapSOLInstruction(
8355
+ owner,
8356
+ tokenAAccount,
8357
+ BigInt(maxAmountTokenA.toString())
8358
+ );
8359
+ preInstructions.push(...wrapSOLIx);
8360
+ }
8361
+ if (tokenBMint.equals(_spltoken.NATIVE_MINT)) {
8362
+ const wrapSOLIx = wrapSOLInstruction(
8363
+ owner,
8364
+ tokenBAccount,
8365
+ BigInt(maxAmountTokenB.toString())
8366
+ );
8367
+ preInstructions.push(...wrapSOLIx);
8368
+ }
8369
+ const postInstructions = [];
8370
+ if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
8371
+ _spltoken.NATIVE_MINT.toBase58()
8372
+ )) {
8373
+ const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
8374
+ closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
8375
+ }
8376
+ const {
8377
+ ix: createPositionIx,
8378
+ position,
8379
+ positionNftAccount
8380
+ } = yield this.buildCreatePositionInstruction({
8381
+ owner,
8382
+ payer: owner,
8383
+ pool,
8384
+ positionNft
8385
+ });
8386
+ const addLiquidityInstruction = yield this.buildAddLiquidityInstruction({
8387
+ pool,
8388
+ position,
8389
+ positionNftAccount,
8390
+ owner,
8391
+ tokenAAccount,
8392
+ tokenBAccount,
8393
+ tokenAMint,
8394
+ tokenBMint,
8395
+ tokenAVault,
8396
+ tokenBVault,
8397
+ tokenAProgram,
8398
+ tokenBProgram,
8399
+ liquidityDelta,
8400
+ tokenAAmountThreshold,
8401
+ tokenBAmountThreshold
8402
+ });
8403
+ const transaction = new (0, _web3js.Transaction)();
8404
+ transaction.add(createPositionIx);
8405
+ transaction.add(
8406
+ ...preInstructions.length > 0 ? preInstructions : [],
8407
+ addLiquidityInstruction,
8408
+ ...postInstructions.length > 0 ? postInstructions : []
8409
+ );
8410
+ return transaction;
8411
+ });
8412
+ }
8254
8413
  /**
8255
8414
  * Builds a transaction to remove liquidity from a position.
8256
8415
  * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
@@ -9094,5 +9253,6 @@ var index_default = cp_amm_default;
9094
9253
 
9095
9254
 
9096
9255
 
9097
- exports.ActivationPoint = ActivationPoint; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.CP_AMM_PROGRAM_ID = CP_AMM_PROGRAM_ID; exports.CollectFeeMode = CollectFeeMode; exports.CpAmm = CpAmm; exports.FEE_DENOMINATOR = FEE_DENOMINATOR; exports.FeeSchedulerMode = FeeSchedulerMode; exports.LIQUIDITY_SCALE = LIQUIDITY_SCALE; exports.MAX_CU_BUFFER = MAX_CU_BUFFER; exports.MAX_FEE_NUMERATOR = MAX_FEE_NUMERATOR; exports.MAX_SQRT_PRICE = MAX_SQRT_PRICE; exports.MIN_CU_BUFFER = MIN_CU_BUFFER; exports.MIN_SQRT_PRICE = MIN_SQRT_PRICE; exports.ONE = ONE; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateInitSqrtPrice = calculateInitSqrtPrice; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.decimalToQ64 = decimalToQ64; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.getAllUserPositionNftAccount = getAllUserPositionNftAccount; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getAvailableVestingLiquidity = getAvailableVestingLiquidity; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getMaxAmountWithSlippage = getMaxAmountWithSlippage; exports.getMinAmountWithSlippage = getMinAmountWithSlippage; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getTotalLockedLiquidity = getTotalLockedLiquidity; exports.getUnClaimReward = getUnClaimReward; exports.isVestingComplete = isVestingComplete; exports.mulDiv = mulDiv; exports.positionByPoolFilter = positionByPoolFilter; exports.pow = pow; exports.q64ToDecimal = q64ToDecimal; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.vestingByPositionFilter = vestingByPositionFilter; exports.wrapSOLInstruction = wrapSOLInstruction;
9256
+
9257
+ exports.ActivationPoint = ActivationPoint; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.CP_AMM_PROGRAM_ID = CP_AMM_PROGRAM_ID; exports.CollectFeeMode = CollectFeeMode; exports.CpAmm = CpAmm; exports.FEE_DENOMINATOR = FEE_DENOMINATOR; exports.FeeSchedulerMode = FeeSchedulerMode; exports.LIQUIDITY_SCALE = LIQUIDITY_SCALE; exports.MAX_CU_BUFFER = MAX_CU_BUFFER; exports.MAX_FEE_NUMERATOR = MAX_FEE_NUMERATOR; exports.MAX_SQRT_PRICE = MAX_SQRT_PRICE; exports.MIN_CU_BUFFER = MIN_CU_BUFFER; exports.MIN_SQRT_PRICE = MIN_SQRT_PRICE; exports.ONE = ONE; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateInitSqrtPrice = calculateInitSqrtPrice; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.decimalToQ64 = decimalToQ64; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.getAllPositionNftAccountByOwner = getAllPositionNftAccountByOwner; exports.getAllUserPositionNftAccount = getAllUserPositionNftAccount; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getAvailableVestingLiquidity = getAvailableVestingLiquidity; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getMaxAmountWithSlippage = getMaxAmountWithSlippage; exports.getMinAmountWithSlippage = getMinAmountWithSlippage; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getTotalLockedLiquidity = getTotalLockedLiquidity; exports.getUnClaimReward = getUnClaimReward; exports.isVestingComplete = isVestingComplete; exports.mulDiv = mulDiv; exports.positionByPoolFilter = positionByPoolFilter; exports.pow = pow; exports.q64ToDecimal = q64ToDecimal; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.vestingByPositionFilter = vestingByPositionFilter; exports.wrapSOLInstruction = wrapSOLInstruction;
9098
9258
  //# sourceMappingURL=index.js.map