DEV Community

MetaVision
MetaVision

Posted on

How We Built an Autonomous DeFi Liquidation Bot and Passed an AGI Evaluation — All in One Week

We're a small team building MetaVision — a Web3 AI platform on Base network. This week we hit two unexpected milestones: our autonomous liquidation bot is live and monitoring $66M in Morpho Blue positions, and our AI agent passed an AGI causal reasoning evaluation. Here's how.

The DeFi Liquidation Bot

Aave V3 and Morpho Blue on Base network have liquidatable positions when a borrower's Health Factor drops below 1.0. We built two monitors:

Aave Monitor (Python) — polls 12,769 borrowers every 15 seconds using direct RPC calls, finds positions with HF < 1.05, and executes liquidations automatically.

Morpho Blue Monitor (Python) — monitors the WETH/USDC market with $66M in borrowings. When HF < 1.0, it calls Morpho's liquidationCall() directly with the correct marketParams struct.

Rust Bot — event-driven WebSocket subscriber that listens to Uniswap V3 and Aerodrome swap events for arbitrage opportunities, now extended with Aave position checks.

Key technical decisions:

# Dynamic debt/collateral detection — no hardcoded assets
for sym, addr, dec in RESERVES:
    rd = dp.functions.getUserReserveData(addr, user).call()
    if rd[2] > debt_amt:  # variable debt
        debt_amt = rd[2]
        debt_asset = addr
    if rd[0] > 0 and collateral_asset is None:
        collateral_asset = addr
Enter fullscreen mode Exit fullscreen mode

The Morpho liquidation incentive is ~4.88% for 86% LLTV markets — meaning we pocket ~$3.81 on a $78 USDC liquidation.

We discovered that Morpho uses a marketParams struct (not individual token addresses like Aave), which caused our first liquidation attempts to revert:

market_params = (
    USDC_ADDR,    # loanToken
    WETH_ADDR,    # collateralToken  
    ORACLE_ADDR,  # oracle
    IRM_ADDR,     # irm
    860000000000000000  # lltv 86%
)
morpho.functions.liquidate(market_params, borrower, seized, 0, b'').call()
Enter fullscreen mode Exit fullscreen mode

The AGI Evaluation

While building, we discovered pathtoAGI Observatory — a fully autonomous evaluation system that tests whether AI agents can reconstruct unknown causal structures from data alone.

World-009: Four variables (p,q,r,s) mod an unknown prime with unknown causal structure. We had to find the prime, the DAG, and predict 12 held-out interventions.

Our approach:

  1. Identify the prime (107) by checking max values
  2. Brute-force linear relationships: q = (a*p + b) mod prime
  3. Discover fan-out DAG: p → q, r, s
# Found structure:
# q = (104*p + 96) mod 107
# r = (59*p + 75) mod 107  
# s = (42*p + 50) mod 107
Enter fullscreen mode Exit fullscreen mode

World-010: Four observed variables (a,b,c,d) where the truth involves a latent variable never shown. We had to posit it exists and reconstruct the full structure.

Key insight from intervention analysis:

  • do_a → only a changes (a is a leaf)
  • do_bb and d change (b→d edge exists)
  • do_c → only c changes (c is a leaf)
  • When do_b, a and c don't change → they share a hidden common cause h

Final structure: h → a, h → b, h → c, b → d with d = (67*b + 3) mod 109

Result: 10/10 on shown interventions. Attempt anchored on-chain via OpenTimestamps before reveal.

The MCP Server

We also run a 21-tool MCP server at https://metavision.click/mcp with:

  • CVE Oracle (355k+ NVD vulnerabilities, Web3-focused)
  • DeFi arbitrage signals (live Uniswap V3 vs Aerodrome)
  • AI inference via x402 micropayments on Base
{
  "mcpServers": {
    "metavision": {
      "type": "http",
      "url": "https://metavision.click/mcp"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

What's Next

  • Results from pathtoAGI evaluation (July 13 and 16)
  • First successful DeFi liquidation (positions at HF 1.01 right now)
  • Morpho Blue integration with flash loans for larger positions

Follow our progress at metavision.click or check the GitHub repo.

Built with Python, Rust, alloy, web3.py, Flask, and Claude as pair programmer.

Top comments (0)