Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolicyEnabler mix-in #40

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

PolicyEnabler mix-in #40

wants to merge 8 commits into from

Conversation

0xJem
Copy link
Collaborator

@0xJem 0xJem commented Feb 4, 2025

Adds an abstract contract, PolicyEnabler, that can be added to contracts that require the ability to be enabled/disabled. Most policies implement this functionality every time, so this mix-in standardizes the approach and role.

@0xJem 0xJem self-assigned this Feb 4, 2025
Copy link

github-actions bot commented Feb 4, 2025

LCOV of commit 3ec98ae during CI #149

Summary coverage rate:
  lines......: 69.4% (1365 of 1966 lines)
  functions..: 72.2% (296 of 410 functions)
  branches...: no data found

Files changed coverage rate: n/a

src/libraries/Enableable.sol Outdated Show resolved Hide resolved
src/libraries/Enableable.sol Outdated Show resolved Hide resolved
src/libraries/Enableable.sol Outdated Show resolved Hide resolved
/// 5. Emits the `Enabled` event
///
/// @param enableData_ The data to pass to the implementation-specific `_enable()` function
function enable(bytes calldata enableData_) public onlyRole(ROLE) whenDisabled {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is can be pulled into all policies - I wonder if it'd be worth reducing bytecode by having a toggleIsEnabled() instead of distinct enable and disable functions?

The modifier could be also be a single:

    modifier whenEnabledIs(bool condition) {
        if (isEnabled == condition) revert IsEnabledNotMatching(condition);
        _;
    }

Tradeoff with being explicit - so don't mind, just throwing it out there (MonoCooler is kinda chunky which is why i bring up)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that the simplicity would be lost, and it also adds ambiguity.

e.g. the whenEnabledIs(bool condition) modifier you shared is reverting if isEnabled == condition, but I would have interpreted it the other way - whenEnabledIs(true) would revert if isEnabled != true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally fair and agree, thought i'd just throw it in the mix.

@0xJem 0xJem changed the title Enableable mix-in PolicyEnabler mix-in Feb 5, 2025
@0xJem 0xJem requested review from Oighty and frontier159 February 6, 2025 08:26
@frontier159
Copy link

LGTM. So the next question is what functions do we add this modifier to on MonoCooler...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants