Workflows & Recipes

DeFi yield research with AI agents

Written by Rishabh Narang, CEO, Hive IntelligenceLast updated

This guide walks through building an AI agent that ranks DeFi yield opportunities with explicit risk evidence. The agent combines yield data from DeFiLlama, DEX pool analytics from Codex, token-contract risk from GoPlus, and transaction simulation from Tenderly: four capability surfaces, one MCP connection, one API key.


Why yield research is hard

Answering "where should I put stablecoin liquidity this week?" requires four independent signals:

  • Yield pools and APY history (DeFiLlama): rank opportunities and spot decaying yields.
  • Pool liquidity and fees (Codex / DeFiLlama fees): confirm the pool can absorb your position and that the advertised APY comes from real fees, not token emissions.
  • Token contract risk (GoPlus): reject pools whose underlying token is a honeypot, has a tax wall, or has an owner who can mint.
  • Your wallet's outstanding approvals (GoPlus / Moralis): avoid adding approvals to risky contracts you already approved.

Each provider has a different auth header, response shape, rate limit, and error convention. Building a yield scanner across all four is a week of plumbing before you write one business rule.


Prerequisites

  • A Hive API key from /dashboard/keys. Your plan controls monthly credits and rate limits; check Pricing and Rate Limits before scheduling multi-chain or hourly scans.
  • Python 3.11+ or Node.js 20+.
  • A wallet address you want to evaluate approval risk against (read-only, no signing keys needed).

Step 1: Pull the top yield candidates

Start with a broad filter: stablecoin pools on Ethereum above a minimum APY with healthy TVL.

python
from hive_intelligence import HiveClient

hive = HiveClient()

pools = hive.execute("get_yield_pools", {
    "chain": "ethereum",
    "minApy": 5,
    "minTvlUsd": 1_000_000,
    "limit": 50,
})

Expected shape:

json
[
  {
    "pool": "747c1d2a-c668-4682-b9f9-296708a3dd90",
    "project": "aave-v3",
    "symbol": "USDC",
    "apy": 6.8,
    "apyBase": 3.2,
    "apyReward": 3.6,
    "tvlUsd": 412_000_000,
    "chain": "Ethereum"
  },
  ...
]

Split apy into apyBase (organic fees) and apyReward (emissions). Emissions-driven yield decays the moment incentives dry up; base yield compounds. For longer holds, sort by apyBase first.


Step 2: Check protocol health

For every unique project the pool list returns, fetch protocol TVL history:

python
projects = {p["project"] for p in pools}
tvl_snapshots = hive.batch([
    {"tool": "get_protocol_tvl", "args": {"protocol": proj}}
    for proj in projects
])

Reject any project whose TVL is down >25% over the last 30 days. The protocol is losing users even if the pool still offers a headline APY.


Step 3: Audit each pool's underlying token

This is the step that removes 80% of the risk. For every pool, extract the underlying token address(es) and run a security check in parallel:

python
import asyncio
from collections import defaultdict

async def audit_token(token_address):
    result = await hive.aexecute("get_token_security", {
        "chainId": "1",
        "contract_addresses": token_address,
    })
    rec = result.get("result", {}).get(token_address.lower(), {})
    return {
        "address": token_address,
        "is_honeypot": rec.get("is_honeypot") == "1",
        "owner_can_mint": rec.get("owner_change_balance") == "1",
        "buy_tax": float(rec.get("buy_tax") or 0),
        "sell_tax": float(rec.get("sell_tax") or 0),
        "is_proxy": rec.get("is_proxy") == "1",
    }

audits = await asyncio.gather(*(audit_token(a) for a in unique_token_addresses))

Reject any pool where the underlying token is a honeypot, has a buy or sell tax above 1%, or where the owner can mint. These are non-negotiable.


Step 4: Check approval contract risk

Before you approve a pool contract or related router, check whether the approval target has known security risks. Malicious or compromised spender contracts are a common DeFi attack path.

python
approvals = hive.execute("check_approval_security", {
    "chainId": "1",
    "contract_addresses": POOL_CONTRACT_ADDRESS,
})

Expected shape:

json
{
  "result": [
    {
      "token_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "approved_contract": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
      "approved_amount": "unlimited",
      "risk": "high"
    }
  ]
}

Flag any risk: high or risk: medium approval. Recommend the user revoke before adding new capital.


Step 5: Rank and present

Combine the signals into a single score and return the top five:

python
def score(pool, audit, tvl_trend):
    if audit["is_honeypot"] or audit["owner_can_mint"]:
        return None
    if audit["buy_tax"] > 1 or audit["sell_tax"] > 1:
        return None
    if tvl_trend < -0.25:
        return None

    base_weight = 0.7 * pool["apyBase"] + 0.3 * pool["apyReward"]
    size_weight = min(pool["tvlUsd"] / 10_000_000, 1.0)
    return base_weight * (0.5 + 0.5 * size_weight)

ranked = sorted(
    (p for p in pools if score(p, audits_by_addr[p["underlying"]], tvl_trends[p["project"]])),
    key=lambda p: score(...),
    reverse=True,
)[:5]

The agent produces a table that answers the original question, ranked by risk-adjusted real yield rather than headline APY.


Example agent prompt (if you're orchestrating via Claude, not Python)

text
Find the top 5 stablecoin yield opportunities on Ethereum with APY
above 5% and TVL above $1M. For each pool:
  1. Fetch protocol TVL history and reject protocols down >25% in 30 days.
  2. Run token_security on the underlying token and reject honeypots,
     high-tax tokens, and contracts where the owner can mint.
  3. Calculate a score weighted toward base APY over reward APY and
     bigger pools over smaller ones.
  4. Return a markdown table with pool, protocol, apyBase, apyReward,
     tvlUsd, and the specific risk reasons rejected pools failed.

With Hive connected, Claude executes this end-to-end: it fetches pools, audits tokens in parallel, ranks results, and produces the table. No integration code on your side.


Tools used

ToolProviderPurpose
get_yield_poolsDeFiLlamaRanked yield pools with APY split
get_yield_pool_chartDeFiLlamaHistorical APY for a given pool
get_protocol_tvlDeFiLlama30/60/90-day TVL history per protocol
get_fees_overviewDeFiLlamaReal fee revenue (separates base APY from emissions)
get_pool_infoCodexDEX pool depth, volume, price impact
get_token_securityGoPlusHoneypot, tax, ownership
check_approval_securityGoPlusWallet's outstanding approvals and risk

All seven tools are on the root /mcp endpoint. For a narrower agent, /hive_defi_protocol/mcp and /hive_security_risk/mcp cover the full set between them.


What to tune next

  • Chain sweep. Loop get_yield_pools across Arbitrum, Base, Optimism, and Polygon. Hive charges one credit per call regardless of chain.
  • Reward-token liquidity. Reward APY is only real if the reward token has liquidity. Add a get_price and get_pool_info for each reward token and discount emissions APY by expected slippage.
  • Automated alerts. Wire the scanner into a cron. Alert when a pool you're exposed to drops below your APY floor, TVL crashes, or the token fails a freshly-run security check.