github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/universal/OptimismMintableERC20Factory.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { OptimismMintableERC20 } from "src/universal/OptimismMintableERC20.sol"; 5 import { ISemver } from "src/universal/ISemver.sol"; 6 import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; 7 8 /// @custom:proxied 9 /// @custom:predeployed 0x4200000000000000000000000000000000000012 10 /// @title OptimismMintableERC20Factory 11 /// @notice OptimismMintableERC20Factory is a factory contract that generates OptimismMintableERC20 12 /// contracts on the network it's deployed to. Simplifies the deployment process for users 13 /// who may be less familiar with deploying smart contracts. Designed to be backwards 14 /// compatible with the older StandardL2ERC20Factory contract. 15 contract OptimismMintableERC20Factory is ISemver, Initializable { 16 /// @custom:spacer OptimismMintableERC20Factory's initializer slot spacing 17 /// @notice Spacer to avoid packing into the initializer slot 18 bytes30 private spacer_0_2_30; 19 20 /// @notice Address of the StandardBridge on this chain. 21 /// @custom:network-specific 22 address public bridge; 23 24 /// @notice Reserve extra slots in the storage layout for future upgrades. 25 /// A gap size of 49 was chosen here, so that the first slot used in a child contract 26 /// would be 1 plus a multiple of 50. 27 uint256[49] private __gap; 28 29 /// @custom:legacy 30 /// @notice Emitted whenever a new OptimismMintableERC20 is created. Legacy version of the newer 31 /// OptimismMintableERC20Created event. We recommend relying on that event instead. 32 /// @param remoteToken Address of the token on the remote chain. 33 /// @param localToken Address of the created token on the local chain. 34 event StandardL2TokenCreated(address indexed remoteToken, address indexed localToken); 35 36 /// @notice Emitted whenever a new OptimismMintableERC20 is created. 37 /// @param localToken Address of the created token on the local chain. 38 /// @param remoteToken Address of the corresponding token on the remote chain. 39 /// @param deployer Address of the account that deployed the token. 40 event OptimismMintableERC20Created(address indexed localToken, address indexed remoteToken, address deployer); 41 42 /// @notice The semver MUST be bumped any time that there is a change in 43 /// the OptimismMintableERC20 token contract since this contract 44 /// is responsible for deploying OptimismMintableERC20 contracts. 45 /// @notice Semantic version. 46 /// @custom:semver 1.9.0 47 string public constant version = "1.9.0"; 48 49 /// @notice Constructs the OptimismMintableERC20Factory contract. 50 constructor() { 51 initialize({ _bridge: address(0) }); 52 } 53 54 /// @notice Initializes the contract. 55 /// @param _bridge Address of the StandardBridge on this chain. 56 function initialize(address _bridge) public initializer { 57 bridge = _bridge; 58 } 59 60 /// @notice Getter function for the address of the StandardBridge on this chain. 61 /// Public getter is legacy and will be removed in the future. Use `bridge` instead. 62 /// @return Address of the StandardBridge on this chain. 63 /// @custom:legacy 64 function BRIDGE() external view returns (address) { 65 return bridge; 66 } 67 68 /// @custom:legacy 69 /// @notice Creates an instance of the OptimismMintableERC20 contract. Legacy version of the 70 /// newer createOptimismMintableERC20 function, which has a more intuitive name. 71 /// @param _remoteToken Address of the token on the remote chain. 72 /// @param _name ERC20 name. 73 /// @param _symbol ERC20 symbol. 74 /// @return Address of the newly created token. 75 function createStandardL2Token( 76 address _remoteToken, 77 string memory _name, 78 string memory _symbol 79 ) 80 external 81 returns (address) 82 { 83 return createOptimismMintableERC20(_remoteToken, _name, _symbol); 84 } 85 86 /// @notice Creates an instance of the OptimismMintableERC20 contract. 87 /// @param _remoteToken Address of the token on the remote chain. 88 /// @param _name ERC20 name. 89 /// @param _symbol ERC20 symbol. 90 /// @return Address of the newly created token. 91 function createOptimismMintableERC20( 92 address _remoteToken, 93 string memory _name, 94 string memory _symbol 95 ) 96 public 97 returns (address) 98 { 99 return createOptimismMintableERC20WithDecimals(_remoteToken, _name, _symbol, 18); 100 } 101 102 /// @notice Creates an instance of the OptimismMintableERC20 contract, with specified decimals. 103 /// @param _remoteToken Address of the token on the remote chain. 104 /// @param _name ERC20 name. 105 /// @param _symbol ERC20 symbol. 106 /// @param _decimals ERC20 decimals 107 /// @return Address of the newly created token. 108 function createOptimismMintableERC20WithDecimals( 109 address _remoteToken, 110 string memory _name, 111 string memory _symbol, 112 uint8 _decimals 113 ) 114 public 115 returns (address) 116 { 117 require(_remoteToken != address(0), "OptimismMintableERC20Factory: must provide remote token address"); 118 119 bytes32 salt = keccak256(abi.encode(_remoteToken, _name, _symbol, _decimals)); 120 address localToken = 121 address(new OptimismMintableERC20{ salt: salt }(bridge, _remoteToken, _name, _symbol, _decimals)); 122 123 // Emit the old event too for legacy support. 124 emit StandardL2TokenCreated(_remoteToken, localToken); 125 126 // Emit the updated event. The arguments here differ from the legacy event, but 127 // are consistent with the ordering used in StandardBridge events. 128 emit OptimismMintableERC20Created(localToken, _remoteToken, msg.sender); 129 130 return localToken; 131 } 132 }