feat: add stablecoins chains command#38
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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 always report zero circulating supply
High Severity
The peggedAmount struct only has a PeggedUSD field (json:"peggedUSD"), but the DefiLlama API uses the peg type as the JSON key inside circulating. For EUR-pegged stablecoins like EURS, the API returns {"peggedEUR": 100000000}, not {"peggedUSD": ...}. This causes Circulating.PeggedUSD to be 0 for all non-USD pegged stablecoins, making CirculatingUSD, all change deltas, and sort ranking incorrect. The --peg-type peggedEUR filter returns entries but with all-zero values.
Additional Locations (1)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7e97edcd4
ℹ️ 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".
| gasResponse := schema.SchemaFromType([]model.GasPrice{}) | ||
| _ = schema.SetCommandMetadata(gasCmd, schema.CommandMetadata{Response: &gasResponse}) |
There was a problem hiding this comment.
Align chains gas schema with single-chain response shape
chains gas emits a scalar GasPrice object when one chain is requested (the single-chain branch in this function), but the registered schema metadata here advertises only []model.GasPrice. Schema-driven clients will parse defi schema as array-only and then fail on the common single-chain call path, which breaks the machine-readable contract for this command.
Useful? React with 👍 / 👎.
| for pegType, amount := range item.TotalCirculatingUSD { | ||
| total += amount | ||
| if amount > dominantAmount { | ||
| dominantAmount = amount | ||
| dominantPeg = pegType |
There was a problem hiding this comment.
Make dominant peg selection deterministic for equal totals
The dominant peg is selected by iterating item.TotalCirculatingUSD and updating only on amount > dominantAmount. Because Go map iteration order is randomized, ties (equal circulating amounts across peg types) can produce different dominant_peg_type values across runs for the same input payload, leading to nondeterministic output that is brittle for automation.
Useful? React with 👍 / 👎.


Summary
stablecoins chainscommand that ranks chains by total stablecoin market cap using DefiLlama's stablecoinchains API--limitflag, follows existing caching and output patternsExample
Test plan
go test ./...passesgo test -race ./...passesgo vet ./...passesstablecoins chains --limit 5 --results-onlyagainst live DefiLlama API🤖 Generated with Claude Code
Note
Medium Risk
Medium risk because it expands the CLI surface area and provider interfaces and introduces direct RPC calls (
ethclient) forchains gas, which can affect runtime behavior and error handling across multiple chains.Overview
Adds new market-discovery commands:
stablecoins topandstablecoins chains(DefiLlama stablecoins APIs) pluschains list(enumerate supported chain IDs/aliases) andchains gas(live EVM gas prices via RPC, with optional--rpc-urland parallel multi-chain mode).Extends the DefiLlama market provider interface and implementation to fetch/sort stablecoin and stablecoin-chain data, and introduces new output models (
Stablecoin,StablecoinChain,SupportedChain,GasPrice) with accompanying unit/runner tests and docs/README/CHANGELOG updates. Cache policy is updated sochains listandchains gasbypass cache initialization.Written by Cursor Bugbot for commit b7e97ed. This will update automatically on new commits. Configure here.