@meteora-ag/dlmm 1.5.2-rc.7 → 1.5.3-rc.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/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;
@@ -13919,7 +13940,10 @@ var DLMM = class {
13919
13940
  maxBinId,
13920
13941
  k
13921
13942
  );
13922
- 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
+ );
13923
13947
  let { compressedBinAmount, compressionLoss } = compressBinAmount(
13924
13948
  binDepositAmount,
13925
13949
  decompressMultiplier
@@ -14082,7 +14106,7 @@ var DLMM = class {
14082
14106
  }).instruction()
14083
14107
  );
14084
14108
  }
14085
- if (instructions.length > 1) {
14109
+ if (instructions.length > 0) {
14086
14110
  initializeBinArraysAndPositionIxs.push(instructions);
14087
14111
  instructions = [];
14088
14112
  }
@@ -14444,8 +14468,8 @@ var DLMM = class {
14444
14468
  tokenXMint: this.lbPair.tokenXMint,
14445
14469
  tokenYMint: this.lbPair.tokenYMint,
14446
14470
  sender: operator,
14447
- tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
14448
- tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
14471
+ tokenXProgram: this.tokenX.owner,
14472
+ tokenYProgram: this.tokenY.owner
14449
14473
  }).remainingAccounts([
14450
14474
  ...transferHookAccountMetas,
14451
14475
  {
@@ -14822,8 +14846,8 @@ var DLMM = class {
14822
14846
  const binSupply = bin.supply;
14823
14847
  const posShare = posShares[idx];
14824
14848
  const posBinRewardInfo = positionRewardInfos[idx];
14825
- const positionXAmount = binSupply.eq(ZERO) ? ZERO : new (0, _decimaljs2.default)(posShare.toString()).mul(new (0, _decimaljs2.default)(bin.xAmount.toString())).div(new (0, _decimaljs2.default)(binSupply.toString()));
14826
- const positionYAmount = binSupply.eq(ZERO) ? ZERO : new (0, _decimaljs2.default)(posShare.toString()).mul(new (0, _decimaljs2.default)(bin.yAmount.toString())).div(new (0, _decimaljs2.default)(binSupply.toString()));
14849
+ const positionXAmount = binSupply.eq(ZERO) ? new (0, _decimaljs2.default)(0) : new (0, _decimaljs2.default)(posShare.toString()).mul(new (0, _decimaljs2.default)(bin.xAmount.toString())).div(new (0, _decimaljs2.default)(binSupply.toString()));
14850
+ const positionYAmount = binSupply.eq(ZERO) ? new (0, _decimaljs2.default)(0) : new (0, _decimaljs2.default)(posShare.toString()).mul(new (0, _decimaljs2.default)(bin.yAmount.toString())).div(new (0, _decimaljs2.default)(binSupply.toString())).floor();
14827
14851
  totalXAmount = totalXAmount.add(new (0, _decimaljs2.default)(positionXAmount.toString()));
14828
14852
  totalYAmount = totalYAmount.add(new (0, _decimaljs2.default)(positionYAmount.toString()));
14829
14853
  const feeInfo = feeInfos[idx];
@@ -14886,8 +14910,8 @@ var DLMM = class {
14886
14910
  binYAmount: bin.yAmount.toString(),
14887
14911
  binLiquidity: binSupply.toString(),
14888
14912
  positionLiquidity: posShare.toString(),
14889
- positionXAmount: positionXAmount.toString(),
14890
- positionYAmount: positionYAmount.toString(),
14913
+ positionXAmount: positionXAmount.toFixed(),
14914
+ positionYAmount: positionYAmount.toFixed(),
14891
14915
  positionFeeXAmount: claimableFeeX.toString(),
14892
14916
  positionFeeYAmount: claimableFeeY.toString(),
14893
14917
  positionRewardAmount: claimableRewardsInBin.map(