Skip to content

Commit d473b84

Browse files
committed
feat: refactor access control so there is only one onlyTrusted mapping
1 parent f9e9a5f commit d473b84

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

contracts/helpers/BaseHarvester.sol

+22-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,20 @@ abstract contract BaseHarvester is IHarvester, AccessControl {
3535
MODIFIERS
3636
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
3737

38-
modifier onlyAllowedOrGuardian() {
39-
if (!isAllowed[msg.sender] && !accessControlManager.isGovernorOrGuardian(msg.sender)) revert NotTrusted();
38+
/**
39+
* @notice Checks whether the `msg.sender` is trusted to update target exposure and do others non critical operations
40+
*/
41+
modifier onlyTrusted() {
42+
if (!isTrusted[msg.sender]) revert NotTrusted();
43+
_;
44+
}
45+
46+
/**
47+
* @notice Checks whether the `msg.sender` is trusted or guardian to update target exposure and do others non critical operations
48+
*/
49+
modifier onlyTrustedOrGuardian() {
50+
if (!isTrusted[msg.sender] && !accessControlManager.isGovernorOrGuardian(msg.sender))
51+
revert NotTrustedOrGuardian();
4052
_;
4153
}
4254

@@ -52,8 +64,8 @@ abstract contract BaseHarvester is IHarvester, AccessControl {
5264
uint96 public maxSlippage;
5365
/// @notice Data associated to a yield bearing asset
5466
mapping(address => YieldBearingParams) public yieldBearingData;
55-
/// @notice Whether an address is allowed to update the target exposure of a yield bearing asset
56-
mapping(address => bool) public isAllowed;
67+
/// @notice trusted addresses that can update target exposure and do others non critical operations
68+
mapping(address => bool) public isTrusted;
5769

5870
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5971
CONSTRUCTOR
@@ -121,23 +133,23 @@ abstract contract BaseHarvester is IHarvester, AccessControl {
121133
}
122134

123135
/**
124-
* @notice add an address to the allowed list
125-
* @param account address to be added
136+
* @notice Toggle the trusted status of an address
137+
* @param trusted address to toggle the trusted status
126138
*/
127-
function toggleAllowed(address account) external onlyGuardian {
128-
isAllowed[account] = !isAllowed[account];
139+
function toggleTrusted(address trusted) external onlyGuardian {
140+
isTrusted[trusted] = !isTrusted[trusted];
129141
}
130142

131143
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132-
ALLOWED FUNCTIONS
144+
TRUSTED FUNCTIONS
133145
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
134146

135147
/**
136148
* @notice Set the target exposure of a yield bearing asset
137149
* @param yieldBearingAsset address of the yield bearing asset
138150
* @param targetExposure target exposure to the yield bearing asset used
139151
*/
140-
function setTargetExposure(address yieldBearingAsset, uint64 targetExposure) external onlyAllowedOrGuardian {
152+
function setTargetExposure(address yieldBearingAsset, uint64 targetExposure) external onlyTrustedOrGuardian {
141153
yieldBearingData[yieldBearingAsset].targetExposure = targetExposure;
142154
}
143155

contracts/helpers/MultiBlockHarvester.sol

-19
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,12 @@ import "../utils/Constants.sol";
2020
contract MultiBlockHarvester is BaseHarvester {
2121
using SafeERC20 for IERC20;
2222

23-
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24-
MODIFIERS
25-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
26-
27-
modifier onlyTrusted() {
28-
if (!isTrusted[msg.sender]) revert NotTrusted();
29-
_;
30-
}
31-
3223
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3324
VARIABLES
3425
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
3526

3627
/// @notice address to deposit to receive yieldBearingAsset
3728
mapping(address => address) public yieldBearingToDepositAddress;
38-
/// @notice trusted addresses
39-
mapping(address => bool) public isTrusted;
4029

4130
/// @notice Maximum amount of stablecoins that can be minted in a single transaction
4231
uint256 public maxMintAmount;
@@ -83,14 +72,6 @@ contract MultiBlockHarvester is BaseHarvester {
8372
yieldBearingToDepositAddress[yieldBearingAsset] = newDepositAddress;
8473
}
8574

86-
/**
87-
* @notice Toggle the trusted status of an address
88-
* @param trusted address to toggle the trusted status
89-
*/
90-
function toggleTrusted(address trusted) external onlyGuardian {
91-
isTrusted[trusted] = !isTrusted[trusted];
92-
}
93-
9475
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9576
TRUSTED FUNCTIONS
9677
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

contracts/utils/Errors.sol

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ error NotCollateral();
3131
error NotGovernor();
3232
error NotGovernorOrGuardian();
3333
error NotTrusted();
34+
error NotTrustedOrGuardian();
3435
error NotWhitelisted();
3536
error OneInchSwapFailed();
3637
error OracleUpdateFailed();

0 commit comments

Comments
 (0)