@meteora-ag/cp-amm-sdk 1.0.1-rc.13 → 1.0.1-rc.14
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 +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +28 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6185,6 +6185,7 @@ var SCALE_OFFSET = 64;
|
|
|
6185
6185
|
var BASIS_POINT_MAX = 1e4;
|
|
6186
6186
|
var MAX_FEE_NUMERATOR = 5e8;
|
|
6187
6187
|
var FEE_DENOMINATOR = 1e9;
|
|
6188
|
+
var PRECISION = 1e6;
|
|
6188
6189
|
var MIN_SQRT_PRICE = new BN("4295048016");
|
|
6189
6190
|
var MAX_SQRT_PRICE = new BN("79226673521066979257578248091");
|
|
6190
6191
|
var MIN_CU_BUFFER = 5e4;
|
|
@@ -6549,6 +6550,7 @@ function getInitPriceQ64(tokenAAmount, tokenBAmount) {
|
|
|
6549
6550
|
|
|
6550
6551
|
// src/helpers/curve.ts
|
|
6551
6552
|
import { BN as BN4 } from "@coral-xyz/anchor";
|
|
6553
|
+
import Decimal2 from "decimal.js";
|
|
6552
6554
|
function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
|
|
6553
6555
|
let result;
|
|
6554
6556
|
if (aToB) {
|
|
@@ -6581,25 +6583,35 @@ function getDeltaAmountB(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
|
6581
6583
|
return result;
|
|
6582
6584
|
}
|
|
6583
6585
|
function getLiquidityDeltaFromAmountA(maxAmountA, lowerSqrtPrice, upperSqrtPrice) {
|
|
6584
|
-
const prod =
|
|
6585
|
-
|
|
6586
|
-
|
|
6586
|
+
const prod = new Decimal2(
|
|
6587
|
+
maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice)).toString()
|
|
6588
|
+
);
|
|
6589
|
+
const delta = new Decimal2(upperSqrtPrice.sub(lowerSqrtPrice).toString());
|
|
6590
|
+
return new BN4(prod.div(delta).floor().toFixed());
|
|
6587
6591
|
}
|
|
6588
6592
|
function getLiquidityDeltaFromAmountB(maxAmountB, lowerSqrtPrice, upperSqrtPrice) {
|
|
6589
|
-
const denominator =
|
|
6590
|
-
|
|
6591
|
-
|
|
6593
|
+
const denominator = new Decimal2(
|
|
6594
|
+
upperSqrtPrice.sub(lowerSqrtPrice).toString()
|
|
6595
|
+
);
|
|
6596
|
+
const prod = new Decimal2(maxAmountB.toString()).mul(
|
|
6597
|
+
Decimal2.pow(2, SCALE_OFFSET * 2)
|
|
6598
|
+
);
|
|
6599
|
+
return new BN4(prod.div(denominator).floor().toFixed());
|
|
6592
6600
|
}
|
|
6593
6601
|
function getAmountAFromLiquidityDelta(liquidity, currentSqrtPrice) {
|
|
6594
|
-
const prod = liquidity.
|
|
6602
|
+
const prod = new Decimal2(liquidity.toString()).mul(
|
|
6603
|
+
new Decimal2(MAX_SQRT_PRICE.sub(currentSqrtPrice).toString())
|
|
6604
|
+
);
|
|
6595
6605
|
const denominator = currentSqrtPrice.mul(MAX_SQRT_PRICE);
|
|
6596
|
-
const result =
|
|
6597
|
-
return result.
|
|
6606
|
+
const result = prod.mul(Decimal2.pow(2, 64)).div(new Decimal2(denominator.toString()));
|
|
6607
|
+
return result.div(Decimal2.pow(2, 64)).floor().toFixed();
|
|
6598
6608
|
}
|
|
6599
6609
|
function getAmountBFromLiquidityDelta(liquidity, currentSqrtPrice) {
|
|
6600
6610
|
const delta = currentSqrtPrice.sub(MIN_SQRT_PRICE);
|
|
6601
|
-
const prod = liquidity.mul(
|
|
6602
|
-
|
|
6611
|
+
const prod = new Decimal2(liquidity.toString()).mul(
|
|
6612
|
+
new Decimal2(delta.toString())
|
|
6613
|
+
);
|
|
6614
|
+
return prod.div(Decimal2.pow(2, 128)).floor().toFixed();
|
|
6603
6615
|
}
|
|
6604
6616
|
|
|
6605
6617
|
// src/helpers/fee.ts
|
|
@@ -6761,7 +6773,7 @@ var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, b
|
|
|
6761
6773
|
|
|
6762
6774
|
// src/helpers/utils.ts
|
|
6763
6775
|
import { BN as BN6 } from "@coral-xyz/anchor";
|
|
6764
|
-
import
|
|
6776
|
+
import Decimal3 from "decimal.js";
|
|
6765
6777
|
var getMaxAmountWithSlippage = (amount, rate) => {
|
|
6766
6778
|
const slippage = (100 + rate) / 100 * BASIS_POINT_MAX;
|
|
6767
6779
|
return amount.mul(new BN6(slippage)).div(new BN6(BASIS_POINT_MAX));
|
|
@@ -6772,13 +6784,12 @@ var getMinAmountWithSlippage = (amount, rate) => {
|
|
|
6772
6784
|
};
|
|
6773
6785
|
var getPriceImpact = (actualAmount, idealAmount) => {
|
|
6774
6786
|
const diff = idealAmount.sub(actualAmount);
|
|
6775
|
-
return new
|
|
6787
|
+
return new Decimal3(diff.toString()).div(new Decimal3(idealAmount.toString())).mul(100).toNumber();
|
|
6776
6788
|
};
|
|
6777
6789
|
var getCurrentPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
6778
|
-
const
|
|
6779
|
-
const price =
|
|
6780
|
-
|
|
6781
|
-
return price.muln(expo);
|
|
6790
|
+
const decimalSqrtPrice = new Decimal3(sqrtPrice.toString());
|
|
6791
|
+
const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new Decimal3(__pow(10, tokenADecimal - tokenBDecimal))).div(Decimal3.pow(2, 128)).toString();
|
|
6792
|
+
return price;
|
|
6782
6793
|
};
|
|
6783
6794
|
var getUnClaimReward = (positionState) => {
|
|
6784
6795
|
return {
|
|
@@ -8016,6 +8027,7 @@ export {
|
|
|
8016
8027
|
MAX_SQRT_PRICE,
|
|
8017
8028
|
MIN_CU_BUFFER,
|
|
8018
8029
|
MIN_SQRT_PRICE,
|
|
8030
|
+
PRECISION,
|
|
8019
8031
|
Rounding,
|
|
8020
8032
|
SCALE_OFFSET,
|
|
8021
8033
|
TradeDirection,
|