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

Split dg and reseal functionality #139

Draft
wants to merge 1 commit into
base: feature/change-variables-dg-ept
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions contracts/DualGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {IDualGovernanceConfigProvider} from "./interfaces/IDualGovernanceConfigP
import {Proposers} from "./libraries/Proposers.sol";
import {Tiebreaker} from "./libraries/Tiebreaker.sol";
import {ExternalCall} from "./libraries/ExternalCalls.sol";
import {Resealer} from "./libraries/Resealer.sol";
import {State, DualGovernanceStateMachine} from "./libraries/DualGovernanceStateMachine.sol";

import {Escrow} from "./Escrow.sol";
Expand All @@ -31,6 +32,7 @@ contract DualGovernance is IDualGovernance {
using Proposers for Proposers.Context;
using Tiebreaker for Tiebreaker.Context;
using DualGovernanceStateMachine for DualGovernanceStateMachine.Context;
using Resealer for Resealer.Context;

// ---
// Errors
Expand Down Expand Up @@ -130,16 +132,7 @@ contract DualGovernance is IDualGovernance {
/// @dev The state machine implementation controlling the state of the Dual Governance.
DualGovernanceStateMachine.Context internal _stateMachine;

// ---
// Standalone State Variables
// ---

/// @dev The address of the Reseal Committee which is allowed to "reseal" sealables paused for a limited
/// period of time when the Dual Governance proposal adoption is blocked.
address internal _resealCommittee;

/// @dev The address of the Reseal Manager.
IResealManager internal _resealManager;
Resealer.Context internal _resealer;

// ---
// Constructor
Expand All @@ -162,7 +155,7 @@ contract DualGovernance is IDualGovernance {
emit EscrowMasterCopyDeployed(ESCROW_MASTER_COPY);

_stateMachine.initialize(dependencies.configProvider, ESCROW_MASTER_COPY);
_setResealManager(address(dependencies.resealManager));
_resealer.setResealManager(address(dependencies.resealManager));
}

// ---
Expand Down Expand Up @@ -446,7 +439,7 @@ contract DualGovernance is IDualGovernance {
_tiebreaker.checkCallerIsTiebreakerCommittee();
_stateMachine.activateNextState(ESCROW_MASTER_COPY);
_tiebreaker.checkTie(_stateMachine.getPersistedState(), _stateMachine.normalOrVetoCooldownExitedAt);
_resealManager.resume(sealable);
_resealer.resume(sealable);
}

/// @notice Allows the tiebreaker committee to schedule for execution a submitted proposal when
Expand Down Expand Up @@ -480,51 +473,36 @@ contract DualGovernance is IDualGovernance {
/// @param sealable The address of the sealable contract to be resealed.
function resealSealable(address sealable) external {
_stateMachine.activateNextState(ESCROW_MASTER_COPY);
if (msg.sender != _resealCommittee) {
revert CallerIsNotResealCommittee(msg.sender);
}
if (_stateMachine.getPersistedState() == State.Normal) {
revert ResealIsNotAllowedInNormalState();
}
_resealManager.reseal(sealable);
_resealer.reseal(sealable);
}

/// @notice Sets the address of the reseal committee.
/// @param resealCommittee The address of the new reseal committee.
function setResealCommittee(address resealCommittee) external {
_checkCallerIsAdminExecutor();
if (resealCommittee == _resealCommittee) {
revert InvalidResealCommittee(resealCommittee);
}
_resealCommittee = resealCommittee;
emit ResealCommitteeSet(resealCommittee);
_resealer.setResealCommittee(resealCommittee);
}

/// @notice Sets the address of the Reseal Manager.
/// @param resealManager The address of the new Reseal Manager.
function setResealManager(address resealManager) external {
_checkCallerIsAdminExecutor();
_setResealManager(resealManager);
_resealer.setResealManager(resealManager);
}

/// @notice Gets the address of the Reseal Manager.
/// @return resealManager The address of the Reseal Manager.
function getResealManager() external view returns (IResealManager) {
return _resealManager;
return _resealer.resealManager;
}

// ---
// Internal methods
// ---

function _setResealManager(address resealManager) internal {
if (resealManager == address(_resealManager) || resealManager == address(0)) {
revert InvalidResealManager(resealManager);
}
_resealManager = IResealManager(resealManager);
emit ResealManagerSet(resealManager);
}

function _checkCallerIsAdminExecutor() internal view {
if (TIMELOCK.getAdminExecutor() != msg.sender) {
revert CallerIsNotAdminExecutor(msg.sender);
Expand Down
48 changes: 48 additions & 0 deletions contracts/libraries/Resealer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {IResealManager} from "../interfaces/IResealManager.sol";

library Resealer {
error InvalidResealManager(address resealManager);
error InvalidResealCommittee(address resealCommittee);
error CallerIsNotResealCommittee(address caller);

event ResealCommitteeSet(address resealCommittee);
event ResealManagerSet(address resealManager);

struct Context {
/// @dev The address of the Reseal Manager.
IResealManager resealManager;
/// @dev The address of the Reseal Committee which is allowed to "reseal" sealables paused for a limited
/// period of time when the Dual Governance proposal adoption is blocked.
address resealCommittee;
}

function setResealManager(Context storage self, address newResealManager) internal {
if (newResealManager == address(self.resealManager) || newResealManager == address(0)) {
revert InvalidResealManager(newResealManager);
}
self.resealManager = IResealManager(newResealManager);
emit ResealManagerSet(newResealManager);
}

function setResealCommittee(Context storage self, address newResealCommittee) internal {
if (newResealCommittee == self.resealCommittee) {
revert InvalidResealCommittee(newResealCommittee);
}
self.resealCommittee = newResealCommittee;
emit ResealCommitteeSet(newResealCommittee);
}

function reseal(Context storage self, address sealable) internal {
if (msg.sender != self.resealCommittee) {
revert CallerIsNotResealCommittee(msg.sender);
}
self.resealManager.reseal(sealable);
}

function resume(Context storage self, address sealable) internal {
self.resealManager.resume(sealable);
}
}