Defillama 标志

Defillama

组织
Starchild-ai-agent
defillama

DeFi analytics: protocol TVL, stablecoin yields, fees, DEX volume, bridges, treasuries. Use when screening yield strategies, comparing protocols, or tracking chain flows (e.g. best USDC yield, Uniswap fees, Arbitrum TVL).

概览

发布者Starchild-ai-agent
代码仓库official-skills
技能名称defillama
星标数
32
复刻数
13
附带文件
2
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 2 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 Starchild-ai-agent 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Defillama AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Starchild-ai-agent/official-skills/tree/main/defillama
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Starchild-ai-agent/official-skills.git /tmp/official-skills
mkdir -p .claude/skills
cp -r /tmp/official-skills/defillama .claude/skills/defillama
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Defillama,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Defillama。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Defillama 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

DefiLlama API

Script-mode skill (PoC). This skill is NOT registered as Anthropic tools. To use it, read this file, then run python in bash and import from exports.py. See Script Usage section below.

Script Usage

This skill ships a single exports.py with all functions. Call it from a bash block like this:

bash
python3 - <<'EOF'
import sys, json
sys.path.insert(0, "/data/workspace/skills/defillama")
from exports import protocols, chains, yield_pools, dex_overview, fees_overview

# Top 10 protocols by TVL
data = protocols()
top = sorted(data, key=lambda p: p.get("tvl") or 0, reverse=True)[:10]
print(json.dumps([{"name": p["name"], "tvl": p["tvl"]} for p in top], indent=2))
EOF

Available functions in exports.py: protocols, chains, protocol_tvl, yield_pools, dex_overview, fees_overview, revenue_overview, stablecoins, bridges, treasury. Read exports.py directly for signatures.

Trit: -1 (MINUS - Validator/Data Source) Color: #4A90D9 (Cold blue, 210°)

Comprehensive DeFi data from DefiLlama's API ecosystem.

Function Reference (signatures)

All functions are in exports.py. Call from a bash block after sys.path.insert(0, "/data/workspace/skills/defillama").

Protocols & TVL

FunctionDescription
protocols()List all protocols with current TVL, chain breakdown, category. Returns list of dicts.
protocol(slug)Detailed history for one protocol (slug from protocols()).
chains()All supported chains with current TVL.
chain_tvl_history(chain)Daily TVL series for one chain.
global_tvl_history()Global daily TVL series.

Stablecoins

FunctionDescription
stablecoins(include_prices=True)All stablecoins with circulating supply per chain.
stablecoin_chains()Per-chain stablecoin totals.

Yields

FunctionDescription
yield_pools()All yield pools with APY, TVL, project, chain.
yield_chart(pool_id)Historical APY/TVL for one pool (pool_id from yield_pools()).

Volume / Fees / Revenue

FunctionDescription
dex_overview(exclude_chart=True)Aggregated DEX volume across all chains.
dex_overview_chain(chain, exclude_chart=True)DEX volume for one chain.
fees_overview(exclude_chart=True)Aggregated fees+revenue across all protocols.
fees_overview_chain(chain, exclude_chart=True)Per-chain fees breakdown.

Bridges

FunctionDescription
bridges()List all bridges with volume stats.
bridge_chain_volume(chain)Bridge volume by chain.
bridge_volume(bridge_id, start_timestamp=None, end_timestamp=None)Time series for one bridge.

Prices

FunctionDescription
current_prices(coins)Current prices. coins = list/string like "ethereum:0x...,coingecko:bitcoin".
historical_prices(coins, timestamp)Prices at a specific unix timestamp.

Matching Keywords (intent triggers)

