Skip to content

Commit

Permalink
Revert "fix(protocol): remove L1/gov/ in favor of Aragon's (#16933)"
Browse files Browse the repository at this point in the history
This reverts commit 1573735.
  • Loading branch information
davidtaikocha committed May 1, 2024
1 parent 5175fbe commit 3352b29
Show file tree
Hide file tree
Showing 19 changed files with 583 additions and 23 deletions.
164 changes: 164 additions & 0 deletions packages/protocol/contracts/L1/gov/TaikoGovernor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import
"@openzeppelin/contracts-upgradeable/governance/compatibility/GovernorCompatibilityBravoUpgradeable.sol";
import
"@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";
import
"@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorSettingsUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

/// @title TaikoGovernor
/// @custom:security-contact [email protected]
contract TaikoGovernor is
Ownable2StepUpgradeable,
GovernorCompatibilityBravoUpgradeable,
GovernorSettingsUpgradeable,
GovernorVotesQuorumFractionUpgradeable,
GovernorTimelockControlUpgradeable
{
uint256[50] private __gap;

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _token The Taiko token.
/// @param _timelock The timelock contract address.
function init(
address _owner,
IVotesUpgradeable _token,
TimelockControllerUpgradeable _timelock
)
external
initializer
{
_transferOwnership(_owner == address(0) ? msg.sender : _owner);
__Governor_init("TaikoGovernor");
__GovernorVotes_init(_token);
__GovernorSettings_init(7200, 50_400, 100_000 ether); // Values respectively: 1day, 1week,
// 0.01% of Taiko Token;
__GovernorVotesQuorumFraction_init(4);
__GovernorTimelockControl_init(_timelock);
}

/// @dev See {IGovernor-propose}
function propose(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
string memory _description
)
public
override(IGovernorUpgradeable, GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable)
returns (uint256)
{
return super.propose(_targets, _values, _calldatas, _description);
}

/// @dev See {GovernorUpgradeable-supportsInterface}
function supportsInterface(bytes4 _interfaceId)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable, IERC165Upgradeable)
returns (bool)
{
return super.supportsInterface(_interfaceId);
}

/// @dev See {GovernorUpgradeable-state}
function state(uint256 _proposalId)
public
view
override(IGovernorUpgradeable, GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (ProposalState)
{
return super.state(_proposalId);
}

/// @notice How long after a proposal is created should voting power be fixed. A
/// large voting delay gives users time to unstake tokens if necessary.
/// @return The duration of the voting delay.
function votingDelay()
public
view
override(IGovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.votingDelay();
}

/// @notice How long does a proposal remain open to votes.
/// @return The duration of the voting period.
function votingPeriod()
public
view
override(IGovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.votingPeriod();
}

/// @notice The number of votes required in order for a voter to become a proposer.
/// @return The number of votes required.
function proposalThreshold()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.proposalThreshold();
}

/// @dev Cancel a proposal with GovernorBravo logic.
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
)
public
virtual
override(IGovernorUpgradeable, GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable)
returns (uint256)
{
return GovernorCompatibilityBravoUpgradeable.cancel(
targets, values, calldatas, descriptionHash
);
}

function _execute(
uint256 _proposalId,
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
bytes32 _descriptionHash
)
internal
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
{
return super._execute(_proposalId, _targets, _values, _calldatas, _descriptionHash);
}

function _cancel(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
bytes32 _descriptionHash
)
internal
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (uint256)
{
return super._cancel(_targets, _values, _calldatas, _descriptionHash);
}

function _executor()
internal
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (address)
{
return super._executor();
}
}
27 changes: 27 additions & 0 deletions packages/protocol/contracts/L1/gov/TaikoTimelockController.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol";
import "../../common/EssentialContract.sol";

/// @title TaikoTimelockController
/// @custom:security-contact [email protected]
contract TaikoTimelockController is EssentialContract, TimelockControllerUpgradeable {
uint256[50] private __gap;

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _minDelay The minimal delay.
function init(address _owner, uint256 _minDelay) external initializer {
__Essential_init(_owner);
address[] memory nil = new address[](0);
__TimelockController_init(_minDelay, nil, nil, owner());
}

/// @dev Gets the minimum delay for an operation to become valid, allows the admin to get around
/// of the min delay.
/// @return The minimum delay.
function getMinDelay() public view override returns (uint256) {
return hasRole(TIMELOCK_ADMIN_ROLE, msg.sender) ? 0 : super.getMinDelay();
}
}
21 changes: 18 additions & 3 deletions packages/protocol/script/AddSGXVerifierInstances.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
pragma solidity 0.8.24;

import "../test/DeployCapability.sol";
import "../contracts/L1/gov/TaikoTimelockController.sol";
import "../contracts/verifiers/SgxVerifier.sol";

contract AddSGXVerifierInstances is DeployCapability {
uint256 public privateKey = vm.envUint("PRIVATE_KEY");
address public timelockAddress = vm.envAddress("TIMELOCK_ADDRESS");
address public sgxVerifier = vm.envAddress("SGX_VERIFIER");
address[] public instances = vm.envAddress("INSTANCES", ",");

Expand All @@ -14,14 +16,27 @@ contract AddSGXVerifierInstances is DeployCapability {

vm.startBroadcast(privateKey);

SgxVerifier(sgxVerifier).addInstances(instances);
updateInstancesByTimelock(timelockAddress);

vm.stopBroadcast();
}

function updateInstancesByTimelock(address timelock) internal {
bytes32 salt = bytes32(block.timestamp);

bytes memory payload =
abi.encodeWithSelector(bytes4(keccak256("addInstances(address[])")), instances);

TaikoTimelockController timelockController = TaikoTimelockController(payable(timelock));

timelockController.schedule(sgxVerifier, 0, payload, bytes32(0), salt, 0);

timelockController.execute(sgxVerifier, 0, payload, bytes32(0), salt);

for (uint256 i; i < instances.length; ++i) {
console2.log("New instance added:");
console2.log("index: ", i);
console2.log("instance: ", instances[0]);
}

vm.stopBroadcast();
}
}
14 changes: 13 additions & 1 deletion packages/protocol/script/AuthorizeTaikoForMultihop.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
pragma solidity 0.8.24;

