@meteora-ag/dlmm 1.0.52-rc.6 → 1.0.52-rc.7

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 CHANGED
@@ -2622,7 +2622,7 @@ type LbClmm = {
2622
2622
  ];
2623
2623
  "accounts": [
2624
2624
  {
2625
- "name": "BinArrayBitmapExtension";
2625
+ "name": "binArrayBitmapExtension";
2626
2626
  "type": {
2627
2627
  "kind": "struct";
2628
2628
  "fields": [
@@ -2668,7 +2668,7 @@ type LbClmm = {
2668
2668
  };
2669
2669
  },
2670
2670
  {
2671
- "name": "BinArray";
2671
+ "name": "binArray";
2672
2672
  "docs": [
2673
2673
  "An account to contain a range of bin. For example: Bin 100 <-> 200.",
2674
2674
  "For example:",
@@ -2717,7 +2717,7 @@ type LbClmm = {
2717
2717
  };
2718
2718
  },
2719
2719
  {
2720
- "name": "LbPair";
2720
+ "name": "lbPair";
2721
2721
  "type": {
2722
2722
  "kind": "struct";
2723
2723
  "fields": [
@@ -2965,7 +2965,7 @@ type LbClmm = {
2965
2965
  };
2966
2966
  },
2967
2967
  {
2968
- "name": "Oracle";
2968
+ "name": "oracle";
2969
2969
  "type": {
2970
2970
  "kind": "struct";
2971
2971
  "fields": [
@@ -2994,7 +2994,7 @@ type LbClmm = {
2994
2994
  };
2995
2995
  },
2996
2996
  {
2997
- "name": "Position";
2997
+ "name": "position";
2998
2998
  "type": {
2999
2999
  "kind": "struct";
3000
3000
  "fields": [
@@ -3115,7 +3115,7 @@ type LbClmm = {
3115
3115
  };
3116
3116
  },
3117
3117
  {
3118
- "name": "PositionV2";
3118
+ "name": "positionV2";
3119
3119
  "type": {
3120
3120
  "kind": "struct";
3121
3121
  "fields": [
@@ -3264,7 +3264,7 @@ type LbClmm = {
3264
3264
  };
3265
3265
  },
3266
3266
  {
3267
- "name": "PresetParameter";
3267
+ "name": "presetParameter";
3268
3268
  "type": {
3269
3269
  "kind": "struct";
3270
3270
  "fields": [
@@ -5147,20 +5147,20 @@ interface TokenReserve {
5147
5147
  decimal: number;
5148
5148
  }
5149
5149
  type ClmmProgram = Program<LbClmm>;
5150
- type LbPair = IdlAccounts<LbClmm>["LbPair"];
5151
- type LbPairAccount = ProgramAccount<IdlAccounts<LbClmm>["LbPair"]>;
5150
+ type LbPair = IdlAccounts<LbClmm>["lbPair"];
5151
+ type LbPairAccount = ProgramAccount<IdlAccounts<LbClmm>["lbPair"]>;
5152
5152
  type Bin = IdlTypes<LbClmm>["Bin"];
5153
- type BinArray = IdlAccounts<LbClmm>["BinArray"];
5154
- type BinArrayAccount = ProgramAccount<IdlAccounts<LbClmm>["BinArray"]>;
5155
- type Position = IdlAccounts<LbClmm>["Position"];
5156
- type PositionV2 = IdlAccounts<LbClmm>["PositionV2"];
5157
- type vParameters = IdlAccounts<LbClmm>["LbPair"]["vParameters"];
5158
- type sParameters = IdlAccounts<LbClmm>["LbPair"]["parameters"];
5153
+ type BinArray = IdlAccounts<LbClmm>["binArray"];
5154
+ type BinArrayAccount = ProgramAccount<IdlAccounts<LbClmm>["binArray"]>;
5155
+ type Position = IdlAccounts<LbClmm>["position"];
5156
+ type PositionV2 = IdlAccounts<LbClmm>["positionV2"];
5157
+ type vParameters = IdlAccounts<LbClmm>["lbPair"]["vParameters"];
5158
+ type sParameters = IdlAccounts<LbClmm>["lbPair"]["parameters"];
5159
5159
  type InitPermissionPairIx = IdlTypes<LbClmm>["InitPermissionPairIx"];
5160
5160
  type BinLiquidityDistribution = IdlTypes<LbClmm>["BinLiquidityDistribution"];
5161
5161
  type BinLiquidityReduction = IdlTypes<LbClmm>["BinLiquidityReduction"];
5162
- type BinArrayBitmapExtensionAccount = ProgramAccount<IdlAccounts<LbClmm>["BinArrayBitmapExtension"]>;
5163
- type BinArrayBitmapExtension = IdlAccounts<LbClmm>["BinArrayBitmapExtension"];
5162
+ type BinArrayBitmapExtensionAccount = ProgramAccount<IdlAccounts<LbClmm>["binArrayBitmapExtension"]>;
5163
+ type BinArrayBitmapExtension = IdlAccounts<LbClmm>["binArrayBitmapExtension"];
5164
5164
  type LiquidityParameterByWeight = IdlTypes<LbClmm>["LiquidityParameterByWeight"];
5165
5165
  type LiquidityOneSideParameter = IdlTypes<LbClmm>["LiquidityOneSideParameter"];
5166
5166
  type LiquidityParameterByStrategy = IdlTypes<LbClmm>["LiquidityParameterByStrategy"];
@@ -5921,6 +5921,10 @@ declare class DLMM {
5921
5921
  */
5922
5922
  syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5923
5923
  getMaxPriceInBinArrays(binArrayAccounts: BinArrayAccount[]): Promise<string>;
5924
+ getAmountOutWithdrawSingleSide(maxLiquidityShare: BN, price: BN, bin: Bin, isWithdrawForY: boolean): {
5925
+ withdrawAmount: BN;
5926
+ };
5927
+ getWithdrawSingleSideAmount(positionPubkey: PublicKey, isWithdrawForY: boolean): Promise<BN>;
5924
5928
  /** Private static method */
5925
5929
  private static getBinArrays;
5926
5930
  private static getClaimableLMReward;
package/dist/index.js CHANGED
@@ -2626,7 +2626,7 @@ var IDL = {
2626
2626
  ],
2627
2627
  "accounts": [
2628
2628
  {
2629
- "name": "BinArrayBitmapExtension",
2629
+ "name": "binArrayBitmapExtension",
2630
2630
  "type": {
2631
2631
  "kind": "struct",
2632
2632
  "fields": [
@@ -2672,7 +2672,7 @@ var IDL = {
2672
2672
  }
2673
2673
  },
2674
2674
  {
2675
- "name": "BinArray",
2675
+ "name": "binArray",
2676
2676
  "docs": [
2677
2677
  "An account to contain a range of bin. For example: Bin 100 <-> 200.",
2678
2678
  "For example:",
@@ -2721,7 +2721,7 @@ var IDL = {
2721
2721
  }
2722
2722
  },
2723
2723
  {
2724
- "name": "LbPair",
2724
+ "name": "lbPair",
2725
2725
  "type": {
2726
2726
  "kind": "struct",
2727
2727
  "fields": [
@@ -2969,7 +2969,7 @@ var IDL = {
2969
2969
  }
2970
2970
  },
2971
2971
  {
2972
- "name": "Oracle",
2972
+ "name": "oracle",
2973
2973
  "type": {
2974
2974
  "kind": "struct",
2975
2975
  "fields": [
@@ -2998,7 +2998,7 @@ var IDL = {
2998
2998
  }
2999
2999
  },
3000
3000
  {
3001
- "name": "Position",
3001
+ "name": "position",
3002
3002
  "type": {
3003
3003
  "kind": "struct",
3004
3004
  "fields": [
@@ -3119,7 +3119,7 @@ var IDL = {
3119
3119
  }
3120
3120
  },
3121
3121
  {
3122
- "name": "PositionV2",
3122
+ "name": "positionV2",
3123
3123
  "type": {
3124
3124
  "kind": "struct",
3125
3125
  "fields": [
@@ -3268,7 +3268,7 @@ var IDL = {
3268
3268
  }
3269
3269
  },
3270
3270
  {
3271
- "name": "PresetParameter",
3271
+ "name": "presetParameter",
3272
3272
  "type": {
3273
3273
  "kind": "struct",
3274
3274
  "fields": [
@@ -7304,7 +7304,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7304
7304
  LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _18 => _18.cluster]), () => ( "mainnet-beta"))],
7305
7305
  provider
7306
7306
  );
7307
- const poolAccount = await program.account.LbPair.fetchNullable(
7307
+ const poolAccount = await program.account.lbPair.fetchNullable(
7308
7308
  new (0, _web3js.PublicKey)(poolAddress)
7309
7309
  );
7310
7310
  if (!poolAccount)
@@ -7324,7 +7324,7 @@ function chunks(array, size) {
7324
7324
  async function chunkedFetchMultiplePoolAccount(program, pks, chunkSize = 100) {
7325
7325
  const accounts = (await Promise.all(
7326
7326
  chunks(pks, chunkSize).map(
7327
- (chunk) => program.account.LbPair.fetchMultiple(chunk)
7327
+ (chunk) => program.account.lbPair.fetchMultiple(chunk)
7328
7328
  )
7329
7329
  )).flat();
7330
7330
  return accounts.filter(Boolean);
@@ -7332,7 +7332,7 @@ async function chunkedFetchMultiplePoolAccount(program, pks, chunkSize = 100) {
7332
7332
  async function chunkedFetchMultipleBinArrayBitmapExtensionAccount(program, pks, chunkSize = 100) {
7333
7333
  const accounts = (await Promise.all(
7334
7334
  chunks(pks, chunkSize).map(
7335
- (chunk) => program.account.BinArrayBitmapExtension.fetchMultiple(chunk)
7335
+ (chunk) => program.account.binArrayBitmapExtension.fetchMultiple(chunk)
7336
7336
  )
7337
7337
  )).flat();
7338
7338
  return accounts;
@@ -7474,7 +7474,7 @@ var DLMM = class {
7474
7474
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _21 => _21.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _22 => _22.cluster]), () => ( "mainnet-beta"))])),
7475
7475
  provider
7476
7476
  );
7477
- return program.account.LbPair.all();
7477
+ return program.account.lbPair.all();
7478
7478
  }
7479
7479
  static async getPairPubkeyIfExists(connection, tokenX, tokenY, binStep, baseFactor, opt) {
7480
7480
  const cluster = _optionalChain([opt, 'optionalAccess', _23 => _23.cluster]) || "mainnet-beta";
@@ -7496,7 +7496,7 @@ var DLMM = class {
7496
7496
  baseFactor,
7497
7497
  program.programId
7498
7498
  );
7499
- const account2 = await program.account.LbPair.fetchNullable(lbPair2Key);
7499
+ const account2 = await program.account.lbPair.fetchNullable(lbPair2Key);
7500
7500
  if (account2)
7501
7501
  return lbPair2Key;
7502
7502
  const [lbPairKey] = deriveLbPair(
@@ -7505,7 +7505,7 @@ var DLMM = class {
7505
7505
  binStep,
7506
7506
  program.programId
7507
7507
  );
7508
- const account = await program.account.LbPair.fetchNullable(lbPairKey);
7508
+ const account = await program.account.lbPair.fetchNullable(lbPairKey);
7509
7509
  if (account && account.parameters.baseFactor === baseFactor.toNumber()) {
7510
7510
  return lbPairKey;
7511
7511
  }
@@ -7736,7 +7736,7 @@ var DLMM = class {
7736
7736
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _38 => _38.cluster]), () => ( "mainnet-beta"))])),
7737
7737
  provider
7738
7738
  );
7739
- const presetParameter = await program.account.PresetParameter.all();
7739
+ const presetParameter = await program.account.presetParameter.all();
7740
7740
  return presetParameter;
7741
7741
  }
7742
7742
  /**
@@ -7763,7 +7763,7 @@ var DLMM = class {
7763
7763
  provider
7764
7764
  );
7765
7765
  const [positions, positionsV2] = await Promise.all([
7766
- program.account.Position.all([
7766
+ program.account.position.all([
7767
7767
  {
7768
7768
  memcmp: {
7769
7769
  bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
@@ -7771,7 +7771,7 @@ var DLMM = class {
7771
7771
  }
7772
7772
  }
7773
7773
  ]),
7774
- program.account.PositionV2.all([
7774
+ program.account.positionV2.all([
7775
7775
  {
7776
7776
  memcmp: {
7777
7777
  bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
@@ -8118,7 +8118,7 @@ var DLMM = class {
8118
8118
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _60 => _60.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8119
8119
  provider
8120
8120
  );
8121
- const positionsState = await program.account.Position.fetchMultiple(
8121
+ const positionsState = await program.account.position.fetchMultiple(
8122
8122
  positions
8123
8123
  );
8124
8124
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
@@ -8331,7 +8331,7 @@ var DLMM = class {
8331
8331
  * @returns a Promise that resolves to an array of BinArrayAccount objects.
8332
8332
  */
8333
8333
  async getBinArrays() {
8334
- return this.program.account.BinArray.all([
8334
+ return this.program.account.binArray.all([
8335
8335
  {
8336
8336
  memcmp: {
8337
8337
  bytes: _bytes.bs58.encode(this.pubkey.toBuffer()),
@@ -8560,7 +8560,7 @@ var DLMM = class {
8560
8560
  * @returns an object with two properties: "binId" which is a number, and "price" which is a string.
8561
8561
  */
8562
8562
  async getActiveBin() {
8563
- const { activeId } = await this.program.account.LbPair.fetch(this.pubkey);
8563
+ const { activeId } = await this.program.account.lbPair.fetch(this.pubkey);
8564
8564
  const [activeBinState] = await this.getBins(
8565
8565
  this.pubkey,
8566
8566
  activeId,
@@ -8610,7 +8610,7 @@ var DLMM = class {
8610
8610
  async getPositionsByUserAndLbPair(userPubKey) {
8611
8611
  const promiseResults = await Promise.all([
8612
8612
  this.getActiveBin(),
8613
- userPubKey && this.program.account.Position.all([
8613
+ userPubKey && this.program.account.position.all([
8614
8614
  {
8615
8615
  memcmp: {
8616
8616
  bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
@@ -8624,7 +8624,7 @@ var DLMM = class {
8624
8624
  }
8625
8625
  }
8626
8626
  ]),
8627
- userPubKey && this.program.account.PositionV2.all([
8627
+ userPubKey && this.program.account.positionV2.all([
8628
8628
  {
8629
8629
  memcmp: {
8630
8630
  bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
@@ -9311,7 +9311,7 @@ var DLMM = class {
9311
9311
  slippage
9312
9312
  }) {
9313
9313
  const maxActiveBinSlippage = slippage ? Math.ceil(slippage / (this.lbPair.binStep / 100)) : MAX_ACTIVE_BIN_SLIPPAGE;
9314
- const positionAccount = await this.program.account.PositionV2.fetch(
9314
+ const positionAccount = await this.program.account.positionV2.fetch(
9315
9315
  positionPubKey
9316
9316
  );
9317
9317
  const { lowerBinId, upperBinId, binIds } = this.processXYAmountDistribution(xYAmountDistribution);
@@ -9510,8 +9510,8 @@ var DLMM = class {
9510
9510
  bps,
9511
9511
  shouldClaimAndClose = false
9512
9512
  }) {
9513
- const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.PositionV2.fetch(position);
9514
- const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.LbPair.fetch(lbPair);
9513
+ const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
9514
+ const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
9515
9515
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
9516
9516
  const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
9517
9517
  const [binArrayLower] = deriveBinArray(
@@ -9677,9 +9677,8 @@ var DLMM = class {
9677
9677
  binIds,
9678
9678
  removeLiquidityForY = false
9679
9679
  }) {
9680
- const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.PositionV2.fetch(position);
9681
- console.log("removeLiquidityFor2Y", removeLiquidityForY);
9682
- const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.LbPair.fetch(lbPair);
9680
+ const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
9681
+ const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
9683
9682
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
9684
9683
  const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
9685
9684
  const [binArrayLower] = deriveBinArray(
@@ -9753,7 +9752,7 @@ var DLMM = class {
9753
9752
  owner,
9754
9753
  position
9755
9754
  }) {
9756
- const { lowerBinId } = await this.program.account.PositionV2.fetch(
9755
+ const { lowerBinId } = await this.program.account.positionV2.fetch(
9757
9756
  position.publicKey
9758
9757
  );
9759
9758
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
@@ -9992,7 +9991,7 @@ var DLMM = class {
9992
9991
  user,
9993
9992
  binArraysPubkey
9994
9993
  }) {
9995
- const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.LbPair.fetch(lbPair);
9994
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
9996
9995
  const preInstructions = [computeBudgetIx()];
9997
9996
  const [
9998
9997
  { ataPubKey: userTokenIn, ix: createInTokenAccountIx },
@@ -10077,7 +10076,7 @@ var DLMM = class {
10077
10076
  priceImpact,
10078
10077
  binArraysPubkey
10079
10078
  }) {
10080
- const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.LbPair.fetch(lbPair);
10079
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10081
10080
  const preInstructions = [computeBudgetIx()];
10082
10081
  const [
10083
10082
  { ataPubKey: userTokenIn, ix: createInTokenAccountIx },
@@ -10166,7 +10165,7 @@ var DLMM = class {
10166
10165
  user,
10167
10166
  binArraysPubkey
10168
10167
  }) {
10169
- const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.LbPair.fetch(lbPair);
10168
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10170
10169
  const preInstructions = [computeBudgetIx()];
10171
10170
  const [
10172
10171
  { ataPubKey: userTokenIn, ix: createInTokenAccountIx },
@@ -10961,9 +10960,111 @@ var DLMM = class {
10961
10960
  Number(binPriceWithLastLiquidity) / (2 ** 64 - 1)
10962
10961
  );
10963
10962
  }
10963
+ getAmountOutWithdrawSingleSide(maxLiquidityShare, price, bin, isWithdrawForY) {
10964
+ const amountX = mulDiv(
10965
+ maxLiquidityShare,
10966
+ bin.amountX,
10967
+ bin.liquiditySupply,
10968
+ 1 /* Down */
10969
+ );
10970
+ const amountY = mulDiv(
10971
+ maxLiquidityShare,
10972
+ bin.amountY,
10973
+ bin.liquiditySupply,
10974
+ 1 /* Down */
10975
+ );
10976
+ const amount0 = isWithdrawForY ? amountX : amountY;
10977
+ const amount1 = isWithdrawForY ? amountY : amountX;
10978
+ const remainAmountX = bin.amountX.sub(amountX);
10979
+ const remainAmountY = bin.amountY.sub(amountY);
10980
+ if (amount0.eq(new (0, _anchor.BN)(0))) {
10981
+ return {
10982
+ withdrawAmount: amount1
10983
+ };
10984
+ }
10985
+ let maxAmountOut = isWithdrawForY ? remainAmountY : remainAmountX;
10986
+ let maxAmountIn = isWithdrawForY ? shlDiv(remainAmountY, price, SCALE_OFFSET, 0 /* Up */) : mulShr(remainAmountX, price, SCALE_OFFSET, 0 /* Up */);
10987
+ let maxFee = computeFee(
10988
+ this.lbPair.binStep,
10989
+ this.lbPair.parameters,
10990
+ this.lbPair.vParameters,
10991
+ maxAmountIn
10992
+ );
10993
+ maxAmountIn = maxAmountIn.add(maxFee);
10994
+ if (amount0.gt(maxAmountIn)) {
10995
+ return {
10996
+ withdrawAmount: maxAmountOut
10997
+ };
10998
+ }
10999
+ const fee = computeFeeFromAmount(
11000
+ this.lbPair.binStep,
11001
+ this.lbPair.parameters,
11002
+ this.lbPair.vParameters,
11003
+ amount0
11004
+ );
11005
+ const amount0AfterFee = amount0.sub(fee);
11006
+ const amountOut = isWithdrawForY ? mulShr(price, amount0AfterFee, SCALE_OFFSET, 1 /* Down */) : shlDiv(amount0AfterFee, price, SCALE_OFFSET, 1 /* Down */);
11007
+ return {
11008
+ withdrawAmount: amount1.add(amountOut > maxAmountOut ? maxAmountOut : amountOut)
11009
+ };
11010
+ }
11011
+ async getWithdrawSingleSideAmount(positionPubkey, isWithdrawForY) {
11012
+ let totalWithdrawAmount = new (0, _anchor.BN)(0);
11013
+ let _lowerBinArray;
11014
+ let _upperBinArray;
11015
+ const position = await this.program.account.positionV2.fetch(
11016
+ positionPubkey
11017
+ );
11018
+ const lowerBinArrayIdx = binIdToBinArrayIndex(new (0, _anchor.BN)(position.lowerBinId));
11019
+ const [lowerBinArray] = deriveBinArray(
11020
+ position.lbPair,
11021
+ lowerBinArrayIdx,
11022
+ this.program.programId
11023
+ );
11024
+ const upperBinArrayIdx = lowerBinArrayIdx.add(new (0, _anchor.BN)(1));
11025
+ const [upperBinArray] = deriveBinArray(
11026
+ position.lbPair,
11027
+ upperBinArrayIdx,
11028
+ this.program.programId
11029
+ );
11030
+ [_lowerBinArray, _upperBinArray] = await this.program.account.binArray.fetchMultiple([
11031
+ lowerBinArray,
11032
+ upperBinArray
11033
+ ]);
11034
+ if (!_lowerBinArray || !_upperBinArray)
11035
+ throw new Error("BinArray not found");
11036
+ for (let idx = 0; idx < position.liquidityShares.length; idx++) {
11037
+ const shareToRemove = position.liquidityShares[idx];
11038
+ if (shareToRemove.eq(new (0, _anchor.BN)(0))) {
11039
+ continue;
11040
+ }
11041
+ const binId = new (0, _anchor.BN)(position.lowerBinId).add(new (0, _anchor.BN)(idx));
11042
+ const binArrayIndex = binIdToBinArrayIndex(binId);
11043
+ const binArray = binArrayIndex.eq(lowerBinArrayIdx) ? _lowerBinArray : _upperBinArray;
11044
+ const bin = getBinFromBinArray(binId.toNumber(), binArray);
11045
+ if (isWithdrawForY) {
11046
+ if (binId.gt(new (0, _anchor.BN)(this.lbPair.activeId))) {
11047
+ break;
11048
+ }
11049
+ } else {
11050
+ if (binId.lt(new (0, _anchor.BN)(this.lbPair.activeId))) {
11051
+ continue;
11052
+ }
11053
+ }
11054
+ const price = getQPriceFromId(binId, new (0, _anchor.BN)(this.lbPair.binStep));
11055
+ const { withdrawAmount } = this.getAmountOutWithdrawSingleSide(
11056
+ shareToRemove,
11057
+ price,
11058
+ bin,
11059
+ isWithdrawForY
11060
+ );
11061
+ totalWithdrawAmount = totalWithdrawAmount.add(withdrawAmount);
11062
+ }
11063
+ return totalWithdrawAmount;
11064
+ }
10964
11065
  /** Private static method */
10965
11066
  static async getBinArrays(program, lbPairPubkey) {
10966
- return program.account.BinArray.all([
11067
+ return program.account.binArray.all([
10967
11068
  {
10968
11069
  memcmp: {
10969
11070
  bytes: _bytes.bs58.encode(lbPairPubkey.toBuffer()),
@@ -10992,7 +11093,7 @@ var DLMM = class {
10992
11093
  upperBinArrayIdx,
10993
11094
  program.programId
10994
11095
  );
10995
- [_lowerBinArray, _upperBinArray] = await program.account.BinArray.fetchMultiple([
11096
+ [_lowerBinArray, _upperBinArray] = await program.account.binArray.fetchMultiple([
10996
11097
  lowerBinArray2,
10997
11098
  upperBinArray2
10998
11099
  ]);
@@ -11063,7 +11164,7 @@ var DLMM = class {
11063
11164
  upperBinArrayIdx,
11064
11165
  program.programId
11065
11166
  );
11066
- [_lowerBinArray, _upperBinArray] = await program.account.BinArray.fetchMultiple([
11167
+ [_lowerBinArray, _upperBinArray] = await program.account.binArray.fetchMultiple([
11067
11168
  lowerBinArray2,
11068
11169
  upperBinArray2
11069
11170
  ]);
@@ -11268,7 +11369,7 @@ var DLMM = class {
11268
11369
  lowerBinArrayIndex,
11269
11370
  this.program.programId
11270
11371
  );
11271
- const binArray = await _asyncNullishCoalesce(lowerBinArrays, async () => ( await this.program.account.BinArray.fetch(binArrayPubKey).catch(() => {
11372
+ const binArray = await _asyncNullishCoalesce(lowerBinArrays, async () => ( await this.program.account.binArray.fetch(binArrayPubKey).catch(() => {
11272
11373
  const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
11273
11374
  const binArrayBins = [];
11274
11375
  for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
@@ -11323,7 +11424,7 @@ var DLMM = class {
11323
11424
  );
11324
11425
  const binArrays = await (async () => {
11325
11426
  if (!lowerBinArrays || !upperBinArrays) {
11326
- return (await this.program.account.BinArray.fetchMultiple([
11427
+ return (await this.program.account.binArray.fetchMultiple([
11327
11428
  lowerBinArrayPubKey,
11328
11429
  upperBinArrayPubKey
11329
11430
  ])).filter((binArray) => binArray !== null);