@meteora-ag/cp-amm-sdk 1.0.1-rc.26 → 1.0.1-rc.28

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
@@ -6372,6 +6372,38 @@ var MAX_SQRT_PRICE = new BN("79226673521066979257578248091");
6372
6372
  var MIN_CU_BUFFER = 5e4;
6373
6373
  var MAX_CU_BUFFER = 2e5;
6374
6374
 
6375
+ // src/types.ts
6376
+ var Rounding = /* @__PURE__ */ ((Rounding2) => {
6377
+ Rounding2[Rounding2["Up"] = 0] = "Up";
6378
+ Rounding2[Rounding2["Down"] = 1] = "Down";
6379
+ return Rounding2;
6380
+ })(Rounding || {});
6381
+ var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
6382
+ ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
6383
+ ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
6384
+ return ActivationPoint2;
6385
+ })(ActivationPoint || {});
6386
+ var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
6387
+ FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
6388
+ FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
6389
+ return FeeSchedulerMode2;
6390
+ })(FeeSchedulerMode || {});
6391
+ var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode3) => {
6392
+ CollectFeeMode3[CollectFeeMode3["BothToken"] = 0] = "BothToken";
6393
+ CollectFeeMode3[CollectFeeMode3["OnlyB"] = 1] = "OnlyB";
6394
+ return CollectFeeMode3;
6395
+ })(CollectFeeMode || {});
6396
+ var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
6397
+ TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
6398
+ TradeDirection2[TradeDirection2["BtoA"] = 1] = "BtoA";
6399
+ return TradeDirection2;
6400
+ })(TradeDirection || {});
6401
+ var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
6402
+ ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
6403
+ ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
6404
+ return ActivationType2;
6405
+ })(ActivationType || {});
6406
+
6375
6407
  // src/pda.ts
6376
6408
  import { PublicKey as PublicKey2 } from "@solana/web3.js";
6377
6409
  function getFirstKey(key1, key2) {
@@ -6590,38 +6622,6 @@ function getAllNftByUser(_0, _1) {
6590
6622
  // src/helpers/fee.ts
6591
6623
  import { BN as BN5 } from "@coral-xyz/anchor";
6592
6624
 
6593
- // src/types.ts
6594
- var Rounding = /* @__PURE__ */ ((Rounding2) => {
6595
- Rounding2[Rounding2["Up"] = 0] = "Up";
6596
- Rounding2[Rounding2["Down"] = 1] = "Down";
6597
- return Rounding2;
6598
- })(Rounding || {});
6599
- var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
6600
- ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
6601
- ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
6602
- return ActivationPoint2;
6603
- })(ActivationPoint || {});
6604
- var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
6605
- FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
6606
- FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
6607
- return FeeSchedulerMode2;
6608
- })(FeeSchedulerMode || {});
6609
- var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode3) => {
6610
- CollectFeeMode3[CollectFeeMode3["BothToken"] = 0] = "BothToken";
6611
- CollectFeeMode3[CollectFeeMode3["OnlyB"] = 1] = "OnlyB";
6612
- return CollectFeeMode3;
6613
- })(CollectFeeMode || {});
6614
- var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
6615
- TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
6616
- TradeDirection2[TradeDirection2["BtoA"] = 1] = "BtoA";
6617
- return TradeDirection2;
6618
- })(TradeDirection || {});
6619
- var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
6620
- ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
6621
- ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
6622
- return ActivationType2;
6623
- })(ActivationType || {});
6624
-
6625
6625
  // src/math/feeMath.ts
6626
6626
  import { BN as BN2 } from "@coral-xyz/anchor";
6627
6627
  var MAX_EXPONENTIAL = new BN2(524288);
@@ -7652,6 +7652,123 @@ var CpAmm = class {
7652
7652
  };
7653
7653
  });
7654
7654
  }
