Add cosmos.directory integration for chain parameters#65
Merged
gluckzhang merged 5 commits intomainfrom Jan 23, 2026
Merged
Conversation
20a6041 to
1744855
Compare
gluckzhang
approved these changes
Jan 23, 2026
Member
gluckzhang
left a comment
There was a problem hiding this comment.
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.
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Signed-off-by: Long Zhang <[email protected]>
f7c9a7f to
5507dcc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
chain_nameconfig field (defaults to lowercase of chain display name)Testing
go build ./...✅go test ./...✅chain_nameuse existing behavior🤖 Generated with Claude Code