From d1bee94ebdbdc7e017a8096831fd25fad00ab931 Mon Sep 17 00:00:00 2001 From: amusingaxl <112016538+amusingaxl@users.noreply.github.com> Date: Fri, 17 May 2024 10:26:16 -0300 Subject: [PATCH] refactor: improve universal spells structure and comments --- src/clip-breaker/UniversalClipBreakerSpell.sol | 10 +++++----- src/osm-stop/UniversalOsmStopSpell.sol | 17 +++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/clip-breaker/UniversalClipBreakerSpell.sol b/src/clip-breaker/UniversalClipBreakerSpell.sol index c9dc5db..dc5b9d8 100644 --- a/src/clip-breaker/UniversalClipBreakerSpell.sol +++ b/src/clip-breaker/UniversalClipBreakerSpell.sol @@ -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); @@ -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); } } @@ -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; } } diff --git a/src/osm-stop/UniversalOsmStopSpell.sol b/src/osm-stop/UniversalOsmStopSpell.sol index 38bd4cd..4f1a1a8 100644 --- a/src/osm-stop/UniversalOsmStopSpell.sol +++ b/src/osm-stop/UniversalOsmStopSpell.sol @@ -30,9 +30,6 @@ interface OsmMomLike { interface OsmLike { function stopped() external view returns (uint256); -} - -interface WardsLike { function wards(address who) external view returns (uint256); } @@ -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); @@ -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); } } @@ -104,11 +101,11 @@ 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; } @@ -116,7 +113,7 @@ contract UniversalOsmStopSpell is DssEmergencySpell { // 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; } }