@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.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +14 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6510,6 +6510,7 @@ declare function getFeeNumerator(currentPoint: number, activationPoint: BN, numb
|
|
|
6510
6510
|
declare function getSwapAmount(inAmount: BN, sqrtPrice: BN, liquidity: BN, tradeFeeNumerator: BN, aToB: boolean, collectFeeMode: number): {
|
|
6511
6511
|
amountOut: BN;
|
|
6512
6512
|
totalFee: BN;
|
|
6513
|
+
nextSqrtPrice: BN;
|
|
6513
6514
|
};
|
|
6514
6515
|
/**
|
|
6515
6516
|
* Converts basis points (bps) to a fee numerator
|
|
@@ -6596,11 +6597,11 @@ declare const getMaxAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
|
6596
6597
|
declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
6597
6598
|
/**
|
|
6598
6599
|
* Calculate price impact as a percentage
|
|
6599
|
-
* @param
|
|
6600
|
-
* @param
|
|
6600
|
+
* @param nextSqrtPrice sqrt price after swap
|
|
6601
|
+
* @param currentSqrtPrice current pool sqrt price
|
|
6601
6602
|
* @returns Price impact as a percentage (e.g., 1.5 means 1.5%)
|
|
6602
6603
|
*/
|
|
6603
|
-
declare const getPriceImpact: (
|
|
6604
|
+
declare const getPriceImpact: (nextSqrtPrice: BN, currentSqrtPrice: BN) => number;
|
|
6604
6605
|
declare const getPriceFromSqrtPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => string;
|
|
6605
6606
|
declare const getSqrtPriceFromPrice: (price: string, tokenADecimal: number, tokenBDecimal: number) => BN;
|
|
6606
6607
|
declare const getUnClaimReward: (poolState: PoolState, positionState: PositionState) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -6510,6 +6510,7 @@ declare function getFeeNumerator(currentPoint: number, activationPoint: BN, numb
|
|
|
6510
6510
|
declare function getSwapAmount(inAmount: BN, sqrtPrice: BN, liquidity: BN, tradeFeeNumerator: BN, aToB: boolean, collectFeeMode: number): {
|
|
6511
6511
|
amountOut: BN;
|
|
6512
6512
|
totalFee: BN;
|
|
6513
|
+
nextSqrtPrice: BN;
|
|
6513
6514
|
};
|
|
6514
6515
|
/**
|
|
6515
6516
|
* Converts basis points (bps) to a fee numerator
|
|
@@ -6596,11 +6597,11 @@ declare const getMaxAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
|
6596
6597
|
declare const getMinAmountWithSlippage: (amount: BN, rate: number) => BN;
|
|
6597
6598
|
/**
|
|
6598
6599
|
* Calculate price impact as a percentage
|
|
6599
|
-
* @param
|
|
6600
|
-
* @param
|
|
6600
|
+
* @param nextSqrtPrice sqrt price after swap
|
|
6601
|
+
* @param currentSqrtPrice current pool sqrt price
|
|
6601
6602
|
* @returns Price impact as a percentage (e.g., 1.5 means 1.5%)
|
|
6602
6603
|
*/
|
|
6603
|
-
declare const getPriceImpact: (
|
|
6604
|
+
declare const getPriceImpact: (nextSqrtPrice: BN, currentSqrtPrice: BN) => number;
|
|
6604
6605
|
declare const getPriceFromSqrtPrice: (sqrtPrice: BN, tokenADecimal: number, tokenBDecimal: number) => string;
|
|
6605
6606
|
declare const getSqrtPriceFromPrice: (price: string, tokenADecimal: number, tokenBDecimal: number) => BN;
|
|
6606
6607
|
declare const getUnClaimReward: (poolState: PoolState, positionState: PositionState) => {
|
package/dist/index.js
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
|
-
|
|
7348
|
+
nextSqrtPrice,
|
|
7343
7349
|
1 /* Down */
|
|
7344
7350
|
) : getAmountAFromLiquidityDelta(
|
|
7345
7351
|
liquidity,
|
|
7346
7352
|
sqrtPrice,
|
|
7347
|
-
|
|
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 (0, _anchor.BN)(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 (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
7525
7531
|
};
|
|
7526
|
-
var getPriceImpact = (
|
|
7527
|
-
const diff =
|
|
7528
|
-
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(
|
|
7532
|
+
var getPriceImpact = (nextSqrtPrice, currentSqrtPrice) => {
|
|
7533
|
+
const diff = nextSqrtPrice.pow(new (0, _anchor.BN)(2)).sub(currentSqrtPrice.pow(new (0, _anchor.BN)(2))).abs();
|
|
7534
|
+
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(currentSqrtPrice.pow(new (0, _anchor.BN)(2)).toString())).mul(100).toNumber();
|
|
7529
7535
|
};
|
|
7530
7536
|
var getPriceFromSqrtPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
7531
7537
|
const decimalSqrtPrice = new (0, _decimaljs2.default)(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(
|
|
8520
|
+
priceImpact: getPriceImpact(nextSqrtPrice, sqrtPriceQ64)
|
|
8515
8521
|
};
|
|
8516
8522
|
}
|
|
8517
8523
|
/**
|