Created
February 11, 2026 11:19
-
-
Save mukul013/0a19844af112b222eb799ab42f9e1a4b to your computer and use it in GitHub Desktop.
Open dlmm position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.info(`Using initializeMultiplePositionAndAddLiquidityByStrategy for binDifference: ${binIdDifference}`); | |
| console.info(`Selected strategy: ${selectedStrategy}`); | |
| console.info(`Total X Amount: ${totalXAmount.toString()}, Total Y Amount: ${totalYAmount.toString()}`); | |
| console.info(`Min Bin ID: ${minBinId}, Max Bin ID: ${maxBinId}`); | |
| const { instructionsByPositions } = await dlmmPool.initializeMultiplePositionAndAddLiquidityByStrategy( | |
| async (count) => { | |
| const positionKeypairs = []; | |
| for (let i = 0; i < count; i++) { | |
| positionKeypairs.push(Keypair.generate()); | |
| } | |
| return positionKeypairs; | |
| }, | |
| totalXAmount, | |
| totalYAmount, | |
| { | |
| minBinId, | |
| maxBinId, | |
| strategyType: selectedStrategy, | |
| }, | |
| signer.publicKey, | |
| signer.publicKey, | |
| isRetry ? 23 : 15, | |
| ); | |
| // Extract position keypair and instructions from first position | |
| const { positionKeypair, initializePositionIx, initializeAtaIxs, addLiquidityIxs } = instructionsByPositions[0]; | |
| positionAddress = positionKeypair.publicKey.toBase58(); | |
| // Create transactions array | |
| const transactions: VersionedTransaction[] = []; | |
| const blockhash = (await getConnection().getLatestBlockhash()).blockhash; | |
| // First transaction: Initialize position with Valhalla fee | |
| const initInstructions = []; | |
| if (initializeAtaIxs && initializeAtaIxs.length > 0) { | |
| initInstructions.push(...initializeAtaIxs); | |
| } | |
| initInstructions.push(initializePositionIx); | |
| const initPositionTx = new VersionedTransaction( | |
| new TransactionMessage({ | |
| payerKey: signer.publicKey, | |
| recentBlockhash: blockhash, | |
| instructions: initInstructions, | |
| }).compileToV0Message([]), | |
| ); | |
| // adding the init position tx | |
| transactions.push(initPositionTx); | |
| // Additional transactions: Add liquidity instructions | |
| for (const addLiquidityIxArray of addLiquidityIxs) { | |
| const addLiquidityTx = new VersionedTransaction( | |
| new TransactionMessage({ | |
| payerKey: signer.publicKey, | |
| recentBlockhash: blockhash, | |
| instructions: addLiquidityIxArray, | |
| }).compileToV0Message([]), | |
| ); | |
| transactions.push(addLiquidityTx); | |
| } | |
| const txProcessor = this.createTransactionProcessor(discordUserId, signer); | |
| // Send and confirm the bundle of transactions | |
| const signerConfigs = []; | |
| // First transaction is initialize position, so we add the position keypair as an additional signer | |
| signerConfigs.push({ | |
| transactionIndexes: [0], // First transaction is initialize position | |
| additionalSigners: [positionKeypair], | |
| }); | |
| const bundleTxHash = await txProcessor.sendAndConfirmMultiple( | |
| transactions, | |
| 'open DLMM position (multiple)', | |
| signerConfigs, | |
| ); | |
| if (!bundleTxHash) { | |
| throw new Error('Failed to confirm DLMM open position transaction bundle'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment