@meteora-ag/dlmm 1.3.4 → 1.3.6-rc.0

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 CHANGED
@@ -8066,49 +8066,14 @@ var DLMM = class {
8066
8066
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _46 => _46.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8067
8067
  provider
8068
8068
  );
8069
- const [positions, positionsV2] = await Promise.all([
8070
- program.account.position.all([
8071
- {
8072
- memcmp: {
8073
- bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
8074
- offset: 8 + 32
8075
- }
8076
- }
8077
- ]),
8078
- program.account.positionV2.all([
8079
- {
8080
- memcmp: {
8081
- bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
8082
- offset: 8 + 32
8083
- }
8069
+ const positionsV2 = await program.account.positionV2.all([
8070
+ {
8071
+ memcmp: {
8072
+ bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
8073
+ offset: 8 + 32
8084
8074
  }
8085
- ])
8075
+ }
8086
8076
  ]);
8087
- const binArrayPubkeySet = /* @__PURE__ */ new Set();
8088
- const lbPairSet = /* @__PURE__ */ new Set();
8089
- positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8090
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8091
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8092
- const [lowerBinArrayPubKey] = deriveBinArray(
8093
- lbPair,
8094
- lowerBinArrayIndex,
8095
- program.programId
8096
- );
8097
- const [upperBinArrayPubKey] = deriveBinArray(
8098
- lbPair,
8099
- upperBinArrayIndex,
8100
- program.programId
8101
- );
8102
- binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
8103
- binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
8104
- lbPairSet.add(lbPair.toBase58());
8105
- });
8106
- const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
8107
- (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8108
- );
8109
- const lbPairArray = Array.from(lbPairSet).map(
8110
- (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8111
- );
8112
8077
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8113
8078
  const lbPairSetV2 = /* @__PURE__ */ new Set();
8114
8079
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
@@ -8136,46 +8101,12 @@ var DLMM = class {
8136
8101
  );
8137
8102
  const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
8138
8103
  _web3js.SYSVAR_CLOCK_PUBKEY,
8139
- ...binArrayPubkeyArray,
8140
- ...lbPairArray,
8141
8104
  ...binArrayPubkeyArrayV2,
8142
8105
  ...lbPairArrayV2
8143
8106
  ]);
8144
- const positionBinArraysMap = /* @__PURE__ */ new Map();
8145
- for (let i = 0; i < binArrayPubkeyArray.length; i++) {
8146
- const binArrayPubkey = binArrayPubkeyArray[i];
8147
- const binArrayAccInfoBuffer = binArraysAccInfo[i];
8148
- if (!binArrayAccInfoBuffer)
8149
- throw new Error(
8150
- `Bin Array account ${binArrayPubkey.toBase58()} not found`
8151
- );
8152
- const binArrayAccInfo = program.coder.accounts.decode(
8153
- "binArray",
8154
- binArrayAccInfoBuffer.data
8155
- );
8156
- positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8157
- }
8158
- const lbPairArraysMap = /* @__PURE__ */ new Map();
8159
- for (let i = binArrayPubkeyArray.length; i < binArrayPubkeyArray.length + lbPairArray.length; i++) {
8160
- const lbPairPubkey = lbPairArray[i - binArrayPubkeyArray.length];
8161
- const lbPairAccInfoBuffer = binArraysAccInfo[i];
8162
- if (!lbPairAccInfoBuffer)
8163
- throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
8164
- const lbPairAccInfo = program.coder.accounts.decode(
8165
- "lbPair",
8166
- lbPairAccInfoBuffer.data
8167
- );
8168
- lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
8169
- }
8170
- const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
8171
- reserveX,
8172
- reserveY,
8173
- tokenXMint,
8174
- tokenYMint
8175
- ]).flat();
8176
8107
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8177
- for (let i = binArrayPubkeyArray.length + lbPairArray.length; i < binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i++) {
8178
- const binArrayPubkey = binArrayPubkeyArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length)];
8108
+ for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
8109
+ const binArrayPubkey = binArrayPubkeyArrayV2[i];
8179
8110
  const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
8180
8111
  if (!binArrayAccInfoBufferV2)
