You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.9 KiB
94 lines
2.9 KiB
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
3 years ago
|
pragma solidity >=0.8.0;
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Internal Imports ============
|
||
3 years ago
|
import {IMailbox} from "../interfaces/IMailbox.sol";
|
||
3 years ago
|
// ============ External Imports ============
|
||
3 years ago
|
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
||
4 years ago
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* @title Mailbox
|
||
4 years ago
|
* @author Celo Labs Inc.
|
||
3 years ago
|
* @notice Shared utilities between Outbox and Inbox.
|
||
3 years ago
|
*/
|
||
3 years ago
|
abstract contract Mailbox is IMailbox, OwnableUpgradeable {
|
||
3 years ago
|
// ============ Immutable Variables ============
|
||
|
|
||
|
// Domain of chain on which the contract is deployed
|
||
3 years ago
|
uint32 public immutable override localDomain;
|
||
3 years ago
|
|
||
|
// ============ Public Variables ============
|
||
|
|
||
3 years ago
|
// Address of the validator manager contract.
|
||
|
address public validatorManager;
|
||
3 years ago
|
|
||
|
// ============ Upgrade Gap ============
|
||
|
|
||
3 years ago
|
// gap for upgrade safety
|
||
3 years ago
|
uint256[49] private __GAP;
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Events ============
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Emitted when the validator manager contract is changed
|
||
3 years ago
|
* @param validatorManager The address of the new validatorManager
|
||
3 years ago
|
*/
|
||
3 years ago
|
event ValidatorManagerSet(address validatorManager);
|
||
3 years ago
|
|
||
3 years ago
|
// ============ Modifiers ============
|
||
|
|
||
3 years ago
|
/**
|
||
|
* @notice Ensures that a function is called by the validator manager contract.
|
||
|
*/
|
||
|
modifier onlyValidatorManager() {
|
||
3 years ago
|
require(msg.sender == validatorManager, "!validatorManager");
|
||
3 years ago
|
_;
|
||
|
}
|
||
|
|
||
3 years ago
|
// ============ Constructor ============
|
||
|
|
||
4 years ago
|
constructor(uint32 _localDomain) {
|
||
|
localDomain = _localDomain;
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Initializer ============
|
||
|
|
||
3 years ago
|
function __Mailbox_initialize(address _validatorManager)
|
||
3 years ago
|
internal
|
||
|
onlyInitializing
|
||
|
{
|
||
3 years ago
|
// initialize owner
|
||
|
__Ownable_init();
|
||
3 years ago
|
_setValidatorManager(_validatorManager);
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
// ============ External Functions ============
|
||
4 years ago
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* @notice Set a new validator manager contract
|
||
|
* @dev Mailbox(es) will initially be initialized using a trusted validator manager contract;
|
||
3 years ago
|
* we will progressively decentralize by swapping the trusted contract with a new implementation
|
||
|
* that implements Validator bonding & slashing, and rules for Validator selection & rotation
|
||
3 years ago
|
* @param _validatorManager the new validator manager contract
|
||
3 years ago
|
*/
|
||
3 years ago
|
function setValidatorManager(address _validatorManager) external onlyOwner {
|
||
3 years ago
|
_setValidatorManager(_validatorManager);
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Internal Functions ============
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Set the validator manager
|
||
|
* @param _validatorManager Address of the validator manager
|
||
3 years ago
|
*/
|
||
3 years ago
|
function _setValidatorManager(address _validatorManager) internal {
|
||
3 years ago
|
require(
|
||
|
Address.isContract(_validatorManager),
|
||
|
"!contract validatorManager"
|
||
|
);
|
||
3 years ago
|
validatorManager = _validatorManager;
|
||
3 years ago
|
emit ValidatorManagerSet(_validatorManager);
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|