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/L2-epoch-manager-test #11312

Merged
merged 29 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
caa2a2f
Merge remote-tracking branch 'origin/release/core-contracts/12' into …
soloseng Nov 21, 2024
4f4a917
WIP inheritance issues ?
soloseng Nov 22, 2024
75d40e9
Merge branch 'release/core-contracts/12' into soloseng/L2-FeeCurrency…
soloseng Dec 16, 2024
4a2c7f7
fixing compilation
soloseng Dec 20, 2024
d8a532f
removed mento from UsingRegistryV2 in 08
soloseng Dec 21, 2024
afe5356
using local precompile handler
soloseng Jan 7, 2025
23bd832
fixed unit test inheritance conflicts
soloseng Jan 7, 2025
e85910d
removed shadowed var
soloseng Jan 7, 2025
8b6b836
passing devchain e2e
soloseng Jan 7, 2025
5b3dd2d
passing migration test
soloseng Jan 7, 2025
ee99877
override Utils08 setup and cleanup
soloseng Jan 8, 2025
97d7ef3
change Utils08 filename
soloseng Jan 8, 2025
c519fa9
Merge remote-tracking branch 'origin/release/core-contracts/12' into …
soloseng Jan 8, 2025
3fa7426
Merge branch 'soloseng/L2-FeeCurrencyDirectory-test' into soloseng/fi…
soloseng Jan 8, 2025
48f0b7f
passing devchain
soloseng Jan 10, 2025
bf5de2d
reorg TestWithUtils08
soloseng Jan 10, 2025
4322801
Passing L2 epochManagerEnabler test
soloseng Jan 10, 2025
99f09b2
renamed to force update
soloseng Jan 13, 2025
da2d92a
using capital letter
soloseng Jan 13, 2025
5581845
Merge branch 'soloseng/fix-precompile-inheritance' into soloseng/L2-e…
soloseng Jan 13, 2025
21ad790
wip partially migrated without mockAccounts contract
soloseng Jan 14, 2025
f44045c
++ finish epoch processing L2 test
soloseng Jan 15, 2025
24b9f96
clean up setup
soloseng Jan 15, 2025
8f2fcf5
++ more working L1 & L2 test
soloseng Jan 16, 2025
0b31d9c
++ remaining L2 tests
soloseng Jan 16, 2025
286e569
clean up comments
soloseng Jan 16, 2025
c2af92f
more clean up
soloseng Jan 16, 2025
d5d1178
PR feedback
soloseng Jan 21, 2025
6d2f8e0
Merge remote-tracking branch 'origin/release/core-contracts/12' into …
soloseng Jan 24, 2025
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
72 changes: 72 additions & 0 deletions packages/protocol/contracts-0.8/common/PrecompilesOverrideV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts-0.8/common/IsL2Check.sol";

import "./UsingPrecompiles.sol";
import "./UsingRegistryV2NoMento.sol";

/**
* @title PrecompilesOverride Contract
* @notice This contract allows for a smoother transition from L1 to L2
* by abstracting away the usingPrecompile contract, and taking care of the L1 to L2 swtiching logic.
**/
contract PrecompilesOverrideV2 is UsingPrecompiles, UsingRegistryV2NoMento {
/**
* @notice Returns the epoch number at a block.
* @param blockNumber Block number where epoch number is calculated.
* @return Epoch number.
*/
function getEpochNumberOfBlock(uint256 blockNumber) public view override returns (uint256) {
if (isL2()) {
return getEpochManager().getEpochNumberOfBlock(blockNumber);
} else {
return epochNumberOfBlock(blockNumber, getEpochSize());
}
}

/**
* @notice Returns the epoch number at a block.
* @return Current epoch number.
*/
function getEpochNumber() public view override returns (uint256) {
return getEpochNumberOfBlock(block.number);
}

/**
* @notice Gets a validator signer address from the current validator set.
* @param index Index of requested validator in the validator set.
* @return Address of validator signer at the requested index.
*/
function validatorSignerAddressFromCurrentSet(
uint256 index
) public view override returns (address) {
if (isL2()) {
return getEpochManager().getElectedSignerByIndex(index);
} else {
return super.validatorSignerAddressFromCurrentSet(index);
}
}

/**
* @notice Gets a validator address from the current validator set.
* @param index Index of requested validator in the validator set.
* @return Address of validator at the requested index.
*/
function validatorAddressFromCurrentSet(uint256 index) public view onlyL2 returns (address) {
return getEpochManager().getElectedAccountByIndex(index);
}

/**
* @notice Gets the size of the current elected validator set.
* @return Size of the current elected validator set.
*/
function numberValidatorsInCurrentSet() public view override returns (uint256) {
if (isL2()) {
return getEpochManager().numberOfElectedInCurrentSet();
} else {
return super.numberValidatorsInCurrentSet();
}
}
}
156 changes: 156 additions & 0 deletions packages/protocol/contracts-0.8/common/UsingRegistry2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0 <0.8.20;

