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

feat(protocol): add TaikoGovernor and improve TaikoToken #13711

Merged
merged 8 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
temp
  • Loading branch information
dantaik committed May 5, 2023
commit a6e97375e745cd6d2a21c99cfb9d9610212bc609
5 changes: 5 additions & 0 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {TaikoErrors} from "./TaikoErrors.sol";
import {TaikoData} from "./TaikoData.sol";
import {TaikoEvents} from "./TaikoEvents.sol";

/// @custom:security-contact [email protected]
contract TaikoL1 is
EssentialContract,
ICrossChainSync,
Expand All @@ -31,6 +32,10 @@ contract TaikoL1 is
TaikoData.State public state;
uint256[100] private __gap;

constructor() {
_disableInitializers();
}

receive() external payable {
depositEtherToL2();
}
Expand Down
15 changes: 14 additions & 1 deletion packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import {
SafeCastUpgradeable
} from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";

library LibTaikoTokenConfig {
uint8 public constant DECIMALS = uint8(8);
}

/// @dev This is Taiko's governance and fee token.
/// @custom:security-contact [email protected]
contract TaikoToken is EssentialContract, ERC20Upgradeable, IMintableERC20 {
using LibMath for uint256;
using SafeCastUpgradeable for uint256;
Expand All @@ -41,6 +46,9 @@ contract TaikoToken is EssentialContract, ERC20Upgradeable, IMintableERC20 {
/*********************
* External Functions*
*********************/
constructor() {
_disableInitializers();
}

/// @dev Initializer to be called after being deployed behind a proxy.
/// Based on our simulation in simulate/tokenomics/index.js, both
Expand All @@ -59,9 +67,14 @@ contract TaikoToken is EssentialContract, ERC20Upgradeable, IMintableERC20 {
ERC20Upgradeable.__ERC20_init({
name_: _name,
symbol_: _symbol,
decimals_: 8
decimals_: LibTaikoTokenConfig.DECIMALS
});

// __ERC20Burnable_init();
// __ERC20Snapshot_init();
// __ERC20Permit_init(_name);
// __ERC20Votes_init();

for (uint256 i = 0; i < _premintRecipients.length; ++i) {
_mint(_premintRecipients[i], _premintAmounts[i]);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SafeCastUpgradeable
} from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";

/// @custom:security-contact [email protected]
contract TaikoL2 is EssentialContract, TaikoL2Signer, ICrossChainSync {
using SafeCastUpgradeable for uint256;
using LibMath for uint256;
Expand Down Expand Up @@ -87,6 +88,10 @@ contract TaikoL2 is EssentialContract, TaikoL2Signer, ICrossChainSync {
* Constructor *
**********************/

constructor() {
_disableInitializers();
}

function init(
address _addressManager,
EIP1559Params calldata _param1559
Expand Down
5 changes: 5 additions & 0 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {LibBridgeStatus} from "./libs/LibBridgeStatus.sol";
* Bridge contract which is deployed on both L1 and L2. Mostly a thin wrapper
* which calls the library implementations. See _IBridge_ for more details.
* @dev The code hash for the same address on L1 and L2 may be different.
* @custom:security-contact [email protected]
*/
contract Bridge is EssentialContract, IBridge, BridgeErrors {
using LibBridgeData for Message;
Expand All @@ -47,6 +48,10 @@ contract Bridge is EssentialContract, IBridge, BridgeErrors {
* External Functions*
*********************/

constructor() {
_disableInitializers();
}

/// Allow Bridge to receive ETH from the TokenVault or EtherVault.
receive() external payable {
if (
Expand Down
5 changes: 5 additions & 0 deletions packages/protocol/contracts/bridge/BridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {EssentialContract} from "../common/EssentialContract.sol";
import {ERC20Upgradeable} from "../thirdparty/ERC20Upgradeable.sol";
import {BridgeErrors} from "./BridgeErrors.sol";

/// @custom:security-contact [email protected]
contract BridgedERC20 is
EssentialContract,
IERC20Upgradeable,
Expand All @@ -32,6 +33,10 @@ contract BridgedERC20 is
event BridgeMint(address indexed account, uint256 amount);
event BridgeBurn(address indexed account, uint256 amount);

constructor() {
_disableInitializers();
}

/// @dev Initializer to be called after being deployed behind a proxy.
// Intention is for a different BridgedERC20 Contract to be deployed
// per unique _srcToken i.e. one for USDC, one for USDT etc.
Expand Down
4 changes: 4 additions & 0 deletions packages/protocol/contracts/bridge/EtherVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {LibAddress} from "../libs/LibAddress.sol";
import {BridgeErrors} from "./BridgeErrors.sol";

/**
* @custom:security-contact [email protected]
* EtherVault is a special vault contract that:
* - Is initialized with 2^128 Ether.
* - Allows the contract owner to authorize addresses.
Expand Down Expand Up @@ -56,6 +57,9 @@ contract EtherVault is EssentialContract, BridgeErrors {
/*********************
* External Functions*
*********************/
constructor() {
_disableInitializers();
}

receive() external payable {
// EthVault's balance must == 0 OR the sender isAuthorized.
Expand Down
6 changes: 5 additions & 1 deletion packages/protocol/contracts/bridge/TokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
* It also manages the mapping between canonical ERC20 tokens and their bridged
* tokens.
* @dev Ether is held by Bridges on L1 and by the EtherVault on L2,
* not TokenVaults.
* not TokenVaults.
* @custom:security-contact [email protected]
*/
contract TokenVault is EssentialContract {
using SafeERC20Upgradeable for ERC20Upgradeable;
Expand Down Expand Up @@ -132,6 +133,9 @@ contract TokenVault is EssentialContract {
/*********************
* External Functions*
*********************/
constructor() {
_disableInitializers();
}

function init(address addressManager) external initializer {
EssentialContract._init(addressManager);
Expand Down
8 changes: 5 additions & 3 deletions packages/protocol/contracts/common/AddressManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ interface IAddressManager {
) external view returns (address);
}

/**
* @title AddressManager
*/
/// @custom:security-contact [email protected]
contract AddressManager is OwnableUpgradeable, IAddressManager {
mapping(uint256 domain => mapping(bytes32 name => address addr))
private addresses;
Expand All @@ -53,6 +51,10 @@ contract AddressManager is OwnableUpgradeable, IAddressManager {
address _oldAddress
);

constructor() {
_disableInitializers();
}

/// @dev Initializer to be called after being deployed behind a proxy.
function init() external initializer {
OwnableUpgradeable.__Ownable_init();
Expand Down
175 changes: 175 additions & 0 deletions packages/protocol/contracts/gov/TaikoGovernor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {
GovernorUpgradeable,
IGovernorUpgradeable
} from "@openzeppelin/contracts-upgradeable/governance/GovernorUpgradeable.sol";
import {
GovernorSettingsUpgradeable
} from "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorSettingsUpgradeable.sol";
import {
GovernorCountingSimpleUpgradeable
} from "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorCountingSimpleUpgradeable.sol";
import {
GovernorVotesUpgradeable
} from "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesUpgradeable.sol";
import {
GovernorVotesQuorumFractionUpgradeable,
IVotesUpgradeable
} from "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";
import {
GovernorTimelockControlUpgradeable,
TimelockControllerUpgradeable
} from "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import {
Initializable
} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {
OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import {LibTaikoTokenConfig} from "../L1/TaikoToken.sol";

/// @custom:security-contact [email protected]
contract TaikoGovernor is
Initializable,
GovernorUpgradeable,
GovernorSettingsUpgradeable,
GovernorCountingSimpleUpgradeable,
GovernorVotesUpgradeable,
GovernorVotesQuorumFractionUpgradeable,
GovernorTimelockControlUpgradeable,
OwnableUpgradeable
{
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
IVotesUpgradeable _token,
TimelockControllerUpgradeable _timelock
) public initializer {
__Governor_init("TaikoGovernor");
__GovernorSettings_init(
7200 /* 7200 block = 1 day */,
100800 /* 2 week */,
LibTaikoTokenConfig.DECIMALS
);
__GovernorCountingSimple_init();
__GovernorVotes_init(_token);
__GovernorVotesQuorumFraction_init(4);
__GovernorTimelockControl_init(_timelock);
__Ownable_init();
}

// The following functions are overrides required by Solidity.
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
)
public
override(GovernorUpgradeable, IGovernorUpgradeable)
returns (uint256)
{
return super.propose(targets, values, calldatas, description);
}

function votingDelay()
public
view
override(IGovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.votingDelay();
}

function votingPeriod()
public
view
override(IGovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.votingPeriod();
}

function quorum(
uint256 blockNumber
)
public
view
override(IGovernorUpgradeable, GovernorVotesQuorumFractionUpgradeable)
returns (uint256)
{
return super.quorum(blockNumber);
}

function state(
uint256 proposalId
)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (ProposalState)
{
return super.state(proposalId);
}

function proposalThreshold()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.proposalThreshold();
}

function supportsInterface(
bytes4 interfaceId
)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}

function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
)
internal
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
{
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();
}
}
5 changes: 5 additions & 0 deletions packages/protocol/contracts/signal/SignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {ISignalService} from "./ISignalService.sol";
import {ICrossChainSync} from "../common/ICrossChainSync.sol";
import {LibSecureMerkleTrie} from "../thirdparty/LibSecureMerkleTrie.sol";

/// @custom:security-contact [email protected]
contract SignalService is ISignalService, EssentialContract {
struct SignalProof {
uint256 height;
Expand All @@ -21,6 +22,10 @@ contract SignalService is ISignalService, EssentialContract {
error B_NULL_APP_ADDR();
error B_WRONG_CHAIN_ID();

constructor() {
_disableInitializers();
}

/// @dev Initializer to be called after being deployed behind a proxy.
function init(address _addressManager) external initializer {
EssentialContract._init(_addressManager);
Expand Down