Skip to content

release: merge release-dev/elip5 token upgrade #1333

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
102 changes: 8 additions & 94 deletions src/contracts/token/BackingEigen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,24 @@ import "@openzeppelin-upgrades/contracts/token/ERC20/extensions/ERC20VotesUpgrad
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";

contract BackingEigen is OwnableUpgradeable, ERC20VotesUpgradeable {
/// CONSTANTS & IMMUTABLES
/// @notice the address of the wrapped Eigen token EIGEN
IERC20 public immutable EIGEN;

/// STORAGE
/// @dev Do not remove, deprecated storage.
/// @notice the timestamp after which transfer restrictions are disabled
uint256 public transferRestrictionsDisabledAfter;
uint256 internal __dreprecated_transferRestrictionsDisabledAfter;
/// @dev Do not remove, deprecated storage.
/// @notice mapping of addresses that are allowed to transfer tokens to any address
mapping(address => bool) public allowedFrom;
mapping(address => bool) internal __dreprecated_allowedFrom;
/// @dev Do not remove, deprecated storage.
/// @notice mapping of addresses that are allowed to receive tokens from any address
mapping(address => bool) public allowedTo;
mapping(address => bool) internal __dreprecated_allowedTo;

// @notice whether or not an address is allowed to mint new bEIGEN tokens
mapping(address => bool) public isMinter;

/// @notice event emitted when the allowedFrom status of an address is set
event SetAllowedFrom(address indexed from, bool isAllowedFrom);
/// @notice event emitted when the allowedTo status of an address is set
event SetAllowedTo(address indexed to, bool isAllowedTo);
/// @notice event emitted when the transfer restrictions are disabled
event TransferRestrictionsDisabled();
/// @notice event emitted when the EIGEN token is backed
event Backed();
// @notice event emitted when the `isMinter` mapping is modified
event IsMinterModified(address indexed minterAddress, bool newStatus);

constructor(
IERC20 _EIGEN
) {
EIGEN = _EIGEN;
constructor() {
_disableInitializers();
}

Expand Down Expand Up @@ -74,51 +63,6 @@ contract BackingEigen is OwnableUpgradeable, ERC20VotesUpgradeable {
__ERC20_init("Backing Eigen", "bEIGEN");
_transferOwnership(initialOwner);
__ERC20Permit_init("bEIGEN");

// set transfer restrictions to be disabled at type(uint256).max to be set down later
transferRestrictionsDisabledAfter = type(uint256).max;

// the EIGEN contract should be allowed to transfer tokens to any address for unwrapping
// likewise, anyone should be able to transfer bEIGEN to EIGEN for wrapping
_setAllowedFrom(address(EIGEN), true);
_setAllowedTo(address(EIGEN), true);

// Mint the entire supply of EIGEN - this is a one-time event that
// ensures bEIGEN fully backs EIGEN.
_mint(address(EIGEN), 1_673_646_668_284_660_000_000_000_000);
emit Backed();
}

/// EXTERNAL FUNCTIONS

/**
* @notice This function allows the owner to set the allowedFrom status of an address
* @param from the address whose allowedFrom status is being set
* @param isAllowedFrom the new allowedFrom status
*/
function setAllowedFrom(address from, bool isAllowedFrom) external onlyOwner {
_setAllowedFrom(from, isAllowedFrom);
}

/**
* @notice This function allows the owner to set the allowedTo status of an address
* @param to the address whose allowedTo status is being set
* @param isAllowedTo the new allowedTo status
*/
function setAllowedTo(address to, bool isAllowedTo) external onlyOwner {
_setAllowedTo(to, isAllowedTo);
}

/**
* @notice Allows the owner to disable transfer restrictions
*/
function disableTransferRestrictions() external onlyOwner {
require(
transferRestrictionsDisabledAfter == type(uint256).max,
"BackingEigen.disableTransferRestrictions: transfer restrictions are already disabled"
);
transferRestrictionsDisabledAfter = 0;
emit TransferRestrictionsDisabled();
}

/// VIEW FUNCTIONS
Expand All @@ -139,34 +83,4 @@ contract BackingEigen is OwnableUpgradeable, ERC20VotesUpgradeable {
function CLOCK_MODE() public pure override returns (string memory) {
return "mode=timestamp";
}

/// INTERNAL FUNCTIONS

function _setAllowedFrom(address from, bool isAllowedFrom) internal {
allowedFrom[from] = isAllowedFrom;
emit SetAllowedFrom(from, isAllowedFrom);
}

function _setAllowedTo(address to, bool isAllowedTo) internal {
allowedTo[to] = isAllowedTo;
emit SetAllowedTo(to, isAllowedTo);
}

/**
* @notice Overrides the beforeTokenTransfer function to enforce transfer restrictions
* @param from the address tokens are being transferred from
* @param to the address tokens are being transferred to
* @param amount the amount of tokens being transferred
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal override {
// if transfer restrictions are enabled
if (block.timestamp <= transferRestrictionsDisabledAfter) {
// if both from and to are not whitelisted
require(
allowedFrom[from] || allowedTo[to] || from == address(0),
"BackingEigen._beforeTokenTransfer: from or to must be whitelisted"
);
}
super._beforeTokenTransfer(from, to, amount);
}
}
120 changes: 18 additions & 102 deletions src/contracts/token/Eigen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {
IERC20 public immutable bEIGEN;

/// STORAGE
/// @dev Do not remove, deprecated storage.
/// @notice mapping of minter addresses to the timestamp after which they are allowed to mint
mapping(address => uint256) public mintAllowedAfter;
mapping(address => uint256) internal __deprecated_mintAllowedAfter;
/// @dev Do not remove, deprecated storage.
/// @notice mapping of minter addresses to the amount of tokens they are allowed to mint
mapping(address => uint256) public mintingAllowance;

mapping(address => uint256) internal __deprecated_mintingAllowance;
/// @dev Do not remove, deprecated storage.
/// @notice the timestamp after which transfer restrictions are disabled
uint256 public transferRestrictionsDisabledAfter;
uint256 internal __deprecated_transferRestrictionsDisabledAfter;
/// @dev Do not remove, deprecated storage.
/// @notice mapping of addresses that are allowed to transfer tokens to any address
mapping(address => bool) public allowedFrom;
mapping(address => bool) internal __deprecated_allowedFrom;
/// @dev Do not remove, deprecated storage.
/// @notice mapping of addresses that are allowed to receive tokens from any address
mapping(address => bool) public allowedTo;
mapping(address => bool) internal __deprecated_allowedTo;

/// @notice event emitted when the allowedFrom status of an address is set
event SetAllowedFrom(address indexed from, bool isAllowedFrom);
/// @notice event emitted when the allowedTo status of an address is set
event SetAllowedTo(address indexed to, bool isAllowedTo);
/// @notice event emitted when a minter mints
event Mint(address indexed minter, uint256 amount);
/// @notice event emitted when the transfer restrictions disabled
event TransferRestrictionsDisabled();
/// EVENTS
/// @notice Emitted when bEIGEN tokens are wrapped into EIGEN
event TokenWrapped(address indexed account, uint256 amount);
/// @notice Emitted when EIGEN tokens are unwrapped into bEIGEN
event TokenUnwrapped(address indexed account, uint256 amount);

constructor(
IERC20 _bEIGEN
Expand All @@ -41,83 +42,14 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {

/**
* @notice An initializer function that sets initial values for the contract's state variables.
* @param minters the addresses that are allowed to mint
* @param mintingAllowances the amount of tokens that each minter is allowed to mint
*/
function initialize(
address initialOwner,
address[] memory minters,
uint256[] memory mintingAllowances,
uint256[] memory mintAllowedAfters
address initialOwner
) public initializer {
__Ownable_init();
__ERC20_init("Eigen", "EIGEN");
_transferOwnership(initialOwner);
__ERC20Permit_init("EIGEN");

require(
minters.length == mintingAllowances.length,
"Eigen.initialize: minters and mintingAllowances must be the same length"
);
require(
minters.length == mintAllowedAfters.length,
"Eigen.initialize: minters and mintAllowedAfters must be the same length"
);
// set minting allowances for each minter
for (uint256 i = 0; i < minters.length; i++) {
mintingAllowance[minters[i]] = mintingAllowances[i];
mintAllowedAfter[minters[i]] = mintAllowedAfters[i];
// allow each minter to transfer tokens
allowedFrom[minters[i]] = true;
emit SetAllowedFrom(minters[i], true);
}

// set transfer restrictions to be disabled at type(uint256).max to be set down later
transferRestrictionsDisabledAfter = type(uint256).max;
}

/**
* @notice This function allows the owner to set the allowedFrom status of an address
* @param from the address whose allowedFrom status is being set
* @param isAllowedFrom the new allowedFrom status
*/
function setAllowedFrom(address from, bool isAllowedFrom) external onlyOwner {
allowedFrom[from] = isAllowedFrom;
emit SetAllowedFrom(from, isAllowedFrom);
}

/**
* @notice This function allows the owner to set the allowedTo status of an address
* @param to the address whose allowedTo status is being set
* @param isAllowedTo the new allowedTo status
*/
function setAllowedTo(address to, bool isAllowedTo) external onlyOwner {
allowedTo[to] = isAllowedTo;
emit SetAllowedTo(to, isAllowedTo);
}

/**
* @notice Allows the owner to disable transfer restrictions
*/
function disableTransferRestrictions() external onlyOwner {
require(
transferRestrictionsDisabledAfter == type(uint256).max,
"Eigen.disableTransferRestrictions: transfer restrictions are already disabled"
);
transferRestrictionsDisabledAfter = 0;
emit TransferRestrictionsDisabled();
}

/**
* @notice This function allows minter to mint tokens
*/
function mint() external {
require(mintingAllowance[msg.sender] > 0, "Eigen.mint: msg.sender has no minting allowance");
require(block.timestamp > mintAllowedAfter[msg.sender], "Eigen.mint: msg.sender is not allowed to mint yet");
uint256 amount = mintingAllowance[msg.sender];
mintingAllowance[msg.sender] = 0;
_mint(msg.sender, amount);
emit Mint(msg.sender, amount);
}

/**
Expand All @@ -128,6 +60,7 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {
) external {
require(bEIGEN.transferFrom(msg.sender, address(this), amount), "Eigen.wrap: bEIGEN transfer failed");
_mint(msg.sender, amount);
emit TokenWrapped(msg.sender, amount);
}

/**
Expand All @@ -138,6 +71,7 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {
) external {
_burn(msg.sender, amount);
require(bEIGEN.transfer(msg.sender, amount), "Eigen.unwrap: bEIGEN transfer failed");
emit TokenUnwrapped(msg.sender, amount);
}

/**
Expand All @@ -150,24 +84,6 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {
}
}

/**
* @notice Overrides the beforeTokenTransfer function to enforce transfer restrictions
* @param from the address tokens are being transferred from
* @param to the address tokens are being transferred to
* @param amount the amount of tokens being transferred
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal override {
// if transfer restrictions are enabled
if (block.timestamp <= transferRestrictionsDisabledAfter) {
// if both from and to are not whitelisted
require(
from == address(0) || to == address(0) || allowedFrom[from] || allowedTo[to],
"Eigen._beforeTokenTransfer: from or to must be whitelisted"
);
}
super._beforeTokenTransfer(from, to, amount);
}

/**
* @notice Overridden to return the total bEIGEN supply instead.
* @dev The issued supply of EIGEN should match the bEIGEN balance of this contract,
Expand Down
32 changes: 0 additions & 32 deletions src/test/harnesses/EigenHarness.sol

This file was deleted.

Loading