Skip to main content

EnablerV2

Git Source

Inherits: IEnablerV2, ERC165

Title: EnablerV2

An abstract base contract that implements IEnablerV2 and exposes authorization and lifecycle hooks for inheriting contracts.

The contract is agnostic to the access control model used by the implementation. Inheriting contracts must override _authorizeEnable and _authorizeDisable to revert when the caller is not permitted to perform the requested transition, and may override _beforeEnable and _beforeDisable to perform implementation-specific state changes alongside the transition.

The legacy IEnabler surface is preserved: enable and disable retain their selectors and payload semantics, and the Enabled and Disabled events are emitted in addition to the new Transition event on every successful transition. Storage layout is intentionally compact: isEnabled and lastTransitionAt share a single slot.

State Variables​

isEnabled​

Returns true if the contract is enabled

The flag is initialized to false at construction time, so a freshly deployed contract always starts in the disabled state and must be explicitly enabled before its gated functionality becomes available.

bool public override isEnabled;

Returns

NameTypeDescription
<none>boolTrue if the contract is enabled, false otherwise

lastTransitionAt​

Returns the timestamp of the most recent transition between the enabled and disabled states.

The value remains zero until the first successful enable, after which it tracks the timestamp of the most recent transition. The field is packed into the same storage slot as isEnabled.

uint48 public override lastTransitionAt;

Returns

NameTypeDescription
<none>uint48The timestamp of the most recent transition, or zero before the first enable.

Functions​

enable​

On success, the contract is moved to the enabled state, lastTransitionAt is updated to the current timestamp, and both the legacy Enabled event and the Transition event are emitted.

Reverts if:

  • The contract is currently enabled.
  • _authorizeEnable rejects the caller.
  • _beforeEnable reverts.
function enable(bytes calldata data_) public virtual override givenDisabled;

Parameters

NameTypeDescription
data_bytesOptional data to pass to a custom enable function

disable​

On success, the contract is moved to the disabled state, lastTransitionAt is updated to the current timestamp, and both the legacy Disabled event and the Transition event are emitted.

Reverts if:

  • The contract is currently disabled.
  • _authorizeDisable rejects the caller.
  • _beforeDisable reverts.
function disable(bytes calldata data_) public virtual override givenEnabled;

Parameters

NameTypeDescription
data_bytesOptional data to pass to a custom disable function

_authorizeEnable​

Validates that the caller is permitted to enable the contract.

The function is invoked from enable before any state mutation. The data_ payload is forwarded unchanged so that authorization may depend on the contents of the call.

Reverts if:

  • The caller is not authorized to perform the enable.
function _authorizeEnable(bytes calldata data_) internal view virtual;

Parameters

NameTypeDescription
data_bytesThe calldata payload passed to enable.

_authorizeDisable​

Validates that the caller is permitted to disable the contract.

The function is invoked from disable before any state mutation. The data_ payload is forwarded unchanged so that authorization may depend on the contents of the call.

Reverts if:

  • The caller is not authorized to perform the disable.
function _authorizeDisable(bytes calldata data_) internal view virtual;

Parameters

NameTypeDescription
data_bytesThe calldata payload passed to disable.

_beforeEnable​

Performs implementation-specific state changes that must run immediately before the contract is moved to the enabled state.

The function is invoked from enable after _authorizeEnable succeeds and before isEnabled is updated. The default implementation is a no-op.

function _beforeEnable(bytes calldata data_) internal virtual;

Parameters

NameTypeDescription
data_bytesThe calldata payload passed to enable.

_beforeDisable​

Performs implementation-specific state changes that must run immediately before the contract is moved to the disabled state.

The function is invoked from disable after _authorizeDisable succeeds and before isEnabled is updated. The default implementation is a no-op.

function _beforeDisable(bytes calldata data_) internal virtual;

Parameters

NameTypeDescription
data_bytesThe calldata payload passed to disable.

_requireEnabled​

Asserts that the contract is currently enabled.

The check is exposed as a function so that inheriting contracts can compose it without using a modifier.

Reverts if:

  • The contract is currently disabled.
function _requireEnabled() internal view;

givenEnabled​

Modifier that reverts when the contract is not currently enabled.

modifier givenEnabled();

_requireDisabled​

Asserts that the contract is currently disabled.

The check is exposed as a function so that inheriting contracts can compose it without using a modifier.

Reverts if:

  • The contract is currently enabled.
function _requireDisabled() internal view;

givenDisabled​

Modifier that reverts when the contract is currently enabled.

modifier givenDisabled();

_getBlockTimestamp​

Returns the current block timestamp narrowed to uint48.

The function is exposed as a virtual hook so that test doubles can override the source of time without modifying the implementation.

function _getBlockTimestamp() internal view virtual returns (uint48 timestamp);

Returns

NameTypeDescription
timestampuint48The current block timestamp.

supportsInterface​

The contract advertises support for IEnablerV2, the legacy IEnabler, and any interface advertised by the parent ERC165 implementation. Extension mixins are expected to override this function and add their own interface identifiers.

function supportsInterface(bytes4 interfaceId_) public view virtual override returns (bool);

Parameters

NameTypeDescription
interfaceId_bytes4

Returns

NameTypeDescription
<none>bool