@meteora-ag/dlmm 1.6.0-rc.26 → 1.6.0-rc.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -11267,6 +11267,20 @@ function isPositionNoFee(position) {
11267
11267
  function isPositionNoReward(position) {
11268
11268
  return position.rewardOne.isZero() && position.rewardTwo.isZero();
11269
11269
  }
11270
+ function chunkBinRangeIntoExtendedPositions(minBinId, maxBinId) {
11271
+ const chunkedBinRange = [];
11272
+ for (let currentMinBinId = minBinId; currentMinBinId <= maxBinId; currentMinBinId += POSITION_MAX_LENGTH.toNumber()) {
11273
+ const currentMaxBinId = Math.min(
11274
+ currentMinBinId + POSITION_MAX_LENGTH.toNumber() - 1,
11275
+ maxBinId
11276
+ );
11277
+ chunkedBinRange.push({
11278
+ lowerBinId: currentMinBinId,
11279
+ upperBinId: currentMaxBinId
11280
+ });
11281
+ }
11282
+ return chunkedBinRange;
11283
+ }
11270
11284
  function chunkBinRange(minBinId, maxBinId) {
11271
11285
  const chunkedBinRange = [];
11272
11286
  let startBinId = minBinId;
@@ -11283,6 +11297,65 @@ function chunkBinRange(minBinId, maxBinId) {
11283
11297
  }
11284
11298
  return chunkedBinRange;
11285
11299
  }
11300
+ function chunkPositionBinRange(position, minBinId, maxBinId) {
11301
+ const chunkedFeesAndRewards = [];
11302
+ let totalAmountX = new BN10(0);
11303
+ let totalAmountY = new BN10(0);
11304
+ let totalFeeXAmount = new BN10(0);
11305
+ let totalFeeYAmount = new BN10(0);
11306
+ let totalRewardAmounts = [new BN10(0), new BN10(0)];
11307
+ let count = 0;
11308
+ for (let i = 0; i < position.positionData.positionBinData.length; i++) {
11309
+ const positionBinData = position.positionData.positionBinData[i];
11310
+ if (positionBinData.binId >= minBinId && positionBinData.binId <= maxBinId) {
11311
+ totalFeeXAmount = totalFeeXAmount.add(
11312
+ new BN10(positionBinData.positionFeeXAmount)
11313
+ );
11314
+ totalFeeYAmount = totalFeeYAmount.add(
11315
+ new BN10(positionBinData.positionFeeYAmount)
11316
+ );
11317
+ totalAmountX = totalAmountX.add(new BN10(positionBinData.positionXAmount));
11318
+ totalAmountY = totalAmountY.add(new BN10(positionBinData.positionYAmount));
11319
+ for (const [
11320
+ index,
11321
+ reward
11322
+ ] of positionBinData.positionRewardAmount.entries()) {
11323
+ totalRewardAmounts[index] = totalRewardAmounts[index].add(
11324
+ new BN10(reward)
11325
+ );
11326
+ }
11327
+ count++;
11328
+ }
11329
+ if (count === DEFAULT_BIN_PER_POSITION.toNumber() || positionBinData.binId == maxBinId) {
11330
+ chunkedFeesAndRewards.push({
11331
+ minBinId: positionBinData.binId - count + 1,
11332
+ maxBinId: positionBinData.binId,
11333
+ feeXAmount: totalFeeXAmount,
11334
+ feeYAmount: totalFeeYAmount,
11335
+ rewardAmounts: totalRewardAmounts,
11336
+ amountX: totalAmountX,
11337
+ amountY: totalAmountY
11338
+ });
11339
+ totalFeeXAmount = new BN10(0);
11340
+ totalFeeYAmount = new BN10(0);
11341
+ totalAmountX = new BN10(0);
11342
+ totalAmountY = new BN10(0);
11343
+ totalRewardAmounts = [new BN10(0), new BN10(0)];
11344
+ count = 0;
11345
+ }
11346
+ }
11347
+ return chunkedFeesAndRewards;
11348
+ }
11349
+ function calculatePositionSize(binCount) {
11350
+ const extraBinCount = binCount.gt(DEFAULT_BIN_PER_POSITION) ? binCount.sub(DEFAULT_BIN_PER_POSITION) : new BN10(0);
11351
+ return new BN10(POSITION_MIN_SIZE).add(
11352
+ extraBinCount.mul(new BN10(POSITION_BIN_DATA_SIZE))
11353
+ );
11354
+ }
11355
+ function getPositionRentExemption(connection, binCount) {
11356
+ const size = calculatePositionSize(binCount);
11357
+ return connection.getMinimumBalanceForRentExemption(size.toNumber());
11358
+ }
11286
11359
  async function getPositionExpandRentExemption(currentMinBinId, currentMaxBinId, connection, binCountToExpand) {
11287
11360
  const currentPositionWidth = currentMaxBinId.sub(currentMinBinId).addn(1);
11288
11361
  const positionWidthAfterExpand = currentPositionWidth.add(binCountToExpand);
@@ -15036,7 +15109,11 @@ var DLMM = class {
15036
15109
  tokenY,
15037
15110
  new BN21(presetParameterState.binStep),
15038
15111
  new BN21(presetParameterState.baseFactor),
15039
- new BN21(presetParameterState.baseFactor)
15112
+ new BN21(presetParameterState.baseFactor),
15113
+ {
15114
+ cluster: opt?.cluster,
15115
+ programId: opt?.programId
15116
+ }
15040
15117
  );
15041
15118
  if (existsPool) {
15042
15119
  throw new Error("Pool already exists");
@@ -15642,17 +15719,46 @@ var DLMM = class {
15642
15719
  }
15643
15720
  async quoteCreatePosition({ strategy }) {
15644
15721
  const { minBinId, maxBinId } = strategy;
15722
+ const binCount = maxBinId - minBinId + 1;
15723
+ const positionCount = Math.floor(binCount / MAX_BINS_PER_POSITION.toNumber()) + 1;
15724
+ let positionReallocCost = 0;
15725
+ for (let i = 0; i < positionCount; i++) {
15726
+ const lowerBinId = minBinId;
15727
+ const upperBinId = Math.min(
15728
+ maxBinId,
15729
+ lowerBinId + DEFAULT_BIN_PER_POSITION.toNumber() - 1
15730
+ );
15731
+ const maxUpperBinId = Math.min(
15732
+ maxBinId,
15733
+ upperBinId + MAX_BINS_PER_POSITION.toNumber() - 1
15734
+ );
15735
+ const binToExpand = maxUpperBinId - upperBinId;
15736
+ const { positionExtendCost } = await this.quoteExtendPosition(
15737
+ new BN21(lowerBinId),
15738
+ new BN21(upperBinId),
15739
+ new BN21(binToExpand)
15740
+ );
15741
+ positionReallocCost += positionExtendCost.toNumber();
15742
+ }
15645
15743
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN21(minBinId));
15646
15744
  const upperBinArrayIndex = BN21.max(
15647
15745
  binIdToBinArrayIndex(new BN21(maxBinId)),
15648
15746
  lowerBinArrayIndex.add(new BN21(1))
15649
15747
  );
15748
+ let bitmapExtensionCost = 0;
15749
+ if (isOverflowDefaultBinArrayBitmap(lowerBinArrayIndex) || isOverflowDefaultBinArrayBitmap(upperBinArrayIndex)) {
15750
+ bitmapExtensionCost = BIN_ARRAY_BITMAP_FEE;
15751
+ }
15650
15752
  const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
15651
15753
  const transactionCount = Math.ceil(
15652
15754
  (maxBinId - minBinId + 1) / DEFAULT_BIN_PER_POSITION.toNumber()
15653
15755
  );
15654
15756
  const binArrayCost = binArraysCount * BIN_ARRAY_FEE;
15655
15757
  return {
15758
+ positionCount,
15759
+ positionCost: positionCount * POSITION_FEE,
15760
+ positionReallocCost,
15761
+ bitmapExtensionCost,
15656
15762
  binArraysCount,
15657
15763
  binArrayCost,
15658
15764
  transactionCount
@@ -19811,6 +19917,7 @@ export {
19811
19917
  PRECISION,
19812
19918
  PairStatus,
19813
19919
  PairType,
19920
+ PositionV2Wrapper,
19814
19921
  PositionVersion,
19815
19922
  RebalancePosition,
19816
19923
  ResizeSide,
@@ -19831,9 +19938,13 @@ export {
19831
19938
  buildLiquidityStrategyParameters,
19832
19939
  calculateBidAskDistribution,
19833
19940
  calculateNormalDistribution,
19941
+ calculatePositionSize,
19834
19942
  calculateSpotDistribution,
19835
19943
  capSlippagePercentage,
19944
+ chunkBinRange,
19945
+ chunkBinRangeIntoExtendedPositions,
19836
19946
  chunkDepositWithRebalanceEndpoint,
19947
+ chunkPositionBinRange,
19837
19948
  chunkedFetchMultipleBinArrayBitmapExtensionAccount,
19838
19949
  chunkedFetchMultiplePoolAccount,
19839
19950
  chunkedGetMultipleAccountInfos,
@@ -19843,6 +19954,7 @@ export {
19843
19954
  computeProtocolFee,
19844
19955
  createProgram,
19845
19956
  decodeAccount,
19957
+ decodeExtendedPosition,
19846
19958
  src_default as default,
19847
19959
  deriveBinArray,
19848
19960
  deriveBinArrayBitmapExtension,
@@ -19872,6 +19984,9 @@ export {
19872
19984
  getAndCapMaxActiveBinSlippage,
19873
19985
  getAutoFillAmountByRebalancedPosition,
19874
19986
  getBaseFee,
19987
+ getBinArrayAccountMetasCoverage,
19988
+ getBinArrayIndexesCoverage,
19989
+ getBinArrayKeysCoverage2 as getBinArrayKeysCoverage,
19875
19990
  getBinArrayLowerUpperBinId,
19876
19991
  getBinArraysRequiredByPositionRange,
19877
19992
  getBinCount,
@@ -19879,10 +19994,14 @@ export {
19879
19994
  getBinIdIndexInBinArray,
19880
19995
  getEstimatedComputeUnitIxWithBuffer,
19881
19996
  getEstimatedComputeUnitUsageWithBuffer,
19997
+ getExtendedPositionBinCount,
19882
19998
  getLiquidityStrategyParameterBuilder,
19883
19999
  getOrCreateATAInstruction,
19884
20000
  getOutAmount,
19885
20001
  getPositionCountByBinCount,
20002
+ getPositionExpandRentExemption,
20003
+ getPositionLowerUpperBinIdWithLiquidity,
20004
+ getPositionRentExemption,
19886
20005
  getPriceOfBinByBinId,
19887
20006
  getRebalanceBinArrayIndexesAndBitmapCoverage,
19888
20007
  getSlippageMaxAmount,
@@ -19895,6 +20014,8 @@ export {
19895
20014
  getVariableFee,
19896
20015
  isBinIdWithinBinArray,
19897
20016
  isOverflowDefaultBinArrayBitmap,
20017
+ isPositionNoFee,
20018
+ isPositionNoReward,
19898
20019
  parseLogs,
19899
20020
  range,
19900
20021
  resetUninvolvedLiquidityParams,
@@ -19911,6 +20032,7 @@ export {
19911
20032
  toWeightDistribution,
19912
20033
  unwrapSOLInstruction,
19913
20034
  updateBinArray,
20035
+ wrapPosition,
19914
20036
  wrapSOLInstruction
19915
20037
  };
19916
20038
  //# sourceMappingURL=index.mjs.map