forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add superchain erc20 factory #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/contracts-bedrock/src/L2/SuperchainERC20Factory.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.25; | ||
|
|
||
| import { ISemver } from "src/universal/ISemver.sol"; | ||
| import { Predeploys } from "src/libraries/Predeploys.sol"; | ||
| import { BeaconProxy } from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; | ||
| import { CREATE3 } from "@rari-capital/solmate/src/utils/CREATE3.sol"; | ||
|
|
||
| /// @custom:proxied | ||
| /// @title SuperchainERC20Factory | ||
| /// @notice SuperchainERC20Factory is a factory contract that deploys SuperchainERC20 Beacon Proxies using CREATE3. | ||
| contract SuperchainERC20Factory is ISemver { | ||
| /// @notice Mapping of the deployed SuperchainERC20 to the remote token address. | ||
| mapping(address superchainToken => address remoteToken) public deployments; | ||
|
|
||
| /// @notice Emitted when a SuperchainERC20 is deployed. | ||
| /// @param superchainERC20 Address of the SuperchainERC20 deployment. | ||
| /// @param remoteToken Address of the remote token. | ||
| /// @param name Name of the SuperchainERC20. | ||
| /// @param symbol Symbol of the SuperchainERC20. | ||
| /// @param decimals Decimals of the SuperchainERC20. | ||
| event SuperchainERC20Deployed( | ||
| address indexed superchainERC20, address indexed remoteToken, string name, string symbol, uint8 decimals | ||
| ); | ||
|
|
||
| /// @notice Semantic version. | ||
| /// @custom:semver 1.0.0 | ||
| string public constant version = "1.0.0"; | ||
|
|
||
| /// @notice Deploys a SuperchainERC20 Beacon Proxy using CREATE3. | ||
| /// @param _remoteToken Address of the remote token. | ||
| /// @param _name Name of the SuperchainERC20. | ||
| /// @param _symbol Symbol of the SuperchainERC20. | ||
| /// @param _decimals Decimals of the SuperchainERC20. | ||
| /// @return _superchainERC20 Address of the SuperchainERC20 deployment. | ||
| function deploy( | ||
| address _remoteToken, | ||
| string memory _name, | ||
| string memory _symbol, | ||
| uint8 _decimals | ||
| ) | ||
| external | ||
| returns (address _superchainERC20) | ||
| { | ||
| // Encode the BeaconProxy creation code with the beacon contract address and metadata | ||
| bytes memory _creationCode = abi.encodePacked( | ||
| type(BeaconProxy).creationCode, | ||
| abi.encode(Predeploys.SUPERCHAIN_ERC20_BEACON, abi.encode(_remoteToken, _name, _symbol, _decimals)) | ||
| ); | ||
|
|
||
| // Use CREATE3 for deterministic deployment | ||
| bytes32 _salt = keccak256(abi.encode(_remoteToken, _name, _symbol, _decimals)); | ||
| _superchainERC20 = CREATE3.deploy({ salt: _salt, creationCode: _creationCode, value: 0 }); | ||
|
|
||
| // Store SuperchainERC20 and remote token addresses | ||
| deployments[_superchainERC20] = _remoteToken; | ||
|
|
||
| emit SuperchainERC20Deployed(_superchainERC20, _remoteToken, _name, _symbol, _decimals); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this repo is incorrect, use this one: https://github.com/transmissions11/solmate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the repo remapping is using
'@rari-capital/solmate/=lib/solmate', should we add another solmate lib?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also use CREATE3 from
@solady/=lib/solady/srcThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm leave it then, apparently this links to t11s repo somehow