Skip to content

feat: add protocols revenue command#41

Closed
ggonzalez94 wants to merge 8 commits into
mainfrom
feat/protocols-revenue
Closed

feat: add protocols revenue command#41
ggonzalez94 wants to merge 8 commits into
mainfrom
feat/protocols-revenue

Conversation

@ggonzalez94
Copy link
Copy Markdown
Owner

@ggonzalez94 ggonzalez94 commented Mar 16, 2026

Summary

  • Adds protocols revenue command to rank protocols by 24h revenue (protocol-retained fees) with 7d/30d totals and 1d/7d/1m percentage changes
  • Uses DefiLlama /overview/fees?dataType=dailyRevenue endpoint (no API key required)
  • Supports --category filter (e.g. Dexs, Lending) and --limit
  • Revenue is distinct from fees: it represents the portion of fees retained by the protocol itself, not paid to LPs/validators — the most important fundamental metric for protocol valuation

Example

defi protocols revenue --limit 5 --results-only --select rank,protocol,category,revenue_24h_usd,change_1d_pct

Test plan

  • go test ./... passes
  • go test -race ./internal/app/ ./internal/providers/defillama/ passes
  • go vet ./... passes
  • Smoke tested defi protocols revenue --limit 3 --results-only against live DefiLlama API
  • Client tests: sort/limit, category filter, null/zero/negative exclusion
  • Runner test: end-to-end JSON envelope validation

🤖 Generated with Claude Code


Note

Medium Risk
Mostly additive CLI commands, but it expands the MarketDataProvider interface and introduces live RPC querying/concurrency in chains 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) and chains 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, and stablecoins 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.

ggonzalez94 and others added 8 commits March 8, 2026 15:28
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>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

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"`
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

})
}
return out, nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/app/runner.go
if err != nil {
return err
}
return s.emitSuccess(trimRootPath(cmd.CommandPath()), result, nil, cacheMetaBypass(), nil, false)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +517 to +519
price := 0.0
if item.Price != nil {
price = *item.Price
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@ggonzalez94
Copy link
Copy Markdown
Owner Author

Closing: superseded by #43 which contains all commits from this stacked branch chain (this PR's 8 commits are included in #43's 10).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant