-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathOptimismMintableERC20Factory.sol
More file actions
145 lines (124 loc) · 6.23 KB
/
OptimismMintableERC20Factory.sol
File metadata and controls
145 lines (124 loc) · 6.23 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
// Contracts
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import { OptimismMintableERC20 } from "src/universal/OptimismMintableERC20.sol";
import { ProxyAdminOwnedBase } from "src/universal/ProxyAdminOwnedBase.sol";
// Interfaces
import { ISemver } from "interfaces/universal/ISemver.sol";
import { IOptimismERC20Factory } from "interfaces/L2/IOptimismERC20Factory.sol";
/// @custom:proxied true
/// @custom:predeployed 0x4200000000000000000000000000000000000012
/// @title OptimismMintableERC20Factory
/// @notice OptimismMintableERC20Factory is a factory contract that generates OptimismMintableERC20
/// contracts on the network it's deployed to. Simplifies the deployment process for users
/// who may be less familiar with deploying smart contracts. Designed to be backwards
/// compatible with the older StandardL2ERC20Factory contract.
contract OptimismMintableERC20Factory is ProxyAdminOwnedBase, ISemver, Initializable, IOptimismERC20Factory {
/// @custom:spacer OptimismMintableERC20Factory's initializer slot spacing
/// @notice Spacer to avoid packing into the initializer slot
bytes30 private spacer_0_2_30;
/// @notice Address of the StandardBridge on this chain.
/// @custom:network-specific
address public bridge;
/// @notice Mapping of local token address to remote token address.
/// This is used to keep track of the token deployments.
mapping(address => address) public deployments;
/// @notice Reserve extra slots in the storage layout for future upgrades.
/// A gap size of 48 was chosen here, so that the first slot used in a child contract
/// would be a multiple of 50.
uint256[48] private __gap;
/// @custom:legacy
/// @notice Emitted whenever a new OptimismMintableERC20 is created. Legacy version of the newer
/// OptimismMintableERC20Created event. We recommend relying on that event instead.
/// @param remoteToken Address of the token on the remote chain.
/// @param localToken Address of the created token on the local chain.
event StandardL2TokenCreated(address indexed remoteToken, address indexed localToken);
/// @notice Emitted whenever a new OptimismMintableERC20 is created.
/// @param localToken Address of the created token on the local chain.
/// @param remoteToken Address of the corresponding token on the remote chain.
/// @param deployer Address of the account that deployed the token.
event OptimismMintableERC20Created(address indexed localToken, address indexed remoteToken, address deployer);
/// @notice The semver MUST be bumped any time that there is a change in
/// the OptimismMintableERC20 token contract since this contract
/// is responsible for deploying OptimismMintableERC20 contracts.
/// @notice Semantic version.
/// @custom:semver 1.11.0
string public constant version = "1.11.0";
/// @notice Constructs the OptimismMintableERC20Factory contract.
constructor() {
_disableInitializers();
}
/// @notice Initializes the contract.
/// @param _bridge Address of the StandardBridge on this chain.
function initialize(address _bridge) external initializer {
_assertOnlyProxyAdminOrProxyAdminOwner();
bridge = _bridge;
}
/// @notice Getter function for the address of the StandardBridge on this chain.
/// Public getter is legacy and will be removed in the future. Use `bridge` instead.
/// @return Address of the StandardBridge on this chain.
/// @custom:legacy
function BRIDGE() external view returns (address) {
return bridge;
}
/// @custom:legacy
/// @notice Creates an instance of the OptimismMintableERC20 contract. Legacy version of the
/// newer createOptimismMintableERC20 function, which has a more intuitive name.
/// @param _remoteToken Address of the token on the remote chain.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
/// @return Address of the newly created token.
function createStandardL2Token(
address _remoteToken,
string memory _name,
string memory _symbol
)
external
returns (address)
{
return createOptimismMintableERC20(_remoteToken, _name, _symbol);
}
/// @notice Creates an instance of the OptimismMintableERC20 contract.
/// @param _remoteToken Address of the token on the remote chain.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
/// @return Address of the newly created token.
function createOptimismMintableERC20(
address _remoteToken,
string memory _name,
string memory _symbol
)
public
returns (address)
{
return createOptimismMintableERC20WithDecimals(_remoteToken, _name, _symbol, 18);
}
/// @notice Creates an instance of the OptimismMintableERC20 contract, with specified decimals.
/// @param _remoteToken Address of the token on the remote chain.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
/// @param _decimals ERC20 decimals
/// @return Address of the newly created token.
function createOptimismMintableERC20WithDecimals(
address _remoteToken,
string memory _name,
string memory _symbol,
uint8 _decimals
)
public
returns (address)
{
require(_remoteToken != address(0), "OptimismMintableERC20Factory: must provide remote token address");
bytes32 salt = keccak256(abi.encode(_remoteToken, _name, _symbol, _decimals));
address localToken =
address(new OptimismMintableERC20{ salt: salt }(bridge, _remoteToken, _name, _symbol, _decimals));
deployments[localToken] = _remoteToken;
// Emit the old event too for legacy support.
emit StandardL2TokenCreated(_remoteToken, localToken);
// Emit the updated event. The arguments here differ from the legacy event, but
// are consistent with the ordering used in StandardBridge events.
emit OptimismMintableERC20Created(localToken, _remoteToken, msg.sender);
return localToken;
}
}