Skip to content

Conversation

@bernatfp
Copy link
Member

Summary

Implement cosmos.directory integration to automatically fetch chain parameters (denom metadata, APR, slashing params) and provide RPC fallback. This feature works orthogonally with any provider and requires only a new 'chain_name' config field.

Changes

  • Add chain_name config field (defaults to lowercase of chain display name)
  • Parse cosmos.directory API responses for chain data (types, params, APR)
  • Use cosmos.directory as fallback for denom metadata and APR when ABCI queries fail
  • Automatically fallback to cosmos.directory RPC proxy when configured nodes fail
  • Add 10-second timeout to HTTP requests and 30-minute response caching
  • Updated example config with documentation

Testing

  • Build passes: go build ./...
  • Tests pass: go test ./...
  • Backward compatible: chains without chain_name use existing behavior
  • Works with all providers (default, namada, future providers)

🤖 Generated with Claude Code

@bernatfp bernatfp force-pushed the bernatfp/cosmos-directory-provider branch from 20a6041 to 1744855 Compare January 19, 2026 13:17
@bernatfp bernatfp requested a review from gluckzhang January 19, 2026 13:27
Copy link
Member

@gluckzhang gluckzhang left a comment

Choose a reason for hiding this comment

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

Have reviewed the code and tested it locally. Fixed some json data structure issues and improved logging, and the logic of using this fallback to calculate the APR.

bernatfp and others added 5 commits January 23, 2026 13:36
Implement cosmos.directory support to automatically fetch chain parameters
(denom metadata, APR, slashing params) and provide RPC fallback. This feature
works orthogonally with any provider (default, namada, etc.) and requires only
a new 'chain_name' config field. If not set, defaults to lowercase of the chain
display name.

Key changes:
- Add 'chain_name' config field to ChainConfig
- Add cosmos.directory data types and API fetching with 10s timeout and 30m caching
- Use cosmos.directory as fallback for denom metadata (after ABCI query fails)
- Use cosmos.directory as fallback for APR/chain info (after ABCI query fails)
- Automatically try cosmos.directory RPC proxy when configured nodes fail
- Updated example config with chain_name documentation

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add non-negative check before converting int exponent to uint32 to prevent
potential integer overflow when processing cosmos.directory denom units.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
  Summary of Changes

  td2/chain-details.go

  1. Added wrapper struct to properly unmarshal the nested API response:
  type CosmosDirectoryResponse struct {
      Chain CosmosDirectoryChainData `json:"chain"`
  }
  2. Simplified CosmosDirectoryChainData - removed fields that are actually
   in params
  3. Expanded CDParams to include all top-level params fields:
    - authz, actual_block_time, actual_blocks_per_year,
  current_block_height
    - unbonding_time, max_validators, community_tax
    - bonded_tokens, annual_provision, estimated_apr, calculated_apr
  4. Added CDAssetDenomInfo struct and fixed CDAsset to use proper types:
  type CDAssetDenomInfo struct {
      Denom    string `json:"denom"`
      Exponent int    `json:"exponent"`
  }
  5. Updated fetchCosmosDirectoryChainData to unmarshal into wrapper then
  extract chain data
  6. Fixed getChainInfoFromCosmosDirectory - removed totalSupply (not in
  API), fixed field access paths
  7. Fixed getDenomMetadataFromCosmosDirectory and
  getBankMetadataFromCosmosDirectory** to use asset.Base.Denom and
  asset.Display.Denom

  td2/validator.go

  Updated the caller of getChainInfoFromCosmosDirectory to match the new
  signature (removed totalSupply return value).
Signed-off-by: Long Zhang <gluckzhang@gmail.com>
Signed-off-by: Long Zhang <gluckzhang@gmail.com>
@gluckzhang gluckzhang force-pushed the bernatfp/cosmos-directory-provider branch from f7c9a7f to 5507dcc Compare January 23, 2026 12:36
@gluckzhang gluckzhang merged commit ea4f576 into main Jan 23, 2026
2 checks passed
@gluckzhang gluckzhang deleted the bernatfp/cosmos-directory-provider branch January 23, 2026 12:43
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.

3 participants