@meteora-ag/dlmm 1.3.10 → 1.3.12-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -11,8 +11,8 @@ import {
11
11
  getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
12
12
  } from "@solana/spl-token";
13
13
  import {
14
- ComputeBudgetProgram as ComputeBudgetProgram2,
15
- PublicKey as PublicKey6,
14
+ ComputeBudgetProgram as ComputeBudgetProgram3,
15
+ PublicKey as PublicKey7,
16
16
  SYSVAR_CLOCK_PUBKEY,
17
17
  SYSVAR_RENT_PUBKEY,
18
18
  SystemProgram as SystemProgram2,
@@ -5511,9 +5511,9 @@ import {
5511
5511
  getMint
5512
5512
  } from "@solana/spl-token";
5513
5513
  import {
5514
- ComputeBudgetProgram,
5514
+ ComputeBudgetProgram as ComputeBudgetProgram2,
5515
5515
  SystemProgram,
5516
- TransactionInstruction
5516
+ TransactionInstruction as TransactionInstruction2
5517
5517
  } from "@solana/web3.js";
5518
5518
 
5519
5519
  // src/dlmm/helpers/math.ts
@@ -6472,22 +6472,51 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
6472
6472
  return new BN5(c1.sub(c0).floor().toString());
6473
6473
  }
6474
6474
 
6475
- // src/dlmm/helpers/index.ts
6476
- import { getSimulationComputeUnits } from "@solana-developers/helpers";
6477
-
6478
6475
  // src/dlmm/helpers/computeUnit.ts
6476
+ import { ComputeBudgetProgram, PublicKey as PublicKey2, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
6479
6477
  var DEFAULT_ADD_LIQUIDITY_CU = 8e5;
6480
6478
  var MIN_CU_BUFFER = 5e4;
6481
6479
  var MAX_CU_BUFFER = 2e5;
6480
+ var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
6481
+ const testInstructions = [
6482
+ // Set an arbitrarily high number in simulation
6483
+ // so we can be sure the transaction will succeed
6484
+ // and get the real compute units used
6485
+ ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
6486
+ ...instructions
6487
+ ];
6488
+ const testTransaction = new VersionedTransaction(
6489
+ new TransactionMessage({
6490
+ instructions: testInstructions,
6491
+ payerKey: payer,
6492
+ // RecentBlockhash can by any public key during simulation
6493
+ // since 'replaceRecentBlockhash' is set to 'true' below
6494
+ recentBlockhash: PublicKey2.default.toString()
6495
+ }).compileToV0Message(lookupTables)
6496
+ );
6497
+ const rpcResponse = await connection.simulateTransaction(testTransaction, {
6498
+ replaceRecentBlockhash: true,
6499
+ sigVerify: false,
6500
+ commitment
6501
+ });
6502
+ if (rpcResponse?.value?.err) {
6503
+ const logs = rpcResponse.value.logs?.join("\n \u2022 ") || "No logs available";
6504
+ throw new Error(
6505
+ `Transaction simulation failed:
6506
+ \u2022${logs}` + JSON.stringify(rpcResponse?.value?.err)
6507
+ );
6508
+ }
6509
+ return rpcResponse.value.unitsConsumed || null;
6510
+ };
6482
6511
 
6483
6512
  // src/dlmm/helpers/derive.ts
6484
- import { PublicKey as PublicKey2 } from "@solana/web3.js";
6513
+ import { PublicKey as PublicKey3 } from "@solana/web3.js";
6485
6514
  function sortTokenMints(tokenX, tokenY) {
6486
6515
  const [minKey, maxKey] = tokenX.toBuffer().compare(tokenY.toBuffer()) == 1 ? [tokenY, tokenX] : [tokenX, tokenY];
6487
6516
  return [minKey, maxKey];
6488
6517
  }
