@meteora-ag/cp-amm-sdk 1.4.1 → 1.4.3

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
@@ -8479,18 +8479,18 @@ declare function getFeeTimeSchedulerParams(startingBaseFeeBps: number, endingBas
8479
8479
  declare function computeSqrtPriceStepBps(priceMultiple: number, numberOfPeriod: number): number;
8480
8480
  /**
8481
8481
  * Gets the fee market cap scheduler parameters. Derives sqrtPriceStepBps
8482
- * automatically from starting/ending market cap so the fee schedule is
8483
- * fully exhausted when the token grows from startingMarketCap to endingMarketCap.
8482
+ * automatically from `priceMultiple` so the fee schedule is fully exhausted
8483
+ * when the spot price grows by that multiple from the initial price.
8484
+ *
8484
8485
  * @param startingBaseFeeBps - Starting (max) fee in basis points
8485
8486
  * @param endingBaseFeeBps - Ending (min) fee in basis points
8486
8487
  * @param baseFeeMode - Linear or exponential decay
8487
8488
  * @param numberOfPeriod - Number of fee reduction periods
8488
- * @param startingMarketCap - Initial market cap (e.g. 20_000 for $20k)
8489
- * @param endingMarketCap - Target market cap (e.g. 20_000_000 for $20M)
8489
+ * @param priceMultiple - Target spot-price multiple from the initial price (e.g. 1000 for 1000x). Must be > 1.
8490
8490
  * @param schedulerExpirationDuration - Seconds after which the schedule expires to the ending fee regardless of price
8491
8491
  * @returns BaseFee with the computed sqrtPriceStepBps encoded
8492
8492
  */
8493
- declare function getFeeMarketCapSchedulerParams(startingBaseFeeBps: number, endingBaseFeeBps: number, baseFeeMode: BaseFeeMode, numberOfPeriod: number, startingMarketCap: number, endingMarketCap: number, schedulerExpirationDuration: number): BaseFee;
8493
+ declare function getFeeMarketCapSchedulerParams(startingBaseFeeBps: number, endingBaseFeeBps: number, baseFeeMode: BaseFeeMode, numberOfPeriod: number, priceMultiple: number, schedulerExpirationDuration: number): BaseFee;
8494
8494
  /**
8495
8495
  * Gets the rate limiter parameters
8496
8496
  * @param baseFeeBps - The base fee in basis points
@@ -8531,8 +8531,7 @@ declare function getBaseFeeParams(baseFeeParams: {
8531
8531
  startingFeeBps: number;
8532
8532
  endingFeeBps: number;
8533
8533
  numberOfPeriod: number;
8534
- startingMarketCap: number;
8535
- endingMarketCap: number;
8534
+ priceMultiple: number;
8536
8535
  schedulerExpirationDuration: number;
8537
8536
  };
8538
8537
  }, tokenBDecimal: number, activationType: ActivationType): BaseFee;
package/dist/index.d.ts CHANGED
@@ -8479,18 +8479,18 @@ declare function getFeeTimeSchedulerParams(startingBaseFeeBps: number, endingBas
8479
8479
  declare function computeSqrtPriceStepBps(priceMultiple: number, numberOfPeriod: number): number;
8480
8480
  /**
8481
8481
  * Gets the fee market cap scheduler parameters. Derives sqrtPriceStepBps
8482
- * automatically from starting/ending market cap so the fee schedule is
8483
- * fully exhausted when the token grows from startingMarketCap to endingMarketCap.
8482
+ * automatically from `priceMultiple` so the fee schedule is fully exhausted
8483
+ * when the spot price grows by that multiple from the initial price.
8484
+ *
8484
8485
  * @param startingBaseFeeBps - Starting (max) fee in basis points
8485
8486
  * @param endingBaseFeeBps - Ending (min) fee in basis points
8486
8487
  * @param baseFeeMode - Linear or exponential decay
8487
8488
  * @param numberOfPeriod - Number of fee reduction periods
8488
- * @param startingMarketCap - Initial market cap (e.g. 20_000 for $20k)
8489
- * @param endingMarketCap - Target market cap (e.g. 20_000_000 for $20M)
8489
+ * @param priceMultiple - Target spot-price multiple from the initial price (e.g. 1000 for 1000x). Must be > 1.
8490
8490
  * @param schedulerExpirationDuration - Seconds after which the schedule expires to the ending fee regardless of price
8491
8491
  * @returns BaseFee with the computed sqrtPriceStepBps encoded
8492
8492
  */
8493
- declare function getFeeMarketCapSchedulerParams(startingBaseFeeBps: number, endingBaseFeeBps: number, baseFeeMode: BaseFeeMode, numberOfPeriod: number, startingMarketCap: number, endingMarketCap: number, schedulerExpirationDuration: number): BaseFee;
8493
+ declare function getFeeMarketCapSchedulerParams(startingBaseFeeBps: number, endingBaseFeeBps: number, baseFeeMode: BaseFeeMode, numberOfPeriod: number, priceMultiple: number, schedulerExpirationDuration: number): BaseFee;
8494
8494
  /**
8495
8495
  * Gets the rate limiter parameters
8496
8496
  * @param baseFeeBps - The base fee in basis points
@@ -8531,8 +8531,7 @@ declare function getBaseFeeParams(baseFeeParams: {
8531
8531
  startingFeeBps: number;
8532
8532
  endingFeeBps: number;
8533
8533
  numberOfPeriod: number;
8534
- startingMarketCap: number;
8535
- endingMarketCap: number;
8534
+ priceMultiple: number;
8536
8535
  schedulerExpirationDuration: number;
8537
8536
  };
8538
8537
  }, tokenBDecimal: number, activationType: ActivationType): BaseFee;
package/dist/index.js CHANGED
@@ -8190,11 +8190,11 @@ var BaseFeeMode = /* @__PURE__ */ ((BaseFeeMode3) => {
8190
8190
  BaseFeeMode3[BaseFeeMode3["FeeMarketCapSchedulerExponential"] = 4] = "FeeMarketCapSchedulerExponential";
8191
8191
  return BaseFeeMode3;
8192
8192
  })(BaseFeeMode || {});
8193
- var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode4) => {
8194
- CollectFeeMode4[CollectFeeMode4["BothToken"] = 0] = "BothToken";
8195
- CollectFeeMode4[CollectFeeMode4["OnlyB"] = 1] = "OnlyB";
8196
- CollectFeeMode4[CollectFeeMode4["Compounding"] = 2] = "Compounding";
8197
- return CollectFeeMode4;
8193
+ var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode3) => {
8194
+ CollectFeeMode3[CollectFeeMode3["BothToken"] = 0] = "BothToken";
8195
+ CollectFeeMode3[CollectFeeMode3["OnlyB"] = 1] = "OnlyB";
8196
+ CollectFeeMode3[CollectFeeMode3["Compounding"] = 2] = "Compounding";
8197
+ return CollectFeeMode3;
8198
8198
  })(CollectFeeMode || {});
