My MEV story

My MEV story - one of opportunity, luck, incompetence, competition, discovery and euphoria.

This time last year, my best friend in the whole world asked me if I was interested in a 'Solidity project'. He had been following a lending protocol for some time, and thought there was an edge in liquidating their insolvent positions.

I had been learning about the EVM and mempool activity previously, and was working in corporate land as an optimisation specialist, but the idea of processing information as fast as possible and racing to do something was very exciting. Especially when he told me the percentages involved.

If a position in a collateralised loan became insolvent, the liquidator could earn up to 10% of the position size by detecting and liquidating that position.

It's on... My goal was to model all positions in this protocol, and determine when to call (a seemingly trivial) contract method on those positions when they became insolvent.

My Real World job was 100% Ruby. I found a Ruby library that let me interact with Ethereum contracts and started gathering data. I was later informed that I was likely to be the only person on the planet doing MEV in Ruby :)

I used the Etherscan API to grab addresses which had interacted with the protocol, and wrote some basic contract wrappers to pull their balances.

If any of the positions were insolvent, I dumped the details out to STDOUT.

The user wallet address, the collateral type, and how much they had borrowed.

We started out brute force. Every block we would poll the entire position set. We moved from STDOUT to Discord messages. If anything looked like it was insolvent, the bot would send a message to a private Discord server with relevant details.

To prove the concept we needed to know the wallet addresses of the positions, and the amounts they had borrowed. This data could be fed into the protocol contract to liquidate insolvent positions.

So our bot just alerted with that content, formatted to copy & paste into Etherscan as quickly as possible, along with a link directly to the Write section of the contract.

The first few days we saw a handful of insolvent positions. We took it in turns to race to Etherscan to attempt the liquidations.

Sometimes it worked. It was exhilarating. Nothing huge though. A few dollars here and there, if gas was cheap enough.

At this point everything was running on my laptop. It was slow. Geth is a heavy bastard.

I fired up some bare metal hosting and moved everything over. Running on the basis of alerting on Discord, hoping one of us was around to execute manually on Etherscan.

The day after we moved everything over to a dedicated server running a full Geth node and our scanning code (“the bot”), the crypto world shat itself.

In one night, Dec 3rd to the 4th, ETH dropped 20%.

The bot went crazy. I was asleep. My friend was awake...

I woke up the next morning to 20+ missed calls. Alerts on all devices. I had no idea. I was tired from coding all night, making sure the software was running correctly.

I replied to one of the text messages, and was called back immediately.

"Mate. It fucking worked. Are you sitting down?”

Over the next 15 mins, he explained how he had reacted to every alert the bot had posted to the Discord. How multiple million dollar positions had become insolvent due to the market collapse, and how he had spend the night reacting to those alerts.

Some positions were just too big to liquidate. There was no liquidity available - he had to manually adjust the sums involved and chip away at them. Hero.

Over a series of manual Etherscan transactions, populated with inputs generated by our bot, we had liquidated millions of dollars of insolvent positions.

I woke up to find out this software had netted real, life-changing money in profit.

At this stage, the only explanation as to why we were able to win like this, was that all the other bots in the game had run out of ETH due to the black swan event. At first he couldn’t win anything, then eventually he was winning everything.

Running everything manually was our temporary edge, and it paid. Massively.

The other bots ran out of gas before the big positions exposed themselves. We could manually move funds around and liquidate via the Etherscan Web UI.

We had a great Christmas.

I went into full time MEV learning mode. Regular work seemed so ridiculously dull in comparison. Why stress so much over KPIs & improving a corporate web requests by 1ms when I can put the same effort into optimising a Geth call and potentially win another $50K+ liquidation?

I had pretty much checked out of my (seemingly) dream job at this point.

We continued to iterate and layer on optimisations and automations.

We learnt about Flashbots, back-running & oracle monitoring. We had to, as we had to figure out how and why we were losing races.

Each phase of improvements paid off. We acted on every market drop.

We found competitors and eventually beat them (omg 0xeef, I love and hate you). By May we had more than doubled the profit and banked it all.

6 months later, this game seems massively overcrowded. The FB bribes are huge. The liquidation routes are bespoke and ridiculously advanced. And after PoS, I'm not even sure if our txs are making it into the new world of profitable block building.

I've seen our calls get hijacked by generalised front runners and dynamic contract deployers. That's where I'm spending my research time now.

It's a fun game we're playing. I can't believe how lucky I've been. I've always loved learning, but this is something else!

I’ve gone from Ruby, to Go and have recently started learning about Rust. Please send help.

Come say hi on Twitter. If you’re into that sort of thing.

Subscribe to etherael
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.