@meteora-ag/dlmm 1.0.49-rc.2 → 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.d.ts CHANGED
@@ -5226,6 +5226,7 @@ interface SwapQuote {
5226
5226
  minOutAmount: BN;
5227
5227
  priceImpact: Decimal;
5228
5228
  binArraysPubkey: any[];
5229
+ endPrice: Decimal;
5229
5230
  }
5230
5231
  interface SwapQuoteExactOut {
5231
5232
  inAmount: BN;
@@ -5538,12 +5539,6 @@ declare class DLMM {
5538
5539
  * @returns an object with two properties: "binId" which is a number, and "price" which is a string.
5539
5540
  */
5540
5541
  getActiveBin(): Promise<BinLiquidity>;
5541
- /**
5542
- * The function get the price of a bin based on its bin ID.
5543
- * @param {number} binId - The `binId` parameter is a number that represents the ID of a bin.
5544
- * @returns {number} the calculated price of a bin based on the provided binId.
5545
- */
5546
- getPriceOfBinByBinId(binId: number): string;
5547
5542
  /**
5548
5543
  * The function get bin ID based on a given price and a boolean flag indicating whether to
5549
5544
  * round down or up.
@@ -5844,7 +5839,6 @@ declare class DLMM {
5844
5839
  private static getClaimableSwapFee;
5845
5840
  private static processPosition;
5846
5841
  private static getBinsBetweenLowerAndUpperBound;
5847
- private static getPriceOfBinByBinId;
5848
5842
  /** Private method */
5849
5843
  private processXYAmountDistribution;
5850
5844
  private getBins;
package/dist/index.js 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 (0, _decimaljs2.default)(this.lbPair.binStep).div(
8495
- new (0, _decimaljs2.default)(BASIS_POINT_MAX)
8496
- );
8497
- return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(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 (0, _decimaljs2.default)(startPrice).sub(new (0, _decimaljs2.default)(endPrice)).abs().div(new (0, _decimaljs2.default)(startPrice)).mul(new (0, _decimaljs2.default)(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 (0, _decimaljs2.default)(100));
9710
9705
  const maxInAmount = actualInAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).add(allowedSlippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
9711
9706
  return {
9712
9707
  inAmount: actualInAmount,
@@ -9810,6 +9805,10 @@ var DLMM = class {
9810
9805
  );
9811
9806
  const priceImpact = new (0, _decimaljs2.default)(actualOutAmount.toString()).sub(new (0, _decimaljs2.default)(outAmountWithoutSlippage.toString())).div(new (0, _decimaljs2.default)(outAmountWithoutSlippage.toString())).mul(new (0, _decimaljs2.default)(100));
9812
9807
  const minOutAmount = actualOutAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).sub(allowedSlippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
9808
+ const endPrice = getPriceOfBinByBinId(
9809
+ activeId.toNumber(),
9810
+ this.lbPair.binStep
9811
+ );
9813
9812
  return {
9814
9813
  consumedInAmount: inAmount,
9815
9814
  outAmount: actualOutAmount,
@@ -9817,7 +9816,8 @@ var DLMM = class {
9817
9816
  protocolFee: protocolFeeAmount,
9818
9817
  minOutAmount,
9819
9818
  priceImpact,
9820
- binArraysPubkey: [...binArraysForSwap.keys()]
9819
+ binArraysPubkey: [...binArraysForSwap.keys()],
9820
+ endPrice
9821
9821
  };
9822
9822
  }
9823
9823
  async swapExactOut({
@@ -10738,7 +10738,7 @@ var DLMM = class {
10738
10738
  }).add(syncWithMarketPriceTx);
10739
10739
  }
10740
10740
  async getMaxPriceInBinArrays(binArrayAccounts) {
10741
- const sortedBinArrays = [...binArrayAccounts].sort(
10741
+ const sortedBinArrays = binArrayAccounts.sort(
10742
10742
  ({ account: { index: indexA } }, { account: { index: indexB } }) => indexA.toNumber() - indexB.toNumber()
10743
10743
  );
10744
10744
  let count = sortedBinArrays.length - 1;
@@ -10746,7 +10746,7 @@ var DLMM = class {
10746
10746
  while (count >= 0) {
10747
10747
  const binArray = sortedBinArrays[count];
10748
10748
  if (binArray) {
10749
- const bins = binArray.account.bins;
10749
+ const bins = binArray.account.bins.reverse();
10750
10750
  if (bins.every(({ amountX }) => amountX.isZero())) {
10751
10751
  count--;
10752
10752
  } else {
@@ -10988,10 +10988,10 @@ var DLMM = class {
10988
10988
  binArray.bins.forEach((bin, idx) => {
10989
10989
  const binId = lowerBinIdForBinArray.toNumber() + idx;
10990
10990
  if (binId >= lowerBinId && binId <= upperBinId) {
10991
- const pricePerLamport = this.getPriceOfBinByBinId(
10992
- lbPair.binStep,
10993
- binId
10994
- );
10991
+ const pricePerLamport = getPriceOfBinByBinId(
10992
+ binId,
10993
+ lbPair.binStep
10994
+ ).toString();
10995
10995
  bins.push({
10996
10996
  binId,
10997
10997
  xAmount: bin.amountX,
@@ -11012,10 +11012,10 @@ var DLMM = class {
11012
11012
  binArray.bins.forEach((bin, idx) => {
11013
11013
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11014
11014
  if (binId >= lowerBinId && binId <= upperBinId) {
11015
- const pricePerLamport = this.getPriceOfBinByBinId(
11016
- lbPair.binStep,
11017
- binId
11018
- );
11015
+ const pricePerLamport = getPriceOfBinByBinId(
11016
+ binId,
11017
+ lbPair.binStep
11018
+ ).toString();
11019
11019
  bins.push({
11020
11020
  binId,
11021
11021
  xAmount: bin.amountX,
@@ -11031,10 +11031,6 @@ var DLMM = class {
11031
11031
  }
11032
11032
  return bins;
11033
11033
  }
11034
- static getPriceOfBinByBinId(binStep, binId) {
11035
- const binStepNum = new (0, _decimaljs2.default)(binStep).div(new (0, _decimaljs2.default)(BASIS_POINT_MAX));
11036
- return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(binId)).toString();
11037
- }
11038
11034
  /** Private method */
11039
11035
  processXYAmountDistribution(xYAmountDistribution) {
11040
11036
  let currentBinId = null;
@@ -11073,8 +11069,6 @@ var DLMM = class {
11073
11069
  const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
11074
11070
  const binArrayBins = [];
11075
11071
  for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
11076
- const binId = new (0, _anchor.BN)(i);
11077
- const pricePerLamport = this.getPriceOfBinByBinId(binId.toNumber());
11078
11072
  binArrayBins.push({
11079
11073
  amountX: new (0, _anchor.BN)(0),
11080
11074
  amountY: new (0, _anchor.BN)(0),
@@ -11099,7 +11093,10 @@ var DLMM = class {
11099
11093
  binArray.bins.forEach((bin, idx) => {
11100
11094
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11101
11095
  if (binId >= lowerBinId && binId <= upperBinId) {
11102
- const pricePerLamport = this.getPriceOfBinByBinId(binId);
11096
+ const pricePerLamport = getPriceOfBinByBinId(
11097
+ binId,
11098
+ this.lbPair.binStep
11099
+ ).toString();
11103
11100
  bins.push({
11104
11101
  binId,
11105
11102
  xAmount: bin.amountX,
@@ -11140,7 +11137,10 @@ var DLMM = class {
11140
11137
  binArray.bins.forEach((bin, idx) => {
11141
11138
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11142
11139
  if (binId >= lowerBinId && binId <= upperBinId) {
11143
- const pricePerLamport = this.getPriceOfBinByBinId(binId);
11140
+ const pricePerLamport = getPriceOfBinByBinId(
11141
+ binId,
11142
+ this.lbPair.binStep
11143
+ ).toString();
11144
11144
  bins.push({
11145
11145
  binId,
11146
11146
  xAmount: bin.amountX,