@meteora-ag/cp-amm-sdk 1.1.5-rc.0 → 1.1.5-rc.2

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
@@ -7411,7 +7411,7 @@ declare function validateFeeFraction(numerator: BN$1, denominator: BN$1): void;
7411
7411
  * @param partner - The partner address
7412
7412
  * @returns True if the partner is valid, false otherwise
7413
7413
  */
7414
- declare function hasPartner(partner: PublicKey): boolean;
7414
+ declare function hasPartner(poolState: PoolState): boolean;
7415
7415
  /**
7416
7416
  * Gets the current point
7417
7417
  * @param connection - The connection to the Solana cluster
@@ -7858,7 +7858,11 @@ declare function getExcludedFeeAmountFromIncludedFeeAmount(includedFeeAmount: BN
7858
7858
  * @param feeIncrementBps - The fee increment in basis points
7859
7859
  * @returns [checkedOutputAmount: BN, checkedIncludedFeeAmount: BN, capped: boolean]
7860
7860
  */
7861
- declare function getCheckedAmounts(referenceAmount: BN$1, cliffFeeNumerator: BN$1, maxFeeBps: number, feeIncrementBps: number): [BN$1, BN$1, boolean];
7861
+ declare function getCheckedAmounts(referenceAmount: BN$1, cliffFeeNumerator: BN$1, maxFeeBps: number, feeIncrementBps: number): {
7862
+ checkedExcludedFeeAmount: BN$1;
7863
+ checkedIncludedFeeAmount: BN$1;
7864
+ isOverflow: boolean;
7865
+ };
7862
7866
  /**
7863
7867
  * Calculates the fee numerator from an excluded fee amount.
7864
7868
  * @param excludedFeeAmount - The excluded fee amount
package/dist/index.d.ts CHANGED
@@ -7411,7 +7411,7 @@ declare function validateFeeFraction(numerator: BN$1, denominator: BN$1): void;
7411
7411
  * @param partner - The partner address
7412
7412
  * @returns True if the partner is valid, false otherwise
7413
7413
  */
7414
- declare function hasPartner(partner: PublicKey): boolean;
7414
+ declare function hasPartner(poolState: PoolState): boolean;
7415
7415
  /**
7416
7416
  * Gets the current point
7417
7417
  * @param connection - The connection to the Solana cluster
@@ -7858,7 +7858,11 @@ declare function getExcludedFeeAmountFromIncludedFeeAmount(includedFeeAmount: BN
7858
7858
  * @param feeIncrementBps - The fee increment in basis points
7859
7859
  * @returns [checkedOutputAmount: BN, checkedIncludedFeeAmount: BN, capped: boolean]
7860
7860
  */
7861
- declare function getCheckedAmounts(referenceAmount: BN$1, cliffFeeNumerator: BN$1, maxFeeBps: number, feeIncrementBps: number): [BN$1, BN$1, boolean];
7861
+ declare function getCheckedAmounts(referenceAmount: BN$1, cliffFeeNumerator: BN$1, maxFeeBps: number, feeIncrementBps: number): {
7862
+ checkedExcludedFeeAmount: BN$1;
7863
+ checkedIncludedFeeAmount: BN$1;
7864
+ isOverflow: boolean;
7865
+ };
7862
7866
  /**
7863
7867
  * Calculates the fee numerator from an excluded fee amount.
7864
7868
  * @param excludedFeeAmount - The excluded fee amount
package/dist/index.js CHANGED
@@ -8254,17 +8254,13 @@ function pow(base, exp) {
8254
8254
 
8255
8255
  // src/math/feeMath.ts
8256
8256
  function toNumerator(bps, feeDenominator) {
8257
- try {
8258
- const numerator = mulDiv(
8259
- bps,
8260
- feeDenominator,
8261
- new (0, _anchor.BN)(BASIS_POINT_MAX),
8262
- 1 /* Down */
8263
- );
8264
- return numerator;
8265
- } catch (error) {
8266
- throw new Error("Type cast failed or calculation overflow in toNumerator");
8267
- }
8257
+ const numerator = mulDiv(
8258
+ bps,
8259
+ feeDenominator,
8260
+ new (0, _anchor.BN)(BASIS_POINT_MAX),
8261
+ 1 /* Down */
8262
+ );
8263
+ return numerator;
8268
8264
  }
