@meteora-ag/dlmm 1.9.13 → 1.9.14

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.js CHANGED
@@ -11811,125 +11811,410 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
11811
11811
  return new (0, _anchor.BN)(c1.sub(c0).floor().toString());
11812
11812
  }
11813
11813
 
11814
- // src/dlmm/helpers/binArray.ts
11815
- function internalBitmapRange() {
11816
- const lowerBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.neg();
11817
- const upperBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.sub(new (0, _anchor.BN)(1));
11818
- return [lowerBinArrayIndex, upperBinArrayIndex];
11819
- }
11820
- function buildBitmapFromU64Arrays(u64Arrays, type) {
11821
- const buffer = Buffer.concat(
11822
- u64Arrays.map((b) => {
11823
- return b.toArrayLike(Buffer, "le", 8);
11824
- })
11825
- );
11826
- return new (0, _anchor.BN)(buffer, "le");
11814
+ // src/dlmm/helpers/positions/index.ts
11815
+
11816
+
11817
+ // src/dlmm/helpers/positions/wrapper.ts
11818
+
11819
+ function combineBaseAndExtendedPositionBinData(base, extended) {
11820
+ const combinedLiquidityShares = base.liquidityShares;
11821
+ const combinedRewardInfos = base.rewardInfos;
11822
+ const combinedFeeInfos = base.feeInfos;
11823
+ for (const binData of extended) {
11824
+ combinedLiquidityShares.push(binData.liquidityShare);
11825
+ combinedRewardInfos.push(binData.rewardInfo);
11826
+ combinedFeeInfos.push(binData.feeInfo);
11827
+ }
11828
+ return {
11829
+ liquidityShares: combinedLiquidityShares,
11830
+ rewardInfos: combinedRewardInfos,
11831
+ feeInfos: combinedFeeInfos
11832
+ };
11827
11833
  }
11828
- function bitmapTypeDetail(type) {
11829
- if (type == 0 /* U1024 */) {
11830
- return {
11831
- bits: 1024,
11832
- bytes: 1024 / 8
11833
- };
11834
+ function wrapPosition(program, key, account) {
11835
+ const disc = account.data.subarray(0, 8);
11836
+ if (disc.equals(Buffer.from(getAccountDiscriminator("positionV2")))) {
11837
+ const state = decodeAccount(
11838
+ program,
11839
+ "positionV2",
11840
+ account.data
11841
+ );
11842
+ const extended = decodeExtendedPosition(
11843
+ state,
11844
+ program,
11845
+ account.data.subarray(8 + POSITION_MIN_SIZE)
11846
+ );
11847
+ const combinedPositionBinData = combineBaseAndExtendedPositionBinData(
11848
+ state,
11849
+ extended
11850
+ );
11851
+ return new PositionV2Wrapper(key, state, extended, combinedPositionBinData);
11834
11852
  } else {
11835
- return {
11836
- bits: 512,
11837
- bytes: 512 / 8
11838
- };
11853
+ throw new Error("Unknown position account");
11839
11854
  }
11840
11855
  }
11841
- function mostSignificantBit(number, bitLength) {
11842
- const highestIndex = bitLength - 1;
11843
- if (number.isZero()) {
11844
- return null;
11856
+ var PositionV2Wrapper = class {
11857
+ constructor(positionAddress, inner, extended, combinedPositionBinData) {
11858
+ this.positionAddress = positionAddress;
11859
+ this.inner = inner;
11860
+ this.extended = extended;
11861
+ this.combinedPositionBinData = combinedPositionBinData;
11845
11862
  }
11846
- for (let i = highestIndex; i >= 0; i--) {
11847
- if (number.testn(i)) {
11848
- return highestIndex - i;
11849
- }
11863
+ address() {
11864
+ return this.positionAddress;
11850
11865
  }
11851
- return null;
11852
- }
11853
- function leastSignificantBit(number, bitLength) {
11854
- if (number.isZero()) {
11855
- return null;
11866
+ totalClaimedRewards() {
11867
+ return this.inner.totalClaimedRewards;
11856
11868
  }
11857
- for (let i = 0; i < bitLength; i++) {
11858
- if (number.testn(i)) {
11859
- return i;
11869
+ feeOwner() {
11870
+ return this.inner.feeOwner;
11871
+ }
11872
+ lockReleasePoint() {
11873
+ return this.inner.lockReleasePoint;
11874
+ }
11875
+ operator() {
11876
+ return this.inner.operator;
11877
+ }
11878
+ totalClaimedFeeYAmount() {
11879
+ return this.inner.totalClaimedFeeYAmount;
11880
+ }
11881
+ totalClaimedFeeXAmount() {
11882
+ return this.inner.totalClaimedFeeXAmount;
11883
+ }
11884
+ lbPair() {
11885
+ return this.inner.lbPair;
11886
+ }
11887
+ lowerBinId() {
11888
+ return new (0, _bnjs2.default)(this.inner.lowerBinId);
11889
+ }
11890
+ upperBinId() {
11891
+ return new (0, _bnjs2.default)(this.inner.upperBinId);
11892
+ }
11893
+ liquidityShares() {
11894
+ return this.combinedPositionBinData.liquidityShares;
11895
+ }
11896
+ rewardInfos() {
11897
+ return this.combinedPositionBinData.rewardInfos;
11898
+ }
11899
+ feeInfos() {
11900
+ return this.combinedPositionBinData.feeInfos;
11901
+ }
11902
+ lastUpdatedAt() {
11903
+ return this.inner.lastUpdatedAt;
11904
+ }
11905
+ getBinArrayIndexesCoverage() {
11906
+ const isExtended = this.extended.length > 0;
11907
+ if (isExtended) {
11908
+ return getBinArrayIndexesCoverage(this.lowerBinId(), this.upperBinId());
11909
+ } else {
11910
+ const lowerBinArrayIndex = binIdToBinArrayIndex(this.lowerBinId());
11911
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _bnjs2.default)(1));
11912
+ return [lowerBinArrayIndex, upperBinArrayIndex];
11860
11913
  }
11861
11914
  }
11862
- return null;
11915
+ getBinArrayKeysCoverage(programId) {
11916
+ return this.getBinArrayIndexesCoverage().map(
11917
+ (index) => deriveBinArray(this.lbPair(), index, programId)[0]
11918
+ );
11919
+ }
11920
+ version() {
11921
+ return 1 /* V2 */;
11922
+ }
11923
+ owner() {
11924
+ return this.inner.owner;
11925
+ }
11926
+ width() {
11927
+ return this.upperBinId().sub(this.lowerBinId()).add(new (0, _bnjs2.default)(1));
11928
+ }
11929
+ };
11930
+
11931
+ // src/dlmm/helpers/positions/index.ts
11932
+ function getBinArrayIndexesCoverage(lowerBinId, upperBinId) {
11933
+ const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
11934
+ const upperBinArrayIndex = binIdToBinArrayIndex(upperBinId);
11935
+ const binArrayIndexes = [];
11936
+ for (let i = lowerBinArrayIndex.toNumber(); i <= upperBinArrayIndex.toNumber(); i++) {
11937
+ binArrayIndexes.push(new (0, _bnjs2.default)(i));
11938
+ }
11939
+ return binArrayIndexes;
11863
11940
  }
11864
- function extensionBitmapRange() {
11865
- return [
11866
- BIN_ARRAY_BITMAP_SIZE.neg().mul(
11867
- EXTENSION_BINARRAY_BITMAP_SIZE.add(new (0, _anchor.BN)(1))
11868
- ),
11869
- BIN_ARRAY_BITMAP_SIZE.mul(
11870
- EXTENSION_BINARRAY_BITMAP_SIZE.add(new (0, _anchor.BN)(1))
11871
- ).sub(new (0, _anchor.BN)(1))
11872
- ];
11941
+ function getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId) {
11942
+ const binArrayIndexes = getBinArrayIndexesCoverage(lowerBinId, upperBinId);
11943
+ return binArrayIndexes.map((index) => {
11944
+ return deriveBinArray(lbPair, index, programId)[0];
11945
+ });
11873
11946
  }
11874
- function findSetBit(startIndex, endIndex, binArrayBitmapExtension) {
11875
- const getBinArrayOffset = (binArrayIndex) => {
11876
- return binArrayIndex.gt(new (0, _anchor.BN)(0)) ? binArrayIndex.mod(BIN_ARRAY_BITMAP_SIZE) : binArrayIndex.add(new (0, _anchor.BN)(1)).neg().mod(BIN_ARRAY_BITMAP_SIZE);
11877
- };
11878
- const getBitmapOffset = (binArrayIndex) => {
11879
- return binArrayIndex.gt(new (0, _anchor.BN)(0)) ? binArrayIndex.div(BIN_ARRAY_BITMAP_SIZE).sub(new (0, _anchor.BN)(1)) : binArrayIndex.add(new (0, _anchor.BN)(1)).neg().div(BIN_ARRAY_BITMAP_SIZE).sub(new (0, _anchor.BN)(1));
11880
- };
11881
- if (startIndex <= endIndex) {
11882
- for (let i = startIndex; i <= endIndex; i++) {
11883
- const binArrayOffset = getBinArrayOffset(new (0, _anchor.BN)(i)).toNumber();
11884
- const bitmapOffset = getBitmapOffset(new (0, _anchor.BN)(i)).toNumber();
11885
- const bitmapChunks = i > 0 ? binArrayBitmapExtension.positiveBinArrayBitmap[bitmapOffset] : binArrayBitmapExtension.negativeBinArrayBitmap[bitmapOffset];
11886
- const bitmap = buildBitmapFromU64Arrays(bitmapChunks, 1 /* U512 */);
11887
- if (bitmap.testn(binArrayOffset)) {
11888
- return i;
11889
- }
11890
- }
11891
- } else {
11892
- for (let i = startIndex; i >= endIndex; i--) {
11893
- const binArrayOffset = getBinArrayOffset(new (0, _anchor.BN)(i)).toNumber();
11894
- const bitmapOffset = getBitmapOffset(new (0, _anchor.BN)(i)).toNumber();
11895
- const bitmapChunks = i > 0 ? binArrayBitmapExtension.positiveBinArrayBitmap[bitmapOffset] : binArrayBitmapExtension.negativeBinArrayBitmap[bitmapOffset];
11896
- const bitmap = buildBitmapFromU64Arrays(bitmapChunks, 1 /* U512 */);
11897
- if (bitmap.testn(binArrayOffset)) {
11898
- return i;
11899
- }
11947
+ function getBinArrayAccountMetasCoverage(lowerBinId, upperBinId, lbPair, programId) {
11948
+ return getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId).map(
11949
+ (key) => {
11950
+ return {
11951
+ pubkey: key,
11952
+ isSigner: false,
11953
+ isWritable: true
11954
+ };
11900
11955
  }
11901
- }
11902
- return null;
11903
- }
11904
- function isOverflowDefaultBinArrayBitmap(binArrayIndex) {
11905
- const [minBinArrayIndex, maxBinArrayIndex] = internalBitmapRange();
11906
- return binArrayIndex.gt(maxBinArrayIndex) || binArrayIndex.lt(minBinArrayIndex);
11956
+ );
11907
11957
  }
11908
- function deriveBinArrayBitmapExtension(lbPair, programId) {
11909
- return _web3js.PublicKey.findProgramAddressSync(
11910
- [Buffer.from("bitmap"), lbPair.toBytes()],
11911
- programId
11958
+ function getPositionLowerUpperBinIdWithLiquidity(position) {
11959
+ const binWithLiquidity = position.positionBinData.filter(
11960
+ (b) => !new (0, _bnjs2.default)(b.binLiquidity).isZero() || !new (0, _bnjs2.default)(b.positionFeeXAmount.toString()).isZero() || !new (0, _bnjs2.default)(b.positionFeeYAmount.toString()).isZero() || !new (0, _bnjs2.default)(b.positionRewardAmount[0].toString()).isZero() || !new (0, _bnjs2.default)(b.positionRewardAmount[1].toString()).isZero()
11912
11961
  );
11962
+ return binWithLiquidity.length > 0 ? {
11963
+ lowerBinId: new (0, _bnjs2.default)(binWithLiquidity[0].binId),
11964
+ upperBinId: new (0, _bnjs2.default)(binWithLiquidity[binWithLiquidity.length - 1].binId)
11965
+ } : null;
11913
11966
  }
11914
- function binIdToBinArrayIndex(binId) {
11915
- const { div: idx, mod } = binId.divmod(MAX_BIN_ARRAY_SIZE);
11916
- return binId.isNeg() && !mod.isZero() ? idx.sub(new (0, _anchor.BN)(1)) : idx;
11967
+ function isPositionNoFee(position) {
11968
+ return position.feeX.isZero() && position.feeY.isZero();
11917
11969
  }
11918
- function getBinArrayLowerUpperBinId(binArrayIndex) {
11919
- const lowerBinId = binArrayIndex.mul(MAX_BIN_ARRAY_SIZE);
11920
- const upperBinId = lowerBinId.add(MAX_BIN_ARRAY_SIZE).sub(new (0, _anchor.BN)(1));
11921
- return [lowerBinId, upperBinId];
11970
+ function isPositionNoReward(position) {
11971
+ return position.rewardOne.isZero() && position.rewardTwo.isZero();
11922
11972
  }
11923
- function isBinIdWithinBinArray(activeId, binArrayIndex) {
11924
- const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayIndex);
11925
- return activeId.gte(lowerBinId) && activeId.lte(upperBinId);
11973
+ function chunkBinRangeIntoExtendedPositions(minBinId, maxBinId) {
11974
+ const chunkedBinRange = [];
11975
+ for (let currentMinBinId = minBinId; currentMinBinId <= maxBinId; currentMinBinId += POSITION_MAX_LENGTH.toNumber()) {
11976
+ const currentMaxBinId = Math.min(
11977
+ currentMinBinId + POSITION_MAX_LENGTH.toNumber() - 1,
11978
+ maxBinId
11979
+ );
11980
+ chunkedBinRange.push({
11981
+ lowerBinId: currentMinBinId,
11982
+ upperBinId: currentMaxBinId
11983
+ });
11984
+ }
11985
+ return chunkedBinRange;
11926
11986
  }
11927
- function getBinFromBinArray(binId, binArray) {
11928
- const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArray.index);
11929
- let index = 0;
11930
- if (binId > 0) {
11931
- index = binId - lowerBinId.toNumber();
11932
- } else {
11987
+ function chunkBinRange(minBinId, maxBinId, binPerChunk) {
11988
+ const chunkedBinRange = [];
11989
+ let startBinId = minBinId;
11990
+ binPerChunk = _nullishCoalesce(binPerChunk, () => ( DEFAULT_BIN_PER_POSITION.toNumber()));
11991
+ while (startBinId <= maxBinId) {
11992
+ const endBinId = Math.min(startBinId + binPerChunk - 1, maxBinId);
11993
+ chunkedBinRange.push({
11994
+ lowerBinId: startBinId,
11995
+ upperBinId: endBinId
11996
+ });
11997
+ startBinId += binPerChunk;
11998
+ }
11999
+ return chunkedBinRange;
12000
+ }
12001
+ function chunkPositionBinRange(position, minBinId, maxBinId) {
12002
+ const chunkedFeesAndRewards = [];
12003
+ let totalAmountX = new (0, _bnjs2.default)(0);
12004
+ let totalAmountY = new (0, _bnjs2.default)(0);
12005
+ let totalFeeXAmount = new (0, _bnjs2.default)(0);
12006
+ let totalFeeYAmount = new (0, _bnjs2.default)(0);
12007
+ let totalRewardAmounts = [new (0, _bnjs2.default)(0), new (0, _bnjs2.default)(0)];
12008
+ let count = 0;
12009
+ for (let i = 0; i < position.positionData.positionBinData.length; i++) {
12010
+ const positionBinData = position.positionData.positionBinData[i];
12011
+ if (positionBinData.binId >= minBinId && positionBinData.binId <= maxBinId) {
12012
+ totalFeeXAmount = totalFeeXAmount.add(
12013
+ new (0, _bnjs2.default)(positionBinData.positionFeeXAmount)
12014
+ );
12015
+ totalFeeYAmount = totalFeeYAmount.add(
12016
+ new (0, _bnjs2.default)(positionBinData.positionFeeYAmount)
12017
+ );
12018
+ totalAmountX = totalAmountX.add(new (0, _bnjs2.default)(positionBinData.positionXAmount));
12019
+ totalAmountY = totalAmountY.add(new (0, _bnjs2.default)(positionBinData.positionYAmount));
12020
+ for (const [
12021
+ index,
12022
+ reward
12023
+ ] of positionBinData.positionRewardAmount.entries()) {
12024
+ totalRewardAmounts[index] = totalRewardAmounts[index].add(
12025
+ new (0, _bnjs2.default)(reward)
12026
+ );
12027
+ }
12028
+ count++;
12029
+ }
12030
+ if (count === DEFAULT_BIN_PER_POSITION.toNumber() || positionBinData.binId == maxBinId) {
12031
+ chunkedFeesAndRewards.push({
12032
+ minBinId: positionBinData.binId - count + 1,
12033
+ maxBinId: positionBinData.binId,
12034
+ feeXAmount: totalFeeXAmount,
12035
+ feeYAmount: totalFeeYAmount,
12036
+ rewardAmounts: totalRewardAmounts,
12037
+ amountX: totalAmountX,
12038
+ amountY: totalAmountY
12039
+ });
12040
+ totalFeeXAmount = new (0, _bnjs2.default)(0);
12041
+ totalFeeYAmount = new (0, _bnjs2.default)(0);
12042
+ totalAmountX = new (0, _bnjs2.default)(0);
12043
+ totalAmountY = new (0, _bnjs2.default)(0);
12044
+ totalRewardAmounts = [new (0, _bnjs2.default)(0), new (0, _bnjs2.default)(0)];
12045
+ count = 0;
12046
+ }
12047
+ }
12048
+ return chunkedFeesAndRewards;
12049
+ }
12050
+ function calculatePositionSize(binCount) {
12051
+ const extraBinCount = binCount.gt(DEFAULT_BIN_PER_POSITION) ? binCount.sub(DEFAULT_BIN_PER_POSITION) : new (0, _bnjs2.default)(0);
12052
+ return new (0, _bnjs2.default)(POSITION_MIN_SIZE).add(
12053
+ extraBinCount.mul(new (0, _bnjs2.default)(POSITION_BIN_DATA_SIZE))
12054
+ );
12055
+ }
12056
+ function getPositionRentExemption(connection, binCount) {
12057
+ const size = calculatePositionSize(binCount);
12058
+ return connection.getMinimumBalanceForRentExemption(size.toNumber());
12059
+ }
12060
+ async function getPositionExpandRentExemption(currentMinBinId, currentMaxBinId, connection, binCountToExpand) {
12061
+ const currentPositionWidth = currentMaxBinId.sub(currentMinBinId).addn(1);
12062
+ const positionWidthAfterExpand = currentPositionWidth.add(binCountToExpand);
12063
+ if (positionWidthAfterExpand.lte(DEFAULT_BIN_PER_POSITION)) {
12064
+ return 0;
12065
+ } else {
12066
+ const binCountInExpandedBytes = positionWidthAfterExpand.sub(
12067
+ DEFAULT_BIN_PER_POSITION
12068
+ );
12069
+ const expandSize = binCountInExpandedBytes.toNumber() * POSITION_BIN_DATA_SIZE;
12070
+ const [minimumLamports, rentExemptionLamports] = await Promise.all([
12071
+ connection.getMinimumBalanceForRentExemption(0),
12072
+ connection.getMinimumBalanceForRentExemption(expandSize)
12073
+ ]);
12074
+ return rentExemptionLamports - minimumLamports;
12075
+ }
12076
+ }
12077
+ function getExtendedPositionBinCount(minBinId, maxBinId) {
12078
+ const width = maxBinId.sub(minBinId).addn(1);
12079
+ const extended = width.sub(DEFAULT_BIN_PER_POSITION);
12080
+ return extended.lte(new (0, _bnjs2.default)(0)) ? new (0, _bnjs2.default)(0) : extended;
12081
+ }
12082
+ function decodeExtendedPosition(base, program, bytes) {
12083
+ const width = base.upperBinId - base.lowerBinId + 1;
12084
+ const extendedWidth = width - DEFAULT_BIN_PER_POSITION.toNumber();
12085
+ const extendedPosition = [];
12086
+ for (let i = 0; i < extendedWidth; i++) {
12087
+ const offset = i * POSITION_BIN_DATA_SIZE;
12088
+ const data = bytes.subarray(offset, offset + POSITION_BIN_DATA_SIZE);
12089
+ const decodedPositionBinData = program.coder.types.decode(
12090
+ // TODO: Find a type safe way
12091
+ "positionBinData",
12092
+ data
12093
+ );
12094
+ extendedPosition.push(decodedPositionBinData);
12095
+ }
12096
+ return extendedPosition;
12097
+ }
12098
+
12099
+ // src/dlmm/helpers/binArray.ts
12100
+ function internalBitmapRange() {
12101
+ const lowerBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.neg();
12102
+ const upperBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.sub(new (0, _anchor.BN)(1));
12103
+ return [lowerBinArrayIndex, upperBinArrayIndex];
12104
+ }
12105
+ function buildBitmapFromU64Arrays(u64Arrays, type) {
12106
+ const buffer = Buffer.concat(
12107
+ u64Arrays.map((b) => {
12108
+ return b.toArrayLike(Buffer, "le", 8);
12109
+ })
12110
+ );
12111
+ return new (0, _anchor.BN)(buffer, "le");
12112
+ }
12113
+ function bitmapTypeDetail(type) {
12114
+ if (type == 0 /* U1024 */) {
12115
+ return {
12116
+ bits: 1024,
12117
+ bytes: 1024 / 8
12118
+ };
12119
+ } else {
12120
+ return {
12121
+ bits: 512,
12122
+ bytes: 512 / 8
12123
+ };
12124
+ }
12125
+ }
12126
+ function mostSignificantBit(number, bitLength) {
12127
+ const highestIndex = bitLength - 1;
12128
+ if (number.isZero()) {
12129
+ return null;
12130
+ }
12131
+ for (let i = highestIndex; i >= 0; i--) {
12132
+ if (number.testn(i)) {
12133
+ return highestIndex - i;
12134
+ }
12135
+ }
12136
+ return null;
12137
+ }
12138
+ function leastSignificantBit(number, bitLength) {
12139
+ if (number.isZero()) {
12140
+ return null;
12141
+ }
12142
+ for (let i = 0; i < bitLength; i++) {
12143
+ if (number.testn(i)) {
12144
+ return i;
12145
+ }
12146
+ }
12147
+ return null;
12148
+ }
12149
+ function extensionBitmapRange() {
12150
+ return [
12151
+ BIN_ARRAY_BITMAP_SIZE.neg().mul(
12152
+ EXTENSION_BINARRAY_BITMAP_SIZE.add(new (0, _anchor.BN)(1))
12153
+ ),
12154
+ BIN_ARRAY_BITMAP_SIZE.mul(
12155
+ EXTENSION_BINARRAY_BITMAP_SIZE.add(new (0, _anchor.BN)(1))
12156
+ ).sub(new (0, _anchor.BN)(1))
12157
+ ];
12158
+ }
12159
+ function findSetBit(startIndex, endIndex, binArrayBitmapExtension) {
12160
+ const getBinArrayOffset = (binArrayIndex) => {
12161
+ return binArrayIndex.gt(new (0, _anchor.BN)(0)) ? binArrayIndex.mod(BIN_ARRAY_BITMAP_SIZE) : binArrayIndex.add(new (0, _anchor.BN)(1)).neg().mod(BIN_ARRAY_BITMAP_SIZE);
12162
+ };
12163
+ const getBitmapOffset = (binArrayIndex) => {
12164
+ return binArrayIndex.gt(new (0, _anchor.BN)(0)) ? binArrayIndex.div(BIN_ARRAY_BITMAP_SIZE).sub(new (0, _anchor.BN)(1)) : binArrayIndex.add(new (0, _anchor.BN)(1)).neg().div(BIN_ARRAY_BITMAP_SIZE).sub(new (0, _anchor.BN)(1));
12165
+ };
12166
+ if (startIndex <= endIndex) {
12167
+ for (let i = startIndex; i <= endIndex; i++) {
12168
+ const binArrayOffset = getBinArrayOffset(new (0, _anchor.BN)(i)).toNumber();
12169
+ const bitmapOffset = getBitmapOffset(new (0, _anchor.BN)(i)).toNumber();
12170
+ const bitmapChunks = i > 0 ? binArrayBitmapExtension.positiveBinArrayBitmap[bitmapOffset] : binArrayBitmapExtension.negativeBinArrayBitmap[bitmapOffset];
12171
+ const bitmap = buildBitmapFromU64Arrays(bitmapChunks, 1 /* U512 */);
12172
+ if (bitmap.testn(binArrayOffset)) {
12173
+ return i;
12174
+ }
12175
+ }
12176
+ } else {
12177
+ for (let i = startIndex; i >= endIndex; i--) {
12178
+ const binArrayOffset = getBinArrayOffset(new (0, _anchor.BN)(i)).toNumber();
12179
+ const bitmapOffset = getBitmapOffset(new (0, _anchor.BN)(i)).toNumber();
12180
+ const bitmapChunks = i > 0 ? binArrayBitmapExtension.positiveBinArrayBitmap[bitmapOffset] : binArrayBitmapExtension.negativeBinArrayBitmap[bitmapOffset];
12181
+ const bitmap = buildBitmapFromU64Arrays(bitmapChunks, 1 /* U512 */);
12182
+ if (bitmap.testn(binArrayOffset)) {
12183
+ return i;
12184
+ }
12185
+ }
12186
+ }
12187
+ return null;
12188
+ }
12189
+ function isOverflowDefaultBinArrayBitmap(binArrayIndex) {
12190
+ const [minBinArrayIndex, maxBinArrayIndex] = internalBitmapRange();
12191
+ return binArrayIndex.gt(maxBinArrayIndex) || binArrayIndex.lt(minBinArrayIndex);
12192
+ }
12193
+ function deriveBinArrayBitmapExtension(lbPair, programId) {
12194
+ return _web3js.PublicKey.findProgramAddressSync(
12195
+ [Buffer.from("bitmap"), lbPair.toBytes()],
12196
+ programId
12197
+ );
12198
+ }
12199
+ function binIdToBinArrayIndex(binId) {
12200
+ const { div: idx, mod } = binId.divmod(MAX_BIN_ARRAY_SIZE);
12201
+ return binId.isNeg() && !mod.isZero() ? idx.sub(new (0, _anchor.BN)(1)) : idx;
12202
+ }
12203
+ function getBinArrayLowerUpperBinId(binArrayIndex) {
12204
+ const lowerBinId = binArrayIndex.mul(MAX_BIN_ARRAY_SIZE);
12205
+ const upperBinId = lowerBinId.add(MAX_BIN_ARRAY_SIZE).sub(new (0, _anchor.BN)(1));
12206
+ return [lowerBinId, upperBinId];
12207
+ }
12208
+ function isBinIdWithinBinArray(activeId, binArrayIndex) {
12209
+ const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayIndex);
12210
+ return activeId.gte(lowerBinId) && activeId.lte(upperBinId);
12211
+ }
12212
+ function getBinFromBinArray(binId, binArray) {
12213
+ const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArray.index);
12214
+ let index = 0;
12215
+ if (binId > 0) {
12216
+ index = binId - lowerBinId.toNumber();
12217
+ } else {
11933
12218
  const delta = upperBinId.toNumber() - binId;
11934
12219
  index = MAX_BIN_ARRAY_SIZE.toNumber() - delta - 1;
11935
12220
  }
@@ -12048,455 +12333,181 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
12048
12333
  for (let i = 0; i < positionCount.toNumber(); i++) {
12049
12334
  const lowerBinId = minBinId.add(DEFAULT_BIN_PER_POSITION.mul(new (0, _anchor.BN)(i)));
12050
12335
  const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
12051
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
12052
- const [lowerBinArray] = deriveBinArray(pair, lowerBinArrayIndex, programId);
12053
- const [upperBinArray] = deriveBinArray(pair, upperBinArrayIndex, programId);
12054
- binArrays.set(lowerBinArray.toBase58(), lowerBinArrayIndex);
12055
- binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
12056
- }
12057
- return Array.from(binArrays, ([key, index]) => ({
12058
- key: new (0, _web3js.PublicKey)(key),
12059
- index
12060
- }));
12061
- }
12062
- function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version, lbPair) {
12063
- for (let currentBinId = lowerBinId; currentBinId <= upperBinId; currentBinId++) {
12064
- const bin = binsById.get(currentBinId);
12065
- if (bin != null) {
12066
- yield BinLiquidity.fromBin(
12067
- bin,
12068
- currentBinId,
12069
- binStep,
12070
- baseTokenDecimal,
12071
- quoteTokenDecimal,
12072
- version,
12073
- lbPair
12074
- );
12075
- } else {
12076
- yield BinLiquidity.empty(
12077
- currentBinId,
12078
- binStep,
12079
- baseTokenDecimal,
12080
- quoteTokenDecimal,
12081
- version
12082
- );
12083
- }
12084
- }
12085
- }
12086
- function getBinIdIndexInBinArray(binId, lowerBinId, upperBinId) {
12087
- if (binId.lt(lowerBinId) || binId.gt(upperBinId)) {
12088
- return null;
12089
- }
12090
- return binId.sub(lowerBinId);
12091
- }
12092
- function binDeltaToMinMaxBinId(binDelta, activeBinId) {
12093
- const minBinId = activeBinId - binDelta;
12094
- const maxBinId = minBinId + binDelta * 2;
12095
- return {
12096
- minBinId,
12097
- maxBinId
12098
- };
12099
- }
12100
- function decodeRewardPerTokenStored(bin) {
12101
- const rewardPerTokenStored0Buf0 = bin.fulfilledOrderAmountX.toArrayLike(
12102
- Buffer,
12103
- "le",
12104
- 8
12105
- );
12106
- const rewardPerTokenStored0Buf1 = bin.fulfilledOrderAmountY.toArrayLike(
12107
- Buffer,
12108
- "le",
12109
- 8
12110
- );
12111
- const rewardPerTokenStored0 = new (0, _anchor.BN)(
12112
- Buffer.concat([rewardPerTokenStored0Buf0, rewardPerTokenStored0Buf1]),
12113
- "le"
12114
- );
12115
- const rewardPerTokenStored1Buf0 = bin.limitOrderFeeAskSide.toArrayLike(
12116
- Buffer,
12117
- "le",
12118
- 8
12119
- );
12120
- const rewardPerTokenStored1Buf1 = bin.limitOrderFeeBidSide.toArrayLike(
12121
- Buffer,
12122
- "le",
12123
- 8
12124
- );
12125
- const rewardPerTokenStored1 = new (0, _anchor.BN)(
12126
- Buffer.concat([rewardPerTokenStored1Buf0, rewardPerTokenStored1Buf1]),
12127
- "le"
12128
- );
12129
- return [rewardPerTokenStored0, rewardPerTokenStored1];
12130
- }
12131
- function getBinArrayInfoForNonContiguousBinIds(binIds, programId, lbPair) {
12132
- let binArrayBitmapExtension = programId;
12133
- const binArrayIndexes = /* @__PURE__ */ new Set();
12134
- for (const binId of binIds) {
12135
- const binArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(binId));
12136
- if (isOverflowDefaultBinArrayBitmap(binArrayIndex) && binArrayBitmapExtension.equals(programId)) {
12137
- binArrayBitmapExtension = deriveBinArrayBitmapExtension(
12138
- lbPair,
12139
- programId
12140
- )[0];
12141
- }
12142
- binArrayIndexes.add(binArrayIndex.toNumber());
12143
- }
12144
- const binArrayPubkeys = [...binArrayIndexes].map(
12145
- (idx) => deriveBinArray(lbPair, new (0, _anchor.BN)(idx), programId)[0]
12146
- );
12147
- const binArrayAccountMetas = binArrayPubkeys.map((pubkey) => {
12148
- return {
12149
- pubkey,
12150
- isSigner: false,
12151
- isWritable: true
12152
- };
12153
- });
12154
- return {
12155
- binArrayAccountMetas,
12156
- binArrayBitmapExtension,
12157
- binArrayIndexes: [...binArrayIndexes].map((idx) => new (0, _anchor.BN)(idx))
12158
- };
12159
- }
12160
-
12161
- // src/dlmm/helpers/computeUnit.ts
12162
-
12163
-
12164
-
12165
-
12166
-
12167
-
12168
- var DEFAULT_ADD_LIQUIDITY_CU = 1e6;
12169
- var DEFAULT_EXTEND_POSITION_HIGH_CU = 1e6;
12170
- var DEFAULT_EXTEND_POSITION_LOW_CU = 3e4;
12171
- var DEFAULT_INIT_POSITION_CU = 3e4;
12172
- var DEFAULT_INIT_BIN_ARRAY_CU = 35e4;
12173
- var MIN_CU_BUFFER = 5e4;
12174
- var MAX_CU_BUFFER = 2e5;
12175
- var MAX_CU = 14e5;
12176
- var getDefaultExtendPositionCU = (side) => {
12177
- switch (side) {
12178
- case 0 /* Lower */:
12179
- return DEFAULT_EXTEND_POSITION_HIGH_CU;
12180
- case 1 /* Upper */:
12181
- return DEFAULT_EXTEND_POSITION_LOW_CU;
12182
- }
12183
- };
12184
- var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
12185
- const testInstructions = [
12186
- // Set an arbitrarily high number in simulation
12187
- // so we can be sure the transaction will succeed
12188
- // and get the real compute units used
12189
- _web3js.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
12190
- ...instructions
12191
- ];
12192
- const testTransaction = new (0, _web3js.VersionedTransaction)(
12193
- new (0, _web3js.TransactionMessage)({
12194
- instructions: testInstructions,
12195
- payerKey: payer,
12196
- // RecentBlockhash can by any public key during simulation
12197
- // since 'replaceRecentBlockhash' is set to 'true' below
12198
- recentBlockhash: _web3js.PublicKey.default.toString()
12199
- }).compileToV0Message(lookupTables)
12200
- );
12201
- const rpcResponse = await connection.simulateTransaction(testTransaction, {
12202
- replaceRecentBlockhash: true,
12203
- sigVerify: false,
12204
- commitment
12205
- });
12206
- if (_optionalChain([rpcResponse, 'optionalAccess', _45 => _45.value, 'optionalAccess', _46 => _46.err])) {
12207
- const logs = _optionalChain([rpcResponse, 'access', _47 => _47.value, 'access', _48 => _48.logs, 'optionalAccess', _49 => _49.join, 'call', _50 => _50("\n \u2022 ")]) || "No logs available";
12208
- throw new Error(
12209
- `Transaction simulation failed:
12210
- \u2022${logs}` + JSON.stringify(_optionalChain([rpcResponse, 'optionalAccess', _51 => _51.value, 'optionalAccess', _52 => _52.err]))
12211
- );
12212
- }
12213
- return rpcResponse.value.unitsConsumed || null;
12214
- };
12215
-
12216
- // src/dlmm/helpers/positions/index.ts
12217
-
12218
-
12219
- // src/dlmm/helpers/positions/wrapper.ts
12220
-
12221
- function combineBaseAndExtendedPositionBinData(base, extended) {
12222
- const combinedLiquidityShares = base.liquidityShares;
12223
- const combinedRewardInfos = base.rewardInfos;
12224
- const combinedFeeInfos = base.feeInfos;
12225
- for (const binData of extended) {
12226
- combinedLiquidityShares.push(binData.liquidityShare);
12227
- combinedRewardInfos.push(binData.rewardInfo);
12228
- combinedFeeInfos.push(binData.feeInfo);
12229
- }
12230
- return {
12231
- liquidityShares: combinedLiquidityShares,
12232
- rewardInfos: combinedRewardInfos,
12233
- feeInfos: combinedFeeInfos
12234
- };
12235
- }
12236
- function wrapPosition(program, key, account) {
12237
- const disc = account.data.subarray(0, 8);
12238
- if (disc.equals(Buffer.from(getAccountDiscriminator("positionV2")))) {
12239
- const state = decodeAccount(
12240
- program,
12241
- "positionV2",
12242
- account.data
12243
- );
12244
- const extended = decodeExtendedPosition(
12245
- state,
12246
- program,
12247
- account.data.subarray(8 + POSITION_MIN_SIZE)
12248
- );
12249
- const combinedPositionBinData = combineBaseAndExtendedPositionBinData(
12250
- state,
12251
- extended
12252
- );
12253
- return new PositionV2Wrapper(key, state, extended, combinedPositionBinData);
12254
- } else {
12255
- throw new Error("Unknown position account");
12256
- }
12257
- }
12258
- var PositionV2Wrapper = class {
12259
- constructor(positionAddress, inner, extended, combinedPositionBinData) {
12260
- this.positionAddress = positionAddress;
12261
- this.inner = inner;
12262
- this.extended = extended;
12263
- this.combinedPositionBinData = combinedPositionBinData;
12264
- }
12265
- address() {
12266
- return this.positionAddress;
12267
- }
12268
- totalClaimedRewards() {
12269
- return this.inner.totalClaimedRewards;
12270
- }
12271
- feeOwner() {
12272
- return this.inner.feeOwner;
12273
- }
12274
- lockReleasePoint() {
12275
- return this.inner.lockReleasePoint;
12276
- }
12277
- operator() {
12278
- return this.inner.operator;
12279
- }
12280
- totalClaimedFeeYAmount() {
12281
- return this.inner.totalClaimedFeeYAmount;
12282
- }
12283
- totalClaimedFeeXAmount() {
12284
- return this.inner.totalClaimedFeeXAmount;
12285
- }
12286
- lbPair() {
12287
- return this.inner.lbPair;
12288
- }
12289
- lowerBinId() {
12290
- return new (0, _bnjs2.default)(this.inner.lowerBinId);
12291
- }
12292
- upperBinId() {
12293
- return new (0, _bnjs2.default)(this.inner.upperBinId);
12294
- }
12295
- liquidityShares() {
12296
- return this.combinedPositionBinData.liquidityShares;
12297
- }
12298
- rewardInfos() {
12299
- return this.combinedPositionBinData.rewardInfos;
12300
- }
12301
- feeInfos() {
12302
- return this.combinedPositionBinData.feeInfos;
12303
- }
12304
- lastUpdatedAt() {
12305
- return this.inner.lastUpdatedAt;
12306
- }
12307
- getBinArrayIndexesCoverage() {
12308
- const isExtended = this.extended.length > 0;
12309
- if (isExtended) {
12310
- return getBinArrayIndexesCoverage(this.lowerBinId(), this.upperBinId());
12311
- } else {
12312
- const lowerBinArrayIndex = binIdToBinArrayIndex(this.lowerBinId());
12313
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _bnjs2.default)(1));
12314
- return [lowerBinArrayIndex, upperBinArrayIndex];
12315
- }
12316
- }
12317
- getBinArrayKeysCoverage(programId) {
12318
- return this.getBinArrayIndexesCoverage().map(
12319
- (index) => deriveBinArray(this.lbPair(), index, programId)[0]
12320
- );
12321
- }
12322
- version() {
12323
- return 1 /* V2 */;
12324
- }
12325
- owner() {
12326
- return this.inner.owner;
12327
- }
12328
- width() {
12329
- return this.upperBinId().sub(this.lowerBinId()).add(new (0, _bnjs2.default)(1));
12330
- }
12331
- };
12332
-
12333
- // src/dlmm/helpers/positions/index.ts
12334
- function getBinArrayIndexesCoverage(lowerBinId, upperBinId) {
12335
- const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
12336
- const upperBinArrayIndex = binIdToBinArrayIndex(upperBinId);
12337
- const binArrayIndexes = [];
12338
- for (let i = lowerBinArrayIndex.toNumber(); i <= upperBinArrayIndex.toNumber(); i++) {
12339
- binArrayIndexes.push(new (0, _bnjs2.default)(i));
12340
- }
12341
- return binArrayIndexes;
12342
- }
12343
- function getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId) {
12344
- const binArrayIndexes = getBinArrayIndexesCoverage(lowerBinId, upperBinId);
12345
- return binArrayIndexes.map((index) => {
12346
- return deriveBinArray(lbPair, index, programId)[0];
12347
- });
12348
- }
12349
- function getBinArrayAccountMetasCoverage(lowerBinId, upperBinId, lbPair, programId) {
12350
- return getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId).map(
12351
- (key) => {
12352
- return {
12353
- pubkey: key,
12354
- isSigner: false,
12355
- isWritable: true
12356
- };
12357
- }
12358
- );
12359
- }
12360
- function getPositionLowerUpperBinIdWithLiquidity(position) {
12361
- const binWithLiquidity = position.positionBinData.filter(
12362
- (b) => !new (0, _bnjs2.default)(b.binLiquidity).isZero() || !new (0, _bnjs2.default)(b.positionFeeXAmount.toString()).isZero() || !new (0, _bnjs2.default)(b.positionFeeYAmount.toString()).isZero() || !new (0, _bnjs2.default)(b.positionRewardAmount[0].toString()).isZero() || !new (0, _bnjs2.default)(b.positionRewardAmount[1].toString()).isZero()
12363
- );
12364
- return binWithLiquidity.length > 0 ? {
12365
- lowerBinId: new (0, _bnjs2.default)(binWithLiquidity[0].binId),
12366
- upperBinId: new (0, _bnjs2.default)(binWithLiquidity[binWithLiquidity.length - 1].binId)
12367
- } : null;
12368
- }
12369
- function isPositionNoFee(position) {
12370
- return position.feeX.isZero() && position.feeY.isZero();
12371
- }
12372
- function isPositionNoReward(position) {
12373
- return position.rewardOne.isZero() && position.rewardTwo.isZero();
12374
- }
12375
- function chunkBinRangeIntoExtendedPositions(minBinId, maxBinId) {
12376
- const chunkedBinRange = [];
12377
- for (let currentMinBinId = minBinId; currentMinBinId <= maxBinId; currentMinBinId += POSITION_MAX_LENGTH.toNumber()) {
12378
- const currentMaxBinId = Math.min(
12379
- currentMinBinId + POSITION_MAX_LENGTH.toNumber() - 1,
12380
- maxBinId
12381
- );
12382
- chunkedBinRange.push({
12383
- lowerBinId: currentMinBinId,
12384
- upperBinId: currentMaxBinId
12385
- });
12336
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
12337
+ const [lowerBinArray] = deriveBinArray(pair, lowerBinArrayIndex, programId);
12338
+ const [upperBinArray] = deriveBinArray(pair, upperBinArrayIndex, programId);
12339
+ binArrays.set(lowerBinArray.toBase58(), lowerBinArrayIndex);
12340
+ binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
12386
12341
  }
12387
- return chunkedBinRange;
12342
+ return Array.from(binArrays, ([key, index]) => ({
12343
+ key: new (0, _web3js.PublicKey)(key),
12344
+ index
12345
+ }));
12388
12346
  }
12389
- function chunkBinRange(minBinId, maxBinId, binPerChunk) {
12390
- const chunkedBinRange = [];
12391
- let startBinId = minBinId;
12392
- binPerChunk = _nullishCoalesce(binPerChunk, () => ( DEFAULT_BIN_PER_POSITION.toNumber()));
12393
- while (startBinId <= maxBinId) {
12394
- const endBinId = Math.min(startBinId + binPerChunk - 1, maxBinId);
12395
- chunkedBinRange.push({
12396
- lowerBinId: startBinId,
12397
- upperBinId: endBinId
12398
- });
12399
- startBinId += binPerChunk;
12400
- }
12401
- return chunkedBinRange;
12347
+ function getBinArraysRequiredByPositionRange2(pair, fromBinId, toBinId, programId) {
12348
+ const [minBinId, maxBinId] = fromBinId.lt(toBinId) ? [fromBinId, toBinId] : [toBinId, fromBinId];
12349
+ const binArrayIndexes = getBinArrayIndexesCoverage(minBinId, maxBinId);
12350
+ return Array.from(binArrayIndexes, (index) => {
12351
+ const [binArrayPubkey] = deriveBinArray(pair, index, programId);
12352
+ return {
12353
+ key: binArrayPubkey,
12354
+ index
12355
+ };
12356
+ });
12402
12357
  }
12403
- function chunkPositionBinRange(position, minBinId, maxBinId) {
12404
- const chunkedFeesAndRewards = [];
12405
- let totalAmountX = new (0, _bnjs2.default)(0);
12406
- let totalAmountY = new (0, _bnjs2.default)(0);
12407
- let totalFeeXAmount = new (0, _bnjs2.default)(0);
12408
- let totalFeeYAmount = new (0, _bnjs2.default)(0);
12409
- let totalRewardAmounts = [new (0, _bnjs2.default)(0), new (0, _bnjs2.default)(0)];
12410
- let count = 0;
12411
- for (let i = 0; i < position.positionData.positionBinData.length; i++) {
12412
- const positionBinData = position.positionData.positionBinData[i];
12413
- if (positionBinData.binId >= minBinId && positionBinData.binId <= maxBinId) {
12414
- totalFeeXAmount = totalFeeXAmount.add(
12415
- new (0, _bnjs2.default)(positionBinData.positionFeeXAmount)
12358
+ function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version, lbPair) {
12359
+ for (let currentBinId = lowerBinId; currentBinId <= upperBinId; currentBinId++) {
12360
+ const bin = binsById.get(currentBinId);
12361
+ if (bin != null) {
12362
+ yield BinLiquidity.fromBin(
12363
+ bin,
12364
+ currentBinId,
12365
+ binStep,
12366
+ baseTokenDecimal,
12367
+ quoteTokenDecimal,
12368
+ version,
12369
+ lbPair
12416
12370
  );
12417
- totalFeeYAmount = totalFeeYAmount.add(
12418
- new (0, _bnjs2.default)(positionBinData.positionFeeYAmount)
12371
+ } else {
12372
+ yield BinLiquidity.empty(
12373
+ currentBinId,
12374
+ binStep,
12375
+ baseTokenDecimal,
12376
+ quoteTokenDecimal,
12377
+ version
12419
12378
  );
12420
- totalAmountX = totalAmountX.add(new (0, _bnjs2.default)(positionBinData.positionXAmount));
12421
- totalAmountY = totalAmountY.add(new (0, _bnjs2.default)(positionBinData.positionYAmount));
12422
- for (const [
12423
- index,
12424
- reward
12425
- ] of positionBinData.positionRewardAmount.entries()) {
12426
- totalRewardAmounts[index] = totalRewardAmounts[index].add(
12427
- new (0, _bnjs2.default)(reward)
12428
- );
12429
- }
12430
- count++;
12431
- }
12432
- if (count === DEFAULT_BIN_PER_POSITION.toNumber() || positionBinData.binId == maxBinId) {
12433
- chunkedFeesAndRewards.push({
12434
- minBinId: positionBinData.binId - count + 1,
12435
- maxBinId: positionBinData.binId,
12436
- feeXAmount: totalFeeXAmount,
12437
- feeYAmount: totalFeeYAmount,
12438
- rewardAmounts: totalRewardAmounts,
12439
- amountX: totalAmountX,
12440
- amountY: totalAmountY
12441
- });
12442
- totalFeeXAmount = new (0, _bnjs2.default)(0);
12443
- totalFeeYAmount = new (0, _bnjs2.default)(0);
12444
- totalAmountX = new (0, _bnjs2.default)(0);
12445
- totalAmountY = new (0, _bnjs2.default)(0);
12446
- totalRewardAmounts = [new (0, _bnjs2.default)(0), new (0, _bnjs2.default)(0)];
12447
- count = 0;
12448
12379
  }
12449
12380
  }
12450
- return chunkedFeesAndRewards;
12451
12381
  }
12452
- function calculatePositionSize(binCount) {
12453
- const extraBinCount = binCount.gt(DEFAULT_BIN_PER_POSITION) ? binCount.sub(DEFAULT_BIN_PER_POSITION) : new (0, _bnjs2.default)(0);
12454
- return new (0, _bnjs2.default)(POSITION_MIN_SIZE).add(
12455
- extraBinCount.mul(new (0, _bnjs2.default)(POSITION_BIN_DATA_SIZE))
12456
- );
12382
+ function getBinIdIndexInBinArray(binId, lowerBinId, upperBinId) {
12383
+ if (binId.lt(lowerBinId) || binId.gt(upperBinId)) {
12384
+ return null;
12385
+ }
12386
+ return binId.sub(lowerBinId);
12457
12387
  }
12458
- function getPositionRentExemption(connection, binCount) {
12459
- const size = calculatePositionSize(binCount);
12460
- return connection.getMinimumBalanceForRentExemption(size.toNumber());
12388
+ function binDeltaToMinMaxBinId(binDelta, activeBinId) {
12389
+ const minBinId = activeBinId - binDelta;
12390
+ const maxBinId = minBinId + binDelta * 2;
12391
+ return {
12392
+ minBinId,
12393
+ maxBinId
12394
+ };
12461
12395
  }
12462
- async function getPositionExpandRentExemption(currentMinBinId, currentMaxBinId, connection, binCountToExpand) {
12463
- const currentPositionWidth = currentMaxBinId.sub(currentMinBinId).addn(1);
12464
- const positionWidthAfterExpand = currentPositionWidth.add(binCountToExpand);
12465
- if (positionWidthAfterExpand.lte(DEFAULT_BIN_PER_POSITION)) {
12466
- return 0;
12467
- } else {
12468
- const binCountInExpandedBytes = positionWidthAfterExpand.sub(
12469
- DEFAULT_BIN_PER_POSITION
12470
- );
12471
- const expandSize = binCountInExpandedBytes.toNumber() * POSITION_BIN_DATA_SIZE;
12472
- const [minimumLamports, rentExemptionLamports] = await Promise.all([
12473
- connection.getMinimumBalanceForRentExemption(0),
12474
- connection.getMinimumBalanceForRentExemption(expandSize)
12475
- ]);
12476
- return rentExemptionLamports - minimumLamports;
12477
- }
12396
+ function decodeRewardPerTokenStored(bin) {
12397
+ const rewardPerTokenStored0Buf0 = bin.fulfilledOrderAmountX.toArrayLike(
12398
+ Buffer,
12399
+ "le",
12400
+ 8
12401
+ );
12402
+ const rewardPerTokenStored0Buf1 = bin.fulfilledOrderAmountY.toArrayLike(
12403
+ Buffer,
12404
+ "le",
12405
+ 8
12406
+ );
12407
+ const rewardPerTokenStored0 = new (0, _anchor.BN)(
12408
+ Buffer.concat([rewardPerTokenStored0Buf0, rewardPerTokenStored0Buf1]),
12409
+ "le"
12410
+ );
12411
+ const rewardPerTokenStored1Buf0 = bin.limitOrderFeeAskSide.toArrayLike(
12412
+ Buffer,
12413
+ "le",
12414
+ 8
12415
+ );
12416
+ const rewardPerTokenStored1Buf1 = bin.limitOrderFeeBidSide.toArrayLike(
12417
+ Buffer,
12418
+ "le",
12419
+ 8
12420
+ );
12421
+ const rewardPerTokenStored1 = new (0, _anchor.BN)(
12422
+ Buffer.concat([rewardPerTokenStored1Buf0, rewardPerTokenStored1Buf1]),
12423
+ "le"
12424
+ );
12425
+ return [rewardPerTokenStored0, rewardPerTokenStored1];
12478
12426
  }
12479
- function getExtendedPositionBinCount(minBinId, maxBinId) {
12480
- const width = maxBinId.sub(minBinId).addn(1);
12481
- const extended = width.sub(DEFAULT_BIN_PER_POSITION);
12482
- return extended.lte(new (0, _bnjs2.default)(0)) ? new (0, _bnjs2.default)(0) : extended;
12427
+ function getBinArrayInfoForNonContiguousBinIds(binIds, programId, lbPair) {
12428
+ let binArrayBitmapExtension = programId;
12429
+ const binArrayIndexes = /* @__PURE__ */ new Set();
12430
+ for (const binId of binIds) {
12431
+ const binArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(binId));
12432
+ if (isOverflowDefaultBinArrayBitmap(binArrayIndex) && binArrayBitmapExtension.equals(programId)) {
12433
+ binArrayBitmapExtension = deriveBinArrayBitmapExtension(
12434
+ lbPair,
12435
+ programId
12436
+ )[0];
12437
+ }
12438
+ binArrayIndexes.add(binArrayIndex.toNumber());
12439
+ }
12440
+ const binArrayPubkeys = [...binArrayIndexes].map(
12441
+ (idx) => deriveBinArray(lbPair, new (0, _anchor.BN)(idx), programId)[0]
12442
+ );
12443
+ const binArrayAccountMetas = binArrayPubkeys.map((pubkey) => {
12444
+ return {
12445
+ pubkey,
12446
+ isSigner: false,
12447
+ isWritable: true
12448
+ };
12449
+ });
12450
+ return {
12451
+ binArrayAccountMetas,
12452
+ binArrayBitmapExtension,
12453
+ binArrayIndexes: [...binArrayIndexes].map((idx) => new (0, _anchor.BN)(idx))
12454
+ };
12483
12455
  }
12484
- function decodeExtendedPosition(base, program, bytes) {
12485
- const width = base.upperBinId - base.lowerBinId + 1;
12486
- const extendedWidth = width - DEFAULT_BIN_PER_POSITION.toNumber();
12487
- const extendedPosition = [];
12488
- for (let i = 0; i < extendedWidth; i++) {
12489
- const offset = i * POSITION_BIN_DATA_SIZE;
12490
- const data = bytes.subarray(offset, offset + POSITION_BIN_DATA_SIZE);
12491
- const decodedPositionBinData = program.coder.types.decode(
12492
- // TODO: Find a type safe way
12493
- "positionBinData",
12494
- data
12456
+
12457
+ // src/dlmm/helpers/computeUnit.ts
12458
+
12459
+
12460
+
12461
+
12462
+
12463
+
12464
+ var DEFAULT_ADD_LIQUIDITY_CU = 1e6;
12465
+ var DEFAULT_EXTEND_POSITION_HIGH_CU = 1e6;
12466
+ var DEFAULT_EXTEND_POSITION_LOW_CU = 3e4;
12467
+ var DEFAULT_INIT_POSITION_CU = 3e4;
12468
+ var DEFAULT_INIT_BIN_ARRAY_CU = 35e4;
12469
+ var MIN_CU_BUFFER = 5e4;
12470
+ var MAX_CU_BUFFER = 2e5;
12471
+ var MAX_CU = 14e5;
12472
+ var getDefaultExtendPositionCU = (side) => {
12473
+ switch (side) {
12474
+ case 0 /* Lower */:
12475
+ return DEFAULT_EXTEND_POSITION_HIGH_CU;
12476
+ case 1 /* Upper */:
12477
+ return DEFAULT_EXTEND_POSITION_LOW_CU;
12478
+ }
12479
+ };
12480
+ var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
12481
+ const testInstructions = [
12482
+ // Set an arbitrarily high number in simulation
12483
+ // so we can be sure the transaction will succeed
12484
+ // and get the real compute units used
12485
+ _web3js.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
12486
+ ...instructions
12487
+ ];
12488
+ const testTransaction = new (0, _web3js.VersionedTransaction)(
12489
+ new (0, _web3js.TransactionMessage)({
12490
+ instructions: testInstructions,
12491
+ payerKey: payer,
12492
+ // RecentBlockhash can by any public key during simulation
12493
+ // since 'replaceRecentBlockhash' is set to 'true' below
12494
+ recentBlockhash: _web3js.PublicKey.default.toString()
12495
+ }).compileToV0Message(lookupTables)
12496
+ );
12497
+ const rpcResponse = await connection.simulateTransaction(testTransaction, {
12498
+ replaceRecentBlockhash: true,
12499
+ sigVerify: false,
12500
+ commitment
12501
+ });
12502
+ if (_optionalChain([rpcResponse, 'optionalAccess', _45 => _45.value, 'optionalAccess', _46 => _46.err])) {
12503
+ const logs = _optionalChain([rpcResponse, 'access', _47 => _47.value, 'access', _48 => _48.logs, 'optionalAccess', _49 => _49.join, 'call', _50 => _50("\n \u2022 ")]) || "No logs available";
12504
+ throw new Error(
12505
+ `Transaction simulation failed:
12506
+ \u2022${logs}` + JSON.stringify(_optionalChain([rpcResponse, 'optionalAccess', _51 => _51.value, 'optionalAccess', _52 => _52.err]))
12495
12507
  );
12496
- extendedPosition.push(decodedPositionBinData);
12497
12508
  }
12498
- return extendedPosition;
12499
- }
12509
+ return rpcResponse.value.unitsConsumed || null;
12510
+ };
12500
12511
 
12501
12512
  // src/dlmm/helpers/rebalance/rebalancePosition.ts
12502
12513
 
@@ -23323,7 +23334,8 @@ var src_default = DLMM;
23323
23334
 
23324
23335
 
23325
23336
 
23326
- exports.ADMIN = ADMIN; exports.ALT_ADDRESS = ALT_ADDRESS; exports.ActionType = ActionType; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_FEE = BIN_ARRAY_BITMAP_FEE; exports.BIN_ARRAY_BITMAP_FEE_BN = BIN_ARRAY_BITMAP_FEE_BN; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_DEFAULT_VERSION = BIN_ARRAY_DEFAULT_VERSION; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BIN_ARRAY_FEE_BN = BIN_ARRAY_FEE_BN; exports.BinLiquidity = BinLiquidity; exports.BitmapType = BitmapType; exports.ClockLayout = ClockLayout; exports.CollectFeeMode = CollectFeeMode; exports.ConcreteFunctionType = ConcreteFunctionType; exports.DEFAULT_BIN_PER_POSITION = DEFAULT_BIN_PER_POSITION; exports.DLMMError = DLMMError; exports.DlmmSdkError = DlmmSdkError; exports.DynamicOracle = DynamicOracle; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.FunctionType = FunctionType; exports.IDL = idl_default; exports.ILM_BASE = ILM_BASE; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.LIMIT_ORDER_BIN_DATA_SIZE = LIMIT_ORDER_BIN_DATA_SIZE; exports.LIMIT_ORDER_FEE_SHARE = LIMIT_ORDER_FEE_SHARE; exports.LIMIT_ORDER_MIN_SIZE = LIMIT_ORDER_MIN_SIZE; exports.LimitOrderStatus = LimitOrderStatus; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BINS_PER_POSITION = MAX_BINS_PER_POSITION; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_ID_PER_BIN_STEP = MAX_BIN_ID_PER_BIN_STEP; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_LIMIT_ORDER = MAX_BIN_PER_LIMIT_ORDER; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_EXTRA_BIN_ARRAYS = MAX_EXTRA_BIN_ARRAYS; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.MAX_RESIZE_LENGTH = MAX_RESIZE_LENGTH; exports.MEMO_PROGRAM_ID = MEMO_PROGRAM_ID; exports.Network = Network; exports.Observation = Observation; exports.POOL_FEE = POOL_FEE; exports.POOL_FEE_BN = POOL_FEE_BN; exports.POSITION_BIN_DATA_SIZE = POSITION_BIN_DATA_SIZE; exports.POSITION_FEE = POSITION_FEE; exports.POSITION_FEE_BN = POSITION_FEE_BN; exports.POSITION_MAX_LENGTH = POSITION_MAX_LENGTH; exports.POSITION_MIN_SIZE = POSITION_MIN_SIZE; exports.PRECISION = PRECISION; exports.PairStatus = PairStatus; exports.PairType = PairType; exports.PositionPermission = PositionPermission; exports.PositionV2Wrapper = PositionV2Wrapper; exports.PositionVersion = PositionVersion; exports.REBALANCE_POSITION_PADDING = REBALANCE_POSITION_PADDING; exports.RebalancePosition = RebalancePosition; exports.ResizeSide = ResizeSide; exports.Rounding = Rounding; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.ShrinkMode = ShrinkMode; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.TOKEN_ACCOUNT_FEE = TOKEN_ACCOUNT_FEE; exports.TOKEN_ACCOUNT_FEE_BN = TOKEN_ACCOUNT_FEE_BN; exports.U64_MAX = U64_MAX; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binArrayLbPairFilter = binArrayLbPairFilter; exports.binDeltaToMinMaxBinId = binDeltaToMinMaxBinId; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.buildBitFlagAndNegateStrategyParameters = buildBitFlagAndNegateStrategyParameters; exports.buildLiquidityStrategyParameters = buildLiquidityStrategyParameters; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculatePositionSize = calculatePositionSize; exports.calculateSpotDistribution = calculateSpotDistribution; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.capSlippagePercentage = capSlippagePercentage; exports.chunkBinRange = chunkBinRange; exports.chunkBinRangeIntoExtendedPositions = chunkBinRangeIntoExtendedPositions; exports.chunkDepositWithRebalanceEndpoint = chunkDepositWithRebalanceEndpoint; exports.chunkPositionBinRange = chunkPositionBinRange; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunkedGetProgramAccounts = chunkedGetProgramAccounts; exports.chunks = chunks; exports.compressBinAmount = compressBinAmount; exports.computeBaseFactorFromFeeBps = computeBaseFactorFromFeeBps; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.createProgram = createProgram; exports.decodeAccount = decodeAccount; exports.decodeExtendedPosition = decodeExtendedPosition; exports.decodeRewardPerTokenStored = decodeRewardPerTokenStored; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveCustomizablePermissionlessLbPair = deriveCustomizablePermissionlessLbPair; exports.deriveEventAuthority = deriveEventAuthority; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveLbPairWithPresetParamWithIndexKey = deriveLbPairWithPresetParamWithIndexKey; exports.deriveOperator = deriveOperator; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePlaceHolderAccountMeta = derivePlaceHolderAccountMeta; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.derivePresetParameterWithIndex = derivePresetParameterWithIndex; exports.deriveReserve = deriveReserve; exports.deriveRewardVault = deriveRewardVault; exports.deriveTokenBadge = deriveTokenBadge; exports.distributeAmountToCompressedBinsByRatio = distributeAmountToCompressedBinsByRatio; exports.encodePositionPermissions = encodePositionPermissions; exports.enumerateBins = enumerateBins; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.findOptimumDecompressMultiplier = findOptimumDecompressMultiplier; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.generateAmountForBinRange = generateAmountForBinRange; exports.generateBinAmount = generateBinAmount; exports.getAccountDiscriminator = getAccountDiscriminator; exports.getAmountIn = getAmountIn; exports.getAmountInBinsAskSide = getAmountInBinsAskSide; exports.getAmountInBinsBidSide = getAmountInBinsBidSide; exports.getAmountOut = getAmountOut; exports.getAndCapMaxActiveBinSlippage = getAndCapMaxActiveBinSlippage; exports.getAutoFillAmountByRebalancedPosition = getAutoFillAmountByRebalancedPosition; exports.getBaseFee = getBaseFee; exports.getBinArrayAccountMetasCoverage = getBinArrayAccountMetasCoverage; exports.getBinArrayIndexesCoverage = getBinArrayIndexesCoverage; exports.getBinArrayInfoForNonContiguousBinIds = getBinArrayInfoForNonContiguousBinIds; exports.getBinArrayKeysCoverage = getBinArrayKeysCoverage; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinCount = getBinCount; exports.getBinFromBinArray = getBinFromBinArray; exports.getBinIdIndexInBinArray = getBinIdIndexInBinArray; exports.getBinMaxAmountOut = getBinMaxAmountOut; exports.getC = getC; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getExcludedFeeAmount = getExcludedFeeAmount; exports.getExtendedPositionBinCount = getExtendedPositionBinCount; exports.getExtraAccountMetasForTransferHook = getExtraAccountMetasForTransferHook; exports.getFeeMode = getFeeMode; exports.getIncludedFeeAmount = getIncludedFeeAmount; exports.getLimitOrderLiquidity = getLimitOrderLiquidity; exports.getLiquidityStrategyParameterBuilder = getLiquidityStrategyParameterBuilder; exports.getMultipleMintsExtraAccountMetasForTransferHook = getMultipleMintsExtraAccountMetasForTransferHook; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPositionCount = getPositionCount; exports.getPositionCountByBinCount = getPositionCountByBinCount; exports.getPositionExpandRentExemption = getPositionExpandRentExemption; exports.getPositionLowerUpperBinIdWithLiquidity = getPositionLowerUpperBinIdWithLiquidity; exports.getPositionRentExemption = getPositionRentExemption; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getQPriceBaseFactor = getQPriceBaseFactor; exports.getQPriceFromId = getQPriceFromId; exports.getRebalanceBinArrayIndexesAndBitmapCoverage = getRebalanceBinArrayIndexesAndBitmapCoverage; exports.getSlippageMaxAmount = getSlippageMaxAmount; exports.getSlippageMinAmount = getSlippageMinAmount; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgramId = getTokenProgramId; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.isPositionNoFee = isPositionNoFee; exports.isPositionNoReward = isPositionNoReward; exports.isSupportLimitOrder = isSupportLimitOrder; exports.limitOrderFilter = limitOrderFilter; exports.limitOrderLbPairFilter = limitOrderLbPairFilter; exports.limitOrderOwnerFilter = limitOrderOwnerFilter; exports.mulDiv = mulDiv; exports.mulShr = mulShr; exports.parseLogs = parseLogs; exports.positionLbPairFilter = positionLbPairFilter; exports.positionOwnerFilter = positionOwnerFilter; exports.positionV2Filter = positionV2Filter; exports.presetParameter2BaseFactorFilter = presetParameter2BaseFactorFilter; exports.presetParameter2BaseFeePowerFactor = presetParameter2BaseFeePowerFactor; exports.presetParameter2BinStepFilter = presetParameter2BinStepFilter; exports.range = range; exports.resetUninvolvedLiquidityParams = resetUninvolvedLiquidityParams; exports.shlDiv = shlDiv; exports.splitFee = splitFee; exports.suggestBalancedXParametersFromY = suggestBalancedXParametersFromY; exports.suggestBalancedYParametersFromX = suggestBalancedYParametersFromX; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountIntoBins = toAmountIntoBins; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapOracle = wrapOracle; exports.wrapPosition = wrapPosition; exports.wrapSOLInstruction = wrapSOLInstruction;
23337
+
23338
+ exports.ADMIN = ADMIN; exports.ALT_ADDRESS = ALT_ADDRESS; exports.ActionType = ActionType; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_FEE = BIN_ARRAY_BITMAP_FEE; exports.BIN_ARRAY_BITMAP_FEE_BN = BIN_ARRAY_BITMAP_FEE_BN; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_DEFAULT_VERSION = BIN_ARRAY_DEFAULT_VERSION; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BIN_ARRAY_FEE_BN = BIN_ARRAY_FEE_BN; exports.BinLiquidity = BinLiquidity; exports.BitmapType = BitmapType; exports.ClockLayout = ClockLayout; exports.CollectFeeMode = CollectFeeMode; exports.ConcreteFunctionType = ConcreteFunctionType; exports.DEFAULT_BIN_PER_POSITION = DEFAULT_BIN_PER_POSITION; exports.DLMMError = DLMMError; exports.DlmmSdkError = DlmmSdkError; exports.DynamicOracle = DynamicOracle; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.FunctionType = FunctionType; exports.IDL = idl_default; exports.ILM_BASE = ILM_BASE; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.LIMIT_ORDER_BIN_DATA_SIZE = LIMIT_ORDER_BIN_DATA_SIZE; exports.LIMIT_ORDER_FEE_SHARE = LIMIT_ORDER_FEE_SHARE; exports.LIMIT_ORDER_MIN_SIZE = LIMIT_ORDER_MIN_SIZE; exports.LimitOrderStatus = LimitOrderStatus; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BINS_PER_POSITION = MAX_BINS_PER_POSITION; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_ID_PER_BIN_STEP = MAX_BIN_ID_PER_BIN_STEP; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_LIMIT_ORDER = MAX_BIN_PER_LIMIT_ORDER; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_EXTRA_BIN_ARRAYS = MAX_EXTRA_BIN_ARRAYS; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.MAX_RESIZE_LENGTH = MAX_RESIZE_LENGTH; exports.MEMO_PROGRAM_ID = MEMO_PROGRAM_ID; exports.Network = Network; exports.Observation = Observation; exports.POOL_FEE = POOL_FEE; exports.POOL_FEE_BN = POOL_FEE_BN; exports.POSITION_BIN_DATA_SIZE = POSITION_BIN_DATA_SIZE; exports.POSITION_FEE = POSITION_FEE; exports.POSITION_FEE_BN = POSITION_FEE_BN; exports.POSITION_MAX_LENGTH = POSITION_MAX_LENGTH; exports.POSITION_MIN_SIZE = POSITION_MIN_SIZE; exports.PRECISION = PRECISION; exports.PairStatus = PairStatus; exports.PairType = PairType; exports.PositionPermission = PositionPermission; exports.PositionV2Wrapper = PositionV2Wrapper; exports.PositionVersion = PositionVersion; exports.REBALANCE_POSITION_PADDING = REBALANCE_POSITION_PADDING; exports.RebalancePosition = RebalancePosition; exports.ResizeSide = ResizeSide; exports.Rounding = Rounding; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.ShrinkMode = ShrinkMode; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.TOKEN_ACCOUNT_FEE = TOKEN_ACCOUNT_FEE; exports.TOKEN_ACCOUNT_FEE_BN = TOKEN_ACCOUNT_FEE_BN; exports.U64_MAX = U64_MAX; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binArrayLbPairFilter = binArrayLbPairFilter; exports.binDeltaToMinMaxBinId = binDeltaToMinMaxBinId; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.buildBitFlagAndNegateStrategyParameters = buildBitFlagAndNegateStrategyParameters; exports.buildLiquidityStrategyParameters = buildLiquidityStrategyParameters; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculatePositionSize = calculatePositionSize; exports.calculateSpotDistribution = calculateSpotDistribution; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.capSlippagePercentage = capSlippagePercentage; exports.chunkBinRange = chunkBinRange; exports.chunkBinRangeIntoExtendedPositions = chunkBinRangeIntoExtendedPositions; exports.chunkDepositWithRebalanceEndpoint = chunkDepositWithRebalanceEndpoint; exports.chunkPositionBinRange = chunkPositionBinRange; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunkedGetProgramAccounts = chunkedGetProgramAccounts; exports.chunks = chunks; exports.compressBinAmount = compressBinAmount; exports.computeBaseFactorFromFeeBps = computeBaseFactorFromFeeBps; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.createProgram = createProgram; exports.decodeAccount = decodeAccount; exports.decodeExtendedPosition = decodeExtendedPosition; exports.decodeRewardPerTokenStored = decodeRewardPerTokenStored; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveCustomizablePermissionlessLbPair = deriveCustomizablePermissionlessLbPair; exports.deriveEventAuthority = deriveEventAuthority; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveLbPairWithPresetParamWithIndexKey = deriveLbPairWithPresetParamWithIndexKey; exports.deriveOperator = deriveOperator; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePlaceHolderAccountMeta = derivePlaceHolderAccountMeta; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.derivePresetParameterWithIndex = derivePresetParameterWithIndex; exports.deriveReserve = deriveReserve; exports.deriveRewardVault = deriveRewardVault; exports.deriveTokenBadge = deriveTokenBadge; exports.distributeAmountToCompressedBinsByRatio = distributeAmountToCompressedBinsByRatio; exports.encodePositionPermissions = encodePositionPermissions; exports.enumerateBins = enumerateBins; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.findOptimumDecompressMultiplier = findOptimumDecompressMultiplier; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.generateAmountForBinRange = generateAmountForBinRange; exports.generateBinAmount = generateBinAmount; exports.getAccountDiscriminator = getAccountDiscriminator; exports.getAmountIn = getAmountIn; exports.getAmountInBinsAskSide = getAmountInBinsAskSide; exports.getAmountInBinsBidSide = getAmountInBinsBidSide; exports.getAmountOut = getAmountOut; exports.getAndCapMaxActiveBinSlippage = getAndCapMaxActiveBinSlippage; exports.getAutoFillAmountByRebalancedPosition = getAutoFillAmountByRebalancedPosition; exports.getBaseFee = getBaseFee; exports.getBinArrayAccountMetasCoverage = getBinArrayAccountMetasCoverage; exports.getBinArrayIndexesCoverage = getBinArrayIndexesCoverage; exports.getBinArrayInfoForNonContiguousBinIds = getBinArrayInfoForNonContiguousBinIds; exports.getBinArrayKeysCoverage = getBinArrayKeysCoverage; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinArraysRequiredByPositionRange2 = getBinArraysRequiredByPositionRange2; exports.getBinCount = getBinCount; exports.getBinFromBinArray = getBinFromBinArray; exports.getBinIdIndexInBinArray = getBinIdIndexInBinArray; exports.getBinMaxAmountOut = getBinMaxAmountOut; exports.getC = getC; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getExcludedFeeAmount = getExcludedFeeAmount; exports.getExtendedPositionBinCount = getExtendedPositionBinCount; exports.getExtraAccountMetasForTransferHook = getExtraAccountMetasForTransferHook; exports.getFeeMode = getFeeMode; exports.getIncludedFeeAmount = getIncludedFeeAmount; exports.getLimitOrderLiquidity = getLimitOrderLiquidity; exports.getLiquidityStrategyParameterBuilder = getLiquidityStrategyParameterBuilder; exports.getMultipleMintsExtraAccountMetasForTransferHook = getMultipleMintsExtraAccountMetasForTransferHook; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPositionCount = getPositionCount; exports.getPositionCountByBinCount = getPositionCountByBinCount; exports.getPositionExpandRentExemption = getPositionExpandRentExemption; exports.getPositionLowerUpperBinIdWithLiquidity = getPositionLowerUpperBinIdWithLiquidity; exports.getPositionRentExemption = getPositionRentExemption; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getQPriceBaseFactor = getQPriceBaseFactor; exports.getQPriceFromId = getQPriceFromId; exports.getRebalanceBinArrayIndexesAndBitmapCoverage = getRebalanceBinArrayIndexesAndBitmapCoverage; exports.getSlippageMaxAmount = getSlippageMaxAmount; exports.getSlippageMinAmount = getSlippageMinAmount; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgramId = getTokenProgramId; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.isPositionNoFee = isPositionNoFee; exports.isPositionNoReward = isPositionNoReward; exports.isSupportLimitOrder = isSupportLimitOrder; exports.limitOrderFilter = limitOrderFilter; exports.limitOrderLbPairFilter = limitOrderLbPairFilter; exports.limitOrderOwnerFilter = limitOrderOwnerFilter; exports.mulDiv = mulDiv; exports.mulShr = mulShr; exports.parseLogs = parseLogs; exports.positionLbPairFilter = positionLbPairFilter; exports.positionOwnerFilter = positionOwnerFilter; exports.positionV2Filter = positionV2Filter; exports.presetParameter2BaseFactorFilter = presetParameter2BaseFactorFilter; exports.presetParameter2BaseFeePowerFactor = presetParameter2BaseFeePowerFactor; exports.presetParameter2BinStepFilter = presetParameter2BinStepFilter; exports.range = range; exports.resetUninvolvedLiquidityParams = resetUninvolvedLiquidityParams; exports.shlDiv = shlDiv; exports.splitFee = splitFee; exports.suggestBalancedXParametersFromY = suggestBalancedXParametersFromY; exports.suggestBalancedYParametersFromX = suggestBalancedYParametersFromX; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountIntoBins = toAmountIntoBins; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapOracle = wrapOracle; exports.wrapPosition = wrapPosition; exports.wrapSOLInstruction = wrapSOLInstruction;
23327
23339
  //# sourceMappingURL=index.js.map
23328
23340
 
23329
23341
  // CJS interop: Make default export primary for require() compatibility