8199
8199
  var TradeDirection = /* @__PURE__ */ ((TradeDirection3) => {
8200
8200
  TradeDirection3[TradeDirection3["AtoB"] = 0] = "AtoB";
@@ -11848,12 +11848,12 @@ function computeSqrtPriceStepBps(priceMultiple, numberOfPeriod) {
11848
11848
  }
11849
11849
  return sqrtPriceStepBps;
11850
11850
  }
11851
- function getFeeMarketCapSchedulerParams(startingBaseFeeBps, endingBaseFeeBps, baseFeeMode, numberOfPeriod, startingMarketCap, endingMarketCap, schedulerExpirationDuration) {
11851
+ function getFeeMarketCapSchedulerParams(startingBaseFeeBps, endingBaseFeeBps, baseFeeMode, numberOfPeriod, priceMultiple, schedulerExpirationDuration) {
11852
11852
  if (numberOfPeriod <= 0) {
11853
11853
  throw new Error("Total periods must be greater than zero");
11854
11854
  }
11855
- if (endingMarketCap <= startingMarketCap) {
11856
- throw new Error("endingMarketCap must be greater than startingMarketCap");
11855
+ if (priceMultiple <= 1) {
11856
+ throw new Error("priceMultiple must be greater than 1");
11857
11857
  }
11858
11858
  const poolMaxFeeBps = getMaxFeeBps(CURRENT_POOL_VERSION);
11859
11859
  if (startingBaseFeeBps <= endingBaseFeeBps) {
@@ -11869,7 +11869,6 @@ function getFeeMarketCapSchedulerParams(startingBaseFeeBps, endingBaseFeeBps, ba
11869
11869
  if (schedulerExpirationDuration == 0) {
11870
11870
  throw new Error("schedulerExpirationDuration must be greater than zero");
11871
11871
  }
11872
- const priceMultiple = endingMarketCap / startingMarketCap;
11873
11872
  const sqrtPriceStepBps = computeSqrtPriceStepBps(
11874
11873
  priceMultiple,
11875
11874
  numberOfPeriod
@@ -12006,8 +12005,7 @@ function getBaseFeeParams(baseFeeParams, tokenBDecimal, activationType) {
12006
12005
  startingFeeBps,
12007
12006
  endingFeeBps,
12008
12007
  numberOfPeriod,
12009
- startingMarketCap,
12010
- endingMarketCap,
12008
+ priceMultiple,
12011
12009
  schedulerExpirationDuration
12012
12010
  } = baseFeeParams.feeMarketCapSchedulerParam;
12013
12011
  return getFeeMarketCapSchedulerParams(
@@ -12015,8 +12013,7 @@ function getBaseFeeParams(baseFeeParams, tokenBDecimal, activationType) {
12015
12013
  endingFeeBps,
12016
12014
  baseFeeParams.baseFeeMode,
12017
12015
  numberOfPeriod,
12018
- startingMarketCap,
12019
- endingMarketCap,
12016
+ priceMultiple,
12020
12017
  schedulerExpirationDuration
12021
12018
  );
12022
12019
  }
@@ -13289,7 +13286,9 @@ var CpAmm = class {
13289
13286
  });
13290
13287
  const postInstruction = [];
13291
13288
  if (isLockLiquidity) {
13292
- const permanentLockIx = yield this._program.methods.permanentLockPosition(liquidityDelta).accountsPartial({
13289
+ const configState = yield this.fetchConfigState(config);
13290
+ const lockLiquidity = configState.collectFeeMode === 2 /* Compounding */ ? liquidityDelta.sub(DEAD_LIQUIDITY) : liquidityDelta;
13291
+ const permanentLockIx = yield this._program.methods.permanentLockPosition(lockLiquidity).accountsPartial({
13293
13292
  position,
13294
13293
  positionNftAccount,
13295
13294
  pool,
@@ -13388,7 +13387,8 @@ var CpAmm = class {
13388
13387
  });
13389
13388
  const postInstruction = [];
13390
13389
  if (isLockLiquidity) {
13391
- const permanentLockIx = yield this._program.methods.permanentLockPosition(liquidityDelta).accountsPartial({
13390
+ const lockLiquidity = collectFeeMode === 2 /* Compounding */ ? liquidityDelta.sub(DEAD_LIQUIDITY) : liquidityDelta;
13391
+ const permanentLockIx = yield this._program.methods.permanentLockPosition(lockLiquidity).accountsPartial({
13392
13392
  position,
13393
13393
  positionNftAccount,
13394
13394
  pool,
@@ -13494,7 +13494,8 @@ var CpAmm = class {
13494
13494
  });
13495
13495
  const postInstruction = [];
13496
13496
  if (isLockLiquidity) {
13497
- const permanentLockIx = yield this._program.methods.permanentLockPosition(liquidityDelta).accountsPartial({
13497
+ const lockLiquidity = collectFeeMode === 2 /* Compounding */ ? liquidityDelta.sub(DEAD_LIQUIDITY) : liquidityDelta;
13498
+ const permanentLockIx = yield this._program.methods.permanentLockPosition(lockLiquidity).accountsPartial({
13498
13499
  position,
13499
13500
  positionNftAccount,
13500
13501
  pool,