8181
8112
  throw new Error(
@@ -8188,8 +8119,8 @@ var DLMM = class {
8188
8119
  positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8189
8120
  }
8190
8121
  const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
8191
- for (let i = binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8192
- const lbPairPubkey = lbPairArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length)];
8122
+ for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8123
+ const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
8193
8124
  const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
8194
8125
  if (!lbPairAccInfoBufferV2)
8195
8126
  throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
@@ -8207,43 +8138,14 @@ var DLMM = class {
8207
8138
  ]).flat();
8208
8139
  const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
8209
8140
  program.provider.connection,
8210
- [...reservePublicKeys, ...reservePublicKeysV2]
8141
+ reservePublicKeysV2
8211
8142
  );
8212
- const lbPairReserveMap = /* @__PURE__ */ new Map();
8213
- const lbPairMintMap = /* @__PURE__ */ new Map();
8214
- lbPairArray.forEach((lbPair, idx) => {
8215
- const index = idx * 4;
8216
- const reserveAccBufferX = reserveAccountsInfo[index];
8217
- const reserveAccBufferY = reserveAccountsInfo[index + 1];
8218
- if (!reserveAccBufferX || !reserveAccBufferY)
8219
- throw new Error(
8220
- `Reserve account for LB Pair ${lbPair.toBase58()} not found`
8221
- );
8222
- const reserveAccX = _spltoken.AccountLayout.decode(reserveAccBufferX.data);
8223
- const reserveAccY = _spltoken.AccountLayout.decode(reserveAccBufferY.data);
8224
- lbPairReserveMap.set(lbPair.toBase58(), {
8225
- reserveX: reserveAccX.amount,
8226
- reserveY: reserveAccY.amount
8227
- });
8228
- const mintXBuffer = reserveAccountsInfo[index + 2];
8229
- const mintYBuffer = reserveAccountsInfo[index + 3];
8230
- if (!mintXBuffer || !mintYBuffer)
8231
- throw new Error(
8232
- `Mint account for LB Pair ${lbPair.toBase58()} not found`
8233
- );
8234
- const mintX = _spltoken.MintLayout.decode(mintXBuffer.data);
8235
- const mintY = _spltoken.MintLayout.decode(mintYBuffer.data);
8236
- lbPairMintMap.set(lbPair.toBase58(), {
8237
- mintXDecimal: mintX.decimals,
8238
- mintYDecimal: mintY.decimals
8239
- });
8240
- });
8241
8143
  const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
8242
8144
  const lbPairMintMapV2 = /* @__PURE__ */ new Map();
8243
8145
  lbPairArrayV2.forEach((lbPair, idx) => {
8244
8146
  const index = idx * 4;
8245
- const reserveAccBufferXV2 = reserveAccountsInfo[reservePublicKeys.length + index];
8246
- const reserveAccBufferYV2 = reserveAccountsInfo[reservePublicKeys.length + index + 1];
8147
+ const reserveAccBufferXV2 = reserveAccountsInfo[index];
8148
+ const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
8247
8149
  if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
8248
8150
  throw new Error(
8249
8151
  `Reserve account for LB Pair ${lbPair.toBase58()} not found`
@@ -8254,8 +8156,8 @@ var DLMM = class {
8254
8156
  reserveX: reserveAccX.amount,
8255
8157
  reserveY: reserveAccY.amount
8256
8158
  });
8257
- const mintXBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 2];
8258
- const mintYBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 3];
8159
+ const mintXBufferV2 = reserveAccountsInfo[index + 2];
8160
+ const mintYBufferV2 = reserveAccountsInfo[index + 3];
8259
8161
  if (!mintXBufferV2 || !mintYBufferV2)
