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

E2E EpochManager test + Epoch truffle migrations & Anvil L2 migration build fix #11198

Merged
merged 76 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f9979ce
unit test with mocks
soloseng Aug 19, 2024
75bf938
++ integration tests
soloseng Aug 20, 2024
cb47ec9
clean up
soloseng Aug 20, 2024
fbdc5fd
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Aug 20, 2024
b8f5584
-- logging
soloseng Aug 20, 2024
282ef91
removed duplicate interface
soloseng Aug 20, 2024
40711cb
using `MockCeloToken` to get test to pass.
soloseng Aug 20, 2024
654b279
removed endEpochTimestamp
soloseng Aug 20, 2024
2072107
moved IEpochManager to 0.5 folder
soloseng Aug 20, 2024
9a6c01f
added L2 conditions for EpochRewards functions using precompiles
soloseng Aug 20, 2024
c48b8e5
renamed EpochManagerInitializer due to name conflict
soloseng Aug 21, 2024
47f93af
++ more unit test
soloseng Aug 21, 2024
d3b1db4
setup anvil migration
soloseng Aug 22, 2024
a6e2844
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Aug 26, 2024
2ba9360
compiles
soloseng Aug 26, 2024
35b637a
++ require fund in unreleased treasury
soloseng Aug 27, 2024
c02c0a4
Updated regex
soloseng Aug 27, 2024
92ac7cf
++ registry 0.8 for testing only
soloseng Aug 27, 2024
f50ac8b
clean up
soloseng Aug 27, 2024
3aa816c
++ unit test
soloseng Aug 27, 2024
180162b
initial integration test using L1 devchain
soloseng Aug 27, 2024
22946ff
++ comment
soloseng Aug 27, 2024
0ed7e93
-- forge based integration test
soloseng Aug 27, 2024
7fcc9a8
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Aug 27, 2024
8f0ea64
++ to const
soloseng Aug 27, 2024
cfa7cdb
happy linter
soloseng Aug 28, 2024
cdf7aea
update contract name
soloseng Aug 28, 2024
4b709d3
Adding truffle migrations
pahor167 Aug 29, 2024
969f9d3
Fix of L2 Anvil migrations
pahor167 Aug 29, 2024
8838c5c
Improved anvil devchain compilation
pahor167 Aug 29, 2024
93274c8
Release init params
pahor167 Aug 29, 2024
b49f929
++ PR feedback
soloseng Aug 29, 2024
1b616ca
++ checks
soloseng Sep 10, 2024
b47dba3
updated carbon address
soloseng Sep 10, 2024
f34e7e0
E2E test
pahor167 Sep 11, 2024
a050d27
lint
pahor167 Sep 11, 2024
0e8da38
Merge branch 'soloseng/startNextEpochProcess-unit-and-integration-tes…
pahor167 Sep 11, 2024
48db871
proxy stableToken mint call via Validators contract
soloseng Sep 11, 2024
8a8f4d9
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Sep 11, 2024
bbb239f
-- duplicate imports
soloseng Sep 11, 2024
2ffeed2
removed registry08. replaced with vm call
soloseng Sep 11, 2024
b195ebb
PR feedback
soloseng Sep 11, 2024
e84a5b5
generate Ecdsa Pub Key dynamically in migration.s.sol
pahor167 Sep 12, 2024
3c2ebfc
-- coment
soloseng Sep 12, 2024
83bd5aa
passing unit tests
soloseng Sep 12, 2024
1d4eaa4
clean up
soloseng Sep 12, 2024
43ae993
++ mintStable test
soloseng Sep 12, 2024
de06b4e
-- TODO; compiles test when filtering
soloseng Sep 12, 2024
15a5290
E2E test with 3 groups with 2 validators each
pahor167 Sep 13, 2024
84f4349
fix for rewards computation
pahor167 Sep 13, 2024
17c5884
lint
pahor167 Sep 13, 2024
bc53164
merge
pahor167 Sep 13, 2024
9ddb522
anvil migration rename
pahor167 Sep 13, 2024
48cf98c
remove setEpochMangerEnabler
pahor167 Sep 13, 2024
28bf1ff
truffle build fix
pahor167 Sep 16, 2024
e5ffbf1
initializeEpochManagerSystem
pahor167 Sep 16, 2024
96363fc
migration test fix
pahor167 Sep 16, 2024
812604d
prettify
pahor167 Sep 16, 2024
abdbae4
removal of logging
pahor167 Sep 16, 2024
55bd69b
removal of logging2
pahor167 Sep 16, 2024
fe91831
EpochManagerEnabler version
pahor167 Sep 12, 2024
2c5a95f
Enable epoch manager in devchain
pahor167 Sep 16, 2024
13510fd
lint
pahor167 Sep 16, 2024
eb5691b
Merge branch 'feat/l2-epoch-system' into pahor/truffleMigrations
martinvol Sep 17, 2024
6011483
Rolled back contracts/identity/FederatedAttestations.sol added by mis…
martinvol Sep 17, 2024
776f864
removed duplicated function
martinvol Sep 17, 2024
a152a09
Fix tests
martinvol Sep 17, 2024
f5a2cb8
lint
martinvol Sep 17, 2024
95a6b65
Fixed tests and moved ValidatorsMock08 to solidity test folder
martinvol Sep 17, 2024
69b3bd8
Added release data
martinvol Sep 17, 2024
f477f74
Deleted prints in release script
martinvol Sep 17, 2024
4093393
Removed unnecesary mocking
martinvol Sep 17, 2024
fc278cb
Force compilation of validator
martinvol Sep 17, 2024
5bf0d85
moved mocks to right path
martinvol Sep 17, 2024
df7a9e8
Fixed tests
martinvol Sep 17, 2024
1d62d5f
Added ScoreManager to releaseData/initializationData/release12.json
martinvol Sep 17, 2024
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
13 changes: 12 additions & 1 deletion packages/protocol/contractPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ export const SOLIDITY_08_PACKAGE = {
proxiesPath: '/', // Proxies are still with 0.5 contracts
// Proxies shouldn't have to be added to a list manually
// https://github.com/celo-org/celo-monorepo/issues/10555
contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory', 'CeloUnreleasedTreasure', 'Validators'],
contracts: [
'GasPriceMinimum',
'FeeCurrencyDirectory',
'CeloUnreleasedTreasure',
'Validators',
'EpochManager',
'EpochManagerEnabler',
'ScoreManager',
],
proxyContracts: [
'GasPriceMinimumProxy',
'FeeCurrencyDirectoryProxy',
'MentoFeeCurrencyAdapterV1',
'CeloUnreleasedTreasureProxy',
'ValidatorsProxy',
'EpochManagerProxy',
'EpochManagerEnablerProxy',
'ScoreManagerProxy',
],
truffleConfig: 'truffle-config0.8.js',
} satisfies ContractPackage
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import "./UsingRegistry.sol";
import "../common/IsL2Check.sol";

