From b9f4edf99a964b0ddf98975eebdfba50b39a2270 Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Wed, 18 Sep 2024 15:12:33 -0300 Subject: [PATCH] Simplify Operator struct (#126) --- .../chainio/clients/elcontracts/src/reader.rs | 14 ++-- .../chainio/clients/elcontracts/src/writer.rs | 53 +++++++-------- .../src/operatorsinfo_inmemory.rs | 14 ++-- crates/types/src/operator.rs | 68 ++----------------- ...in_quorum_with_avs_registry_coordinator.rs | 20 +++--- .../examples/get_operator_info.rs | 20 +++--- 6 files changed, 60 insertions(+), 129 deletions(-) diff --git a/crates/chainio/clients/elcontracts/src/reader.rs b/crates/chainio/clients/elcontracts/src/reader.rs index c0ede66b..6112de51 100644 --- a/crates/chainio/clients/elcontracts/src/reader.rs +++ b/crates/chainio/clients/elcontracts/src/reader.rs @@ -258,13 +258,13 @@ impl ELChainReader { _0: operator_details, } = operator_det; - Ok(Operator::new( - operator, - operator_details.earningsReceiver, - operator_details.delegationApprover, - operator_details.stakerOptOutWindowBlocks, - None, - )) + Ok(Operator { + address: operator, + earnings_receiver_address: operator_details.earningsReceiver, + delegation_approver_address: operator_details.delegationApprover, + staker_opt_out_window_blocks: operator_details.stakerOptOutWindowBlocks, + metadata_url: None, + }) } Err(e) => Err(ElContractsError::AlloyContractError(e)), } diff --git a/crates/chainio/clients/elcontracts/src/writer.rs b/crates/chainio/clients/elcontracts/src/writer.rs index 23250777..2765941a 100644 --- a/crates/chainio/clients/elcontracts/src/writer.rs +++ b/crates/chainio/clients/elcontracts/src/writer.rs @@ -43,14 +43,11 @@ impl ELChainWriter { &self, operator: Operator, ) -> Result, ElContractsError> { - info!( - "registering operator {:?} to EigenLayer", - operator.has_address() - ); + info!("registering operator {:?} to EigenLayer", operator.address); let op_details = OperatorDetails { - earningsReceiver: operator.has_earnings_receiver_address(), - delegationApprover: operator.has_delegation_approver_address(), - stakerOptOutWindowBlocks: operator.has_staker_opt_out_window_blocks(), + earningsReceiver: operator.earnings_receiver_address, + delegationApprover: operator.delegation_approver_address, + stakerOptOutWindowBlocks: operator.staker_opt_out_window_blocks, }; let provider = get_signer(self.signer.clone(), &self.provider); @@ -58,7 +55,7 @@ impl ELChainWriter { let binding = { let contract_call = contract_delegation_manager - .registerAsOperator(op_details, operator.has_metadata_url().unwrap_or_default()); + .registerAsOperator(op_details, operator.metadata_url.unwrap_or_default()); contract_call.gas(300000) }; @@ -87,12 +84,12 @@ impl ELChainWriter { ) -> Result { info!( "updating operator detils of operator {:?} to EigenLayer", - operator.has_address() + operator.address ); let operator_details = OperatorDetails { - earningsReceiver: operator.has_earnings_receiver_address(), - delegationApprover: operator.has_delegation_approver_address(), - stakerOptOutWindowBlocks: operator.has_staker_opt_out_window_blocks(), + earningsReceiver: operator.earnings_receiver_address, + delegationApprover: operator.delegation_approver_address, + stakerOptOutWindowBlocks: operator.staker_opt_out_window_blocks, }; let provider = get_signer(self.signer.clone(), &self.provider); @@ -106,10 +103,10 @@ impl ELChainWriter { .await .map_err(ElContractsError::AlloyContractError)?; - info!(tx_hash = %modify_operator_tx.tx_hash(), operator = %operator.has_address(), "updated operator details tx"); + info!(tx_hash = %modify_operator_tx.tx_hash(), operator = %operator.address, "updated operator details tx"); let contract_call_update_metadata_uri = contract_delegation_manager - .updateOperatorMetadataURI(operator.has_metadata_url().unwrap_or_default()); + .updateOperatorMetadataURI(operator.metadata_url.unwrap_or_default()); let metadata_tx = contract_call_update_metadata_uri.send().await?; @@ -281,13 +278,13 @@ mod tests { ) .expect("no key"); - let operator = Operator::new( - wallet.address(), - wallet.address(), - wallet.address(), - 3, - Some("eigensdk-rs".to_string()), - ); + let operator = Operator { + address: wallet.address(), + earnings_receiver_address: wallet.address(), + delegation_approver_address: wallet.address(), + staker_opt_out_window_blocks: 3, + metadata_url: Some("eigensdk-rs".to_string()), + }; // First test: register as an operator let tx_hash = el_chain_writer @@ -308,13 +305,13 @@ mod tests { ) .expect("no key"); - let operator_modified = Operator::new( - wallet_modified.address(), - wallet_modified.address(), - wallet_modified.address(), - 3, - Some("eigensdk-rs".to_string()), - ); + let operator_modified = Operator { + address: wallet_modified.address(), + earnings_receiver_address: wallet_modified.address(), + delegation_approver_address: wallet_modified.address(), + staker_opt_out_window_blocks: 3, + metadata_url: Some("eigensdk-rs".to_string()), + }; // Second test: update operator details let tx_hash = el_chain_writer diff --git a/crates/services/operatorsinfo/src/operatorsinfo_inmemory.rs b/crates/services/operatorsinfo/src/operatorsinfo_inmemory.rs index 1f42a377..f622e793 100644 --- a/crates/services/operatorsinfo/src/operatorsinfo_inmemory.rs +++ b/crates/services/operatorsinfo/src/operatorsinfo_inmemory.rs @@ -446,13 +446,13 @@ mod tests { pvt_key.to_string(), ); - let operator_details = Operator::new( - signer.address(), - signer.address(), - signer.address(), - 3, - Some("eigensdk-rs".to_string()), - ); + let operator_details = Operator { + address: signer.address(), + earnings_receiver_address: signer.address(), + delegation_approver_address: signer.address(), + staker_opt_out_window_blocks: 3, + metadata_url: Some("eigensdk-rs".to_string()), + }; el_chain_writer .register_as_operator(operator_details) diff --git a/crates/types/src/operator.rs b/crates/types/src/operator.rs index f7427146..3208a49b 100644 --- a/crates/types/src/operator.rs +++ b/crates/types/src/operator.rs @@ -39,69 +39,11 @@ impl From for OperatorPubKeys { } pub struct Operator { - address: Address, - earnings_receiver_address: Address, - delegation_approver_address: Address, - staker_opt_out_window_blocks: u32, - metadata_url: Option, -} - -impl Operator { - pub fn new( - address: Address, - earnings_receiver_address: Address, - delegation_approver_address: Address, - staker_opt_out_window_blocks: u32, - metadata_url: Option, - ) -> Self { - Operator { - address, - earnings_receiver_address, - delegation_approver_address, - staker_opt_out_window_blocks, - metadata_url, - } - } - - pub fn address(&mut self, address: Address) { - self.address = address; - } - - pub fn metadata_url(&mut self, metadata: String) { - self.metadata_url = Some(metadata); - } - - pub fn earnings_receiver_address(&mut self, address: Address) { - self.earnings_receiver_address = address; - } - - pub fn delegation_approver_address(&mut self, address: Address) { - self.delegation_approver_address = address; - } - - pub fn staker_opt_out_window_blocks(&mut self, block: u32) { - self.staker_opt_out_window_blocks = block; - } - - pub fn has_address(&self) -> Address { - self.address - } - - pub fn has_metadata_url(&self) -> Option { - self.metadata_url.clone() - } - - pub fn has_earnings_receiver_address(&self) -> Address { - self.earnings_receiver_address - } - - pub fn has_delegation_approver_address(&self) -> Address { - self.delegation_approver_address - } - - pub fn has_staker_opt_out_window_blocks(&self) -> u32 { - self.staker_opt_out_window_blocks - } + pub address: Address, + pub earnings_receiver_address: Address, + pub delegation_approver_address: Address, + pub staker_opt_out_window_blocks: u32, + pub metadata_url: Option, } pub type Socket = String; diff --git a/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs b/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs index 3139e6d8..a42dd2d2 100644 --- a/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs +++ b/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs @@ -42,11 +42,7 @@ async fn main() -> Result<()> { "12248929636257230549931416853095037629726205319386239410403476017439825112537".to_string(), )?; - let digest_hash: FixedBytes<32> = FixedBytes::from([ - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, - ]); + let digest_hash: FixedBytes<32> = FixedBytes::from([0x02; 32]); // Get the current SystemTime let now = SystemTime::now(); @@ -85,13 +81,13 @@ async fn main() -> Result<()> { ) .expect("no key "); - let operator_details = Operator::new( - wallet.address(), - wallet.address(), - wallet.address(), - 3, - Some("eigensdk-rs".to_string()), - ); + let operator_details = Operator { + address: wallet.address(), + earnings_receiver_address: wallet.address(), + delegation_approver_address: wallet.address(), + staker_opt_out_window_blocks: 3, + metadata_url: Some("eigensdk-rs".to_string()), + }; // Register the address as operator in delegation manager let _s = el_writer.register_as_operator(operator_details).await; diff --git a/examples/info-operator-service/examples/get_operator_info.rs b/examples/info-operator-service/examples/get_operator_info.rs index 194df947..6b069c27 100644 --- a/examples/info-operator-service/examples/get_operator_info.rs +++ b/examples/info-operator-service/examples/get_operator_info.rs @@ -90,13 +90,13 @@ pub async fn register_operator(pvt_key: &str, bls_key: &str) { pvt_key.to_string(), ); - let operator_details = Operator::new( - signer.address(), - signer.address(), - signer.address(), - 3, - Some("eigensdk-rs".to_string()), - ); + let operator_details = Operator { + address: signer.address(), + earnings_receiver_address: signer.address(), + delegation_approver_address: signer.address(), + staker_opt_out_window_blocks: 3, + metadata_url: Some("eigensdk-rs".to_string()), + }; let _ = el_chain_writer .register_as_operator(operator_details) @@ -114,11 +114,7 @@ pub async fn register_operator(pvt_key: &str, bls_key: &str) { .unwrap(); let bls_key_pair = BlsKeyPair::new(bls_key.to_string()).unwrap(); - let salt: FixedBytes<32> = FixedBytes::from([ - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, - ]); + let salt: FixedBytes<32> = FixedBytes::from([0x02; 32]); let now = SystemTime::now(); let mut expiry: U256 = U256::from(0); // Convert SystemTime to a Duration since the UNIX epoch