@meteora-ag/dlmm 1.3.1 → 1.3.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.d.ts CHANGED
@@ -6007,19 +6007,21 @@ declare class DLMM {
6007
6007
  /**
6008
6008
  * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
6009
6009
  * @param
6010
- * - `owner`: The public key of the positions owner.
6010
+ * - `payer`: The public key of the tx payer.
6011
6011
  * - `base`: Base key
6012
6012
  * - `seedAmount`: Token X lamport amount to be seeded to the pool.
6013
6013
  * - `price`: TokenX/TokenY Price in UI format
6014
6014
  * - `roundingUp`: Whether to round up the price
6015
+ * - `positionOwner`: The owner of the position
6015
6016
  * - `feeOwner`: Position fee owner
6016
6017
  * - `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.
6017
6018
  * - `lockReleasePoint`: The lock release point of the position.
6019
+ * - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
6018
6020
  *
6019
6021
  * The returned instructions need to be executed sequentially if it was separated into multiple transactions.
6020
6022
  * @returns {Promise<TransactionInstruction[]>}
6021
6023
  */
6022
- seedLiquiditySingleBin(owner: PublicKey, base: PublicKey, seedAmount: BN, price: number, roundingUp: boolean, feeOwner: PublicKey, operator: PublicKey, lockReleasePoint: BN): Promise<TransactionInstruction[]>;
6024
+ seedLiquiditySingleBin(payer: PublicKey, base: PublicKey, seedAmount: BN, price: number, roundingUp: boolean, positionOwner: PublicKey, feeOwner: PublicKey, operator: PublicKey, lockReleasePoint: BN, shouldSeedPositionOwner?: boolean): Promise<TransactionInstruction[]>;
6023
6025
  /**
6024
6026
  * Initializes bin arrays for the given bin array indexes if it wasn't initialized.
6025
6027
  *
package/dist/index.js CHANGED
@@ -7591,6 +7591,8 @@ var _bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
7591
7591
 
7592
7592
 
7593
7593
 
7594
+
7595
+
7594
7596
  // src/dlmm/error.ts
7595
7597
 
7596
7598
  var DLMMError = class extends Error {
@@ -10236,6 +10238,7 @@ var DLMM = class {
10236
10238
  }) {
10237
10239
  const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10238
10240
  const preInstructions = [computeBudgetIx()];
10241
+ const postInstructions = [];
10239
10242
  const [
10240
10243
  { ataPubKey: userTokenIn, ix: createInTokenAccountIx },
10241
10244
  { ataPubKey: userTokenOut, ix: createOutTokenAccountIx }
@@ -10260,8 +10263,9 @@ var DLMM = class {
10260
10263
  BigInt(maxInAmount.toString())
10261
10264
  );
10262
10265
  preInstructions.push(...wrapSOLIx);
10266
+ const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10267
+ closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10263
10268
  }
10264
- const postInstructions = [];
10265
10269
  if (outToken.equals(_spltoken.NATIVE_MINT)) {
10266
10270
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10267
10271
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
@@ -10321,6 +10325,7 @@ var DLMM = class {
10321
10325
  }) {
10322
10326
  const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10323
10327
  const preInstructions = [computeBudgetIx()];
10328
+ const postInstructions = [];
10324
10329
  const [
10325
10330
  { ataPubKey: userTokenIn, ix: createInTokenAccountIx },
10326
10331
  { ataPubKey: userTokenOut, ix: createOutTokenAccountIx }
@@ -10345,8 +10350,9 @@ var DLMM = class {
10345
10350
  BigInt(inAmount.toString())
10346
10351
  );
10347
10352
  preInstructions.push(...wrapSOLIx);
10353
+ const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10354
+ closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10348
10355
  }
10349
- const postInstructions = [];
10350
10356
  if (outToken.equals(_spltoken.NATIVE_MINT)) {
10351
10357
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10352
10358
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
@@ -10410,6 +10416,7 @@ var DLMM = class {
10410
10416
  }) {
10411
10417
  const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10412
10418
  const preInstructions = [computeBudgetIx()];
10419
+ const postInstructions = [];
10413
10420
  const [
10414
10421
  { ataPubKey: userTokenIn, ix: createInTokenAccountIx },
10415
10422
  { ataPubKey: userTokenOut, ix: createOutTokenAccountIx }
@@ -10434,8 +10441,9 @@ var DLMM = class {
10434
10441
  BigInt(inAmount.toString())
10435
10442
  );
10436
10443
  preInstructions.push(...wrapSOLIx);
10444
+ const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10445
+ closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10437
10446
  }
10438
- const postInstructions = [];
10439
10447
  if (outToken.equals(_spltoken.NATIVE_MINT)) {
10440
10448
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10441
10449
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
@@ -10872,37 +10880,37 @@ var DLMM = class {
10872
10880
  /**
10873
10881
  * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
10874
10882
  * @param
10875
- * - `owner`: The public key of the positions owner.
10883
+ * - `payer`: The public key of the tx payer.
10876
10884
  * - `base`: Base key
10877
10885
  * - `seedAmount`: Token X lamport amount to be seeded to the pool.
10878
10886
  * - `price`: TokenX/TokenY Price in UI format
10879
10887
  * - `roundingUp`: Whether to round up the price
10888
+ * - `positionOwner`: The owner of the position
10880
10889
  * - `feeOwner`: Position fee owner
10881
10890
  * - `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
10891
  * - `lockReleasePoint`: The lock release point of the position.
10892
+ * - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
10883
10893
  *
10884
10894
  * The returned instructions need to be executed sequentially if it was separated into multiple transactions.
10885
10895
  * @returns {Promise<TransactionInstruction[]>}
10886
10896
  */
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);
10897
+ async seedLiquiditySingleBin(payer, base, seedAmount, price, roundingUp, positionOwner, feeOwner, operator, lockReleasePoint, shouldSeedPositionOwner = false) {
10898
+ const pricePerLamport = DLMM.getPricePerLamport(
10899
+ this.tokenX.decimal,
10900
+ this.tokenY.decimal,
10901
+ price
10902
+ );
10903
+ const binIdNumber = DLMM.getBinIdFromPrice(
10904
+ pricePerLamport,
10905
+ this.lbPair.binStep,
10906
+ !roundingUp
10907
+ );
10890
10908
  const binId = new (0, _anchor.BN)(binIdNumber);
10891
10909
  const lowerBinArrayIndex = binIdToBinArrayIndex(binId);
10892
10910
  const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
10893
10911
  const [lowerBinArray] = deriveBinArray(this.pubkey, lowerBinArrayIndex, this.program.programId);
10894
10912
  const [upperBinArray] = deriveBinArray(this.pubkey, upperBinArrayIndex, this.program.programId);
10895
10913
  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
10914
  const preInstructions = [];
10907
10915
  const [
10908
10916
  { ataPubKey: userTokenX, ix: createPayerTokenXIx },
@@ -10911,17 +10919,22 @@ var DLMM = class {
10911
10919
  getOrCreateATAInstruction(
10912
10920
  this.program.provider.connection,
10913
10921
  this.tokenX.publicKey,
10914
- owner
10922
+ operator,
10923
+ payer
10915
10924
  ),
10916
10925
  getOrCreateATAInstruction(
10917
10926
  this.program.provider.connection,
10918
10927
  this.tokenY.publicKey,
10919
- owner
10928
+ operator,
10929
+ payer
10920
10930
  )
10921
10931
  ]);
10922
10932
  createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
10923
10933
  createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
10924
- let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(this.pubkey, this.program.programId);
10934
+ let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(
10935
+ this.pubkey,
10936
+ this.program.programId
10937
+ );
10925
10938
  const accounts = await this.program.provider.connection.getMultipleAccountsInfo([
10926
10939
  lowerBinArray,
10927
10940
  upperBinArray,
@@ -10933,13 +10946,38 @@ var DLMM = class {
10933
10946
  if (!bitmapExtensionAccount) {
10934
10947
  preInstructions.push(await this.program.methods.initializeBinArrayBitmapExtension().accounts({
10935
10948
  binArrayBitmapExtension,
10936
- funder: owner,
10949
+ funder: payer,
10937
10950
  lbPair: this.pubkey
10938
10951
  }).instruction());
10939
10952
  }
10940
10953
  } else {
10941
10954
  binArrayBitmapExtension = this.program.programId;
10942
10955
  }
10956
+ const operatorTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
10957
+ this.lbPair.tokenXMint,
10958
+ operator,
10959
+ true
10960
+ );
10961
+ const positionOwnerTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
10962
+ this.lbPair.tokenXMint,
10963
+ positionOwner,
10964
+ true
10965
+ );
10966
+ if (shouldSeedPositionOwner) {
10967
+ const positionOwnerTokenXAccount = await this.program.provider.connection.getAccountInfo(positionOwnerTokenX);
10968
+ if (positionOwnerTokenXAccount) {
10969
+ const account = _spltoken.AccountLayout.decode(positionOwnerTokenXAccount.data);
10970
+ if (account.amount == BigInt(0)) {
10971
+ const transferIx = _spltoken.createTransferInstruction.call(void 0, operatorTokenX, positionOwnerTokenX, payer, 1);
10972
+ preInstructions.push(transferIx);
10973
+ }
10974
+ } else {
10975
+ const createPositionOwnerTokenXIx = _spltoken.createAssociatedTokenAccountInstruction.call(void 0, payer, positionOwnerTokenX, positionOwner, this.lbPair.tokenXMint);
10976
+ preInstructions.push(createPositionOwnerTokenXIx);
10977
+ const transferIx = _spltoken.createTransferInstruction.call(void 0, operatorTokenX, positionOwnerTokenX, payer, 1);
10978
+ preInstructions.push(transferIx);
10979
+ }
10980
+ }
10943
10981
  const lowerBinArrayAccount = accounts[0];
10944
10982
  const upperBinArrayAccount = accounts[1];
10945
10983
  const positionAccount = accounts[2];
@@ -10947,7 +10985,7 @@ var DLMM = class {
10947
10985
  preInstructions.push(
10948
10986
  await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
10949
10987
  binArray: lowerBinArray,
10950
- funder: owner,
10988
+ funder: payer,
10951
10989
  lbPair: this.pubkey
10952
10990
  }).instruction()
10953
10991
  );
