Skip to content

Commit

Permalink
fix: generalize config for N operators
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jan 31, 2025
1 parent 732edd8 commit 2185428
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 535 deletions.
175 changes: 112 additions & 63 deletions bin/incredible-squaring-avs/src/commands/avs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use eigen_utils::core::allocationmanager::IAllocationManagerTypes::AllocateParam
use eigen_utils::middleware::registrycoordinator::{
IRegistryCoordinator, IStakeRegistry, RegistryCoordinator,
};
use incredible_config::IncredibleConfig;
use incredible_config::{
BlsConfig, EcdsaConfig, IncredibleConfig, OperatorConfig, OperatorRegistrationConfig,
};
use incredible_testing_utils::{
get_incredible_squaring_operator_state_retriever, get_incredible_squaring_registry_coordinator,
get_incredible_squaring_service_manager, get_incredible_squaring_strategy_address,
Expand Down Expand Up @@ -418,28 +420,28 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
config.set_service_manager_address(service_manager_address_anvil.to_string());
config.set_node_api_port_address(node_api_address);
config.set_metrics_port_address(metrics_address);
config.set_slash_simulate(slash_simulate);
// there's a default value ,so using unwrap is no issue
config.set_task_manager_signer(task_manager_signer);
config.set_signer(signer); // there's a default value ,so using unwrap is no issue
config.set_operator_set_id(operator_set_id);
config.set_chain_id(chain_id);
config.set_http_rpc_url(rpc_url.clone());
config.set_ws_rpc_url(ws_rpc_url);
config.set_ecdsa_keystore_path(ecdsa_keystore_path.clone());
config.set_ecdsa_keystore_pasword(ecdsa_keystore_password.clone());
config.set_aggregator_ip_address(aggregator_ip_address);
config.set_bls_keystore_path(bls_keystore_path.clone());
config.set_bls_keystore_password(bls_keystore_password.clone());
config.set_allocation_delay(allocation_delay);
config.set_operator_registration_sig_salt(operator_to_avs_registration_sig_salt);
config.set_socket(socket);

config.set_quorum_number(quorum_number.clone());
config.set_operator_id(operator_id);
config.set_operator_address(operator_address);
config.set_operator_2_address(operator_2_address);
config.set_operator_2_id(operator_2_id);

// config.set_slash_simulate(slash_simulate);
// config.set_operator_set_id(operator_set_id);
// config.set_ecdsa_keystore_path(ecdsa_keystore_path.clone());
// config.set_ecdsa_keystore_pasword(ecdsa_keystore_password.clone());
// config.set_bls_keystore_path(bls_keystore_path.clone());
// config.set_bls_keystore_password(bls_keystore_password.clone());
// config.set_allocation_delay(allocation_delay);
// config.set_operator_registration_sig_salt(operator_to_avs_registration_sig_salt);
// config.set_socket(socket);
// config.set_quorum_number(quorum_number.clone());
// config.set_operator_id(operator_id);
// config.set_operator_address(operator_address);
// config.set_operator_2_address(operator_2_address);
// config.set_operator_2_id(operator_2_id);
}
config.set_erc20_mock_strategy_address(
erc20_mock_strategy_address.unwrap_or(erc20_mock_strategy_address_anvil.to_string()),
Expand All @@ -449,12 +451,9 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
.clone()
.unwrap_or(delegation_manager_address_anvil.to_string()),
);
config.set_operator_2_quorum_number(quorum_number);
config.set_avs_directory_address(
avs_directory_addr.unwrap_or(avs_directory_address_anvil.to_string()),
);
config.set_operator_signing_key(operator_pvt_key);
config.set_operator_2_signing_key(operator_2_pvt_key);
// use value from config , if None , then use anvil
config.set_registry_coordinator_addr(
registry_coordinator_address
Expand All @@ -475,10 +474,6 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
);
config.set_rewards_coordinator_address(rewards_coordinator_address_anvil.to_string());
config.set_permission_controller_address(permission_controller_address_anvil.to_string());
config.set_ecdsa_keystore_2_path(ecdsa_keystore_2_path.clone());
config.set_ecdsa_keystore_2_pasword(ecdsa_keystore_2_password.clone());
config
.set_operator_2_registration_sig_salt(operator_2_to_avs_registration_sig_salt.clone());
let now = SystemTime::now();
let mut expiry: U256 = U256::from(0);
if let Ok(duration_since_epoch) = now.duration_since(UNIX_EPOCH) {
Expand All @@ -490,27 +485,79 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
debug!("System time seems to be before the UNIX epoch.");
}
// provided expiry , if not , use default expiry : 10000 seconds
config.set_sig_expiry(sig_expiry.unwrap_or(expiry.to_string()).to_string());
config.set_bls_keystore_2_path(bls_keystore_2_path.clone());
config.set_bls_keystore_2_password(bls_keystore_2_password.clone());
config.set_operator_2_sig_expiry(
operator_2_sig_expiry
.unwrap_or(expiry.to_string())
.to_string(),
);
config.set_operator_1_token_amount(operator_1_token_amount);
config.set_operator_2_token_amount(operator_2_token_amount);
let op1_sig_expiry = sig_expiry.unwrap_or(expiry.to_string()).to_string();

