Skip to content

Commit

Permalink
remove redundant modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Korokhov committed May 21, 2024
1 parent 1c786c1 commit 97c4944
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 40 deletions.
52 changes: 20 additions & 32 deletions src/contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,6 @@ contract Vault is

mapping(address operator => mapping(address network => Limit limit)) private _operatorLimit;

modifier isNetwork(address account) {
if (!IRegistry(NETWORK_REGISTRY).isEntity(account)) {
revert NotNetwork();
}
_;
}

modifier onlyNetwork() {
if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) {
revert NotNetwork();
}
_;
}

modifier onlyNetworkMiddleware(address network) {
if (IMiddlewarePlugin(NETWORK_MIDDLEWARE_PLUGIN).middleware(network) != msg.sender) {
revert NotNetworkMiddleware();
}
_;
}

modifier onlyOperator() {
if (!IRegistry(OPERATOR_REGISTRY).isEntity(msg.sender)) {
revert NotOperator();
}
_;
}

constructor(
address networkRegistry,
address operatorRegistry,
Expand Down Expand Up @@ -533,7 +505,11 @@ contract Vault is
address resolver,
address operator,
uint256 amount
) external onlyNetworkMiddleware(network) returns (uint256 slashIndex) {
) external returns (uint256 slashIndex) {
if (IMiddlewarePlugin(NETWORK_MIDDLEWARE_PLUGIN).middleware(network) != msg.sender) {
revert NotNetworkMiddleware();
}

uint256 maxSlash_ = maxSlash(network, resolver, operator);

if (amount == 0 || maxSlash_ == 0) {
Expand Down Expand Up @@ -679,7 +655,11 @@ contract Vault is
/**
* @inheritdoc IVault
*/
function optInNetwork(address resolver, uint256 maxNetworkLimit_) external onlyNetwork {
function optInNetwork(address resolver, uint256 maxNetworkLimit_) external {
if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) {
revert NotNetwork();
}

if (isNetworkOptedIn[msg.sender][resolver]) {
revert NetworkAlreadyOptedIn();
}
Expand Down Expand Up @@ -721,7 +701,11 @@ contract Vault is
/**
* @inheritdoc IVault
*/
function optInOperator() external onlyOperator {
function optInOperator() external {
if (!IRegistry(OPERATOR_REGISTRY).isEntity(msg.sender)) {
revert NotOperator();
}

if (isOperatorOptedIn(msg.sender)) {
revert OperatorAlreadyOptedIn();
}
Expand Down Expand Up @@ -756,7 +740,11 @@ contract Vault is
address token,
uint256 amount,
uint48 timestamp
) external nonReentrant isNetwork(network) returns (uint256 rewardIndex) {
) external nonReentrant returns (uint256 rewardIndex) {
if (!IRegistry(NETWORK_REGISTRY).isEntity(network)) {
revert NotNetwork();
}

if (timestamp >= clock()) {
revert InvalidRewardTimestamp();
}
Expand Down
13 changes: 5 additions & 8 deletions src/contracts/plugins/NetworkOptInPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,18 @@ contract NetworkOptInPlugin is Plugin, ERC6372, INetworkOptInPlugin {
*/
mapping(address operator => mapping(address network => uint48 timestamp)) public lastOperatorOptOut;

modifier isNetwork(address network) {
if (!IRegistry(NETWORK_REGISTRY).isEntity(network)) {
revert NotNetwork();
}
_;
}

constructor(address operatorRegistry, address networkRegistry) Plugin(operatorRegistry) {
NETWORK_REGISTRY = networkRegistry;
}

/**
* @inheritdoc INetworkOptInPlugin
*/
function optIn(address network) external onlyEntity isNetwork(network) {
function optIn(address network) external onlyEntity {
if (!IRegistry(NETWORK_REGISTRY).isEntity(network)) {
revert NotNetwork();
}

if (isOperatorOptedIn[msg.sender][network]) {
revert OperatorAlreadyOptedIn();
}
Expand Down

0 comments on commit 97c4944

Please sign in to comment.