From 206c15c192e54b360007f9ede969333db7ae2ce8 Mon Sep 17 00:00:00 2001 From: amusingaxl <112016538+amusingaxl@users.noreply.github.com> Date: Fri, 17 May 2024 10:15:44 -0300 Subject: [PATCH] refactor: reorganize contracts and update natspec --- src/DssEmergencySpell.sol | 25 +++++++++++-------- .../SingleAutoLineWipeSpell.sol | 4 +-- src/clip-breaker/SingleClipBreakerSpell.sol | 12 ++++----- .../UniversalClipBreakerSpell.sol | 20 +++++++-------- src/osm-stop/SingleOsmStopSpell.sol | 4 +-- src/osm-stop/UniversalOsmStopSpell.sol | 14 +++++------ 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/DssEmergencySpell.sol b/src/DssEmergencySpell.sol index c4b7bf5..50e23a0 100644 --- a/src/DssEmergencySpell.sol +++ b/src/DssEmergencySpell.sol @@ -42,30 +42,33 @@ abstract contract DssEmergencySpell is DssEmergencySpellLike { uint256 public constant eta = 0; bytes public constant sig = ""; uint256 public constant expiration = type(uint256).max; + // @notice Office Hours is always `false` for emergency spells. + bool public constant officeHours = false; address public immutable action = address(this); bytes32 public immutable tag = keccak256(abi.encodePacked(address(this))); address public immutable pause = ChainlogLike(log).getAddress("MCD_PAUSE"); + uint256 public immutable nextCastTime = block.timestamp; - // @notice Office Hours is always `false` for emergency spells. - bool public constant officeHours = false; - - function nextCastTime() external virtual view returns (uint256) { - return block.timestamp; - } /** - * @notice Emergency spell are triggered when scheduled. - * @dev This function maintains the name for compatibility with regular spells, however nothing is actually being + * @notice Triggers the emergency actions of the spell. + * @dev Emergency spells are triggered when scheduled. + * This function maintains the name for compatibility with regular spells, however nothing is actually being * scheduled. Emergency spell take affect immediately, so there is no need to call `pause.plot()`. */ function schedule() external { _emeregencyActions(); } - function _emeregencyActions() internal virtual; - /** - * @notice This function is a no-op. It exists only to keep interface compatibility with regular spells. + * @notice No-op. + * @dev this function exists only to keep interface compatibility with regular spells. */ function cast() external {} + + /** + * @notice Implements the emergency actions to be triggered by the spell. + */ + function _emeregencyActions() internal virtual; + } diff --git a/src/auto-line-wipe/SingleAutoLineWipeSpell.sol b/src/auto-line-wipe/SingleAutoLineWipeSpell.sol index a52490c..c652247 100644 --- a/src/auto-line-wipe/SingleAutoLineWipeSpell.sol +++ b/src/auto-line-wipe/SingleAutoLineWipeSpell.sol @@ -49,8 +49,8 @@ contract SingleAutoLineWipeSpell is DssEmergencySpell { } /** - * @notice Return whether the spell is done or not. - * @dev Check if the ilk has been wiped from auto-line. + * @notice Returns whether the spell is done or not. + * @dev Checks if the ilk has been wiped from auto-line. */ function done() external view returns (bool) { (uint256 maxLine, uint256 gap, uint48 ttl, uint48 last, uint48 lastInc) = diff --git a/src/clip-breaker/SingleClipBreakerSpell.sol b/src/clip-breaker/SingleClipBreakerSpell.sol index 5fb80d9..4f66c3a 100644 --- a/src/clip-breaker/SingleClipBreakerSpell.sol +++ b/src/clip-breaker/SingleClipBreakerSpell.sol @@ -30,13 +30,13 @@ interface IlkRegistryLike { } contract SingleClipBreakerSpell is DssEmergencySpell { - ClipperMomLike public immutable clipperMom = ClipperMomLike(_log.getAddress("CLIPPER_MOM")); - IlkRegistryLike public immutable ilkReg = IlkRegistryLike(_log.getAddress("ILK_REGISTRY")); - + /// @dev During an emergency, set the breaker level to 3 to prevent botyh `kick()`, `redo()` and `take()`. uint256 public constant BREAKER_LEVEL = 3; - // For level 3 breakers, the delay is not applicable, so we set it to zero. + /// @dev The delay is not applicable for level 3 breakers, so we set it to zero. uint256 public constant BREAKER_DELAY = 0; + ClipperMomLike public immutable clipperMom = ClipperMomLike(_log.getAddress("CLIPPER_MOM")); + IlkRegistryLike public immutable ilkReg = IlkRegistryLike(_log.getAddress("ILK_REGISTRY")); bytes32 public immutable ilk; event SetBreaker(address indexed clip); @@ -56,8 +56,8 @@ contract SingleClipBreakerSpell is DssEmergencySpell { } /** - * @notice Return whether the spell is done or not. - * @dev Check if the Clip instance has stopped = 3. + * @notice Returns whether the spell is done or not. + * @dev Checks if the Clip instance has stopped = 3. */ function done() external view returns (bool) { return ClipLike(ilkReg.xlip(ilk)).stopped() == BREAKER_LEVEL; diff --git a/src/clip-breaker/UniversalClipBreakerSpell.sol b/src/clip-breaker/UniversalClipBreakerSpell.sol index 726e5ef..c9dc5db 100644 --- a/src/clip-breaker/UniversalClipBreakerSpell.sol +++ b/src/clip-breaker/UniversalClipBreakerSpell.sol @@ -34,19 +34,19 @@ interface ClipLike { } contract UniversalClipBreakerSpell is DssEmergencySpell { - IlkRegistryLike public immutable ilkReg = IlkRegistryLike(_log.getAddress("ILK_REGISTRY")); - ClipperMomLike public immutable clipperMom = ClipperMomLike(_log.getAddress("CLIPPER_MOM")); - string public constant override description = "Emergency Spell | Universal Clip Breaker"; - + /// @dev During an emergency, set the breaker level to 3 to prevent botyh `kick()`, `redo()` and `take()`. uint256 public constant BREAKER_LEVEL = 3; - // For level 3 breakers, the delay is not applicable, so we set it to zero. + /// @dev The delay is not applicable for level 3 breakers, so we set it to zero. uint256 public constant BREAKER_DELAY = 0; + IlkRegistryLike public immutable ilkReg = IlkRegistryLike(_log.getAddress("ILK_REGISTRY")); + ClipperMomLike public immutable clipperMom = ClipperMomLike(_log.getAddress("CLIPPER_MOM")); + event SetBreaker(bytes32 indexed ilk, address indexed clip); /** - * @notice Set breakers, when possible, for all Clip instances that can be found in the ilk registry. + * @notice Sets breakers, when possible, for all Clip instances that can be found in the ilk registry. */ function _emeregencyActions() internal override { bytes32[] memory ilks = ilkReg.list(); @@ -54,7 +54,7 @@ contract UniversalClipBreakerSpell is DssEmergencySpell { } /** - * @notice Set breakers for all Clips in the batch. + * @notice Sets breakers for all Clips in the batch. * @dev This is an escape hatch to prevent this spell from being blocked in case it would hit the block gas limit. * In case `end` is greater than the ilk registry length, the iteration will be automatically capped. * @param start The index to start the iteration (inclusive). @@ -67,7 +67,7 @@ contract UniversalClipBreakerSpell is DssEmergencySpell { } /** - * @notice Set breakers, when possible, for all Clip instances that can be found from the `ilks` list. + * @notice Sets breakers, when possible, for all Clip instances that can be found from the `ilks` list. * @param ilks The list of ilks to consider. */ function _doSetBreaker(bytes32[] memory ilks) internal { @@ -95,8 +95,8 @@ contract UniversalClipBreakerSpell is DssEmergencySpell { } /** - * @notice Return whether the spell is done or not. - * @dev Check if all possible Clip instances from the ilk registry have stopped = 3. + * @notice Returns whether the spell is done or not. + * @dev Checks if all possible Clip instances from the ilk registry have stopped = 3. */ function done() external view returns (bool) { bytes32[] memory ilks = ilkReg.list(); diff --git a/src/osm-stop/SingleOsmStopSpell.sol b/src/osm-stop/SingleOsmStopSpell.sol index 0afa4ea..c8a6d5e 100644 --- a/src/osm-stop/SingleOsmStopSpell.sol +++ b/src/osm-stop/SingleOsmStopSpell.sol @@ -46,8 +46,8 @@ contract SingleOsmStopSpell is DssEmergencySpell { } /** - * @notice Return whether the spell is done or not. - * @dev Check if the OSM instance is stopped. + * @notice Returns whether the spell is done or not. + * @dev Checks if the OSM instance is stopped. */ function done() external view returns (bool) { return OsmLike(osmMom.osms(ilk)).stopped() == 1; diff --git a/src/osm-stop/UniversalOsmStopSpell.sol b/src/osm-stop/UniversalOsmStopSpell.sol index ffedf48..38bd4cd 100644 --- a/src/osm-stop/UniversalOsmStopSpell.sol +++ b/src/osm-stop/UniversalOsmStopSpell.sol @@ -37,15 +37,15 @@ interface WardsLike { } contract UniversalOsmStopSpell is DssEmergencySpell { + string public constant override description = "Emergency Spell | Universal OSM Stop"; + IlkRegistryLike public immutable ilkReg = IlkRegistryLike(_log.getAddress("ILK_REGISTRY")); OsmMomLike public immutable osmMom = OsmMomLike(_log.getAddress("OSM_MOM")); - string public constant override description = "Emergency Spell | Universal OSM Stop"; - event Stop(bytes32 indexed ilk, address indexed osm); /** - * @notice Stop, when possible, all OSMs that can be found through the ilk registry. + * @notice Stops, when possible, all OSMs that can be found through the ilk registry. */ function _emeregencyActions() internal override { bytes32[] memory ilks = ilkReg.list(); @@ -53,7 +53,7 @@ contract UniversalOsmStopSpell is DssEmergencySpell { } /** - * @notice Stop all OSMs in the batch. + * @notice Stops all OSMs in the batch. * @dev This is an escape hatch to prevent this spell from being blocked in case it would hit the block gas limit. * In case `end` is greater than the ilk registry length, the iteration will be automatically capped. * @param start The index to start the iteration (inclusive). @@ -66,7 +66,7 @@ contract UniversalOsmStopSpell is DssEmergencySpell { } /** - * @notice Stop, when possible, all OSMs that can be found from the `ilks` list. + * @notice Stops, when possible, all OSMs that can be found from the `ilks` list. * @param ilks The list of ilks to consider. */ function _doStop(bytes32[] memory ilks) internal { @@ -94,8 +94,8 @@ contract UniversalOsmStopSpell is DssEmergencySpell { } /** - * @notice Return whether the spell is done or not. - * @dev Check if all possible OSM instances from the ilk registry are stopped. + * @notice Returns whether the spell is done or not. + * @dev Checks if all possible OSM instances from the ilk registry are stopped. */ function done() external view returns (bool) { bytes32[] memory ilks = ilkReg.list();