From f4a007b024e5a868a59e9c97125dd9b9d884b45f Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:54:57 +0300 Subject: [PATCH] feat(protocol): Add TaikoGovernor (#15228) Co-authored-by: Daniel Wang --- packages/protocol/contracts/L1/TaikoToken.sol | 6 +- .../contracts/L1/gov/TaikoGovernor.sol | 113 ++++++++++++++++++ 2 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 packages/protocol/contracts/L1/gov/TaikoGovernor.sol diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index f02c9289d9c..dd7bd2ffa43 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -44,9 +44,9 @@ contract TaikoToken is initializer { EssentialContract._init(_addressManager); - ERC20Upgradeable.__ERC20_init_unchained(_name, _symbol); - ERC20SnapshotUpgradeable.__ERC20Snapshot_init_unchained(); - ERC20VotesUpgradeable.__ERC20Votes_init_unchained(); + ERC20Upgradeable.__ERC20_init(_name, _symbol); + ERC20SnapshotUpgradeable.__ERC20Snapshot_init(); + ERC20VotesUpgradeable.__ERC20Votes_init(); // Mint 1 billion tokens _mint(_recipient, 1_000_000_000 ether); diff --git a/packages/protocol/contracts/L1/gov/TaikoGovernor.sol b/packages/protocol/contracts/L1/gov/TaikoGovernor.sol new file mode 100644 index 00000000000..00fc4228e2c --- /dev/null +++ b/packages/protocol/contracts/L1/gov/TaikoGovernor.sol @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.2; + +import "lib/openzeppelin-contracts/contracts/governance/Governor.sol"; +import + "lib/openzeppelin-contracts/contracts/governance/compatibility/GovernorCompatibilityBravo.sol"; +import + "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorVotes.sol"; +import + "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorVotesQuorumFraction.sol"; +import + "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorTimelockControl.sol"; + +contract TaikoGovernor is + Governor, + GovernorCompatibilityBravo, + GovernorVotes, + GovernorVotesQuorumFraction, + GovernorTimelockControl +{ + constructor( + IVotes _token, + TimelockController _timelock + ) + Governor("MyGovernor") + GovernorVotes(_token) + GovernorVotesQuorumFraction(4) + GovernorTimelockControl(_timelock) + { } + + // How long after a proposal is created should voting power be fixed. A + // large voting delay gives users time to unstake tokens if necessary. + function votingDelay() public pure override returns (uint256) { + return 7200; // 1 day + } + + // How long does a proposal remain open to votes. + function votingPeriod() public pure override returns (uint256) { + return 50_400; // 1 week + } + + // The number of votes required in order for a voter to become a proposer + function proposalThreshold() public pure override returns (uint256) { + return 1_000_000_000 ether / 10_000; // 0.01% of Taiko Token + } + + // The functions below are overrides required by Solidity. + function state(uint256 proposalId) + public + view + override(Governor, IGovernor, GovernorTimelockControl) + returns (ProposalState) + { + return super.state(proposalId); + } + + function propose( + address[] memory targets, + uint256[] memory values, + bytes[] memory calldatas, + string memory description + ) + public + override(Governor, IGovernor, GovernorCompatibilityBravo) + returns (uint256) + { + return super.propose(targets, values, calldatas, description); + } + + function _execute( + uint256 proposalId, + address[] memory targets, + uint256[] memory values, + bytes[] memory calldatas, + bytes32 descriptionHash + ) + internal + override(Governor, GovernorTimelockControl) + { + super._execute(proposalId, targets, values, calldatas, descriptionHash); + } + + function _cancel( + address[] memory targets, + uint256[] memory values, + bytes[] memory calldatas, + bytes32 descriptionHash + ) + internal + override(Governor, GovernorTimelockControl) + returns (uint256) + { + return super._cancel(targets, values, calldatas, descriptionHash); + } + + function _executor() + internal + view + override(Governor, GovernorTimelockControl) + returns (address) + { + return super._executor(); + } + + function supportsInterface(bytes4 interfaceId) + public + view + override(Governor, IERC165, GovernorTimelockControl) + returns (bool) + { + return super.supportsInterface(interfaceId); + } +}