Building an On-Chain Liquidation Bot on Solana

Building an On-Chain Liquidation Bot on Solana

Building the liquidation bot taught me more about on-chain state than any tutorial could.

The core challenge isn’t the liquidation itself — it’s the monitoring. You have to keep a live view of every borrower’s health factor across a protocol, react in milliseconds when one drops below threshold, and execute atomically before anyone else does.

What I Built

The bot monitors borrower positions on a DeFi lending protocol, calculates health factors in real time, and submits liquidation transactions when a position becomes eligible. It handles slippage, gas estimation, and MEV-awareness.

The Hard Parts

RPC reliability — a single RPC endpoint will let you down at the worst moment. Running multiple endpoints with automatic failover is non-negotiable.

Ordering — the mempool is adversarial. By the time your tx lands, someone else may have already liquidated the position. Tracking what’s in-flight and gracefully handling failed liquidations matters more than raw speed.

Health factor math — every protocol does it slightly differently. Reading the smart contract source directly rather than relying on SDK abstractions saved me a lot of subtle bugs.

Lessons

Start with a read-only monitor that just logs eligible positions before you touch execution. It’s boring, but it’s how you validate your math before real money is at risk.

Full source on GitHub.

Related Posts

BankBud: From Rate Tracker to DeFi Onboarding Funnel

BankBud: From Rate Tracker to DeFi Onboarding Funnel

Problem The average US savings account pays 0.01–0.10% APY. High-yield savings accounts (HYSAs) offer 3.8–4.5%. And DeFi stablecoin yields sit at 4–9%. That's not a small gap — on a $50,000 ba

read more
Building a DeFi Dashboard — Architecture Decisions

Building a DeFi Dashboard — Architecture Decisions

I spent the last few months building a liquidation bot for Aave V3 on Arbitrum. The architecture decisions along the way are worth writing down — not because they're perfect, but because they illustra

read more
MEV on Solana: What's Different from Ethereum

MEV on Solana: What's Different from Ethereum

Coming from Ethereum MEV research, Solana felt familiar on the surface and deeply different underneath. No Mempool The biggest shift: Solana has no public mempool. Transactions go directly to the

read more
What Traditional Banks Need to Understand About DeFi

What Traditional Banks Need to Understand About DeFi

I work in traditional banking by day and build DeFi projects by night. From the inside, I can tell you: most bankers misunderstand what DeFi actually is. They hear "crypto" and think speculation,

read more
From Banker to Builder

From Banker to Builder

I work in banking by day. I build crypto projects by night. Most people assume these worlds are in conflict. They're not. If anything, understanding one makes you better at the other. How I Got H

read more