import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/ICeloToken.sol";
import "./interfaces/ICeloUnreleasedTreasureInitializer.sol";
import "@openzeppelin/contracts8/token/ERC20/IERC20.sol";

/**
* @title Contract for unreleased Celo tokens.
Expand Down Expand Up @@ -49,8 +47,7 @@ contract CeloUnreleasedTreasure is UsingRegistry, ReentrancyGuard, Initializable
*/
function release(address to, uint256 amount) external onlyEpochManager {
require(address(this).balance >= amount, "Insufficient balance.");
IERC20 celoToken = IERC20(address(getCeloToken()));
celoToken.transfer(to, amount);
require(getCeloToken().transfer(to, amount), "CELO transfer failed.");
emit Released(to, amount);
}

Expand Down
62 changes: 41 additions & 21 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "../common/UsingRegistry.sol";
import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/IEpochManager.sol";
import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/interfaces/IEpochManager.sol";

contract EpochManager is
Initializable,
Expand All @@ -23,7 +24,6 @@ contract EpochManager is
uint256 firstBlock;
uint256 lastBlock;
uint256 startTimestamp;
uint256 endTimestamp;
uint256 rewardsBlock;
}

Expand Down Expand Up @@ -59,7 +59,7 @@ contract EpochManager is
mapping(address => uint256) public validatorPendingPayments;

address public carbonOffsettingPartner;
address public epochManagerInitializer;
address public epochManagerEnabler;

/**
* @notice Event emited when epochProcessing has begun.
Expand All @@ -73,8 +73,8 @@ contract EpochManager is
*/
event EpochProcessingEnded(uint256 indexed epochNumber);

modifier onlyEpochManagerInitializer() {
require(msg.sender == epochManagerInitializer, "msg.sender is not Initializer");
modifier onlyEpochManagerEnabler() {
require(msg.sender == epochManagerEnabler, "msg.sender is not Initializer");
_;
}

Expand All @@ -93,14 +93,23 @@ contract EpochManager is
address registryAddress,
uint256 newEpochDuration,
address _carbonOffsettingPartner,
address _epochManagerInitializer
address _epochManagerEnabler
) external initializer {
require(_epochManagerInitializer != address(0), "EpochManagerInitializer address is required");
require(_epochManagerEnabler != address(0), "EpochManagerEnabler address is required");
_transferOwnership(msg.sender);
setRegistry(registryAddress);
setEpochDuration(newEpochDuration);
carbonOffsettingPartner = _carbonOffsettingPartner;
epochManagerInitializer = _epochManagerInitializer;
epochManagerEnabler = _epochManagerEnabler;
}

