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

Soloseng/dynamically-fetch-epochmanagerenabler-address #11207

23 changes: 7 additions & 16 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ contract EpochManager is
mapping(uint256 => Epoch) private epochs;
mapping(address => uint256) public validatorPendingPayments;

address public carbonOffsettingPartner;
address public epochManagerInitializer;

/**
* @notice Event emited when epochProcessing has begun.
* @param epochNumber The epoch number that is being processed.
Expand All @@ -74,7 +71,10 @@ contract EpochManager is
event EpochProcessingEnded(uint256 indexed epochNumber);

modifier onlyEpochManagerInitializer() {
require(msg.sender == epochManagerInitializer, "msg.sender is not Initializer");
require(
msg.sender == registry.getAddressForOrDie(EPOCH_MANAGER_INITIALIZER_REGISTRY_ID),
"msg.sender is not Initializer"
);
_;
}

Expand All @@ -89,18 +89,10 @@ contract EpochManager is
* @param registryAddress The address of the registry core smart contract.
* @param newEpochDuration The duration of an epoch in seconds.
*/
function initialize(
address registryAddress,
uint256 newEpochDuration,
address _carbonOffsettingPartner,
address _epochManagerInitializer
) external initializer {
require(_epochManagerInitializer != address(0), "EpochManagerInitializer address is required");
function initialize(address registryAddress, uint256 newEpochDuration) external initializer {
_transferOwnership(msg.sender);
setRegistry(registryAddress);
setEpochDuration(newEpochDuration);
carbonOffsettingPartner = _carbonOffsettingPartner;
epochManagerInitializer = _epochManagerInitializer;
}

// DESIGNDESICION(XXX): we assume that the first epoch on the L2 starts as soon as the system is initialized
Expand All @@ -127,7 +119,6 @@ contract EpochManager is
_currentEpoch.startTimestamp = block.timestamp;

elected = firstElected;
epochManagerInitializer = address(0);
}

// TODO maybe "freezeEpochRewards" "prepareForNextEpoch"
Expand Down Expand Up @@ -208,7 +199,7 @@ contract EpochManager is
epochProcessing.totalRewardsCommunity
);
getCeloUnreleasedTreasure().release(
carbonOffsettingPartner,
getEpochRewards().carbonOffsettingPartner(),
epochProcessing.totalRewardsCarbonFund
);
// run elections
Expand Down Expand Up @@ -285,7 +276,7 @@ contract EpochManager is
}

function systemAlreadyInitialized() public view returns (bool) {
return initialized && epochManagerInitializer == address(0);
return initialized && elected.length > 0;
}