Use this skill when users ask about any of the following:

  • TVL: TVL ranking, protocol TVL, chain TVL, TVL changes, DeFi market share
  • Stablecoin yield: stablecoin yield, USDC/USDT APY, low-risk yield pools, safe yield, fixed-income-like DeFi
  • Yield / Farming: APY ranking, yield pool screening, vault yield, lending APY, borrow rates, LSD/LRT yield
  • DEX / Fees / Revenue: DEX volume, protocol fees, protocol revenue, revenue growth, which DEX revenue is growing fastest
  • Flows / Rotation: capital flows, chain inflow/outflow, stablecoin netflow, liquidity rotation
  • Protocol Research: protocol fundamentals, multi-protocol comparison, sector comparison, DeFi snapshot/report

Typical user prompts this skill should match:

  • “Which DEX has seen the strongest revenue growth recently?”
  • “Find me some low-risk stablecoin yield options with decent returns.”
  • “Create a DeFi market snapshot for today (TVL / volume / fees).”
  • “Compare ETH vs SOL on-chain flow changes over the last 30 days.”

Base URLs

APIBase URLAuth
Free APIhttps://api.llama.fiNone (no key needed)
Pro APIhttps://pro-api.llama.fi/{API_KEY}Key in path /API_KEY/endpoint
Bridge APIhttps://bridges.llama.fiNone

Key rule: Use https://api.llama.fi for all free endpoints (TVL, chains, DEX, fees, prices). Use https://pro-api.llama.fi/{API_KEY} ONLY for pro endpoints (yields, derivatives, emissions). Env var: DEFILLAMA_API_KEY — used in pro URL path, NOT as HTTP header.

Most Common Endpoints (Start Here)

For 90% of DeFi analytics tasks, use these free endpoints (api.llama.fi):

TaskEndpointExample
TVL Top N protocolsGET /protocolsSort by .tvl field
Single protocol detailGET /protocol/{slug}e.g. /protocol/aave
Chain TVL historyGET /v2/historicalChainTvl/{chain}.date + .tvl fields
DEX volumesGET /overview/dexs?excludeChart=true.total24h, .total7d
Protocol feesGET /overview/fees?excludeChart=true.total24h
All chains TVLGET /v2/chainsSum .tvl for global total

