DeFi protocol liquidity monitoring

We design and develop full-cycle blockchain solutions: from smart contract architecture to launching DeFi protocols, NFT marketplaces and crypto exchanges. Security audits, tokenomics, integration with existing infrastructure.
Showing 1 of 1 servicesAll 1306 services
DeFi protocol liquidity monitoring
Medium
~3-5 business days
FAQ
Blockchain Development Services
Blockchain Development Stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1214
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_logo-advance_0.png
    B2B Advance company logo design
    561
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823

DeFi Protocol Liquidity Monitoring

A protocol with $50M TVL without liquidity monitoring is not saving on tools, it's blind risk management. When 30% of liquidity leaves a pool in 4 hours due to whale withdrawal, the team has two options: learn about it through an alert and take action, or learn from a tweet that users can't execute swaps due to high slippage.

What to Monitor and Why It's Non-Trivial

Liquidity Concentration in Uniswap v3

In Uniswap v2, total liquidity is a clear metric: reserve0 * reserve1 = k, bigger k means better slippage. In Uniswap v3, liquidity is concentrated by ticks. A pool can have $10M TVL, but if 95% is concentrated in ±2% range from current price — when price exits this range, effective liquidity drops 20x.

Correct monitoring: not just totalValueLocked, but activeLiquidity — liquidity in active range around current price. Metric from Uniswap v3 subgraph:

query ActiveLiquidity {
  pool(id: "0x...") {
    liquidity
    sqrtPrice
    tick
    ticks(where: { liquidityNet_not: "0" }, orderBy: tickIdx) {
      tickIdx
      liquidityNet
    }
  }
}

From this data, build depth chart: how much liquidity available at ±1%, ±5%, ±10% price move.

Whale Withdrawal Detection

Large LP can withdraw liquidity at once, crushing depth on specific market. For protocol depending on liquidity in specific pools (e.g., stablecoin pool for redemption), this is critical risk.

Monitor Burn events (Uniswap v3) and RemoveLiquidity events (Curve, Balancer) via WebSocket subscription. If one LP withdraws >10% of total liquidity — alert immediately.

Monitoring Stack

Data Collection

Three layers of sources:

On-chain events (realtime). ethers.js WebSocket subscription to Sync, Swap, Mint, Burn events of target contracts. Delay — seconds from transaction confirmation. Need own node or WSS from Alchemy/Infura with eth_subscribe support.

The Graph subgraphs (with 1-5 minute delay). Convenient for aggregated metrics — hourly/daily TVL, volume, fees. For historical data and trends. Official subgraphs from Uniswap, Curve, Balancer, Aave, Compound available in The Graph Explorer.

DeFi Llama API (with 10-60 minute delay). Convenient for cross-protocol TVL comparisons and general picture. Not suitable for realtime alerts.

Storage and Visualization

TimescaleDB (PostgreSQL extension) is optimal for time-series liquidity data. Time-based partitioning, hypertables for automatic archiving of historical data.

Grafana + TimescaleDB datasource — standard stack for dashboard. Pre-configured panels for:

  • TVL per pool in realtime
  • Depth chart (available liquidity at given slippage)
  • Volume/liquidity ratio (stress indicator)
  • Top LP providers and their share

Alert System

Metric Warning Threshold Critical Threshold Channel
TVL drop -10% per hour -25% per hour Telegram
Single LP withdrawal >5% total liquidity >15% total liquidity PagerDuty
Slippage (1% trade) >0.5% >2% Telegram
Price deviation from oracle >2% >5% PagerDuty
Utilization (lending) >80% >95% PagerDuty

PagerDuty or OpsGenie for critical alerts — push notification to phone, regardless of time. Telegram bot for informational notifications.

Tenderly Alerts — alternative for on-chain events without own infrastructure: configure triggers via UI, webhook to Discord/Slack/Telegram.

APY Calculation and Monitoring

APY in DeFi is not constant: depends on volume (trading fees), token emission (liquidity mining rewards), and base rate (for lending).

Formula for LP APY in Uniswap v3:

dailyFees = pool.volumeUSD24h * feeTier / 1_000_000
feeAPR = (dailyFees / pool.tvlUSD) * 365

At $1M TVL and $2M daily volume on pool with 0.05% fee (500): dailyFees = $1000, feeAPR = 36.5%. But this is for all TVL. LP with concentrated position in active range earns more proportionally to their effective liquidity.

Monitor APY per pool with alerting on sharp drops — signal of reduced trading activity or volume moving to competing pool.

Implementation Process

Inventory (1 day). List all contracts, events, metrics for monitoring. Prioritize: what's critical for protocol operation.

Data Collection Setup (1-2 days). WebSocket indexer on Node.js/TypeScript, write to TimescaleDB. For historical data — initial sync via The Graph.

Dashboard (1 day). Grafana with main panels. Doesn't need to be beautiful — needs to be readable with correct time windows.

Alerts (1 day). Thresholds based on protocol historical data. Too sensitive alerts — team stops reacting to them. Start with 5-6 critical metrics.

Timeline Estimates

Basic monitoring of one protocol (TVL, events, alerts) — 3-5 days. Comprehensive monitoring of multiple protocols with depth chart, APY tracking and custom dashboard — up to 2 weeks.