@meteora-ag/cp-amm-sdk 1.0.0-rc.3 → 1.0.0-rc.4

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
@@ -6401,7 +6401,6 @@ var SCALE_OFFSET = 64;
6401
6401
  var BASIS_POINT_MAX = 1e4;
6402
6402
  var MAX_FEE_NUMERATOR = 5e8;
6403
6403
  var FEE_DENOMINATOR = 1e9;
6404
- var PRECISION = 1e6;
6405
6404
  var MIN_SQRT_PRICE = new BN("4295048016");
6406
6405
  var MAX_SQRT_PRICE = new BN("79226673521066979257578248091");
6407
6406
  var MIN_CU_BUFFER = 5e4;
@@ -6493,12 +6492,6 @@ function derivePositionNftAccount(positionNftMint) {
6493
6492
  CP_AMM_PROGRAM_ID
6494
6493
  )[0];
6495
6494
  }
6496
- function deriveTokenBadge(tokenMint) {
6497
- return PublicKey2.findProgramAddressSync(
6498
- [Buffer.from("token_badge"), tokenMint.toBuffer()],
6499
- CP_AMM_PROGRAM_ID
6500
- )[0];
6501
- }
6502
6495
 
6503
6496
  // src/helpers/token.ts
6504
6497
  import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
@@ -6516,7 +6509,6 @@ import {
6516
6509
  TokenInvalidAccountOwnerError
6517
6510
  } from "@solana/spl-token";
6518
6511
  import {
6519
- PublicKey as PublicKey3,
6520
6512
  SystemProgram,
6521
6513
  TransactionInstruction
6522
6514
  } from "@solana/web3.js";
@@ -6590,16 +6582,6 @@ var unwrapSOLInstruction = (owner, allowOwnerOffCurve = true) => __async(void 0,
6590
6582
  }
6591
6583
  return null;
6592
6584
  });
6593
- function getNftOwner(connection, nftMint) {
6594
- return __async(this, null, function* () {
6595
- const largesTokenAccount = yield connection.getTokenLargestAccounts(nftMint);
6596
- const accountInfo = yield connection.getParsedAccountInfo(
6597
- largesTokenAccount.value[0].address
6598
- );
6599
- const owner = new PublicKey3(accountInfo.value.data.parsed.info.owner);
6600
- return new PublicKey3(owner);
6601
- });
6602
- }
6603
6585
  function getAllUserPositionNftAccount(connection, user) {
6604
6586
  return __async(this, null, function* () {
6605
6587
  const filters = [
@@ -6752,12 +6734,6 @@ function mulDiv(x, y, denominator, rounding) {
6752
6734
  }
6753
6735
  return div;
6754
6736
  }
6755
- function divCeil(a, b) {
6756
- if (a.isZero()) {
6757
- return new BN3(0);
6758
- }
6759
- return a.add(b.sub(new BN3(1))).div(b);
6760
- }
6761
6737
  function q64ToDecimal(num, decimalPlaces) {
6762
6738
  return new Decimal(num.toString()).div(Decimal.pow(2, 64)).toDecimalPlaces(decimalPlaces);
6763
6739
  }
@@ -6849,7 +6825,7 @@ function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFr
6849
6825
  new BN5(binStep),
6850
6826
  new BN5(variableFeeControl)
6851
6827
  );
6852
- feeNumerator.add(dynamicFeeNumberator);
6828
+ feeNumerator = feeNumerator.add(dynamicFeeNumberator);
6853
6829
  }
6854
6830
  return feeNumerator.gt(new BN5(MAX_FEE_NUMERATOR)) ? new BN5(MAX_FEE_NUMERATOR) : feeNumerator;
6855
6831
  }
@@ -7164,11 +7140,11 @@ function getAvailableVestingLiquidity(vestingData, currentPoint) {
7164
7140
  numberOfPeriod,
7165
7141
  totalReleasedLiquidity
7166
7142
  } = vestingData;
