const DLMM = require('@meteora-ag/dlmm').default; const { Connection, PublicKey } = require('@solana/web3.js'); const POOL_ADDRESS = "GZ65Nw5MCJUaEEDFdpoV5CNgnyh3JDZJB6JFtAXEAjeH"; const USER_ADDRESS = "5Xihd2FdAXZnER7HWjT8GiZm14hyPiUpGfqLLL86yaa9"; (async () => { try { const connection = new Connection( 'https://mainnet.helius-rpc.com/?api-key=4754acdc-8330-4d7d-98bd-b9b35af1b178' ); const dlmmPool = await DLMM.create(connection, new PublicKey(POOL_ADDRESS)); const { tokenX, tokenY } = dlmmPool; const { address: tokenXAddress, decimals: tokenXDecimals } = tokenX.mint; const { address: tokenYAddress, decimals: tokenYDecimals } = tokenY.mint; // Ensure userPositions is always an array const { userPositions = [] } = await dlmmPool.getPositionsByUserAndLbPair( new PublicKey(USER_ADDRESS) ); const results = []; for (const position of userPositions) { const { positionData } = position; const { totalXAmount, totalYAmount } = positionData; const formattedXAmount = totalXAmount / 10 ** tokenXDecimals; const formattedYAmount = totalYAmount / 10 ** tokenYDecimals; results.push({ positionAccountAddress: position.publicKey.toBase58(), tokenXAddress: tokenXAddress.toBase58(), tokenXAmount: formattedXAmount, tokenYAddress: tokenYAddress.toBase58(), tokenYAmount: formattedYAmount }); } // Always output a JSON array console.log(JSON.stringify(results)); process.stdout.write("\n"); // ensure stdout flushes } catch (error) { // Output error as JSON to keep Python parsing safe console.error(JSON.stringify({ error: error.message || error })); process.exit(1); } })();