6489
6518
  function derivePresetParameter(binStep, programId) {
6490
- return PublicKey2.findProgramAddressSync(
6519
+ return PublicKey3.findProgramAddressSync(
6491
6520
  [
6492
6521
  Buffer.from("preset_parameter"),
6493
6522
  new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))
@@ -6496,7 +6525,7 @@ function derivePresetParameter(binStep, programId) {
6496
6525
  );
6497
6526
  }
6498
6527
  function derivePresetParameter2(binStep, baseFactor, programId) {
6499
- return PublicKey2.findProgramAddressSync(
6528
+ return PublicKey3.findProgramAddressSync(
6500
6529
  [
6501
6530
  Buffer.from("preset_parameter"),
6502
6531
  new Uint8Array(binStep.toArrayLike(Buffer, "le", 2)),
@@ -6507,7 +6536,7 @@ function derivePresetParameter2(binStep, baseFactor, programId) {
6507
6536
  }
6508
6537
  function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
6509
6538
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6510
- return PublicKey2.findProgramAddressSync(
6539
+ return PublicKey3.findProgramAddressSync(
6511
6540
  [
6512
6541
  minKey.toBuffer(),
6513
6542
  maxKey.toBuffer(),
@@ -6519,7 +6548,7 @@ function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
6519
6548
  }
6520
6549
  function deriveLbPair(tokenX, tokenY, binStep, programId) {
6521
6550
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6522
- return PublicKey2.findProgramAddressSync(
6551
+ return PublicKey3.findProgramAddressSync(
6523
6552
  [
6524
6553
  minKey.toBuffer(),
6525
6554
  maxKey.toBuffer(),
@@ -6530,14 +6559,14 @@ function deriveLbPair(tokenX, tokenY, binStep, programId) {
6530
6559
  }
6531
6560
  function deriveCustomizablePermissionlessLbPair(tokenX, tokenY, programId) {
6532
6561
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6533
- return PublicKey2.findProgramAddressSync(
6562
+ return PublicKey3.findProgramAddressSync(
6534
6563
  [ILM_BASE.toBuffer(), minKey.toBuffer(), maxKey.toBuffer()],
6535
6564
  programId
6536
6565
  );
6537
6566
  }
6538
6567
  function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
6539
6568
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6540
- return PublicKey2.findProgramAddressSync(
6569
+ return PublicKey3.findProgramAddressSync(
6541
6570
  [
6542
6571
  baseKey.toBuffer(),
6543
6572
  minKey.toBuffer(),
@@ -6548,7 +6577,7 @@ function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
6548
6577
  );
6549
6578
  }
6550
6579
  function deriveOracle(lbPair, programId) {
6551
- return PublicKey2.findProgramAddressSync(
6580
+ return PublicKey3.findProgramAddressSync(
6552
6581
  [Buffer.from("oracle"), lbPair.toBytes()],
6553
6582
  programId
6554
6583
  );
@@ -6562,7 +6591,7 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
6562
6591
  } else {
6563
6592
  lowerBinIdBytes = new Uint8Array(lowerBinId.toArrayLike(Buffer, "le", 4));
6564
6593
  }
6565
- return PublicKey2.findProgramAddressSync(
6594
+ return PublicKey3.findProgramAddressSync(
6566
6595
  [
6567
6596
  Buffer.from("position"),
6568
6597
  lbPair.toBuffer(),
@@ -6582,13 +6611,13 @@ function deriveBinArray(lbPair, index, programId) {
6582
6611
  } else {
6583
6612
  binArrayBytes = new Uint8Array(index.toArrayLike(Buffer, "le", 8));
6584
6613
  }
6585
- return PublicKey2.findProgramAddressSync(
6614
+ return PublicKey3.findProgramAddressSync(
6586
6615
  [Buffer.from("bin_array"), lbPair.toBytes(), binArrayBytes],
6587
6616
  programId
6588
6617
  );
6589
6618
  }
6590
6619
  function deriveReserve(token, lbPair, programId) {
6591
- return PublicKey2.findProgramAddressSync(
6620
+ return PublicKey3.findProgramAddressSync(
6592
6621
  [lbPair.toBuffer(), token.toBuffer()],
6593
6622
  programId
6594
6623
  );
@@ -6596,7 +6625,7 @@ function deriveReserve(token, lbPair, programId) {
6596
6625
 
6597
6626
  // src/dlmm/helpers/binArray.ts
6598
6627
  import { BN as BN7 } from "@coral-xyz/anchor";
6599
- import { PublicKey as PublicKey3 } from "@solana/web3.js";
6628
+ import { PublicKey as PublicKey4 } from "@solana/web3.js";
6600
6629
 
6601
6630
  // src/dlmm/types/index.ts
6602
6631
  import {
@@ -6784,7 +6813,7 @@ function isOverflowDefaultBinArrayBitmap(binArrayIndex) {
6784
6813
  return binArrayIndex.gt(maxBinArrayIndex) || binArrayIndex.lt(minBinArrayIndex);
6785
6814
  }
6786
6815
  function deriveBinArrayBitmapExtension(lbPair, programId) {
6787
- return PublicKey3.findProgramAddressSync(
6816
+ return PublicKey4.findProgramAddressSync(
6788
6817
  [Buffer.from("bitmap"), lbPair.toBytes()],
6789
6818
  programId
6790
6819
  );
@@ -6933,7 +6962,7 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
6933
6962
  binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
6934
6963
  }
6935
6964
  return Array.from(binArrays, ([key, index]) => ({
6936
- key: new PublicKey3(key),
6965
+ key: new PublicKey4(key),
6937
6966
  index
6938
6967
  }));
6939
6968
  }
@@ -7606,7 +7635,7 @@ function toStrategyParameters({
7606
7635
 
7607
7636
  // src/dlmm/helpers/lbPair.ts
7608
7637
  import { AnchorProvider, Program as Program2 } from "@coral-xyz/anchor";
7609
- import { PublicKey as PublicKey4 } from "@solana/web3.js";
7638
+ import { PublicKey as PublicKey5 } from "@solana/web3.js";
7610
7639
  async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7611
7640
  const provider = new AnchorProvider(
7612
7641
  connection,
@@ -7619,7 +7648,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7619
7648
  provider
7620
7649
  );
7621
7650
  const poolAccount = await program.account.lbPair.fetchNullable(
7622
- new PublicKey4(poolAddress)
7651
+ new PublicKey5(poolAddress)
7623
7652
  );
7624
7653
  if (!poolAccount)
7625
7654
  throw new Error("Pool account not found");
@@ -7705,7 +7734,7 @@ var wrapSOLInstruction = (from, to, amount) => {
7705
7734
  toPubkey: to,
7706
7735
  lamports: amount
7707
7736
  }),
7708
- new TransactionInstruction({
7737
+ new TransactionInstruction2({
7709
7738
  keys: [
7710
7739
  {
7711
7740
  pubkey: to,
@@ -7774,7 +7803,7 @@ var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePa
7774
7803
  console.error("Error::getEstimatedComputeUnitUsageWithBuffer", error);
7775
7804
  return 14e5;
7776
7805
  });
7777
- return ComputeBudgetProgram.setComputeUnitLimit({ units });
7806
+ return ComputeBudgetProgram2.setComputeUnitLimit({ units });
7778
7807
  };
7779
7808
 
7780
7809
  // src/dlmm/index.ts
@@ -8146,10 +8175,10 @@ var DLMM = class {
8146
8175
  lbPairSetV2.add(lbPair.toBase58());
8147
8176
  });
8148
8177
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8149
- (pubkey) => new PublicKey6(pubkey)
8178
+ (pubkey) => new PublicKey7(pubkey)
8150
8179
  );
8151
8180
  const lbPairArrayV2 = Array.from(lbPairSetV2).map(
8152
- (pubkey) => new PublicKey6(pubkey)
8181
+ (pubkey) => new PublicKey7(pubkey)
8153
8182
  );
8154
8183
  const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
8155
8184
  SYSVAR_CLOCK_PUBKEY,
@@ -8577,7 +8606,7 @@ var DLMM = class {
8577
8606
  shouldStop = true;
8578
8607
  }
8579
8608
  const accountsToFetch = Array.from(binArraysPubkey).map(
8580
- (pubkey) => new PublicKey6(pubkey)
8609
+ (pubkey) => new PublicKey7(pubkey)
8581
8610
  );
8582
8611
  const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
8583
8612
  this.program.provider.connection,
@@ -8846,7 +8875,7 @@ var DLMM = class {
8846
8875
  binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8847
8876
  });
8848
8877
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8849
- (pubkey) => new PublicKey6(pubkey)
8878
+ (pubkey) => new PublicKey7(pubkey)
8850
8879
  );
8851
8880
  const lbPairAndBinArrays = await chunkedGetMultipleAccountInfos(
8852
8881
  this.program.provider.connection,
@@ -9807,7 +9836,7 @@ var DLMM = class {
9807
9836
  this.program.programId
9808
9837
  );
9809
9838
  const preInstructions = [];
9810
- const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? user : feeOwner;
9839
+ const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? user : feeOwner;
9811
9840
  const [
9812
9841
  { ataPubKey: userTokenX, ix: createPayerTokenXIx },
9813
9842
  { ataPubKey: userTokenY, ix: createPayerTokenYIx },
@@ -9865,7 +9894,7 @@ var DLMM = class {
9865
9894
  postInstructions.push(claimSwapFeeIx);
9866
9895
  for (let i = 0; i < 2; i++) {
9867
9896
  const rewardInfo = this.lbPair.rewardInfos[i];
9868
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
9897
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
9869
9898
  continue;
9870
9899
  const { ataPubKey, ix: rewardAtaIx } = await getOrCreateATAInstruction(
9871
9900
  this.program.provider.connection,
@@ -10586,6 +10615,21 @@ var DLMM = class {
10586
10615
  lastValidBlockHeight
10587
10616
  }).add(setActivationPointTx);
10588
10617
  }
10618
+ async setPairStatus(enabled) {
10619
+ const pairStatus = enabled ? 0 : 1;
10620
+ const tx = await this.program.methods.setPairStatus(pairStatus).accounts(
10621
+ {
10622
+ lbPair: this.pubkey,
10623
+ admin: this.lbPair.creator
10624
+ }
10625
+ ).transaction();
10626
+ const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
10627
+ return new Transaction({
10628
+ feePayer: this.lbPair.creator,
10629
+ blockhash,
10630
+ lastValidBlockHeight
10631
+ }).add(tx);
10632
+ }
10589
10633
  /**
10590
10634
  * The function `claimSwapFee` is used to claim swap fees for a specific position owned by a specific owner.
10591
10635
  * @param
@@ -10665,11 +10709,11 @@ var DLMM = class {
10665
10709
  const tokensInvolved = [...pairTokens];
10666
10710
  for (let i = 0; i < 2; i++) {
10667
10711
  const rewardMint = this.lbPair.rewardInfos[i].mint;
10668
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
10712
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
10669
10713
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
10670
10714
  }
10671
10715
  }
10672
- const feeOwner = position.positionData.feeOwner.equals(PublicKey6.default) ? owner : position.positionData.feeOwner;
10716
+ const feeOwner = position.positionData.feeOwner.equals(PublicKey7.default) ? owner : position.positionData.feeOwner;
10673
10717
  const createATAAccAndIx = await Promise.all(
10674
10718
  tokensInvolved.map((token) => {
10675
10719
  if (pairTokens.some((t) => t.equals(token))) {
@@ -10929,7 +10973,7 @@ var DLMM = class {
10929
10973
  );
10930
10974
  }
10931
10975
  addLiquidityIxs.push([
10932
- ComputeBudgetProgram2.setComputeUnitLimit({
10976
+ ComputeBudgetProgram3.setComputeUnitLimit({
10933
10977
  units: DEFAULT_ADD_LIQUIDITY_CU
10934
10978
  }),
10935
10979
  ...instructions
@@ -11216,7 +11260,7 @@ var DLMM = class {
11216
11260
  const tokensInvolved = [...pairsToken];
11217
11261
  for (let i = 0; i < 2; i++) {
11218
11262
  const rewardMint = this.lbPair.rewardInfos[i].mint;
11219
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
11263
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
11220
11264
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
11221
11265
  }
11222
11266
  }
@@ -11226,9 +11270,9 @@ var DLMM = class {
11226
11270
  const feeOwners = [
11227
11271
  .../* @__PURE__ */ new Set([
11228
11272
  owner.toBase58(),
11229
- ...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey6.default)).map((p) => p.positionData.feeOwner.toBase58())
11273
+ ...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey7.default)).map((p) => p.positionData.feeOwner.toBase58())
11230
11274
  ])
11231
- ].map((pk) => new PublicKey6(pk));
11275
+ ].map((pk) => new PublicKey7(pk));
11232
11276
  const createATAAccAndIx = await Promise.all(
11233
11277
  tokensInvolved.map((token) => {
11234
11278
  if (pairsToken.some((p) => p.equals(token))) {
@@ -11562,7 +11606,7 @@ var DLMM = class {
11562
11606
  const preActivationSwapPoint = this.lbPair.activationPoint.sub(
11563
11607
  this.lbPair.preActivationDuration
11564
11608
  );
11565
- const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey6.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
11609
+ const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey7.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
11566
11610
  if (currentPoint < activationPoint) {
11567
11611
  return true;
11568
11612
  }
@@ -11616,7 +11660,7 @@ var DLMM = class {
11616
11660
  const liquidityShare = positionVersion === 0 /* V1 */ ? position.liquidityShares[binIdxInPosition] : position.liquidityShares[binIdxInPosition].shrn(64);
11617
11661
  for (let j = 0; j < 2; j++) {
11618
11662
  const pairRewardInfo = lbPair.rewardInfos[j];
11619
- if (!pairRewardInfo.mint.equals(PublicKey6.default)) {
11663
+ if (!pairRewardInfo.mint.equals(PublicKey7.default)) {
11620
11664
  let rewardPerTokenStored = binState.rewardPerTokenStored[j];
11621
11665
  if (i == lbPair.activeId && !binState.liquiditySupply.isZero()) {
11622
11666
  const currentTime = new BN10(
@@ -11977,7 +12021,7 @@ var DLMM = class {
11977
12021
  const claimTransactions = [];
11978
12022
  for (let i = 0; i < 2; i++) {
11979
12023
  const rewardInfo = this.lbPair.rewardInfos[i];
11980
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
12024
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
11981
12025
  continue;
11982
12026
  const preInstructions = [];
11983
12027
  const { ataPubKey, ix } = await getOrCreateATAInstruction(
@@ -12030,7 +12074,7 @@ var DLMM = class {
12030
12074
  this.pubkey,
12031
12075
  this.program.programId
12032
12076
  );
12033
- const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? owner : feeOwner;
12077
+ const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? owner : feeOwner;
12034
12078
  const preInstructions = [];
12035
12079
  const [
12036
12080
  { ataPubKey: userTokenX, ix: createInTokenAccountIx },