Skip to content

Commit 47d08b5

Browse files
fix: use rewards coordinator in get split functions (#250)
### What Changed? In get_operator_avs_split and get_operator_pi_split was being used delegation manager address to instantiate rewards coordinator. Now is used rewards coordinator's address. ### Reviewer Checklist - [ ] New features are tested and documented - [ ] PR updates the changelog with a description of changes - [ ] PR has one of the `changelog-X` labels (if applies) - [ ] Code deprecates any old functionality before removing it --------- Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
1 parent 707044a commit 47d08b5

File tree

8 files changed

+167
-18
lines changed

8 files changed

+167
-18
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ Those changes in added, changed or breaking changes, should include usage exampl
2727
* Fixed incorrect package name in Cargo.toml for examples in [#285](https://github.com/Layr-Labs/eigensdk-rs/pull/285).
2828

2929
### Breaking changes
30+
* fix: use rewards coordinator on get operator avs/pi split methods by @maximopalopoli in https://github.com/Layr-Labs/eigensdk-rs/pull/250
31+
* The parameters of `ChainReader::new` changed, and it now receives the address of the rewards coordinator.
32+
33+
It was previously called this way:
34+
``` Rust
35+
let el_chain_reader = ELChainReader::new(
36+
logger,
37+
SLASHER_ADDRESS,
38+
DELEGATION_MANAGER_ADDRESS,
39+
AVS_DIRECTORY_ADDRESS,
40+
provider_url,
41+
);
42+
```
43+
Now, it's called this way:
44+
``` Rust
45+
let el_chain_reader = ELChainReader::new(
46+
logger,
47+
SLASHER_ADDRESS,
48+
DELEGATION_MANAGER_ADDRESS,
49+
REWARDS_COORDINATOR,
50+
AVS_DIRECTORY_ADDRESS,
51+
provider_url,
52+
);
53+
```
54+
3055
### Removed
3156
* Removed homepage from testing-utils crate in [#266](https://github.com/Layr-Labs/eigensdk-rs/pull/266).
3257
* Removed changelog generation by release-plz in [#281](https://github.com/Layr-Labs/eigensdk-rs/pull/281).

crates/chainio/clients/avsregistry/src/writer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ impl AvsRegistryChainWriter {
100100

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

103+
// We set rewards coordinator address as zero because we are not going to use it on any writer operation
104+
let rewards_coordinator_addr = Address::ZERO;
105+
103106
let el_reader = ELChainReader::build(
104107
logger.clone(),
105108
delegation_manager_addr,
106109
avs_directory,
110+
rewards_coordinator_addr,
107111
&provider,
108112
)
109113
.await

crates/chainio/clients/elcontracts/src/reader.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use eigen_types::operator::Operator;
66
use eigen_utils::core::islasher::ISlasher;
77
use eigen_utils::core::{
88
avsdirectory::AVSDirectory, delegationmanager::DelegationManager, erc20::ERC20,
9-
istrategy::IStrategy, rewardscoordinator::RewardsCoordinator,
9+
irewardscoordinator::IRewardsCoordinator, istrategy::IStrategy,
1010
};
1111
#[derive(Debug, Clone)]
1212
pub struct ELChainReader {
1313
_logger: SharedLogger,
1414
slasher: Address,
1515
pub(crate) delegation_manager: Address,
1616
avs_directory: Address,
17+
rewards_coordinator: Address,
1718
pub provider: String,
1819
}
1920

@@ -35,13 +36,15 @@ impl ELChainReader {
3536
_logger: SharedLogger,
3637
slasher: Address,
3738
delegation_manager: Address,
39+
rewards_coordinator: Address,
3840
avs_directory: Address,
3941
provider: String,
4042
) -> Self {
4143
ELChainReader {
4244
_logger,
4345
slasher,
4446
delegation_manager,
47+
rewards_coordinator,
4548
avs_directory,
4649
provider,
4750
}
@@ -66,6 +69,7 @@ impl ELChainReader {
6669
_logger: SharedLogger,
6770
delegation_manager: Address,
6871
avs_directory: Address,
72+
rewards_coordinator: Address,
6973
client: &String,
7074
) -> Result<Self, ElContractsError> {
7175
let provider = get_provider(client);
@@ -85,6 +89,7 @@ impl ELChainReader {
8589
avs_directory,
8690
slasher: slasher_addr,
8791
delegation_manager,
92+
rewards_coordinator,
8893
provider: client.to_string(),
8994
})
9095
}
@@ -384,63 +389,65 @@ impl ELChainReader {
384389
Ok(is_operator_is)
385390
}
386391

387-
/// Get Operator Avs Split
392+
/// Gets the split of a specific `operator` for a specific `avs`
388393
///
389394
/// # Arguments
390395
///
391-
/// * `operator` - The operator's address
392-
/// * `avs` - The Avs 's address
396+
/// * `operator` - The operator address
397+
/// * `avs` - The AVS address
393398
///
394399
/// # Returns
395400
///
396-
/// * `u16` - the split for the specific operator for the specific avs
401+
/// * u16 - The split of the operator for the AVS, if the call is successful
397402
///
398403
/// # Errors
399404
///
400-
/// * `ElContractsError` - if the call to the contract fails
405+
/// * `ElContractsError` - if the call to the contract fails.
401406
pub async fn get_operator_avs_split(
402407
&self,
403408
operator: Address,
404409
avs: Address,
405410
) -> Result<u16, ElContractsError> {
406411
let provider = get_provider(&self.provider);
407412

408-
let contract_rewards_coordinator =
409-
RewardsCoordinator::new(self.delegation_manager, provider);
413+
let rewards_coordinator = IRewardsCoordinator::new(self.rewards_coordinator, provider);
410414

411-
Ok(contract_rewards_coordinator
415+
let operator_avs_split = rewards_coordinator
412416
.getOperatorAVSSplit(operator, avs)
413417
.call()
414418
.await
415419
.map_err(ElContractsError::AlloyContractError)?
416-
._0)
420+
._0;
421+
422+
Ok(operator_avs_split)
417423
}
418424

419-
/// Get Operator PI Split
425+
/// Gets the split of a specific `operator` for Programmatic Incentives
420426
///
421427
/// # Arguments
422428
///
423-
/// * `operator` - The operator's address
429+
/// * `operator` - The operator address
424430
///
425431
/// # Returns
426432
///
427-
/// * `u16` - The split for a specific `operator` for Programmatic Incentives
433+
/// * u16 - The split of the operator for PI, if the call is successful
428434
///
429435
/// # Errors
430436
///
431-
/// * `ElContractsError` - if the call to the contract fails
437+
/// * `ElContractsError` - if the call to the contract fails.
432438
pub async fn get_operator_pi_split(&self, operator: Address) -> Result<u16, ElContractsError> {
433439
let provider = get_provider(&self.provider);
434440

435-
let contract_rewards_coordinator =
436-
RewardsCoordinator::new(self.delegation_manager, provider);
441+
let rewards_coordinator = IRewardsCoordinator::new(self.rewards_coordinator, provider);
437442

438-
Ok(contract_rewards_coordinator
443+
let operator_pi_split = rewards_coordinator
439444
.getOperatorPISplit(operator)
440445
.call()
441446
.await
442447
.map_err(ElContractsError::AlloyContractError)?
443-
._0)
448+
._0;
449+
450+
Ok(operator_pi_split)
444451
}
445452
}
446453

@@ -451,6 +458,7 @@ mod tests {
451458
use alloy::providers::Provider;
452459
use alloy::{eips::eip1898::BlockNumberOrTag::Number, rpc::types::BlockTransactionsKind};
453460
use eigen_logging::get_test_logger;
461+
use eigen_testing_utils::anvil_constants::get_rewards_coordinator_address;
454462
use eigen_testing_utils::{
455463
anvil::start_anvil_container,
456464
anvil_constants::{
@@ -490,11 +498,14 @@ mod tests {
490498
let MockAvsServiceManager::avsDirectoryReturn {
491499
_0: avs_directory_address,
492500
} = avs_directory_address_return;
501+
let rewards_coordinator_address =
502+
get_rewards_coordinator_address(http_endpoint.clone()).await;
493503

494504
ELChainReader::new(
495505
get_test_logger(),
496506
slasher_address,
497507
delegation_manager_address,
508+
rewards_coordinator_address,
498509
avs_directory_address,
499510
http_endpoint,
500511
)

crates/chainio/clients/elcontracts/src/writer.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,15 @@ mod tests {
398398
let MockAvsServiceManager::avsDirectoryReturn {
399399
_0: avs_directory_address,
400400
} = avs_directory_address_return;
401+
let rewards_coordinator_address =
402+
get_rewards_coordinator_address(http_endpoint.clone()).await;
401403

402404
(
403405
ELChainReader::new(
404406
get_test_logger().clone(),
405407
slasher_address,
406408
delegation_manager_address,
409+
rewards_coordinator_address,
407410
avs_directory_address,
408411
http_endpoint,
409412
),
@@ -751,4 +754,106 @@ mod tests {
751754
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
752755
assert!(receipt.status());
753756
}
757+
#[tokio::test]
758+
async fn test_set_operator_avs_split_modified() {
759+
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
760+
let el_chain_writer = new_test_writer_with_private_key(
761+
http_endpoint.to_string(),
762+
ANVIL_FIRST_PRIVATE_KEY.to_string(),
763+
)
764+
.await;
765+
let new_split = 5;
766+
let avs_address = get_service_manager_address(http_endpoint.clone()).await;
767+
768+
let split = el_chain_writer
769+
.el_chain_reader
770+
.get_operator_avs_split(ANVIL_FIRST_ADDRESS, avs_address)
771+
.await
772+
.unwrap();
773+
774+
assert_eq!(split, 1000);
775+
776+
// Set the activation delay to zero so that the split change can be
777+
// processed right after setting it
778+
let signer = get_signer(ANVIL_FIRST_PRIVATE_KEY, &http_endpoint);
779+
let rewards_coordinator_address =
780+
get_rewards_coordinator_address(http_endpoint.to_string()).await;
781+
782+
let rewards_coordinator = IRewardsCoordinator::new(rewards_coordinator_address, &signer);
783+
let activation_delay = 0;
784+
let set_activation_delay = rewards_coordinator
785+
.setActivationDelay(activation_delay)
786+
.send()
787+
.await
788+
.unwrap();
789+
let receipt = set_activation_delay.get_receipt().await.unwrap();
790+
assert!(receipt.status());
791+
792+
let tx_hash = el_chain_writer
793+
.set_operator_avs_split(ANVIL_FIRST_ADDRESS, avs_address, new_split)
794+
.await
795+
.unwrap();
796+
797+
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
798+
assert!(receipt.status());
799+
800+
let split = el_chain_writer
801+
.el_chain_reader
802+
.get_operator_avs_split(ANVIL_FIRST_ADDRESS, avs_address)
803+
.await
804+
.unwrap();
805+
806+
assert_eq!(split, new_split);
807+
}
808+
809+
#[tokio::test]
810+
async fn test_set_operator_pi_split_modified() {
811+
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
812+
let el_chain_writer = new_test_writer_with_private_key(
813+
http_endpoint.to_string(),
814+
ANVIL_FIRST_PRIVATE_KEY.to_string(),
815+
)
816+
.await;
817+
let new_split = 5;
818+
819+
let split = el_chain_writer
820+
.el_chain_reader
821+
.get_operator_pi_split(ANVIL_FIRST_ADDRESS)
822+
.await
823+
.unwrap();
824+
825+
assert_eq!(split, 1000);
826+
827+
// Set the activation delay to zero so that the split change can be
828+
// processed right after setting it
829+
let signer = get_signer(ANVIL_FIRST_PRIVATE_KEY, &http_endpoint);
830+
let rewards_coordinator_address =
831+
get_rewards_coordinator_address(http_endpoint.to_string()).await;
832+
833+
let rewards_coordinator = IRewardsCoordinator::new(rewards_coordinator_address, &signer);
834+
let activation_delay = 0;
835+
let set_activation_delay = rewards_coordinator
836+
.setActivationDelay(activation_delay)
837+
.send()
838+
.await
839+
.unwrap();
840+
let receipt = set_activation_delay.get_receipt().await.unwrap();
841+
assert!(receipt.status());
842+
843+
let tx_hash = el_chain_writer
844+
.set_operator_pi_split(ANVIL_FIRST_ADDRESS, new_split)
845+
.await
846+
.unwrap();
847+
848+
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
849+
assert!(receipt.status());
850+
851+
let split = el_chain_writer
852+
.el_chain_reader
853+
.get_operator_pi_split(ANVIL_FIRST_ADDRESS)
854+
.await
855+
.unwrap();
856+
857+
assert_eq!(split, new_split);
858+
}
754859
}

crates/services/bls_aggregation/src/bls_agg_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub mod integration_test {
127127
)
128128
.await
129129
.unwrap();
130+
130131
let avs_writer = AvsRegistryChainWriter::build_avs_registry_chain_writer(
131132
get_test_logger(),
132133
http_endpoint.clone(),

crates/services/operatorsinfo/src/operatorsinfo_inmemory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ mod tests {
646646
get_test_logger(),
647647
Address::ZERO,
648648
delegation_manager_address,
649+
rewards_coordinator_address,
649650
avs_directory_address,
650651
http_endpoint.to_string(),
651652
);

examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ async fn main() -> Result<()> {
6464
get_test_logger().clone(),
6565
SLASHER_ADDRESS,
6666
DELEGATION_MANAGER_ADDRESS,
67+
REWARDS_COORDINATOR,
6768
AVS_DIRECTORY_ADDRESS,
6869
"https://ethereum-holesky.blockpi.network/v1/rpc/public".to_string(),
6970
);

examples/info-operator-service/examples/get_operator_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub async fn register_operator(pvt_key: &str, bls_key: &str, http_endpoint: &str
8383
get_test_logger(),
8484
Address::ZERO,
8585
delegation_manager_address,
86+
rewards_coordinator_address,
8687
avs_directory_address,
8788
http_endpoint.to_owned(),
8889
);

0 commit comments

Comments
 (0)