Skip to content

Commit b74d40b

Browse files
committed
feat: consolidate mint function to BackingEigen, and change BackingEigen constructor to break circular dependency on Eigen (#1246)
**Motivation:** - consolidate mint function to BackingEigen - change BackingEigen constructor to break circular dependency on Eigen **Modifications:** - remove mint function in Eigen - move all tests to use mint function in BackingEigen - change integration tests setup to have minters mint their own supply - change BackingEigen constructor to break circular dependency on Eigen **Result:** - only BackingEigen has mint capability - no more circular dependency between BackingEigen and Eigen
1 parent b505569 commit b74d40b

File tree

5 files changed

+40
-97
lines changed

5 files changed

+40
-97
lines changed

src/contracts/token/BackingEigen.sol

+1-14
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import "@openzeppelin-upgrades/contracts/token/ERC20/extensions/ERC20VotesUpgrad
66
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
77

88
contract BackingEigen is OwnableUpgradeable, ERC20VotesUpgradeable {
9-
/// CONSTANTS & IMMUTABLES
10-
/// @notice the address of the wrapped Eigen token EIGEN
11-
IERC20 public immutable EIGEN;
12-
139
/// STORAGE
1410
/// @dev Do not remove, deprecated storage.
1511
/// @notice the timestamp after which transfer restrictions are disabled
@@ -24,14 +20,10 @@ contract BackingEigen is OwnableUpgradeable, ERC20VotesUpgradeable {
2420
// @notice whether or not an address is allowed to mint new bEIGEN tokens
2521
mapping(address => bool) public isMinter;
2622

27-
event Backed();
2823
// @notice event emitted when the `isMinter` mapping is modified
2924
event IsMinterModified(address indexed minterAddress, bool newStatus);
3025

31-
constructor(
32-
IERC20 _EIGEN
33-
) {
34-
EIGEN = _EIGEN;
26+
constructor() {
3527
_disableInitializers();
3628
}
3729

@@ -71,11 +63,6 @@ contract BackingEigen is OwnableUpgradeable, ERC20VotesUpgradeable {
7163
__ERC20_init("Backing Eigen", "bEIGEN");
7264
_transferOwnership(initialOwner);
7365
__ERC20Permit_init("bEIGEN");
74-
75-
// Mint the entire supply of EIGEN - this is a one-time event that
76-
// ensures bEIGEN fully backs EIGEN.
77-
_mint(address(EIGEN), 1_673_646_668_284_660_000_000_000_000);
78-
emit Backed();
7966
}
8067

8168
/// VIEW FUNCTIONS

src/contracts/token/Eigen.sol

+1-33
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {
2727
/// @notice mapping of addresses that are allowed to receive tokens from any address
2828
mapping(address => bool) internal __deprecated_allowedTo;
2929

30-
/// @notice event emitted when a minter mints
31-
event Mint(address indexed minter, uint256 amount);
32-
3330
constructor(
3431
IERC20 _bEIGEN
3532
) {
@@ -39,43 +36,14 @@ contract Eigen is OwnableUpgradeable, ERC20VotesUpgradeable {
3936

4037
/**
4138
* @notice An initializer function that sets initial values for the contract's state variables.
42-
* @param minters the addresses that are allowed to mint
43-
* @param mintingAllowances the amount of tokens that each minter is allowed to mint
4439
*/
4540
function initialize(
46-
address initialOwner,
47-
address[] memory minters,
48-
uint256[] memory mintingAllowances,
49-
uint256[] memory mintAllowedAfters
41+
address initialOwner
5042
) public initializer {
5143
__Ownable_init();
5244
__ERC20_init("Eigen", "EIGEN");
5345
_transferOwnership(initialOwner);
5446
__ERC20Permit_init("EIGEN");
55-
56-
require(
57-
minters.length == mintingAllowances.length,
58-
"Eigen.initialize: minters and mintingAllowances must be the same length"
59-
);
60-
require(
61-
minters.length == mintAllowedAfters.length,
62-
"Eigen.initialize: minters and mintAllowedAfters must be the same length"
63-
);
64-
}
65-
66-
/**
67-
* @notice This function allows minter to mint tokens
68-
*/
69-
function mint() external {
70-
require(__deprecated_mintingAllowance[msg.sender] > 0, "Eigen.mint: msg.sender has no minting allowance");
71-
require(
72-
block.timestamp > __deprecated_mintAllowedAfter[msg.sender],
73-
"Eigen.mint: msg.sender is not allowed to mint yet"
74-
);
75-
uint256 amount = __deprecated_mintingAllowance[msg.sender];
76-
__deprecated_mintingAllowance[msg.sender] = 0;
77-
_mint(msg.sender, amount);
78-
emit Mint(msg.sender, amount);
7947
}
8048

8149
/**

src/test/harnesses/EigenHarness.sol

-13
This file was deleted.

src/test/token/EigenWrapping.t.sol

+34-33
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import "forge-std/Test.sol";
55

66
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
77
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
8-
import "../harnesses/EigenHarness.sol";
98

9+
import "../../contracts/token/Eigen.sol";
1010
import "../../contracts/token/BackingEigen.sol";
1111

1212
contract EigenWrappingTests is Test {
@@ -17,17 +17,17 @@ contract EigenWrappingTests is Test {
1717

1818
ProxyAdmin proxyAdmin;
1919

20-
EigenHarness eigenImpl;
20+
Eigen eigenImpl;
2121
Eigen eigen;
2222

2323
BackingEigen bEIGENImpl;
2424
BackingEigen bEIGEN;
2525

2626
uint totalSupply = 1.67e9 ether;
2727

28-
// EVENTS FROM EIGEN.sol
29-
/// @notice event emitted when a minter mints
30-
event Mint(address indexed minter, uint amount);
28+
// EVENTS FROM BackingEigen.sol
29+
/// @notice event emitted when a minter status is modified
30+
event IsMinterModified(address indexed minterAddress, bool newStatus);
3131

3232
modifier filterAddress(address fuzzedAddress) {
3333
vm.assume(!fuzzedOutAddresses[fuzzedAddress]);
@@ -43,13 +43,40 @@ contract EigenWrappingTests is Test {
4343
bEIGEN = BackingEigen(address(new TransparentUpgradeableProxy(address(proxyAdmin), address(proxyAdmin), "")));
4444

4545
// deploy impls
46-
eigenImpl = new EigenHarness(IERC20(address(bEIGEN)));
47-
bEIGENImpl = new BackingEigen(IERC20(address(eigen)));
46+
eigenImpl = new Eigen(IERC20(address(bEIGEN)));
47+
bEIGENImpl = new BackingEigen();
4848

4949
// upgrade proxies
5050
proxyAdmin.upgrade(ITransparentUpgradeableProxy(payable(address(eigen))), address(eigenImpl));
5151
proxyAdmin.upgrade(ITransparentUpgradeableProxy(payable(address(bEIGEN))), address(bEIGENImpl));
5252

53+
// initialize bEIGEN - this will mint the entire supply to the Eigen contract
54+
bEIGEN.initialize(minter1);
55+
56+
// set minters (for future minting if needed)
57+
vm.expectEmit(true, false, false, false);
58+
emit IsMinterModified(minter1, true);
59+
bEIGEN.setIsMinter(minter1, true);
60+
61+
vm.expectEmit(true, false, false, false);
62+
emit IsMinterModified(minter2, true);
63+
bEIGEN.setIsMinter(minter2, true);
64+
65+
// initialize eigen with empty arrays since we don't need minting anymore
66+
eigen.initialize(minter1);
67+
68+
// Mint and wrap tokens for minter1
69+
vm.startPrank(minter1);
70+
bEIGEN.mint(minter1, totalSupply / 2);
71+
bEIGEN.approve(address(eigen), totalSupply / 2);
72+
eigen.wrap(totalSupply / 2);
73+
vm.stopPrank();
74+
75+
// Mint and wrap tokens for minter2
76+
vm.startPrank(minter2);
77+
bEIGEN.mint(minter2, totalSupply / 2);
78+
bEIGEN.approve(address(eigen), totalSupply / 2);
79+
eigen.wrap(totalSupply / 2);
5380
vm.stopPrank();
5481

5582
fuzzedOutAddresses[minter1] = true;
@@ -63,11 +90,6 @@ contract EigenWrappingTests is Test {
6390
function test_AnyoneCanUnwrap(address unwrapper, uint unwrapAmount) public filterAddress(unwrapper) {
6491
vm.assume(unwrapper != address(0));
6592

66-
_simulateMint();
67-
68-
// initialize bEIGEN
69-
bEIGEN.initialize(minter1);
70-
7193
// minter1 balance
7294
uint minter1Balance = eigen.balanceOf(minter1);
7395

@@ -100,11 +122,6 @@ contract EigenWrappingTests is Test {
100122
function test_AnyoneCanWrap(address wrapper, uint wrapAmount) public filterAddress(wrapper) {
101123
vm.assume(wrapper != address(0));
102124

103-
_simulateMint();
104-
105-
// initialize bEIGEN
106-
bEIGEN.initialize(minter1);
107-
108125
// initial bEIGEN balance
109126
uint initialBEIGENBalanceOfEigenToken = bEIGEN.balanceOf(address(eigen));
110127
// minter1 balance
@@ -139,11 +156,6 @@ contract EigenWrappingTests is Test {
139156
}
140157

141158
function test_CannotUnwrapMoreThanBalance(address unwrapper, uint unwrapAmount) public filterAddress(unwrapper) {
142-
_simulateMint();
143-
144-
// initialize bEIGEN
145-
bEIGEN.initialize(minter1);
146-
147159
// unwrap amount should be less than minter1 balance
148160
unwrapAmount = unwrapAmount % eigen.balanceOf(minter1);
149161

@@ -158,11 +170,6 @@ contract EigenWrappingTests is Test {
158170
}
159171

160172
function test_CannotWrapMoreThanBalance(address wrapper, uint wrapAmount) public filterAddress(wrapper) {
161-
_simulateMint();
162-
163-
// initialize bEIGEN
164-
bEIGEN.initialize(minter1);
165-
166173
// wrap amount should be less than minter1 balance
167174
wrapAmount = wrapAmount % eigen.balanceOf(minter1);
168175

@@ -181,10 +188,4 @@ contract EigenWrappingTests is Test {
181188
eigen.wrap(wrapAmount + 1);
182189
vm.stopPrank();
183190
}
184-
185-
function _simulateMint() internal {
186-
// dummy mint
187-
EigenHarness(address(eigen)).mint(minter1, totalSupply / 2);
188-
EigenHarness(address(eigen)).mint(minter2, totalSupply / 2);
189-
}
190191
}

src/test/token/bEIGEN.t.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import "forge-std/Test.sol";
55

66
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
77
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
8-
import "../harnesses/EigenHarness.sol";
98

9+
import "../../contracts/token/Eigen.sol";
1010
import "../../contracts/token/BackingEigen.sol";
1111

1212
contract bEIGENTest is Test {
@@ -18,7 +18,7 @@ contract bEIGENTest is Test {
1818

1919
ProxyAdmin proxyAdmin;
2020

21-
EigenHarness eigenImpl;
21+
Eigen eigenImpl;
2222
Eigen eigen;
2323

2424
BackingEigen bEIGENImpl;
@@ -33,8 +33,8 @@ contract bEIGENTest is Test {
3333
bEIGEN = BackingEigen(address(new TransparentUpgradeableProxy(address(proxyAdmin), address(proxyAdmin), "")));
3434

3535
// deploy impls
36-
eigenImpl = new EigenHarness(IERC20(address(bEIGEN)));
37-
bEIGENImpl = new BackingEigen(IERC20(address(eigen)));
36+
eigenImpl = new Eigen(IERC20(address(bEIGEN)));
37+
bEIGENImpl = new BackingEigen();
3838

3939
// upgrade proxies
4040
proxyAdmin.upgrade(ITransparentUpgradeableProxy(payable(address(eigen))), address(eigenImpl));

0 commit comments

Comments
 (0)