As the title suggests the goal is to listen to all Raydium swaps that happen live, preferably via websockets and be able to decode meaningful info. I have a code snippet that to my understanding does half of the equation but I have some questions regarding the decoding part.
console.log("Monitoring logs for program:", programAddress.toString());
connection.onLogs(
programAddress,
({ logs, err, signature }) => {
if (err) return;
if (logs && logs.some(log => log.includes("swap"))) {
console.log("Signature for 'swap':", signature);
fetchAndDecodeSwapInstruction(signature, connection);
}
},
"confirmed"
);
Inside the fetchAndDecodeSwapInstruction
I can parse the logs and deduce some info but I want a more general way to handle all types of Raydium swaps and decode amounts in and out, token addresses and pair address. I have a snippet where I check if the instruction's programId
is the RAYDIUM_PUBLIC_KEY
like so
for (const instruction of instructions) {
if (instruction.programId.toBase58() === RAYDIUM_PUBLIC_KEY) {
// do something
}
}
But it never triggers which is confusing to me. I am familiar with how ETH works but not much with Solana so I would appreciate it if anyone can point me to the right direction or even better some example code in Javascript.