Skip to content

Commit

Permalink
Merge pull request #277 from Gearbox-protocol/spearbit-19
Browse files Browse the repository at this point in the history
fix: minor stylistic fixes
  • Loading branch information
lekhovitsky authored Sep 1, 2024
2 parents b87c124 + e26c2c8 commit 7050142
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 78 deletions.
14 changes: 7 additions & 7 deletions contracts/core/GearStakingV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ contract GearStakingV3 is IGearStakingV3, Ownable, ReentrancyGuardTrait, SanityC
mapping(address => WithdrawalData) internal withdrawalData;

/// @notice Mapping from address to its status as allowed voting contract
mapping(address => VotingContractStatus) public allowedVotingContract;
mapping(address => VotingContractStatus) public override allowedVotingContract;

/// @notice Address of a new staking contract that can be migrated to
address public override successor;

/// @notice Address of the previous staking contract that is migrated from
address public override migrator;

/// @dev Ensures that function is called by migrator
modifier migratorOnly() {
if (msg.sender != migrator) revert CallerNotMigratorException();
_;
}

/// @notice Constructor
/// @param owner_ Contract owner
/// @param gear_ GEAR token address
Expand All @@ -64,12 +70,6 @@ contract GearStakingV3 is IGearStakingV3, Ownable, ReentrancyGuardTrait, SanityC
transferOwnership(owner_); // U:[GS-1]
}

/// @dev Ensures that function is called by migrator
modifier migratorOnly() {
if (msg.sender != migrator) revert CallerNotMigratorException();
_;
}

/// @notice Stakes given amount of GEAR, and, optionally, performs a sequence of votes
/// @param amount Amount of GEAR to stake
/// @param votes Sequence of votes to perform, see `MultiVote`
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/PriceOracleV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract PriceOracleV3 is ACLNonReentrantTrait, PriceFeedValidationTrait, IPrice

