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 all 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
54 changes: 9 additions & 45 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
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.
/// We can simplify the code since we no longer need to maintain upgradability with Hekla.
abstract contract EssentialContract_ is EssentialContract {
uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable;
}
dantaik marked this conversation as resolved.
Show resolved Hide resolved

/// @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 +44,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 +84,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);
}
}
40 changes: 13 additions & 27 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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
/// We can simplify the code since we no longer need to maintain upgradability with Hekla.
abstract contract BridgedERC20Base_ is BridgedERC20Base {
uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable;
}

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

Expand All @@ -20,7 +27,7 @@ contract BridgedERC20 is BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesU
uint256 public srcChainId;

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

uint256[47] private __gap;

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

Expand Down Expand Up @@ -85,38 +91,18 @@ contract BridgedERC20 is BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesU
return (srcToken, srcChainId);
}

/// @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, BridgedERC20Base)
override(BridgedERC20Base, ERC20VotesUpgradeable)
{
return super._mint(_to, _amount);
}
Expand All @@ -126,7 +112,7 @@ contract BridgedERC20 is BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesU
uint256 _amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable, BridgedERC20Base)
override(BridgedERC20Base, ERC20VotesUpgradeable)
{
return super._burn(_from, _amount);
}
Expand Down
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