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

feat: add rewards-v2 related functionality #221

Merged
merged 9 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MIDDLEWARE_CONTRACTS_ARGS:=$(patsubst %, --select '^%$$', $(shell echo $(MIDDLEW


### Core bindings ###
CORE_CONTRACTS:="DelegationManager IRewardsCoordinator StrategyManager IEigenPod EigenPod IEigenPodManager EigenPodManager IStrategy AVSDirectory AllocationManager PermissionController"
CORE_CONTRACTS:="DelegationManager IRewardsCoordinator RewardsCoordinator StrategyManager IEigenPod EigenPod IEigenPodManager EigenPodManager IStrategy AVSDirectory AllocationManager PermissionController ERC20 Slasher ISlasher"
CORE_CONTRACTS_LOCATION:=$(MIDDLEWARE_CONTRACTS_LOCATION)/lib/eigenlayer-contracts
CORE_BINDINGS_PATH:=crates/utils/src/core
# The echo is to remove quotes, and the patsubst to make the regex match the full text only
Expand Down
4 changes: 2 additions & 2 deletions crates/chainio/clients/avsregistry/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use eigen_types::operator::{
bitmap_to_quorum_ids, bitmap_to_quorum_ids_from_u192, OperatorPubKeys,
};
use eigen_utils::{
deploy::stakeregistry::StakeRegistry, middleware::blsapkregistry::BLSApkRegistry,
middleware::blsapkregistry::BLSApkRegistry,
middleware::operatorstateretriever::OperatorStateRetriever,
middleware::registrycoordinator::RegistryCoordinator,
middleware::registrycoordinator::RegistryCoordinator, middleware::stakeregistry::StakeRegistry,
};

use num_bigint::BigInt;
Expand Down
69 changes: 64 additions & 5 deletions crates/chainio/clients/elcontracts/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use alloy_primitives::{Address, FixedBytes, U256};
use eigen_common::get_provider;
use eigen_logging::logger::SharedLogger;
use eigen_types::operator::Operator;
use eigen_utils::middleware::{
use eigen_utils::core::islasher::ISlasher;
use eigen_utils::core::{
avsdirectory::AVSDirectory, delegationmanager::DelegationManager, erc20::ERC20,
islasher::ISlasher, istrategy::IStrategy,
istrategy::IStrategy, rewardscoordinator::RewardsCoordinator,
};

#[derive(Debug, Clone)]
pub struct ELChainReader {
_logger: SharedLogger,
Expand Down Expand Up @@ -383,6 +383,65 @@ impl ELChainReader {
let DelegationManager::isOperatorReturn { _0: is_operator_is } = is_operator;
Ok(is_operator_is)
}

/// Get Operator Avs Split
///
/// # Arguments
///
/// * `operator` - The operator's address
/// * `avs` - The Avs 's address
///
/// # Returns
///
/// * `u16` - the split for the specific operator for the specific avs
///
/// # Errors
///
/// * `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);

Ok(contract_rewards_coordinator
.getOperatorAVSSplit(operator, avs)
.call()
.await
.map_err(ElContractsError::AlloyContractError)?
._0)
}

/// Get Operator PI Split
///
/// # Arguments
///
/// * `operator` - The operator's address
///
/// # Returns
///
/// * `u16` - The split for a specific `operator` for Programmatic Incentives
///
/// # Errors
///
/// * `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);

Ok(contract_rewards_coordinator
.getOperatorPISplit(operator)
.call()
.await
.map_err(ElContractsError::AlloyContractError)?
._0)
}
}

#[cfg(test)]
Expand All @@ -399,13 +458,13 @@ mod tests {
},
};
use eigen_utils::{
deploy::mockavsservicemanager::MockAvsServiceManager,
middleware::{
core::{
avsdirectory::AVSDirectory::{self, calculateOperatorAVSRegistrationDigestHashReturn},
delegationmanager::DelegationManager::{
self, calculateDelegationApprovalDigestHashReturn,
},
},
sdk::mockavsservicemanager::MockAvsServiceManager,
};
use std::str::FromStr;

Expand Down
115 changes: 110 additions & 5 deletions crates/chainio/clients/elcontracts/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::reader::ELChainReader;
use alloy_primitives::{Address, FixedBytes, TxHash, U256};
use eigen_common::get_signer;
pub use eigen_types::operator::Operator;
use eigen_utils::deploy::irewardscoordinator::IRewardsCoordinator::{self, RewardsMerkleClaim};
use eigen_utils::middleware::{
use eigen_utils::core::irewardscoordinator::IRewardsCoordinator::{self, RewardsMerkleClaim};
use eigen_utils::core::{
delegationmanager::{
DelegationManager::{self},
IDelegationManager::OperatorDetails,
Expand Down Expand Up @@ -250,6 +250,78 @@ impl ELChainWriter {
let tx = process_claim_call.send().await?;
Ok(*tx.tx_hash())
}

/// Set Operator Avs Split
/// Sets the split for a specific operator for a specific avs
/// Only callable by the operator
/// Split has to be between 0 and 10000 bips (inclusive)
/// The split will be activated after the activation delay
///
/// # Arguments
///
/// * `operator` - The operator who is setting the split
/// * `avs` - The avs for which the split is being set by the operator.
/// * `split` - The split for the operator for the specific avs in bips.
///
/// # Returns
///
/// * `Result<FixedBytes<32>, ElContractsError>` - The transaction hash if the claim is sent, otherwise an error.
///
/// # Errors
///
/// * `ElContractsError` - if the call to the contract fails.
pub async fn set_operator_avs_split(
&self,
operator: Address,
avs: Address,
split: u16,
) -> Result<FixedBytes<32>, ElContractsError> {
let provider = get_signer(&self.signer, &self.provider);

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

let set_operator_avs_split_call =
contract_rewards_coordinator.setOperatorAVSSplit(operator, avs, split);

let tx = set_operator_avs_split_call.send().await?;
Ok(*tx.tx_hash())
}

/// Set Operator PI Split
/// Sets the split for a specific operator for Programmatic Incentives.
/// Only callable by the operator
/// Split has to be between 0 and 10000 bips (inclusive)
/// The split will be activated after the activation delay
///
/// # Arguments
///
/// * `operator` - The operator on behalf of which the split is being set.
/// * `split` - The split for the operator for Programmatic Incentives in bips.
///
/// # Returns
///
/// * `Result<FixedBytes<32>, ElContractsError>` - The transaction hash if the claim is sent, otherwise an error.
///
/// # Errors
///
/// * `ElContractsError` - if the call to the contract fails.
pub async fn set_operator_pi_split(
&self,
operator: Address,
split: u16,
) -> Result<FixedBytes<32>, ElContractsError> {
let provider = get_signer(&self.signer, &self.provider);

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

let set_operator_pi_split_call =
contract_rewards_coordinator.setOperatorPISplit(operator, split);

let tx = set_operator_pi_split_call.send().await?;
Ok(*tx.tx_hash())
}
}

#[cfg(test)]
Expand All @@ -273,12 +345,14 @@ mod tests {
};
use eigen_types::operator::Operator;
use eigen_utils::{
deploy::{
contractsregistry::ContractsRegistry::{self, get_test_valuesReturn},
core::{
delegationmanager::DelegationManager,
irewardscoordinator::IRewardsCoordinator::{EarnerTreeMerkleLeaf, RewardsMerkleClaim},
},
sdk::{
contractsregistry::ContractsRegistry::{self, get_test_valuesReturn},
mockavsservicemanager::MockAvsServiceManager,
},
middleware::delegationmanager::DelegationManager,
};
use serial_test::serial;
use std::str::FromStr;
Expand Down Expand Up @@ -521,4 +595,35 @@ mod tests {
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
assert!(receipt.status());
}

#[tokio::test]
#[serial]
async fn test_set_operator_avs_split() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let el_chain_writer = new_test_writer(http_endpoint.clone()).await;
let operator = address!("90f79bf6eb2c4f870365e785982e1f101e93b906"); // derived from test private key in new_test_writer
let avs = get_service_manager_address(http_endpoint.clone()).await;
let split = 1000;
let tx_hash = el_chain_writer
.set_operator_avs_split(operator, avs, split)
.await
.unwrap();
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
assert!(receipt.status());
}

#[tokio::test]
#[serial]
async fn test_set_operator_pi_split() {
let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
let el_chain_writer = new_test_writer(http_endpoint.clone()).await;
let operator = address!("90f79bf6eb2c4f870365e785982e1f101e93b906"); // derived from test private key in new_test_writer
let split = 1000;
let tx_hash = el_chain_writer
.set_operator_pi_split(operator, split)
.await
.unwrap();
let receipt = wait_transaction(&http_endpoint, tx_hash).await.unwrap();
assert!(receipt.status());
}
}
2 changes: 1 addition & 1 deletion crates/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./" }]

via-ir = true
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion crates/contracts/lib/eigenlayer-middleware
Submodule eigenlayer-middleware updated 64 files
+0 −3 .gitmodules
+ audits/M2 Mainnet - Dedaub - Feb 2024.pdf
+ audits/Rewards v2 - SigmaPrime - Dec 2024.pdf
+2 −2 docs/README.md
+1 −1 docs/ServiceManagerBase.md
+1 −1 docs/experimental/AVS-Guide.md
+1 −0 foundry.toml
+0 −1 lib/ds-test
+1 −1 lib/eigenlayer-contracts
+1 −1 lib/forge-std
+8 −4 src/BLSApkRegistry.sol
+116 −62 src/BLSSignatureChecker.sol
+184 −0 src/EjectionManager.sol
+5 −1 src/IndexRegistry.sol
+33 −0 src/OperatorStateRetriever.sol
+87 −39 src/RegistryCoordinator.sol
+12 −2 src/RegistryCoordinatorStorage.sol
+192 −36 src/ServiceManagerBase.sol
+53 −0 src/ServiceManagerBaseStorage.sol
+3 −3 src/ServiceManagerRouter.sol
+52 −0 src/SocketRegistry.sol
+22 −10 src/StakeRegistry.sol
+24 −3 src/interfaces/IECDSAStakeRegistryEventsAndErrors.sol
+55 −0 src/interfaces/IEjectionManager.sol
+8 −0 src/interfaces/IRegistryCoordinator.sol
+37 −34 src/interfaces/IServiceManager.sol
+61 −0 src/interfaces/IServiceManagerUI.sol
+10 −0 src/interfaces/ISocketRegistry.sol
+0 −20 src/interfaces/ISocketUpdater.sol
+353 −0 src/unaudited/ECDSAServiceManagerBase.sol
+204 −75 src/unaudited/ECDSAStakeRegistry.sol
+10 −3 src/unaudited/ECDSAStakeRegistryStorage.sol
+14 −10 src/unaudited/examples/ECDSAStakeRegistryPermissioned.sol
+128 −0 test/events/IServiceManagerBaseEvents.sol
+1 −1 test/ffi/BLSPubKeyCompendiumFFI.t.sol
+3 −2 test/harnesses/RegistryCoordinatorHarness.t.sol
+7 −1 test/integration/CoreRegistration.t.sol
+129 −65 test/integration/IntegrationDeployer.t.sol
+1 −1 test/integration/TimeMachine.t.sol
+13 −11 test/integration/User.t.sol
+0 −63 test/integration/mocks/BeaconChainOracleMock.t.sol
+16 −15 test/integration/utils/Sort.t.sol
+7 −29 test/mocks/AVSDirectoryMock.sol
+27 −37 test/mocks/DelegationMock.sol
+22 −0 test/mocks/ECDSAServiceManagerMock.sol
+14 −0 test/mocks/ECDSAStakeRegistryMock.sol
+2 −0 test/mocks/RegistryCoordinatorMock.sol
+138 −0 test/mocks/RewardsCoordinatorMock.sol
+9 −3 test/mocks/ServiceManagerMock.sol
+369 −147 test/unit/BLSApkRegistryUnit.t.sol
+2 −1 test/unit/BLSSignatureCheckerUnit.t.sol
+1 −1 test/unit/BitmapUtils.t.sol
+186 −0 test/unit/ECDSAServiceManager.t.sol
+60 −14 test/unit/ECDSAStakeRegistryEqualWeightUnit.t.sol
+48 −16 test/unit/ECDSAStakeRegistryPermissionedUnit.t.sol
+472 −105 test/unit/ECDSAStakeRegistryUnit.t.sol
+448 −0 test/unit/EjectionManagerUnit.t.sol
+266 −110 test/unit/OperatorStateRetrieverUnit.t.sol
+85 −29 test/unit/RegistryCoordinatorUnit.t.sol
+1,082 −0 test/unit/ServiceManagerBase.t.sol
+1 −0 test/unit/ServiceManagerRouter.t.sol
+49 −0 test/unit/SocketRegistryUnit.t.sol
+822 −412 test/unit/StakeRegistryUnit.t.sol
+137 −90 test/utils/MockAVSDeployer.sol
7 changes: 5 additions & 2 deletions crates/contracts/script/DeployMockAvsRegistries.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/
import {IStrategyManager, IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {ISlasher} from "eigenlayer-contracts/src/contracts/interfaces/ISlasher.sol";
import "eigenlayer-contracts/src/test/mocks/EmptyContract.sol";

import {SocketRegistry} from "eigenlayer-middleware/src/SocketRegistry.sol";
import "eigenlayer-middleware/src/RegistryCoordinator.sol" as blsregcoord;
// import {ISocketRegistry} from "eigenlayer-middleware/src/interfaces/ISocketRegistry.sol";
import {IServiceManager} from "eigenlayer-middleware/src/interfaces/IServiceManager.sol";
import {IBLSApkRegistry, IIndexRegistry, IStakeRegistry} from "eigenlayer-middleware/src/RegistryCoordinator.sol";
import {BLSApkRegistry} from "eigenlayer-middleware/src/BLSApkRegistry.sol";
Expand Down Expand Up @@ -153,12 +154,14 @@ contract DeployMockAvsRegistries is
address(stakeRegistryImplementation)
);
}
address socketRegistry = address(new SocketRegistry(registryCoordinator));

registryCoordinatorImplementation = new blsregcoord.RegistryCoordinator(
blsregcoord.IServiceManager(address(mockAvsServiceManager)),
blsregcoord.IStakeRegistry(address(stakeRegistry)),
blsregcoord.IBLSApkRegistry(address(blsApkRegistry)),
blsregcoord.IIndexRegistry(address(indexRegistry))
blsregcoord.IIndexRegistry(address(indexRegistry)),
blsregcoord.ISocketRegistry(socketRegistry)
);

{
Expand Down
5 changes: 3 additions & 2 deletions crates/contracts/src/MockAvsServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ contract MockAvsServiceManager is ServiceManagerBase, BLSSignatureChecker {
)
ServiceManagerBase(
_avsDirectory,
_rewardsCoordinator,
_registryCoordinator,
_registryCoordinator.stakeRegistry()
)
BLSSignatureChecker(_registryCoordinator)
{}

function initialize(address _initialOwner) external initializer {
function initialize(address _initialOwner,address _rewardsInitiator) external initializer {
// TODO: setting _rewardsInitializer to be _initialOwner for now.
__ServiceManagerBase_init(_initialOwner);
__ServiceManagerBase_init(_initialOwner,_rewardsInitiator);
}
}
2 changes: 1 addition & 1 deletion crates/eigen-cli/src/eigen_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::primitives::Address;
use alloy::providers::Provider;
use eigen_common::get_provider;
use eigen_utils::{
middleware::delegationmanager::DelegationManager,
core::delegationmanager::DelegationManager,
middleware::iblssignaturechecker::IBLSSignatureChecker,
middleware::registrycoordinator::RegistryCoordinator,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ license-file.workspace = true

[dependencies]
alloy.workspace = true
reqwest.workspace = true
reqwest.workspace = true

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading