@meteora-ag/dlmm 1.3.1-sam.0 → 1.3.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.js CHANGED
@@ -7975,14 +7975,49 @@ var DLMM = class {
7975
7975
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _46 => _46.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7976
7976
  provider
7977
7977
  );
7978
- const positionsV2 = await program.account.positionV2.all([
7979
- {
7980
- memcmp: {
7981
- bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
7982
- offset: 8 + 32
7978
+ const [positions, positionsV2] = await Promise.all([
7979
+ program.account.position.all([
7980
+ {
7981
+ memcmp: {
7982
+ bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
7983
+ offset: 8 + 32
7984
+ }
7983
7985
  }
7984
- }
7986
+ ]),
7987
+ program.account.positionV2.all([
7988
+ {
7989
+ memcmp: {
7990
+ bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
7991
+ offset: 8 + 32
7992
+ }
7993
+ }
7994
+ ])
7985
7995
  ]);
7996
+ const binArrayPubkeySet = /* @__PURE__ */ new Set();
7997
+ const lbPairSet = /* @__PURE__ */ new Set();
7998
+ positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
7999
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8000
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8001
+ const [lowerBinArrayPubKey] = deriveBinArray(
8002
+ lbPair,
8003
+ lowerBinArrayIndex,
8004
+ program.programId
8005
+ );
8006
+ const [upperBinArrayPubKey] = deriveBinArray(
8007
+ lbPair,
8008
+ upperBinArrayIndex,
8009
+ program.programId
8010
+ );
8011
+ binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
8012
+ binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
8013
+ lbPairSet.add(lbPair.toBase58());
8014
+ });
8015
+ const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
8016
+ (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8017
+ );
8018
+ const lbPairArray = Array.from(lbPairSet).map(
8019
+ (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8020
+ );
7986
8021
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
7987
8022
  const lbPairSetV2 = /* @__PURE__ */ new Set();
7988
8023
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
@@ -8010,12 +8045,46 @@ var DLMM = class {
8010
8045
  );
8011
8046
  const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
8012
8047
  _web3js.SYSVAR_CLOCK_PUBKEY,
8048
+ ...binArrayPubkeyArray,
8049
+ ...lbPairArray,
8013
8050
  ...binArrayPubkeyArrayV2,
8014
8051
  ...lbPairArrayV2
8015
8052
  ]);
8053
+ const positionBinArraysMap = /* @__PURE__ */ new Map();
8054
+ for (let i = 0; i < binArrayPubkeyArray.length; i++) {
8055
+ const binArrayPubkey = binArrayPubkeyArray[i];
8056
+ const binArrayAccInfoBuffer = binArraysAccInfo[i];
8057
+ if (!binArrayAccInfoBuffer)
8058
+ throw new Error(
8059
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
8060
+ );
8061
+ const binArrayAccInfo = program.coder.accounts.decode(
8062
+ "binArray",
8063
+ binArrayAccInfoBuffer.data
8064
+ );
8065
+ positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8066
+ }
8067
+ const lbPairArraysMap = /* @__PURE__ */ new Map();
8068
+ for (let i = binArrayPubkeyArray.length; i < binArrayPubkeyArray.length + lbPairArray.length; i++) {
8069
+ const lbPairPubkey = lbPairArray[i - binArrayPubkeyArray.length];
8070
+ const lbPairAccInfoBuffer = binArraysAccInfo[i];
8071
+ if (!lbPairAccInfoBuffer)
8072
+ throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
8073
+ const lbPairAccInfo = program.coder.accounts.decode(
8074
+ "lbPair",
8075
+ lbPairAccInfoBuffer.data
8076
+ );
8077
+ lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
8078
+ }
8079
+ const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
8080
+ reserveX,
8081
+ reserveY,
8082
+ tokenXMint,
8083
+ tokenYMint
8084
+ ]).flat();
8016
8085
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8017
- for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
8018
- const binArrayPubkey = binArrayPubkeyArrayV2[i];
8086
+ for (let i = binArrayPubkeyArray.length + lbPairArray.length; i < binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i++) {
8087
+ const binArrayPubkey = binArrayPubkeyArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length)];
8019
8088
  const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
8020
8089
  if (!binArrayAccInfoBufferV2)
8021
8090
  throw new Error(
@@ -8028,8 +8097,8 @@ var DLMM = class {
8028
8097
  positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8029
8098
  }
8030
8099
  const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
8031
- for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8032
- const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
8100
+ for (let i = binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8101
+ const lbPairPubkey = lbPairArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length)];
8033
8102
  const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
8034
8103
  if (!lbPairAccInfoBufferV2)
8035
8104
  throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
@@ -8047,14 +8116,43 @@ var DLMM = class {
8047
8116
  ]).flat();
8048
8117
  const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
