@meteora-ag/dlmm 1.6.0-rc.30 → 1.6.0-rc.32
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.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
SystemProgram as SystemProgram2,
|
|
20
20
|
Transaction
|
|
21
21
|
} from "@solana/web3.js";
|
|
22
|
-
import
|
|
22
|
+
import Decimal9 from "decimal.js";
|
|
23
23
|
|
|
24
24
|
// src/dlmm/constants/index.ts
|
|
25
25
|
import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
|
@@ -12939,6 +12939,9 @@ function buildLiquidityStrategyParameters(amountX, amountY, minDeltaId, maxDelta
|
|
|
12939
12939
|
};
|
|
12940
12940
|
}
|
|
12941
12941
|
|
|
12942
|
+
// src/dlmm/helpers/index.ts
|
|
12943
|
+
import Decimal8 from "decimal.js";
|
|
12944
|
+
|
|
12942
12945
|
// src/dlmm/helpers/lbPair.ts
|
|
12943
12946
|
import { PublicKey as PublicKey8 } from "@solana/web3.js";
|
|
12944
12947
|
import { TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
|
|
@@ -13668,10 +13671,20 @@ function getBinCount(minBinId, maxBinId) {
|
|
|
13668
13671
|
return maxBinId - minBinId + 1;
|
|
13669
13672
|
}
|
|
13670
13673
|
function getSlippageMaxAmount(amount, slippage) {
|
|
13671
|
-
|
|
13674
|
+
if (slippage == 100) {
|
|
13675
|
+
return U64_MAX;
|
|
13676
|
+
}
|
|
13677
|
+
const amountDecimal = new Decimal8(amount.toString());
|
|
13678
|
+
const slippageAppliedAmount = new BN18(
|
|
13679
|
+
amountDecimal.mul(new Decimal8(100 + slippage)).div(new Decimal8(100)).floor().toString()
|
|
13680
|
+
);
|
|
13681
|
+
return slippageAppliedAmount;
|
|
13672
13682
|
}
|
|
13673
13683
|
function getSlippageMinAmount(amount, slippage) {
|
|
13674
|
-
|
|
13684
|
+
const amountDecimal = new Decimal8(amount.toString());
|
|
13685
|
+
return new BN18(
|
|
13686
|
+
amountDecimal.mul(new Decimal8(100 - slippage)).div(new Decimal8(100)).ceil().toString()
|
|
13687
|
+
);
|
|
13675
13688
|
}
|
|
13676
13689
|
function getPositionCountByBinCount(binCount) {
|
|
13677
13690
|
return Math.ceil(binCount / MAX_BINS_PER_POSITION.toNumber());
|
|
@@ -14792,11 +14805,11 @@ var DLMM = class {
|
|
|
14792
14805
|
return positionsMap;
|
|
14793
14806
|
}
|
|
14794
14807
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
14795
|
-
return new
|
|
14808
|
+
return new Decimal9(price).mul(new Decimal9(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
14796
14809
|
}
|
|
14797
14810
|
static getBinIdFromPrice(price, binStep, min) {
|
|
14798
|
-
const binStepNum = new
|
|
14799
|
-
const binId = new
|
|
14811
|
+
const binStepNum = new Decimal9(binStep).div(new Decimal9(BASIS_POINT_MAX));
|
|
14812
|
+
const binId = new Decimal9(price).log().dividedBy(new Decimal9(1).add(binStepNum).log());
|
|
14800
14813
|
return (min ? binId.floor() : binId.ceil()).toNumber();
|
|
14801
14814
|
}
|
|
14802
14815
|
/**
|
|
@@ -15412,8 +15425,8 @@ var DLMM = class {
|
|
|
15412
15425
|
*/
|
|
15413
15426
|
static calculateFeeInfo(baseFactor, binStep, baseFeePowerFactor) {
|
|
15414
15427
|
const baseFeeRate = new BN21(baseFactor).mul(new BN21(binStep)).mul(new BN21(10)).mul(new BN21(10).pow(new BN21(baseFeePowerFactor ?? 0)));
|
|
15415
|
-
const baseFeeRatePercentage = new
|
|
15416
|
-
const maxFeeRatePercentage = new
|
|
15428
|
+
const baseFeeRatePercentage = new Decimal9(baseFeeRate.toString()).mul(new Decimal9(100)).div(new Decimal9(FEE_PRECISION.toString()));
|
|
15429
|
+
const maxFeeRatePercentage = new Decimal9(MAX_FEE_RATE.toString()).mul(new Decimal9(100)).div(new Decimal9(FEE_PRECISION.toString()));
|
|
15417
15430
|
return {
|
|
15418
15431
|
baseFeeRatePercentage,
|
|
15419
15432
|
maxFeeRatePercentage
|
|
@@ -15431,7 +15444,7 @@ var DLMM = class {
|
|
|
15431
15444
|
this.lbPair.binStep,
|
|
15432
15445
|
this.lbPair.parameters.baseFeePowerFactor
|
|
15433
15446
|
);
|
|
15434
|
-
const protocolFeePercentage = new
|
|
15447
|
+
const protocolFeePercentage = new Decimal9(protocolShare.toString()).mul(new Decimal9(100)).div(new Decimal9(BASIS_POINT_MAX));
|
|
15435
15448
|
return {
|
|
15436
15449
|
baseFeeRatePercentage,
|
|
15437
15450
|
maxFeeRatePercentage,
|
|
@@ -15463,7 +15476,7 @@ var DLMM = class {
|
|
|
15463
15476
|
sParameters3,
|
|
15464
15477
|
vParameterClone
|
|
15465
15478
|
);
|
|
15466
|
-
return new
|
|
15479
|
+
return new Decimal9(totalFee.toString()).div(new Decimal9(FEE_PRECISION.toString())).mul(100);
|
|
15467
15480
|
}
|
|
15468
15481
|
/**
|
|
15469
15482
|
* The function `getEmissionRate` returns the emission rates for two rewards.
|
|
@@ -15476,8 +15489,8 @@ var DLMM = class {
|
|
|
15476
15489
|
({ rewardRate, rewardDurationEnd }) => now > rewardDurationEnd.toNumber() ? void 0 : rewardRate
|
|
15477
15490
|
);
|
|
15478
15491
|
return {
|
|
15479
|
-
rewardOne: rewardOneEmissionRate ? new
|
|
15480
|
-
rewardTwo: rewardTwoEmissionRate ? new
|
|
15492
|
+
rewardOne: rewardOneEmissionRate ? new Decimal9(rewardOneEmissionRate.toString()).div(PRECISION) : void 0,
|
|
15493
|
+
rewardTwo: rewardTwoEmissionRate ? new Decimal9(rewardTwoEmissionRate.toString()).div(PRECISION) : void 0
|
|
15481
15494
|
};
|
|
15482
15495
|
}
|
|
15483
15496
|
/**
|
|
@@ -15570,8 +15583,8 @@ var DLMM = class {
|
|
|
15570
15583
|
* @returns {string} real price of bin
|
|
15571
15584
|
*/
|
|
15572
15585
|
fromPricePerLamport(pricePerLamport) {
|
|
15573
|
-
return new
|
|
15574
|
-
new
|
|
15586
|
+
return new Decimal9(pricePerLamport).div(
|
|
15587
|
+
new Decimal9(
|
|
15575
15588
|
10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
|
|
15576
15589
|
)
|
|
15577
15590
|
).toString();
|
|
@@ -15729,12 +15742,12 @@ var DLMM = class {
|
|
|
15729
15742
|
const lowerBinArrayIndex = binIdToBinArrayIndex(currentMinBinId);
|
|
15730
15743
|
const upperBinArrayIndex = binIdToBinArrayIndex(currentMaxBinId);
|
|
15731
15744
|
const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
|
|
15732
|
-
const binArrayCost = new
|
|
15733
|
-
new
|
|
15745
|
+
const binArrayCost = new Decimal9(binArraysCount).mul(
|
|
15746
|
+
new Decimal9(BIN_ARRAY_FEE)
|
|
15734
15747
|
);
|
|
15735
15748
|
return {
|
|
15736
|
-
positionExtendCost: new
|
|
15737
|
-
new
|
|
15749
|
+
positionExtendCost: new Decimal9(positionExtendCost).div(
|
|
15750
|
+
new Decimal9(LAMPORTS_PER_SOL2)
|
|
15738
15751
|
),
|
|
15739
15752
|
binArrayCost
|
|
15740
15753
|
};
|
|
@@ -15742,7 +15755,10 @@ var DLMM = class {
|
|
|
15742
15755
|
async quoteCreatePosition({ strategy }) {
|
|
15743
15756
|
const { minBinId, maxBinId } = strategy;
|
|
15744
15757
|
const binCount = maxBinId - minBinId + 1;
|
|
15745
|
-
|
|
15758
|
+
let positionCount = Math.floor(binCount / MAX_BINS_PER_POSITION.toNumber());
|
|
15759
|
+
if (binCount % MAX_BINS_PER_POSITION.toNumber() > 0) {
|
|
15760
|
+
positionCount++;
|
|
15761
|
+
}
|
|
15746
15762
|
let positionReallocCost = 0;
|
|
15747
15763
|
let lastUpperBinId = minBinId;
|
|
15748
15764
|
for (let i = 0; i < positionCount; i++) {
|
|
@@ -17107,7 +17123,7 @@ var DLMM = class {
|
|
|
17107
17123
|
activeId.toNumber(),
|
|
17108
17124
|
this.lbPair.binStep
|
|
17109
17125
|
);
|
|
17110
|
-
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new
|
|
17126
|
+
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal9(100));
|
|
17111
17127
|
actualInAmount = calculateTransferFeeIncludedAmount(
|
|
17112
17128
|
actualInAmount.add(feeAmount),
|
|
17113
17129
|
inMint,
|
|
@@ -17294,7 +17310,7 @@ var DLMM = class {
|
|
|
17294
17310
|
),
|
|
17295
17311
|
swapForY
|
|
17296
17312
|
);
|
|
17297
|
-
const priceImpact = new
|
|
17313
|
+
const priceImpact = new Decimal9(totalOutAmount.toString()).sub(new Decimal9(outAmountWithoutSlippage.toString())).div(new Decimal9(outAmountWithoutSlippage.toString())).mul(new Decimal9(100)).abs();
|
|
17298
17314
|
const endPrice = getPriceOfBinByBinId(
|
|
17299
17315
|
lastFilledActiveBinId.toNumber(),
|
|
17300
17316
|
this.lbPair.binStep
|
|
@@ -17903,11 +17919,11 @@ var DLMM = class {
|
|
|
17903
17919
|
let totalBinArraysCount = new BN21(0);
|
|
17904
17920
|
let totalBinArraysLamports = new BN21(0);
|
|
17905
17921
|
let binArrayBitmapLamports = new BN21(0);
|
|
17906
|
-
const toLamportMultiplier = new
|
|
17922
|
+
const toLamportMultiplier = new Decimal9(
|
|
17907
17923
|
10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
|
|
17908
17924
|
);
|
|
17909
|
-
const minPricePerLamport = new
|
|
17910
|
-
const maxPricePerLamport = new
|
|
17925
|
+
const minPricePerLamport = new Decimal9(minPrice).mul(toLamportMultiplier);
|
|
17926
|
+
const maxPricePerLamport = new Decimal9(maxPrice).mul(toLamportMultiplier);
|
|
17911
17927
|
const minBinId = new BN21(
|
|
17912
17928
|
DLMM.getBinIdFromPrice(minPricePerLamport, this.lbPair.binStep, false)
|
|
17913
17929
|
);
|
|
@@ -19393,8 +19409,8 @@ var DLMM = class {
|
|
|
19393
19409
|
if (!bins.length)
|
|
19394
19410
|
return null;
|
|
19395
19411
|
const positionData = [];
|
|
19396
|
-
let totalXAmount = new
|
|
19397
|
-
let totalYAmount = new
|
|
19412
|
+
let totalXAmount = new Decimal9(0);
|
|
19413
|
+
let totalYAmount = new Decimal9(0);
|
|
19398
19414
|
const ZERO = new BN21(0);
|
|
19399
19415
|
let feeX = ZERO;
|
|
19400
19416
|
let feeY = ZERO;
|
|
@@ -19405,8 +19421,8 @@ var DLMM = class {
|
|
|
19405
19421
|
const posBinRewardInfo = positionRewardInfos[idx];
|
|
19406
19422
|
const positionXAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.xAmount).div(binSupply);
|
|
19407
19423
|
const positionYAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.yAmount).div(binSupply);
|
|
19408
|
-
totalXAmount = totalXAmount.add(new
|
|
19409
|
-
totalYAmount = totalYAmount.add(new
|
|
19424
|
+
totalXAmount = totalXAmount.add(new Decimal9(positionXAmount.toString()));
|
|
19425
|
+
totalYAmount = totalYAmount.add(new Decimal9(positionYAmount.toString()));
|
|
19410
19426
|
const feeInfo = feeInfos[idx];
|
|
19411
19427
|
const newFeeX = mulShr(
|
|
19412
19428
|
posShares[idx].shrn(SCALE_OFFSET),
|
|
@@ -19570,7 +19586,7 @@ var DLMM = class {
|
|
|
19570
19586
|
rewardPerTokenStored: [ZERO, ZERO],
|
|
19571
19587
|
price: pricePerLamport,
|
|
19572
19588
|
version: 2,
|
|
19573
|
-
pricePerToken: new
|
|
19589
|
+
pricePerToken: new Decimal9(pricePerLamport).mul(new Decimal9(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
19574
19590
|
});
|
|
19575
19591
|
} else {
|
|
19576
19592
|
const bin = binArray.bins[i];
|
|
@@ -19584,7 +19600,7 @@ var DLMM = class {
|
|
|
19584
19600
|
rewardPerTokenStored: bin.rewardPerTokenStored,
|
|
19585
19601
|
price: pricePerLamport,
|
|
19586
19602
|
version: binArray.version,
|
|
19587
|
-
pricePerToken: new
|
|
19603
|
+
pricePerToken: new Decimal9(pricePerLamport).mul(new Decimal9(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
19588
19604
|
});
|
|
19589
19605
|
}
|
|
19590
19606
|
}
|