// Note: This is not an exact copy of UsingRegistry or UsingRegistryV2 in the contract's folder
// because Mento's interfaces still don't support Solidity 0.8

import "@openzeppelin/contracts8/access/Ownable.sol";
import "@openzeppelin/contracts8/token/ERC20/IERC20.sol";

import "../../contracts/common/interfaces/IRegistry.sol";
import "../../contracts/common/interfaces/IAccounts.sol";
import "../../contracts/common/interfaces/IEpochManager.sol";
import "../../contracts/common/interfaces/IFreezer.sol";
import "../../contracts/common/interfaces/ICeloUnreleasedTreasury.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 "./interfaces/IScoreReader.sol";

contract UsingRegistryy is Ownable {
// solhint-disable state-visibility
bytes32 constant ACCOUNTS_REGISTRY_ID = keccak256(abi.encodePacked("Accounts"));
bytes32 constant ATTESTATIONS_REGISTRY_ID = keccak256(abi.encodePacked("Attestations"));
bytes32 constant DOWNTIME_SLASHER_REGISTRY_ID = keccak256(abi.encodePacked("DowntimeSlasher"));
bytes32 constant DOUBLE_SIGNING_SLASHER_REGISTRY_ID =
keccak256(abi.encodePacked("DoubleSigningSlasher"));
bytes32 constant ELECTION_REGISTRY_ID = keccak256(abi.encodePacked("Election"));
bytes32 constant EPOCH_REWARDS_REGISTRY_ID = keccak256(abi.encodePacked("EpochRewards"));
bytes32 constant EXCHANGE_REGISTRY_ID = keccak256(abi.encodePacked("Exchange"));
bytes32 constant FEE_CURRENCY_WHITELIST_REGISTRY_ID =
keccak256(abi.encodePacked("FeeCurrencyWhitelist"));
bytes32 constant FREEZER_REGISTRY_ID = keccak256(abi.encodePacked("Freezer"));
bytes32 constant GOLD_TOKEN_REGISTRY_ID = keccak256(abi.encodePacked("GoldToken"));
bytes32 constant GOVERNANCE_REGISTRY_ID = keccak256(abi.encodePacked("Governance"));
bytes32 constant GOVERNANCE_SLASHER_REGISTRY_ID =
keccak256(abi.encodePacked("GovernanceSlasher"));
bytes32 constant LOCKED_GOLD_REGISTRY_ID = keccak256(abi.encodePacked("LockedGold"));
bytes32 constant RESERVE_REGISTRY_ID = keccak256(abi.encodePacked("Reserve"));
bytes32 constant RANDOM_REGISTRY_ID = keccak256(abi.encodePacked("Random"));
bytes32 constant SORTED_ORACLES_REGISTRY_ID = keccak256(abi.encodePacked("SortedOracles"));
bytes32 constant STABLE_TOKEN_REGISTRY_ID = keccak256(abi.encodePacked("StableToken"));
bytes32 constant VALIDATORS_REGISTRY_ID = keccak256(abi.encodePacked("Validators"));
bytes32 constant MENTOFEEHANDLERSELLER_REGISTRY_ID =
keccak256(abi.encodePacked("MentoFeeHandlerSeller"));
bytes32 constant CELO_TOKEN_REGISTRY_ID = keccak256(abi.encodePacked("CeloToken"));
bytes32 constant LOCKED_CELO_REGISTRY_ID = keccak256(abi.encodePacked("LockedCelo"));
bytes32 constant CELO_UNRELEASED_TREASURY_REGISTRY_ID =
keccak256(abi.encodePacked("CeloUnreleasedTreasury"));
bytes32 constant EPOCH_MANAGER_ENABLER_REGISTRY_ID =
keccak256(abi.encodePacked("EpochManagerEnabler"));
bytes32 constant EPOCH_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("EpochManager"));
bytes32 constant SCORE_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("ScoreManager"));
// solhint-enable state-visibility