8049
8118
  program.provider.connection,
8050
- reservePublicKeysV2
8119
+ [...reservePublicKeys, ...reservePublicKeysV2]
8051
8120
  );
8121
+ const lbPairReserveMap = /* @__PURE__ */ new Map();
8122
+ const lbPairMintMap = /* @__PURE__ */ new Map();
8123
+ lbPairArray.forEach((lbPair, idx) => {
8124
+ const index = idx * 4;
8125
+ const reserveAccBufferX = reserveAccountsInfo[index];
8126
+ const reserveAccBufferY = reserveAccountsInfo[index + 1];
8127
+ if (!reserveAccBufferX || !reserveAccBufferY)
8128
+ throw new Error(
8129
+ `Reserve account for LB Pair ${lbPair.toBase58()} not found`
8130
+ );
8131
+ const reserveAccX = _spltoken.AccountLayout.decode(reserveAccBufferX.data);
8132
+ const reserveAccY = _spltoken.AccountLayout.decode(reserveAccBufferY.data);
8133
+ lbPairReserveMap.set(lbPair.toBase58(), {
8134
+ reserveX: reserveAccX.amount,
8135
+ reserveY: reserveAccY.amount
8136
+ });
8137
+ const mintXBuffer = reserveAccountsInfo[index + 2];
8138
+ const mintYBuffer = reserveAccountsInfo[index + 3];
8139
+ if (!mintXBuffer || !mintYBuffer)
8140
+ throw new Error(
8141
+ `Mint account for LB Pair ${lbPair.toBase58()} not found`
8142
+ );
8143
+ const mintX = _spltoken.MintLayout.decode(mintXBuffer.data);
8144
+ const mintY = _spltoken.MintLayout.decode(mintYBuffer.data);
8145
+ lbPairMintMap.set(lbPair.toBase58(), {
8146
+ mintXDecimal: mintX.decimals,
8147
+ mintYDecimal: mintY.decimals
8148
+ });
8149
+ });
8052
8150
  const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
8053
8151
  const lbPairMintMapV2 = /* @__PURE__ */ new Map();
8054
8152
  lbPairArrayV2.forEach((lbPair, idx) => {
8055
8153
  const index = idx * 4;
8056
- const reserveAccBufferXV2 = reserveAccountsInfo[index];
8057
- const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
8154
+ const reserveAccBufferXV2 = reserveAccountsInfo[reservePublicKeys.length + index];
8155
+ const reserveAccBufferYV2 = reserveAccountsInfo[reservePublicKeys.length + index + 1];
8058
8156
  if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
8059
8157
  throw new Error(
8060
8158
  `Reserve account for LB Pair ${lbPair.toBase58()} not found`
@@ -8065,8 +8163,8 @@ var DLMM = class {
8065
8163
  reserveX: reserveAccX.amount,
8066
8164
  reserveY: reserveAccY.amount
8067
8165
  });
8068
- const mintXBufferV2 = reserveAccountsInfo[index + 2];
8069
- const mintYBufferV2 = reserveAccountsInfo[index + 3];
8166
+ const mintXBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 2];
8167
+ const mintYBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 3];
8070
8168
  if (!mintXBufferV2 || !mintYBufferV2)
8071
8169
  throw new Error(
8072
8170
  `Mint account for LB Pair ${lbPair.toBase58()} not found`
@@ -8082,6 +8180,74 @@ var DLMM = class {
8082
8180
  clockAccInfo.data.readBigInt64LE(32).toString()
8083
8181
  ).toNumber();
8084
8182
  const positionsMap = /* @__PURE__ */ new Map();
8183
+ for (let position of positions) {
8184
+ const { account, publicKey: positionPubKey } = position;
8185
+ const { upperBinId, lowerBinId, lbPair } = account;
8186
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8187
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8188
+ const [lowerBinArrayPubKey] = deriveBinArray(
8189
+ lbPair,
8190
+ lowerBinArrayIndex,
8191
+ program.programId
8192
+ );
8193
+ const [upperBinArrayPubKey] = deriveBinArray(
8194
+ lbPair,
8195
+ upperBinArrayIndex,
8196
+ program.programId
8197
+ );
8198
+ const lowerBinArray = positionBinArraysMap.get(
8199
+ lowerBinArrayPubKey.toBase58()
8200
+ );
8201
+ const upperBinArray = positionBinArraysMap.get(
8202
+ upperBinArrayPubKey.toBase58()
8203
+ );
8204
+ const lbPairAcc = lbPairArraysMap.get(lbPair.toBase58());
8205
+ const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
8206
+ lbPair.toBase58()
8207
+ );
8208
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
8209
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
8210
+ const tokenX = {
8211
+ publicKey: lbPairAcc.tokenXMint,
8212
+ reserve: lbPairAcc.reserveX,
8213
+ amount: reserveXBalance,
8214
+ decimal: mintXDecimal
8215
+ };
8216
+ const tokenY = {
8217
+ publicKey: lbPairAcc.tokenYMint,
8218
+ reserve: lbPairAcc.reserveY,
8219
+ amount: reserveYBalance,
8220
+ decimal: mintYDecimal
8221
+ };
8222
+ const positionData = await DLMM.processPosition(
8223
+ program,
8224
+ 0 /* V1 */,
8225
+ lbPairAcc,
8226
+ onChainTimestamp,
8227
+ account,
8228
+ mintXDecimal,
8229
+ mintYDecimal,
8230
+ lowerBinArray,
8231
+ upperBinArray,
8232
+ _web3js.PublicKey.default
8233
+ );
8234
+ if (positionData) {
8235
+ positionsMap.set(lbPair.toBase58(), {
8236
+ publicKey: lbPair,
8237
+ lbPair: lbPairAcc,
8238
+ tokenX,
8239
+ tokenY,
8240
+ lbPairPositionsData: [
8241
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
8242
+ {
8243
+ publicKey: positionPubKey,
8244
+ positionData,
8245
+ version: 0 /* V1 */
8246
+ }
8247
+ ]
8248
+ });
8249
+ }
8250
+ }
8085
8251
  for (let position of positionsV2) {
8086
8252
  const { account, publicKey: positionPubKey } = position;
8087
8253
  const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
@@ -8108,8 +8274,8 @@ var DLMM = class {
8108
8274
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
8109
8275
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
8110
8276
  ]);
