From 32dd47af427a37f6e1629c0daf5a5db190ea8915 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Fri, 3 Nov 2023 10:33:03 +0100 Subject: [PATCH 1/2] refactor(revoke): rename revoke functions --- src/MetaMorpho.sol | 18 +++++++++--------- src/interfaces/IMetaMorpho.sol | 6 +++--- src/libraries/EventsLib.sol | 12 ++++++------ test/forge/GuardianTest.sol | 24 ++++++++++++------------ test/metamorpho_tests.tree | 12 ++++++------ 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/MetaMorpho.sol b/src/MetaMorpho.sol index c5b714ea..824f04a3 100644 --- a/src/MetaMorpho.sol +++ b/src/MetaMorpho.sol @@ -399,24 +399,24 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph /* ONLY GUARDIAN FUNCTIONS */ /// @notice Revokes the `pendingTimelock`. - function revokeTimelock() external onlyGuardian { - emit EventsLib.RevokeTimelock(_msgSender(), pendingTimelock); - + function revokePendingTimelock() external onlyGuardian { delete pendingTimelock; + + emit EventsLib.RevokePendingTimelock(_msgSender()); } /// @notice Revokes the `pendingGuardian`. - function revokeGuardian() external onlyGuardian { - emit EventsLib.RevokeGuardian(_msgSender(), pendingGuardian); - + function revokePendingGuardian() external onlyGuardian { delete pendingGuardian; + + emit EventsLib.RevokePendingGuardian(_msgSender()); } /// @notice Revokes the pending cap of the market defined by `id`. - function revokeCap(Id id) external onlyGuardian { - emit EventsLib.RevokeCap(_msgSender(), id, pendingCap[id]); - + function revokePendingCap(Id id) external onlyGuardian { delete pendingCap[id]; + + emit EventsLib.RevokePendingCap(_msgSender(), id); } /* EXTERNAL */ diff --git a/src/interfaces/IMetaMorpho.sol b/src/interfaces/IMetaMorpho.sol index 99ce58b6..b69f1e71 100644 --- a/src/interfaces/IMetaMorpho.sol +++ b/src/interfaces/IMetaMorpho.sol @@ -57,12 +57,12 @@ interface IMetaMorpho is IERC4626 { function submitTimelock(uint256 newTimelock) external; function acceptTimelock() external; - function revokeTimelock() external; + function revokePendingTimelock() external; function pendingTimelock() external view returns (uint192 value, uint64 submittedAt); function submitCap(MarketParams memory marketParams, uint256 supplyCap) external; function acceptCap(Id id) external; - function revokeCap(Id id) external; + function revokePendingCap(Id id) external; function pendingCap(Id) external view returns (uint192 value, uint64 submittedAt); function submitFee(uint256 newFee) external; @@ -71,7 +71,7 @@ interface IMetaMorpho is IERC4626 { function submitGuardian(address newGuardian) external; function acceptGuardian() external; - function revokeGuardian() external; + function revokePendingGuardian() external; function pendingGuardian() external view returns (address guardian, uint96 submittedAt); function transferRewards(address) external; diff --git a/src/libraries/EventsLib.sol b/src/libraries/EventsLib.sol index fceea864..f00a3265 100644 --- a/src/libraries/EventsLib.sol +++ b/src/libraries/EventsLib.sol @@ -48,14 +48,14 @@ library EventsLib { /// @notice Emitted when an `allocator` is set to `isAllocator`. event SetIsAllocator(address indexed allocator, bool isAllocator); - /// @notice Emitted when a `pendingTimelock` is revoked by `guardian`. - event RevokeTimelock(address indexed guardian, PendingUint192 pendingTimelock); + /// @notice Emitted when the pending timelock is revoked by `guardian`. + event RevokePendingTimelock(address indexed guardian); - /// @notice Emitted when a `pendingCap` for the market identified by `id` is revoked by `guardian`. - event RevokeCap(address indexed guardian, Id indexed id, PendingUint192 pendingCap); + /// @notice Emitted when the pending cap of a market identified by `id` is revoked by `guardian`. + event RevokePendingCap(address indexed guardian, Id indexed id); - /// @notice Emitted when a `pendingGuardian` is revoked by `guardian`. - event RevokeGuardian(address indexed guardian, PendingAddress pendingGuardian); + /// @notice Emitted when the pending guardian is revoked by `guardian`. + event RevokePendingGuardian(address indexed guardian); /// @notice Emitted when the `supplyQgueue` is set to `newSupplyQueue`. event SetSupplyQueue(address indexed allocator, Id[] newSupplyQueue); diff --git a/test/forge/GuardianTest.sol b/test/forge/GuardianTest.sol index 4e6a8a2d..ea917401 100644 --- a/test/forge/GuardianTest.sol +++ b/test/forge/GuardianTest.sol @@ -28,7 +28,7 @@ contract GuardianTest is IntegrationTest { vault.submitGuardian(GUARDIAN); } - function testRevokeTimelockDecreased(uint256 timelock, uint256 elapsed) public { + function testRevokePendingTimelockDecreased(uint256 timelock, uint256 elapsed) public { timelock = bound(timelock, ConstantsLib.MIN_TIMELOCK, TIMELOCK - 1); elapsed = bound(elapsed, 0, TIMELOCK - 1); @@ -37,10 +37,10 @@ contract GuardianTest is IntegrationTest { vm.warp(block.timestamp + elapsed); - vm.expectEmit(); - emit EventsLib.RevokeTimelock(GUARDIAN, IPending(address(vault)).pendingTimelock()); + vm.expectEmit(address(vault)); + emit EventsLib.RevokePendingTimelock(GUARDIAN); vm.prank(GUARDIAN); - vault.revokeTimelock(); + vault.revokePendingTimelock(); uint256 newTimelock = vault.timelock(); (uint256 pendingTimelock, uint64 submittedAt) = vault.pendingTimelock(); @@ -50,7 +50,7 @@ contract GuardianTest is IntegrationTest { assertEq(submittedAt, 0, "submittedAt"); } - function testRevokeCapIncreased(uint256 seed, uint256 cap, uint256 elapsed) public { + function testRevokePendingCapIncreased(uint256 seed, uint256 cap, uint256 elapsed) public { MarketParams memory marketParams = _randomMarketParams(seed); elapsed = bound(elapsed, 0, TIMELOCK - 1); cap = bound(cap, 1, type(uint192).max); @@ -62,10 +62,10 @@ contract GuardianTest is IntegrationTest { Id id = marketParams.id(); - vm.expectEmit(); - emit EventsLib.RevokeCap(GUARDIAN, id, IPending(address(vault)).pendingCap(id)); + vm.expectEmit(address(vault)); + emit EventsLib.RevokePendingCap(GUARDIAN, id); vm.prank(GUARDIAN); - vault.revokeCap(id); + vault.revokePendingCap(id); (uint192 newCap, uint64 withdrawRank) = vault.config(id); (uint256 pendingCap, uint64 submittedAt) = vault.pendingCap(id); @@ -76,7 +76,7 @@ contract GuardianTest is IntegrationTest { assertEq(submittedAt, 0, "submittedAt"); } - function testRevokeGuardian(uint256 elapsed) public { + function testRevokePendingGuardian(uint256 elapsed) public { elapsed = bound(elapsed, 0, TIMELOCK - 1); address guardian = makeAddr("Guardian2"); @@ -86,10 +86,10 @@ contract GuardianTest is IntegrationTest { vm.warp(block.timestamp + elapsed); - vm.expectEmit(); - emit EventsLib.RevokeGuardian(GUARDIAN, IPending(address(vault)).pendingGuardian()); + vm.expectEmit(address(vault)); + emit EventsLib.RevokePendingGuardian(GUARDIAN); vm.prank(GUARDIAN); - vault.revokeGuardian(); + vault.revokePendingGuardian(); address newGuardian = vault.guardian(); (address pendingGuardian, uint96 submittedAt) = vault.pendingGuardian(); diff --git a/test/metamorpho_tests.tree b/test/metamorpho_tests.tree index c5f1ff0f..1bafd921 100644 --- a/test/metamorpho_tests.tree +++ b/test/metamorpho_tests.tree @@ -289,27 +289,27 @@ . -└── revokeTimelock() external +└── revokePendingTimelock() external ├── when msg.sender not guardian │ └── revert with NotGuardian() └── when msg.sender is guardian - ├── it should emit RevokeTimelock(msg.sender, pendingTimelock) + ├── it should emit RevokePendingTimelock(msg.sender, pendingTimelock) └── it should delete pendingTimelock . -└── revokeCap(Id id) external +└── revokePendingCap(Id id) external ├── when msg.sender not guardian │ └── revert with NotGuardian() └── when msg.sender is guardian - ├── it should emit RevokeCap(msg.sender, id, pendingCap[id]) + ├── it should emit RevokePendingCap(msg.sender, id, pendingCap[id]) └── it should delete pendingCap[id] . -└── revokeGuardian() external +└── revokePendingGuardian() external ├── when msg.sender not guardian │ └── revert with NotGuardian() └── when msg.sender is guardian - ├── it should emit RevokeGuardian(msg.sender, pendingGuardian); + ├── it should emit RevokePendingGuardian(msg.sender, pendingGuardian); └── it should delete pendingGuardian From a662428227520812eec0c0fcd4e37af1c980304e Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Sat, 4 Nov 2023 19:00:34 +0300 Subject: [PATCH 2/2] test: udpate tree --- test/metamorpho_tests.tree | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/metamorpho_tests.tree b/test/metamorpho_tests.tree index 9a848e3d..83470710 100644 --- a/test/metamorpho_tests.tree +++ b/test/metamorpho_tests.tree @@ -283,7 +283,7 @@ ├── when msg.sender not guardian │ └── revert with NotGuardian() └── when msg.sender is guardian - ├── it should emit RevokePendingTimelock(msg.sender, pendingTimelock) + ├── it should emit RevokePendingTimelock(msg.sender) └── it should delete pendingTimelock . @@ -291,7 +291,7 @@ ├── when msg.sender not guardian │ └── revert with NotGuardian() └── when msg.sender is guardian - ├── it should emit RevokePendingCap(msg.sender, id, pendingCap[id]) + ├── it should emit RevokePendingCap(msg.sender, id) └── it should delete pendingCap[id] . @@ -299,7 +299,7 @@ ├── when msg.sender not guardian │ └── revert with NotGuardian() └── when msg.sender is guardian - ├── it should emit RevokePendingGuardian(msg.sender, pendingGuardian); + ├── it should emit RevokePendingGuardian(msg.sender); └── it should delete pendingGuardian