Skip to content

Commit

Permalink
Merge branch 'dev' into fix/change-holesky-anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
damiramirez committed Feb 7, 2025
2 parents 11681e7 + 9c6aae8 commit e418366
Show file tree
Hide file tree
Showing 28 changed files with 2,211 additions and 501 deletions.
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Those changes in added, changed or breaking changes, should include usage exampl
* Added `eigen_common` dependency to the `eigensdk` crate when "full" feature is enabled in [#249](https://github.com/Layr-Labs/eigensdk-rs/pull/249).
* Added bindings for `ECDSAStakeRegistry` and `ECDSAServiceManagerBase` in [#269](https://github.com/Layr-Labs/eigensdk-rs/pull/269).
* Added release-plz in ci in [#275](https://github.com/Layr-Labs/eigensdk-rs/pull/275).
* Added new method `set_rewards_initiator` in `avsregistry/writer` in [#273](https://github.com/Layr-Labs/eigensdk-rs/pull/273).
```rust
let tx_hash = avs_writer
.set_rewards_initiator(new_rewards_init_address)
.await
.unwrap();
```
* Added new method `clear_deallocation_queue` in `elcontracts/writer` in [#270](https://github.com/Layr-Labs/eigensdk-rs/pull/270)
```rust
let tx_hash_clear = el_chain_writer
Expand Down Expand Up @@ -44,6 +51,7 @@ Those changes in added, changed or breaking changes, should include usage exampl
// tx_status should be true
```
* Added custom configuration for release-plz in [#281](https://github.com/Layr-Labs/eigensdk-rs/pull/281).
* Added Rewards2.1 support in [#323](https://github.com/Layr-Labs/eigensdk-rs/pull/323).

### Changed
* Changes in the way bindings are generated in [#243](https://github.com/Layr-Labs/eigensdk-rs/pull/243).
Expand All @@ -54,6 +62,57 @@ Those changes in added, changed or breaking changes, should include usage exampl
* Fixed incorrect package name in Cargo.toml for examples in [#285](https://github.com/Layr-Labs/eigensdk-rs/pull/285).

### Breaking changes
* refactor: update interface on `bls aggregation` in [#254](https://github.com/Layr-Labs/eigensdk-rs/pull/254)
* Introduces a new struct `TaskMetadata` with a constructor `TaskMetadata::new` to initialize a new task and a method `with_window_duration` to set the window duration.
* Refactors `initialize_new_task` and `single_task_aggregator` to accept a `TaskMetadata` struct instead of multiple parameters.
```rust
// BEFORE
bls_agg_service
.initialize_new_task(
task_index,
block_number as u32,
quorum_numbers,
quorum_threshold_percentages,
time_to_expiry,
)
.await
.unwrap();

// AFTER
let metadata = TaskMetadata::new(
task_index,
block_number,
quorum_numbers,
quorum_threshold_percentages,
time_to_expiry,
)
bls_agg_service.initialize_new_task(metadata).await.unwrap();
```

* Removes `initialize_new_task_with_window` since `window_duration` can now be set in `TaskMetadata`.
```rust
// BEFORE
bls_agg_service
.initialize_new_task_with_window(
task_index,
block_number as u32,
quorum_numbers,
quorum_threshold_percentages,
time_to_expiry,
window_duration,
)
.await
.unwrap();

// AFTER
let metadata = TaskMetadata::new(
task_index,
block_number,
quorum_numbers,
quorum_threshold_percentages,
time_to_expiry,
).with_window_duration(window_duration);
bls_agg_service.initialize_new_task(metadata).await.unwrap();
* refactor: encapsulate parameters into `TaskSignature` in [#260](https://github.com/Layr-Labs/eigensdk-rs/pull/260)
* Introduced `TaskSignature` struct to encapsulate parameters related to task signatures:
* Updated `process_new_signature` to accept a `TaskSignature` struct instead of multiple parameters.
Expand Down
10 changes: 10 additions & 0 deletions crates/chainio/clients/avsregistry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ pub mod error;
#[allow(dead_code)]
/// Fake avs registry module
pub mod fake_reader;

#[cfg(test)]
pub(crate) mod test_utils {
use alloy::primitives::{address, Address};

pub(crate) const ANVIL_FIRST_PRIVATE_KEY: &str =
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
pub(crate) const ANVIL_SECOND_ADDRESS: Address =
address!("70997970C51812dc3A010C7d01b50e0d17dc79C8");
}
63 changes: 61 additions & 2 deletions crates/chainio/clients/avsregistry/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,32 @@ impl AvsRegistryChainWriter {
Ok(*tx.tx_hash())
}

/// Set a new address as the rewards initiator
///
/// # Arguments
/// * `rewards_initiator` - The new address to set as the rewards initiator
///
/// # Returns
/// * `TxHash` - The transaction hash of the set rewards initiator transaction
pub async fn set_rewards_initiator(
&self,
rewards_initiator: Address,
) -> Result<TxHash, AvsRegistryError> {
info!("setting a new address as the rewards initiator");
let provider = get_signer(&self.signer.clone(), &self.provider);

let contract_service_manager_base =
ServiceManagerBase::new(self.service_manager_addr, provider);
let contract_call = contract_service_manager_base.setRewardsInitiator(rewards_initiator);

contract_call
.send()
.await
.map_err(AvsRegistryError::AlloyContractError)
.inspect(|tx| info!(tx_hash = ?tx, "successfully set a new address as the rewards initiator"))
.map(|tx| *tx.tx_hash())
}

/// Update socket
///
/// This function is used to update the socket of the sender (if it is a registered operator).
Expand Down Expand Up @@ -337,16 +363,19 @@ impl AvsRegistryChainWriter {

#[cfg(test)]
mod tests {

use super::AvsRegistryChainWriter;
use crate::test_utils::{ANVIL_FIRST_PRIVATE_KEY, ANVIL_SECOND_ADDRESS};
use alloy::primitives::{Address, Bytes, FixedBytes, U256};
use eigen_common::get_signer;
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::get_test_logger;
use eigen_testing_utils::anvil::start_m2_anvil_container;
use eigen_testing_utils::anvil::{start_anvil_container, start_m2_anvil_container};
use eigen_testing_utils::anvil_constants::{
get_operator_state_retriever_address, get_registry_coordinator_address,
};
use eigen_testing_utils::transaction::wait_transaction;
use eigen_utils::rewardsv2::middleware::servicemanagerbase::ServiceManagerBase;
use eigen_utils::slashing::middleware::registrycoordinator::RegistryCoordinator;
use futures_util::StreamExt;
use std::str::FromStr;
Expand Down Expand Up @@ -399,7 +428,37 @@ mod tests {
http_endpoint.clone(),
)
.await;
test_deregister_operator(&avs_writer, quorum_nums, http_endpoint).await;
test_deregister_operator(&avs_writer, quorum_nums, http_endpoint.clone()).await;
}

#[tokio::test]
async fn test_set_rewards_initiator() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let private_key = ANVIL_FIRST_PRIVATE_KEY.to_string();
let avs_writer =
build_avs_registry_chain_writer(http_endpoint.clone(), private_key.clone()).await;

// Set up event poller to listen to `RewardsInitiatorUpdated` events
let provider = get_signer(&avs_writer.signer.clone(), &avs_writer.provider);
let contract_registry_coordinator =
ServiceManagerBase::new(avs_writer.service_manager_addr, provider);
let event = contract_registry_coordinator.RewardsInitiatorUpdated_filter();
let poller = event.watch().await.unwrap();

let new_rewards_init_address = ANVIL_SECOND_ADDRESS;

let tx_hash = avs_writer
.set_rewards_initiator(new_rewards_init_address)
.await
.unwrap();

let tx_status = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
assert!(tx_status.status());

// Assert that event `RewardsInitiatorUpdated` is the same as `new_rewards_init_address`
let mut stream = poller.into_stream();
let (stream_event, _) = stream.next().await.unwrap().unwrap();
assert_eq!(stream_event.newRewardsInitiator, new_rewards_init_address);
}

// this function is caller from test_avs_writer_methods
Expand Down
46 changes: 39 additions & 7 deletions crates/chainio/clients/elcontracts/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ use alloy::{
};
use eigen_common::{get_provider, SdkProvider};
use eigen_logging::logger::SharedLogger;
use eigen_utils::{
slashing::core::{
allocationmanager::AllocationManager::{self, OperatorSet},
use eigen_utils::slashing::core::allocationmanager::AllocationManager::{self, OperatorSet};
use eigen_utils::slashing::{
core::{
avsdirectory::AVSDirectory,
delegationmanager::DelegationManager,
irewardscoordinator::{
IRewardsCoordinator,
IRewardsCoordinator::{self},
IRewardsCoordinatorTypes::{DistributionRoot, RewardsMerkleClaim},
},
istrategy::IStrategy::{self, IStrategyInstance},
permissioncontroller::PermissionController,
},
slashing::middleware::ierc20::IERC20::{self, IERC20Instance},
middleware::ierc20::IERC20::{self, IERC20Instance},
};

#[derive(Debug, Clone)]
pub struct ELChainReader {
_logger: SharedLogger,
Expand Down Expand Up @@ -462,6 +461,39 @@ impl ELChainReader {
Ok(operator_pi_split)
}

/// Gets the split for a specific `operator` for a given `OperatorSet`
///
/// # Arguments
///
/// * `operator` - The operator address
/// * `OperatorSet` - The operator set which consists of avs address and id.
///
/// # Returns
///
/// * u16 - The split for a specific `operator` for a given `OperatorSet`, if the call is successful
///
/// # Errors
///
/// * `ElContractsError` - if the call to the contract fails.
pub async fn get_operator_set_split(
&self,
operator: Address,
operator_set: eigen_utils::slashing::core::irewardscoordinator::IRewardsCoordinator::OperatorSet,
) -> Result<u16, ElContractsError> {
let provider = get_provider(&self.provider);

let rewards_coordinator = IRewardsCoordinator::new(self.rewards_coordinator, provider);

let operator_set_split = rewards_coordinator
.getOperatorSetSplit(operator, operator_set)
.call()
.await
.map_err(ElContractsError::AlloyContractError)?
._0;

Ok(operator_set_split)
}

/// Get the operator's shares in a strategy
///
/// # Arguments
Expand Down Expand Up @@ -1414,6 +1446,7 @@ pub struct AllocationInfo {

#[cfg(test)]
mod tests {

use super::*;
use crate::test_utils::{build_el_chain_reader, new_test_claim, OPERATOR_ADDRESS};
use alloy::primitives::{address, keccak256, Address, FixedBytes, U256};
Expand Down Expand Up @@ -1625,7 +1658,6 @@ mod tests {
async fn test_check_claim() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let el_chain_reader = build_el_chain_reader(http_endpoint.to_string()).await;

let (_, claim) = new_test_claim(&http_endpoint).await;

let valid_claim = el_chain_reader.check_claim(claim.clone()).await.unwrap();
Expand Down
Loading

0 comments on commit e418366

Please sign in to comment.