Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
7abe4d12
Commit
7abe4d12
authored
Aug 12, 2023
by
Noah Citron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use deterministic deployment for OptimismMintableERC20Factory
parent
be461bd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
OptimismMintableERC20Factory.sol
...ts-bedrock/src/universal/OptimismMintableERC20Factory.sol
+2
-1
OptimismMintableERC20Factory.t.sol
...contracts-bedrock/test/OptimismMintableERC20Factory.t.sol
+20
-9
No files found.
packages/contracts-bedrock/src/universal/OptimismMintableERC20Factory.sol
View file @
7abe4d12
...
...
@@ -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);
...
...
packages/contracts-bedrock/test/OptimismMintableERC20Factory.t.sol
View file @
7abe4d12
// 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_
succeed
s() external {
function test_createStandardL2Token_sameTwice_
revert
s() 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)));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment