Skip to content

Commit

Permalink
refactor: improve universal spells structure and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amusingaxl committed May 17, 2024
1 parent 206c15c commit d1bee94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/clip-breaker/UniversalClipBreakerSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract UniversalClipBreakerSpell is DssEmergencySpell {

try ClipLike(clip).wards(address(clipperMom)) returns (uint256 ward) {
// Ignore Clip instances that have not relied on ClipperMom.
if (ward != 1) continue;
if (ward == 0) continue;
} catch Error(string memory reason) {
// If the reason is empty, it means the contract is most likely not a Clip instance.
require(bytes(reason).length == 0, reason);
Expand All @@ -88,7 +88,7 @@ contract UniversalClipBreakerSpell is DssEmergencySpell {
try clipperMom.setBreaker(clip, BREAKER_LEVEL, BREAKER_DELAY) {
emit SetBreaker(ilk, clip);
} catch Error(string memory reason) {
// Ignore any failing calls to `clipeprMom.setBreaker` with no revert reason.
// If the reason is empty, it means the contract is most likely not a Clip instance.
require(bytes(reason).length == 0, reason);
}
}
Expand All @@ -108,16 +108,16 @@ contract UniversalClipBreakerSpell is DssEmergencySpell {

try ClipLike(clip).wards(address(clipperMom)) returns (uint256 ward) {
// Ignore Clip instances that have not relied on ClipperMom.
if (ward != 1) continue;
if (ward == 0) continue;
} catch {
// Ignore any errors.
// If The call failed, it means the contract is most likely not a Clip instance, so it can be ignored.
continue;
}

try ClipLike(clip).stopped() returns (uint256 stopped) {
if (stopped != BREAKER_LEVEL) return false;
} catch {
// Ignore any errors.
// If the call failed, it means the contract is most likely not a Clip instance, so it can be ignored.
continue;
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/osm-stop/UniversalOsmStopSpell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ interface OsmMomLike {

interface OsmLike {
function stopped() external view returns (uint256);
}

interface WardsLike {
function wards(address who) external view returns (uint256);
}

Expand Down Expand Up @@ -75,9 +72,9 @@ contract UniversalOsmStopSpell is DssEmergencySpell {

if (osm == address(0)) continue;

try WardsLike(osm).wards(address(osmMom)) returns (uint256 ward) {
try OsmLike(osm).wards(address(osmMom)) returns (uint256 ward) {
// Ignore Osm instances that have not relied on OsmMom.
if (ward != 1) continue;
if (ward == 0) continue;
} catch Error(string memory reason) {
// If the reason is empty, it means the contract is most likely not an OSM instance.
require(bytes(reason).length == 0, reason);
Expand All @@ -87,7 +84,7 @@ contract UniversalOsmStopSpell is DssEmergencySpell {
try OsmMomLike(osmMom).stop(ilks[i]) {
emit Stop(ilks[i], osm);
} catch Error(string memory reason) {
// Ignore any failing calls to `osmMom.stop` with no revert reason.
// If the reason is empty, it means the contract is most likely not an OSM instance.
require(bytes(reason).length == 0, reason);
}
}
Expand All @@ -104,19 +101,19 @@ contract UniversalOsmStopSpell is DssEmergencySpell {

if (osm == address(0)) continue;

try WardsLike(osm).wards(address(osmMom)) returns (uint256 ward) {
try OsmLike(osm).wards(address(osmMom)) returns (uint256 ward) {
// Ignore Osm instances that have not relied on OsmMom.
if (ward != 1) continue;
if (ward == 0) continue;
} catch {
// Ignore any errors.
// If the call failed, it means the contract is most likely not an OSM instance, so it can be ignored.
continue;
}

try OsmLike(osm).stopped() returns (uint256 stopped) {
// If any of the OSMs that match the conditions is not stopped, the spell was not executed yet.
if (stopped == 0) return false;
} catch {
// Ignore any errors.
// If the call failed, it means the contract is most likely not an OSM instance, so it can be ignored.
continue;
}
}
Expand Down

0 comments on commit d1bee94

Please sign in to comment.