@meteora-ag/dlmm 1.0.52-rc.8 → 1.0.53
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 +41 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5293,6 +5293,7 @@ interface SwapQuote {
|
|
|
5293
5293
|
minOutAmount: BN;
|
|
5294
5294
|
priceImpact: Decimal;
|
|
5295
5295
|
binArraysPubkey: any[];
|
|
5296
|
+
endPrice: Decimal;
|
|
5296
5297
|
}
|
|
5297
5298
|
interface SwapQuoteExactOut {
|
|
5298
5299
|
inAmount: BN;
|
|
@@ -5605,12 +5606,6 @@ declare class DLMM {
|
|
|
5605
5606
|
* @returns an object with two properties: "binId" which is a number, and "price" which is a string.
|
|
5606
5607
|
*/
|
|
5607
5608
|
getActiveBin(): Promise<BinLiquidity>;
|
|
5608
|
-
/**
|
|
5609
|
-
* The function get the price of a bin based on its bin ID.
|
|
5610
|
-
* @param {number} binId - The `binId` parameter is a number that represents the ID of a bin.
|
|
5611
|
-
* @returns {number} the calculated price of a bin based on the provided binId.
|
|
5612
|
-
*/
|
|
5613
|
-
getPriceOfBinByBinId(binId: number): string;
|
|
5614
5609
|
/**
|
|
5615
5610
|
* The function get bin ID based on a given price and a boolean flag indicating whether to
|
|
5616
5611
|
* round down or up.
|
|
@@ -5931,7 +5926,6 @@ declare class DLMM {
|
|
|
5931
5926
|
private static getClaimableSwapFee;
|
|
5932
5927
|
private static processPosition;
|
|
5933
5928
|
private static getBinsBetweenLowerAndUpperBound;
|
|
5934
|
-
private static getPriceOfBinByBinId;
|
|
5935
5929
|
/** Private method */
|
|
5936
5930
|
private processXYAmountDistribution;
|
|
5937
5931
|
private getBins;
|
package/dist/index.js
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 (0, _decimaljs2.default)(this.lbPair.binStep).div(
|
|
8580
|
-
new (0, _decimaljs2.default)(BASIS_POINT_MAX)
|
|
8581
|
-
);
|
|
8582
|
-
return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(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 =
|
|
9863
|
-
|
|
9864
|
-
|
|
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 (0, _decimaljs2.default)(100));
|
|
9865
9860
|
const maxInAmount = actualInAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).add(allowedSlippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
9866
9861
|
return {
|
|
9867
9862
|
inAmount: actualInAmount,
|
|
@@ -9972,6 +9967,10 @@ var DLMM = class {
|
|
|
9972
9967
|
);
|
|
9973
9968
|
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));
|
|
9974
9969
|
const minOutAmount = actualOutAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).sub(allowedSlippage)).div(new (0, _anchor.BN)(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({
|
|
@@ -11005,33 +11005,33 @@ var DLMM = class {
|
|
|
11005
11005
|
const amount0AfterFee = amount0.sub(fee);
|
|
11006
11006
|
const amountOut = isWithdrawForY ? mulShr(price, amount0AfterFee, SCALE_OFFSET, 1 /* Down */) : shlDiv(amount0AfterFee, price, SCALE_OFFSET, 1 /* Down */);
|
|
11007
11007
|
return {
|
|
11008
|
-
withdrawAmount: amount1.add(amountOut
|
|
11008
|
+
withdrawAmount: amount1.add(amountOut.gt(maxAmountOut) ? maxAmountOut : amountOut)
|
|
11009
11009
|
};
|
|
11010
11010
|
}
|
|
11011
11011
|
async getWithdrawSingleSideAmount(positionPubkey, isWithdrawForY) {
|
|
11012
11012
|
let totalWithdrawAmount = new (0, _anchor.BN)(0);
|
|
11013
|
-
let
|
|
11014
|
-
let
|
|
11013
|
+
let lowerBinArray;
|
|
11014
|
+
let upperBinArray;
|
|
11015
11015
|
const position = await this.program.account.positionV2.fetch(
|
|
11016
11016
|
positionPubkey
|
|
11017
11017
|
);
|
|
11018
11018
|
const lowerBinArrayIdx = binIdToBinArrayIndex(new (0, _anchor.BN)(position.lowerBinId));
|
|
11019
|
-
const [
|
|
11019
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
11020
11020
|
position.lbPair,
|
|
11021
11021
|
lowerBinArrayIdx,
|
|
11022
11022
|
this.program.programId
|
|
11023
11023
|
);
|
|
11024
11024
|
const upperBinArrayIdx = lowerBinArrayIdx.add(new (0, _anchor.BN)(1));
|
|
11025
|
-
const [
|
|
11025
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
11026
11026
|
position.lbPair,
|
|
11027
11027
|
upperBinArrayIdx,
|
|
11028
11028
|
this.program.programId
|
|
11029
11029
|
);
|
|
11030
|
-
[
|
|
11031
|
-
|
|
11032
|
-
|
|
11030
|
+
[lowerBinArray, upperBinArray] = await this.program.account.binArray.fetchMultiple([
|
|
11031
|
+
lowerBinArrayPubKey,
|
|
11032
|
+
upperBinArrayPubKey
|
|
11033
11033
|
]);
|
|
11034
|
-
if (!
|
|
11034
|
+
if (!lowerBinArray || !upperBinArray)
|
|
11035
11035
|
throw new Error("BinArray not found");
|
|
11036
11036
|
for (let idx = 0; idx < position.liquidityShares.length; idx++) {
|
|
11037
11037
|
const shareToRemove = position.liquidityShares[idx];
|
|
@@ -11040,7 +11040,7 @@ var DLMM = class {
|
|
|
11040
11040
|
}
|
|
11041
11041
|
const binId = new (0, _anchor.BN)(position.lowerBinId).add(new (0, _anchor.BN)(idx));
|
|
11042
11042
|
const binArrayIndex = binIdToBinArrayIndex(binId);
|
|
11043
|
-
const binArray = binArrayIndex.eq(lowerBinArrayIdx) ?
|
|
11043
|
+
const binArray = binArrayIndex.eq(lowerBinArrayIdx) ? lowerBinArray : upperBinArray;
|
|
11044
11044
|
const bin = getBinFromBinArray(binId.toNumber(), binArray);
|
|
11045
11045
|
if (isWithdrawForY) {
|
|
11046
11046
|
if (binId.gt(new (0, _anchor.BN)(this.lbPair.activeId))) {
|
|
@@ -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 =
|
|
11292
|
-
|
|
11293
|
-
|
|
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 =
|
|
11316
|
-
|
|
11317
|
-
|
|
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 (0, _decimaljs2.default)(binStep).div(new (0, _decimaljs2.default)(BASIS_POINT_MAX));
|
|
11336
|
-
return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(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 (0, _anchor.BN)(i);
|
|
11377
|
-
const pricePerLamport = this.getPriceOfBinByBinId(binId.toNumber());
|
|
11378
11372
|
binArrayBins.push({
|
|
11379
11373
|
amountX: new (0, _anchor.BN)(0),
|
|
11380
11374
|
amountY: new (0, _anchor.BN)(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 =
|
|
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 =
|
|
11440
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
11441
|
+
binId,
|
|
11442
|
+
this.lbPair.binStep
|
|
11443
|
+
).toString();
|
|
11444
11444
|
bins.push({
|
|
11445
11445
|
binId,
|
|
11446
11446
|
xAmount: bin.amountX,
|