From f20a02f048da1349269da2cc75b61cd8a3c8fd22 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:57:33 +0800 Subject: [PATCH] feat(protocol): remove ERC20SnapshotUpgradeable from TaikoToken and BrigedERC20 tokens (#16809) --- packages/protocol/contracts/L1/TaikoToken.sol | 54 ++++--------------- .../contracts/tokenvault/BridgedERC20.sol | 40 +++++--------- .../contracts/tokenvault/BridgedERC721.sol | 4 +- 3 files changed, 24 insertions(+), 74 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index 5363ce6afb6..6557e040ee7 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -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"; 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; +} + /// @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 security@taiko.xyz -contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable { +contract TaikoToken is EssentialContract_, ERC20VotesUpgradeable { uint256[50] private __gap; error TKO_INVALID_ADDR(); @@ -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); @@ -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); - } } diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index 7dac1c3b4b1..be981e07593 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -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. +/// 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 security@taiko.xyz -contract BridgedERC20 is BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable { +contract BridgedERC20 is BridgedERC20Base_, ERC20VotesUpgradeable { /// @dev Slot 1. address public srcToken; @@ -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; @@ -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); @@ -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); } @@ -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); } diff --git a/packages/protocol/contracts/tokenvault/BridgedERC721.sol b/packages/protocol/contracts/tokenvault/BridgedERC721.sol index 57ed0aacf9a..3d9eb0c1968 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC721.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC721.sol @@ -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()); }