7655
+ /**
7656
+ * Calculates the deposit quote for liquidity pool.
7657
+ *
7658
+ * @param {GetDepositQuoteParams} params - The parameters for calculating the deposit quote.
7659
+ *
7660
+ * @returns {Promise<Object>} Deposit quote results
7661
+ * @returns {BN} returns.actualInputAmount - The actual amount used as input (after deducting transfer fees).
7662
+ * @returns {BN} returns.outputAmount - The calculated corresponding amount of the other token.
7663
+ * @returns {BN} returns.liquidityDelta - The amount of liquidity that will be added to the pool.
7664
+ */
7665
+ getDepositQuote(params) {
7666
+ return __async(this, null, function* () {
7667
+ const {
7668
+ inAmount,
7669
+ isTokenA,
7670
+ inputTokenInfo,
7671
+ outputTokenInfo,
7672
+ minSqrtPrice,
7673
+ maxSqrtPrice,
7674
+ sqrtPrice
7675
+ } = params;
7676
+ const actualAmountIn = inputTokenInfo ? inAmount.sub(
7677
+ calculateTransferFeeIncludedAmount(
7678
+ inAmount,
7679
+ inputTokenInfo.mint,
7680
+ inputTokenInfo.currentEpoch
7681
+ ).transferFee
7682
+ ) : inAmount;
7683
+ const { liquidityDelta, rawAmount } = isTokenA ? {
7684
+ liquidityDelta: getLiquidityDeltaFromAmountA(
7685
+ actualAmountIn,
7686
+ sqrtPrice,
7687
+ maxSqrtPrice
7688
+ ),
7689
+ rawAmount: (delta) => getAmountBFromLiquidityDelta(
7690
+ delta,
7691
+ sqrtPrice,
7692
+ minSqrtPrice,
7693
+ 0 /* Up */
7694
+ )
7695
+ } : {
7696
+ liquidityDelta: getLiquidityDeltaFromAmountB(
7697
+ actualAmountIn,
7698
+ minSqrtPrice,
7699
+ sqrtPrice
7700
+ ),
7701
+ rawAmount: (delta) => getAmountAFromLiquidityDelta(
7702
+ delta,
7703
+ sqrtPrice,
7704
+ maxSqrtPrice,
7705
+ 0 /* Up */
7706
+ )
7707
+ };
7708
+ const rawOutputAmount = new BN9(rawAmount(liquidityDelta));
7709
+ const outputAmount = outputTokenInfo ? calculateTransferFeeIncludedAmount(
7710
+ rawOutputAmount,
7711
+ outputTokenInfo.mint,
7712
+ outputTokenInfo.currentEpoch
7713
+ ).amount : rawOutputAmount;
7714
+ return {
7715
+ actualInputAmount: actualAmountIn,
7716
+ consumedInputAmount: inAmount,
7717
+ liquidityDelta,
7718
+ outputAmount
7719
+ };
7720
+ });
7721
+ }
7722
+ /**
7723
+ * Calculates the withdrawal quote for removing liquidity from a concentrated liquidity pool.
7724
+ *
7725
+ * @param {GetWithdrawQuoteParams} params - The parameters for calculating the withdraw quote
7726
+ *
7727
+ * @param {Object|null} params.tokenATokenInfo - must provide if token a is token2022
7728
+ * @param {Object|null} params.tokenBTokenInfo - must provide if token b is token2022
7729
+ *
7730
+ * @returns {Promise<Object>} Withdrawal quote results
7731
+ * @returns {BN} returns.liquidityDelta - The amount of liquidity that will be removed from the pool
7732
+ * @returns {BN} returns.outAmountA - The calculated amount of token A to be received (after deducting transfer fees)
7733
+ * @returns {BN} returns.outAmountB - The calculated amount of token B to be received (after deducting transfer fees)
7734
+ */
7735
+ getWithdrawQuote(params) {
7736
+ return __async(this, null, function* () {
7737
+ const {
7738
+ liquidityDelta,
7739
+ sqrtPrice,
7740
+ maxSqrtPrice,
7741
+ minSqrtPrice,
7742
+ tokenATokenInfo,
7743
+ tokenBTokenInfo
7744
+ } = params;
7745
+ const amountA = getAmountAFromLiquidityDelta(
7746
+ liquidityDelta,
7747
+ sqrtPrice,
7748
+ maxSqrtPrice,
7749
+ 1 /* Down */
7750
+ );
7751
+ const amountB = getAmountBFromLiquidityDelta(
7752
+ liquidityDelta,
7753
+ sqrtPrice,
7754
+ minSqrtPrice,
7755
+ 1 /* Down */
7756
+ );
7757
+ return {
7758
+ liquidityDelta,
7759
+ outAmountA: tokenATokenInfo ? calculateTransferFeeExcludedAmount(
7760
+ new BN9(amountA),
7761
+ tokenATokenInfo.mint,
7762
+ tokenATokenInfo.currentEpoch
7763
+ ).amount : new BN9(amountA),
7764
+ outAmountB: tokenBTokenInfo ? calculateTransferFeeExcludedAmount(
7765
+ new BN9(amountB),
7766
+ tokenBTokenInfo.mint,
7767
+ tokenBTokenInfo.currentEpoch
7768
+ ).amount : new BN9(amountB)
7769
+ };
7770
+ });
7771
+ }
7655
7772
  /**
7656
7773
  * Computes the liquidity delta based on the provided token amounts and pool state.
7657
7774
  *
@@ -8049,9 +8166,11 @@ var CpAmm = class {
8049
8166
  tokenBAmountThreshold
8050
8167
  });
8051
8168
  const transaction = new Transaction();
8052
- transaction.add(...preInstructions);
8053
- transaction.add(addLiquidityInstruction);
8054
- transaction.add(...postInstructions);
8169
+ transaction.add(
8170
+ ...preInstructions.length > 0 ? preInstructions : [],
8171
+ addLiquidityInstruction,
8172
+ ...postInstructions.length > 0 ? postInstructions : []
8173
+ );
8055
8174
  return transaction;
8056
8175
  });
8057
8176
  }
@@ -8183,9 +8302,11 @@ var CpAmm = class {
8183
8302
  tokenBProgram
8184
8303
  });
8185
8304
  const transaction = new Transaction();
8186
- transaction.add(...preInstructions);
8187
- transaction.add(removeAllLiquidityInstruction);
8188
- transaction.add(...postInstructions);
8305
+ transaction.add(
8306
+ ...preInstructions.length > 0 ? preInstructions : [],
8307
+ removeAllLiquidityInstruction,
8308
+ ...postInstructions.length > 0 ? postInstructions : []
8309
+ );
8189
8310
  return transaction;
8190
8311
  });
8191
8312
  }
@@ -8408,9 +8529,11 @@ var CpAmm = class {
8408
8529
  tokenBProgram
8409
8530
  });
8410
8531
  const transaction = new Transaction();
8411
- transaction.add(...preInstructions);
8412
- transaction.add(claimPositionFeeInstruction);
8413
- transaction.add(...postInstructions);
8532
+ transaction.add(
8533
+ ...preInstructions.length > 0 ? preInstructions : [],
8534
+ claimPositionFeeInstruction,
8535
+ ...postInstructions.length > 0 ? postInstructions : []
8536
+ );
8414
8537
  return transaction;
8415
8538
  });
8416
8539
  }
@@ -8486,7 +8609,9 @@ var CpAmm = class {
8486
8609
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
8487
8610
  }
8488
8611
  const transaction = new Transaction();
8489
- transaction.add(...preInstructions);
8612
+ if (preInstructions.length > 0) {
8613
+ transaction.add(...preInstructions);
8614
+ }
8490
8615
  const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
8491
8616
  owner,
8492
8617
  poolAuthority,
@@ -8530,6 +8655,9 @@ var CpAmm = class {
8530
8655
  positionNftAccount
8531
8656
  });
8532
8657
  transaction.add(closePositionInstruction);
8658
+ if (postInstructions.length > 0) {
8659
+ transaction.add(...postInstructions);
8660
+ }
8533
8661
  return transaction;
8534
8662
  });
8535
8663
  }
@@ -8594,7 +8722,9 @@ var CpAmm = class {
8594
8722
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
8595
8723
  }
8596
8724
  const transaction = new Transaction();
8597
- transaction.add(...preInstructions);
8725
+ if (preInstructions.length > 0) {
8726
+ transaction.add(...preInstructions);
8727
+ }
8598
8728
  const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
8599
8729
  owner,
8600
8730
  poolAuthority,
@@ -8656,6 +8786,9 @@ var CpAmm = class {
8656
8786
  positionNftAccount: positionBNftAccount
8657
8787
  });
8658
8788
  transaction.add(closePositionInstruction);
8789
+ if (postInstructions.length > 0) {
8790
+ transaction.add(...postInstructions);
8791
+ }
8659
8792
  return transaction;
8660
8793
  });
8661
8794
  }