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

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
@@ -6548,6 +6548,31 @@ declare const getEstimatedComputeUnitUsageWithBuffer: (connection: Connection, i
6548
6548
  */
6549
6549
  declare const getEstimatedComputeUnitIxWithBuffer: (connection: Connection, instructions: TransactionInstruction[], feePayer: PublicKey, buffer?: number) => Promise<TransactionInstruction>;
6550
6550
 
6551
+ /**
6552
+ * It takes an amount and a slippage rate, and returns the maximum amount that can be received with
6553
+ * that slippage rate
6554
+ * @param {BN} amount - The amount of tokens you want to buy.
6555
+ * @param {number} slippageRate - The maximum percentage of slippage you're willing to accept. (Max to 2 decimal place)
6556
+ * @returns The maximum amount of tokens that can be bought with the given amount of ETH, given the
6557
+ * slippage rate.
6558
+ */
6559
+ declare const getMaxAmountWithSlippage: (amount: BN, slippageRate: number) => BN;
6560
+ /**
6561
+ * It takes an amount and a slippage rate, and returns the minimum amount that will be received after
6562
+ * slippage
6563
+ * @param {BN} amount - The amount of tokens you want to sell.
6564
+ * @param {number} slippageRate - The percentage of slippage you're willing to accept. (Max to 2 decimal place)
6565
+ * @returns The minimum amount that can be received after slippage is applied.
6566
+ */
6567
+ declare const getMinAmountWithSlippage: (amount: BN, slippageRate: number) => BN;
6568
+ declare const getPriceImpact: (amount: BN, amountWithoutSlippage: BN) => number;
6569
+ declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => BN;
6570
+ declare const getUnClaimReward: (positionState: PositionState) => {
6571
+ feeTokenA: BN;
6572
+ feeTokenB: BN;
6573
+ rewards: BN[];
6574
+ };
6575
+
6551
6576
  var address = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
6552
6577
  var metadata = {
6553
6578
  name: "cp_amm",
@@ -12707,4 +12732,4 @@ var CpAmmIDL = {
12707
12732
  types: types
12708
12733
  };
12709
12734
 
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 };
12735
+ 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, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getTokenDecimals, getTokenProgram, getUnClaimReward, unwrapSOLInstruction, wrapSOLInstruction };
package/dist/index.d.ts CHANGED
@@ -6548,6 +6548,31 @@ declare const getEstimatedComputeUnitUsageWithBuffer: (connection: Connection, i
6548
6548
  */
6549
6549
  declare const getEstimatedComputeUnitIxWithBuffer: (connection: Connection, instructions: TransactionInstruction[], feePayer: PublicKey, buffer?: number) => Promise<TransactionInstruction>;
6550
6550
 
6551
+ /**
6552
+ * It takes an amount and a slippage rate, and returns the maximum amount that can be received with
6553
+ * that slippage rate
6554
+ * @param {BN} amount - The amount of tokens you want to buy.
6555
+ * @param {number} slippageRate - The maximum percentage of slippage you're willing to accept. (Max to 2 decimal place)
6556
+ * @returns The maximum amount of tokens that can be bought with the given amount of ETH, given the
6557
+ * slippage rate.
6558
+ */
6559
+ declare const getMaxAmountWithSlippage: (amount: BN, slippageRate: number) => BN;
6560
+ /**
6561
+ * It takes an amount and a slippage rate, and returns the minimum amount that will be received after
6562
+ * slippage
6563
+ * @param {BN} amount - The amount of tokens you want to sell.
6564
+ * @param {number} slippageRate - The percentage of slippage you're willing to accept. (Max to 2 decimal place)
6565
+ * @returns The minimum amount that can be received after slippage is applied.
6566
+ */
6567
+ declare const getMinAmountWithSlippage: (amount: BN, slippageRate: number) => BN;
6568
+ declare const getPriceImpact: (amount: BN, amountWithoutSlippage: BN) => number;
6569
+ declare const getCurrentPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => BN;
6570
+ declare const getUnClaimReward: (positionState: PositionState) => {
6571
+ feeTokenA: BN;
6572
+ feeTokenB: BN;
6573
+ rewards: BN[];
6574
+ };
6575
+
6551
6576
  var address = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
6552
6577
  var metadata = {
6553
6578
  name: "cp_amm",
@@ -12707,4 +12732,4 @@ var CpAmmIDL = {
12707
12732
  types: types
12708
12733
  };
12709
12734
 
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 };
12735
+ 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, getCurrentPrice, getDeltaAmountA, getDeltaAmountB, getDynamicFeeNumerator, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getFeeNumerator, getFirstKey, getLiquidityDeltaFromAmountA, getLiquidityDeltaFromAmountB, getMaxAmountWithSlippage, getMinAmountWithSlippage, getNextSqrtPrice, getNftOwner, getOrCreateATAInstruction, getPriceImpact, getSecondKey, getSimulationComputeUnits, getTokenDecimals, getTokenProgram, getUnClaimReward, unwrapSOLInstruction, wrapSOLInstruction };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __async = (__this, __arguments, generator) => {
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __pow = Math.pow;
2
+ var __async = (__this, __arguments, generator) => {
2
3
  return new Promise((resolve, reject) => {
3
4
  var fulfilled = (value) => {
4
5
  try {
@@ -6820,6 +6821,10 @@ var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, b
6820
6821
  // src/utils/utils.ts
6821
6822
 
6822
6823
 
6824
+ var getMaxAmountWithSlippage = (amount, slippageRate) => {
6825
+ const slippage = (100 + slippageRate) / 100 * BASIS_POINT_MAX;
6826
+ return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
6827
+ };
6823
6828
  var getMinAmountWithSlippage = (amount, slippageRate) => {
6824
6829
  const slippage = (100 - slippageRate) / 100 * BASIS_POINT_MAX;
6825
6830
  return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
@@ -6828,6 +6833,19 @@ var getPriceImpact = (amount, amountWithoutSlippage) => {
6828
6833
  const diff = amountWithoutSlippage.sub(amount);
6829
6834
  return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(amountWithoutSlippage.toString())).mul(100).toNumber();
6830
6835
  };
6836
+ var getCurrentPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
6837
+ const rawSqrtPrice = sqrtPrice.shrn(SCALE_OFFSET);
6838
+ const price = rawSqrtPrice.mul(rawSqrtPrice);
6839
+ const expo = __pow(10, tokenADecimal - tokenBDecimal);
6840
+ return price.muln(expo);
6841
+ };
6842
+ var getUnClaimReward = (positionState) => {
6843
+ return {
6844
+ feeTokenA: positionState.feeAPending,
6845
+ feeTokenB: positionState.feeBPending,
6846
+ rewards: positionState.rewardInfos.length > 0 ? positionState.rewardInfos.map((item) => item.rewardPendings) : []
6847
+ };
6848
+ };
6831
6849
 
6832
6850
  // src/utils/accountFilters.ts
6833
6851
  var positionByPoolFilter = (pool) => {
@@ -7989,5 +8007,10 @@ var index_default = cp_amm_default;
7989
8007
 
7990
8008
 
7991
8009
 
7992
- 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.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.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateSwap = calculateSwap; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.deriveEventAuthority = deriveEventAuthority; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getDeltaAmountA = getDeltaAmountA; exports.getDeltaAmountB = getDeltaAmountB; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getNftOwner = getNftOwner; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
8010
+
8011
+
8012
+
8013
+
8014
+
8015
+ 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.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.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateSwap = calculateSwap; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.deriveEventAuthority = deriveEventAuthority; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getCurrentPrice = getCurrentPrice; exports.getDeltaAmountA = getDeltaAmountA; exports.getDeltaAmountB = getDeltaAmountB; 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.getNftOwner = getNftOwner; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getUnClaimReward = getUnClaimReward; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
7993
8016
  //# sourceMappingURL=index.js.map