@meteora-ag/dlmm 1.0.2-abcd12345.1 → 1.0.3

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
@@ -6126,17 +6126,58 @@ var DLMM = class {
6126
6126
  this.pubkey,
6127
6127
  this.program.programId
6128
6128
  )[0];
6129
- const binArrayBitmapExtensionState = await this.program.account.binArrayBitmapExtension.fetchNullable(
6130
- binArrayBitmapExtensionPubkey
6129
+ const [
6130
+ lbPairAccountInfo,
6131
+ binArrayBitmapExtensionAccountInfo,
6132
+ reserveXAccountInfo,
6133
+ reserveYAccountInfo
6134
+ ] = await chunkedGetMultipleAccountInfos(this.program.provider.connection, [
6135
+ this.pubkey,
6136
+ binArrayBitmapExtensionPubkey,
6137
+ this.lbPair.reserveX,
6138
+ this.lbPair.reserveY
6139
+ ]);
6140
+ const lbPairState = this.program.coder.accounts.decode(
6141
+ "lbPair",
6142
+ lbPairAccountInfo.data
6131
6143
  );
6132
- if (binArrayBitmapExtensionState) {
6133
- this.binArrayBitmapExtension = {
6134
- account: binArrayBitmapExtensionState,
6135
- publicKey: binArrayBitmapExtensionPubkey
6136
- };
6144
+ if (binArrayBitmapExtensionAccountInfo) {
6145
+ const binArrayBitmapExtensionState = this.program.coder.accounts.decode(
6146
+ "binArrayBitmapExtension",
6147
+ binArrayBitmapExtensionAccountInfo.data
6148
+ );
6149
+ if (binArrayBitmapExtensionState) {
6150
+ this.binArrayBitmapExtension = {
6151
+ account: binArrayBitmapExtensionState,
6152
+ publicKey: binArrayBitmapExtensionPubkey
6153
+ };
6154
+ }
6137
6155
  }
6138
- const newLbPair = await this.program.account.lbPair.fetch(this.pubkey);
6139
- this.lbPair = newLbPair;
6156
+ const reserveXBalance = _spltoken.AccountLayout.decode(reserveXAccountInfo.data);
6157
+ const reserveYBalance = _spltoken.AccountLayout.decode(reserveYAccountInfo.data);
6158
+ const [tokenXDecimal, tokenYDecimal] = await Promise.all([
6159
+ getTokenDecimals(
6160
+ this.program.provider.connection,
6161
+ lbPairState.tokenXMint
6162
+ ),
6163
+ getTokenDecimals(
6164
+ this.program.provider.connection,
6165
+ lbPairState.tokenYMint
6166
+ )
6167
+ ]);
6168
+ this.tokenX = {
6169
+ amount: reserveXBalance.amount,
6170
+ decimal: tokenXDecimal,
6171
+ publicKey: lbPairState.tokenXMint,
6172
+ reserve: lbPairState.reserveX
6173
+ };
6174
+ this.tokenY = {
6175
+ amount: reserveYBalance.amount,
6176
+ decimal: tokenYDecimal,
6177
+ publicKey: lbPairState.tokenYMint,
6178
+ reserve: lbPairState.reserveY
6179
+ };
6180
+ this.lbPair = lbPairState;
6140
6181
  }
6141
6182
  /**
6142
6183
  * The function `getBinArrays` returns an array of `BinArrayAccount` objects
@@ -7145,7 +7186,7 @@ var DLMM = class {
7145
7186
  const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
7146
7187
  const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
7147
7188
  const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
7148
- const removeLiquidityTx = await this.program.methods.removeAllLiquidity().accounts({
7189
+ const removeLiquidityTx = await this.program.methods.removeLiquidity(binLiquidityReduction).accounts({
7149
7190
  position,
7150
7191
  lbPair,
7151
7192
  userTokenX,
@@ -7733,10 +7774,6 @@ var DLMM = class {
7733
7774
  liquidityShares: posShares,
7734
7775
  lastUpdatedAt
7735
7776
  } = positionAccount;
7736
- console.log(
7737
- "\u{1F680} ~ DLMM ~ posShares:",
7738
- posShares.map((a) => a.toString())
7739
- );
7740
7777
  const bins = this.getBinsBetweenLowerAndUpperBound(
7741
7778
  lbPair,
7742
7779
  lowerBinId,
@@ -7754,16 +7791,7 @@ var DLMM = class {
7754
7791
  let totalXAmount = new (0, _decimaljs2.default)(0);
7755
7792
  let totalYAmount = new (0, _decimaljs2.default)(0);
7756
7793
  bins.forEach((bin, idx) => {
7757
- console.log(
7758
- "\u{1F680} ~ DLMM ~ bins.forEach ~ bin:",
7759
- bin.xAmount.toString(),
7760
- bin.yAmount.toString()
7761
- );
7762
7794
  const binSupply = new (0, _decimaljs2.default)(bin.supply.toString());
7763
- console.log(
7764
- "\u{1F680} ~ DLMM ~ bins.forEach ~ binSupply:",
7765
- binSupply.toString()
7766
- );
7767
7795
  let posShare;
7768
7796
  if (bin.version === 1 && version === 0 /* V1 */) {
7769
7797
  posShare = new (0, _decimaljs2.default)(posShares[idx].shln(64).toString());
@@ -7771,15 +7799,7 @@ var DLMM = class {
7771
7799
  posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
7772
7800
  }
7773
7801
  const positionXAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.xAmount.toString()).div(binSupply).floor();
7774
- console.log(
7775
- "\u{1F680} ~ DLMM ~ bins.forEach ~ positionXAmount:",
7776
- positionXAmount.toString()
7777
- );
7778
7802
  const positionYAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.yAmount.toString()).div(binSupply).floor();
7779
- console.log(
7780
- "\u{1F680} ~ DLMM ~ bins.forEach ~ positionYAmount:",
7781
- positionYAmount.toString()
7782
- );
7783
7803
  totalXAmount = totalXAmount.add(positionXAmount);
7784
7804
  totalYAmount = totalYAmount.add(positionYAmount);
7785
7805
  positionData.push({