8111
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
8112
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
8277
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _56 => _56.get, 'call', _57 => _57(lbPair.toBase58()), 'optionalAccess', _58 => _58.reserveX]), () => ( BigInt(0)));
8278
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _59 => _59.get, 'call', _60 => _60(lbPair.toBase58()), 'optionalAccess', _61 => _61.reserveY]), () => ( BigInt(0)));
8113
8279
  const tokenX = {
8114
8280
  publicKey: lbPairAcc.tokenXMint,
8115
8281
  reserve: lbPairAcc.reserveX,
@@ -8141,7 +8307,7 @@ var DLMM = class {
8141
8307
  tokenX,
8142
8308
  tokenY,
8143
8309
  lbPairPositionsData: [
8144
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
8310
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _62 => _62.get, 'call', _63 => _63(lbPair.toBase58()), 'optionalAccess', _64 => _64.lbPairPositionsData]), () => ( [])),
8145
8311
  {
8146
8312
  publicKey: positionPubKey,
8147
8313
  positionData,
@@ -8153,6 +8319,56 @@ var DLMM = class {
8153
8319
  }
8154
8320
  return positionsMap;
8155
8321
  }
8322
+ static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
8323
+ const cluster = _optionalChain([opt, 'optionalAccess', _65 => _65.cluster]) || "mainnet-beta";
8324
+ const provider = new (0, _anchor.AnchorProvider)(
8325
+ connection,
8326
+ {},
8327
+ _anchor.AnchorProvider.defaultOptions()
8328
+ );
8329
+ const program = new (0, _anchor.Program)(
8330
+ IDL,
8331
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8332
+ provider
8333
+ );
8334
+ const positionsState = await program.account.position.fetchMultiple(
8335
+ positions
8336
+ );
8337
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
8338
+ return Promise.all(
8339
+ positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
8340
+ const position = positions[idx];
8341
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8342
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
8343
+ const [lowerBinArrayPubKey] = deriveBinArray(
8344
+ lbPair,
8345
+ lowerBinArrayIndex,
8346
+ program.programId
8347
+ );
8348
+ const [upperBinArrayPubKey] = deriveBinArray(
8349
+ lbPair,
8350
+ upperBinArrayIndex,
8351
+ program.programId
8352
+ );
8353
+ const migrateTx = await program.methods.migratePosition().accounts({
8354
+ binArrayLower: lowerBinArrayPubKey,
8355
+ binArrayUpper: upperBinArrayPubKey,
8356
+ lbPair,
8357
+ owner: walletPubkey,
8358
+ positionV1: position,
8359
+ positionV2: newPositions[idx],
8360
+ program: program.programId,
8361
+ rentReceiver: walletPubkey,
8362
+ systemProgram: _web3js.SystemProgram.programId
8363
+ }).transaction();
8364
+ return new (0, _web3js.Transaction)({
8365
+ blockhash,
8366
+ lastValidBlockHeight,
8367
+ feePayer: walletPubkey
8368
+ }).add(migrateTx);
8369
+ })
8370
+ );
8371
+ }
8156
8372
  static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8157
8373
  return new (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8158
8374
  }
@@ -8170,7 +8386,7 @@ var DLMM = class {
8170
8386
  );