/**
* @notice Sets the address of the Epoch Manager Enabler.
* @param _epochManagerEnabler The address of the Epoch Manager Enabler.
*/
function setEpochMangerEnabler(address _epochManagerEnabler) external onlyOwner {
pahor167 marked this conversation as resolved.
Show resolved Hide resolved
require(_epochManagerEnabler != address(0), "EpochManagerEnabler address is required");
epochManagerEnabler = _epochManagerEnabler;
}

// DESIGNDESICION(XXX): we assume that the first epoch on the L2 starts as soon as the system is initialized
Expand All @@ -110,7 +119,12 @@ contract EpochManager is
uint256 firstEpochNumber,
uint256 firstEpochBlock,
address[] memory firstElected
) external onlyEpochManagerInitializer {
) external onlyEpochManagerEnabler {
require(
getCeloToken().balanceOf(registry.getAddressForOrDie(CELO_UNRELEASED_TREASURE_REGISTRY_ID)) >
0,
"CeloUnreleasedTreasury not yet funded."
);
require(!systemAlreadyInitialized(), "Epoch system already initialized");
require(firstEpochNumber > 0, "First epoch number must be greater than 0");
require(firstEpochBlock > 0, "First epoch block must be greater than 0");
Expand All @@ -127,7 +141,7 @@ contract EpochManager is
_currentEpoch.startTimestamp = block.timestamp;

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

// TODO maybe "freezeEpochRewards" "prepareForNextEpoch"
Expand Down Expand Up @@ -172,7 +186,6 @@ contract EpochManager is
require(isOnEpochProcess(), "Epoch process is not started");
// finalize epoch
// TODO last block should be the block before and timestamp from previous block
epochs[currentEpochNumber].endTimestamp = block.timestamp;
epochs[currentEpochNumber].lastBlock = block.number - 1;
// start new epoch
currentEpochNumber++;
Expand Down Expand Up @@ -218,16 +231,9 @@ contract EpochManager is
}

/// returns the current epoch Info
function getCurrentEpoch() external view returns (uint256, uint256, uint256, uint256, uint256) {
function getCurrentEpoch() external view returns (uint256, uint256, uint256, uint256) {
Epoch storage _epoch = epochs[currentEpochNumber];

return (
_epoch.firstBlock,
_epoch.lastBlock,
_epoch.startTimestamp,
_epoch.endTimestamp,
_epoch.rewardsBlock
);
return (_epoch.firstBlock, _epoch.lastBlock, _epoch.startTimestamp, _epoch.rewardsBlock);
}

/// returns the current epoch number.
Expand All @@ -236,6 +242,21 @@ contract EpochManager is
return currentEpochNumber;
}

/// returns epoch processing state
function getEpochProcessingState()
external
view
returns (uint256, uint256, uint256, uint256, uint256)
{
return (
uint256(epochProcessing.status),
epochProcessing.perValidatorReward,
epochProcessing.totalRewardsVoter,
epochProcessing.totalRewardsCommunity,
epochProcessing.totalRewardsCarbonFund
);
}

function getElected() external view returns (address[] memory) {
return elected;
}
Expand Down Expand Up @@ -285,7 +306,7 @@ contract EpochManager is
}

function systemAlreadyInitialized() public view returns (bool) {
return initialized && epochManagerInitializer == address(0);
return initialized && epochManagerEnabler == address(0);
}

function allocateValidatorsRewards() internal {
Expand Down Expand Up @@ -313,7 +334,6 @@ contract EpochManager is
);

