From dc20da1cea7d7f4b8ca8a3a005d69dc2265369c4 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 20 Sep 2023 15:38:23 +0200 Subject: [PATCH] feat(timelock): bypass timelock in favor of user --- src/MetaMorpho.sol | 24 ++++++++++++++---------- src/libraries/ErrorsLib.sol | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/MetaMorpho.sol b/src/MetaMorpho.sol index a7a57b76..27b40f4a 100644 --- a/src/MetaMorpho.sol +++ b/src/MetaMorpho.sol @@ -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. @@ -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. @@ -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)); @@ -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); } } diff --git a/src/libraries/ErrorsLib.sol b/src/libraries/ErrorsLib.sol index f21251ea..4b772819 100644 --- a/src/libraries/ErrorsLib.sol +++ b/src/libraries/ErrorsLib.sol @@ -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";