@meteora-ag/cp-amm-sdk 1.0.1-rc.11 → 1.0.1-rc.13

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
@@ -1,5 +1,5 @@
1
1
  import { Program, IdlAccounts, BN, IdlTypes } from '@coral-xyz/anchor';
2
- import { PublicKey, Transaction, Connection, TransactionInstruction, AddressLookupTableAccount, Commitment } from '@solana/web3.js';
2
+ import { PublicKey, Transaction, Connection, TransactionInstruction, AddressLookupTableAccount, Commitment, GetProgramAccountsFilter } from '@solana/web3.js';
3
3
 
4
4
  /**
5
5
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -6177,6 +6177,10 @@ declare enum ActivationType {
6177
6177
  Slot = 0,
6178
6178
  Timestamp = 1
6179
6179
  }
6180
+ type FeeMode = {
6181
+ feeOnInput: boolean;
6182
+ feesOnTokenA: boolean;
6183
+ };
6180
6184
  type PoolState = IdlAccounts<CpAmm$1>["pool"];
6181
6185
  type PositionState = IdlAccounts<CpAmm$1>["position"];
6182
6186
  type VestingState = IdlAccounts<CpAmm$1>["vesting"];
@@ -6227,8 +6231,6 @@ type InitializeCustomizeablePoolParams = {
6227
6231
  type PreparePoolCreationParams = {
6228
6232
  tokenAAmount: BN;
6229
6233
  tokenBAmount: BN;
6230
- tokenADecimal: number;
6231
- tokenBDecimal: number;
6232
6234
  };
6233
6235
  type PreparedPoolCreation = {
6234
6236
  sqrtPriceQ64: BN;
@@ -6243,8 +6245,6 @@ type CreatePoolParams = {
6243
6245
  tokenBMint: PublicKey;
6244
6246
  tokenAAmount: BN;
6245
6247
  tokenBAmount: BN;
6246
- tokenADecimal: number;
6247
- tokenBDecimal: number;
6248
6248
  activationPoint: BN | null;
6249
6249
  tokenAProgram: PublicKey;
6250
6250
  tokenBProgram: PublicKey;
@@ -6391,44 +6391,90 @@ type PermanentLockParams = {
6391
6391
  unlockedLiquidity: BN;
6392
6392
  };
6393
6393
 
6394
+ /**
6395
+ * CpAmm SDK class to interact with the Dynamic CP-AMM
6396
+ */
6394
6397
  declare class CpAmm {
6395
6398
  _program: AmmProgram;
6396
6399
  constructor(connection: Connection);
6400
+ /**
6401
+ * Returns the Anchor program instance.
6402
+ * @returns The AmmProgram instance.
6403
+ */
6397
6404
  getProgram(): AmmProgram;
6398
6405
  /**
6399
- Prepares token ordering, calculates the initial sqrtPrice in Q64 format,
6400
- @private
6401
- @async
6402
- @param {PublicKey} tokenX - One token mint address in the pair.
6403
- @param {PublicKey} tokenY - The other token mint address in the pair.
6404
- @param {Decimal} initialPrice - The initial price ratio of tokenX/tokenY (will be inverted if needed).
6405
- @param {Decimal} liquidity - The initial liquidity value.
6406
- @returns {PreparedPoolCreation} Object containing the ordered token mints and their Q64 price/liquidity values.
6407
- */
6406
+ * Prepares parameters required for pool creation, including initial sqrt price and liquidity.
6407
+ * @private
6408
+ * @param {PreparePoolCreationParams} params - Initial token amounts for pool creation.
6409
+ * @returns init sqrt price and liquidity in Q64 format.
6410
+ */
6408
6411
  private preparePoolCreationParams;
6412
+ /**
6413
+ * Fetches the Config state of the program.
6414
+ * @param config - Public key of the config account.
6415
+ * @returns Parsed ConfigState.
6416
+ */
6409
6417
  fetchConfigState(config: PublicKey): Promise<ConfigState>;
6418
+ /**
6419
+ * Fetches the Pool state.
6420
+ * @param pool - Public key of the pool.
6421
+ * @returns Parsed PoolState.
6422
+ */
6410
6423
  fetchPoolState(pool: PublicKey): Promise<PoolState>;
6424
+ /**
6425
+ * Fetches the Position state.
6426
+ * @param position - Public key of the position.
6427
+ * @returns Parsed PositionState.
6428
+ */
6411
6429
  fetchPositionState(position: PublicKey): Promise<PositionState>;
6430
+ /**
6431
+ * Retrieves all config accounts.
6432
+ * @returns Array of config public keys and their states.
6433
+ */
6412
6434
  getAllConfigs(): Promise<Array<{
6413
6435
  publicKey: PublicKey;
6414
6436
  account: ConfigState;
6415
6437
  }>>;
6438
+ /**
6439
+ * Retrieves all pool accounts.
6440
+ * @returns Array of pool public keys and their states.
6441
+ */
6416
6442
  getAllPools(): Promise<Array<{
6417
6443
  publicKey: PublicKey;
6418
6444
  account: PoolState;
6419
6445
  }>>;
6446
+ /**
6447
+ * Retrieves all position accounts.
6448
+ * @returns Array of position public keys and their states.
6449
+ */
6420
6450
  getAllPositions(): Promise<Array<{
6421
6451
  publicKey: PublicKey;
6422
6452
  account: PositionState;
6423
6453
  }>>;
6454
+ /**
6455
+ * Gets all positions of a user for a specific pool.
6456
+ * @param pool - Public key of the pool.
6457
+ * @param user - Public key of the user.
6458
+ * @returns List of user positions for the pool.
6459
+ */
6424
6460
  getUserPositionByPool(pool: PublicKey, user: PublicKey): Promise<Array<{
6425
6461
  publicKey: PublicKey;
6426
6462
  account: PositionState;
6427
6463
  }>>;
6464
+ /**
6465
+ * Gets all positions of a user across all pools.
6466
+ * @param user - Public key of the user.
6467
+ * @returns Array of user positions.
6468
+ */
6428
6469
  getPositionsByUser(user: PublicKey): Promise<Array<{
6429
6470
  publicKey: PublicKey;
6430
6471
  account: PositionState;
6431
6472
  }>>;
6473
+ /**
6474
+ * Calculates swap quote based on input amount and pool state.
6475
+ * @param params - Swap parameters including input amount, pool state, slippage, etc.
6476
+ * @returns Swap quote including expected output amount, fee, and price impact.
6477
+ */
6432
6478
  getQuote(params: GetQuoteParams): Promise<{
6433
6479
  swapInAmount: BN;
6434
6480
  swapOutAmount: BN;
@@ -6439,35 +6485,109 @@ declare class CpAmm {
6439
6485
  /**
6440
6486
  * Computes the liquidity delta based on the provided token amounts and pool state.
6441
6487
  *
6442
- * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation, including:
6443
- * - tokenX: The mint address of token X.
6444
- * - tokenY: The mint address of token Y.
6445
- * - maxAmountX: The maximum amount of token X available.
6446
- * - maxAmountY: The maximum amount of token Y available.
6447
- * - pool: The address of the liquidity pool.
6448
- *
6488
+ * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
6449
6489
  * @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
6450
6490
  */
6451
6491
  getLiquidityDelta(params: LiquidityDeltaParams): Promise<BN>;
6492
+ /**
6493
+ * Builds a transaction to create a permissionless pool.
6494
+ * @param params - Parameters for pool creation.
6495
+ * @returns Transaction builder.
6496
+ */
6452
6497
  createPool(params: CreatePoolParams): TxBuilder;
6498
+ /**
6499
+ * Builds a transaction to create a customizable pool.
6500
+ * @param params - Parameters for customizable pool creation.
6501
+ * @returns Transaction and related addresses.
6502
+ */
6453
6503
  createCustomPool(params: InitializeCustomizeablePoolParams): Promise<{
6454
6504
  tx: Transaction;
6455
6505
  pool: PublicKey;
6456
6506
  position: PublicKey;
6457
6507
  }>;
6508
+ /**
6509
+ * Builds a transaction to create a position.
6510
+ * @param {CreatePositionParams} params - Parameters for position creation.
6511
+ * @returns Transaction builder.
6512
+ */
6458
6513
  createPosition(params: CreatePositionParams): TxBuilder;
6514
+ /**
6515
+ * Builds a transaction to add liquidity to an existing position.
6516
+ * @param {AddLiquidityParams} params - Parameters for adding liquidity.
6517
+ * @returns Transaction builder.
6518
+ */
6459
6519
  addLiquidity(params: AddLiquidityParams): TxBuilder;
6520
+ /**
6521
+ * Builds a transaction to remove liquidity from a position.
6522
+ * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
6523
+ * @returns Transaction builder.
6524
+ */
6460
6525
  removeLiquidity(params: RemoveLiquidityParams): TxBuilder;
6526
+ /**
6527
+ * Builds a transaction to perform a swap in the pool.
6528
+ * @param {SwapParams} params - Parameters for swapping tokens.
6529
+ * @returns Transaction builder.
6530
+ */
6461
6531
  swap(params: SwapParams): TxBuilder;
6532
+ /**
6533
+ * Builds a transaction to lock a position with vesting schedule.
6534
+ * @param {LockPositionParams} params - Locking parameters.
6535
+ * @returns Transaction builder.
6536
+ */
6462
6537
  lockPosition(params: LockPositionParams): TxBuilder;
6538
+ /**
6539
+ * Builds a transaction to permanently lock a position.
6540
+ * @param {PermanentLockParams} params - Parameters for permanent locking.
6541
+ * @returns Transaction builder.
6542
+ */
6463
6543
  permanentLockPosition(params: PermanentLockParams): TxBuilder;
6544
+ /**
6545
+ * Builds a transaction to refresh vesting status of a position.
6546
+ * @param {RefreshVestingParams} params - Refresh vesting parameters.
6547
+ * @returns Transaction builder.
6548
+ */
6464
6549
  refreshVesting(params: RefreshVestingParams): TxBuilder;
6550
+ /**
6551
+ * Builds a transaction to claim position fee rewards.
6552
+ * @param {ClaimPositionFeeParams} params - Parameters for claiming position fee.
6553
+ * @returns Transaction builder.
6554
+ */
6465
6555
  claimPositionFee(params: ClaimPositionFeeParams): TxBuilder;
6556
+ /**
6557
+ * Builds a transaction to update reward duration.
6558
+ * @param {UpdateRewardDurationParams} params - Parameters including pool and new duration.
6559
+ * @returns Transaction builder.
6560
+ */
6466
6561
  updateRewardDuration(params: UpdateRewardDurationParams): TxBuilder;
6562
+ /**
6563
+ * Builds a transaction to update reward funder address.
6564
+ * @param {UpdateRewardFunderParams} params - Parameters including pool and new funder address.
6565
+ * @returns Transaction builder.
6566
+ */
6467
6567
  updateRewardFunder(params: UpdateRewardFunderParams): TxBuilder;
6568
+ /**
6569
+ * Builds a transaction to fund rewards in a pool.
6570
+ * @param {FundRewardParams} params - Funding parameters.
6571
+ * @returns Transaction builder.
6572
+ */
6468
6573
  fundReward(params: FundRewardParams): TxBuilder;
6574
+ /**
6575
+ * Builds a transaction to withdraw ineligible rewards from a pool.
6576
+ * @param {WithdrawIneligibleRewardParams} params - Parameters for withdrawal.
6577
+ * @returns Transaction builder.
6578
+ */
6469
6579
  withdrawIneligibleReward(params: WithdrawIneligibleRewardParams): TxBuilder;
6580
+ /**
6581
+ * Builds a transaction to claim partner fee rewards.
6582
+ * @param {ClaimPartnerFeeParams} params - Claim parameters including amounts and partner address.
6583
+ * @returns Transaction builder.
6584
+ */
6470
6585
  claimPartnerFee(params: ClaimPartnerFeeParams): TxBuilder;
6586
+ /**
6587
+ * Builds a transaction to claim reward from a position.
6588
+ * @param {ClaimRewardParams} params - Parameters for claiming reward.
6589
+ * @returns Transaction builder.
6590
+ */
6471
6591
  claimReward(params: ClaimRewardParams): TxBuilder;
6472
6592
  }
6473
6593
 
@@ -6512,14 +6632,26 @@ declare function getFeeNumerator(currentPoint: number, activationPoint: BN, numb
6512
6632
  binStep: BN;
6513
6633
  variableFeeControl: BN;
6514
6634
  }): BN;
6635
+ /**
6636
+ *
6637
+ * Calculates the output amount and fees for a swap operation in a concentrated liquidity pool.
6638
+ *
6639
+ * @param inAmount - The input amount of tokens the user is swapping
6640
+ * @param sqrtPrice - The current square root price of the pool
6641
+ * @param liquidity - The current liquidity available in the pool
6642
+ * @param tradeFeeNumerator - The fee numerator used to calculate trading fees
6643
+ * @param aToB - Direction of the swap: true for token A to token B, false for token B to token A
6644
+ * @param collectFeeMode - Determines how fees are collected (0: both tokens, 1: only token B)
6645
+ * @returns Object containing the actual output amount after fees and the total fee amount
6646
+ */
6647
+ declare function getSwapAmount(inAmount: BN, sqrtPrice: BN, liquidity: BN, tradeFeeNumerator: BN, aToB: boolean, collectFeeMode: number): {
6648
+ actualOutAmount: BN;
6649
+ totalFee: BN;
6650
+ };
6515
6651
 
6516
6652
  declare function getNextSqrtPrice(amount: BN, sqrtPrice: BN, liquidity: BN, aToB: boolean): BN;
6517
6653
  declare function getDeltaAmountA(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, rounding: Rounding): BN;
6518
6654
  declare function getDeltaAmountB(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, rounding: Rounding): BN;
6519
- declare function calculateSwap(inAmount: BN, sqrtPrice: BN, liquidity: BN, tradeFeeNumerator: BN, aToB: boolean, collectFeeMode: number): {
6520
- amountOutExcludedlpFee: BN;
6521
- lpFee: BN;
6522
- };
6523
6655
  declare function getLiquidityDeltaFromAmountA(maxAmountA: BN, lowerSqrtPrice: BN, // current sqrt price
6524
6656
  upperSqrtPrice: BN): BN;
6525
6657
  declare function getLiquidityDeltaFromAmountB(maxAmountB: BN, lowerSqrtPrice: BN, // min sqrt price
@@ -6548,6 +6680,39 @@ declare const getEstimatedComputeUnitUsageWithBuffer: (connection: Connection, i
6548
6680
  */
6549
6681
  declare const getEstimatedComputeUnitIxWithBuffer: (connection: Connection, instructions: TransactionInstruction[], feePayer: PublicKey, buffer?: number) => Promise<TransactionInstruction>;
6550
6682
 
6683
+ /**
6684
+ * It takes an amount and a slippage rate, and returns the maximum amount that can be received with
6685
+ * that slippage rate
6686
+ * @param {BN} amount - The amount of tokens you want to buy.
6687
+ * @param {number} rate - The maximum percentage of slippage you're willing to accept. (Max to 2 decimal place)
6688
+ * @returns The maximum amount of tokens that can be bought with the given amount of ETH, given the
6689
+ * slippage rate.
6690
+ */
6691
+ declare const getMaxAmountWithSlippage: (amount: BN, rate: number) => BN;
6692
+ /**
6693
+ * It takes an amount and a slippage rate, and returns the minimum amount that will be received after
6694
+ * slippage
6695
+ * @param {BN} amount - The amount of tokens you want to sell.
6696
+ * @param {number} rate - The percentage of slippage you're willing to accept. (Max to 2 decimal place)
6697
+ * @returns The minimum amount that can be received after slippage is applied.
6698
+ */
6699
+ declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
6700
+ /**
6701
+ * Calculate price impact as a percentage
6702
+ * @param actualAmount Amount after slippage in token units
6703
+ * @param idealAmount Theoretical amount without slippage in token units
6704
+ * @returns Price impact as a percentage (e.g., 1.5 means 1.5%)
6705
+ */
6706
+ declare const getPriceImpact: (actualAmount: BN, idealAmount: BN) => number;
6707
+ declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => BN;
6708
+ declare const getUnClaimReward: (positionState: PositionState) => {
6709
+ feeTokenA: BN;
6710
+ feeTokenB: BN;
6711
+ rewards: BN[];
6712
+ };
6713
+
6714
+ declare const positionByPoolFilter: (pool: PublicKey) => GetProgramAccountsFilter;
6715
+
6551
6716
  var address = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
6552
6717
  var metadata = {
6553
6718
  name: "cp_amm",
@@ -12707,4 +12872,4 @@ var CpAmmIDL = {
12707
12872
  types: types
12708
12873
  };
12709
12874
 
12710
- export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, calculateSwap, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getSecondKey, getSimulationComputeUnits, getTokenDecimals, getTokenProgram, unwrapSOLInstruction, wrapSOLInstruction };
12875
+ export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, positionByPoolFilter, unwrapSOLInstruction, wrapSOLInstruction };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Program, IdlAccounts, BN, IdlTypes } from '@coral-xyz/anchor';
2
- import { PublicKey, Transaction, Connection, TransactionInstruction, AddressLookupTableAccount, Commitment } from '@solana/web3.js';
2
+ import { PublicKey, Transaction, Connection, TransactionInstruction, AddressLookupTableAccount, Commitment, GetProgramAccountsFilter } from '@solana/web3.js';
3
3
 
4
4
  /**
5
5
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -6177,6 +6177,10 @@ declare enum ActivationType {
6177
6177
  Slot = 0,
6178
6178
  Timestamp = 1
6179
6179
  }
6180
+ type FeeMode = {
6181
+ feeOnInput: boolean;
6182
+ feesOnTokenA: boolean;
6183
+ };
6180
6184
  type PoolState = IdlAccounts<CpAmm$1>["pool"];
6181
6185
  type PositionState = IdlAccounts<CpAmm$1>["position"];
6182
6186
  type VestingState = IdlAccounts<CpAmm$1>["vesting"];
@@ -6227,8 +6231,6 @@ type InitializeCustomizeablePoolParams = {
6227
6231
  type PreparePoolCreationParams = {
6228
6232
  tokenAAmount: BN;
6229
6233
  tokenBAmount: BN;
6230
- tokenADecimal: number;
6231
- tokenBDecimal: number;
6232
6234
  };
6233
6235
  type PreparedPoolCreation = {
6234
6236
  sqrtPriceQ64: BN;
@@ -6243,8 +6245,6 @@ type CreatePoolParams = {
6243
6245
  tokenBMint: PublicKey;
6244
6246
  tokenAAmount: BN;
6245
6247
  tokenBAmount: BN;
6246
- tokenADecimal: number;
6247
- tokenBDecimal: number;
6248
6248
  activationPoint: BN | null;
6249
6249
  tokenAProgram: PublicKey;
6250
6250
  tokenBProgram: PublicKey;
@@ -6391,44 +6391,90 @@ type PermanentLockParams = {
6391
6391
  unlockedLiquidity: BN;
6392
6392
  };
6393
6393
 
6394
+ /**
6395
+ * CpAmm SDK class to interact with the Dynamic CP-AMM
6396
+ */
6394
6397
  declare class CpAmm {
6395
6398
  _program: AmmProgram;
6396
6399
  constructor(connection: Connection);
6400
+ /**
6401
+ * Returns the Anchor program instance.
6402
+ * @returns The AmmProgram instance.
6403
+ */
6397
6404
  getProgram(): AmmProgram;
6398
6405
  /**
6399
- Prepares token ordering, calculates the initial sqrtPrice in Q64 format,
6400
- @private
6401
- @async
6402
- @param {PublicKey} tokenX - One token mint address in the pair.
6403
- @param {PublicKey} tokenY - The other token mint address in the pair.
6404
- @param {Decimal} initialPrice - The initial price ratio of tokenX/tokenY (will be inverted if needed).
6405
- @param {Decimal} liquidity - The initial liquidity value.
6406
- @returns {PreparedPoolCreation} Object containing the ordered token mints and their Q64 price/liquidity values.
6407
- */
6406
+ * Prepares parameters required for pool creation, including initial sqrt price and liquidity.
6407
+ * @private
6408
+ * @param {PreparePoolCreationParams} params - Initial token amounts for pool creation.
6409
+ * @returns init sqrt price and liquidity in Q64 format.
6410
+ */
6408
6411
  private preparePoolCreationParams;
6412
+ /**
6413
+ * Fetches the Config state of the program.
6414
+ * @param config - Public key of the config account.
6415
+ * @returns Parsed ConfigState.
6416
+ */
6409
6417
  fetchConfigState(config: PublicKey): Promise<ConfigState>;
6418
+ /**
6419
+ * Fetches the Pool state.
6420
+ * @param pool - Public key of the pool.
6421
+ * @returns Parsed PoolState.
6422
+ */
6410
6423
  fetchPoolState(pool: PublicKey): Promise<PoolState>;
6424
+ /**
6425
+ * Fetches the Position state.
6426
+ * @param position - Public key of the position.
6427
+ * @returns Parsed PositionState.
6428
+ */
6411
6429
  fetchPositionState(position: PublicKey): Promise<PositionState>;
6430
+ /**
6431
+ * Retrieves all config accounts.
6432
+ * @returns Array of config public keys and their states.
6433
+ */
6412
6434
  getAllConfigs(): Promise<Array<{
6413
6435
  publicKey: PublicKey;
6414
6436
  account: ConfigState;
6415
6437
  }>>;
6438
+ /**
6439
+ * Retrieves all pool accounts.
6440
+ * @returns Array of pool public keys and their states.
6441
+ */
6416
6442
  getAllPools(): Promise<Array<{
6417
6443
  publicKey: PublicKey;
6418
6444
  account: PoolState;
6419
6445
  }>>;
6446
+ /**
6447
+ * Retrieves all position accounts.
6448
+ * @returns Array of position public keys and their states.
6449
+ */
6420
6450
  getAllPositions(): Promise<Array<{
6421
6451
  publicKey: PublicKey;
6422
6452
  account: PositionState;
6423
6453
  }>>;
6454
+ /**
6455
+ * Gets all positions of a user for a specific pool.
6456
+ * @param pool - Public key of the pool.
6457
+ * @param user - Public key of the user.
6458
+ * @returns List of user positions for the pool.
6459
+ */
6424
6460
  getUserPositionByPool(pool: PublicKey, user: PublicKey): Promise<Array<{
6425
6461
  publicKey: PublicKey;
6426
6462
  account: PositionState;
6427
6463
  }>>;
6464
+ /**
6465
+ * Gets all positions of a user across all pools.
6466
+ * @param user - Public key of the user.
6467
+ * @returns Array of user positions.
6468
+ */
6428
6469
  getPositionsByUser(user: PublicKey): Promise<Array<{
6429
6470
  publicKey: PublicKey;
6430
6471
  account: PositionState;
6431
6472
  }>>;
6473
+ /**
6474
+ * Calculates swap quote based on input amount and pool state.
6475
+ * @param params - Swap parameters including input amount, pool state, slippage, etc.
6476
+ * @returns Swap quote including expected output amount, fee, and price impact.
6477
+ */
6432
6478
  getQuote(params: GetQuoteParams): Promise<{
6433
6479
  swapInAmount: BN;
6434
6480
  swapOutAmount: BN;
@@ -6439,35 +6485,109 @@ declare class CpAmm {
6439
6485
  /**
6440
6486
  * Computes the liquidity delta based on the provided token amounts and pool state.
6441
6487
  *
6442
- * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation, including:
6443
- * - tokenX: The mint address of token X.
6444
- * - tokenY: The mint address of token Y.
6445
- * - maxAmountX: The maximum amount of token X available.
6446
- * - maxAmountY: The maximum amount of token Y available.
6447
- * - pool: The address of the liquidity pool.
6448
- *
6488
+ * @param {LiquidityDeltaParams} params - The parameters for liquidity calculation
6449
6489
  * @returns {Promise<BN>} - The computed liquidity delta in Q64 value.
6450
6490
  */
6451
6491
  getLiquidityDelta(params: LiquidityDeltaParams): Promise<BN>;
6492
+ /**
6493
+ * Builds a transaction to create a permissionless pool.
6494
+ * @param params - Parameters for pool creation.
6495
+ * @returns Transaction builder.
6496
+ */
6452
6497
  createPool(params: CreatePoolParams): TxBuilder;
6498
+ /**
6499
+ * Builds a transaction to create a customizable pool.
6500
+ * @param params - Parameters for customizable pool creation.
6501
+ * @returns Transaction and related addresses.
6502
+ */
6453
6503
  createCustomPool(params: InitializeCustomizeablePoolParams): Promise<{
6454
6504
  tx: Transaction;
6455
6505
  pool: PublicKey;
6456
6506
  position: PublicKey;
6457
6507
  }>;
6508
+ /**
6509
+ * Builds a transaction to create a position.
6510
+ * @param {CreatePositionParams} params - Parameters for position creation.
6511
+ * @returns Transaction builder.
6512
+ */
6458
6513
  createPosition(params: CreatePositionParams): TxBuilder;
6514
+ /**
6515
+ * Builds a transaction to add liquidity to an existing position.
6516
+ * @param {AddLiquidityParams} params - Parameters for adding liquidity.
6517
+ * @returns Transaction builder.
6518
+ */
6459
6519
  addLiquidity(params: AddLiquidityParams): TxBuilder;
6520
+ /**
6521
+ * Builds a transaction to remove liquidity from a position.
6522
+ * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
6523
+ * @returns Transaction builder.
6524
+ */
6460
6525
  removeLiquidity(params: RemoveLiquidityParams): TxBuilder;
6526
+ /**
6527
+ * Builds a transaction to perform a swap in the pool.
6528
+ * @param {SwapParams} params - Parameters for swapping tokens.
6529
+ * @returns Transaction builder.
6530
+ */
6461
6531
  swap(params: SwapParams): TxBuilder;
6532
+ /**
6533
+ * Builds a transaction to lock a position with vesting schedule.
6534
+ * @param {LockPositionParams} params - Locking parameters.
6535
+ * @returns Transaction builder.
6536
+ */
6462
6537
  lockPosition(params: LockPositionParams): TxBuilder;
6538
+ /**
6539
+ * Builds a transaction to permanently lock a position.
6540
+ * @param {PermanentLockParams} params - Parameters for permanent locking.
6541
+ * @returns Transaction builder.
6542
+ */
6463
6543
  permanentLockPosition(params: PermanentLockParams): TxBuilder;
6544
+ /**
6545
+ * Builds a transaction to refresh vesting status of a position.
6546
+ * @param {RefreshVestingParams} params - Refresh vesting parameters.
6547
+ * @returns Transaction builder.
6548
+ */
6464
6549
  refreshVesting(params: RefreshVestingParams): TxBuilder;
6550
+ /**
6551
+ * Builds a transaction to claim position fee rewards.
6552
+ * @param {ClaimPositionFeeParams} params - Parameters for claiming position fee.
6553
+ * @returns Transaction builder.
6554
+ */
6465
6555
  claimPositionFee(params: ClaimPositionFeeParams): TxBuilder;
6556
+ /**
6557
+ * Builds a transaction to update reward duration.
6558
+ * @param {UpdateRewardDurationParams} params - Parameters including pool and new duration.
6559
+ * @returns Transaction builder.
6560
+ */
6466
6561
  updateRewardDuration(params: UpdateRewardDurationParams): TxBuilder;
6562
+ /**
6563
+ * Builds a transaction to update reward funder address.
6564
+ * @param {UpdateRewardFunderParams} params - Parameters including pool and new funder address.
6565
+ * @returns Transaction builder.
6566
+ */
6467
6567
  updateRewardFunder(params: UpdateRewardFunderParams): TxBuilder;
6568
+ /**
6569
+ * Builds a transaction to fund rewards in a pool.
6570
+ * @param {FundRewardParams} params - Funding parameters.
6571
+ * @returns Transaction builder.
6572
+ */
6468
6573
  fundReward(params: FundRewardParams): TxBuilder;
6574
+ /**
6575
+ * Builds a transaction to withdraw ineligible rewards from a pool.
6576
+ * @param {WithdrawIneligibleRewardParams} params - Parameters for withdrawal.
6577
+ * @returns Transaction builder.
6578
+ */
6469
6579
  withdrawIneligibleReward(params: WithdrawIneligibleRewardParams): TxBuilder;
6580
+ /**
6581
+ * Builds a transaction to claim partner fee rewards.
6582
+ * @param {ClaimPartnerFeeParams} params - Claim parameters including amounts and partner address.
6583
+ * @returns Transaction builder.
6584
+ */
6470
6585
  claimPartnerFee(params: ClaimPartnerFeeParams): TxBuilder;
6586
+ /**
6587
+ * Builds a transaction to claim reward from a position.
6588
+ * @param {ClaimRewardParams} params - Parameters for claiming reward.
6589
+ * @returns Transaction builder.
6590
+ */
6471
6591
  claimReward(params: ClaimRewardParams): TxBuilder;
6472
6592
  }
6473
6593
 
@@ -6512,14 +6632,26 @@ declare function getFeeNumerator(currentPoint: number, activationPoint: BN, numb
6512
6632
  binStep: BN;
6513
6633
  variableFeeControl: BN;
6514
6634
  }): BN;
6635
+ /**
6636
+ *
6637
+ * Calculates the output amount and fees for a swap operation in a concentrated liquidity pool.
6638
+ *
6639
+ * @param inAmount - The input amount of tokens the user is swapping
6640
+ * @param sqrtPrice - The current square root price of the pool
6641
+ * @param liquidity - The current liquidity available in the pool
6642
+ * @param tradeFeeNumerator - The fee numerator used to calculate trading fees
6643
+ * @param aToB - Direction of the swap: true for token A to token B, false for token B to token A
6644
+ * @param collectFeeMode - Determines how fees are collected (0: both tokens, 1: only token B)
6645
+ * @returns Object containing the actual output amount after fees and the total fee amount
6646
+ */
6647
+ declare function getSwapAmount(inAmount: BN, sqrtPrice: BN, liquidity: BN, tradeFeeNumerator: BN, aToB: boolean, collectFeeMode: number): {
6648
+ actualOutAmount: BN;
6649
+ totalFee: BN;
6650
+ };
6515
6651
 
6516
6652
  declare function getNextSqrtPrice(amount: BN, sqrtPrice: BN, liquidity: BN, aToB: boolean): BN;
6517
6653
  declare function getDeltaAmountA(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, rounding: Rounding): BN;
6518
6654
  declare function getDeltaAmountB(lowerSqrtPrice: BN, upperSqrtPrice: BN, liquidity: BN, rounding: Rounding): BN;
6519
- declare function calculateSwap(inAmount: BN, sqrtPrice: BN, liquidity: BN, tradeFeeNumerator: BN, aToB: boolean, collectFeeMode: number): {
6520
- amountOutExcludedlpFee: BN;
6521
- lpFee: BN;
6522
- };
6523
6655
  declare function getLiquidityDeltaFromAmountA(maxAmountA: BN, lowerSqrtPrice: BN, // current sqrt price
6524
6656
  upperSqrtPrice: BN): BN;
6525
6657
  declare function getLiquidityDeltaFromAmountB(maxAmountB: BN, lowerSqrtPrice: BN, // min sqrt price
@@ -6548,6 +6680,39 @@ declare const getEstimatedComputeUnitUsageWithBuffer: (connection: Connection, i
6548
6680
  */
6549
6681
  declare const getEstimatedComputeUnitIxWithBuffer: (connection: Connection, instructions: TransactionInstruction[], feePayer: PublicKey, buffer?: number) => Promise<TransactionInstruction>;
6550
6682
 
6683
+ /**
6684
+ * It takes an amount and a slippage rate, and returns the maximum amount that can be received with
6685
+ * that slippage rate
6686
+ * @param {BN} amount - The amount of tokens you want to buy.
6687
+ * @param {number} rate - The maximum percentage of slippage you're willing to accept. (Max to 2 decimal place)
6688
+ * @returns The maximum amount of tokens that can be bought with the given amount of ETH, given the
6689
+ * slippage rate.
6690
+ */
6691
+ declare const getMaxAmountWithSlippage: (amount: BN, rate: number) => BN;
6692
+ /**
6693
+ * It takes an amount and a slippage rate, and returns the minimum amount that will be received after
6694
+ * slippage
6695
+ * @param {BN} amount - The amount of tokens you want to sell.
6696
+ * @param {number} rate - The percentage of slippage you're willing to accept. (Max to 2 decimal place)
6697
+ * @returns The minimum amount that can be received after slippage is applied.
6698
+ */
6699
+ declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
6700
+ /**
6701
+ * Calculate price impact as a percentage
6702
+ * @param actualAmount Amount after slippage in token units
6703
+ * @param idealAmount Theoretical amount without slippage in token units
6704
+ * @returns Price impact as a percentage (e.g., 1.5 means 1.5%)
6705
+ */
6706
+ declare const getPriceImpact: (actualAmount: BN, idealAmount: BN) => number;
6707
+ declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => BN;
6708
+ declare const getUnClaimReward: (positionState: PositionState) => {
6709
+ feeTokenA: BN;
6710
+ feeTokenB: BN;
6711
+ rewards: BN[];
6712
+ };
6713
+
6714
+ declare const positionByPoolFilter: (pool: PublicKey) => GetProgramAccountsFilter;
6715
+
6551
6716
  var address = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
6552
6717
  var metadata = {
6553
6718
  name: "cp_amm",
@@ -12707,4 +12872,4 @@ var CpAmmIDL = {
12707
12872
  types: types
12708
12873
  };
12709
12874
 
12710
- export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, calculateSwap, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getSecondKey, getSimulationComputeUnits, getTokenDecimals, getTokenProgram, unwrapSOLInstruction, wrapSOLInstruction };
12875
+ export { ActivationPoint, ActivationType, type AddLiquidityParams, type AmmProgram, BASIS_POINT_MAX, type BaseFee, CP_AMM_PROGRAM_ID, type ClaimPartnerFeeParams, type ClaimPositionFeeParams, type ClaimRewardParams, CollectFeeMode, type ConfigState, CpAmm, type CpAmm$1 as CpAmmTypes, type CreatePoolParams, type CreatePositionParams, type DynamicFee, FEE_DENOMINATOR, type FeeMode, FeeSchedulerMode, type FundRewardParams, type GetQuoteParams, type InitializeCustomizeablePoolParams, type InitializeRewardParams, type LiquidityDeltaParams, type LockPositionParams, MAX_CU_BUFFER, MAX_FEE_NUMERATOR, MAX_SQRT_PRICE, MIN_CU_BUFFER, MIN_SQRT_PRICE, type PermanentLockParams, type PoolFeesParams, type PoolState, type PositionState, type PreparePoolCreationParams, type PreparedPoolCreation, type RefreshVestingParams, type RemoveLiquidityParams, type RewardInfo, Rounding, SCALE_OFFSET, type SwapParams, type SwapQuotes, type TokenBadgeState, TradeDirection, type TxBuilder, type UpdateRewardDurationParams, type UpdateRewardFunderParams, type VestingState, type WithdrawIneligibleRewardParams, CpAmmIDL as default, deriveClaimFeeOperatorAddress, deriveConfigAddress, deriveCustomizablePoolAddress, deriveEventAuthority, derivePoolAddress, derivePoolAuthority, derivePositionAddress, derivePositionNftAccount, deriveRewardVaultAddress, deriveTokenBadgeAddress, deriveTokenVaultAddress, getAmountAFromLiquidityDelta, getAmountBFromLiquidityDelta, getBaseFeeNumerator, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getSwapAmount, getTokenDecimals, getTokenProgram, getUnClaimReward, positionByPoolFilter, unwrapSOLInstruction, wrapSOLInstruction };