DEV Community

Superwavvy
Superwavvy

Posted on

Building a DeFi Monitoring System: 2 Bots, Real Data, Real Insights

I started building on-chain tools in September with a simple goal: learn blockchain development while creating something useful. Two weeks later, I had two production bots collecting real Ethereum data. Here's what I built, why, and what the data tells us.

The Problem

DeFi moves fast. Token prices swing 5-10% in hours. Liquidations happen constantly. If you're monitoring these manually, you're always behind. I wanted to automate the watching and get instant alerts.

But more importantly, I wanted to understand how it works by building it myself.

The System

Two complementary bots:

  1. Price Alert Bot — Monitors token prices every 2 hours, sends Telegram alerts on 5%+ moves
  2. Liquidation Detector — Polls Aave every 15 minutes, sends Discord alerts when liquidations happen

Both feed into Supabase PostgreSQL for persistence and analysis.

Everything runs 24/7 on Termux (Node.js on my Android phone) in tmux sessions. No cloud servers. No DevOps overhead.

Building It

Price Alert Bot

The concept is simple: fetch prices, compare to history, alert on meaningful moves.

const price = await getPriceFromCoingecko('UNI');
const lastPrice = await loadFromSupabase('UNI');
const changePercent = ((price - lastPrice) / lastPrice) * 100;

if (Math.abs(changePercent) >= 5) {
  await sendTelegramAlert(`📈 UNI moved ${changePercent}%`);
}
Enter fullscreen mode Exit fullscreen mode

The harder part: avoiding API limits. CoinGecko free tier is strict. I learned that checking every 15 minutes (96 calls/day per token) hits limits fast. Solution: check every 2 hours instead (12 calls/day per token). Still catches all meaningful moves.

Liquidation Detector

Liquidations are blockchain events. When someone's collateral drops below their debt threshold, Aave liquidates them. The event fires on-chain instantly.

I tried event listeners first (like traditional blockchain monitoring). Free-tier Alchemy killed the connection after 5 minutes with timeouts.

Switched to polling instead: query the last 9 blocks every 15 minutes (under Alchemy's 10-block free-tier limit). More reliable, same result.

const logs = await provider.getLogs({
  address: AAVE_LENDING_POOL,
  topics: [LIQUIDATION_CALL_TOPIC],
  fromBlock: currentBlock - 9,
  toBlock: currentBlock
});

logs.forEach(log => {
  // Parse event data, store to Supabase, send Discord alert
});
Enter fullscreen mode Exit fullscreen mode

Real Data: 2 Weeks In

Running both bots for 2 weeks gives us actual insights:

Price Analysis

UNI (74 price records):

  • Range: $5.68 - $7.20
  • Volatility: 26.76%
  • Change: +2.21%

AAVE (18 records):

  • Range: $124.48 - $129.57
  • Volatility: 4.09%
  • Change: -3.53%

Key insight: UNI is way more volatile than AAVE. If you're building a risk model, token volatility matters. A 5% alert threshold for UNI catches real moves. Same threshold for AAVE would fire constantly.

Liquidation Analysis

Liquidations detected: 0 (so far)

This might sound like a failure. It's not. Aave is well-capitalized. Most positions are healthy. Liquidations spike during crashes (March 2020, May 2022). Right now, markets are calm.

But the data tells us: The detector is working correctly. It's querying the right contract, decoding events properly, storing to Supabase. When crashes come, we'll have real-time visibility.

Architecture Lessons

Why Supabase?

Serverless PostgreSQL. Free tier gets 500MB + unlimited read/write to a point. Perfect for side projects. Both bots share one project with separate tables.

Deduplication is built in: tx_hash UNIQUE prevents storing the same liquidation twice.

Why Polling Over Events?

Event listeners sound better (real-time vs. 15-minute latency). But free-tier providers are unreliable. Polling every 15 minutes is more stable than event listeners that disconnect every 5 minutes.

The tradeoff: real-time vs. reliability. I chose reliability.

Running on Your Phone

My laptop stays off. My phone runs 24/7. Termux lets me run Node.js on Android like a normal Linux environment. I use tmux to keep both bots alive in background sessions that survive disconnects and phone restarts.

To start the bots:

tmux new-session -d -s price-alert "node price-alert-bot.js"
tmux new-session -d -s liquidation "node liquidation-detector.js"
Enter fullscreen mode Exit fullscreen mode

Check they're running:

tmux list-sessions
Enter fullscreen mode Exit fullscreen mode

View live output anytime:

tmux attach -t price-alert
Enter fullscreen mode Exit fullscreen mode

(Exit with Ctrl+B then D — doesn't kill the process)

That's it. Both bots run in the background forever. My phone is now a DeFi monitoring station.

Open Source

Both bots are on GitHub:

  • Price Alert Bot: github.com/superwavvy/price-alert-bot
  • Liquidation Detector: github.com/superwavvy/liquidation-detector

No monetization yet. Just sharing what works.

Conclusion

DeFi moves fast. Building fast is how you keep up. I built two monitoring bots in 2 weeks, deployed them to production (my phone), collected real data, and learned more about blockchain than any course could teach.

The data is boring right now (0 liquidations, 2% price movement). But boring data on a working system beats exciting theories on a broken one.


Running on: Termux (Android), Node.js v26, Supabase, Alchemy API (free tier), CoinGecko API (free tier)

Tools: ethers.js v6, axios, node-cron, tmux

Timeline: Sept 1 - Sept 10, 2026. Full time learning, part-time earning.

Top comments (0)