@meteora-ag/cp-amm-sdk 1.2.3 → 1.2.4-rc.0

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
@@ -8064,6 +8064,7 @@ function getUserRewardPending(poolState, positionState, rewardIndex, currentTime
8064
8064
  }
8065
8065
 
8066
8066
  // src/helpers/accountFilters.ts
8067
+ import { PublicKey as PublicKey5 } from "@solana/web3.js";
8067
8068
  var positionByPoolFilter = (pool) => {
8068
8069
  return {
8069
8070
  memcmp: {
@@ -8080,6 +8081,18 @@ var vestingByPositionFilter = (position) => {
8080
8081
  }
8081
8082
  };
8082
8083
  };
8084
+ function offsetBasedFilter(value, offset) {
8085
+ const valueKey = typeof value === "string" ? new PublicKey5(value) : value;
8086
+ return [
8087
+ {
8088
+ memcmp: {
8089
+ offset,
8090
+ bytes: valueKey.toBase58(),
8091
+ encoding: "base58"
8092
+ }
8093
+ }
8094
+ ];
8095
+ }
8083
8096
 
8084
8097
  // src/helpers/token2022.ts
8085
8098
  import { BN as BN3 } from "@coral-xyz/anchor";
@@ -9808,11 +9821,11 @@ function validateFeeFraction(numerator, denominator) {
9808
9821
  }
9809
9822
 
9810
9823
  // src/helpers/common.ts
9811
- import { PublicKey as PublicKey5 } from "@solana/web3.js";
9824
+ import { PublicKey as PublicKey6 } from "@solana/web3.js";
9812
9825
  import BN15 from "bn.js";
9813
9826
  import Decimal4 from "decimal.js";
9814
9827
  function hasPartner(poolState) {
9815
- return !poolState.partner.equals(PublicKey5.default);
9828
+ return !poolState.partner.equals(PublicKey6.default);
9816
9829
  }
9817
9830
  function getCurrentPoint(connection, activationType) {
9818
9831
  return __async(this, null, function* () {
@@ -10551,6 +10564,18 @@ var CpAmm = class {
10551
10564
  return poolState;
10552
10565
  });
10553
10566
  }
10567
+ /**
10568
+ * Fetches all Pool states by tokenAMint.
10569
+ * @param tokenAMint - Public key of the tokenA mint.
10570
+ * @returns Array of matched pool accounts and their state.
10571
+ */
10572
+ fetchPoolStatesByTokenAMint(tokenAMint) {
10573
+ return __async(this, null, function* () {
10574
+ const filters = offsetBasedFilter(tokenAMint, 168);
10575
+ const pools = yield this._program.account.pool.all(filters);
10576
+ return pools;
10577
+ });
10578
+ }
10554
10579
  /**
10555
10580
  * Fetches the Position state.
10556
10581
  * @param position - Public key of the position.
@@ -11615,6 +11640,82 @@ var CpAmm = class {
11615
11640
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
11616
11641
  });
11617
11642
  }
11643
+ /**
11644
+ * Builds a transaction to remove liquidity from a position.
11645
+ * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
11646
+ * @returns Transaction builder.
11647
+ */
11648
+ removeLiquidity2(params) {
11649
+ return __async(this, null, function* () {
11650
+ const {
11651
+ owner,
11652
+ receiver,
11653
+ feePayer,
11654
+ pool,
11655
+ position,
11656
+ positionNftAccount,
11657
+ liquidityDelta,
11658
+ tokenAAmountThreshold,
11659
+ tokenBAmountThreshold,
11660
+ tokenAMint,
11661
+ tokenBMint,
11662
+ tokenAVault,
11663
+ tokenBVault,
11664
+ tokenAProgram,
11665
+ tokenBProgram,
11666
+ vestings
11667
+ } = params;
11668
+ const {
11669
+ tokenAAta: tokenAAccount,
11670
+ tokenBAta: tokenBAccount,
11671
+ instructions: preInstructions
11672
+ } = yield this.prepareTokenAccounts({
11673
+ payer: feePayer,
11674
+ tokenAOwner: receiver,
11675
+ tokenBOwner: receiver,
11676
+ tokenAMint,
11677
+ tokenBMint,
11678
+ tokenAProgram,
11679
+ tokenBProgram
11680
+ });
11681
+ const postInstructions = [];
11682
+ if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
11683
+ NATIVE_MINT2.toBase58()
11684
+ )) {
11685
+ const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
11686
+ closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
11687
+ }
11688
+ if (vestings.length > 0) {
11689
+ const refreshVestingInstruction = yield this.buildRefreshVestingInstruction({
11690
+ owner,
11691
+ position,
11692
+ positionNftAccount,
11693
+ pool,
11694
+ vestingAccounts: vestings.map((item) => item.account)
11695
+ });
11696
+ refreshVestingInstruction && preInstructions.push(refreshVestingInstruction);
11697
+ }
11698
+ return yield this._program.methods.removeLiquidity({
11699
+ liquidityDelta,
11700
+ tokenAAmountThreshold,
11701
+ tokenBAmountThreshold
11702
+ }).accountsPartial({
11703
+ poolAuthority: this.poolAuthority,
11704
+ pool,
11705
+ position,
11706
+ positionNftAccount,
11707
+ owner,
11708
+ tokenAAccount,
11709
+ tokenBAccount,
11710
+ tokenAMint,
11711
+ tokenBMint,
11712
+ tokenAVault,
11713
+ tokenBVault,
11714
+ tokenAProgram,
11715
+ tokenBProgram
11716
+ }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
11717
+ });
11718
+ }
11618
11719
  /**
11619
11720
  * Builds a transaction to remove liquidity from a position.
11620
11721
  * @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
@@ -12831,6 +12932,7 @@ export {
12831
12932
  isVestingComplete,
12832
12933
  isZeroRateLimiter,
12833
12934
  mulDiv,
12935
+ offsetBasedFilter,
12834
12936
  parseFeeSchedulerSecondFactor,
12835
12937
  parseRateLimiterSecondFactor,
12836
12938
  positionByPoolFilter,