Skip to content

Commit

Permalink
Refactor AllowListOperatorManager
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Jan 31, 2024
1 parent 61b2fbd commit ecc926b
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/zkbob/manager/AllowListOperatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ contract AllowListOperatorManager is IOperatorManager, Ownable {
}

constructor(address[] memory _operators, address[] memory _feeReceivers, bool _allowListEnabled) Ownable() {
require(_operators.length == _feeReceivers.length, "OperatorManager: arrays length mismatch");

allowListEnabled = _allowListEnabled;
bool[] memory _allowed = new bool[](_operators.length);
for (uint256 i = 0; i < _operators.length; i++) {
_allowed[i] = true;
_setOperator(_operators[i], true, _feeReceivers[i]);
}
_setOperators(_operators, _allowed, _feeReceivers);
}

/**
Expand Down Expand Up @@ -77,7 +77,12 @@ contract AllowListOperatorManager is IOperatorManager, Ownable {
external
onlyOwner
{
_setOperators(_operators, _allowed, _feeReceivers);
require(_operators.length == _feeReceivers.length, "OperatorManager: arrays length mismatch");
require(_operators.length == _allowed.length, "OperatorManager: arrays length mismatch");

for (uint256 i = 0; i < _operators.length; i++) {
_setOperator(_operators[i], _allowed[i], _feeReceivers[i]);
}
}

/**
Expand All @@ -90,24 +95,9 @@ contract AllowListOperatorManager is IOperatorManager, Ownable {
emit UpdateOperator(msg.sender, _feeReceiver, true);
}

function _setOperators(
address[] memory _operators,
bool[] memory _allowed,
address[] memory _feeReceivers
)
internal
{
require(_operators.length == _feeReceivers.length, "OperatorManager: arrays length mismatch");
require(_operators.length == _allowed.length, "OperatorManager: arrays length mismatch");

for (uint256 i = 0; i < _operators.length; i++) {
_setOperator(_operators[i], _allowed[i], _feeReceivers[i]);
}
}

function _setOperator(address _operator, bool _allowed, address _feeReceiver) internal nonZeroAddress(_operator) {
operators[_operator] = _allowed;
if (_feeReceiver != address(0) && _allowed) {
if (_allowed) {
operatorFeeReceiver[_operator] = _feeReceiver;
}
emit UpdateOperator(_operator, operatorFeeReceiver[_operator], _allowed);
Expand Down

0 comments on commit ecc926b

Please sign in to comment.