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: ejection policy change #313

Merged
merged 2 commits into from
Nov 13, 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
19 changes: 13 additions & 6 deletions src/EjectionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@ contract EjectionManager is IEjectionManager, OwnableUpgradeable{
quorumEjectionParams[quorumNumber].rateLimitWindow > 0 &&
stakeForEjection + operatorStake > amountEjectable
){
stakeEjectedForQuorum[quorumNumber].push(StakeEjection({
timestamp: block.timestamp,
stakeEjected: stakeForEjection
}));
ratelimitHit = true;

Copy link
Collaborator

Choose a reason for hiding this comment

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

In the above, if statement, it feels like we could simplify the logic flow by inverting the condition and pulling out the rateLimitWindow check to a guard clause

`

        uint32 numEjectedOperators;

        bool ratelimitHit;
        for(uint8 j = 0; j < _operatorIds[i].length; ++j) {
            uint256 operatorStake = stakeRegistry.getCurrentStake(_operatorIds[i][j], quorumNumber);
            if(quorumEjectionParams[quorumNumber].rateLimitWindow == 0) {
                break;
            }
            if (isEjector[msg.sender] && !ratelimitHit) {
                stakeForEjection += operatorStake;
                ++numEjectedOperators;
                registryCoordinator.ejectOperator(
                    registryCoordinator.getOperatorFromId(_operatorIds[i][j]),
                    abi.encodePacked(quorumNumber)
                );

                emit OperatorEjected(_operatorIds[i][j], quorumNumber);

                if (stakeForEjection > amountEjectable) {
                    stakeEjectedForQuorum[quorumNumber].push(StakeEjection({
                        timestamp: block.timestamp,
                        stakeEjected: stakeForEjection
                    }));
                    break;
                }
            }
        }

        emit QuorumEjection(numEjectedOperators, ratelimitHit);
    }

`

stakeForEjection += operatorStake;
++ejectedOperators;

registryCoordinator.ejectOperator(
registryCoordinator.getOperatorFromId(_operatorIds[i][j]),
abi.encodePacked(quorumNumber)
);

emit OperatorEjected(_operatorIds[i][j], quorumNumber);

break;
}

Expand All @@ -103,7 +110,7 @@ contract EjectionManager is IEjectionManager, OwnableUpgradeable{
}

//record the stake ejected if ejector and ratelimit enforced
if(!ratelimitHit && isEjector[msg.sender]){
if(isEjector[msg.sender]){
stakeEjectedForQuorum[quorumNumber].push(StakeEjection({
timestamp: block.timestamp,
stakeEjected: stakeForEjection
Expand Down Expand Up @@ -172,4 +179,4 @@ contract EjectionManager is IEjectionManager, OwnableUpgradeable{
}
return totalEjectable - totalEjected;
}
}
}
2 changes: 1 addition & 1 deletion src/interfaces/IEjectionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ interface IEjectionManager {
* @param _quorumNumber The quorum number to view ejectable stake for
*/
function amountEjectableForQuorum(uint8 _quorumNumber) external view returns (uint256);
}
}
4 changes: 2 additions & 2 deletions test/unit/EjectionManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
}

function testEjectOperators_MultipleOperatorOutsideRatelimit() public {
uint8 operatorsCanEject = 1;
uint8 operatorsCanEject = 2;
uint8 operatorsToEject = 10;
uint8 numOperators = 10;
uint96 stake = 1 ether;
Expand Down Expand Up @@ -396,4 +396,4 @@ contract EjectionManagerUnitTests is MockAVSDeployer {
_registerOperatorWithCoordinator(operator, MAX_QUORUM_BITMAP, pubKey, stake);
}
}
}
}
Loading