@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/clmm.d.ts +1 -0
- package/lib/clmm.d.ts.map +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -1
- package/lib/index.js +154 -97
- package/lib/index.mjs +153 -97
- package/lib/pool-manager.d.ts +1 -0
- package/lib/pool-manager.d.ts.map +1 -1
- package/lib/position-manager.d.ts +11 -3
- package/lib/position-manager.d.ts.map +1 -1
- package/lib/swap.d.ts +1 -0
- package/lib/swap.d.ts.map +1 -1
- package/lib/types.d.ts +9 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/utils/pda.d.ts +19 -10
- package/lib/utils/pda.d.ts.map +1 -1
- package/lib/utils/tickQuery.d.ts +4 -4
- package/lib/utils/tickQuery.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -72,6 +72,7 @@ __export(index_exports, {
|
|
|
72
72
|
Q64: () => Q64,
|
|
73
73
|
SLIPPAGE_CALC: () => SLIPPAGE_CALC,
|
|
74
74
|
STABBLE_CLMM_PROGRAM_ID: () => STABBLE_CLMM_PROGRAM_ID,
|
|
75
|
+
STABBLE_CLMM_QAS_PROGRAM_ID: () => STABBLE_CLMM_QAS_PROGRAM_ID,
|
|
75
76
|
SYSTEM_PROGRAM_ID: () => SYSTEM_PROGRAM_ID,
|
|
76
77
|
SYSVAR_RENT_PROGRAM_ID: () => SYSVAR_RENT_PROGRAM_ID,
|
|
77
78
|
SqrtPriceMath: () => SqrtPriceMath,
|
|
@@ -5184,6 +5185,7 @@ var import_decimal2 = __toESM(require("decimal.js"));
|
|
|
5184
5185
|
// src/constants.ts
|
|
5185
5186
|
var import_bn = __toESM(require("bn.js"));
|
|
5186
5187
|
var STABBLE_CLMM_PROGRAM_ID = "6dMXqGZ3ga2dikrYS9ovDXgHGh5RUsb2RTUj6hrQXhk6";
|
|
5188
|
+
var STABBLE_CLMM_QAS_PROGRAM_ID = "8896VTm3Z3g8PuktiDdW9JLxZP1ww2r5c9Tz5AbaBjAJ";
|
|
5187
5189
|
var METADATA_PROGRAM_ID = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
|
|
5188
5190
|
var SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
5189
5191
|
var SYSVAR_RENT_PROGRAM_ID = "SysvarRent111111111111111111111111111111111";
|
|
@@ -5646,11 +5648,12 @@ var PdaUtils = class {
|
|
|
5646
5648
|
* @param ammConfig - AMM config address
|
|
5647
5649
|
* @param tokenMintA - Token A mint address
|
|
5648
5650
|
* @param tokenMintB - Token B mint address
|
|
5651
|
+
* @param programId - Program address (defaults to production)
|
|
5649
5652
|
* @returns Pool state PDA
|
|
5650
5653
|
*/
|
|
5651
|
-
static async getPoolStatePda(ammConfig, tokenMintA, tokenMintB) {
|
|
5654
|
+
static async getPoolStatePda(ammConfig, tokenMintA, tokenMintB, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5652
5655
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5653
|
-
programAddress:
|
|
5656
|
+
programAddress: programId,
|
|
5654
5657
|
seeds: [
|
|
5655
5658
|
PDA_SEEDS.POOL_STATE,
|
|
5656
5659
|
addressEncoder.encode(ammConfig),
|
|
@@ -5662,22 +5665,24 @@ var PdaUtils = class {
|
|
|
5662
5665
|
/**
|
|
5663
5666
|
* Derive AMM config PDA
|
|
5664
5667
|
* @param index - Config index
|
|
5668
|
+
* @param programId - Program address (defaults to production)
|
|
5665
5669
|
* @returns AMM config PDA
|
|
5666
5670
|
*/
|
|
5667
|
-
static async getAmmConfigPda(index) {
|
|
5671
|
+
static async getAmmConfigPda(index, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5668
5672
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5669
|
-
programAddress:
|
|
5673
|
+
programAddress: programId,
|
|
5670
5674
|
seeds: [PDA_SEEDS.AMM_CONFIG, (0, import_kit50.getU16Encoder)().encode(index)]
|
|
5671
5675
|
});
|
|
5672
5676
|
}
|
|
5673
5677
|
/**
|
|
5674
5678
|
* Derive position state PDA
|
|
5675
5679
|
* @param nftMint - Position NFT mint address
|
|
5680
|
+
* @param programId - Program address (defaults to production)
|
|
5676
5681
|
* @returns Position state PDA
|
|
5677
5682
|
*/
|
|
5678
|
-
static async getPositionStatePda(nftMint) {
|
|
5683
|
+
static async getPositionStatePda(nftMint, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5679
5684
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5680
|
-
programAddress:
|
|
5685
|
+
programAddress: programId,
|
|
5681
5686
|
seeds: [PDA_SEEDS.POSITION_STATE, addressEncoder.encode(nftMint)]
|
|
5682
5687
|
});
|
|
5683
5688
|
}
|
|
@@ -5685,11 +5690,12 @@ var PdaUtils = class {
|
|
|
5685
5690
|
* Derive tick array state PDA
|
|
5686
5691
|
* @param poolState - Pool state address
|
|
5687
5692
|
* @param startTickIndex - Starting tick index of the array
|
|
5693
|
+
* @param programId - Program address (defaults to production)
|
|
5688
5694
|
* @returns Tick array state PDA
|
|
5689
5695
|
*/
|
|
5690
|
-
static async getTickArrayStatePda(poolState, startTickIndex) {
|
|
5696
|
+
static async getTickArrayStatePda(poolState, startTickIndex, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5691
5697
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5692
|
-
programAddress:
|
|
5698
|
+
programAddress: programId,
|
|
5693
5699
|
seeds: [
|
|
5694
5700
|
PDA_SEEDS.TICK_ARRAY_STATE,
|
|
5695
5701
|
addressEncoder.encode(poolState),
|
|
@@ -5700,32 +5706,34 @@ var PdaUtils = class {
|
|
|
5700
5706
|
/**
|
|
5701
5707
|
* Derive observation state PDA
|
|
5702
5708
|
* @param poolState - Pool state address
|
|
5709
|
+
* @param programId - Program address (defaults to production)
|
|
5703
5710
|
* @returns Observation state PDA
|
|
5704
5711
|
*/
|
|
5705
|
-
static async getObservationStatePda(poolState) {
|
|
5712
|
+
static async getObservationStatePda(poolState, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5706
5713
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5707
|
-
programAddress:
|
|
5714
|
+
programAddress: programId,
|
|
5708
5715
|
seeds: [PDA_SEEDS.OBSERVATION_STATE, addressEncoder.encode(poolState)]
|
|
5709
5716
|
});
|
|
5710
5717
|
}
|
|
5711
|
-
static async getPoolVaultIdPda(poolAddress, vaultAddress) {
|
|
5718
|
+
static async getPoolVaultIdPda(poolAddress, vaultAddress, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5712
5719
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5713
5720
|
seeds: [
|
|
5714
5721
|
PDA_SEEDS.POOL_VAULT,
|
|
5715
5722
|
addressEncoder.encode(poolAddress),
|
|
5716
5723
|
addressEncoder.encode(vaultAddress)
|
|
5717
5724
|
],
|
|
5718
|
-
programAddress:
|
|
5725
|
+
programAddress: programId
|
|
5719
5726
|
});
|
|
5720
5727
|
}
|
|
5721
5728
|
/**
|
|
5722
5729
|
* Derive tick array bitmap extension PDA
|
|
5723
5730
|
* @param poolState - Pool state address
|
|
5731
|
+
* @param programId - Program address (defaults to production)
|
|
5724
5732
|
* @returns Tick array bitmap extension PDA
|
|
5725
5733
|
*/
|
|
5726
|
-
static async getTickArrayBitmapExtensionPda(poolState) {
|
|
5734
|
+
static async getTickArrayBitmapExtensionPda(poolState, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5727
5735
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5728
|
-
programAddress:
|
|
5736
|
+
programAddress: programId,
|
|
5729
5737
|
seeds: [PDA_SEEDS.BITMAP_EXTENSION, addressEncoder.encode(poolState)]
|
|
5730
5738
|
});
|
|
5731
5739
|
}
|
|
@@ -5748,9 +5756,10 @@ var PdaUtils = class {
|
|
|
5748
5756
|
* @param tickUpper - Upper tick of range
|
|
5749
5757
|
* @param tickSpacing - Tick spacing of the pool
|
|
5750
5758
|
* @param tickCurrent - Current pool tick
|
|
5759
|
+
* @param programId - Program address (defaults to production)
|
|
5751
5760
|
* @returns Array of tick array PDAs
|
|
5752
5761
|
*/
|
|
5753
|
-
static async getTickArrayPdasForRange(poolState, tickLower, tickUpper, tickSpacing, tickCurrent) {
|
|
5762
|
+
static async getTickArrayPdasForRange(poolState, tickLower, tickUpper, tickSpacing, tickCurrent, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5754
5763
|
const startIndexLower = this.getTickArrayStartIndex(tickLower, tickSpacing);
|
|
5755
5764
|
const startIndexUpper = this.getTickArrayStartIndex(tickUpper, tickSpacing);
|
|
5756
5765
|
const startIndexCurrent = this.getTickArrayStartIndex(
|
|
@@ -5764,7 +5773,7 @@ var PdaUtils = class {
|
|
|
5764
5773
|
]);
|
|
5765
5774
|
return await Promise.all(
|
|
5766
5775
|
Array.from(indices).map(
|
|
5767
|
-
(index) => this.getTickArrayStatePda(poolState, index)
|
|
5776
|
+
(index) => this.getTickArrayStatePda(poolState, index, programId)
|
|
5768
5777
|
)
|
|
5769
5778
|
);
|
|
5770
5779
|
}
|
|
@@ -5773,11 +5782,12 @@ var PdaUtils = class {
|
|
|
5773
5782
|
* @param poolState - Pool state address
|
|
5774
5783
|
* @param tickLowerIndex - Lower tick index
|
|
5775
5784
|
* @param tickUpperIndex - Upper tick index
|
|
5785
|
+
* @param programId - Program address (defaults to production)
|
|
5776
5786
|
* @returns Protocol position state PDA
|
|
5777
5787
|
*/
|
|
5778
|
-
static async getProtocolPositionStatePda(poolState, tickLowerIndex, tickUpperIndex) {
|
|
5788
|
+
static async getProtocolPositionStatePda(poolState, tickLowerIndex, tickUpperIndex, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5779
5789
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5780
|
-
programAddress:
|
|
5790
|
+
programAddress: programId,
|
|
5781
5791
|
seeds: [
|
|
5782
5792
|
PDA_SEEDS.POSITION_STATE,
|
|
5783
5793
|
addressEncoder.encode(poolState),
|
|
@@ -5789,11 +5799,12 @@ var PdaUtils = class {
|
|
|
5789
5799
|
/**
|
|
5790
5800
|
* Derive operation state PDA
|
|
5791
5801
|
* @param poolState - Pool state address
|
|
5802
|
+
* @param programId - Program address (defaults to production)
|
|
5792
5803
|
* @returns Operation state PDA
|
|
5793
5804
|
*/
|
|
5794
|
-
static async getOperationStatePda(poolState) {
|
|
5805
|
+
static async getOperationStatePda(poolState, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5795
5806
|
return await (0, import_kit50.getProgramDerivedAddress)({
|
|
5796
|
-
programAddress:
|
|
5807
|
+
programAddress: programId,
|
|
5797
5808
|
seeds: [PDA_SEEDS.OPERATION, addressEncoder.encode(poolState)]
|
|
5798
5809
|
});
|
|
5799
5810
|
}
|
|
@@ -5812,7 +5823,7 @@ async function getMetadataPda(mint) {
|
|
|
5812
5823
|
// src/utils/tickQuery.ts
|
|
5813
5824
|
var FETCH_TICKARRAY_COUNT = 15;
|
|
5814
5825
|
var TickQuery = class _TickQuery {
|
|
5815
|
-
static async getTickArrays(rpc, poolId, tickCurrent, tickSpacing, tickArrayBitmapArray, exTickArrayBitmap) {
|
|
5826
|
+
static async getTickArrays(rpc, poolId, tickCurrent, tickSpacing, tickArrayBitmapArray, exTickArrayBitmap, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5816
5827
|
const tickArraysToFetch = [];
|
|
5817
5828
|
const currentTickArrayStartIndex = TickUtils.getTickArrayStartIndexByTick(
|
|
5818
5829
|
tickCurrent,
|
|
@@ -5828,7 +5839,8 @@ var TickQuery = class _TickQuery {
|
|
|
5828
5839
|
for (let i = 0; i < startIndexArray.length; i++) {
|
|
5829
5840
|
const [tickArrayAddress] = await PdaUtils.getTickArrayStatePda(
|
|
5830
5841
|
poolId,
|
|
5831
|
-
startIndexArray[i]
|
|
5842
|
+
startIndexArray[i],
|
|
5843
|
+
programId
|
|
5832
5844
|
);
|
|
5833
5845
|
tickArraysToFetch.push(tickArrayAddress);
|
|
5834
5846
|
}
|
|
@@ -5883,7 +5895,7 @@ var TickQuery = class _TickQuery {
|
|
|
5883
5895
|
* @param zeroForOne - Search direction
|
|
5884
5896
|
* @returns First initialized tick, tick array address, and start index
|
|
5885
5897
|
*/
|
|
5886
|
-
static async firstInitializedTickInOneArray(poolId, tickArray, zeroForOne) {
|
|
5898
|
+
static async firstInitializedTickInOneArray(poolId, tickArray, zeroForOne, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5887
5899
|
let nextInitializedTick = void 0;
|
|
5888
5900
|
if (zeroForOne) {
|
|
5889
5901
|
for (let i = TICK_ARRAY_SIZE - 1; i >= 0; i--) {
|
|
@@ -5904,7 +5916,8 @@ var TickQuery = class _TickQuery {
|
|
|
5904
5916
|
}
|
|
5905
5917
|
const [tickArrayAddress] = await PdaUtils.getTickArrayStatePda(
|
|
5906
5918
|
poolId,
|
|
5907
|
-
tickArray.data.startTickIndex
|
|
5919
|
+
tickArray.data.startTickIndex,
|
|
5920
|
+
programId
|
|
5908
5921
|
);
|
|
5909
5922
|
return {
|
|
5910
5923
|
nextTick: nextInitializedTick,
|
|
@@ -5922,7 +5935,7 @@ var TickQuery = class _TickQuery {
|
|
|
5922
5935
|
* @param zeroForOne - Search direction
|
|
5923
5936
|
* @returns Next initialized tick info
|
|
5924
5937
|
*/
|
|
5925
|
-
static async nextInitializedTickInOneArray(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne) {
|
|
5938
|
+
static async nextInitializedTickInOneArray(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5926
5939
|
const startIndex = TickUtils.getTickArrayStartIndexByTick(
|
|
5927
5940
|
tickIndex,
|
|
5928
5941
|
tickSpacing
|
|
@@ -5961,7 +5974,8 @@ var TickQuery = class _TickQuery {
|
|
|
5961
5974
|
}
|
|
5962
5975
|
const [tickArrayAddress] = await PdaUtils.getTickArrayStatePda(
|
|
5963
5976
|
poolId,
|
|
5964
|
-
startIndex
|
|
5977
|
+
startIndex,
|
|
5978
|
+
programId
|
|
5965
5979
|
);
|
|
5966
5980
|
return {
|
|
5967
5981
|
initializedTick: nextInitializedTick,
|
|
@@ -5979,7 +5993,7 @@ var TickQuery = class _TickQuery {
|
|
|
5979
5993
|
* @param zeroForOne - Search direction
|
|
5980
5994
|
* @returns Next initialized tick info
|
|
5981
5995
|
*/
|
|
5982
|
-
static async nextInitializedTick(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne) {
|
|
5996
|
+
static async nextInitializedTick(poolId, tickArrayCache, tickIndex, tickSpacing, zeroForOne, programId = STABBLE_CLMM_PROGRAM_ID) {
|
|
5983
5997
|
let {
|
|
5984
5998
|
initializedTick: nextTick,
|
|
5985
5999
|
tickArrayAddress,
|
|
@@ -5989,7 +6003,8 @@ var TickQuery = class _TickQuery {
|
|
|
5989
6003
|
tickArrayCache,
|
|
5990
6004
|
tickIndex,
|
|
5991
6005
|
tickSpacing,
|
|
5992
|
-
zeroForOne
|
|
6006
|
+
zeroForOne,
|
|
6007
|
+
programId
|
|
5993
6008
|
);
|
|
5994
6009
|
while (nextTick === void 0 || nextTick.liquidityGross <= 0n) {
|
|
5995
6010
|
const nextArrayStartIndex = zeroForOne ? tickArrayStartTickIndex - this.tickCount(tickSpacing) : tickArrayStartTickIndex + this.tickCount(tickSpacing);
|
|
@@ -6006,7 +6021,8 @@ var TickQuery = class _TickQuery {
|
|
|
6006
6021
|
const result = await this.firstInitializedTickInOneArray(
|
|
6007
6022
|
poolId,
|
|
6008
6023
|
cachedTickArray,
|
|
6009
|
-
zeroForOne
|
|
6024
|
+
zeroForOne,
|
|
6025
|
+
programId
|
|
6010
6026
|
);
|
|
6011
6027
|
nextTick = result.nextTick;
|
|
6012
6028
|
tickArrayAddress = result.tickArrayAddress;
|
|
@@ -7847,7 +7863,9 @@ function getApisFromEndpoint(rpc) {
|
|
|
7847
7863
|
var Clmm = class {
|
|
7848
7864
|
constructor(config) {
|
|
7849
7865
|
this.config = config;
|
|
7866
|
+
this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
|
|
7850
7867
|
}
|
|
7868
|
+
programId;
|
|
7851
7869
|
/**
|
|
7852
7870
|
* Create a new AMM configuration
|
|
7853
7871
|
* @param params - Configuration parameters
|
|
@@ -7862,7 +7880,7 @@ var Clmm = class {
|
|
|
7862
7880
|
protocolFeeRate,
|
|
7863
7881
|
fundFeeRate
|
|
7864
7882
|
} = params;
|
|
7865
|
-
const ammConfigPda = await PdaUtils.getAmmConfigPda(index);
|
|
7883
|
+
const ammConfigPda = await PdaUtils.getAmmConfigPda(index, this.programId);
|
|
7866
7884
|
const instruction = await getCreateAmmConfigInstructionAsync({
|
|
7867
7885
|
owner,
|
|
7868
7886
|
ammConfig: ammConfigPda[0],
|
|
@@ -7936,7 +7954,9 @@ async function getToken(rpc, tokenAccount) {
|
|
|
7936
7954
|
var PoolManager = class {
|
|
7937
7955
|
constructor(config) {
|
|
7938
7956
|
this.config = config;
|
|
7957
|
+
this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
|
|
7939
7958
|
}
|
|
7959
|
+
programId;
|
|
7940
7960
|
/**
|
|
7941
7961
|
* Make create pool instructions
|
|
7942
7962
|
* @param params - Pool creation parameters
|
|
@@ -7972,12 +7992,13 @@ var PoolManager = class {
|
|
|
7972
7992
|
const [poolPda] = await PdaUtils.getPoolStatePda(
|
|
7973
7993
|
ammConfigId,
|
|
7974
7994
|
token0,
|
|
7975
|
-
token1
|
|
7995
|
+
token1,
|
|
7996
|
+
this.programId
|
|
7976
7997
|
);
|
|
7977
|
-
const [observationPda] = await PdaUtils.getObservationStatePda(poolPda);
|
|
7978
|
-
const [tickArrayBitmapPda] = await PdaUtils.getTickArrayBitmapExtensionPda(poolPda);
|
|
7979
|
-
const [tokenVault0] = await PdaUtils.getPoolVaultIdPda(poolPda, token0);
|
|
7980
|
-
const [tokenVault1] = await PdaUtils.getPoolVaultIdPda(poolPda, token1);
|
|
7998
|
+
const [observationPda] = await PdaUtils.getObservationStatePda(poolPda, this.programId);
|
|
7999
|
+
const [tickArrayBitmapPda] = await PdaUtils.getTickArrayBitmapExtensionPda(poolPda, this.programId);
|
|
8000
|
+
const [tokenVault0] = await PdaUtils.getPoolVaultIdPda(poolPda, token0, this.programId);
|
|
8001
|
+
const [tokenVault1] = await PdaUtils.getPoolVaultIdPda(poolPda, token1, this.programId);
|
|
7981
8002
|
const instruction = await getCreatePoolInstructionAsync({
|
|
7982
8003
|
poolCreator: owner,
|
|
7983
8004
|
ammConfig: ammConfigId,
|
|
@@ -8022,7 +8043,7 @@ var PoolManager = class {
|
|
|
8022
8043
|
protocolFeeRate,
|
|
8023
8044
|
fundFeeRate
|
|
8024
8045
|
} = params;
|
|
8025
|
-
const ammConfigPda = await PdaUtils.getAmmConfigPda(index);
|
|
8046
|
+
const ammConfigPda = await PdaUtils.getAmmConfigPda(index, this.programId);
|
|
8026
8047
|
const instruction = getCreateAmmConfigInstruction({
|
|
8027
8048
|
owner,
|
|
8028
8049
|
ammConfig: ammConfigPda[0],
|
|
@@ -8074,17 +8095,18 @@ var PoolManager = class {
|
|
|
8074
8095
|
* @returns Pool information if found
|
|
8075
8096
|
*/
|
|
8076
8097
|
async getPoolByTokenPairAndConfig(tokenA, tokenB, ammConfigIndex = 0) {
|
|
8077
|
-
const ammConfigPda = await PdaUtils.getAmmConfigPda(ammConfigIndex);
|
|
8098
|
+
const ammConfigPda = await PdaUtils.getAmmConfigPda(ammConfigIndex, this.programId);
|
|
8078
8099
|
const poolPda = await PdaUtils.getPoolStatePda(
|
|
8079
8100
|
ammConfigPda[0],
|
|
8080
8101
|
tokenA,
|
|
8081
|
-
tokenB
|
|
8102
|
+
tokenB,
|
|
8103
|
+
this.programId
|
|
8082
8104
|
);
|
|
8083
8105
|
return this.getPool(poolPda[0]);
|
|
8084
8106
|
}
|
|
8085
8107
|
async getAllPools(rpc) {
|
|
8086
8108
|
try {
|
|
8087
|
-
let accounts = await rpc.getProgramAccounts(
|
|
8109
|
+
let accounts = await rpc.getProgramAccounts(this.programId, {
|
|
8088
8110
|
commitment: "finalized",
|
|
8089
8111
|
encoding: "base64",
|
|
8090
8112
|
filters: [
|
|
@@ -8199,7 +8221,9 @@ var TOKEN_ACCOUNT_SIZE = 165n;
|
|
|
8199
8221
|
var PositionManager = class {
|
|
8200
8222
|
constructor(config) {
|
|
8201
8223
|
this.config = config;
|
|
8224
|
+
this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
|
|
8202
8225
|
}
|
|
8226
|
+
programId;
|
|
8203
8227
|
buildWrapSolInstructions(params) {
|
|
8204
8228
|
const { payer, ata, owner, amount } = params;
|
|
8205
8229
|
return [
|
|
@@ -8301,7 +8325,8 @@ var PositionManager = class {
|
|
|
8301
8325
|
poolAccount.data.tickSpacing
|
|
8302
8326
|
);
|
|
8303
8327
|
const [positionStatePda] = await PdaUtils.getPositionStatePda(
|
|
8304
|
-
nftMintAccount.address
|
|
8328
|
+
nftMintAccount.address,
|
|
8329
|
+
this.programId
|
|
8305
8330
|
);
|
|
8306
8331
|
const [metadataPda] = await getMetadataPda(nftMintAccount.address);
|
|
8307
8332
|
const [positionNftAccountPda] = await (0, import_token4.findAssociatedTokenPda)({
|
|
@@ -8312,7 +8337,8 @@ var PositionManager = class {
|
|
|
8312
8337
|
const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
|
|
8313
8338
|
poolAccount.address,
|
|
8314
8339
|
tickLower,
|
|
8315
|
-
tickUpper
|
|
8340
|
+
tickUpper,
|
|
8341
|
+
this.programId
|
|
8316
8342
|
);
|
|
8317
8343
|
const instruction = await getOpenPositionWithToken22NftInstructionAsync({
|
|
8318
8344
|
payer: ownerInfo.feePayer,
|
|
@@ -8387,14 +8413,17 @@ var PositionManager = class {
|
|
|
8387
8413
|
);
|
|
8388
8414
|
const [tickArrayLower] = await PdaUtils.getTickArrayStatePda(
|
|
8389
8415
|
poolAccount.address,
|
|
8390
|
-
tickArrayLowerStartIndex
|
|
8416
|
+
tickArrayLowerStartIndex,
|
|
8417
|
+
this.programId
|
|
8391
8418
|
);
|
|
8392
8419
|
const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
|
|
8393
8420
|
poolAccount.address,
|
|
8394
|
-
tickArrayUpperStartIndex
|
|
8421
|
+
tickArrayUpperStartIndex,
|
|
8422
|
+
this.programId
|
|
8395
8423
|
);
|
|
8396
8424
|
const [positionStatePda] = await PdaUtils.getPositionStatePda(
|
|
8397
|
-
nftMintAccount.address
|
|
8425
|
+
nftMintAccount.address,
|
|
8426
|
+
this.programId
|
|
8398
8427
|
);
|
|
8399
8428
|
const [metadataPda] = await getMetadataPda(nftMintAccount.address);
|
|
8400
8429
|
const [positionNftAccountPda] = await (0, import_token4.findAssociatedTokenPda)({
|
|
@@ -8405,7 +8434,8 @@ var PositionManager = class {
|
|
|
8405
8434
|
const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
|
|
8406
8435
|
poolAccount.address,
|
|
8407
8436
|
tickLower,
|
|
8408
|
-
tickUpper
|
|
8437
|
+
tickUpper,
|
|
8438
|
+
this.programId
|
|
8409
8439
|
);
|
|
8410
8440
|
const amount0Max = base === "MintA" ? baseAmount : otherAmountMax;
|
|
8411
8441
|
const amount1Max = base === "MintA" ? otherAmountMax : baseAmount;
|
|
@@ -8413,7 +8443,7 @@ var PositionManager = class {
|
|
|
8413
8443
|
poolAccount.data.tickSpacing,
|
|
8414
8444
|
[tickArrayLowerStartIndex, tickArrayUpperStartIndex]
|
|
8415
8445
|
);
|
|
8416
|
-
const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolAccount.address) : void 0;
|
|
8446
|
+
const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolAccount.address, this.programId) : void 0;
|
|
8417
8447
|
const remAccounts = extBitmapAccount ? [{ address: extBitmapAccount[0], role: import_kit53.AccountRole.WRITABLE }] : [];
|
|
8418
8448
|
let wrapSolInstructions = [];
|
|
8419
8449
|
if (poolAccount.data.tokenMint0.toString() === NATIVE_MINT.toString()) {
|
|
@@ -8489,7 +8519,8 @@ var PositionManager = class {
|
|
|
8489
8519
|
amountMaxB
|
|
8490
8520
|
} = params;
|
|
8491
8521
|
const [personalPosition] = await PdaUtils.getPositionStatePda(
|
|
8492
|
-
ownerPosition.nftMint
|
|
8522
|
+
ownerPosition.nftMint,
|
|
8523
|
+
this.programId
|
|
8493
8524
|
);
|
|
8494
8525
|
const [positionNftAccount] = await (0, import_token4.findAssociatedTokenPda)({
|
|
8495
8526
|
mint: ownerPosition.nftMint,
|
|
@@ -8499,27 +8530,30 @@ var PositionManager = class {
|
|
|
8499
8530
|
const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
|
|
8500
8531
|
poolState.address,
|
|
8501
8532
|
ownerPosition.tickLowerIndex,
|
|
8502
|
-
ownerPosition.tickUpperIndex
|
|
8533
|
+
ownerPosition.tickUpperIndex,
|
|
8534
|
+
this.programId
|
|
8503
8535
|
);
|
|
8504
8536
|
const [tickArrayLower] = await PdaUtils.getTickArrayStatePda(
|
|
8505
8537
|
poolState.address,
|
|
8506
8538
|
PdaUtils.getTickArrayStartIndex(
|
|
8507
8539
|
ownerPosition.tickLowerIndex,
|
|
8508
8540
|
poolState.data.tickSpacing
|
|
8509
|
-
)
|
|
8541
|
+
),
|
|
8542
|
+
this.programId
|
|
8510
8543
|
);
|
|
8511
8544
|
const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
|
|
8512
8545
|
poolState.address,
|
|
8513
8546
|
PdaUtils.getTickArrayStartIndex(
|
|
8514
8547
|
ownerPosition.tickUpperIndex,
|
|
8515
8548
|
poolState.data.tickSpacing
|
|
8516
|
-
)
|
|
8549
|
+
),
|
|
8550
|
+
this.programId
|
|
8517
8551
|
);
|
|
8518
8552
|
const isOverflow = PoolUtils.isOverflowDefaultTickArrayBitmap(
|
|
8519
8553
|
poolState.data.tickSpacing,
|
|
8520
8554
|
[ownerPosition.tickLowerIndex, ownerPosition.tickUpperIndex]
|
|
8521
8555
|
);
|
|
8522
|
-
const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address) : void 0;
|
|
8556
|
+
const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address, this.programId) : void 0;
|
|
8523
8557
|
const remAccounts = extBitmapAccount ? [{ address: extBitmapAccount[0], role: import_kit53.AccountRole.WRITABLE }] : [];
|
|
8524
8558
|
const instruction = getIncreaseLiquidityV2Instruction({
|
|
8525
8559
|
nftOwner: ownerInfo.wallet,
|
|
@@ -8577,7 +8611,8 @@ var PositionManager = class {
|
|
|
8577
8611
|
} = params;
|
|
8578
8612
|
const signers = [];
|
|
8579
8613
|
const [personalPosition] = await PdaUtils.getPositionStatePda(
|
|
8580
|
-
ownerPosition.nftMint
|
|
8614
|
+
ownerPosition.nftMint,
|
|
8615
|
+
this.programId
|
|
8581
8616
|
);
|
|
8582
8617
|
const [positionNftAccount] = await (0, import_token4.findAssociatedTokenPda)({
|
|
8583
8618
|
mint: ownerPosition.nftMint,
|
|
@@ -8587,27 +8622,30 @@ var PositionManager = class {
|
|
|
8587
8622
|
const [protocolPositionPda] = await PdaUtils.getProtocolPositionStatePda(
|
|
8588
8623
|
poolState.address,
|
|
8589
8624
|
ownerPosition.tickLowerIndex,
|
|
8590
|
-
ownerPosition.tickUpperIndex
|
|
8625
|
+
ownerPosition.tickUpperIndex,
|
|
8626
|
+
this.programId
|
|
8591
8627
|
);
|
|
8592
8628
|
const [tickArrayLower] = await PdaUtils.getTickArrayStatePda(
|
|
8593
8629
|
poolState.address,
|
|
8594
8630
|
PdaUtils.getTickArrayStartIndex(
|
|
8595
8631
|
ownerPosition.tickLowerIndex,
|
|
8596
8632
|
poolState.data.tickSpacing
|
|
8597
|
-
)
|
|
8633
|
+
),
|
|
8634
|
+
this.programId
|
|
8598
8635
|
);
|
|
8599
8636
|
const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
|
|
8600
8637
|
poolState.address,
|
|
8601
8638
|
PdaUtils.getTickArrayStartIndex(
|
|
8602
8639
|
ownerPosition.tickUpperIndex,
|
|
8603
8640
|
poolState.data.tickSpacing
|
|
8604
|
-
)
|
|
8641
|
+
),
|
|
8642
|
+
this.programId
|
|
8605
8643
|
);
|
|
8606
8644
|
const isOverflow = PoolUtils.isOverflowDefaultTickArrayBitmap(
|
|
8607
8645
|
poolState.data.tickSpacing,
|
|
8608
8646
|
[ownerPosition.tickLowerIndex, ownerPosition.tickUpperIndex]
|
|
8609
8647
|
);
|
|
8610
|
-
const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address) : void 0;
|
|
8648
|
+
const extBitmapAccount = isOverflow ? await PdaUtils.getTickArrayBitmapExtensionPda(poolState.address, this.programId) : void 0;
|
|
8611
8649
|
const remAccounts = extBitmapAccount ? [{ address: extBitmapAccount[0], role: import_kit53.AccountRole.WRITABLE }] : [];
|
|
8612
8650
|
const createRecipientAta0Ix = (0, import_token4.getCreateAssociatedTokenIdempotentInstruction)(
|
|
8613
8651
|
{
|
|
@@ -8690,7 +8728,8 @@ var PositionManager = class {
|
|
|
8690
8728
|
async makeClosePositionInstructions(params) {
|
|
8691
8729
|
const { ownerPosition, ownerInfo } = params;
|
|
8692
8730
|
const [personalPosition] = await PdaUtils.getPositionStatePda(
|
|
8693
|
-
ownerPosition.nftMint
|
|
8731
|
+
ownerPosition.nftMint,
|
|
8732
|
+
this.programId
|
|
8694
8733
|
);
|
|
8695
8734
|
const [positionNftAccount] = await (0, import_token4.findAssociatedTokenPda)({
|
|
8696
8735
|
mint: ownerPosition.nftMint,
|
|
@@ -8719,7 +8758,7 @@ var PositionManager = class {
|
|
|
8719
8758
|
*/
|
|
8720
8759
|
async getPosition(positionMint) {
|
|
8721
8760
|
try {
|
|
8722
|
-
const positionStatePda = await PdaUtils.getPositionStatePda(positionMint);
|
|
8761
|
+
const positionStatePda = await PdaUtils.getPositionStatePda(positionMint, this.programId);
|
|
8723
8762
|
const positionState = await fetchMaybePersonalPositionState(
|
|
8724
8763
|
this.config.rpc,
|
|
8725
8764
|
positionStatePda[0],
|
|
@@ -8800,11 +8839,11 @@ var PositionManager = class {
|
|
|
8800
8839
|
};
|
|
8801
8840
|
}
|
|
8802
8841
|
/**
|
|
8803
|
-
* Get
|
|
8842
|
+
* Get raw positions for a wallet (without pool-state enrichment)
|
|
8804
8843
|
* @param wallet - Wallet address
|
|
8805
|
-
* @returns Array of
|
|
8844
|
+
* @returns Array of raw position states owned by the wallet
|
|
8806
8845
|
*/
|
|
8807
|
-
async
|
|
8846
|
+
async getRawPositionsForWallet(wallet) {
|
|
8808
8847
|
try {
|
|
8809
8848
|
const response22 = await this.config.rpc.getTokenAccountsByOwner(
|
|
8810
8849
|
wallet,
|
|
@@ -8821,38 +8860,7 @@ var PositionManager = class {
|
|
|
8821
8860
|
(ta) => this.getPosition(ta.account.data.parsed.info.mint)
|
|
8822
8861
|
)
|
|
8823
8862
|
);
|
|
8824
|
-
|
|
8825
|
-
(p) => !!p
|
|
8826
|
-
);
|
|
8827
|
-
const enrichedPositions = await Promise.all(
|
|
8828
|
-
validPositions.map(async (position) => {
|
|
8829
|
-
try {
|
|
8830
|
-
const poolAccount = await fetchMaybePoolState(
|
|
8831
|
-
this.config.rpc,
|
|
8832
|
-
position.poolId,
|
|
8833
|
-
{ commitment: this.config.commitment }
|
|
8834
|
-
);
|
|
8835
|
-
if (!poolAccount.exists) {
|
|
8836
|
-
console.warn(`Pool ${position.poolId} not found for position`);
|
|
8837
|
-
return null;
|
|
8838
|
-
}
|
|
8839
|
-
const { fees, rewards } = await this.getPositionFeeAndRewards(
|
|
8840
|
-
position,
|
|
8841
|
-
poolAccount.data
|
|
8842
|
-
);
|
|
8843
|
-
return this.enrichPositionInfo(
|
|
8844
|
-
position,
|
|
8845
|
-
poolAccount.data,
|
|
8846
|
-
fees,
|
|
8847
|
-
rewards
|
|
8848
|
-
);
|
|
8849
|
-
} catch (error) {
|
|
8850
|
-
console.error(`Failed to enrich position: ${error}`);
|
|
8851
|
-
return null;
|
|
8852
|
-
}
|
|
8853
|
-
})
|
|
8854
|
-
);
|
|
8855
|
-
return enrichedPositions.filter((p) => !!p);
|
|
8863
|
+
return positions.filter((p) => !!p);
|
|
8856
8864
|
} catch (error) {
|
|
8857
8865
|
throw new ClmmError(
|
|
8858
8866
|
"POSITION_NOT_FOUND" /* POSITION_NOT_FOUND */,
|
|
@@ -8860,6 +8868,49 @@ var PositionManager = class {
|
|
|
8860
8868
|
);
|
|
8861
8869
|
}
|
|
8862
8870
|
}
|
|
8871
|
+
/**
|
|
8872
|
+
* Get all positions for a wallet, enriched with pool data
|
|
8873
|
+
* @param wallet - Wallet address
|
|
8874
|
+
* @returns Structured result with enriched positions and any failures
|
|
8875
|
+
*/
|
|
8876
|
+
async getPositionsForWallet(wallet) {
|
|
8877
|
+
const rawPositions = await this.getRawPositionsForWallet(wallet);
|
|
8878
|
+
const results = await Promise.allSettled(
|
|
8879
|
+
rawPositions.map(async (position) => {
|
|
8880
|
+
const poolAccount = await fetchMaybePoolState(
|
|
8881
|
+
this.config.rpc,
|
|
8882
|
+
position.poolId,
|
|
8883
|
+
{ commitment: this.config.commitment }
|
|
8884
|
+
);
|
|
8885
|
+
if (!poolAccount.exists) {
|
|
8886
|
+
throw new Error(`Pool ${position.poolId} not found for position`);
|
|
8887
|
+
}
|
|
8888
|
+
const { fees, rewards } = await this.getPositionFeeAndRewards(
|
|
8889
|
+
position,
|
|
8890
|
+
poolAccount.data
|
|
8891
|
+
);
|
|
8892
|
+
return this.enrichPositionInfo(
|
|
8893
|
+
position,
|
|
8894
|
+
poolAccount.data,
|
|
8895
|
+
fees,
|
|
8896
|
+
rewards
|
|
8897
|
+
);
|
|
8898
|
+
})
|
|
8899
|
+
);
|
|
8900
|
+
const positions = [];
|
|
8901
|
+
const failed = [];
|
|
8902
|
+
results.forEach((result, index) => {
|
|
8903
|
+
if (result.status === "fulfilled") {
|
|
8904
|
+
positions.push(result.value);
|
|
8905
|
+
} else {
|
|
8906
|
+
failed.push({
|
|
8907
|
+
position: rawPositions[index],
|
|
8908
|
+
error: result.reason instanceof Error ? result.reason : new Error(String(result.reason))
|
|
8909
|
+
});
|
|
8910
|
+
}
|
|
8911
|
+
});
|
|
8912
|
+
return { positions, failed };
|
|
8913
|
+
}
|
|
8863
8914
|
/**
|
|
8864
8915
|
* Calculate pending fees and rewards for a position.
|
|
8865
8916
|
*
|
|
@@ -8873,14 +8924,16 @@ var PositionManager = class {
|
|
|
8873
8924
|
PdaUtils.getTickArrayStartIndex(
|
|
8874
8925
|
position.tickLowerIndex,
|
|
8875
8926
|
pool.tickSpacing
|
|
8876
|
-
)
|
|
8927
|
+
),
|
|
8928
|
+
this.programId
|
|
8877
8929
|
);
|
|
8878
8930
|
const [tickArrayUpper] = await PdaUtils.getTickArrayStatePda(
|
|
8879
8931
|
position.poolId,
|
|
8880
8932
|
PdaUtils.getTickArrayStartIndex(
|
|
8881
8933
|
position.tickUpperIndex,
|
|
8882
8934
|
pool.tickSpacing
|
|
8883
|
-
)
|
|
8935
|
+
),
|
|
8936
|
+
this.programId
|
|
8884
8937
|
);
|
|
8885
8938
|
const tickArrayLowerAccount = await fetchMaybeTickArrayState(
|
|
8886
8939
|
this.config.rpc,
|
|
@@ -10255,6 +10308,7 @@ var SwapManager = class {
|
|
|
10255
10308
|
constructor(config, managerConfig) {
|
|
10256
10309
|
this.config = config;
|
|
10257
10310
|
this.managerConfig = managerConfig;
|
|
10311
|
+
this.programId = config.programAddress ?? STABBLE_CLMM_PROGRAM_ID;
|
|
10258
10312
|
this.poolDataManager = new PoolDataManager(config, {
|
|
10259
10313
|
cacheTTL: 2e3,
|
|
10260
10314
|
immutability: "freeze",
|
|
@@ -10275,6 +10329,7 @@ var SwapManager = class {
|
|
|
10275
10329
|
);
|
|
10276
10330
|
}
|
|
10277
10331
|
}
|
|
10332
|
+
programId;
|
|
10278
10333
|
poolDataManager;
|
|
10279
10334
|
mathEngine;
|
|
10280
10335
|
priceApiClient;
|
|
@@ -10885,7 +10940,8 @@ var SwapManager = class {
|
|
|
10885
10940
|
const startIndex = currentStartIndex + offset * TICKS_PER_ARRAY * tickSpacing;
|
|
10886
10941
|
const [tickArrayPda] = await PdaUtils.getTickArrayStatePda(
|
|
10887
10942
|
poolAddress,
|
|
10888
|
-
startIndex
|
|
10943
|
+
startIndex,
|
|
10944
|
+
this.programId
|
|
10889
10945
|
);
|
|
10890
10946
|
tickArrayAddresses.push(tickArrayPda);
|
|
10891
10947
|
}
|
|
@@ -11195,7 +11251,7 @@ var SwapManager = class {
|
|
|
11195
11251
|
}
|
|
11196
11252
|
const pool = await this.poolDataManager.getPoolState(poolAddress, options);
|
|
11197
11253
|
const zeroForOne = params.tokenIn === pool.tokenMint0;
|
|
11198
|
-
const [observationState] = await PdaUtils.getObservationStatePda(poolAddress);
|
|
11254
|
+
const [observationState] = await PdaUtils.getObservationStatePda(poolAddress, this.programId);
|
|
11199
11255
|
const [inputTokenAccount] = await (0, import_token5.findAssociatedTokenPda)({
|
|
11200
11256
|
mint: params.tokenIn,
|
|
11201
11257
|
owner: payer.address,
|
|
@@ -11451,6 +11507,7 @@ var DEFAULT_SDK_CONFIG = {
|
|
|
11451
11507
|
Q64,
|
|
11452
11508
|
SLIPPAGE_CALC,
|
|
11453
11509
|
STABBLE_CLMM_PROGRAM_ID,
|
|
11510
|
+
STABBLE_CLMM_QAS_PROGRAM_ID,
|
|
11454
11511
|
SYSTEM_PROGRAM_ID,
|
|
11455
11512
|
SYSVAR_RENT_PROGRAM_ID,
|
|
11456
11513
|
SqrtPriceMath,
|