Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/contracts-bedrock/src/L2/SuperchainERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ contract SuperchainERC20 is ISuperchainERC20, ERC20, ISemver {
/// @notice Decimals of the token
uint8 private immutable DECIMALS;

/// @notice Address of the corresponding version of this token on the L1.
address public immutable L1_TOKEN;

/// @notice Emitted whenever tokens are minted for an account.
/// @param account Address of the account tokens are being minted for.
/// @param amount Amount of tokens minted.
Expand Down Expand Up @@ -65,10 +68,12 @@ contract SuperchainERC20 is ISuperchainERC20, ERC20, ISemver {
/// @custom:semver 1.0.0
string public constant version = "1.0.0";

/// @param _l1Token Address of the corresponding L1 token.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
/// @param _decimals ERC20 decimals.
constructor(string memory _name, string memory _symbol, uint8 _decimals) ERC20(_name, _symbol) {
constructor(address _l1Token, string memory _name, string memory _symbol, uint8 _decimals) ERC20(_name, _symbol) {
L1_TOKEN = _l1Token;
DECIMALS = _decimals;
}

Expand Down
12 changes: 10 additions & 2 deletions packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ISuperchainERC20 } from "src/L2/ISuperchainERC20.sol";
/// @dev Contract for testing the SuperchainERC20 contract.
contract SuperchainERC20Test is Test {
address internal constant ZERO_ADDRESS = address(0);
address internal constant L1_TOKEN = address(0x123);
string internal constant NAME = "SuperchainERC20";
string internal constant SYMBOL = "SCE";
uint8 internal constant DECIMALS = 18;
Expand All @@ -36,7 +37,7 @@ contract SuperchainERC20Test is Test {

/// @dev Sets up the test suite.
function setUp() public {
superchainERC20 = new SuperchainERC20(NAME, SYMBOL, DECIMALS);
superchainERC20 = new SuperchainERC20(L1_TOKEN, NAME, SYMBOL, DECIMALS);
}

/// @dev Helper function to setup a mock and expect a call to it.
Expand All @@ -50,6 +51,7 @@ contract SuperchainERC20Test is Test {
assertEq(superchainERC20.name(), NAME);
assertEq(superchainERC20.symbol(), SYMBOL);
assertEq(superchainERC20.decimals(), DECIMALS);
assertEq(superchainERC20.L1_TOKEN(), L1_TOKEN);
}

/// @dev Tests the `mint` function reverts when the caller is not the bridge.
Expand Down Expand Up @@ -284,7 +286,13 @@ contract SuperchainERC20Test is Test {

/// @dev Tests the `decimals` function always returns the correct value.
function testFuzz_decimals_succeeds(uint8 _decimals) public {
SuperchainERC20 _newSuperchainERC20 = new SuperchainERC20(NAME, SYMBOL, _decimals);
SuperchainERC20 _newSuperchainERC20 = new SuperchainERC20(L1_TOKEN, NAME, SYMBOL, _decimals);
assertEq(_newSuperchainERC20.decimals(), _decimals);
}

/// @dev Tests the `L1_TOKEN` function always returns the correct value.
function testFuzz_l1Token_succeeds(address _l1Token) public {
SuperchainERC20 _newSuperchainERC20 = new SuperchainERC20(_l1Token, NAME, SYMBOL, DECIMALS);
assertEq(_newSuperchainERC20.L1_TOKEN(), _l1Token);
}
}