Skip to content

feat: add stablecoins chains command#38

Closed
ggonzalez94 wants to merge 5 commits into
mainfrom
feat/stablecoins-chains
Closed

feat: add stablecoins chains command#38
ggonzalez94 wants to merge 5 commits into
mainfrom
feat/stablecoins-chains

Conversation

@ggonzalez94
Copy link
Copy Markdown
Owner

@ggonzalez94 ggonzalez94 commented Mar 12, 2026

Summary

  • Add stablecoins chains command that ranks chains by total stablecoin market cap using DefiLlama's stablecoinchains API
  • Returns chain name, CAIP-2 chain ID, total circulating USD (aggregated across all peg types), and dominant peg type
  • No API key required, supports --limit flag, follows existing caching and output patterns

Example

defi stablecoins chains --limit 5 --results-only

Test plan

  • go test ./... passes
  • go test -race ./... passes
  • go vet ./... passes
  • Smoke tested stablecoins chains --limit 5 --results-only against live DefiLlama API
  • httptest-based adapter tests: sort/limit, zero-supply filtering, no-limit mode
  • CHANGELOG and README updated

🤖 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) for chains gas, which can affect runtime behavior and error handling across multiple chains.

Overview
Adds new market-discovery commands: stablecoins top and stablecoins chains (DefiLlama stablecoins APIs) plus chains list (enumerate supported chain IDs/aliases) and chains gas (live EVM gas prices via RPC, with optional --rpc-url and 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 so chains list and chains gas bypass cache initialization.

Written by Cursor Bugbot for commit b7e97ed. This will update automatically on new commits. Configure here.

ggonzalez94 and others added 5 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>
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 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"`
}
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 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)
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: 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".

Comment thread internal/app/runner.go
Comment on lines +499 to +500
gasResponse := schema.SchemaFromType([]model.GasPrice{})
_ = schema.SetCommandMetadata(gasCmd, schema.CommandMetadata{Response: &gasResponse})
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 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 👍 / 👎.

Comment on lines +372 to +376
for pegType, amount := range item.TotalCirculatingUSD {
total += amount
if amount > dominantAmount {
dominantAmount = amount
dominantPeg = pegType
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 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 👍 / 👎.

@ggonzalez94
Copy link
Copy Markdown
Owner Author

Closing: superseded by #43 which contains all commits from this stacked branch chain (this PR's 5 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