Jack Allan Kasbeer

← Inventions & Projects

BIA: 3rd Fastest on a Raydium Pool

· solana, jito, mev, typescript, redis

I put a call to getNextScheduledLeader() in BIA because I wanted to send a transaction at the right moment. The first time I measured it, the answer took about 2.1 seconds. A Solana slot was roughly four-tenths of a second. While the bot was asking whose turn it was, about five turns went by.

I built BIA in TypeScript over six weeks in early 2024. She watched new Raydium pools and tried to buy as they opened. In the pools I watched she was usually somewhere around the tenth to fifteenth buyer. The best position I saw was third. That was a place in line. I didn’t collect a network-wide benchmark.

A row of fifteen numbered boxes for the first fifteen buys in a new pool. Box 3 is highlighted as BIA's best result; boxes 10 through 15 are shaded as where she usually landed.
Where BIA's buy landed among a new pool's first trades, from my own watching of the pools she entered.

Minutes to get ready

Some Raydium pool-creation transactions announced an opening time minutes in advance. BIA could read the creation log, check the pair and prepare the pool accounts while she waited. I kept a set of transaction signatures she’d already seen after duplicated notifications started producing duplicated work. Raydium AMM

The early version fetched more data than it needed. Many of those accounts had addresses I could derive locally from the market ID. That left three network reads for the market and the two mints. I also moved the scheduler from whole seconds to milliseconds. A whole second of rounding was a substantial part of the wait I was trying to remove.

February 14, crossing out the loop

My first sender asked a block engine about the next leader and waited until the leader was near. Checking all four regions took about eight seconds in an early measurement. After the process had warmed up the single lookup was closer to 200 milliseconds, still a noticeable fraction of a slot.

On February 14 I removed the wait and sent the same signed bundle to four regional engines. The important word there is same. Four copies of one signed transaction can produce one confirmed purchase. Four workers signing independently are a different design.

Two flows. February 13: when the pool opens, poll getNextScheduledLeader every 250 milliseconds until the leader is two slots or fewer away, then send the bundle to Frankfurt. February 14: when the pool opens, send the same bundle to New York, Frankfurt, Amsterdam and Tokyo at once; the leader's own engine already has it, and one signature can only land once.
February 14: stop predicting the leader and cover every engine it could be listening to.

That evening’s notes put buys at roughly one to three seconds and sells at three to four seconds after opening. I made several changes that week. I could time the whole build, but I couldn’t assign the improvement to one change.

February 15, one listener

At first each running copy watched the chain, parsed the same creation and derived the same keys. I moved that work into one listener and published the pool keys and opening time to workers over Redis. A second channel handled pools that were open by the time we found them. Redis Pub/Sub

Architecture: Raydium AMM v4's pool-creation fee account feeds BIA through onLogs. BIA parses the transaction, derives pool keys and reads the open time, then publishes to a Redis schedule channel if the pool opens later or an instant channel if it's already open. Workers subscribe to both, build the buy, and send it as a bundle to Jito's New York, Frankfurt, Amsterdam and Tokyo block engines, which reach the current leader, and the buy lands in the new pool.
BIA as of February 21: one listener, two channels, workers, four block engines.

The exit loop had a smaller timing bug. It checked the balance every half-second and was supposed to give up after ten tries. I’d forgotten to clear the interval on failure. A pool could be long over and the bot would still be waking up for it.

The branch that stayed in the repo

In March I had an experimental branch that listened for pending pool creations. It never shipped. Jito shut down its mempool service on March 8, and I parked the branch.

When I read those six weeks of notes now, the number I remember is 2.1 seconds. It was an ordinary network call, placed at the one point in the program where I had no time to spare.