7167
- if (currentPoint < cliffPoint) {
7143
+ if (currentPoint.lt(cliffPoint)) {
7168
7144
  return new BN9(0);
7169
7145
  }
7170
7146
  if (periodFrequency.isZero()) {
7171
- return cliffUnlockLiquidity.sub(totalReleasedLiquidity);
7147
+ return cliffUnlockLiquidity;
7172
7148
  }
7173
7149
  let passedPeriod = new BN9(currentPoint).sub(cliffPoint).div(periodFrequency);
7174
7150
  passedPeriod = min(passedPeriod, new BN9(numberOfPeriod));
@@ -7246,12 +7222,12 @@ var CpAmm = class {
7246
7222
  getTokenBadgeAccounts(tokenAMint, tokenBMint) {
7247
7223
  return [
7248
7224
  {
7249
- pubkey: deriveTokenBadge(tokenAMint),
7225
+ pubkey: deriveTokenBadgeAddress(tokenAMint),
7250
7226
  isWritable: false,
7251
7227
  isSigner: false
7252
7228
  },
7253
7229
  {
7254
- pubkey: deriveTokenBadge(tokenBMint),
7230
+ pubkey: deriveTokenBadgeAddress(tokenBMint),
7255
7231
  isWritable: false,
7256
7232
  isSigner: false
7257
7233
  }
@@ -7706,87 +7682,85 @@ var CpAmm = class {
7706
7682
  * @returns Swap quote including expected output amount, fee, and price impact.
7707
7683
  */
7708
7684
  getQuote(params) {
7709
- return __async(this, null, function* () {
7710
- const {
7685
+ const {
7686
+ inAmount,
7687
+ inputTokenMint,
7688
+ slippage,
7689
+ poolState,
7690
+ currentTime,
7691
+ currentSlot,
7692
+ inputTokenInfo,
7693
+ outputTokenInfo
7694
+ } = params;
7695
+ const {
7696
+ sqrtPrice: sqrtPriceQ64,
7697
+ liquidity: liquidityQ64,
7698
+ activationType,
7699
+ activationPoint,
7700
+ collectFeeMode,
7701
+ poolFees
7702
+ } = poolState;
7703
+ const {
7704
+ feeSchedulerMode,
7705
+ cliffFeeNumerator,
7706
+ numberOfPeriod,
7707
+ reductionFactor,
7708
+ periodFrequency
7709
+ } = poolFees.baseFee;
7710
+ const dynamicFee = poolFees.dynamicFee;
7711
+ let actualAmountIn = inAmount;
7712
+ if (inputTokenInfo) {
7713
+ actualAmountIn = calculateTransferFeeExcludedAmount(
7711
7714
  inAmount,
7712
- inputTokenMint,
7713
- slippage,
7714
- poolState,
7715
- currentTime,
7716
- currentSlot,
7717
- inputTokenInfo,
7718
- outputTokenInfo
7719
- } = params;
7720
- const {
7721
- sqrtPrice: sqrtPriceQ64,
7722
- liquidity: liquidityQ64,
7723
- activationType,
7724
- activationPoint,
7725
- collectFeeMode,
7726
- poolFees
7727
- } = poolState;
7728
- const {
7729
- feeSchedulerMode,
7730
- cliffFeeNumerator,
7731
- numberOfPeriod,
7732
- reductionFactor,
7733
- periodFrequency
7734
- } = poolFees.baseFee;
7735
- const dynamicFee = poolFees.dynamicFee;
7736
- let actualAmountIn = inAmount;
7737
- if (inputTokenInfo) {
7738
- actualAmountIn = calculateTransferFeeExcludedAmount(
7739
- inAmount,
7740
- inputTokenInfo.mint,
7741
- inputTokenInfo.currentEpoch
7742
- ).amount;
7743
- }
7744
- const aToB = poolState.tokenAMint.equals(inputTokenMint);
7745
- const currentPoint = activationType ? currentTime : currentSlot;
7746
- let dynamicFeeParams;
7747
- if (dynamicFee.initialized) {
7748
- const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFee;
7749
- dynamicFeeParams = { volatilityAccumulator, binStep, variableFeeControl };
7750
- }
7751
- const tradeFeeNumerator = getFeeNumerator(
7752
- currentPoint,
7753
- activationPoint,
7754
- numberOfPeriod,
7755
- periodFrequency,
7756
- feeSchedulerMode,
7757
- cliffFeeNumerator,
7758
- reductionFactor,
7759
- dynamicFeeParams
7760
- );
7761
- const { amountOut, totalFee } = getSwapAmount(
7762
- actualAmountIn,
7763
- sqrtPriceQ64,
7764
- liquidityQ64,
7765
- tradeFeeNumerator,
7766
- aToB,
7767
- collectFeeMode
7768
- );
7769
- let actualAmountOut = amountOut;
7770
- if (outputTokenInfo) {
7771
- actualAmountOut = calculateTransferFeeExcludedAmount(
7772
- amountOut,
7773
- outputTokenInfo.mint,
7774
- outputTokenInfo.currentEpoch
7775
- ).amount;
7776
- }
7777
- const minSwapOutAmount = getMinAmountWithSlippage(
7778
- actualAmountOut,
7779
- slippage
7780
- );
7781
- return {
7782
- swapInAmount: inAmount,
7783
- consumedInAmount: actualAmountIn,
7784
- swapOutAmount: actualAmountOut,
7785
- minSwapOutAmount,
7786
- totalFee,
7787
- priceImpact: getPriceImpact(minSwapOutAmount, actualAmountOut)
7788
- };
7789
- });
7715
+ inputTokenInfo.mint,
7716
+ inputTokenInfo.currentEpoch
7717
+ ).amount;
7718
+ }
7719
+ const aToB = poolState.tokenAMint.equals(inputTokenMint);
7720
+ const currentPoint = activationType ? currentTime : currentSlot;
7721
+ let dynamicFeeParams;
7722
+ if (dynamicFee.initialized) {
7723
+ const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFee;
7724
+ dynamicFeeParams = { volatilityAccumulator, binStep, variableFeeControl };
7725
+ }
7726
+ const tradeFeeNumerator = getFeeNumerator(
7727
+ currentPoint,
7728
+ activationPoint,
7729
+ numberOfPeriod,
7730
+ periodFrequency,
7731
+ feeSchedulerMode,
7732
+ cliffFeeNumerator,
7733
+ reductionFactor,
7734
+ dynamicFeeParams
7735
+ );
7736
+ const { amountOut, totalFee } = getSwapAmount(
7737
+ actualAmountIn,
7738
+ sqrtPriceQ64,
7739
+ liquidityQ64,
7740
+ tradeFeeNumerator,
7741
+ aToB,
7742
+ collectFeeMode
7743
+ );
7744
+ let actualAmountOut = amountOut;
7745
+ if (outputTokenInfo) {
7746
+ actualAmountOut = calculateTransferFeeExcludedAmount(
7747
+ amountOut,
7748
+ outputTokenInfo.mint,
7749
+ outputTokenInfo.currentEpoch
7750
+ ).amount;
7751
+ }
7752
+ const minSwapOutAmount = getMinAmountWithSlippage(
7753
+ actualAmountOut,
7754
+ slippage
7755
+ );
7756
+ return {
7757
+ swapInAmount: inAmount,
7758
+ consumedInAmount: actualAmountIn,
7759
+ swapOutAmount: actualAmountOut,
7760
+ minSwapOutAmount,
7761
+ totalFee,
7762
+ priceImpact: getPriceImpact(minSwapOutAmount, actualAmountOut)
7763
+ };
7790
7764
  }
7791
7765
  /**
7792
7766
  * Calculates the deposit quote for liquidity pool.
@@ -7799,61 +7773,59 @@ var CpAmm = class {
7799
7773
  * @returns {BN} returns.liquidityDelta - The amount of liquidity that will be added to the pool.
7800
7774
  */
7801
7775
  getDepositQuote(params) {
7802
- return __async(this, null, function* () {
7803
- const {
7776
+ const {
7777
+ inAmount,
7778
+ isTokenA,
7779
+ inputTokenInfo,
7780
+ outputTokenInfo,
7781
+ minSqrtPrice,
7782
+ maxSqrtPrice,
7783
+ sqrtPrice
7784
+ } = params;
7785
+ const actualAmountIn = inputTokenInfo ? inAmount.sub(
7786
+ calculateTransferFeeIncludedAmount(
7804
7787
  inAmount,
7805
- isTokenA,
7806
- inputTokenInfo,
7807
- outputTokenInfo,
7788
+ inputTokenInfo.mint,
7789
+ inputTokenInfo.currentEpoch
7790
+ ).transferFee
7791
+ ) : inAmount;
7792
+ const { liquidityDelta, rawAmount } = isTokenA ? {
7793
+ liquidityDelta: getLiquidityDeltaFromAmountA(
7794
+ actualAmountIn,
7795
+ sqrtPrice,
7796
+ maxSqrtPrice
7797
+ ),
7798
+ rawAmount: (delta) => getAmountBFromLiquidityDelta(
7799
+ delta,
7800
+ sqrtPrice,
7801
+ minSqrtPrice,
7802
+ 0 /* Up */
7803
+ )
7804
+ } : {
7805
+ liquidityDelta: getLiquidityDeltaFromAmountB(
7806
+ actualAmountIn,
7808
7807
  minSqrtPrice,
7809
- maxSqrtPrice,
7810
7808
  sqrtPrice
7811
- } = params;
7812
- const actualAmountIn = inputTokenInfo ? inAmount.sub(
7813
- calculateTransferFeeIncludedAmount(
7814
- inAmount,
7815
- inputTokenInfo.mint,
7816
- inputTokenInfo.currentEpoch
7817
- ).transferFee
7818
- ) : inAmount;
7819
- const { liquidityDelta, rawAmount } = isTokenA ? {
7820
- liquidityDelta: getLiquidityDeltaFromAmountA(
7821
- actualAmountIn,
7822
- sqrtPrice,
7823
- maxSqrtPrice
7824
- ),
7825
- rawAmount: (delta) => getAmountBFromLiquidityDelta(
7826
- delta,
7827
- sqrtPrice,
7828
- minSqrtPrice,
7829
- 0 /* Up */
7830
- )
7831
- } : {
7832
- liquidityDelta: getLiquidityDeltaFromAmountB(
7833
- actualAmountIn,
7834
- minSqrtPrice,
7835
- sqrtPrice
7836
- ),
7837
- rawAmount: (delta) => getAmountAFromLiquidityDelta(
7838
- delta,
7839
- sqrtPrice,
7840
- maxSqrtPrice,
7841
- 0 /* Up */
7842
- )
7843
- };
7844
- const rawOutputAmount = new BN10(rawAmount(liquidityDelta));
7845
- const outputAmount = outputTokenInfo ? calculateTransferFeeIncludedAmount(
7846
- rawOutputAmount,
7847
- outputTokenInfo.mint,
7848
- outputTokenInfo.currentEpoch
7849
- ).amount : rawOutputAmount;
7850
- return {
7851
- actualInputAmount: actualAmountIn,
7852
- consumedInputAmount: inAmount,
7853
- liquidityDelta,
7854
- outputAmount
7855
- };
7856
- });
7809
+ ),
7810
+ rawAmount: (delta) => getAmountAFromLiquidityDelta(
7811
+ delta,
7812
+ sqrtPrice,
7813
+ maxSqrtPrice,
7814
+ 0 /* Up */
7815
+ )
7816
+ };
7817
+ const rawOutputAmount = new BN10(rawAmount(liquidityDelta));
7818
+ const outputAmount = outputTokenInfo ? calculateTransferFeeIncludedAmount(
7819
+ rawOutputAmount,
7820
+ outputTokenInfo.mint,
7821
+ outputTokenInfo.currentEpoch
7822
+ ).amount : rawOutputAmount;
7823
+ return {
7824
+ actualInputAmount: actualAmountIn,
7825
+ consumedInputAmount: inAmount,
7826
+ liquidityDelta,
7827
+ outputAmount
7828
+ };
7857
7829
  }
7858
7830
  /**
7859
7831
  * Calculates the withdrawal quote for removing liquidity from a concentrated liquidity pool.
@@ -7869,41 +7841,39 @@ var CpAmm = class {
7869
7841
  * @returns {BN} returns.outAmountB - The calculated amount of token B to be received (after deducting transfer fees)
7870
7842
  */
7871
7843
  getWithdrawQuote(params) {
7872
- return __async(this, null, function* () {
7873
- const {
7874
- liquidityDelta,
7875
- sqrtPrice,
7876
- maxSqrtPrice,
7877
- minSqrtPrice,
7878
- tokenATokenInfo,
7879
- tokenBTokenInfo
7880
- } = params;
7881
- const amountA = getAmountAFromLiquidityDelta(
7882
- liquidityDelta,
7883
- sqrtPrice,
7884
- maxSqrtPrice,
7885
- 1 /* Down */
7886
- );
7887
- const amountB = getAmountBFromLiquidityDelta(
7888
- liquidityDelta,
7889
- sqrtPrice,
7890
- minSqrtPrice,
7891
- 1 /* Down */
7892
- );
7893
- return {
7894
- liquidityDelta,
7895
- outAmountA: tokenATokenInfo ? calculateTransferFeeExcludedAmount(
7896
- amountA,
7897
- tokenATokenInfo.mint,
7898
- tokenATokenInfo.currentEpoch
7899
- ).amount : amountA,
7900
- outAmountB: tokenBTokenInfo ? calculateTransferFeeExcludedAmount(
7901
- amountB,
7902
- tokenBTokenInfo.mint,
7903
- tokenBTokenInfo.currentEpoch
7904
- ).amount : amountB
7905
- };
7906
- });
7844
+ const {
7845
+ liquidityDelta,
7846
+ sqrtPrice,
7847
+ maxSqrtPrice,
7848
+ minSqrtPrice,
7849
+ tokenATokenInfo,
7850
+ tokenBTokenInfo
7851
+ } = params;
7852
+ const amountA = getAmountAFromLiquidityDelta(
7853
+ liquidityDelta,
7854
+ sqrtPrice,
7855
+ maxSqrtPrice,
7856
+ 1 /* Down */
7857
+ );
7858
+ const amountB = getAmountBFromLiquidityDelta(
7859
+ liquidityDelta,
7860
+ sqrtPrice,
7861
+ minSqrtPrice,
7862
+ 1 /* Down */
7863
+ );
7864
+ return {
7865
+ liquidityDelta,
7866
+ outAmountA: tokenATokenInfo ? calculateTransferFeeExcludedAmount(
7867
+ amountA,
7868
+ tokenATokenInfo.mint,
7869
+ tokenATokenInfo.currentEpoch
7870
+ ).amount : amountA,
7871
+ outAmountB: tokenBTokenInfo ? calculateTransferFeeExcludedAmount(
7872
+ amountB,
7873
+ tokenBTokenInfo.mint,
7874
+ tokenBTokenInfo.currentEpoch
7875
+ ).amount : amountB
7876
+ };
7907
7877
  }
7908
7878
  /**
7909
7879
  * Calculates liquidity and corresponding token amounts for token A single-sided pool creation
@@ -9072,7 +9042,6 @@ export {
9072
9042
  MIN_CU_BUFFER,
9073
9043
  MIN_SQRT_PRICE,
9074
9044
  ONE,
9075
- PRECISION,
9076
9045
  Rounding,
9077
9046
  SCALE_OFFSET,
9078
9047
  TradeDirection,
@@ -9089,10 +9058,8 @@ export {
9089
9058
  derivePositionAddress,
9090
9059
  derivePositionNftAccount,
9091
9060
  deriveRewardVaultAddress,
9092
- deriveTokenBadge,
9093
9061
  deriveTokenBadgeAddress,
9094
9062
  deriveTokenVaultAddress,
9095
- divCeil,
9096
9063
  getAllUserPositionNftAccount,
9097
9064
  getAmountAFromLiquidityDelta,
9098
9065
  getAmountBFromLiquidityDelta,
@@ -9108,7 +9075,6 @@ export {
9108
9075
  getMaxAmountWithSlippage,
9109
9076
  getMinAmountWithSlippage,
9110
9077
  getNextSqrtPrice,
9111
- getNftOwner,
9112
9078
  getOrCreateATAInstruction,
9113
9079
  getPriceFromSqrtPrice,
9114
9080
  getPriceImpact,