diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f75a2a8..0cdc3e98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: cache: "npm" - run: npm ci - run: npx hardhat compile --show-stack-traces - - run: TS_NODE_TRANSPILE_ONLY=1 npx hardhat test --parallel + - run: TS_NODE_TRANSPILE_ONLY=1 npx hardhat test forge_tests: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index f260b6d1..c91de7f4 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Some contracts in the Edge suite need be deployed only once on root. These contr Other contracts are deployed on root once per Supernet. These contracts can deployed using the [`DeployNewRootContractSet.s.sol`](script/deployment/DeployNewRootContractSet.s.sol) script, after [`rootContractSetConfig.json`](script/deployment/rootContractSetConfig.json) has been filled with appropriate values. -Note that the script does not initialize `CheckpointManager`. Instead protects it to be initializable only by the `INITIALIZER` address later. +Note that the script does not initialize `CheckpointManager`. Instead, it protects it to be initializable only by the `INITIATOR` address later. Not all root contracts are deployed at this point, however. There are parts of the bridge that need the addresses of various child contracts in order to be initialized. These contracts can deployed using the [`DeployRootTokenContracts.s.sol`](script/deployment/DeployRootTokenContracts.s.sol) script, after [`rootTokenContractsConfig.json`](script/deployment/rootTokenContractsConfig.json) has been filled with appropriate values. diff --git a/contracts/child/ChildERC1155.sol b/contracts/child/ChildERC1155.sol index a3507cbf..a7dfdaee 100644 --- a/contracts/child/ChildERC1155.sol +++ b/contracts/child/ChildERC1155.sol @@ -24,6 +24,10 @@ contract ChildERC1155 is EIP712MetaTransaction, ERC1155Upgradeable, IChildERC115 _; } + constructor() { + _disableInitializers(); + } + /** * @inheritdoc IChildERC1155 */ diff --git a/contracts/child/ChildERC1155Predicate.sol b/contracts/child/ChildERC1155Predicate.sol index 91188781..09219c54 100644 --- a/contracts/child/ChildERC1155Predicate.sol +++ b/contracts/child/ChildERC1155Predicate.sol @@ -71,6 +71,10 @@ contract ChildERC1155Predicate is IChildERC1155Predicate, Initializable, System _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildERC1155Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/ChildERC1155PredicateAccessList.sol b/contracts/child/ChildERC1155PredicateAccessList.sol index 449ebc93..dbf082a3 100644 --- a/contracts/child/ChildERC1155PredicateAccessList.sol +++ b/contracts/child/ChildERC1155PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract ChildERC1155PredicateAccessList is AccessList, ChildERC1155Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/ChildERC20.sol b/contracts/child/ChildERC20.sol index d0513a73..8eb57a3f 100644 --- a/contracts/child/ChildERC20.sol +++ b/contracts/child/ChildERC20.sol @@ -25,6 +25,10 @@ contract ChildERC20 is EIP712MetaTransaction, ERC20Upgradeable, IChildERC20 { _; } + constructor() { + _disableInitializers(); + } + /** * @inheritdoc IChildERC20 */ diff --git a/contracts/child/ChildERC20Predicate.sol b/contracts/child/ChildERC20Predicate.sol index ac1d515e..ae8f8587 100644 --- a/contracts/child/ChildERC20Predicate.sol +++ b/contracts/child/ChildERC20Predicate.sol @@ -49,6 +49,10 @@ contract ChildERC20Predicate is IChildERC20Predicate, Initializable, System { ); event L2TokenMapped(address indexed rootToken, address indexed childToken); + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildERC20Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/ChildERC20PredicateAccessList.sol b/contracts/child/ChildERC20PredicateAccessList.sol index cf927f84..babdd7b7 100644 --- a/contracts/child/ChildERC20PredicateAccessList.sol +++ b/contracts/child/ChildERC20PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract ChildERC20PredicateAccessList is AccessList, ChildERC20Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/ChildERC721.sol b/contracts/child/ChildERC721.sol index 3841066d..7ff6dd1c 100644 --- a/contracts/child/ChildERC721.sol +++ b/contracts/child/ChildERC721.sol @@ -22,6 +22,10 @@ contract ChildERC721 is EIP712MetaTransaction, ERC721Upgradeable, IChildERC721 { _; } + constructor() { + _disableInitializers(); + } + /** * @inheritdoc IChildERC721 */ diff --git a/contracts/child/ChildERC721Predicate.sol b/contracts/child/ChildERC721Predicate.sol index bf13fc3e..a762c1dd 100644 --- a/contracts/child/ChildERC721Predicate.sol +++ b/contracts/child/ChildERC721Predicate.sol @@ -67,6 +67,10 @@ contract ChildERC721Predicate is IChildERC721Predicate, Initializable, System { _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildERC721Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/ChildERC721PredicateAccessList.sol b/contracts/child/ChildERC721PredicateAccessList.sol index 69c4b014..c0852894 100644 --- a/contracts/child/ChildERC721PredicateAccessList.sol +++ b/contracts/child/ChildERC721PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract ChildERC721PredicateAccessList is AccessList, ChildERC721Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/EIP1559Burn.sol b/contracts/child/EIP1559Burn.sol index 8a4b8add..eec4ef0c 100644 --- a/contracts/child/EIP1559Burn.sol +++ b/contracts/child/EIP1559Burn.sol @@ -20,6 +20,10 @@ contract EIP1559Burn is Initializable { // slither-disable-next-line locked-ether receive() external payable {} // solhint-disable-line no-empty-blocks + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for EIP1559 burn contract * @param newChildERC20Predicate Address of the ERC20 predicate on child chain diff --git a/contracts/child/ForkParams.sol b/contracts/child/ForkParams.sol deleted file mode 100644 index b1c297dd..00000000 --- a/contracts/child/ForkParams.sol +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -import "@openzeppelin/contracts/access/Ownable.sol"; -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; - -/** - @title ForkParams - @author Polygon Technology (@QEDK) - @notice Configurable softfork features that are read by the client on each epoch - @dev The contract allows for configurable softfork parameters without genesis updation - */ -contract ForkParams is Ownable, Initializable { - mapping(bytes32 => uint256) public featureToBlockNumber; // keccak256("FEATURE_NAME") -> blockNumber - - event NewFeature(bytes32 indexed feature, uint256 indexed block); - event UpdatedFeature(bytes32 indexed feature, uint256 indexed block); - - /** - * @notice initialize function to set the owner - * @param newOwner address to transfer the ownership to - */ - function initialize(address newOwner) public initializer { - _transferOwnership(newOwner); - } - - /** - * @notice function to add a new feature at a block number - * @dev block number must be set in the future and feature must already not be scheduled - * @param blockNumber block number to schedule the feature - * @param feature feature name to schedule - */ - function addNewFeature(uint256 blockNumber, string calldata feature) external onlyOwner { - require(blockNumber >= block.number, "ForkParams: INVALID_BLOCK"); - bytes32 featureHash = keccak256(abi.encode(feature)); - require(featureToBlockNumber[featureHash] == 0, "ForkParams: FEATURE_EXISTS"); - featureToBlockNumber[featureHash] = blockNumber; - - emit NewFeature(featureHash, blockNumber); - } - - /** - * @notice function to update the block number for a feature - * @dev block number must be set in the future and feature must already be scheduled - * @param newBlockNumber new block number to schedule the feature at - * @param feature feature name to schedule - */ - function updateFeatureBlock(uint256 newBlockNumber, string calldata feature) external onlyOwner { - bytes32 featureHash = keccak256(abi.encode(feature)); - uint256 featureBlock = featureToBlockNumber[featureHash]; - require(featureBlock != 0, "ForkParams: NONEXISTENT_FEATURE"); - require(newBlockNumber >= block.number && block.number < featureBlock, "ForkParams: INVALID_BLOCK"); - featureToBlockNumber[featureHash] = newBlockNumber; - - emit UpdatedFeature(featureHash, newBlockNumber); - } - - /** - * @notice function to check if a feature is activated - * @dev returns true if feature is activated, false if feature is scheduled in the future and reverts if feature does not exists - * @param feature feature name to check for activation - */ - function isFeatureActivated(string calldata feature) external view returns (bool) { - uint256 featureBlock = featureToBlockNumber[keccak256(abi.encode(feature))]; - require(featureBlock != 0, "ForkParams: NONEXISTENT_FEATURE"); - if (block.number >= featureBlock) { - return true; - } - return false; - } -} diff --git a/contracts/child/NativeERC20.sol b/contracts/child/NativeERC20.sol index 543d80ac..35d4e751 100644 --- a/contracts/child/NativeERC20.sol +++ b/contracts/child/NativeERC20.sol @@ -30,6 +30,10 @@ contract NativeERC20 is Context, Initializable, System, INativeERC20 { _; } + constructor() { + _disableInitializers(); + } + /** * @dev Sets the values for {predicate}, {name} and {symbol}. * diff --git a/contracts/child/NativeERC20Mintable.sol b/contracts/child/NativeERC20Mintable.sol index 0d84fb0c..b262fc73 100644 --- a/contracts/child/NativeERC20Mintable.sol +++ b/contracts/child/NativeERC20Mintable.sol @@ -31,6 +31,10 @@ contract NativeERC20Mintable is Context, Initializable, System, Ownable2Step, IE _; } + constructor() { + _disableInitializers(); + } + /** * @dev Sets the values for {predicate}, {name} and {symbol}. * diff --git a/contracts/child/NetworkParams.sol b/contracts/child/NetworkParams.sol deleted file mode 100644 index f167ebde..00000000 --- a/contracts/child/NetworkParams.sol +++ /dev/null @@ -1,249 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -import "@openzeppelin/contracts/access/Ownable2Step.sol"; -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; - -/** - @title NetworkParams - @author Polygon Technology (@QEDK) - @notice Configurable network parameters that are read by the client on each epoch - @dev The contract allows for configurable network parameters without the need for a hardfork - */ -contract NetworkParams is Ownable2Step, Initializable { - struct InitParams { - address newOwner; - uint256 newCheckpointBlockInterval; // in blocks - uint256 newEpochSize; // in blocks - uint256 newEpochReward; // in wei - uint256 newSprintSize; // in blocks - uint256 newMinValidatorSetSize; - uint256 newMaxValidatorSetSize; - uint256 newWithdrawalWaitPeriod; // in blocks - uint256 newBlockTime; // in seconds - uint256 newBlockTimeDrift; // in seconds - uint256 newVotingDelay; // in blocks - uint256 newVotingPeriod; // in blocks - uint256 newProposalThreshold; // in percent - uint256 newBaseFeeChangeDenom; // in wei - } - - uint256 public checkpointBlockInterval; // in blocks - uint256 public epochSize; // in blocks - uint256 public epochReward; // in wei - uint256 public sprintSize; // in blocks - uint256 public minValidatorSetSize; - uint256 public maxValidatorSetSize; - uint256 public withdrawalWaitPeriod; // in blocks - uint256 public blockTime; // in seconds - uint256 public blockTimeDrift; // in seconds - uint256 public votingDelay; // in blocks - uint256 public votingPeriod; // in blocks - uint256 public proposalThreshold; // in percent - uint256 public baseFeeChangeDenom; // in wei - - event NewCheckpointBlockInterval(uint256 indexed checkpointInterval); - event NewEpochSize(uint256 indexed size); - event NewEpochReward(uint256 indexed reward); - event NewSprintSize(uint256 indexed size); - event NewMinValidatorSetSize(uint256 indexed minValidatorSet); - event NewMaxValidatorSetSize(uint256 indexed maxValidatorSet); - event NewWithdrawalWaitPeriod(uint256 indexed withdrawalPeriod); - event NewBlockTime(uint256 indexed blockTime); - event NewBlockTimeDrift(uint256 indexed blockTimeDrift); - event NewVotingDelay(uint256 indexed votingDelay); - event NewVotingPeriod(uint256 indexed votingPeriod); - event NewProposalThreshold(uint256 indexed proposalThreshold); - event NewBaseFeeChangeDenom(uint256 indexed baseFeeChangeDenom); - - /** - * @notice initializer for NetworkParams, sets the initial set of values for the network - * @dev disallows setting of zero values for sanity check purposes - * @param initParams initial set of values for the network - */ - function initialize(InitParams memory initParams) public initializer { - require( - initParams.newOwner != address(0) && - initParams.newCheckpointBlockInterval != 0 && - initParams.newEpochSize != 0 && - initParams.newSprintSize != 0 && - initParams.newMinValidatorSetSize != 0 && - initParams.newMaxValidatorSetSize != 0 && - initParams.newWithdrawalWaitPeriod != 0 && - initParams.newBlockTime != 0 && - initParams.newBlockTimeDrift != 0 && - initParams.newVotingPeriod != 0 && - initParams.newBaseFeeChangeDenom != 0, - "NetworkParams: INVALID_INPUT" - ); - checkpointBlockInterval = initParams.newCheckpointBlockInterval; - epochSize = initParams.newEpochSize; - epochReward = initParams.newEpochReward; - sprintSize = initParams.newSprintSize; - minValidatorSetSize = initParams.newMinValidatorSetSize; - maxValidatorSetSize = initParams.newMaxValidatorSetSize; - withdrawalWaitPeriod = initParams.newWithdrawalWaitPeriod; - blockTime = initParams.newBlockTime; - blockTimeDrift = initParams.newBlockTimeDrift; - votingDelay = initParams.newVotingDelay; - votingPeriod = initParams.newVotingPeriod; - proposalThreshold = initParams.newProposalThreshold; - baseFeeChangeDenom = initParams.newBaseFeeChangeDenom; - _transferOwnership(initParams.newOwner); - } - - /** - * @notice function to set new checkpoint block interval - * @dev disallows setting of a zero value for sanity check purposes - * @param newCheckpointBlockInterval new checkpoint block interval - */ - function setNewCheckpointBlockInterval(uint256 newCheckpointBlockInterval) external onlyOwner { - require(newCheckpointBlockInterval != 0, "NetworkParams: INVALID_CHECKPOINT_INTERVAL"); - checkpointBlockInterval = newCheckpointBlockInterval; - - emit NewCheckpointBlockInterval(newCheckpointBlockInterval); - } - - /** - * @notice function to set new epoch size - * @dev disallows setting of a zero value for sanity check purposes - * @param newEpochSize new epoch reward - */ - function setNewEpochSize(uint256 newEpochSize) external onlyOwner { - require(newEpochSize != 0, "NetworkParams: INVALID_EPOCH_SIZE"); - epochSize = newEpochSize; - - emit NewEpochSize(newEpochSize); - } - - /** - * @notice function to set new epoch reward - * @dev disallows setting of a zero value for sanity check purposes - * @param newEpochReward new epoch reward - */ - function setNewEpochReward(uint256 newEpochReward) external onlyOwner { - epochReward = newEpochReward; - - emit NewEpochReward(newEpochReward); - } - - /** - * @notice function to set new sprint size - * @dev disallows setting of a zero value for sanity check purposes - * @param newSprintSize new sprint size - */ - function setNewSprintSize(uint256 newSprintSize) external onlyOwner { - require(newSprintSize != 0, "NetworkParams: INVALID_SPRINT_SIZE"); - sprintSize = newSprintSize; - - emit NewSprintSize(newSprintSize); - } - - /** - * @notice function to set new minimum validator set size - * @dev disallows setting of a zero value for sanity check purposes - * @param newMinValidatorSetSize new minimum validator set size - */ - // slither-disable-next-line similar-names - function setNewMinValidatorSetSize(uint256 newMinValidatorSetSize) external onlyOwner { - require(newMinValidatorSetSize != 0, "NetworkParams: INVALID_MIN_VALIDATOR_SET_SIZE"); - minValidatorSetSize = newMinValidatorSetSize; - - emit NewMinValidatorSetSize(newMinValidatorSetSize); - } - - /** - * @notice function to set new maximum validator set size - * @dev disallows setting of a zero value for sanity check purposes - * @param newMaxValidatorSetSize new maximum validator set size - */ - // slither-disable-next-line similar-names - function setNewMaxValidatorSetSize(uint256 newMaxValidatorSetSize) external onlyOwner { - require(newMaxValidatorSetSize != 0, "NetworkParams: INVALID_MAX_VALIDATOR_SET_SIZE"); - maxValidatorSetSize = newMaxValidatorSetSize; - - emit NewMaxValidatorSetSize(newMaxValidatorSetSize); - } - - /** - * @notice function to set new withdrawal wait period - * @dev disallows setting of a zero value for sanity check purposes - * @param newWithdrawalWaitPeriod new withdrawal wait period - */ - function setNewWithdrawalWaitPeriod(uint256 newWithdrawalWaitPeriod) external onlyOwner { - require(newWithdrawalWaitPeriod != 0, "NetworkParams: INVALID_WITHDRAWAL_WAIT_PERIOD"); - withdrawalWaitPeriod = newWithdrawalWaitPeriod; - - emit NewWithdrawalWaitPeriod(newWithdrawalWaitPeriod); - } - - /** - * @notice function to set new block time - * @dev disallows setting of a zero value for sanity check purposes - * @param newBlockTime new block time - */ - function setNewBlockTime(uint256 newBlockTime) external onlyOwner { - require(newBlockTime != 0, "NetworkParams: INVALID_BLOCK_TIME"); - blockTime = newBlockTime; - - emit NewBlockTime(newBlockTime); - } - - /** - * @notice function to set new block time drift - * @dev disallows setting of a zero value for sanity check purposes - * @param newBlockTimeDrift new block time drift - */ - function setNewBlockTimeDrift(uint256 newBlockTimeDrift) external onlyOwner { - require(newBlockTimeDrift != 0, "NetworkParams: INVALID_BLOCK_TIME_DRIFT"); - blockTimeDrift = newBlockTimeDrift; - - emit NewBlockTimeDrift(newBlockTimeDrift); - } - - /** - * @notice function to set new voting delay - * @dev disallows setting of a zero value for sanity check purposes - * @param newVotingDelay new voting delay - */ - function setNewVotingDelay(uint256 newVotingDelay) external onlyOwner { - votingDelay = newVotingDelay; - - emit NewVotingDelay(newVotingDelay); - } - - /** - * @notice function to set new voting period - * @dev disallows setting of a zero value for sanity check purposes - * @param newVotingPeriod new voting period - */ - function setNewVotingPeriod(uint256 newVotingPeriod) external onlyOwner { - require(newVotingPeriod != 0, "NetworkParams: INVALID_VOTING_PERIOD"); - votingPeriod = newVotingPeriod; - - emit NewVotingPeriod(newVotingPeriod); - } - - /** - * @notice function to set new proposal threshold - * @dev disallows setting of a zero value for sanity check purposes - * @param newProposalThreshold new proposal threshold - */ - function setNewProposalThreshold(uint256 newProposalThreshold) external onlyOwner { - proposalThreshold = newProposalThreshold; - - emit NewProposalThreshold(newProposalThreshold); - } - - /** - * @notice function to set new base fee change denominator - * @dev disallows setting of a zero value for sanity check purposes - * @param newBaseFeeChangeDenom new base fee change denominator - */ - function setNewBaseFeeChangeDenom(uint256 newBaseFeeChangeDenom) external onlyOwner { - require(newBaseFeeChangeDenom != 0, "NetworkParams: INVALID_BASE_FEE_CHANGE_DENOM"); - baseFeeChangeDenom = newBaseFeeChangeDenom; - - emit NewBaseFeeChangeDenom(newBaseFeeChangeDenom); - } -} diff --git a/contracts/child/README.md b/contracts/child/README.md index 4a39a121..d2dc4b3e 100644 --- a/contracts/child/README.md +++ b/contracts/child/README.md @@ -14,18 +14,10 @@ The predicate contracts provide an interface for the bridge to manage transactio For use in Supernets that wish to have a mechanism similar to EIP1559, burning a portion of the assets used to pay gas fees - the fees are sent to this contract, then withdrawn to root to be burnt. -## ForkParams - -Allows for the inclusion of softfork features on the child chain. Read by the client each epoch. - ## L2StateSender A simple arbitrary message bridge for sending messages from child to root. -## NetworkParams - -Configurable network parameters (such as validator set size and block gas limit) that are read by the client each epoch. - ## State Receiver This contract represents the child side of the message bridge. diff --git a/contracts/child/RootMintableERC1155Predicate.sol b/contracts/child/RootMintableERC1155Predicate.sol index e5e625e0..e720ef51 100644 --- a/contracts/child/RootMintableERC1155Predicate.sol +++ b/contracts/child/RootMintableERC1155Predicate.sol @@ -20,6 +20,10 @@ contract RootMintableERC1155Predicate is Initializable, ERC1155Holder, IRootMint bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootMintableERC1155Predicate * @param newL2StateSender Address of L2StateSender to send deposit information to diff --git a/contracts/child/RootMintableERC1155PredicateAccessList.sol b/contracts/child/RootMintableERC1155PredicateAccessList.sol index c4b79740..34296ab7 100644 --- a/contracts/child/RootMintableERC1155PredicateAccessList.sol +++ b/contracts/child/RootMintableERC1155PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract RootMintableERC1155PredicateAccessList is AccessList, RootMintableERC1155Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/RootMintableERC20Predicate.sol b/contracts/child/RootMintableERC20Predicate.sol index 1d9e8314..28814285 100644 --- a/contracts/child/RootMintableERC20Predicate.sol +++ b/contracts/child/RootMintableERC20Predicate.sol @@ -26,6 +26,10 @@ contract RootMintableERC20Predicate is IRootMintableERC20Predicate, Initializabl bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootMintableERC20Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/RootMintableERC20PredicateAccessList.sol b/contracts/child/RootMintableERC20PredicateAccessList.sol index 97dee441..e2373b92 100644 --- a/contracts/child/RootMintableERC20PredicateAccessList.sol +++ b/contracts/child/RootMintableERC20PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract RootMintableERC20PredicateAccessList is AccessList, RootMintableERC20Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/RootMintableERC721Predicate.sol b/contracts/child/RootMintableERC721Predicate.sol index 8524122a..293db17e 100644 --- a/contracts/child/RootMintableERC721Predicate.sol +++ b/contracts/child/RootMintableERC721Predicate.sol @@ -21,6 +21,10 @@ contract RootMintableERC721Predicate is Initializable, ERC721Holder, System, IRo bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootMintableERC721Predicate * @param newL2StateSender Address of L2StateSender to send deposit information to diff --git a/contracts/child/RootMintableERC721PredicateAccessList.sol b/contracts/child/RootMintableERC721PredicateAccessList.sol index 9064bc99..e58a47b6 100644 --- a/contracts/child/RootMintableERC721PredicateAccessList.sol +++ b/contracts/child/RootMintableERC721PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract RootMintableERC721PredicateAccessList is AccessList, RootMintableERC721Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/governance/ChildGovernor.sol b/contracts/child/governance/ChildGovernor.sol deleted file mode 100644 index 6f8828dc..00000000 --- a/contracts/child/governance/ChildGovernor.sol +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -import "@openzeppelin/contracts-upgradeable/governance/GovernorUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/governance/compatibility/GovernorCompatibilityBravoUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol"; - -import {NetworkParams} from "contracts/child/NetworkParams.sol"; - -contract ChildGovernor is - GovernorUpgradeable, - GovernorCompatibilityBravoUpgradeable, - GovernorVotesUpgradeable, - GovernorVotesQuorumFractionUpgradeable, - GovernorTimelockControlUpgradeable -{ - NetworkParams private _networkParams; - - function initialize( - IVotesUpgradeable token_, - TimelockControllerUpgradeable timelock_, - uint256 quorumNumerator_, - address networkParams - ) public initializer { - __Governor_init("ChildGovernor"); - __GovernorTimelockControl_init(timelock_); - __GovernorVotes_init(token_); - __GovernorVotesQuorumFraction_init(quorumNumerator_); - - _networkParams = NetworkParams(networkParams); - } - - // TODO: adjust values for block time of child chain - - function votingDelay() public view override returns (uint256) { - return _networkParams.votingDelay(); - } - - function votingPeriod() public view override returns (uint256) { - return _networkParams.votingPeriod(); - } - - // END TODO - - function proposalThreshold() public view override returns (uint256) { - return _networkParams.proposalThreshold(); - } - - // The functions below are overrides required by Solidity. - - function state( - uint256 proposalId - ) - public - view - override(GovernorUpgradeable, IGovernorUpgradeable, GovernorTimelockControlUpgradeable) - returns (ProposalState) - { - return super.state(proposalId); - } - - function propose( - address[] memory targets, - uint256[] memory values, - bytes[] memory calldatas, - string memory description - ) - public - override(GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable, IGovernorUpgradeable) - returns (uint256) - { - return super.propose(targets, values, calldatas, description); - } - - function _execute( - uint256 proposalId, - address[] memory targets, - uint256[] memory values, - bytes[] memory calldatas, - bytes32 descriptionHash - ) internal override(GovernorUpgradeable, GovernorTimelockControlUpgradeable) { - super._execute(proposalId, targets, values, calldatas, descriptionHash); - } - - function _cancel( - address[] memory targets, - uint256[] memory values, - bytes[] memory calldatas, - bytes32 descriptionHash - ) internal override(GovernorUpgradeable, GovernorTimelockControlUpgradeable) returns (uint256) { - return super._cancel(targets, values, calldatas, descriptionHash); - } - - function _executor() - internal - view - override(GovernorUpgradeable, GovernorTimelockControlUpgradeable) - returns (address) - { - return super._executor(); - } - - function supportsInterface( - bytes4 interfaceId - ) public view override(GovernorUpgradeable, IERC165Upgradeable, GovernorTimelockControlUpgradeable) returns (bool) { - return super.supportsInterface(interfaceId); - } - - function cancel( - address[] memory targets, - uint256[] memory values, - bytes[] memory calldatas, - bytes32 descriptionHash - ) - public - override(IGovernorUpgradeable, GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable) - returns (uint256) - { - return super.cancel(targets, values, calldatas, descriptionHash); - } -} diff --git a/contracts/child/governance/ChildTimelock.sol b/contracts/child/governance/ChildTimelock.sol deleted file mode 100644 index adc826b4..00000000 --- a/contracts/child/governance/ChildTimelock.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol"; - -contract ChildTimelock is TimelockControllerUpgradeable { - function initialize( - uint256 minDelay, - address[] memory proposers, - address[] memory executors, - address admin - ) public initializer { - __TimelockController_init(minDelay, proposers, executors, admin); - } -} diff --git a/contracts/child/governance/README.md b/contracts/child/governance/README.md deleted file mode 100644 index 0900ba82..00000000 --- a/contracts/child/governance/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Governance - -This directory contains contracts used in the governance of specific Supernets, and live on the Supernet itself. - -## ChildGovernor - -An implementation of OpenZeppelin's Governor Bravo (from the upgradeable version). - -## ChildTimelock - -A timelock in order to create a set delay between the initiation of a proposal and its execution. (An implementation of a base contract from OpenZeppelin which does the same.) diff --git a/contracts/child/validator/RewardPool.sol b/contracts/child/validator/RewardPool.sol index 72b7fa95..5865f274 100644 --- a/contracts/child/validator/RewardPool.sol +++ b/contracts/child/validator/RewardPool.sol @@ -7,25 +7,26 @@ import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeab import "../System.sol"; import "../../interfaces/child/validator/IRewardPool.sol"; -import {NetworkParams} from "contracts/child/NetworkParams.sol"; - contract RewardPool is IRewardPool, System, Initializable { using SafeERC20Upgradeable for IERC20Upgradeable; IERC20Upgradeable public rewardToken; address public rewardWallet; IValidatorSet public validatorSet; + uint256 public baseReward; mapping(uint256 => uint256) public paidRewardPerEpoch; mapping(address => uint256) public pendingRewards; - NetworkParams private _networkParams; + constructor() { + _disableInitializers(); + } function initialize( address newRewardToken, address newRewardWallet, address newValidatorSet, - address networkParamsAddr + uint256 newBaseReward ) public initializer { require( newRewardToken != address(0) && newRewardWallet != address(0) && newValidatorSet != address(0), @@ -35,19 +36,19 @@ contract RewardPool is IRewardPool, System, Initializable { rewardToken = IERC20Upgradeable(newRewardToken); rewardWallet = newRewardWallet; validatorSet = IValidatorSet(newValidatorSet); - - _networkParams = NetworkParams(networkParamsAddr); + baseReward = newBaseReward; } /** * @inheritdoc IRewardPool */ - function distributeRewardFor(uint256 epochId, Uptime[] calldata uptime, uint256 epochSize) external onlySystemCall { + function distributeRewardFor(uint256 epochId, Uptime[] calldata uptime) external onlySystemCall { require(paidRewardPerEpoch[epochId] == 0, "REWARD_ALREADY_DISTRIBUTED"); uint256 totalBlocks = validatorSet.totalBlocks(epochId); require(totalBlocks != 0, "EPOCH_NOT_COMMITTED"); + uint256 epochSize = validatorSet.EPOCH_SIZE(); // slither-disable-next-line divide-before-multiply - uint256 reward = (_networkParams.epochReward() * totalBlocks) / epochSize; + uint256 reward = (baseReward * totalBlocks) / epochSize; // TODO disincentivize long epoch times uint256 totalSupply = validatorSet.totalSupplyAt(epochId); diff --git a/contracts/child/validator/ValidatorSet.sol b/contracts/child/validator/ValidatorSet.sol index e6a0dfb8..8435cc3c 100644 --- a/contracts/child/validator/ValidatorSet.sol +++ b/contracts/child/validator/ValidatorSet.sol @@ -1,26 +1,24 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.19; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol"; import "../../lib/WithdrawalQueue.sol"; import "../../interfaces/child/validator/IValidatorSet.sol"; import "../../interfaces/IStateSender.sol"; -import "../../child/NetworkParams.sol"; import "../System.sol"; -///@dev Inherits a modified version of `ERC20VotesUpgradeable` with a shifted storage layout. -contract ValidatorSet is IValidatorSet, ERC20VotesUpgradeable, System { +contract ValidatorSet is IValidatorSet, ERC20SnapshotUpgradeable, System { using WithdrawalQueueLib for WithdrawalQueue; bytes32 private constant _STAKE_SIG = keccak256("STAKE"); bytes32 private constant _UNSTAKE_SIG = keccak256("UNSTAKE"); - bytes32 private constant _SLASH_SIG = keccak256("SLASH"); - uint256 public constant SLASHING_PERCENTAGE = 50; // to be read through NetworkParams later - uint256 public constant SLASH_INCENTIVE_PERCENTAGE = 30; // exitor reward, to be read through NetworkParams later + uint256 public constant WITHDRAWAL_WAIT_PERIOD = 1; IStateSender private _stateSender; address private _stateReceiver; address private _rootChainManager; + // slither-disable-next-line naming-convention + uint256 public EPOCH_SIZE; uint256 public currentEpochId; @@ -28,28 +26,26 @@ contract ValidatorSet is IValidatorSet, ERC20VotesUpgradeable, System { uint256[] public epochEndBlocks; mapping(address => WithdrawalQueue) private _withdrawals; - NetworkParams private _networkParams; - mapping(uint256 => uint256) private _commitBlockNumbers; - - mapping(uint256 => bool) public slashProcessed; + constructor() { + _disableInitializers(); + } function initialize( address newStateSender, address newStateReceiver, address newRootChainManager, - address newNetworkParams, + uint256 newEpochSize, ValidatorInit[] memory initialValidators ) public initializer { require( newStateSender != address(0) && newStateReceiver != address(0) && newRootChainManager != address(0), "INVALID_INPUT" ); - __ERC20Permit_init("ValidatorSet"); __ERC20_init("ValidatorSet", "VSET"); _stateSender = IStateSender(newStateSender); _stateReceiver = newStateReceiver; _rootChainManager = newRootChainManager; - _networkParams = NetworkParams(newNetworkParams); + EPOCH_SIZE = newEpochSize; for (uint256 i = 0; i < initialValidators.length; ) { _stake(initialValidators[i].addr, initialValidators[i].stake); unchecked { @@ -63,39 +59,22 @@ contract ValidatorSet is IValidatorSet, ERC20VotesUpgradeable, System { /** * @inheritdoc IValidatorSet */ - function commitEpoch(uint256 id, Epoch calldata epoch, uint256 epochSize) external onlySystemCall { + function commitEpoch(uint256 id, Epoch calldata epoch) external onlySystemCall { uint256 newEpochId = currentEpochId++; require(id == newEpochId, "UNEXPECTED_EPOCH_ID"); require(epoch.endBlock > epoch.startBlock, "NO_BLOCKS_COMMITTED"); - require((epoch.endBlock - epoch.startBlock + 1) % epochSize == 0, "EPOCH_MUST_BE_DIVISIBLE_BY_EPOCH_SIZE"); + require((epoch.endBlock - epoch.startBlock + 1) % EPOCH_SIZE == 0, "EPOCH_MUST_BE_DIVISIBLE_BY_EPOCH_SIZE"); require(epochs[newEpochId - 1].endBlock + 1 == epoch.startBlock, "INVALID_START_BLOCK"); epochs[newEpochId] = epoch; - _commitBlockNumbers[newEpochId] = block.number; epochEndBlocks.push(epoch.endBlock); emit NewEpoch(id, epoch.startBlock, epoch.endBlock, epoch.epochRoot); } - /** - * @inheritdoc IValidatorSet - */ - function slash(address[] calldata validators) external onlySystemCall { - _stateSender.syncState( - _rootChainManager, - abi.encode(_SLASH_SIG, validators, SLASHING_PERCENTAGE, SLASH_INCENTIVE_PERCENTAGE) - ); - } - function onStateReceive(uint256 /*counter*/, address sender, bytes calldata data) external override { require(msg.sender == _stateReceiver && sender == _rootChainManager, "INVALID_SENDER"); if (bytes32(data[:32]) == _STAKE_SIG) { (address validator, uint256 amount) = abi.decode(data[32:], (address, uint256)); _stake(validator, amount); - } else if (bytes32(data[:32]) == _SLASH_SIG) { - (, uint256 exitEventId, address[] memory validatorsToSlash, ) = abi.decode( - data, - (bytes32, uint256, address[], uint256) - ); - _slash(exitEventId, validatorsToSlash); } } @@ -141,38 +120,18 @@ contract ValidatorSet is IValidatorSet, ERC20VotesUpgradeable, System { length = endBlock == 0 ? 0 : endBlock - epochs[epochId].startBlock + 1; } - function balanceOfAt(address account, uint256 epochNumber) external view returns (uint256) { - return super.getPastVotes(account, _commitBlockNumbers[epochNumber]); - } - - function totalSupplyAt(uint256 epochNumber) external view returns (uint256) { - return super.getPastTotalSupply(_commitBlockNumbers[epochNumber]); - } - function _registerWithdrawal(address account, uint256 amount) internal { - _withdrawals[account].append(amount, currentEpochId + _networkParams.withdrawalWaitPeriod()); + _withdrawals[account].append(amount, currentEpochId + WITHDRAWAL_WAIT_PERIOD); emit WithdrawalRegistered(account, amount); } - function _slash(uint256 exitEventId, address[] memory validatorsToSlash) internal { - require(!slashProcessed[exitEventId], "SLASH_ALREADY_PROCESSED"); // sanity check - slashProcessed[exitEventId] = true; - uint256 length = validatorsToSlash.length; - for (uint256 i = 0; i < length; ) { - _burn(validatorsToSlash[i], balanceOf(validatorsToSlash[i])); // unstake validator - // slither-disable-next-line mapping-deletion - delete _withdrawals[validatorsToSlash[i]]; // remove pending withdrawals - unchecked { - ++i; - } - } - emit Slashed(exitEventId, validatorsToSlash); - } - function _stake(address validator, uint256 amount) internal { - assert(balanceOf(validator) + amount <= _maxSupply()); _mint(validator, amount); - _delegate(validator, validator); + } + + /// @dev the epoch number is also the snapshot id + function _getCurrentSnapshotId() internal view override returns (uint256) { + return currentEpochId; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal override { @@ -180,8 +139,16 @@ contract ValidatorSet is IValidatorSet, ERC20VotesUpgradeable, System { super._beforeTokenTransfer(from, to, amount); } - function _delegate(address delegator, address delegatee) internal override { - if (delegator != delegatee) revert("DELEGATION_FORBIDDEN"); - super._delegate(delegator, delegatee); + function balanceOfAt( + address account, + uint256 epochNumber + ) public view override(ERC20SnapshotUpgradeable, IValidatorSet) returns (uint256) { + return super.balanceOfAt(account, epochNumber); + } + + function totalSupplyAt( + uint256 epochNumber + ) public view override(ERC20SnapshotUpgradeable, IValidatorSet) returns (uint256) { + return super.totalSupplyAt(epochNumber); } } diff --git a/contracts/common/Merkle.sol b/contracts/common/Merkle.sol index f9fbfc7f..22ee8de9 100644 --- a/contracts/common/Merkle.sol +++ b/contracts/common/Merkle.sol @@ -38,6 +38,7 @@ library Merkle { // store the leaf at the calculated slot mstore(leafSlot, leaf) // store proof element in whichever slot is not occupied by the leaf + // slither-disable-next-line incorrect-exp mstore(xor(leafSlot, 32), calldataload(i)) // hash the first 64 bytes in memory leaf := keccak256(0, 64) @@ -90,6 +91,7 @@ library Merkle { // store the leaf at the calculated slot mstore(leafSlot, leaf) // store proof element in whichever slot is not occupied by the leaf + // slither-disable-next-line incorrect-exp mstore(xor(leafSlot, 32), calldataload(i)) // hash the first 64 bytes in memory leaf := keccak256(0, 64) diff --git a/contracts/interfaces/child/validator/IRewardPool.sol b/contracts/interfaces/child/validator/IRewardPool.sol index 5479e5eb..376059b1 100644 --- a/contracts/interfaces/child/validator/IRewardPool.sol +++ b/contracts/interfaces/child/validator/IRewardPool.sol @@ -20,7 +20,7 @@ interface IRewardPool { /// @notice distributes reward for the given epoch /// @dev transfers funds from sender to this contract /// @param uptime uptime data for every validator - function distributeRewardFor(uint256 epochId, Uptime[] calldata uptime, uint256 epochSize) external; + function distributeRewardFor(uint256 epochId, Uptime[] calldata uptime) external; /// @notice withdraws pending rewards for the sender (validator) function withdrawReward() external; diff --git a/contracts/interfaces/child/validator/IValidatorSet.sol b/contracts/interfaces/child/validator/IValidatorSet.sol index 1eacb4fe..135210b2 100644 --- a/contracts/interfaces/child/validator/IValidatorSet.sol +++ b/contracts/interfaces/child/validator/IValidatorSet.sol @@ -22,20 +22,12 @@ struct Epoch { */ interface IValidatorSet is IStateReceiver { event NewEpoch(uint256 indexed id, uint256 indexed startBlock, uint256 indexed endBlock, bytes32 epochRoot); - event Slashed(uint256 indexed exitId, address[] validators); event WithdrawalRegistered(address indexed account, uint256 amount); event Withdrawal(address indexed account, uint256 amount); /// @notice commits a new epoch /// @dev system call - function commitEpoch(uint256 id, Epoch calldata epoch, uint256 epochSize) external; - - /// @notice initialises slashing process - /// @dev system call, - /// @dev given list of validators are slashed on L2 - /// subsequently after their stake is slashed on L1 - /// @param validators list of validators to be slashed - function slash(address[] calldata validators) external; + function commitEpoch(uint256 id, Epoch calldata epoch) external; /// @notice allows a validator to announce their intention to withdraw a given amount of tokens /// @dev initializes a waiting period before the tokens can be withdrawn @@ -45,6 +37,11 @@ interface IValidatorSet is IStateReceiver { /// @dev calls the bridge to release the funds on root function withdraw() external; + /// @notice amount of blocks in an epoch + /// @dev when an epoch is committed a multiple of this number of blocks must be committed + // slither-disable-next-line naming-convention + function EPOCH_SIZE() external view returns (uint256); + /// @notice total amount of blocks in a given epoch function totalBlocks(uint256 epochId) external view returns (uint256 length); diff --git a/contracts/interfaces/root/IExitHelper.sol b/contracts/interfaces/root/IExitHelper.sol index 92a8c047..64fdbf12 100644 --- a/contracts/interfaces/root/IExitHelper.sol +++ b/contracts/interfaces/root/IExitHelper.sol @@ -14,13 +14,6 @@ interface IExitHelper { bytes32[] proof; } - /** - * @notice Returns the address that called the exit function - * @dev only available in the context of the exit function - * @return address of the caller - */ - function caller() external view returns (address); - /** * @notice Perform an exit for one event * @param blockNumber Block number of the exit event on L2 diff --git a/contracts/interfaces/root/IRootERC20Predicate.sol b/contracts/interfaces/root/IRootERC20Predicate.sol index 8706fe78..34710799 100644 --- a/contracts/interfaces/root/IRootERC20Predicate.sol +++ b/contracts/interfaces/root/IRootERC20Predicate.sol @@ -49,4 +49,10 @@ interface IRootERC20Predicate is IL2StateReceiver { * @return address Address of the child token */ function mapToken(IERC20Metadata rootToken) external returns (address); + + /** + * @notice Function that retrieves rootchain token that represents Supernets native token + * @return address Address of rootchain token (mapped to Supernets native token) + */ + function nativeTokenRoot() external returns (address); } diff --git a/contracts/interfaces/root/staking/ICustomSupernetManager.sol b/contracts/interfaces/root/staking/ICustomSupernetManager.sol index d5b529c7..a56e5e4a 100644 --- a/contracts/interfaces/root/staking/ICustomSupernetManager.sol +++ b/contracts/interfaces/root/staking/ICustomSupernetManager.sol @@ -21,6 +21,7 @@ interface ICustomSupernetManager { event RemovedFromWhitelist(address indexed validator); event ValidatorRegistered(address indexed validator, uint256[4] blsKey); event ValidatorDeactivated(address indexed validator); + event GenesisBalanceAdded(address indexed account, uint256 indexed amount); event GenesisFinalized(uint256 amountValidators); event StakingEnabled(); @@ -42,10 +43,6 @@ interface ICustomSupernetManager { /// @dev only callable by owner function enableStaking() external; - /// @notice Withdraws slashed MATIC of slashed validators - /// @dev only callable by owner - function withdrawSlashedStake(address to) external; - /// @notice called by the exit helpers to either release the stake of a validator or slash it /// @dev can only be synced from child after genesis function onL2StateReceive(uint256 /*id*/, address sender, bytes calldata data) external; @@ -55,4 +52,9 @@ interface ICustomSupernetManager { /// @notice returns validator instance based on provided address function getValidator(address validator_) external view returns (Validator memory); + + /// @notice addGenesisBalance is used to specify genesis balance information for genesis accounts on the Supernets. + /// It is applicable only in case Supernets native contract is mapped to a pre-existing rootchain ERC20 token. + /// @param amount represents the amount to be premined in the genesis. + function addGenesisBalance(uint256 amount) external; } diff --git a/contracts/interfaces/root/staking/IStakeManager.sol b/contracts/interfaces/root/staking/IStakeManager.sol index 4da4bf59..69e7b183 100644 --- a/contracts/interfaces/root/staking/IStakeManager.sol +++ b/contracts/interfaces/root/staking/IStakeManager.sol @@ -13,7 +13,6 @@ interface IStakeManager { event StakeAdded(uint256 indexed id, address indexed validator, uint256 amount); event StakeRemoved(uint256 indexed id, address indexed validator, uint256 amount); event StakeWithdrawn(address indexed validator, address indexed recipient, uint256 amount); - event ValidatorSlashed(uint256 indexed id, address indexed validator, uint256 amount); /// @notice registers a new child chain with the staking contract /// @return id of the child chain @@ -28,10 +27,6 @@ interface IStakeManager { /// @notice allows a validator to withdraw released stake function withdrawStake(address to, uint256 amount) external; - /// @notice called by child manager contract to slash a validator's stake - /// @notice manager collects slashed amount - function slashStakeOf(address validator, uint256 amount) external; - /// @notice returns the amount of stake a validator can withdraw function withdrawableStake(address validator) external view returns (uint256 amount); diff --git a/contracts/lib/GenesisLib.sol b/contracts/lib/GenesisLib.sol index a011ac9b..7bf093b4 100644 --- a/contracts/lib/GenesisLib.sol +++ b/contracts/lib/GenesisLib.sol @@ -13,7 +13,7 @@ enum GenesisStatus { } struct GenesisValidator { - address validator; + address addr; uint256 initialStake; } @@ -41,7 +41,8 @@ library GenesisLib { self.genesisValidators.push(GenesisValidator(validator, stake)); } else { // update values - GenesisValidator storage genesisValidator = self.genesisValidators[_indexOf(self, validator)]; + uint256 idx = _indexOf(self, validator); + GenesisValidator storage genesisValidator = self.genesisValidators[idx]; genesisValidator.initialStake += stake; } } diff --git a/contracts/lib/GenesisProxy.sol b/contracts/lib/GenesisProxy.sol new file mode 100644 index 00000000..4a03452a --- /dev/null +++ b/contracts/lib/GenesisProxy.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +/** + @title GenesisProxy + @author Polygon Technology + @notice wrapper for OpenZeppelin's Transparent Upgreadable Proxy, intended for use during genesis for genesis contracts + @notice one GenesisProxy should be deployed for each genesis contract + */ +contract GenesisProxy is TransparentUpgradeableProxy { + // keccak256("GenesisProxy INITIATOR_SLOT") + bytes32 private constant INITIATOR_SLOT = hex"16561015e0650c143c10fb1907c52a56b654e2f0922ca3245bde5beff81a333d"; + + constructor() TransparentUpgradeableProxy(address(0), address(0), "") { + revert(); + } + + function protectSetUpProxy(address initiator) external { + bytes32 protected; + + // slither-disable-next-line assembly + assembly { + protected := sload(INITIATOR_SLOT) + sstore(INITIATOR_SLOT, initiator) + } + + require(protected == "", "Already protected"); + } + + function setUpProxy(address logic, address admin, bytes memory data) external { + address initiator; + + // slither-disable-next-line assembly + assembly { + initiator := sload(INITIATOR_SLOT) + } + + require(initiator != address(1), "Already set-up"); + + require(msg.sender == initiator, "Unauthorized"); + + // TransparentUpgradeableProxy constructor + _changeAdmin(admin); + + // ERC1967Proxy constructor + _upgradeToAndCall(logic, data, false); + + // slither-disable-next-line assembly + assembly { + sstore(INITIATOR_SLOT, 1) + } + } +} diff --git a/contracts/root/CheckpointManager.sol b/contracts/root/CheckpointManager.sol index f3da47e2..aae41958 100644 --- a/contracts/root/CheckpointManager.sol +++ b/contracts/root/CheckpointManager.sol @@ -28,13 +28,15 @@ contract CheckpointManager is ICheckpointManager, Initializable { bytes32 public currentValidatorSetHash; // slither-disable-next-line naming-convention - address private immutable _INITIALIZER; + address private immutable _INITIATOR; /// @notice If the contract is meant to be initialized at a later time, specifiy the address that will initialize it. /// @notice Otherwise, pass `address(0)`. - constructor(address INITIALIZER) { + constructor(address initiator) { // slither-disable-next-line missing-zero-check - _INITIALIZER = INITIALIZER; + _INITIATOR = initiator; + + _disableInitializers(); } /** @@ -50,7 +52,7 @@ contract CheckpointManager is ICheckpointManager, Initializable { uint256 chainId_, Validator[] calldata newValidatorSet ) external initializer { - if (_INITIALIZER != address(0)) require(msg.sender == _INITIALIZER); + if (_INITIATOR != address(0)) require(msg.sender == _INITIATOR); // slither-disable-start events-maths chainId = chainId_; diff --git a/contracts/root/ChildMintableERC1155Predicate.sol b/contracts/root/ChildMintableERC1155Predicate.sol index 1675b8dd..3e815f39 100644 --- a/contracts/root/ChildMintableERC1155Predicate.sol +++ b/contracts/root/ChildMintableERC1155Predicate.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; import "../interfaces/root/IChildMintableERC1155Predicate.sol"; import "../interfaces/child/IChildERC1155.sol"; @@ -32,6 +31,10 @@ contract ChildMintableERC1155Predicate is Initializable, IChildMintableERC1155Pr _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildMintableERC1155Predicate * @param newStateSender Address of StateSender to send exit information to diff --git a/contracts/root/ChildMintableERC20Predicate.sol b/contracts/root/ChildMintableERC20Predicate.sol index c3096045..818a50ff 100644 --- a/contracts/root/ChildMintableERC20Predicate.sol +++ b/contracts/root/ChildMintableERC20Predicate.sol @@ -28,6 +28,10 @@ contract ChildMintableERC20Predicate is Initializable, IChildMintableERC20Predic mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildMintableERC20Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/ChildMintableERC721Predicate.sol b/contracts/root/ChildMintableERC721Predicate.sol index ac476c81..d466684d 100644 --- a/contracts/root/ChildMintableERC721Predicate.sol +++ b/contracts/root/ChildMintableERC721Predicate.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; import "../interfaces/root/IChildMintableERC721Predicate.sol"; import "../interfaces/child/IChildERC721.sol"; @@ -32,6 +31,10 @@ contract ChildMintableERC721Predicate is Initializable, IChildMintableERC721Pred _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildMintableERC721Predicate * @param newStateSender Address of StateSender to send exit information to diff --git a/contracts/root/ExitHelper.sol b/contracts/root/ExitHelper.sol index dd0bd630..cdbc0f92 100644 --- a/contracts/root/ExitHelper.sol +++ b/contracts/root/ExitHelper.sol @@ -8,7 +8,6 @@ import "../interfaces/root/IExitHelper.sol"; contract ExitHelper is IExitHelper, Initializable { mapping(uint256 => bool) public processedExits; ICheckpointManager public checkpointManager; - address public caller; event ExitProcessed(uint256 indexed id, bool indexed success, bytes returnData); @@ -18,6 +17,10 @@ contract ExitHelper is IExitHelper, Initializable { _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialize the contract with the checkpoint manager address * @dev The checkpoint manager contract must be deployed first @@ -84,14 +87,10 @@ contract ExitHelper is IExitHelper, Initializable { processedExits[id] = true; - // slither-disable-next-line costly-loop - caller = msg.sender; // slither-disable-next-line calls-loop,low-level-calls,reentrancy-events,reentrancy-no-eth,reentrancy-benign (bool success, bytes memory returnData) = receiver.call( abi.encodeWithSignature("onL2StateReceive(uint256,address,bytes)", id, sender, data) ); - // slither-disable-next-line costly-loop - caller = address(0); // if state sync fails, revert flag if (!success) processedExits[id] = false; diff --git a/contracts/root/RootERC1155Predicate.sol b/contracts/root/RootERC1155Predicate.sol index 3f25f24f..4ec1facc 100644 --- a/contracts/root/RootERC1155Predicate.sol +++ b/contracts/root/RootERC1155Predicate.sol @@ -20,6 +20,10 @@ contract RootERC1155Predicate is Initializable, ERC1155Holder, IRootERC1155Predi bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootERC1155Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/RootERC20Predicate.sol b/contracts/root/RootERC20Predicate.sol index b9ab0ba1..c103b73d 100644 --- a/contracts/root/RootERC20Predicate.sol +++ b/contracts/root/RootERC20Predicate.sol @@ -19,6 +19,11 @@ contract RootERC20Predicate is Initializable, IRootERC20Predicate { bytes32 public constant WITHDRAW_SIG = keccak256("WITHDRAW"); bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + address public nativeTokenRoot; + + constructor() { + _disableInitializers(); + } /** * @notice Initialization function for RootERC20Predicate @@ -32,7 +37,7 @@ contract RootERC20Predicate is Initializable, IRootERC20Predicate { address newExitHelper, address newChildERC20Predicate, address newChildTokenTemplate, - address nativeTokenRootAddress + address newNativeTokenRoot ) external initializer { require( newStateSender != address(0) && @@ -45,9 +50,10 @@ contract RootERC20Predicate is Initializable, IRootERC20Predicate { exitHelper = newExitHelper; childERC20Predicate = newChildERC20Predicate; childTokenTemplate = newChildTokenTemplate; - if (nativeTokenRootAddress != address(0)) { - rootTokenToChildToken[nativeTokenRootAddress] = 0x0000000000000000000000000000000000001010; - emit TokenMapped(nativeTokenRootAddress, 0x0000000000000000000000000000000000001010); + if (newNativeTokenRoot != address(0)) { + nativeTokenRoot = newNativeTokenRoot; + rootTokenToChildToken[nativeTokenRoot] = 0x0000000000000000000000000000000000001010; + emit TokenMapped(nativeTokenRoot, 0x0000000000000000000000000000000000001010); } } @@ -138,5 +144,5 @@ contract RootERC20Predicate is Initializable, IRootERC20Predicate { } // slither-disable-next-line unused-state,naming-convention - uint256[50] private __gap; + uint256[49] private __gap; } diff --git a/contracts/root/RootERC721Predicate.sol b/contracts/root/RootERC721Predicate.sol index 7103a682..9e0df559 100644 --- a/contracts/root/RootERC721Predicate.sol +++ b/contracts/root/RootERC721Predicate.sol @@ -20,6 +20,10 @@ contract RootERC721Predicate is Initializable, ERC721Holder, IRootERC721Predicat bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootERC721Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/staking/CustomSupernetManager.sol b/contracts/root/staking/CustomSupernetManager.sol index 528a0de0..de266424 100644 --- a/contracts/root/staking/CustomSupernetManager.sol +++ b/contracts/root/staking/CustomSupernetManager.sol @@ -8,7 +8,7 @@ import "./SupernetManager.sol"; import "../../interfaces/common/IBLS.sol"; import "../../interfaces/IStateSender.sol"; import "../../interfaces/root/staking/ICustomSupernetManager.sol"; -import "../../interfaces/root/IExitHelper.sol"; +import "../../interfaces/root/IRootERC20Predicate.sol"; contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeable, SupernetManager { using SafeERC20 for IERC20; @@ -16,7 +16,6 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl bytes32 private constant _STAKE_SIG = keccak256("STAKE"); bytes32 private constant _UNSTAKE_SIG = keccak256("UNSTAKE"); - bytes32 private constant _SLASH_SIG = keccak256("SLASH"); IBLS private _bls; IStateSender private _stateSender; @@ -28,12 +27,18 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl GenesisSet private _genesis; mapping(address => Validator) public validators; + IRootERC20Predicate private _rootERC20Predicate; + mapping(address => uint256) public genesisBalances; modifier onlyValidator(address validator) { if (!validators[validator].isActive) revert Unauthorized("VALIDATOR"); _; } + constructor() { + _disableInitializers(); + } + function initialize( address newStakeManager, address newBls, @@ -41,6 +46,7 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl address newMatic, address newChildValidatorSet, address newExitHelper, + address newRootERC20Predicate, string memory newDomain ) public initializer { require( @@ -53,12 +59,14 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl bytes(newDomain).length != 0, "INVALID_INPUT" ); + __SupernetManager_init(newStakeManager); _bls = IBLS(newBls); _stateSender = IStateSender(newStateSender); _matic = IERC20(newMatic); _childValidatorSet = newChildValidatorSet; _exitHelper = newExitHelper; + _rootERC20Predicate = IRootERC20Predicate(newRootERC20Predicate); domain = keccak256(abi.encodePacked(newDomain)); __Ownable2Step_init(); } @@ -104,14 +112,6 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl emit StakingEnabled(); } - /** - * @inheritdoc ICustomSupernetManager - */ - function withdrawSlashedStake(address to) external onlyOwner { - uint256 balance = _matic.balanceOf(address(this)); - _matic.safeTransfer(to, balance); - } - /** * @inheritdoc ICustomSupernetManager */ @@ -120,10 +120,6 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl if (bytes32(data[:32]) == _UNSTAKE_SIG) { (address validator, uint256 amount) = abi.decode(data[32:], (address, uint256)); _unstake(validator, amount); - } else if (bytes32(data[:32]) == _SLASH_SIG) { - (, address[] memory validatorsToSlash, uint256 slashingPercentage, uint256 slashIncentivePercentage) = abi - .decode(data, (bytes32, address[], uint256, uint256)); - _slash(id, validatorsToSlash, slashingPercentage, slashIncentivePercentage); } } @@ -142,6 +138,34 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl return validators[validator_]; } + /** + * + * @inheritdoc ICustomSupernetManager + */ + function addGenesisBalance(uint256 amount) external { + require(amount > 0, "CustomSupernetManager: INVALID_AMOUNT"); + if (address(_rootERC20Predicate) == address(0)) { + revert Unauthorized("CustomSupernetManager: UNDEFINED_ROOT_ERC20_PREDICATE"); + } + + IERC20 nativeTokenRoot = IERC20(_rootERC20Predicate.nativeTokenRoot()); + if (address(nativeTokenRoot) == address(0)) { + revert Unauthorized("CustomSupernetManager: UNDEFINED_NATIVE_TOKEN_ROOT"); + } + require(!_genesis.completed(), "CustomSupernetManager: GENESIS_SET_IS_ALREADY_FINALIZED"); + + // we need to track EOAs as well in the genesis set, in order to be able to query genesisBalances mapping + _genesis.insert(msg.sender, 0); + // slither-disable-next-line reentrancy-benign + genesisBalances[msg.sender] += amount; + + // lock native tokens on the root erc20 predicate + nativeTokenRoot.safeTransferFrom(msg.sender, address(_rootERC20Predicate), amount); + + // slither-disable-next-line reentrancy-events + emit GenesisBalanceAdded(msg.sender, amount); + } + function _onStake(address validator, uint256 amount) internal override onlyValidator(validator) { if (_genesis.gatheringGenesisValidators()) { _genesis.insert(validator, amount); @@ -158,36 +182,6 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl _removeIfValidatorUnstaked(validator); } - function _slash( - uint256 exitEventId, - address[] memory validatorsToSlash, - uint256 slashingPercentage, - uint256 slashIncentivePercentage - ) internal { - uint256 length = validatorsToSlash.length; - uint256 totalSlashedAmount; - for (uint256 i = 0; i < length; ) { - uint256 slashedAmount = (_stakeManager.stakeOf(validatorsToSlash[i], id) * slashingPercentage) / 100; - // slither-disable-next-line reentrancy-benign,reentrancy-events,reentrancy-no-eth - _stakeManager.slashStakeOf(validatorsToSlash[i], slashedAmount); - _removeIfValidatorUnstaked(validatorsToSlash[i]); - totalSlashedAmount += slashedAmount; - unchecked { - ++i; - } - } - - // contract will always have enough balance since slashStakeOf returns entire slashed amt - uint256 rewardAmount = (totalSlashedAmount * slashIncentivePercentage) / 100; - _matic.safeTransfer(IExitHelper(_exitHelper).caller(), rewardAmount); - - // complete slashing on child chain - _stateSender.syncState( - _childValidatorSet, - abi.encode(_SLASH_SIG, exitEventId, validatorsToSlash, slashingPercentage) - ); - } - function _verifyValidatorRegistration( address signer, uint256[2] calldata signature, @@ -224,5 +218,5 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl } // slither-disable-next-line unused-state,naming-convention - uint256[50] private __gap; + uint256[48] private __gap; } diff --git a/contracts/root/staking/StakeManager.sol b/contracts/root/staking/StakeManager.sol index 3df3abfc..eae113e4 100644 --- a/contracts/root/staking/StakeManager.sol +++ b/contracts/root/staking/StakeManager.sol @@ -13,6 +13,10 @@ contract StakeManager is IStakeManager, Initializable, StakeManagerChildData, St IERC20 private _stakingToken; + constructor() { + _disableInitializers(); + } + function initialize(address newStakingToken) public initializer { _stakingToken = IERC20(newStakingToken); } @@ -61,19 +65,6 @@ contract StakeManager is IStakeManager, Initializable, StakeManagerChildData, St _withdrawStake(msg.sender, to, amount); } - /** - * @inheritdoc IStakeManager - */ - function slashStakeOf(address validator, uint256 amount) external { - uint256 id = idFor(msg.sender); - uint256 stake = _stakeOf(validator, id); - if (amount > stake) amount = stake; - _removeStake(validator, id, stake); - _withdrawStake(validator, msg.sender, amount); - emit StakeRemoved(id, validator, stake); - emit ValidatorSlashed(id, validator, amount); - } - /** * @inheritdoc IStakeManager */ diff --git a/docs/child/ForkParams.md b/docs/child/ForkParams.md deleted file mode 100644 index 2733fa22..00000000 --- a/docs/child/ForkParams.md +++ /dev/null @@ -1,223 +0,0 @@ -# ForkParams - -*Polygon Technology (@QEDK)* - -> ForkParams - -Configurable softfork features that are read by the client on each epoch - -*The contract allows for configurable softfork parameters without genesis updation* - -## Methods - -### addNewFeature - -```solidity -function addNewFeature(uint256 blockNumber, string feature) external nonpayable -``` - -function to add a new feature at a block number - -*block number must be set in the future and feature must already not be scheduled* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| blockNumber | uint256 | block number to schedule the feature | -| feature | string | feature name to schedule | - -### featureToBlockNumber - -```solidity -function featureToBlockNumber(bytes32) external view returns (uint256) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### initialize - -```solidity -function initialize(address newOwner) external nonpayable -``` - -initialize function to set the owner - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | address to transfer the ownership to | - -### isFeatureActivated - -```solidity -function isFeatureActivated(string feature) external view returns (bool) -``` - -function to check if a feature is activated - -*returns true if feature is activated, false if feature is scheduled in the future and reverts if feature does not exists* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| feature | string | feature name to check for activation | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - -### updateFeatureBlock - -```solidity -function updateFeatureBlock(uint256 newBlockNumber, string feature) external nonpayable -``` - -function to update the block number for a feature - -*block number must be set in the future and feature must already be scheduled* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newBlockNumber | uint256 | new block number to schedule the feature at | -| feature | string | feature name to schedule | - - - -## Events - -### Initialized - -```solidity -event Initialized(uint8 version) -``` - - - -*Triggered when the contract has been initialized or reinitialized.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| version | uint8 | undefined | - -### NewFeature - -```solidity -event NewFeature(bytes32 indexed feature, uint256 indexed block) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| feature `indexed` | bytes32 | undefined | -| block `indexed` | uint256 | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### UpdatedFeature - -```solidity -event UpdatedFeature(bytes32 indexed feature, uint256 indexed block) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| feature `indexed` | bytes32 | undefined | -| block `indexed` | uint256 | undefined | - - - diff --git a/docs/child/NetworkParams.md b/docs/child/NetworkParams.md deleted file mode 100644 index 53096be7..00000000 --- a/docs/child/NetworkParams.md +++ /dev/null @@ -1,793 +0,0 @@ -# NetworkParams - -*Polygon Technology (@QEDK)* - -> NetworkParams - -Configurable network parameters that are read by the client on each epoch - -*The contract allows for configurable network parameters without the need for a hardfork* - -## Methods - -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - -### baseFeeChangeDenom - -```solidity -function baseFeeChangeDenom() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### blockTime - -```solidity -function blockTime() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### blockTimeDrift - -```solidity -function blockTimeDrift() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### checkpointBlockInterval - -```solidity -function checkpointBlockInterval() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### epochReward - -```solidity -function epochReward() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### epochSize - -```solidity -function epochSize() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### initialize - -```solidity -function initialize(NetworkParams.InitParams initParams) external nonpayable -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| initParams | NetworkParams.InitParams | undefined | - -### maxValidatorSetSize - -```solidity -function maxValidatorSetSize() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### minValidatorSetSize - -```solidity -function minValidatorSetSize() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### proposalThreshold - -```solidity -function proposalThreshold() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - -### setNewBaseFeeChangeDenom - -```solidity -function setNewBaseFeeChangeDenom(uint256 newBaseFeeChangeDenom) external nonpayable -``` - -function to set new base fee change denominator - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newBaseFeeChangeDenom | uint256 | new base fee change denominator | - -### setNewBlockTime - -```solidity -function setNewBlockTime(uint256 newBlockTime) external nonpayable -``` - -function to set new block time - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newBlockTime | uint256 | new block time | - -### setNewBlockTimeDrift - -```solidity -function setNewBlockTimeDrift(uint256 newBlockTimeDrift) external nonpayable -``` - -function to set new block time drift - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newBlockTimeDrift | uint256 | new block time drift | - -### setNewCheckpointBlockInterval - -```solidity -function setNewCheckpointBlockInterval(uint256 newCheckpointBlockInterval) external nonpayable -``` - -function to set new checkpoint block interval - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newCheckpointBlockInterval | uint256 | new checkpoint block interval | - -### setNewEpochReward - -```solidity -function setNewEpochReward(uint256 newEpochReward) external nonpayable -``` - -function to set new epoch reward - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newEpochReward | uint256 | new epoch reward | - -### setNewEpochSize - -```solidity -function setNewEpochSize(uint256 newEpochSize) external nonpayable -``` - -function to set new epoch size - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newEpochSize | uint256 | new epoch reward | - -### setNewMaxValidatorSetSize - -```solidity -function setNewMaxValidatorSetSize(uint256 newMaxValidatorSetSize) external nonpayable -``` - -function to set new maximum validator set size - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newMaxValidatorSetSize | uint256 | new maximum validator set size | - -### setNewMinValidatorSetSize - -```solidity -function setNewMinValidatorSetSize(uint256 newMinValidatorSetSize) external nonpayable -``` - -function to set new minimum validator set size - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newMinValidatorSetSize | uint256 | new minimum validator set size | - -### setNewProposalThreshold - -```solidity -function setNewProposalThreshold(uint256 newProposalThreshold) external nonpayable -``` - -function to set new proposal threshold - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newProposalThreshold | uint256 | new proposal threshold | - -### setNewSprintSize - -```solidity -function setNewSprintSize(uint256 newSprintSize) external nonpayable -``` - -function to set new sprint size - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newSprintSize | uint256 | new sprint size | - -### setNewVotingDelay - -```solidity -function setNewVotingDelay(uint256 newVotingDelay) external nonpayable -``` - -function to set new voting delay - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newVotingDelay | uint256 | new voting delay | - -### setNewVotingPeriod - -```solidity -function setNewVotingPeriod(uint256 newVotingPeriod) external nonpayable -``` - -function to set new voting period - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newVotingPeriod | uint256 | new voting period | - -### setNewWithdrawalWaitPeriod - -```solidity -function setNewWithdrawalWaitPeriod(uint256 newWithdrawalWaitPeriod) external nonpayable -``` - -function to set new withdrawal wait period - -*disallows setting of a zero value for sanity check purposes* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newWithdrawalWaitPeriod | uint256 | new withdrawal wait period | - -### sprintSize - -```solidity -function sprintSize() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - -### votingDelay - -```solidity -function votingDelay() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### votingPeriod - -```solidity -function votingPeriod() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### withdrawalWaitPeriod - -```solidity -function withdrawalWaitPeriod() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - - - -## Events - -### Initialized - -```solidity -event Initialized(uint8 version) -``` - - - -*Triggered when the contract has been initialized or reinitialized.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| version | uint8 | undefined | - -### NewBaseFeeChangeDenom - -```solidity -event NewBaseFeeChangeDenom(uint256 indexed baseFeeChangeDenom) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| baseFeeChangeDenom `indexed` | uint256 | undefined | - -### NewBlockTime - -```solidity -event NewBlockTime(uint256 indexed blockTime) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| blockTime `indexed` | uint256 | undefined | - -### NewBlockTimeDrift - -```solidity -event NewBlockTimeDrift(uint256 indexed blockTimeDrift) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| blockTimeDrift `indexed` | uint256 | undefined | - -### NewCheckpointBlockInterval - -```solidity -event NewCheckpointBlockInterval(uint256 indexed checkpointInterval) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| checkpointInterval `indexed` | uint256 | undefined | - -### NewEpochReward - -```solidity -event NewEpochReward(uint256 indexed reward) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| reward `indexed` | uint256 | undefined | - -### NewEpochSize - -```solidity -event NewEpochSize(uint256 indexed size) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| size `indexed` | uint256 | undefined | - -### NewMaxValidatorSetSize - -```solidity -event NewMaxValidatorSetSize(uint256 indexed maxValidatorSet) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| maxValidatorSet `indexed` | uint256 | undefined | - -### NewMinValidatorSetSize - -```solidity -event NewMinValidatorSetSize(uint256 indexed minValidatorSet) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| minValidatorSet `indexed` | uint256 | undefined | - -### NewProposalThreshold - -```solidity -event NewProposalThreshold(uint256 indexed proposalThreshold) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalThreshold `indexed` | uint256 | undefined | - -### NewSprintSize - -```solidity -event NewSprintSize(uint256 indexed size) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| size `indexed` | uint256 | undefined | - -### NewVotingDelay - -```solidity -event NewVotingDelay(uint256 indexed votingDelay) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| votingDelay `indexed` | uint256 | undefined | - -### NewVotingPeriod - -```solidity -event NewVotingPeriod(uint256 indexed votingPeriod) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| votingPeriod `indexed` | uint256 | undefined | - -### NewWithdrawalWaitPeriod - -```solidity -event NewWithdrawalWaitPeriod(uint256 indexed withdrawalPeriod) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| withdrawalPeriod `indexed` | uint256 | undefined | - -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - - - diff --git a/docs/child/governance/ChildGovernor.md b/docs/child/governance/ChildGovernor.md deleted file mode 100644 index 51e2b156..00000000 --- a/docs/child/governance/ChildGovernor.md +++ /dev/null @@ -1,1281 +0,0 @@ -# ChildGovernor - - - - - - - - - -## Methods - -### BALLOT_TYPEHASH - -```solidity -function BALLOT_TYPEHASH() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### CLOCK_MODE - -```solidity -function CLOCK_MODE() external view returns (string) -``` - - - -*Machine-readable description of the clock as specified in EIP-6372.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | string | undefined | - -### COUNTING_MODE - -```solidity -function COUNTING_MODE() external pure returns (string) -``` - -module:voting - -*A description of the possible `support` values for {castVote} and the way these votes are counted, meant to be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`. There are 2 standard keys: `support` and `quorum`. - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`. - `quorum=bravo` means that only For votes are counted towards quorum. - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum. If a counting module makes use of encoded `params`, it should include this under a `params` key with a unique name that describes the behavior. For example: - `params=fractional` might refer to a scheme where votes are divided fractionally between for/against/abstain. - `params=erc721` might refer to a scheme where specific NFTs are delegated to vote. NOTE: The string can be decoded by the standard https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`] JavaScript class.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | string | undefined | - -### EXTENDED_BALLOT_TYPEHASH - -```solidity -function EXTENDED_BALLOT_TYPEHASH() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### cancel - -```solidity -function cancel(uint256 proposalId) external nonpayable -``` - - - -*Cancel a proposal with GovernorBravo logic.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -### cancel - -```solidity -function cancel(address[] targets, uint256[] values, bytes[] calldatas, bytes32 descriptionHash) external nonpayable returns (uint256) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| calldatas | bytes[] | undefined | -| descriptionHash | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### castVote - -```solidity -function castVote(uint256 proposalId, uint8 support) external nonpayable returns (uint256) -``` - - - -*See {IGovernor-castVote}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| support | uint8 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### castVoteBySig - -```solidity -function castVoteBySig(uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s) external nonpayable returns (uint256) -``` - - - -*See {IGovernor-castVoteBySig}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| support | uint8 | undefined | -| v | uint8 | undefined | -| r | bytes32 | undefined | -| s | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### castVoteWithReason - -```solidity -function castVoteWithReason(uint256 proposalId, uint8 support, string reason) external nonpayable returns (uint256) -``` - - - -*See {IGovernor-castVoteWithReason}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| support | uint8 | undefined | -| reason | string | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### castVoteWithReasonAndParams - -```solidity -function castVoteWithReasonAndParams(uint256 proposalId, uint8 support, string reason, bytes params) external nonpayable returns (uint256) -``` - - - -*See {IGovernor-castVoteWithReasonAndParams}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| support | uint8 | undefined | -| reason | string | undefined | -| params | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### castVoteWithReasonAndParamsBySig - -```solidity -function castVoteWithReasonAndParamsBySig(uint256 proposalId, uint8 support, string reason, bytes params, uint8 v, bytes32 r, bytes32 s) external nonpayable returns (uint256) -``` - - - -*See {IGovernor-castVoteWithReasonAndParamsBySig}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| support | uint8 | undefined | -| reason | string | undefined | -| params | bytes | undefined | -| v | uint8 | undefined | -| r | bytes32 | undefined | -| s | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### clock - -```solidity -function clock() external view returns (uint48) -``` - - - -*Clock (as specified in EIP-6372) is set to match the token's clock. Fallback to block numbers if the token does not implement EIP-6372.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint48 | undefined | - -### eip712Domain - -```solidity -function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions) -``` - - - -*See {EIP-5267}. _Available since v4.9._* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| fields | bytes1 | undefined | -| name | string | undefined | -| version | string | undefined | -| chainId | uint256 | undefined | -| verifyingContract | address | undefined | -| salt | bytes32 | undefined | -| extensions | uint256[] | undefined | - -### execute - -```solidity -function execute(address[] targets, uint256[] values, bytes[] calldatas, bytes32 descriptionHash) external payable returns (uint256) -``` - - - -*See {IGovernor-execute}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| calldatas | bytes[] | undefined | -| descriptionHash | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### execute - -```solidity -function execute(uint256 proposalId) external payable -``` - - - -*See {IGovernorCompatibilityBravo-execute}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -### getActions - -```solidity -function getActions(uint256 proposalId) external view returns (address[] targets, uint256[] values, string[] signatures, bytes[] calldatas) -``` - - - -*See {IGovernorCompatibilityBravo-getActions}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| signatures | string[] | undefined | -| calldatas | bytes[] | undefined | - -### getReceipt - -```solidity -function getReceipt(uint256 proposalId, address voter) external view returns (struct IGovernorCompatibilityBravoUpgradeable.Receipt) -``` - - - -*See {IGovernorCompatibilityBravo-getReceipt}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| voter | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | IGovernorCompatibilityBravoUpgradeable.Receipt | undefined | - -### getVotes - -```solidity -function getVotes(address account, uint256 timepoint) external view returns (uint256) -``` - - - -*See {IGovernor-getVotes}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | -| timepoint | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### getVotesWithParams - -```solidity -function getVotesWithParams(address account, uint256 timepoint, bytes params) external view returns (uint256) -``` - - - -*See {IGovernor-getVotesWithParams}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | -| timepoint | uint256 | undefined | -| params | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### hasVoted - -```solidity -function hasVoted(uint256 proposalId, address account) external view returns (bool) -``` - - - -*See {IGovernor-hasVoted}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| account | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### hashProposal - -```solidity -function hashProposal(address[] targets, uint256[] values, bytes[] calldatas, bytes32 descriptionHash) external pure returns (uint256) -``` - - - -*See {IGovernor-hashProposal}. The proposal id is produced by hashing the ABI encoded `targets` array, the `values` array, the `calldatas` array and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id can be produced from the proposal data which is part of the {ProposalCreated} event. It can even be computed in advance, before the proposal is submitted. Note that the chainId and the governor address are not part of the proposal id computation. Consequently, the same proposal (with same operation and same description) will have the same id if submitted on multiple governors across multiple networks. This also means that in order to execute the same operation twice (on the same governor) the proposer will have to change the description in order to avoid proposal id conflicts.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| calldatas | bytes[] | undefined | -| descriptionHash | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### initialize - -```solidity -function initialize(contract IVotesUpgradeable token_, contract TimelockControllerUpgradeable timelock_, uint256 quorumNumerator_, address networkParams) external nonpayable -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| token_ | contract IVotesUpgradeable | undefined | -| timelock_ | contract TimelockControllerUpgradeable | undefined | -| quorumNumerator_ | uint256 | undefined | -| networkParams | address | undefined | - -### name - -```solidity -function name() external view returns (string) -``` - - - -*See {IGovernor-name}.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | string | undefined | - -### onERC1155BatchReceived - -```solidity -function onERC1155BatchReceived(address, address, uint256[], uint256[], bytes) external nonpayable returns (bytes4) -``` - - - -*See {IERC1155Receiver-onERC1155BatchReceived}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | -| _1 | address | undefined | -| _2 | uint256[] | undefined | -| _3 | uint256[] | undefined | -| _4 | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes4 | undefined | - -### onERC1155Received - -```solidity -function onERC1155Received(address, address, uint256, uint256, bytes) external nonpayable returns (bytes4) -``` - - - -*See {IERC1155Receiver-onERC1155Received}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | -| _1 | address | undefined | -| _2 | uint256 | undefined | -| _3 | uint256 | undefined | -| _4 | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes4 | undefined | - -### onERC721Received - -```solidity -function onERC721Received(address, address, uint256, bytes) external nonpayable returns (bytes4) -``` - - - -*See {IERC721Receiver-onERC721Received}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | -| _1 | address | undefined | -| _2 | uint256 | undefined | -| _3 | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes4 | undefined | - -### proposalDeadline - -```solidity -function proposalDeadline(uint256 proposalId) external view returns (uint256) -``` - - - -*See {IGovernor-proposalDeadline}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### proposalEta - -```solidity -function proposalEta(uint256 proposalId) external view returns (uint256) -``` - - - -*Public accessor to check the eta of a queued proposal* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### proposalProposer - -```solidity -function proposalProposer(uint256 proposalId) external view returns (address) -``` - - - -*Returns the account that created a given proposal.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### proposalSnapshot - -```solidity -function proposalSnapshot(uint256 proposalId) external view returns (uint256) -``` - - - -*See {IGovernor-proposalSnapshot}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### proposalThreshold - -```solidity -function proposalThreshold() external view returns (uint256) -``` - - - -*Part of the Governor Bravo's interface: _"The number of votes required in order for a voter to become a proposer"_.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### proposals - -```solidity -function proposals(uint256 proposalId) external view returns (uint256 id, address proposer, uint256 eta, uint256 startBlock, uint256 endBlock, uint256 forVotes, uint256 againstVotes, uint256 abstainVotes, bool canceled, bool executed) -``` - - - -*See {IGovernorCompatibilityBravo-proposals}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| id | uint256 | undefined | -| proposer | address | undefined | -| eta | uint256 | undefined | -| startBlock | uint256 | undefined | -| endBlock | uint256 | undefined | -| forVotes | uint256 | undefined | -| againstVotes | uint256 | undefined | -| abstainVotes | uint256 | undefined | -| canceled | bool | undefined | -| executed | bool | undefined | - -### propose - -```solidity -function propose(address[] targets, uint256[] values, bytes[] calldatas, string description) external nonpayable returns (uint256) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| calldatas | bytes[] | undefined | -| description | string | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### propose - -```solidity -function propose(address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string description) external nonpayable returns (uint256) -``` - - - -*See {IGovernorCompatibilityBravo-propose}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| signatures | string[] | undefined | -| calldatas | bytes[] | undefined | -| description | string | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### queue - -```solidity -function queue(address[] targets, uint256[] values, bytes[] calldatas, bytes32 descriptionHash) external nonpayable returns (uint256) -``` - - - -*Function to queue a proposal to the timelock.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| calldatas | bytes[] | undefined | -| descriptionHash | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### queue - -```solidity -function queue(uint256 proposalId) external nonpayable -``` - - - -*See {IGovernorCompatibilityBravo-queue}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -### quorum - -```solidity -function quorum(uint256 timepoint) external view returns (uint256) -``` - - - -*Returns the quorum for a timepoint, in terms of number of votes: `supply * numerator / denominator`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| timepoint | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### quorumDenominator - -```solidity -function quorumDenominator() external view returns (uint256) -``` - - - -*Returns the quorum denominator. Defaults to 100, but may be overridden.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### quorumNumerator - -```solidity -function quorumNumerator(uint256 timepoint) external view returns (uint256) -``` - - - -*Returns the quorum numerator at a specific timepoint. See {quorumDenominator}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| timepoint | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### quorumNumerator - -```solidity -function quorumNumerator() external view returns (uint256) -``` - - - -*Returns the current quorum numerator. See {quorumDenominator}.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### quorumVotes - -```solidity -function quorumVotes() external view returns (uint256) -``` - - - -*See {IGovernorCompatibilityBravo-quorumVotes}.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### relay - -```solidity -function relay(address target, uint256 value, bytes data) external payable -``` - - - -*Relays a transaction or function call to an arbitrary target. In cases where the governance executor is some contract other than the governor itself, like when using a timelock, this function can be invoked in a governance proposal to recover tokens or Ether that was sent to the governor contract by mistake. Note that if the executor is simply the governor itself, use of `relay` is redundant.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| target | address | undefined | -| value | uint256 | undefined | -| data | bytes | undefined | - -### state - -```solidity -function state(uint256 proposalId) external view returns (enum IGovernorUpgradeable.ProposalState) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | enum IGovernorUpgradeable.ProposalState | undefined | - -### supportsInterface - -```solidity -function supportsInterface(bytes4 interfaceId) external view returns (bool) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| interfaceId | bytes4 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### timelock - -```solidity -function timelock() external view returns (address) -``` - - - -*Public accessor to check the address of the timelock* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### token - -```solidity -function token() external view returns (contract IERC5805Upgradeable) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | contract IERC5805Upgradeable | undefined | - -### updateQuorumNumerator - -```solidity -function updateQuorumNumerator(uint256 newQuorumNumerator) external nonpayable -``` - - - -*Changes the quorum numerator. Emits a {QuorumNumeratorUpdated} event. Requirements: - Must be called through a governance proposal. - New numerator must be smaller or equal to the denominator.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newQuorumNumerator | uint256 | undefined | - -### updateTimelock - -```solidity -function updateTimelock(contract TimelockControllerUpgradeable newTimelock) external nonpayable -``` - - - -*Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates must be proposed, scheduled, and executed through governance proposals. CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newTimelock | contract TimelockControllerUpgradeable | undefined | - -### version - -```solidity -function version() external view returns (string) -``` - - - -*See {IGovernor-version}.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | string | undefined | - -### votingDelay - -```solidity -function votingDelay() external view returns (uint256) -``` - -module:user-config - -*Delay, between the proposal is created and the vote starts. The unit this duration is expressed in depends on the clock (see EIP-6372) this contract uses. This can be increased to leave time for users to buy voting power, or delegate it, before the voting of a proposal starts.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### votingPeriod - -```solidity -function votingPeriod() external view returns (uint256) -``` - -module:user-config - -*Delay between the vote start and vote end. The unit this duration is expressed in depends on the clock (see EIP-6372) this contract uses. NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting duration compared to the voting delay.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - - - -## Events - -### EIP712DomainChanged - -```solidity -event EIP712DomainChanged() -``` - - - -*MAY be emitted to signal that the domain could have changed.* - - -### Initialized - -```solidity -event Initialized(uint8 version) -``` - - - -*Triggered when the contract has been initialized or reinitialized.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| version | uint8 | undefined | - -### ProposalCanceled - -```solidity -event ProposalCanceled(uint256 proposalId) -``` - - - -*Emitted when a proposal is canceled.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -### ProposalCreated - -```solidity -event ProposalCreated(uint256 proposalId, address proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 voteStart, uint256 voteEnd, string description) -``` - - - -*Emitted when a proposal is created.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| proposer | address | undefined | -| targets | address[] | undefined | -| values | uint256[] | undefined | -| signatures | string[] | undefined | -| calldatas | bytes[] | undefined | -| voteStart | uint256 | undefined | -| voteEnd | uint256 | undefined | -| description | string | undefined | - -### ProposalExecuted - -```solidity -event ProposalExecuted(uint256 proposalId) -``` - - - -*Emitted when a proposal is executed.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | - -### ProposalQueued - -```solidity -event ProposalQueued(uint256 proposalId, uint256 eta) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| proposalId | uint256 | undefined | -| eta | uint256 | undefined | - -### QuorumNumeratorUpdated - -```solidity -event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| oldQuorumNumerator | uint256 | undefined | -| newQuorumNumerator | uint256 | undefined | - -### TimelockChange - -```solidity -event TimelockChange(address oldTimelock, address newTimelock) -``` - - - -*Emitted when the timelock controller used for proposal execution is modified.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| oldTimelock | address | undefined | -| newTimelock | address | undefined | - -### VoteCast - -```solidity -event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason) -``` - - - -*Emitted when a vote is cast without params. Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| voter `indexed` | address | undefined | -| proposalId | uint256 | undefined | -| support | uint8 | undefined | -| weight | uint256 | undefined | -| reason | string | undefined | - -### VoteCastWithParams - -```solidity -event VoteCastWithParams(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason, bytes params) -``` - - - -*Emitted when a vote is cast with params. Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used. `params` are additional encoded parameters. Their interpepretation also depends on the voting module used.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| voter `indexed` | address | undefined | -| proposalId | uint256 | undefined | -| support | uint8 | undefined | -| weight | uint256 | undefined | -| reason | string | undefined | -| params | bytes | undefined | - - - -## Errors - -### Empty - -```solidity -error Empty() -``` - - - -*An operation (e.g. {front}) couldn't be completed due to the queue being empty.* - - - diff --git a/docs/child/governance/ChildTimelock.md b/docs/child/governance/ChildTimelock.md deleted file mode 100644 index f88c950c..00000000 --- a/docs/child/governance/ChildTimelock.md +++ /dev/null @@ -1,772 +0,0 @@ -# ChildTimelock - - - - - - - - - -## Methods - -### CANCELLER_ROLE - -```solidity -function CANCELLER_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### DEFAULT_ADMIN_ROLE - -```solidity -function DEFAULT_ADMIN_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### EXECUTOR_ROLE - -```solidity -function EXECUTOR_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### PROPOSER_ROLE - -```solidity -function PROPOSER_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### TIMELOCK_ADMIN_ROLE - -```solidity -function TIMELOCK_ADMIN_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### cancel - -```solidity -function cancel(bytes32 id) external nonpayable -``` - - - -*Cancel an operation. Requirements: - the caller must have the 'canceller' role.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id | bytes32 | undefined | - -### execute - -```solidity -function execute(address target, uint256 value, bytes payload, bytes32 predecessor, bytes32 salt) external payable -``` - - - -*Execute an (ready) operation containing a single transaction. Emits a {CallExecuted} event. Requirements: - the caller must have the 'executor' role.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| target | address | undefined | -| value | uint256 | undefined | -| payload | bytes | undefined | -| predecessor | bytes32 | undefined | -| salt | bytes32 | undefined | - -### executeBatch - -```solidity -function executeBatch(address[] targets, uint256[] values, bytes[] payloads, bytes32 predecessor, bytes32 salt) external payable -``` - - - -*Execute an (ready) operation containing a batch of transactions. Emits one {CallExecuted} event per transaction in the batch. Requirements: - the caller must have the 'executor' role.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| payloads | bytes[] | undefined | -| predecessor | bytes32 | undefined | -| salt | bytes32 | undefined | - -### getMinDelay - -```solidity -function getMinDelay() external view returns (uint256) -``` - - - -*Returns the minimum delay for an operation to become valid. This value can be changed by executing an operation that calls `updateDelay`.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### getRoleAdmin - -```solidity -function getRoleAdmin(bytes32 role) external view returns (bytes32) -``` - - - -*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### getTimestamp - -```solidity -function getTimestamp(bytes32 id) external view returns (uint256) -``` - - - -*Returns the timestamp at which an operation becomes ready (0 for unset operations, 1 for done operations).* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### grantRole - -```solidity -function grantRole(bytes32 role, address account) external nonpayable -``` - - - -*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined | -| account | address | undefined | - -### hasRole - -```solidity -function hasRole(bytes32 role, address account) external view returns (bool) -``` - - - -*Returns `true` if `account` has been granted `role`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined | -| account | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### hashOperation - -```solidity -function hashOperation(address target, uint256 value, bytes data, bytes32 predecessor, bytes32 salt) external pure returns (bytes32) -``` - - - -*Returns the identifier of an operation containing a single transaction.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| target | address | undefined | -| value | uint256 | undefined | -| data | bytes | undefined | -| predecessor | bytes32 | undefined | -| salt | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### hashOperationBatch - -```solidity -function hashOperationBatch(address[] targets, uint256[] values, bytes[] payloads, bytes32 predecessor, bytes32 salt) external pure returns (bytes32) -``` - - - -*Returns the identifier of an operation containing a batch of transactions.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| payloads | bytes[] | undefined | -| predecessor | bytes32 | undefined | -| salt | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - -### initialize - -```solidity -function initialize(uint256 minDelay, address[] proposers, address[] executors, address admin) external nonpayable -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| minDelay | uint256 | undefined | -| proposers | address[] | undefined | -| executors | address[] | undefined | -| admin | address | undefined | - -### isOperation - -```solidity -function isOperation(bytes32 id) external view returns (bool) -``` - - - -*Returns whether an id correspond to a registered operation. This includes both Pending, Ready and Done operations.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### isOperationDone - -```solidity -function isOperationDone(bytes32 id) external view returns (bool) -``` - - - -*Returns whether an operation is done or not.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### isOperationPending - -```solidity -function isOperationPending(bytes32 id) external view returns (bool) -``` - - - -*Returns whether an operation is pending or not. Note that a "pending" operation may also be "ready".* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### isOperationReady - -```solidity -function isOperationReady(bytes32 id) external view returns (bool) -``` - - - -*Returns whether an operation is ready for execution. Note that a "ready" operation is also "pending".* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id | bytes32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### onERC1155BatchReceived - -```solidity -function onERC1155BatchReceived(address, address, uint256[], uint256[], bytes) external nonpayable returns (bytes4) -``` - - - -*See {IERC1155Receiver-onERC1155BatchReceived}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | -| _1 | address | undefined | -| _2 | uint256[] | undefined | -| _3 | uint256[] | undefined | -| _4 | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes4 | undefined | - -### onERC1155Received - -```solidity -function onERC1155Received(address, address, uint256, uint256, bytes) external nonpayable returns (bytes4) -``` - - - -*See {IERC1155Receiver-onERC1155Received}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | -| _1 | address | undefined | -| _2 | uint256 | undefined | -| _3 | uint256 | undefined | -| _4 | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes4 | undefined | - -### onERC721Received - -```solidity -function onERC721Received(address, address, uint256, bytes) external nonpayable returns (bytes4) -``` - - - -*See {IERC721Receiver-onERC721Received}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | -| _1 | address | undefined | -| _2 | uint256 | undefined | -| _3 | bytes | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes4 | undefined | - -### renounceRole - -```solidity -function renounceRole(bytes32 role, address account) external nonpayable -``` - - - -*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined | -| account | address | undefined | - -### revokeRole - -```solidity -function revokeRole(bytes32 role, address account) external nonpayable -``` - - - -*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role | bytes32 | undefined | -| account | address | undefined | - -### schedule - -```solidity -function schedule(address target, uint256 value, bytes data, bytes32 predecessor, bytes32 salt, uint256 delay) external nonpayable -``` - - - -*Schedule an operation containing a single transaction. Emits {CallSalt} if salt is nonzero, and {CallScheduled}. Requirements: - the caller must have the 'proposer' role.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| target | address | undefined | -| value | uint256 | undefined | -| data | bytes | undefined | -| predecessor | bytes32 | undefined | -| salt | bytes32 | undefined | -| delay | uint256 | undefined | - -### scheduleBatch - -```solidity -function scheduleBatch(address[] targets, uint256[] values, bytes[] payloads, bytes32 predecessor, bytes32 salt, uint256 delay) external nonpayable -``` - - - -*Schedule an operation containing a batch of transactions. Emits {CallSalt} if salt is nonzero, and one {CallScheduled} event per transaction in the batch. Requirements: - the caller must have the 'proposer' role.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| targets | address[] | undefined | -| values | uint256[] | undefined | -| payloads | bytes[] | undefined | -| predecessor | bytes32 | undefined | -| salt | bytes32 | undefined | -| delay | uint256 | undefined | - -### supportsInterface - -```solidity -function supportsInterface(bytes4 interfaceId) external view returns (bool) -``` - - - -*See {IERC165-supportsInterface}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| interfaceId | bytes4 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### updateDelay - -```solidity -function updateDelay(uint256 newDelay) external nonpayable -``` - - - -*Changes the minimum timelock duration for future operations. Emits a {MinDelayChange} event. Requirements: - the caller must be the timelock itself. This can only be achieved by scheduling and later executing an operation where the timelock is the target and the data is the ABI-encoded call to this function.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newDelay | uint256 | undefined | - - - -## Events - -### CallExecuted - -```solidity -event CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data) -``` - - - -*Emitted when a call is performed as part of operation `id`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id `indexed` | bytes32 | undefined | -| index `indexed` | uint256 | undefined | -| target | address | undefined | -| value | uint256 | undefined | -| data | bytes | undefined | - -### CallSalt - -```solidity -event CallSalt(bytes32 indexed id, bytes32 salt) -``` - - - -*Emitted when new proposal is scheduled with non-zero salt.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id `indexed` | bytes32 | undefined | -| salt | bytes32 | undefined | - -### CallScheduled - -```solidity -event CallScheduled(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data, bytes32 predecessor, uint256 delay) -``` - - - -*Emitted when a call is scheduled as part of operation `id`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id `indexed` | bytes32 | undefined | -| index `indexed` | uint256 | undefined | -| target | address | undefined | -| value | uint256 | undefined | -| data | bytes | undefined | -| predecessor | bytes32 | undefined | -| delay | uint256 | undefined | - -### Cancelled - -```solidity -event Cancelled(bytes32 indexed id) -``` - - - -*Emitted when operation `id` is cancelled.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id `indexed` | bytes32 | undefined | - -### Initialized - -```solidity -event Initialized(uint8 version) -``` - - - -*Triggered when the contract has been initialized or reinitialized.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| version | uint8 | undefined | - -### MinDelayChange - -```solidity -event MinDelayChange(uint256 oldDuration, uint256 newDuration) -``` - - - -*Emitted when the minimum delay for future operations is modified.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| oldDuration | uint256 | undefined | -| newDuration | uint256 | undefined | - -### RoleAdminChanged - -```solidity -event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) -``` - - - -*Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite {RoleAdminChanged} not being emitted signaling this. _Available since v3.1._* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role `indexed` | bytes32 | undefined | -| previousAdminRole `indexed` | bytes32 | undefined | -| newAdminRole `indexed` | bytes32 | undefined | - -### RoleGranted - -```solidity -event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) -``` - - - -*Emitted when `account` is granted `role`. `sender` is the account that originated the contract call, an admin role bearer except when using {AccessControl-_setupRole}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role `indexed` | bytes32 | undefined | -| account `indexed` | address | undefined | -| sender `indexed` | address | undefined | - -### RoleRevoked - -```solidity -event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) -``` - - - -*Emitted when `account` is revoked `role`. `sender` is the account that originated the contract call: - if using `revokeRole`, it is the admin role bearer - if using `renounceRole`, it is the role bearer (i.e. `account`)* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| role `indexed` | bytes32 | undefined | -| account `indexed` | address | undefined | -| sender `indexed` | address | undefined | - - - diff --git a/docs/child/validator/RewardPool.md b/docs/child/validator/RewardPool.md index 9e353ddc..33da34aa 100644 --- a/docs/child/validator/RewardPool.md +++ b/docs/child/validator/RewardPool.md @@ -157,6 +157,23 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### baseReward + +```solidity +function baseReward() external view returns (uint256) +``` + + + + + + #### Returns | Name | Type | Description | @@ -166,7 +183,7 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) ### distributeRewardFor ```solidity -function distributeRewardFor(uint256 epochId, Uptime[] uptime, uint256 epochSize) external nonpayable +function distributeRewardFor(uint256 epochId, Uptime[] uptime) external nonpayable ``` @@ -179,12 +196,11 @@ function distributeRewardFor(uint256 epochId, Uptime[] uptime, uint256 epochSize |---|---|---| | epochId | uint256 | undefined | | uptime | Uptime[] | undefined | -| epochSize | uint256 | undefined | ### initialize ```solidity -function initialize(address newRewardToken, address newRewardWallet, address newValidatorSet, address networkParamsAddr) external nonpayable +function initialize(address newRewardToken, address newRewardWallet, address newValidatorSet, uint256 newBaseReward) external nonpayable ``` @@ -198,7 +214,7 @@ function initialize(address newRewardToken, address newRewardWallet, address new | newRewardToken | address | undefined | | newRewardWallet | address | undefined | | newValidatorSet | address | undefined | -| networkParamsAddr | address | undefined | +| newBaseReward | uint256 | undefined | ### paidRewardPerEpoch diff --git a/docs/child/validator/ValidatorSet.md b/docs/child/validator/ValidatorSet.md index 77ef0e50..c1f15acc 100644 --- a/docs/child/validator/ValidatorSet.md +++ b/docs/child/validator/ValidatorSet.md @@ -6,7 +6,7 @@ -*Inherits a modified version of `ERC20VotesUpgradeable` with a shifted storage layout.* + ## Methods @@ -44,39 +44,22 @@ function BLOCKLIST_PRECOMPILE() external view returns (address) |---|---|---| | _0 | address | undefined | -### CLOCK_MODE - -```solidity -function CLOCK_MODE() external view returns (string) -``` - - - -*Description of the clock* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | string | undefined | - -### DOMAIN_SEPARATOR +### EPOCH_SIZE ```solidity -function DOMAIN_SEPARATOR() external view returns (bytes32) +function EPOCH_SIZE() external view returns (uint256) ``` +amount of blocks in an epoch - -*See {IERC20Permit-DOMAIN_SEPARATOR}.* +*when an epoch is committed a multiple of this number of blocks must be committed* #### Returns | Name | Type | Description | |---|---|---| -| _0 | bytes32 | undefined | +| _0 | uint256 | undefined | ### NATIVE_TOKEN_CONTRACT @@ -146,27 +129,10 @@ function READ_ADDRESSLIST_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### SLASHING_PERCENTAGE - -```solidity -function SLASHING_PERCENTAGE() external view returns (uint256) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### SLASH_INCENTIVE_PERCENTAGE +### SYSTEM ```solidity -function SLASH_INCENTIVE_PERCENTAGE() external view returns (uint256) +function SYSTEM() external view returns (address) ``` @@ -178,12 +144,12 @@ function SLASH_INCENTIVE_PERCENTAGE() external view returns (uint256) | Name | Type | Description | |---|---|---| -| _0 | uint256 | undefined | +| _0 | address | undefined | -### SYSTEM +### VALIDATOR_PKCHECK_PRECOMPILE ```solidity -function SYSTEM() external view returns (address) +function VALIDATOR_PKCHECK_PRECOMPILE() external view returns (address) ``` @@ -197,10 +163,10 @@ function SYSTEM() external view returns (address) |---|---|---| | _0 | address | undefined | -### VALIDATOR_PKCHECK_PRECOMPILE +### VALIDATOR_PKCHECK_PRECOMPILE_GAS ```solidity -function VALIDATOR_PKCHECK_PRECOMPILE() external view returns (address) +function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) ``` @@ -212,12 +178,12 @@ function VALIDATOR_PKCHECK_PRECOMPILE() external view returns (address) | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| _0 | uint256 | undefined | -### VALIDATOR_PKCHECK_PRECOMPILE_GAS +### WITHDRAWAL_WAIT_PERIOD ```solidity -function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) +function WITHDRAWAL_WAIT_PERIOD() external view returns (uint256) ``` @@ -305,7 +271,7 @@ function balanceOf(address account) external view returns (uint256) function balanceOfAt(address account, uint256 epochNumber) external view returns (uint256) ``` -returns a validator balance for a given epoch + @@ -322,50 +288,10 @@ returns a validator balance for a given epoch |---|---|---| | _0 | uint256 | undefined | -### checkpoints - -```solidity -function checkpoints(address account, uint32 pos) external view returns (struct ERC20VotesUpgradeable.Checkpoint) -``` - - - -*Get the `pos`-th checkpoint for `account`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | -| pos | uint32 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | ERC20VotesUpgradeable.Checkpoint | undefined | - -### clock - -```solidity -function clock() external view returns (uint48) -``` - - - -*Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint48 | undefined | - ### commitEpoch ```solidity -function commitEpoch(uint256 id, Epoch epoch, uint256 epochSize) external nonpayable +function commitEpoch(uint256 id, Epoch epoch) external nonpayable ``` @@ -378,7 +304,6 @@ function commitEpoch(uint256 id, Epoch epoch, uint256 epochSize) external nonpay |---|---|---| | id | uint256 | undefined | | epoch | Epoch | undefined | -| epochSize | uint256 | undefined | ### currentEpochId @@ -437,88 +362,6 @@ function decreaseAllowance(address spender, uint256 subtractedValue) external no |---|---|---| | _0 | bool | undefined | -### delegate - -```solidity -function delegate(address delegatee) external nonpayable -``` - - - -*Delegate votes from the sender to `delegatee`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| delegatee | address | undefined | - -### delegateBySig - -```solidity -function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external nonpayable -``` - - - -*Delegates votes from signer to `delegatee`* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| delegatee | address | undefined | -| nonce | uint256 | undefined | -| expiry | uint256 | undefined | -| v | uint8 | undefined | -| r | bytes32 | undefined | -| s | bytes32 | undefined | - -### delegates - -```solidity -function delegates(address account) external view returns (address) -``` - - - -*Get the address `account` is currently delegating to.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### eip712Domain - -```solidity -function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions) -``` - - - -*See {EIP-5267}. _Available since v4.9._* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| fields | bytes1 | undefined | -| name | string | undefined | -| version | string | undefined | -| chainId | uint256 | undefined | -| verifyingContract | address | undefined | -| salt | bytes32 | undefined | -| extensions | uint256[] | undefined | - ### epochEndBlocks ```solidity @@ -565,73 +408,6 @@ function epochs(uint256) external view returns (uint256 startBlock, uint256 endB | endBlock | uint256 | undefined | | epochRoot | bytes32 | undefined | -### getPastTotalSupply - -```solidity -function getPastTotalSupply(uint256 timepoint) external view returns (uint256) -``` - - - -*Retrieve the `totalSupply` at the end of `timepoint`. Note, this value is the sum of all balances. It is NOT the sum of all the delegated votes! Requirements: - `timepoint` must be in the past* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| timepoint | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### getPastVotes - -```solidity -function getPastVotes(address account, uint256 timepoint) external view returns (uint256) -``` - - - -*Retrieve the number of votes for `account` at the end of `timepoint`. Requirements: - `timepoint` must be in the past* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | -| timepoint | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### getVotes - -```solidity -function getVotes(address account) external view returns (uint256) -``` - - - -*Gets the current votes balance for `account`* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - ### increaseAllowance ```solidity @@ -658,7 +434,7 @@ function increaseAllowance(address spender, uint256 addedValue) external nonpaya ### initialize ```solidity -function initialize(address newStateSender, address newStateReceiver, address newRootChainManager, address newNetworkParams, ValidatorInit[] initialValidators) external nonpayable +function initialize(address newStateSender, address newStateReceiver, address newRootChainManager, uint256 newEpochSize, ValidatorInit[] initialValidators) external nonpayable ``` @@ -672,7 +448,7 @@ function initialize(address newStateSender, address newStateReceiver, address ne | newStateSender | address | undefined | | newStateReceiver | address | undefined | | newRootChainManager | address | undefined | -| newNetworkParams | address | undefined | +| newEpochSize | uint256 | undefined | | initialValidators | ValidatorInit[] | undefined | ### name @@ -692,50 +468,6 @@ function name() external view returns (string) |---|---|---| | _0 | string | undefined | -### nonces - -```solidity -function nonces(address owner) external view returns (uint256) -``` - - - -*See {IERC20Permit-nonces}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| owner | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### numCheckpoints - -```solidity -function numCheckpoints(address account) external view returns (uint32) -``` - - - -*Get number of checkpoints for `account`.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| account | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint32 | undefined | - ### onStateReceive ```solidity @@ -776,66 +508,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in MATIC wei) | -### permit - -```solidity -function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable -``` - - - -*See {IERC20Permit-permit}.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| owner | address | undefined | -| spender | address | undefined | -| value | uint256 | undefined | -| deadline | uint256 | undefined | -| v | uint8 | undefined | -| r | bytes32 | undefined | -| s | bytes32 | undefined | - -### slash - -```solidity -function slash(address[] validators) external nonpayable -``` - -initialises slashing process - -*system call,given list of validators are slashed on L2 subsequently after their stake is slashed on L1* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| validators | address[] | list of validators to be slashed | - -### slashProcessed - -```solidity -function slashProcessed(uint256) external view returns (bool) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - ### symbol ```solidity @@ -898,7 +570,7 @@ function totalSupply() external view returns (uint256) function totalSupplyAt(uint256 epochNumber) external view returns (uint256) ``` -returns the total supply for a given epoch + @@ -1032,53 +704,6 @@ event Approval(address indexed owner, address indexed spender, uint256 value) | spender `indexed` | address | undefined | | value | uint256 | undefined | -### DelegateChanged - -```solidity -event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate) -``` - - - -*Emitted when an account changes their delegate.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| delegator `indexed` | address | undefined | -| fromDelegate `indexed` | address | undefined | -| toDelegate `indexed` | address | undefined | - -### DelegateVotesChanged - -```solidity -event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance) -``` - - - -*Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| delegate `indexed` | address | undefined | -| previousBalance | uint256 | undefined | -| newBalance | uint256 | undefined | - -### EIP712DomainChanged - -```solidity -event EIP712DomainChanged() -``` - - - -*MAY be emitted to signal that the domain could have changed.* - - ### Initialized ```solidity @@ -1114,22 +739,21 @@ event NewEpoch(uint256 indexed id, uint256 indexed startBlock, uint256 indexed e | endBlock `indexed` | uint256 | undefined | | epochRoot | bytes32 | undefined | -### Slashed +### Snapshot ```solidity -event Slashed(uint256 indexed exitId, address[] validators) +event Snapshot(uint256 id) ``` - +*Emitted by {_snapshot} when a snapshot identified by `id` is created.* #### Parameters | Name | Type | Description | |---|---|---| -| exitId `indexed` | uint256 | undefined | -| validators | address[] | undefined | +| id | uint256 | undefined | ### Transfer diff --git a/docs/common/Merkle.md b/docs/common/Merkle.md index ea502075..7d3d06d9 100644 --- a/docs/common/Merkle.md +++ b/docs/common/Merkle.md @@ -1,10 +1,10 @@ # Merkle -*Polygon Technology (similar to ENS, but written from scratch)* +*QEDK* > Merkle -library for checking membership in a merkle tree +Gas optimized verification of proof of inclusion for a leaf in an ordered Merkle tree diff --git a/docs/interfaces/child/validator/IRewardPool.md b/docs/interfaces/child/validator/IRewardPool.md index 12835dce..f2f7f496 100644 --- a/docs/interfaces/child/validator/IRewardPool.md +++ b/docs/interfaces/child/validator/IRewardPool.md @@ -13,7 +13,7 @@ Distributes rewards to validators for committed epochs ### distributeRewardFor ```solidity -function distributeRewardFor(uint256 epochId, Uptime[] uptime, uint256 epochSize) external nonpayable +function distributeRewardFor(uint256 epochId, Uptime[] uptime) external nonpayable ``` @@ -26,7 +26,6 @@ function distributeRewardFor(uint256 epochId, Uptime[] uptime, uint256 epochSize |---|---|---| | epochId | uint256 | undefined | | uptime | Uptime[] | undefined | -| epochSize | uint256 | undefined | ### paidRewardPerEpoch diff --git a/docs/interfaces/child/validator/IValidatorSet.md b/docs/interfaces/child/validator/IValidatorSet.md index c6bbd39a..d526a466 100644 --- a/docs/interfaces/child/validator/IValidatorSet.md +++ b/docs/interfaces/child/validator/IValidatorSet.md @@ -10,6 +10,23 @@ Manages voting power for validators and commits epochs for child chains ## Methods +### EPOCH_SIZE + +```solidity +function EPOCH_SIZE() external view returns (uint256) +``` + +amount of blocks in an epoch + +*when an epoch is committed a multiple of this number of blocks must be committed* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + ### balanceOfAt ```solidity @@ -36,7 +53,7 @@ returns a validator balance for a given epoch ### commitEpoch ```solidity -function commitEpoch(uint256 id, Epoch epoch, uint256 epochSize) external nonpayable +function commitEpoch(uint256 id, Epoch epoch) external nonpayable ``` @@ -49,7 +66,6 @@ function commitEpoch(uint256 id, Epoch epoch, uint256 epochSize) external nonpay |---|---|---| | id | uint256 | undefined | | epoch | Epoch | undefined | -| epochSize | uint256 | undefined | ### onStateReceive @@ -91,22 +107,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in MATIC wei) | -### slash - -```solidity -function slash(address[] validators) external nonpayable -``` - -initialises slashing process - -*system call,given list of validators are slashed on L2 subsequently after their stake is slashed on L1* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| validators | address[] | list of validators to be slashed | - ### totalBlocks ```solidity @@ -223,23 +223,6 @@ event NewEpoch(uint256 indexed id, uint256 indexed startBlock, uint256 indexed e | endBlock `indexed` | uint256 | undefined | | epochRoot | bytes32 | undefined | -### Slashed - -```solidity -event Slashed(uint256 indexed exitId, address[] validators) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| exitId `indexed` | uint256 | undefined | -| validators | address[] | undefined | - ### Withdrawal ```solidity diff --git a/docs/interfaces/root/IExitHelper.md b/docs/interfaces/root/IExitHelper.md index 119be1f1..d84afed9 100644 --- a/docs/interfaces/root/IExitHelper.md +++ b/docs/interfaces/root/IExitHelper.md @@ -26,23 +26,6 @@ function batchExit(IExitHelper.BatchExitInput[] inputs) external nonpayable |---|---|---| | inputs | IExitHelper.BatchExitInput[] | undefined | -### caller - -```solidity -function caller() external view returns (address) -``` - -Returns the address that called the exit function - -*only available in the context of the exit function* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | address of the caller | - ### exit ```solidity diff --git a/docs/interfaces/root/IRootERC20Predicate.md b/docs/interfaces/root/IRootERC20Predicate.md index c11982d6..2037f675 100644 --- a/docs/interfaces/root/IRootERC20Predicate.md +++ b/docs/interfaces/root/IRootERC20Predicate.md @@ -67,6 +67,23 @@ Function to be used for token mapping |---|---|---| | _0 | address | address Address of the child token | +### nativeTokenRoot + +```solidity +function nativeTokenRoot() external nonpayable returns (address) +``` + +Function that retrieves rootchain token that represents Supernets native token + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | address Address of rootchain token (mapped to Supernets native token) | + ### onL2StateReceive ```solidity diff --git a/docs/interfaces/root/staking/ICustomSupernetManager.md b/docs/interfaces/root/staking/ICustomSupernetManager.md index 5eabe384..3a5b474a 100644 --- a/docs/interfaces/root/staking/ICustomSupernetManager.md +++ b/docs/interfaces/root/staking/ICustomSupernetManager.md @@ -10,6 +10,22 @@ Manages validator access and syncs voting power between the stake manager and va ## Methods +### addGenesisBalance + +```solidity +function addGenesisBalance(uint256 amount) external nonpayable +``` + +addGenesisBalance is used to specify genesis balance information for genesis accounts on the Supernets. It is applicable only in case Supernets native contract is mapped to a pre-existing rootchain ERC20 token. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| amount | uint256 | represents the amount to be premined in the genesis. | + ### enableStaking ```solidity @@ -122,30 +138,30 @@ Allows to whitelist validators that are allowed to stake |---|---|---| | validators_ | address[] | undefined | -### withdrawSlashedStake + + +## Events + +### AddedToWhitelist ```solidity -function withdrawSlashedStake(address to) external nonpayable +event AddedToWhitelist(address indexed validator) ``` -Withdraws slashed MATIC of slashed validators -*only callable by owner* + + #### Parameters | Name | Type | Description | |---|---|---| -| to | address | undefined | - - +| validator `indexed` | address | undefined | -## Events - -### AddedToWhitelist +### GenesisBalanceAdded ```solidity -event AddedToWhitelist(address indexed validator) +event GenesisBalanceAdded(address indexed account, uint256 indexed amount) ``` @@ -156,7 +172,8 @@ event AddedToWhitelist(address indexed validator) | Name | Type | Description | |---|---|---| -| validator `indexed` | address | undefined | +| account `indexed` | address | undefined | +| amount `indexed` | uint256 | undefined | ### GenesisFinalized diff --git a/docs/interfaces/root/staking/IStakeManager.md b/docs/interfaces/root/staking/IStakeManager.md index 76889577..db340fd7 100644 --- a/docs/interfaces/root/staking/IStakeManager.md +++ b/docs/interfaces/root/staking/IStakeManager.md @@ -86,23 +86,6 @@ called by child manager contract to release a validator's stake -#### Parameters - -| Name | Type | Description | -|---|---|---| -| validator | address | undefined | -| amount | uint256 | undefined | - -### slashStakeOf - -```solidity -function slashStakeOf(address validator, uint256 amount) external nonpayable -``` - -called by child manager contract to slash a validator's stakemanager collects slashed amount - - - #### Parameters | Name | Type | Description | @@ -325,23 +308,5 @@ event StakeWithdrawn(address indexed validator, address indexed recipient, uint2 | recipient `indexed` | address | undefined | | amount | uint256 | undefined | -### ValidatorSlashed - -```solidity -event ValidatorSlashed(uint256 indexed id, address indexed validator, uint256 amount) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id `indexed` | uint256 | undefined | -| validator `indexed` | address | undefined | -| amount | uint256 | undefined | - diff --git a/docs/lib/GenesisProxy.md b/docs/lib/GenesisProxy.md new file mode 100644 index 00000000..36bea189 --- /dev/null +++ b/docs/lib/GenesisProxy.md @@ -0,0 +1,101 @@ +# GenesisProxy + +*Polygon Technology* + +> GenesisProxy + +wrapper for OpenZeppelin's Transparent Upgreadable Proxy, intended for use during genesis for genesis contractsone GenesisProxy should be deployed for each genesis contract + + + +## Methods + +### protectSetUpProxy + +```solidity +function protectSetUpProxy(address initiator) external nonpayable +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| initiator | address | undefined | + +### setUpProxy + +```solidity +function setUpProxy(address logic, address admin, bytes data) external nonpayable +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| logic | address | undefined | +| admin | address | undefined | +| data | bytes | undefined | + + + +## Events + +### AdminChanged + +```solidity +event AdminChanged(address previousAdmin, address newAdmin) +``` + + + +*Emitted when the admin account has changed.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| previousAdmin | address | undefined | +| newAdmin | address | undefined | + +### BeaconUpgraded + +```solidity +event BeaconUpgraded(address indexed beacon) +``` + + + +*Emitted when the beacon is changed.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| beacon `indexed` | address | undefined | + +### Upgraded + +```solidity +event Upgraded(address indexed implementation) +``` + + + +*Emitted when the implementation is upgraded.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| implementation `indexed` | address | undefined | + + + diff --git a/docs/root/ExitHelper.md b/docs/root/ExitHelper.md index e0593be2..671eddb3 100644 --- a/docs/root/ExitHelper.md +++ b/docs/root/ExitHelper.md @@ -26,23 +26,6 @@ function batchExit(IExitHelper.BatchExitInput[] inputs) external nonpayable |---|---|---| | inputs | IExitHelper.BatchExitInput[] | undefined | -### caller - -```solidity -function caller() external view returns (address) -``` - -Returns the address that called the exit function - -*only available in the context of the exit function* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | address of the caller | - ### checkpointManager ```solidity diff --git a/docs/root/RootERC20Predicate.md b/docs/root/RootERC20Predicate.md index a1116f71..15170349 100644 --- a/docs/root/RootERC20Predicate.md +++ b/docs/root/RootERC20Predicate.md @@ -150,7 +150,7 @@ function exitHelper() external view returns (address) ### initialize ```solidity -function initialize(address newStateSender, address newExitHelper, address newChildERC20Predicate, address newChildTokenTemplate, address nativeTokenRootAddress) external nonpayable +function initialize(address newStateSender, address newExitHelper, address newChildERC20Predicate, address newChildTokenTemplate, address newNativeTokenRoot) external nonpayable ``` Initialization function for RootERC20Predicate @@ -165,7 +165,7 @@ Initialization function for RootERC20Predicate | newExitHelper | address | Address of ExitHelper to receive withdrawal information from | | newChildERC20Predicate | address | Address of child ERC20 predicate to communicate with | | newChildTokenTemplate | address | undefined | -| nativeTokenRootAddress | address | undefined | +| newNativeTokenRoot | address | undefined | ### mapToken @@ -189,6 +189,23 @@ Function to be used for token mapping |---|---|---| | _0 | address | address Address of the child token | +### nativeTokenRoot + +```solidity +function nativeTokenRoot() external view returns (address) +``` + +Function that retrieves rootchain token that represents Supernets native token + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | address Address of rootchain token (mapped to Supernets native token) | + ### onL2StateReceive ```solidity diff --git a/docs/root/staking/CustomSupernetManager.md b/docs/root/staking/CustomSupernetManager.md index b3135f74..eacd2065 100644 --- a/docs/root/staking/CustomSupernetManager.md +++ b/docs/root/staking/CustomSupernetManager.md @@ -21,6 +21,22 @@ function acceptOwnership() external nonpayable *The new owner accepts the ownership transfer.* +### addGenesisBalance + +```solidity +function addGenesisBalance(uint256 amount) external nonpayable +``` + +addGenesisBalance is used to specify genesis balance information for genesis accounts on the Supernets. It is applicable only in case Supernets native contract is mapped to a pre-existing rootchain ERC20 token. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| amount | uint256 | represents the amount to be premined in the genesis. | + ### domain ```solidity @@ -60,6 +76,28 @@ finalizes initial genesis validator set *only callable by owner* +### genesisBalances + +```solidity +function genesisBalances(address) external view returns (uint256) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + ### genesisSet ```solidity @@ -119,7 +157,7 @@ function id() external view returns (uint256) ### initialize ```solidity -function initialize(address newStakeManager, address newBls, address newStateSender, address newMatic, address newChildValidatorSet, address newExitHelper, string newDomain) external nonpayable +function initialize(address newStakeManager, address newBls, address newStateSender, address newMatic, address newChildValidatorSet, address newExitHelper, address newRootERC20Predicate, string newDomain) external nonpayable ``` @@ -136,6 +174,7 @@ function initialize(address newStakeManager, address newBls, address newStateSen | newMatic | address | undefined | | newChildValidatorSet | address | undefined | | newExitHelper | address | undefined | +| newRootERC20Predicate | address | undefined | | newDomain | string | undefined | ### onInit @@ -307,30 +346,30 @@ Allows to whitelist validators that are allowed to stake |---|---|---| | validators_ | address[] | undefined | -### withdrawSlashedStake + + +## Events + +### AddedToWhitelist ```solidity -function withdrawSlashedStake(address to) external nonpayable +event AddedToWhitelist(address indexed validator) ``` -Withdraws slashed MATIC of slashed validators -*only callable by owner* + + #### Parameters | Name | Type | Description | |---|---|---| -| to | address | undefined | - - - -## Events +| validator `indexed` | address | undefined | -### AddedToWhitelist +### GenesisBalanceAdded ```solidity -event AddedToWhitelist(address indexed validator) +event GenesisBalanceAdded(address indexed account, uint256 indexed amount) ``` @@ -341,7 +380,8 @@ event AddedToWhitelist(address indexed validator) | Name | Type | Description | |---|---|---| -| validator `indexed` | address | undefined | +| account `indexed` | address | undefined | +| amount `indexed` | uint256 | undefined | ### GenesisFinalized diff --git a/docs/root/staking/StakeManager.md b/docs/root/staking/StakeManager.md index 051fa9f6..75556d69 100644 --- a/docs/root/staking/StakeManager.md +++ b/docs/root/staking/StakeManager.md @@ -102,23 +102,6 @@ called by child manager contract to release a validator's stake -#### Parameters - -| Name | Type | Description | -|---|---|---| -| validator | address | undefined | -| amount | uint256 | undefined | - -### slashStakeOf - -```solidity -function slashStakeOf(address validator, uint256 amount) external nonpayable -``` - -called by child manager contract to slash a validator's stakemanager collects slashed amount - - - #### Parameters | Name | Type | Description | @@ -357,23 +340,5 @@ event StakeWithdrawn(address indexed validator, address indexed recipient, uint2 | recipient `indexed` | address | undefined | | amount | uint256 | undefined | -### ValidatorSlashed - -```solidity -event ValidatorSlashed(uint256 indexed id, address indexed validator, uint256 amount) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| id `indexed` | uint256 | undefined | -| validator `indexed` | address | undefined | -| amount | uint256 | undefined | - diff --git a/foundry.toml b/foundry.toml index bc7baa2e..ab796199 100644 --- a/foundry.toml +++ b/foundry.toml @@ -14,7 +14,8 @@ ffi = true fs_permissions = [ { access = "read", path = "script/deployment/sharedRootContractsConfig.json" }, { access = "read", path = "script/deployment/rootContractSetConfig.json" }, - { access = "read", path = "script/deployment/rootTokenContractsConfig.json" } + { access = "read", path = "script/deployment/rootTokenContractsConfig.json" }, + { access = "read", path = "out/" } ] # do not use for computationally expensive tests diff --git a/lib/forge-std b/lib/forge-std index aea0b268..705263c9 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit aea0b2685bebc883c09f5554d7fb481e85d0564d +Subproject commit 705263c95892a906d7af65f0f73ce8a4a0c80b80 diff --git a/package.json b/package.json index 13876f8b..4cabcfb2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "coverage": "npx hardhat coverage", "coverage:foundry": "forge coverage --report lcov && genhtml -o forge-coverage lcov.info", "prepare": "husky install", - "husky:pre-commit": "npm run prettier && git add ." + "husky:pre-commit": "" }, "dependencies": { "@openzeppelin/contracts": "^4.9.3", diff --git a/script/deployment/DeployNewRootContractSet.s.sol b/script/deployment/DeployNewRootContractSet.s.sol index 75f43c2a..9f79a1c5 100644 --- a/script/deployment/DeployNewRootContractSet.s.sol +++ b/script/deployment/DeployNewRootContractSet.s.sol @@ -32,12 +32,12 @@ contract DeployNewRootContractSet is address customSupernetManagerProxy ) { - string memory config = vm.readFile("script/deployment/newRootContractSetConfig.json"); + string memory config = vm.readFile("script/deployment/rootContractSetConfig.json"); vm.startBroadcast(); ProxyAdmin _proxyAdmin = new ProxyAdmin(); - _proxyAdmin.transferOwnership(config.readAddress('["common"].proxyAdminOwner')); + _proxyAdmin.transferOwnership(config.readAddress('["ProxyAdmin"].proxyAdminOwner')); vm.stopBroadcast(); @@ -56,11 +56,12 @@ contract DeployNewRootContractSet is (customSupernetManagerLogic, customSupernetManagerProxy) = deployCustomSupernetManager( proxyAdmin, config.readAddress('["CustomSupernetManager"].newStakeManager'), - config.readAddress('["common"].newBls'), + config.readAddress('["CustomSupernetManager"].newBls'), stateSender, config.readAddress('["CustomSupernetManager"].newMatic'), config.readAddress('["CustomSupernetManager"].newChildValidatorSet'), exitHelperProxy, + config.readAddress('["CustomSupernetManager"].newRootERC20Predicate'), config.readString('["CustomSupernetManager"].newDomain') ); } diff --git a/script/deployment/DeployRootTokenContracts.s.sol b/script/deployment/DeployRootTokenContracts.s.sol index d1db349a..322189af 100644 --- a/script/deployment/DeployRootTokenContracts.s.sol +++ b/script/deployment/DeployRootTokenContracts.s.sol @@ -45,7 +45,7 @@ contract DeployRootTokenContracts is config.readAddress('["common"].stateSender'), config.readAddress('["common"].exitHelper'), config.readAddress('["RootERC20Predicate"].newChildERC20Predicate'), - config.readAddress('["common"].newChildTokenTemplate'), + config.readAddress('["RootERC20Predicate"].newChildTokenTemplate'), config.readAddress('["RootERC20Predicate"].nativeTokenRootAddress') ); @@ -54,7 +54,7 @@ contract DeployRootTokenContracts is config.readAddress('["common"].stateSender'), config.readAddress('["common"].exitHelper'), rootERC20PredicateProxy, - config.readAddress('["common"].newChildTokenTemplate') + config.readAddress('["newChildTokenTemplate"].newChildTokenTemplate') ); (rootERC721PredicateLogic, rootERC721PredicateProxy) = deployRootERC721Predicate( @@ -62,7 +62,7 @@ contract DeployRootTokenContracts is config.readAddress('["common"].stateSender'), config.readAddress('["common"].exitHelper'), config.readAddress('["RootERC721Predicate"].newChildERC721Predicate'), - config.readAddress('["common"].newChildTokenTemplate') + config.readAddress('["RootERC721Predicate"].newChildTokenTemplate') ); (childMintableERC721PredicateLogic, childMintableERC721PredicateProxy) = deployChildMintableERC721Predicate( @@ -70,7 +70,7 @@ contract DeployRootTokenContracts is config.readAddress('["common"].stateSender'), config.readAddress('["common"].exitHelper'), rootERC721PredicateProxy, - config.readAddress('["common"].newChildTokenTemplate') + config.readAddress('["ChildMintableERC721Predicate"].newChildTokenTemplate') ); (rootERC1155PredicateLogic, rootERC1155PredicateProxy) = deployRootERC1155Predicate( @@ -78,7 +78,7 @@ contract DeployRootTokenContracts is config.readAddress('["common"].stateSender'), config.readAddress('["common"].exitHelper'), config.readAddress('["RootERC1155Predicate"].newChildERC1155Predicate'), - config.readAddress('["common"].newChildTokenTemplate') + config.readAddress('["RootERC1155Predicate"].newChildTokenTemplate') ); (childMintableERC1155PredicateLogic, childMintableERC1155PredicateProxy) = deployChildMintableERC1155Predicate( @@ -86,7 +86,7 @@ contract DeployRootTokenContracts is config.readAddress('["common"].stateSender'), config.readAddress('["common"].exitHelper'), rootERC1155PredicateProxy, - config.readAddress('["common"].newChildTokenTemplate') + config.readAddress('["ChildMintableERC1155Predicate"].newChildTokenTemplate') ); } } diff --git a/script/deployment/DeploySharedRootContracts.sol b/script/deployment/DeploySharedRootContracts.sol index 72d74d61..c1ae872c 100644 --- a/script/deployment/DeploySharedRootContracts.sol +++ b/script/deployment/DeploySharedRootContracts.sol @@ -22,7 +22,7 @@ contract DeploySharedRootContracts is BLSDeployer, BN256G2Deployer, StakeManager vm.startBroadcast(); ProxyAdmin _proxyAdmin = new ProxyAdmin(); - _proxyAdmin.transferOwnership(config.readAddress('["StakeManager"].proxyAdminOwner')); + _proxyAdmin.transferOwnership(config.readAddress('["ProxyAdmin"].proxyAdminOwner')); vm.stopBroadcast(); diff --git a/script/deployment/root/DeployCheckpointManager.s.sol b/script/deployment/root/DeployCheckpointManager.s.sol index c90cc047..c0f4b8cb 100644 --- a/script/deployment/root/DeployCheckpointManager.s.sol +++ b/script/deployment/root/DeployCheckpointManager.s.sol @@ -30,19 +30,19 @@ abstract contract CheckpointManagerDeployer is Script { ///@notice Alternative function: Does NOT initialize the contract! function deployCheckpointManager( address proxyAdmin, - address INITIALIZER + address initiator ) internal returns (address logicAddr, address proxyAddr) { - return _deployCheckpointManager(proxyAdmin, "", INITIALIZER); + return _deployCheckpointManager(proxyAdmin, "", initiator); } function _deployCheckpointManager( address proxyAdmin, bytes memory initData, - address INITIALIZER + address initiator ) private returns (address logicAddr, address proxyAddr) { vm.startBroadcast(); - CheckpointManager checkpointManager = new CheckpointManager(INITIALIZER); + CheckpointManager checkpointManager = new CheckpointManager(initiator); TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( address(checkpointManager), diff --git a/script/deployment/root/staking/DeployCustomSupernetManager.s.sol b/script/deployment/root/staking/DeployCustomSupernetManager.s.sol index f68ab3ab..8f4e6c9c 100644 --- a/script/deployment/root/staking/DeployCustomSupernetManager.s.sol +++ b/script/deployment/root/staking/DeployCustomSupernetManager.s.sol @@ -16,11 +16,21 @@ abstract contract CustomSupernetManagerDeployer is Script { address newMatic, address newChildValidatorSet, address newExitHelper, + address newRootERC20Predicate, string memory newDomain ) internal returns (address logicAddr, address proxyAddr) { bytes memory initData = abi.encodeCall( CustomSupernetManager.initialize, - (newStakeManager, newBls, newStateSender, newMatic, newChildValidatorSet, newExitHelper, newDomain) + ( + newStakeManager, + newBls, + newStateSender, + newMatic, + newChildValidatorSet, + newExitHelper, + newRootERC20Predicate, + newDomain + ) ); vm.startBroadcast(); @@ -49,6 +59,7 @@ contract DeployCustomSupernetManager is CustomSupernetManagerDeployer { address newMatic, address newChildValidatorSet, address newExitHelper, + address newRootERC20Predicate, string memory newDomain ) external returns (address logicAddr, address proxyAddr) { return @@ -60,6 +71,7 @@ contract DeployCustomSupernetManager is CustomSupernetManagerDeployer { newMatic, newChildValidatorSet, newExitHelper, + newRootERC20Predicate, newDomain ); } diff --git a/script/deployment/rootContractSetConfig.json b/script/deployment/rootContractSetConfig.json index dbe6450b..543b0142 100644 --- a/script/deployment/rootContractSetConfig.json +++ b/script/deployment/rootContractSetConfig.json @@ -1,18 +1,18 @@ { - "common": { - "proxyAdminOwner": "", - "newBls": "", - "newChildTokenTemplate": "" + "ProxyAdmin": { + "proxyAdminOwner": "" }, "CheckpointManager": { - "INITIALIZER": "" + "initiator": "" }, "CustomSupernetManager": { "newStakeManager": "", + "newBls": "", "newMatic": "", "newChildValidatorSet": "", + "newRootERC20Predicate": "", "newDomain": "" } } diff --git a/script/deployment/sharedRootContractsConfig.json b/script/deployment/sharedRootContractsConfig.json index 03bc8a8b..f74e7569 100644 --- a/script/deployment/sharedRootContractsConfig.json +++ b/script/deployment/sharedRootContractsConfig.json @@ -1,6 +1,9 @@ { + "ProxyAdmin": { + "proxyAdminOwner": "" + }, + "StakeManager": { - "proxyAdminOwner": "", "newStakingToken": "" } } diff --git a/script/deployment/test/DeployChildContracts.s.sol b/script/deployment/test/DeployChildContracts.s.sol new file mode 100644 index 00000000..f75f8cdc --- /dev/null +++ b/script/deployment/test/DeployChildContracts.s.sol @@ -0,0 +1,319 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; + +import "script/deployment/test/child/validator/DeployRewardPool.s.sol"; +import "script/deployment/test/child/validator/DeployValidatorSet.s.sol"; +import "script/deployment/test/child/DeployChildERC20.s.sol"; +import "script/deployment/test/child/DeployChildERC20Predicate.s.sol"; +import "script/deployment/test/child/DeployChildERC20PredicateAccessList.s.sol"; +import "script/deployment/test/child/DeployChildERC721.s.sol"; +import "script/deployment/test/child/DeployChildERC721Predicate.s.sol"; +import "script/deployment/test/child/DeployChildERC721PredicateAccessList.s.sol"; +import "script/deployment/test/child/DeployChildERC1155.s.sol"; +import "script/deployment/test/child/DeployChildERC1155Predicate.s.sol"; +import "script/deployment/test/child/DeployChildERC1155PredicateAccessList.s.sol"; +import "script/deployment/test/child/DeployEIP1559Burn.s.sol"; +import "script/deployment/test/child/DeployL2StateSender.s.sol"; +import "script/deployment/test/child/DeployNativeERC20.s.sol"; +import "script/deployment/test/child/DeployNativeERC20Mintable.s.sol"; +import "script/deployment/test/child/DeployRootMintableERC20Predicate.s.sol"; +import "script/deployment/test/child/DeployRootMintableERC20PredicateAccessList.s.sol"; +import "script/deployment/test/child/DeployRootMintableERC721Predicate.s.sol"; +import "script/deployment/test/child/DeployRootMintableERC721PredicateAccessList.s.sol"; +import "script/deployment/test/child/DeployRootMintableERC1155Predicate.s.sol"; +import "script/deployment/test/child/DeployRootMintableERC1155PredicateAccessList.s.sol"; +import "script/deployment/test/child/DeployStateReceiver.s.sol"; +import "script/deployment/test/child/DeploySystem.s.sol"; + +contract DeployChildContracts is + RewardPoolDeployer, + ValidatorSetDeployer, + ChildERC20Deployer, + ChildERC20PredicateDeployer, + ChildERC20PredicateAccessListDeployer, + ChildERC721Deployer, + ChildERC721PredicateDeployer, + ChildERC721PredicateAccessListDeployer, + ChildERC1155Deployer, + ChildERC1155PredicateDeployer, + ChildERC1155PredicateAccessListDeployer, + EIP1559BurnDeployer, + L2StateSenderDeployer, + NativeERC20Deployer, + NativeERC20MintableDeployer, + RootMintableERC20PredicateDeployer, + RootMintableERC20PredicateAccessListDeployer, + RootMintableERC721PredicateDeployer, + RootMintableERC721PredicateAccessListDeployer, + RootMintableERC1155PredicateDeployer, + RootMintableERC1155PredicateAccessListDeployer, + StateReceiverDeployer, + SystemDeployer +{ + using stdJson for string; + + address public proxyAdmin; + address public rewardPoolLogic; + address public rewardPoolProxy; + address public validatorSetLogic; + address public validatorSetProxy; + address public childERC20Logic; + address public childERC20Proxy; + address public childERC20PredicateLogic; + address public childERC20PredicateProxy; + address public childERC20PredicateAccessListLogic; + address public childERC20PredicateAccessListProxy; + address public childERC721Logic; + address public childERC721Proxy; + address public childERC721PredicateLogic; + address public childERC721PredicateProxy; + address public childERC721PredicateAccessListLogic; + address public childERC721PredicateAccessListProxy; + address public childERC1155Logic; + address public childERC1155Proxy; + address public childERC1155PredicateLogic; + address public childERC1155PredicateProxy; + address public childERC1155PredicateAccessListLogic; + address public childERC1155PredicateAccessListProxy; + address public eip1559BurnLogic; + address public eip1559BurnProxy; + address public l2StateSender; + address public nativeERC20Logic; + address public nativeERC20Proxy; + address public nativeERC20MintableLogic; + address public nativeERC20MintableProxy; + address public rootMintableERC20PredicateLogic; + address public rootMintableERC20PredicateProxy; + address public rootMintableERC20PredicateAccessListLogic; + address public rootMintableERC20PredicateAccessListProxy; + address public rootMintableERC721PredicateLogic; + address public rootMintableERC721PredicateProxy; + address public rootMintableERC721PredicateAccessListLogic; + address public rootMintableERC721PredicateAccessListProxy; + address public rootMintableERC1155PredicateLogic; + address public rootMintableERC1155PredicateProxy; + address public rootMintableERC1155PredicateAccessListLogic; + address public rootMintableERC1155PredicateAccessListProxy; + address public stateReceiver; + address public system; + + function run() external { + string memory config = vm.readFile("script/deployment/childContractsConfig.json"); + + vm.startBroadcast(); + + ProxyAdmin _proxyAdmin = new ProxyAdmin(); + _proxyAdmin.transferOwnership(config.readAddress('["ProxyAdmin"].proxyAdminOwner')); + + vm.stopBroadcast(); + + proxyAdmin = address(_proxyAdmin); + + stateReceiver = deployStateReceiver(); + + (validatorSetLogic, validatorSetProxy) = deployValidatorSet( + proxyAdmin, + config.readAddress('["ValidatorSet"].newStateSender'), + stateReceiver, + config.readAddress('["ValidatorSet"].newRootChainManager'), + config.readUint('["ValidatorSet"].newEpochSize'), + abi.decode(config.readBytes('["ValidatorSet"].initialValidators'), (ValidatorInit[])) + ); + + (rewardPoolLogic, rewardPoolProxy) = deployRewardPool( + proxyAdmin, + config.readAddress('["RewardPool"].newRewardToken'), + config.readAddress('["RewardPool"].newRewardWallet'), + validatorSetProxy, + config.readUint('["RewardPool"].newBaseReward') + ); + + (childERC20Logic, childERC20Proxy) = deployChildERC20( + proxyAdmin, + config.readAddress('["ChildERC20"].rootToken_'), + config.readString('["ChildERC20"].name_'), + config.readString('["ChildERC20"].symbol_'), + uint8(config.readUint('["ChildERC20"].decimals_')) + ); + + l2StateSender = deployL2StateSender(); + + (childERC20PredicateLogic, childERC20PredicateProxy) = deployChildERC20Predicate( + proxyAdmin, + l2StateSender, + stateReceiver, + config.readAddress('["ChildERC20Predicate"].newRootERC20Predicate'), + config.readAddress('["ChildERC20Predicate"].newChildTokenTemplate'), + config.readAddress('["ChildERC20Predicate"].newNativeTokenRootAddress') + ); + + (childERC20PredicateAccessListLogic, childERC20PredicateAccessListProxy) = deployChildERC20PredicateAccessList( + proxyAdmin, + l2StateSender, + stateReceiver, + config.readAddress('["ChildERC20PredicateAccessList"].newRootERC20Predicate'), + config.readAddress('["ChildERC20PredicateAccessList"].newChildTokenTemplate'), + config.readAddress('["ChildERC20PredicateAccessList"].newNativeTokenRootAddress'), + config.readBool('["ChildERC20PredicateAccessList"].newUseAllowList'), + config.readBool('["ChildERC20PredicateAccessList"].newUseBlockList'), + config.readAddress('["ChildERC20PredicateAccessList"].newOwner') + ); + + (childERC721Logic, childERC721Proxy) = deployChildERC721( + proxyAdmin, + config.readAddress('["ChildERC721"].rootToken_'), + config.readString('["ChildERC721"].name_'), + config.readString('["ChildERC721"].symbol_') + ); + + (childERC721PredicateLogic, childERC721PredicateProxy) = deployChildERC721Predicate( + proxyAdmin, + l2StateSender, + stateReceiver, + config.readAddress('["ChildERC721Predicate"].newRootERC721Predicate'), + config.readAddress('["ChildERC721Predicate"].newChildTokenTemplate') + ); + + ( + childERC721PredicateAccessListLogic, + childERC721PredicateAccessListProxy + ) = deployChildERC721PredicateAccessList( + proxyAdmin, + l2StateSender, + stateReceiver, + config.readAddress('["ChildERC721PredicateAccessList"].newRootERC721Predicate'), + config.readAddress('["ChildERC721PredicateAccessList"].newChildTokenTemplate'), + config.readBool('["ChildERC721PredicateAccessList"].newUseAllowList'), + config.readBool('["ChildERC721PredicateAccessList"].newUseBlockList'), + config.readAddress('["ChildERC721PredicateAccessList"].newOwner') + ); + + (childERC1155Logic, childERC1155Proxy) = deployChildERC1155( + proxyAdmin, + config.readAddress('["ChildERC1155"].rootToken_'), + config.readString('["ChildERC1155"].uri_') + ); + + (childERC1155PredicateLogic, childERC1155PredicateProxy) = deployChildERC1155Predicate( + proxyAdmin, + l2StateSender, + stateReceiver, + config.readAddress('["ChildERC1155Predicate"].newRootERC1155Predicate'), + config.readAddress('["ChildERC1155Predicate"].newChildTokenTemplate') + ); + + ( + childERC1155PredicateAccessListLogic, + childERC1155PredicateAccessListProxy + ) = deployChildERC1155PredicateAccessList( + proxyAdmin, + l2StateSender, + stateReceiver, + config.readAddress('["ChildERC1155PredicateAccessList"].newRootERC1155Predicate'), + config.readAddress('["ChildERC1155PredicateAccessList"].newChildTokenTemplate'), + config.readBool('["ChildERC1155PredicateAccessList"].newUseAllowList'), + config.readBool('["ChildERC1155PredicateAccessList"].newUseBlockList'), + config.readAddress('["ChildERC1155PredicateAccessList"].newOwner') + ); + + (eip1559BurnLogic, eip1559BurnProxy) = deployEIP1559Burn( + proxyAdmin, + IChildERC20Predicate(childERC20PredicateProxy), + config.readAddress('["EIP1559Burn"].newBurnDestination') + ); + + (nativeERC20Logic, nativeERC20Proxy) = deployNativeERC20( + proxyAdmin, + config.readAddress('["NativeERC20"].predicate_'), + config.readAddress('["NativeERC20"].rootToken_'), + config.readString('["NativeERC20"].name_'), + config.readString('["NativeERC20"].symbol_'), + uint8(config.readUint('["NativeERC20"].decimals_')), + config.readUint('["NativeERC20"].tokenSupply_') + ); + + (nativeERC20MintableLogic, nativeERC20MintableProxy) = deployNativeERC20Mintable( + proxyAdmin, + config.readAddress('["NativeERC20Mintable"].predicate_'), + config.readAddress('["NativeERC20Mintable"].owner_'), + config.readAddress('["NativeERC20Mintable"].rootToken_'), + config.readString('["NativeERC20Mintable"].name_'), + config.readString('["NativeERC20Mintable"].symbol_'), + uint8(config.readUint('["NativeERC20Mintable"].decimals_')), + config.readUint('["NativeERC20Mintable"].tokenSupply_') + ); + + (rootMintableERC20PredicateLogic, rootMintableERC20PredicateProxy) = deployRootMintableERC20Predicate( + proxyAdmin, + l2StateSender, + stateReceiver, + childERC20PredicateProxy, + config.readAddress('["RootMintableERC20Predicate"].newChildTokenTemplate') + ); + + ( + rootMintableERC20PredicateAccessListLogic, + rootMintableERC20PredicateAccessListProxy + ) = deployRootMintableERC20PredicateAccessList( + proxyAdmin, + l2StateSender, + stateReceiver, + childERC20PredicateProxy, + config.readAddress('["RootMintableERC20PredicateAccessList"].newChildTokenTemplate'), + config.readBool('["RootMintableERC20PredicateAccessList"].newUseAllowList'), + config.readBool('["RootMintableERC20PredicateAccessList"].newUseBlockList'), + config.readAddress('["RootMintableERC20PredicateAccessList"].newOwner') + ); + + (rootMintableERC721PredicateLogic, rootMintableERC721PredicateProxy) = deployRootMintableERC721Predicate( + proxyAdmin, + l2StateSender, + stateReceiver, + childERC721PredicateProxy, + config.readAddress('["RootMintableERC721Predicate"].newChildTokenTemplate') + ); + + ( + rootMintableERC721PredicateAccessListLogic, + rootMintableERC721PredicateAccessListProxy + ) = deployRootMintableERC721PredicateAccessList( + proxyAdmin, + l2StateSender, + stateReceiver, + childERC721PredicateProxy, + config.readAddress('["RootMintableERC721PredicateAccessList"].newChildTokenTemplate'), + config.readBool('["RootMintableERC721PredicateAccessList"].newUseAllowList'), + config.readBool('["RootMintableERC721PredicateAccessList"].newUseBlockList'), + config.readAddress('["RootMintableERC721PredicateAccessList"].newOwner') + ); + + (rootMintableERC1155PredicateLogic, rootMintableERC1155PredicateProxy) = deployRootMintableERC1155Predicate( + proxyAdmin, + l2StateSender, + stateReceiver, + childERC1155PredicateProxy, + config.readAddress('["RootMintableERC1155Predicate"].newChildTokenTemplate') + ); + + ( + rootMintableERC1155PredicateAccessListLogic, + rootMintableERC1155PredicateAccessListProxy + ) = deployRootMintableERC1155PredicateAccessList( + proxyAdmin, + l2StateSender, + stateReceiver, + childERC1155PredicateProxy, + config.readAddress('["RootMintableERC1155PredicateAccessList"].newChildTokenTemplate'), + config.readBool('["RootMintableERC1155PredicateAccessList"].newUseAllowList'), + config.readBool('["RootMintableERC1155PredicateAccessList"].newUseBlockList'), + config.readAddress('["RootMintableERC1155PredicateAccessList"].newOwner') + ); + + system = deploySystem(); + } +} diff --git a/script/deployment/test/README.md b/script/deployment/test/README.md new file mode 100644 index 00000000..53dbba69 --- /dev/null +++ b/script/deployment/test/README.md @@ -0,0 +1 @@ +**For testing purposes only!** diff --git a/script/deployment/test/child/DeployChildERC1155.s.sol b/script/deployment/test/child/DeployChildERC1155.s.sol new file mode 100644 index 00000000..73e6fed4 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC1155.s.sol @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC1155} from "contracts/child/ChildERC1155.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC1155Deployer is Script { + function deployChildERC1155( + address proxyAdmin, + address rootToken_, + string memory uri_ + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall(ChildERC1155.initialize, (rootToken_, uri_)); + + vm.startBroadcast(); + + ChildERC1155 childERC1155 = new ChildERC1155(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC1155), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC1155); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC1155 is ChildERC1155Deployer { + function run( + address proxyAdmin, + address rootToken_, + string memory uri_ + ) external returns (address logicAddr, address proxyAddr) { + return deployChildERC1155(proxyAdmin, rootToken_, uri_); + } +} diff --git a/script/deployment/test/child/DeployChildERC1155Predicate.s.sol b/script/deployment/test/child/DeployChildERC1155Predicate.s.sol new file mode 100644 index 00000000..a53ea000 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC1155Predicate.s.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC1155Predicate} from "contracts/child/ChildERC1155Predicate.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC1155PredicateDeployer is Script { + function deployChildERC1155Predicate( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC1155Predicate, + address newChildTokenTemplate + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ChildERC1155Predicate.initialize, + (newL2StateSender, newStateReceiver, newRootERC1155Predicate, newChildTokenTemplate) + ); + + vm.startBroadcast(); + + ChildERC1155Predicate childERC1155Predicate = new ChildERC1155Predicate(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC1155Predicate), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC1155Predicate); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC1155Predicate is ChildERC1155PredicateDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC1155Predicate, + address newChildTokenTemplate + ) external returns (address logicAddr, address proxyAddr) { + return + deployChildERC1155Predicate( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newRootERC1155Predicate, + newChildTokenTemplate + ); + } +} diff --git a/script/deployment/test/child/DeployChildERC1155PredicateAccessList.s.sol b/script/deployment/test/child/DeployChildERC1155PredicateAccessList.s.sol new file mode 100644 index 00000000..0e0ced11 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC1155PredicateAccessList.s.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC1155PredicateAccessList} from "contracts/child/ChildERC1155PredicateAccessList.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC1155PredicateAccessListDeployer is Script { + function deployChildERC1155PredicateAccessList( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC1155Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ChildERC1155PredicateAccessList.initialize, + ( + newL2StateSender, + newStateReceiver, + newRootERC1155Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ) + ); + + vm.startBroadcast(); + + ChildERC1155PredicateAccessList childERC1155PredicateAccessList = new ChildERC1155PredicateAccessList(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC1155PredicateAccessList), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC1155PredicateAccessList); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC1155PredicateAccessList is ChildERC1155PredicateAccessListDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC1155Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) external returns (address logicAddr, address proxyAddr) { + return + deployChildERC1155PredicateAccessList( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newRootERC1155Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ); + } +} diff --git a/script/deployment/test/child/DeployChildERC20.s.sol b/script/deployment/test/child/DeployChildERC20.s.sol new file mode 100644 index 00000000..b03ad990 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC20.s.sol @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC20} from "contracts/child/ChildERC20.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC20Deployer is Script { + function deployChildERC20( + address proxyAdmin, + address rootToken_, + string memory name_, + string memory symbol_, + uint8 decimals_ + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall(ChildERC20.initialize, (rootToken_, name_, symbol_, decimals_)); + + vm.startBroadcast(); + + ChildERC20 childERC20 = new ChildERC20(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(childERC20), proxyAdmin, initData); + + vm.stopBroadcast(); + + logicAddr = address(childERC20); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC20 is ChildERC20Deployer { + function run( + address proxyAdmin, + address rootToken_, + string memory name_, + string memory symbol_, + uint8 decimals_ + ) external returns (address logicAddr, address proxyAddr) { + return deployChildERC20(proxyAdmin, rootToken_, name_, symbol_, decimals_); + } +} diff --git a/script/deployment/test/child/DeployChildERC20Predicate.s.sol b/script/deployment/test/child/DeployChildERC20Predicate.s.sol new file mode 100644 index 00000000..35fc3e6e --- /dev/null +++ b/script/deployment/test/child/DeployChildERC20Predicate.s.sol @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC20Predicate} from "contracts/child/ChildERC20Predicate.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC20PredicateDeployer is Script { + function deployChildERC20Predicate( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC20Predicate, + address newChildTokenTemplate, + address newNativeTokenRootAddress + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ChildERC20Predicate.initialize, + ( + newL2StateSender, + newStateReceiver, + newRootERC20Predicate, + newChildTokenTemplate, + newNativeTokenRootAddress + ) + ); + + vm.startBroadcast(); + + ChildERC20Predicate childERC20Predicate = new ChildERC20Predicate(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC20Predicate), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC20Predicate); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC20Predicate is ChildERC20PredicateDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC20Predicate, + address newChildTokenTemplate, + address newNativeTokenRootAddress + ) external returns (address logicAddr, address proxyAddr) { + return + deployChildERC20Predicate( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newRootERC20Predicate, + newChildTokenTemplate, + newNativeTokenRootAddress + ); + } +} diff --git a/script/deployment/test/child/DeployChildERC20PredicateAccessList.s.sol b/script/deployment/test/child/DeployChildERC20PredicateAccessList.s.sol new file mode 100644 index 00000000..37d355b5 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC20PredicateAccessList.s.sol @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC20PredicateAccessList} from "contracts/child/ChildERC20PredicateAccessList.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC20PredicateAccessListDeployer is Script { + function deployChildERC20PredicateAccessList( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC20Predicate, + address newChildTokenTemplate, + address newNativeTokenRootAddress, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ChildERC20PredicateAccessList.initialize, + ( + newL2StateSender, + newStateReceiver, + newRootERC20Predicate, + newChildTokenTemplate, + newNativeTokenRootAddress, + newUseAllowList, + newUseBlockList, + newOwner + ) + ); + + vm.startBroadcast(); + + ChildERC20PredicateAccessList childERC20PredicateAccessList = new ChildERC20PredicateAccessList(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC20PredicateAccessList), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC20PredicateAccessList); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC20PredicateAccessList is ChildERC20PredicateAccessListDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC20Predicate, + address newChildTokenTemplate, + address newNativeTokenRootAddress, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) external returns (address logicAddr, address proxyAddr) { + return + deployChildERC20PredicateAccessList( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newRootERC20Predicate, + newChildTokenTemplate, + newNativeTokenRootAddress, + newUseAllowList, + newUseBlockList, + newOwner + ); + } +} diff --git a/script/deployment/test/child/DeployChildERC721.s.sol b/script/deployment/test/child/DeployChildERC721.s.sol new file mode 100644 index 00000000..c0afb63f --- /dev/null +++ b/script/deployment/test/child/DeployChildERC721.s.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC721} from "contracts/child/ChildERC721.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC721Deployer is Script { + function deployChildERC721( + address proxyAdmin, + address rootToken_, + string memory name_, + string memory symbol_ + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall(ChildERC721.initialize, (rootToken_, name_, symbol_)); + + vm.startBroadcast(); + + ChildERC721 childERC721 = new ChildERC721(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(childERC721), proxyAdmin, initData); + + vm.stopBroadcast(); + + logicAddr = address(childERC721); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC721 is ChildERC721Deployer { + function run( + address proxyAdmin, + address rootToken_, + string memory name_, + string memory symbol_ + ) external returns (address logicAddr, address proxyAddr) { + return deployChildERC721(proxyAdmin, rootToken_, name_, symbol_); + } +} diff --git a/script/deployment/test/child/DeployChildERC721Predicate.s.sol b/script/deployment/test/child/DeployChildERC721Predicate.s.sol new file mode 100644 index 00000000..e4b78052 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC721Predicate.s.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC721Predicate} from "contracts/child/ChildERC721Predicate.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC721PredicateDeployer is Script { + function deployChildERC721Predicate( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC721Predicate, + address newChildTokenTemplate + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ChildERC721Predicate.initialize, + (newL2StateSender, newStateReceiver, newRootERC721Predicate, newChildTokenTemplate) + ); + + vm.startBroadcast(); + + ChildERC721Predicate childERC721Predicate = new ChildERC721Predicate(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC721Predicate), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC721Predicate); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC721Predicate is ChildERC721PredicateDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC721Predicate, + address newChildTokenTemplate + ) external returns (address logicAddr, address proxyAddr) { + return + deployChildERC721Predicate( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newRootERC721Predicate, + newChildTokenTemplate + ); + } +} diff --git a/script/deployment/test/child/DeployChildERC721PredicateAccessList.s.sol b/script/deployment/test/child/DeployChildERC721PredicateAccessList.s.sol new file mode 100644 index 00000000..92b7fe81 --- /dev/null +++ b/script/deployment/test/child/DeployChildERC721PredicateAccessList.s.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ChildERC721PredicateAccessList} from "contracts/child/ChildERC721PredicateAccessList.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ChildERC721PredicateAccessListDeployer is Script { + function deployChildERC721PredicateAccessList( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC721Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ChildERC721PredicateAccessList.initialize, + ( + newL2StateSender, + newStateReceiver, + newRootERC721Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ) + ); + + vm.startBroadcast(); + + ChildERC721PredicateAccessList childERC721PredicateAccessList = new ChildERC721PredicateAccessList(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(childERC721PredicateAccessList), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(childERC721PredicateAccessList); + proxyAddr = address(proxy); + } +} + +contract DeployChildERC721PredicateAccessList is ChildERC721PredicateAccessListDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newRootERC721Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) external returns (address logicAddr, address proxyAddr) { + return + deployChildERC721PredicateAccessList( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newRootERC721Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ); + } +} diff --git a/script/deployment/test/child/DeployEIP1559Burn.s.sol b/script/deployment/test/child/DeployEIP1559Burn.s.sol new file mode 100644 index 00000000..89b50ca4 --- /dev/null +++ b/script/deployment/test/child/DeployEIP1559Burn.s.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {EIP1559Burn, IChildERC20Predicate} from "contracts/child/EIP1559Burn.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract EIP1559BurnDeployer is Script { + function deployEIP1559Burn( + address proxyAdmin, + IChildERC20Predicate newChildERC20Predicate, + address newBurnDestination + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall(EIP1559Burn.initialize, (newChildERC20Predicate, newBurnDestination)); + + vm.startBroadcast(); + + EIP1559Burn eip1559Burn = new EIP1559Burn(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(eip1559Burn), proxyAdmin, initData); + + vm.stopBroadcast(); + + logicAddr = address(eip1559Burn); + proxyAddr = address(proxy); + } +} + +contract DeployEIP1559Burn is EIP1559BurnDeployer { + function run( + address proxyAdmin, + IChildERC20Predicate newChildERC20Predicate, + address newBurnDestination + ) external returns (address logicAddr, address proxyAddr) { + return deployEIP1559Burn(proxyAdmin, newChildERC20Predicate, newBurnDestination); + } +} diff --git a/script/deployment/test/child/DeployL2StateSender.s.sol b/script/deployment/test/child/DeployL2StateSender.s.sol new file mode 100644 index 00000000..a4b00d61 --- /dev/null +++ b/script/deployment/test/child/DeployL2StateSender.s.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {L2StateSender} from "contracts/child/L2StateSender.sol"; + +abstract contract L2StateSenderDeployer is Script { + function deployL2StateSender() internal returns (address contractAddr) { + vm.startBroadcast(); + + L2StateSender l2StateSender = new L2StateSender(); + + vm.stopBroadcast(); + + contractAddr = address(l2StateSender); + } +} + +contract DeployL2StateSender is L2StateSenderDeployer { + function run() external returns (address contractAddr) { + return deployL2StateSender(); + } +} diff --git a/script/deployment/test/child/DeployNativeERC20.s.sol b/script/deployment/test/child/DeployNativeERC20.s.sol new file mode 100644 index 00000000..b147ab4b --- /dev/null +++ b/script/deployment/test/child/DeployNativeERC20.s.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {NativeERC20} from "contracts/child/NativeERC20.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract NativeERC20Deployer is Script { + function deployNativeERC20( + address proxyAdmin, + address predicate_, + address rootToken_, + string memory name_, + string memory symbol_, + uint8 decimals_, + uint256 tokenSupply_ + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + NativeERC20.initialize, + (predicate_, rootToken_, name_, symbol_, decimals_, tokenSupply_) + ); + + vm.startBroadcast(); + + NativeERC20 nativeERC20 = new NativeERC20(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(nativeERC20), proxyAdmin, initData); + + vm.stopBroadcast(); + + logicAddr = address(nativeERC20); + proxyAddr = address(proxy); + } +} + +contract DeployNativeERC20 is NativeERC20Deployer { + function run( + address proxyAdmin, + address predicate_, + address rootToken_, + string memory name_, + string memory symbol_, + uint8 decimals_, + uint256 tokenSupply_ + ) external returns (address logicAddr, address proxyAddr) { + return deployNativeERC20(proxyAdmin, predicate_, rootToken_, name_, symbol_, decimals_, tokenSupply_); + } +} diff --git a/script/deployment/test/child/DeployNativeERC20Mintable.s.sol b/script/deployment/test/child/DeployNativeERC20Mintable.s.sol new file mode 100644 index 00000000..f5cadf1d --- /dev/null +++ b/script/deployment/test/child/DeployNativeERC20Mintable.s.sol @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {NativeERC20Mintable} from "contracts/child/NativeERC20Mintable.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract NativeERC20MintableDeployer is Script { + function deployNativeERC20Mintable( + address proxyAdmin, + address predicate_, + address owner_, + address rootToken_, + string memory name_, + string memory symbol_, + uint8 decimals_, + uint256 tokenSupply_ + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + NativeERC20Mintable.initialize, + (predicate_, owner_, rootToken_, name_, symbol_, decimals_, tokenSupply_) + ); + + vm.startBroadcast(); + + NativeERC20Mintable nativeERC20Mintable = new NativeERC20Mintable(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(nativeERC20Mintable), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(nativeERC20Mintable); + proxyAddr = address(proxy); + } +} + +contract DeployNativeERC20Mintable is NativeERC20MintableDeployer { + function run( + address proxyAdmin, + address predicate_, + address owner_, + address rootToken_, + string memory name_, + string memory symbol_, + uint8 decimals_, + uint256 tokenSupply_ + ) external returns (address logicAddr, address proxyAddr) { + return + deployNativeERC20Mintable( + proxyAdmin, + predicate_, + owner_, + rootToken_, + name_, + symbol_, + decimals_, + tokenSupply_ + ); + } +} diff --git a/script/deployment/test/child/DeployRootMintableERC1155Predicate.s.sol b/script/deployment/test/child/DeployRootMintableERC1155Predicate.s.sol new file mode 100644 index 00000000..eb859cf9 --- /dev/null +++ b/script/deployment/test/child/DeployRootMintableERC1155Predicate.s.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RootMintableERC1155Predicate} from "contracts/child/RootMintableERC1155Predicate.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RootMintableERC1155PredicateDeployer is Script { + function deployRootMintableERC1155Predicate( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC1155Predicate, + address newChildTokenTemplate + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RootMintableERC1155Predicate.initialize, + (newL2StateSender, newStateReceiver, newChildERC1155Predicate, newChildTokenTemplate) + ); + + vm.startBroadcast(); + + RootMintableERC1155Predicate rootMintableERC1155Predicate = new RootMintableERC1155Predicate(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(rootMintableERC1155Predicate), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(rootMintableERC1155Predicate); + proxyAddr = address(proxy); + } +} + +contract DeployRootMintableERC1155Predicate is RootMintableERC1155PredicateDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC1155Predicate, + address newChildTokenTemplate + ) external returns (address logicAddr, address proxyAddr) { + return + deployRootMintableERC1155Predicate( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newChildERC1155Predicate, + newChildTokenTemplate + ); + } +} diff --git a/script/deployment/test/child/DeployRootMintableERC1155PredicateAccessList.s.sol b/script/deployment/test/child/DeployRootMintableERC1155PredicateAccessList.s.sol new file mode 100644 index 00000000..b31a8c18 --- /dev/null +++ b/script/deployment/test/child/DeployRootMintableERC1155PredicateAccessList.s.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RootMintableERC1155PredicateAccessList} from "contracts/child/RootMintableERC1155PredicateAccessList.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RootMintableERC1155PredicateAccessListDeployer is Script { + function deployRootMintableERC1155PredicateAccessList( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC1155Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RootMintableERC1155PredicateAccessList.initialize, + ( + newL2StateSender, + newStateReceiver, + newChildERC1155Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ) + ); + + vm.startBroadcast(); + + RootMintableERC1155PredicateAccessList rootMintableERC1155PredicateAccessList = new RootMintableERC1155PredicateAccessList(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(rootMintableERC1155PredicateAccessList), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(rootMintableERC1155PredicateAccessList); + proxyAddr = address(proxy); + } +} + +contract DeployRootMintableERC1155PredicateAccessList is RootMintableERC1155PredicateAccessListDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC1155Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) external returns (address logicAddr, address proxyAddr) { + return + deployRootMintableERC1155PredicateAccessList( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newChildERC1155Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ); + } +} diff --git a/script/deployment/test/child/DeployRootMintableERC20Predicate.s.sol b/script/deployment/test/child/DeployRootMintableERC20Predicate.s.sol new file mode 100644 index 00000000..791ddf68 --- /dev/null +++ b/script/deployment/test/child/DeployRootMintableERC20Predicate.s.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RootMintableERC20Predicate} from "contracts/child/RootMintableERC20Predicate.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RootMintableERC20PredicateDeployer is Script { + function deployRootMintableERC20Predicate( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC20Predicate, + address newChildTokenTemplate + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RootMintableERC20Predicate.initialize, + (newL2StateSender, newStateReceiver, newChildERC20Predicate, newChildTokenTemplate) + ); + + vm.startBroadcast(); + + RootMintableERC20Predicate rootMintableERC20Predicate = new RootMintableERC20Predicate(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(rootMintableERC20Predicate), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(rootMintableERC20Predicate); + proxyAddr = address(proxy); + } +} + +contract DeployRootMintableERC20Predicate is RootMintableERC20PredicateDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC20Predicate, + address newChildTokenTemplate + ) external returns (address logicAddr, address proxyAddr) { + return + deployRootMintableERC20Predicate( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newChildERC20Predicate, + newChildTokenTemplate + ); + } +} diff --git a/script/deployment/test/child/DeployRootMintableERC20PredicateAccessList.s.sol b/script/deployment/test/child/DeployRootMintableERC20PredicateAccessList.s.sol new file mode 100644 index 00000000..99e7abd2 --- /dev/null +++ b/script/deployment/test/child/DeployRootMintableERC20PredicateAccessList.s.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RootMintableERC20PredicateAccessList} from "contracts/child/RootMintableERC20PredicateAccessList.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RootMintableERC20PredicateAccessListDeployer is Script { + function deployRootMintableERC20PredicateAccessList( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC20Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RootMintableERC20PredicateAccessList.initialize, + ( + newL2StateSender, + newStateReceiver, + newChildERC20Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ) + ); + + vm.startBroadcast(); + + RootMintableERC20PredicateAccessList rootMintableERC20PredicateAccessList = new RootMintableERC20PredicateAccessList(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(rootMintableERC20PredicateAccessList), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(rootMintableERC20PredicateAccessList); + proxyAddr = address(proxy); + } +} + +contract DeployRootMintableERC20PredicateAccessList is RootMintableERC20PredicateAccessListDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC20Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) external returns (address logicAddr, address proxyAddr) { + return + deployRootMintableERC20PredicateAccessList( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newChildERC20Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ); + } +} diff --git a/script/deployment/test/child/DeployRootMintableERC721Predicate.s.sol b/script/deployment/test/child/DeployRootMintableERC721Predicate.s.sol new file mode 100644 index 00000000..0150ed65 --- /dev/null +++ b/script/deployment/test/child/DeployRootMintableERC721Predicate.s.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RootMintableERC721Predicate} from "contracts/child/RootMintableERC721Predicate.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RootMintableERC721PredicateDeployer is Script { + function deployRootMintableERC721Predicate( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC721Predicate, + address newChildTokenTemplate + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RootMintableERC721Predicate.initialize, + (newL2StateSender, newStateReceiver, newChildERC721Predicate, newChildTokenTemplate) + ); + + vm.startBroadcast(); + + RootMintableERC721Predicate rootMintableERC721Predicate = new RootMintableERC721Predicate(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(rootMintableERC721Predicate), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(rootMintableERC721Predicate); + proxyAddr = address(proxy); + } +} + +contract DeployRootMintableERC721Predicate is RootMintableERC721PredicateDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC721Predicate, + address newChildTokenTemplate + ) external returns (address logicAddr, address proxyAddr) { + return + deployRootMintableERC721Predicate( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newChildERC721Predicate, + newChildTokenTemplate + ); + } +} diff --git a/script/deployment/test/child/DeployRootMintableERC721PredicateAccessList.s.sol b/script/deployment/test/child/DeployRootMintableERC721PredicateAccessList.s.sol new file mode 100644 index 00000000..fc96ab9c --- /dev/null +++ b/script/deployment/test/child/DeployRootMintableERC721PredicateAccessList.s.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RootMintableERC721PredicateAccessList} from "contracts/child/RootMintableERC721PredicateAccessList.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RootMintableERC721PredicateAccessListDeployer is Script { + function deployRootMintableERC721PredicateAccessList( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC721Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RootMintableERC721PredicateAccessList.initialize, + ( + newL2StateSender, + newStateReceiver, + newChildERC721Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ) + ); + + vm.startBroadcast(); + + RootMintableERC721PredicateAccessList rootMintableERC721PredicateAccessList = new RootMintableERC721PredicateAccessList(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(rootMintableERC721PredicateAccessList), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(rootMintableERC721PredicateAccessList); + proxyAddr = address(proxy); + } +} + +contract DeployRootMintableERC721PredicateAccessList is RootMintableERC721PredicateAccessListDeployer { + function run( + address proxyAdmin, + address newL2StateSender, + address newStateReceiver, + address newChildERC721Predicate, + address newChildTokenTemplate, + bool newUseAllowList, + bool newUseBlockList, + address newOwner + ) external returns (address logicAddr, address proxyAddr) { + return + deployRootMintableERC721PredicateAccessList( + proxyAdmin, + newL2StateSender, + newStateReceiver, + newChildERC721Predicate, + newChildTokenTemplate, + newUseAllowList, + newUseBlockList, + newOwner + ); + } +} diff --git a/script/deployment/test/child/DeployStateReceiver.s.sol b/script/deployment/test/child/DeployStateReceiver.s.sol new file mode 100644 index 00000000..c2699f5f --- /dev/null +++ b/script/deployment/test/child/DeployStateReceiver.s.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {StateReceiver} from "contracts/child/StateReceiver.sol"; + +abstract contract StateReceiverDeployer is Script { + function deployStateReceiver() internal returns (address contractAddr) { + vm.startBroadcast(); + + StateReceiver stateReceiver = new StateReceiver(); + + vm.stopBroadcast(); + + contractAddr = address(stateReceiver); + } +} + +contract DeployStateReceiver is StateReceiverDeployer { + function run() external returns (address contractAddr) { + return deployStateReceiver(); + } +} diff --git a/script/deployment/test/child/DeploySystem.s.sol b/script/deployment/test/child/DeploySystem.s.sol new file mode 100644 index 00000000..54a831b9 --- /dev/null +++ b/script/deployment/test/child/DeploySystem.s.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {System} from "contracts/child/System.sol"; + +abstract contract SystemDeployer is Script { + function deploySystem() internal returns (address contractAddr) { + vm.startBroadcast(); + + System system = new System(); + + vm.stopBroadcast(); + + contractAddr = address(system); + } +} + +contract DeploySystem is SystemDeployer { + function run() external returns (address contractAddr) { + return deploySystem(); + } +} diff --git a/script/deployment/test/child/validator/DeployRewardPool.s.sol b/script/deployment/test/child/validator/DeployRewardPool.s.sol new file mode 100644 index 00000000..40d2310c --- /dev/null +++ b/script/deployment/test/child/validator/DeployRewardPool.s.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {RewardPool} from "contracts/child/validator/RewardPool.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract RewardPoolDeployer is Script { + function deployRewardPool( + address proxyAdmin, + address newRewardToken, + address newRewardWallet, + address newValidatorSet, + uint256 newBaseReward + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + RewardPool.initialize, + (newRewardToken, newRewardWallet, newValidatorSet, newBaseReward) + ); + + vm.startBroadcast(); + + RewardPool rewardPool = new RewardPool(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(rewardPool), proxyAdmin, initData); + + vm.stopBroadcast(); + + logicAddr = address(rewardPool); + proxyAddr = address(proxy); + } +} + +contract DeployRewardPool is RewardPoolDeployer { + function run( + address proxyAdmin, + address newRewardToken, + address newRewardWallet, + address newValidatorSet, + uint256 newBaseReward + ) external returns (address logicAddr, address proxyAddr) { + return deployRewardPool(proxyAdmin, newRewardToken, newRewardWallet, newValidatorSet, newBaseReward); + } +} diff --git a/script/deployment/test/child/validator/DeployValidatorSet.s.sol b/script/deployment/test/child/validator/DeployValidatorSet.s.sol new file mode 100644 index 00000000..e8049d12 --- /dev/null +++ b/script/deployment/test/child/validator/DeployValidatorSet.s.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Script.sol"; + +import {ValidatorSet, ValidatorInit} from "contracts/child/validator/ValidatorSet.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +abstract contract ValidatorSetDeployer is Script { + function deployValidatorSet( + address proxyAdmin, + address newStateSender, + address newStateReceiver, + address newRootChainManager, + uint256 newEpochSize, + ValidatorInit[] memory initialValidators + ) internal returns (address logicAddr, address proxyAddr) { + bytes memory initData = abi.encodeCall( + ValidatorSet.initialize, + (newStateSender, newStateReceiver, newRootChainManager, newEpochSize, initialValidators) + ); + + vm.startBroadcast(); + + ValidatorSet validatorSet = new ValidatorSet(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(validatorSet), + proxyAdmin, + initData + ); + + vm.stopBroadcast(); + + logicAddr = address(validatorSet); + proxyAddr = address(proxy); + } +} + +contract DeployValidatorSet is ValidatorSetDeployer { + function run( + address proxyAdmin, + address newStateSender, + address newStateReceiver, + address newRootChainManager, + uint256 newEpochSize, + ValidatorInit[] memory initialValidators + ) external returns (address logicAddr, address proxyAddr) { + return + deployValidatorSet( + proxyAdmin, + newStateSender, + newStateReceiver, + newRootChainManager, + newEpochSize, + initialValidators + ); + } +} diff --git a/script/deployment/test/childContractsConfig.json b/script/deployment/test/childContractsConfig.json new file mode 100644 index 00000000..67702895 --- /dev/null +++ b/script/deployment/test/childContractsConfig.json @@ -0,0 +1,141 @@ +{ + "ProxyAdmin": { + "proxyAdminOwner": "" + }, + + "NetworkParams": { + "initParams": "" + }, + + "ValidatorSet": { + "newStateSender": "", + "newRootChainManager": "", + "newEpochSize": "", + "initialValidators": "" + }, + + "RewardPool": { + "newRewardToken": "", + "newRewardWallet": "", + "newBaseReward": "" + }, + + "ChildERC20": { + "rootToken_": "", + "name_": "", + "symbol_": "", + "decimals_": "" + }, + + "ChildERC20Predicate": { + "newRootERC20Predicate": "", + "newChildTokenTemplate": "", + "newNativeTokenRootAddress": "" + }, + + "ChildERC20PredicateAccessList": { + "newRootERC20Predicate": "", + "newChildTokenTemplate": "", + "newNativeTokenRootAddress": "", + "newUseAllowList": "", + "newUseBlockList": "", + "newOwner": "" + }, + + "ChildERC721": { + "rootToken_": "", + "name_": "", + "symbol_": "" + }, + + "ChildERC721Predicate": { + "newRootERC721Predicate": "", + "newChildTokenTemplate": "" + }, + + "ChildERC721PredicateAccessList": { + "newRootERC721Predicate": "", + "newChildTokenTemplate": "", + "newUseAllowList": "", + "newUseBlockList": "", + "newOwner": "" + }, + + "ChildERC1155": { + "rootToken_": "", + "uri_": "" + }, + + "ChildERC1155Predicate": { + "newRootERC1155Predicate": "", + "newChildTokenTemplate": "" + }, + + "ChildERC1155PredicateAccessList": { + "newRootERC1155Predicate": "", + "newChildTokenTemplate": "", + "newUseAllowList": "", + "newUseBlockList": "", + "newOwner": "" + }, + + "EIP1559Burn": { + "newBurnDestination": "" + }, + + "ForkParams": { + "newOwner": "" + }, + + "NativeERC20": { + "predicate_": "", + "rootToken_": "", + "name_": "", + "symbol_": "", + "decimals_": "", + "tokenSupply_": "" + }, + + "NativeERC20Mintable": { + "predicate_": "", + "owner_": "", + "rootToken_": "", + "name_": "", + "symbol_": "", + "decimals_": "", + "tokenSupply_": "" + }, + + "RootMintableERC20Predicate": { + "newChildTokenTemplate": "" + }, + + "RootMintableERC20PredicateAccessList": { + "newChildTokenTemplate": "", + "newUseAllowList": "", + "newUseBlockList": "", + "newOwner": "" + }, + + "RootMintableERC721Predicate": { + "newChildTokenTemplate": "" + }, + + "RootMintableERC721PredicateAccessList": { + "newRootERC72newChildTokenTemplate1Predicate": "", + "newUseAllowList": "", + "newUseBlockList": "", + "newOwner": "" + }, + + "RootMintableERC1155Predicate": { + "newChildTokenTemplate": "" + }, + + "RootMintableERC1155PredicateAccessList": { + "newChildTokenTemplate": "", + "newUseAllowList": "", + "newUseBlockList": "", + "newOwner": "" + } +} diff --git a/test/child/ChildERC1155.test.ts b/test/child/ChildERC1155.test.ts index 671d6d6f..e88f5469 100644 --- a/test/child/ChildERC1155.test.ts +++ b/test/child/ChildERC1155.test.ts @@ -20,14 +20,18 @@ describe("ChildERC1155", () => { const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); childERC1155 = await ChildERC1155.deploy(); - await childERC1155.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC1155.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC1155 = ChildERC1155.attach(_proxy.address); + const ChildERC1155Predicate: ChildERC1155Predicate__factory = await ethers.getContractFactory( "ChildERC1155Predicate" ); childERC1155Predicate = await ChildERC1155Predicate.deploy(); - await childERC1155Predicate.deployed(); impersonateAccount(childERC1155Predicate.address); @@ -195,20 +199,20 @@ describe("ChildERC1155", () => { ); await expect(mintTx) .to.emit(predicateChildERC1155, "TransferSingle") - .withArgs("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", ethers.constants.AddressZero, accounts[0].address, 0, 1); + .withArgs("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", ethers.constants.AddressZero, accounts[0].address, 0, 1); await expect(mintTx) .to.emit(predicateChildERC1155, "TransferSingle") - .withArgs("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", ethers.constants.AddressZero, accounts[0].address, 1, 2); + .withArgs("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", ethers.constants.AddressZero, accounts[0].address, 1, 2); await expect(mintTx) .to.emit(predicateChildERC1155, "TransferSingle") - .withArgs("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", ethers.constants.AddressZero, accounts[1].address, 2, 3); + .withArgs("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", ethers.constants.AddressZero, accounts[1].address, 2, 3); }); it("batch burn tokens success", async () => { const burnTx = await predicateChildERC1155.burnBatch(accounts[0].address, [0, 1], [1, 2]); await expect(burnTx) .to.emit(predicateChildERC1155, "TransferBatch") .withArgs( - "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", accounts[0].address, ethers.constants.AddressZero, [0, 1], diff --git a/test/child/ChildERC1155Predicate.test.ts b/test/child/ChildERC1155Predicate.test.ts index c9c1f822..bc0b082d 100644 --- a/test/child/ChildERC1155Predicate.test.ts +++ b/test/child/ChildERC1155Predicate.test.ts @@ -53,9 +53,14 @@ describe("ChildERC1155Predicate", () => { "ChildERC1155Predicate" ); childERC1155Predicate = await ChildERC1155Predicate.deploy(); - await childERC1155Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC1155Predicate = ChildERC1155Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); @@ -405,7 +410,13 @@ describe("ChildERC1155Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256", "uint256"], @@ -439,7 +450,13 @@ describe("ChildERC1155Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); await expect(stateReceiverChildERC1155Predicate.withdraw(childToken.address, 0, 1)).to.be.revertedWith( "ChildERC1155Predicate: UNMAPPED_TOKEN" diff --git a/test/child/ChildERC20.test.ts b/test/child/ChildERC20.test.ts index be1ac4c4..97919f27 100644 --- a/test/child/ChildERC20.test.ts +++ b/test/child/ChildERC20.test.ts @@ -21,14 +21,22 @@ describe("ChildERC20", () => { const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); childERC20 = await ChildERC20.deploy(); - await childERC20.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC20.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC20 = ChildERC20.attach(_proxy.address); + const ChildERC20Predicate: ChildERC20Predicate__factory = await ethers.getContractFactory("ChildERC20Predicate"); childERC20Predicate = await ChildERC20Predicate.deploy(); - await childERC20Predicate.deployed(); + const _proxy2 = await TransparentUpgradeableProxy.deploy(childERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + childERC20Predicate = ChildERC20Predicate.attach(_proxy2.address); + impersonateAccount(childERC20Predicate.address); setBalance(childERC20Predicate.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/child/ChildERC20Predicate.test.ts b/test/child/ChildERC20Predicate.test.ts index 9961cd1b..ca9530ac 100644 --- a/test/child/ChildERC20Predicate.test.ts +++ b/test/child/ChildERC20Predicate.test.ts @@ -57,9 +57,14 @@ describe("ChildERC20Predicate", () => { const ChildERC20Predicate: ChildERC20Predicate__factory = await ethers.getContractFactory("ChildERC20Predicate"); childERC20Predicate = await ChildERC20Predicate.deploy(); - await childERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC20Predicate = ChildERC20Predicate.attach(_proxy.address); + const NativeERC20: NativeERC20__factory = await ethers.getContractFactory("NativeERC20"); const tempNativeERC20 = await NativeERC20.deploy(); @@ -373,7 +378,13 @@ describe("ChildERC20Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); const stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "address", "uint256"], @@ -393,7 +404,13 @@ describe("ChildERC20Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); await expect(stateReceiverChildERC20Predicate.withdraw(childToken.address, 1)).to.be.revertedWith( "ChildERC20Predicate: UNMAPPED_TOKEN" diff --git a/test/child/ChildERC721.test.ts b/test/child/ChildERC721.test.ts index 13bcc705..3fade871 100644 --- a/test/child/ChildERC721.test.ts +++ b/test/child/ChildERC721.test.ts @@ -22,14 +22,22 @@ describe("ChildERC721", () => { const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); childERC721 = await ChildERC721.deploy(); - await childERC721.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC721.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC721 = ChildERC721.attach(_proxy.address); + const ChildERC721Predicate: ChildERC721Predicate__factory = await ethers.getContractFactory("ChildERC721Predicate"); childERC721Predicate = await ChildERC721Predicate.deploy(); - await childERC721Predicate.deployed(); + const _proxy2 = await TransparentUpgradeableProxy.deploy(childERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + childERC721Predicate = ChildERC721Predicate.attach(_proxy2.address); + impersonateAccount(childERC721Predicate.address); setBalance(childERC721Predicate.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/child/ChildERC721Predicate.test.ts b/test/child/ChildERC721Predicate.test.ts index 89c2cc51..4bbd3e2d 100644 --- a/test/child/ChildERC721Predicate.test.ts +++ b/test/child/ChildERC721Predicate.test.ts @@ -55,9 +55,14 @@ describe("ChildERC721Predicate", () => { const ChildERC721Predicate: ChildERC721Predicate__factory = await ethers.getContractFactory("ChildERC721Predicate"); childERC721Predicate = await ChildERC721Predicate.deploy(); - await childERC721Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC721Predicate = ChildERC721Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); @@ -400,7 +405,13 @@ describe("ChildERC721Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256"], @@ -426,7 +437,13 @@ describe("ChildERC721Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); await expect(stateReceiverChildERC721Predicate.withdraw(childToken.address, 0)).to.be.revertedWith( "ChildERC721Predicate: UNMAPPED_TOKEN" diff --git a/test/child/EIP1559Burn.test.ts b/test/child/EIP1559Burn.test.ts index 56347e43..65cbe882 100644 --- a/test/child/EIP1559Burn.test.ts +++ b/test/child/EIP1559Burn.test.ts @@ -58,9 +58,14 @@ describe("EIP1559Burn", () => { const ChildERC20Predicate: ChildERC20Predicate__factory = await ethers.getContractFactory("ChildERC20Predicate"); childERC20Predicate = await ChildERC20Predicate.deploy(); - await childERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC20Predicate = ChildERC20Predicate.attach(_proxy.address); + const NativeERC20: NativeERC20__factory = await ethers.getContractFactory("NativeERC20"); const tempNativeERC20 = await NativeERC20.deploy(); @@ -100,9 +105,12 @@ describe("EIP1559Burn", () => { const EIP1559Burn: EIP1559Burn__factory = await ethers.getContractFactory("EIP1559Burn"); eip1559Burn = await EIP1559Burn.deploy(); - await eip1559Burn.deployed(); + const _proxy2 = await TransparentUpgradeableProxy.deploy(eip1559Burn.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + eip1559Burn = EIP1559Burn.attach(_proxy2.address); + totalSupply = 0; }); diff --git a/test/child/ForkParams.test.ts b/test/child/ForkParams.test.ts deleted file mode 100644 index 86948b00..00000000 --- a/test/child/ForkParams.test.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { impersonateAccount, mine, stopImpersonatingAccount } from "@nomicfoundation/hardhat-network-helpers"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { expect } from "chai"; -import { BigNumber } from "ethers"; -import { ethers } from "hardhat"; -import { ForkParams } from "../../typechain-types"; - -describe("ForkParams", () => { - let forkParams: ForkParams, accounts: SignerWithAddress[], futureBlockNumber: number; - before(async () => { - accounts = await ethers.getSigners(); - const forkParamsFactory = await ethers.getContractFactory("ForkParams"); - forkParams = (await forkParamsFactory.deploy()) as ForkParams; - - await forkParams.deployed(); - await forkParams.initialize(accounts[0].address); - }); - - it("validate deployment", async () => { - expect(await forkParams.owner()).to.equal(accounts[0].address); - }); - - it("should throw error on reinitialization", async () => { - await expect(forkParams.initialize(accounts[1].address)).to.be.revertedWith( - "Initializable: contract is already initialized" - ); - }); - - it("add new feature from wrong account", async () => { - await impersonateAccount(accounts[1].address); - const newForkParams = forkParams.connect(accounts[1]); - await expect(newForkParams.addNewFeature(1, "FEATURE")).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("add feature for wrong block", async () => { - await expect(forkParams.addNewFeature(0, "FEATURE")).to.be.revertedWith("ForkParams: INVALID_BLOCK"); - }); - - it("add feature success", async () => { - futureBlockNumber = (await ethers.provider.getBlockNumber()) + Math.floor(Math.random() * 10 + 10); - await forkParams.addNewFeature(futureBlockNumber, "FEATURE"); - expect( - await forkParams.featureToBlockNumber( - ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(["string"], ["FEATURE"])) - ) - ).to.equal(BigNumber.from(futureBlockNumber)); - }); - - it("add feature fail, feature exists", async () => { - await expect(forkParams.addNewFeature(futureBlockNumber, "FEATURE")).to.be.revertedWith( - "ForkParams: FEATURE_EXISTS" - ); - }); - - it("fetch feature revert on non-existent feature", async () => { - await expect(forkParams.isFeatureActivated("FEATURE_1")).to.be.revertedWith("ForkParams: NONEXISTENT_FEATURE"); - }); - - it("fetch feature success before activation", async () => { - expect(await forkParams.isFeatureActivated("FEATURE")).to.be.false; - }); - - it("reschedule feature fail, old block", async () => { - await expect(forkParams.updateFeatureBlock(3, "FEATURE")).to.be.revertedWith("ForkParams: INVALID_BLOCK"); - }); - - it("reschedule feature fail, feature does not exist", async () => { - await expect(forkParams.updateFeatureBlock(futureBlockNumber, "FEATURE_1")).to.be.revertedWith( - "ForkParams: NONEXISTENT_FEATURE" - ); - }); - - it("reschedule feature success", async () => { - futureBlockNumber += Math.floor(Math.random() * 5 + 1); - await forkParams.updateFeatureBlock(futureBlockNumber, "FEATURE"); - expect( - await forkParams.featureToBlockNumber( - ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(["string"], ["FEATURE"])) - ) - ).to.equal(BigNumber.from(futureBlockNumber)); - }); - - it("fetch feature success after activation", async () => { - mine(futureBlockNumber - (await ethers.provider.getBlockNumber())); - expect(await forkParams.isFeatureActivated("FEATURE")).to.be.true; - }); - - it("reschedule feature fail, feature activated", async () => { - await expect(forkParams.updateFeatureBlock(futureBlockNumber, "FEATURE")).to.be.revertedWith( - "ForkParams: INVALID_BLOCK" - ); - }); -}); diff --git a/test/child/NetworkParams.test.ts b/test/child/NetworkParams.test.ts deleted file mode 100644 index 13fcf937..00000000 --- a/test/child/NetworkParams.test.ts +++ /dev/null @@ -1,337 +0,0 @@ -import { impersonateAccount, stopImpersonatingAccount, setBalance } from "@nomicfoundation/hardhat-network-helpers"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { expect } from "chai"; -import { BigNumber } from "ethers"; -import { ethers } from "hardhat"; -import { NetworkParams } from "../../typechain-types"; - -describe("NetworkParams", () => { - let initParams: NetworkParams.InitParamsStruct; - let networkParams: NetworkParams, accounts: SignerWithAddress[]; - before(async () => { - accounts = await ethers.getSigners(); - - initParams = { - newOwner: ethers.constants.AddressZero, - newCheckpointBlockInterval: 0, - newEpochSize: 0, - newEpochReward: 0, - newSprintSize: 0, - newMinValidatorSetSize: 0, - newMaxValidatorSetSize: 0, - newWithdrawalWaitPeriod: 0, - newBlockTime: 0, - newBlockTimeDrift: 0, - newVotingDelay: 0, - newVotingPeriod: 0, - newProposalThreshold: 0, - newBaseFeeChangeDenom: 0, - }; - }); - - it("fail initialization, invalid input", async () => { - const networkParamsFactory = await ethers.getContractFactory("NetworkParams"); - networkParams = (await networkParamsFactory.deploy()) as NetworkParams; - await networkParams.deployed(); - await expect(networkParams.initialize(initParams)).to.be.revertedWith("NetworkParams: INVALID_INPUT"); - }); - - it("initialization success", async () => { - initParams.newOwner = accounts[0].address; - initParams.newCheckpointBlockInterval = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newEpochSize = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newEpochReward = ethers.utils.parseUnits(String(Math.floor(Math.random() * 20 + 1))); - initParams.newSprintSize = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newMinValidatorSetSize = Math.floor(Math.random() * 20 + 5); - initParams.newMaxValidatorSetSize = Math.floor(Math.random() * 20 + 5); - initParams.newWithdrawalWaitPeriod = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newBlockTime = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newBlockTimeDrift = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newVotingDelay = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newVotingPeriod = 2 ** Math.floor(Math.random() * 5 + 10); - initParams.newProposalThreshold = Math.floor(Math.random() * 100 + 1); - initParams.newBaseFeeChangeDenom = ethers.utils.parseUnits(String(Math.floor(Math.random() * 20 + 1))); - - await networkParams.initialize(initParams); - - expect(await networkParams.owner()).to.equal(initParams.newOwner); - expect(await networkParams.checkpointBlockInterval()).to.equal(initParams.newCheckpointBlockInterval); - expect(await networkParams.epochSize()).to.equal(initParams.newEpochSize); - expect(await networkParams.epochReward()).to.equal(initParams.newEpochReward); - expect(await networkParams.sprintSize()).to.equal(initParams.newSprintSize); - expect(await networkParams.minValidatorSetSize()).to.equal(initParams.newMinValidatorSetSize); - expect(await networkParams.maxValidatorSetSize()).to.equal(initParams.newMaxValidatorSetSize); - expect(await networkParams.withdrawalWaitPeriod()).to.equal(initParams.newWithdrawalWaitPeriod); - expect(await networkParams.blockTime()).to.equal(initParams.newBlockTime); - expect(await networkParams.blockTimeDrift()).to.equal(initParams.newBlockTimeDrift); - expect(await networkParams.votingDelay()).to.equal(initParams.newVotingDelay); - expect(await networkParams.votingPeriod()).to.equal(initParams.newVotingPeriod); - expect(await networkParams.proposalThreshold()).to.equal(initParams.newProposalThreshold); - expect(await networkParams.baseFeeChangeDenom()).to.equal(initParams.newBaseFeeChangeDenom); - }); - - it("should throw error on reinitialization", async () => { - await expect(networkParams.initialize(initParams)).to.be.revertedWith( - "Initializable: contract is already initialized" - ); - }); - - it("set new checkpoint block interval fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewCheckpointBlockInterval(1)).to.be.revertedWith( - "Ownable: caller is not the owner" - ); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new checkpoint block interval fail: invalid input", async () => { - await expect(networkParams.setNewCheckpointBlockInterval(0)).to.be.revertedWith( - "NetworkParams: INVALID_CHECKPOINT_INTERVAL" - ); - }); - - it("set new checkpoint block interval success", async () => { - initParams.newCheckpointBlockInterval = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewCheckpointBlockInterval(initParams.newCheckpointBlockInterval); - - expect(await networkParams.checkpointBlockInterval()).to.equal(initParams.newCheckpointBlockInterval); - }); - - it("set new epoch size fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewEpochSize(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new epoch size fail: invalid input", async () => { - await expect(networkParams.setNewEpochSize(0)).to.be.revertedWith("NetworkParams: INVALID_EPOCH_SIZE"); - }); - - it("set new epoch size success", async () => { - initParams.newEpochSize = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewEpochSize(initParams.newEpochSize); - - expect(await networkParams.epochSize()).to.equal(initParams.newEpochSize); - }); - - it("set new epoch reward fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewEpochReward(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new epoch reward success", async () => { - initParams.newEpochReward = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewEpochReward(initParams.newEpochReward); - - expect(await networkParams.epochReward()).to.equal(initParams.newEpochReward); - }); - - it("set new sprint size fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - await expect(newNetworkParams.setNewSprintSize(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new sprint size fail: invalid input", async () => { - await expect(networkParams.setNewSprintSize(0)).to.be.revertedWith("NetworkParams: INVALID_SPRINT_SIZE"); - }); - - it("set new sprint size success", async () => { - initParams.newSprintSize = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewSprintSize(initParams.newSprintSize); - - expect(await networkParams.sprintSize()).to.equal(initParams.newSprintSize); - }); - - it("set new min validator set size fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewMinValidatorSetSize(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new min validator set size fail: invalid input", async () => { - await expect(networkParams.setNewMinValidatorSetSize(0)).to.be.revertedWith( - "NetworkParams: INVALID_MIN_VALIDATOR_SET_SIZE" - ); - }); - - it("set new min validator set size success", async () => { - initParams.newMinValidatorSetSize = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewMinValidatorSetSize(initParams.newMinValidatorSetSize); - - expect(await networkParams.minValidatorSetSize()).to.equal(initParams.newMinValidatorSetSize); - }); - - it("set new max validator set size fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewMaxValidatorSetSize(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new max validator set size fail: invalid input", async () => { - await expect(networkParams.setNewMaxValidatorSetSize(0)).to.be.revertedWith( - "NetworkParams: INVALID_MAX_VALIDATOR_SET_SIZE" - ); - }); - - it("set new max validator set size success", async () => { - initParams.newMaxValidatorSetSize = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewMaxValidatorSetSize(initParams.newMaxValidatorSetSize); - - expect(await networkParams.maxValidatorSetSize()).to.equal(initParams.newMaxValidatorSetSize); - }); - - it("set new withdrawal wait period fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewWithdrawalWaitPeriod(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new withdrawal wait period fail: invalid input", async () => { - await expect(networkParams.setNewWithdrawalWaitPeriod(0)).to.be.revertedWith( - "NetworkParams: INVALID_WITHDRAWAL_WAIT_PERIOD" - ); - }); - - it("set new withdrawal wait period success", async () => { - initParams.newWithdrawalWaitPeriod = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewWithdrawalWaitPeriod(initParams.newWithdrawalWaitPeriod); - - expect(await networkParams.withdrawalWaitPeriod()).to.equal(initParams.newWithdrawalWaitPeriod); - }); - - it("set new block time fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewBlockTime(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new block time fail: invalid input", async () => { - await expect(networkParams.setNewBlockTime(0)).to.be.revertedWith("NetworkParams: INVALID_BLOCK_TIME"); - }); - - it("set new block time success", async () => { - initParams.newBlockTime = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewBlockTime(initParams.newBlockTime); - - expect(await networkParams.blockTime()).to.equal(initParams.newBlockTime); - }); - - it("set new block time drift fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewBlockTimeDrift(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new block time drift fail: invalid input", async () => { - await expect(networkParams.setNewBlockTimeDrift(0)).to.be.revertedWith("NetworkParams: INVALID_BLOCK_TIME_DRIFT"); - }); - - it("set new block time drift success", async () => { - initParams.newBlockTimeDrift = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewBlockTimeDrift(initParams.newBlockTimeDrift); - - expect(await networkParams.blockTimeDrift()).to.equal(initParams.newBlockTimeDrift); - }); - - it("set new voting delay fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewVotingDelay(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new voting delay success", async () => { - initParams.newVotingDelay = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewVotingDelay(initParams.newVotingDelay); - - expect(await networkParams.votingDelay()).to.equal(initParams.newVotingDelay); - }); - - it("set new voting period fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewVotingPeriod(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new voting period fail: invalid input", async () => { - await expect(networkParams.setNewVotingPeriod(0)).to.be.revertedWith("NetworkParams: INVALID_VOTING_PERIOD"); - }); - - it("set new voting period success", async () => { - initParams.newVotingPeriod = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewVotingPeriod(initParams.newVotingPeriod); - - expect(await networkParams.votingPeriod()).to.equal(initParams.newVotingPeriod); - }); - - it("set new proposal threshold fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewProposalThreshold(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new proposal threshold success", async () => { - initParams.newProposalThreshold = 10 ** Math.floor(Math.random() + 6); - await networkParams.setNewProposalThreshold(initParams.newProposalThreshold); - - expect(await networkParams.proposalThreshold()).to.equal(initParams.newProposalThreshold); - }); - - it("set new base fee change denom fail: only owner", async () => { - await impersonateAccount(accounts[1].address); - await setBalance(accounts[1].address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - const newNetworkParams = networkParams.connect(accounts[1]); - - await expect(newNetworkParams.setNewBaseFeeChangeDenom(1)).to.be.revertedWith("Ownable: caller is not the owner"); - await stopImpersonatingAccount(accounts[1].address); - }); - - it("set new base fee change denom fail: invalid input", async () => { - await expect(networkParams.setNewBaseFeeChangeDenom(0)).to.be.revertedWith( - "NetworkParams: INVALID_BASE_FEE_CHANGE_DENOM" - ); - }); - - it("set new base fee change denom success", async () => { - initParams.newBaseFeeChangeDenom = ethers.utils.parseUnits(String(Math.floor(Math.random() * 20 + 11))); - await networkParams.setNewBaseFeeChangeDenom(initParams.newBaseFeeChangeDenom); - - expect(await networkParams.baseFeeChangeDenom()).to.equal(initParams.newBaseFeeChangeDenom); - }); -}); diff --git a/test/child/RootMintableERC1155Predicate.test.ts b/test/child/RootMintableERC1155Predicate.test.ts index 769b7221..387349db 100644 --- a/test/child/RootMintableERC1155Predicate.test.ts +++ b/test/child/RootMintableERC1155Predicate.test.ts @@ -50,9 +50,14 @@ describe("RootMintableERC1155Predicate", () => { "RootMintableERC1155Predicate" ); rootMintableERC1155Predicate = await RootMintableERC1155Predicate.deploy(); - await rootMintableERC1155Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootMintableERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootMintableERC1155Predicate = RootMintableERC1155Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/child/RootMintableERC20Predicate.test.ts b/test/child/RootMintableERC20Predicate.test.ts index 883ef3b1..af12ca28 100644 --- a/test/child/RootMintableERC20Predicate.test.ts +++ b/test/child/RootMintableERC20Predicate.test.ts @@ -52,9 +52,14 @@ describe("RootMintableERC20Predicate", () => { "RootMintableERC20Predicate" ); rootMintableERC20Predicate = await RootMintableERC20Predicate.deploy(); - await rootMintableERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootMintableERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootMintableERC20Predicate = RootMintableERC20Predicate.attach(_proxy.address); + const NativeERC20: NativeERC20__factory = await ethers.getContractFactory("NativeERC20"); const tempNativeERC20 = await NativeERC20.deploy(); diff --git a/test/child/RootMintableERC721Predicate.test.ts b/test/child/RootMintableERC721Predicate.test.ts index 1d83632f..fbb92676 100644 --- a/test/child/RootMintableERC721Predicate.test.ts +++ b/test/child/RootMintableERC721Predicate.test.ts @@ -49,9 +49,14 @@ describe("RootMintableERC721Predicate", () => { "RootMintableERC721Predicate" ); rootMintableERC721Predicate = await RootMintableERC721Predicate.deploy(); - await rootMintableERC721Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootMintableERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootMintableERC721Predicate = RootMintableERC721Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/forge/child/ChildERC1155.t.sol b/test/forge/child/ChildERC1155.t.sol index 846c8a82..35d4e764 100644 --- a/test/forge/child/ChildERC1155.t.sol +++ b/test/forge/child/ChildERC1155.t.sol @@ -17,8 +17,8 @@ contract ChildERC1155Test is Test { string URI = "lorem"; function setUp() public { - childERC1155 = new ChildERC1155(); - predicate = new ChildERC1155Predicate(); + childERC1155 = ChildERC1155(proxify("ChildERC1155.sol", "")); + predicate = ChildERC1155Predicate(proxify("ChildERC1155Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/ChildERC20.t.sol b/test/forge/child/ChildERC20.t.sol index 1f69d1a0..6e86d6dd 100644 --- a/test/forge/child/ChildERC20.t.sol +++ b/test/forge/child/ChildERC20.t.sol @@ -18,8 +18,8 @@ contract ChildERC20Test is Test { uint8 decimals = 18; function setUp() public { - childERC20 = new ChildERC20(); - predicate = new ChildERC20Predicate(); + childERC20 = ChildERC20(proxify("ChildERC20.sol", "")); + predicate = ChildERC20Predicate(proxify("ChildERC20Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/ChildERC20Predicate.t.sol b/test/forge/child/ChildERC20Predicate.t.sol index b5fb8a3d..c7a4ca25 100644 --- a/test/forge/child/ChildERC20Predicate.t.sol +++ b/test/forge/child/ChildERC20Predicate.t.sol @@ -18,7 +18,7 @@ contract ChildERC20PredicateTest is Test { address bob; function setUp() public { - predicate = new ChildERC20Predicate(); + predicate = ChildERC20Predicate(proxify("ChildERC20Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/ChildERC721.t.sol b/test/forge/child/ChildERC721.t.sol index 354de150..4936c8e8 100644 --- a/test/forge/child/ChildERC721.t.sol +++ b/test/forge/child/ChildERC721.t.sol @@ -18,8 +18,8 @@ contract ChildERC721Test is Test { string URI = "lorem"; function setUp() public { - childERC721 = new ChildERC721(); - predicate = new ChildERC721Predicate(); + childERC721 = ChildERC721(proxify("ChildERC721.sol", "")); + predicate = ChildERC721Predicate(proxify("ChildERC721Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/validator/RewardPool.t.sol b/test/forge/child/validator/RewardPool.t.sol index 9f51eac4..f0c575af 100644 --- a/test/forge/child/validator/RewardPool.t.sol +++ b/test/forge/child/validator/RewardPool.t.sol @@ -7,8 +7,6 @@ import {ValidatorSet, ValidatorInit, Epoch} from "contracts/child/validator/Vali import {RewardPool, IRewardPool, Uptime} from "contracts/child/validator/RewardPool.sol"; import "contracts/interfaces/Errors.sol"; -import {NetworkParams} from "contracts/child/NetworkParams.sol"; - abstract contract Uninitialized is Test { address public constant SYSTEM = 0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE; @@ -19,23 +17,18 @@ abstract contract Uninitialized is Test { address alice = makeAddr("alice"); uint256 epochSize = 64; - NetworkParams networkParams; - function setUp() public virtual { - networkParams = new NetworkParams(); - networkParams.initialize(NetworkParams.InitParams(address(1), 1, 64, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); - token = new MockERC20(); - validatorSet = new ValidatorSet(); + validatorSet = ValidatorSet(proxify("ValidatorSet.sol", "")); ValidatorInit[] memory init = new ValidatorInit[](2); init[0] = ValidatorInit({addr: address(this), stake: 300}); init[1] = ValidatorInit({addr: alice, stake: 100}); - validatorSet.initialize(address(1), address(1), address(1), address(networkParams), init); + validatorSet.initialize(address(1), address(1), address(1), epochSize, init); Epoch memory epoch = Epoch({startBlock: 1, endBlock: 64, epochRoot: bytes32(0)}); vm.prank(SYSTEM); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); vm.roll(block.number + 1); - pool = new RewardPool(); + pool = RewardPool(proxify("RewardPool.sol", "")); token.mint(rewardWallet, 1000 ether); vm.prank(rewardWallet); token.approve(address(pool), type(uint256).max); @@ -45,7 +38,7 @@ abstract contract Uninitialized is Test { abstract contract Initialized is Uninitialized { function setUp() public virtual override { super.setUp(); - pool.initialize(address(token), rewardWallet, address(validatorSet), address(networkParams)); + pool.initialize(address(token), rewardWallet, address(validatorSet), 1 ether); } } @@ -56,13 +49,13 @@ abstract contract Distributed is Initialized { uptime[0] = Uptime({validator: address(this), signedBlocks: 64}); uptime[1] = Uptime({validator: alice, signedBlocks: 64}); vm.prank(SYSTEM); - pool.distributeRewardFor(1, uptime, epochSize); + pool.distributeRewardFor(1, uptime); } } contract RewardPool_Initialize is Uninitialized { function test_Initialize() public { - pool.initialize(address(token), rewardWallet, address(validatorSet), address(networkParams)); + pool.initialize(address(token), rewardWallet, address(validatorSet), 1 ether); assertEq(address(pool.rewardToken()), address(token)); assertEq(pool.rewardWallet(), rewardWallet); assertEq(address(pool.validatorSet()), address(validatorSet)); @@ -74,21 +67,21 @@ contract RewardPool_Distribute is Initialized { function test_RevertOnlySystem() public { vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, "SYSTEMCALL")); - pool.distributeRewardFor(1, new Uptime[](0), epochSize); + pool.distributeRewardFor(1, new Uptime[](0)); } function test_RevertGenesisEpoch() public { Uptime[] memory uptime = new Uptime[](0); vm.expectRevert("EPOCH_NOT_COMMITTED"); vm.prank(SYSTEM); - pool.distributeRewardFor(0, uptime, epochSize); + pool.distributeRewardFor(0, uptime); } function test_RevertFutureEpoch() public { Uptime[] memory uptime = new Uptime[](0); vm.expectRevert("EPOCH_NOT_COMMITTED"); vm.prank(SYSTEM); - pool.distributeRewardFor(2, uptime, epochSize); + pool.distributeRewardFor(2, uptime); } function test_RevertSignedBlocksExceedsTotalBlocks() public { @@ -96,23 +89,20 @@ contract RewardPool_Distribute is Initialized { uptime[0] = Uptime({validator: address(this), signedBlocks: 65}); vm.prank(SYSTEM); vm.expectRevert("SIGNED_BLOCKS_EXCEEDS_TOTAL"); - pool.distributeRewardFor(1, uptime, epochSize); + pool.distributeRewardFor(1, uptime); } - function test_DistributeRewards(uint256 epochReward) public { - vm.assume(epochReward <= pool.rewardToken().balanceOf(rewardWallet)); - vm.mockCall(address(networkParams), abi.encodeCall(networkParams.epochReward, ()), abi.encode(epochReward)); - + function test_DistributeRewards() public { Uptime[] memory uptime = new Uptime[](2); uptime[0] = Uptime({validator: address(this), signedBlocks: 60}); uptime[1] = Uptime({validator: alice, signedBlocks: 50}); - uint256 reward1 = (networkParams.epochReward() * 3 * 60) / (4 * 64); - uint256 reward2 = (networkParams.epochReward() * 1 * 50) / (4 * 64); + uint256 reward1 = (1 ether * 3 * 60) / (4 * 64); + uint256 reward2 = (1 ether * 1 * 50) / (4 * 64); uint256 totalReward = reward1 + reward2; vm.prank(SYSTEM); vm.expectEmit(true, true, true, true); emit RewardDistributed(1, totalReward); - pool.distributeRewardFor(1, uptime, epochSize); + pool.distributeRewardFor(1, uptime); assertEq(pool.pendingRewards(address(this)), reward1); assertEq(pool.pendingRewards(alice), reward2); assertEq(pool.paidRewardPerEpoch(1), totalReward); @@ -124,7 +114,7 @@ contract RewardPool_DuplicateDistribution is Distributed { Uptime[] memory uptime = new Uptime[](0); vm.startPrank(SYSTEM); vm.expectRevert("REWARD_ALREADY_DISTRIBUTED"); - pool.distributeRewardFor(1, uptime, epochSize); + pool.distributeRewardFor(1, uptime); } } diff --git a/test/forge/child/validator/ValidatorSet.t.sol b/test/forge/child/validator/ValidatorSet.t.sol index 1bfec832..49339cc7 100644 --- a/test/forge/child/validator/ValidatorSet.t.sol +++ b/test/forge/child/validator/ValidatorSet.t.sol @@ -6,8 +6,6 @@ import {ValidatorSet, ValidatorInit, Epoch} from "contracts/child/validator/Vali import {L2StateSender} from "contracts/child/L2StateSender.sol"; import "contracts/interfaces/Errors.sol"; -import {NetworkParams} from "contracts/child/NetworkParams.sol"; - abstract contract Uninitialized is Test { address internal constant SYSTEM = 0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE; bytes32 internal constant STAKE_SIG = keccak256("STAKE"); @@ -20,16 +18,9 @@ abstract contract Uninitialized is Test { address bob = makeAddr("bob"); uint256 epochSize = 64; - NetworkParams networkParams; - function setUp() public virtual { - networkParams = new NetworkParams(); - networkParams.initialize( - NetworkParams.InitParams(address(1), 1, epochSize, 1 ether, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) - ); - stateSender = new L2StateSender(); - validatorSet = new ValidatorSet(); + validatorSet = ValidatorSet(proxify("ValidatorSet.sol", "")); } } @@ -39,7 +30,7 @@ abstract contract Initialized is Uninitialized { ValidatorInit[] memory init = new ValidatorInit[](2); init[0] = ValidatorInit({addr: address(this), stake: 300}); init[1] = ValidatorInit({addr: alice, stake: 100}); - validatorSet.initialize(address(stateSender), stateReceiver, rootChainManager, address(networkParams), init); + validatorSet.initialize(address(stateSender), stateReceiver, rootChainManager, epochSize, init); } } @@ -49,7 +40,7 @@ abstract contract Committed is Initialized { _beforeCommit(); Epoch memory epoch = Epoch({startBlock: 1, endBlock: 64, epochRoot: bytes32(0)}); vm.prank(SYSTEM); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); vm.roll(block.number + 1); _afterCommit(); } @@ -64,7 +55,7 @@ contract ValidatorSet_Initialize is Uninitialized { ValidatorInit[] memory init = new ValidatorInit[](2); init[0] = ValidatorInit({addr: address(this), stake: 300}); init[1] = ValidatorInit({addr: alice, stake: 100}); - validatorSet.initialize(address(stateSender), stateReceiver, rootChainManager, address(networkParams), init); + validatorSet.initialize(address(stateSender), stateReceiver, rootChainManager, epochSize, init); assertEq(validatorSet.balanceOf(address(this)), 300); assertEq(validatorSet.balanceOf(alice), 100); assertEq(validatorSet.totalSupply(), 400); @@ -79,7 +70,7 @@ contract ValidatorSet_CommitEpoch is Initialized { function test_RevertOnlySystemCall() public { Epoch memory epoch = Epoch({startBlock: 1, endBlock: 64, epochRoot: bytes32(0)}); vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, "SYSTEMCALL")); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); } function test_RevertInvalidEpochId(uint256 id) public { @@ -87,7 +78,7 @@ contract ValidatorSet_CommitEpoch is Initialized { Epoch memory epoch = Epoch({startBlock: 1, endBlock: 64, epochRoot: bytes32(0)}); vm.expectRevert("UNEXPECTED_EPOCH_ID"); vm.prank(SYSTEM); - validatorSet.commitEpoch(id, epoch, epochSize); + validatorSet.commitEpoch(id, epoch); } function test_RevertNoBlocksCommitted(uint256 startBlock, uint256 endBlock) public { @@ -95,7 +86,7 @@ contract ValidatorSet_CommitEpoch is Initialized { Epoch memory epoch = Epoch({startBlock: startBlock, endBlock: endBlock, epochRoot: bytes32(0)}); vm.expectRevert("NO_BLOCKS_COMMITTED"); vm.prank(SYSTEM); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); } function test_RevertEpochSize(uint256 startBlock, uint256 endBlock) public { @@ -104,14 +95,14 @@ contract ValidatorSet_CommitEpoch is Initialized { Epoch memory epoch = Epoch({startBlock: startBlock, endBlock: endBlock, epochRoot: bytes32(0)}); vm.expectRevert("EPOCH_MUST_BE_DIVISIBLE_BY_EPOCH_SIZE"); vm.prank(SYSTEM); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); } function test_RevertInvalidStartBlock() public { Epoch memory epoch = Epoch({startBlock: 0, endBlock: 63, epochRoot: bytes32(0)}); vm.expectRevert("INVALID_START_BLOCK"); vm.prank(SYSTEM); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); } function test_CommitEpoch() public { @@ -119,7 +110,7 @@ contract ValidatorSet_CommitEpoch is Initialized { vm.prank(SYSTEM); vm.expectEmit(true, true, true, true); emit NewEpoch(1, 1, 64, bytes32(0)); - validatorSet.commitEpoch(1, epoch, epochSize); + validatorSet.commitEpoch(1, epoch); assertEq(validatorSet.currentEpochId(), 2); assertEq(validatorSet.epochEndBlocks(1), 64); assertEq(validatorSet.totalBlocks(1), 64); @@ -217,48 +208,4 @@ contract ValidatorSet_WithdrawStake is Committed { contract ValidatorSet_Slash is Committed { bytes32 private constant SLASH_SIG = keccak256("SLASH"); event L2StateSynced(uint256 indexed id, address indexed sender, address indexed receiver, bytes data); - event Slashed(uint256 indexed exitId, address[] validators); - - function test_InitilizeSlashOnlySystemCall() public { - vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, "SYSTEMCALL")); - validatorSet.slash(new address[](0)); - } - - function test_InitialiseSlash(address[] memory validators) public { - vm.assume(validators.length <= (stateSender.MAX_LENGTH() - 160) / 32); - uint256 slashingPercentage = validatorSet.SLASHING_PERCENTAGE(); - uint256 slashIncentivePercentage = validatorSet.SLASH_INCENTIVE_PERCENTAGE(); - vm.prank(SYSTEM); - vm.expectEmit(true, true, true, true); - emit L2StateSynced(1, address(validatorSet), rootChainManager, abi.encode(SLASH_SIG, validators, slashingPercentage, slashIncentivePercentage)); - validatorSet.slash(validators); - } - - function test_FinalizeSlash() public { - uint256 exitEventId = 1; - uint256 slashingPercentage = validatorSet.SLASHING_PERCENTAGE(); - address[] memory validatorsToSlash = new address[](2); - validatorsToSlash[0] = alice; - validatorsToSlash[1] = address(this); - - assertEq(validatorSet.balanceOf(alice), 100); - assertEq(validatorSet.balanceOf(address(this)), 300); - - vm.expectEmit(true, true, true, true); - emit Slashed(exitEventId, validatorsToSlash); - vm.prank(stateReceiver); - validatorSet.onStateReceive(1 /* StateSyncCounter */, rootChainManager, abi.encode(SLASH_SIG, exitEventId, validatorsToSlash, slashingPercentage)); - - assertEq(validatorSet.balanceOf(alice), 0, "should unstake"); - assertEq(validatorSet.balanceOf(address(this)), 0, "should unstake"); - } - - function test_FinalizeSlashAlreadyProcessedSanityCheck() public { - uint256 exitEventId = 1; - vm.startPrank(stateReceiver); - validatorSet.onStateReceive(1 /* StateSyncCounter */, rootChainManager, abi.encode(SLASH_SIG, exitEventId, new address[](0), 0)); - vm.expectRevert("SLASH_ALREADY_PROCESSED"); - validatorSet.onStateReceive(1 /* StateSyncCounter */, rootChainManager, abi.encode(SLASH_SIG, exitEventId, new address[](0), 0)); - vm.stopPrank(); - } } diff --git a/test/forge/libs/GenesisProxy.t.sol b/test/forge/libs/GenesisProxy.t.sol new file mode 100644 index 00000000..76e2f4a7 --- /dev/null +++ b/test/forge/libs/GenesisProxy.t.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.19; + +import "forge-std/Test.sol"; + +import {GenesisProxy} from "contracts/lib/GenesisProxy.sol"; +import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +contract GenesisProxyTest is Test { + address newOwner = makeAddr("newOwner"); + + address logicAddr; + address proxyAddr; + + DummyContract internal proxyAsDummyContract; + GenesisProxy internal proxy; + ITransparentUpgradeableProxy internal proxyWithAdminInterface; + + address proxyAdmin; + + function setUp() public { + logicAddr = address(new DummyContract()); + + proxyAdmin = makeAddr("proxyAdmin"); + + proxyAddr = makeAddr("proxyAddr"); + vm.etch(proxyAddr, vm.getDeployedCode("GenesisProxy.sol")); + _recordProxy(proxyAddr); + + proxy.protectSetUpProxy(proxyAdmin); + vm.prank(proxyAdmin); + proxy.setUpProxy(logicAddr, proxyAdmin, abi.encodeWithSelector(DummyContract.initialize.selector, newOwner)); + } + + function testRevert_constructor() public { + vm.expectRevert(); + new GenesisProxy(); + } + + function test_RevertIfProtected_protectSetUpProxy() public { + proxyAddr = makeAddr("proxyAddr random"); + vm.etch(proxyAddr, vm.getDeployedCode("GenesisProxy.sol")); + _recordProxy(proxyAddr); + + proxy.protectSetUpProxy(proxyAdmin); + + vm.expectRevert("Already protected"); + proxy.protectSetUpProxy(proxyAdmin); + + vm.prank(proxyAdmin); + proxy.setUpProxy(logicAddr, proxyAdmin, abi.encodeWithSelector(DummyContract.initialize.selector, newOwner)); + + vm.expectRevert("Already protected"); + proxy.protectSetUpProxy(proxyAdmin); + } + + function test_RevertIfUnauthorized_setUpProxy() public { + proxyAddr = makeAddr("proxyAddr random"); + vm.etch(proxyAddr, vm.getDeployedCode("GenesisProxy.sol")); + _recordProxy(proxyAddr); + + proxy.protectSetUpProxy(proxyAdmin); + + vm.expectRevert("Unauthorized"); + proxy.setUpProxy(address(0), address(0), ""); + } + + function test_RevertIfAlreadySetUp_setUpProxy() public { + vm.expectRevert("Already set-up"); + proxy.setUpProxy(address(0), address(0), ""); + } + + function test_ProxyConfiguration() public { + vm.startPrank(proxyAdmin); + + assertEq(proxyWithAdminInterface.admin(), proxyAdmin); + assertEq(proxyWithAdminInterface.implementation(), logicAddr); + + vm.stopPrank(); + } + + function test_Delegation() public { + assertEq(proxyAsDummyContract.owner(), newOwner); + } + + function testLogicChange() public { + address newLogicAddr = makeAddr("newLogicAddr"); + vm.etch(newLogicAddr, hex"00"); + + vm.startPrank(proxyAdmin); + + proxyWithAdminInterface.upgradeTo(newLogicAddr); + assertEq(proxyWithAdminInterface.implementation(), newLogicAddr); + + vm.stopPrank(); + } + + function testAdminChange() public { + address newAdmin = makeAddr("newAdmin"); + + vm.prank(proxyAdmin); + proxyWithAdminInterface.changeAdmin(newAdmin); + + vm.prank(newAdmin); + assertEq(proxyWithAdminInterface.admin(), newAdmin); + } + + function _recordProxy(address _proxyAddr) internal { + proxyAsDummyContract = DummyContract(_proxyAddr); + proxy = GenesisProxy(payable(address(_proxyAddr))); + proxyWithAdminInterface = ITransparentUpgradeableProxy(_proxyAddr); + } +} + +contract DummyContract { + address public owner; + + function initialize(address _owner) public { + owner = _owner; + } +} diff --git a/test/forge/root/CheckpointManager.t.sol b/test/forge/root/CheckpointManager.t.sol index ff8a64e8..834dcdfb 100644 --- a/test/forge/root/CheckpointManager.t.sol +++ b/test/forge/root/CheckpointManager.t.sol @@ -31,7 +31,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { bls = new BLS(); bn256G2 = new BN256G2(); - checkpointManager = new CheckpointManager(address(0)); + checkpointManager = CheckpointManager(proxify("CheckpointManager.sol", abi.encode(address(0)))); admin = makeAddr("admin"); alice = makeAddr("Alice"); @@ -87,8 +87,8 @@ abstract contract FirstSubmitted is Initialized { contract CheckpointManager_Initialize is Uninitialized { function testCannotIntialize() public { - address INITIALIZER = makeAddr("INITIALIZER"); - checkpointManager = new CheckpointManager(INITIALIZER); + address initiator = makeAddr("initiator"); + checkpointManager = CheckpointManager(proxify("CheckpointManager.sol", abi.encode(address(initiator)))); vm.expectRevert(); checkpointManager.initialize(bls, bn256G2, submitCounter, validatorSet); diff --git a/test/forge/root/ExitHelper.t.sol b/test/forge/root/ExitHelper.t.sol index 21c202d0..8a9d9d10 100644 --- a/test/forge/root/ExitHelper.t.sol +++ b/test/forge/root/ExitHelper.t.sol @@ -37,8 +37,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { bls = new BLS(); bn256G2 = new BN256G2(); - checkpointManager = new CheckpointManager(address(0)); - exitHelper = new ExitHelper(); + exitHelper = ExitHelper(proxify("ExitHelper.sol", "")); admin = makeAddr("admin"); alice = makeAddr("Alice"); @@ -81,6 +80,7 @@ abstract contract Uninitialized is Test { } submitCounter = 1; + checkpointManager = CheckpointManager(proxify("CheckpointManager.sol", abi.encode(address(0)))); checkpointManager.initialize(bls, bn256G2, submitCounter, validatorSet); } } diff --git a/test/forge/root/staking/CustomSupernetManager.t.sol b/test/forge/root/staking/CustomSupernetManager.t.sol index 1f9d1091..01860bfe 100644 --- a/test/forge/root/staking/CustomSupernetManager.t.sol +++ b/test/forge/root/staking/CustomSupernetManager.t.sol @@ -8,6 +8,7 @@ import {ExitHelper} from "contracts/root/ExitHelper.sol"; import {StakeManager} from "contracts/root/staking/StakeManager.sol"; import {CustomSupernetManager, Validator, GenesisValidator} from "contracts/root/staking/CustomSupernetManager.sol"; import {MockERC20} from "contracts/mocks/MockERC20.sol"; +import {RootERC20Predicate} from "contracts/root/RootERC20Predicate.sol"; import "contracts/interfaces/Errors.sol"; abstract contract Uninitialized is Test { @@ -20,6 +21,7 @@ abstract contract Uninitialized is Test { MockERC20 token; StakeManager stakeManager; CustomSupernetManager supernetManager; + RootERC20Predicate rootERC20Predicate; function setUp() public virtual { bls = new BLS(); @@ -27,9 +29,10 @@ abstract contract Uninitialized is Test { childValidatorSet = makeAddr("childValidatorSet"); exitHelper = address(new ExitHelper()); token = new MockERC20(); - stakeManager = new StakeManager(); - supernetManager = new CustomSupernetManager(); + stakeManager = StakeManager(proxify("StakeManager.sol", "")); + supernetManager = CustomSupernetManager(proxify("CustomSupernetManager.sol", "")); stakeManager.initialize(address(token)); + rootERC20Predicate = RootERC20Predicate(proxify("RootERC20Predicate.sol", "")); } } @@ -43,6 +46,7 @@ abstract contract Initialized is Uninitialized { address(token), childValidatorSet, exitHelper, + address(rootERC20Predicate), DOMAIN ); } @@ -170,6 +174,7 @@ contract CustomSupernetManager_Initialize is Uninitialized { address(token), childValidatorSet, exitHelper, + address(rootERC20Predicate), DOMAIN ); assertEq(supernetManager.owner(), address(this), "should set owner"); @@ -267,7 +272,7 @@ contract CustomSupernetManager_StakeGenesis is ValidatorsRegistered { GenesisValidator[] memory genesisValidators = supernetManager.genesisSet(); assertEq(genesisValidators.length, 1, "should set genesisSet"); GenesisValidator memory validator = genesisValidators[0]; - assertEq(validator.validator, address(this), "should set validator address"); + assertEq(validator.addr, address(this), "should set validator address"); assertEq(validator.initialStake, amount, "should set amount"); } @@ -277,7 +282,7 @@ contract CustomSupernetManager_StakeGenesis is ValidatorsRegistered { GenesisValidator[] memory genesisValidators = supernetManager.genesisSet(); assertEq(genesisValidators.length, 1, "should set genesisSet"); GenesisValidator memory validator = genesisValidators[0]; - assertEq(validator.validator, address(this), "should set validator address"); + assertEq(validator.addr, address(this), "should set validator address"); assertEq(validator.initialStake, amount, "should set amount"); } } @@ -383,119 +388,86 @@ contract CustomSupernetManager_Unstake is EnabledStaking { } } -contract CustomSupernetManager_Slash is EnabledStaking { - address private mev = makeAddr("MEV"); - bytes32 private constant SLASH_SIG = keccak256("SLASH"); - event ValidatorDeactivated(address indexed validator); - event StateSynced(uint256 indexed id, address indexed sender, address indexed receiver, bytes data); - event StakeRemoved(uint256 indexed id, address indexed validator, uint256 amount); - event StakeWithdrawn(address indexed validator, address indexed recipient, uint256 amount); - event Transfer(address indexed from, address indexed to, uint256 value); - - uint256 private slashingPercentage = 50; // sent from ValidatorSet - uint256 private slashIncentivePercentage = 30; // sent from ValidatorSet - - function test_SuccessfulFullWithdrawal() public { - uint256 exitEventId = 1; - - address[] memory validatorsToSlash = new address[](1); - validatorsToSlash[0] = address(this); - bytes memory callData = abi.encode(SLASH_SIG, validatorsToSlash, slashingPercentage, slashIncentivePercentage); - uint256 slashedAmount = (amount * slashingPercentage) / 100; +contract CustomSupernetManager_PremineInitialized is Initialized { + uint256 balance = 100 ether; + event GenesisBalanceAdded(address indexed account, uint256 indexed amount); - vm.expectEmit(true, true, true, true); - emit StakeWithdrawn(address(this), address(supernetManager), slashedAmount); - vm.expectEmit(true, true, true, true); - emit StakeRemoved(exitEventId, address(this), amount); - vm.expectEmit(true, true, true, true); - emit ValidatorDeactivated(address(this)); - // emits state sync event to complete slashing on child chain - vm.expectEmit(true, true, true, true); - emit StateSynced( - exitEventId, - address(supernetManager), - childValidatorSet, - abi.encode(SLASH_SIG, exitEventId, validatorsToSlash, slashingPercentage) - ); - vm.store(exitHelper, callerSlotOnExitHelper, bytes32(uint256(uint160(mev)))); // simulate caller of exit() - vm.prank(exitHelper); - supernetManager.onL2StateReceive(exitEventId, childValidatorSet, callData); - vm.store(exitHelper, callerSlotOnExitHelper, bytes32(0)); + address childERC20Predicate; + address childTokenTemplate; + address bob = makeAddr("bob"); - assertEq(stakeManager.stakeOf(address(this), 1), 0, "should unstake all"); - assertEq( - stakeManager.withdrawableStake(address(this)), - amount - (amount * slashingPercentage) / 100, - "should slash" + function setUp() public virtual override { + super.setUp(); + token.mint(bob, balance); + childERC20Predicate = makeAddr("childERC20Predicate"); + childTokenTemplate = makeAddr("childTokenTemplate"); + rootERC20Predicate.initialize( + address(stateSender), + exitHelper, + childERC20Predicate, + childTokenTemplate, + address(token) ); - assertEq(supernetManager.getValidator(address(this)).isActive, false, "should deactivate"); } - function test_SlashIncentiveDistribution() external { - uint256 exitEventId = 1; - address[] memory validatorsToSlash = new address[](1); - validatorsToSlash[0] = address(this); - bytes memory callData = abi.encode(SLASH_SIG, validatorsToSlash, slashingPercentage, slashIncentivePercentage); - uint256 slashedAmount = (amount * slashingPercentage) / 100; - uint256 exitorReward = (slashedAmount * slashIncentivePercentage) / 100; - - assertEq(token.balanceOf(mev), 0); // balance before + function test_addGenesisBalance_successful() public { + vm.startPrank(bob); + token.approve(address(supernetManager), balance); vm.expectEmit(true, true, true, true); - emit Transfer(address(supernetManager), mev, exitorReward); - vm.store(exitHelper, callerSlotOnExitHelper, bytes32(uint256(uint160(mev)))); // simulate caller of exit() - vm.prank(exitHelper); - supernetManager.onL2StateReceive(exitEventId, childValidatorSet, callData); - vm.store(exitHelper, callerSlotOnExitHelper, bytes32(0)); - assertEq(token.balanceOf(mev), exitorReward, "should transfer slashing reward"); - } - - function test_SlashEntireValidatorSet() external { - uint256 aliceStakedAmount = amount << 3; - token.mint(alice, aliceStakedAmount); - vm.prank(alice); - stakeManager.stakeFor(1, aliceStakedAmount); + emit GenesisBalanceAdded(bob, balance); + supernetManager.addGenesisBalance(balance); - uint256 aliceSlashedAmount = (aliceStakedAmount * slashingPercentage) / 100; - uint256 thisSlashedAmount = (amount * slashingPercentage) / 100; + GenesisValidator[] memory genesisAccounts = supernetManager.genesisSet(); + assertEq(genesisAccounts.length, 1, "should set genesisSet"); + GenesisValidator memory account = genesisAccounts[0]; + assertEq(account.addr, bob, "should set validator address"); + assertEq(account.initialStake, 0, "should set initial stake to 0"); - address[] memory validatorsToSlash = new address[](2); - validatorsToSlash[0] = alice; - validatorsToSlash[1] = address(this); - bytes memory callData = abi.encode(SLASH_SIG, validatorsToSlash, slashingPercentage, slashIncentivePercentage); + uint256 actualBalance = supernetManager.genesisBalances(account.addr); + assertEq(actualBalance, balance, "should set genesis balance"); + } - vm.store(exitHelper, callerSlotOnExitHelper, bytes32(uint256(uint160(mev)))); // simulate caller of exit() - vm.prank(exitHelper); - supernetManager.onL2StateReceive(1, childValidatorSet, callData); - vm.store(exitHelper, callerSlotOnExitHelper, bytes32(0)); + function test_addGenesisBalance_genesisSetFinalizedRevert() public { + supernetManager.finalizeGenesis(); + supernetManager.enableStaking(); + vm.expectRevert("CustomSupernetManager: GENESIS_SET_IS_ALREADY_FINALIZED"); + supernetManager.addGenesisBalance(balance); + } - assertEq(stakeManager.stakeOf(address(this), 1), 0, "should unstake all"); - assertEq(stakeManager.stakeOf(alice, 1), 0, "should unstake all"); - assertEq(stakeManager.withdrawableStake(address(this)), amount - thisSlashedAmount, "should slash"); - assertEq(stakeManager.withdrawableStake(alice), aliceStakedAmount - aliceSlashedAmount, "should slash"); - assertEq(supernetManager.getValidator(address(this)).isActive, false, "should deactivate"); - assertEq(supernetManager.getValidator(alice).isActive, false, "should deactivate"); - uint256 exitorReward = ((thisSlashedAmount + aliceSlashedAmount) * slashIncentivePercentage) / 100; - assertEq(token.balanceOf(mev), exitorReward, "should transfer slashing reward"); + function test_addGenesisBalance_invalidAmountRevert() public { + vm.expectRevert("CustomSupernetManager: INVALID_AMOUNT"); + supernetManager.addGenesisBalance(0); } } -contract CustomSupernetManager_WithdrawSlash is Slashed { - event Transfer(address indexed from, address indexed to, uint256 value); +contract CustomSupernetManager_UndefinedRootERC20Predicate is Uninitialized { + function setUp() public virtual override { + super.setUp(); + supernetManager.initialize( + address(stakeManager), + address(bls), + address(stateSender), + address(token), + childValidatorSet, + exitHelper, + address(0), + DOMAIN + ); + } - function test_RevertNotOwner() public { - vm.expectRevert("Ownable: caller is not the owner"); - vm.prank(alice); - supernetManager.withdrawSlashedStake(alice); + function test_addGenesisBalance_revertUndefinedRootERC20Predicate() public { + vm.expectRevert( + abi.encodeWithSelector(Unauthorized.selector, "CustomSupernetManager: UNDEFINED_ROOT_ERC20_PREDICATE") + ); + supernetManager.addGenesisBalance(100 ether); } +} - function test_WithdrawSlashedAmount() public { - uint256 slashedAmount = (amount * slashingPercentage) / 100; - uint256 slashingReward = (slashedAmount * slashIncentivePercentage) / 100; // given to exitor after slash - uint256 withdrawableAmount = slashedAmount - slashingReward; - assertEq(token.balanceOf(address(supernetManager)), withdrawableAmount); - vm.expectEmit(true, true, true, true); - emit Transfer(address(supernetManager), alice, withdrawableAmount); - supernetManager.withdrawSlashedStake(alice); - assertEq(token.balanceOf(address(supernetManager)), 0); +contract CustomSupernetManager_UndefinedNativeTokenRoot is Initialized { + function test_addGenesisBalance_revertUndefinedNativeTokenRoot() public { + vm.expectRevert( + abi.encodeWithSelector(Unauthorized.selector, "CustomSupernetManager: UNDEFINED_NATIVE_TOKEN_ROOT") + ); + supernetManager.addGenesisBalance(100 ether); } } diff --git a/test/forge/root/staking/StakeManager.t.sol b/test/forge/root/staking/StakeManager.t.sol index e132ea06..19561840 100644 --- a/test/forge/root/staking/StakeManager.t.sol +++ b/test/forge/root/staking/StakeManager.t.sol @@ -13,7 +13,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { token = new MockERC20(); - stakeManager = new StakeManager(); + stakeManager = StakeManager(proxify("StakeManager.sol", "")); supernetManager = new MockSupernetManager(); } } @@ -150,34 +150,6 @@ contract StakeManager_ReleaseStake is Staked, StakeManager { } } -contract StakeManager_SlashStake is Staked, StakeManager { - function test_RevertNotSupernetManager() public { - vm.expectRevert("StakeManagerChildData: INVALID_MANAGER"); - stakeManager.slashStakeOf(address(this), 1); - } - - function test_SlashStakeFor(uint256 amount) public { - if (amount > maxAmount) amount = maxAmount; - vm.expectEmit(true, true, true, true); - emit StakeRemoved(id, address(this), stakeManager.stakeOf(address(this), id)); - vm.expectEmit(true, true, true, true); - emit ValidatorSlashed(id, address(this), amount); - vm.prank(address(supernetManager)); - stakeManager.slashStakeOf(address(this), amount); - assertEq(stakeManager.stakeOf(address(this), id), 0, "should be unstaked completely"); - assertEq( - stakeManager.withdrawableStake(address(this)), - maxAmount - amount, - "withdrawable stake should be reduced by the slashed amount" - ); - assertEq( - token.balanceOf(address(supernetManager)), - amount, - "supernet manager should receive the slashed amount" - ); - } -} - contract StakeManager_WithdrawStake is Unstaked, StakeManager { function test_WithdrawStake(uint256 amount) public { vm.assume(amount <= maxAmount); diff --git a/test/forge/root/staking/deployment/DeployCustomSupernetManager.t.sol b/test/forge/root/staking/deployment/DeployCustomSupernetManager.t.sol index 41137dc1..c544a93d 100644 --- a/test/forge/root/staking/deployment/DeployCustomSupernetManager.t.sol +++ b/test/forge/root/staking/deployment/DeployCustomSupernetManager.t.sol @@ -25,6 +25,7 @@ contract DeployCustomSupernetManagerTest is Test { address newMatic; address newChildValidatorSet; address newExitHelper; + address newRootERC20Predicate; string newDomain; function setUp() public { @@ -37,6 +38,7 @@ contract DeployCustomSupernetManagerTest is Test { newMatic = makeAddr("newMatic"); newChildValidatorSet = makeAddr("newChildValidatorSet"); newExitHelper = makeAddr("newExitHelper"); + newRootERC20Predicate = makeAddr("newRootERC20Predicate"); newDomain = "newDomain"; (logicAddr, proxyAddr) = deployer.run( @@ -47,6 +49,7 @@ contract DeployCustomSupernetManagerTest is Test { newMatic, newChildValidatorSet, newExitHelper, + newRootERC20Predicate, newDomain ); _recordProxy(proxyAddr); @@ -70,6 +73,7 @@ contract DeployCustomSupernetManagerTest is Test { newMatic, newChildValidatorSet, newExitHelper, + newRootERC20Predicate, newDomain ); diff --git a/test/forge/utils/Cheats.sol b/test/forge/utils/Cheats.sol new file mode 100644 index 00000000..d403bf77 --- /dev/null +++ b/test/forge/utils/Cheats.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.19; + +// 💬 ABOUT +// StdCheats and custom cheats. + +// 🧩 MODULES +import {StdCheats} from "forge-std/StdCheats.sol"; + +// 📦 BOILERPLATE +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +// ⭐️ CHEATS +abstract contract Cheats is StdCheats { + address immutable PROXY_ADMIN = makeAddr("PROXY_ADMIN"); + + function proxify(string memory what, bytes memory args) internal returns (address proxyAddr) { + address logicAddr = deployCode(what, args); + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(logicAddr, PROXY_ADMIN, ""); + proxyAddr = address(proxy); + } +} diff --git a/test/forge/utils/Test.sol b/test/forge/utils/Test.sol index 066272b5..fa1d72f8 100644 --- a/test/forge/utils/Test.sol +++ b/test/forge/utils/Test.sol @@ -5,9 +5,9 @@ pragma solidity 0.8.19; // Custom Test. // 🧩 MODULES -import {console2 as console} from "forge-std/console2.sol"; +import {console} from "forge-std/console.sol"; import {Assertions} from "./Assertions.sol"; -import {StdCheats} from "forge-std/StdCheats.sol"; +import {Cheats} from "./Cheats.sol"; import {stdError} from "forge-std/StdError.sol"; import {StdUtils} from "forge-std/StdUtils.sol"; @@ -16,6 +16,6 @@ import {TestBase} from "forge-std/Base.sol"; import {DSTest} from "ds-test/test.sol"; // ⭐️ TEST -abstract contract Test is DSTest, Assertions, StdCheats, StdUtils, TestBase { +abstract contract Test is TestBase, DSTest, Assertions, Cheats, StdUtils { } diff --git a/test/root/CheckpointManager.test.ts b/test/root/CheckpointManager.test.ts index b3f2c3ad..a670a726 100644 --- a/test/root/CheckpointManager.test.ts +++ b/test/root/CheckpointManager.test.ts @@ -30,6 +30,12 @@ describe("CheckpointManager", () => { const CheckpointManager = await ethers.getContractFactory("CheckpointManager"); checkpointManager = (await CheckpointManager.deploy(ethers.constants.AddressZero)) as CheckpointManager; await checkpointManager.deployed(); + + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(checkpointManager.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + checkpointManager = CheckpointManager.attach(_proxy.address); }); it("Initialize failed by zero voting power", async () => { diff --git a/test/root/ChildMintableERC1155Predicate.test.ts b/test/root/ChildMintableERC1155Predicate.test.ts index a8f93c3a..a63c2507 100644 --- a/test/root/ChildMintableERC1155Predicate.test.ts +++ b/test/root/ChildMintableERC1155Predicate.test.ts @@ -52,9 +52,14 @@ describe("ChildMintableERC1155Predicate", () => { "ChildMintableERC1155Predicate" ); childMintableERC1155Predicate = await ChildMintableERC1155Predicate.deploy(); - await childMintableERC1155Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childMintableERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childMintableERC1155Predicate = ChildMintableERC1155Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperChildERC1155Predicate = childMintableERC1155Predicate.connect(await ethers.getSigner(exitHelper.address)); @@ -382,7 +387,13 @@ describe("ChildMintableERC1155Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256", "uint256"], @@ -416,7 +427,13 @@ describe("ChildMintableERC1155Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); await expect(childMintableERC1155Predicate.withdraw(childToken.address, 0, 1)).to.be.revertedWith( "ChildMintableERC1155Predicate: UNMAPPED_TOKEN" diff --git a/test/root/ChildMintableERC20Predicate.test.ts b/test/root/ChildMintableERC20Predicate.test.ts index b8852644..a1bbd7a2 100644 --- a/test/root/ChildMintableERC20Predicate.test.ts +++ b/test/root/ChildMintableERC20Predicate.test.ts @@ -52,9 +52,14 @@ describe("ChildMintableERC20Predicate", () => { "ChildMintableERC20Predicate" ); childMintableERC20Predicate = await ChildMintableERC20Predicate.deploy(); - await childMintableERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childMintableERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childMintableERC20Predicate = ChildMintableERC20Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperChildMintableERC20Predicate = childMintableERC20Predicate.connect( @@ -320,7 +325,13 @@ describe("ChildMintableERC20Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); const stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "address", "uint256"], @@ -340,7 +351,13 @@ describe("ChildMintableERC20Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); await expect(childMintableERC20Predicate.withdraw(childToken.address, 1)).to.be.revertedWith( "ChildMintableERC20Predicate: UNMAPPED_TOKEN" diff --git a/test/root/ChildMintableERC721Predicate.test.ts b/test/root/ChildMintableERC721Predicate.test.ts index 8f55badf..7f6bac8f 100644 --- a/test/root/ChildMintableERC721Predicate.test.ts +++ b/test/root/ChildMintableERC721Predicate.test.ts @@ -56,9 +56,14 @@ describe("ChildMintableERC721Predicate", () => { "ChildMintableERC721Predicate" ); childMintableERC721Predicate = await ChildMintableERC721Predicate.deploy(); - await childMintableERC721Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childMintableERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childMintableERC721Predicate = ChildMintableERC721Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperChildMintableERC721Predicate = childMintableERC721Predicate.connect( @@ -399,7 +404,13 @@ describe("ChildMintableERC721Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256"], @@ -425,7 +436,13 @@ describe("ChildMintableERC721Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); await expect(exitHelperChildMintableERC721Predicate.withdraw(childToken.address, 0)).to.be.revertedWith( "ChildMintableERC721Predicate: UNMAPPED_TOKEN" diff --git a/test/root/ExitHelper.test.ts b/test/root/ExitHelper.test.ts index 8e283706..d32f7095 100644 --- a/test/root/ExitHelper.test.ts +++ b/test/root/ExitHelper.test.ts @@ -37,9 +37,19 @@ describe("ExitHelper", () => { checkpointManager = (await CheckpointManager.deploy(ethers.constants.AddressZero)) as CheckpointManager; await checkpointManager.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(checkpointManager.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + checkpointManager = CheckpointManager.attach(_proxy.address); + const ExitHelper = await ethers.getContractFactory("ExitHelper"); exitHelper = (await ExitHelper.deploy()) as ExitHelper; await exitHelper.deployed(); + + const _proxy2 = await TransparentUpgradeableProxy.deploy(exitHelper.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + exitHelper = ExitHelper.attach(_proxy2.address); }); it("Initialize CheckpointManager and validate initialization", async () => { diff --git a/test/root/RootERC1155Predicate.test.ts b/test/root/RootERC1155Predicate.test.ts index b7013967..f7b55c4d 100644 --- a/test/root/RootERC1155Predicate.test.ts +++ b/test/root/RootERC1155Predicate.test.ts @@ -35,7 +35,6 @@ describe("RootERC1155Predicate", () => { const ExitHelper: ExitHelper__factory = await ethers.getContractFactory("ExitHelper"); exitHelper = await ExitHelper.deploy(); - await exitHelper.deployed(); childERC1155Predicate = ethers.Wallet.createRandom().address; @@ -47,9 +46,14 @@ describe("RootERC1155Predicate", () => { const RootERC1155Predicate: RootERC1155Predicate__factory = await ethers.getContractFactory("RootERC1155Predicate"); rootERC1155Predicate = await RootERC1155Predicate.deploy(); - await rootERC1155Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy2 = await TransparentUpgradeableProxy.deploy(rootERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + rootERC1155Predicate = RootERC1155Predicate.attach(_proxy2.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperRootERC1155Predicate = rootERC1155Predicate.connect(await ethers.getSigner(exitHelper.address)); diff --git a/test/root/RootERC20Predicate.test.ts b/test/root/RootERC20Predicate.test.ts index d14ce640..7997d2e8 100644 --- a/test/root/RootERC20Predicate.test.ts +++ b/test/root/RootERC20Predicate.test.ts @@ -46,9 +46,14 @@ describe("RootERC20Predicate", () => { const RootERC20Predicate: RootERC20Predicate__factory = await ethers.getContractFactory("RootERC20Predicate"); rootERC20Predicate = await RootERC20Predicate.deploy(); - await rootERC20Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootERC20Predicate = RootERC20Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperRootERC20Predicate = rootERC20Predicate.connect(await ethers.getSigner(exitHelper.address)); diff --git a/test/root/RootERC721Predicate.test.ts b/test/root/RootERC721Predicate.test.ts index c32473af..a381d67b 100644 --- a/test/root/RootERC721Predicate.test.ts +++ b/test/root/RootERC721Predicate.test.ts @@ -46,9 +46,14 @@ describe("RootERC721Predicate", () => { const RootERC721Predicate: RootERC721Predicate__factory = await ethers.getContractFactory("RootERC721Predicate"); rootERC721Predicate = await RootERC721Predicate.deploy(); - await rootERC721Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootERC721Predicate = RootERC721Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperRootERC721Predicate = rootERC721Predicate.connect(await ethers.getSigner(exitHelper.address));