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: val limits for modules #1

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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
25 changes: 25 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 @@ -146,6 +156,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
Loading