function allocateValidatorsRewards() internal {
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/contracts-0.8/common/UsingRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ contract UsingRegistry is Ownable {
bytes32 constant LOCKED_CELO_REGISTRY_ID = keccak256(abi.encodePacked("LockedCelo"));
bytes32 constant CELO_UNRELEASED_TREASURE_REGISTRY_ID =
keccak256(abi.encodePacked("CeloUnreleasedTreasure"));
bytes32 constant EPOCH_MANAGER_INITIALIZER_REGISTRY_ID =
soloseng marked this conversation as resolved.
Show resolved Hide resolved
keccak256(abi.encodePacked("EpochManagerInitializer"));
bytes32 constant EPOCH_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("EpochManager"));
bytes32 constant SCORE_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("ScoreManager"));
// solhint-enable state-visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../../../contracts/governance/interfaces/IEpochRewards.sol";
*/
contract EpochRewardsMock08 is IEpochRewards {
uint256 private numValidatorsInCurrentSet;
address public carbonOffsettingPartner;

function setNumberValidatorsInCurrentSet(uint256 value) external {
numValidatorsInCurrentSet = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ interface IEpochManager {
function getCurrentEpoch() external view returns (uint256, uint256, uint256, uint256, uint256);
function getCurrentEpochNumber() external view returns (uint256);
function getElected() external view returns (address[] memory);
function epochManagerInitializer() external view returns (address);
function epochDuration() external view returns (uint256);
}
17 changes: 7 additions & 10 deletions packages/protocol/contracts/governance/EpochRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ contract EpochRewards is
* @param value The percentage of the total reward to be sent to the community funds.
* @return True upon success.
*/
function setCommunityRewardFraction(uint256 value) public onlyOwner onlyL1 returns (bool) {
function setCommunityRewardFraction(uint256 value) public onlyOwner returns (bool) {
require(
value != communityRewardFraction.unwrap() && value < FixidityLib.fixed1().unwrap(),
"Value must be different from existing community reward fraction and less than 1"
Expand All @@ -299,10 +299,7 @@ contract EpochRewards is
* @param value The percentage of the total reward to be sent to the carbon offsetting partner.
* @return True upon success.
*/
function setCarbonOffsettingFund(
address partner,
uint256 value
) public onlyOwner onlyL1 returns (bool) {
function setCarbonOffsettingFund(address partner, uint256 value) public onlyOwner returns (bool) {
require(
partner != carbonOffsettingPartner || value != carbonOffsettingFraction.unwrap(),
"Partner and value must be different from existing carbon offsetting fund"
Expand All @@ -319,7 +316,7 @@ contract EpochRewards is
* @param value The percentage of floating Gold voting to target.
* @return True upon success.
*/
function setTargetVotingGoldFraction(uint256 value) public onlyOwner onlyL1 returns (bool) {
function setTargetVotingGoldFraction(uint256 value) public onlyOwner returns (bool) {
require(value != targetVotingGoldFraction.unwrap(), "Target voting gold fraction unchanged");
require(
value < FixidityLib.fixed1().unwrap(),
Expand All @@ -335,7 +332,7 @@ contract EpochRewards is
* @param value The value in Celo Dollars.
* @return True upon success.
*/
function setTargetValidatorEpochPayment(uint256 value) public onlyOwner onlyL1 returns (bool) {
function setTargetValidatorEpochPayment(uint256 value) public onlyOwner returns (bool) {
require(value != targetValidatorEpochPayment, "Target validator epoch payment unchanged");
targetValidatorEpochPayment = value;
emit TargetValidatorEpochPaymentSet(value);
Expand All @@ -355,7 +352,7 @@ contract EpochRewards is
uint256 max,
uint256 underspendAdjustmentFactor,
uint256 overspendAdjustmentFactor
) public onlyOwner onlyL1 returns (bool) {
) public onlyOwner returns (bool) {
require(
max != rewardsMultiplierParams.max.unwrap() ||
overspendAdjustmentFactor != rewardsMultiplierParams.adjustmentFactors.overspend.unwrap() ||
Expand All @@ -382,7 +379,7 @@ contract EpochRewards is
function setTargetVotingYieldParameters(
uint256 max,
uint256 adjustmentFactor
) public onlyOwner onlyL1 returns (bool) {
) public onlyOwner returns (bool) {
require(
max != targetVotingYieldParams.max.unwrap() ||
adjustmentFactor != targetVotingYieldParams.adjustmentFactor.unwrap(),
Expand All @@ -404,7 +401,7 @@ contract EpochRewards is
* @param targetVotingYield The relative target block reward for voters.
* @return True upon success.
*/
function setTargetVotingYield(uint256 targetVotingYield) public onlyOwner onlyL1 returns (bool) {
function setTargetVotingYield(uint256 targetVotingYield) public onlyOwner returns (bool) {
FixidityLib.Fraction memory target = FixidityLib.wrap(targetVotingYield);
require(
target.lte(targetVotingYieldParams.max),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface IEpochRewards {
function getCarbonOffsettingFraction() external view returns (uint256);
function getTargetVotingGoldFraction() external view returns (uint256);
function getRewardsMultiplier() external view returns (uint256);
function carbonOffsettingPartner() external view returns (address);
}
5 changes: 2 additions & 3 deletions packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
uint256 res = scoreManager.getValidatorScore(actor("validator1"));
uint256 res2 = epochRewards.getCommunityRewardFraction();

epochManager.initialize(REGISTRY_ADDRESS, 10, carbonOffsettingPartner, epochManagerInitializer);
epochManager.initialize(REGISTRY_ADDRESS, 10);

blockTravel(vm, firstEpochBlock);
}
Expand All @@ -100,12 +100,11 @@ contract EpochManagerTest_initialize is EpochManagerTest {
function test_initialize() public virtual {
assertEq(address(epochManager.registry()), REGISTRY_ADDRESS);
assertEq(epochManager.epochDuration(), 10);
assertEq(epochManager.carbonOffsettingPartner(), carbonOffsettingPartner);
}

function test_Reverts_WhenAlreadyInitialized() public virtual {
vm.expectRevert("contract already initialized");
epochManager.initialize(REGISTRY_ADDRESS, 10, carbonOffsettingPartner, epochManagerInitializer);
epochManager.initialize(REGISTRY_ADDRESS, 10);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ contract EpochRewardsTest_setTargetVotingGoldFraction is EpochRewardsTest {
epochRewards.setTargetVotingGoldFraction(targetVotingGoldFraction);
}

function test_Reverts_WhenCalledOnL2() public {
function test_Emits_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
epochRewards.setTargetVotingGoldFraction(targetVotingGoldFraction);
vm.expectEmit(true, true, true, true);
emit TargetVotingGoldFractionSet(newFraction);
epochRewards.setTargetVotingGoldFraction(newFraction);
}
}

Expand Down Expand Up @@ -238,10 +239,11 @@ contract EpochRewardsTest_setCommunityRewardFraction is EpochRewardsTest {
epochRewards.setCommunityRewardFraction(communityRewardFraction);
}

function test_Reverts_WhenCalledOnL2() public {
function test_Emits_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
epochRewards.setCommunityRewardFraction(communityRewardFraction);
vm.expectEmit(true, true, true, true);
emit CommunityRewardFractionSet(newFraction);
epochRewards.setCommunityRewardFraction(newFraction);
}
}

Expand Down Expand Up @@ -274,10 +276,11 @@ contract EpochRewardsTest_setTargetValidatorEpochPayment is EpochRewardsTest {
epochRewards.setTargetValidatorEpochPayment(targetValidatorEpochPayment);
}

function test_Reverts_WhenCalledOnL2() public {
function test_Emits_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
epochRewards.setTargetValidatorEpochPayment(targetValidatorEpochPayment);
vm.expectEmit(true, true, true, true);
emit TargetValidatorEpochPaymentSet(newPayment);
epochRewards.setTargetValidatorEpochPayment(newPayment);
}
}

Expand Down Expand Up @@ -332,12 +335,17 @@ contract EpochRewardsTest_setRewardsMultiplierParameters is EpochRewardsTest {
);
}

function test_Reverts_WhenCalledOnL2() public {
function test_Emits_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
vm.expectEmit(true, true, true, true);
emit RewardsMultiplierParametersSet(
rewardsMultiplierMax,
newRewardsMultiplierAdjustmentsUnderspend,
rewardsMultiplierAdjustmentsOverspend
);
epochRewards.setRewardsMultiplierParameters(
rewardsMultiplierMax,
rewardsMultiplierAdjustmentsUnderspend,
newRewardsMultiplierAdjustmentsUnderspend,
rewardsMultiplierAdjustmentsOverspend
);
}
Expand Down Expand Up @@ -388,9 +396,13 @@ contract EpochRewardsTest_setTargetVotingYieldParameters is EpochRewardsTest {
);
}

function test_Reverts_WhenCalledOnL2() public {
function test_Emits_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
vm.expectEmit(true, true, true, true);
emit TargetVotingYieldParametersSet(
newTargetVotingYieldParamsMax,
newTargetVotingYieldParamsAdjustmentFactor
);
epochRewards.setTargetVotingYieldParameters(
newTargetVotingYieldParamsMax,
newTargetVotingYieldParamsAdjustmentFactor
Expand Down Expand Up @@ -420,9 +432,10 @@ contract EpochRewardsTest_setTargetVotingYield is EpochRewardsTest {
epochRewards.setTargetVotingYield(newTargetVotingYieldParamsInitial);
}

function test_Reverts_WhenCalledOnL2() public {
function test_Emits_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
vm.expectEmit(true, true, true, true);
emit TargetVotingYieldSet(newTargetVotingYieldParamsInitial);
epochRewards.setTargetVotingYield(newTargetVotingYieldParamsInitial);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test-sol/utils/ECDSAHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract ECDSAHelper is Test {
bytes32 _s
) public returns (bytes memory) {
address SECP256K1Address = actor("SECP256K1Address");
deployCodeTo("out/SECP256K1.sol/SECP256K1.0.5.17.json", SECP256K1Address);
deployCodeTo("SECP256K1.sol:SECP256K1", SECP256K1Address);
sECP256K1 = ISECP256K1(SECP256K1Address);

string memory header = "\x19Ethereum Signed Message:\n32";
Expand Down
Loading