@meteora-ag/dlmm 1.6.0-rc.31 → 1.6.0-rc.32

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
@@ -19,7 +19,7 @@ import {
19
19
  SystemProgram as SystemProgram2,
20
20
  Transaction
21
21
  } from "@solana/web3.js";
22
- import Decimal8 from "decimal.js";
22
+ import Decimal9 from "decimal.js";
23
23
 
24
24
  // src/dlmm/constants/index.ts
25
25
  import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
@@ -12939,6 +12939,9 @@ function buildLiquidityStrategyParameters(amountX, amountY, minDeltaId, maxDelta
12939
12939
  };
12940
12940
  }
12941
12941
 
12942
+ // src/dlmm/helpers/index.ts
12943
+ import Decimal8 from "decimal.js";
12944
+
12942
12945
  // src/dlmm/helpers/lbPair.ts
12943
12946
  import { PublicKey as PublicKey8 } from "@solana/web3.js";
12944
12947
  import { TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
@@ -13668,10 +13671,20 @@ function getBinCount(minBinId, maxBinId) {
13668
13671
  return maxBinId - minBinId + 1;
13669
13672
  }
13670
13673
  function getSlippageMaxAmount(amount, slippage) {
13671
- return slippage == 100 ? U64_MAX : amount.muln(100 + slippage).divn(100);
13674
+ if (slippage == 100) {
13675
+ return U64_MAX;
13676
+ }
13677
+ const amountDecimal = new Decimal8(amount.toString());
13678
+ const slippageAppliedAmount = new BN18(
13679
+ amountDecimal.mul(new Decimal8(100 + slippage)).div(new Decimal8(100)).floor().toString()
13680
+ );
13681
+ return slippageAppliedAmount;
13672
13682
  }
13673
13683
  function getSlippageMinAmount(amount, slippage) {
13674
- return amount.muln(100 - slippage).divn(100);
13684
+ const amountDecimal = new Decimal8(amount.toString());
13685
+ return new BN18(
13686
+ amountDecimal.mul(new Decimal8(100 - slippage)).div(new Decimal8(100)).ceil().toString()
13687
+ );
13675
13688
  }
13676
13689
  function getPositionCountByBinCount(binCount) {
13677
13690
  return Math.ceil(binCount / MAX_BINS_PER_POSITION.toNumber());
@@ -14792,11 +14805,11 @@ var DLMM = class {
14792
14805
  return positionsMap;
14793
14806
  }
14794
14807
  static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
14795
- return new Decimal8(price).mul(new Decimal8(10 ** (tokenYDecimal - tokenXDecimal))).toString();
14808
+ return new Decimal9(price).mul(new Decimal9(10 ** (tokenYDecimal - tokenXDecimal))).toString();
14796
14809
  }
14797
14810
  static getBinIdFromPrice(price, binStep, min) {
14798
- const binStepNum = new Decimal8(binStep).div(new Decimal8(BASIS_POINT_MAX));
14799
- const binId = new Decimal8(price).log().dividedBy(new Decimal8(1).add(binStepNum).log());
14811
+ const binStepNum = new Decimal9(binStep).div(new Decimal9(BASIS_POINT_MAX));
14812
+ const binId = new Decimal9(price).log().dividedBy(new Decimal9(1).add(binStepNum).log());
14800
14813
  return (min ? binId.floor() : binId.ceil()).toNumber();
14801
14814
  }
14802
14815
  /**
@@ -15412,8 +15425,8 @@ var DLMM = class {
15412
15425
  */
15413
15426
  static calculateFeeInfo(baseFactor, binStep, baseFeePowerFactor) {
15414
15427
  const baseFeeRate = new BN21(baseFactor).mul(new BN21(binStep)).mul(new BN21(10)).mul(new BN21(10).pow(new BN21(baseFeePowerFactor ?? 0)));
15415
- const baseFeeRatePercentage = new Decimal8(baseFeeRate.toString()).mul(new Decimal8(100)).div(new Decimal8(FEE_PRECISION.toString()));
15416
- const maxFeeRatePercentage = new Decimal8(MAX_FEE_RATE.toString()).mul(new Decimal8(100)).div(new Decimal8(FEE_PRECISION.toString()));
15428
+ const baseFeeRatePercentage = new Decimal9(baseFeeRate.toString()).mul(new Decimal9(100)).div(new Decimal9(FEE_PRECISION.toString()));
15429
+ const maxFeeRatePercentage = new Decimal9(MAX_FEE_RATE.toString()).mul(new Decimal9(100)).div(new Decimal9(FEE_PRECISION.toString()));
15417
15430
  return {
15418
15431
  baseFeeRatePercentage,
15419
15432
  maxFeeRatePercentage
@@ -15431,7 +15444,7 @@ var DLMM = class {
15431
15444
  this.lbPair.binStep,
15432
15445
  this.lbPair.parameters.baseFeePowerFactor
15433
15446
  );
15434
- const protocolFeePercentage = new Decimal8(protocolShare.toString()).mul(new Decimal8(100)).div(new Decimal8(BASIS_POINT_MAX));
15447
+ const protocolFeePercentage = new Decimal9(protocolShare.toString()).mul(new Decimal9(100)).div(new Decimal9(BASIS_POINT_MAX));
15435
15448
  return {
15436
15449
  baseFeeRatePercentage,
15437
15450
  maxFeeRatePercentage,
@@ -15463,7 +15476,7 @@ var DLMM = class {
15463
15476
  sParameters3,
15464
15477
  vParameterClone
15465
15478
  );
15466
- return new Decimal8(totalFee.toString()).div(new Decimal8(FEE_PRECISION.toString())).mul(100);
15479
+ return new Decimal9(totalFee.toString()).div(new Decimal9(FEE_PRECISION.toString())).mul(100);
15467
15480
  }
15468
15481
  /**
15469
15482
  * The function `getEmissionRate` returns the emission rates for two rewards.
@@ -15476,8 +15489,8 @@ var DLMM = class {
15476
15489
  ({ rewardRate, rewardDurationEnd }) => now > rewardDurationEnd.toNumber() ? void 0 : rewardRate
15477
15490
  );
15478
15491
  return {
15479
- rewardOne: rewardOneEmissionRate ? new Decimal8(rewardOneEmissionRate.toString()).div(PRECISION) : void 0,
15480
- rewardTwo: rewardTwoEmissionRate ? new Decimal8(rewardTwoEmissionRate.toString()).div(PRECISION) : void 0
15492
+ rewardOne: rewardOneEmissionRate ? new Decimal9(rewardOneEmissionRate.toString()).div(PRECISION) : void 0,
15493
+ rewardTwo: rewardTwoEmissionRate ? new Decimal9(rewardTwoEmissionRate.toString()).div(PRECISION) : void 0
15481
15494
  };
15482
15495
  }
15483
15496
  /**
@@ -15570,8 +15583,8 @@ var DLMM = class {
15570
15583
  * @returns {string} real price of bin
15571
15584
  */
15572
15585
  fromPricePerLamport(pricePerLamport) {
15573
- return new Decimal8(pricePerLamport).div(
15574
- new Decimal8(
15586
+ return new Decimal9(pricePerLamport).div(
15587
+ new Decimal9(
15575
15588
  10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
15576
15589
  )
15577
15590
  ).toString();
@@ -15729,12 +15742,12 @@ var DLMM = class {
15729
15742
  const lowerBinArrayIndex = binIdToBinArrayIndex(currentMinBinId);
15730
15743
  const upperBinArrayIndex = binIdToBinArrayIndex(currentMaxBinId);
15731
15744
  const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
15732
- const binArrayCost = new Decimal8(binArraysCount).mul(
15733
- new Decimal8(BIN_ARRAY_FEE)
15745
+ const binArrayCost = new Decimal9(binArraysCount).mul(
15746
+ new Decimal9(BIN_ARRAY_FEE)
15734
15747
  );
15735
15748
  return {
15736
- positionExtendCost: new Decimal8(positionExtendCost).div(
15737
- new Decimal8(LAMPORTS_PER_SOL2)
15749
+ positionExtendCost: new Decimal9(positionExtendCost).div(
15750
+ new Decimal9(LAMPORTS_PER_SOL2)
15738
15751
  ),
15739
15752
  binArrayCost
15740
15753
  };
@@ -17110,7 +17123,7 @@ var DLMM = class {
17110
17123
  activeId.toNumber(),
17111
17124
  this.lbPair.binStep
17112
17125
  );
17113
- const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal8(100));
17126
+ const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal9(100));
17114
17127
  actualInAmount = calculateTransferFeeIncludedAmount(
17115
17128
  actualInAmount.add(feeAmount),
17116
17129
  inMint,
@@ -17297,7 +17310,7 @@ var DLMM = class {
17297
17310
  ),
17298
17311
  swapForY
17299
17312
  );
17300
- const priceImpact = new Decimal8(totalOutAmount.toString()).sub(new Decimal8(outAmountWithoutSlippage.toString())).div(new Decimal8(outAmountWithoutSlippage.toString())).mul(new Decimal8(100)).abs();
17313
+ const priceImpact = new Decimal9(totalOutAmount.toString()).sub(new Decimal9(outAmountWithoutSlippage.toString())).div(new Decimal9(outAmountWithoutSlippage.toString())).mul(new Decimal9(100)).abs();
17301
17314
  const endPrice = getPriceOfBinByBinId(
17302
17315
  lastFilledActiveBinId.toNumber(),
17303
17316
  this.lbPair.binStep
@@ -17906,11 +17919,11 @@ var DLMM = class {
17906
17919
  let totalBinArraysCount = new BN21(0);
17907
17920
  let totalBinArraysLamports = new BN21(0);
17908
17921
  let binArrayBitmapLamports = new BN21(0);
17909
- const toLamportMultiplier = new Decimal8(
17922
+ const toLamportMultiplier = new Decimal9(
17910
17923
  10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
17911
17924
  );
17912
- const minPricePerLamport = new Decimal8(minPrice).mul(toLamportMultiplier);
17913
- const maxPricePerLamport = new Decimal8(maxPrice).mul(toLamportMultiplier);
17925
+ const minPricePerLamport = new Decimal9(minPrice).mul(toLamportMultiplier);
17926
+ const maxPricePerLamport = new Decimal9(maxPrice).mul(toLamportMultiplier);
17914
17927
  const minBinId = new BN21(
17915
17928
  DLMM.getBinIdFromPrice(minPricePerLamport, this.lbPair.binStep, false)
17916
17929
  );
@@ -19396,8 +19409,8 @@ var DLMM = class {
19396
19409
  if (!bins.length)
19397
19410
  return null;
19398
19411
  const positionData = [];
19399
- let totalXAmount = new Decimal8(0);
19400
- let totalYAmount = new Decimal8(0);
19412
+ let totalXAmount = new Decimal9(0);
19413
+ let totalYAmount = new Decimal9(0);
19401
19414
  const ZERO = new BN21(0);
19402
19415
  let feeX = ZERO;
19403
19416
  let feeY = ZERO;
@@ -19408,8 +19421,8 @@ var DLMM = class {
19408
19421
  const posBinRewardInfo = positionRewardInfos[idx];
19409
19422
  const positionXAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.xAmount).div(binSupply);
19410
19423
  const positionYAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.yAmount).div(binSupply);
19411
- totalXAmount = totalXAmount.add(new Decimal8(positionXAmount.toString()));
19412
- totalYAmount = totalYAmount.add(new Decimal8(positionYAmount.toString()));
19424
+ totalXAmount = totalXAmount.add(new Decimal9(positionXAmount.toString()));
19425
+ totalYAmount = totalYAmount.add(new Decimal9(positionYAmount.toString()));
19413
19426
  const feeInfo = feeInfos[idx];
19414
19427
  const newFeeX = mulShr(
19415
19428
  posShares[idx].shrn(SCALE_OFFSET),
@@ -19573,7 +19586,7 @@ var DLMM = class {
19573
19586
  rewardPerTokenStored: [ZERO, ZERO],
19574
19587
  price: pricePerLamport,
19575
19588
  version: 2,
19576
- pricePerToken: new Decimal8(pricePerLamport).mul(new Decimal8(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
19589
+ pricePerToken: new Decimal9(pricePerLamport).mul(new Decimal9(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
19577
19590
  });
19578
19591
  } else {
19579
19592
  const bin = binArray.bins[i];
@@ -19587,7 +19600,7 @@ var DLMM = class {
19587
19600
  rewardPerTokenStored: bin.rewardPerTokenStored,
19588
19601
  price: pricePerLamport,
19589
19602
  version: binArray.version,
19590
- pricePerToken: new Decimal8(pricePerLamport).mul(new Decimal8(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
19603
+ pricePerToken: new Decimal9(pricePerLamport).mul(new Decimal9(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
19591
19604
  });
19592
19605
  }
19593
19606
  }