@meteora-ag/dlmm 1.9.1 → 1.9.3
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 +64 -7
- package/dist/index.js +239 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -15649,6 +15649,71 @@ async function chunkedGetMultipleAccountInfos(connection, pks, chunkSize = 100)
|
|
|
15649
15649
|
)).flat();
|
|
15650
15650
|
return accountInfos;
|
|
15651
15651
|
}
|
|
15652
|
+
async function chunkedGetProgramAccounts(connection, programId, filters, chunkSize = 100, onChunkFetched, isParallelExecution = false) {
|
|
15653
|
+
const accountsWithoutData = await connection.getProgramAccounts(programId, {
|
|
15654
|
+
filters,
|
|
15655
|
+
dataSlice: { offset: 0, length: 0 }
|
|
15656
|
+
});
|
|
15657
|
+
if (accountsWithoutData.length === 0) {
|
|
15658
|
+
return [];
|
|
15659
|
+
}
|
|
15660
|
+
const pubkeys = accountsWithoutData.map((account) => account.pubkey);
|
|
15661
|
+
const totalAccounts = pubkeys.length;
|
|
15662
|
+
const chunkedPks = chunks(pubkeys, chunkSize);
|
|
15663
|
+
const totalChunks = chunkedPks.length;
|
|
15664
|
+
let chunksLoaded = 0;
|
|
15665
|
+
let accountsLoaded = 0;
|
|
15666
|
+
const chunkResults = new Array(totalChunks);
|
|
15667
|
+
const processChunk = async (chunk, chunkIndex) => {
|
|
15668
|
+
const chunkAccountInfos = await connection.getMultipleAccountsInfo(chunk);
|
|
15669
|
+
chunkResults[chunkIndex] = chunkAccountInfos;
|
|
15670
|
+
if (onChunkFetched) {
|
|
15671
|
+
const chunkAccounts = [];
|
|
15672
|
+
const startIdx = chunkIndex * chunkSize;
|
|
15673
|
+
for (let i = 0; i < chunkAccountInfos.length; i++) {
|
|
15674
|
+
const accountInfo = chunkAccountInfos[i];
|
|
15675
|
+
if (accountInfo) {
|
|
15676
|
+
chunkAccounts.push({
|
|
15677
|
+
pubkey: pubkeys[startIdx + i],
|
|
15678
|
+
account: accountInfo
|
|
15679
|
+
});
|
|
15680
|
+
}
|
|
15681
|
+
}
|
|
15682
|
+
chunksLoaded++;
|
|
15683
|
+
accountsLoaded += chunkAccounts.length;
|
|
15684
|
+
onChunkFetched(chunkAccounts, {
|
|
15685
|
+
chunksLoaded,
|
|
15686
|
+
totalChunks,
|
|
15687
|
+
accountsLoaded,
|
|
15688
|
+
totalAccounts
|
|
15689
|
+
});
|
|
15690
|
+
}
|
|
15691
|
+
};
|
|
15692
|
+
if (isParallelExecution) {
|
|
15693
|
+
await Promise.all(
|
|
15694
|
+
chunkedPks.map((chunk, chunkIndex) => processChunk(chunk, chunkIndex))
|
|
15695
|
+
);
|
|
15696
|
+
} else {
|
|
15697
|
+
for (let chunkIndex = 0; chunkIndex < chunkedPks.length; chunkIndex++) {
|
|
15698
|
+
await processChunk(chunkedPks[chunkIndex], chunkIndex);
|
|
15699
|
+
}
|
|
15700
|
+
}
|
|
15701
|
+
const result = [];
|
|
15702
|
+
for (let chunkIndex = 0; chunkIndex < chunkResults.length; chunkIndex++) {
|
|
15703
|
+
const chunkAccountInfos = chunkResults[chunkIndex];
|
|
15704
|
+
const startIdx = chunkIndex * chunkSize;
|
|
15705
|
+
for (let i = 0; i < chunkAccountInfos.length; i++) {
|
|
15706
|
+
const accountInfo = chunkAccountInfos[i];
|
|
15707
|
+
if (accountInfo) {
|
|
15708
|
+
result.push({
|
|
15709
|
+
pubkey: pubkeys[startIdx + i],
|
|
15710
|
+
account: accountInfo
|
|
15711
|
+
});
|
|
15712
|
+
}
|
|
15713
|
+
}
|
|
15714
|
+
}
|
|
15715
|
+
return result;
|
|
15716
|
+
}
|
|
15652
15717
|
var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, feePayer, buffer, altAddress) => {
|
|
15653
15718
|
if (!buffer) {
|
|
15654
15719
|
buffer = 0.1;
|
|
@@ -16669,17 +16734,20 @@ var DLMM = class {
|
|
|
16669
16734
|
* class, which represents the connection to the Solana blockchain.
|
|
16670
16735
|
* @param {PublicKey} userPubKey - The user's wallet public key.
|
|
16671
16736
|
* @param {Opt} [opt] - An optional object that contains additional options for the function.
|
|
16737
|
+
* @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
|
|
16672
16738
|
* @returns The function `getAllLbPairPositionsByUser` returns a `Promise` that resolves to a `Map`
|
|
16673
16739
|
* object. The `Map` object contains key-value pairs, where the key is a string representing the LB
|
|
16674
16740
|
* Pair account, and the value is an object of PositionInfo
|
|
16675
16741
|
*/
|
|
16676
|
-
static async getAllLbPairPositionsByUser(connection, userPubKey, opt) {
|
|
16742
|
+
static async getAllLbPairPositionsByUser(connection, userPubKey, opt, getPositionsOpt) {
|
|
16677
16743
|
const program = createProgram(connection, opt);
|
|
16678
|
-
const positionsV2 = await
|
|
16744
|
+
const positionsV2 = await chunkedGetProgramAccounts(
|
|
16745
|
+
program.provider.connection,
|
|
16679
16746
|
program.programId,
|
|
16680
|
-
|
|
16681
|
-
|
|
16682
|
-
|
|
16747
|
+
[positionV2Filter(), positionOwnerFilter(userPubKey)],
|
|
16748
|
+
getPositionsOpt?.chunkSize,
|
|
16749
|
+
getPositionsOpt?.onChunkFetched,
|
|
16750
|
+
getPositionsOpt?.isParallelExecution
|
|
16683
16751
|
);
|
|
16684
16752
|
const positionWrappers = [
|
|
16685
16753
|
...positionsV2.map((p) => wrapPosition(program, p.pubkey, p.account))
|
|
@@ -16873,16 +16941,19 @@ var DLMM = class {
|
|
|
16873
16941
|
* The function `getLbPairLockInfo` retrieves all pair positions that has locked liquidity.
|
|
16874
16942
|
* @param {number} [lockDurationOpt] - An optional value indicating the minimum position lock duration that the function should return.
|
|
16875
16943
|
* Depending on the lbPair activationType, the param should be a number of seconds or a number of slots.
|
|
16944
|
+
* @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
|
|
16876
16945
|
* @returns The function `getLbPairLockInfo` returns a `Promise` that resolves to a `PairLockInfo`
|
|
16877
16946
|
* object. The `PairLockInfo` object contains an array of `PositionLockInfo` objects.
|
|
16878
16947
|
*/
|
|
16879
|
-
async getLbPairLockInfo(lockDurationOpt) {
|
|
16948
|
+
async getLbPairLockInfo(lockDurationOpt, getPositionsOpt) {
|
|
16880
16949
|
const lockDuration = lockDurationOpt | 0;
|
|
16881
|
-
const positionAccounts = await
|
|
16950
|
+
const positionAccounts = await chunkedGetProgramAccounts(
|
|
16951
|
+
this.program.provider.connection,
|
|
16882
16952
|
this.program.programId,
|
|
16883
|
-
|
|
16884
|
-
|
|
16885
|
-
|
|
16953
|
+
[positionLbPairFilter(this.pubkey)],
|
|
16954
|
+
getPositionsOpt?.chunkSize,
|
|
16955
|
+
getPositionsOpt?.onChunkFetched,
|
|
16956
|
+
getPositionsOpt?.isParallelExecution
|
|
16886
16957
|
);
|
|
16887
16958
|
const lbPairPositions = positionAccounts.map((acc) => {
|
|
16888
16959
|
return wrapPosition(this.program, acc.pubkey, acc.account);
|
|
@@ -17017,18 +17088,59 @@ var DLMM = class {
|
|
|
17017
17088
|
baseFeePowerFactor: baseFeePowerFactor.toNumber(),
|
|
17018
17089
|
padding: Array(63).fill(0)
|
|
17019
17090
|
};
|
|
17091
|
+
const preInstructions = [];
|
|
17020
17092
|
const userTokenX = getAssociatedTokenAddressSync2(
|
|
17021
17093
|
tokenX,
|
|
17022
17094
|
creatorKey,
|
|
17023
17095
|
true,
|
|
17024
17096
|
tokenXAccount.owner
|
|
17025
17097
|
);
|
|
17098
|
+
const createUserTokenXIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
17099
|
+
creatorKey,
|
|
17100
|
+
userTokenX,
|
|
17101
|
+
creatorKey,
|
|
17102
|
+
tokenX,
|
|
17103
|
+
tokenXAccount.owner
|
|
17104
|
+
);
|
|
17105
|
+
preInstructions.push(createUserTokenXIx);
|
|
17026
17106
|
const userTokenY = getAssociatedTokenAddressSync2(
|
|
17027
17107
|
tokenY,
|
|
17028
17108
|
creatorKey,
|
|
17029
17109
|
true,
|
|
17030
17110
|
tokenYAccount.owner
|
|
17031
17111
|
);
|
|
17112
|
+
const createUserTokenYIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
17113
|
+
creatorKey,
|
|
17114
|
+
userTokenY,
|
|
17115
|
+
creatorKey,
|
|
17116
|
+
tokenY,
|
|
17117
|
+
tokenYAccount.owner
|
|
17118
|
+
);
|
|
17119
|
+
preInstructions.push(createUserTokenYIx);
|
|
17120
|
+
const postInstructions = [];
|
|
17121
|
+
if ((tokenX.equals(NATIVE_MINT2) || tokenY.equals(NATIVE_MINT2)) && !opt?.skipSolWrappingOperation) {
|
|
17122
|
+
const wrapAmount = BigInt(1);
|
|
17123
|
+
if (tokenX.equals(NATIVE_MINT2)) {
|
|
17124
|
+
const wrapSOLIxX = wrapSOLInstruction(
|
|
17125
|
+
creatorKey,
|
|
17126
|
+
userTokenX,
|
|
17127
|
+
wrapAmount
|
|
17128
|
+
);
|
|
17129
|
+
preInstructions.push(...wrapSOLIxX);
|
|
17130
|
+
}
|
|
17131
|
+
if (tokenY.equals(NATIVE_MINT2)) {
|
|
17132
|
+
const wrapSOLIxY = wrapSOLInstruction(
|
|
17133
|
+
creatorKey,
|
|
17134
|
+
userTokenY,
|
|
17135
|
+
wrapAmount
|
|
17136
|
+
);
|
|
17137
|
+
preInstructions.push(...wrapSOLIxY);
|
|
17138
|
+
}
|
|
17139
|
+
const unwrapSOLIx = await unwrapSOLInstruction(creatorKey);
|
|
17140
|
+
if (unwrapSOLIx) {
|
|
17141
|
+
postInstructions.push(unwrapSOLIx);
|
|
17142
|
+
}
|
|
17143
|
+
}
|
|
17032
17144
|
return program.methods.initializeCustomizablePermissionlessLbPair2(ixData).accountsPartial({
|
|
17033
17145
|
tokenBadgeX: tokenBadgeXAccount ? tokenBadgeX : program.programId,
|
|
17034
17146
|
tokenBadgeY: tokenBadgeYAccount ? tokenBadgeY : program.programId,
|
|
@@ -17045,7 +17157,7 @@ var DLMM = class {
|
|
|
17045
17157
|
funder: creatorKey,
|
|
17046
17158
|
tokenProgramX: tokenXAccount.owner,
|
|
17047
17159
|
tokenProgramY: tokenYAccount.owner
|
|
17048
|
-
}).transaction();
|
|
17160
|
+
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
17049
17161
|
}
|
|
17050
17162
|
/**
|
|
17051
17163
|
* Create a new customizable permissionless pair. Support only token program.
|
|
@@ -17069,6 +17181,7 @@ var DLMM = class {
|
|
|
17069
17181
|
tokenY,
|
|
17070
17182
|
program.programId
|
|
17071
17183
|
);
|
|
17184
|
+
const [tokenXAccount, tokenYAccount] = await connection.getMultipleAccountsInfo([tokenX, tokenY]);
|
|
17072
17185
|
const [reserveX] = deriveReserve(tokenX, lbPair, program.programId);
|
|
17073
17186
|
const [reserveY] = deriveReserve(tokenY, lbPair, program.programId);
|
|
17074
17187
|
const [oracle] = deriveOracle(lbPair, program.programId);
|
|
@@ -17095,8 +17208,59 @@ var DLMM = class {
|
|
|
17095
17208
|
creatorPoolOnOffControl: creatorPoolOnOffControl ? creatorPoolOnOffControl : false,
|
|
17096
17209
|
padding: Array(63).fill(0)
|
|
17097
17210
|
};
|
|
17098
|
-
const
|
|
17099
|
-
const
|
|
17211
|
+
const preInstructions = [];
|
|
17212
|
+
const userTokenX = getAssociatedTokenAddressSync2(
|
|
17213
|
+
tokenX,
|
|
17214
|
+
creatorKey,
|
|
17215
|
+
true,
|
|
17216
|
+
tokenXAccount.owner
|
|
17217
|
+
);
|
|
17218
|
+
const createUserTokenXIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
17219
|
+
creatorKey,
|
|
17220
|
+
userTokenX,
|
|
17221
|
+
creatorKey,
|
|
17222
|
+
tokenX,
|
|
17223
|
+
tokenXAccount.owner
|
|
17224
|
+
);
|
|
17225
|
+
preInstructions.push(createUserTokenXIx);
|
|
17226
|
+
const userTokenY = getAssociatedTokenAddressSync2(
|
|
17227
|
+
tokenY,
|
|
17228
|
+
creatorKey,
|
|
17229
|
+
true,
|
|
17230
|
+
tokenYAccount.owner
|
|
17231
|
+
);
|
|
17232
|
+
const createUserTokenYIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
17233
|
+
creatorKey,
|
|
17234
|
+
userTokenY,
|
|
17235
|
+
creatorKey,
|
|
17236
|
+
tokenY,
|
|
17237
|
+
tokenYAccount.owner
|
|
17238
|
+
);
|
|
17239
|
+
preInstructions.push(createUserTokenYIx);
|
|
17240
|
+
const postInstructions = [];
|
|
17241
|
+
if ((tokenX.equals(NATIVE_MINT2) || tokenY.equals(NATIVE_MINT2)) && !opt?.skipSolWrappingOperation) {
|
|
17242
|
+
const wrapAmount = BigInt(1);
|
|
17243
|
+
if (tokenX.equals(NATIVE_MINT2)) {
|
|
17244
|
+
const wrapSOLIxX = wrapSOLInstruction(
|
|
17245
|
+
creatorKey,
|
|
17246
|
+
userTokenX,
|
|
17247
|
+
wrapAmount
|
|
17248
|
+
);
|
|
17249
|
+
preInstructions.push(...wrapSOLIxX);
|
|
17250
|
+
}
|
|
17251
|
+
if (tokenY.equals(NATIVE_MINT2)) {
|
|
17252
|
+
const wrapSOLIxY = wrapSOLInstruction(
|
|
17253
|
+
creatorKey,
|
|
17254
|
+
userTokenY,
|
|
17255
|
+
wrapAmount
|
|
17256
|
+
);
|
|
17257
|
+
preInstructions.push(...wrapSOLIxY);
|
|
17258
|
+
}
|
|
17259
|
+
const unwrapSOLIx = await unwrapSOLInstruction(creatorKey);
|
|
17260
|
+
if (unwrapSOLIx) {
|
|
17261
|
+
postInstructions.push(unwrapSOLIx);
|
|
17262
|
+
}
|
|
17263
|
+
}
|
|
17100
17264
|
return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accountsPartial({
|
|
17101
17265
|
lbPair,
|
|
17102
17266
|
reserveX,
|
|
@@ -17109,7 +17273,7 @@ var DLMM = class {
|
|
|
17109
17273
|
userTokenX,
|
|
17110
17274
|
userTokenY,
|
|
17111
17275
|
funder: creatorKey
|
|
17112
|
-
}).transaction();
|
|
17276
|
+
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
17113
17277
|
}
|
|
17114
17278
|
/**
|
|
17115
17279
|
* Create a new liquidity pair. Support only token program.
|
|
@@ -17683,24 +17847,27 @@ var DLMM = class {
|
|
|
17683
17847
|
* `PublicKey`. It represents the public key of a user. If no `userPubKey` is provided, the function
|
|
17684
17848
|
* will return an object with an empty `userPositions` array and the active bin information obtained
|
|
17685
17849
|
* from the `getActive
|
|
17850
|
+
* @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
|
|
17686
17851
|
* @returns The function `getPositionsByUserAndLbPair` returns a Promise that resolves to an object
|
|
17687
17852
|
* with two properties:
|
|
17688
17853
|
* - "activeBin" which is an object with two properties: "binId" and "price". The value of "binId"
|
|
17689
17854
|
* is the active bin ID of the lbPair, and the value of "price" is the price of the active bin.
|
|
17690
17855
|
* - "userPositions" which is an array of Position objects.
|
|
17691
17856
|
*/
|
|
17692
|
-
async getPositionsByUserAndLbPair(userPubKey) {
|
|
17857
|
+
async getPositionsByUserAndLbPair(userPubKey, getPositionsOpt) {
|
|
17693
17858
|
const promiseResults = await Promise.all([
|
|
17694
17859
|
this.getActiveBin(),
|
|
17695
|
-
userPubKey &&
|
|
17860
|
+
userPubKey && chunkedGetProgramAccounts(
|
|
17861
|
+
this.program.provider.connection,
|
|
17696
17862
|
this.program.programId,
|
|
17697
|
-
|
|
17698
|
-
|
|
17699
|
-
|
|
17700
|
-
|
|
17701
|
-
|
|
17702
|
-
|
|
17703
|
-
|
|
17863
|
+
[
|
|
17864
|
+
positionV2Filter(),
|
|
17865
|
+
positionOwnerFilter(userPubKey),
|
|
17866
|
+
positionLbPairFilter(this.pubkey)
|
|
17867
|
+
],
|
|
17868
|
+
getPositionsOpt?.chunkSize,
|
|
17869
|
+
getPositionsOpt?.onChunkFetched,
|
|
17870
|
+
getPositionsOpt?.isParallelExecution
|
|
17704
17871
|
)
|
|
17705
17872
|
]);
|
|
17706
17873
|
const [activeBin, positionsV2] = promiseResults;
|
|
@@ -22207,6 +22374,7 @@ export {
|
|
|
22207
22374
|
chunkedFetchMultipleBinArrayBitmapExtensionAccount,
|
|
22208
22375
|
chunkedFetchMultiplePoolAccount,
|
|
22209
22376
|
chunkedGetMultipleAccountInfos,
|
|
22377
|
+
chunkedGetProgramAccounts,
|
|
22210
22378
|
chunks,
|
|
22211
22379
|
computeFee,
|
|
22212
22380
|
computeFeeFromAmount,
|