@@ -10956,22 +10994,27 @@ var DLMM = class {
10956
10994
  preInstructions.push(
10957
10995
  await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
10958
10996
  binArray: upperBinArray,
10959
- funder: owner,
10997
+ funder: payer,
10960
10998
  lbPair: this.pubkey
10961
10999
  }).instruction()
10962
11000
  );
10963
11001
  }
10964
11002
  if (!positionAccount) {
10965
11003
  preInstructions.push(
10966
- await this.program.methods.initializePositionByOperator(binId.toNumber(), 1, feeOwner, lockReleasePoint).accounts({
10967
- payer: owner,
11004
+ await this.program.methods.initializePositionByOperator(
11005
+ binId.toNumber(),
11006
+ 1,
11007
+ feeOwner,
11008
+ lockReleasePoint
11009
+ ).accounts({
11010
+ payer,
10968
11011
  base,
10969
11012
  position: positionPda,
10970
11013
  lbPair: this.pubkey,
10971
- owner,
11014
+ owner: positionOwner,
10972
11015
  operator,
10973
11016
  operatorTokenX,
10974
- ownerTokenX
11017
+ ownerTokenX: positionOwnerTokenX
10975
11018
  }).instruction()
10976
11019
  );
10977
11020
  }
@@ -10997,7 +11040,7 @@ var DLMM = class {
10997
11040
  tokenYMint: this.lbPair.tokenYMint,
10998
11041
  binArrayLower: lowerBinArray,
10999
11042
  binArrayUpper: upperBinArray,
11000
- sender: owner,
11043
+ sender: operator,
11001
11044
  tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
11002
11045
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
11003
11046
  }).instruction();