forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: abstract baseline #55
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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 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 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 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,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import { ISuperchainERC20Extensions } from "src/L2/interfaces/ISuperchainERC20.sol"; | ||
import { ERC20 } from "@solady/tokens/ERC20.sol"; | ||
import { IL2ToL2CrossDomainMessenger } from "src/L2/interfaces/IL2ToL2CrossDomainMessenger.sol"; | ||
import { Predeploys } from "src/libraries/Predeploys.sol"; | ||
import { ZeroAddress } from "src/libraries/errors/CommonErrors.sol"; | ||
|
||
/// @notice Thrown when attempting to relay a message and the function caller (msg.sender) is not | ||
/// L2ToL2CrossDomainMessenger. | ||
error CallerNotL2ToL2CrossDomainMessenger(); | ||
|
||
/// @notice Thrown when attempting to relay a message and the cross domain message sender is not this SuperchainERC20. | ||
error InvalidCrossDomainSender(); | ||
|
||
/// @title SuperchainERC20 | ||
/// @notice SuperchainERC20 is a standard extension of the base ERC20 token contract that unifies ERC20 token | ||
/// bridging to make it fungible across the Superchain. It builds on top of the L2ToL2CrossDomainMessenger for | ||
/// both replay protection and domain binding. | ||
abstract contract SuperchainERC20 is ISuperchainERC20Extensions, ERC20 { | ||
/// @notice Address of the L2ToL2CrossDomainMessenger Predeploy. | ||
address internal constant MESSENGER = Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER; | ||
|
||
/// @notice Sends tokens to some target address on another chain. | ||
/// @param _to Address to send tokens to. | ||
/// @param _amount Amount of tokens to send. | ||
/// @param _chainId Chain ID of the destination chain. | ||
function sendERC20(address _to, uint256 _amount, uint256 _chainId) external virtual { | ||
if (_to == address(0)) revert ZeroAddress(); | ||
|
||
_burn(msg.sender, _amount); | ||
|
||
bytes memory _message = abi.encodeCall(this.relayERC20, (msg.sender, _to, _amount)); | ||
IL2ToL2CrossDomainMessenger(MESSENGER).sendMessage(_chainId, address(this), _message); | ||
|
||
emit SendERC20(msg.sender, _to, _amount, _chainId); | ||
} | ||
|
||
/// @notice Relays tokens received from another chain. | ||
/// @param _from Address of the msg.sender of sendERC20 on the source chain. | ||
/// @param _to Address to relay tokens to. | ||
/// @param _amount Amount of tokens to relay. | ||
function relayERC20(address _from, address _to, uint256 _amount) external virtual { | ||
if (msg.sender != MESSENGER) revert CallerNotL2ToL2CrossDomainMessenger(); | ||
|
||
if (IL2ToL2CrossDomainMessenger(MESSENGER).crossDomainMessageSender() != address(this)) { | ||
revert InvalidCrossDomainSender(); | ||
} | ||
|
||
uint256 source = IL2ToL2CrossDomainMessenger(MESSENGER).crossDomainMessageSource(); | ||
|
||
_mint(_to, _amount); | ||
|
||
emit RelayERC20(_from, _to, _amount, source); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
remember to add the comment and open the discussion around this one