use blueprint_eigenlayer_extra::registration::RegistrationStateManager;
use blueprint_runner::config::{BlueprintEnvironment, ContextConfig, SupportedChains};
use blueprint_runner::eigenlayer::config::EigenlayerProtocolSettings;
use color_eyre::Result;
use std::path::{Path, PathBuf};
use url::Url;
pub async fn sync_avs_registrations(
http_rpc_url: &Url,
keystore_uri: &str,
settings_file: Option<&Path>,
) -> Result<()> {
println!("🔄 Synchronizing AVS registrations with on-chain state");
println!(" RPC Endpoint: {}", http_rpc_url);
let mut state_manager = RegistrationStateManager::load()?;
let registration_count = state_manager.registrations().registrations.len();
println!(" Local registrations: {}", registration_count);
if registration_count == 0 {
println!("⚠️ No local registrations to sync");
return Ok(());
}
println!("🔑 Using keystore: {}", keystore_uri);
let eigenlayer_settings = if let Some(settings_path) = settings_file {
println!(
"📄 Loading protocol settings from: {}",
settings_path.display()
);
EigenlayerProtocolSettings::default()
} else {
println!("📄 Using default protocol settings");
EigenlayerProtocolSettings::default()
};
let context_config = ContextConfig::create_eigenlayer_config(
http_rpc_url.clone(),
http_rpc_url.clone(), keystore_uri.to_string(),
None, PathBuf::from("/tmp/eigenlayer_sync"), None, SupportedChains::LocalTestnet, eigenlayer_settings,
);
let env = BlueprintEnvironment::load_with_config(context_config)
.map_err(|e| color_eyre::eyre::eyre!("Failed to create environment: {}", e))?;
println!();
println!("🔍 Verifying registrations on-chain...");
let changes = state_manager
.reconcile_with_chain(&env)
.await
.map_err(|e| color_eyre::eyre::eyre!("Failed to reconcile with chain: {}", e))?;
println!();
if changes > 0 {
println!(
"✅ Synchronization complete: {} registration(s) updated",
changes
);
println!();
println!("💡 Run 'cargo tangle blueprint eigenlayer list' to see updated registrations");
} else {
println!("✅ All registrations are in sync with on-chain state");
}
Ok(())
}