BIA: 3rd Fastest on a Raydium Pool
· solana, jito, mev, typescript, redis
BIA is a trading bot I’ve been building since early February. She does one thing: when a new token pool opens on Raydium, she tries to be one of the first buyers, then sells a few seconds later. No model and no social signal. The only input is “this pool is new.”
On most pools she landed somewhere between the 10th and 15th buy. On her best pools she beat the competing bots and got the 3rd. Nearly every speedup along the way came from removing a wait, not from a faster language or server.
This post follows one pool from the moment it’s announced to the moment BIA sells, and covers what each stage taught me.
T − minutes: the pool announces itself
The race starts before the pool opens. When someone creates a pool on Raydium’s AMM v4, the creation transaction can set an open_time in the future, and it shows up in the program’s log line: init_pc_amount, init_coin_amount, open_time. Everyone watching the chain learns the exact second trading will start, often minutes ahead.
So BIA doesn’t need to see the pool first. She needs to have everything ready when the clock hits zero. Her ears are a websocket subscription to the logs of Raydium’s pool-creation fee account:
// BIA's monitoring system: websocket on the logs of
// Raydium LP V4's pool-creation fee account
function findTokensToSwap(connection, programAddress) {
connection.onLogs(programAddress, ({ logs, err, signature }) => {
if (err) return
if (seenTransactions.includes(signature)) return
if (logs?.some(log => log.includes("init_pc_amount"))) {
seenTransactions.push(signature)
parseTxnThenShare(signature)
}
}, "finalized")
}
She listens at finalized commitment, the slowest of the three levels. For a pool opening minutes from now, a few seconds of detection lag costs nothing. The seenTransactions check is there because of a February 7 note to myself: “the new pool buys are being duplicated right now.”
Before she passes a pool on, she drops anything that isn’t paired with SOL. As of February 17 she also skips “flipped” pools, where SOL is the base token instead of the quote.
T − seconds: do everything early that can be done early
To swap against a Raydium pool you pass about eighteen accounts: the pool, its vaults, its authority, the OpenBook market, and the market’s bids, asks and event queue. Fetching them one by one is slow. But almost all of them are program-derived addresses, computed from the market ID and a fixed seed. The creation transaction gives you the market ID, and the rest is hashing:
// condensed from derivePoolKeys(): every pool account is a PDA of the market ID
const pda = (seed: string) =>
findProgramAddress([raydium.toBuffer(), marketId.toBuffer(), Buffer.from(seed)], raydium)
id: pda('amm_associated_seed'),
baseVault: pda('coin_vault_associated_seed'),
quoteVault: pda('pc_vault_associated_seed'),
openOrders: pda('open_order_associated_seed'),
targetOrders: pda('target_associated_seed'),
Only three reads touch the network: the market account and the two mints. Everything else is local.
The buy instructions get built at this stage too, while there’s still time to spare. They create and fund a wrapped-SOL account, sync it, create the token account, swap, and close the wrapped-SOL account. Then a timer is set for the exact open time, in milliseconds. (The first version scheduled in whole seconds, which threw away up to a second per pool.) I also turned off preflight simulation. A February 7 note guessed that would save 2–3 seconds per send. I never isolated that number, but nothing about a sniper benefits from a dry run.
T − 0.4 s: whose block is it?
Solana itself doesn’t have a public mempool. Each slot (roughly 400 ms) has one leader that builds the block, and leaders hold four consecutive slots before the next one takes over. To get ahead of other buyers in the same block, you send a Jito bundle. That’s an ordered, all-or-nothing group of transactions with a tip, delivered through a block engine to leaders running Jito’s validator client. Jito runs engines in several regions, and every leader running its client is connected to one of them.
My first version tried to be clever about timing. At the open time it asked the block engine who the next leader was, and waited until that leader was two slots or fewer away before sending:
// Feb 13: wait for the leader slot, then send once
let isLeaderSlot = false
while (!isLeaderSlot) {
const nextLeader = await jitoClient.getNextScheduledLeader()
isLeaderSlot = nextLeader.nextLeaderSlot - nextLeader.currentSlot <= 2
await wait(250)
}
await jitoClient.sendBundle(bundle) // Frankfurt only
That one call was the problem. When I timed it, getNextScheduledLeader() took about 2.1 seconds, and 8 seconds to check every region. That’s five slots gone just asking the question. After the bot had been running for about half an hour it was down to about 200 ms (131 ms minimum, 394 ms maximum), but even that is half a slot.
On February 14 I deleted the loop. Now the same bundle goes to all four engines the instant the timer fires, and again every 800 ms for a few rounds. The tip also moved inside the buy transaction instead of riding along as a second one:
// Feb 14: don't ask, just send everywhere
await jitoClientNewyork.sendBundle(bundle)
await jitoClientFrankfurt.sendBundle(bundle)
await jitoClientAmsterdam.sendBundle(bundle)
await jitoClientTokyo.sendBundle(bundle)
The commit message says “speedup seen from sending a bundle to each region and not waiting for leader slot.” Whichever engine the leader is connected to already has the bundle when its slot arrives. Copies of the same bundle can’t double-buy, because a signed transaction can only land once.
Once the workers arrived (next section), I revisited the leader on February 18. One plan was to have each worker schedule its swap only if the next leader was within five slots, which is the 2.1 s call plus a 400 ms buffer. It also meant accepting that workers in different regions might each buy. My own note called that fragile, and floated a simpler version: schedule the swap 2 s before the open, and check that the leader is within two slots right before sending.
T + 0: one listener, many hands
Until February 15, every copy of BIA did everything: listen, parse, build, send. Running several of them meant every copy fetched the same transaction and derived the same keys, which is wasted work right before the moment that matters. So I split her in two.
BIA became a pure listener. She parses the pool, derives the keys and works out the open time, the “birthday.” Then she publishes one small message. The workers (I called them the daddys) subscribe, build the buy and fire it at the birthday. The first transport was raw websockets. Within an hour I’d replaced them with Redis pub/sub, which gave fan-out to any number of subscribers for free:
async function tellDaddysToScheduleBuy(pk, birthday) {
await redis.publish(channelName, JSON.stringify({ poolKeys: pk, birthday }))
}
That evening I trimmed the message down to just the pool keys and the birthday, so the hot path carries nothing a worker doesn’t need. On February 21 a second channel arrived for pools that were already open when BIA found them. Those skip the timer and buy immediately.
T + 1–3 s: in. T + 3–4 s: out.
The commit from the evening of February 14 just says “she is buying in 1-3s and selling in 3-4s… amazing.” In other words, in and out within about four seconds of the open.
The exit is a loop that runs every half second. It reads her token balance straight from the account’s raw bytes (an 8-byte slice at offset 64), builds a sell for the whole amount and sends it as a plain transaction, with no bundle and no preflight. It gives up after ten tries. That limit only worked after a fix the same night: “forgot to clear the interval if the swap out fails after 10 attempts… lol.” Until then, a pool that never let her out kept a timer firing forever.
What moved the needle
| Date | Change | Effect |
|---|---|---|
| Feb 7–12 | Skip preflight; build buys before the open | Estimated 2–3 s saved per send (my note at the time, never isolated) |
| Feb 14 | Stop waiting for the leader; send to all four Jito engines | Speedup seen that day; buys in 1–3 s, sells in 3–4 s |
| Feb 14 | Schedule in milliseconds, not seconds | Up to 1 s less drift at the open |
| Feb 15 | Split into a listener and workers over Redis pub/sub | One parse per pool, no matter how many workers |
| Feb 17 | Drop flipped pools | One swap direction left to handle |
| Feb 21 | Instant channel for already-open pools | Pools found late no longer wait for a timer |
After the race
At the end of February I started a different branch. Instead of reading pool creations after they landed, it read pending transactions from Jito’s mempool and built a bundle around the pool-creation transaction itself, so the buy could ride in the same bundle as the pool’s birth. By March 5 it was filtering just the New York mempool and assembling bundles, with every commit marked DO NOT PULL.
It never shipped. On March 8, Jito shut its mempool down, citing the sandwich attacks it had enabled against ordinary traders. The branch has been parked ever since.
What I’d take into the next bot isn’t a trick that’s specific to Solana:
- Measure the question before you ask it. The leader lookup was the slowest thing in the hot path. It was there to save effort, and it cost more than the effort it saved.
- Do the work before the clock starts. Keys, instructions and accounts can all be ready before the open. The only thing left at T = 0 should be signing and sending.
- Make the hot message small. Fanning work out to the workers only helps if what’s sent to them is tiny.