@meteora-ag/dlmm 1.0.49-rc.1 → 1.0.50-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.mjs CHANGED
@@ -8485,17 +8485,6 @@ var DLMM = class {
8485
8485
  );
8486
8486
  return activeBinState;
8487
8487
  }
8488
- /**
8489
- * The function get the price of a bin based on its bin ID.
8490
- * @param {number} binId - The `binId` parameter is a number that represents the ID of a bin.
8491
- * @returns {number} the calculated price of a bin based on the provided binId.
8492
- */
8493
- getPriceOfBinByBinId(binId) {
8494
- const binStepNum = new Decimal4(this.lbPair.binStep).div(
8495
- new Decimal4(BASIS_POINT_MAX)
8496
- );
8497
- return new Decimal4(1).add(new Decimal4(binStepNum)).pow(new Decimal4(binId)).toString();
8498
- }
8499
8488
  /**
8500
8489
  * The function get bin ID based on a given price and a boolean flag indicating whether to
8501
8490
  * round down or up.
@@ -9704,9 +9693,15 @@ var DLMM = class {
9704
9693
  }
9705
9694
  }
9706
9695
  }
9707
- const startPrice = this.getPriceOfBinByBinId(startBinId.toNumber());
9708
- const endPrice = this.getPriceOfBinByBinId(activeId.toNumber());
9709
- const priceImpact = new Decimal4(startPrice).sub(new Decimal4(endPrice)).abs().div(new Decimal4(startPrice)).mul(new Decimal4(100));
9696
+ const startPrice = getPriceOfBinByBinId(
9697
+ startBinId.toNumber(),
9698
+ this.lbPair.binStep
9699
+ );
9700
+ const endPrice = getPriceOfBinByBinId(
9701
+ activeId.toNumber(),
9702
+ this.lbPair.binStep
9703
+ );
9704
+ const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal4(100));
9710
9705
  const maxInAmount = actualInAmount.mul(new BN9(BASIS_POINT_MAX).add(allowedSlippage)).div(new BN9(BASIS_POINT_MAX));
9711
9706
  return {
9712
9707
  inAmount: actualInAmount,
@@ -9768,11 +9763,6 @@ var DLMM = class {
9768
9763
  sParameters2,
9769
9764
  activeId.toNumber()
9770
9765
  );
9771
- console.log(
9772
- activeId.toString(),
9773
- binArrayAccountToSwap.account.index.toString(),
9774
- isBinIdWithinBinArray(activeId, binArrayAccountToSwap.account.index)
9775
- );
9776
9766
  if (isBinIdWithinBinArray(activeId, binArrayAccountToSwap.account.index)) {
9777
9767
  const bin = getBinFromBinArray(
9778
9768
  activeId.toNumber(),
@@ -9786,13 +9776,6 @@ var DLMM = class {
9786
9776
  inAmountLeft,
9787
9777
  swapForY
9788
9778
  );
9789
- console.log(
9790
- "\u{1F680} ~ DLMM ~ amountIn:",
9791
- amountIn.toString(),
9792
- amountOut.toString(),
9793
- fee.toString(),
9794
- protocolFee.toString()
9795
- );
9796
9779
  if (!amountIn.isZero()) {
9797
9780
  inAmountLeft = inAmountLeft.sub(amountIn);
9798
9781
  actualOutAmount = actualOutAmount.add(amountOut);
@@ -9822,6 +9805,10 @@ var DLMM = class {
9822
9805
  );
9823
9806
  const priceImpact = new Decimal4(actualOutAmount.toString()).sub(new Decimal4(outAmountWithoutSlippage.toString())).div(new Decimal4(outAmountWithoutSlippage.toString())).mul(new Decimal4(100));
9824
9807
  const minOutAmount = actualOutAmount.mul(new BN9(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN9(BASIS_POINT_MAX));
9808
+ const endPrice = getPriceOfBinByBinId(
9809
+ activeId.toNumber(),
9810
+ this.lbPair.binStep
9811
+ );
9825
9812
  return {
9826
9813
  consumedInAmount: inAmount,
9827
9814
  outAmount: actualOutAmount,
@@ -9829,7 +9816,8 @@ var DLMM = class {
9829
9816
  protocolFee: protocolFeeAmount,
9830
9817
  minOutAmount,
9831
9818
  priceImpact,
9832
- binArraysPubkey: [...binArraysForSwap.keys()]
9819
+ binArraysPubkey: [...binArraysForSwap.keys()],
9820
+ endPrice
9833
9821
  };
9834
9822
  }
9835
9823
  async swapExactOut({
@@ -11000,10 +10988,10 @@ var DLMM = class {
11000
10988
  binArray.bins.forEach((bin, idx) => {
11001
10989
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11002
10990
  if (binId >= lowerBinId && binId <= upperBinId) {
11003
- const pricePerLamport = this.getPriceOfBinByBinId(
11004
- lbPair.binStep,
11005
- binId
11006
- );
10991
+ const pricePerLamport = getPriceOfBinByBinId(
10992
+ binId,
10993
+ lbPair.binStep
10994
+ ).toString();
11007
10995
  bins.push({
11008
10996
  binId,
11009
10997
  xAmount: bin.amountX,
@@ -11024,10 +11012,10 @@ var DLMM = class {
11024
11012
  binArray.bins.forEach((bin, idx) => {
11025
11013
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11026
11014
  if (binId >= lowerBinId && binId <= upperBinId) {
11027
- const pricePerLamport = this.getPriceOfBinByBinId(
11028
- lbPair.binStep,
11029
- binId
11030
- );
11015
+ const pricePerLamport = getPriceOfBinByBinId(
11016
+ binId,
11017
+ lbPair.binStep
11018
+ ).toString();
11031
11019
  bins.push({
11032
11020
  binId,
11033
11021
  xAmount: bin.amountX,
@@ -11043,10 +11031,6 @@ var DLMM = class {
11043
11031
  }
11044
11032
  return bins;
11045
11033
  }
11046
- static getPriceOfBinByBinId(binStep, binId) {
11047
- const binStepNum = new Decimal4(binStep).div(new Decimal4(BASIS_POINT_MAX));
11048
- return new Decimal4(1).add(new Decimal4(binStepNum)).pow(new Decimal4(binId)).toString();
11049
- }
11050
11034
  /** Private method */
