@meteora-ag/dlmm 1.5.0 → 1.5.1-rc1

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
@@ -8530,6 +8530,24 @@ function getPositionCount(minBinId, maxBinId) {
8530
8530
  const positionCount = binDelta.div(MAX_BIN_PER_POSITION);
8531
8531
  return positionCount.add(new (0, _anchor.BN)(1));
8532
8532
  }
8533
+ function findOptimumDecompressMultiplier(binAmount, tokenDecimal) {
8534
+ let multiplier = new (0, _anchor.BN)(10).pow(tokenDecimal);
8535
+ while (!multiplier.isZero()) {
8536
+ let found = true;
8537
+ for (const [_binId, amount] of binAmount) {
8538
+ const compressedAmount = amount.div(multiplier);
8539
+ if (compressedAmount.isZero()) {
8540
+ multiplier = multiplier.div(new (0, _anchor.BN)(10));
8541
+ found = false;
8542
+ break;
8543
+ }
8544
+ }
8545
+ if (found) {
8546
+ return multiplier;
8547
+ }
8548
+ }
8549
+ throw "Couldn't find optimum multiplier";
8550
+ }
8533
8551
  function compressBinAmount(binAmount, multiplier) {
8534
8552
  const compressedBinAmount = /* @__PURE__ */ new Map();
8535
8553
  let totalAmount = new (0, _anchor.BN)(0);
@@ -8566,6 +8584,9 @@ function generateAmountForBinRange(amount, binStep, tokenXDecimal, tokenYDecimal
8566
8584
  maxPrice,
8567
8585
  k
8568
8586
  );
8587
+ if (binAmount.isZero()) {
8588
+ throw "bin amount is zero";
8589
+ }
8569
8590
  binAmounts.set(i, binAmount);
8570
8591
  }
8571
8592
  return binAmounts;
@@ -11345,7 +11366,9 @@ var DLMM = class {
11345
11366
  tokenBadgeX,
11346
11367
  tokenBadgeY
11347
11368
  ]);
11348
- const presetParameterState = await program.account.presetParameter2.fetch(presetParameter);
11369
+ const presetParameterState = await program.account.presetParameter2.fetch(
11370
+ presetParameter
11371
+ );
11349
11372
  const existsPool = await this.getPairPubkeyIfExists(
11350
11373
  connection,
11351
11374
  tokenX,
@@ -12545,7 +12568,9 @@ var DLMM = class {
12545
12568
  slippage
12546
12569
  }) {
12547
12570
  const maxActiveBinSlippage = slippage ? Math.ceil(slippage / (this.lbPair.binStep / 100)) : MAX_ACTIVE_BIN_SLIPPAGE;
12548
- const positionAccount = await this.program.account.positionV2.fetch(positionPubKey);
12571
+ const positionAccount = await this.program.account.positionV2.fetch(
12572
+ positionPubKey
12573
+ );
12549
12574
  const { lowerBinId, upperBinId, binIds } = this.processXYAmountDistribution(xYAmountDistribution);
12550
12575
  if (lowerBinId < positionAccount.lowerBinId)
12551
12576
  throw new Error(
@@ -13915,7 +13940,10 @@ var DLMM = class {
13915
13940
  maxBinId,
13916
13941
  k
13917
13942
  );
13918
- const decompressMultiplier = new (0, _anchor.BN)(10 ** this.tokenX.mint.decimals);
13943
+ const decompressMultiplier = findOptimumDecompressMultiplier(
13944
+ binDepositAmount,
13945
+ new (0, _anchor.BN)(this.tokenX.mint.decimals)
13946
+ );
13919
13947
  let { compressedBinAmount, compressionLoss } = compressBinAmount(
13920
13948
  binDepositAmount,
13921
13949
  decompressMultiplier
@@ -14078,7 +14106,7 @@ var DLMM = class {
14078
14106
  }).instruction()
14079
14107
  );
14080
14108
  }
14081
- if (instructions.length > 1) {
14109
+ if (instructions.length > 0) {
14082
14110
  initializeBinArraysAndPositionIxs.push(instructions);
14083
14111
  instructions = [];
14084
14112
  }