8260
8162
  throw new Error(
8261
8163
  `Mint account for LB Pair ${lbPair.toBase58()} not found`
@@ -8271,74 +8173,6 @@ var DLMM = class {
8271
8173
  clockAccInfo.data.readBigInt64LE(32).toString()
8272
8174
  ).toNumber();
8273
8175
  const positionsMap = /* @__PURE__ */ new Map();
8274
- for (let position of positions) {
8275
- const { account, publicKey: positionPubKey } = position;
8276
- const { upperBinId, lowerBinId, lbPair } = account;
8277
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8278
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8279
- const [lowerBinArrayPubKey] = deriveBinArray(
8280
- lbPair,
8281
- lowerBinArrayIndex,
8282
- program.programId
8283
- );
8284
- const [upperBinArrayPubKey] = deriveBinArray(
8285
- lbPair,
8286
- upperBinArrayIndex,
8287
- program.programId
8288
- );
8289
- const lowerBinArray = positionBinArraysMap.get(
8290
- lowerBinArrayPubKey.toBase58()
8291
- );
8292
- const upperBinArray = positionBinArraysMap.get(
8293
- upperBinArrayPubKey.toBase58()
8294
- );
8295
- const lbPairAcc = lbPairArraysMap.get(lbPair.toBase58());
8296
- const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
8297
- lbPair.toBase58()
8298
- );
8299
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
8300
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
8301
- const tokenX = {
8302
- publicKey: lbPairAcc.tokenXMint,
8303
- reserve: lbPairAcc.reserveX,
8304
- amount: reserveXBalance,
8305
- decimal: mintXDecimal
8306
- };
8307
- const tokenY = {
8308
- publicKey: lbPairAcc.tokenYMint,
8309
- reserve: lbPairAcc.reserveY,
8310
- amount: reserveYBalance,
8311
- decimal: mintYDecimal
8312
- };
8313
- const positionData = await DLMM.processPosition(
8314
- program,
8315
- 0 /* V1 */,
8316
- lbPairAcc,
8317
- onChainTimestamp,
8318
- account,
8319
- mintXDecimal,
8320
- mintYDecimal,
8321
- lowerBinArray,
8322
- upperBinArray,
8323
- _web3js.PublicKey.default
8324
- );
8325
- if (positionData) {
8326
- positionsMap.set(lbPair.toBase58(), {
8327
- publicKey: lbPair,
8328
- lbPair: lbPairAcc,
8329
- tokenX,
8330
- tokenY,
8331
- lbPairPositionsData: [
8332
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
8333
- {
8334
- publicKey: positionPubKey,
8335
- positionData,
8336
- version: 0 /* V1 */
8337
- }
8338
- ]
8339
- });
8340
- }
8341
- }
8342
8176
  for (let position of positionsV2) {
8343
8177
  const { account, publicKey: positionPubKey } = position;
8344
8178
  const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
@@ -8365,8 +8199,8 @@ var DLMM = class {
8365
8199
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
8366
8200
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
8367
8201
  ]);
8368
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _56 => _56.get, 'call', _57 => _57(lbPair.toBase58()), 'optionalAccess', _58 => _58.reserveX]), () => ( BigInt(0)));
8369
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _59 => _59.get, 'call', _60 => _60(lbPair.toBase58()), 'optionalAccess', _61 => _61.reserveY]), () => ( BigInt(0)));
8202
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
8203
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
8370
8204
  const tokenX = {
8371
8205
  publicKey: lbPairAcc.tokenXMint,
8372
8206
  reserve: lbPairAcc.reserveX,
@@ -8398,7 +8232,7 @@ var DLMM = class {
8398
8232
  tokenX,
8399
8233
  tokenY,
8400
8234
  lbPairPositionsData: [
8401
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _62 => _62.get, 'call', _63 => _63(lbPair.toBase58()), 'optionalAccess', _64 => _64.lbPairPositionsData]), () => ( [])),
8235
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
8402
8236
  {
8403
8237
  publicKey: positionPubKey,
8404
8238
  positionData,
@@ -8410,56 +8244,6 @@ var DLMM = class {
8410
8244
  }
8411
8245
  return positionsMap;
8412
8246
  }