uint256 CELOequivalent = (numerator * totalRewards) / denominator;
// this is not a mint anymore
getCeloUnreleasedTreasure().release(
registry.getAddressForOrDie(RESERVE_REGISTRY_ID),
CELOequivalent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import "../common/UsingPrecompiles.sol";

import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/interfaces/IEpochManagerEnabler.sol";
import "../../contracts/governance/interfaces/IEpochRewards.sol";

contract EpochManagerInitializer is Initializable, UsingPrecompiles, UsingRegistry {
contract EpochManagerEnabler is Initializable, UsingPrecompiles, UsingRegistry {
/**
* @notice Sets initialized == true on implementation contracts
* @param test Set to true to skip implementation initialization
Expand Down
102 changes: 102 additions & 0 deletions packages/protocol/contracts-0.8/common/Registry08.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "@openzeppelin/contracts8/utils/math/SafeMath.sol";
import "@openzeppelin/contracts8/access/Ownable.sol";

import "../../contracts/common/interfaces/IRegistry.sol";
import "../../contracts/common/interfaces/IRegistryInitializer.sol";
import "../../contracts/common/Initializable.sol";

/**
* @title Routes identifiers to addresses.
*/
contract Registry08 is IRegistry, IRegistryInitializer, Ownable, Initializable {
using SafeMath for uint256;

mapping(bytes32 => address) public registry;

event RegistryUpdated(string identifier, bytes32 indexed identifierHash, address indexed addr);

/**
* @notice Sets initialized == true on implementation contracts
* @param test Set to true to skip implementation initialization
*/
constructor(bool test) public Initializable(test) {}

/**
* @notice Used in place of the constructor to allow the contract to be upgradable via proxy.
*/
function initialize() external initializer {
_transferOwnership(msg.sender);
}

/**
* @notice Associates the given address with the given identifier.
* @param identifier Identifier of contract whose address we want to set.
* @param addr Address of contract.
*/
function setAddressFor(string calldata identifier, address addr) external onlyOwner {
bytes32 identifierHash = keccak256(abi.encodePacked(identifier));
registry[identifierHash] = addr;
emit RegistryUpdated(identifier, identifierHash, addr);
}

/**
* @notice Gets address associated with the given identifierHash.
* @param identifierHash Identifier hash of contract whose address we want to look up.
* @dev Throws if address not set.
*/
function getAddressForOrDie(bytes32 identifierHash) external view returns (address) {
require(registry[identifierHash] != address(0), "identifier has no registry entry");
return registry[identifierHash];
}

/**
* @notice Gets address associated with the given identifierHash.
* @param identifierHash Identifier hash of contract whose address we want to look up.
*/
function getAddressFor(bytes32 identifierHash) external view returns (address) {
return registry[identifierHash];
}

/**
* @notice Gets address associated with the given identifier.
* @param identifier Identifier of contract whose address we want to look up.
* @dev Throws if address not set.
*/
function getAddressForStringOrDie(string calldata identifier) external view returns (address) {
bytes32 identifierHash = keccak256(abi.encodePacked(identifier));
require(registry[identifierHash] != address(0), "identifier has no registry entry");
return registry[identifierHash];
}

/**
* @notice Gets address associated with the given identifier.
* @param identifier Identifier of contract whose address we want to look up.
*/
function getAddressForString(string calldata identifier) external view returns (address) {
bytes32 identifierHash = keccak256(abi.encodePacked(identifier));
return registry[identifierHash];
}

/**
* @notice Iterates over provided array of identifiers, getting the address for each.
* Returns true if `sender` matches the address of one of the provided identifiers.
* @param identifierHashes Array of hashes of approved identifiers.
* @param sender Address in question to verify membership.
* @return True if `sender` corresponds to the address of any of `identifiers`
* registry entries.
*/
function isOneOf(
bytes32[] calldata identifierHashes,
address sender
) external view returns (bool) {
for (uint256 i = 0; i < identifierHashes.length; i = i.add(1)) {
if (registry[identifierHashes[i]] == sender) {
return true;
}
}
return false;
}
}
4 changes: 1 addition & 3 deletions packages/protocol/contracts-0.8/common/ScoreManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ contract ScoreManager is Initializable, Ownable {

/**
* @notice Used in place of the constructor to allow the contract to be upgradable via proxy.
* @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) external initializer {
function initialize() external initializer {
_transferOwnership(msg.sender);
}

Expand Down
9 changes: 4 additions & 5 deletions packages/protocol/contracts-0.8/common/UsingRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ import "../../contracts/common/interfaces/IAccounts.sol";
import "../../contracts/common/interfaces/IEpochManager.sol";
import "../../contracts/common/interfaces/IFreezer.sol";
import "../../contracts/common/interfaces/ICeloUnreleasedTreasure.sol";
import "../../contracts/common/interfaces/IFeeCurrencyWhitelist.sol";
import "../../contracts/common/interfaces/IFeeHandlerSeller.sol";
import "../../contracts/common/interfaces/IEpochManager.sol";
import "../../contracts/governance/interfaces/IGovernance.sol";
import "../../contracts/governance/interfaces/ILockedGold.sol";
import "../../contracts/governance/interfaces/ILockedCelo.sol";
import "../../contracts/governance/interfaces/IValidators.sol";
import "../../contracts/governance/interfaces/IElection.sol";
import "../../contracts/governance/interfaces/IEpochRewards.sol";
import "../../contracts/stability/interfaces/ISortedOracles.sol";
import "../../contracts/common/interfaces/IFeeCurrencyWhitelist.sol";
import "./interfaces/IScoreReader.sol";

import "../../contracts/governance/interfaces/IElection.sol";
import "../../contracts/common/interfaces/IFeeHandlerSeller.sol";
import "../../contracts/governance/interfaces/IEpochRewards.sol";
import "./interfaces/IScoreReader.sol";

contract UsingRegistry is Ownable {
// solhint-disable state-visibility
Expand Down
34 changes: 0 additions & 34 deletions packages/protocol/contracts-0.8/common/interfaces/ICeloToken.sol

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.5.13 <0.9.0;

interface IEpochManagerEnablerInitializer {
function initialize(address registryAddress) external;
}
Loading
Loading