8171
8387
  const program = new (0, _anchor.Program)(
8172
8388
  IDL,
8173
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _56 => _56.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8389
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _67 => _67.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8174
8390
  provider
8175
8391
  );
8176
8392
  const [lbPair] = derivePermissionLbPair(
@@ -8219,7 +8435,7 @@ var DLMM = class {
8219
8435
  );
8220
8436
  const program = new (0, _anchor.Program)(
8221
8437
  IDL,
8222
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _57 => _57.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8438
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _68 => _68.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8223
8439
  provider
8224
8440
  );
8225
8441
  const [lbPair] = deriveCustomizablePermissionlessLbPair(
@@ -8267,7 +8483,7 @@ var DLMM = class {
8267
8483
  );
8268
8484
  const program = new (0, _anchor.Program)(
8269
8485
  IDL,
8270
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _58 => _58.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8486
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _69 => _69.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8271
8487
  provider
8272
8488
  );
8273
8489
  const existsPool = await this.getPairPubkeyIfExists(
@@ -8403,7 +8619,7 @@ var DLMM = class {
8403
8619
  swapForY,
8404
8620
  new (0, _anchor.BN)(activeIdToLoop),
8405
8621
  this.lbPair,
8406
- _nullishCoalesce(_optionalChain([this, 'access', _59 => _59.binArrayBitmapExtension, 'optionalAccess', _60 => _60.account]), () => ( null))
8622
+ _nullishCoalesce(_optionalChain([this, 'access', _70 => _70.binArrayBitmapExtension, 'optionalAccess', _71 => _71.account]), () => ( null))
8407
8623
  );
8408
8624
  if (binArrayIndex === null)
8409
8625
  shouldStop = true;
@@ -8644,6 +8860,20 @@ var DLMM = class {
8644
8860
  async getPositionsByUserAndLbPair(userPubKey) {
8645
8861
  const promiseResults = await Promise.all([
8646
8862
  this.getActiveBin(),
8863
+ userPubKey && this.program.account.position.all([
8864
+ {
8865
+ memcmp: {
8866
+ bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
8867
+ offset: 8 + 32
8868
+ }
8869
+ },
8870
+ {
8871
+ memcmp: {
8872
+ bytes: _bytes.bs58.encode(this.pubkey.toBuffer()),
8873
+ offset: 8
8874
+ }
8875
+ }
8876
+ ]),
8647
8877
  userPubKey && this.program.account.positionV2.all([
8648
8878
  {
8649
8879
  memcmp: {
@@ -8659,7 +8889,7 @@ var DLMM = class {
8659
8889
  }
8660
8890
  ])
8661
8891
  ]);
8662
- const [activeBin, positionsV2] = promiseResults;
8892
+ const [activeBin, positions, positionsV2] = promiseResults;
8663
8893
  if (!activeBin) {
8664
8894
  throw new Error("Error fetching active bin");
8665
8895
  }
@@ -8669,9 +8899,29 @@ var DLMM = class {
8669
8899
  userPositions: []
8670
8900
  };
8671
8901
  }
8672
- if (!positionsV2) {
8902
+ if (!positions || !positionsV2) {
8673
8903
  throw new Error("Error fetching positions");
8674
8904
  }
8905
+ const binArrayPubkeySet = /* @__PURE__ */ new Set();
8906
+ positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
8907
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8908
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8909
+ const [lowerBinArrayPubKey] = deriveBinArray(
8910
+ this.pubkey,
8911
+ lowerBinArrayIndex,
8912
+ this.program.programId
8913
+ );
8914
+ const [upperBinArrayPubKey] = deriveBinArray(
8915
+ this.pubkey,
8916
+ upperBinArrayIndex,
8917
+ this.program.programId
8918
+ );
8919
+ binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
8920
+ binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
8921
+ });
8922
+ const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
8923
+ (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8924
+ );
8675
8925
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8676
8926
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8677
8927
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
@@ -8697,13 +8947,28 @@ var DLMM = class {
8697
8947
  [
8698
8948
  this.pubkey,
8699
8949
  _web3js.SYSVAR_CLOCK_PUBKEY,
8950
+ ...binArrayPubkeyArray,
8700
8951
  ...binArrayPubkeyArrayV2
8701
8952
  ]
8702
8953
  );
8703
8954
  const [lbPairAccInfo, clockAccInfo, ...binArraysAccInfo] = lbPairAndBinArrays;
8955
+ const positionBinArraysMap = /* @__PURE__ */ new Map();
8956
+ for (let i = 0; i < binArrayPubkeyArray.length; i++) {
8957
+ const binArrayPubkey = binArrayPubkeyArray[i];
8958
+ const binArrayAccBuffer = binArraysAccInfo[i];
8959
+ if (!binArrayAccBuffer)
8960
+ throw new Error(
8961
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
8962
+ );
8963
+ const binArrayAccInfo = this.program.coder.accounts.decode(
8964
+ "binArray",
8965
+ binArrayAccBuffer.data
8966
+ );
8967
+ positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8968
+ }
8704
8969
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8705
- for (let i = 0; i < binArraysAccInfo.length; i++) {
8706
- const binArrayPubkey = binArrayPubkeyArrayV2[i];
8970
+ for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
8971
+ const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
8707
8972
  const binArrayAccBufferV2 = binArraysAccInfo[i];
8708
8973
  if (!binArrayAccBufferV2)
8709
8974
  throw new Error(
@@ -8720,6 +8985,45 @@ var DLMM = class {
8720
8985
  const onChainTimestamp = new (0, _anchor.BN)(
8721
8986
  clockAccInfo.data.readBigInt64LE(32).toString()
8722
8987
  ).toNumber();
8988
+ const userPositions = await Promise.all(
8989
+ positions.map(async ({ publicKey, account }) => {
8990
+ const { lowerBinId, upperBinId } = account;
8991
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8992
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8993
+ const [lowerBinArrayPubKey] = deriveBinArray(
8994
+ this.pubkey,
8995
+ lowerBinArrayIndex,
8996
+ this.program.programId
8997
+ );
8998
+ const [upperBinArrayPubKey] = deriveBinArray(
8999
+ this.pubkey,
9000
+ upperBinArrayIndex,
9001
+ this.program.programId
9002
+ );
9003
+ const lowerBinArray = positionBinArraysMap.get(
9004
+ lowerBinArrayPubKey.toBase58()
9005
+ );
9006
+ const upperBinArray = positionBinArraysMap.get(
9007
+ upperBinArrayPubKey.toBase58()
9008
+ );
9009
+ return {
9010
+ publicKey,
9011
+ positionData: await DLMM.processPosition(
9012
+ this.program,
9013
+ 0 /* V1 */,
9014
+ this.lbPair,
9015
+ onChainTimestamp,
9016
+ account,
9017
+ this.tokenX.decimal,
9018
+ this.tokenY.decimal,
9019
+ lowerBinArray,
9020
+ upperBinArray,
9021
+ _web3js.PublicKey.default
9022
+ ),
9023
+ version: 0 /* V1 */
9024
+ };
9025
+ })
9026
+ );
8723
9027
  const userPositionsV2 = await Promise.all(
8724
9028
  positionsV2.map(async ({ publicKey, account }) => {
8725
9029
  const { lowerBinId, upperBinId, feeOwner } = account;
@@ -8761,7 +9065,7 @@ var DLMM = class {
8761
9065
  );
8762
9066
  return {
8763
9067
  activeBin,
8764
- userPositions: userPositionsV2
9068
+ userPositions: [...userPositions, ...userPositionsV2]
8765
9069
  };
8766
9070
  }
8767
9071
  async quoteCreatePosition({ strategy }) {
@@ -8817,72 +9121,6 @@ var DLMM = class {
8817
9121
  feePayer: user
8818
9122
  }).add(setComputeUnitLimitIx, createPositionIx, ...createBinArrayIxs);
8819
9123
  }
8820
- /**
8821
- * The function `getPosition` retrieves position information for a given public key and processes it
8822
- * using various data to return a `LbPosition` object.
8823
- * @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
8824
- * function that fetches position information based on a given public key. Here's a breakdown of the
8825
- * parameters used in the function:
8826
- * @returns The `getPosition` function returns a Promise that resolves to an object of type
8827
- * `LbPosition`. The object contains the following properties:
8828
- * - `publicKey`: The public key of the position account
8829
- * - `positionData`: Position Object
8830
- * - `version`: The version of the position (in this case, `Position.V2`)
8831
- */
8832
- async getPosition(positionPubKey) {
8833
- const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
8834
- if (!positionAccountInfo) {
8835
- throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
8836
- }
8837
- const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
8838
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8839
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8840
- const [lowerBinArrayPubKey] = deriveBinArray(
8841
- this.pubkey,
8842
- lowerBinArrayIndex,
8843
- this.program.programId
8844
- );
8845
- const [upperBinArrayPubKey] = deriveBinArray(
8846
- this.pubkey,
8847
- upperBinArrayIndex,
8848
- this.program.programId
8849
- );
8850
- const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
8851
- this.program.provider.connection,
8852
- [
8853
- _web3js.SYSVAR_CLOCK_PUBKEY,
8854
- lowerBinArrayPubKey,
8855
- upperBinArrayPubKey
8856
- ]
8857
- );
8858
- const onChainTimestamp = new (0, _anchor.BN)(
8859
- clockAccInfo.data.readBigInt64LE(32).toString()
8860
- ).toNumber();
8861
- const lowerBinArray = this.program.coder.accounts.decode(
8862
- "binArray",
8863
- lowerBinArrayAccInfo.data
8864
- );
8865
- const upperBinArray = this.program.coder.accounts.decode(
8866
- "binArray",
8867
- upperBinArrayAccInfo.data
8868
- );
8869
- return {
8870
- publicKey: positionPubKey,
8871
- positionData: await DLMM.processPosition(
8872
- this.program,
8873
- 1 /* V2 */,
8874
- this.lbPair,
8875
- onChainTimestamp,
8876
- positionAccountInfo,
8877
- this.tokenX.decimal,
8878
- this.tokenY.decimal,
8879
- lowerBinArray,
8880
- upperBinArray,
8881
- feeOwner
8882
- ),
8883
- version: 1 /* V2 */
8884
- };
8885
- }
8886
9124
  /**
8887
9125
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
8888
9126
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -9561,40 +9799,9 @@ var DLMM = class {
9561
9799
  bps,
9562
9800
  shouldClaimAndClose = false
9563
9801
  }) {
9564
- const lowerBinIdToRemove = Math.min(...binIds);
9565
- const upperBinIdToRemove = Math.max(...binIds);
9566
- const [lowerBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new (0, _anchor.BN)(binIds[0])), this.program.programId);
9567
- const [upperBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new (0, _anchor.BN)(binIds[binIds.length - 1])), this.program.programId);
9568
- const [positionAccInfo, lbPairAccInfo, upperBinArrayInfoAcc, lowerBinArrayInfoAcc] = await this.program.provider.connection.getMultipleAccountsInfo([
9569
- position,
9570
- this.pubkey,
9571
- upperBinArrayPubKey,
9572
- lowerBinArrayPubKey
9573
- ]);
9574
- const { lbPair, owner, feeOwner, upperBinId: positionUpperBinId, lowerBinId: positionLowerBinId } = this.program.coder.accounts.decode(
9575
- "positionV2",
9576
- positionAccInfo.data
9577
- );
9578
- const { reserveX, reserveY, tokenXMint, tokenYMint } = this.program.coder.accounts.decode(
9579
- "lbPair",
9580
- lbPairAccInfo.data
9581
- );
9582
- const upperBinArray = this.program.coder.accounts.decode("binArray", upperBinArrayInfoAcc.data);
9583
- const lowerBinArray = this.program.coder.accounts.decode("binArray", lowerBinArrayInfoAcc.data);
9584
- const bins = await this.getBins(
9585
- this.pubkey,
9586
- positionLowerBinId,
9587
- positionUpperBinId,
9588
- this.tokenX.decimal,
9589
- this.tokenY.decimal,
9590
- lowerBinArray,
9591
- upperBinArray
9592
- );
9593
- const positionHasNoLiquidity = bins.every(({ supply }) => supply.isZero());
9594
- if (positionHasNoLiquidity) {
9595
- throw new Error("No liquidity to remove");
9596
- }
9597
- const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(positionLowerBinId));
9802
+ const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
9803
+ const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
9804
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
9598
9805
  const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
9599
9806
  const [binArrayLower] = deriveBinArray(
9600
9807
  lbPair,
@@ -9710,11 +9917,13 @@ var DLMM = class {
9710
9917
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
9711
9918
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
9712
9919
  }
9713
- const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinIdToRemove));
9714
- const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinIdToRemove));
9920
+ const minBinId = Math.min(...binIds);
9921
+ const maxBinId = Math.max(...binIds);
9922
+ const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
9923
+ const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
9715
9924
  const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
9716
9925
  const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
9717
- const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
9926
+ const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
9718
9927
  position,
9719
9928
  lbPair,
9720
9929
  userTokenX,
@@ -9831,7 +10040,7 @@ var DLMM = class {
9831
10040
  swapForY,
9832
10041
  activeId,
9833
10042
  this.lbPair,
9834
- _nullishCoalesce(_optionalChain([this, 'access', _61 => _61.binArrayBitmapExtension, 'optionalAccess', _62 => _62.account]), () => ( null)),
10043
+ _nullishCoalesce(_optionalChain([this, 'access', _72 => _72.binArrayBitmapExtension, 'optionalAccess', _73 => _73.account]), () => ( null)),
9835
10044
  binArrays
9836
10045
  );
9837
10046
  if (binArrayAccountToSwap == null) {
@@ -9935,7 +10144,7 @@ var DLMM = class {
9935
10144
  swapForY,
9936
10145
  activeId,
9937
10146
  this.lbPair,
9938
- _nullishCoalesce(_optionalChain([this, 'access', _63 => _63.binArrayBitmapExtension, 'optionalAccess', _64 => _64.account]), () => ( null)),
10147
+ _nullishCoalesce(_optionalChain([this, 'access', _74 => _74.binArrayBitmapExtension, 'optionalAccess', _75 => _75.account]), () => ( null)),
9939
10148
  binArrays
9940
10149
  );
9941
10150
  if (binArrayAccountToSwap == null) {
@@ -10660,6 +10869,140 @@ var DLMM = class {
10660
10869
  addLiquidityIxs
10661
10870
  };
10662
10871
  }
10872
+ /**
10873
+ * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
10874
+ * @param
10875
+ * - `owner`: The public key of the positions owner.
10876
+ * - `base`: Base key
10877
+ * - `seedAmount`: Token X lamport amount to be seeded to the pool.
10878
+ * - `price`: TokenX/TokenY Price in UI format
10879
+ * - `roundingUp`: Whether to round up the price
10880
+ * - `feeOwner`: Position fee owner
10881
+ * - `operator`: Operator of the position. Operator able to manage the position on behalf of the position owner. However, liquidity withdrawal issue by the operator can only send to the position owner.
10882
+ * - `lockReleasePoint`: The lock release point of the position.
10883
+ *
10884
+ * The returned instructions need to be executed sequentially if it was separated into multiple transactions.
10885
+ * @returns {Promise<TransactionInstruction[]>}
10886
+ */
10887
+ async seedLiquiditySingleBin(owner, base, seedAmount, price, roundingUp, feeOwner, operator, lockReleasePoint) {
10888
+ const pricePerLamport = DLMM.getPricePerLamport(this.tokenX.decimal, this.tokenY.decimal, price);
10889
+ const binIdNumber = DLMM.getBinIdFromPrice(pricePerLamport, this.lbPair.binStep, !roundingUp);
10890
+ const binId = new (0, _anchor.BN)(binIdNumber);
10891
+ const lowerBinArrayIndex = binIdToBinArrayIndex(binId);
10892
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
10893
+ const [lowerBinArray] = deriveBinArray(this.pubkey, lowerBinArrayIndex, this.program.programId);
10894
+ const [upperBinArray] = deriveBinArray(this.pubkey, upperBinArrayIndex, this.program.programId);
10895
+ const [positionPda] = derivePosition(this.pubkey, base, binId, new (0, _anchor.BN)(1), this.program.programId);
10896
+ const operatorTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
10897
+ this.lbPair.tokenXMint,
10898
+ operator,
10899
+ true
10900
+ );
10901
+ const ownerTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
10902
+ this.lbPair.tokenXMint,
10903
+ owner,
10904
+ true
10905
+ );
10906
+ const preInstructions = [];
10907
+ const [
10908
+ { ataPubKey: userTokenX, ix: createPayerTokenXIx },
10909
+ { ataPubKey: userTokenY, ix: createPayerTokenYIx }
10910
+ ] = await Promise.all([
10911
+ getOrCreateATAInstruction(
10912
+ this.program.provider.connection,
10913
+ this.tokenX.publicKey,
10914
+ owner
10915
+ ),
10916
+ getOrCreateATAInstruction(
10917
+ this.program.provider.connection,
10918
+ this.tokenY.publicKey,
10919
+ owner
10920
+ )
10921
+ ]);
10922
+ createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
10923
+ createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
10924
+ let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(this.pubkey, this.program.programId);
10925
+ const accounts = await this.program.provider.connection.getMultipleAccountsInfo([
10926
+ lowerBinArray,
10927
+ upperBinArray,
10928
+ positionPda,
10929
+ binArrayBitmapExtension
10930
+ ]);
10931
+ if (isOverflowDefaultBinArrayBitmap(lowerBinArrayIndex)) {
10932
+ const bitmapExtensionAccount = accounts[3];
10933
+ if (!bitmapExtensionAccount) {
10934
+ preInstructions.push(await this.program.methods.initializeBinArrayBitmapExtension().accounts({
10935
+ binArrayBitmapExtension,
10936
+ funder: owner,
10937
+ lbPair: this.pubkey
10938
+ }).instruction());
10939
+ }
10940
+ } else {
10941
+ binArrayBitmapExtension = this.program.programId;
10942
+ }
10943
+ const lowerBinArrayAccount = accounts[0];
10944
+ const upperBinArrayAccount = accounts[1];
10945
+ const positionAccount = accounts[2];
10946
+ if (!lowerBinArrayAccount) {
10947
+ preInstructions.push(
10948
+ await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
10949
+ binArray: lowerBinArray,
10950
+ funder: owner,
10951
+ lbPair: this.pubkey
10952
+ }).instruction()
10953
+ );
10954
+ }
10955
+ if (!upperBinArrayAccount) {
10956
+ preInstructions.push(
10957
+ await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
10958
+ binArray: upperBinArray,
10959
+ funder: owner,
10960
+ lbPair: this.pubkey
10961
+ }).instruction()
10962
+ );
10963
+ }
10964
+ if (!positionAccount) {
10965
+ preInstructions.push(
10966
+ await this.program.methods.initializePositionByOperator(binId.toNumber(), 1, feeOwner, lockReleasePoint).accounts({
10967
+ payer: owner,
10968
+ base,
10969
+ position: positionPda,
10970
+ lbPair: this.pubkey,
10971
+ owner,
10972
+ operator,
10973
+ operatorTokenX,
10974
+ ownerTokenX
10975
+ }).instruction()
10976
+ );
10977
+ }
10978
+ const binLiquidityDist = {
10979
+ binId: binIdNumber,
10980
+ distributionX: BASIS_POINT_MAX,
10981
+ distributionY: 0
10982
+ };
10983
+ const addLiquidityParams = {
10984
+ amountX: seedAmount,
10985
+ amountY: new (0, _anchor.BN)(0),
10986
+ binLiquidityDist: [binLiquidityDist]
10987
+ };
10988
+ const depositLiquidityIx = await this.program.methods.addLiquidity(addLiquidityParams).accounts({
10989
+ position: positionPda,
10990
+ lbPair: this.pubkey,
10991
+ binArrayBitmapExtension,
10992
+ userTokenX,
10993
+ userTokenY,
10994
+ reserveX: this.lbPair.reserveX,
10995
+ reserveY: this.lbPair.reserveY,
10996
+ tokenXMint: this.lbPair.tokenXMint,
10997
+ tokenYMint: this.lbPair.tokenYMint,
10998
+ binArrayLower: lowerBinArray,
10999
+ binArrayUpper: upperBinArray,
11000
+ sender: owner,
11001
+ tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
11002
+ tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
11003
+ }).instruction();
11004
+ return [...preInstructions, depositLiquidityIx];
11005
+ }
10663
11006
  /**
10664
11007
  * Initializes bin arrays for the given bin array indexes if it wasn't initialized.
10665
11008
  *
@@ -10869,7 +11212,7 @@ var DLMM = class {
10869
11212
  swapForY,
10870
11213
  new (0, _anchor.BN)(activeBinId),
10871
11214
  this.lbPair,
10872
- _nullishCoalesce(_optionalChain([this, 'access', _65 => _65.binArrayBitmapExtension, 'optionalAccess', _66 => _66.account]), () => ( null))
11215
+ _nullishCoalesce(_optionalChain([this, 'access', _76 => _76.binArrayBitmapExtension, 'optionalAccess', _77 => _77.account]), () => ( null))
10873
11216
  );
10874
11217
  if (toBinArrayIndex === null)
10875
11218
  return true;
@@ -10906,7 +11249,7 @@ var DLMM = class {
10906
11249
  swapForY,
10907
11250
  new (0, _anchor.BN)(activeBinId),
10908
11251
  this.lbPair,
10909
- _nullishCoalesce(_optionalChain([this, 'access', _67 => _67.binArrayBitmapExtension, 'optionalAccess', _68 => _68.account]), () => ( null))
11252
+ _nullishCoalesce(_optionalChain([this, 'access', _78 => _78.binArrayBitmapExtension, 'optionalAccess', _79 => _79.account]), () => ( null))
10910
11253
  );
10911
11254
  const accountsToFetch = [];
10912
11255
  const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
@@ -10937,13 +11280,13 @@ var DLMM = class {
10937
11280
  let fromBinArray = null;
10938
11281
  let toBinArray = null;
10939
11282
  let binArrayBitmapExtension = null;
10940
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _69 => _69[0]])) {
11283
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _80 => _80[0]])) {
10941
11284
  binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
10942
11285
  }
10943
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _70 => _70[1]])) {
11286
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _81 => _81[1]])) {
10944
11287
  fromBinArray = fromBinArrayPubkey;
10945
11288
  }
10946
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _71 => _71[2]]) && !!toBinArrayIndex) {
11289
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _82 => _82[2]]) && !!toBinArrayIndex) {
10947
11290
  toBinArray = toBinArrayPubkey;
10948
11291
  }
10949
11292
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
@@ -11268,7 +11611,12 @@ var DLMM = class {
11268
11611
  let totalYAmount = new (0, _decimaljs2.default)(0);
11269
11612
  bins.forEach((bin, idx) => {
11270
11613
  const binSupply = new (0, _decimaljs2.default)(bin.supply.toString());
11271
- const posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
11614
+ let posShare;
11615
+ if (bin.version === 1 && version === 0 /* V1 */) {
11616
+ posShare = new (0, _decimaljs2.default)(posShares[idx].shln(64).toString());
11617
+ } else {
11618
+ posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
11619
+ }
11272
11620
  const positionXAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
11273
11621
  const positionYAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
11274
11622
  totalXAmount = totalXAmount.add(positionXAmount);