8413
- static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
8414
- const cluster = _optionalChain([opt, 'optionalAccess', _65 => _65.cluster]) || "mainnet-beta";
8415
- const provider = new (0, _anchor.AnchorProvider)(
8416
- connection,
8417
- {},
8418
- _anchor.AnchorProvider.defaultOptions()
8419
- );
8420
- const program = new (0, _anchor.Program)(
8421
- IDL,
8422
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8423
- provider
8424
- );
8425
- const positionsState = await program.account.position.fetchMultiple(
8426
- positions
8427
- );
8428
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
8429
- return Promise.all(
8430
- positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
8431
- const position = positions[idx];
8432
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8433
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
8434
- const [lowerBinArrayPubKey] = deriveBinArray(
8435
- lbPair,
8436
- lowerBinArrayIndex,
8437
- program.programId
8438
- );
8439
- const [upperBinArrayPubKey] = deriveBinArray(
8440
- lbPair,
8441
- upperBinArrayIndex,
8442
- program.programId
8443
- );
8444
- const migrateTx = await program.methods.migratePosition().accounts({
8445
- binArrayLower: lowerBinArrayPubKey,
8446
- binArrayUpper: upperBinArrayPubKey,
8447
- lbPair,
8448
- owner: walletPubkey,
8449
- positionV1: position,
8450
- positionV2: newPositions[idx],
8451
- program: program.programId,
8452
- rentReceiver: walletPubkey,
8453
- systemProgram: _web3js.SystemProgram.programId
8454
- }).transaction();
8455
- return new (0, _web3js.Transaction)({
8456
- blockhash,
8457
- lastValidBlockHeight,
8458
- feePayer: walletPubkey
8459
- }).add(migrateTx);
8460
- })
8461
- );
8462
- }
8463
8247
  static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8464
8248
  return new (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8465
8249
  }
@@ -8477,7 +8261,7 @@ var DLMM = class {
8477
8261
  );
8478
8262
  const program = new (0, _anchor.Program)(
8479
8263
  IDL,
8480
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _67 => _67.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8264
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _56 => _56.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8481
8265
  provider
8482
8266
  );
