@meteora-ag/dlmm 1.0.0 → 1.0.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/README.md +15 -9
- package/dist/index.d.ts +9 -0
- package/dist/index.js +58 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6152,6 +6152,63 @@ var DLMM = class {
|
|
|
6152
6152
|
}
|
|
6153
6153
|
]);
|
|
6154
6154
|
}
|
|
6155
|
+
/**
|
|
6156
|
+
* The function `getBinArrayAroundActiveBin` retrieves a specified number of `BinArrayAccount`
|
|
6157
|
+
* objects from the blockchain, based on the active bin and its surrounding bin arrays.
|
|
6158
|
+
* @param
|
|
6159
|
+
* swapForY - The `swapForY` parameter is a boolean value that indicates whether the swap is using quote token as input.
|
|
6160
|
+
* [count=4] - The `count` parameter is the number of bin arrays to retrieve on left and right respectively. By default, it is set to 4.
|
|
6161
|
+
* @returns an array of `BinArrayAccount` objects.
|
|
6162
|
+
*/
|
|
6163
|
+
async getBinArrayForSwap(swapForY, count = 4) {
|
|
6164
|
+
await this.refetchStates();
|
|
6165
|
+
const binArraysPubkey = /* @__PURE__ */ new Set();
|
|
6166
|
+
let shouldStop = false;
|
|
6167
|
+
let activeIdToLoop = this.lbPair.activeId;
|
|
6168
|
+
while (!shouldStop) {
|
|
6169
|
+
const binArrayIndex = findNextBinArrayIndexWithLiquidity(
|
|
6170
|
+
swapForY,
|
|
6171
|
+
new BN6(activeIdToLoop),
|
|
6172
|
+
this.lbPair,
|
|
6173
|
+
this.binArrayBitmapExtension?.account ?? null
|
|
6174
|
+
);
|
|
6175
|
+
if (binArrayIndex === null)
|
|
6176
|
+
shouldStop = true;
|
|
6177
|
+
else {
|
|
6178
|
+
const [binArrayPubKey] = deriveBinArray(
|
|
6179
|
+
this.pubkey,
|
|
6180
|
+
binArrayIndex,
|
|
6181
|
+
this.program.programId
|
|
6182
|
+
);
|
|
6183
|
+
binArraysPubkey.add(binArrayPubKey.toBase58());
|
|
6184
|
+
const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayIndex);
|
|
6185
|
+
activeIdToLoop = swapForY ? lowerBinId.toNumber() - 1 : upperBinId.toNumber() + 1;
|
|
6186
|
+
}
|
|
6187
|
+
if (binArraysPubkey.size === count)
|
|
6188
|
+
shouldStop = true;
|
|
6189
|
+
}
|
|
6190
|
+
const accountsToFetch = Array.from(binArraysPubkey).map(
|
|
6191
|
+
(pubkey) => new PublicKey5(pubkey)
|
|
6192
|
+
);
|
|
6193
|
+
const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
|
|
6194
|
+
this.program.provider.connection,
|
|
6195
|
+
accountsToFetch
|
|
6196
|
+
);
|
|
6197
|
+
const binArrays = await Promise.all(
|
|
6198
|
+
binArraysAccInfoBuffer.map(async (accInfo, idx) => {
|
|
6199
|
+
const account = this.program.coder.accounts.decode(
|
|
6200
|
+
"binArray",
|
|
6201
|
+
accInfo.data
|
|
6202
|
+
);
|
|
6203
|
+
const publicKey = accountsToFetch[idx];
|
|
6204
|
+
return {
|
|
6205
|
+
account,
|
|
6206
|
+
publicKey
|
|
6207
|
+
};
|
|
6208
|
+
})
|
|
6209
|
+
);
|
|
6210
|
+
return binArrays;
|
|
6211
|
+
}
|
|
6155
6212
|
/**
|
|
6156
6213
|
* The function `getFeeInfo` calculates and returns the base fee rate percentage, maximum fee rate
|
|
6157
6214
|
* percentage, and protocol fee percentage.
|