⚠️ Pro endpoints (/yields/*, /emissions, etc.) require DEFILLAMA_API_KEY in the URL path.

Proxy Requirement (sc-proxy)

When using fake API keys (for example fake-defillama-key-12345), requests must go through sc-proxy so the key can be replaced upstream.

  • Env key name: DEFILLAMA_API_KEY
  • Auto proxy detection envs: PROXY_HOST, PROXY_PORT
  • If HTTP_PROXY / HTTPS_PROXY are unset, direct requests may hit upstream and return key errors.

Python template (recommended)

python
import os
import requests

host = os.getenv("PROXY_HOST")
port = os.getenv("PROXY_PORT")
session = requests.Session()
if host and port:
    if ":" in host and not host.startswith("["):
        host = f"[{host}]"  # IPv6-safe
    proxy = f"http://{host}:{port}"
    session.proxies.update({"http": proxy, "https": proxy})

# Free endpoint (no key needed):
r_free = session.get("https://api.llama.fi/protocols", timeout=25)
print("Free:", r_free.status_code)

# Pro endpoint (key in URL path):
api_key = os.environ["DEFILLAMA_API_KEY"]
r_pro = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools", timeout=25)
print("Pro:", r_pro.status_code)

Quick test commands

bash
set -a && source .env && set +a
python3 - << 'PY'
import os, requests
s = requests.Session()
host, port = os.getenv('PROXY_HOST'), os.getenv('PROXY_PORT')
if host and port:
    if ':' in host and not host.startswith('['):
        host = f'[{host}]'
    p = f'http://{host}:{port}'
    s.proxies.update({'http': p, 'https': p})

# Free endpoint
r1 = s.get('https://api.llama.fi/protocols', timeout=25)
print('free /protocols:', r1.status_code)

# Pro endpoint
k = os.environ['DEFILLAMA_API_KEY']
r2 = s.get(f'https://pro-api.llama.fi/{k}/yields/pools', timeout=25)
print('pro /yields/pools:', r2.status_code)
PY

Quick Reference

TVL & Protocols

bash
# All protocols with TVL
GET /protocols

# Single protocol detail
GET /protocol/{slug}

# Chain TVL
GET /v2/chains
GET /v2/historicalChainTvl/{chain}

Prices

bash
# Current prices (chain:address format)
GET /coins/prices/current/{coins}

# Historical
GET /coins/prices/historical/{timestamp}/{coins}

# Chart data
GET /coins/chart/{coins}?period=30d

Yields (Pro)

bash
GET /yields/pools           # All yield pools
GET /yields/chart/{pool}    # Pool history
GET /yields/poolsBorrow     # Borrow rates
GET /yields/perps           # Perp funding
GET /yields/lsdRates        # LSD rates

Volume

bash
GET /overview/dexs?excludeChart=true              # DEX volumes (recommended)
GET /overview/dexs/{chain}?excludeChart=true      # Chain DEX
GET /summary/dexs/{protocol}                       # Protocol detail
GET /overview/options?excludeChart=true           # Options
GET /overview/derivatives?excludeChart=true       # Derivatives (Pro)

Fees & Revenue

bash
GET /overview/fees?excludeChart=true              # All fees/revenue (recommended)
GET /overview/fees/{chain}?excludeChart=true      # Chain fees
GET /summary/fees/{protocol}                      # Protocol fees
# dataType: dailyFees | dailyRevenue | dailyHoldersRevenue

Bridges

bash
# Base: https://bridges.llama.fi
GET /bridges                        # All bridges
GET /bridge/{id}                    # Bridge detail
GET /bridgevolume/{chain}           # Volume by chain
GET /transactions/{id}              # Bridge txs

DAT (Digital Asset Treasury)

bash
GET /dat/institutions               # All institutions
GET /dat/institutions/{symbol}      # e.g., MSTR

Usage Script

clojure
;; See scripts/defillama.bb for full implementation
(require '[defillama :as dl])

;; TVL
(dl/protocols)
(dl/protocol "aave")
(dl/chain-tvl "Ethereum")

;; Prices
(dl/price "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
(dl/price-chart "coingecko:ethereum" {:period "30d"})

;; Yields
(dl/yield-pools)
(dl/pool-chart "747c1d2a-c668-4682-b9f9-296708a3dd90")

;; Volumes
(dl/dex-overview)
(dl/dex-protocol "uniswap")

;; Fees
(dl/fees-overview)
(dl/fees-protocol "hyperliquid")

Endpoint Categories

Free Endpoints

  • /protocols, /protocol/{slug}, /tvl/{slug}
  • /v2/chains, /v2/historicalChainTvl
  • /coins/prices/*, /coins/chart/*
  • /overview/dexs, /overview/options
  • /overview/fees, /summary/fees/*

Pro Endpoints (API Key Required)

  • /yields/* - All yield endpoints (stablecoin pools, APY ranking, borrow/perps/LSD)
  • /overview/derivatives
  • /tokenProtocols/{symbol}
  • /inflows/{protocol}/{timestamp}
  • /chainAssets
  • /emissions, /emission/{protocol}
  • /categories, /forks, /oracles
  • /entities, /treasuries
  • /hacks, /raises
  • /etfs/*, /dat/*
  • Bridge endpoints on bridges.llama.fi

Response Patterns

TVL Response

json
{"id": "2269", "name": "Aave", "tvl": 5200000000, "chains": ["Ethereum"]}

Price Response

json
{"coins": {"ethereum:0x...": {"price": 0.999, "symbol": "USDC", "confidence": 0.99}}}

Yield Pool Response

json
{"pool": "uuid", "chain": "Ethereum", "project": "aave-v3", "apy": 3.5, "tvlUsd": 1500000000}

GF(3) Integration

This skill serves as MINUS (-1) validator in triads:

  • Provides authoritative DeFi data
  • Validates protocol metrics
  • Constrains analysis with real data

Compose with:

  • aptos-agent (+1): Execute based on data
  • exa-search (0): Enrich with web context

Output Format Guidelines (Chinese/English Queries)

Always format DeFi data responses as human-readable markdown. Support both Chinese and English queries.

Number Formatting

  • TVL ≥ $1B → $X.XXB; TVL ≥ $1M → $XXXM
  • APY → XX.X%
  • 24h changes → +X.X% or -X.X%
  • Always include units: $, %, B (billion), M (million)

Recommended Output Templates

TVL Leaderboard:

markdown
| # | Protocol | TVL | Chains |
|---|--------------|-----|-----------|
| 1 | Aave V3      | $24.7B | Ethereum, Arbitrum |

Yield Pools:

markdown
| Pool | APY | TVL | Risk |
|---------|-----|-----|---------|
| USDC    | 5.2% | $500M | ✅ Low risk |

Market Snapshot:

markdown
| Metric | Value |
|------------|-----------|
| Total TVL       | $96B       |
| DEX 24h volume  | $5.7B      |
| Fees 24h        | $49M       |

Risk Labels

Always include risk indicators for yield pools:

  • ✅ Low risk — stable APY < 20%, no IL risk
  • ⚠️ Medium risk — APY 20-100%, or IL risk present
  • 🔴 High risk — APY > 100% (likely incentive-driven, unsustainable)

Tip: excludeChart Parameter

For volume/fee overview endpoints, always add ?excludeChart=true to reduce response size:

bash
GET /overview/dexs?excludeChart=true    # DEX volumes (much faster)
GET /overview/fees?excludeChart=true    # Fee data (much faster)

Common Pitfalls & Gotchas

1. Wrong Base URL for Free Endpoints

❌ WRONG: https://pro-api.llama.fi/protocols → returns 404 "Path needs to start with /yields/..." ✅ CORRECT: https://api.llama.fi/protocols

Free endpoints NEVER go through pro-api.llama.fi.

2. Pro Endpoint Without API Key

❌ WRONG: https://pro-api.llama.fi/yields/pools → 401 or wrong route ✅ CORRECT: https://pro-api.llama.fi/{DEFILLAMA_API_KEY}/yields/pools

The API key is in the URL path, not in a header.

3. Missing excludeChart=true for Volume/Fee Endpoints

Without this param, /overview/dexs returns large chart history arrays. Always add ?excludeChart=true for summary queries.

4. Handling TVL Null Values

When sorting protocols by TVL, filter first:

python
valid = [p for p in protocols if isinstance(p.get('tvl'), (int, float)) and p['tvl'] > 0]

5. Stablecoins vs TVL

DefiLlama's chain TVL includes ALL DeFi assets, not just stablecoins. For stablecoin-specific flows, use the stablecoins.llama.fi API (separate from pro-api). When asked about "stablecoin flows", the chain TVL change is a reasonable proxy.

6. Yields Pool UUID

The pool field in /yields/pools is a UUID like "747c1d2a-c668-4682-b9f9-296708a3dd90". Use this UUID (not token address) for /yields/chart/{pool} history.

7. Stablecoin Yield Screening Baseline

For “conservative stablecoin yield” requests, start with this baseline filter:

  • stablecoin == true
  • tvlUsd >= 50_000_000
  • apy between 2 and 20 (drop extreme incentive spikes)
  • ilRisk == "no"
  • Prefer exposure == "single" for conservative profiles

Workflow Examples (Agent Recipes)

Recipe 1: DeFi TVL Top 10 (1 call)

python
r = requests.get("https://api.llama.fi/protocols")
protocols = r.json()
top10 = sorted([p for p in protocols if p.get('tvl',0) > 0], key=lambda x: x['tvl'], reverse=True)[:10]
# Output: markdown table with | # | Protocol | TVL | Chain |

Recipe 2: ETH vs SOL 30-day TVL comparison (2 calls)

python
r1 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Ethereum")
r2 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Solana")
# Filter last 30d: [d for d in r1.json() if d['date'] >= time.time() - 30*86400]
# Output: | Chain | TVL 30d ago | TVL today | Change % |

Recipe 3: Stablecoin yield shortlist (1 call)

python
r = requests.get(f"https://pro-api.llama.fi/{API_KEY}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
safe = [p for p in pools
        if p.get('stablecoin') is True
        and (p.get('tvlUsd') or 0) >= 50_000_000
        and (p.get('apy') or 0) >= 2
        and (p.get('apy') or 0) <= 20
        and p.get('ilRisk') == 'no']
top = sorted(safe, key=lambda x: x.get('apy', 0), reverse=True)[:10]
# Output: | Project | Chain | Symbol | APY | TVL | Risk |

Recipe 4: DeFi Market Snapshot (3 calls)

python
chains = requests.get("https://api.llama.fi/v2/chains").json()
dexs   = requests.get("https://api.llama.fi/overview/dexs?excludeChart=true").json()
fees   = requests.get("https://api.llama.fi/overview/fees?excludeChart=true").json()
# total_tvl = sum(c['tvl'] for c in chains if isinstance(c.get('tvl'), (int,float)))
# Output: snapshot table with TVL, DEX 24h vol, Fee 24h

Recipe 5: Protocol TVL spike analysis (2 calls)

python
r1 = requests.get("https://api.llama.fi/protocols")  # find protocol with big change_1d
r2 = requests.get(f"https://api.llama.fi/protocol/{slug}")  # get chainTvls detail
# Output: | Hypothesis | Explanation | How to verify | (table + step-by-step verification)

Stablecoin Data

For stablecoin-specific analytics (distinct from general TVL), use the stablecoins API:

bash
# Stablecoins overview (separate from pro-api)
GET https://stablecoins.llama.fi/stablecoins?includePrices=true

# Chain-specific stablecoin data
GET https://stablecoins.llama.fi/stablecoincharts/{chain}
# chain = "Ethereum", "Solana", "BSC", etc.

# All chains stablecoin summary
GET https://stablecoins.llama.fi/stablecoinchains

When users ask about "stablecoin net flows" or "stablecoin inflows":

  1. Use stablecoincharts/{chain} for 30-day stablecoin TVL change (more accurate than general TVL)
  2. Or use /v2/historicalChainTvl/{chain} as proxy if stablecoin API is unavailable

Yields Pool Data Handling

The /yields/pools response is {"data": [...], "status": "success"}:

python
r = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
# Filter example: TVL > $50M and APY > 0
filtered = [p for p in pools if p.get('tvlUsd', 0) >= 50_000_000 and (p.get('apy') or 0) > 0]

Key pool fields:

FieldTypeDescription
poolUUID stringUnique pool identifier
chainstringChain name
projectstringProtocol name
symbolstringToken pair (e.g. "USDC-WETH")
tvlUsdnumberTVL in USD
apynumberCurrent APY %
apyBasenumberBase APY (lending/trading fees)
apyRewardnumberIncentive APY (token rewards)
ilRisk"yes"/"no"Impermanent loss risk
exposure"single"/"multi"Single vs multi-asset exposure
apyPct7DnumberAPY change past 7 days

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Defillama AI 技能有什么作用?

DeFi analytics: protocol TVL, stablecoin yields, fees, DEX volume, bridges, treasuries. Use when screening yield strategies, comparing protocols, or tracking chain flows (e.g. best USDC yield, Uniswap fees, Arbitrum TVL).

为什么在 TypingMind 中使用 Defillama?

因为您只需安装一次,就能搭配任何模型使用。Defillama 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Defillama?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Starchild-ai-agent/official-skills/tree/main/defillama。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Defillama?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Defillama 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Defillama 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Defillama AI 技能免费吗?

Starchild-ai-agent 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