@meteora-ag/dlmm 1.0.52-rc.7 → 1.0.52-rc.9

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
@@ -8570,17 +8570,6 @@ var DLMM = class {
8570
8570
  );
8571
8571
  return activeBinState;
8572
8572
  }
8573
- /**
8574
- * The function get the price of a bin based on its bin ID.
8575
- * @param {number} binId - The `binId` parameter is a number that represents the ID of a bin.
8576
- * @returns {number} the calculated price of a bin based on the provided binId.
8577
- */
8578
- getPriceOfBinByBinId(binId) {
8579
- const binStepNum = new Decimal4(this.lbPair.binStep).div(
8580
- new Decimal4(BASIS_POINT_MAX)
8581
- );
8582
- return new Decimal4(1).add(new Decimal4(binStepNum)).pow(new Decimal4(binId)).toString();
8583
- }
8584
8573
  /**
8585
8574
  * The function get bin ID based on a given price and a boolean flag indicating whether to
8586
8575
  * round down or up.
@@ -9859,9 +9848,15 @@ var DLMM = class {
9859
9848
  }
9860
9849
  }
9861
9850
  }
9862
- const startPrice = this.getPriceOfBinByBinId(startBinId.toNumber());
9863
- const endPrice = this.getPriceOfBinByBinId(activeId.toNumber());
9864
- const priceImpact = new Decimal4(startPrice).sub(new Decimal4(endPrice)).abs().div(new Decimal4(startPrice)).mul(new Decimal4(100));
9851
+ const startPrice = getPriceOfBinByBinId(
9852
+ startBinId.toNumber(),
9853
+ this.lbPair.binStep
9854
+ );
9855
+ const endPrice = getPriceOfBinByBinId(
9856
+ activeId.toNumber(),
9857
+ this.lbPair.binStep
9858
+ );
9859
+ const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal4(100));
9865
9860
  const maxInAmount = actualInAmount.mul(new BN9(BASIS_POINT_MAX).add(allowedSlippage)).div(new BN9(BASIS_POINT_MAX));
9866
9861
  return {
9867
9862
  inAmount: actualInAmount,
@@ -9972,6 +9967,10 @@ var DLMM = class {
9972
9967
  );
9973
9968
  const priceImpact = new Decimal4(actualOutAmount.toString()).sub(new Decimal4(outAmountWithoutSlippage.toString())).div(new Decimal4(outAmountWithoutSlippage.toString())).mul(new Decimal4(100));
9974
9969
  const minOutAmount = actualOutAmount.mul(new BN9(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN9(BASIS_POINT_MAX));
9970
+ const endPrice = getPriceOfBinByBinId(
9971
+ activeId.toNumber(),
9972
+ this.lbPair.binStep
9973
+ );
9975
9974
  return {
9976
9975
  consumedInAmount: inAmount,
9977
9976
  outAmount: actualOutAmount,
@@ -9979,7 +9978,8 @@ var DLMM = class {
9979
9978
  protocolFee: protocolFeeAmount,
9980
9979
  minOutAmount,
9981
9980
  priceImpact,
9982
- binArraysPubkey: [...binArraysForSwap.keys()]
9981
+ binArraysPubkey: [...binArraysForSwap.keys()],
9982
+ endPrice
9983
9983
  };
9984
9984
  }
9985
9985
  async swapExactOut({
@@ -11288,10 +11288,10 @@ var DLMM = class {
11288
11288
  binArray.bins.forEach((bin, idx) => {
11289
11289
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11290
11290
  if (binId >= lowerBinId && binId <= upperBinId) {
11291
- const pricePerLamport = this.getPriceOfBinByBinId(
11292
- lbPair.binStep,
11293
- binId
11294
- );
11291
+ const pricePerLamport = getPriceOfBinByBinId(
11292
+ binId,
11293
+ lbPair.binStep
11294
+ ).toString();
11295
11295
  bins.push({
11296
11296
  binId,
11297
11297
  xAmount: bin.amountX,
@@ -11312,10 +11312,10 @@ var DLMM = class {
11312
11312
  binArray.bins.forEach((bin, idx) => {
11313
11313
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11314
11314
  if (binId >= lowerBinId && binId <= upperBinId) {
11315
- const pricePerLamport = this.getPriceOfBinByBinId(
11316
- lbPair.binStep,
11317
- binId
11318
- );
11315
+ const pricePerLamport = getPriceOfBinByBinId(
11316
+ binId,
11317
+ lbPair.binStep
11318
+ ).toString();
11319
11319
  bins.push({
11320
11320
  binId,
11321
11321
  xAmount: bin.amountX,
@@ -11331,10 +11331,6 @@ var DLMM = class {
11331
11331
  }
11332
11332
  return bins;
11333
11333
  }
11334
- static getPriceOfBinByBinId(binStep, binId) {
11335
- const binStepNum = new Decimal4(binStep).div(new Decimal4(BASIS_POINT_MAX));
11336
- return new Decimal4(1).add(new Decimal4(binStepNum)).pow(new Decimal4(binId)).toString();
11337
- }
11338
11334
  /** Private method */
11339
11335
  processXYAmountDistribution(xYAmountDistribution) {
11340
11336
  let currentBinId = null;
@@ -11373,8 +11369,6 @@ var DLMM = class {
11373
11369
  const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
11374
11370
  const binArrayBins = [];
11375
11371
  for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
11376
- const binId = new BN9(i);
11377
- const pricePerLamport = this.getPriceOfBinByBinId(binId.toNumber());
11378
11372
  binArrayBins.push({
11379
11373
  amountX: new BN9(0),
11380
11374
  amountY: new BN9(0),
@@ -11399,7 +11393,10 @@ var DLMM = class {
11399
11393
  binArray.bins.forEach((bin, idx) => {
11400
11394
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11401
11395
  if (binId >= lowerBinId && binId <= upperBinId) {
11402
- const pricePerLamport = this.getPriceOfBinByBinId(binId);
11396
+ const pricePerLamport = getPriceOfBinByBinId(
11397
+ binId,
11398
+ this.lbPair.binStep
11399
+ ).toString();
11403
11400
  bins.push({
11404
11401
  binId,
11405
11402
  xAmount: bin.amountX,
@@ -11440,7 +11437,10 @@ var DLMM = class {
11440
11437
  binArray.bins.forEach((bin, idx) => {
11441
11438
  const binId = lowerBinIdForBinArray.toNumber() + idx;
11442
11439
  if (binId >= lowerBinId && binId <= upperBinId) {
11443
- const pricePerLamport = this.getPriceOfBinByBinId(binId);
11440
+ const pricePerLamport = getPriceOfBinByBinId(
11441
+ binId,
11442
+ this.lbPair.binStep
11443
+ ).toString();
11444
11444
  bins.push({
11445
11445
  binId,
11446
11446
  xAmount: bin.amountX,