8269
8265
  function getFeeInPeriod(cliffFeeNumerator, reductionFactor, passedPeriod) {
8270
8266
  if (reductionFactor.isZero()) {
@@ -8309,20 +8305,19 @@ function getFeeMode(collectFeeMode, tradeDirection, hasReferral) {
8309
8305
  };
8310
8306
  }
8311
8307
  function getTotalFeeNumerator(poolFees, baseFeeNumerator, maxFeeNumerator) {
8312
- const dynamicFeeNumerator = getDynamicFeeNumerator(
8313
- poolFees.dynamicFee.volatilityAccumulator,
8314
- new (0, _anchor.BN)(poolFees.dynamicFee.binStep),
8315
- new (0, _anchor.BN)(poolFees.dynamicFee.variableFeeControl)
8316
- );
8308
+ let dynamicFeeNumerator = new (0, _anchor.BN)(0);
8309
+ if (poolFees.dynamicFee.initialized !== 0) {
8310
+ dynamicFeeNumerator = getDynamicFeeNumerator(
8311
+ poolFees.dynamicFee.volatilityAccumulator,
8312
+ new (0, _anchor.BN)(poolFees.dynamicFee.binStep),
8313
+ new (0, _anchor.BN)(poolFees.dynamicFee.variableFeeControl)
8314
+ );
8315
+ }
8317
8316
  const totalFeeNumerator = dynamicFeeNumerator.add(baseFeeNumerator);
8318
8317
  if (totalFeeNumerator.gt(U64_MAX)) {
8319
8318
  throw new Error("Type cast failed: fee does not fit in u64");
8320
8319
  }
8321
- if (totalFeeNumerator.gt(maxFeeNumerator)) {
8322
- return maxFeeNumerator;
8323
- } else {
8324
- return totalFeeNumerator;
8325
- }
8320
+ return _anchor.BN.min(totalFeeNumerator, maxFeeNumerator);
8326
8321
  }
8327
8322
  function getTotalTradingFeeFromIncludedFeeAmount(poolFees, currentPoint, activationPoint, includedFeeAmount, tradeDirection, maxFeeNumerator) {
8328
8323
  const baseFeeHandler = getBaseFeeHandler(
@@ -8552,24 +8547,32 @@ function getCheckedAmounts(referenceAmount, cliffFeeNumerator, maxFeeBps, feeInc
8552
8547
  const maxIndexInputAmount = maxIndex.add(one).mul(x0);
8553
8548
  if (maxIndexInputAmount.lte(U64_MAX)) {
8554
8549
  const checkedIncludedFeeAmount = maxIndexInputAmount;
8555
- const checkedOutputAmount = getExcludedFeeAmountFromIncludedFeeAmount(
8550
+ const checkedExcludedFeeAmount = getExcludedFeeAmountFromIncludedFeeAmount(
8556
8551
  checkedIncludedFeeAmount,
8557
8552
  referenceAmount,
8558
8553
  cliffFeeNumerator,
8559
8554
  maxFeeBps,
8560
8555
  feeIncrementBps
8561
8556
  );
8562
- return [checkedOutputAmount, checkedIncludedFeeAmount, false];
8557
+ return {
8558
+ checkedExcludedFeeAmount,
8559
+ checkedIncludedFeeAmount,
8560
+ isOverflow: false
8561
+ };
8563
8562
  } else {
8564
8563
  const checkedIncludedFeeAmount = U64_MAX;
8565
- const checkedOutputAmount = getExcludedFeeAmountFromIncludedFeeAmount(
8564
+ const checkedExcludedFeeAmount = getExcludedFeeAmountFromIncludedFeeAmount(
8566
8565
  checkedIncludedFeeAmount,
8567
8566
  referenceAmount,
8568
8567
  cliffFeeNumerator,
8569
8568
  maxFeeBps,
8570
8569
  feeIncrementBps
8571
8570
  );
8572
- return [checkedOutputAmount, checkedIncludedFeeAmount, true];
8571
+ return {
8572
+ checkedExcludedFeeAmount,
8573
+ checkedIncludedFeeAmount,
8574
+ isOverflow: true
8575
+ };
8573
8576
  }
8574
8577
  }
8575
8578
  function getFeeNumeratorFromExcludedFeeAmount(excludedFeeAmount, referenceAmount, cliffFeeNumerator, maxFeeBps, feeIncrementBps) {
@@ -8583,7 +8586,7 @@ function getFeeNumeratorFromExcludedFeeAmount(excludedFeeAmount, referenceAmount
8583
8586
  if (excludedFeeAmount.lte(excludedFeeReferenceAmount)) {
8584
8587
  return cliffFeeNumerator;
8585
8588
  }
8586
- const [checkedExcludedFeeAmount, checkedIncludedFeeAmount, isOverflow] = getCheckedAmounts(
8589
+ const { checkedExcludedFeeAmount, checkedIncludedFeeAmount, isOverflow } = getCheckedAmounts(
8587
8590
  referenceAmount,
8588
8591
  cliffFeeNumerator,
8589
8592
  maxFeeBps,
@@ -8888,9 +8891,6 @@ function isDynamicFeeEnabled(dynamicFee) {
8888
8891
  return dynamicFee.initialized !== 0;
8889
8892
  }
8890
8893
  function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
8891
- if (variableFeeControl.isZero()) {
8892
- return new (0, _bnjs2.default)(0);
8893
- }
8894
8894
  const squareVfaBin = volatilityAccumulator.mul(new (0, _bnjs2.default)(binStep)).pow(new (0, _bnjs2.default)(2));
8895
8895
  const vFee = variableFeeControl.mul(squareVfaBin);
8896
8896
  return vFee.add(new (0, _bnjs2.default)(DYNAMIC_FEE_ROUNDING_OFFSET)).div(new (0, _bnjs2.default)(DYNAMIC_FEE_SCALING_FACTOR));
@@ -8984,9 +8984,6 @@ function getAmountBFromLiquidityDelta(lowerSqrtPrice, upperSqrtPrice, liquidity,
8984
8984
  liquidity,
8985
8985
  rounding
8986
8986
  );
8987
- if (result.gt(U64_MAX)) {
8988
- throw new Error("MathOverflow: result exceeds u64 max");
8989
- }
8990
8987
  return result;
8991
8988
  }
8992
8989
  function getDeltaAmountBUnsignedUnchecked(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
@@ -9009,9 +9006,6 @@ function getAmountAFromLiquidityDelta(lowerSqrtPrice, upperSqrtPrice, liquidity,
9009
9006
  liquidity,
9010
9007
  rounding
9011
9008
  );
9012
- if (result.gt(U64_MAX)) {
9013
- throw new Error("MathOverflow: result exceeds u64 max");
9014
- }
9015
9009
  return result;
9016
9010
  }
9017
9011
  function getDeltaAmountAUnsignedUnchecked(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
@@ -9057,7 +9051,7 @@ function getSwapResultFromExactInput(poolState, amountIn, feeMode, tradeDirectio
9057
9051
  amountIn,
9058
9052
  tradeFeeNumerator,
9059
9053
  feeMode.hasReferral,
9060
- hasPartner(poolState.partner)
9054
+ hasPartner(poolState)
9061
9055
  );
9062
9056
  actualProtocolFee = protocolFee;
9063
9057
  actualTradingFee = tradingFee;
@@ -9083,7 +9077,7 @@ function getSwapResultFromExactInput(poolState, amountIn, feeMode, tradeDirectio
9083
9077
  outputAmount,
9084
9078
  tradeFeeNumerator,
9085
9079
  feeMode.hasReferral,
9086
- hasPartner(poolState.partner)
9080
+ hasPartner(poolState)
9087
9081
  );
9088
9082
  actualProtocolFee = protocolFee;
9089
9083
  actualTradingFee = tradingFee;
@@ -9114,8 +9108,8 @@ function calculateAtoBFromAmountIn(poolState, amountIn) {
9114
9108
  throw new Error("Price range is violated");
9115
9109
  }
9116
9110
  const outputAmount = getAmountBFromLiquidityDelta(
9117
- poolState.sqrtPrice,
9118
9111
  nextSqrtPrice,
9112
+ poolState.sqrtPrice,
9119
9113
  poolState.liquidity,
9120
9114
  1 /* Down */
9121
9115
  );
@@ -9168,7 +9162,7 @@ function getSwapResultFromPartialInput(poolState, amountIn, feeMode, tradeDirect
9168
9162
  amountIn,
9169
9163
  tradeFeeNumerator,
9170
9164
  feeMode.hasReferral,
9171
- hasPartner(poolState.partner)
9165
+ hasPartner(poolState)
9172
9166
  );
9173
9167
  actualProtocolFee = protocolFee;
9174
9168
  actualTradingFee = tradingFee;
@@ -9211,7 +9205,7 @@ function getSwapResultFromPartialInput(poolState, amountIn, feeMode, tradeDirect
9211
9205
  poolState.poolFees,
9212
9206
  feeAmount,
9213
9207
  feeMode.hasReferral,
9214
- hasPartner(poolState.partner)
9208
+ hasPartner(poolState)
9215
9209
  );
9216
9210
  actualProtocolFee = protocolFee;
9217
9211
  actualTradingFee = tradingFee;
@@ -9233,7 +9227,7 @@ function getSwapResultFromPartialInput(poolState, amountIn, feeMode, tradeDirect
9233
9227
  outputAmount,
9234
9228
  tradeFeeNumerator,
9235
9229
  feeMode.hasReferral,
9236
- hasPartner(poolState.partner)
9230
+ hasPartner(poolState)
9237
9231
  );
9238
9232
  actualProtocolFee = protocolFee;
9239
9233
  actualTradingFee = tradingFee;
@@ -9347,7 +9341,7 @@ function getSwapResultFromExactOutput(poolState, amountOut, feeMode, tradeDirect
9347
9341
  poolState.poolFees,
9348
9342
  feeAmount,
9349
9343
  feeMode.hasReferral,
9350
- hasPartner(poolState.partner)
9344
+ hasPartner(poolState)
9351
9345
  );
9352
9346
  actualTradingFee = split.tradingFee;
9353
9347
  actualProtocolFee = split.protocolFee;
@@ -9386,7 +9380,7 @@ function getSwapResultFromExactOutput(poolState, amountOut, feeMode, tradeDirect
9386
9380
  poolState.poolFees,
9387
9381
  feeAmount,
9388
9382
  feeMode.hasReferral,
9389
- hasPartner(poolState.partner)
9383
+ hasPartner(poolState)
9390
9384
  );
9391
9385
  actualTradingFee = split.tradingFee;
9392
9386
  actualProtocolFee = split.protocolFee;
@@ -9722,8 +9716,8 @@ function validateFeeFraction(numerator, denominator) {
9722
9716
 
9723
9717
 
9724
9718
 
9725
- function hasPartner(partner) {
9726
- return !partner.equals(_web3js.PublicKey.default);
9719
+ function hasPartner(poolState) {
9720
+ return !poolState.partner.equals(_web3js.PublicKey.default);
9727
9721
  }
9728
9722
  function getCurrentPoint(connection, activationType) {
9729
9723
  return __async(this, null, function* () {
@@ -9737,9 +9731,6 @@ function getCurrentPoint(connection, activationType) {
9737
9731
  });
9738
9732
  }
9739
9733
  function isSwapEnabled(pool, currentPoint) {
9740
- if (typeof pool.poolStatus !== "number") {
9741
- throw new Error("invalid pool status");
9742
- }
9743
9734
  return pool.poolStatus === 0 /* Enable */ && currentPoint.gte(pool.activationPoint);
9744
9735
  }
9745
9736
  function convertToFeeSchedulerSecondFactor(value) {
@@ -10675,7 +10666,7 @@ var CpAmm = class {
10675
10666
  tokenBDecimal,
10676
10667
  hasReferral
10677
10668
  } = params;
10678
- const { sqrtPrice: sqrtPriceQ64, activationType } = poolState;
10669
+ const { activationType } = poolState;
10679
10670
  const aToB = poolState.tokenAMint.equals(inputTokenMint);
10680
10671
  const currentPoint = activationType ? new (0, _bnjs2.default)(currentTime) : new (0, _bnjs2.default)(currentSlot);
10681
10672
  const swapResult = swapQuoteExactInput(