@meteora-ag/dlmm 1.6.0-rc.0 → 1.6.0-rc.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.d.ts +10 -40
- package/dist/index.js +28 -155
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -155
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
} from "@solana/spl-token";
|
|
13
13
|
import {
|
|
14
14
|
ComputeBudgetProgram as ComputeBudgetProgram3,
|
|
15
|
-
Keypair as Keypair2,
|
|
16
15
|
LAMPORTS_PER_SOL as LAMPORTS_PER_SOL2,
|
|
17
16
|
PublicKey as PublicKey10,
|
|
18
17
|
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY2,
|
|
@@ -12180,20 +12179,6 @@ function isPositionNoFee(position) {
|
|
|
12180
12179
|
function isPositionNoReward(position) {
|
|
12181
12180
|
return position.rewardOne.isZero() && position.rewardTwo.isZero();
|
|
12182
12181
|
}
|
|
12183
|
-
function chunkBinRangeIntoExtendedPositions(minBinId, maxBinId) {
|
|
12184
|
-
const chunkedBinRange = [];
|
|
12185
|
-
for (let currentMinBinId = minBinId; currentMinBinId <= maxBinId; currentMinBinId += POSITION_MAX_LENGTH.toNumber()) {
|
|
12186
|
-
const currentMaxBinId = Math.min(
|
|
12187
|
-
currentMinBinId + POSITION_MAX_LENGTH.toNumber() - 1,
|
|
12188
|
-
maxBinId
|
|
12189
|
-
);
|
|
12190
|
-
chunkedBinRange.push({
|
|
12191
|
-
lowerBinId: currentMinBinId,
|
|
12192
|
-
upperBinId: currentMaxBinId
|
|
12193
|
-
});
|
|
12194
|
-
}
|
|
12195
|
-
return chunkedBinRange;
|
|
12196
|
-
}
|
|
12197
12182
|
function chunkBinRange(minBinId, maxBinId) {
|
|
12198
12183
|
const chunkedBinRange = [];
|
|
12199
12184
|
let startBinId = minBinId;
|
|
@@ -15134,68 +15119,6 @@ var DLMM = class {
|
|
|
15134
15119
|
positionCost
|
|
15135
15120
|
};
|
|
15136
15121
|
}
|
|
15137
|
-
/**
|
|
15138
|
-
* Estimates the cost to create a new position based on the given strategy.
|
|
15139
|
-
*
|
|
15140
|
-
* This function calculates the costs associated with creating bin arrays, positions
|
|
15141
|
-
* and extending positions for a specified range of bins.
|
|
15142
|
-
*
|
|
15143
|
-
* @param {TQuoteCreatePositionParams} param0 - The settings of the requested new position,
|
|
15144
|
-
* including the strategy with minimum and maximum bin IDs.
|
|
15145
|
-
* @returns An object containing:
|
|
15146
|
-
* - binArraysCount: The number of bin arrays required.
|
|
15147
|
-
* - binArrayCost: The estimated cost for creating bin arrays.
|
|
15148
|
-
* - positionCount: The number of positions required.
|
|
15149
|
-
* - positionCost: The fee cost for creating positions.
|
|
15150
|
-
* - positionExtendCost: The rent cost in lamports for extending positions.
|
|
15151
|
-
*/
|
|
15152
|
-
async quoteCreateMultiplePositions({
|
|
15153
|
-
strategy
|
|
15154
|
-
}) {
|
|
15155
|
-
const { minBinId, maxBinId } = strategy;
|
|
15156
|
-
const minBinIdBN = new BN21(minBinId);
|
|
15157
|
-
const maxBinIdBN = new BN21(maxBinId);
|
|
15158
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(minBinIdBN);
|
|
15159
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(maxBinIdBN);
|
|
15160
|
-
const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
|
|
15161
|
-
const binArrayCost = new Decimal7(binArraysCount).mul(
|
|
15162
|
-
new Decimal7(BIN_ARRAY_FEE)
|
|
15163
|
-
);
|
|
15164
|
-
let positionCost = new Decimal7(0);
|
|
15165
|
-
let positionExtendCost = new Decimal7(0);
|
|
15166
|
-
const chunkedPositionBinRange = chunkBinRangeIntoExtendedPositions(
|
|
15167
|
-
minBinId,
|
|
15168
|
-
maxBinId
|
|
15169
|
-
);
|
|
15170
|
-
const positionCount = chunkedPositionBinRange.length;
|
|
15171
|
-
for (const { lowerBinId, upperBinId } of chunkedPositionBinRange) {
|
|
15172
|
-
positionCost = positionCost.add(new Decimal7(POSITION_FEE));
|
|
15173
|
-
const lowerBinIdBN = new BN21(lowerBinId);
|
|
15174
|
-
const upperBinIdBN = new BN21(upperBinId);
|
|
15175
|
-
const extendedBinCount = getExtendedPositionBinCount(
|
|
15176
|
-
lowerBinIdBN,
|
|
15177
|
-
upperBinIdBN
|
|
15178
|
-
);
|
|
15179
|
-
const upperBinIdBeforeExtend = upperBinIdBN.sub(extendedBinCount);
|
|
15180
|
-
positionExtendCost = positionExtendCost.add(
|
|
15181
|
-
await getPositionExpandRentExemption(
|
|
15182
|
-
lowerBinIdBN,
|
|
15183
|
-
upperBinIdBeforeExtend,
|
|
15184
|
-
this.program.provider.connection,
|
|
15185
|
-
extendedBinCount
|
|
15186
|
-
).then(
|
|
15187
|
-
(lamports) => new Decimal7(lamports).div(new Decimal7(LAMPORTS_PER_SOL2))
|
|
15188
|
-
)
|
|
15189
|
-
);
|
|
15190
|
-
}
|
|
15191
|
-
return {
|
|
15192
|
-
binArraysCount,
|
|
15193
|
-
binArrayCost,
|
|
15194
|
-
positionCount,
|
|
15195
|
-
positionCost,
|
|
15196
|
-
positionExtendCost
|
|
15197
|
-
};
|
|
15198
|
-
}
|
|
15199
15122
|
/**
|
|
15200
15123
|
* Creates an empty position and initializes the corresponding bin arrays if needed.
|
|
15201
15124
|
* @param param0 The settings of the requested new position.
|
|
@@ -15234,84 +15157,6 @@ var DLMM = class {
|
|
|
15234
15157
|
feePayer: user
|
|
15235
15158
|
}).add(setCUIx, ...instructions);
|
|
15236
15159
|
}
|
|
15237
|
-
/**
|
|
15238
|
-
* Creates multiple empty positions for a user in specified bin ranges with necessary bin arrays.
|
|
15239
|
-
*
|
|
15240
|
-
* @param {number} minBinId - The minimum bin ID for the positions.
|
|
15241
|
-
* @param {number} maxBinId - The maximum bin ID for the positions.
|
|
15242
|
-
* @param {PublicKey} user - The public key of the user for whom the positions are created.
|
|
15243
|
-
*
|
|
15244
|
-
* @returns An object containing arrays of transactions for initializing positions, extending positions and initialzing bin arrays.
|
|
15245
|
-
*/
|
|
15246
|
-
async createMultipleEmptyPositions({
|
|
15247
|
-
minBinId,
|
|
15248
|
-
maxBinId,
|
|
15249
|
-
user
|
|
15250
|
-
}) {
|
|
15251
|
-
const chunkedBinRange = chunkBinRangeIntoExtendedPositions(
|
|
15252
|
-
minBinId,
|
|
15253
|
-
maxBinId
|
|
15254
|
-
);
|
|
15255
|
-
const positionCount = chunkedBinRange.length;
|
|
15256
|
-
const positionKeypairs = [];
|
|
15257
|
-
const initPositionIxs = [];
|
|
15258
|
-
const initBinArrayIxs = [];
|
|
15259
|
-
const binArrayIndexSet = /* @__PURE__ */ new Set();
|
|
15260
|
-
for (let i = 0; i < positionCount; i++) {
|
|
15261
|
-
const positionKeypair = Keypair2.generate();
|
|
15262
|
-
positionKeypairs.push(positionKeypair);
|
|
15263
|
-
const { lowerBinId, upperBinId } = chunkedBinRange[i];
|
|
15264
|
-
let width = upperBinId - lowerBinId + 1;
|
|
15265
|
-
width = Math.min(width, DEFAULT_BIN_PER_POSITION.toNumber());
|
|
15266
|
-
const initPositionIx = await this.createInitAndExtendPositionIx(
|
|
15267
|
-
lowerBinId,
|
|
15268
|
-
upperBinId,
|
|
15269
|
-
width,
|
|
15270
|
-
user,
|
|
15271
|
-
positionKeypair.publicKey
|
|
15272
|
-
);
|
|
15273
|
-
initPositionIxs.push(initPositionIx);
|
|
15274
|
-
const binArrayIndexes = getBinArrayIndexesCoverage(
|
|
15275
|
-
new BN21(lowerBinId),
|
|
15276
|
-
new BN21(upperBinId)
|
|
15277
|
-
).filter((idx) => !binArrayIndexSet.has(idx.toNumber()));
|
|
15278
|
-
const createBinArrayIxs = await this.createBinArraysIfNeeded(
|
|
15279
|
-
binArrayIndexes,
|
|
15280
|
-
user
|
|
15281
|
-
).then(
|
|
15282
|
-
(ixs) => ixs.map((ix) => [
|
|
15283
|
-
ComputeBudgetProgram3.setComputeUnitLimit({
|
|
15284
|
-
units: DEFAULT_INIT_BIN_ARRAY_CU
|
|
15285
|
-
}),
|
|
15286
|
-
ix
|
|
15287
|
-
])
|
|
15288
|
-
);
|
|
15289
|
-
binArrayIndexes.map((idx) => {
|
|
15290
|
-
binArrayIndexSet.add(idx.toNumber());
|
|
15291
|
-
});
|
|
15292
|
-
initBinArrayIxs.push(...createBinArrayIxs);
|
|
15293
|
-
}
|
|
15294
|
-
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
15295
|
-
const initPositionTxs = initPositionIxs.map((ix) => {
|
|
15296
|
-
return new Transaction({
|
|
15297
|
-
blockhash,
|
|
15298
|
-
lastValidBlockHeight,
|
|
15299
|
-
feePayer: user
|
|
15300
|
-
}).add(...ix);
|
|
15301
|
-
});
|
|
15302
|
-
const initBinArrayTxs = initBinArrayIxs.map((ix) => {
|
|
15303
|
-
return new Transaction({
|
|
15304
|
-
blockhash,
|
|
15305
|
-
lastValidBlockHeight,
|
|
15306
|
-
feePayer: user
|
|
15307
|
-
}).add(...ix);
|
|
15308
|
-
});
|
|
15309
|
-
return {
|
|
15310
|
-
positionKeypairs,
|
|
15311
|
-
initPositionTxs,
|
|
15312
|
-
initBinArrayTxs
|
|
15313
|
-
};
|
|
15314
|
-
}
|
|
15315
15160
|
/**
|
|
15316
15161
|
* The function `getPosition` retrieves position information for a given public key and processes it
|
|
15317
15162
|
* using various data to return a `LbPosition` object.
|
|
@@ -18602,6 +18447,34 @@ var DLMM = class {
|
|
|
18602
18447
|
rebalancePositionInstruction
|
|
18603
18448
|
};
|
|
18604
18449
|
}
|
|
18450
|
+
/**
|
|
18451
|
+
* Create an extended empty position.
|
|
18452
|
+
*
|
|
18453
|
+
* @param lowerBinid The lowest bin of the position.
|
|
18454
|
+
* @param upperBinId The highest bin of the position.
|
|
18455
|
+
* @param position The public key of the position.
|
|
18456
|
+
* @param owner The owner of the position.
|
|
18457
|
+
* @returns The instructions to create the extended empty position.
|
|
18458
|
+
*/
|
|
18459
|
+
async createExtendedEmptyPosition(lowerBinid, upperBinId, position, owner) {
|
|
18460
|
+
const positionWidth = upperBinId - lowerBinid + 1;
|
|
18461
|
+
const basePositionWidth = Math.min(
|
|
18462
|
+
positionWidth,
|
|
18463
|
+
DEFAULT_BIN_PER_POSITION.toNumber()
|
|
18464
|
+
);
|
|
18465
|
+
const ixs = await this.createInitAndExtendPositionIx(
|
|
18466
|
+
lowerBinid,
|
|
18467
|
+
upperBinId,
|
|
18468
|
+
basePositionWidth,
|
|
18469
|
+
owner,
|
|
18470
|
+
position
|
|
18471
|
+
);
|
|
18472
|
+
const latestBlockhashInfo = await this.program.provider.connection.getLatestBlockhash();
|
|
18473
|
+
const tx = new Transaction({
|
|
18474
|
+
...latestBlockhashInfo
|
|
18475
|
+
}).add(...ixs);
|
|
18476
|
+
return tx;
|
|
18477
|
+
}
|
|
18605
18478
|
async createInitAndExtendPositionIx(lowerBinId, upperBinId, basePositionWidth, user, position) {
|
|
18606
18479
|
const createPositionIx = await this.program.methods.initializePosition(lowerBinId, basePositionWidth).accountsPartial({
|
|
18607
18480
|
payer: user,
|