github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/legacy/LegacyMintableERC20.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 import { ILegacyMintableERC20 } from "src/universal/OptimismMintableERC20.sol"; 6 7 /// @title LegacyMintableERC20 8 /// @notice The legacy implementation of the OptimismMintableERC20. This 9 /// contract is deprecated and should no longer be used. 10 contract LegacyMintableERC20 is ILegacyMintableERC20, ERC20 { 11 /// @notice Emitted when the token is minted by the bridge. 12 event Mint(address indexed _account, uint256 _amount); 13 14 /// @notice Emitted when a token is burned by the bridge. 15 event Burn(address indexed _account, uint256 _amount); 16 17 /// @notice The token on the remote domain. 18 address public l1Token; 19 20 /// @notice The local bridge. 21 address public l2Bridge; 22 23 /// @param _l2Bridge Address of the L2 standard bridge. 24 /// @param _l1Token Address of the corresponding L1 token. 25 /// @param _name ERC20 name. 26 /// @param _symbol ERC20 symbol. 27 constructor( 28 address _l2Bridge, 29 address _l1Token, 30 string memory _name, 31 string memory _symbol 32 ) 33 ERC20(_name, _symbol) 34 { 35 l1Token = _l1Token; 36 l2Bridge = _l2Bridge; 37 } 38 39 /// @notice Modifier that requires the contract was called by the bridge. 40 modifier onlyL2Bridge() { 41 require(msg.sender == l2Bridge, "Only L2 Bridge can mint and burn"); 42 _; 43 } 44 45 /// @notice EIP165 implementation. 46 function supportsInterface(bytes4 _interfaceId) public pure returns (bool) { 47 bytes4 firstSupportedInterface = bytes4(keccak256("supportsInterface(bytes4)")); // ERC165 48 bytes4 secondSupportedInterface = ILegacyMintableERC20.l1Token.selector ^ ILegacyMintableERC20.mint.selector 49 ^ ILegacyMintableERC20.burn.selector; 50 return _interfaceId == firstSupportedInterface || _interfaceId == secondSupportedInterface; 51 } 52 53 /// @notice Only the bridge can mint tokens. 54 /// @param _to The account receiving tokens. 55 /// @param _amount The amount of tokens to receive. 56 function mint(address _to, uint256 _amount) public virtual onlyL2Bridge { 57 _mint(_to, _amount); 58 59 emit Mint(_to, _amount); 60 } 61 62 /// @notice Only the bridge can burn tokens. 63 /// @param _from The account having tokens burnt. 64 /// @param _amount The amount of tokens being burnt. 65 function burn(address _from, uint256 _amount) public virtual onlyL2Bridge { 66 _burn(_from, _amount); 67 68 emit Burn(_from, _amount); 69 } 70 }