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

Add multiple pausers/freezers to 2.1.0 FacadeWrite #856

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
58 changes: 31 additions & 27 deletions contracts/facade/FacadeWrite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ contract FacadeWrite is IFacadeWrite {
bool deployGovernance,
bool unpause,
GovernanceParams calldata govParams,
address owner,
address guardian,
address pauser
GovernanceRoles calldata govRoles
) external returns (address newOwner) {
// Get Main
IMain main = rToken.main();
Expand All @@ -141,7 +139,7 @@ contract FacadeWrite is IFacadeWrite {
main.revokeRole(OWNER, msg.sender);

if (deployGovernance) {
require(owner == address(0), "owner should be empty");
require(govRoles.owner == address(0), "owner should be empty");

TimelockController timelock = new TimelockController(
govParams.timelockDelay,
Expand All @@ -162,44 +160,50 @@ contract FacadeWrite is IFacadeWrite {

// Setup Roles
timelock.grantRole(timelock.PROPOSER_ROLE(), governance); // Gov only proposer
timelock.grantRole(timelock.CANCELLER_ROLE(), guardian); // Guardian as canceller
// Set Guardian as canceller, if address(0) then no one can cancel
timelock.grantRole(timelock.CANCELLER_ROLE(), govRoles.guardian);
timelock.grantRole(timelock.EXECUTOR_ROLE(), address(0)); // Anyone as executor
timelock.revokeRole(timelock.TIMELOCK_ADMIN_ROLE(), address(this)); // Revoke admin role

// Set new owner to timelock
newOwner = address(timelock);
} else {
require(owner != address(0), "owner not defined");
newOwner = owner;
require(govRoles.owner != address(0), "owner not defined");
newOwner = govRoles.owner;
}

// Setup guardian as freeze starter / extender + pauser
if (guardian != address(0)) {
// As a further decentralization step it is suggested to further differentiate between
// these two roles. But this is what will make sense for simple system setup.
main.grantRole(SHORT_FREEZER, guardian);
main.grantRole(LONG_FREEZER, guardian);
main.grantRole(PAUSER, guardian);
// Unpause if required
if (unpause) {
main.unpause();
}

// Setup Pauser
if (pauser != address(0)) {
main.grantRole(PAUSER, pauser);
main.revokeRole(PAUSER, address(this));
main.revokeRole(SHORT_FREEZER, address(this));
main.revokeRole(LONG_FREEZER, address(this));

// Setup pausers
for (uint256 i = 0; i < govRoles.pausers.length; ++i) {
if (govRoles.pausers[i] != address(0)) {
main.grantRole(PAUSER, govRoles.pausers[i]);
}
}

// Unpause if required
if (unpause) {
main.unpause();
// Setup short freezers
for (uint256 i = 0; i < govRoles.shortFreezers.length; ++i) {
if (govRoles.shortFreezers[i] != address(0)) {
main.grantRole(SHORT_FREEZER, govRoles.shortFreezers[i]);
}
}

// Setup long freezers
for (uint256 i = 0; i < govRoles.longFreezers.length; ++i) {
if (govRoles.longFreezers[i] != address(0)) {
main.grantRole(LONG_FREEZER, govRoles.longFreezers[i]);
}
}

// Transfer Ownership and renounce roles
// Transfer Ownership and renounce owner role
main.grantRole(OWNER, newOwner);
main.grantRole(SHORT_FREEZER, newOwner);
main.grantRole(LONG_FREEZER, newOwner);
main.grantRole(PAUSER, newOwner);
main.renounceRole(OWNER, address(this));
main.renounceRole(SHORT_FREEZER, address(this));
main.renounceRole(LONG_FREEZER, address(this));
main.renounceRole(PAUSER, address(this));
}
}
16 changes: 13 additions & 3 deletions contracts/interfaces/IFacadeWrite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ struct GovernanceParams {
uint256 timelockDelay; // in seconds (used for timelock)
}

/**
* @title GovernanceRoles
* @notice The set of roles required (owner, guardian, pausers, and freezers)
*/
struct GovernanceRoles {
address owner;
address guardian;
address[] pausers;
address[] shortFreezers;
address[] longFreezers;
}

/**
* @title IFacadeWrite
* @notice A UX-friendly layer for interactin with the protocol
Expand All @@ -89,8 +101,6 @@ interface IFacadeWrite {
bool deployGovernance,
bool unfreeze,
GovernanceParams calldata govParams,
address owner,
address guardian,
address pauser
GovernanceRoles calldata govRoles
) external returns (address);
}
Loading