Use Cases

DeFi Yield Research with AI Agents

Written by , CEO & Co-Founder, Hive IntelligenceLast updated

This guide walks through building an AI agent that produces a ranked list of safe DeFi yield opportunities. The agent combines yield data from DeFiLlama, DEX pool analytics from Codex, token-contract risk from GoPlus, and approval-level risk from Covalent GoldRush -- four providers, 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, 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 (GoldRush) -- 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 -- create one free. The Demo tier is enough for a daily scanner across one chain; upgrade to Analyst for multi-chain scans every hour.
  • 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.

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:

[
  {
    "pool": "0x...",
    "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:

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 bleeding 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:

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.

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

Expected shape:

{
  "result": [
    {
      "token_address": "0x...",
      "approved_contract": "0x...",
      "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:

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, not headline APY.


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

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 -- fetching pools, auditing tokens in parallel, ranking results, and producing 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_securityGoldRushWallet'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, 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.