8483
8267
  const [lbPair] = derivePermissionLbPair(
@@ -8526,7 +8310,7 @@ var DLMM = class {
8526
8310
  );
8527
8311
  const program = new (0, _anchor.Program)(
8528
8312
  IDL,
8529
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _68 => _68.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8313
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _57 => _57.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8530
8314
  provider
8531
8315
  );
8532
8316
  const [lbPair] = deriveCustomizablePermissionlessLbPair(
@@ -8574,7 +8358,7 @@ var DLMM = class {
8574
8358
  );
8575
8359
  const program = new (0, _anchor.Program)(
8576
8360
  IDL,
8577
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _69 => _69.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8361
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _58 => _58.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8578
8362
  provider
8579
8363
  );
8580
8364
  const existsPool = await this.getPairPubkeyIfExists(
@@ -8710,7 +8494,7 @@ var DLMM = class {
8710
8494
  swapForY,
8711
8495
  new (0, _anchor.BN)(activeIdToLoop),
8712
8496
  this.lbPair,
8713
- _nullishCoalesce(_optionalChain([this, 'access', _70 => _70.binArrayBitmapExtension, 'optionalAccess', _71 => _71.account]), () => ( null))
8497
+ _nullishCoalesce(_optionalChain([this, 'access', _59 => _59.binArrayBitmapExtension, 'optionalAccess', _60 => _60.account]), () => ( null))
8714
8498
  );
8715
8499
  if (binArrayIndex === null)
8716
8500
  shouldStop = true;
@@ -8951,20 +8735,6 @@ var DLMM = class {
8951
8735
  async getPositionsByUserAndLbPair(userPubKey) {
8952
8736
  const promiseResults = await Promise.all([
8953
8737
  this.getActiveBin(),
8954
- userPubKey && this.program.account.position.all([
8955
- {
8956
- memcmp: {
8957
- bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
8958
- offset: 8 + 32
8959
- }
8960
- },
8961
- {
8962
- memcmp: {
8963
- bytes: _bytes.bs58.encode(this.pubkey.toBuffer()),
8964
- offset: 8
8965
- }
8966
- }
8967
- ]),
8968
8738
  userPubKey && this.program.account.positionV2.all([
8969
8739
  {
8970
8740
  memcmp: {
@@ -8980,7 +8750,7 @@ var DLMM = class {
8980
8750
  }
8981
8751
  ])
8982
8752
  ]);
8983
- const [activeBin, positions, positionsV2] = promiseResults;
8753
+ const [activeBin, positionsV2] = promiseResults;
8984
8754
  if (!activeBin) {
8985
8755
  throw new Error("Error fetching active bin");
8986
8756
  }
@@ -8990,29 +8760,9 @@ var DLMM = class {
8990
8760
  userPositions: []
8991
8761
  };
8992
8762
  }
8993
- if (!positions || !positionsV2) {
8763
+ if (!positionsV2) {
8994
8764
  throw new Error("Error fetching positions");
8995
8765
  }
8996
- const binArrayPubkeySet = /* @__PURE__ */ new Set();
8997
- positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
8998
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8999
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
9000
- const [lowerBinArrayPubKey] = deriveBinArray(
9001
- this.pubkey,
9002
- lowerBinArrayIndex,
9003
- this.program.programId
9004
- );
9005
- const [upperBinArrayPubKey] = deriveBinArray(
9006
- this.pubkey,
9007
- upperBinArrayIndex,
9008
- this.program.programId
9009
- );
9010
- binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
9011
- binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
9012
- });
9013
- const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
9014
- (pubkey) => new (0, _web3js.PublicKey)(pubkey)
9015
- );
9016
8766
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
9017
8767
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
9018
8768
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
@@ -9038,28 +8788,13 @@ var DLMM = class {
9038
8788
  [
9039
8789
  this.pubkey,
9040
8790
  _web3js.SYSVAR_CLOCK_PUBKEY,
9041
- ...binArrayPubkeyArray,
9042
8791
  ...binArrayPubkeyArrayV2
9043
8792
  ]
9044
8793
  );
9045
8794
  const [lbPairAccInfo, clockAccInfo, ...binArraysAccInfo] = lbPairAndBinArrays;
9046
- const positionBinArraysMap = /* @__PURE__ */ new Map();
9047
- for (let i = 0; i < binArrayPubkeyArray.length; i++) {
9048
- const binArrayPubkey = binArrayPubkeyArray[i];
9049
- const binArrayAccBuffer = binArraysAccInfo[i];
9050
- if (!binArrayAccBuffer)
9051
- throw new Error(
9052
- `Bin Array account ${binArrayPubkey.toBase58()} not found`
9053
- );
9054
- const binArrayAccInfo = this.program.coder.accounts.decode(
9055
- "binArray",
9056
- binArrayAccBuffer.data
9057
- );
9058
- positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
9059
- }
9060
8795
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
9061
- for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
9062
- const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
8796
+ for (let i = 0; i < binArraysAccInfo.length; i++) {
8797
+ const binArrayPubkey = binArrayPubkeyArrayV2[i];
9063
8798
  const binArrayAccBufferV2 = binArraysAccInfo[i];
9064
8799
  if (!binArrayAccBufferV2)
9065
8800
  throw new Error(
@@ -9076,45 +8811,6 @@ var DLMM = class {
9076
8811
  const onChainTimestamp = new (0, _anchor.BN)(
9077
8812
  clockAccInfo.data.readBigInt64LE(32).toString()
9078
8813
  ).toNumber();
9079
- const userPositions = await Promise.all(
9080
- positions.map(async ({ publicKey, account }) => {
9081
- const { lowerBinId, upperBinId } = account;
9082
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
9083
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
9084
- const [lowerBinArrayPubKey] = deriveBinArray(
9085
- this.pubkey,
9086
- lowerBinArrayIndex,
9087
- this.program.programId
9088
- );
9089
- const [upperBinArrayPubKey] = deriveBinArray(
9090
- this.pubkey,
9091
- upperBinArrayIndex,
9092
- this.program.programId
9093
- );
9094
- const lowerBinArray = positionBinArraysMap.get(
9095
- lowerBinArrayPubKey.toBase58()
9096
- );
9097
- const upperBinArray = positionBinArraysMap.get(
9098
- upperBinArrayPubKey.toBase58()
9099
- );
9100
- return {
9101
- publicKey,
9102
- positionData: await DLMM.processPosition(
9103
- this.program,
9104
- 0 /* V1 */,
9105
- this.lbPair,
9106
- onChainTimestamp,
9107
- account,
9108
- this.tokenX.decimal,
9109
- this.tokenY.decimal,
9110
- lowerBinArray,
9111
- upperBinArray,
9112
- _web3js.PublicKey.default
9113
- ),
9114
- version: 0 /* V1 */
9115
- };
9116
- })
9117
- );
9118
8814
  const userPositionsV2 = await Promise.all(
9119
8815
  positionsV2.map(async ({ publicKey, account }) => {
9120
8816
  const { lowerBinId, upperBinId, feeOwner } = account;
@@ -9156,7 +8852,7 @@ var DLMM = class {
9156
8852
  );
9157
8853
  return {
9158
8854
  activeBin,
9159
- userPositions: [...userPositions, ...userPositionsV2]
8855
+ userPositions: userPositionsV2
9160
8856
  };
9161
8857
  }
9162
8858
  async quoteCreatePosition({ strategy }) {
@@ -9217,6 +8913,93 @@ var DLMM = class {
9217
8913
  feePayer: user
9218
8914
  }).add(setCUIx, ...instructions);
9219
8915
  }
8916
+ /**
8917
+ * The function `getPosition` retrieves position information for a given public key and processes it
8918
+ * using various data to return a `LbPosition` object.
8919
+ * @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
8920
+ * function that fetches position information based on a given public key. Here's a breakdown of the
8921
+ * parameters used in the function:
8922
+ * @returns The `getPosition` function returns a Promise that resolves to an object of type
8923
+ * `LbPosition`. The object contains the following properties:
8924
+ * - `publicKey`: The public key of the position account
8925
+ * - `positionData`: Position Object
8926
+ * - `version`: The version of the position (in this case, `Position.V2`)
8927
+ */
8928
+ async getPosition(positionPubKey) {
8929
+ const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
8930
+ if (!positionAccountInfo) {
8931
+ throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
8932
+ }
8933
+ const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
8934
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8935
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8936
+ const [lowerBinArrayPubKey] = deriveBinArray(
8937
+ this.pubkey,
8938
+ lowerBinArrayIndex,
8939
+ this.program.programId
8940
+ );
8941
+ const [upperBinArrayPubKey] = deriveBinArray(
8942
+ this.pubkey,
8943
+ upperBinArrayIndex,
8944
+ this.program.programId
8945
+ );
8946
+ const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
8947
+ this.program.provider.connection,
8948
+ [
8949
+ _web3js.SYSVAR_CLOCK_PUBKEY,
8950
+ lowerBinArrayPubKey,
8951
+ upperBinArrayPubKey
8952
+ ]
8953
+ );
8954
+ if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
8955
+ return {
8956
+ publicKey: positionPubKey,
8957
+ positionData: {
8958
+ totalXAmount: "0",
8959
+ totalYAmount: "0",
8960
+ positionBinData: [],
8961
+ lastUpdatedAt: new (0, _anchor.BN)(0),
8962
+ upperBinId,
8963
+ lowerBinId,
8964
+ feeX: new (0, _anchor.BN)(0),
8965
+ feeY: new (0, _anchor.BN)(0),
8966
+ rewardOne: new (0, _anchor.BN)(0),
8967
+ rewardTwo: new (0, _anchor.BN)(0),
8968
+ feeOwner,
8969
+ totalClaimedFeeXAmount: new (0, _anchor.BN)(0),
8970
+ totalClaimedFeeYAmount: new (0, _anchor.BN)(0)
8971
+ },
8972
+ version: 1 /* V2 */
8973
+ };
8974
+ }
8975
+ const onChainTimestamp = new (0, _anchor.BN)(
8976
+ clockAccInfo.data.readBigInt64LE(32).toString()
8977
+ ).toNumber();
8978
+ const lowerBinArray = this.program.coder.accounts.decode(
8979
+ "binArray",
8980
+ lowerBinArrayAccInfo.data
8981
+ );
8982
+ const upperBinArray = this.program.coder.accounts.decode(
8983
+ "binArray",
8984
+ upperBinArrayAccInfo.data
8985
+ );
8986
+ return {
8987
+ publicKey: positionPubKey,
8988
+ positionData: await DLMM.processPosition(
8989
+ this.program,
8990
+ 1 /* V2 */,
8991
+ this.lbPair,
8992
+ onChainTimestamp,
8993
+ positionAccountInfo,
8994
+ this.tokenX.decimal,
8995
+ this.tokenY.decimal,
8996
+ lowerBinArray,
8997
+ upperBinArray,
8998
+ feeOwner
8999
+ ),
9000
+ version: 1 /* V2 */
9001
+ };
9002
+ }
9220
9003
  /**
9221
9004
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
9222
9005
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -9940,9 +9723,40 @@ var DLMM = class {
9940
9723
  bps,
9941
9724
  shouldClaimAndClose = false
9942
9725
  }) {
9943
- const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
9944
- const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
9945
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
9726
+ const lowerBinIdToRemove = Math.min(...binIds);
9727
+ const upperBinIdToRemove = Math.max(...binIds);
9728
+ const [lowerBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new (0, _anchor.BN)(binIds[0])), this.program.programId);
9729
+ const [upperBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new (0, _anchor.BN)(binIds[binIds.length - 1])), this.program.programId);
9730
+ const [positionAccInfo, lbPairAccInfo, upperBinArrayInfoAcc, lowerBinArrayInfoAcc] = await this.program.provider.connection.getMultipleAccountsInfo([
9731
+ position,
9732
+ this.pubkey,
9733
+ upperBinArrayPubKey,
9734
+ lowerBinArrayPubKey
9735
+ ]);
9736
+ const { lbPair, owner, feeOwner, upperBinId: positionUpperBinId, lowerBinId: positionLowerBinId } = this.program.coder.accounts.decode(
9737
+ "positionV2",
9738
+ positionAccInfo.data
9739
+ );
9740
+ const { reserveX, reserveY, tokenXMint, tokenYMint } = this.program.coder.accounts.decode(
9741
+ "lbPair",
9742
+ lbPairAccInfo.data
9743
+ );
9744
+ const upperBinArray = this.program.coder.accounts.decode("binArray", upperBinArrayInfoAcc.data);
9745
+ const lowerBinArray = this.program.coder.accounts.decode("binArray", lowerBinArrayInfoAcc.data);
9746
+ const bins = await this.getBins(
9747
+ this.pubkey,
9748
+ positionLowerBinId,
9749
+ positionUpperBinId,
9750
+ this.tokenX.decimal,
9751
+ this.tokenY.decimal,
9752
+ lowerBinArray,
9753
+ upperBinArray
9754
+ );
9755
+ const positionHasNoLiquidity = bins.every(({ supply }) => supply.isZero());
9756
+ if (positionHasNoLiquidity) {
9757
+ throw new Error("No liquidity to remove");
9758
+ }
9759
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(positionLowerBinId));
9946
9760
  const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
9947
9761
  const [binArrayLower] = deriveBinArray(
9948
9762
  lbPair,
@@ -10056,13 +9870,11 @@ var DLMM = class {
10056
9870
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10057
9871
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10058
9872
  }
10059
- const minBinId = Math.min(...binIds);
10060
- const maxBinId = Math.max(...binIds);
10061
- const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
10062
- const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
9873
+ const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinIdToRemove));
9874
+ const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinIdToRemove));
10063
9875
  const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
10064
9876
  const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
10065
- const removeLiquidityIx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
9877
+ const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
10066
9878
  position,
10067
9879
  lbPair,
10068
9880
  userTokenX,
@@ -10080,7 +9892,7 @@ var DLMM = class {
10080
9892
  }).instruction();
10081
9893
  const instructions = [
10082
9894
  ...preInstructions,
10083
- removeLiquidityIx,
9895
+ removeLiquidityTx,
10084
9896
  ...postInstructions
10085
9897
  ];
10086
9898
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
@@ -10196,7 +10008,7 @@ var DLMM = class {
10196
10008
  swapForY,
10197
10009
  activeId,
10198
10010
  this.lbPair,
10199
- _nullishCoalesce(_optionalChain([this, 'access', _72 => _72.binArrayBitmapExtension, 'optionalAccess', _73 => _73.account]), () => ( null)),
10011
+ _nullishCoalesce(_optionalChain([this, 'access', _61 => _61.binArrayBitmapExtension, 'optionalAccess', _62 => _62.account]), () => ( null)),
10200
10012
  binArrays
10201
10013
  );
10202
10014
  if (binArrayAccountToSwap == null) {
@@ -10300,7 +10112,7 @@ var DLMM = class {
10300
10112
  swapForY,
10301
10113
  activeId,
10302
10114
  this.lbPair,
10303
- _nullishCoalesce(_optionalChain([this, 'access', _74 => _74.binArrayBitmapExtension, 'optionalAccess', _75 => _75.account]), () => ( null)),
10115
+ _nullishCoalesce(_optionalChain([this, 'access', _63 => _63.binArrayBitmapExtension, 'optionalAccess', _64 => _64.account]), () => ( null)),
10304
10116
  binArrays
10305
10117
  );
10306
10118
  if (binArrayAccountToSwap == null) {
@@ -11486,7 +11298,7 @@ var DLMM = class {
11486
11298
  swapForY,
11487
11299
  new (0, _anchor.BN)(activeBinId),
11488
11300
  this.lbPair,
11489
- _nullishCoalesce(_optionalChain([this, 'access', _76 => _76.binArrayBitmapExtension, 'optionalAccess', _77 => _77.account]), () => ( null))
11301
+ _nullishCoalesce(_optionalChain([this, 'access', _65 => _65.binArrayBitmapExtension, 'optionalAccess', _66 => _66.account]), () => ( null))
11490
11302
  );
11491
11303
  if (toBinArrayIndex === null)
11492
11304
  return true;
@@ -11523,7 +11335,7 @@ var DLMM = class {
11523
11335
  swapForY,
11524
11336
  new (0, _anchor.BN)(activeBinId),
11525
11337
  this.lbPair,
11526
- _nullishCoalesce(_optionalChain([this, 'access', _78 => _78.binArrayBitmapExtension, 'optionalAccess', _79 => _79.account]), () => ( null))
11338
+ _nullishCoalesce(_optionalChain([this, 'access', _67 => _67.binArrayBitmapExtension, 'optionalAccess', _68 => _68.account]), () => ( null))
11527
11339
  );
11528
11340
  const accountsToFetch = [];
11529
11341
  const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
@@ -11554,13 +11366,13 @@ var DLMM = class {
11554
11366
  let fromBinArray = null;
11555
11367
  let toBinArray = null;
11556
11368
  let binArrayBitmapExtension = null;
11557
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _80 => _80[0]])) {
11369
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _69 => _69[0]])) {
11558
11370
  binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
11559
11371
  }
11560
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _81 => _81[1]])) {
11372
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _70 => _70[1]])) {
11561
11373
  fromBinArray = fromBinArrayPubkey;
11562
11374
  }
11563
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _82 => _82[2]]) && !!toBinArrayIndex) {
11375
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _71 => _71[2]]) && !!toBinArrayIndex) {
11564
11376
  toBinArray = toBinArrayPubkey;
11565
11377
  }
11566
11378
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
@@ -11885,12 +11697,7 @@ var DLMM = class {
11885
11697
  let totalYAmount = new (0, _decimaljs2.default)(0);
11886
11698
  bins.forEach((bin, idx) => {
11887
11699
  const binSupply = new (0, _decimaljs2.default)(bin.supply.toString());
11888
- let posShare;
11889
- if (bin.version === 1 && version === 0 /* V1 */) {
11890
- posShare = new (0, _decimaljs2.default)(posShares[idx].shln(64).toString());
11891
- } else {
11892
- posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
11893
- }
11700
+ const posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
11894
11701
  const positionXAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
11895
11702
  const positionYAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
11896
11703
  totalXAmount = totalXAmount.add(positionXAmount);
@@ -12041,7 +11848,7 @@ var DLMM = class {
12041
11848
  const [lowerBinId2] = getBinArrayLowerUpperBinId(index);
12042
11849
  return bins.map((b, i) => [lowerBinId2.toNumber() + i, b]);
12043
11850
  }));
12044
- const version = binArrays.length !== 0 ? binArrays[0].version : 1;
11851
+ const version = _nullishCoalesce(_optionalChain([binArrays, 'access', _72 => _72.find, 'call', _73 => _73((binArray) => binArray != null), 'optionalAccess', _74 => _74.version]), () => ( 1));
12045
11852
  return Array.from(enumerateBins(
12046
11853
  binsById,
12047
11854
  lowerBinId,