let operator_1_config = OperatorConfig {
registration_config: Some(OperatorRegistrationConfig {
operator_to_avs_registration_sig_salt,
socket: socket.clone(),
quorum_number: quorum_number.clone(),
sig_expiry: op1_sig_expiry.clone(),
operator_pvt_key: operator_pvt_key.clone(),
ecdsa_config: EcdsaConfig {
keystore_path: ecdsa_keystore_path.clone(),
keystore_password: ecdsa_keystore_password.clone(),
},
}),
operator_address,
operator_id,
operator_set_id: operator_set_id.clone(),
operator_token_amount: operator_1_token_amount.clone(),
allocation_delay: allocation_delay.clone(),
slash_simulate,
bls_config: BlsConfig {
keystore_path: bls_keystore_path.clone(),
keystore_password: bls_keystore_password.clone(),
},
};
config.add_operator(operator_1_config.clone());

// provided expiry , if not , use default expiry : 10000 seconds
let op2_sig_expiry = operator_2_sig_expiry
.unwrap_or(expiry.to_string())
.to_string();

let operator_2_config = OperatorConfig {
registration_config: Some(OperatorRegistrationConfig {
operator_to_avs_registration_sig_salt: operator_2_to_avs_registration_sig_salt,
socket: socket.clone(),
quorum_number,
sig_expiry: op2_sig_expiry,
operator_pvt_key: operator_2_pvt_key.clone(),
ecdsa_config: EcdsaConfig {
keystore_path: ecdsa_keystore_2_path.clone(),
keystore_password: ecdsa_keystore_2_password.clone(),
},
}),
operator_address: operator_2_address,
operator_id: operator_2_id,
operator_set_id: operator_set_id.clone(),
operator_token_amount: operator_2_token_amount.clone(),
allocation_delay: allocation_delay.clone(),
slash_simulate,
bls_config: BlsConfig {
keystore_path: bls_keystore_2_path.clone(),
keystore_password: bls_keystore_2_password.clone(),
},
};
config.add_operator(operator_2_config.clone());

let socket_addr_metrics: SocketAddr = SocketAddr::from_str(&config.metrics_port_address())?;
init_registry(socket_addr_metrics);

let operator_1_pvt_key = operator_1_config
.registration_config
.unwrap()
.operator_pvt_key;

// enable operator sets
// this can only be called by registry coordinator's owner.
// in our case the deployer key in scripts was anvil's 0 index key which is same as operator1
let enable_operator_sets_tx_hash = enable_operator_sets(
config.registry_coordinator_addr()?,
config.operator_pvt_key(),
config.ecdsa_keystore_path(),
config.ecdsa_keystore_password(),
Some(operator_1_pvt_key.clone()),
ecdsa_keystore_path.clone(),
ecdsa_keystore_password.clone(),
&rpc_url,
)
.await?;
Expand All @@ -519,19 +566,21 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
let total_delegated_quorum_create_tx_hash = create_total_delegated_stake_quorum(
config.erc20_mock_strategy_addr()?,
config.registry_coordinator_addr()?,
config.operator_pvt_key(),
config.ecdsa_keystore_path(),
config.ecdsa_keystore_password(),
Some(operator_1_pvt_key.clone()),
ecdsa_keystore_path.clone(),
ecdsa_keystore_password.clone(),
&rpc_url,
)
.await?;
info!(tx_hash = %total_delegated_quorum_create_tx_hash,"total delegated stake quorum create tx_hash");

let allocation_delay = allocation_delay.parse()?;

