feat: add --chain filter to protocols top#42
Conversation
Agents and automation tools need to discover available chains before using other commands. This adds `chains list` which enumerates all supported chains with names, slugs, CAIP-2 identifiers, namespaces, and accepted aliases. No API keys required; bypasses cache. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Agents planning execution need gas price context before deciding whether to proceed with swaps, bridges, or other on-chain operations. This adds `chains gas --chain <id>` which queries current base fee, priority fee, and legacy gas price via RPC with EIP-1559 detection. No API keys required, bypasses cache, supports --rpc-url override. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Allow --chain to accept comma-separated chain identifiers (e.g. --chain 1,10,137,8453,42161) for parallel multi-chain gas price queries. Single-chain usage preserves the existing scalar response for backward compatibility. Multi-chain returns an array with partial-result support and warnings for failed chains. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `stablecoins top` command using DefiLlama's free stablecoins API to list stablecoins ranked by circulating market cap. Returns price, chain count, peg type/mechanism, and day/week/month supply change deltas. Supports `--peg-type` filter and `--limit`. No API key required. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…cap ranking Surface stablecoin liquidity distribution across chains using DefiLlama's stablecoinchains API. Returns chains ranked by total stablecoin supply with CAIP-2 chain IDs and dominant peg type. No API key required. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `protocols fees` command that ranks protocols by 24h fee revenue using the DefiLlama fees API. Includes 7d/30d totals, percentage changes (1d/7d/1m), category filtering, and chain counts. No API key required. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `dexes volume` command to rank DEXes by 24h trading volume with 7d/30d totals and 1d/7d/1m percentage changes. Uses DefiLlama DEX volume API (no API key required). Supports `--chain` filter for chain presence and `--limit`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Revenue (protocol-retained fees) is the most important fundamental metric for protocol valuation. This adds `protocols revenue` using DefiLlama's /overview/fees?dataType=dailyRevenue endpoint with the same --category filter and --limit flags as protocols fees. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds --chain flag to `protocols top` that filters protocols by chain presence and ranks by chain-specific TVL from DefiLlama's chainTvls data. Supports combined --category and --chain filtering. Output now includes chains count field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
|
||
| type peggedAmount struct { | ||
| PeggedUSD float64 `json:"peggedUSD"` | ||
| } |
There was a problem hiding this comment.
Non-USD pegged stablecoins report zero circulating supply
High Severity
The peggedAmount struct only deserializes the peggedUSD JSON key. The DefiLlama API returns circulating amounts keyed by peg type — e.g., {"peggedEUR": 100000000} for EUR-pegged stablecoins. Non-USD stablecoins (like EURS with pegType: "peggedEUR") will unmarshal with PeggedUSD = 0, causing zero CirculatingUSD, zero day/week/month deltas, and incorrect sort ordering. The --peg-type peggedEUR filter will return results but all with zero values. The tests mask this by incorrectly using "peggedUSD" as the key for the EURS mock data.
Additional Locations (1)
| if tvl <= 0 { | ||
| tvl = p.TVL | ||
| } | ||
| } |
There was a problem hiding this comment.
Chain TVL fallback inflates multi-chain protocol rankings
Medium Severity
When --chain is specified but chainTVL() returns 0 (no matching key in chainTvls), the code falls back to the protocol's total TVL across all chains. For multi-chain protocols with missing chain-specific data, this inflates their apparent TVL on the queried chain, contradicting the PR's stated behavior that tvl_usd reflects "the protocol's value locked on that chain rather than total TVL."
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5dcc08eea0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if tvl <= 0 { | ||
| tvl = p.TVL |
There was a problem hiding this comment.
Avoid falling back to total TVL for chain-filtered results
When a chain filter is set, this branch replaces missing/zero chain TVL with p.TVL, so protocols can be ranked and reported using global TVL even though --chain was requested. This produces inflated tvl_usd and incorrect ordering whenever DefiLlama returns a legitimate 0 for that chain (or no plain chain key but still includes the chain in chains). The fallback should only happen for truly missing chain-specific data, not for valid zero values.
Useful? React with 👍 / 👎.


Summary
--chainflag toprotocols topthat filters protocols by chain presence and ranks by chain-specific TVL using DefiLlama'schainTvlsdata--chainis specified,tvl_usdreflects the protocol's TVL on that specific chain rather than total TVL across all chains--categoryand--chainfiltering (e.g.protocols top --chain Arbitrum --category Lending)chainscount field showing how many chains each protocol is deployed onExamples
Test plan
go test ./...passesgo test -race ./...passesgo vet ./...passesprotocols top --chain Ethereum --limit 5protocols top --chain Arbitrum --category Lending --limit 5🤖 Generated with Claude Code
Note
Medium Risk
Adds multiple new market-data commands and expands the DefiLlama adapter plus CLI interfaces; most risk is around new RPC dialing/concurrency in
chains gasand potential schema/contract changes (new fields likechains).Overview
Expands market-discovery command surface. Adds new top-level commands for
dexes volumeandstablecoins top|chains, plus newprotocols feesandprotocols revenuerankings sourced from DefiLlama endpoints (no API key).Enhances chain-related tooling. Introduces
chains list(enumerate supported chains/aliases) andchains gas(live EVM gas pricing via RPC, supports multi-chain parallel queries with partial-result warnings), and marks these as metadata-style commands that bypass cache initialization.Extends existing protocol rankings.
protocols topgains a--chainfilter that filters by chain presence and ranks by chain-specific TVL (falling back to total TVL when chain TVL is missing), and protocol rows now include achainscount.Updates provider interfaces/models, adds DefiLlama client support for the new endpoints (including stablecoins API base), and adds extensive unit tests plus docs/README/CHANGELOG updates to reflect the new commands and output fields.
Written by Cursor Bugbot for commit 5dcc08e. This will update automatically on new commits. Configure here.