cargo_tangle/command/eigenlayer/
sync.rs1use blueprint_eigenlayer_extra::registration::RegistrationStateManager;
3use blueprint_runner::config::{BlueprintEnvironment, ContextConfig, SupportedChains};
4use blueprint_runner::eigenlayer::config::EigenlayerProtocolSettings;
5use color_eyre::Result;
6use std::path::{Path, PathBuf};
7use url::Url;
8
9pub async fn sync_avs_registrations(
25 http_rpc_url: &Url,
26 keystore_uri: &str,
27 settings_file: Option<&Path>,
28) -> Result<()> {
29 println!("🔄 Synchronizing AVS registrations with on-chain state");
30 println!(" RPC Endpoint: {}", http_rpc_url);
31
32 let mut state_manager = RegistrationStateManager::load()?;
34
35 let registration_count = state_manager.registrations().registrations.len();
36 println!(" Local registrations: {}", registration_count);
37
38 if registration_count == 0 {
39 println!("⚠️ No local registrations to sync");
40 return Ok(());
41 }
42
43 println!("🔑 Using keystore: {}", keystore_uri);
44
45 let eigenlayer_settings = if let Some(settings_path) = settings_file {
47 println!(
48 "📄 Loading protocol settings from: {}",
49 settings_path.display()
50 );
51 EigenlayerProtocolSettings::default()
54 } else {
55 println!("📄 Using default protocol settings");
56 EigenlayerProtocolSettings::default()
57 };
58
59 let context_config = ContextConfig::create_eigenlayer_config(
61 http_rpc_url.clone(),
62 http_rpc_url.clone(), keystore_uri.to_string(),
64 None, PathBuf::from("/tmp/eigenlayer_sync"), None, SupportedChains::LocalTestnet, eigenlayer_settings,
69 );
70
71 let env = BlueprintEnvironment::load_with_config(context_config)
72 .map_err(|e| color_eyre::eyre::eyre!("Failed to create environment: {}", e))?;
73
74 println!();
75 println!("🔍 Verifying registrations on-chain...");
76
77 let changes = state_manager
79 .reconcile_with_chain(&env)
80 .await
81 .map_err(|e| color_eyre::eyre::eyre!("Failed to reconcile with chain: {}", e))?;
82
83 println!();
84 if changes > 0 {
85 println!(
86 "✅ Synchronization complete: {} registration(s) updated",
87 changes
88 );
89 println!();
90 println!("💡 Run 'cargo tangle blueprint eigenlayer list' to see updated registrations");
91 } else {
92 println!("✅ All registrations are in sync with on-chain state");
93 }
94
95 Ok(())
96}