Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use rewards coordinator in get split functions #250

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,33 @@ Each version will have a separate `Breaking Changes` section as well. To describ
* Fixed the rewardsv2 bindings version in readme to 0.5.4 in [#246](https://github.com/Layr-Labs/eigensdk-rs/pull/246).

### Breaking changes
* fix: use rewards coordinator on get operator avs/pi split methods by @maximopalopoli in https://github.com/Layr-Labs/eigensdk-rs/pull/250
* The parameters of `ChainReader::new` changed, and it now receives the address of the rewards coordinator.

It was previously called this way:
``` Rust
let el_chain_reader = ELChainReader::new(
logger,
SLASHER_ADDRESS,
DELEGATION_MANAGER_ADDRESS,
AVS_DIRECTORY_ADDRESS,
provider_url,
);
```
Now, it's called this way:
``` Rust
let el_chain_reader = ELChainReader::new(
logger,
SLASHER_ADDRESS,
DELEGATION_MANAGER_ADDRESS,
REWARDS_COORDINATOR,
AVS_DIRECTORY_ADDRESS,
provider_url,
);
```

### Removed
### Other Changes

## [0.1.3] - 2024-01-17
### Added 🎉
Expand Down
4 changes: 4 additions & 0 deletions crates/chainio/clients/avsregistry/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ impl AvsRegistryChainWriter {

let ServiceManagerBase::avsDirectoryReturn { _0: avs_directory } = avs_directory_addr;

// We set rewards coordinator address as zero because we are not going to use it on any writer operation
let rewards_coordinator_addr = Address::ZERO;

let el_reader = ELChainReader::build(
logger.clone(),
delegation_manager_addr,
avs_directory,
rewards_coordinator_addr,
&provider,
)
.await
Expand Down
47 changes: 29 additions & 18 deletions crates/chainio/clients/elcontracts/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use eigen_types::operator::Operator;
use eigen_utils::core::islasher::ISlasher;
use eigen_utils::core::{
avsdirectory::AVSDirectory, delegationmanager::DelegationManager, erc20::ERC20,
istrategy::IStrategy, rewardscoordinator::RewardsCoordinator,
irewardscoordinator::IRewardsCoordinator, istrategy::IStrategy,
};
#[derive(Debug, Clone)]
pub struct ELChainReader {
_logger: SharedLogger,
slasher: Address,
pub(crate) delegation_manager: Address,
avs_directory: Address,
rewards_coordinator: Address,
pub provider: String,
}

Expand All @@ -35,13 +36,15 @@ impl ELChainReader {
_logger: SharedLogger,
slasher: Address,
delegation_manager: Address,
rewards_coordinator: Address,
avs_directory: Address,
provider: String,
) -> Self {
ELChainReader {
_logger,
slasher,
delegation_manager,
rewards_coordinator,
avs_directory,
provider,
}
Expand All @@ -66,6 +69,7 @@ impl ELChainReader {
_logger: SharedLogger,
delegation_manager: Address,
avs_directory: Address,
rewards_coordinator: Address,
client: &String,
) -> Result<Self, ElContractsError> {
let provider = get_provider(client);
Expand All @@ -85,6 +89,7 @@ impl ELChainReader {
avs_directory,
slasher: slasher_addr,
delegation_manager,
rewards_coordinator,
provider: client.to_string(),
})
}
Expand Down Expand Up @@ -384,63 +389,65 @@ impl ELChainReader {
Ok(is_operator_is)
}

/// Get Operator Avs Split
/// Gets the split of a specific `operator` for a specific `avs`
///
/// # Arguments
///
/// * `operator` - The operator's address
/// * `avs` - The Avs 's address
/// * `operator` - The operator address
/// * `avs` - The AVS address
///
/// # Returns
///
/// * `u16` - the split for the specific operator for the specific avs
/// * u16 - The split of the operator for the AVS, if the call is successful
///
/// # Errors
///
/// * `ElContractsError` - if the call to the contract fails
/// * `ElContractsError` - if the call to the contract fails.
pub async fn get_operator_avs_split(
&self,
operator: Address,
avs: Address,
) -> Result<u16, ElContractsError> {
let provider = get_provider(&self.provider);

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

Ok(contract_rewards_coordinator
let operator_avs_split = rewards_coordinator
.getOperatorAVSSplit(operator, avs)
.call()
.await
.map_err(ElContractsError::AlloyContractError)?
._0)
._0;

Ok(operator_avs_split)
}

/// Get Operator PI Split
/// Gets the split of a specific `operator` for Programmatic Incentives
///
/// # Arguments
///
/// * `operator` - The operator's address
/// * `operator` - The operator address
///
/// # Returns
///
/// * `u16` - The split for a specific `operator` for Programmatic Incentives
/// * u16 - The split of the operator for PI, if the call is successful
///
/// # Errors
///
/// * `ElContractsError` - if the call to the contract fails
/// * `ElContractsError` - if the call to the contract fails.
pub async fn get_operator_pi_split(&self, operator: Address) -> Result<u16, ElContractsError> {
let provider = get_provider(&self.provider);

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

Ok(contract_rewards_coordinator
let operator_pi_split = rewards_coordinator
.getOperatorPISplit(operator)
.call()
.await
.map_err(ElContractsError::AlloyContractError)?
._0)
._0;

Ok(operator_pi_split)
}
}

Expand All @@ -451,6 +458,7 @@ mod tests {
use alloy::providers::Provider;
use alloy::{eips::eip1898::BlockNumberOrTag::Number, rpc::types::BlockTransactionsKind};
use eigen_logging::get_test_logger;
use eigen_testing_utils::anvil_constants::get_rewards_coordinator_address;
use eigen_testing_utils::{
anvil::start_anvil_container,
anvil_constants::{
Expand Down Expand Up @@ -490,11 +498,14 @@ mod tests {
let MockAvsServiceManager::avsDirectoryReturn {
_0: avs_directory_address,
} = avs_directory_address_return;
let rewards_coordinator_address =
get_rewards_coordinator_address(http_endpoint.clone()).await;

ELChainReader::new(
get_test_logger(),
slasher_address,
delegation_manager_address,
rewards_coordinator_address,
avs_directory_address,
http_endpoint,
)
Expand Down
105 changes: 105 additions & 0 deletions crates/chainio/clients/elcontracts/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,15 @@ mod tests {
let MockAvsServiceManager::avsDirectoryReturn {
_0: avs_directory_address,
} = avs_directory_address_return;
let rewards_coordinator_address =
get_rewards_coordinator_address(http_endpoint.clone()).await;

(
ELChainReader::new(
get_test_logger().clone(),
slasher_address,
delegation_manager_address,
rewards_coordinator_address,
avs_directory_address,
http_endpoint,
),
Expand Down Expand Up @@ -751,4 +754,106 @@ mod tests {
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
assert!(receipt.status());
}
#[tokio::test]
async fn test_set_operator_avs_split_modified() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let el_chain_writer = new_test_writer_with_private_key(
http_endpoint.to_string(),
ANVIL_FIRST_PRIVATE_KEY.to_string(),
)
.await;
let new_split = 5;
let avs_address = get_service_manager_address(http_endpoint.clone()).await;

let split = el_chain_writer
.el_chain_reader
.get_operator_avs_split(ANVIL_FIRST_ADDRESS, avs_address)
.await
.unwrap();

assert_eq!(split, 1000);

// Set the activation delay to zero so that the split change can be
// processed right after setting it
let signer = get_signer(ANVIL_FIRST_PRIVATE_KEY, &http_endpoint);
let rewards_coordinator_address =
get_rewards_coordinator_address(http_endpoint.to_string()).await;

let rewards_coordinator = IRewardsCoordinator::new(rewards_coordinator_address, &signer);
let activation_delay = 0;
let set_activation_delay = rewards_coordinator
.setActivationDelay(activation_delay)
.send()
.await
.unwrap();
let receipt = set_activation_delay.get_receipt().await.unwrap();
assert!(receipt.status());

let tx_hash = el_chain_writer
.set_operator_avs_split(ANVIL_FIRST_ADDRESS, avs_address, new_split)
.await
.unwrap();

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

let split = el_chain_writer
.el_chain_reader
.get_operator_avs_split(ANVIL_FIRST_ADDRESS, avs_address)
.await
.unwrap();

assert_eq!(split, new_split);
}

#[tokio::test]
async fn test_set_operator_pi_split_modified() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let el_chain_writer = new_test_writer_with_private_key(
http_endpoint.to_string(),
ANVIL_FIRST_PRIVATE_KEY.to_string(),
)
.await;
let new_split = 5;

let split = el_chain_writer
.el_chain_reader
.get_operator_pi_split(ANVIL_FIRST_ADDRESS)
.await
.unwrap();

assert_eq!(split, 1000);

// Set the activation delay to zero so that the split change can be
// processed right after setting it
let signer = get_signer(ANVIL_FIRST_PRIVATE_KEY, &http_endpoint);
let rewards_coordinator_address =
get_rewards_coordinator_address(http_endpoint.to_string()).await;

let rewards_coordinator = IRewardsCoordinator::new(rewards_coordinator_address, &signer);
let activation_delay = 0;
let set_activation_delay = rewards_coordinator
.setActivationDelay(activation_delay)
.send()
.await
.unwrap();
let receipt = set_activation_delay.get_receipt().await.unwrap();
assert!(receipt.status());

let tx_hash = el_chain_writer
.set_operator_pi_split(ANVIL_FIRST_ADDRESS, new_split)
.await
.unwrap();

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

let split = el_chain_writer
.el_chain_reader
.get_operator_pi_split(ANVIL_FIRST_ADDRESS)
.await
.unwrap();

assert_eq!(split, new_split);
}
}
1 change: 1 addition & 0 deletions crates/services/bls_aggregation/src/bls_agg_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub mod integration_test {
)
.await
.unwrap();

let avs_writer = AvsRegistryChainWriter::build_avs_registry_chain_writer(
get_test_logger(),
http_endpoint.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ mod tests {
get_test_logger(),
Address::ZERO,
delegation_manager_address,
rewards_coordinator_address,
avs_directory_address,
http_endpoint.to_string(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async fn main() -> Result<()> {
get_test_logger().clone(),
SLASHER_ADDRESS,
DELEGATION_MANAGER_ADDRESS,
REWARDS_COORDINATOR,
AVS_DIRECTORY_ADDRESS,
"https://ethereum-holesky.blockpi.network/v1/rpc/public".to_string(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub async fn register_operator(pvt_key: &str, bls_key: &str, http_endpoint: &str
get_test_logger(),
Address::ZERO,
delegation_manager_address,
rewards_coordinator_address,
avs_directory_address,
http_endpoint.to_owned(),
);
Expand Down
Loading