Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/getBins doesnt work correctly if more than 2 bin arrays #116

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## @meteora-ag/dlmm [1.2.4] - PR #116

### Fixed

- Fixed `getBins` incorrect bin array index to fetch

## @meteora-ag/dlmm [1.2.3] - PR #112

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion ts-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteora-ag/dlmm",
"version": "1.2.3",
"version": "1.2.4",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
34 changes: 15 additions & 19 deletions ts-client/src/dlmm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2413,9 +2413,13 @@ export class DLMM {
const strategyParameters: LiquidityParameterByStrategy["strategyParameters"] =
toStrategyParameters(strategy) as ProgramStrategyParameter;

const positionAccount = await this.program.account.positionV2.fetch(positionPubKey);
const positionAccount = await this.program.account.positionV2.fetch(
positionPubKey
);

const lowerBinArrayIndex = binIdToBinArrayIndex(new BN(positionAccount.lowerBinId));
const lowerBinArrayIndex = binIdToBinArrayIndex(
new BN(positionAccount.lowerBinId)
);
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN(1));

const [binArrayLower] = deriveBinArray(
Expand Down Expand Up @@ -5293,24 +5297,17 @@ export class DLMM {
}
});
} else {
const [lowerBinArrayPubKey] = deriveBinArray(
lbPairPubKey,
lowerBinArrayIndex,
this.program.programId
);
const [upperBinArrayPubKey] = deriveBinArray(
lbPairPubKey,
upperBinArrayIndex,
this.program.programId
);
const accountsToFetch = [];
for (let i = lowerBinArrayIndex.toNumber(); i <= upperBinArrayIndex.toNumber(); i++) {
accountsToFetch.push(
deriveBinArray(lbPairPubKey, new BN(i), this.program.programId)[0]
)
}

const binArrays = await (async () => {
if (!lowerBinArrays || !upperBinArrays) {
return (
await this.program.account.binArray.fetchMultiple([
lowerBinArrayPubKey,
upperBinArrayPubKey,
])
await this.program.account.binArray.fetchMultiple(accountsToFetch)
).filter((binArray) => binArray !== null);
}

Expand All @@ -5319,9 +5316,8 @@ export class DLMM {

binArrays.forEach((binArray) => {
if (!binArray) return;
const [lowerBinIdForBinArray] = getBinArrayLowerUpperBinId(
binArray.index
);
const [lowerBinIdForBinArray] =
getBinArrayLowerUpperBinId(binArray.index);
binArray.bins.forEach((bin, idx) => {
const binId = lowerBinIdForBinArray.toNumber() + idx;
if (binId >= lowerBinId && binId <= upperBinId) {
Expand Down
Loading