forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rename mint/burn and add SuperchainERC20 (#74)
* refactor: rename mint and burn functions on superchain erc20 * chore: rename optimism superchain erc20 to superchain erc20 * feat: create optimism superchain erc20 contract * chore: update natspec and errors * fix: superchain erc20 tests * refactor: make superchain erc20 abstract * refactor: move storage and erc20 metadata functions to implementation * chore: update interfaces * chore: update superchain erc20 events * fix: tests * fix: natspecs * fix: add semmver lock and snapshots * fix: remove unused imports * fix: natspecs --------- Co-authored-by: 0xDiscotech <[email protected]>
- Loading branch information
1 parent
07c9c77
commit d9bdad1
Showing
17 changed files
with
445 additions
and
126 deletions.
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
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.