Fetched data from a raydium pool.Which values do I need for the calculation of the "fair price" or rather current price?
Outcome should looks something like this : 1 SOL = 169.3 USDC(If the format or the way the question is asked please give me feedback!)Updated this question!import { Connection, PublicKey } from "@solana/web3.js";import { LIQUIDITY_STATE_LAYOUT_V4 } from "@raydium-io/raydium-sdk";const SOL_USDC_POOL_ID = "58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2"; // Your pool IDasync function getTokenBalance(connection: Connection, vault: PublicKey, decimals: number): Promise<number> { const balance = await connection.getTokenAccountBalance(vault); return parseFloat(balance.value.amount) / Math.pow(10, decimals); // Adjust the balance for the token's decimals}async function parsePoolInfo() { const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed"); const info = await connection.getAccountInfo(new PublicKey(SOL_USDC_POOL_ID)); if (!info) return; // Assuming the structure was successfully decoded const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(info.data); // Directly use the specific decimals for SOL and USDC const baseTokenDecimals = 9; // Decimals for SOL const quoteTokenDecimals = 6; // Decimals for USDC const baseTokenBalance = await getTokenBalance(connection, poolState.baseVault, baseTokenDecimals); const quoteTokenBalance = await getTokenBalance(connection, poolState.quoteVault, quoteTokenDecimals); // The calculation remains the same, but the clarification is that these decimals are now hardcoded const priceOfBaseInQuote = quoteTokenBalance / baseTokenBalance; console.log("Decoded Pool Data:", poolState); console.log(`Price of 1 SOL in USDC: ${priceOfBaseInQuote.toFixed(4)}`); // Adjusted for decimals}parsePoolInfo();