@meteora-ag/dlmm 1.0.50-rc.2 → 1.0.51
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 +31 -3
- package/dist/index.js +101 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -5226,7 +5226,6 @@ interface SwapQuote {
|
|
|
5226
5226
|
minOutAmount: BN;
|
|
5227
5227
|
priceImpact: Decimal;
|
|
5228
5228
|
binArraysPubkey: any[];
|
|
5229
|
-
endPrice: Decimal;
|
|
5230
5229
|
}
|
|
5231
5230
|
interface SwapQuoteExactOut {
|
|
5232
5231
|
inAmount: BN;
|
|
@@ -5539,6 +5538,12 @@ declare class DLMM {
|
|
|
5539
5538
|
* @returns an object with two properties: "binId" which is a number, and "price" which is a string.
|
|
5540
5539
|
*/
|
|
5541
5540
|
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;
|
|
5542
5547
|
/**
|
|
5543
5548
|
* The function get bin ID based on a given price and a boolean flag indicating whether to
|
|
5544
5549
|
* round down or up.
|
|
@@ -5675,6 +5680,8 @@ declare class DLMM {
|
|
|
5675
5680
|
* - `inAmount`: Amount of lamport to swap in
|
|
5676
5681
|
* - `swapForY`: Swap token X to Y when it is true, else reversed.
|
|
5677
5682
|
* - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
|
|
5683
|
+
* - `binArrays`: binArrays for swapQuote.
|
|
5684
|
+
* - `isPartialFill`: Flag to check whether the the swapQuote is partial fill, default = false.
|
|
5678
5685
|
* @returns {SwapQuote}
|
|
5679
5686
|
* - `consumedInAmount`: Amount of lamport to swap in
|
|
5680
5687
|
* - `outAmount`: Amount of lamport to swap out
|
|
@@ -5684,7 +5691,7 @@ declare class DLMM {
|
|
|
5684
5691
|
* - `priceImpact`: Price impact of the swap
|
|
5685
5692
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
5686
5693
|
*/
|
|
5687
|
-
swapQuote(inAmount: BN, swapForY: boolean, allowedSlippage: BN, binArrays: BinArrayAccount[]): SwapQuote;
|
|
5694
|
+
swapQuote(inAmount: BN, swapForY: boolean, allowedSlippage: BN, binArrays: BinArrayAccount[], isPartialFill?: boolean): SwapQuote;
|
|
5688
5695
|
swapExactOut({ inToken, outToken, outAmount, maxInAmount, lbPair, user, binArraysPubkey, }: SwapExactOutParams): Promise<Transaction>;
|
|
5689
5696
|
/**
|
|
5690
5697
|
* Returns a transaction to be signed and sent by user performing swap.
|
|
@@ -5791,6 +5798,14 @@ declare class DLMM {
|
|
|
5791
5798
|
* @returns {Promise<SeedLiquidityResponse>}
|
|
5792
5799
|
*/
|
|
5793
5800
|
seedLiquidity(owner: PublicKey, operator: PublicKey, feeOwner: PublicKey, seedAmount: BN, curvature: number, minPrice: number, maxPrice: number, base: PublicKey): Promise<SeedLiquidityResponse>;
|
|
5801
|
+
/**
|
|
5802
|
+
* Initializes bin arrays for the given bin array indexes if it wasn't initialized.
|
|
5803
|
+
*
|
|
5804
|
+
* @param {BN[]} binArrayIndexes - An array of bin array indexes to initialize.
|
|
5805
|
+
* @param {PublicKey} funder - The public key of the funder.
|
|
5806
|
+
* @return {Promise<TransactionInstruction[]>} An array of transaction instructions to initialize the bin arrays.
|
|
5807
|
+
*/
|
|
5808
|
+
initializeBinArrays(binArrayIndexes: BN[], funder: PublicKey): Promise<TransactionInstruction[]>;
|
|
5794
5809
|
/**
|
|
5795
5810
|
*
|
|
5796
5811
|
* @param
|
|
@@ -5839,6 +5854,7 @@ declare class DLMM {
|
|
|
5839
5854
|
private static getClaimableSwapFee;
|
|
5840
5855
|
private static processPosition;
|
|
5841
5856
|
private static getBinsBetweenLowerAndUpperBound;
|
|
5857
|
+
private static getPriceOfBinByBinId;
|
|
5842
5858
|
/** Private method */
|
|
5843
5859
|
private processXYAmountDistribution;
|
|
5844
5860
|
private getBins;
|
|
@@ -5878,6 +5894,18 @@ declare function isBinIdWithinBinArray(activeId: BN, binArrayIndex: BN): boolean
|
|
|
5878
5894
|
declare function getBinFromBinArray(binId: number, binArray: BinArray): Bin;
|
|
5879
5895
|
declare function findNextBinArrayIndexWithLiquidity(swapForY: boolean, activeId: BN, lbPairState: LbPair, binArrayBitmapExtension: BinArrayBitmapExtension | null): BN | null;
|
|
5880
5896
|
declare function findNextBinArrayWithLiquidity(swapForY: boolean, activeBinId: BN, lbPairState: LbPair, binArrayBitmapExtension: BinArrayBitmapExtension | null, binArrays: BinArrayAccount[]): BinArrayAccount | null;
|
|
5897
|
+
/**
|
|
5898
|
+
* Retrieves the bin arrays required to initialize multiple positions in continuous range.
|
|
5899
|
+
*
|
|
5900
|
+
* @param {PublicKey} pair - The public key of the pair.
|
|
5901
|
+
* @param {BN} fromBinId - The starting bin ID.
|
|
5902
|
+
* @param {BN} toBinId - The ending bin ID.
|
|
5903
|
+
* @return {[{key: PublicKey, index: BN }]} An array of bin arrays required for the given position range.
|
|
5904
|
+
*/
|
|
5905
|
+
declare function getBinArraysRequiredByPositionRange(pair: PublicKey, fromBinId: BN, toBinId: BN, programId: PublicKey): {
|
|
5906
|
+
key: PublicKey;
|
|
5907
|
+
index: BN;
|
|
5908
|
+
}[];
|
|
5881
5909
|
|
|
5882
5910
|
declare function getPriceOfBinByBinId(binId: number, binStep: number): Decimal;
|
|
5883
5911
|
/** private */
|
|
@@ -6250,4 +6278,4 @@ declare const MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = 26;
|
|
|
6250
6278
|
declare const MAX_BIN_PER_TX = 69;
|
|
6251
6279
|
declare const MAX_ACTIVE_BIN_SLIPPAGE = 3;
|
|
6252
6280
|
|
|
6253
|
-
export { ADMIN, BASIS_POINT_MAX, BIN_ARRAY_BITMAP_SIZE, BIN_ARRAY_FEE, Bin, BinAndAmount, BinArray, BinArrayAccount, BinArrayBitmapExtension, BinArrayBitmapExtensionAccount, BinLiquidity, BinLiquidityDistribution, BinLiquidityReduction, BitmapType, ClmmProgram, CompressedBinDepositAmount, CompressedBinDepositAmounts, DLMMError, EXTENSION_BINARRAY_BITMAP_SIZE, EmissionRate, FEE_PRECISION, FeeInfo, GetOrCreateATAResponse, IAccountsCache, IDL, InitPermissionPairIx, LBCLMM_PROGRAM_IDS, LMRewards, LbClmm, LbPair, LbPairAccount, LbPosition, LiquidityOneSideParameter, LiquidityParameterByStrategy, LiquidityParameterByStrategyOneSide, LiquidityParameterByWeight, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BIN_ARRAY_SIZE, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, MAX_BIN_PER_POSITION, MAX_BIN_PER_TX, MAX_CLAIM_ALL_ALLOWED, MAX_FEE_RATE, Network, POSITION_FEE, PRECISION, PairType, Position, PositionBinData, PositionData, PositionInfo, PositionV2, PositionVersion, ProgramStrategyParameter, ProgramStrategyType, SCALE, SCALE_OFFSET, SIMULATION_USER, SeedLiquidityResponse, Strategy, StrategyParameters, StrategyType, SwapExactOutParams, SwapFee, SwapParams, SwapQuote, SwapQuoteExactOut, SwapWithPriceImpactParams, TInitializePositionAndAddLiquidityParams, TInitializePositionAndAddLiquidityParamsByStrategy, TQuoteCreatePositionParams, TokenReserve, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, binIdToBinArrayIndex, calculateBidAskDistribution, calculateNormalDistribution, calculateSpotDistribution, chunkedFetchMultipleBinArrayBitmapExtensionAccount, chunkedFetchMultiplePoolAccount, chunkedGetMultipleAccountInfos, chunks, computeBudgetIx, computeFee, computeFeeFromAmount, computeProtocolFee, DLMM as default, deriveBinArray, deriveBinArrayBitmapExtension, deriveLbPair, deriveLbPair2, deriveOracle, derivePermissionLbPair, derivePosition, derivePresetParameter, derivePresetParameter2, deriveReserve, findNextBinArrayIndexWithLiquidity, findNextBinArrayWithLiquidity, fromWeightDistributionToAmount, fromWeightDistributionToAmountOneSide, getBaseFee, getBinArrayLowerUpperBinId, getBinFromBinArray, getOrCreateATAInstruction, getOutAmount, getPriceOfBinByBinId, getTokenBalance, getTokenDecimals, getTokensMintFromPoolAddress, getTotalFee, getVariableFee, isBinIdWithinBinArray, isOverflowDefaultBinArrayBitmap, parseLogs, sParameters, swapExactInQuoteAtBin, swapExactOutQuoteAtBin, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountsBothSideByStrategy, toAmountsOneSideByStrategy, toStrategyParameters, toWeightDistribution, unwrapSOLInstruction, vParameters, wrapSOLInstruction };
|
|
6281
|
+
export { ADMIN, BASIS_POINT_MAX, BIN_ARRAY_BITMAP_SIZE, BIN_ARRAY_FEE, Bin, BinAndAmount, BinArray, BinArrayAccount, BinArrayBitmapExtension, BinArrayBitmapExtensionAccount, BinLiquidity, BinLiquidityDistribution, BinLiquidityReduction, BitmapType, ClmmProgram, CompressedBinDepositAmount, CompressedBinDepositAmounts, DLMMError, EXTENSION_BINARRAY_BITMAP_SIZE, EmissionRate, FEE_PRECISION, FeeInfo, GetOrCreateATAResponse, IAccountsCache, IDL, InitPermissionPairIx, LBCLMM_PROGRAM_IDS, LMRewards, LbClmm, LbPair, LbPairAccount, LbPosition, LiquidityOneSideParameter, LiquidityParameterByStrategy, LiquidityParameterByStrategyOneSide, LiquidityParameterByWeight, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BIN_ARRAY_SIZE, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, MAX_BIN_PER_POSITION, MAX_BIN_PER_TX, MAX_CLAIM_ALL_ALLOWED, MAX_FEE_RATE, Network, POSITION_FEE, PRECISION, PairType, Position, PositionBinData, PositionData, PositionInfo, PositionV2, PositionVersion, ProgramStrategyParameter, ProgramStrategyType, SCALE, SCALE_OFFSET, SIMULATION_USER, SeedLiquidityResponse, Strategy, StrategyParameters, StrategyType, SwapExactOutParams, SwapFee, SwapParams, SwapQuote, SwapQuoteExactOut, SwapWithPriceImpactParams, TInitializePositionAndAddLiquidityParams, TInitializePositionAndAddLiquidityParamsByStrategy, TQuoteCreatePositionParams, TokenReserve, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, binIdToBinArrayIndex, calculateBidAskDistribution, calculateNormalDistribution, calculateSpotDistribution, chunkedFetchMultipleBinArrayBitmapExtensionAccount, chunkedFetchMultiplePoolAccount, chunkedGetMultipleAccountInfos, chunks, computeBudgetIx, computeFee, computeFeeFromAmount, computeProtocolFee, DLMM as default, deriveBinArray, deriveBinArrayBitmapExtension, deriveLbPair, deriveLbPair2, deriveOracle, derivePermissionLbPair, derivePosition, derivePresetParameter, derivePresetParameter2, deriveReserve, findNextBinArrayIndexWithLiquidity, findNextBinArrayWithLiquidity, fromWeightDistributionToAmount, fromWeightDistributionToAmountOneSide, getBaseFee, getBinArrayLowerUpperBinId, getBinArraysRequiredByPositionRange, getBinFromBinArray, getOrCreateATAInstruction, getOutAmount, getPriceOfBinByBinId, getTokenBalance, getTokenDecimals, getTokensMintFromPoolAddress, getTotalFee, getVariableFee, isBinIdWithinBinArray, isOverflowDefaultBinArrayBitmap, parseLogs, sParameters, swapExactInQuoteAtBin, swapExactOutQuoteAtBin, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountsBothSideByStrategy, toAmountsOneSideByStrategy, toStrategyParameters, toWeightDistribution, unwrapSOLInstruction, vParameters, wrapSOLInstruction };
|
package/dist/index.js
CHANGED
|
@@ -6475,6 +6475,24 @@ function findNextBinArrayWithLiquidity(swapForY, activeBinId, lbPairState, binAr
|
|
|
6475
6475
|
}
|
|
6476
6476
|
return binArrayAccount;
|
|
6477
6477
|
}
|
|
6478
|
+
function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId) {
|
|
6479
|
+
const [minBinId, maxBinId] = fromBinId.lt(toBinId) ? [fromBinId, toBinId] : [toBinId, fromBinId];
|
|
6480
|
+
const positionCount = getPositionCount(minBinId, maxBinId);
|
|
6481
|
+
const binArrays = /* @__PURE__ */ new Map();
|
|
6482
|
+
for (let i = 0; i < positionCount.toNumber(); i++) {
|
|
6483
|
+
const lowerBinId = minBinId.add(MAX_BIN_PER_POSITION.mul(new (0, _anchor.BN)(i)));
|
|
6484
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
|
|
6485
|
+
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
6486
|
+
const [lowerBinArray] = deriveBinArray(pair, lowerBinArrayIndex, programId);
|
|
6487
|
+
const [upperBinArray] = deriveBinArray(pair, upperBinArrayIndex, programId);
|
|
6488
|
+
binArrays.set(lowerBinArray.toBase58(), lowerBinArrayIndex);
|
|
6489
|
+
binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
|
|
6490
|
+
}
|
|
6491
|
+
return Array.from(binArrays, ([key, index]) => ({
|
|
6492
|
+
key: new (0, _web3js.PublicKey)(key),
|
|
6493
|
+
index
|
|
6494
|
+
}));
|
|
6495
|
+
}
|
|
6478
6496
|
|
|
6479
6497
|
// src/dlmm/helpers/fee.ts
|
|
6480
6498
|
|
|
@@ -8485,6 +8503,17 @@ var DLMM = class {
|
|
|
8485
8503
|
);
|
|
8486
8504
|
return activeBinState;
|
|
8487
8505
|
}
|
|
8506
|
+
/**
|
|
8507
|
+
* The function get the price of a bin based on its bin ID.
|
|
8508
|
+
* @param {number} binId - The `binId` parameter is a number that represents the ID of a bin.
|
|
8509
|
+
* @returns {number} the calculated price of a bin based on the provided binId.
|
|
8510
|
+
*/
|
|
8511
|
+
getPriceOfBinByBinId(binId) {
|
|
8512
|
+
const binStepNum = new (0, _decimaljs2.default)(this.lbPair.binStep).div(
|
|
8513
|
+
new (0, _decimaljs2.default)(BASIS_POINT_MAX)
|
|
8514
|
+
);
|
|
8515
|
+
return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(binId)).toString();
|
|
8516
|
+
}
|
|
8488
8517
|
/**
|
|
8489
8518
|
* The function get bin ID based on a given price and a boolean flag indicating whether to
|
|
8490
8519
|
* round down or up.
|
|
@@ -9693,15 +9722,9 @@ var DLMM = class {
|
|
|
9693
9722
|
}
|
|
9694
9723
|
}
|
|
9695
9724
|
}
|
|
9696
|
-
const startPrice = getPriceOfBinByBinId(
|
|
9697
|
-
|
|
9698
|
-
|
|
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));
|
|
9725
|
+
const startPrice = this.getPriceOfBinByBinId(startBinId.toNumber());
|
|
9726
|
+
const endPrice = this.getPriceOfBinByBinId(activeId.toNumber());
|
|
9727
|
+
const priceImpact = new (0, _decimaljs2.default)(startPrice).sub(new (0, _decimaljs2.default)(endPrice)).abs().div(new (0, _decimaljs2.default)(startPrice)).mul(new (0, _decimaljs2.default)(100));
|
|
9705
9728
|
const maxInAmount = actualInAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).add(allowedSlippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
9706
9729
|
return {
|
|
9707
9730
|
inAmount: actualInAmount,
|
|
@@ -9719,6 +9742,8 @@ var DLMM = class {
|
|
|
9719
9742
|
* - `inAmount`: Amount of lamport to swap in
|
|
9720
9743
|
* - `swapForY`: Swap token X to Y when it is true, else reversed.
|
|
9721
9744
|
* - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
|
|
9745
|
+
* - `binArrays`: binArrays for swapQuote.
|
|
9746
|
+
* - `isPartialFill`: Flag to check whether the the swapQuote is partial fill, default = false.
|
|
9722
9747
|
* @returns {SwapQuote}
|
|
9723
9748
|
* - `consumedInAmount`: Amount of lamport to swap in
|
|
9724
9749
|
* - `outAmount`: Amount of lamport to swap out
|
|
@@ -9728,7 +9753,7 @@ var DLMM = class {
|
|
|
9728
9753
|
* - `priceImpact`: Price impact of the swap
|
|
9729
9754
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
9730
9755
|
*/
|
|
9731
|
-
swapQuote(inAmount, swapForY, allowedSlippage, binArrays) {
|
|
9756
|
+
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill) {
|
|
9732
9757
|
const currentTimestamp = Date.now() / 1e3;
|
|
9733
9758
|
let inAmountLeft = inAmount;
|
|
9734
9759
|
let vParameterClone = Object.assign({}, this.lbPair.vParameters);
|
|
@@ -9755,7 +9780,11 @@ var DLMM = class {
|
|
|
9755
9780
|
binArrays
|
|
9756
9781
|
);
|
|
9757
9782
|
if (binArrayAccountToSwap == null) {
|
|
9758
|
-
|
|
9783
|
+
if (isPartialFill) {
|
|
9784
|
+
break;
|
|
9785
|
+
} else {
|
|
9786
|
+
throw new Error("Insufficient liquidity");
|
|
9787
|
+
}
|
|
9759
9788
|
}
|
|
9760
9789
|
binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
|
|
9761
9790
|
this.updateVolatilityAccumulator(
|
|
@@ -9796,6 +9825,7 @@ var DLMM = class {
|
|
|
9796
9825
|
}
|
|
9797
9826
|
if (!startBin)
|
|
9798
9827
|
throw new Error("Invalid start bin");
|
|
9828
|
+
inAmount = inAmount.sub(inAmountLeft);
|
|
9799
9829
|
const outAmountWithoutSlippage = getOutAmount(
|
|
9800
9830
|
startBin,
|
|
9801
9831
|
inAmount.sub(
|
|
@@ -9805,10 +9835,6 @@ var DLMM = class {
|
|
|
9805
9835
|
);
|
|
9806
9836
|
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));
|
|
9807
9837
|
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
|
-
);
|
|
9812
9838
|
return {
|
|
9813
9839
|
consumedInAmount: inAmount,
|
|
9814
9840
|
outAmount: actualOutAmount,
|
|
@@ -9816,8 +9842,7 @@ var DLMM = class {
|
|
|
9816
9842
|
protocolFee: protocolFeeAmount,
|
|
9817
9843
|
minOutAmount,
|
|
9818
9844
|
priceImpact,
|
|
9819
|
-
binArraysPubkey: [...binArraysForSwap.keys()]
|
|
9820
|
-
endPrice
|
|
9845
|
+
binArraysPubkey: [...binArraysForSwap.keys()]
|
|
9821
9846
|
};
|
|
9822
9847
|
}
|
|
9823
9848
|
async swapExactOut({
|
|
@@ -10106,7 +10131,9 @@ var DLMM = class {
|
|
|
10106
10131
|
positions
|
|
10107
10132
|
}) {
|
|
10108
10133
|
const claimAllTxs = (await Promise.all(
|
|
10109
|
-
positions.
|
|
10134
|
+
positions.filter(
|
|
10135
|
+
({ positionData: { rewardOne, rewardTwo } }) => !rewardOne.isZero() || !rewardTwo.isZero()
|
|
10136
|
+
).map(async (position, idx) => {
|
|
10110
10137
|
return await this.createClaimBuildMethod({
|
|
10111
10138
|
owner,
|
|
10112
10139
|
position,
|
|
@@ -10190,12 +10217,14 @@ var DLMM = class {
|
|
|
10190
10217
|
positions
|
|
10191
10218
|
}) {
|
|
10192
10219
|
const claimAllTxs = (await Promise.all(
|
|
10193
|
-
positions.
|
|
10220
|
+
positions.filter(
|
|
10221
|
+
({ positionData: { feeX, feeY } }) => !feeX.isZero() || !feeY.isZero()
|
|
10222
|
+
).map(async (position, idx, positions2) => {
|
|
10194
10223
|
return await this.createClaimSwapFeeMethod({
|
|
10195
10224
|
owner,
|
|
10196
10225
|
position,
|
|
10197
10226
|
shouldIncludePretIx: idx === 0,
|
|
10198
|
-
shouldIncludePostIx: idx ===
|
|
10227
|
+
shouldIncludePostIx: idx === positions2.length - 1
|
|
10199
10228
|
});
|
|
10200
10229
|
})
|
|
10201
10230
|
)).flat();
|
|
@@ -10485,6 +10514,34 @@ var DLMM = class {
|
|
|
10485
10514
|
addLiquidityIxs
|
|
10486
10515
|
};
|
|
10487
10516
|
}
|
|
10517
|
+
/**
|
|
10518
|
+
* Initializes bin arrays for the given bin array indexes if it wasn't initialized.
|
|
10519
|
+
*
|
|
10520
|
+
* @param {BN[]} binArrayIndexes - An array of bin array indexes to initialize.
|
|
10521
|
+
* @param {PublicKey} funder - The public key of the funder.
|
|
10522
|
+
* @return {Promise<TransactionInstruction[]>} An array of transaction instructions to initialize the bin arrays.
|
|
10523
|
+
*/
|
|
10524
|
+
async initializeBinArrays(binArrayIndexes, funder) {
|
|
10525
|
+
const ixs = [];
|
|
10526
|
+
for (const idx of binArrayIndexes) {
|
|
10527
|
+
const [binArray] = deriveBinArray(
|
|
10528
|
+
this.pubkey,
|
|
10529
|
+
idx,
|
|
10530
|
+
this.program.programId
|
|
10531
|
+
);
|
|
10532
|
+
const binArrayAccount = await this.program.provider.connection.getAccountInfo(binArray);
|
|
10533
|
+
if (binArrayAccount === null) {
|
|
10534
|
+
ixs.push(
|
|
10535
|
+
await this.program.methods.initializeBinArray(idx).accounts({
|
|
10536
|
+
binArray,
|
|
10537
|
+
funder,
|
|
10538
|
+
lbPair: this.pubkey
|
|
10539
|
+
}).instruction()
|
|
10540
|
+
);
|
|
10541
|
+
}
|
|
10542
|
+
}
|
|
10543
|
+
return ixs;
|
|
10544
|
+
}
|
|
10488
10545
|
/**
|
|
10489
10546
|
*
|
|
10490
10547
|
* @param
|
|
@@ -10584,7 +10641,9 @@ var DLMM = class {
|
|
|
10584
10641
|
);
|
|
10585
10642
|
createATAAccAndIx.forEach(({ ix }) => ix && preInstructions.push(ix));
|
|
10586
10643
|
const claimAllSwapFeeTxs = (await Promise.all(
|
|
10587
|
-
positions.
|
|
10644
|
+
positions.filter(
|
|
10645
|
+
({ positionData: { feeX, feeY } }) => !feeX.isZero() || !feeY.isZero()
|
|
10646
|
+
).map(async (position) => {
|
|
10588
10647
|
return await this.createClaimSwapFeeMethod({
|
|
10589
10648
|
owner,
|
|
10590
10649
|
position,
|
|
@@ -10594,7 +10653,9 @@ var DLMM = class {
|
|
|
10594
10653
|
})
|
|
10595
10654
|
)).flat();
|
|
10596
10655
|
const claimAllLMTxs = (await Promise.all(
|
|
10597
|
-
positions.
|
|
10656
|
+
positions.filter(
|
|
10657
|
+
({ positionData: { rewardOne, rewardTwo } }) => !rewardOne.isZero() || !rewardTwo.isZero()
|
|
10658
|
+
).map(async (position) => {
|
|
10598
10659
|
return await this.createClaimBuildMethod({
|
|
10599
10660
|
owner,
|
|
10600
10661
|
position,
|
|
@@ -10988,10 +11049,10 @@ var DLMM = class {
|
|
|
10988
11049
|
binArray.bins.forEach((bin, idx) => {
|
|
10989
11050
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
10990
11051
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
10991
|
-
const pricePerLamport = getPriceOfBinByBinId(
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
)
|
|
11052
|
+
const pricePerLamport = this.getPriceOfBinByBinId(
|
|
11053
|
+
lbPair.binStep,
|
|
11054
|
+
binId
|
|
11055
|
+
);
|
|
10995
11056
|
bins.push({
|
|
10996
11057
|
binId,
|
|
10997
11058
|
xAmount: bin.amountX,
|
|
@@ -11012,10 +11073,10 @@ var DLMM = class {
|
|
|
11012
11073
|
binArray.bins.forEach((bin, idx) => {
|
|
11013
11074
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11014
11075
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11015
|
-
const pricePerLamport = getPriceOfBinByBinId(
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
)
|
|
11076
|
+
const pricePerLamport = this.getPriceOfBinByBinId(
|
|
11077
|
+
lbPair.binStep,
|
|
11078
|
+
binId
|
|
11079
|
+
);
|
|
11019
11080
|
bins.push({
|
|
11020
11081
|
binId,
|
|
11021
11082
|
xAmount: bin.amountX,
|
|
@@ -11031,6 +11092,10 @@ var DLMM = class {
|
|
|
11031
11092
|
}
|
|
11032
11093
|
return bins;
|
|
11033
11094
|
}
|
|
11095
|
+
static getPriceOfBinByBinId(binStep, binId) {
|
|
11096
|
+
const binStepNum = new (0, _decimaljs2.default)(binStep).div(new (0, _decimaljs2.default)(BASIS_POINT_MAX));
|
|
11097
|
+
return new (0, _decimaljs2.default)(1).add(new (0, _decimaljs2.default)(binStepNum)).pow(new (0, _decimaljs2.default)(binId)).toString();
|
|
11098
|
+
}
|
|
11034
11099
|
/** Private method */
|
|
11035
11100
|
processXYAmountDistribution(xYAmountDistribution) {
|
|
11036
11101
|
let currentBinId = null;
|
|
@@ -11069,6 +11134,8 @@ var DLMM = class {
|
|
|
11069
11134
|
const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
|
|
11070
11135
|
const binArrayBins = [];
|
|
11071
11136
|
for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
|
|
11137
|
+
const binId = new (0, _anchor.BN)(i);
|
|
11138
|
+
const pricePerLamport = this.getPriceOfBinByBinId(binId.toNumber());
|
|
11072
11139
|
binArrayBins.push({
|
|
11073
11140
|
amountX: new (0, _anchor.BN)(0),
|
|
11074
11141
|
amountY: new (0, _anchor.BN)(0),
|
|
@@ -11093,10 +11160,7 @@ var DLMM = class {
|
|
|
11093
11160
|
binArray.bins.forEach((bin, idx) => {
|
|
11094
11161
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11095
11162
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11096
|
-
const pricePerLamport = getPriceOfBinByBinId(
|
|
11097
|
-
binId,
|
|
11098
|
-
this.lbPair.binStep
|
|
11099
|
-
).toString();
|
|
11163
|
+
const pricePerLamport = this.getPriceOfBinByBinId(binId);
|
|
11100
11164
|
bins.push({
|
|
11101
11165
|
binId,
|
|
11102
11166
|
xAmount: bin.amountX,
|
|
@@ -11137,10 +11201,7 @@ var DLMM = class {
|
|
|
11137
11201
|
binArray.bins.forEach((bin, idx) => {
|
|
11138
11202
|
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11139
11203
|
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11140
|
-
const pricePerLamport = getPriceOfBinByBinId(
|
|
11141
|
-
binId,
|
|
11142
|
-
this.lbPair.binStep
|
|
11143
|
-
).toString();
|
|
11204
|
+
const pricePerLamport = this.getPriceOfBinByBinId(binId);
|
|
11144
11205
|
bins.push({
|
|
11145
11206
|
binId,
|
|
11146
11207
|
xAmount: bin.amountX,
|
|
@@ -11464,5 +11525,6 @@ var src_default = DLMM;
|
|
|
11464
11525
|
|
|
11465
11526
|
|
|
11466
11527
|
|
|
11467
|
-
|
|
11528
|
+
|
|
11529
|
+
exports.ADMIN = ADMIN; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BitmapType = BitmapType; exports.DLMMError = DLMMError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeBudgetIx = computeBudgetIx; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.deriveReserve = deriveReserve; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinFromBinArray = getBinFromBinArray; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toAmountsOneSideByStrategy = toAmountsOneSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
11468
11530
|
//# sourceMappingURL=index.js.map
|