feat: add protocols revenue command#41
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>
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 stablecoins get zero circulating values
High Severity
The peggedAmount struct only decodes the peggedUSD JSON key. The DefiLlama API returns circulating amounts keyed by peg type (e.g., {"peggedEUR": 100000000} for EUR-pegged stablecoins). This means any non-USD pegged stablecoin (EUR, JPY, GBP, etc.) will have CirculatingUSD of 0, incorrect sorting, and zero delta change calculations. Contrast with StablecoinChains, which correctly uses map[string]float64 to handle all peg types. The test masks this by incorrectly using peggedUSD as the key for the EUR-pegged EURS entry.
Additional Locations (1)
| }) | ||
| } | ||
| return out, nil | ||
| } |
There was a problem hiding this comment.
Fees and revenue functions are nearly identical
Low Severity
ProtocolsRevenue is a near-exact copy of ProtocolsFees — identical filtering, sorting, limiting, and mapping logic — differing only in the endpoint URL (one extra query parameter) and the output model type. This duplicated logic increases the risk of inconsistent bug fixes if one function is updated but not the other.
Additional Locations (1)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b9101c0103
ℹ️ 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 err != nil { | ||
| return err | ||
| } | ||
| return s.emitSuccess(trimRootPath(cmd.CommandPath()), result, nil, cacheMetaBypass(), nil, false) |
There was a problem hiding this comment.
Keep
chains gas response shape consistent
chains gas emits a scalar object for single-chain requests here, but the command metadata declares an array response (SchemaFromType([]model.GasPrice{})), so schema-driven clients will deserialize the same command into different types depending on input count. This breaks the CLI's machine-readable contract for automation in the common single-chain case.
Useful? React with 👍 / 👎.
| price := 0.0 | ||
| if item.Price != nil { | ||
| price = *item.Price |
There was a problem hiding this comment.
Preserve missing stablecoin prices instead of forcing 0
When DefiLlama returns null for price, this code converts it to 0.0, which is indistinguishable from a real zero price and can falsely signal a complete depeg in downstream automation. The issue appears whenever upstream omits price data for a token, so unknown prices should be represented as missing rather than coerced to zero.
Useful? React with 👍 / 👎.


Summary
protocols revenuecommand to rank protocols by 24h revenue (protocol-retained fees) with 7d/30d totals and 1d/7d/1m percentage changes/overview/fees?dataType=dailyRevenueendpoint (no API key required)--categoryfilter (e.g.Dexs,Lending) and--limitExample
Test plan
go test ./...passesgo test -race ./internal/app/ ./internal/providers/defillama/passesgo vet ./...passesdefi protocols revenue --limit 3 --results-onlyagainst live DefiLlama API🤖 Generated with Claude Code
Note
Medium Risk
Mostly additive CLI commands, but it expands the
MarketDataProviderinterface and introduces live RPC querying/concurrency inchains gas, which could affect provider implementations and runtime behavior (timeouts/partial results).Overview
Adds new market-discovery commands:
chains list(enumerate supported chain IDs/aliases) andchains gas(live EVM gas price via RPC with optional multi-chain parallel queries, cache-bypassed).Extends protocol/market analytics with
protocols fees,protocols revenue,dexes volume,stablecoins top, andstablecoins chains, backed by new DefiLlama client endpoints and new response models; rankings filter out null/zero values and support simple limit/category/chain/peg filters.Updates docs/README/CHANGELOG and adds comprehensive unit/runner tests for the new commands, plus updates cache-bypass metadata handling for
chains list/chains gas.Written by Cursor Bugbot for commit b9101c0. This will update automatically on new commits. Configure here.