Skip to content

Commit

Permalink
refactor: reorganize contracts and update natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
amusingaxl committed May 17, 2024
1 parent 7cd769c commit 206c15c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
25 changes: 14 additions & 11 deletions src/DssEmergencySpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
4 changes: 2 additions & 2 deletions src/auto-line-wipe/SingleAutoLineWipeSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
12 changes: 6 additions & 6 deletions src/clip-breaker/SingleClipBreakerSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/clip-breaker/UniversalClipBreakerSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ 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();
_doSetBreaker(ilks);
}

/**
* @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).
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/osm-stop/SingleOsmStopSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/osm-stop/UniversalOsmStopSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ 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();
_doStop(ilks);
}

/**
* @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).
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 206c15c

Please sign in to comment.