Skip to content
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(protocol): remove ERC20SnapshotUpgradeable from TaikoToken and BrigedERC20 tokens #16809

Merged
merged 8 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 8 additions & 45 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
dantaik marked this conversation as resolved.
Show resolved Hide resolved
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import "../common/EssentialContract.sol";
import "../common/LibStrings.sol";

/// @notice TaikoToken was `EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`.
/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent
/// contract list.
abstract contract EssentialContract_ is EssentialContract {
uint256[50] private __gap;
}

/// @title TaikoToken
/// @notice The TaikoToken (TKO), in the protocol is used for prover collateral
/// in the form of bonds. It is an ERC20 token with 18 decimal places of
/// precision.
/// @dev Labeled in AddressResolver as "taiko_token"
/// @custom:security-contact [email protected]
contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable {
contract TaikoToken is EssentialContract_, ERC20VotesUpgradeable {
uint256[50] private __gap;

error TKO_INVALID_ADDR();
Expand All @@ -37,7 +43,6 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
__Essential_init(_owner, _addressManager);
__Context_init_unchained();
__ERC20_init(_name, _symbol);
__ERC20Snapshot_init();
__ERC20Votes_init();
__ERC20Permit_init(_name);

Expand Down Expand Up @@ -78,46 +83,4 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
if (_to == address(this)) revert TKO_INVALID_ADDR();
return super.transferFrom(_from, _to, _amount);
}

function _beforeTokenTransfer(
address _from,
address _to,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20SnapshotUpgradeable)
{
return super._beforeTokenTransfer(_from, _to, _amount);
}

function _afterTokenTransfer(
address _from,
address _to,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
return super._afterTokenTransfer(_from, _to, _amount);
}

function _mint(
address _to,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
return super._mint(_to, _amount);
}

function _burn(
address _from,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
return super._burn(_from, _amount);
}
}
82 changes: 13 additions & 69 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import "./LibBridgedToken.sol";
import "./BridgedERC20Base.sol";

/// @notice BridgedERC20 was `BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`.
/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent
/// contract list.
dantaik marked this conversation as resolved.
Show resolved Hide resolved
abstract contract BridgedERC20Base_ is BridgedERC20Base {
uint256[50] private __gap;
}

/// @title BridgedERC20
/// @notice An upgradeable ERC20 contract that represents tokens bridged from
/// another chain.
/// @custom:security-contact [email protected]
contract BridgedERC20 is
BridgedERC20Base,
IERC20MetadataUpgradeable,
ERC20SnapshotUpgradeable,
ERC20VotesUpgradeable
{
contract BridgedERC20 is BridgedERC20Base_, ERC20VotesUpgradeable {
/// @dev Slot 1.
address public srcToken;

Expand All @@ -26,7 +26,7 @@ contract BridgedERC20 is
uint256 public srcChainId;

/// @dev Slot 3.
address public snapshooter;
address private __deprecated1;

uint256[47] private __gap;

Expand Down Expand Up @@ -56,7 +56,6 @@ contract BridgedERC20 is
LibBridgedToken.validateInputs(_srcToken, _srcChainId, _symbol, _name);
__Essential_init(_owner, _addressManager);
__ERC20_init(_name, _symbol);
__ERC20Snapshot_init();
__ERC20Votes_init();
__ERC20Permit_init(_name);

Expand All @@ -68,34 +67,19 @@ contract BridgedERC20 is

/// @notice Gets the name of the token.
/// @return The name.
function name()
public
view
override(ERC20Upgradeable, IERC20MetadataUpgradeable)
returns (string memory)
{
function name() public view override returns (string memory) {
return LibBridgedToken.buildName(super.name(), srcChainId);
}

/// @notice Gets the symbol of the bridged token.
/// @return The symbol.
function symbol()
public
view
override(ERC20Upgradeable, IERC20MetadataUpgradeable)
returns (string memory)
{
function symbol() public view override returns (string memory) {
return LibBridgedToken.buildSymbol(super.symbol());
}

/// @notice Gets the number of decimal places of the token.
/// @return The number of decimal places of the token.
function decimals()
public
view
override(ERC20Upgradeable, IERC20MetadataUpgradeable)
returns (uint8)
{
function decimals() public view override returns (uint8) {
return __srcDecimals;
}

Expand All @@ -114,49 +98,9 @@ contract BridgedERC20 is
return _burn(_from, _amount);
}

/// @dev For ERC20SnapshotUpgradeable and ERC20VotesUpgradeable, need to implement the following
/// functions
function _beforeTokenTransfer(
address _from,
address _to,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20SnapshotUpgradeable)
{
function _beforeTokenTransfer(address _from, address _to, uint256 _amount) internal override {
if (_to == address(this)) revert BTOKEN_CANNOT_RECEIVE();
if (paused()) revert INVALID_PAUSE_STATUS();
return super._beforeTokenTransfer(_from, _to, _amount);
}

function _afterTokenTransfer(
address _from,
address _to,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
return super._afterTokenTransfer(_from, _to, _amount);
}

function _mint(
address _to,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
return super._mint(_to, _amount);
}

function _burn(
address _from,
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
return super._burn(_from, _amount);
}
}
4 changes: 2 additions & 2 deletions packages/protocol/contracts/tokenvault/BridgedERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable {

/// @notice Gets the name of the token.
/// @return The name.
function name() public view override(ERC721Upgradeable) returns (string memory) {
function name() public view override returns (string memory) {
return LibBridgedToken.buildName(super.name(), srcChainId);
}

/// @notice Gets the symbol of the bridged token.
/// @return The symbol.
function symbol() public view override(ERC721Upgradeable) returns (string memory) {
function symbol() public view override returns (string memory) {
return LibBridgedToken.buildSymbol(super.symbol());
}

Expand Down
Loading