@stabbleorg/mclmm-sdk 0.3.3 → 0.4.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/lib/index.mjs CHANGED
@@ -5733,6 +5733,7 @@ import Decimal2 from "decimal.js";
5733
5733
  // src/constants.ts
5734
5734
  import BN from "bn.js";
5735
5735
  var STABBLE_CLMM_PROGRAM_ID = "6dMXqGZ3ga2dikrYS9ovDXgHGh5RUsb2RTUj6hrQXhk6";
5736
+ var STABBLE_CLMM_QAS_PROGRAM_ID = "8896VTm3Z3g8PuktiDdW9JLxZP1ww2r5c9Tz5AbaBjAJ";
5736
5737
  var METADATA_PROGRAM_ID = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
5737
5738
  var SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
5738
5739
  var SYSVAR_RENT_PROGRAM_ID = "SysvarRent111111111111111111111111111111111";
@@ -6202,11 +6203,12 @@ var PdaUtils = class {
6202
6203
  * @param ammConfig - AMM config address
6203
6204
  * @param tokenMintA - Token A mint address
6204
6205
  * @param tokenMintB - Token B mint address
6206
+ * @param programId - Program address (defaults to production)
6205
6207
  * @returns Pool state PDA
6206
6208
  */
6207
- static async getPoolStatePda(ammConfig, tokenMintA, tokenMintB) {
6209
+ static async getPoolStatePda(ammConfig, tokenMintA, tokenMintB, programId = STABBLE_CLMM_PROGRAM_ID) {
6208
6210
  return await getProgramDerivedAddress10({
6209
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6211
+ programAddress: programId,
6210
6212
  seeds: [
6211
6213
  PDA_SEEDS.POOL_STATE,
6212
6214
  addressEncoder.encode(ammConfig),
@@ -6218,22 +6220,24 @@ var PdaUtils = class {
6218
6220
  /**
6219
6221
  * Derive AMM config PDA
6220
6222
  * @param index - Config index
6223
+ * @param programId - Program address (defaults to production)
6221
6224
  * @returns AMM config PDA
6222
6225
  */
6223
- static async getAmmConfigPda(index) {
6226
+ static async getAmmConfigPda(index, programId = STABBLE_CLMM_PROGRAM_ID) {
6224
6227
  return await getProgramDerivedAddress10({
6225
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6228
+ programAddress: programId,
6226
6229
  seeds: [PDA_SEEDS.AMM_CONFIG, getU16Encoder7().encode(index)]
6227
6230
  });
6228
6231
  }
6229
6232
  /**
6230
6233
  * Derive position state PDA
6231
6234
  * @param nftMint - Position NFT mint address
6235
+ * @param programId - Program address (defaults to production)
6232
6236
  * @returns Position state PDA
6233
6237
  */
6234
- static async getPositionStatePda(nftMint) {
6238
+ static async getPositionStatePda(nftMint, programId = STABBLE_CLMM_PROGRAM_ID) {
6235
6239
  return await getProgramDerivedAddress10({
6236
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6240
+ programAddress: programId,
6237
6241
  seeds: [PDA_SEEDS.POSITION_STATE, addressEncoder.encode(nftMint)]
6238
6242
  });
6239
6243
  }
@@ -6241,11 +6245,12 @@ var PdaUtils = class {
6241
6245
  * Derive tick array state PDA
6242
6246
  * @param poolState - Pool state address
6243
6247
  * @param startTickIndex - Starting tick index of the array
6248
+ * @param programId - Program address (defaults to production)
6244
6249
  * @returns Tick array state PDA
6245
6250
  */
6246
- static async getTickArrayStatePda(poolState, startTickIndex) {
6251
+ static async getTickArrayStatePda(poolState, startTickIndex, programId = STABBLE_CLMM_PROGRAM_ID) {
6247
6252
  return await getProgramDerivedAddress10({
6248
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6253
+ programAddress: programId,
6249
6254
  seeds: [
6250
6255
  PDA_SEEDS.TICK_ARRAY_STATE,
6251
6256
  addressEncoder.encode(poolState),
@@ -6256,32 +6261,34 @@ var PdaUtils = class {
6256
6261
  /**
6257
6262
  * Derive observation state PDA
6258
6263
  * @param poolState - Pool state address
6264
+ * @param programId - Program address (defaults to production)
6259
6265
  * @returns Observation state PDA
6260
6266
  */
6261
- static async getObservationStatePda(poolState) {
6267
+ static async getObservationStatePda(poolState, programId = STABBLE_CLMM_PROGRAM_ID) {
6262
6268
  return await getProgramDerivedAddress10({
6263
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6269
+ programAddress: programId,
6264
6270
  seeds: [PDA_SEEDS.OBSERVATION_STATE, addressEncoder.encode(poolState)]
6265
6271
  });
6266
6272
  }
6267
- static async getPoolVaultIdPda(poolAddress, vaultAddress) {
6273
+ static async getPoolVaultIdPda(poolAddress, vaultAddress, programId = STABBLE_CLMM_PROGRAM_ID) {
6268
6274
  return await getProgramDerivedAddress10({
6269
6275
  seeds: [
6270
6276
  PDA_SEEDS.POOL_VAULT,
6271
6277
  addressEncoder.encode(poolAddress),
6272
6278
  addressEncoder.encode(vaultAddress)
6273
6279
  ],
6274
- programAddress: STABBLE_CLMM_PROGRAM_ID
6280
+ programAddress: programId
6275
6281
  });
6276
6282
  }
6277
6283
  /**
6278
6284
  * Derive tick array bitmap extension PDA
6279
6285
  * @param poolState - Pool state address
6286
+ * @param programId - Program address (defaults to production)
6280
6287
  * @returns Tick array bitmap extension PDA
6281
6288
  */
6282
- static async getTickArrayBitmapExtensionPda(poolState) {
6289
+ static async getTickArrayBitmapExtensionPda(poolState, programId = STABBLE_CLMM_PROGRAM_ID) {
6283
6290
  return await getProgramDerivedAddress10({
6284
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6291
+ programAddress: programId,
6285
6292
  seeds: [PDA_SEEDS.BITMAP_EXTENSION, addressEncoder.encode(poolState)]
6286
6293
  });
6287
6294
  }
@@ -6304,9 +6311,10 @@ var PdaUtils = class {
6304
6311
  * @param tickUpper - Upper tick of range
6305
6312
  * @param tickSpacing - Tick spacing of the pool
6306
6313
  * @param tickCurrent - Current pool tick
6314
+ * @param programId - Program address (defaults to production)
6307
6315
  * @returns Array of tick array PDAs
6308
6316
  */
6309
- static async getTickArrayPdasForRange(poolState, tickLower, tickUpper, tickSpacing, tickCurrent) {
6317
+ static async getTickArrayPdasForRange(poolState, tickLower, tickUpper, tickSpacing, tickCurrent, programId = STABBLE_CLMM_PROGRAM_ID) {
6310
6318
  const startIndexLower = this.getTickArrayStartIndex(tickLower, tickSpacing);
6311
6319
  const startIndexUpper = this.getTickArrayStartIndex(tickUpper, tickSpacing);
6312
6320
  const startIndexCurrent = this.getTickArrayStartIndex(
@@ -6320,7 +6328,7 @@ var PdaUtils = class {
6320
6328
  ]);
6321
6329
  return await Promise.all(
6322
6330
  Array.from(indices).map(
6323
- (index) => this.getTickArrayStatePda(poolState, index)
6331
+ (index) => this.getTickArrayStatePda(poolState, index, programId)
6324
6332
  )
6325
6333
  );
6326
6334
  }
@@ -6329,11 +6337,12 @@ var PdaUtils = class {
6329
6337
  * @param poolState - Pool state address
6330
6338
  * @param tickLowerIndex - Lower tick index
6331
6339
  * @param tickUpperIndex - Upper tick index
6340
+ * @param programId - Program address (defaults to production)
6332
6341
  * @returns Protocol position state PDA
6333
6342
  */
6334
- static async getProtocolPositionStatePda(poolState, tickLowerIndex, tickUpperIndex) {
6343
+ static async getProtocolPositionStatePda(poolState, tickLowerIndex, tickUpperIndex, programId = STABBLE_CLMM_PROGRAM_ID) {
6335
6344
  return await getProgramDerivedAddress10({
6336
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6345
+ programAddress: programId,
6337
6346
  seeds: [
6338
6347
  PDA_SEEDS.POSITION_STATE,
6339
6348
  addressEncoder.encode(poolState),
@@ -6345,11 +6354,12 @@ var PdaUtils = class {
6345
6354
  /**
6346
6355
  * Derive operation state PDA
6347
6356
  * @param poolState - Pool state address
6357
+ * @param programId - Program address (defaults to production)
6348
6358
  * @returns Operation state PDA
6349
6359
  */
6350
- static async getOperationStatePda(poolState) {
6360
+ static async getOperationStatePda(poolState, programId = STABBLE_CLMM_PROGRAM_ID) {
6351
6361
  return await getProgramDerivedAddress10({
6352
- programAddress: STABBLE_CLMM_PROGRAM_ID,
6362
+ programAddress: programId,
6353
6363
  seeds: [PDA_SEEDS.OPERATION, addressEncoder.encode(poolState)]
6354
6364
  });
6355
6365
  }
@@ -6368,7 +6378,7 @@ async function getMetadataPda(mint) {
6368
6378
  // src/utils/tickQuery.ts
6369
6379
  var FETCH_TICKARRAY_COUNT = 15;
6370
6380
  var TickQuery = class _TickQuery {
6371
- static async getTickArrays(rpc, poolId, tickCurrent, tickSpacing, tickArrayBitmapArray, exTickArrayBitmap) {
6381
+ static async getTickArrays(rpc, poolId, tickCurrent, tickSpacing, tickArrayBitmapArray, exTickArrayBitmap, programId = STABBLE_CLMM_PROGRAM_ID) {
6372
6382
  const tickArraysToFetch = [];
6373
6383
  const currentTickArrayStartIndex = TickUtils.getTickArrayStartIndexByTick(
6374
6384
  tickCurrent,
@@ -6384,7 +6394,8 @@ var TickQuery = class _TickQuery {
6384
6394
  for (let i = 0; i < startIndexArray.length; i++) {
6385
6395
  const [tickArrayAddress] = await PdaUtils.getTickArrayStatePda(
6386
6396
  poolId,
6387
- startIndexArray[i]
6397
+ startIndexArray[i],
6398
+ programId
6388
6399
  );
6389
6400
  tickArraysToFetch.push(tickArrayAddress);
6390
6401
  }
@@ -6439,7 +6450,7 @@ var TickQuery = class _TickQuery {
6439
6450
  * @param zeroForOne - Search direction
6440
6451
  * @returns First initialized tick, tick array address, and start index
6441
6452
  */
6442
- static async firstInitializedTickInOneArray(poolId, tickArray, zeroForOne) {
6453
+ static async firstInitializedTickInOneArray(poolId, tickArray, zeroForOne, programId = STABBLE_CLMM_PROGRAM_ID) {
6443
6454
  let nextInitializedTick = void 0;
6444
6455
  if (zeroForOne) {
6445
6456
  for (let i = TICK_ARRAY_SIZE - 1; i >= 0; i--) {
@@ -6460,7 +6471,8 @@ var TickQuery = class _TickQuery {
6460
6471
  }
6461
6472
  const [tickArrayAddress] = await PdaUtils.getTickArrayStatePda(
6462
6473
  poolId,
6463
- tickArray.data.startTickIndex
6474
+ tickArray.data.startTickIndex,
6475
+ programId
6464
6476
  );
6465
6477
  return {
6466
6478
  nextTick: nextInitializedTick,
@@ -6478,7 +6490,7 @@ var TickQuery = class _TickQuery {
6478
6490
  * @param zeroForOne - Search direction
6479
6491
  * @returns Next initialized tick info
6480
6492
  */
6481
- static async nextInitializedTickInOneArray(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne) {
6493
+ static async nextInitializedTickInOneArray(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne, programId = STABBLE_CLMM_PROGRAM_ID) {
6482
6494
  const startIndex = TickUtils.getTickArrayStartIndexByTick(
6483
6495
  tickIndex,
6484
6496
  tickSpacing
@@ -6517,7 +6529,8 @@ var TickQuery = class _TickQuery {
6517
6529
  }
6518
6530
  const [tickArrayAddress] = await PdaUtils.getTickArrayStatePda(
6519
6531
  poolId,
6520
- startIndex
6532
+ startIndex,
6533
+ programId
6521
6534
  );
6522
6535
  return {
6523
6536
  initializedTick: nextInitializedTick,
@@ -6535,7 +6548,7 @@ var TickQuery = class _TickQuery {
6535
6548
  * @param zeroForOne - Search direction
6536
6549
  * @returns Next initialized tick info
6537
6550
  */
6538
- static async nextInitializedTick(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne) {
6551
+ static async nextInitializedTick(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne, programId = STABBLE_CLMM_PROGRAM_ID) {
6539
6552
  let {
6540
6553
  initializedTick: nextTick,
6541
6554
  tickArrayAddress,
@@ -6545,7 +6558,8 @@ var TickQuery = class _TickQuery {
6545
6558
  tickArrayCache,
6546
6559
  tickIndex,
6547
6560
  tickSpacing,
6548
- zeroForOne
6561
+ zeroForOne,
6562
+ programId
6549
6563
  );
6550
6564
  while (nextTick === void 0 || nextTick.liquidityGross <= 0n) {
6551
6565
  const nextArrayStartIndex = zeroForOne ? tickArrayStartTickIndex - this.tickCount(tickSpacing) : tickArrayStartTickIndex + this.tickCount(tickSpacing);
@@ -6562,7 +6576,8 @@ var TickQuery = class _TickQuery {
6562
6576
  const result = await this.firstInitializedTickInOneArray(
6563
6577
  poolId,
6564
6578
  cachedTickArray,
6565
- zeroForOne
6579
+ zeroForOne,
6580
+ programId
6566
6581
  );
6567
6582
  nextTick = result.nextTick;
6568
6583
  tickArrayAddress = result.tickArrayAddress;
@@ -8405,7 +8420,9 @@ function getApisFromEndpoint(rpc) {
8405
8420
  var Clmm = class {
8406
8421
  constructor(config) {
8407
8422
  this.config = config;
8423
+ this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
8408
8424
  }
8425
+ programId;
8409
8426
  /**
8410
8427
  * Create a new AMM configuration
8411
8428
  * @param params - Configuration parameters
@@ -8420,7 +8437,7 @@ var Clmm = class {
8420
8437
  protocolFeeRate,
8421
8438
  fundFeeRate
8422
8439
  } = params;
8423
- const ammConfigPda = await PdaUtils.getAmmConfigPda(index);
8440
+ const ammConfigPda = await PdaUtils.getAmmConfigPda(index, this.programId);
8424
8441
  const instruction = await getCreateAmmConfigInstructionAsync({
8425
8442
  owner,
8426
8443
  ammConfig: ammConfigPda[0],
@@ -8499,7 +8516,9 @@ async function getToken(rpc, tokenAccount) {
8499
8516
  var PoolManager = class {
8500
8517
  constructor(config) {
8501
8518
  this.config = config;
8519
+ this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
8502
8520
  }
8521
+ programId;
8503
8522
  /**
8504
8523
  * Make create pool instructions
8505
8524
  * @param params - Pool creation parameters
@@ -8535,12 +8554,13 @@ var PoolManager = class {
8535
8554
  const [poolPda] = await PdaUtils.getPoolStatePda(
8536
8555
  ammConfigId,
8537
8556
  token0,
8538
- token1
8557
+ token1,
8558
+ this.programId
8539
8559
  );
8540
- const [observationPda] = await PdaUtils.getObservationStatePda(poolPda);
8541
- const [tickArrayBitmapPda] = await PdaUtils.getTickArrayBitmapExtensionPda(poolPda);
8542
- const [tokenVault0] = await PdaUtils.getPoolVaultIdPda(poolPda, token0);
8543
- const [tokenVault1] = await PdaUtils.getPoolVaultIdPda(poolPda, token1);
8560
+ const [observationPda] = await PdaUtils.getObservationStatePda(poolPda, this.programId);
8561
+ const [tickArrayBitmapPda] = await PdaUtils.getTickArrayBitmapExtensionPda(poolPda, this.programId);
8562
+ const [tokenVault0] = await PdaUtils.getPoolVaultIdPda(poolPda, token0, this.programId);
8563
+ const [tokenVault1] = await PdaUtils.getPoolVaultIdPda(poolPda, token1, this.programId);
8544
8564
  const instruction = await getCreatePoolInstructionAsync({
8545
8565
  poolCreator: owner,
8546
8566
  ammConfig: ammConfigId,
@@ -8585,7 +8605,7 @@ var PoolManager = class {
8585
8605
  protocolFeeRate,
8586
8606
  fundFeeRate
8587
8607
  } = params;
8588
- const ammConfigPda = await PdaUtils.getAmmConfigPda(index);
8608
+ const ammConfigPda = await PdaUtils.getAmmConfigPda(index, this.programId);
8589
8609
  const instruction = getCreateAmmConfigInstruction({
8590
8610
  owner,
8591
8611
  ammConfig: ammConfigPda[0],
@@ -8637,17 +8657,18 @@ var PoolManager = class {
8637
8657
  * @returns Pool information if found
8638
8658
  */
8639
8659
  async getPoolByTokenPairAndConfig(tokenA, tokenB, ammConfigIndex = 0) {
8640
- const ammConfigPda = await PdaUtils.getAmmConfigPda(ammConfigIndex);
8660
+ const ammConfigPda = await PdaUtils.getAmmConfigPda(ammConfigIndex, this.programId);
8641
8661
  const poolPda = await PdaUtils.getPoolStatePda(
8642
8662
  ammConfigPda[0],
8643
8663
  tokenA,
8644
- tokenB
8664
+ tokenB,
8665
+ this.programId
8645
8666
  );
8646
8667
  return this.getPool(poolPda[0]);
8647
8668
  }
8648
8669
  async getAllPools(rpc) {
8649
8670
  try {
8650
- let accounts = await rpc.getProgramAccounts(STABBLE_CLMM_PROGRAM_ID, {
8671
+ let accounts = await rpc.getProgramAccounts(this.programId, {
8651
8672
  commitment: "finalized",
8652
8673
  encoding: "base64",
8653
8674
  filters: [
@@ -8777,7 +8798,9 @@ var TOKEN_ACCOUNT_SIZE = 165n;
8777
8798
  var PositionManager = class {
8778
8799
  constructor(config) {
8779
8800
  this.config = config;
8801
+ this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
8780
8802
  }
8803
+ programId;
8781
8804
  buildWrapSolInstructions(params) {
8782
8805
  const { payer, ata, owner, amount } = params;
8783
8806
  return [
@@ -8879,7 +8902,8 @@ var PositionManager = class {
8879
8902
  poolAccount.data.tickSpacing
8880
8903
  );
8881
8904
  const [positionStatePda] = await PdaUtils.getPositionStatePda(
8882
- nftMintAccount.address
8905
+ nftMintAccount.address,
8906
+ this.programId
8883
8907
  );
8884
8908
  const [metadataPda] = await getMetadataPda(nftMintAccount.address);
8885
8909
  const [positionNftAccountPda] = await findAssociatedTokenPda({
@@ -8890,7 +8914,8 @@ var PositionManager = class {
8890
8914
  const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
8891
8915
  poolAccount.address,
8892
8916
  tickLower,
8893
- tickUpper
8917
+ tickUpper,
8918
+ this.programId
8894
8919
  );
8895
8920
  const instruction = await getOpenPositionWithToken22NftInstructionAsync({
8896
8921
  payer: ownerInfo.feePayer,
@@ -8965,14 +8990,17 @@ var PositionManager = class {
8965
8990
  );
8966
8991
  const [tickArrayLower] = await PdaUtils.getTickArrayStatePda(
8967
8992
  poolAccount.address,
8968
- tickArrayLowerStartIndex
8993
+ tickArrayLowerStartIndex,
8994
+ this.programId
8969
8995
  );
8970
8996
  const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
8971
8997
  poolAccount.address,
8972
- tickArrayUpperStartIndex
8998
+ tickArrayUpperStartIndex,
8999
+ this.programId
8973
9000
  );
8974
9001
  const [positionStatePda] = await PdaUtils.getPositionStatePda(
8975
- nftMintAccount.address
9002
+ nftMintAccount.address,
9003
+ this.programId
8976
9004
  );
8977
9005
  const [metadataPda] = await getMetadataPda(nftMintAccount.address);
8978
9006
  const [positionNftAccountPda] = await findAssociatedTokenPda({
@@ -8983,7 +9011,8 @@ var PositionManager = class {
8983
9011
  const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
8984
9012
  poolAccount.address,
8985
9013
  tickLower,
8986
- tickUpper
9014
+ tickUpper,
9015
+ this.programId
8987
9016
  );
8988
9017
  const amount0Max = base === "MintA" ? baseAmount : otherAmountMax;
8989
9018
  const amount1Max = base === "MintA" ? otherAmountMax : baseAmount;
@@ -8991,7 +9020,7 @@ var PositionManager = class {
8991
9020
  poolAccount.data.tickSpacing,
8992
9021
  [tickArrayLowerStartIndex, tickArrayUpperStartIndex]
8993
9022
  );
8994
- const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolAccount.address) : void 0;
9023
+ const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolAccount.address, this.programId) : void 0;
8995
9024
  const remAccounts = extBitmapAccount ? [{ address: extBitmapAccount[0], role: AccountRole2.WRITABLE }] : [];
8996
9025
  let wrapSolInstructions = [];
8997
9026
  if (poolAccount.data.tokenMint0.toString() === NATIVE_MINT.toString()) {
@@ -9067,7 +9096,8 @@ var PositionManager = class {
9067
9096
  amountMaxB
9068
9097
  } = params;
9069
9098
  const [personalPosition] = await PdaUtils.getPositionStatePda(
9070
- ownerPosition.nftMint
9099
+ ownerPosition.nftMint,
9100
+ this.programId
9071
9101
  );
9072
9102
  const [positionNftAccount] = await findAssociatedTokenPda({
9073
9103
  mint: ownerPosition.nftMint,
@@ -9077,27 +9107,30 @@ var PositionManager = class {
9077
9107
  const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
9078
9108
  poolState.address,
9079
9109
  ownerPosition.tickLowerIndex,
9080
- ownerPosition.tickUpperIndex
9110
+ ownerPosition.tickUpperIndex,
9111
+ this.programId
9081
9112
  );
9082
9113
  const [tickArrayLower] = await PdaUtils.getTickArrayStatePda(
9083
9114
  poolState.address,
9084
9115
  PdaUtils.getTickArrayStartIndex(
9085
9116
  ownerPosition.tickLowerIndex,
9086
9117
  poolState.data.tickSpacing
9087
- )
9118
+ ),
9119
+ this.programId
9088
9120
  );
9089
9121
  const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
9090
9122
  poolState.address,
9091
9123
  PdaUtils.getTickArrayStartIndex(
9092
9124
  ownerPosition.tickUpperIndex,
9093
9125
  poolState.data.tickSpacing
9094
- )
9126
+ ),
9127
+ this.programId
9095
9128
  );
9096
9129
  const isOverflow = PoolUtils.isOverflowDefaultTickArrayBitmap(
9097
9130
  poolState.data.tickSpacing,
9098
9131
  [ownerPosition.tickLowerIndex, ownerPosition.tickUpperIndex]
9099
9132
  );
9100
- const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address) : void 0;
9133
+ const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address, this.programId) : void 0;
9101
9134
  const remAccounts = extBitmapAccount ? [{ address: extBitmapAccount[0], role: AccountRole2.WRITABLE }] : [];
9102
9135
  const instruction = getIncreaseLiquidityV2Instruction({
9103
9136
  nftOwner: ownerInfo.wallet,
@@ -9155,7 +9188,8 @@ var PositionManager = class {
9155
9188
  } = params;
9156
9189
  const signers = [];
9157
9190
  const [personalPosition] = await PdaUtils.getPositionStatePda(
9158
- ownerPosition.nftMint
9191
+ ownerPosition.nftMint,
9192
+ this.programId
9159
9193
  );
9160
9194
  const [positionNftAccount] = await findAssociatedTokenPda({
9161
9195
  mint: ownerPosition.nftMint,
@@ -9165,27 +9199,30 @@ var PositionManager = class {
9165
9199
  const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
9166
9200
  poolState.address,
9167
9201
  ownerPosition.tickLowerIndex,
9168
- ownerPosition.tickUpperIndex
9202
+ ownerPosition.tickUpperIndex,
9203
+ this.programId
9169
9204
  );
9170
9205
  const [tickArrayLower] = await PdaUtils.getTickArrayStatePda(
9171
9206
  poolState.address,
9172
9207
  PdaUtils.getTickArrayStartIndex(
9173
9208
  ownerPosition.tickLowerIndex,
9174
9209
  poolState.data.tickSpacing
9175
- )
9210
+ ),
9211
+ this.programId
9176
9212
  );
9177
9213
  const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
9178
9214
  poolState.address,
9179
9215
  PdaUtils.getTickArrayStartIndex(
9180
9216
  ownerPosition.tickUpperIndex,
9181
9217
  poolState.data.tickSpacing
9182
- )
9218
+ ),
9219
+ this.programId
9183
9220
  );
9184
9221
  const isOverflow = PoolUtils.isOverflowDefaultTickArrayBitmap(
9185
9222
  poolState.data.tickSpacing,
9186
9223
  [ownerPosition.tickLowerIndex, ownerPosition.tickUpperIndex]
9187
9224
  );
9188
- const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address) : void 0;
9225
+ const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address, this.programId) : void 0;
9189
9226
  const remAccounts = extBitmapAccount ? [{ address: extBitmapAccount[0], role: AccountRole2.WRITABLE }] : [];
9190
9227
  const createRecipientAta0Ix = getCreateAssociatedTokenIdempotentInstruction(
9191
9228
  {
@@ -9268,7 +9305,8 @@ var PositionManager = class {
9268
9305
  async makeClosePositionInstructions(params) {
9269
9306
  const { ownerPosition, ownerInfo } = params;
9270
9307
  const [personalPosition] = await PdaUtils.getPositionStatePda(
9271
- ownerPosition.nftMint
9308
+ ownerPosition.nftMint,
9309
+ this.programId
9272
9310
  );
9273
9311
  const [positionNftAccount] = await findAssociatedTokenPda({
9274
9312
  mint: ownerPosition.nftMint,
@@ -9297,7 +9335,7 @@ var PositionManager = class {
9297
9335
  */
9298
9336
  async getPosition(positionMint) {
9299
9337
  try {
9300
- const positionStatePda = await PdaUtils.getPositionStatePda(positionMint);
9338
+ const positionStatePda = await PdaUtils.getPositionStatePda(positionMint, this.programId);
9301
9339
  const positionState = await fetchMaybePersonalPositionState(
9302
9340
  this.config.rpc,
9303
9341
  positionStatePda[0],
@@ -9378,11 +9416,11 @@ var PositionManager = class {
9378
9416
  };
9379
9417
  }
9380
9418
  /**
9381
- * Get all positions for a wallet
9419
+ * Get raw positions for a wallet (without pool-state enrichment)
9382
9420
  * @param wallet - Wallet address
9383
- * @returns Array of positions owned by the wallet
9421
+ * @returns Array of raw position states owned by the wallet
9384
9422
  */
9385
- async getPositionsForWallet(wallet) {
9423
+ async getRawPositionsForWallet(wallet) {
9386
9424
  try {
9387
9425
  const response22 = await this.config.rpc.getTokenAccountsByOwner(
9388
9426
  wallet,
@@ -9399,38 +9437,7 @@ var PositionManager = class {
9399
9437
  (ta) => this.getPosition(ta.account.data.parsed.info.mint)
9400
9438
  )
9401
9439
  );
9402
- const validPositions = positions.filter(
9403
- (p) => !!p
9404
- );
9405
- const enrichedPositions = await Promise.all(
9406
- validPositions.map(async (position) => {
9407
- try {
9408
- const poolAccount = await fetchMaybePoolState(
9409
- this.config.rpc,
9410
- position.poolId,
9411
- { commitment: this.config.commitment }
9412
- );
9413
- if (!poolAccount.exists) {
9414
- console.warn(`Pool ${position.poolId} not found for position`);
9415
- return null;
9416
- }
9417
- const { fees, rewards } = await this.getPositionFeeAndRewards(
9418
- position,
9419
- poolAccount.data
9420
- );
9421
- return this.enrichPositionInfo(
9422
- position,
9423
- poolAccount.data,
9424
- fees,
9425
- rewards
9426
- );
9427
- } catch (error) {
9428
- console.error(`Failed to enrich position: ${error}`);
9429
- return null;
9430
- }
9431
- })
9432
- );
9433
- return enrichedPositions.filter((p) => !!p);
9440
+ return positions.filter((p) => !!p);
9434
9441
  } catch (error) {
9435
9442
  throw new ClmmError(
9436
9443
  "POSITION_NOT_FOUND" /* POSITION_NOT_FOUND */,
@@ -9438,6 +9445,49 @@ var PositionManager = class {
9438
9445
  );
9439
9446
  }
9440
9447
  }
9448
+ /**
9449
+ * Get all positions for a wallet, enriched with pool data
9450
+ * @param wallet - Wallet address
9451
+ * @returns Structured result with enriched positions and any failures
9452
+ */
9453
+ async getPositionsForWallet(wallet) {
9454
+ const rawPositions = await this.getRawPositionsForWallet(wallet);
9455
+ const results = await Promise.allSettled(
9456
+ rawPositions.map(async (position) => {
9457
+ const poolAccount = await fetchMaybePoolState(
9458
+ this.config.rpc,
9459
+ position.poolId,
9460
+ { commitment: this.config.commitment }
9461
+ );
9462
+ if (!poolAccount.exists) {
9463
+ throw new Error(`Pool ${position.poolId} not found for position`);
9464
+ }
9465
+ const { fees, rewards } = await this.getPositionFeeAndRewards(
9466
+ position,
9467
+ poolAccount.data
9468
+ );
9469
+ return this.enrichPositionInfo(
9470
+ position,
9471
+ poolAccount.data,
9472
+ fees,
9473
+ rewards
9474
+ );
9475
+ })
9476
+ );
9477
+ const positions = [];
9478
+ const failed = [];
9479
+ results.forEach((result, index) => {
9480
+ if (result.status === "fulfilled") {
9481
+ positions.push(result.value);
9482
+ } else {
9483
+ failed.push({
9484
+ position: rawPositions[index],
9485
+ error: result.reason instanceof Error ? result.reason : new Error(String(result.reason))
9486
+ });
9487
+ }
9488
+ });
9489
+ return { positions, failed };
9490
+ }
9441
9491
  /**
9442
9492
  * Calculate pending fees and rewards for a position.
9443
9493
  *
@@ -9451,14 +9501,16 @@ var PositionManager = class {
9451
9501
  PdaUtils.getTickArrayStartIndex(
9452
9502
  position.tickLowerIndex,
9453
9503
  pool.tickSpacing
9454
- )
9504
+ ),
9505
+ this.programId
9455
9506
  );
9456
9507
  const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
9457
9508
  position.poolId,
9458
9509
  PdaUtils.getTickArrayStartIndex(
9459
9510
  position.tickUpperIndex,
9460
9511
  pool.tickSpacing
9461
- )
9512
+ ),
9513
+ this.programId
9462
9514
  );
9463
9515
  const tickArrayLowerAccount = await fetchMaybeTickArrayState(
9464
9516
  this.config.rpc,
@@ -10836,6 +10888,7 @@ var SwapManager = class {
10836
10888
  constructor(config, managerConfig) {
10837
10889
  this.config = config;
10838
10890
  this.managerConfig = managerConfig;
10891
+ this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
10839
10892
  this.poolDataManager = new PoolDataManager(config, {
10840
10893
  cacheTTL: 2e3,
10841
10894
  immutability: "freeze",
@@ -10856,6 +10909,7 @@ var SwapManager = class {
10856
10909
  );
10857
10910
  }
10858
10911
  }
10912
+ programId;
10859
10913
  poolDataManager;
10860
10914
  mathEngine;
10861
10915
  priceApiClient;
@@ -11466,7 +11520,8 @@ var SwapManager = class {
11466
11520
  const startIndex = currentStartIndex + offset * TICKS_PER_ARRAY * tickSpacing;
11467
11521
  const [tickArrayPda] = await PdaUtils.getTickArrayStatePda(
11468
11522
  poolAddress,
11469
- startIndex
11523
+ startIndex,
11524
+ this.programId
11470
11525
  );
11471
11526
  tickArrayAddresses.push(tickArrayPda);
11472
11527
  }
@@ -11776,7 +11831,7 @@ var SwapManager = class {
11776
11831
  }
11777
11832
  const pool = await this.poolDataManager.getPoolState(poolAddress, options);
11778
11833
  const zeroForOne = params.tokenIn === pool.tokenMint0;
11779
- const [observationState] = await PdaUtils.getObservationStatePda(poolAddress);
11834
+ const [observationState] = await PdaUtils.getObservationStatePda(poolAddress, this.programId);
11780
11835
  const [inputTokenAccount] = await findAssociatedTokenPda2({
11781
11836
  mint: params.tokenIn,
11782
11837
  owner: payer.address,
@@ -12031,6 +12086,7 @@ export {
12031
12086
  Q64,
12032
12087
  SLIPPAGE_CALC,
12033
12088
  STABBLE_CLMM_PROGRAM_ID,
12089
+ STABBLE_CLMM_QAS_PROGRAM_ID,
12034
12090
  SYSTEM_PROGRAM_ID,
12035
12091
  SYSVAR_RENT_PROGRAM_ID,
12036
12092
  SqrtPriceMath,
@@ -5,6 +5,7 @@ import BN from "bn.js";
5
5
  import Decimal from "decimal.js";
6
6
  export declare class PoolManager {
7
7
  private readonly config;
8
+ private readonly programId;
8
9
  constructor(config: ClmmSdkConfig);
9
10
  /**
10
11
  * Make create pool instructions
@@ -1 +1 @@
1
- {"version":3,"file":"pool-manager.d.ts","sourceRoot":"","sources":["../src/pool-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAEtB,OAAO,EACP,GAAG,EACH,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAML,SAAS,EACV,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,QAAQ,E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