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): Add votes and snapshot plugin #15732

Merged
merged 1 commit into from
Feb 10, 2024
Merged
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
76 changes: 69 additions & 7 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,39 @@ pragma solidity 0.8.24;
import
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import "lib/openzeppelin-contracts/contracts/utils/Strings.sol";

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

/// @title BridgedERC20
/// @notice An upgradeable ERC20 contract that represents tokens bridged from
/// another chain.
contract BridgedERC20 is BridgedERC20Base, IERC20MetadataUpgradeable, ERC20Upgradeable {
contract BridgedERC20 is
BridgedERC20Base,
IERC20MetadataUpgradeable,
ERC20SnapshotUpgradeable,
ERC20VotesUpgradeable
{
address public srcToken; // slot 1
uint8 private srcDecimals;
uint256 public srcChainId; // slot 2
address public snapshooter; // slot 3

uint256[48] private __gap;
uint256[47] private __gap;

error BTOKEN_CANNOT_RECEIVE();
error BTOKEN_INVALID_PARAMS();
error BTOKEN_UNAUTHORIZED();


modifier onlyOwnerOrSnapshooter {
if (msg.sender != owner() && msg.sender != snapshooter)
revert BTOKEN_UNAUTHORIZED();
_;
}
/// @notice Initializes the contract.
/// @dev Different BridgedERC20 Contract is deployed per unique _srcToken
/// (e.g., one for USDC, one for USDT, etc.).
Expand Down Expand Up @@ -65,13 +81,26 @@ contract BridgedERC20 is BridgedERC20Base, IERC20MetadataUpgradeable, ERC20Upgra
// Initialize OwnerUUPSUpgradable and ERC20Upgradeable
__Essential_init(_addressManager);
__ERC20_init({ name_: _name, symbol_: _symbol });
__ERC20Snapshot_init();
__ERC20Votes_init();
__ERC20Permit_init(_name);

// Set contract properties
srcToken = _srcToken;
srcChainId = _srcChainId;
srcDecimals = _decimals;
}

/// @notice Set the snapshoter address.
function setSnapshoter(address _snapshooter) external onlyOwner {
snapshooter = _snapshooter;
}

/// @notice Creates a new token snapshot.
function snapshot() external onlyOwnerOrSnapshooter {
_snapshot();
}

/// @notice Gets the name of the token.
/// @return The name.
function name()
Expand Down Expand Up @@ -119,16 +148,49 @@ contract BridgedERC20 is BridgedERC20Base, IERC20MetadataUpgradeable, ERC20Upgra
_burn(from, amount);
}

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

function _afterTokenTransfer(
address from,
address to,
uint256 amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._afterTokenTransfer(from, to, amount);
}

function _mint(
address to,
uint256 amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._mint(to, amount);
}

function _burn(
address from,
uint256 amount
)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._burn(from, amount);
}
}
Loading