@meteora-ag/dlmm 1.0.49-rc.1 → 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 +1 -7
- package/dist/index.js +31 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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 =
|
|
9708
|
-
|
|
9709
|
-
|
|
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,
|
|
@@ -9768,11 +9763,6 @@ var DLMM = class {
|
|
|
9768
9763
|
sParameters2,
|
|
9769
9764
|
activeId.toNumber()
|
|
9770
9765
|
);
|
|
9771
|
-
console.log(
|
|
9772
|
-
activeId.toString(),
|
|
9773
|
-
binArrayAccountToSwap.account.index.toString(),
|
|
9774
|
-
isBinIdWithinBinArray(activeId, binArrayAccountToSwap.account.index)
|
|
9775
|
-
);
|
|
9776
9766
|
if (isBinIdWithinBinArray(activeId, binArrayAccountToSwap.account.index)) {
|
|
9777
9767
|
const bin = getBinFromBinArray(
|
|
9778
9768
|
activeId.toNumber(),
|
|
@@ -9786,13 +9776,6 @@ var DLMM = class {
|
|
|
9786
9776
|
inAmountLeft,
|
|
9787
9777
|
swapForY
|
|
9788
9778
|
);
|
|
9789
|
-
console.log(
|
|
9790
|
-
"\u{1F680} ~ DLMM ~ amountIn:",
|
|
9791
|
-
amountIn.toString(),
|
|
9792
|
-
amountOut.toString(),
|
|
9793
|
-
fee.toString(),
|
|
9794
|
-
protocolFee.toString()
|
|
9795
|
-
);
|
|
9796
9779
|
if (!amountIn.isZero()) {
|
|
9797
9780
|
inAmountLeft = inAmountLeft.sub(amountIn);
|
|
9798
9781
|
actualOutAmount = actualOutAmount.add(amountOut);
|
|
@@ -9822,6 +9805,10 @@ var DLMM = class {
|
|
|
9822
9805
|
);
|
|
9823
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));
|
|
9824
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
|
+
);
|
|
9825
9812
|
return {
|
|
9826
9813
|
consumedInAmount: inAmount,
|
|
9827
9814
|
outAmount: actualOutAmount,
|
|
@@ -9829,7 +9816,8 @@ var DLMM = class {
|
|
|
9829
9816
|
protocolFee: protocolFeeAmount,
|
|
9830
9817
|
minOutAmount,
|
|
9831
9818
|
priceImpact,
|
|
9832
|
-
binArraysPubkey: [...binArraysForSwap.keys()]
|
|
9819
|
+
binArraysPubkey: [...binArraysForSwap.keys()],
|
|
9820
|
+
endPrice
|
|
9833
9821
|
};
|
|
9834
9822
|
}
|
|
9835
9823
|
async swapExactOut({
|
|
@@ -11000,10 +10988,10 @@ var DLMM = class {
|
|
|
11000
10988
|
binArray.bins.forEach((bin, idx) => {
|
|
11001
10989
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11002
10990
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11003
|
-
const pricePerLamport =
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
);
|
|
10991
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
10992
|
+
binId,
|
|
10993
|
+
lbPair.binStep
|
|
10994
|
+
).toString();
|
|
11007
10995
|
bins.push({
|
|
11008
10996
|
binId,
|
|
11009
10997
|
xAmount: bin.amountX,
|
|
@@ -11024,10 +11012,10 @@ var DLMM = class {
|
|
|
11024
11012
|
binArray.bins.forEach((bin, idx) => {
|
|
11025
11013
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11026
11014
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11027
|
-
const pricePerLamport =
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
);
|
|
11015
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
11016
|
+
binId,
|
|
11017
|
+
lbPair.binStep
|
|
11018
|
+
).toString();
|
|
11031
11019
|
bins.push({
|
|
11032
11020
|
binId,
|
|
11033
11021
|
xAmount: bin.amountX,
|
|
@@ -11043,10 +11031,6 @@ var DLMM = class {
|
|
|
11043
11031
|
}
|
|
11044
11032
|
return bins;
|
|
11045
11033
|
}
|
|
11046
|
-
static getPriceOfBinByBinId(binStep, binId) {
|
|
11047
|
-
const binStepNum = new (0, _decimaljs2.default)(binStep).div(new (0, _decimaljs2.default)(BASIS_POINT_MAX));
|
|
11048
|
-
return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(binId)).toString();
|
|
11049
|
-
}
|
|
11050
11034
|
/** Private method */
|
|
11051
11035
|
processXYAmountDistribution(xYAmountDistribution) {
|
|
11052
11036
|
let currentBinId = null;
|
|
@@ -11085,8 +11069,6 @@ var DLMM = class {
|
|
|
11085
11069
|
const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
|
|
11086
11070
|
const binArrayBins = [];
|
|
11087
11071
|
for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
|
|
11088
|
-
const binId = new (0, _anchor.BN)(i);
|
|
11089
|
-
const pricePerLamport = this.getPriceOfBinByBinId(binId.toNumber());
|
|
11090
11072
|
binArrayBins.push({
|
|
11091
11073
|
amountX: new (0, _anchor.BN)(0),
|
|
11092
11074
|
amountY: new (0, _anchor.BN)(0),
|
|
@@ -11111,7 +11093,10 @@ var DLMM = class {
|
|
|
11111
11093
|
binArray.bins.forEach((bin, idx) => {
|
|
11112
11094
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11113
11095
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11114
|
-
const pricePerLamport =
|
|
11096
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
11097
|
+
binId,
|
|
11098
|
+
this.lbPair.binStep
|
|
11099
|
+
).toString();
|
|
11115
11100
|
bins.push({
|
|
11116
11101
|
binId,
|
|
11117
11102
|
xAmount: bin.amountX,
|
|
@@ -11152,7 +11137,10 @@ var DLMM = class {
|
|
|
11152
11137
|
binArray.bins.forEach((bin, idx) => {
|
|
11153
11138
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11154
11139
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11155
|
-
const pricePerLamport =
|
|
11140
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
11141
|
+
binId,
|
|
11142
|
+
this.lbPair.binStep
|
|
11143
|
+
).toString();
|
|
11156
11144
|
bins.push({
|
|
11157
11145
|
binId,
|
|
11158
11146
|
xAmount: bin.amountX,
|