import "../test/DeployCapability.sol";
import "../contracts/L1/gov/TaikoTimelockController.sol";
import "../contracts/signal/SignalService.sol";

contract AuthorizeTaikoForMultihop is DeployCapability {
uint256 public privateKey = vm.envUint("PRIVATE_KEY");
address public sharedSignalService = vm.envAddress("SHARED_SIGNAL_SERVICE");
address public timelockAddress = vm.envAddress("TIMELOCK_ADDRESS");
// TaikoL1 and TaikoL2 contracts
address[] public taikoContracts = vm.envAddress("TAIKO_CONTRACTS", ",");

function run() external {
require(taikoContracts.length != 0, "invalid taiko contracts");

vm.startBroadcast(privateKey);

for (uint256 i; i < taikoContracts.length; ++i) {
SignalService(sharedSignalService).authorize(taikoContracts[i], true);
bytes32 salt = bytes32(block.timestamp);

bytes memory payload =
abi.encodeCall(SignalService.authorize, (taikoContracts[i], true));

TaikoTimelockController timelock = TaikoTimelockController(payable(timelockAddress));

timelock.schedule(sharedSignalService, 0, payload, bytes32(0), salt, 0);

timelock.execute(sharedSignalService, 0, payload, bytes32(0), salt);
}

vm.stopBroadcast();
Expand Down
13 changes: 12 additions & 1 deletion packages/protocol/script/SetRemoteBridgeSuites.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.24;

import "../test/DeployCapability.sol";
import "../contracts/L1/gov/TaikoTimelockController.sol";

contract SetRemoteBridgeSuites is DeployCapability {
uint256 public privateKey = vm.envUint("PRIVATE_KEY");
Expand Down Expand Up @@ -74,7 +75,17 @@ contract SetRemoteBridgeSuites is DeployCapability {
)
internal
{
AddressManager(registerTo).setAddress(chainId, bytes32(bytes(name)), addr);
bytes32 salt = bytes32(block.timestamp);

bytes memory payload =
abi.encodeCall(AddressManager.setAddress, (chainId, bytes32(bytes(name)), addr));

TaikoTimelockController timelock = TaikoTimelockController(payable(timelockAddress));

timelock.schedule(registerTo, 0, payload, bytes32(0), salt, 0);

timelock.execute(registerTo, 0, payload, bytes32(0), salt);

console2.log("> ", name, "@", registerTo);
console2.log("\t addr : ", addr);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeAddressManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeAddressManager is UpgradeScript {
function run() external setUp {
upgrade("AddressManager", address(new AddressManager()));
console2.log("upgrading AddressManager");
AddressManager newAddressManager = new AddressManager();
upgrade(address(newAddressManager));

console2.log("upgraded AddressManager to", address(newAddressManager));
}
}
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeAssignmentHook.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeAssignmentHook is UpgradeScript {
function run() external setUp {
upgrade("AssignmentHook", address(new AssignmentHook()));
console2.log("upgrading AssignmentHook");
AssignmentHook newAssignmentHook = new AssignmentHook();
upgrade(address(newAssignmentHook));

console2.log("upgraded AssignmentHook to", address(newAssignmentHook));
}
}
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeBridge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeBridge is UpgradeScript {
function run() external setUp {
upgrade("Bridge", address(new Bridge()));
console2.log("upgrading bridge");
Bridge newBridge = new Bridge();
upgrade(address(newBridge));

console2.log("upgraded bridge to", address(newBridge));
}
}
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeERC1155Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeERC1155Vault is UpgradeScript {
function run() external setUp {
upgrade("ERC1155Vault", address(new ERC1155Vault()));
console2.log("upgrading ERC1155Vault");
ERC1155Vault newERC1155Vault = new ERC1155Vault();
upgrade(address(newERC1155Vault));

console2.log("upgraded ERC1155Vault to", address(newERC1155Vault));
}
}
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeERC20Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeERC20Vault is UpgradeScript {
function run() external setUp {
upgrade("ERC20Vault", address(new ERC20Vault()));
console2.log("upgrading ERC20Vault");
ERC20Vault newERC20Vault = new ERC20Vault();
upgrade(address(newERC20Vault));

console2.log("upgraded ERC20Vault to", address(newERC20Vault));
}
}
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeERC721Vault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeERC721Vault is UpgradeScript {
function run() external setUp {
upgrade("ERC721Vault", address(new ERC721Vault()));
console2.log("upgrading ERC721Vault");
ERC721Vault newERC721Vault = new ERC721Vault();
upgrade(address(newERC721Vault));

console2.log("upgraded ERC721Vault to", address(newERC721Vault));
}
}
6 changes: 5 additions & 1 deletion packages/protocol/script/upgrade/UpgradeGuardianProver.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "./UpgradeScript.s.sol";

contract UpgradeGuardianProver is UpgradeScript {
function run() external setUp {
upgrade("GuardianProver", address(new GuardianProver()));
console2.log("upgrading GuardianProver");
GuardianProver newGuardianProver = new GuardianProver();
upgrade(address(newGuardianProver));

console2.log("upgraded GuardianProver to", address(newGuardianProver));
}
}
Loading

0 comments on commit 3352b29

Please sign in to comment.