if register_operator {
let _ = register_operator_with_el_and_deposit_tokens_in_strategy(
metadata_uri.clone(),
config.allocation_delay()?,
config.operator_pvt_key(),
allocation_delay,
Some(operator_1_pvt_key.clone()),
rpc_url.clone(),
ecdsa_keystore_path.clone(),
ecdsa_keystore_password.clone(),
Expand All @@ -543,14 +592,14 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
config.avs_directory_addr()?,
config.strategy_manager_addr()?,
config.erc20_mock_strategy_addr()?,
config.operator_1_token_amount()?,
operator_1_token_amount.parse()?,
)
.await;

let _ = register_operator_with_el_and_deposit_tokens_in_strategy(
metadata_uri,
config.allocation_delay()?,
config.operator_2_pvt_key(),
allocation_delay,
Some(operator_2_pvt_key.clone()),
rpc_url.clone(),
ecdsa_keystore_2_path.clone(),
ecdsa_keystore_2_password.clone(),
Expand All @@ -562,16 +611,16 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
config.avs_directory_addr()?,
config.strategy_manager_addr()?,
config.erc20_mock_strategy_addr()?,
config.operator_2_token_amount()?,
operator_2_token_amount.parse()?,
)
.await;

let allocation_delay_set_tx_hash = set_allocation_delay(
config.allocation_delay()?,
allocation_delay,
allocation_manager_address_anvil,
config.operator_pvt_key(),
config.ecdsa_keystore_path(),
config.ecdsa_keystore_password(),
Some(operator_pvt_key.clone()),
ecdsa_keystore_path.clone(),
ecdsa_keystore_password.clone(),
&rpc_url,
)
.await?;
Expand All @@ -581,9 +630,9 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
);

let modify_allocation_for_operator1_tx_hash = modify_allocation_for_operator(
config.operator_set_id()?,
operator_set_id.parse()?,
allocation_manager_address_anvil,
config.operator_pvt_key(),
Some(operator_pvt_key.clone()),
ecdsa_keystore_path.clone(),
ecdsa_keystore_password.clone(),
&rpc_url,
Expand All @@ -596,9 +645,9 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
info!(tx_hash = %modify_allocation_for_operator1_tx_hash,strategy_address = %config.erc20_mock_strategy_addr()?,"allocation by operator1 for strategy");

let modify_allocation_for_operator2_tx_hash = modify_allocation_for_operator(
config.operator_set_id()?,
operator_set_id.parse()?,
allocation_manager_address_anvil,
config.operator_2_pvt_key(),
Some(operator_2_pvt_key.clone()),
ecdsa_keystore_2_path.clone(),
ecdsa_keystore_2_password.clone(),
&rpc_url,
Expand All @@ -608,42 +657,42 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
)
.await?;
info!(tx_hash = %modify_allocation_for_operator2_tx_hash,strategy_address = %config.erc20_mock_strategy_addr()?,"allocation by operator2 for strategy");
let keystore = Keystore::from_file(&config.bls_keystore_path())?
.decrypt(&config.bls_keystore_password())
let keystore = Keystore::from_file(&bls_keystore_path)?
.decrypt(&bls_keystore_password)
.unwrap();
let fr_key: String = keystore.iter().map(|&value| value as char).collect();
let key_pair = BlsKeyPair::new(fr_key)?;
let register_for_operator_sets_by_operator1_txhash = register_for_operator_sets(
config.operator_set_id()?,
operator_set_id.parse()?,
key_pair,
config.registry_coordinator_addr()?,
allocation_manager_address_anvil,
config.operator_pvt_key(),
Some(operator_pvt_key),
ecdsa_keystore_path.clone(),
ecdsa_keystore_password.clone(),
&rpc_url,
service_manager_address_anvil,
config.socket().to_string(),
socket.clone(),
)
.await?;

info!(tx_hash = %register_for_operator_sets_by_operator1_txhash,"register for operator sets by operator1");
let keystore = Keystore::from_file(&config.bls_keystore_2_path())?
.decrypt(&config.bls_keystore_2_password())
let keystore = Keystore::from_file(&bls_keystore_2_path)?
.decrypt(&bls_keystore_2_password)
.unwrap();
let fr_key: String = keystore.iter().map(|&value| value as char).collect();
let key_pair_2 = BlsKeyPair::new(fr_key)?;
let register_for_operator_sets_by_operator2_txhash = register_for_operator_sets(
config.operator_set_id()?,
operator_set_id.parse()?,
key_pair_2,
config.registry_coordinator_addr()?,
allocation_manager_address_anvil,
config.operator_2_pvt_key(),
Some(operator_2_pvt_key),
ecdsa_keystore_2_path.clone(),
ecdsa_keystore_2_password.clone(),
&rpc_url,
service_manager_address_anvil,
config.operator_2_socket().to_string(),
socket,
)
.await?;
info!(tx_hash = %register_for_operator_sets_by_operator2_txhash,"register for operator sets by operator2");
Expand Down
Loading

0 comments on commit 2185428

Please sign in to comment.