Skip to content

Commit

Permalink
feat(timelock): bypass timelock in favor of user
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Sep 20, 2023
1 parent 7ec2667 commit dc20da1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ contract MetaMorpho is ERC4626, Ownable2Step, IMetaMorpho {
}

function submitTimelock(uint256 newTimelock) external onlyOwner {
require(newTimelock != timelock, ErrorsLib.ALREADY_SET);
require(newTimelock <= MAX_TIMELOCK, ErrorsLib.MAX_TIMELOCK_EXCEEDED);
require(newTimelock != timelock, ErrorsLib.ALREADY_SET);

if (timelock == 0) {
if (newTimelock > timelock || timelock == 0) {
_setTimelock(newTimelock);
} else {
// Safe "unchecked" cast because newTimelock <= MAX_TIMELOCK.
Expand All @@ -142,10 +142,10 @@ contract MetaMorpho is ERC4626, Ownable2Step, IMetaMorpho {
}

function submitFee(uint256 newFee) external onlyOwner {
require(newFee != fee, ErrorsLib.ALREADY_SET);
require(newFee <= WAD, ErrorsLib.MAX_FEE_EXCEEDED);
require(newFee != fee, ErrorsLib.ALREADY_SET);

if (newFee == 0 || timelock == 0) {
if (newFee < fee || timelock == 0) {
_setFee(newFee);
} else {
// Safe "unchecked" cast because newFee <= WAD.
Expand Down Expand Up @@ -174,9 +174,10 @@ contract MetaMorpho is ERC4626, Ownable2Step, IMetaMorpho {
}

function submitGuardian(address newGuardian) external onlyOwner {
require(timelock != 0, ErrorsLib.NO_TIMELOCK);
require(newGuardian != guardian, ErrorsLib.ALREADY_SET);

if (timelock == 0) {
if (guardian == address(0)) {
_setGuardian(newGuardian);
} else {
pendingGuardian = PendingAddress(newGuardian, uint64(block.timestamp));
Expand All @@ -191,18 +192,21 @@ contract MetaMorpho is ERC4626, Ownable2Step, IMetaMorpho {

/* ONLY RISK MANAGER FUNCTIONS */

function submitCap(MarketParams memory marketParams, uint256 marketCap) external onlyRiskManager {
function submitCap(MarketParams memory marketParams, uint256 newMarketCap) external onlyRiskManager {
require(marketParams.borrowableToken == asset(), ErrorsLib.INCONSISTENT_ASSET);

Id id = marketParams.id();
require(MORPHO.lastUpdate(id) != 0, ErrorsLib.MARKET_NOT_CREATED);

if (marketCap == 0 || timelock == 0) {
_setCap(id, marketCap.toUint192());
uint256 marketCap = config[id].cap;
require(newMarketCap != marketCap, ErrorsLib.ALREADY_SET);

if (newMarketCap < marketCap || timelock == 0) {
_setCap(id, newMarketCap.toUint192());
} else {
pendingCap[id] = PendingUint192(marketCap.toUint192(), uint64(block.timestamp));
pendingCap[id] = PendingUint192(newMarketCap.toUint192(), uint64(block.timestamp));

emit EventsLib.SubmitCap(msg.sender, id, marketCap);
emit EventsLib.SubmitCap(msg.sender, id, newMarketCap);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ library ErrorsLib {
/// @notice Thrown when the value is already set.
string internal constant ALREADY_SET = "already set";

string internal constant NO_TIMELOCK = "no timelock";

string internal constant DUPLICATE_MARKET = "duplicate market";

string internal constant MISSING_MARKET = "missing market";
Expand Down

0 comments on commit dc20da1

Please sign in to comment.