-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathERC20hTokenBranchFactory.sol
85 lines (66 loc) · 2.89 KB
/
ERC20hTokenBranchFactory.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable} from "solady/auth/Ownable.sol";
import {ERC20} from "../token/ERC20hTokenBranch.sol";
import {IERC20hTokenBranchFactory, ERC20hTokenBranch} from "../interfaces/IERC20hTokenBranchFactory.sol";
/// @title ERC20hTokenBranch Factory Contract
contract ERC20hTokenBranchFactory is Ownable, IERC20hTokenBranchFactory {
/// @notice Local Network Identifier.
uint24 public immutable localChainId;
/// @notice Local Port Address
address immutable localPortAddress;
/// @notice Local Branch Core Router Address responsible for the addition of new tokens to the system.
address localCoreRouterAddress;
/// @notice Local hTokens deployed in current chain.
ERC20hTokenBranch[] public hTokens;
/// @notice Number of hTokens deployed in current chain.
uint256 public hTokensLenght;
constructor(uint24 _localChainId, address _localPortAddress) {
require(_localPortAddress != address(0), "Port address cannot be 0");
localChainId = _localChainId;
localPortAddress = _localPortAddress;
_initializeOwner(msg.sender);
}
function initialize(address _wrappedNativeTokenAddress, address _coreRouter) external onlyOwner {
require(_coreRouter != address(0), "CoreRouter address cannot be 0");
ERC20hTokenBranch newToken = new ERC20hTokenBranch(
ERC20(_wrappedNativeTokenAddress).name(),
ERC20(_wrappedNativeTokenAddress).symbol(),
localPortAddress
);
hTokens.push(newToken);
hTokensLenght++;
localCoreRouterAddress = _coreRouter;
renounceOwnership();
}
/*///////////////////////////////////////////////////////////////
hTOKEN FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Function to create a new hToken.
* @param _name Name of the Token.
* @param _symbol Symbol of the Token.
*/
function createToken(string memory _name, string memory _symbol)
external
requiresCoreRouter
returns (ERC20hTokenBranch newToken)
{
newToken = new ERC20hTokenBranch(_name, _symbol, localPortAddress);
hTokens.push(newToken);
hTokensLenght++;
}
/*///////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
/// @notice Modifier that verifies msg sender is the RootInterface Contract from Root Chain.
modifier requiresCoreRouter() {
if (msg.sender != localCoreRouterAddress) revert UnrecognizedCoreRouter();
_;
}
/// @notice Modifier that verifies msg sender is the Branch Port Contract from Local Chain.
modifier requiresPort() {
if (msg.sender != localPortAddress) revert UnrecognizedPort();
_;
}
}