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: rename mint/burn and add SuperchainERC20 #74
Merged
agusduha
merged 10 commits into
sc/superchain-erc20-redesign
from
chore/rename-superchainerc20
Oct 1, 2024
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1f796b
refactor: rename mint and burn functions on superchain erc20
0xDiscotech ff47523
feat: create optimism superchain erc20 contract
0xDiscotech 5c31ce7
fix: superchain erc20 tests
0xDiscotech 841101d
refactor: make superchain erc20 abstract
0xDiscotech ba100f8
chore: update superchain erc20 events
0xDiscotech 959bb90
fix: tests
0xDiscotech 0f1fc2c
fix: natspecs
agusduha f48a1a5
fix: add semmver lock and snapshots
agusduha 8965557
fix: remove unused imports
agusduha 8a94c49
fix: natspecs
agusduha 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
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,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import { ISuperchainERC20Extension } from "src/L2/interfaces/ISuperchainERC20.sol"; | ||
import { ISemver } from "src/universal/interfaces/ISemver.sol"; | ||
import { Predeploys } from "src/libraries/Predeploys.sol"; | ||
import { ERC20 } from "@solady/tokens/ERC20.sol"; | ||
|
||
/// @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. This construction allows the SuperchainERC20Bridge to | ||
/// burn and mint tokens. | ||
abstract contract SuperchainERC20 is ERC20, ISuperchainERC20Extension, ISemver { | ||
/// @notice A modifier that only allows the SuperchainERC20Bridge to call | ||
modifier onlySuperchainERC20Bridge() { | ||
if (msg.sender != Predeploys.SUPERCHAIN_ERC20_BRIDGE) revert OnlySuperchainERC20Bridge(); | ||
_; | ||
} | ||
|
||
/// @notice Semantic version. | ||
/// @custom:semver 1.0.0-beta.1 | ||
function version() external pure virtual returns (string memory) { | ||
return "1.0.0-beta.1"; | ||
} | ||
|
||
/// @notice Allows the SuperchainERC20Bridge to mint tokens. | ||
/// @param _to Address to mint tokens to. | ||
/// @param _amount Amount of tokens to mint. | ||
function __superchainMint(address _to, uint256 _amount) external virtual onlySuperchainERC20Bridge { | ||
if (_to == address(0)) revert ZeroAddress(); | ||
|
||
_mint(_to, _amount); | ||
|
||
emit SuperchainMint(_to, _amount); | ||
} | ||
|
||
/// @notice Allows the SuperchainERC20Bridge to burn tokens. | ||
/// @param _from Address to burn tokens from. | ||
/// @param _amount Amount of tokens to burn. | ||
function __superchainBurn(address _from, uint256 _amount) external virtual onlySuperchainERC20Bridge { | ||
if (_from == address(0)) revert ZeroAddress(); | ||
|
||
_burn(_from, _amount); | ||
|
||
emit SuperchainBurn(_from, _amount); | ||
} | ||
} |
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,22 +2,19 @@ | |||||||||
pragma solidity ^0.8.0; | ||||||||||
|
||||||||||
// Interfaces | ||||||||||
import { ISuperchainERC20, ISuperchainERC20Extension } from "src/L2/interfaces/ISuperchainERC20.sol"; | ||||||||||
import { IERC20Solady } from "src/vendor/interfaces/IERC20Solady.sol"; | ||||||||||
|
||||||||||
/// @title IOptimismSuperchainERC20Errors | ||||||||||
/// @notice Interface containing the errors added in the OptimismSuperchainERC20 implementation. | ||||||||||
/// @title ISuperchainERC20Errors | ||||||||||
/// @notice Interface containing the errors added in the SuperchainERC20 implementation. | ||||||||||
interface IOptimismSuperchainERC20Errors { | ||||||||||
/// @notice Thrown when attempting to perform an operation and the account is the zero address. | ||||||||||
error ZeroAddress(); | ||||||||||
|
||||||||||
/// @notice Thrown when attempting to mint or burn tokens and the function caller is not the StandardBridge or the | ||||||||||
/// SuperchainERC20Bridge. | ||||||||||
error OnlyAuthorizedBridge(); | ||||||||||
/// @notice Thrown when attempting to mint or burn tokens and the function caller is not the L2StandardBridge | ||||||||||
error OnlyL2StandardBridge(); | ||||||||||
} | ||||||||||
|
||||||||||
/// @title IOptimismSuperchainERC20Extension | ||||||||||
/// @notice This interface is available on the OptimismSuperchainERC20 contract. | ||||||||||
interface IOptimismSuperchainERC20Extension is IOptimismSuperchainERC20Errors { | ||||||||||
/// @title ISuperchainERC20Extension | ||||||||||
/// @notice This interface is available on the SuperchainERC20 contract. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
interface IOptimismSuperchainERC20Extension is ISuperchainERC20Extension, IOptimismSuperchainERC20Errors { | ||||||||||
/// @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. | ||||||||||
|
@@ -42,6 +39,6 @@ interface IOptimismSuperchainERC20Extension is IOptimismSuperchainERC20Errors { | |||||||||
function remoteToken() external view returns (address); | ||||||||||
} | ||||||||||
|
||||||||||
/// @title IOptimismSuperchainERC20 | ||||||||||
/// @notice Combines Solady's ERC20 interface with the OptimismSuperchainERC20Extension interface. | ||||||||||
/// @title ISuperchainERC20 | ||||||||||
/// @notice Combines Solady's ERC20 interface with the SuperchainERC20Extension interface. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
interface IOptimismSuperchainERC20 is IERC20Solady, IOptimismSuperchainERC20Extension { } |
43 changes: 43 additions & 0 deletions
43
packages/contracts-bedrock/src/L2/interfaces/ISuperchainERC20.sol
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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// Interfaces | ||
import { IERC20Solady } from "src/vendor/interfaces/IERC20Solady.sol"; | ||
|
||
/// @title ISuperchainERC20Errors | ||
/// @notice Interface containing the errors added in the SuperchainERC20 implementation. | ||
interface ISuperchainERC20Errors { | ||
/// @notice Thrown when attempting to perform an operation and the account is the zero address. | ||
error ZeroAddress(); | ||
|
||
/// @notice Thrown when attempting to mint or burn tokens and the function caller is not the SuperchainERC20Bridge. | ||
error OnlySuperchainERC20Bridge(); | ||
} | ||
|
||
/// @title ISuperchainERC20Extension | ||
/// @notice This interface is available on the SuperchainERC20 contract. | ||
interface ISuperchainERC20Extension is ISuperchainERC20Errors { | ||
/// @notice Emitted whenever tokens are minted for by the SuperchainERC20Bridge. | ||
/// @param account Address of the account tokens are being minted for. | ||
/// @param amount Amount of tokens minted. | ||
event SuperchainMint(address indexed account, uint256 amount); | ||
|
||
/// @notice Emitted whenever tokens are burned by the SuperchainERC20Bridge. | ||
/// @param account Address of the account tokens are being burned from. | ||
/// @param amount Amount of tokens burned. | ||
event SuperchainBurn(address indexed account, uint256 amount); | ||
|
||
/// @notice Allows the SuperchainERC20Bridge to mint tokens. | ||
/// @param _to Address to mint tokens to. | ||
/// @param _amount Amount of tokens to mint. | ||
function __superchainMint(address _to, uint256 _amount) external; | ||
|
||
/// @notice Allows the SuperchainERC20Bridge to burn tokens. | ||
/// @param _from Address to burn tokens from. | ||
/// @param _amount Amount of tokens to burn. | ||
function __superchainBurn(address _from, uint256 _amount) external; | ||
} | ||
|
||
/// @title ISuperchainERC20 | ||
/// @notice Combines Solady's ERC20 interface with the SuperchainERC20Extension interface. | ||
interface ISuperchainERC20 is IERC20Solady, ISuperchainERC20Extension { } |
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.