| Crates.io | atp-chain-registry |
| lib.rs | atp-chain-registry |
| version | 0.1.3 |
| created_at | 2025-08-05 08:19:45.932774+00 |
| updated_at | 2025-08-28 07:43:17.234101+00 |
| description | Chain registry for ATP (Account Transfer Protocol) to manage blockchain configurations and metadata. |
| homepage | |
| repository | https://github.com/mycel-labs/atp |
| max_upload_size | |
| id | 1781707 |
| size | 139,869 |
A comprehensive, type-safe chain registry for multi-chain applications, designed for ATP and cross-chain arbitrage systems. Built with Rust and following CAIP (Chain Agnostic Improvement Proposals) standards.
The Chain Registry provides a unified interface to manage blockchain networks, assets, and trading pairs across multiple chains. It enables developers to build chain-agnostic applications that can seamlessly work with any blockchain ecosystem.
use atp_chain_registry::{ChainRegistry, ChainId, AssetId};
use std::str::FromStr;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load the default configuration
let registry = ChainRegistry::default()?;
// Get chain ID from name
let chain_id = registry.get_chain_id_from_config("Ethereum Mainnet")?;
println!("Ethereum Mainnet ID: {}", chain_id);
// Get asset ID from symbol and chain
let asset_id = registry.get_asset_id_from_config("ETH", "eip155:1")?;
println!("ETH on Ethereum: {}", asset_id);
// Find cross-chain trading opportunities
let cross_chain_pairs = registry.get_cross_chain_pairs();
println!("Found {} cross-chain trading pairs", cross_chain_pairs.len());
// Discover trading routes
let eth_asset = AssetId::new(ChainId::from_str("eip155:1")?, "slip44", "60")?;
let sol_asset = AssetId::new(ChainId::from_str("solana:mainnet")?, "slip44", "501")?;
let routes = registry.find_trading_routes(ð_asset, &sol_asset, 3);
println!("Found {} routes from ETH to SOL", routes.len());
Ok(())
}
The Chain Registry implements two key features for chain-agnostic applications:
let chain_id = registry.get_chain_id_from_config("Ethereum Mainnet")?;
// Returns: ChainId("eip155:1")
let asset_id = registry.get_asset_id_from_config("ETH", "eip155:1")?;
// Returns: AssetId("eip155:1/slip44:60")
The Chain Registry follows a clean, modular architecture:
โโโ types.rs # Core data structures (ChainConfig, AssetConfig, TokenPair)
โโโ registry.rs # Main registry implementation and CRUD operations
โโโ query.rs # Advanced query operations and analytics
โโโ error.rs # Comprehensive error handling
โโโ lib.rs # Public API and integration
ChainRegistry - Main registry interface for managing chains, assets, and pairsChainConfig - Blockchain configuration (RPC endpoints, metadata, assets)AssetConfig - Asset configuration (symbol, decimals, metadata)TokenPair - Trading pair configuration (fees, limits, routing)The registry comes with a default configuration supporting:
eip155:1) - ETH native tokeneip155:11155111) - ETH testnetsolana:mainnet) - SOL native tokensolana:devnet) - SOL testnetThe registry is designed to be easily extensible. Add support for new chains by:
ChainConfig with chain detailsAssetConfig for each asset on the chainTokenPair configurations for tradingadd_chain(), add_asset(), add_token_pair()use atp_chain_registry::*;
let mut registry = ChainRegistry::new();
// Add a new chain
let chain_config = ChainConfig {
chain_id: "polygon:mainnet".to_string(),
name: "Polygon Mainnet".to_string(),
native_asset: "slip44:966".to_string(),
rpc_endpoints: vec!["https://polygon-rpc.com".to_string()],
explorer_url: Some("https://polygonscan.com".to_string()),
cryptographic_curve: vec![Curve::Secp256k1],
is_testnet: false,
assets: vec![AssetIdBase::new("slip44", "966")?],
metadata: HashMap::new(),
};
registry.add_chain(chain_config)?;
[chains."polygon:mainnet"]
chain_id = "polygon:mainnet"
name = "Polygon Mainnet"
native_asset = "slip44:966"
rpc_endpoints = ["https://polygon-rpc.com"]
explorer_url = "https://polygonscan.com"
cryptographic_curve = ["secp256k1"]
is_testnet = false
assets = [
{ asset_namespace = "slip44", asset_reference = "966" }
]
let registry = ChainRegistry::from_file("config.toml")?;
cargo run --example configuration_summary
This example demonstrates:
Expected output:
๐ Chain Registry - Configuration Agnostic Demo
๐ Registry Overview:
Total chains: 4
โโ Mainnet: 2
โโ Testnet: 2
Total assets: 2
Trading pairs: 4
โโ Cross-chain: 4
โโ Same-chain: 0
๐ฏ Testing Requested Features:
โ Ethereum Mainnet -> eip155:1
โ Ethereum Sepolia -> eip155:11155111
โ Solana Mainnet -> solana:mainnet
โ Solana Devnet -> solana:devnet
examples/configuration_summary.rs - Show configuration summaryRun the full test suite:
cargo test
Run specific test categories:
# Test core functionality
cargo test registry
# Test configuration loading
cargo test config
# Test with output
cargo test -- --nocapture
let stats = registry.get_statistics();
println!("Chains: {}, Assets: {}, Pairs: {}",
stats.total_chains, stats.total_assets, stats.total_pairs);
All configurations are validated on load:
Comprehensive error types for robust applications:
match registry.get_chain(&chain_id) {
Ok(chain) => { /* use chain */ },
Err(ChainRegistryError::ChainNotFound(id)) => {
println!("Chain {} not found", id);
},
Err(e) => println!("Error: {}", e),
}