/// @notice Applies on-demand price feed updates, see `PriceUpdate` for details
/// @custom:tests U:[PO-5]
function updatePrices(PriceUpdate[] calldata updates) external {
function updatePrices(PriceUpdate[] calldata updates) external override {
unchecked {
uint256 len = updates.length;
for (uint256 i; i < len; ++i) {
Expand Down
14 changes: 7 additions & 7 deletions contracts/credit/CreditAccountV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ contract CreditAccountV3 is ICreditAccountV3 {
_;
}

/// @dev Reverts if `msg.sender` is not credit manager
function _revertIfNotCreditManager() internal view {
if (msg.sender != creditManager) {
revert CallerNotCreditManagerException();
}
}

/// @notice Constructor
/// @param _creditManager Credit manager to connect this account to
constructor(address _creditManager) {
Expand Down Expand Up @@ -91,4 +84,11 @@ contract CreditAccountV3 is ICreditAccountV3 {
{
target.functionCall(data); // U:[CA-5]
}

/// @dev Reverts if `msg.sender` is not credit manager
function _revertIfNotCreditManager() internal view {
if (msg.sender != creditManager) {
revert CallerNotCreditManagerException();
}
}
}
4 changes: 2 additions & 2 deletions contracts/credit/CreditFacadeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait {
/// @notice Maximum amount that can be borrowed by a credit manager in a single block, as a multiple of `maxDebt`
uint8 public override maxDebtPerBlockMultiplier = DEFAULT_LIMIT_PER_BLOCK_MULTIPLIER;

/// @notice Last block when underlying was borrowed by a credit manager
/// @dev Last block when underlying was borrowed by a credit manager
uint64 internal lastBlockBorrowed;

/// @notice The total amount borrowed by a credit manager in `lastBlockBorrowed`
/// @dev The total amount borrowed by a credit manager in `lastBlockBorrowed`
uint128 internal totalBorrowedInBlock;

/// @notice Bot list address
Expand Down
12 changes: 6 additions & 6 deletions contracts/pool/GaugeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ contract GaugeV3 is IGaugeV3, ACLNonReentrantTrait {
/// @notice Whether gauge is frozen and rates cannot be updated
bool public override epochFrozen;

/// @dev Ensures that function caller is voter
modifier onlyVoter() {
_revertIfCallerNotVoter(); // U:[GA-2]
_;
}

/// @notice Constructor
/// @param _pool Address of the lending pool
/// @param _gearStaking Address of the GEAR staking contract
Expand All @@ -65,12 +71,6 @@ contract GaugeV3 is IGaugeV3, ACLNonReentrantTrait {
emit SetFrozenEpoch(true); // U:[GA-1]
}

/// @dev Ensures that function caller is voter
modifier onlyVoter() {
_revertIfCallerNotVoter(); // U:[GA-2]
_;
}

/// @notice Updates the epoch and, unless frozen, rates in the quota keeper
function updateEpoch() external override {
_checkAndUpdateEpoch(); // U:[GA-14]
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool/PoolQuotaKeeperV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract PoolQuotaKeeperV3 is IPoolQuotaKeeperV3, ACLNonReentrantTrait, Contract
/// @dev The list of all quoted tokens
EnumerableSet.AddressSet internal quotaTokensSet;

/// @notice Mapping from token to global token quota params
/// @dev Mapping from token to global token quota params
mapping(address => TokenQuotaParams) internal totalQuotaParams;

/// @dev Mapping from (creditAccount, token) to account's token quota params
Expand Down
12 changes: 6 additions & 6 deletions contracts/pool/PoolV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ contract PoolV3 is ERC4626, ERC20Permit, ACLNonReentrantTrait, ContractsRegister
_;
}

function _revertIfCallerIsNotPoolQuotaKeeper() internal view {
if (msg.sender != poolQuotaKeeper) revert CallerNotPoolQuotaKeeperException(); // U:[LP-2C]
}

/// @notice Constructor
/// @param acl_ ACL contract address
/// @param contractsRegister_ Contracts register address
Expand Down Expand Up @@ -279,8 +275,8 @@ contract PoolV3 is ERC4626, ERC20Permit, ACLNonReentrantTrait, ContractsRegister
}

/// @notice Number of pool shares that would be minted on depositing `assets`
function previewDeposit(uint256 assets) public view override(ERC4626, IERC4626) returns (uint256 shares) {
shares = _convertToShares(_amountMinusFee(assets), Math.Rounding.Down); // U:[LP-10]
function previewDeposit(uint256 assets) public view override(ERC4626, IERC4626) returns (uint256) {
return _convertToShares(_amountMinusFee(assets), Math.Rounding.Down); // U:[LP-10]
}

/// @notice Amount of underlying that would be spent to mint `shares`
Expand Down Expand Up @@ -799,4 +795,8 @@ contract PoolV3 is ERC4626, ERC20Permit, ACLNonReentrantTrait, ContractsRegister
function _convertToU128(uint256 limit) internal pure returns (uint128) {
return (limit == type(uint256).max) ? type(uint128).max : limit.toUint128();
}

function _revertIfCallerIsNotPoolQuotaKeeper() internal view {
if (msg.sender != poolQuotaKeeper) revert CallerNotPoolQuotaKeeperException(); // U:[LP-2C]
}
}
50 changes: 20 additions & 30 deletions contracts/traits/ACLNonReentrantTrait.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,18 @@ abstract contract ACLNonReentrantTrait is ACLTrait, Pausable, ReentrancyGuardTra
_;
}

/// @dev Reverts if the caller is not controller or configurator
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsControllerOrConfigurator() internal view {
if (msg.sender != controller && !_isConfigurator({account: msg.sender})) {
revert CallerNotControllerOrConfiguratorException();
}
}

/// @dev Ensures that function caller has pausable admin role
modifier pausableAdminsOnly() {
_ensureCallerIsPausableAdmin();
_;
}

/// @dev Reverts if the caller is not pausable admin
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsPausableAdmin() internal view {
if (!_isPausableAdmin({account: msg.sender})) {
revert CallerNotPausableAdminException();
}
}

/// @dev Ensures that function caller has unpausable admin role
modifier unpausableAdminsOnly() {
_ensureCallerIsUnpausableAdmin();
_;
}

/// @dev Reverts if the caller is not unpausable admin
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsUnpausableAdmin() internal view {
if (!_isUnpausableAdmin({account: msg.sender})) {
revert CallerNotUnpausableAdminException();
}
}

/// @notice Constructor
/// @param acl ACL contract address
constructor(address acl) ACLTrait(acl) {}
Expand All @@ -90,13 +66,27 @@ abstract contract ACLNonReentrantTrait is ACLTrait, Pausable, ReentrancyGuardTra
emit NewController(newController);
}

/// @dev Checks whether given account has pausable admin role
function _isPausableAdmin(address account) internal view returns (bool) {
return IACL(acl).isPausableAdmin(account);
/// @dev Reverts if the caller is not controller or configurator
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsControllerOrConfigurator() internal view {
if (msg.sender != controller && !_isConfigurator(msg.sender)) {
revert CallerNotControllerOrConfiguratorException();
}
}

/// @dev Checks whether given account has unpausable admin role
function _isUnpausableAdmin(address account) internal view returns (bool) {
return IACL(acl).isUnpausableAdmin(account);
/// @dev Reverts if the caller is not pausable admin
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsPausableAdmin() internal view {
if (!IACL(acl).isPausableAdmin(msg.sender)) {
revert CallerNotPausableAdminException();
}
}

/// @dev Reverts if the caller is not unpausable admin
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsUnpausableAdmin() internal view {
if (!IACL(acl).isUnpausableAdmin(msg.sender)) {
revert CallerNotUnpausableAdminException();
}
}
}
12 changes: 6 additions & 6 deletions contracts/traits/ACLTrait.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ abstract contract ACLTrait is SanityCheckTrait {
/// @notice ACL contract address
address public immutable acl;

/// @notice Constructor
/// @param _acl ACL contract address
constructor(address _acl) nonZeroAddress(_acl) {
acl = _acl;
}

/// @dev Ensures that function caller has configurator role
modifier configuratorOnly() {
_ensureCallerIsConfigurator();
_;
}

/// @notice Constructor
/// @param _acl ACL contract address
constructor(address _acl) nonZeroAddress(_acl) {
acl = _acl;
}

/// @dev Reverts if the caller is not the configurator
/// @dev Used to cut contract size on modifiers
function _ensureCallerIsConfigurator() internal view {
Expand Down
14 changes: 2 additions & 12 deletions contracts/traits/ContractsRegisterTrait.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,11 @@ abstract contract ContractsRegisterTrait is SanityCheckTrait {

/// @dev Ensures that given address is a registered pool
function _ensureRegisteredPool(address addr) internal view {
if (!_isRegisteredPool(addr)) revert RegisteredPoolOnlyException();
if (!IContractsRegister(contractsRegister).isPool(addr)) revert RegisteredPoolOnlyException();
}

/// @dev Ensures that given address is a registered credit manager
function _ensureRegisteredCreditManager(address addr) internal view {
if (!_isRegisteredCreditManager(addr)) revert RegisteredCreditManagerOnlyException();
}

/// @dev Whether given address is a registered pool
function _isRegisteredPool(address addr) internal view returns (bool) {
return IContractsRegister(contractsRegister).isPool(addr);
}

/// @dev Whether given address is a registered credit manager
function _isRegisteredCreditManager(address addr) internal view returns (bool) {
return IContractsRegister(contractsRegister).isCreditManager(addr);
if (!IContractsRegister(contractsRegister).isCreditManager(addr)) revert RegisteredCreditManagerOnlyException();
}
}

0 comments on commit 7050142

Please sign in to comment.