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: return operators ejected #228

Merged
merged 1 commit into from
Apr 16, 2024
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
12 changes: 10 additions & 2 deletions src/EjectionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,21 @@ contract EjectionManager is IEjectionManager, OwnableUpgradeable{
/**
* @notice Ejects operators from the AVSs RegistryCoordinator under a ratelimit
* @param _operatorIds The ids of the operators 'j' to eject for each quorum 'i'
* @return ejectedOperatorsForQuorum The total number of operators ejected for each quorum 'i'
* @dev This function will eject as many operators as possible without reverting prioritizing operators at the lower index
* @dev The owner can eject operators without recording of stake ejection
*/
function ejectOperators(bytes32[][] memory _operatorIds) external {
function ejectOperators(bytes32[][] memory _operatorIds) external returns (uint256[] memory){
require(isEjector[msg.sender] || msg.sender == owner(), "Ejector: Only owner or ejector can eject");

uint256[] memory ejectedOperatorsForQuorum = new uint256[](_operatorIds.length);

for(uint i = 0; i < _operatorIds.length; ++i) {
uint8 quorumNumber = uint8(i);

uint256 amountEjectable = amountEjectableForQuorum(quorumNumber);
uint256 stakeForEjection;
uint256 stakeForEjection;
uint256 ejectedOperators;

bool broke;
for(uint8 j = 0; j < _operatorIds[i].length; ++j) {
Expand All @@ -96,6 +100,7 @@ contract EjectionManager is IEjectionManager, OwnableUpgradeable{
abi.encodePacked(quorumNumber)
) {
stakeForEjection += operatorStake;
++ejectedOperators;
emit OperatorEjected(_operatorIds[i][j], quorumNumber);
} catch (bytes memory err) {
emit FailedOperatorEjection(_operatorIds[i][j], quorumNumber, err);
Expand All @@ -110,7 +115,10 @@ contract EjectionManager is IEjectionManager, OwnableUpgradeable{
}));
}

ejectedOperatorsForQuorum[i] = ejectedOperators;
}

return ejectedOperatorsForQuorum;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IEjectionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface IEjectionManager {
* @notice Ejects operators from the AVSs registryCoordinator under a ratelimit
* @param _operatorIds The ids of the operators to eject for each quorum
*/
function ejectOperators(bytes32[][] memory _operatorIds) external;
function ejectOperators(bytes32[][] memory _operatorIds) external returns (uint256[] memory);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late feedback: can we return uint32 instead? There won't be so many operators to eject


/**
* @notice Sets the ratelimit parameters for a quorum
Expand Down
48 changes: 40 additions & 8 deletions test/unit/EjectionManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject);
}

assertEq(uint8(registryCoordinator.getOperatorStatus(defaultOperator)), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
}
Expand Down Expand Up @@ -118,7 +122,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject);
}

for(uint8 i = 0; i < operatorsToEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down Expand Up @@ -152,7 +160,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsCanEject);
}

for(uint8 i = 0; i < operatorsCanEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down Expand Up @@ -189,7 +201,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject);
}

for(uint8 i = 0; i < operatorsToEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down Expand Up @@ -217,7 +233,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject);
}

for(uint8 i = 0; i < operatorsToEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, operatorsToEject + i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down Expand Up @@ -255,7 +275,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject);
}

for(uint8 i = 0; i < operatorsToEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down Expand Up @@ -288,7 +312,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(registryCoordinatorOwner);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject);
}

for(uint8 i = 0; i < operatorsToEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down Expand Up @@ -326,7 +354,11 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

cheats.prank(ejector);
ejectionManager.ejectOperators(operatorIds);
uint256[] memory ejectedOperatorsForQuorum = ejectionManager.ejectOperators(operatorIds);

for(uint8 i = 0; i < numQuorums; i++) {
assertEq(ejectedOperatorsForQuorum[i], operatorsToEject - 1);
}

for(uint8 i = 0; i < operatorsToEject; i++) {
assertEq(uint8(registryCoordinator.getOperatorStatus(_incrementAddress(defaultOperator, i))), uint8(IRegistryCoordinator.OperatorStatus.DEREGISTERED));
Expand Down
Loading