diff --git a/packages/protocol/contracts-0.8/common/PrecompilesOverrideV2.sol b/packages/protocol/contracts-0.8/common/PrecompilesOverrideV2.sol index 4279e197fb4..647e34d3ccb 100644 --- a/packages/protocol/contracts-0.8/common/PrecompilesOverrideV2.sol +++ b/packages/protocol/contracts-0.8/common/PrecompilesOverrideV2.sol @@ -12,7 +12,7 @@ import "./UsingRegistryV2NoMento.sol"; * @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 { +abstract contract PrecompilesOverrideV2 is UsingPrecompiles, UsingRegistryV2NoMento { /** * @notice Returns the epoch number at a block. * @param blockNumber Block number where epoch number is calculated. diff --git a/packages/protocol/contracts-0.8/common/UsingRegistry2.sol b/packages/protocol/contracts-0.8/common/UsingRegistry2.sol deleted file mode 100644 index a9bfcc8d407..00000000000 --- a/packages/protocol/contracts-0.8/common/UsingRegistry2.sol +++ /dev/null @@ -1,156 +0,0 @@ -// 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)); - } -} diff --git a/packages/protocol/contracts/governance/interfaces/IValidatorsInitializer.sol b/packages/protocol/contracts-0.8/governance/interfaces/IValidatorsInitializer.sol similarity index 100% rename from packages/protocol/contracts/governance/interfaces/IValidatorsInitializer.sol rename to packages/protocol/contracts-0.8/governance/interfaces/IValidatorsInitializer.sol diff --git a/packages/protocol/lib/compatibility/utils.ts b/packages/protocol/lib/compatibility/utils.ts index fb640c71be2..c8b5d5cc80d 100644 --- a/packages/protocol/lib/compatibility/utils.ts +++ b/packages/protocol/lib/compatibility/utils.ts @@ -25,7 +25,7 @@ export class ASTBackwardReport { logFunction: (msg: string) => void): ASTBackwardReport => { // Run reports - logFunction("Running storage report...") + logFunction("Running storage report...\n") const storage = reportLayoutIncompatibilities(oldArtifacts, newArtifacts) logFunction("Done\n") diff --git a/packages/protocol/lib/web3-utils.ts b/packages/protocol/lib/web3-utils.ts index ebaae5d256a..45ec50e22ba 100644 --- a/packages/protocol/lib/web3-utils.ts +++ b/packages/protocol/lib/web3-utils.ts @@ -271,9 +271,9 @@ export function deploymentForProxiedContract { - - const artifact = require(`${path.join(__dirname, "..")}/build/contracts-${contractPath}/${contractName}.json`) +export const makeTruffleContractForMigrationWithoutSingleton = (contractName: string, network: any, contractPath: string, web3: Web3, buildDir?:string) => { + const buildDirPath = buildDir ? `../${buildDir}` : "../build/" + const artifact = require(`${path.join(__dirname, buildDirPath)}/contracts-${contractPath}/${contractName}.json`) const Contract = truffleContract({ contractName: artifact.contractName, abi: artifact.abi, diff --git a/packages/protocol/migrations_sol/Migration.s.sol b/packages/protocol/migrations_sol/Migration.s.sol index a0f4165ad12..27751459fdf 100644 --- a/packages/protocol/migrations_sol/Migration.s.sol +++ b/packages/protocol/migrations_sol/Migration.s.sol @@ -29,7 +29,7 @@ import "@celo-contracts/common/interfaces/IFeeCurrencyWhitelist.sol"; import "@celo-contracts/common/interfaces/IAccounts.sol"; import "@celo-contracts/common/interfaces/IEpochManagerEnabler.sol"; import "@celo-contracts/governance/interfaces/ILockedGoldInitializer.sol"; -import "@celo-contracts/governance/interfaces/IValidatorsInitializer.sol"; +import "@celo-contracts-8/governance/interfaces/IValidatorsInitializer.sol"; import "@celo-contracts/governance/interfaces/IElectionInitializer.sol"; import "@celo-contracts/governance/interfaces/IEpochRewardsInitializer.sol"; import "@celo-contracts/governance/interfaces/IBlockchainParametersInitializer.sol"; diff --git a/packages/protocol/scripts/bash/contract-exclusion-regex.sh b/packages/protocol/scripts/bash/contract-exclusion-regex.sh index 207684a2e79..a8e966107ec 100644 --- a/packages/protocol/scripts/bash/contract-exclusion-regex.sh +++ b/packages/protocol/scripts/bash/contract-exclusion-regex.sh @@ -3,10 +3,12 @@ set -euo pipefail # Exclude test contracts, mock contracts, contract interfaces, Proxy contracts, inlined libraries, # MultiSig contracts, and the ReleaseGold contract. -CONTRACT_EXCLUSION_REGEX=".*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles|CeloFeeCurrencyAdapterOwnable|FeeCurrencyAdapter|FeeCurrencyAdapterOwnable" +CONTRACT_EXCLUSION_REGEX=".*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles|CeloFeeCurrencyAdapterOwnable|FeeCurrencyAdapter|FeeCurrencyAdapterOwnable|IsL2Check|Blockable|PrecompilesOverride|CompileExchange|PrecompilesOverrideV2|UsingRegistryV2NoMento" + +echo "BRANCH: $BRANCH" # Before CR7, UsingRegistry and UsingRegistryV2 had been deployed, they need to keep getting deployed to keep the release reports without changes. -VERSION_NUMBER=$(echo "$BRANCH" | tr -dc '0-9') +VERSION_NUMBER=$(echo "$BRANCH" | grep -o 'v[0-9]\+' | tr -dc '0-9') echo "VERSION_NUMBER: $VERSION_NUMBER" @@ -35,5 +37,7 @@ fi if [ $VERSION_NUMBER -eq 12 ] then # FeeHandlerSeller is not deployed, only its children - CONTRACT_EXCLUSION_REGEX="$CONTRACT_EXCLUSION_REGEX|\\bFeeHandlerSeller\\b" + CONTRACT_EXCLUSION_REGEX="$CONTRACT_EXCLUSION_REGEX|MockElection|\\bFeeHandlerSeller\\b" fi + +echo "FULL CONTRACT_EXCLUSION_REGEX: $CONTRACT_EXCLUSION_REGEX" \ No newline at end of file diff --git a/packages/protocol/scripts/bash/release-lib.sh b/packages/protocol/scripts/bash/release-lib.sh index 09423289191..af240a67f89 100644 --- a/packages/protocol/scripts/bash/release-lib.sh +++ b/packages/protocol/scripts/bash/release-lib.sh @@ -11,10 +11,11 @@ function build_tag() { local BRANCH="$1" local LOG_FILE="$2" + echo "Writing logs to $LOG_FILE" + local CURRENT_HASH=`git log -n 1 --oneline | cut -c 1-9` git fetch origin +'refs/tags/core-contracts.v*:refs/tags/core-contracts.v*' >> $LOG_FILE - echo " - Checkout contracts source code at $BRANCH" BUILD_DIR=$(echo build/$(echo $BRANCH | sed -e 's/\//_/g')) [ -d contracts ] && rm -r contracts @@ -22,7 +23,6 @@ function build_tag() { # this remove is necesary because when bringing a contracts folder from previous commit # if a folder didn't exist in the past, git will not remove the current one # trying to compile it and leading to potental build errors - rm -rf contracts* git checkout $BRANCH -- contracts* 2>>$LOG_FILE >> $LOG_FILE if [ ! -d $BUILD_DIR ]; then @@ -34,4 +34,4 @@ function build_tag() { [ -d contracts ] && rm -r contracts git checkout $CURRENT_HASH -- contracts 2>>$LOG_FILE >> $LOG_FILE -} +} \ No newline at end of file diff --git a/packages/protocol/scripts/truffle/make-release.ts b/packages/protocol/scripts/truffle/make-release.ts index 440fd8a4566..4a8b30add34 100644 --- a/packages/protocol/scripts/truffle/make-release.ts +++ b/packages/protocol/scripts/truffle/make-release.ts @@ -324,7 +324,8 @@ module.exports = async (callback: (error?: any) => number) => { contractName, { ...networks[argv.network], name: argv.network }, SOLIDITY_08_PACKAGE.name, - web3 + web3, + argv.build_directory ) // TODO WARNING: make sure there are no libraries with the same name that don't get deployed } diff --git a/packages/protocol/test-sol/constants.sol b/packages/protocol/test-sol/constants.sol index 8ca9372f1c2..43f4f4ef712 100644 --- a/packages/protocol/test-sol/constants.sol +++ b/packages/protocol/test-sol/constants.sol @@ -6,13 +6,10 @@ contract TestConstants { uint256 public constant FIXED1 = 1e24; uint256 public constant MINUTE = 60; uint256 public constant HOUR = 60 * MINUTE; - // uint256 public constant DAY = 24 * HOUR; - uint256 public constant MONTH = 30 * 86400; - // uint256 public constant MONTH = 30 * DAY; - uint256 constant WEEK = 7 * 86400; - // uint256 constant WEEK = 7 * DAY; - uint256 public constant YEAR = 365 * 86400; - // uint256 public constant YEAR = 365 * DAY; + uint256 public constant DAY_IN_SECONDS = 86400; + uint256 public constant MONTH = 30 * DAY_IN_SECONDS; + uint256 constant WEEK = 7 * DAY_IN_SECONDS; + uint256 public constant YEAR = 365 * DAY_IN_SECONDS; uint256 public constant L1_BLOCK_IN_EPOCH = 17280; uint256 public constant L2_BLOCK_IN_EPOCH = 43200; diff --git a/packages/protocol/test-sol/devchain/e2e/utils.sol b/packages/protocol/test-sol/devchain/e2e/utils.sol index a45f41d3594..804e14aef89 100644 --- a/packages/protocol/test-sol/devchain/e2e/utils.sol +++ b/packages/protocol/test-sol/devchain/e2e/utils.sol @@ -52,5 +52,6 @@ contract Devchain is TestWithUtils08 { } function setUp() public virtual override { // Added to avoid adding a setup function in each e2e test, when its not required. + // Note: This function does not call `super.setUp()`, because we dont want to run the parent's setup. } } diff --git a/packages/protocol/test-sol/unit/common/FeeCurrencyDirectory.t.sol b/packages/protocol/test-sol/unit/common/FeeCurrencyDirectory.t.sol index 4c015e76746..51da01075f3 100644 --- a/packages/protocol/test-sol/unit/common/FeeCurrencyDirectory.t.sol +++ b/packages/protocol/test-sol/unit/common/FeeCurrencyDirectory.t.sol @@ -27,7 +27,7 @@ contract FeeCurrencyDirectoryTest is TestWithUtils08 { } contract FeeCurrencyDirectoryTest_L2 is FeeCurrencyDirectoryTest, WhenL2 { - function setUp() public override(FeeCurrencyDirectoryTest, WhenL2) { + function setUp() public virtual override(FeeCurrencyDirectoryTest, WhenL2) { super.setUp(); } } @@ -84,8 +84,14 @@ contract TestSetCurrencyConfig is FeeCurrencyDirectoryTest { } } +contract TestSetCurrencyConfig_L2 is FeeCurrencyDirectoryTest_L2, TestSetCurrencyConfig { + function setUp() public override(FeeCurrencyDirectoryTest, FeeCurrencyDirectoryTest_L2) { + super.setUp(); + } +} + contract TestRemoveCurrencies is FeeCurrencyDirectoryTest { - function setUp() public override { + function setUp() public virtual override { super.setUp(); address token = address(4); directory.setCurrencyConfig(token, address(oracle), 21000); @@ -127,10 +133,16 @@ contract TestRemoveCurrencies is FeeCurrencyDirectoryTest { } } +contract TestRemoveCurrencies_L2 is FeeCurrencyDirectoryTest_L2, TestRemoveCurrencies { + function setUp() public override(TestRemoveCurrencies, FeeCurrencyDirectoryTest_L2) { + super.setUp(); + } +} + contract TestGetExchangeRate is FeeCurrencyDirectoryTest { address token; - function setUp() public override { + function setUp() public virtual override { super.setUp(); token = address(3); oracle.setExchangeRate(token, 200, 4); // 50:1 ratio @@ -148,3 +160,9 @@ contract TestGetExchangeRate is FeeCurrencyDirectoryTest { directory.getExchangeRate(address(4)); } } + +contract TestGetExchangeRate_L2 is FeeCurrencyDirectoryTest_L2, TestGetExchangeRate { + function setUp() public override(TestGetExchangeRate, FeeCurrencyDirectoryTest_L2) { + super.setUp(); + } +} diff --git a/packages/protocol/test-sol/unit/common/ProxyFactory08.t.sol b/packages/protocol/test-sol/unit/common/ProxyFactory08.t.sol index cbb83d24ab1..0ad37c022b0 100644 --- a/packages/protocol/test-sol/unit/common/ProxyFactory08.t.sol +++ b/packages/protocol/test-sol/unit/common/ProxyFactory08.t.sol @@ -1,6 +1,5 @@ pragma solidity ^0.8.15; -// import "celo-foundry-8/Test.sol"; import "@celo-contracts-8/common/ProxyFactory08.sol"; import "@celo-contracts/common/interfaces/IProxy.sol";