11051
11035
  processXYAmountDistribution(xYAmountDistribution) {
11052
11036
  let currentBinId = null;
@@ -11085,8 +11069,6 @@ var DLMM = class {
11085
11069
  const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
11086
11070
  const binArrayBins = [];
11087
11071
  for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
11088
- const binId = new BN9(i);
11089
- const pricePerLamport = this.getPriceOfBinByBinId(binId.toNumber());
11090
11072
  binArrayBins.push({
11091
11073
  amountX: new BN9(0),
11092
11074
  amountY: new BN9(0),
@@ -11111,7 +11093,10 @@ var DLMM = class {
11111
11093
  binArray.bins.forEach((bin, idx) => {
11112
11094
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11113
11095
  if (binId >= lowerBinId && binId <= upperBinId) {
11114
- const pricePerLamport = this.getPriceOfBinByBinId(binId);
11096
+ const pricePerLamport = getPriceOfBinByBinId(
11097
+ binId,
11098
+ this.lbPair.binStep
11099
+ ).toString();
11115
11100
  bins.push({
11116
11101
  binId,
11117
11102
  xAmount: bin.amountX,
@@ -11152,7 +11137,10 @@ var DLMM = class {
11152
11137
  binArray.bins.forEach((bin, idx) => {
11153
11138
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11154
11139
  if (binId >= lowerBinId && binId <= upperBinId) {
11155
- const pricePerLamport = this.getPriceOfBinByBinId(binId);
11140
+ const pricePerLamport = getPriceOfBinByBinId(
11141
+ binId,
11142
+ this.lbPair.binStep
11143
+ ).toString();
11156
11144
  bins.push({
11157
11145
  binId,
11158
11146
  xAmount: bin.amountX,