@meteora-ag/cp-amm-sdk 1.0.6 → 1.0.7

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
@@ -7336,19 +7336,25 @@ function getSwapAmount(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB,
7336
7336
  totalFee = getTotalFeeOnAmount(inAmount, tradeFeeNumerator);
7337
7337
  actualInAmount = inAmount.sub(totalFee);
7338
7338
  }
7339
+ const nextSqrtPrice = getNextSqrtPrice(
7340
+ actualInAmount,
7341
+ sqrtPrice,
7342
+ liquidity,
7343
+ aToB
7344
+ );
7339
7345
  const outAmount = aToB ? getAmountBFromLiquidityDelta(
7340
7346
  liquidity,
7341
7347
  sqrtPrice,
7342
- getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, true),
7348
+ nextSqrtPrice,
7343
7349
  1 /* Down */
7344
7350
  ) : getAmountAFromLiquidityDelta(
7345
7351
  liquidity,
7346
7352
  sqrtPrice,
7347
- getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, false),
7353
+ nextSqrtPrice,
7348
7354
  1 /* Down */
7349
7355
  );
7350
7356
  const amountOut = feeMode.feeOnInput ? outAmount : (totalFee = getTotalFeeOnAmount(outAmount, tradeFeeNumerator), outAmount.sub(totalFee));
7351
- return { amountOut, totalFee };
7357
+ return { amountOut, totalFee, nextSqrtPrice };
7352
7358
  }
7353
7359
  function bpsToFeeNumerator(bps) {
7354
7360
  return new BN5(bps * FEE_DENOMINATOR).divn(BASIS_POINT_MAX);
@@ -7523,9 +7529,9 @@ var getMinAmountWithSlippage = (amount, rate) => {
7523
7529
  const slippage = (100 - rate) / 100 * BASIS_POINT_MAX;
7524
7530
  return amount.mul(new BN6(slippage)).div(new BN6(BASIS_POINT_MAX));
7525
7531
  };
7526
- var getPriceImpact = (actualAmount, idealAmount) => {
7527
- const diff = idealAmount.sub(actualAmount);
7528
- return new Decimal3(diff.toString()).div(new Decimal3(idealAmount.toString())).mul(100).toNumber();
7532
+ var getPriceImpact = (nextSqrtPrice, currentSqrtPrice) => {
7533
+ const diff = nextSqrtPrice.pow(new BN6(2)).sub(currentSqrtPrice.pow(new BN6(2))).abs();
7534
+ return new Decimal3(diff.toString()).div(new Decimal3(currentSqrtPrice.pow(new BN6(2)).toString())).mul(100).toNumber();
7529
7535
  };
7530
7536
  var getPriceFromSqrtPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
7531
7537
  const decimalSqrtPrice = new Decimal3(sqrtPrice.toString());
@@ -8485,7 +8491,7 @@ var CpAmm = class {
8485
8491
  reductionFactor,
8486
8492
  dynamicFeeParams
8487
8493
  );
8488
- const { amountOut, totalFee } = getSwapAmount(
8494
+ const { amountOut, totalFee, nextSqrtPrice } = getSwapAmount(
8489
8495
  actualAmountIn,
8490
8496
  sqrtPriceQ64,
8491
8497
  liquidityQ64,
@@ -8511,7 +8517,7 @@ var CpAmm = class {
8511
8517
  swapOutAmount: actualAmountOut,
8512
8518
  minSwapOutAmount,
8513
8519
  totalFee,
8514
- priceImpact: getPriceImpact(minSwapOutAmount, actualAmountOut)
8520
+ priceImpact: getPriceImpact(nextSqrtPrice, sqrtPriceQ64)
8515
8521
  };
8516
8522
  }
8517
8523
  /**