Skip to content

Commit

Permalink
Merge pull request #1 from lidofinance/feat/set-limits-and-proxy-eoa-…
Browse files Browse the repository at this point in the history
…checks-1

feat: val limits for modules
  • Loading branch information
AlexandrMov authored Dec 19, 2024
2 parents 185d5fd + f3e9af0 commit b510662
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
forge-std/=lib/forge-std/src/
2 changes: 1 addition & 1 deletion script/CuratorCheck.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract CuratorCheckScript is Script {
function run() public {
vm.startBroadcast();

address _curatorAddress = 0x71d75C9A9e1a4fFa5a16556b51D6e630A4FA902A;
address _curatorAddress = 0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519;
Curator _curator = Curator(_curatorAddress);

_curator.optIn(0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f, 1, 2, 400, 450);
Expand Down
27 changes: 27 additions & 0 deletions src/Curator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ contract Curator {
uint256 keysRangeEnd;
}

uint256 public constant DEFAULT_MAX_VALIDATORS = 1000; // Default max validators if not set explicitly

address public immutable stakingRouterAddress;
address public immutable managerAddress;

mapping(address => RegisteredOperator) public operators;
mapping(uint256 => uint256) public maxValidatorsForModule;

modifier onlyOwner() {
require(msg.sender == managerAddress, "Not the owner");
_;
}

constructor(address _stakingRouterAddress, address _managerAddress) {
stakingRouterAddress = _stakingRouterAddress;
Expand All @@ -72,6 +80,8 @@ contract Curator {
address operatorRewardAddress =
_checkOperatorAndGetRewardAddress(module, moduleId, operatorId, keysRangeStart, keysRangeEnd);

_checkMaxValidators(moduleId, keysRangeStart, keysRangeEnd);

// @todo Uncomment when we create test node operator in 3rd module
/*if (msg.sender != operatorRewardAddress) {
revert RewardAddressMismatch(msg.sender, operatorId, operatorRewardAddress);
Expand Down Expand Up @@ -130,6 +140,8 @@ contract Curator {

_checkOperatorId(module, msg.sender, moduleId, operatorId);

_checkMaxValidators(moduleId, newKeysRangeStart, newKeysRangeEnd);

address operatorRewardAddress =
_checkOperatorAndGetRewardAddress(module, moduleId, operatorId, newKeysRangeStart, newKeysRangeEnd);

Expand All @@ -146,6 +158,21 @@ contract Curator {
operators[operatorRewardAddress].keysRangeEnd = newKeysRangeEnd;
}

function setMaxValidatorsForStakingModule(uint256 moduleId, uint256 maxValidators) external onlyOwner {
require(moduleId > 0, "Invalid module ID");
require(maxValidators > 0, "Max validators must be greater than 0");

maxValidatorsForModule[moduleId] = maxValidators;
}

function _checkMaxValidators(uint256 moduleId, uint256 keysRangeStart, uint256 keysRangeEnd) internal {
uint256 totalKeys = keysRangeEnd - keysRangeStart + 1;
uint256 maxValidators =
maxValidatorsForModule[moduleId] == 0 ? DEFAULT_MAX_VALIDATORS : maxValidatorsForModule[moduleId];

require(totalKeys <= maxValidators, "Validator limit exceeded for module");
}

function _checkModuleId(IStakingRouter router, address sender, uint256 moduleId) internal {
uint256 modulesCount = router.getStakingModulesCount();

Expand Down

0 comments on commit b510662

Please sign in to comment.