@meteora-ag/dlmm 1.3.0 → 1.3.1

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
@@ -10869,6 +10869,140 @@ var DLMM = class {
10869
10869
  addLiquidityIxs
10870
10870
  };
10871
10871
  }
10872
+ /**
10873
+ * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
10874
+ * @param
10875
+ * - `owner`: The public key of the positions owner.
10876
+ * - `base`: Base key
10877
+ * - `seedAmount`: Token X lamport amount to be seeded to the pool.
10878
+ * - `price`: TokenX/TokenY Price in UI format
10879
+ * - `roundingUp`: Whether to round up the price
10880
+ * - `feeOwner`: Position fee owner
10881
+ * - `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
+ * - `lockReleasePoint`: The lock release point of the position.
10883
+ *
10884
+ * The returned instructions need to be executed sequentially if it was separated into multiple transactions.
10885
+ * @returns {Promise<TransactionInstruction[]>}
10886
+ */
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);
10890
+ const binId = new BN9(binIdNumber);
10891
+ const lowerBinArrayIndex = binIdToBinArrayIndex(binId);
10892
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new BN9(1));
10893
+ const [lowerBinArray] = deriveBinArray(this.pubkey, lowerBinArrayIndex, this.program.programId);
10894
+ const [upperBinArray] = deriveBinArray(this.pubkey, upperBinArrayIndex, this.program.programId);
10895
+ const [positionPda] = derivePosition(this.pubkey, base, binId, new BN9(1), this.program.programId);
10896
+ const operatorTokenX = getAssociatedTokenAddressSync2(
10897
+ this.lbPair.tokenXMint,
10898
+ operator,
10899
+ true
10900
+ );
10901
+ const ownerTokenX = getAssociatedTokenAddressSync2(
10902
+ this.lbPair.tokenXMint,
10903
+ owner,
10904
+ true
10905
+ );
10906
+ const preInstructions = [];
10907
+ const [
10908
+ { ataPubKey: userTokenX, ix: createPayerTokenXIx },
10909
+ { ataPubKey: userTokenY, ix: createPayerTokenYIx }
10910
+ ] = await Promise.all([
10911
+ getOrCreateATAInstruction(
10912
+ this.program.provider.connection,
10913
+ this.tokenX.publicKey,
10914
+ owner
10915
+ ),
10916
+ getOrCreateATAInstruction(
10917
+ this.program.provider.connection,
10918
+ this.tokenY.publicKey,
10919
+ owner
10920
+ )
10921
+ ]);
10922
+ createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
10923
+ createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
10924
+ let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(this.pubkey, this.program.programId);
10925
+ const accounts = await this.program.provider.connection.getMultipleAccountsInfo([
10926
+ lowerBinArray,
10927
+ upperBinArray,
10928
+ positionPda,
10929
+ binArrayBitmapExtension
10930
+ ]);
10931
+ if (isOverflowDefaultBinArrayBitmap(lowerBinArrayIndex)) {
10932
+ const bitmapExtensionAccount = accounts[3];
10933
+ if (!bitmapExtensionAccount) {
10934
+ preInstructions.push(await this.program.methods.initializeBinArrayBitmapExtension().accounts({
10935
+ binArrayBitmapExtension,
10936
+ funder: owner,
10937
+ lbPair: this.pubkey
10938
+ }).instruction());
10939
+ }
10940
+ } else {
10941
+ binArrayBitmapExtension = this.program.programId;
10942
+ }
10943
+ const lowerBinArrayAccount = accounts[0];
10944
+ const upperBinArrayAccount = accounts[1];
10945
+ const positionAccount = accounts[2];
10946
+ if (!lowerBinArrayAccount) {
10947
+ preInstructions.push(
10948
+ await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
10949
+ binArray: lowerBinArray,
10950
+ funder: owner,
10951
+ lbPair: this.pubkey
10952
+ }).instruction()
10953
+ );
10954
+ }
10955
+ if (!upperBinArrayAccount) {
10956
+ preInstructions.push(
10957
+ await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
10958
+ binArray: upperBinArray,
10959
+ funder: owner,
10960
+ lbPair: this.pubkey
10961
+ }).instruction()
10962
+ );
10963
+ }
10964
+ if (!positionAccount) {
10965
+ preInstructions.push(
10966
+ await this.program.methods.initializePositionByOperator(binId.toNumber(), 1, feeOwner, lockReleasePoint).accounts({
10967
+ payer: owner,
10968
+ base,
10969
+ position: positionPda,
10970
+ lbPair: this.pubkey,
10971
+ owner,
10972
+ operator,
10973
+ operatorTokenX,
10974
+ ownerTokenX
10975
+ }).instruction()
10976
+ );
10977
+ }
10978
+ const binLiquidityDist = {
10979
+ binId: binIdNumber,
10980
+ distributionX: BASIS_POINT_MAX,
10981
+ distributionY: 0
10982
+ };
10983
+ const addLiquidityParams = {
10984
+ amountX: seedAmount,
10985
+ amountY: new BN9(0),
10986
+ binLiquidityDist: [binLiquidityDist]
10987
+ };
10988
+ const depositLiquidityIx = await this.program.methods.addLiquidity(addLiquidityParams).accounts({
10989
+ position: positionPda,
10990
+ lbPair: this.pubkey,
10991
+ binArrayBitmapExtension,
10992
+ userTokenX,
10993
+ userTokenY,
10994
+ reserveX: this.lbPair.reserveX,
10995
+ reserveY: this.lbPair.reserveY,
10996
+ tokenXMint: this.lbPair.tokenXMint,
10997
+ tokenYMint: this.lbPair.tokenYMint,
10998
+ binArrayLower: lowerBinArray,
10999
+ binArrayUpper: upperBinArray,
11000
+ sender: owner,
11001
+ tokenXProgram: TOKEN_PROGRAM_ID2,
11002
+ tokenYProgram: TOKEN_PROGRAM_ID2
11003
+ }).instruction();
11004
+ return [...preInstructions, depositLiquidityIx];
11005
+ }
10872
11006
  /**
10873
11007
  * Initializes bin arrays for the given bin array indexes if it wasn't initialized.
10874
11008
  *