-
Notifications
You must be signed in to change notification settings - Fork 15
/
ERC20hTokenRootFactory.sol
104 lines (89 loc) · 3.62 KB
/
ERC20hTokenRootFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable} from "solady/auth/Ownable.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {IERC20hTokenRootFactory, ERC20hTokenRoot} from "../interfaces/IERC20hTokenRootFactory.sol";
/// @title ERC20 hToken Root Factory Contract
/// @author MaiaDAO
contract ERC20hTokenRootFactory is Ownable, IERC20hTokenRootFactory {
/// @notice Local Network Identifier.
uint16 public immutable localChainId;
/// @notice Root Port Address.
address public immutable rootPortAddress;
/// @notice Root Core Router Address, in charge of the addition of new tokens to the system.
address public coreRootRouterAddress;
/// @notice Array of all hTokens created.
ERC20hTokenRoot[] public hTokens;
/*///////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/**
* @notice Constructor for ERC20 hToken Root Factory Contract
* @param _localChainId Local Network Layer Zerio Identifier.
* @param _rootPortAddress Root Port Address.
*/
constructor(uint16 _localChainId, address _rootPortAddress) {
require(_rootPortAddress != address(0), "Root Port Address cannot be 0");
localChainId = _localChainId;
rootPortAddress = _rootPortAddress;
_initializeOwner(msg.sender);
}
/*///////////////////////////////////////////////////////////////
INITIALIZER
//////////////////////////////////////////////////////////////*/
/**
* @notice Function to initialize the contract.
* @param _coreRouter Address of the Root Chain's Core Router.
*/
function initialize(address _coreRouter) external onlyOwner {
require(_coreRouter != address(0), "CoreRouter address cannot be 0");
coreRootRouterAddress = _coreRouter;
renounceOwnership();
}
/*///////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Function to get the array of hTokens.
* @return Array of hTokens.
*/
function getHTokens() external view returns (ERC20hTokenRoot[] memory) {
return hTokens;
}
/*///////////////////////////////////////////////////////////////
hTOKEN FACTORY EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Function to create a new hToken.
* @param _name Name of the Token.
* @param _symbol Symbol of the Token.
* @param _decimals Decimals of the Token.
*/
function createToken(string memory _name, string memory _symbol, uint8 _decimals)
external
requiresCoreRouterOrPort
returns (ERC20hTokenRoot newToken)
{
newToken = new ERC20hTokenRoot(
localChainId,
address(this),
rootPortAddress,
_name,
_symbol,
_decimals
);
hTokens.push(newToken);
}
/*///////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
/// @notice Modifier that verifies msg sender is the RootInterface Contract from Root Chain.
modifier requiresCoreRouterOrPort() {
if (msg.sender != coreRootRouterAddress) {
if (msg.sender != rootPortAddress) {
revert UnrecognizedCoreRouterOrPort();
}
}
_;
}
}