diff --git a/crates/chainio/clients/elcontracts/src/reader.rs b/crates/chainio/clients/elcontracts/src/reader.rs index 49130e54..de28bfa4 100644 --- a/crates/chainio/clients/elcontracts/src/reader.rs +++ b/crates/chainio/clients/elcontracts/src/reader.rs @@ -11,7 +11,7 @@ use eigen_utils::{ delegationmanager::DelegationManager, erc20::ERC20::{self, ERC20Instance}, get_provider, - irewardscoordinator::IRewardsCoordinator, + irewardscoordinator::{IRewardsCoordinator, IRewardsCoordinatorTypes::DistributionRoot}, istrategy::IStrategy::{self, IStrategyInstance}, permissioncontroller::PermissionController, SdkProvider, @@ -256,6 +256,34 @@ impl ELChainReader { Ok(end_timestamp) } + /// Get the latest claimable distribution root. + /// + /// # Returns + /// * `Result` - The latest claimable distribution root if the call is successful. + /// + /// # Errors + /// * `ElContractsError` - if the call to the contract fails. + pub async fn get_current_claimable_distribution_root( + &self, + ) -> Result { + let provider = get_provider(&self.provider); + + let contract_rewards_coordinator = + IRewardsCoordinator::new(self.rewards_coordinator, &provider); + + let cumulative_claimed_for_root_call = contract_rewards_coordinator + .getCurrentClaimableDistributionRoot() + .call() + .await + .map_err(ElContractsError::AlloyContractError)?; + + let IRewardsCoordinator::getCurrentClaimableDistributionRootReturn { + _0: cumulative_claimed_for_root_ret, + } = cumulative_claimed_for_root_call; + + Ok(cumulative_claimed_for_root_ret) + } + /// Get the operator's shares in a strategy /// /// # Arguments @@ -1329,6 +1357,28 @@ mod tests { assert_eq!(end_timestamp, 1); } + #[tokio::test] + async fn test_get_current_claimable_distribution_root() { + let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; + let el_chain_reader = build_el_chain_reader(http_endpoint.to_string()).await; + + let distribution_root = el_chain_reader + .get_current_claimable_distribution_root() + .await + .unwrap(); + // The root starts being zero + assert_eq!(distribution_root.root, FixedBytes::ZERO); + + let (root, _) = new_claim(&http_endpoint).await; + + let distribution_root = el_chain_reader + .get_current_claimable_distribution_root() + .await + .unwrap(); + + assert_eq!(distribution_root.root, root); + } + #[tokio::test] async fn test_is_operator_registered() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; diff --git a/crates/chainio/clients/elcontracts/src/writer.rs b/crates/chainio/clients/elcontracts/src/writer.rs index 1490137e..4729d5ef 100644 --- a/crates/chainio/clients/elcontracts/src/writer.rs +++ b/crates/chainio/clients/elcontracts/src/writer.rs @@ -11,10 +11,7 @@ use eigen_utils::{ delegationmanager::DelegationManager, erc20::ERC20, get_signer, - irewardscoordinator::{ - IRewardsCoordinator, - IRewardsCoordinatorTypes::{self, RewardsMerkleClaim}, - }, + irewardscoordinator::{IRewardsCoordinator, IRewardsCoordinatorTypes::RewardsMerkleClaim}, permissioncontroller::PermissionController, registrycoordinator::{IBLSApkRegistry::PubkeyRegistrationParams, RegistryCoordinator}, strategymanager::StrategyManager, @@ -264,34 +261,6 @@ impl ELChainWriter { Ok(*tx.tx_hash()) } - /// Get the latest claimable distribution root. - /// - /// # Returns - /// * `Result` - The latest claimable distribution root if the call is successful. - /// - /// # Errors - /// * `ElContractsError` - if the call to the contract fails. - pub async fn get_current_claimable_distribution_root( - &self, - ) -> Result { - let provider = get_signer(&self.signer, &self.provider); - - let contract_rewards_coordinator = - IRewardsCoordinator::new(self.rewards_coordinator, &provider); - - let cumulative_claimed_for_root_call = contract_rewards_coordinator - .getCurrentClaimableDistributionRoot() - .call() - .await - .map_err(ElContractsError::AlloyContractError)?; - - let IRewardsCoordinator::getCurrentClaimableDistributionRootReturn { - _0: cumulative_claimed_for_root_ret, - } = cumulative_claimed_for_root_call; - - Ok(cumulative_claimed_for_root_ret) - } - /// Get the root index from a given hash. /// /// # Arguments @@ -958,24 +927,6 @@ mod tests { assert_eq!(cumulative_claimed_ret, U256::from(0)); } - #[tokio::test] - async fn test_get_cumulative_claimed_for_root() { - let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await; - let el_chain_writer = new_test_writer( - http_endpoint.to_string(), - ANVIL_FIRST_PRIVATE_KEY.to_string(), - ) - .await; - let (root, _) = new_claim(&http_endpoint).await; - - let distribution_root = el_chain_writer - .get_current_claimable_distribution_root() - .await - .unwrap(); - - assert_eq!(distribution_root.root, root); - } - #[tokio::test] async fn test_add_and_remove_pending_admin() { let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;