@meteora-ag/dlmm 1.5.1-test.1 → 1.5.1
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 +32 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8530,6 +8530,24 @@ function getPositionCount(minBinId, maxBinId) {
|
|
|
8530
8530
|
const positionCount = binDelta.div(MAX_BIN_PER_POSITION);
|
|
8531
8531
|
return positionCount.add(new (0, _anchor.BN)(1));
|
|
8532
8532
|
}
|
|
8533
|
+
function findOptimumDecompressMultiplier(binAmount, tokenDecimal) {
|
|
8534
|
+
let multiplier = new (0, _anchor.BN)(10).pow(tokenDecimal);
|
|
8535
|
+
while (!multiplier.isZero()) {
|
|
8536
|
+
let found = true;
|
|
8537
|
+
for (const [_binId, amount] of binAmount) {
|
|
8538
|
+
const compressedAmount = amount.div(multiplier);
|
|
8539
|
+
if (compressedAmount.isZero()) {
|
|
8540
|
+
multiplier = multiplier.div(new (0, _anchor.BN)(10));
|
|
8541
|
+
found = false;
|
|
8542
|
+
break;
|
|
8543
|
+
}
|
|
8544
|
+
}
|
|
8545
|
+
if (found) {
|
|
8546
|
+
return multiplier;
|
|
8547
|
+
}
|
|
8548
|
+
}
|
|
8549
|
+
throw "Couldn't find optimum multiplier";
|
|
8550
|
+
}
|
|
8533
8551
|
function compressBinAmount(binAmount, multiplier) {
|
|
8534
8552
|
const compressedBinAmount = /* @__PURE__ */ new Map();
|
|
8535
8553
|
let totalAmount = new (0, _anchor.BN)(0);
|
|
@@ -8566,6 +8584,9 @@ function generateAmountForBinRange(amount, binStep, tokenXDecimal, tokenYDecimal
|
|
|
8566
8584
|
maxPrice,
|
|
8567
8585
|
k
|
|
8568
8586
|
);
|
|
8587
|
+
if (binAmount.isZero()) {
|
|
8588
|
+
throw "bin amount is zero";
|
|
8589
|
+
}
|
|
8569
8590
|
binAmounts.set(i, binAmount);
|
|
8570
8591
|
}
|
|
8571
8592
|
return binAmounts;
|
|
@@ -10359,10 +10380,11 @@ var DLMM = class {
|
|
|
10359
10380
|
*/
|
|
10360
10381
|
static async create(connection, dlmm, opt) {
|
|
10361
10382
|
const cluster = _optionalChain([opt, 'optionalAccess', _38 => _38.cluster]) || "mainnet-beta";
|
|
10362
|
-
const provider = new (0, _anchor.AnchorProvider)(
|
|
10363
|
-
|
|
10364
|
-
|
|
10365
|
-
|
|
10383
|
+
const provider = new (0, _anchor.AnchorProvider)(
|
|
10384
|
+
connection,
|
|
10385
|
+
{},
|
|
10386
|
+
_anchor.AnchorProvider.defaultOptions()
|
|
10387
|
+
);
|
|
10366
10388
|
const program = new (0, _anchor.Program)(
|
|
10367
10389
|
IDL,
|
|
10368
10390
|
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _39 => _39.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
@@ -12992,16 +13014,11 @@ var DLMM = class {
|
|
|
12992
13014
|
owner,
|
|
12993
13015
|
position
|
|
12994
13016
|
}) {
|
|
12995
|
-
const preInstructions = [];
|
|
12996
|
-
if (!position.positionData.feeX.isZero() || !position.positionData.feeY.isZero()) {
|
|
12997
|
-
const claimIx = await this.createClaimSwapFeeMethod({ owner, position });
|
|
12998
|
-
preInstructions.push(...claimIx.instructions);
|
|
12999
|
-
}
|
|
13000
13017
|
const closePositionIx = await this.program.methods.closePosition2().accounts({
|
|
13001
13018
|
rentReceiver: owner,
|
|
13002
13019
|
position: position.publicKey,
|
|
13003
13020
|
sender: owner
|
|
13004
|
-
}).
|
|
13021
|
+
}).instruction();
|
|
13005
13022
|
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
13006
13023
|
this.program.provider.connection,
|
|
13007
13024
|
[closePositionIx],
|
|
@@ -13923,7 +13940,10 @@ var DLMM = class {
|
|
|
13923
13940
|
maxBinId,
|
|
13924
13941
|
k
|
|
13925
13942
|
);
|
|
13926
|
-
const decompressMultiplier =
|
|
13943
|
+
const decompressMultiplier = findOptimumDecompressMultiplier(
|
|
13944
|
+
binDepositAmount,
|
|
13945
|
+
new (0, _anchor.BN)(this.tokenX.mint.decimals)
|
|
13946
|
+
);
|
|
13927
13947
|
let { compressedBinAmount, compressionLoss } = compressBinAmount(
|
|
13928
13948
|
binDepositAmount,
|
|
13929
13949
|
decompressMultiplier
|
|
@@ -14086,7 +14106,7 @@ var DLMM = class {
|
|
|
14086
14106
|
}).instruction()
|
|
14087
14107
|
);
|
|
14088
14108
|
}
|
|
14089
|
-
if (instructions.length >
|
|
14109
|
+
if (instructions.length > 0) {
|
|
14090
14110
|
initializeBinArraysAndPositionIxs.push(instructions);
|
|
14091
14111
|
instructions = [];
|
|
14092
14112
|
}
|