@meteora-ag/dlmm 1.5.1-test.2 → 1.5.1

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;
@@ -10359,10 +10380,11 @@ var DLMM = class {
10359
10380
  */
10360
10381
  static async create(connection, dlmm, opt) {
10361
10382
  const cluster = _optionalChain([opt, 'optionalAccess', _38 => _38.cluster]) || "mainnet-beta";
10362
- const provider = new (0, _anchor.AnchorProvider)(connection, {}, {
10363
- ..._anchor.AnchorProvider.defaultOptions(),
10364
- commitment: "confirmed"
10365
- });
10383
+ const provider = new (0, _anchor.AnchorProvider)(
10384
+ connection,
10385
+ {},
10386
+ _anchor.AnchorProvider.defaultOptions()
10387
+ );
10366
10388
  const program = new (0, _anchor.Program)(
10367
10389
  IDL,
10368
10390
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _39 => _39.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
@@ -12992,21 +13014,11 @@ var DLMM = class {
12992
13014
  owner,
12993
13015
  position
12994
13016
  }) {
12995
- const preInstructions = [];
12996
- console.log(
12997
- position.positionData.feeX.toString(),
12998
- position.positionData.feeY.toString()
12999
- );
13000
- if (!position.positionData.feeX.isZero() || !position.positionData.feeY.isZero()) {
13001
- const claimIx = await this.createClaimSwapFeeMethod({ owner, position });
13002
- preInstructions.push(...claimIx.instructions);
13003
- console.log("\u{1F680} ~ DLMM ~ claimIx:", claimIx);
13004
- }
13005
13017
  const closePositionIx = await this.program.methods.closePosition2().accounts({
13006
13018
  rentReceiver: owner,
13007
13019
  position: position.publicKey,
13008
13020
  sender: owner
13009
- }).preInstructions(preInstructions).instruction();
13021
+ }).instruction();
13010
13022
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
13011
13023
  this.program.provider.connection,
13012
13024
  [closePositionIx],
@@ -13928,7 +13940,10 @@ var DLMM = class {
13928
13940
  maxBinId,
13929
13941
  k
13930
13942
  );
13931
- 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
+ );
13932
13947
  let { compressedBinAmount, compressionLoss } = compressBinAmount(
13933
13948
  binDepositAmount,
13934
13949
  decompressMultiplier
@@ -14091,7 +14106,7 @@ var DLMM = class {
14091
14106
  }).instruction()
14092
14107
  );
14093
14108
  }
14094
- if (instructions.length > 1) {
14109
+ if (instructions.length > 0) {
14095
14110
  initializeBinArraysAndPositionIxs.push(instructions);
14096
14111
  instructions = [];
14097
14112
  }