IRegistry public registry;

event RegistrySet(address indexed registryAddress);

modifier onlyRegisteredContract(bytes32 identifierHash) {
require(registry.getAddressForOrDie(identifierHash) == msg.sender, "only registered contract");
_;
}

modifier onlyRegisteredContracts(bytes32[] memory identifierHashes) {
require(registry.isOneOf(identifierHashes, msg.sender), "only registered contracts");
_;
}

/**
* @notice Updates the address pointing to a Registry contract.
* @param registryAddress The address of a registry contract for routing to other contracts.
*/
function setRegistry(address registryAddress) public onlyOwner {
require(registryAddress != address(0), "Cannot register the null address");
registry = IRegistry(registryAddress);
emit RegistrySet(registryAddress);
}

function getGoldToken() internal view returns (IERC20) {
return IERC20(registry.getAddressForOrDie(GOLD_TOKEN_REGISTRY_ID));
}

function getCeloToken() internal view returns (IERC20) {
return IERC20(registry.getAddressForOrDie(CELO_TOKEN_REGISTRY_ID));
}

function getFreezer() internal view returns (IFreezer) {
return IFreezer(registry.getAddressForOrDie(FREEZER_REGISTRY_ID));
}

function getSortedOracles() internal view returns (ISortedOracles) {
return ISortedOracles(registry.getAddressForOrDie(SORTED_ORACLES_REGISTRY_ID));
}

function getFeeCurrencyWhitelist() internal view returns (IFeeCurrencyWhitelist) {
return IFeeCurrencyWhitelist(registry.getAddressForOrDie(FEE_CURRENCY_WHITELIST_REGISTRY_ID));
}

function getLockedGold() internal view returns (ILockedGold) {
return ILockedGold(registry.getAddressForOrDie(LOCKED_GOLD_REGISTRY_ID));
}

function getLockedCelo() internal view returns (ILockedCelo) {
return ILockedCelo(registry.getAddressForOrDie(LOCKED_CELO_REGISTRY_ID));
}

// Current version of Mento doesn't support 0.8
function getStableToken() internal view returns (address) {
return registry.getAddressForOrDie(STABLE_TOKEN_REGISTRY_ID);
}

function getMentoFeeHandlerSeller() internal view returns (IFeeHandlerSeller) {
return IFeeHandlerSeller(registry.getAddressForOrDie(MENTOFEEHANDLERSELLER_REGISTRY_ID));
}

function getAccounts() internal view returns (IAccounts) {
return IAccounts(registry.getAddressForOrDie(ACCOUNTS_REGISTRY_ID));
}

function getValidators() internal view returns (IValidators) {
return IValidators(registry.getAddressForOrDie(VALIDATORS_REGISTRY_ID));
}

function getElection() internal view returns (IElection) {
return IElection(registry.getAddressForOrDie(ELECTION_REGISTRY_ID));
}

function getEpochRewards() internal view returns (IEpochRewards) {
return IEpochRewards(registry.getAddressForOrDie(EPOCH_REWARDS_REGISTRY_ID));
}

function getGovernance() internal view returns (IGovernance) {
return IGovernance(registry.getAddressForOrDie(GOVERNANCE_REGISTRY_ID));
}

function getCeloUnreleasedTreasury() internal view returns (ICeloUnreleasedTreasury) {
return
ICeloUnreleasedTreasury(registry.getAddressForOrDie(CELO_UNRELEASED_TREASURY_REGISTRY_ID));
}

function getEpochManager() internal view returns (IEpochManager) {
return IEpochManager(registry.getAddressForOrDie(EPOCH_MANAGER_REGISTRY_ID));
}

function getScoreReader() internal view returns (IScoreReader) {
return IScoreReader(registry.getAddressForOrDie(SCORE_MANAGER_REGISTRY_ID));
}
}
Loading
Loading