@meteora-ag/dlmm 1.0.31 → 1.0.32-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/README.md CHANGED
@@ -231,6 +231,7 @@ try {
231
231
  | `claimSwapFee` | Claim swap fees for a specific position owned by a specific owner | `Promise<Transaction>` |
232
232
  | `claimAllSwapFee` | Claim swap fees for multiple positions owned by a specific owner | `Promise<Transaction>` |
233
233
  | `claimAllRewards` | Claim swap fees and LM rewards for multiple positions owned by a specific owner | `Promise<Transaction[]>` |
234
+ | `syncWithMarketPrice` | Sync the pool current active bin to match nearest market price bin | `Promise<Transaction>` |
234
235
 
235
236
  ```
236
237
 
package/dist/index.d.ts CHANGED
@@ -1768,6 +1768,39 @@ type LbClmm = {
1768
1768
  }
1769
1769
  ];
1770
1770
  },
1771
+ {
1772
+ name: "initializePresetParameterV2";
1773
+ accounts: [
1774
+ {
1775
+ name: "presetParameter";
1776
+ isMut: true;
1777
+ isSigner: false;
1778
+ },
1779
+ {
1780
+ name: "admin";
1781
+ isMut: true;
1782
+ isSigner: true;
1783
+ },
1784
+ {
1785
+ name: "systemProgram";
1786
+ isMut: false;
1787
+ isSigner: false;
1788
+ },
1789
+ {
1790
+ name: "rent";
1791
+ isMut: false;
1792
+ isSigner: false;
1793
+ }
1794
+ ];
1795
+ args: [
1796
+ {
1797
+ name: "ix";
1798
+ type: {
1799
+ defined: "InitPresetParametersIx";
1800
+ };
1801
+ }
1802
+ ];
1803
+ },
1771
1804
  {
1772
1805
  name: "closePresetParameter";
1773
1806
  accounts: [
@@ -2507,20 +2540,10 @@ type LbClmm = {
2507
2540
  docs: ["Status of the pair. Check PairStatus enum."];
2508
2541
  type: "u8";
2509
2542
  },
2510
- {
2511
- name: "requireBaseFactorSeed";
2512
- type: "u8";
2513
- },
2514
- {
2515
- name: "baseFactorSeed";
2516
- type: {
2517
- array: ["u8", 2];
2518
- };
2519
- },
2520
2543
  {
2521
2544
  name: "padding1";
2522
2545
  type: {
2523
- array: ["u8", 2];
2546
+ array: ["u8", 5];
2524
2547
  };
2525
2548
  },
2526
2549
  {
@@ -5243,6 +5266,15 @@ declare class DLMM {
5243
5266
  owner: PublicKey;
5244
5267
  positions: LbPosition[];
5245
5268
  }): Promise<Transaction[]>;
5269
+ canSyncWithMarketPrice(marketPrice: number, activeBinId: number): boolean;
5270
+ /**
5271
+ * The `syncWithMarketPrice` function is used to sync the liquidity pool with the market price.
5272
+ * @param
5273
+ * - `marketPrice`: The market price to sync with.
5274
+ * - `owner`: The public key of the owner of the liquidity pool.
5275
+ * @returns {Promise<Transaction>}
5276
+ */
5277
+ syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5246
5278
  /** Private static method */
5247
5279
  private static getBinArrays;
5248
5280
  private static getClaimableLMReward;
@@ -5262,19 +5294,9 @@ declare class DLMM {
5262
5294
  }
5263
5295
 
5264
5296
  /** private */
5265
- /**
5266
- *
5267
- * @deprecated Use derivePresetParameter2
5268
- */
5269
5297
  declare function derivePresetParameter(binStep: BN, programId: PublicKey): [PublicKey, number];
5270
- declare function derivePresetParameter2(binStep: BN, baseFactor: BN, programId: PublicKey): [PublicKey, number];
5271
- declare function deriveLbPair2(tokenX: PublicKey, tokenY: PublicKey, binStep: BN, baseFactor: BN, programId: PublicKey): [PublicKey, number];
5272
- /**
5273
- *
5274
- * @deprecated Use deriveLbPair2
5275
- */
5276
5298
  declare function deriveLbPair(tokenX: PublicKey, tokenY: PublicKey, binStep: BN, programId: PublicKey): [PublicKey, number];
5277
- declare function checkPoolExists(connection: Connection, tokenX: PublicKey, tokenY: PublicKey, binStep: BN, baseFactor: BN, programId: PublicKey): Promise<PublicKey | false>;
5299
+ declare function checkPoolExists(connection: Connection, tokenX: PublicKey, tokenY: PublicKey, binStep: BN, programId: PublicKey): Promise<PublicKey | false>;
5278
5300
  declare function derivePermissionLbPair(baseKey: PublicKey, tokenX: PublicKey, tokenY: PublicKey, binStep: BN, programId: PublicKey): [PublicKey, number];
5279
5301
  declare function deriveOracle(lbPair: PublicKey, programId: PublicKey): [PublicKey, number];
5280
5302
  declare function derivePosition(mint: PublicKey, programId: PublicKey): [PublicKey, number];
@@ -5559,8 +5581,6 @@ declare function chunkedFetchMultiplePoolAccount(program: ClmmProgram, pks: Publ
5559
5581
  activeId: number;
5560
5582
  binStep: number;
5561
5583
  status: number;
5562
- requireBaseFactorSeed: number;
5563
- baseFactorSeed: number[];
5564
5584
  padding1: number[];
5565
5585
  tokenXMint: PublicKey;
5566
5586
  tokenYMint: PublicKey;
@@ -5649,4 +5669,4 @@ declare const MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = 26;
5649
5669
  declare const MAX_BIN_PER_TX = 69;
5650
5670
  declare const MAX_ACTIVE_BIN_SLIPPAGE = 3;
5651
5671
 
5652
- export { ADMIN, BASIS_POINT_MAX, BIN_ARRAY_BITMAP_SIZE, BIN_ARRAY_FEE, Bin, BinAndAmount, BinArray, BinArrayAccount, BinArrayBitmapExtension, BinArrayBitmapExtensionAccount, BinLiquidity, BinLiquidityDistribution, BinLiquidityReduction, BitmapType, ClmmProgram, DLMMError, EXTENSION_BINARRAY_BITMAP_SIZE, EmissionRate, FEE_PRECISION, FeeInfo, GetOrCreateATAResponse, IAccountsCache, IDL, InitPermissionPairIx, LBCLMM_PROGRAM_IDS, LMRewards, LbClmm, LbPair, LbPairAccount, LbPosition, LiquidityOneSideParameter, LiquidityParameterByStrategy, LiquidityParameterByStrategyOneSide, LiquidityParameterByWeight, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BIN_ARRAY_SIZE, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, MAX_BIN_PER_POSITION, MAX_BIN_PER_TX, MAX_CLAIM_ALL_ALLOWED, MAX_FEE_RATE, Network, POSITION_FEE, PRECISION, PairType, Position, PositionBinData, PositionData, PositionInfo, PositionVersion, ProgramStrategyParameter, ProgramStrategyType, SCALE, SCALE_OFFSET, SIMULATION_USER, Strategy, StrategyParameters, StrategyType, SwapFee, SwapParams, SwapQuote, TInitializePositionAndAddLiquidityParams, TInitializePositionAndAddLiquidityParamsByStrategy, TQuoteCreatePositionParams, TokenReserve, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, binIdToBinArrayIndex, calculateBidAskDistribution, calculateNormalDistribution, calculateSpotDistribution, checkPoolExists, chunkedFetchMultipleBinArrayBitmapExtensionAccount, chunkedFetchMultiplePoolAccount, chunkedGetMultipleAccountInfos, chunks, computeBudgetIx, computeFee, computeFeeFromAmount, computeProtocolFee, DLMM as default, deriveBinArray, deriveBinArrayBitmapExtension, deriveLbPair, deriveLbPair2, deriveOracle, derivePermissionLbPair, derivePosition, derivePresetParameter, derivePresetParameter2, deriveReserve, findNextBinArrayIndexWithLiquidity, findNextBinArrayWithLiquidity, fromWeightDistributionToAmount, fromWeightDistributionToAmountOneSide, getBaseFee, getBinArrayLowerUpperBinId, getBinFromBinArray, getOrCreateATAInstruction, getOutAmount, getPriceOfBinByBinId, getTokenBalance, getTokenDecimals, getTotalFee, getVariableFee, isBinIdWithinBinArray, isOverflowDefaultBinArrayBitmap, parseLogs, sParameters, swapQuoteAtBin, swapQuoteAtBinWithCap, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountsBothSideByStrategy, toAmountsOneSideByStrategy, toStrategyParameters, toWeightDistribution, unwrapSOLInstruction, vParameters, wrapSOLInstruction };
5672
+ export { ADMIN, BASIS_POINT_MAX, BIN_ARRAY_BITMAP_SIZE, BIN_ARRAY_FEE, Bin, BinAndAmount, BinArray, BinArrayAccount, BinArrayBitmapExtension, BinArrayBitmapExtensionAccount, BinLiquidity, BinLiquidityDistribution, BinLiquidityReduction, BitmapType, ClmmProgram, DLMMError, EXTENSION_BINARRAY_BITMAP_SIZE, EmissionRate, FEE_PRECISION, FeeInfo, GetOrCreateATAResponse, IAccountsCache, IDL, InitPermissionPairIx, LBCLMM_PROGRAM_IDS, LMRewards, LbClmm, LbPair, LbPairAccount, LbPosition, LiquidityOneSideParameter, LiquidityParameterByStrategy, LiquidityParameterByStrategyOneSide, LiquidityParameterByWeight, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BIN_ARRAY_SIZE, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, MAX_BIN_PER_POSITION, MAX_BIN_PER_TX, MAX_CLAIM_ALL_ALLOWED, MAX_FEE_RATE, Network, POSITION_FEE, PRECISION, PairType, Position, PositionBinData, PositionData, PositionInfo, PositionVersion, ProgramStrategyParameter, ProgramStrategyType, SCALE, SCALE_OFFSET, SIMULATION_USER, Strategy, StrategyParameters, StrategyType, SwapFee, SwapParams, SwapQuote, TInitializePositionAndAddLiquidityParams, TInitializePositionAndAddLiquidityParamsByStrategy, TQuoteCreatePositionParams, TokenReserve, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, binIdToBinArrayIndex, calculateBidAskDistribution, calculateNormalDistribution, calculateSpotDistribution, checkPoolExists, chunkedFetchMultipleBinArrayBitmapExtensionAccount, chunkedFetchMultiplePoolAccount, chunkedGetMultipleAccountInfos, chunks, computeBudgetIx, computeFee, computeFeeFromAmount, computeProtocolFee, DLMM as default, deriveBinArray, deriveBinArrayBitmapExtension, deriveLbPair, deriveOracle, derivePermissionLbPair, derivePosition, derivePresetParameter, deriveReserve, findNextBinArrayIndexWithLiquidity, findNextBinArrayWithLiquidity, fromWeightDistributionToAmount, fromWeightDistributionToAmountOneSide, getBaseFee, getBinArrayLowerUpperBinId, getBinFromBinArray, getOrCreateATAInstruction, getOutAmount, getPriceOfBinByBinId, getTokenBalance, getTokenDecimals, getTotalFee, getVariableFee, isBinIdWithinBinArray, isOverflowDefaultBinArrayBitmap, parseLogs, sParameters, swapQuoteAtBin, swapQuoteAtBinWithCap, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountsBothSideByStrategy, toAmountsOneSideByStrategy, toStrategyParameters, toWeightDistribution, unwrapSOLInstruction, vParameters, wrapSOLInstruction };
package/dist/index.js CHANGED
@@ -1772,6 +1772,39 @@ var IDL = {
1772
1772
  }
1773
1773
  ]
1774
1774
  },
1775
+ {
1776
+ name: "initializePresetParameterV2",
1777
+ accounts: [
1778
+ {
1779
+ name: "presetParameter",
1780
+ isMut: true,
1781
+ isSigner: false
1782
+ },
1783
+ {
1784
+ name: "admin",
1785
+ isMut: true,
1786
+ isSigner: true
1787
+ },
1788
+ {
1789
+ name: "systemProgram",
1790
+ isMut: false,
1791
+ isSigner: false
1792
+ },
1793
+ {
1794
+ name: "rent",
1795
+ isMut: false,
1796
+ isSigner: false
1797
+ }
1798
+ ],
1799
+ args: [
1800
+ {
1801
+ name: "ix",
1802
+ type: {
1803
+ defined: "InitPresetParametersIx"
1804
+ }
1805
+ }
1806
+ ]
1807
+ },
1775
1808
  {
1776
1809
  name: "closePresetParameter",
1777
1810
  accounts: [
@@ -2511,20 +2544,10 @@ var IDL = {
2511
2544
  docs: ["Status of the pair. Check PairStatus enum."],
2512
2545
  type: "u8"
2513
2546
  },
2514
- {
2515
- name: "requireBaseFactorSeed",
2516
- type: "u8"
2517
- },
2518
- {
2519
- name: "baseFactorSeed",
2520
- type: {
2521
- array: ["u8", 2]
2522
- }
2523
- },
2524
2547
  {
2525
2548
  name: "padding1",
2526
2549
  type: {
2527
- array: ["u8", 2]
2550
+ array: ["u8", 5]
2528
2551
  }
2529
2552
  },
2530
2553
  {
@@ -4905,28 +4928,6 @@ function derivePresetParameter(binStep, programId) {
4905
4928
  programId
4906
4929
  );
4907
4930
  }
4908
- function derivePresetParameter2(binStep, baseFactor, programId) {
4909
- return _web3js.PublicKey.findProgramAddressSync(
4910
- [
4911
- Buffer.from("preset_parameter"),
4912
- new Uint8Array(binStep.toArrayLike(Buffer, "le", 2)),
4913
- new Uint8Array(baseFactor.toArrayLike(Buffer, "le", 2))
4914
- ],
4915
- programId
4916
- );
4917
- }
4918
- function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
4919
- const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
4920
- return _web3js.PublicKey.findProgramAddressSync(
4921
- [
4922
- minKey.toBuffer(),
4923
- maxKey.toBuffer(),
4924
- new Uint8Array(binStep.toArrayLike(Buffer, "le", 2)),
4925
- new Uint8Array(baseFactor.toArrayLike(Buffer, "le", 2))
4926
- ],
4927
- programId
4928
- );
4929
- }
4930
4931
  function deriveLbPair(tokenX, tokenY, binStep, programId) {
4931
4932
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
4932
4933
  return _web3js.PublicKey.findProgramAddressSync(
@@ -4938,15 +4939,9 @@ function deriveLbPair(tokenX, tokenY, binStep, programId) {
4938
4939
  programId
4939
4940
  );
4940
4941
  }
4941
- async function checkPoolExists(connection, tokenX, tokenY, binStep, baseFactor, programId) {
4942
+ async function checkPoolExists(connection, tokenX, tokenY, binStep, programId) {
4942
4943
  try {
4943
- const [lbPairKey] = deriveLbPair2(
4944
- tokenX,
4945
- tokenY,
4946
- binStep,
4947
- baseFactor,
4948
- programId
4949
- );
4944
+ const [lbPairKey] = deriveLbPair(tokenX, tokenY, binStep, programId);
4950
4945
  await DLMM.create(connection, lbPairKey);
4951
4946
  return lbPairKey;
4952
4947
  } catch (e2) {
@@ -4956,12 +4951,7 @@ async function checkPoolExists(connection, tokenX, tokenY, binStep, baseFactor,
4956
4951
  function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
4957
4952
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
4958
4953
  return _web3js.PublicKey.findProgramAddressSync(
4959
- [
4960
- baseKey.toBuffer(),
4961
- minKey.toBuffer(),
4962
- maxKey.toBuffer(),
4963
- new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))
4964
- ],
4954
+ [baseKey.toBuffer(), minKey.toBuffer(), maxKey.toBuffer(), new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))],
4965
4955
  programId
4966
4956
  );
4967
4957
  }
@@ -5129,7 +5119,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5129
5119
  let startBinArrayIndex = binIdToBinArrayIndex(activeId);
5130
5120
  while (true) {
5131
5121
  if (isOverflowDefaultBinArrayBitmap(startBinArrayIndex)) {
5132
- if (binArrayBitmapExtension == null) {
5122
+ if (binArrayBitmapExtension === null) {
5133
5123
  return null;
5134
5124
  }
5135
5125
  const [minBinArrayIndex, maxBinArrayIndex] = extensionBitmapRange();
@@ -5140,7 +5130,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5140
5130
  minBinArrayIndex.toNumber(),
5141
5131
  binArrayBitmapExtension
5142
5132
  );
5143
- if (binArrayIndex != null) {
5133
+ if (binArrayIndex !== null) {
5144
5134
  return new (0, _anchor.BN)(binArrayIndex);
5145
5135
  } else {
5146
5136
  return null;
@@ -5151,7 +5141,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5151
5141
  BIN_ARRAY_BITMAP_SIZE.neg().sub(new (0, _anchor.BN)(1)).toNumber(),
5152
5142
  binArrayBitmapExtension
5153
5143
  );
5154
- if (binArrayIndex != null) {
5144
+ if (binArrayIndex !== null) {
5155
5145
  return new (0, _anchor.BN)(binArrayIndex);
5156
5146
  } else {
5157
5147
  startBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.neg();
@@ -5164,7 +5154,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5164
5154
  BIN_ARRAY_BITMAP_SIZE.toNumber(),
5165
5155
  binArrayBitmapExtension
5166
5156
  );
5167
- if (binArrayIndex != null) {
5157
+ if (binArrayIndex !== null) {
5168
5158
  return new (0, _anchor.BN)(binArrayIndex);
5169
5159
  } else {
5170
5160
  startBinArrayIndex = BIN_ARRAY_BITMAP_SIZE;
@@ -5175,7 +5165,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5175
5165
  maxBinArrayIndex.toNumber(),
5176
5166
  binArrayBitmapExtension
5177
5167
  );
5178
- if (binArrayIndex != null) {
5168
+ if (binArrayIndex !== null) {
5179
5169
  return new (0, _anchor.BN)(binArrayIndex);
5180
5170
  } else {
5181
5171
  return null;
@@ -5194,7 +5184,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5194
5184
  const upperBitRange = new (0, _anchor.BN)(bitmapDetail.bits - 1).sub(offset);
5195
5185
  const croppedBitmap = bitmap.shln(upperBitRange.toNumber());
5196
5186
  const msb = mostSignificantBit(croppedBitmap, bitmapDetail.bits);
5197
- if (msb != null) {
5187
+ if (msb !== null) {
5198
5188
  return startBinArrayIndex.sub(new (0, _anchor.BN)(msb));
5199
5189
  } else {
5200
5190
  startBinArrayIndex = lowerBinArrayIndex.sub(new (0, _anchor.BN)(1));
@@ -5203,7 +5193,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5203
5193
  const lowerBitRange = offset;
5204
5194
  const croppedBitmap = bitmap.shrn(lowerBitRange.toNumber());
5205
5195
  const lsb = leastSignificantBit(croppedBitmap, bitmapDetail.bits);
5206
- if (lsb != null) {
5196
+ if (lsb !== null) {
5207
5197
  return startBinArrayIndex.add(new (0, _anchor.BN)(lsb));
5208
5198
  } else {
5209
5199
  startBinArrayIndex = upperBinArrayIndex.add(new (0, _anchor.BN)(1));
@@ -7222,13 +7212,7 @@ var DLMM = class {
7222
7212
  presetParameter
7223
7213
  );
7224
7214
  const binStep = new (0, _anchor.BN)(presetParameterState.binStep);
7225
- const [lbPair] = deriveLbPair2(
7226
- tokenX,
7227
- tokenY,
7228
- binStep,
7229
- new (0, _anchor.BN)(presetParameterState.baseFactor),
7230
- program.programId
7231
- );
7215
+ const [lbPair] = deriveLbPair(tokenX, tokenY, binStep, program.programId);
7232
7216
  const [reserveX] = deriveReserve(tokenX, lbPair, program.programId);
7233
7217
  const [reserveY] = deriveReserve(tokenY, lbPair, program.programId);
7234
7218
  const [oracle] = deriveOracle(lbPair, program.programId);
@@ -9339,6 +9323,115 @@ var DLMM = class {
9339
9323
  })
9340
9324
  );
9341
9325
  }
9326
+ canSyncWithMarketPrice(marketPrice, activeBinId) {
9327
+ const marketPriceBinId = this.getBinIdFromPrice(
9328
+ Number(
9329
+ DLMM.getPricePerLamport(
9330
+ this.tokenX.decimal,
9331
+ this.tokenY.decimal,
9332
+ marketPrice
9333
+ )
9334
+ ),
9335
+ false
9336
+ );
9337
+ const marketPriceBinArrayIndex = binIdToBinArrayIndex(
9338
+ new (0, _anchor.BN)(marketPriceBinId)
9339
+ );
9340
+ const swapForY = marketPriceBinId < activeBinId;
9341
+ const toBinArrayIndex = findNextBinArrayIndexWithLiquidity(
9342
+ swapForY,
9343
+ new (0, _anchor.BN)(activeBinId),
9344
+ this.lbPair,
9345
+ _nullishCoalesce(_optionalChain([this, 'access', _58 => _58.binArrayBitmapExtension, 'optionalAccess', _59 => _59.account]), () => ( null))
9346
+ );
9347
+ if (toBinArrayIndex === null)
9348
+ return true;
9349
+ return swapForY ? marketPriceBinArrayIndex.gt(toBinArrayIndex) : marketPriceBinArrayIndex.lt(toBinArrayIndex);
9350
+ }
9351
+ /**
9352
+ * The `syncWithMarketPrice` function is used to sync the liquidity pool with the market price.
9353
+ * @param
9354
+ * - `marketPrice`: The market price to sync with.
9355
+ * - `owner`: The public key of the owner of the liquidity pool.
9356
+ * @returns {Promise<Transaction>}
9357
+ */
9358
+ async syncWithMarketPrice(marketPrice, owner) {
9359
+ const marketPriceBinId = this.getBinIdFromPrice(
9360
+ Number(
9361
+ DLMM.getPricePerLamport(
9362
+ this.tokenX.decimal,
9363
+ this.tokenY.decimal,
9364
+ marketPrice
9365
+ )
9366
+ ),
9367
+ false
9368
+ );
9369
+ const activeBin = await this.getActiveBin();
9370
+ const activeBinId = activeBin.binId;
9371
+ const fromBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(activeBinId));
9372
+ const swapForY = marketPriceBinId < activeBinId;
9373
+ const toBinArrayIndex = findNextBinArrayIndexWithLiquidity(
9374
+ swapForY,
9375
+ new (0, _anchor.BN)(activeBinId),
9376
+ this.lbPair,
9377
+ _nullishCoalesce(_optionalChain([this, 'access', _60 => _60.binArrayBitmapExtension, 'optionalAccess', _61 => _61.account]), () => ( null))
9378
+ );
9379
+ if (!this.canSyncWithMarketPrice(marketPrice, activeBinId)) {
9380
+ throw new Error(
9381
+ "Unable to sync with market price due to bin with liquidity between current and market price bin"
9382
+ );
9383
+ }
9384
+ const accountsToFetch = [];
9385
+ const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
9386
+ this.pubkey,
9387
+ this.program.programId
9388
+ );
9389
+ accountsToFetch.push(binArrayBitMapExtensionPubkey);
9390
+ const [fromBinArrayPubkey] = deriveBinArray(
9391
+ this.pubkey,
9392
+ fromBinArrayIndex,
9393
+ this.program.programId
9394
+ );
9395
+ accountsToFetch.push(fromBinArrayPubkey);
9396
+ const toBinArrayPubkey = (() => {
9397
+ if (!toBinArrayIndex)
9398
+ return null;
9399
+ const [toBinArrayPubkey2] = deriveBinArray(
9400
+ this.pubkey,
9401
+ toBinArrayIndex,
9402
+ this.program.programId
9403
+ );
9404
+ accountsToFetch.push(toBinArrayPubkey2);
9405
+ return toBinArrayPubkey2;
9406
+ })();
9407
+ const binArrayAccounts = await this.program.provider.connection.getMultipleAccountsInfo(
9408
+ accountsToFetch
9409
+ );
9410
+ let fromBinArray = null;
9411
+ let toBinArray = null;
9412
+ let binArrayBitmapExtension = null;
9413
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _62 => _62[0]])) {
9414
+ binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
9415
+ }
9416
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _63 => _63[1]])) {
9417
+ fromBinArray = fromBinArrayPubkey;
9418
+ }
9419
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _64 => _64[2]]) && !!toBinArrayIndex) {
9420
+ toBinArray = toBinArrayPubkey;
9421
+ }
9422
+ const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
9423
+ const syncWithMarketPriceTx = await this.program.methods.goToABin(marketPriceBinId).accounts({
9424
+ lbPair: this.pubkey,
9425
+ binArrayBitmapExtension,
9426
+ fromBinArray,
9427
+ toBinArray
9428
+ }).transaction();
9429
+ return new (0, _web3js.Transaction)({
9430
+ feePayer: owner,
9431
+ blockhash,
9432
+ lastValidBlockHeight
9433
+ }).add(syncWithMarketPriceTx);
9434
+ }
9342
9435
  /** Private static method */
9343
9436
  static async getBinArrays(program, lbPairPubkey) {
9344
9437
  return program.account.binArray.all([
@@ -9935,7 +10028,7 @@ var DLMMError = class extends Error {
9935
10028
  const anchorError = _anchor.AnchorError.parse(
9936
10029
  JSON.parse(JSON.stringify(error)).logs
9937
10030
  );
9938
- if (_optionalChain([anchorError, 'optionalAccess', _58 => _58.program, 'access', _59 => _59.toBase58, 'call', _60 => _60()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
10031
+ if (_optionalChain([anchorError, 'optionalAccess', _65 => _65.program, 'access', _66 => _66.toBase58, 'call', _67 => _67()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
9939
10032
  _errorCode = anchorError.error.errorCode.number;
9940
10033
  _errorName = anchorError.error.errorCode.code;
9941
10034
  _errorMessage = anchorError.error.errorMessage;
@@ -10039,7 +10132,5 @@ var src_default = DLMM;
10039
10132
 
10040
10133
 
10041
10134
 
10042
-
10043
-
10044
- exports.ADMIN = ADMIN; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BitmapType = BitmapType; exports.DLMMError = DLMMError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.checkPoolExists = checkPoolExists; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeBudgetIx = computeBudgetIx; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.deriveReserve = deriveReserve; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinFromBinArray = getBinFromBinArray; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.swapQuoteAtBin = swapQuoteAtBin; exports.swapQuoteAtBinWithCap = swapQuoteAtBinWithCap; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toAmountsOneSideByStrategy = toAmountsOneSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
10135
+ exports.ADMIN = ADMIN; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BitmapType = BitmapType; exports.DLMMError = DLMMError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.checkPoolExists = checkPoolExists; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeBudgetIx = computeBudgetIx; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveLbPair = deriveLbPair; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.deriveReserve = deriveReserve; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinFromBinArray = getBinFromBinArray; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.swapQuoteAtBin = swapQuoteAtBin; exports.swapQuoteAtBinWithCap = swapQuoteAtBinWithCap; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toAmountsOneSideByStrategy = toAmountsOneSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
10045
10136
  //# sourceMappingURL=index.js.map