Commit 7abe4d12 authored by Noah Citron's avatar Noah Citron

feat: use deterministic deployment for OptimismMintableERC20Factory

parent be461bd0
......@@ -70,7 +70,8 @@ contract OptimismMintableERC20Factory is Semver {
{
require(_remoteToken != address(0), "OptimismMintableERC20Factory: must provide remote token address");
address localToken = address(new OptimismMintableERC20(BRIDGE, _remoteToken, _name, _symbol));
bytes32 salt = keccak256(abi.encode(_remoteToken, _name, _symbol));
address localToken = address(new OptimismMintableERC20{salt: salt}(BRIDGE, _remoteToken, _name, _symbol));
// Emit the old event too for legacy support.
emit StandardL2TokenCreated(_remoteToken, localToken);
......
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { OptimismMintableERC20 } from "../src/universal/OptimismMintableERC20.sol";
import { Bridge_Initializer } from "./CommonTest.t.sol";
import { LibRLP } from "./RLP.t.sol";
......@@ -18,7 +19,7 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
function test_createStandardL2Token_succeeds() external {
address remote = address(4);
address local = LibRLP.computeAddress(address(L2TokenFactory), 2);
address local = calculateTokenAddress(remote, "Beep", "BOOP");
vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated(remote, local);
......@@ -30,19 +31,13 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
}
function test_createStandardL2Token_sameTwice_succeeds() external {
function test_createStandardL2Token_sameTwice_reverts() external {
address remote = address(4);
vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
address local = LibRLP.computeAddress(address(L2TokenFactory), 3);
vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated(remote, local);
vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created(local, remote, alice);
vm.expectRevert();
vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
......@@ -53,4 +48,20 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
vm.expectRevert("OptimismMintableERC20Factory: must provide remote token address");
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
}
function calculateTokenAddress(
address _remote,
string memory _name,
string memory _symbol
)
internal
view
returns (address)
{
bytes memory constructorArgs = abi.encode(address(L2Bridge), _remote, _name, _symbol);
bytes memory bytecode = abi.encodePacked(type(OptimismMintableERC20).creationCode, constructorArgs);
bytes32 salt = keccak256(abi.encode(_remote, _name, _symbol));
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(L2TokenFactory), salt, keccak256(bytecode)));
return address(uint160(uint(hash)));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment