From ccfd256789f01f25a2a99cb3a0f681c170a20fdf Mon Sep 17 00:00:00 2001 From: Carter Carlson Date: Tue, 17 Oct 2023 10:49:35 -0700 Subject: [PATCH] refactor: optimize modifiers --- src/ERC20/ERC20PermitPermissionedMint.sol | 14 +++++++++++--- src/OperatorRegistry.sol | 7 ++++++- src/sfrxETH.sol | 7 ++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/ERC20/ERC20PermitPermissionedMint.sol b/src/ERC20/ERC20PermitPermissionedMint.sol index 3bed26d..1b2518c 100644 --- a/src/ERC20/ERC20PermitPermissionedMint.sol +++ b/src/ERC20/ERC20PermitPermissionedMint.sol @@ -38,14 +38,22 @@ contract ERC20PermitPermissionedMint is ERC20Permit, ERC20Burnable, Owned { /* ========== MODIFIERS ========== */ modifier onlyByOwnGov() { - require(msg.sender == timelock_address || msg.sender == owner, "Not owner or timelock"); + _onlyByOwnGov(); _; } + function _onlyByOwnGov() private view { + require(msg.sender == timelock_address || msg.sender == owner, "Not owner or timelock"); + } + modifier onlyMinters() { - require(minters[msg.sender] == true, "Only minters"); + _onlyMinters(); _; - } + } + + function _onlyMinters() private view { + require(minters[msg.sender] == true, "Only minters"); + } /* ========== RESTRICTED FUNCTIONS ========== */ diff --git a/src/OperatorRegistry.sol b/src/OperatorRegistry.sol index f81094c..e826d5c 100644 --- a/src/OperatorRegistry.sol +++ b/src/OperatorRegistry.sol @@ -20,6 +20,7 @@ pragma solidity ^0.8.0; // Reviewer(s) / Contributor(s) // Travis Moore: https://github.com/FortisFortuna // Dennis: https://github.com/denett +// Carter Carlson: https://github.com/pegahcarter import "./Utils/Owned.sol"; @@ -43,10 +44,14 @@ contract OperatorRegistry is Owned { } modifier onlyByOwnGov() { - require(msg.sender == timelock_address || msg.sender == owner, "Not owner or timelock"); + _onlyByOwnGov(); _; } + function _onlyByOwnGov() private view { + require(msg.sender == timelock_address || msg.sender == owner, "Not owner or timelock"); + } + /// @notice Add a new validator /** @dev You should verify offchain that the validator is indeed valid before adding it Reason we don't do that here is for gas */ diff --git a/src/sfrxETH.sol b/src/sfrxETH.sol index 5ca119d..cf025c6 100644 --- a/src/sfrxETH.sol +++ b/src/sfrxETH.sol @@ -22,6 +22,7 @@ pragma solidity ^0.8.0; // Dennett: https://github.com/denett // Travis Moore: https://github.com/FortisFortuna // Jamie Turley: https://github.com/jyturley +// Carter Carlson: https://github.com/pegahcarter import { ERC20, ERC4626, xERC4626 } from "ERC4626/xERC4626.sol"; import "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; @@ -40,10 +41,14 @@ import "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; contract sfrxETH is xERC4626, ReentrancyGuard { modifier andSync { - if (block.timestamp >= rewardsCycleEnd) { syncRewards(); } + _andSync(); _; } + function _andSync() private { + if (block.timestamp >= rewardsCycleEnd) { syncRewards(); } + } + /* ========== CONSTRUCTOR ========== */ constructor(ERC20 _underlying, uint32 _rewardsCycleLength) ERC4626(_underlying, "Staked Frax Ether", "sfrxETH")