-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
520 additions
and
28 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/protocol/contracts-0.8/common/PrecompilesOverrideV2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "./UsingRegistryV2.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, UsingRegistryV2 { | ||
/** | ||
* @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
156
packages/protocol/contracts-0.8/common/UsingRegistry2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.