diff --git a/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsNode.sol b/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsNode.sol index 33e89ef7e..c52ab8d02 100644 --- a/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsNode.sol +++ b/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsNode.sol @@ -23,7 +23,6 @@ contract RocketDAOProtocolSettingsNode is RocketDAOProtocolSettings, RocketDAOPr setSettingBool("node.vacant.minipools.enabled", false); setSettingUint("node.per.minipool.stake.minimum", 0.1 ether); // 10% of user ETH value (matched ETH) setSettingUint("node.per.minipool.stake.maximum", 1.5 ether); // 150% of node ETH value (provided ETH) - setSettingUint("node.voting.power.stake.maximum", 1.5 ether); // 150% of node ETH value (provided ETH) // Settings initialised setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); } diff --git a/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsProposals.sol b/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsProposals.sol index 9317a7ae5..bce67e79a 100644 --- a/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsProposals.sol +++ b/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsProposals.sol @@ -9,6 +9,22 @@ contract RocketDAOProtocolSettingsProposals is RocketDAOProtocolSettings, Rocket constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "proposals") { version = 1; + // Initialize settings on deployment + if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { + // Init settings + setSettingUint("proposal.vote.phase1.time", 1 weeks); // How long a proposal can be voted on in phase 1 + setSettingUint("proposal.vote.phase2.time", 1 weeks); // How long a proposal can be voted on in phase 2 + setSettingUint("proposal.vote.delay.time", 1 weeks); // How long before a proposal can be voted on after it is created + setSettingUint("proposal.execute.time", 4 weeks); // How long a proposal can be executed after its voting period is finished + setSettingUint("proposal.bond", 100 ether); // The amount of RPL a proposer has to put up as a bond for creating a new proposal + setSettingUint("proposal.challenge.bond", 10 ether); // The amount of RPL a challenger has to put up as a bond for challenging a proposal + setSettingUint("proposal.challenge.period", 30 minutes); // The amount of time a proposer has to respond to a challenge before a proposal is defeated + setSettingUint("proposal.quorum", 0.51 ether); // The quorum required to pass a proposal + setSettingUint("proposal.veto.quorum", 0.51 ether); // The quorum required to veto a proposal + setSettingUint("proposal.max.block.age", 1024); // The maximum age of a block a proposal can be raised at + // Settings initialised + setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); + } } /// @notice Update a setting, overrides inherited setting method with extra checks for this contract diff --git a/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsSecurity.sol b/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsSecurity.sol index 1613e27fa..727bf0a46 100644 --- a/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsSecurity.sol +++ b/contracts/contract/dao/protocol/settings/RocketDAOProtocolSettingsSecurity.sol @@ -9,6 +9,29 @@ contract RocketDAOProtocolSettingsSecurity is RocketDAOProtocolSettings, RocketD constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "security") { version = 1; + // Initialize settings on deployment + if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { + // Init settings + setSettingUint("members.quorum", 0.5 ether); // Member quorum threshold that must be met for proposals to pass (51%) + setSettingUint("members.leave.time", 4 weeks); // How long a member must give notice for before manually leaving the security council + setSettingUint("proposal.vote.time", 2 weeks); // How long a proposal can be voted on + setSettingUint("proposal.execute.time", 4 weeks); // How long a proposal can be executed after its voting period is finished + setSettingUint("proposal.action.time", 4 weeks); // Certain proposals require a secondary action to be run after the proposal is successful (joining, leaving etc). This is how long until that action expires + + // Default permissions for security council + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "deposit", "deposit.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "deposit", "deposit.assign.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "minipool", "minipool.submit.withdrawable.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "minipool", "minipool.bond.reduction.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "network", "network.submit.balances.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "network", "network.submit.prices.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.registration.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.smoothing.pool.registration.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.deposit.enabled")), true); + setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.vacant.minipools.enabled")), true); + + setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); + } } /// @dev Overrides inherited setting method with extra sanity checks for this contract diff --git a/contracts/contract/network/RocketNetworkSnapshots.sol b/contracts/contract/network/RocketNetworkSnapshots.sol index 08b6b31d9..5c98c2b0b 100644 --- a/contracts/contract/network/RocketNetworkSnapshots.sol +++ b/contracts/contract/network/RocketNetworkSnapshots.sol @@ -14,6 +14,12 @@ contract RocketNetworkSnapshots is RocketBase, RocketNetworkSnapshotsInterface { constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { // Set contract version version = 1; + + // Setup for if this contract is being deployed as part of a new instance deployment + if (!rocketStorage.getDeployedStatus()) { + _insert(keccak256("network.prices.rpl"), 0.01 ether); + _insert(keccak256("node.voting.power.stake.maximum"), 1.5 ether); + } } function push(bytes32 _key, uint224 _value) onlyLatestContract("rocketNetworkSnapshots", address(this)) onlyLatestNetworkContract external { diff --git a/contracts/contract/rewards/RocketMerkleDistributorMainnet.sol b/contracts/contract/rewards/RocketMerkleDistributorMainnet.sol index c5ab312f8..68f0e11c1 100644 --- a/contracts/contract/rewards/RocketMerkleDistributorMainnet.sol +++ b/contracts/contract/rewards/RocketMerkleDistributorMainnet.sol @@ -37,6 +37,8 @@ contract RocketMerkleDistributorMainnet is RocketBase, RocketMerkleDistributorMa // Precompute keys rocketVaultKey = keccak256(abi.encodePacked("contract.address", "rocketVault")); rocketTokenRPLKey = keccak256(abi.encodePacked("contract.address", "rocketTokenRPL")); + // Set this contract as the relay for network 0 + setAddress(keccak256(abi.encodePacked("rewards.relay.address", uint256(0))), address(this)); } // Called by RocketRewardsPool to include a snapshot into this distributor diff --git a/contracts/contract/upgrade/RocketUpgradeOneDotThree.sol b/contracts/contract/upgrade/RocketUpgradeOneDotThree.sol deleted file mode 100644 index 2aa8c3d8a..000000000 --- a/contracts/contract/upgrade/RocketUpgradeOneDotThree.sol +++ /dev/null @@ -1,323 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.8.18; - -import "../RocketBase.sol"; -import "../../interface/network/RocketNetworkSnapshotsInterface.sol"; -import "../../interface/network/RocketNetworkPricesInterface.sol"; -import "../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterface.sol"; -import "../../interface/util/AddressSetStorageInterface.sol"; -import "../../interface/minipool/RocketMinipoolManagerInterface.sol"; - -/// @notice Transient contract to upgrade Rocket Pool with the Houston set of contract upgrades -contract RocketUpgradeOneDotThree is RocketBase { - - // Whether the upgrade has been performed or not - bool public executed; - - // Whether the contract is locked to further changes - bool public locked; - - // Upgrade contracts - address public newRocketDAOProtocol; - address public newRocketDAOProtocolProposals; - address public newRocketNetworkPrices; - address public newRocketNodeDeposit; - address public newRocketNodeManager; - address public newRocketNodeStaking; - address public newRocketClaimDAO; - address public newRocketDAOProtocolSettingsRewards; - address public newRocketMinipoolManager; - address public newRocketRewardsPool; - address public newRocketNetworkBalances; - address public newRocketDAOProtocolSettingsNetwork; - address public newRocketDAOProtocolSettingsAuction; - address public newRocketDAOProtocolSettingsDeposit; - address public newRocketDAOProtocolSettingsInflation; - address public newRocketDAOProtocolSettingsMinipool; - address public newRocketDAOProtocolSettingsNode; - address public newRocketMerkleDistributorMainnet; - address public rocketDAOProtocolVerifier; - address public rocketDAOProtocolSettingsProposals; - address public rocketDAOProtocolSettingsSecurity; - address public rocketDAOSecurity; - address public rocketDAOSecurityActions; - address public rocketDAOSecurityProposals; - address public rocketNetworkSnapshots; - address public rocketNetworkVoting; - address public rocketDAOProtocolProposal; - - // Upgrade ABIs - string public newRocketDAOProtocolAbi; - string public newRocketDAOProtocolProposalsAbi; - string public newRocketNetworkPricesAbi; - string public newRocketNodeDepositAbi; - string public newRocketNodeManagerAbi; - string public newRocketNodeStakingAbi; - string public newRocketClaimDAOAbi; - string public newRocketDAOProtocolSettingsRewardsAbi; - string public newRocketMinipoolManagerAbi; - string public newRocketRewardsPoolAbi; - string public newRocketNetworkBalancesAbi; - string public newRocketDAOProtocolSettingsNetworkAbi; - string public newRocketDAOProtocolSettingsAuctionAbi; - string public newRocketDAOProtocolSettingsDepositAbi; - string public newRocketDAOProtocolSettingsInflationAbi; - string public newRocketDAOProtocolSettingsMinipoolAbi; - string public newRocketDAOProtocolSettingsNodeAbi; - string public newRocketMerkleDistributorMainnetAbi; - string public rocketDAOProtocolVerifierAbi; - string public rocketDAOProtocolSettingsProposalsAbi; - string public rocketDAOProtocolSettingsSecurityAbi; - string public rocketDAOSecurityAbi; - string public rocketDAOSecurityActionsAbi; - string public rocketDAOSecurityProposalsAbi; - string public rocketNetworkSnapshotsAbi; - string public rocketNetworkVotingAbi; - string public rocketDAOProtocolProposalAbi; - - // Save deployer to limit access to set functions - address immutable deployer; - - // Construct - constructor( - RocketStorageInterface _rocketStorageAddress - ) RocketBase(_rocketStorageAddress) { - // Version - version = 1; - deployer = msg.sender; - } - - /// @notice Returns the address of the RocketStorage contract - function getRocketStorageAddress() external view returns (address) { - return address(rocketStorage); - } - - function set(address[] memory _addresses, string[] memory _abis) external { - require(msg.sender == deployer, "Only deployer"); - require(!locked, "Contract locked"); - - // Set contract addresses - newRocketDAOProtocol = _addresses[0]; - newRocketDAOProtocolProposals = _addresses[1]; - newRocketNetworkPrices = _addresses[2]; - newRocketNodeDeposit = _addresses[3]; - newRocketNodeManager = _addresses[4]; - newRocketNodeStaking = _addresses[5]; - newRocketClaimDAO = _addresses[6]; - newRocketDAOProtocolSettingsRewards = _addresses[7]; - newRocketMinipoolManager = _addresses[8]; - newRocketRewardsPool = _addresses[9]; - newRocketNetworkBalances = _addresses[10]; - newRocketDAOProtocolSettingsNetwork = _addresses[11]; - newRocketDAOProtocolSettingsAuction = _addresses[12]; - newRocketDAOProtocolSettingsDeposit = _addresses[13]; - newRocketDAOProtocolSettingsInflation = _addresses[14]; - newRocketDAOProtocolSettingsMinipool = _addresses[15]; - newRocketDAOProtocolSettingsNode = _addresses[16]; - newRocketMerkleDistributorMainnet = _addresses[17]; - rocketDAOProtocolVerifier = _addresses[18]; - rocketDAOProtocolSettingsProposals = _addresses[19]; - rocketDAOProtocolSettingsSecurity = _addresses[20]; - rocketDAOSecurity = _addresses[21]; - rocketDAOSecurityActions = _addresses[22]; - rocketDAOSecurityProposals = _addresses[23]; - rocketNetworkSnapshots = _addresses[24]; - rocketNetworkVoting = _addresses[25]; - rocketDAOProtocolProposal = _addresses[26]; - - // Set ABIs - newRocketDAOProtocolAbi = _abis[0]; - newRocketDAOProtocolProposalsAbi = _abis[1]; - newRocketNetworkPricesAbi = _abis[2]; - newRocketNodeDepositAbi = _abis[3]; - newRocketNodeManagerAbi = _abis[4]; - newRocketNodeStakingAbi = _abis[5]; - newRocketClaimDAOAbi = _abis[6]; - newRocketDAOProtocolSettingsRewardsAbi = _abis[7]; - newRocketMinipoolManagerAbi = _abis[8]; - newRocketRewardsPoolAbi = _abis[9]; - newRocketNetworkBalancesAbi = _abis[10]; - newRocketDAOProtocolSettingsNetworkAbi = _abis[11]; - newRocketDAOProtocolSettingsAuctionAbi = _abis[12]; - newRocketDAOProtocolSettingsDepositAbi = _abis[13]; - newRocketDAOProtocolSettingsInflationAbi = _abis[14]; - newRocketDAOProtocolSettingsMinipoolAbi = _abis[15]; - newRocketDAOProtocolSettingsNodeAbi = _abis[16]; - newRocketMerkleDistributorMainnetAbi = _abis[17]; - rocketDAOProtocolVerifierAbi = _abis[18]; - rocketDAOProtocolSettingsProposalsAbi = _abis[19]; - rocketDAOProtocolSettingsSecurityAbi = _abis[20]; - rocketDAOSecurityAbi = _abis[21]; - rocketDAOSecurityActionsAbi = _abis[22]; - rocketDAOSecurityProposalsAbi = _abis[23]; - rocketNetworkSnapshotsAbi = _abis[24]; - rocketNetworkVotingAbi = _abis[25]; - rocketDAOProtocolProposalAbi = _abis[26]; - } - - /// @notice Prevents further changes from being applied - function lock() external { - require(msg.sender == deployer, "Only deployer"); - locked = true; - } - - /// @notice Once this contract has been voted in by oDAO, guardian can perform the upgrade - function execute() external onlyGuardian { - require(!executed, "Already executed"); - executed = true; - - // Upgrade contracts - _upgradeContract("rocketDAOProtocol", newRocketDAOProtocol, newRocketDAOProtocolAbi); - _upgradeContract("rocketDAOProtocolProposals", newRocketDAOProtocolProposals, newRocketDAOProtocolProposalsAbi); - _upgradeContract("rocketNetworkPrices", newRocketNetworkPrices, newRocketNetworkPricesAbi); - _upgradeContract("rocketNodeDeposit", newRocketNodeDeposit, newRocketNodeDepositAbi); - _upgradeContract("rocketNodeManager", newRocketNodeManager, newRocketNodeManagerAbi); - _upgradeContract("rocketNodeStaking", newRocketNodeStaking, newRocketNodeStakingAbi); - _upgradeContract("rocketClaimDAO", newRocketClaimDAO, newRocketClaimDAOAbi); - _upgradeContract("rocketDAOProtocolSettingsRewards", newRocketDAOProtocolSettingsRewards, newRocketDAOProtocolSettingsRewardsAbi); - _upgradeContract("rocketMinipoolManager", newRocketMinipoolManager, newRocketMinipoolManagerAbi); - _upgradeContract("rocketRewardsPool", newRocketRewardsPool, newRocketRewardsPoolAbi); - _upgradeContract("rocketNetworkBalances", newRocketNetworkBalances, newRocketNetworkBalancesAbi); - _upgradeContract("rocketDAOProtocolSettingsNetwork", newRocketDAOProtocolSettingsNetwork, newRocketDAOProtocolSettingsNetworkAbi); - _upgradeContract("rocketDAOProtocolSettingsAuction", newRocketDAOProtocolSettingsAuction, newRocketDAOProtocolSettingsAuctionAbi); - _upgradeContract("rocketDAOProtocolSettingsDeposit", newRocketDAOProtocolSettingsDeposit, newRocketDAOProtocolSettingsDepositAbi); - _upgradeContract("rocketDAOProtocolSettingsInflation", newRocketDAOProtocolSettingsInflation, newRocketDAOProtocolSettingsInflationAbi); - _upgradeContract("rocketDAOProtocolSettingsMinipool", newRocketDAOProtocolSettingsMinipool, newRocketDAOProtocolSettingsMinipoolAbi); - _upgradeContract("rocketDAOProtocolSettingsNode", newRocketDAOProtocolSettingsNode, newRocketDAOProtocolSettingsNodeAbi); - _upgradeContract("rocketMerkleDistributorMainnet", newRocketMerkleDistributorMainnet, newRocketMerkleDistributorMainnetAbi); - - // Add new contracts - _addContract("rocketDAOProtocolVerifier", rocketDAOProtocolVerifier, rocketDAOProtocolVerifierAbi); - _addContract("rocketDAOProtocolSettingsProposals", rocketDAOProtocolSettingsProposals, rocketDAOProtocolSettingsProposalsAbi); - _addContract("rocketDAOProtocolSettingsSecurity", rocketDAOProtocolSettingsSecurity, rocketDAOProtocolSettingsSecurityAbi); - _addContract("rocketDAOSecurity", rocketDAOSecurity, rocketDAOSecurityAbi); - _addContract("rocketDAOSecurityActions", rocketDAOSecurityActions, rocketDAOSecurityActionsAbi); - _addContract("rocketDAOSecurityProposals", rocketDAOSecurityProposals, rocketDAOSecurityProposalsAbi); - _addContract("rocketNetworkSnapshots", rocketNetworkSnapshots, rocketNetworkSnapshotsAbi); - _addContract("rocketNetworkVoting", rocketNetworkVoting, rocketNetworkVotingAbi); - _addContract("rocketDAOProtocolProposal", rocketDAOProtocolProposal, rocketDAOProtocolProposalAbi); - - // Update the rewards relay address - bytes32 networkRelayKey = keccak256(abi.encodePacked("rewards.relay.address", uint256(0))); - setAddress(networkRelayKey, newRocketMerkleDistributorMainnet); - - // pDAO proposal settings - bytes32 settingNameSpace = keccak256(abi.encodePacked("dao.protocol.setting.", "proposals")); - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.vote.phase1.time")), 1 weeks); // How long a proposal can be voted on in phase 1 - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.vote.phase2.time")), 1 weeks); // How long a proposal can be voted on in phase 2 - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.vote.delay.time")), 1 weeks); // How long before a proposal can be voted on after it is created - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.execute.time")), 4 weeks); // How long a proposal can be executed after its voting period is finished - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.bond")), 100 ether); // The amount of RPL a proposer has to put up as a bond for creating a new proposal - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.challenge.bond")), 10 ether); // The amount of RPL a challenger has to put up as a bond for challenging a proposal - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.challenge.period")), 30 minutes); // The amount of time a proposer has to respond to a challenge before a proposal is defeated - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.quorum")), 0.51 ether); // The quorum required to pass a proposal - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.veto.quorum")), 0.51 ether); // The quorum required to veto a proposal - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.max.block.age")), 1024); // The maximum age of a block a proposal can be raised at - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - - // pDAO network settings - settingNameSpace = keccak256(abi.encodePacked("dao.protocol.setting.", "network")); - setUint(keccak256(abi.encodePacked(settingNameSpace, "network.submit.balances.frequency")), 1 days); // 24 hours - setUint(keccak256(abi.encodePacked(settingNameSpace, "network.submit.prices.frequency")), 1 days); // 24 hours - - // pDAO rewards settings - settingNameSpace = keccak256(abi.encodePacked("dao.protocol.setting.", "rewards")); - setUint(keccak256(abi.encodePacked(settingNameSpace, "rewards.claims", "periods")), 28); - - // pDAO security council settings - settingNameSpace = keccak256(abi.encodePacked("dao.protocol.setting.", "security")); - setUint(keccak256(abi.encodePacked(settingNameSpace, "members.quorum")), 0.51 ether); // Member quorum threshold that must be met for proposals to pass (51%) - setUint(keccak256(abi.encodePacked(settingNameSpace, "members.leave.time")), 4 weeks); // How long a member must give notice for before manually leaving the security council - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.vote.time")), 2 weeks); // How long a proposal can be voted on - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.execute.time")), 4 weeks); // How long a proposal can be executed after its voting period is finished - setUint(keccak256(abi.encodePacked(settingNameSpace, "proposal.action.time")), 4 weeks); // Certain proposals require a secondary action to be run after the proposal is successful (joining, leaving etc). This is how long until that action expires - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - - // Default permissions for security council - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "deposit", "deposit.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "deposit", "deposit.assign.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "minipool", "minipool.submit.withdrawable.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "minipool", "minipool.bond.reduction.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "network", "network.submit.balances.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "network", "network.submit.prices.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.registration.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.smoothing.pool.registration.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.deposit.enabled")), true); - setBool(keccak256(abi.encodePacked("dao.security.allowed.setting", "node", "node.vacant.minipools.enabled")), true); - - // Initialise RPL price in snapshot system - RocketNetworkSnapshotsInterface rocketNetworkSnapshots = RocketNetworkSnapshotsInterface(getContractAddress("rocketNetworkSnapshots")); - RocketNetworkPricesInterface rocketNetworkPrices = RocketNetworkPricesInterface(getContractAddress("rocketNetworkPrices")); - bytes32 snapshotKey = keccak256("network.prices.rpl"); - rocketNetworkSnapshots.push(snapshotKey, uint224(rocketNetworkPrices.getRPLPrice())); - - // Add snapshot entry for maximum RPL stake voting power (150%) - snapshotKey = keccak256(bytes("node.voting.power.stake.maximum")); - rocketNetworkSnapshots.push(snapshotKey, 1.5 ether); - - // Add node count snapshot entry - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - bytes32 nodeIndexKey = keccak256(abi.encodePacked("nodes.index")); - rocketNetworkSnapshots.push(keccak256(abi.encodePacked("node.count")), uint224(addressSetStorage.getCount(nodeIndexKey))); - - // Set a protocol version value in storage for convenience with bindings - setString(keccak256(abi.encodePacked("protocol.version")), "1.3.0"); - } - - /// @notice Used to fix incorrect mapping of pubkey to minipool caused by a bug in previous release - function fixPubkeys(address[] calldata _minipoolAddresses) external onlyGuardian { - for (uint256 i = 0; i < _minipoolAddresses.length; ++i) { - address minipoolAddress = _minipoolAddresses[i]; - // Require minipool exists - require(getBool(keccak256(abi.encodePacked("minipool.exists", minipoolAddress))), "Minipool does not exist"); - // Check the minipool hasn't been dissolved as this could prevent a failed vacant minipool from trying again - RocketMinipoolInterface minipool = RocketMinipoolInterface(minipoolAddress); - require(minipool.getStatus() != MinipoolStatus.Dissolved, "Minipool was dissolved"); - // Update reverse lookup - bytes memory pubkey = getBytes(keccak256(abi.encodePacked("minipool.pubkey", minipoolAddress))); - setAddress(keccak256(abi.encodePacked("validator.minipool", pubkey)), minipoolAddress); - } - } - - /// @dev Add a new network contract - function _addContract(string memory _name, address _contractAddress, string memory _contractAbi) internal { - // Check contract name - require(bytes(_name).length > 0, "Invalid contract name"); - // Cannot add contract if it already exists (use upgradeContract instead) - require(getAddress(keccak256(abi.encodePacked("contract.address", _name))) == address(0x0), "Contract name is already in use"); - // Cannot add contract if already in use as ABI only - string memory existingAbi = getString(keccak256(abi.encodePacked("contract.abi", _name))); - require(bytes(existingAbi).length == 0, "Contract name is already in use"); - // Check contract address - require(_contractAddress != address(0x0), "Invalid contract address"); - require(!getBool(keccak256(abi.encodePacked("contract.exists", _contractAddress))), "Contract address is already in use"); - // Check ABI isn't empty - require(bytes(_contractAbi).length > 0, "Empty ABI is invalid"); - // Register contract - setBool(keccak256(abi.encodePacked("contract.exists", _contractAddress)), true); - setString(keccak256(abi.encodePacked("contract.name", _contractAddress)), _name); - setAddress(keccak256(abi.encodePacked("contract.address", _name)), _contractAddress); - setString(keccak256(abi.encodePacked("contract.abi", _name)), _contractAbi); - } - - /// @dev Upgrade a network contract - function _upgradeContract(string memory _name, address _contractAddress, string memory _contractAbi) internal { - // Get old contract address & check contract exists - address oldContractAddress = getAddress(keccak256(abi.encodePacked("contract.address", _name))); - require(oldContractAddress != address(0x0), "Contract does not exist"); - // Check new contract address - require(_contractAddress != address(0x0), "Invalid contract address"); - require(_contractAddress != oldContractAddress, "The contract address cannot be set to its current address"); - require(!getBool(keccak256(abi.encodePacked("contract.exists", _contractAddress))), "Contract address is already in use"); - // Check ABI isn't empty - require(bytes(_contractAbi).length > 0, "Empty ABI is invalid"); - // Register new contract - setBool(keccak256(abi.encodePacked("contract.exists", _contractAddress)), true); - setString(keccak256(abi.encodePacked("contract.name", _contractAddress)), _name); - setAddress(keccak256(abi.encodePacked("contract.address", _name)), _contractAddress); - setString(keccak256(abi.encodePacked("contract.abi", _name)), _contractAbi); - // Deregister old contract - deleteString(keccak256(abi.encodePacked("contract.name", oldContractAddress))); - deleteBool(keccak256(abi.encodePacked("contract.exists", oldContractAddress))); - } -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/RocketDAOProtocolOld.sol b/contracts/old/contract/dao/protocol/RocketDAOProtocolOld.sol deleted file mode 100644 index 0339a23c4..000000000 --- a/contracts/old/contract/dao/protocol/RocketDAOProtocolOld.sol +++ /dev/null @@ -1,83 +0,0 @@ -pragma solidity 0.7.6; -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../contract/RocketBase.sol"; -import "../../../interface/dao/protocol/RocketDAOProtocolInterfaceOld.sol"; -import "../../../interface/dao/protocol/RocketDAOProtocolProposalsInterfaceOld.sol"; -import "../../../../types/SettingType.sol"; - - -// The Rocket Pool Network DAO - This is a placeholder for the network DAO to come -contract RocketDAOProtocolOld is RocketBase, RocketDAOProtocolInterfaceOld { - - // The namespace for any data stored in the network DAO (do not change) - string constant daoNameSpace = "dao.protocol."; - - // Only allow bootstrapping when enabled - modifier onlyBootstrapMode() { - require(getBootstrapModeDisabled() == false, "Bootstrap mode not engaged"); - _; - } - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - // Version - version = 1; - } - - - /**** DAO Properties **************/ - - // Returns true if bootstrap mode is disabled - function getBootstrapModeDisabled() override public view returns (bool) { - return getBool(keccak256(abi.encodePacked(daoNameSpace, "bootstrapmode.disabled"))); - } - - - /**** Bootstrapping ***************/ - // While bootstrap mode is engaged, RP can change settings alongside the DAO (when its implemented). When disabled, only DAO will be able to control settings - - // Bootstrap mode - multi Setting - function bootstrapSettingMulti(string[] memory _settingContractNames, string[] memory _settingPaths, SettingType[] memory _types, bytes[] memory _values) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - // Ok good to go, lets update the settings - RocketDAOProtocolProposalsInterfaceOld(getContractAddress("rocketDAOProtocolProposals")).proposalSettingMulti(_settingContractNames, _settingPaths, _types, _values); - } - - // Bootstrap mode - Uint Setting - function bootstrapSettingUint(string memory _settingContractName, string memory _settingPath, uint256 _value) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - // Ok good to go, lets update the settings - RocketDAOProtocolProposalsInterfaceOld(getContractAddress("rocketDAOProtocolProposals")).proposalSettingUint(_settingContractName, _settingPath, _value); - } - - // Bootstrap mode - Bool Setting - function bootstrapSettingBool(string memory _settingContractName, string memory _settingPath, bool _value) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - // Ok good to go, lets update the settings - RocketDAOProtocolProposalsInterfaceOld(getContractAddress("rocketDAOProtocolProposals")).proposalSettingBool(_settingContractName, _settingPath, _value); - } - - // Bootstrap mode - Address Setting - function bootstrapSettingAddress(string memory _settingContractName, string memory _settingPath, address _value) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - // Ok good to go, lets update the settings - RocketDAOProtocolProposalsInterfaceOld(getContractAddress("rocketDAOProtocolProposals")).proposalSettingAddress(_settingContractName, _settingPath, _value); - } - - // Bootstrap mode - Set a claiming contract to receive a % of RPL inflation rewards - function bootstrapSettingClaimer(string memory _contractName, uint256 _perc) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - // Ok good to go, lets update the rewards claiming contract amount - RocketDAOProtocolProposalsInterfaceOld(getContractAddress("rocketDAOProtocolProposals")).proposalSettingRewardsClaimer(_contractName, _perc); - } - - // Bootstrap mode -Spend DAO treasury - function bootstrapSpendTreasury(string memory _invoiceID, address _recipientAddress, uint256 _amount) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - RocketDAOProtocolProposalsInterfaceOld(getContractAddress("rocketDAOProtocolProposals")).proposalSpendTreasury(_invoiceID, _recipientAddress, _amount); - } - - // Bootstrap mode - Disable RP Access (only RP can call this to hand over full control to the DAO) - function bootstrapDisable(bool _confirmDisableBootstrapMode) override external onlyGuardian onlyBootstrapMode onlyLatestContract("rocketDAOProtocol", address(this)) { - require(_confirmDisableBootstrapMode == true, "You must confirm disabling bootstrap mode, it can only be done once!"); - setBool(keccak256(abi.encodePacked(daoNameSpace, "bootstrapmode.disabled")), true); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/RocketDAOProtocolProposalsOld.sol b/contracts/old/contract/dao/protocol/RocketDAOProtocolProposalsOld.sol deleted file mode 100644 index 8829ae9b2..000000000 --- a/contracts/old/contract/dao/protocol/RocketDAOProtocolProposalsOld.sol +++ /dev/null @@ -1,103 +0,0 @@ -pragma solidity 0.7.6; -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../contract/RocketBase.sol"; -import "../../../interface/dao/protocol/RocketDAOProtocolInterfaceOld.sol"; -import "../../../interface/dao/protocol/RocketDAOProtocolProposalsInterfaceOld.sol"; -import "../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterfaceOld.sol"; -import "../../../../interface/rewards/claims/RocketClaimDAOInterface.sol"; -import "../../../../types/SettingType.sol"; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - - -// The protocol DAO Proposals - Placeholder contracts until DAO is implemented -contract RocketDAOProtocolProposalsOld is RocketBase, RocketDAOProtocolProposalsInterfaceOld { - - using SafeMath for uint; - - // The namespace for any data stored in the trusted node DAO (do not change) - string constant daoNameSpace = "dao.protocol."; - - // Only allow certain contracts to execute methods - modifier onlyExecutingContracts() { - // Methods are either executed by bootstrapping methods in rocketDAONodeTrusted or by people executing passed proposals in rocketDAOProposal - require(msg.sender == getContractAddress("rocketDAOProtocol") || msg.sender == getContractAddress("rocketDAOProposal"), "Sender is not permitted to access executing methods"); - _; - } - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - // Version - version = 1; - } - - - /*** Proposals **********************/ - - // Set multiple settings in one proposal - function proposalSettingMulti(string[] memory _settingContractNames, string[] memory _settingPaths, SettingType[] memory _types, bytes[] memory _data) override external onlyExecutingContracts() { - // Check lengths of all arguments are the same - require(_settingContractNames.length == _settingPaths.length && _settingPaths.length == _types.length && _types.length == _data.length, "Invalid parameters supplied"); - // Loop through settings - for (uint256 i = 0; i < _settingContractNames.length; i++) { - if (_types[i] == SettingType.UINT256) { - uint256 value = abi.decode(_data[i], (uint256)); - proposalSettingUint(_settingContractNames[i], _settingPaths[i], value); - } else if (_types[i] == SettingType.BOOL) { - bool value = abi.decode(_data[i], (bool)); - proposalSettingBool(_settingContractNames[i], _settingPaths[i], value); - } else if (_types[i] == SettingType.ADDRESS) { - address value = abi.decode(_data[i], (address)); - proposalSettingAddress(_settingContractNames[i], _settingPaths[i], value); - } else { - revert("Invalid setting type"); - } - } - } - - // Change one of the current uint256 settings of the protocol DAO - function proposalSettingUint(string memory _settingContractName, string memory _settingPath, uint256 _value) override public onlyExecutingContracts() { - // Load contracts - RocketDAOProtocolSettingsInterface rocketDAOProtocolSettings = RocketDAOProtocolSettingsInterface(getContractAddress(_settingContractName)); - // Lets update - rocketDAOProtocolSettings.setSettingUint(_settingPath, _value); - } - - // Change one of the current bool settings of the protocol DAO - function proposalSettingBool(string memory _settingContractName, string memory _settingPath, bool _value) override public onlyExecutingContracts() { - // Load contracts - RocketDAOProtocolSettingsInterface rocketDAOProtocolSettings = RocketDAOProtocolSettingsInterface(getContractAddress(_settingContractName)); - // Lets update - rocketDAOProtocolSettings.setSettingBool(_settingPath, _value); - } - - // Change one of the current address settings of the protocol DAO - function proposalSettingAddress(string memory _settingContractName, string memory _settingPath, address _value) override public onlyExecutingContracts() { - // Load contracts - RocketDAOProtocolSettingsInterface rocketDAOProtocolSettings = RocketDAOProtocolSettingsInterface(getContractAddress(_settingContractName)); - // Lets update - rocketDAOProtocolSettings.setSettingAddress(_settingPath, _value); - } - - // Update a claimer for the rpl rewards, must specify a unique contract name that will be claiming from and a percentage of the rewards - function proposalSettingRewardsClaimer(string memory _contractName, uint256 _perc) override external onlyExecutingContracts() { - // Load contracts - RocketDAOProtocolSettingsRewardsInterfaceOld rocketDAOProtocolSettingsRewards = RocketDAOProtocolSettingsRewardsInterfaceOld(getContractAddress("rocketDAOProtocolSettingsRewards")); - // Update now - rocketDAOProtocolSettingsRewards.setSettingRewardsClaimer(_contractName, _perc); - } - - // Spend RPL from the DAO's treasury - function proposalSpendTreasury(string memory _invoiceID, address _recipientAddress, uint256 _amount) override external onlyExecutingContracts() { - // Load contracts - RocketClaimDAOInterface rocketDAOTreasury = RocketClaimDAOInterface(getContractAddress("rocketClaimDAO")); - // Update now - rocketDAOTreasury.spend(_invoiceID, _recipientAddress, _amount); - } - - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsAuctionOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsAuctionOld.sol deleted file mode 100644 index 2e482e4f4..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsAuctionOld.sol +++ /dev/null @@ -1,68 +0,0 @@ -pragma solidity 0.7.6; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; -import "../../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsAuctionInterface.sol"; - - -// Network auction settings - -contract RocketDAOProtocolSettingsAuctionOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsAuctionInterface { - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "auction") { - // Set version - version = 1; - // Initialize settings on deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // Apply settings - setSettingBool("auction.lot.create.enabled", true); - setSettingBool("auction.lot.bidding.enabled", true); - setSettingUint("auction.lot.value.minimum", 1 ether); - setSettingUint("auction.lot.value.maximum", 10 ether); - setSettingUint("auction.lot.duration", 40320); // 7 days - setSettingUint("auction.price.start", 1 ether); // 100% - setSettingUint("auction.price.reserve", 0.5 ether); // 50% - // Settings initialised - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - } - } - - - // Lot creation currently enabled - function getCreateLotEnabled() override external view returns (bool) { - return getSettingBool("auction.lot.create.enabled"); - } - - // Bidding on lots currently enabled - function getBidOnLotEnabled() override external view returns (bool) { - return getSettingBool("auction.lot.bidding.enabled"); - } - - // The minimum lot size relative to ETH value - function getLotMinimumEthValue() override external view returns (uint256) { - return getSettingUint("auction.lot.value.minimum"); - } - - // The maximum lot size relative to ETH value - function getLotMaximumEthValue() override external view returns (uint256) { - return getSettingUint("auction.lot.value.maximum"); - } - - // The maximum auction duration in blocks - function getLotDuration() override external view returns (uint256) { - return getSettingUint("auction.lot.duration"); - } - - // The starting price relative to current RPL price, as a fraction of 1 ether - function getStartingPriceRatio() override external view returns (uint256) { - return getSettingUint("auction.price.start"); - } - - // The reserve price relative to current RPL price, as a fraction of 1 ether - function getReservePriceRatio() override external view returns (uint256) { - return getSettingUint("auction.price.reserve"); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsDepositOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsDepositOld.sol deleted file mode 100644 index da0a240bb..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsDepositOld.sol +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.7.6; - -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; -import "../../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsDepositInterface.sol"; - - -/// @notice Network deposit settings -contract RocketDAOProtocolSettingsDepositOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsDepositInterface { - - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "deposit") { - // Set version - version = 3; - // Initialize settings on deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // Apply settings - setSettingBool("deposit.enabled", false); - setSettingBool("deposit.assign.enabled", true); - setSettingUint("deposit.minimum", 0.01 ether); - setSettingUint("deposit.pool.maximum", 160 ether); - setSettingUint("deposit.assign.maximum", 90); - setSettingUint("deposit.assign.socialised.maximum", 2); - setSettingUint("deposit.fee", 0.0005 ether); // Set to approx. 1 day of rewards at 18.25% APR - // Settings initialised - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - } - } - - /// @notice Returns true if deposits are currently enabled - function getDepositEnabled() override external view returns (bool) { - return getSettingBool("deposit.enabled"); - } - - /// @notice Returns true if deposit assignments are currently enabled - function getAssignDepositsEnabled() override external view returns (bool) { - return getSettingBool("deposit.assign.enabled"); - } - - /// @notice Returns the minimum deposit size - function getMinimumDeposit() override external view returns (uint256) { - return getSettingUint("deposit.minimum"); - } - - /// @notice Returns the maximum size of the deposit pool - function getMaximumDepositPoolSize() override external view returns (uint256) { - return getSettingUint("deposit.pool.maximum"); - } - - /// @notice Returns the maximum number of deposit assignments to perform at once - function getMaximumDepositAssignments() override external view returns (uint256) { - return getSettingUint("deposit.assign.maximum"); - } - - /// @notice Returns the maximum number of socialised (ie, not related to deposit size) assignments to perform - function getMaximumDepositSocialisedAssignments() override external view returns (uint256) { - return getSettingUint("deposit.assign.socialised.maximum"); - } - - /// @notice Returns the current fee paid on user deposits - function getDepositFee() override external view returns (uint256) { - return getSettingUint("deposit.fee"); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsInflationOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsInflationOld.sol deleted file mode 100644 index 421f06017..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsInflationOld.sol +++ /dev/null @@ -1,70 +0,0 @@ -pragma solidity 0.7.6; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; -import "../../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsInflationInterface.sol"; -import "../../../../../interface/token/RocketTokenRPLInterface.sol"; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -// RPL Inflation settings in RP which the DAO will have full control over -contract RocketDAOProtocolSettingsInflationOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsInflationInterface { - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "inflation") { - // Set version - version = 1; - // Set some initial settings on first deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // RPL Inflation settings - setSettingUint("rpl.inflation.interval.rate", 1000133680617113500); // 5% annual calculated on a daily interval - Calculate in js example: let dailyInflation = web3.utils.toBN((1 + 0.05) ** (1 / (365)) * 1e18); - setSettingUint("rpl.inflation.interval.start", block.timestamp + 1 days); // Set the default start date for inflation to begin as 1 day after deployment - // Deployment check - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); // Flag that this contract has been deployed, so default settings don't get reapplied on a contract upgrade - } - } - - - - /*** Set Uint *****************************************/ - - // Update a setting, overrides inherited setting method with extra checks for this contract - function setSettingUint(string memory _settingPath, uint256 _value) override public onlyDAOProtocolProposal { - // Some safety guards for certain settings - // The start time for inflation must be in the future and cannot be set again once started - bytes32 settingKey = keccak256(bytes(_settingPath)); - if(settingKey == keccak256(bytes("rpl.inflation.interval.start"))) { - // Must be a future timestamp - require(_value > block.timestamp, "Inflation interval start time must be in the future"); - // If it's already set and started, a new start block cannot be set - if(getInflationIntervalStartTime() > 0) { - require(getInflationIntervalStartTime() > block.timestamp, "Inflation has already started"); - } - } else if(settingKey == keccak256(bytes("rpl.inflation.interval.rate"))) { - // RPL contract address - address rplContractAddress = getContractAddressUnsafe("rocketTokenRPL"); - if(rplContractAddress != address(0x0)) { - // Force inflation at old rate before updating inflation rate - RocketTokenRPLInterface rplContract = RocketTokenRPLInterface(rplContractAddress); - // Mint any new tokens from the RPL inflation - rplContract.inflationMintTokens(); - } - } - // Update setting now - setUint(keccak256(abi.encodePacked(settingNameSpace, _settingPath)), _value); - } - - /*** RPL Contract Settings *****************************************/ - - // RPL yearly inflation rate per interval (daily by default) - function getInflationIntervalRate() override external view returns (uint256) { - return getSettingUint("rpl.inflation.interval.rate"); - } - - // The block to start inflation at - function getInflationIntervalStartTime() override public view returns (uint256) { - return getSettingUint("rpl.inflation.interval.start"); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolOld.sol deleted file mode 100644 index 6ab9861d8..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolOld.sol +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.7.6; - -import "@openzeppelin/contracts/math/SafeMath.sol"; -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; -import "../../../../../interface/dao/node/settings/RocketDAONodeTrustedSettingsMinipoolInterface.sol"; -import "../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterfaceOld.sol"; - - -/// @notice Network minipool settings -contract RocketDAOProtocolSettingsMinipoolOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsMinipoolInterfaceOld { - - // Libs - using SafeMath for uint; - - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "minipool") { - // Set version - version = 2; - // Initialize settings on deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // Apply settings - setSettingBool("minipool.submit.withdrawable.enabled", false); - setSettingBool("minipool.bond.reduction.enabled", false); - setSettingUint("minipool.launch.timeout", 72 hours); - setSettingUint("minipool.maximum.count", 14); - setSettingUint("minipool.user.distribute.window.start", 14 days); - setSettingUint("minipool.user.distribute.window.length", 2 days); - // Settings initialised - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - } - } - - /// @notice Update a setting, overrides inherited setting method with extra checks for this contract - /// @param _settingPath The path of the setting within this contract's namespace - /// @param _value The value to set it to - function setSettingUint(string memory _settingPath, uint256 _value) override public onlyDAOProtocolProposal { - // Some safety guards for certain settings - if(getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - if(keccak256(abi.encodePacked(_settingPath)) == keccak256(abi.encodePacked("minipool.launch.timeout"))) { - RocketDAONodeTrustedSettingsMinipoolInterface rocketDAONodeTrustedSettingsMinipool = RocketDAONodeTrustedSettingsMinipoolInterface(getContractAddress("rocketDAONodeTrustedSettingsMinipool")); - require(_value >= (rocketDAONodeTrustedSettingsMinipool.getScrubPeriod().add(1 hours)), "Launch timeout must be greater than scrub period"); - } - } - // Update setting now - setUint(keccak256(abi.encodePacked(settingNameSpace, _settingPath)), _value); - } - - /// @notice Returns the balance required to launch minipool - function getLaunchBalance() override public pure returns (uint256) { - return 32 ether; - } - - /// @notice Returns the value required to pre-launch a minipool - function getPreLaunchValue() override public pure returns (uint256) { - return 1 ether; - } - - /// @notice Returns the deposit amount for a given deposit type (only used for legacy minipool types) - function getDepositUserAmount(MinipoolDeposit _depositType) override external pure returns (uint256) { - if (_depositType == MinipoolDeposit.Full) { return getFullDepositUserAmount(); } - if (_depositType == MinipoolDeposit.Half) { return getHalfDepositUserAmount(); } - return 0; - } - - /// @notice Returns the user amount for a "Full" deposit minipool - function getFullDepositUserAmount() override public pure returns (uint256) { - return getLaunchBalance().div(2); - } - - /// @notice Returns the user amount for a "Half" deposit minipool - function getHalfDepositUserAmount() override public pure returns (uint256) { - return getLaunchBalance().div(2); - } - - /// @notice Returns the amount a "Variable" minipool requires to move to staking status - function getVariableDepositAmount() override public pure returns (uint256) { - return getLaunchBalance().sub(getPreLaunchValue()); - } - - /// @notice Submit minipool withdrawable events currently enabled (trusted nodes only) - function getSubmitWithdrawableEnabled() override external view returns (bool) { - return getSettingBool("minipool.submit.withdrawable.enabled"); - } - - /// @notice Returns true if bond reductions are currentl enabled - function getBondReductionEnabled() override external view returns (bool) { - return getSettingBool("minipool.bond.reduction.enabled"); - } - - /// @notice Returns the timeout period in seconds for prelaunch minipools to launch - function getLaunchTimeout() override external view returns (uint256) { - return getSettingUint("minipool.launch.timeout"); - } - - /// @notice Returns the maximum number of minipools allowed at one time - function getMaximumCount() override external view returns (uint256) { - return getSettingUint("minipool.maximum.count"); - } - - /// @notice Returns true if the given time is within the user distribute window - function isWithinUserDistributeWindow(uint256 _time) override external view returns (bool) { - uint256 start = getUserDistributeWindowStart(); - uint256 length = getUserDistributeWindowLength(); - return (_time >= start && _time < (start.add(length))); - } - - /// @notice Returns true if the given time has passed the distribute window - function hasUserDistributeWindowPassed(uint256 _time) override external view returns (bool) { - uint256 start = getUserDistributeWindowStart(); - uint256 length = getUserDistributeWindowLength(); - return _time >= start.add(length); - } - - /// @notice Returns the start of the user distribute window - function getUserDistributeWindowStart() override public view returns (uint256) { - return getSettingUint("minipool.user.distribute.window.start"); - } - - /// @notice Returns the length of the user distribute window - function getUserDistributeWindowLength() override public view returns (uint256) { - return getSettingUint("minipool.user.distribute.window.length"); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsNetworkOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsNetworkOld.sol deleted file mode 100644 index d15debba9..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsNetworkOld.sol +++ /dev/null @@ -1,117 +0,0 @@ -pragma solidity 0.7.6; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; -import "../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterfaceOld.sol"; - -// Network auction settings - -contract RocketDAOProtocolSettingsNetworkOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsNetworkInterfaceOld { - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "network") { - // Set version - version = 2; - // Initialize settings on deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // Apply settings - setSettingUint("network.consensus.threshold", 0.51 ether); // 51% - setSettingBool("network.submit.balances.enabled", true); - setSettingUint("network.submit.balances.frequency", 5760); // ~24 hours - setSettingBool("network.submit.prices.enabled", true); - setSettingUint("network.submit.prices.frequency", 5760); // ~24 hours - setSettingUint("network.node.fee.minimum", 0.15 ether); // 15% - setSettingUint("network.node.fee.target", 0.15 ether); // 15% - setSettingUint("network.node.fee.maximum", 0.15 ether); // 15% - setSettingUint("network.node.fee.demand.range", 160 ether); - setSettingUint("network.reth.collateral.target", 0.1 ether); - setSettingUint("network.penalty.threshold", 0.51 ether); // Consensus for penalties requires 51% vote - setSettingUint("network.penalty.per.rate", 0.1 ether); // 10% per penalty - setSettingBool("network.submit.rewards.enabled", true); // Enable reward submission - // Settings initialised - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - } - } - - // Update a setting, overrides inherited setting method with extra checks for this contract - function setSettingUint(string memory _settingPath, uint256 _value) override public onlyDAOProtocolProposal { - // Some safety guards for certain settings - // Prevent DAO from setting the withdraw delay greater than ~24 hours - if(keccak256(bytes(_settingPath)) == keccak256(bytes("network.reth.deposit.delay"))) { - // Must be a future timestamp - require(_value <= 5760, "rETH deposit delay cannot exceed 5760 blocks"); - } - // Update setting now - setUint(keccak256(abi.encodePacked(settingNameSpace, _settingPath)), _value); - } - - // The threshold of trusted nodes that must reach consensus on oracle data to commit it - function getNodeConsensusThreshold() override external view returns (uint256) { - return getSettingUint("network.consensus.threshold"); - } - - // The threshold of trusted nodes that must reach consensus on a penalty - function getNodePenaltyThreshold() override external view returns (uint256) { - return getSettingUint("network.penalty.threshold"); - } - - // The amount to penalise a minipool for each feeDistributor infraction - function getPerPenaltyRate() override external view returns (uint256) { - return getSettingUint("network.penalty.per.rate"); - } - - // Submit balances currently enabled (trusted nodes only) - function getSubmitBalancesEnabled() override external view returns (bool) { - return getSettingBool("network.submit.balances.enabled"); - } - - // The frequency in blocks at which network balances should be submitted by trusted nodes - function getSubmitBalancesFrequency() override external view returns (uint256) { - return getSettingUint("network.submit.balances.frequency"); - } - - // Submit prices currently enabled (trusted nodes only) - function getSubmitPricesEnabled() override external view returns (bool) { - return getSettingBool("network.submit.prices.enabled"); - } - - // The frequency in blocks at which network prices should be submitted by trusted nodes - function getSubmitPricesFrequency() override external view returns (uint256) { - return getSettingUint("network.submit.prices.frequency"); - } - - // The minimum node commission rate as a fraction of 1 ether - function getMinimumNodeFee() override external view returns (uint256) { - return getSettingUint("network.node.fee.minimum"); - } - - // The target node commission rate as a fraction of 1 ether - function getTargetNodeFee() override external view returns (uint256) { - return getSettingUint("network.node.fee.target"); - } - - // The maximum node commission rate as a fraction of 1 ether - function getMaximumNodeFee() override external view returns (uint256) { - return getSettingUint("network.node.fee.maximum"); - } - - // The range of node demand values to base fee calculations on (from negative to positive value) - function getNodeFeeDemandRange() override external view returns (uint256) { - return getSettingUint("network.node.fee.demand.range"); - } - - // Target rETH collateralization rate as a fraction of 1 ether - function getTargetRethCollateralRate() override external view returns (uint256) { - return getSettingUint("network.reth.collateral.target"); - } - - // rETH withdraw delay in blocks - function getRethDepositDelay() override external view returns (uint256) { - return getSettingUint("network.reth.deposit.delay"); - } - - // Submit reward snapshots currently enabled (trusted nodes only) - function getSubmitRewardsEnabled() override external view returns (bool) { - return getSettingBool("network.submit.rewards.enabled"); - } -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsNodeOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsNodeOld.sol deleted file mode 100644 index 1a991a9e3..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsNodeOld.sol +++ /dev/null @@ -1,62 +0,0 @@ -pragma solidity 0.7.6; - -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; -import "../../../../../interface/network/RocketNetworkSnapshotsInterface.sol"; -import "../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterfaceOld.sol"; - -// SPDX-License-Identifier: GPL-3.0-only - - -// Network auction settings - -contract RocketDAOProtocolSettingsNodeOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsNodeInterfaceOld { - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "node") { - // Set version - version = 3; - // Initialize settings on deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // Apply settings - setSettingBool("node.registration.enabled", false); - setSettingBool("node.smoothing.pool.registration.enabled", true); - setSettingBool("node.deposit.enabled", false); - setSettingBool("node.vacant.minipools.enabled", false); - setSettingUint("node.per.minipool.stake.minimum", 0.1 ether); // 10% of user ETH value (matched ETH) - setSettingUint("node.per.minipool.stake.maximum", 1.5 ether); // 150% of node ETH value (provided ETH) - // Settings initialised - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); - } - } - - // Node registrations currently enabled - function getRegistrationEnabled() override external view returns (bool) { - return getSettingBool("node.registration.enabled"); - } - - // Node smoothing pool registrations currently enabled - function getSmoothingPoolRegistrationEnabled() override external view returns (bool) { - return getSettingBool("node.smoothing.pool.registration.enabled"); - } - - // Node deposits currently enabled - function getDepositEnabled() override external view returns (bool) { - return getSettingBool("node.deposit.enabled"); - } - - // Vacant minipools currently enabled - function getVacantMinipoolsEnabled() override external view returns (bool) { - return getSettingBool("node.vacant.minipools.enabled"); - } - - // Minimum RPL stake per minipool as a fraction of assigned user ETH value - function getMinimumPerMinipoolStake() override external view returns (uint256) { - return getSettingUint("node.per.minipool.stake.minimum"); - } - - // Maximum RPL stake per minipool as a fraction of assigned user ETH value - function getMaximumPerMinipoolStake() override external view returns (uint256) { - return getSettingUint("node.per.minipool.stake.maximum"); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsRewardsOld.sol b/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsRewardsOld.sol deleted file mode 100644 index c268ecd9c..000000000 --- a/contracts/old/contract/dao/protocol/settings/RocketDAOProtocolSettingsRewardsOld.sol +++ /dev/null @@ -1,81 +0,0 @@ -pragma solidity 0.7.6; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterfaceOld.sol"; -import "../../../../../contract/dao/protocol/settings/RocketDAOProtocolSettings.sol"; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -// Settings in RP which the DAO will have full control over -contract RocketDAOProtocolSettingsRewardsOld is RocketDAOProtocolSettings, RocketDAOProtocolSettingsRewardsInterfaceOld { - - using SafeMath for uint; - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketDAOProtocolSettings(_rocketStorageAddress, "rewards") { - // Set version - version = 1; - // Set some initial settings on first deployment - if(!getBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")))) { - // Each of the initial RPL reward claiming contracts - setSettingRewardsClaimer('rocketClaimDAO', 0.1 ether); // DAO Rewards claim % amount - Percentage given of 1 ether - setSettingRewardsClaimer('rocketClaimNode', 0.70 ether); // Bonded Node Rewards claim % amount - Percentage given of 1 ether - setSettingRewardsClaimer('rocketClaimTrustedNode', 0.2 ether); // Trusted Node Rewards claim % amount - Percentage given of 1 ether - // RPL Claims settings - setSettingUint("rpl.rewards.claim.period.time", 28 days); // The time in which a claim period will span in seconds - 28 days by default - // Deployment check - setBool(keccak256(abi.encodePacked(settingNameSpace, "deployed")), true); // Flag that this contract has been deployed, so default settings don't get reapplied on a contract upgrade - } - } - - - /*** Settings ****************/ - - // Set a new claimer for the rpl rewards, must specify a unique contract name that will be claiming from and a percentage of the rewards - function setSettingRewardsClaimer(string memory _contractName, uint256 _perc) override public onlyDAOProtocolProposal { - // Get the total perc set, can't be more than 100 - uint256 percTotal = getRewardsClaimersPercTotal(); - // If this group already exists, it will update the perc - uint256 percTotalUpdate = percTotal.add(_perc).sub(getRewardsClaimerPerc(_contractName)); - // Can't be more than a total claim amount of 100% - require(percTotalUpdate <= 1 ether, "Claimers cannot total more than 100%"); - // Update the total - setUint(keccak256(abi.encodePacked(settingNameSpace,"rewards.claims", "group.totalPerc")), percTotalUpdate); - // Update/Add the claimer amount - setUint(keccak256(abi.encodePacked(settingNameSpace, "rewards.claims", "group.amount", _contractName)), _perc); - // Set the time it was updated at - setUint(keccak256(abi.encodePacked(settingNameSpace, "rewards.claims", "group.amount.updated.time", _contractName)), block.timestamp); - } - - - - /*** RPL Claims ***********************************************/ - - - // RPL Rewards Claimers (own namespace to prevent DAO setting voting to overwrite them) - - // Get the perc amount that this rewards contract get claim - function getRewardsClaimerPerc(string memory _contractName) override public view returns (uint256) { - return getUint(keccak256(abi.encodePacked(settingNameSpace, "rewards.claims", "group.amount", _contractName))); - } - - // Get the time of when the claim perc was last updated - function getRewardsClaimerPercTimeUpdated(string memory _contractName) override external view returns (uint256) { - return getUint(keccak256(abi.encodePacked(settingNameSpace, "rewards.claims", "group.amount.updated.time", _contractName))); - } - - // Get the perc amount total for all claimers (remaining goes to DAO) - function getRewardsClaimersPercTotal() override public view returns (uint256) { - return getUint(keccak256(abi.encodePacked(settingNameSpace, "rewards.claims", "group.totalPerc"))); - } - - - // RPL Rewards General Settings - - // The period over which claims can be made - function getRewardsClaimIntervalTime() override external view returns (uint256) { - return getSettingUint("rpl.rewards.claim.period.time"); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/minipool/RocketMinipoolManagerOld.sol b/contracts/old/contract/minipool/RocketMinipoolManagerOld.sol deleted file mode 100644 index 191986ae5..000000000 --- a/contracts/old/contract/minipool/RocketMinipoolManagerOld.sol +++ /dev/null @@ -1,531 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.7.6; -pragma abicoder v2; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -import "../../../contract/RocketBase.sol"; -import "../../interface/minipool/RocketMinipoolManagerInterfaceOld.sol"; -import "../../../interface/util/AddressSetStorageInterface.sol"; -import "../../../interface/node/RocketNodeDepositInterface.sol"; -import "../../../interface/node/RocketNodeDistributorFactoryInterface.sol"; -import "../../../interface/node/RocketNodeManagerInterface.sol"; -import "../../../interface/node/RocketNodeDistributorInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterface.sol"; -import "../../../interface/minipool/RocketMinipoolFactoryInterface.sol"; - - -/// @notice Minipool creation, removal and management -contract RocketMinipoolManagerOld is RocketBase, RocketMinipoolManagerInterfaceOld { - - // Libs - using SafeMath for uint; - - // Events - event MinipoolCreated(address indexed minipool, address indexed node, uint256 time); - event MinipoolDestroyed(address indexed minipool, address indexed node, uint256 time); - event BeginBondReduction(address indexed minipool, uint256 time); - event CancelReductionVoted(address indexed minipool, address indexed member, uint256 time); - event ReductionCancelled(address indexed minipool, uint256 time); - - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - version = 3; - } - - /// @notice Get the number of minipools in the network - function getMinipoolCount() override public view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getCount(keccak256(bytes("minipools.index"))); - } - - /// @notice Get the number of minipools in the network in the Staking state - function getStakingMinipoolCount() override public view returns (uint256) { - return getUint(keccak256(bytes("minipools.staking.count"))); - } - - /// @notice Get the number of finalised minipools in the network - function getFinalisedMinipoolCount() override external view returns (uint256) { - return getUint(keccak256(bytes("minipools.finalised.count"))); - } - - /// @notice Get the number of active minipools in the network - function getActiveMinipoolCount() override public view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - uint256 total = addressSetStorage.getCount(keccak256(bytes("minipools.index"))); - uint256 finalised = getUint(keccak256(bytes("minipools.finalised.count"))); - return total.sub(finalised); - } - - /// @notice Returns true if a minipool has had an RPL slashing - function getMinipoolRPLSlashed(address _minipoolAddress) override external view returns (bool) { - return getBool(keccak256(abi.encodePacked("minipool.rpl.slashed", _minipoolAddress))); - } - - /// @notice Get the number of minipools in each status. - /// Returns the counts for Initialised, Prelaunch, Staking, Withdrawable, and Dissolved in that order. - /// @param _offset The offset into the minipool set to start - /// @param _limit The maximum number of minipools to iterate - function getMinipoolCountPerStatus(uint256 _offset, uint256 _limit) override external view - returns (uint256 initialisedCount, uint256 prelaunchCount, uint256 stakingCount, uint256 withdrawableCount, uint256 dissolvedCount) { - // Get contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Precompute minipool key - bytes32 minipoolKey = keccak256(abi.encodePacked("minipools.index")); - // Iterate over the requested minipool range - uint256 totalMinipools = getMinipoolCount(); - uint256 max = _offset.add(_limit); - if (max > totalMinipools || _limit == 0) { max = totalMinipools; } - for (uint256 i = _offset; i < max; i++) { - // Get the minipool at index i - RocketMinipoolInterface minipool = RocketMinipoolInterface(addressSetStorage.getItem(minipoolKey, i)); - // Get the minipool's status, and update the appropriate counter - MinipoolStatus status = minipool.getStatus(); - if (status == MinipoolStatus.Initialised) { - initialisedCount++; - } - else if (status == MinipoolStatus.Prelaunch) { - prelaunchCount++; - } - else if (status == MinipoolStatus.Staking) { - stakingCount++; - } - else if (status == MinipoolStatus.Withdrawable) { - withdrawableCount++; - } - else if (status == MinipoolStatus.Dissolved) { - dissolvedCount++; - } - } - } - - /// @notice Returns an array of all minipools in the prelaunch state - /// @param _offset The offset into the minipool set to start iterating - /// @param _limit The maximum number of minipools to iterate over - function getPrelaunchMinipools(uint256 _offset, uint256 _limit) override external view - returns (address[] memory) { - // Get contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Precompute minipool key - bytes32 minipoolKey = keccak256(abi.encodePacked("minipools.index")); - // Iterate over the requested minipool range - uint256 totalMinipools = getMinipoolCount(); - uint256 max = _offset.add(_limit); - if (max > totalMinipools || _limit == 0) { max = totalMinipools; } - // Create array big enough for every minipool - address[] memory minipools = new address[](max.sub(_offset)); - uint256 total = 0; - for (uint256 i = _offset; i < max; i++) { - // Get the minipool at index i - RocketMinipoolInterface minipool = RocketMinipoolInterface(addressSetStorage.getItem(minipoolKey, i)); - // Get the minipool's status, and to array if it's in prelaunch - MinipoolStatus status = minipool.getStatus(); - if (status == MinipoolStatus.Prelaunch) { - minipools[total] = address(minipool); - total++; - } - } - // Dirty hack to cut unused elements off end of return value - assembly { - mstore(minipools, total) - } - return minipools; - } - - /// @notice Get a network minipool address by index - /// @param _index Index into the minipool set to return - function getMinipoolAt(uint256 _index) override external view returns (address) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getItem(keccak256(abi.encodePacked("minipools.index")), _index); - } - - /// @notice Get the number of minipools owned by a node - /// @param _nodeAddress The node operator to query the count of minipools of - function getNodeMinipoolCount(address _nodeAddress) override external view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getCount(keccak256(abi.encodePacked("node.minipools.index", _nodeAddress))); - } - - /// @notice Get the number of minipools owned by a node that are not finalised - /// @param _nodeAddress The node operator to query the count of active minipools of - function getNodeActiveMinipoolCount(address _nodeAddress) override public view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - uint256 finalised = getUint(keccak256(abi.encodePacked("node.minipools.finalised.count", _nodeAddress))); - uint256 total = addressSetStorage.getCount(keccak256(abi.encodePacked("node.minipools.index", _nodeAddress))); - return total.sub(finalised); - } - - /// @notice Get the number of minipools owned by a node that are finalised - /// @param _nodeAddress The node operator to query the count of finalised minipools of - function getNodeFinalisedMinipoolCount(address _nodeAddress) override external view returns (uint256) { - return getUint(keccak256(abi.encodePacked("node.minipools.finalised.count", _nodeAddress))); - } - - /// @notice Get the number of minipools owned by a node that are in staking status - /// @param _nodeAddress The node operator to query the count of staking minipools of - function getNodeStakingMinipoolCount(address _nodeAddress) override public view returns (uint256) { - RocketNodeDepositInterface rocketNodeDeposit = RocketNodeDepositInterface(getContractAddress("rocketNodeDeposit")); - // Get valid deposit amounts - uint256[] memory depositSizes = rocketNodeDeposit.getDepositAmounts(); - uint256 total; - for (uint256 i = 0; i < depositSizes.length; i++){ - total = total.add(getNodeStakingMinipoolCountBySize(_nodeAddress, depositSizes[i])); - } - return total; - } - - /// @notice Get the number of minipools owned by a node that are in staking status - /// @param _nodeAddress The node operator to query the count of minipools by desposit size of - /// @param _depositSize The deposit size to filter result by - function getNodeStakingMinipoolCountBySize(address _nodeAddress, uint256 _depositSize) override public view returns (uint256) { - bytes32 nodeKey; - if (_depositSize == 16 ether){ - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", _nodeAddress)); - } else { - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", _nodeAddress, _depositSize)); - } - return getUint(nodeKey); - } - - /// @notice Get a node minipool address by index - /// @param _nodeAddress The node operator to query the minipool of - /// @param _index Index into the node operator's set of minipools - function getNodeMinipoolAt(address _nodeAddress, uint256 _index) override external view returns (address) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getItem(keccak256(abi.encodePacked("node.minipools.index", _nodeAddress)), _index); - } - - /// @notice Get the number of validating minipools owned by a node - /// @param _nodeAddress The node operator to query the count of validating minipools of - function getNodeValidatingMinipoolCount(address _nodeAddress) override external view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getCount(keccak256(abi.encodePacked("node.minipools.validating.index", _nodeAddress))); - } - - /// @notice Get a validating node minipool address by index - /// @param _nodeAddress The node operator to query the validating minipool of - /// @param _index Index into the node operator's set of validating minipools - function getNodeValidatingMinipoolAt(address _nodeAddress, uint256 _index) override external view returns (address) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getItem(keccak256(abi.encodePacked("node.minipools.validating.index", _nodeAddress)), _index); - } - - /// @notice Get a minipool address by validator pubkey - /// @param _pubkey The pubkey to query - function getMinipoolByPubkey(bytes memory _pubkey) override public view returns (address) { - return getAddress(keccak256(abi.encodePacked("validator.minipool", _pubkey))); - } - - /// @notice Returns true if a minipool exists - /// @param _minipoolAddress The address of the minipool to check the existence of - function getMinipoolExists(address _minipoolAddress) override public view returns (bool) { - return getBool(keccak256(abi.encodePacked("minipool.exists", _minipoolAddress))); - } - - /// @notice Returns true if a minipool previously existed at the given address - /// @param _minipoolAddress The address to check the previous existence of a minipool at - function getMinipoolDestroyed(address _minipoolAddress) override external view returns (bool) { - return getBool(keccak256(abi.encodePacked("minipool.destroyed", _minipoolAddress))); - } - - /// @notice Returns a minipool's validator pubkey - /// @param _minipoolAddress The minipool to query the pubkey of - function getMinipoolPubkey(address _minipoolAddress) override public view returns (bytes memory) { - return getBytes(keccak256(abi.encodePacked("minipool.pubkey", _minipoolAddress))); - } - - /// @notice Calculates what the withdrawal credentials of a minipool should be set to - /// @param _minipoolAddress The minipool to calculate the withdrawal credentials for - function getMinipoolWithdrawalCredentials(address _minipoolAddress) override public pure returns (bytes memory) { - return abi.encodePacked(byte(0x01), bytes11(0x0), address(_minipoolAddress)); - } - - /// @notice Decrements a node operator's number of staking minipools based on the minipools prior bond amount and - /// increments it based on their new bond amount. - /// @param _previousBond The minipool's previous bond value - /// @param _newBond The minipool's new bond value - /// @param _previousFee The fee of the minipool prior to the bond change - /// @param _newFee The fee of the minipool after the bond change - function updateNodeStakingMinipoolCount(uint256 _previousBond, uint256 _newBond, uint256 _previousFee, uint256 _newFee) override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - bytes32 nodeKey; - bytes32 numeratorKey; - // Get contracts - RocketMinipoolInterface minipool = RocketMinipoolInterface(msg.sender); - address nodeAddress = minipool.getNodeAddress(); - // Try to distribute current fees at previous average commission rate - _tryDistribute(nodeAddress); - // Decrement previous bond count - if (_previousBond == 16 ether){ - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", nodeAddress)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", nodeAddress)); - } else { - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", nodeAddress, _previousBond)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", nodeAddress, _previousBond)); - } - subUint(nodeKey, 1); - subUint(numeratorKey, _previousFee); - // Increment new bond count - if (_newBond == 16 ether){ - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", nodeAddress)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", nodeAddress)); - } else { - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", nodeAddress, _newBond)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", nodeAddress, _newBond)); - } - addUint(nodeKey, 1); - addUint(numeratorKey, _newFee); - } - - /// @dev Increments a node operator's number of staking minipools and calculates updated average node fee. - /// Must be called from the minipool itself as msg.sender is used to query the minipool's node fee - /// @param _nodeAddress The node address to increment the number of staking minipools of - function incrementNodeStakingMinipoolCount(address _nodeAddress) override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - // Get contracts - RocketMinipoolInterface minipool = RocketMinipoolInterface(msg.sender); - // Try to distribute current fees at previous average commission rate - _tryDistribute(_nodeAddress); - // Update the node specific count - uint256 depositSize = minipool.getNodeDepositBalance(); - bytes32 nodeKey; - bytes32 numeratorKey; - if (depositSize == 16 ether){ - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", _nodeAddress)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", _nodeAddress)); - } else { - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", _nodeAddress, depositSize)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", _nodeAddress, depositSize)); - } - uint256 nodeValue = getUint(nodeKey); - setUint(nodeKey, nodeValue.add(1)); - // Update the total count - bytes32 totalKey = keccak256(abi.encodePacked("minipools.staking.count")); - uint256 totalValue = getUint(totalKey); - setUint(totalKey, totalValue.add(1)); - // Update node fee average - addUint(numeratorKey, minipool.getNodeFee()); - } - - /// @dev Decrements a node operator's number of minipools in staking status and calculates updated average node fee. - /// Must be called from the minipool itself as msg.sender is used to query the minipool's node fee - /// @param _nodeAddress The node address to decrement the number of staking minipools of - function decrementNodeStakingMinipoolCount(address _nodeAddress) override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - // Get contracts - RocketMinipoolInterface minipool = RocketMinipoolInterface(msg.sender); - // Try to distribute current fees at previous average commission rate - _tryDistribute(_nodeAddress); - // Update the node specific count - uint256 depositSize = minipool.getNodeDepositBalance(); - bytes32 nodeKey; - bytes32 numeratorKey; - if (depositSize == 16 ether){ - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", _nodeAddress)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", _nodeAddress)); - } else { - nodeKey = keccak256(abi.encodePacked("node.minipools.staking.count", _nodeAddress, depositSize)); - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", _nodeAddress, depositSize)); - } - uint256 nodeValue = getUint(nodeKey); - setUint(nodeKey, nodeValue.sub(1)); - // Update the total count - bytes32 totalKey = keccak256(abi.encodePacked("minipools.staking.count")); - uint256 totalValue = getUint(totalKey); - setUint(totalKey, totalValue.sub(1)); - // Update node fee average - subUint(numeratorKey, minipool.getNodeFee()); - } - - /// @dev Calls distribute on the given node's distributor if it has a balance and has been initialised - /// @param _nodeAddress The node operator to try distribute rewards for - function _tryDistribute(address _nodeAddress) internal { - // Get contracts - RocketNodeDistributorFactoryInterface rocketNodeDistributorFactory = RocketNodeDistributorFactoryInterface(getContractAddress("rocketNodeDistributorFactory")); - address distributorAddress = rocketNodeDistributorFactory.getProxyAddress(_nodeAddress); - // If there are funds to distribute than call distribute - if (distributorAddress.balance > 0) { - // Get contracts - RocketNodeManagerInterface rocketNodeManager = RocketNodeManagerInterface(getContractAddress("rocketNodeManager")); - // Ensure distributor has been initialised - require(rocketNodeManager.getFeeDistributorInitialised(_nodeAddress), "Distributor not initialised"); - RocketNodeDistributorInterface distributor = RocketNodeDistributorInterface(distributorAddress); - distributor.distribute(); - } - } - - /// @dev Increments a node operator's number of minipools that have been finalised - /// @param _nodeAddress The node operator to increment finalised minipool count for - function incrementNodeFinalisedMinipoolCount(address _nodeAddress) override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - // Can only finalise a minipool once - bytes32 finalisedKey = keccak256(abi.encodePacked("node.minipools.finalised", msg.sender)); - require(!getBool(finalisedKey), "Minipool has already been finalised"); - setBool(finalisedKey, true); - // Update the node specific count - addUint(keccak256(abi.encodePacked("node.minipools.finalised.count", _nodeAddress)), 1); - // Update the total count - addUint(keccak256(bytes("minipools.finalised.count")), 1); - // Update ETH matched - uint256 ethMatched = getUint(keccak256(abi.encodePacked("eth.matched.node.amount", _nodeAddress))); - if (ethMatched == 0) { - ethMatched = getNodeActiveMinipoolCount(_nodeAddress).mul(16 ether); - } else { - RocketMinipoolInterface minipool = RocketMinipoolInterface(msg.sender); - ethMatched = ethMatched.sub(minipool.getUserDepositBalance()); - } - setUint(keccak256(abi.encodePacked("eth.matched.node.amount", _nodeAddress)), ethMatched); - } - - /// @dev Create a minipool. Only accepts calls from the RocketNodeDeposit contract - /// @param _nodeAddress The owning node operator's address - /// @param _salt A salt used in determining the minipool's address - function createMinipool(address _nodeAddress, uint256 _salt) override public onlyLatestContract("rocketMinipoolManager", address(this)) onlyLatestContract("rocketNodeDeposit", msg.sender) returns (RocketMinipoolInterface) { - // Load contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Check node minipool limit based on RPL stake - { // Local scope to prevent stack too deep error - RocketDAOProtocolSettingsMinipoolInterface rocketDAOProtocolSettingsMinipool = RocketDAOProtocolSettingsMinipoolInterface(getContractAddress("rocketDAOProtocolSettingsMinipool")); - // Check global minipool limit - uint256 totalMinipoolCount = getActiveMinipoolCount(); - require(totalMinipoolCount.add(1) <= rocketDAOProtocolSettingsMinipool.getMaximumCount(), "Global minipool limit reached"); - } - // Create minipool contract - address contractAddress = deployContract(_nodeAddress, _salt); - // Initialise minipool data - setBool(keccak256(abi.encodePacked("minipool.exists", contractAddress)), true); - // Add minipool to indexes - addressSetStorage.addItem(keccak256(abi.encodePacked("minipools.index")), contractAddress); - addressSetStorage.addItem(keccak256(abi.encodePacked("node.minipools.index", _nodeAddress)), contractAddress); - // Emit minipool created event - emit MinipoolCreated(contractAddress, _nodeAddress, block.timestamp); - // Return created minipool address - return RocketMinipoolInterface(contractAddress); - } - - /// @notice Creates a vacant minipool that can be promoted by changing the given validator's withdrawal credentials - /// @param _nodeAddress Address of the owning node operator - /// @param _salt A salt used in determining the minipool's address - /// @param _validatorPubkey A validator pubkey that the node operator intends to migrate the withdrawal credentials of - /// @param _bondAmount The bond amount selected by the node operator - /// @param _currentBalance The current balance of the validator on the beaconchain (will be checked by oDAO and scrubbed if not correct) - function createVacantMinipool(address _nodeAddress, uint256 _salt, bytes calldata _validatorPubkey, uint256 _bondAmount, uint256 _currentBalance) override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyLatestContract("rocketNodeDeposit", msg.sender) returns (RocketMinipoolInterface) { - // Get contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Create the minipool - RocketMinipoolInterface minipool = createMinipool(_nodeAddress, _salt); - // Prepare the minipool - minipool.prepareVacancy(_bondAmount, _currentBalance); - // Set the minipool's validator pubkey - _setMinipoolPubkey(address(minipool), _validatorPubkey); - // Add minipool to the vacant set - addressSetStorage.addItem(keccak256(abi.encodePacked("minipools.vacant.index")), address(minipool)); - // Return - return minipool; - } - - /// @dev Called by minipool to remove from vacant set on promotion or dissolution - function removeVacantMinipool() override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - // Remove from vacant set - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - addressSetStorage.removeItem(keccak256(abi.encodePacked("minipools.vacant.index")), msg.sender); - // Remove mapping of pubkey to minipool to allow NO to try again in future - bytes memory pubkey = getMinipoolPubkey(msg.sender); - deleteAddress(keccak256(abi.encodePacked("validator.minipool", pubkey))); - } - - /// @notice Returns the number of minipools in the vacant minipool set - function getVacantMinipoolCount() override external view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getCount(keccak256(abi.encodePacked("minipools.vacant.index"))); - } - - /// @notice Returns the vacant minipool at a given index - /// @param _index The index into the vacant minipool set to retrieve - function getVacantMinipoolAt(uint256 _index) override external view returns (address) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getItem(keccak256(abi.encodePacked("minipools.vacant.index")), _index); - } - - /// @dev Destroy a minipool cleaning up all relevant state. Only accepts calls from registered minipools - function destroyMinipool() override external onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - // Load contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Initialize minipool & get properties - RocketMinipoolInterface minipool = RocketMinipoolInterface(msg.sender); - address nodeAddress = minipool.getNodeAddress(); - // Update ETH matched - uint256 ethMatched = getUint(keccak256(abi.encodePacked("eth.matched.node.amount", nodeAddress))); - if (ethMatched == 0) { - ethMatched = getNodeActiveMinipoolCount(nodeAddress).mul(16 ether); - } - // Handle legacy minipools - if (minipool.getDepositType() == MinipoolDeposit.Variable) { - ethMatched = ethMatched.sub(minipool.getUserDepositBalance()); - } else { - ethMatched = ethMatched.sub(16 ether); - } - setUint(keccak256(abi.encodePacked("eth.matched.node.amount", nodeAddress)), ethMatched); - // Update minipool data - setBool(keccak256(abi.encodePacked("minipool.exists", msg.sender)), false); - // Record minipool as destroyed to prevent recreation at same address - setBool(keccak256(abi.encodePacked("minipool.destroyed", msg.sender)), true); - // Remove minipool from indexes - addressSetStorage.removeItem(keccak256(abi.encodePacked("minipools.index")), msg.sender); - addressSetStorage.removeItem(keccak256(abi.encodePacked("node.minipools.index", nodeAddress)), msg.sender); - // Clean up pubkey state - bytes memory pubkey = getMinipoolPubkey(msg.sender); - deleteBytes(keccak256(abi.encodePacked("minipool.pubkey", msg.sender))); - deleteAddress(keccak256(abi.encodePacked("validator.minipool", pubkey))); - // Emit minipool destroyed event - emit MinipoolDestroyed(msg.sender, nodeAddress, block.timestamp); - } - - /// @dev Set a minipool's validator pubkey. Only accepts calls from registered minipools - /// @param _pubkey The pubkey to set for the calling minipool - function setMinipoolPubkey(bytes calldata _pubkey) override public onlyLatestContract("rocketMinipoolManager", address(this)) onlyRegisteredMinipool(msg.sender) { - _setMinipoolPubkey(msg.sender, _pubkey); - } - - /// @dev Internal logic to set a minipool's pubkey, reverts if pubkey already set - /// @param _pubkey The pubkey to set for the calling minipool - function _setMinipoolPubkey(address _minipool, bytes calldata _pubkey) private { - // Check validator pubkey is not in use - require(getMinipoolByPubkey(_pubkey) == address(0x0), "Validator pubkey is in use"); - // Load contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Initialise minipool & get properties - RocketMinipoolInterface minipool = RocketMinipoolInterface(_minipool); - address nodeAddress = minipool.getNodeAddress(); - // Set minipool validator pubkey & validator minipool address - setBytes(keccak256(abi.encodePacked("minipool.pubkey", _minipool)), _pubkey); - setAddress(keccak256(abi.encodePacked("validator.minipool", _pubkey)), _minipool); - // Add minipool to node validating minipools index - addressSetStorage.addItem(keccak256(abi.encodePacked("node.minipools.validating.index", nodeAddress)), _minipool); - } - - /// @dev Wrapper around minipool getDepositType which handles backwards compatibility with v1 and v2 delegates - /// @param _minipoolAddress Minipool address to get the deposit type of - function getMinipoolDepositType(address _minipoolAddress) external override view returns (MinipoolDeposit) { - RocketMinipoolInterface minipoolInterface = RocketMinipoolInterface(_minipoolAddress); - uint8 version = 1; - - // Version 1 minipools did not have a version() function - try minipoolInterface.version() returns (uint8 tryVersion) { - version = tryVersion; - } catch (bytes memory /*lowLevelData*/) {} - - if (version == 1 || version == 2) { - try minipoolInterface.getDepositType{gas: 30000}() returns (MinipoolDeposit depositType) { - return depositType; - } catch (bytes memory /*lowLevelData*/) { - return MinipoolDeposit.Variable; - } - } - - return minipoolInterface.getDepositType(); - } - - /// @dev Performs a CREATE2 deployment of a minipool contract with given salt - /// @param _nodeAddress The owning node operator's address - /// @param _salt A salt used in determining the minipool's address - function deployContract(address _nodeAddress, uint256 _salt) private returns (address) { - RocketMinipoolFactoryInterface rocketMinipoolFactory = RocketMinipoolFactoryInterface(getContractAddress("rocketMinipoolFactory")); - return rocketMinipoolFactory.deployContract(_nodeAddress, _salt); - } -} \ No newline at end of file diff --git a/contracts/old/contract/network/RocketNetworkBalancesOld.sol b/contracts/old/contract/network/RocketNetworkBalancesOld.sol deleted file mode 100644 index daad24b65..000000000 --- a/contracts/old/contract/network/RocketNetworkBalancesOld.sol +++ /dev/null @@ -1,137 +0,0 @@ -pragma solidity 0.7.6; - -// SPDX-License-Identifier: GPL-3.0-only - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -import "../../../contract/RocketBase.sol"; -import "../../interface/network/RocketNetworkBalancesInterfaceOld.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterface.sol"; -import "../../../interface/dao/node/RocketDAONodeTrustedInterface.sol"; - -// Network balances - -contract RocketNetworkBalancesOld is RocketBase, RocketNetworkBalancesInterfaceOld { - - // Libs - using SafeMath for uint; - - // Events - event BalancesSubmitted(address indexed from, uint256 block, uint256 totalEth, uint256 stakingEth, uint256 rethSupply, uint256 time); - event BalancesUpdated(uint256 block, uint256 totalEth, uint256 stakingEth, uint256 rethSupply, uint256 time); - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - version = 2; - } - - // The block number which balances are current for - function getBalancesBlock() override public view returns (uint256) { - return getUint(keccak256("network.balances.updated.block")); - } - function setBalancesBlock(uint256 _value) private { - setUint(keccak256("network.balances.updated.block"), _value); - } - - // The current RP network total ETH balance - function getTotalETHBalance() override public view returns (uint256) { - return getUint(keccak256("network.balance.total")); - } - function setTotalETHBalance(uint256 _value) private { - setUint(keccak256("network.balance.total"), _value); - } - - // The current RP network staking ETH balance - function getStakingETHBalance() override public view returns (uint256) { - return getUint(keccak256("network.balance.staking")); - } - function setStakingETHBalance(uint256 _value) private { - setUint(keccak256("network.balance.staking"), _value); - } - - // The current RP network total rETH supply - function getTotalRETHSupply() override external view returns (uint256) { - return getUint(keccak256("network.balance.reth.supply")); - } - function setTotalRETHSupply(uint256 _value) private { - setUint(keccak256("network.balance.reth.supply"), _value); - } - - // Get the current RP network ETH utilization rate as a fraction of 1 ETH - // Represents what % of the network's balance is actively earning rewards - function getETHUtilizationRate() override external view returns (uint256) { - uint256 totalEthBalance = getTotalETHBalance(); - uint256 stakingEthBalance = getStakingETHBalance(); - if (totalEthBalance == 0) { return calcBase; } - return calcBase.mul(stakingEthBalance).div(totalEthBalance); - } - - // Submit network balances for a block - // Only accepts calls from trusted (oracle) nodes - function submitBalances(uint256 _block, uint256 _totalEth, uint256 _stakingEth, uint256 _rethSupply) override external onlyLatestContract("rocketNetworkBalances", address(this)) onlyTrustedNode(msg.sender) { - // Check settings - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - require(rocketDAOProtocolSettingsNetwork.getSubmitBalancesEnabled(), "Submitting balances is currently disabled"); - // Check block - require(_block < block.number, "Balances can not be submitted for a future block"); - require(_block > getBalancesBlock(), "Network balances for an equal or higher block are set"); - // Get submission keys - bytes32 nodeSubmissionKey = keccak256(abi.encodePacked("network.balances.submitted.node", msg.sender, _block, _totalEth, _stakingEth, _rethSupply)); - bytes32 submissionCountKey = keccak256(abi.encodePacked("network.balances.submitted.count", _block, _totalEth, _stakingEth, _rethSupply)); - // Check & update node submission status - require(!getBool(nodeSubmissionKey), "Duplicate submission from node"); - setBool(nodeSubmissionKey, true); - setBool(keccak256(abi.encodePacked("network.balances.submitted.node", msg.sender, _block)), true); - // Increment submission count - uint256 submissionCount = getUint(submissionCountKey).add(1); - setUint(submissionCountKey, submissionCount); - // Emit balances submitted event - emit BalancesSubmitted(msg.sender, _block, _totalEth, _stakingEth, _rethSupply, block.timestamp); - // Check submission count & update network balances - RocketDAONodeTrustedInterface rocketDAONodeTrusted = RocketDAONodeTrustedInterface(getContractAddress("rocketDAONodeTrusted")); - if (calcBase.mul(submissionCount).div(rocketDAONodeTrusted.getMemberCount()) >= rocketDAOProtocolSettingsNetwork.getNodeConsensusThreshold()) { - updateBalances(_block, _totalEth, _stakingEth, _rethSupply); - } - } - - // Executes updateBalances if consensus threshold is reached - function executeUpdateBalances(uint256 _block, uint256 _totalEth, uint256 _stakingEth, uint256 _rethSupply) override external onlyLatestContract("rocketNetworkBalances", address(this)) { - // Check settings - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - require(rocketDAOProtocolSettingsNetwork.getSubmitBalancesEnabled(), "Submitting balances is currently disabled"); - // Check block - require(_block < block.number, "Balances can not be submitted for a future block"); - require(_block > getBalancesBlock(), "Network balances for an equal or higher block are set"); - // Check balances - require(_stakingEth <= _totalEth, "Invalid network balances"); - // Get submission keys - bytes32 submissionCountKey = keccak256(abi.encodePacked("network.balances.submitted.count", _block, _totalEth, _stakingEth, _rethSupply)); - // Get submission count - uint256 submissionCount = getUint(submissionCountKey); - // Check submission count & update network balances - RocketDAONodeTrustedInterface rocketDAONodeTrusted = RocketDAONodeTrustedInterface(getContractAddress("rocketDAONodeTrusted")); - require(calcBase.mul(submissionCount).div(rocketDAONodeTrusted.getMemberCount()) >= rocketDAOProtocolSettingsNetwork.getNodeConsensusThreshold(), "Consensus has not been reached"); - updateBalances(_block, _totalEth, _stakingEth, _rethSupply); - } - - // Update network balances - function updateBalances(uint256 _block, uint256 _totalEth, uint256 _stakingEth, uint256 _rethSupply) private { - // Update balances - setBalancesBlock(_block); - setTotalETHBalance(_totalEth); - setStakingETHBalance(_stakingEth); - setTotalRETHSupply(_rethSupply); - // Emit balances updated event - emit BalancesUpdated(_block, _totalEth, _stakingEth, _rethSupply, block.timestamp); - } - - // Returns the latest block number that oracles should be reporting balances for - function getLatestReportableBlock() override external view returns (uint256) { - // Load contracts - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - // Get the block balances were lasted updated and the update frequency - uint256 updateFrequency = rocketDAOProtocolSettingsNetwork.getSubmitBalancesFrequency(); - // Calculate the last reportable block based on update frequency - return block.number.div(updateFrequency).mul(updateFrequency); - } -} \ No newline at end of file diff --git a/contracts/old/contract/network/RocketNetworkPricesOld.sol b/contracts/old/contract/network/RocketNetworkPricesOld.sol deleted file mode 100644 index 76c8fdeae..000000000 --- a/contracts/old/contract/network/RocketNetworkPricesOld.sol +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.7.6; - -import "../../../contract/RocketBase.sol"; -import "../../interface/network/RocketNetworkPricesInterfaceOld.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterface.sol"; -import "../../../interface/dao/node/RocketDAONodeTrustedInterface.sol"; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -/// @notice Oracle contract for network token price data -contract RocketNetworkPricesOld is RocketBase, RocketNetworkPricesInterfaceOld { - - // Libs - using SafeMath for uint; - - // Events - event PricesSubmitted(address indexed from, uint256 block, uint256 rplPrice, uint256 time); - event PricesUpdated(uint256 block, uint256 rplPrice, uint256 time); - - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - // Set contract version - version = 2; - - // On initial deploy, preset RPL price to 0.01 - if (getRPLPrice() == 0) { - setRPLPrice(0.01 ether); - } - } - - /// @notice Returns the block number which prices are current for - function getPricesBlock() override public view returns (uint256) { - return getUint(keccak256("network.prices.updated.block")); - } - - /// @dev Sets the block number which prices are current for - function setPricesBlock(uint256 _value) private { - setUint(keccak256("network.prices.updated.block"), _value); - } - - /// @notice Returns the current network RPL price in ETH - function getRPLPrice() override public view returns (uint256) { - return getUint(keccak256("network.prices.rpl")); - } - - /// @dev Sets the current network RPL price in ETH - function setRPLPrice(uint256 _value) private { - setUint(keccak256("network.prices.rpl"), _value); - } - - /// @notice Submit network price data for a block - /// Only accepts calls from trusted (oracle) nodes - /// @param _block The block this price submission is for - /// @param _rplPrice The price of RPL at the given block - function submitPrices(uint256 _block, uint256 _rplPrice) override external onlyLatestContract("rocketNetworkPrices", address(this)) onlyTrustedNode(msg.sender) { - // Check settings - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - require(rocketDAOProtocolSettingsNetwork.getSubmitPricesEnabled(), "Submitting prices is currently disabled"); - // Check block - require(_block < block.number, "Prices can not be submitted for a future block"); - require(_block > getPricesBlock(), "Network prices for an equal or higher block are set"); - // Get submission keys - bytes32 nodeSubmissionKey = keccak256(abi.encodePacked("network.prices.submitted.node.key", msg.sender, _block, _rplPrice)); - bytes32 submissionCountKey = keccak256(abi.encodePacked("network.prices.submitted.count", _block, _rplPrice)); - // Check & update node submission status - require(!getBool(nodeSubmissionKey), "Duplicate submission from node"); - setBool(nodeSubmissionKey, true); - setBool(keccak256(abi.encodePacked("network.prices.submitted.node", msg.sender, _block)), true); - // Increment submission count - uint256 submissionCount = getUint(submissionCountKey).add(1); - setUint(submissionCountKey, submissionCount); - // Emit prices submitted event - emit PricesSubmitted(msg.sender, _block, _rplPrice, block.timestamp); - // Check submission count & update network prices - RocketDAONodeTrustedInterface rocketDAONodeTrusted = RocketDAONodeTrustedInterface(getContractAddress("rocketDAONodeTrusted")); - if (calcBase.mul(submissionCount).div(rocketDAONodeTrusted.getMemberCount()) >= rocketDAOProtocolSettingsNetwork.getNodeConsensusThreshold()) { - // Update the price - updatePrices(_block, _rplPrice); - } - } - - /// @notice Executes updatePrices if consensus threshold is reached - /// @param _block The block to execute price update for - /// @param _rplPrice The price of RPL at the given block - function executeUpdatePrices(uint256 _block, uint256 _rplPrice) override external onlyLatestContract("rocketNetworkPrices", address(this)) { - // Check settings - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - require(rocketDAOProtocolSettingsNetwork.getSubmitPricesEnabled(), "Submitting prices is currently disabled"); - // Check block - require(_block < block.number, "Prices can not be submitted for a future block"); - require(_block > getPricesBlock(), "Network prices for an equal or higher block are set"); - // Get submission keys - bytes32 submissionCountKey = keccak256(abi.encodePacked("network.prices.submitted.count", _block, _rplPrice)); - // Get submission count - uint256 submissionCount = getUint(submissionCountKey); - // Check submission count & update network prices - RocketDAONodeTrustedInterface rocketDAONodeTrusted = RocketDAONodeTrustedInterface(getContractAddress("rocketDAONodeTrusted")); - require(calcBase.mul(submissionCount).div(rocketDAONodeTrusted.getMemberCount()) >= rocketDAOProtocolSettingsNetwork.getNodeConsensusThreshold(), "Consensus has not been reached"); - // Update the price - updatePrices(_block, _rplPrice); - } - - /// @dev Update network price data - /// @param _block The block to update price for - /// @param _rplPrice The price of RPL at the given block - function updatePrices(uint256 _block, uint256 _rplPrice) private { - // Update price - setRPLPrice(_rplPrice); - setPricesBlock(_block); - // Emit prices updated event - emit PricesUpdated(_block, _rplPrice, block.timestamp); - } - - /// @notice Returns the latest block number that oracles should be reporting prices for - function getLatestReportableBlock() override external view returns (uint256) { - // Load contracts - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - // Get the block prices were lasted updated and the update frequency - uint256 updateFrequency = rocketDAOProtocolSettingsNetwork.getSubmitPricesFrequency(); - // Calculate the last reportable block based on update frequency - return block.number.div(updateFrequency).mul(updateFrequency); - } -} \ No newline at end of file diff --git a/contracts/old/contract/node/RocketNodeDepositOld.sol b/contracts/old/contract/node/RocketNodeDepositOld.sol deleted file mode 100644 index 7ae25cb68..000000000 --- a/contracts/old/contract/node/RocketNodeDepositOld.sol +++ /dev/null @@ -1,275 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.7.6; - -import "../../../contract/RocketBase.sol"; -import "../../interface/node/RocketNodeDepositInterfaceOld.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterface.sol"; -import "../../../interface/deposit/RocketDepositPoolInterface.sol"; -import "../../../interface/minipool/RocketMinipoolInterface.sol"; -import "../../../interface/minipool/RocketMinipoolQueueInterface.sol"; -import "../../../interface/node/RocketNodeStakingInterface.sol"; -import "../../../interface/node/RocketNodeManagerInterface.sol"; -import "../../../interface/minipool/RocketMinipoolManagerInterface.sol"; -import "../../../interface/network/RocketNetworkFeesInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterface.sol"; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -/// @notice Handles node deposits and minipool creation -contract RocketNodeDepositOld is RocketBase, RocketNodeDepositInterfaceOld { - - // Libs - using SafeMath for uint; - - // Events - event DepositReceived(address indexed from, uint256 amount, uint256 time); - - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - version = 3; - } - - /// @dev Accept incoming ETH from the deposit pool - receive() external payable onlyLatestContract("rocketDepositPool", msg.sender) {} - - /// @notice Returns a node operator's credit balance in wei - function getNodeDepositCredit(address _nodeOperator) override public view returns (uint256) { - return getUint(keccak256(abi.encodePacked("node.deposit.credit.balance", _nodeOperator))); - } - - /// @dev Increases a node operators deposit credit balance - function increaseDepositCreditBalance(address _nodeOperator, uint256 _amount) override external onlyLatestContract("rocketNodeDeposit", address(this)) { - // Accept calls from network contracts or registered minipools - require(getBool(keccak256(abi.encodePacked("minipool.exists", msg.sender))) || - getBool(keccak256(abi.encodePacked("contract.exists", msg.sender))), - "Invalid or outdated network contract"); - // Increase credit balance - addUint(keccak256(abi.encodePacked("node.deposit.credit.balance", _nodeOperator)), _amount); - } - - /// @notice Accept a node deposit and create a new minipool under the node. Only accepts calls from registered nodes - /// @param _bondAmount The amount of capital the node operator wants to put up as his bond - /// @param _minimumNodeFee Transaction will revert if network commission rate drops below this amount - /// @param _validatorPubkey Pubkey of the validator the node operator wishes to migrate - /// @param _validatorSignature Signature from the validator over the deposit data - /// @param _depositDataRoot The hash tree root of the deposit data (passed onto the deposit contract on pre stake) - /// @param _salt Salt used to deterministically construct the minipool's address - /// @param _expectedMinipoolAddress The expected deterministic minipool address. Will revert if it doesn't match - function deposit(uint256 _bondAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) override external payable onlyLatestContract("rocketNodeDeposit", address(this)) onlyRegisteredNode(msg.sender) { - // Check amount - require(msg.value == _bondAmount, "Invalid value"); - // Process the deposit - _deposit(_bondAmount, _minimumNodeFee, _validatorPubkey, _validatorSignature, _depositDataRoot, _salt, _expectedMinipoolAddress); - } - - /// @notice Accept a node deposit and create a new minipool under the node. Only accepts calls from registered nodes - /// @param _bondAmount The amount of capital the node operator wants to put up as his bond - /// @param _minimumNodeFee Transaction will revert if network commission rate drops below this amount - /// @param _validatorPubkey Pubkey of the validator the node operator wishes to migrate - /// @param _validatorSignature Signature from the validator over the deposit data - /// @param _depositDataRoot The hash tree root of the deposit data (passed onto the deposit contract on pre stake) - /// @param _salt Salt used to deterministically construct the minipool's address - /// @param _expectedMinipoolAddress The expected deterministic minipool address. Will revert if it doesn't match - function depositWithCredit(uint256 _bondAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) override external payable onlyLatestContract("rocketNodeDeposit", address(this)) onlyRegisteredNode(msg.sender) { - // Query node's deposit credit - uint256 credit = getNodeDepositCredit(msg.sender); - // Credit balance accounting - if (credit < _bondAmount) { - uint256 shortFall = _bondAmount.sub(credit); - require(msg.value == shortFall, "Invalid value"); - setUint(keccak256(abi.encodePacked("node.deposit.credit.balance", msg.sender)), 0); - } else { - require(msg.value == 0, "Invalid value"); - subUint(keccak256(abi.encodePacked("node.deposit.credit.balance", msg.sender)), _bondAmount); - } - // Process the deposit - _deposit(_bondAmount, _minimumNodeFee, _validatorPubkey, _validatorSignature, _depositDataRoot, _salt, _expectedMinipoolAddress); - } - - /// @notice Returns true if the given amount is a valid deposit amount - function isValidDepositAmount(uint256 _amount) override public pure returns (bool) { - return _amount == 16 ether || _amount == 8 ether; - } - - /// @notice Returns an array of valid deposit amounts - function getDepositAmounts() override external pure returns (uint256[] memory) { - uint256[] memory amounts = new uint256[](2); - amounts[0] = 16 ether; - amounts[1] = 8 ether; - return amounts; - } - - /// @dev Internal logic to process a deposit - function _deposit(uint256 _bondAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) private { - // Check pre-conditions - checkDepositsEnabled(); - checkDistributorInitialised(); - checkNodeFee(_minimumNodeFee); - require(isValidDepositAmount(_bondAmount), "Invalid deposit amount"); - // Get launch constants - uint256 launchAmount; - uint256 preLaunchValue; - { - RocketDAOProtocolSettingsMinipoolInterface rocketDAOProtocolSettingsMinipool = RocketDAOProtocolSettingsMinipoolInterface(getContractAddress("rocketDAOProtocolSettingsMinipool")); - launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance(); - preLaunchValue = rocketDAOProtocolSettingsMinipool.getPreLaunchValue(); - } - // Check that pre deposit won't fail - if (msg.value < preLaunchValue) { - RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(getContractAddress("rocketDepositPool")); - require(preLaunchValue.sub(msg.value) <= rocketDepositPool.getBalance(), "Deposit pool balance is insufficient for pre deposit"); - } - // Emit deposit received event - emit DepositReceived(msg.sender, msg.value, block.timestamp); - // Increase ETH matched (used to calculate RPL collateral requirements) - _increaseEthMatched(msg.sender, launchAmount.sub(_bondAmount)); - // Create the minipool - RocketMinipoolInterface minipool = createMinipool(_salt, _expectedMinipoolAddress); - // Process node deposit - _processNodeDeposit(preLaunchValue, _bondAmount); - // Perform the pre deposit - minipool.preDeposit{value: preLaunchValue}(_bondAmount, _validatorPubkey, _validatorSignature, _depositDataRoot); - // Enqueue the minipool - enqueueMinipool(address(minipool)); - // Assign deposits if enabled - assignDeposits(); - } - - /// @dev Processes a node deposit with the deposit pool - /// @param _preLaunchValue The prelaunch value (result of call to `RocketDAOProtocolSettingsMinipool.getPreLaunchValue()` - /// @param _bondAmount The bond amount for this deposit - function _processNodeDeposit(uint256 _preLaunchValue, uint256 _bondAmount) private { - // Get contracts - RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(getContractAddress("rocketDepositPool")); - // Retrieve ETH from deposit pool if required - uint256 shortFall = 0; - if (msg.value < _preLaunchValue) { - shortFall = _preLaunchValue.sub(msg.value); - rocketDepositPool.nodeCreditWithdrawal(shortFall); - } - uint256 remaining = msg.value.add(shortFall).sub(_preLaunchValue); - // Deposit the left over value into the deposit pool - rocketDepositPool.nodeDeposit{value: remaining}(_bondAmount.sub(_preLaunchValue)); - } - - /// @notice Creates a "vacant" minipool which a node operator can use to migrate a validator with a BLS withdrawal credential - /// @param _bondAmount The amount of capital the node operator wants to put up as his bond - /// @param _minimumNodeFee Transaction will revert if network commission rate drops below this amount - /// @param _validatorPubkey Pubkey of the validator the node operator wishes to migrate - /// @param _salt Salt used to deterministically construct the minipool's address - /// @param _expectedMinipoolAddress The expected deterministic minipool address. Will revert if it doesn't match - /// @param _currentBalance The current balance of the validator on the beaconchain (will be checked by oDAO and scrubbed if not correct) - function createVacantMinipool(uint256 _bondAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, uint256 _salt, address _expectedMinipoolAddress, uint256 _currentBalance) override external onlyLatestContract("rocketNodeDeposit", address(this)) onlyRegisteredNode(msg.sender) { - // Check pre-conditions - checkVacantMinipoolsEnabled(); - checkDistributorInitialised(); - checkNodeFee(_minimumNodeFee); - require(isValidDepositAmount(_bondAmount), "Invalid deposit amount"); - // Increase ETH matched (used to calculate RPL collateral requirements) - RocketDAOProtocolSettingsMinipoolInterface rocketDAOProtocolSettingsMinipool = RocketDAOProtocolSettingsMinipoolInterface(getContractAddress("rocketDAOProtocolSettingsMinipool")); - uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance(); - _increaseEthMatched(msg.sender, launchAmount.sub(_bondAmount)); - // Create the minipool - _createVacantMinipool(_salt, _validatorPubkey, _bondAmount, _expectedMinipoolAddress, _currentBalance); - } - - /// @notice Called by minipools during bond reduction to increase the amount of ETH the node operator has - /// @param _nodeAddress The node operator's address to increase the ETH matched for - /// @param _amount The amount to increase the ETH matched - /// @dev Will revert if the new ETH matched amount exceeds the node operators limit - function increaseEthMatched(address _nodeAddress, uint256 _amount) override external onlyLatestContract("rocketNodeDeposit", address(this)) onlyLatestNetworkContract() { - _increaseEthMatched(_nodeAddress, _amount); - } - - /// @dev Increases the amount of ETH that has been matched against a node operators bond. Reverts if it exceeds the - /// collateralisation requirements of the network - function _increaseEthMatched(address _nodeAddress, uint256 _amount) private { - // Check amount doesn't exceed limits - RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking")); - uint256 ethMatched = rocketNodeStaking.getNodeETHMatched(_nodeAddress).add(_amount); - require( - ethMatched <= rocketNodeStaking.getNodeETHMatchedLimit(_nodeAddress), - "ETH matched after deposit exceeds limit based on node RPL stake" - ); - setUint(keccak256(abi.encodePacked("eth.matched.node.amount", _nodeAddress)), ethMatched); - } - - /// @dev Adds a minipool to the queue - function enqueueMinipool(address _minipoolAddress) private { - // Add minipool to queue - RocketMinipoolQueueInterface(getContractAddress("rocketMinipoolQueue")).enqueueMinipool(_minipoolAddress); - } - - /// @dev Reverts if node operator has not initialised their fee distributor - function checkDistributorInitialised() private view { - // Check node has initialised their fee distributor - RocketNodeManagerInterface rocketNodeManager = RocketNodeManagerInterface(getContractAddress("rocketNodeManager")); - require(rocketNodeManager.getFeeDistributorInitialised(msg.sender), "Fee distributor not initialised"); - } - - /// @dev Creates a minipool and returns an instance of it - /// @param _salt The salt used to determine the minipools address - /// @param _expectedMinipoolAddress The expected minipool address. Reverts if not correct - function createMinipool(uint256 _salt, address _expectedMinipoolAddress) private returns (RocketMinipoolInterface) { - // Load contracts - RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager")); - // Check minipool doesn't exist or previously exist - require(!rocketMinipoolManager.getMinipoolExists(_expectedMinipoolAddress) && !rocketMinipoolManager.getMinipoolDestroyed(_expectedMinipoolAddress), "Minipool already exists or was previously destroyed"); - // Create minipool - RocketMinipoolInterface minipool = rocketMinipoolManager.createMinipool(msg.sender, _salt); - // Ensure minipool address matches expected - require(address(minipool) == _expectedMinipoolAddress, "Unexpected minipool address"); - // Return - return minipool; - } - - /// @dev Creates a vacant minipool and returns an instance of it - /// @param _salt The salt used to determine the minipools address - /// @param _validatorPubkey Pubkey of the validator owning this minipool - /// @param _bondAmount ETH value the node operator is putting up as capital for this minipool - /// @param _expectedMinipoolAddress The expected minipool address. Reverts if not correct - /// @param _currentBalance The current balance of the validator on the beaconchain (will be checked by oDAO and scrubbed if not correct) - function _createVacantMinipool(uint256 _salt, bytes calldata _validatorPubkey, uint256 _bondAmount, address _expectedMinipoolAddress, uint256 _currentBalance) private returns (RocketMinipoolInterface) { - // Load contracts - RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager")); - // Check minipool doesn't exist or previously exist - require(!rocketMinipoolManager.getMinipoolExists(_expectedMinipoolAddress) && !rocketMinipoolManager.getMinipoolDestroyed(_expectedMinipoolAddress), "Minipool already exists or was previously destroyed"); - // Create minipool - RocketMinipoolInterface minipool = rocketMinipoolManager.createVacantMinipool(msg.sender, _salt, _validatorPubkey, _bondAmount, _currentBalance); - // Ensure minipool address matches expected - require(address(minipool) == _expectedMinipoolAddress, "Unexpected minipool address"); - // Return - return minipool; - } - - /// @dev Reverts if network node fee is below a minimum - /// @param _minimumNodeFee The minimum node fee required to not revert - function checkNodeFee(uint256 _minimumNodeFee) private view { - // Load contracts - RocketNetworkFeesInterface rocketNetworkFees = RocketNetworkFeesInterface(getContractAddress("rocketNetworkFees")); - // Check current node fee - uint256 nodeFee = rocketNetworkFees.getNodeFee(); - require(nodeFee >= _minimumNodeFee, "Minimum node fee exceeds current network node fee"); - } - - /// @dev Reverts if deposits are not enabled - function checkDepositsEnabled() private view { - // Get contracts - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - // Check node settings - require(rocketDAOProtocolSettingsNode.getDepositEnabled(), "Node deposits are currently disabled"); - } - - /// @dev Reverts if vacant minipools are not enabled - function checkVacantMinipoolsEnabled() private view { - // Get contracts - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - // Check node settings - require(rocketDAOProtocolSettingsNode.getVacantMinipoolsEnabled(), "Vacant minipools are currently disabled"); - } - - /// @dev Executes an assignDeposits call on the deposit pool - function assignDeposits() private { - RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(getContractAddress("rocketDepositPool")); - rocketDepositPool.maybeAssignDeposits(); - } -} \ No newline at end of file diff --git a/contracts/old/contract/node/RocketNodeManagerOld.sol b/contracts/old/contract/node/RocketNodeManagerOld.sol deleted file mode 100644 index 0c1bb5307..000000000 --- a/contracts/old/contract/node/RocketNodeManagerOld.sol +++ /dev/null @@ -1,385 +0,0 @@ -pragma solidity 0.7.6; -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "@openzeppelin/contracts/math/SafeMath.sol"; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - -import "../../interface/node/RocketNodeManagerInterfaceOld.sol"; -import "../../../contract/RocketBase.sol"; -import "../../../interface/util/AddressSetStorageInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterface.sol"; -import "../../../interface/node/RocketNodeDistributorFactoryInterface.sol"; -import "../../../interface/minipool/RocketMinipoolManagerInterface.sol"; -import "../../../interface/node/RocketNodeDepositInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterface.sol"; -import "../../../interface/dao/node/settings/RocketDAONodeTrustedSettingsRewardsInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterface.sol"; -import "../../../interface/node/RocketNodeStakingInterface.sol"; -import "../../../interface/node/RocketNodeDistributorInterface.sol"; - - -// Node registration and management -contract RocketNodeManagerOld is RocketBase, RocketNodeManagerInterfaceOld { - - // Libraries - using SafeMath for uint256; - - // Events - event NodeRegistered(address indexed node, uint256 time); - event NodeTimezoneLocationSet(address indexed node, uint256 time); - event NodeRewardNetworkChanged(address indexed node, uint256 network); - event NodeSmoothingPoolStateChanged(address indexed node, bool state); - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - version = 3; - } - - // Get the number of nodes in the network - function getNodeCount() override public view returns (uint256) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getCount(keccak256(abi.encodePacked("nodes.index"))); - } - - // Get a breakdown of the number of nodes per timezone - function getNodeCountPerTimezone(uint256 _offset, uint256 _limit) override external view returns (TimezoneCount[] memory) { - // Get contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Precompute node key - bytes32 nodeKey = keccak256(abi.encodePacked("nodes.index")); - // Calculate range - uint256 totalNodes = addressSetStorage.getCount(nodeKey); - uint256 max = _offset.add(_limit); - if (max > totalNodes || _limit == 0) { max = totalNodes; } - // Create an array with as many elements as there are potential values to return - TimezoneCount[] memory counts = new TimezoneCount[](max.sub(_offset)); - uint256 uniqueTimezoneCount = 0; - // Iterate the minipool range - for (uint256 i = _offset; i < max; i++) { - address nodeAddress = addressSetStorage.getItem(nodeKey, i); - string memory timezone = getString(keccak256(abi.encodePacked("node.timezone.location", nodeAddress))); - // Find existing entry in our array - bool existing = false; - for (uint256 j = 0; j < uniqueTimezoneCount; j++) { - if (keccak256(bytes(counts[j].timezone)) == keccak256(bytes(timezone))) { - existing = true; - // Increment the counter - counts[j].count++; - break; - } - } - // Entry was not found, so create a new one - if (!existing) { - counts[uniqueTimezoneCount].timezone = timezone; - counts[uniqueTimezoneCount].count = 1; - uniqueTimezoneCount++; - } - } - // Dirty hack to cut unused elements off end of return value - assembly { - mstore(counts, uniqueTimezoneCount) - } - return counts; - } - - // Get a node address by index - function getNodeAt(uint256 _index) override external view returns (address) { - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - return addressSetStorage.getItem(keccak256(abi.encodePacked("nodes.index")), _index); - } - - // Check whether a node exists - function getNodeExists(address _nodeAddress) override public view returns (bool) { - return getBool(keccak256(abi.encodePacked("node.exists", _nodeAddress))); - } - - // Get a node's current withdrawal address - function getNodeWithdrawalAddress(address _nodeAddress) override public view returns (address) { - return rocketStorage.getNodeWithdrawalAddress(_nodeAddress); - } - - // Get a node's pending withdrawal address - function getNodePendingWithdrawalAddress(address _nodeAddress) override public view returns (address) { - return rocketStorage.getNodePendingWithdrawalAddress(_nodeAddress); - } - - // Get a node's timezone location - function getNodeTimezoneLocation(address _nodeAddress) override public view returns (string memory) { - return getString(keccak256(abi.encodePacked("node.timezone.location", _nodeAddress))); - } - - // Register a new node with Rocket Pool - function registerNode(string calldata _timezoneLocation) override external onlyLatestContract("rocketNodeManager", address(this)) { - // Load contracts - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Check node settings - require(rocketDAOProtocolSettingsNode.getRegistrationEnabled(), "Rocket Pool node registrations are currently disabled"); - // Check timezone location - require(bytes(_timezoneLocation).length >= 4, "The timezone location is invalid"); - // Initialise node data - setBool(keccak256(abi.encodePacked("node.exists", msg.sender)), true); - setString(keccak256(abi.encodePacked("node.timezone.location", msg.sender)), _timezoneLocation); - // Add node to index - addressSetStorage.addItem(keccak256(abi.encodePacked("nodes.index")), msg.sender); - // Initialise fee distributor for this node - _initialiseFeeDistributor(msg.sender); - // Set node registration time (uses old storage key name for backwards compatibility) - setUint(keccak256(abi.encodePacked("rewards.pool.claim.contract.registered.time", "rocketClaimNode", msg.sender)), block.timestamp); - // Emit node registered event - emit NodeRegistered(msg.sender, block.timestamp); - } - - // Get's the timestamp of when a node was registered - function getNodeRegistrationTime(address _nodeAddress) onlyRegisteredNode(_nodeAddress) override public view returns (uint256) { - return getUint(keccak256(abi.encodePacked("rewards.pool.claim.contract.registered.time", "rocketClaimNode", _nodeAddress))); - } - - // Set a node's timezone location - // Only accepts calls from registered nodes - function setTimezoneLocation(string calldata _timezoneLocation) override external onlyLatestContract("rocketNodeManager", address(this)) onlyRegisteredNode(msg.sender) { - // Check timezone location - require(bytes(_timezoneLocation).length >= 4, "The timezone location is invalid"); - // Set timezone location - setString(keccak256(abi.encodePacked("node.timezone.location", msg.sender)), _timezoneLocation); - // Emit node timezone location set event - emit NodeTimezoneLocationSet(msg.sender, block.timestamp); - } - - // Returns true if node has initialised their fee distributor contract - function getFeeDistributorInitialised(address _nodeAddress) override public view returns (bool) { - // Load contracts - RocketNodeDistributorFactoryInterface rocketNodeDistributorFactory = RocketNodeDistributorFactoryInterface(getContractAddress("rocketNodeDistributorFactory")); - // Get distributor address - address contractAddress = rocketNodeDistributorFactory.getProxyAddress(_nodeAddress); - // Check if contract exists at that address - uint32 codeSize; - assembly { - codeSize := extcodesize(contractAddress) - } - return codeSize > 0; - } - - // Node operators created before the distributor was implemented must call this to setup their distributor contract - function initialiseFeeDistributor() override external onlyLatestContract("rocketNodeManager", address(this)) onlyRegisteredNode(msg.sender) { - // Prevent multiple calls - require(!getFeeDistributorInitialised(msg.sender), "Already initialised"); - // Load contracts - RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager")); - // Calculate and set current average fee numerator - uint256 count = rocketMinipoolManager.getNodeMinipoolCount(msg.sender); - if (count > 0){ - uint256 numerator = 0; - // Note: this loop is safe as long as all current node operators at the time of upgrade have few enough minipools - for (uint256 i = 0; i < count; i++) { - RocketMinipoolInterface minipool = RocketMinipoolInterface(rocketMinipoolManager.getNodeMinipoolAt(msg.sender, i)); - if (minipool.getStatus() == MinipoolStatus.Staking){ - numerator = numerator.add(minipool.getNodeFee()); - } - } - setUint(keccak256(abi.encodePacked("node.average.fee.numerator", msg.sender)), numerator); - } - // Create the distributor contract - _initialiseFeeDistributor(msg.sender); - } - - // Deploys the fee distributor contract for a given node - function _initialiseFeeDistributor(address _nodeAddress) internal { - // Load contracts - RocketNodeDistributorFactoryInterface rocketNodeDistributorFactory = RocketNodeDistributorFactoryInterface(getContractAddress("rocketNodeDistributorFactory")); - // Create the distributor proxy - rocketNodeDistributorFactory.createProxy(_nodeAddress); - } - - // Calculates a nodes average node fee - function getAverageNodeFee(address _nodeAddress) override external view returns (uint256) { - // Load contracts - RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager")); - RocketNodeDepositInterface rocketNodeDeposit = RocketNodeDepositInterface(getContractAddress("rocketNodeDeposit")); - RocketDAOProtocolSettingsMinipoolInterface rocketDAOProtocolSettingsMinipool = RocketDAOProtocolSettingsMinipoolInterface(getContractAddress("rocketDAOProtocolSettingsMinipool")); - // Get valid deposit amounts - uint256[] memory depositSizes = rocketNodeDeposit.getDepositAmounts(); - // Setup memory for calculations - uint256[] memory depositWeights = new uint256[](depositSizes.length); - uint256[] memory depositCounts = new uint256[](depositSizes.length); - uint256 depositWeightTotal; - uint256 totalCount; - uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance(); - // Retrieve the number of staking minipools per deposit size - for (uint256 i = 0; i < depositSizes.length; i++) { - depositCounts[i] = rocketMinipoolManager.getNodeStakingMinipoolCountBySize(_nodeAddress, depositSizes[i]); - totalCount = totalCount.add(depositCounts[i]); - } - if (totalCount == 0) { - return 0; - } - // Calculate the weights of each deposit size - for (uint256 i = 0; i < depositSizes.length; i++) { - depositWeights[i] = launchAmount.sub(depositSizes[i]).mul(depositCounts[i]); - depositWeightTotal = depositWeightTotal.add(depositWeights[i]); - } - for (uint256 i = 0; i < depositSizes.length; i++) { - depositWeights[i] = depositWeights[i].mul(calcBase).div(depositWeightTotal); - } - // Calculate the weighted average - uint256 weightedAverage = 0; - for (uint256 i = 0; i < depositSizes.length; i++) { - if (depositCounts[i] > 0) { - bytes32 numeratorKey; - if (depositSizes[i] == 16 ether) { - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", _nodeAddress)); - } else { - numeratorKey = keccak256(abi.encodePacked("node.average.fee.numerator", _nodeAddress, depositSizes[i])); - } - uint256 numerator = getUint(numeratorKey); - weightedAverage = weightedAverage.add(numerator.mul(depositWeights[i]).div(depositCounts[i])); - } - } - return weightedAverage.div(calcBase); - } - - // Designates which network a node would like their rewards relayed to - function setRewardNetwork(address _nodeAddress, uint256 _network) override external onlyLatestContract("rocketNodeManager", address(this)) { - // Confirm the transaction is from the node's current withdrawal address - address withdrawalAddress = rocketStorage.getNodeWithdrawalAddress(_nodeAddress); - require(withdrawalAddress == msg.sender, "Only a tx from a node's withdrawal address can change reward network"); - // Check network is enabled - RocketDAONodeTrustedSettingsRewardsInterface rocketDAONodeTrustedSettingsRewards = RocketDAONodeTrustedSettingsRewardsInterface(getContractAddress("rocketDAONodeTrustedSettingsRewards")); - require(rocketDAONodeTrustedSettingsRewards.getNetworkEnabled(_network), "Network is not enabled"); - // Set the network - setUint(keccak256(abi.encodePacked("node.reward.network", _nodeAddress)), _network); - // Emit event - emit NodeRewardNetworkChanged(_nodeAddress, _network); - } - - // Returns which network a node has designated as their desired reward network - function getRewardNetwork(address _nodeAddress) override public view onlyLatestContract("rocketNodeManager", address(this)) returns (uint256) { - return getUint(keccak256(abi.encodePacked("node.reward.network", _nodeAddress))); - } - - // Allows a node to register or deregister from the smoothing pool - function setSmoothingPoolRegistrationState(bool _state) override external onlyLatestContract("rocketNodeManager", address(this)) onlyRegisteredNode(msg.sender) { - // Ensure registration is enabled - RocketDAOProtocolSettingsNodeInterface daoSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - require(daoSettingsNode.getSmoothingPoolRegistrationEnabled(), "Smoothing pool registrations are not active"); - // Precompute storage keys - bytes32 changeKey = keccak256(abi.encodePacked("node.smoothing.pool.changed.time", msg.sender)); - bytes32 stateKey = keccak256(abi.encodePacked("node.smoothing.pool.state", msg.sender)); - // Get from the DAO settings - RocketDAOProtocolSettingsRewardsInterface daoSettingsRewards = RocketDAOProtocolSettingsRewardsInterface(getContractAddress("rocketDAOProtocolSettingsRewards")); - uint256 rewardInterval = daoSettingsRewards.getRewardsClaimIntervalTime(); - // Ensure node operator has waited the required time - uint256 lastChange = getUint(changeKey); - require(block.timestamp >= lastChange.add(rewardInterval), "Not enough time has passed since changing state"); - // Ensure state is actually changing - require(getBool(stateKey) != _state, "Invalid state change"); - // Update registration state - setUint(changeKey, block.timestamp); - setBool(stateKey, _state); - // Emit state change event - emit NodeSmoothingPoolStateChanged(msg.sender, _state); - } - - // Returns whether a node is registered or not from the smoothing pool - function getSmoothingPoolRegistrationState(address _nodeAddress) override public view returns (bool) { - return getBool(keccak256(abi.encodePacked("node.smoothing.pool.state", _nodeAddress))); - } - - // Returns the timestamp of when the node last changed their smoothing pool registration state - function getSmoothingPoolRegistrationChanged(address _nodeAddress) override external view returns (uint256) { - return getUint(keccak256(abi.encodePacked("node.smoothing.pool.changed.time", _nodeAddress))); - } - - // Returns the sum of nodes that are registered for the smoothing pool between _offset and (_offset + _limit) - function getSmoothingPoolRegisteredNodeCount(uint256 _offset, uint256 _limit) override external view returns (uint256) { - // Get contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Precompute node key - bytes32 nodeKey = keccak256(abi.encodePacked("nodes.index")); - // Iterate over the requested minipool range - uint256 totalNodes = getNodeCount(); - uint256 max = _offset.add(_limit); - if (max > totalNodes || _limit == 0) { max = totalNodes; } - uint256 count = 0; - for (uint256 i = _offset; i < max; i++) { - address nodeAddress = addressSetStorage.getItem(nodeKey, i); - if (getSmoothingPoolRegistrationState(nodeAddress)) { - count++; - } - } - return count; - } - - /// @notice Convenience function to return all on-chain details about a given node - /// @param _nodeAddress Address of the node to query details for - function getNodeDetails(address _nodeAddress) override public view returns (NodeDetails memory nodeDetails) { - // Get contracts - RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking")); - RocketNodeDepositInterface rocketNodeDeposit = RocketNodeDepositInterface(getContractAddress("rocketNodeDeposit")); - RocketNodeDistributorFactoryInterface rocketNodeDistributorFactory = RocketNodeDistributorFactoryInterface(getContractAddress("rocketNodeDistributorFactory")); - RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager")); - IERC20 rocketTokenRETH = IERC20(getContractAddress("rocketTokenRETH")); - IERC20 rocketTokenRPL = IERC20(getContractAddress("rocketTokenRPL")); - IERC20 rocketTokenRPLFixedSupply = IERC20(getContractAddress("rocketTokenRPLFixedSupply")); - // Node details - nodeDetails.nodeAddress = _nodeAddress; - nodeDetails.withdrawalAddress = rocketStorage.getNodeWithdrawalAddress(_nodeAddress); - nodeDetails.pendingWithdrawalAddress = rocketStorage.getNodePendingWithdrawalAddress(_nodeAddress); - nodeDetails.exists = getNodeExists(_nodeAddress); - nodeDetails.registrationTime = getNodeRegistrationTime(_nodeAddress); - nodeDetails.timezoneLocation = getNodeTimezoneLocation(_nodeAddress); - nodeDetails.feeDistributorInitialised = getFeeDistributorInitialised(_nodeAddress); - nodeDetails.rewardNetwork = getRewardNetwork(_nodeAddress); - // Staking details - nodeDetails.rplStake = rocketNodeStaking.getNodeRPLStake(_nodeAddress); - nodeDetails.effectiveRPLStake = rocketNodeStaking.getNodeEffectiveRPLStake(_nodeAddress); - nodeDetails.minimumRPLStake = rocketNodeStaking.getNodeMinimumRPLStake(_nodeAddress); - nodeDetails.maximumRPLStake = rocketNodeStaking.getNodeMaximumRPLStake(_nodeAddress); - nodeDetails.ethMatched = rocketNodeStaking.getNodeETHMatched(_nodeAddress); - nodeDetails.ethMatchedLimit = rocketNodeStaking.getNodeETHMatchedLimit(_nodeAddress); - // Distributor details - nodeDetails.feeDistributorAddress = rocketNodeDistributorFactory.getProxyAddress(_nodeAddress); - uint256 distributorBalance = nodeDetails.feeDistributorAddress.balance; - RocketNodeDistributorInterface distributor = RocketNodeDistributorInterface(nodeDetails.feeDistributorAddress); - nodeDetails.distributorBalanceNodeETH = distributor.getNodeShare(); - nodeDetails.distributorBalanceUserETH = distributorBalance.sub(nodeDetails.distributorBalanceNodeETH); - // Minipool details - nodeDetails.minipoolCount = rocketMinipoolManager.getNodeMinipoolCount(_nodeAddress); - // Balance details - nodeDetails.balanceETH = _nodeAddress.balance; - nodeDetails.balanceRETH = rocketTokenRETH.balanceOf(_nodeAddress); - nodeDetails.balanceRPL = rocketTokenRPL.balanceOf(_nodeAddress); - nodeDetails.balanceOldRPL = rocketTokenRPLFixedSupply.balanceOf(_nodeAddress); - nodeDetails.depositCreditBalance = rocketNodeDeposit.getNodeDepositCredit(_nodeAddress); - // Return - return nodeDetails; - } - - /// @notice Returns a slice of the node operator address set - /// @param _offset The starting point into the slice - /// @param _limit The maximum number of results to return - function getNodeAddresses(uint256 _offset, uint256 _limit) override external view returns (address[] memory) { - // Get contracts - AddressSetStorageInterface addressSetStorage = AddressSetStorageInterface(getContractAddress("addressSetStorage")); - // Precompute node key - bytes32 nodeKey = keccak256(abi.encodePacked("nodes.index")); - // Iterate over the requested minipool range - uint256 totalNodes = getNodeCount(); - uint256 max = _offset.add(_limit); - if (max > totalNodes || _limit == 0) { max = totalNodes; } - // Create array big enough for every minipool - address[] memory nodes = new address[](max.sub(_offset)); - uint256 total = 0; - for (uint256 i = _offset; i < max; i++) { - nodes[total] = addressSetStorage.getItem(nodeKey, i); - total++; - } - // Dirty hack to cut unused elements off end of return value - assembly { - mstore(nodes, total) - } - return nodes; - } -} \ No newline at end of file diff --git a/contracts/old/contract/node/RocketNodeStakingOld.sol b/contracts/old/contract/node/RocketNodeStakingOld.sol deleted file mode 100644 index 1194d70b9..000000000 --- a/contracts/old/contract/node/RocketNodeStakingOld.sol +++ /dev/null @@ -1,301 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity 0.7.6; - -import "@openzeppelin/contracts/math/SafeMath.sol"; - -import "../../interface/node/RocketNodeStakingInterfaceOld.sol"; -import "../../../contract/RocketBase.sol"; -import "../../interface/minipool/RocketMinipoolManagerInterfaceOld.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterface.sol"; -import "../../../interface/network/RocketNetworkPricesInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterface.sol"; -import "../../../interface/RocketVaultInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterface.sol"; - - -/// @notice Handles node deposits and minipool creation -contract RocketNodeStakingOld is RocketBase, RocketNodeStakingInterfaceOld { - - // Libs - using SafeMath for uint; - - // Events - event RPLStaked(address indexed from, uint256 amount, uint256 time); - event RPLWithdrawn(address indexed to, uint256 amount, uint256 time); - event RPLSlashed(address indexed node, uint256 amount, uint256 ethValue, uint256 time); - event StakeRPLForAllowed(address indexed node, address indexed caller, bool allowed, uint256 time); - - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - version = 4; - } - - /// @notice Returns the total quantity of RPL staked on the network - function getTotalRPLStake() override external view returns (uint256) { - return getUint(keccak256("rpl.staked.total.amount")); - } - - /// @dev Increases the total network RPL stake - /// @param _amount How much to increase by - function increaseTotalRPLStake(uint256 _amount) private { - addUint(keccak256("rpl.staked.total.amount"), _amount); - } - - /// @dev Decrease the total network RPL stake - /// @param _amount How much to decrease by - function decreaseTotalRPLStake(uint256 _amount) private { - subUint(keccak256("rpl.staked.total.amount"), _amount); - } - - /// @notice Returns the amount a given node operator has staked - /// @param _nodeAddress The address of the node operator to query - function getNodeRPLStake(address _nodeAddress) override public view returns (uint256) { - return getUint(keccak256(abi.encodePacked("rpl.staked.node.amount", _nodeAddress))); - } - - /// @dev Increases a node operator's RPL stake - /// @param _amount How much to increase by - function increaseNodeRPLStake(address _nodeAddress, uint256 _amount) private { - addUint(keccak256(abi.encodePacked("rpl.staked.node.amount", _nodeAddress)), _amount); - } - - /// @dev Decrease a node operator's RPL stake - /// @param _amount How much to decrease by - function decreaseNodeRPLStake(address _nodeAddress, uint256 _amount) private { - subUint(keccak256(abi.encodePacked("rpl.staked.node.amount", _nodeAddress)), _amount); - } - - /// @notice Returns a node's matched ETH amount (amount taken from protocol to stake) - /// @param _nodeAddress The address of the node operator to query - function getNodeETHMatched(address _nodeAddress) override public view returns (uint256) { - uint256 ethMatched = getUint(keccak256(abi.encodePacked("eth.matched.node.amount", _nodeAddress))); - - if (ethMatched > 0) { - return ethMatched; - } else { - // Fallback for backwards compatibility before ETH matched was recorded (all minipools matched 16 ETH from protocol) - RocketMinipoolManagerInterfaceOld rocketMinipoolManager = RocketMinipoolManagerInterfaceOld(getContractAddress("rocketMinipoolManager")); - return rocketMinipoolManager.getNodeActiveMinipoolCount(_nodeAddress).mul(16 ether); - } - } - - /// @notice Returns a node's provided ETH amount (amount supplied to create minipools) - /// @param _nodeAddress The address of the node operator to query - function getNodeETHProvided(address _nodeAddress) override public view returns (uint256) { - // Get contracts - RocketMinipoolManagerInterfaceOld rocketMinipoolManager = RocketMinipoolManagerInterfaceOld(getContractAddress("rocketMinipoolManager")); - uint256 activeMinipoolCount = rocketMinipoolManager.getNodeActiveMinipoolCount(_nodeAddress); - // Retrieve stored ETH matched value - uint256 ethMatched = getUint(keccak256(abi.encodePacked("eth.matched.node.amount", _nodeAddress))); - if (ethMatched > 0) { - RocketDAOProtocolSettingsMinipoolInterface rocketDAOProtocolSettingsMinipool = RocketDAOProtocolSettingsMinipoolInterface(getContractAddress("rocketDAOProtocolSettingsMinipool")); - uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance(); - // ETH provided is number of staking minipools * 32 - eth matched - uint256 totalEthStaked = activeMinipoolCount.mul(launchAmount); - return totalEthStaked.sub(ethMatched); - } else { - // Fallback for legacy minipools is number of staking minipools * 16 - return activeMinipoolCount.mul(16 ether); - } - } - - /// @notice Returns the ratio between capital taken from users and provided by a node operator. - /// The value is a 1e18 precision fixed point integer value of (node capital + user capital) / node capital. - /// @param _nodeAddress The address of the node operator to query - function getNodeETHCollateralisationRatio(address _nodeAddress) override public view returns (uint256) { - uint256 ethMatched = getUint(keccak256(abi.encodePacked("eth.matched.node.amount", _nodeAddress))); - if (ethMatched == 0) { - // Node operator only has legacy minipools and all legacy minipools had a 1:1 ratio - return calcBase.mul(2); - } else { - RocketDAOProtocolSettingsMinipoolInterface rocketDAOProtocolSettingsMinipool = RocketDAOProtocolSettingsMinipoolInterface(getContractAddress("rocketDAOProtocolSettingsMinipool")); - uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance(); - RocketMinipoolManagerInterfaceOld rocketMinipoolManager = RocketMinipoolManagerInterfaceOld(getContractAddress("rocketMinipoolManager")); - uint256 totalEthStaked = rocketMinipoolManager.getNodeActiveMinipoolCount(_nodeAddress).mul(launchAmount); - return totalEthStaked.mul(calcBase).div(totalEthStaked.sub(ethMatched)); - } - } - - /// @notice Returns the timestamp at which a node last staked RPL - function getNodeRPLStakedTime(address _nodeAddress) override public view returns (uint256) { - return getUint(keccak256(abi.encodePacked("rpl.staked.node.time", _nodeAddress))); - } - - /// @dev Sets the timestamp at which a node last staked RPL - /// @param _nodeAddress The address of the node operator to set the value for - /// @param _time The timestamp to set - function setNodeRPLStakedTime(address _nodeAddress, uint256 _time) private { - setUint(keccak256(abi.encodePacked("rpl.staked.node.time", _nodeAddress)), _time); - } - - /// @notice Calculate and return a node's effective RPL stake amount - /// @param _nodeAddress The address of the node operator to calculate for - function getNodeEffectiveRPLStake(address _nodeAddress) override external view returns (uint256) { - // Load contracts - RocketNetworkPricesInterface rocketNetworkPrices = RocketNetworkPricesInterface(getContractAddress("rocketNetworkPrices")); - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - // Get node's current RPL stake - uint256 rplStake = getNodeRPLStake(_nodeAddress); - // Retrieve variables for calculations - uint256 matchedETH = getNodeETHMatched(_nodeAddress); - uint256 providedETH = getNodeETHProvided(_nodeAddress); - uint256 rplPrice = rocketNetworkPrices.getRPLPrice(); - // RPL stake cannot exceed maximum - uint256 maximumStakePercent = rocketDAOProtocolSettingsNode.getMaximumPerMinipoolStake(); - uint256 maximumStake = providedETH.mul(maximumStakePercent).div(rplPrice); - if (rplStake > maximumStake) { - return maximumStake; - } - // If RPL stake is lower than minimum, node has no effective stake - uint256 minimumStakePercent = rocketDAOProtocolSettingsNode.getMinimumPerMinipoolStake(); - uint256 minimumStake = matchedETH.mul(minimumStakePercent).div(rplPrice); - if (rplStake < minimumStake) { - return 0; - } - // Otherwise, return the actual stake - return rplStake; - } - - /// @notice Calculate and return a node's minimum RPL stake to collateralize their minipools - /// @param _nodeAddress The address of the node operator to calculate for - function getNodeMinimumRPLStake(address _nodeAddress) override external view returns (uint256) { - // Load contracts - RocketNetworkPricesInterface rocketNetworkPrices = RocketNetworkPricesInterface(getContractAddress("rocketNetworkPrices")); - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - // Retrieve variables - uint256 minimumStakePercent = rocketDAOProtocolSettingsNode.getMinimumPerMinipoolStake(); - uint256 matchedETH = getNodeETHMatched(_nodeAddress); - return matchedETH - .mul(minimumStakePercent) - .div(rocketNetworkPrices.getRPLPrice()); - } - - /// @notice Calculate and return a node's maximum RPL stake to fully collateralise their minipools - /// @param _nodeAddress The address of the node operator to calculate for - function getNodeMaximumRPLStake(address _nodeAddress) override public view returns (uint256) { - // Load contracts - RocketNetworkPricesInterface rocketNetworkPrices = RocketNetworkPricesInterface(getContractAddress("rocketNetworkPrices")); - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - // Retrieve variables - uint256 maximumStakePercent = rocketDAOProtocolSettingsNode.getMaximumPerMinipoolStake(); - uint256 providedETH = getNodeETHProvided(_nodeAddress); - return providedETH - .mul(maximumStakePercent) - .div(rocketNetworkPrices.getRPLPrice()); - } - - /// @notice Calculate and return a node's limit of how much user ETH they can use based on RPL stake - /// @param _nodeAddress The address of the node operator to calculate for - function getNodeETHMatchedLimit(address _nodeAddress) override external view returns (uint256) { - // Load contracts - RocketNetworkPricesInterface rocketNetworkPrices = RocketNetworkPricesInterface(getContractAddress("rocketNetworkPrices")); - RocketDAOProtocolSettingsNodeInterface rocketDAOProtocolSettingsNode = RocketDAOProtocolSettingsNodeInterface(getContractAddress("rocketDAOProtocolSettingsNode")); - // Calculate & return limit - uint256 minimumStakePercent = rocketDAOProtocolSettingsNode.getMinimumPerMinipoolStake(); - return getNodeRPLStake(_nodeAddress) - .mul(rocketNetworkPrices.getRPLPrice()) - .div(minimumStakePercent); - } - - /// @notice Accept an RPL stake - /// Only accepts calls from registered nodes - /// Requires call to have approved this contract to spend RPL - /// @param _amount The amount of RPL to stake - function stakeRPL(uint256 _amount) override external onlyLatestContract("rocketNodeStaking", address(this)) onlyRegisteredNode(msg.sender) { - _stakeRPL(msg.sender, _amount); - } - - /// @notice Accept an RPL stake from any address for a specified node - /// Requires caller to have approved this contract to spend RPL - /// Requires caller to be on the node operator's allow list (see `setStakeForAllowed`) - /// @param _nodeAddress The address of the node operator to stake on behalf of - /// @param _amount The amount of RPL to stake - function stakeRPLFor(address _nodeAddress, uint256 _amount) override external onlyLatestContract("rocketNodeStaking", address(this)) onlyRegisteredNode(_nodeAddress) { - // Must be node's withdrawal address, allow listed address or rocketMerkleDistributorMainnet - if (msg.sender != getAddress(keccak256(abi.encodePacked("contract.address", "rocketMerkleDistributorMainnet")))) { - address withdrawalAddress = rocketStorage.getNodeWithdrawalAddress(_nodeAddress); - if (msg.sender != withdrawalAddress) { - require(getBool(keccak256(abi.encodePacked("node.stake.for.allowed", _nodeAddress, msg.sender))), "Not allowed to stake for"); - } - } - _stakeRPL(_nodeAddress, _amount); - } - - /// @notice Explicitly allow or remove allowance of an address to be able to stake on behalf of a node - /// @param _caller The address you wish to allow - /// @param _allowed Whether the address is allowed or denied - function setStakeRPLForAllowed(address _caller, bool _allowed) override external onlyLatestContract("rocketNodeStaking", address(this)) onlyRegisteredNode(msg.sender) { - setBool(keccak256(abi.encodePacked("node.stake.for.allowed", msg.sender, _caller)), _allowed); - emit StakeRPLForAllowed(msg.sender, _caller, _allowed, block.timestamp); - } - - /// @dev Internal logic for staking RPL - /// @param _nodeAddress The address to increase the RPL stake of - /// @param _amount The amount of RPL to stake - function _stakeRPL(address _nodeAddress, uint256 _amount) internal { - // Load contracts - address rplTokenAddress = getContractAddress("rocketTokenRPL"); - address rocketVaultAddress = getContractAddress("rocketVault"); - IERC20 rplToken = IERC20(rplTokenAddress); - RocketVaultInterface rocketVault = RocketVaultInterface(rocketVaultAddress); - // Transfer RPL tokens - require(rplToken.transferFrom(msg.sender, address(this), _amount), "Could not transfer RPL to staking contract"); - // Deposit RPL tokens to vault - require(rplToken.approve(rocketVaultAddress, _amount), "Could not approve vault RPL deposit"); - rocketVault.depositToken("rocketNodeStaking", rplToken, _amount); - // Update RPL stake amounts & node RPL staked block - increaseTotalRPLStake(_amount); - increaseNodeRPLStake(_nodeAddress, _amount); - setNodeRPLStakedTime(_nodeAddress, block.timestamp); - // Emit RPL staked event - emit RPLStaked(_nodeAddress, _amount, block.timestamp); - } - - /// @notice Withdraw staked RPL back to the node account - /// Only accepts calls from registered nodes - /// Withdraws to withdrawal address if set, otherwise defaults to node address - /// @param _amount The amount of RPL to withdraw - function withdrawRPL(uint256 _amount) override external onlyLatestContract("rocketNodeStaking", address(this)) onlyRegisteredNode(msg.sender) { - // Load contracts - RocketDAOProtocolSettingsRewardsInterface rocketDAOProtocolSettingsRewards = RocketDAOProtocolSettingsRewardsInterface(getContractAddress("rocketDAOProtocolSettingsRewards")); - RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault")); - // Check cooldown period (one claim period) has passed since RPL last staked - require(block.timestamp.sub(getNodeRPLStakedTime(msg.sender)) >= rocketDAOProtocolSettingsRewards.getRewardsClaimIntervalTime(), "The withdrawal cooldown period has not passed"); - // Get & check node's current RPL stake - uint256 rplStake = getNodeRPLStake(msg.sender); - require(rplStake >= _amount, "Withdrawal amount exceeds node's staked RPL balance"); - // Check withdrawal would not undercollateralize node - require(rplStake.sub(_amount) >= getNodeMaximumRPLStake(msg.sender), "Node's staked RPL balance after withdrawal is less than required balance"); - // Update RPL stake amounts - decreaseTotalRPLStake(_amount); - decreaseNodeRPLStake(msg.sender, _amount); - // Transfer RPL tokens to node address - rocketVault.withdrawToken(rocketStorage.getNodeWithdrawalAddress(msg.sender), IERC20(getContractAddress("rocketTokenRPL")), _amount); - // Emit RPL withdrawn event - emit RPLWithdrawn(msg.sender, _amount, block.timestamp); - } - - /// @notice Slash a node's RPL by an ETH amount - /// Only accepts calls from registered minipools - /// @param _nodeAddress The address to slash RPL from - /// @param _ethSlashAmount The amount of RPL to slash denominated in ETH value - function slashRPL(address _nodeAddress, uint256 _ethSlashAmount) override external onlyLatestContract("rocketNodeStaking", address(this)) onlyRegisteredMinipool(msg.sender) { - // Load contracts - RocketNetworkPricesInterface rocketNetworkPrices = RocketNetworkPricesInterface(getContractAddress("rocketNetworkPrices")); - RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault")); - // Calculate RPL amount to slash - uint256 rplSlashAmount = calcBase.mul(_ethSlashAmount).div(rocketNetworkPrices.getRPLPrice()); - // Cap slashed amount to node's RPL stake - uint256 rplStake = getNodeRPLStake(_nodeAddress); - if (rplSlashAmount > rplStake) { rplSlashAmount = rplStake; } - // Transfer slashed amount to auction contract - if(rplSlashAmount > 0) rocketVault.transferToken("rocketAuctionManager", IERC20(getContractAddress("rocketTokenRPL")), rplSlashAmount); - // Update RPL stake amounts - decreaseTotalRPLStake(rplSlashAmount); - decreaseNodeRPLStake(_nodeAddress, rplSlashAmount); - // Mark minipool as slashed - setBool(keccak256(abi.encodePacked("minipool.rpl.slashed", msg.sender)), true); - // Emit RPL slashed event - emit RPLSlashed(_nodeAddress, rplSlashAmount, _ethSlashAmount, block.timestamp); - } - -} \ No newline at end of file diff --git a/contracts/old/contract/rewards/RocketClaimDAOOld.sol b/contracts/old/contract/rewards/RocketClaimDAOOld.sol deleted file mode 100644 index e7f27a415..000000000 --- a/contracts/old/contract/rewards/RocketClaimDAOOld.sol +++ /dev/null @@ -1,38 +0,0 @@ -pragma solidity 0.7.6; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../contract/RocketBase.sol"; -import "../../../interface/RocketVaultInterface.sol"; -import "../../../interface/rewards/RocketRewardsPoolInterface.sol"; -import "../../interface/rewards/claims/RocketClaimDAOInterfaceOld.sol"; - - -// RPL Rewards claiming by the DAO -contract RocketClaimDAOOld is RocketBase, RocketClaimDAOInterfaceOld { - - // Events - event RPLTokensSentByDAOProtocol(string invoiceID, address indexed from, address indexed to, uint256 amount, uint256 time); - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - // Version - version = 2; - } - - // Spend the network DAOs RPL rewards - function spend(string memory _invoiceID, address _recipientAddress, uint256 _amount) override external onlyLatestContract("rocketDAOProtocolProposals", msg.sender) { - // Load contracts - RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault")); - // Addresses - IERC20 rplToken = IERC20(getContractAddress("rocketTokenRPL")); - // Some initial checks - require(_amount > 0 && _amount <= rocketVault.balanceOfToken("rocketClaimDAO", rplToken), "You cannot send 0 RPL or more than the DAO has in its account"); - // Send now - rocketVault.withdrawToken(_recipientAddress, rplToken, _amount); - // Log it - emit RPLTokensSentByDAOProtocol(_invoiceID, address(this), _recipientAddress, _amount, block.timestamp); - } - - -} \ No newline at end of file diff --git a/contracts/old/contract/rewards/RocketMerkleDistributorMainnetOld.sol b/contracts/old/contract/rewards/RocketMerkleDistributorMainnetOld.sol deleted file mode 100644 index db54b2b04..000000000 --- a/contracts/old/contract/rewards/RocketMerkleDistributorMainnetOld.sol +++ /dev/null @@ -1,169 +0,0 @@ -pragma solidity 0.7.6; -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../contract/RocketBase.sol"; -import "../../../interface/rewards/RocketRewardsRelayInterface.sol"; -import "../../../interface/RocketVaultWithdrawerInterface.sol"; -import "../../../interface/RocketVaultInterface.sol"; -import "../../../interface/token/RocketTokenRPLInterface.sol"; -import "../../../interface/node/RocketNodeStakingInterface.sol"; - -import "@openzeppelin/contracts/math/SafeMath.sol"; -import "@openzeppelin/contracts/cryptography/MerkleProof.sol"; - -/* -* On mainnet, the relay and the distributor are the same contract as there is no need for an intermediate contract to -* handle cross-chain messaging. -*/ - -contract RocketMerkleDistributorMainnetOld is RocketBase, RocketRewardsRelayInterface, RocketVaultWithdrawerInterface { - - // Libs - using SafeMath for uint; - - // Events - event RewardsClaimed(address indexed claimer, uint256[] rewardIndex, uint256[] amountRPL, uint256[] amountETH); - - // Constants - uint256 constant network = 0; - - // Immutables - bytes32 immutable rocketVaultKey; - bytes32 immutable rocketTokenRPLKey; - - // Allow receiving ETH - receive() payable external {} - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - // Version - version = 1; - // Precompute keys - rocketVaultKey = keccak256(abi.encodePacked("contract.address", "rocketVault")); - rocketTokenRPLKey = keccak256(abi.encodePacked("contract.address", "rocketTokenRPL")); - // Set this contract as the relay for network 0 - setAddress(keccak256(abi.encodePacked("rewards.relay.address", uint256(0))), address(this)); - } - - // Called by RocketRewardsPool to include a snapshot into this distributor - function relayRewards(uint256 _rewardIndex, bytes32 _root, uint256 _rewardsRPL, uint256 _rewardsETH) external override onlyLatestContract("rocketMerkleDistributorMainnet", address(this)) onlyLatestContract("rocketRewardsPool", msg.sender) { - bytes32 key = keccak256(abi.encodePacked('rewards.merkle.root', _rewardIndex)); - require(getBytes32(key) == bytes32(0)); - setBytes32(key, _root); - // Send the ETH and RPL to the vault - RocketVaultInterface rocketVault = RocketVaultInterface(getAddress(rocketVaultKey)); - if (_rewardsETH > 0) { - rocketVault.depositEther{value: _rewardsETH}(); - } - if (_rewardsRPL > 0) { - IERC20 rocketTokenRPL = IERC20(getAddress(rocketTokenRPLKey)); - rocketTokenRPL.approve(address(rocketVault), _rewardsRPL); - rocketVault.depositToken("rocketMerkleDistributorMainnet", rocketTokenRPL, _rewardsRPL); - } - } - - // Reward recipients can call this method with a merkle proof to claim rewards for one or more reward intervals - function claim(address _nodeAddress, uint256[] calldata _rewardIndex, uint256[] calldata _amountRPL, uint256[] calldata _amountETH, bytes32[][] calldata _merkleProof) external override { - claimAndStake(_nodeAddress, _rewardIndex, _amountRPL, _amountETH, _merkleProof, 0); - } - - // Node operators can call this method to claim rewards for one or more reward intervals and specify an amount of RPL to stake at the same time - function claimAndStake(address _nodeAddress, uint256[] calldata _rewardIndex, uint256[] calldata _amountRPL, uint256[] calldata _amountETH, bytes32[][] calldata _merkleProof, uint256 _stakeAmount) public override { - // Get contracts - RocketVaultInterface rocketVault = RocketVaultInterface(getAddress(rocketVaultKey)); - address rocketTokenRPLAddress = getAddress(rocketTokenRPLKey); - // Verify claims - _claim(_rewardIndex, _nodeAddress, _amountRPL, _amountETH, _merkleProof); - { - // Get withdrawal address - address withdrawalAddress = rocketStorage.getNodeWithdrawalAddress(_nodeAddress); - require(msg.sender == _nodeAddress || msg.sender == withdrawalAddress, "Can only claim from node or withdrawal address"); - // Calculate totals - uint256 totalAmountRPL = 0; - uint256 totalAmountETH = 0; - for (uint256 i = 0; i < _rewardIndex.length; i++) { - totalAmountRPL = totalAmountRPL.add(_amountRPL[i]); - totalAmountETH = totalAmountETH.add(_amountETH[i]); - } - // Validate input - require(_stakeAmount <= totalAmountRPL, "Invalid stake amount"); - // Distribute any remaining tokens to the node's withdrawal address - uint256 remaining = totalAmountRPL.sub(_stakeAmount); - if (remaining > 0) { - rocketVault.withdrawToken(withdrawalAddress, IERC20(rocketTokenRPLAddress), remaining); - } - // Distribute ETH - if (totalAmountETH > 0) { - rocketVault.withdrawEther(totalAmountETH); - (bool result,) = withdrawalAddress.call{value: totalAmountETH}(""); - require(result, "Failed to claim ETH"); - } - } - // Restake requested amount - if (_stakeAmount > 0) { - RocketTokenRPLInterface rocketTokenRPL = RocketTokenRPLInterface(rocketTokenRPLAddress); - RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking")); - rocketVault.withdrawToken(address(this), IERC20(rocketTokenRPLAddress), _stakeAmount); - rocketTokenRPL.approve(address(rocketNodeStaking), _stakeAmount); - rocketNodeStaking.stakeRPLFor(_nodeAddress, _stakeAmount); - } - // Emit event - emit RewardsClaimed(_nodeAddress, _rewardIndex, _amountRPL, _amountETH); - } - - // Verifies the given data exists as a leaf nodes for the specified reward interval and marks them as claimed if they are valid - // Note: this function is optimised for gas when _rewardIndex is ordered numerically - function _claim(uint256[] calldata _rewardIndex, address _nodeAddress, uint256[] calldata _amountRPL, uint256[] calldata _amountETH, bytes32[][] calldata _merkleProof) internal { - // Set initial parameters to the first reward index in the array - uint256 indexWordIndex = _rewardIndex[0] / 256; - bytes32 claimedWordKey = keccak256(abi.encodePacked('rewards.interval.claimed', _nodeAddress, indexWordIndex)); - uint256 claimedWord = getUint(claimedWordKey); - // Loop over every entry - for (uint256 i = 0; i < _rewardIndex.length; i++) { - // Prevent accidental claim of 0 - require(_amountRPL[i] > 0 || _amountETH[i] > 0, "Invalid amount"); - // Check if this entry has a different word index than the previous - if (indexWordIndex != _rewardIndex[i] / 256) { - // Store the previous word - setUint(claimedWordKey, claimedWord); - // Load the word for this entry - indexWordIndex = _rewardIndex[i] / 256; - claimedWordKey = keccak256(abi.encodePacked('rewards.interval.claimed', _nodeAddress, indexWordIndex)); - claimedWord = getUint(claimedWordKey); - } - // Calculate the bit index for this entry - uint256 indexBitIndex = _rewardIndex[i] % 256; - // Ensure the bit is not yet set on this word - uint256 mask = (1 << indexBitIndex); - require(claimedWord & mask != mask, "Already claimed"); - // Verify the merkle proof - require(_verifyProof(_rewardIndex[i], _nodeAddress, _amountRPL[i], _amountETH[i], _merkleProof[i]), "Invalid proof"); - // Set the bit for the current reward index - claimedWord = claimedWord | (1 << indexBitIndex); - } - // Store the word - setUint(claimedWordKey, claimedWord); - } - - // Verifies that the - function _verifyProof(uint256 _rewardIndex, address _nodeAddress, uint256 _amountRPL, uint256 _amountETH, bytes32[] calldata _merkleProof) internal view returns (bool) { - bytes32 node = keccak256(abi.encodePacked(_nodeAddress, network, _amountRPL, _amountETH)); - bytes32 key = keccak256(abi.encodePacked('rewards.merkle.root', _rewardIndex)); - bytes32 merkleRoot = getBytes32(key); - return MerkleProof.verify(_merkleProof, merkleRoot, node); - } - - // Returns true if the given claimer has claimed for the given reward interval - function isClaimed(uint256 _rewardIndex, address _claimer) public override view returns (bool) { - uint256 indexWordIndex = _rewardIndex / 256; - uint256 indexBitIndex = _rewardIndex % 256; - uint256 claimedWord = getUint(keccak256(abi.encodePacked('rewards.interval.claimed', _claimer, indexWordIndex))); - uint256 mask = (1 << indexBitIndex); - return claimedWord & mask == mask; - } - - // Allow receiving ETH from RocketVault, no action required - function receiveVaultWithdrawalETH() external override payable {} -} diff --git a/contracts/old/contract/rewards/RocketRewardsPoolOld.sol b/contracts/old/contract/rewards/RocketRewardsPoolOld.sol deleted file mode 100644 index 5eaeacb8f..000000000 --- a/contracts/old/contract/rewards/RocketRewardsPoolOld.sol +++ /dev/null @@ -1,260 +0,0 @@ -pragma solidity 0.7.6; -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "@openzeppelin/contracts/math/SafeMath.sol"; -import "../../interface/rewards/RocketRewardsPoolInterfaceOld.sol"; -import "../../../contract/RocketBase.sol"; -import "../../../interface/RocketVaultInterface.sol"; -import "../../../interface/token/RocketTokenRPLInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterface.sol"; -import "../../../interface/dao/node/RocketDAONodeTrustedInterface.sol"; -import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterface.sol"; -import "../../../interface/rewards/RocketRewardsRelayInterface.sol"; -import "../../../interface/rewards/RocketSmoothingPoolInterface.sol"; - - -// Holds RPL generated by the network for claiming from stakers (node operators etc) - -contract RocketRewardsPoolOld is RocketBase, RocketRewardsPoolInterfaceOld { - - // Libs - using SafeMath for uint256; - - // Events - event RewardSnapshotSubmitted(address indexed from, uint256 indexed rewardIndex, RewardSubmission submission, uint256 time); - event RewardSnapshot(uint256 indexed rewardIndex, RewardSubmission submission, uint256 intervalStartTime, uint256 intervalEndTime, uint256 time); - - // Construct - constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) { - // Version - version = 3; - } - - function getRewardIndex() override public view returns(uint256) { - return getUint(keccak256("rewards.snapshot.index")); - } - function incrementRewardIndex() private { - addUint(keccak256("rewards.snapshot.index"), 1); - } - - /** - * Get how much RPL the Rewards Pool contract currently has assigned to it as a whole - * @return uint256 Returns rpl balance of rocket rewards contract - */ - function getRPLBalance() override public view returns(uint256) { - // Get the vault contract instance - RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault")); - // Check contract RPL balance - return rocketVault.balanceOfToken("rocketRewardsPool", IERC20(getContractAddress("rocketTokenRPL"))); - } - - // Returns the total amount of RPL that needs to be distributed to claimers at the current block - function getPendingRPLRewards() override public view returns (uint256) { - RocketTokenRPLInterface rplContract = RocketTokenRPLInterface(getContractAddress("rocketTokenRPL")); - uint256 pendingInflation = rplContract.inflationCalculate(); - // Any inflation that has accrued so far plus any amount that would be minted if we called it now - return getRPLBalance().add(pendingInflation); - } - - // Returns the total amount of ETH in the smoothing pool ready to be distributed - function getPendingETHRewards() override public view returns (uint256) { - address rocketSmoothingPoolAddress = getContractAddress("rocketSmoothingPool"); - return rocketSmoothingPoolAddress.balance; - } - - /** - * Get the last set interval start time - * @return uint256 Last set start timestamp for a claim interval - */ - function getClaimIntervalTimeStart() override public view returns(uint256) { - return getUint(keccak256("rewards.pool.claim.interval.time.start")); - } - - /** - * Get how many seconds in a claim interval - * @return uint256 Number of seconds in a claim interval - */ - function getClaimIntervalTime() override public view returns(uint256) { - // Get from the DAO settings - RocketDAOProtocolSettingsRewardsInterface daoSettingsRewards = RocketDAOProtocolSettingsRewardsInterface(getContractAddress("rocketDAOProtocolSettingsRewards")); - return daoSettingsRewards.getRewardsClaimIntervalTime(); - } - - /** - * Compute intervals since last claim period - * @return uint256 Time intervals since last update - */ - function getClaimIntervalsPassed() override public view returns(uint256) { - return block.timestamp.sub(getClaimIntervalTimeStart()).div(getClaimIntervalTime()); - } - - /// @notice Returns the block number that the given claim interval was executed at - /// @param _interval The interval for which to grab the execution block of - function getClaimIntervalExecutionBlock(uint256 _interval) override external view returns(uint256) { - return getUint(keccak256(abi.encodePacked("rewards.pool.interval.execution.block", _interval))); - } - - /** - * Get the percentage this contract can claim in this interval - * @return uint256 Rewards percentage this contract can claim in this interval - */ - function getClaimingContractPerc(string memory _claimingContract) override public view returns (uint256) { - // Load contract - RocketDAOProtocolSettingsRewardsInterface daoSettingsRewards = RocketDAOProtocolSettingsRewardsInterface(getContractAddress("rocketDAOProtocolSettingsRewards")); - // Get the % amount allocated to this claim contract - return daoSettingsRewards.getRewardsClaimerPerc(_claimingContract); - } - - /** - * Get an array of percentages that the given contracts can claim in this interval - * @return uint256[] Array of percentages in the order of the supplied contract names - */ - function getClaimingContractsPerc(string[] memory _claimingContracts) override external view returns (uint256[] memory) { - // Load contract - RocketDAOProtocolSettingsRewardsInterface daoSettingsRewards = RocketDAOProtocolSettingsRewardsInterface(getContractAddress("rocketDAOProtocolSettingsRewards")); - // Get the % amount allocated to this claim contract - uint256[] memory percentages = new uint256[](_claimingContracts.length); - for (uint256 i = 0; i < _claimingContracts.length; i++){ - percentages[i] = daoSettingsRewards.getRewardsClaimerPerc(_claimingContracts[i]); - } - return percentages; - } - - // Returns whether a trusted node has submitted for a given reward index - function getTrustedNodeSubmitted(address _trustedNodeAddress, uint256 _rewardIndex) override external view returns (bool) { - return getBool(keccak256(abi.encode("rewards.snapshot.submitted.node", _trustedNodeAddress, _rewardIndex))); - } - - // Returns the number of trusted nodes who have agreed to the given submission - function getSubmissionCount(RewardSubmission calldata _submission) override external view returns (uint256) { - return getUint(keccak256(abi.encode("rewards.snapshot.submitted.count", _submission))); - } - - // Submit a reward snapshot - // Only accepts calls from trusted (oracle) nodes - function submitRewardSnapshot(RewardSubmission calldata _submission) override external onlyLatestContract("rocketRewardsPool", address(this)) onlyTrustedNode(msg.sender) { - // Get contracts - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - // Check submission is currently enabled - require(rocketDAOProtocolSettingsNetwork.getSubmitRewardsEnabled(), "Submitting rewards is currently disabled"); - // Validate inputs - require(_submission.rewardIndex == getRewardIndex(), "Can only submit snapshot for next period"); - require(_submission.intervalsPassed > 0, "Invalid number of intervals passed"); - require(_submission.nodeRPL.length == _submission.trustedNodeRPL.length && _submission.trustedNodeRPL.length == _submission.nodeETH.length, "Invalid array length"); - // Calculate RPL reward total and validate - { // Scope to prevent stake too deep - uint256 totalRewardsRPL = _submission.treasuryRPL; - for (uint256 i = 0; i < _submission.nodeRPL.length; i++){ - totalRewardsRPL = totalRewardsRPL.add(_submission.nodeRPL[i]); - } - for (uint256 i = 0; i < _submission.trustedNodeRPL.length; i++){ - totalRewardsRPL = totalRewardsRPL.add(_submission.trustedNodeRPL[i]); - } - require(totalRewardsRPL <= getPendingRPLRewards(), "Invalid RPL rewards"); - } - // Calculate ETH reward total and validate - { // Scope to prevent stack too deep - uint256 totalRewardsETH = 0; - for (uint256 i = 0; i < _submission.nodeETH.length; i++){ - totalRewardsETH = totalRewardsETH.add(_submission.nodeETH[i]); - } - require(totalRewardsETH <= getPendingETHRewards(), "Invalid ETH rewards"); - } - // Store and increment vote - uint256 submissionCount; - { // Scope to prevent stack too deep - // Check & update node submission status - bytes32 nodeSubmissionKey = keccak256(abi.encode("rewards.snapshot.submitted.node.key", msg.sender, _submission)); - require(!getBool(nodeSubmissionKey), "Duplicate submission from node"); - setBool(nodeSubmissionKey, true); - setBool(keccak256(abi.encode("rewards.snapshot.submitted.node", msg.sender, _submission.rewardIndex)), true); - } - { // Scope to prevent stack too deep - // Increment submission count - bytes32 submissionCountKey = keccak256(abi.encode("rewards.snapshot.submitted.count", _submission)); - submissionCount = getUint(submissionCountKey).add(1); - setUint(submissionCountKey, submissionCount); - } - // Emit snapshot submitted event - emit RewardSnapshotSubmitted(msg.sender, _submission.rewardIndex, _submission, block.timestamp); - // If consensus is reached, execute the snapshot - RocketDAONodeTrustedInterface rocketDAONodeTrusted = RocketDAONodeTrustedInterface(getContractAddress("rocketDAONodeTrusted")); - if (calcBase.mul(submissionCount).div(rocketDAONodeTrusted.getMemberCount()) >= rocketDAOProtocolSettingsNetwork.getNodeConsensusThreshold()) { - _executeRewardSnapshot(_submission); - } - } - - // Executes reward snapshot if consensus threshold is reached - function executeRewardSnapshot(RewardSubmission calldata _submission) override external onlyLatestContract("rocketRewardsPool", address(this)) { - // Validate reward index of submission - require(_submission.rewardIndex == getRewardIndex(), "Can only execute snapshot for next period"); - // Get submission count - bytes32 submissionCountKey = keccak256(abi.encode("rewards.snapshot.submitted.count", _submission)); - uint256 submissionCount = getUint(submissionCountKey); - // Confirm consensus and execute - RocketDAONodeTrustedInterface rocketDAONodeTrusted = RocketDAONodeTrustedInterface(getContractAddress("rocketDAONodeTrusted")); - RocketDAOProtocolSettingsNetworkInterface rocketDAOProtocolSettingsNetwork = RocketDAOProtocolSettingsNetworkInterface(getContractAddress("rocketDAOProtocolSettingsNetwork")); - require(calcBase.mul(submissionCount).div(rocketDAONodeTrusted.getMemberCount()) >= rocketDAOProtocolSettingsNetwork.getNodeConsensusThreshold(), "Consensus has not been reached"); - _executeRewardSnapshot(_submission); - } - - // Executes reward snapshot and sends assets to the relays for distribution to reward recipients - function _executeRewardSnapshot(RewardSubmission calldata _submission) private { - // Get contract - RocketTokenRPLInterface rplContract = RocketTokenRPLInterface(getContractAddress("rocketTokenRPL")); - RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault")); - // Execute inflation if required - rplContract.inflationMintTokens(); - // Increment the reward index and update the claim interval timestamp - incrementRewardIndex(); - uint256 claimIntervalTimeStart = getClaimIntervalTimeStart(); - uint256 claimIntervalTimeEnd = claimIntervalTimeStart.add(getClaimIntervalTime().mul(_submission.intervalsPassed)); - // Emit reward snapshot event - emit RewardSnapshot(_submission.rewardIndex, _submission, claimIntervalTimeStart, claimIntervalTimeEnd, block.timestamp); - setUint(keccak256(abi.encodePacked("rewards.pool.interval.execution.block", _submission.rewardIndex)), block.number); - setUint(keccak256("rewards.pool.claim.interval.time.start"), claimIntervalTimeEnd); - // Send out the treasury rewards - if (_submission.treasuryRPL > 0) { - rocketVault.transferToken("rocketClaimDAO", rplContract, _submission.treasuryRPL); - } - // Get the smoothing pool instance - RocketSmoothingPoolInterface rocketSmoothingPool = RocketSmoothingPoolInterface(getContractAddress("rocketSmoothingPool")); - // Send deposit pool user's ETH - if (_submission.userETH > 0) { - address rocketTokenRETHAddress = getContractAddress("rocketTokenRETH"); - rocketSmoothingPool.withdrawEther(rocketTokenRETHAddress, _submission.userETH); - } - // Loop over each network and distribute rewards - for (uint i = 0; i < _submission.nodeRPL.length; i++) { - // Quick out if no rewards for this network - uint256 rewardsRPL = _submission.nodeRPL[i].add(_submission.trustedNodeRPL[i]); - uint256 rewardsETH = _submission.nodeETH[i]; - if (rewardsRPL == 0 && rewardsETH == 0) { - continue; - } - // Grab the relay address - RocketRewardsRelayInterface relay; - { // Scope to prevent stack too deep - address networkRelayAddress; - bytes32 networkRelayKey = keccak256(abi.encodePacked("rewards.relay.address", i)); - networkRelayAddress = getAddress(networkRelayKey); - // Validate network is valid - require (networkRelayAddress != address(0), "Snapshot contains rewards for invalid network"); - relay = RocketRewardsRelayInterface(networkRelayAddress); - } - // Transfer rewards - if (rewardsRPL > 0) { - // RPL rewards are withdrawn from the vault - rocketVault.withdrawToken(address(relay), rplContract, rewardsRPL); - } - if (rewardsETH > 0) { - // ETH rewards are withdrawn from the smoothing pool - rocketSmoothingPool.withdrawEther(address(relay), rewardsETH); - } - // Call into relay contract to handle distribution of rewards - relay.relayRewards(_submission.rewardIndex, _submission.merkleRoot, rewardsRPL, rewardsETH); - } - } -} \ No newline at end of file diff --git a/contracts/old/interface/dao/protocol/RocketDAOProtocolInterfaceOld.sol b/contracts/old/interface/dao/protocol/RocketDAOProtocolInterfaceOld.sol deleted file mode 100644 index 32912954b..000000000 --- a/contracts/old/interface/dao/protocol/RocketDAOProtocolInterfaceOld.sol +++ /dev/null @@ -1,17 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; -pragma abicoder v2; - -import "../../../../types/SettingType.sol"; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketDAOProtocolInterfaceOld { - function getBootstrapModeDisabled() external view returns (bool); - function bootstrapSettingMulti(string[] memory _settingContractNames, string[] memory _settingPaths, SettingType[] memory _types, bytes[] memory _values) external; - function bootstrapSettingUint(string memory _settingContractName, string memory _settingPath, uint256 _value) external; - function bootstrapSettingBool(string memory _settingContractName, string memory _settingPath, bool _value) external; - function bootstrapSettingAddress(string memory _settingContractName, string memory _settingPath, address _value) external; - function bootstrapSettingClaimer(string memory _contractName, uint256 _perc) external; - function bootstrapSpendTreasury(string memory _invoiceID, address _recipientAddress, uint256 _amount) external; - function bootstrapDisable(bool _confirmDisableBootstrapMode) external; -} \ No newline at end of file diff --git a/contracts/old/interface/dao/protocol/RocketDAOProtocolProposalsInterfaceOld.sol b/contracts/old/interface/dao/protocol/RocketDAOProtocolProposalsInterfaceOld.sol deleted file mode 100644 index 6509aa2c4..000000000 --- a/contracts/old/interface/dao/protocol/RocketDAOProtocolProposalsInterfaceOld.sol +++ /dev/null @@ -1,15 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; -pragma abicoder v2; - -import "../../../../types/SettingType.sol"; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketDAOProtocolProposalsInterfaceOld { - function proposalSettingMulti(string[] memory _settingContractNames, string[] memory _settingPaths, SettingType[] memory _types, bytes[] memory _data) external; - function proposalSettingUint(string memory _settingContractName, string memory _settingPath, uint256 _value) external; - function proposalSettingBool(string memory _settingContractName, string memory _settingPath, bool _value) external; - function proposalSettingAddress(string memory _settingContractName, string memory _settingPath, address _value) external; - function proposalSettingRewardsClaimer(string memory _contractName, uint256 _perc) external; - function proposalSpendTreasury(string memory _invoiceID, address _recipientAddress, uint256 _amount) external; -} \ No newline at end of file diff --git a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterfaceOld.sol b/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterfaceOld.sol deleted file mode 100644 index 4e11d714b..000000000 --- a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterfaceOld.sol +++ /dev/null @@ -1,22 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../../../types/MinipoolDeposit.sol"; - -interface RocketDAOProtocolSettingsMinipoolInterfaceOld { - function getLaunchBalance() external view returns (uint256); - function getPreLaunchValue() external pure returns (uint256); - function getDepositUserAmount(MinipoolDeposit _depositType) external view returns (uint256); - function getFullDepositUserAmount() external view returns (uint256); - function getHalfDepositUserAmount() external view returns (uint256); - function getVariableDepositAmount() external view returns (uint256); - function getSubmitWithdrawableEnabled() external view returns (bool); - function getBondReductionEnabled() external view returns (bool); - function getLaunchTimeout() external view returns (uint256); - function getMaximumCount() external view returns (uint256); - function isWithinUserDistributeWindow(uint256 _time) external view returns (bool); - function hasUserDistributeWindowPassed(uint256 _time) external view returns (bool); - function getUserDistributeWindowStart() external view returns (uint256); - function getUserDistributeWindowLength() external view returns (uint256); -} \ No newline at end of file diff --git a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterfaceOld.sol b/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterfaceOld.sol deleted file mode 100644 index 7af0152b2..000000000 --- a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsNetworkInterfaceOld.sol +++ /dev/null @@ -1,20 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketDAOProtocolSettingsNetworkInterfaceOld { - function getNodeConsensusThreshold() external view returns (uint256); - function getNodePenaltyThreshold() external view returns (uint256); - function getPerPenaltyRate() external view returns (uint256); - function getSubmitBalancesEnabled() external view returns (bool); - function getSubmitBalancesFrequency() external view returns (uint256); - function getSubmitPricesEnabled() external view returns (bool); - function getSubmitPricesFrequency() external view returns (uint256); - function getMinimumNodeFee() external view returns (uint256); - function getTargetNodeFee() external view returns (uint256); - function getMaximumNodeFee() external view returns (uint256); - function getNodeFeeDemandRange() external view returns (uint256); - function getTargetRethCollateralRate() external view returns (uint256); - function getRethDepositDelay() external view returns (uint256); - function getSubmitRewardsEnabled() external view returns (bool); -} \ No newline at end of file diff --git a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterfaceOld.sol b/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterfaceOld.sol deleted file mode 100644 index a501dd2e6..000000000 --- a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterfaceOld.sol +++ /dev/null @@ -1,12 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketDAOProtocolSettingsNodeInterfaceOld { - function getRegistrationEnabled() external view returns (bool); - function getSmoothingPoolRegistrationEnabled() external view returns (bool); - function getDepositEnabled() external view returns (bool); - function getVacantMinipoolsEnabled() external view returns (bool); - function getMinimumPerMinipoolStake() external view returns (uint256); - function getMaximumPerMinipoolStake() external view returns (uint256); -} diff --git a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterfaceOld.sol b/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterfaceOld.sol deleted file mode 100644 index 1b56af2ac..000000000 --- a/contracts/old/interface/dao/protocol/settings/RocketDAOProtocolSettingsRewardsInterfaceOld.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketDAOProtocolSettingsRewardsInterfaceOld { - function setSettingRewardsClaimer(string memory _contractName, uint256 _perc) external; - function getRewardsClaimerPerc(string memory _contractName) external view returns (uint256); - function getRewardsClaimerPercTimeUpdated(string memory _contractName) external view returns (uint256); - function getRewardsClaimersPercTotal() external view returns (uint256); - function getRewardsClaimIntervalTime() external view returns (uint256); -} \ No newline at end of file diff --git a/contracts/old/interface/minipool/RocketMinipoolManagerInterfaceOld.sol b/contracts/old/interface/minipool/RocketMinipoolManagerInterfaceOld.sol deleted file mode 100644 index 20dd11931..000000000 --- a/contracts/old/interface/minipool/RocketMinipoolManagerInterfaceOld.sol +++ /dev/null @@ -1,43 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../interface/minipool/RocketMinipoolInterface.sol"; - -interface RocketMinipoolManagerInterfaceOld { - function getMinipoolCount() external view returns (uint256); - function getStakingMinipoolCount() external view returns (uint256); - function getFinalisedMinipoolCount() external view returns (uint256); - function getActiveMinipoolCount() external view returns (uint256); - function getMinipoolRPLSlashed(address _minipoolAddress) external view returns (bool); - function getMinipoolCountPerStatus(uint256 offset, uint256 limit) external view returns (uint256, uint256, uint256, uint256, uint256); - function getPrelaunchMinipools(uint256 offset, uint256 limit) external view returns (address[] memory); - function getMinipoolAt(uint256 _index) external view returns (address); - function getNodeMinipoolCount(address _nodeAddress) external view returns (uint256); - function getNodeActiveMinipoolCount(address _nodeAddress) external view returns (uint256); - function getNodeFinalisedMinipoolCount(address _nodeAddress) external view returns (uint256); - function getNodeStakingMinipoolCount(address _nodeAddress) external view returns (uint256); - function getNodeStakingMinipoolCountBySize(address _nodeAddress, uint256 _depositSize) external view returns (uint256); - function getNodeMinipoolAt(address _nodeAddress, uint256 _index) external view returns (address); - function getNodeValidatingMinipoolCount(address _nodeAddress) external view returns (uint256); - function getNodeValidatingMinipoolAt(address _nodeAddress, uint256 _index) external view returns (address); - function getMinipoolByPubkey(bytes calldata _pubkey) external view returns (address); - function getMinipoolExists(address _minipoolAddress) external view returns (bool); - function getMinipoolDestroyed(address _minipoolAddress) external view returns (bool); - function getMinipoolPubkey(address _minipoolAddress) external view returns (bytes memory); - function updateNodeStakingMinipoolCount(uint256 _previousBond, uint256 _newBond, uint256 _previousFee, uint256 _newFee) external; - function getMinipoolWithdrawalCredentials(address _minipoolAddress) external pure returns (bytes memory); - function createMinipool(address _nodeAddress, uint256 _salt) external returns (RocketMinipoolInterface); - function createVacantMinipool(address _nodeAddress, uint256 _salt, bytes calldata _validatorPubkey, uint256 _bondAmount, uint256 _currentBalance) external returns (RocketMinipoolInterface); - function removeVacantMinipool() external; - function getVacantMinipoolCount() external view returns (uint256); - function getVacantMinipoolAt(uint256 _index) external view returns (address); - function destroyMinipool() external; - function incrementNodeStakingMinipoolCount(address _nodeAddress) external; - function decrementNodeStakingMinipoolCount(address _nodeAddress) external; - function incrementNodeFinalisedMinipoolCount(address _nodeAddress) external; - function setMinipoolPubkey(bytes calldata _pubkey) external; - function getMinipoolDepositType(address _minipoolAddress) external view returns (MinipoolDeposit); -} \ No newline at end of file diff --git a/contracts/old/interface/network/RocketNetworkBalancesInterfaceOld.sol b/contracts/old/interface/network/RocketNetworkBalancesInterfaceOld.sol deleted file mode 100644 index 537298694..000000000 --- a/contracts/old/interface/network/RocketNetworkBalancesInterfaceOld.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketNetworkBalancesInterfaceOld { - function getBalancesBlock() external view returns (uint256); - function getLatestReportableBlock() external view returns (uint256); - function getTotalETHBalance() external view returns (uint256); - function getStakingETHBalance() external view returns (uint256); - function getTotalRETHSupply() external view returns (uint256); - function getETHUtilizationRate() external view returns (uint256); - function submitBalances(uint256 _block, uint256 _total, uint256 _staking, uint256 _rethSupply) external; - function executeUpdateBalances(uint256 _block, uint256 _totalEth, uint256 _stakingEth, uint256 _rethSupply) external; -} \ No newline at end of file diff --git a/contracts/old/interface/network/RocketNetworkPricesInterfaceOld.sol b/contracts/old/interface/network/RocketNetworkPricesInterfaceOld.sol deleted file mode 100644 index 5968b6fb8..000000000 --- a/contracts/old/interface/network/RocketNetworkPricesInterfaceOld.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketNetworkPricesInterfaceOld { - function getPricesBlock() external view returns (uint256); - function getRPLPrice() external view returns (uint256); - function getLatestReportableBlock() external view returns (uint256); - function submitPrices(uint256 _block, uint256 _rplPrice) external; - function executeUpdatePrices(uint256 _block, uint256 _rplPrice) external; -} \ No newline at end of file diff --git a/contracts/old/interface/node/RocketNodeDepositInterfaceOld.sol b/contracts/old/interface/node/RocketNodeDepositInterfaceOld.sol deleted file mode 100644 index 99beba0e3..000000000 --- a/contracts/old/interface/node/RocketNodeDepositInterfaceOld.sol +++ /dev/null @@ -1,16 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../types/MinipoolDeposit.sol"; - -interface RocketNodeDepositInterfaceOld { - function getNodeDepositCredit(address _nodeOperator) external view returns (uint256); - function increaseDepositCreditBalance(address _nodeOperator, uint256 _amount) external; - function deposit(uint256 _depositAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) external payable; - function depositWithCredit(uint256 _depositAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) external payable; - function isValidDepositAmount(uint256 _amount) external pure returns (bool); - function getDepositAmounts() external pure returns (uint256[] memory); - function createVacantMinipool(uint256 _bondAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, uint256 _salt, address _expectedMinipoolAddress, uint256 _currentBalance) external; - function increaseEthMatched(address _nodeAddress, uint256 _amount) external; -} \ No newline at end of file diff --git a/contracts/old/interface/node/RocketNodeManagerInterfaceOld.sol b/contracts/old/interface/node/RocketNodeManagerInterfaceOld.sol deleted file mode 100644 index 7ed28c7d1..000000000 --- a/contracts/old/interface/node/RocketNodeManagerInterfaceOld.sol +++ /dev/null @@ -1,37 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; -pragma abicoder v2; - -// SPDX-License-Identifier: GPL-3.0-only - -import "../../../types/NodeDetails.sol"; - -interface RocketNodeManagerInterfaceOld { - - // Structs - struct TimezoneCount { - string timezone; - uint256 count; - } - - function getNodeCount() external view returns (uint256); - function getNodeCountPerTimezone(uint256 offset, uint256 limit) external view returns (TimezoneCount[] memory); - function getNodeAt(uint256 _index) external view returns (address); - function getNodeExists(address _nodeAddress) external view returns (bool); - function getNodeWithdrawalAddress(address _nodeAddress) external view returns (address); - function getNodePendingWithdrawalAddress(address _nodeAddress) external view returns (address); - function getNodeTimezoneLocation(address _nodeAddress) external view returns (string memory); - function registerNode(string calldata _timezoneLocation) external; - function getNodeRegistrationTime(address _nodeAddress) external view returns (uint256); - function setTimezoneLocation(string calldata _timezoneLocation) external; - function setRewardNetwork(address _nodeAddress, uint256 network) external; - function getRewardNetwork(address _nodeAddress) external view returns (uint256); - function getFeeDistributorInitialised(address _nodeAddress) external view returns (bool); - function initialiseFeeDistributor() external; - function getAverageNodeFee(address _nodeAddress) external view returns (uint256); - function setSmoothingPoolRegistrationState(bool _state) external; - function getSmoothingPoolRegistrationState(address _nodeAddress) external returns (bool); - function getSmoothingPoolRegistrationChanged(address _nodeAddress) external returns (uint256); - function getSmoothingPoolRegisteredNodeCount(uint256 _offset, uint256 _limit) external view returns (uint256); - function getNodeDetails(address _nodeAddress) external view returns (NodeDetails memory); - function getNodeAddresses(uint256 _offset, uint256 _limit) external view returns (address[] memory); -} \ No newline at end of file diff --git a/contracts/old/interface/node/RocketNodeStakingInterfaceOld.sol b/contracts/old/interface/node/RocketNodeStakingInterfaceOld.sol deleted file mode 100644 index f5359c405..000000000 --- a/contracts/old/interface/node/RocketNodeStakingInterfaceOld.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketNodeStakingInterfaceOld { - function getTotalRPLStake() external view returns (uint256); - function getNodeRPLStake(address _nodeAddress) external view returns (uint256); - function getNodeETHMatched(address _nodeAddress) external view returns (uint256); - function getNodeETHProvided(address _nodeAddress) external view returns (uint256); - function getNodeETHCollateralisationRatio(address _nodeAddress) external view returns (uint256); - function getNodeRPLStakedTime(address _nodeAddress) external view returns (uint256); - function getNodeEffectiveRPLStake(address _nodeAddress) external view returns (uint256); - function getNodeMinimumRPLStake(address _nodeAddress) external view returns (uint256); - function getNodeMaximumRPLStake(address _nodeAddress) external view returns (uint256); - function getNodeETHMatchedLimit(address _nodeAddress) external view returns (uint256); - function stakeRPL(uint256 _amount) external; - function stakeRPLFor(address _nodeAddress, uint256 _amount) external; - function setStakeRPLForAllowed(address _caller, bool _allowed) external; - function withdrawRPL(uint256 _amount) external; - function slashRPL(address _nodeAddress, uint256 _ethSlashAmount) external; -} \ No newline at end of file diff --git a/contracts/old/interface/rewards/RocketRewardsPoolInterfaceOld.sol b/contracts/old/interface/rewards/RocketRewardsPoolInterfaceOld.sol deleted file mode 100644 index 38acaab8d..000000000 --- a/contracts/old/interface/rewards/RocketRewardsPoolInterfaceOld.sol +++ /dev/null @@ -1,23 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; -pragma abicoder v2; - -import "../../../types/RewardSubmission.sol"; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketRewardsPoolInterfaceOld { - function getRewardIndex() external view returns(uint256); - function getRPLBalance() external view returns(uint256); - function getPendingRPLRewards() external view returns (uint256); - function getPendingETHRewards() external view returns (uint256); - function getClaimIntervalTimeStart() external view returns(uint256); - function getClaimIntervalTime() external view returns(uint256); - function getClaimIntervalsPassed() external view returns(uint256); - function getClaimIntervalExecutionBlock(uint256 _interval) external view returns(uint256); - function getClaimingContractPerc(string memory _claimingContract) external view returns(uint256); - function getClaimingContractsPerc(string[] memory _claimingContracts) external view returns (uint256[] memory); - function getTrustedNodeSubmitted(address _trustedNodeAddress, uint256 _rewardIndex) external view returns (bool); - function getSubmissionCount(RewardSubmission calldata _submission) external view returns (uint256); - function submitRewardSnapshot(RewardSubmission calldata _submission) external; - function executeRewardSnapshot(RewardSubmission calldata _submission) external; -} \ No newline at end of file diff --git a/contracts/old/interface/rewards/claims/RocketClaimDAOInterfaceOld.sol b/contracts/old/interface/rewards/claims/RocketClaimDAOInterfaceOld.sol deleted file mode 100644 index 8b5f18641..000000000 --- a/contracts/old/interface/rewards/claims/RocketClaimDAOInterfaceOld.sol +++ /dev/null @@ -1,7 +0,0 @@ -pragma solidity >0.5.0 <0.9.0; - -// SPDX-License-Identifier: GPL-3.0-only - -interface RocketClaimDAOInterfaceOld { - function spend(string memory _invoiceID, address _recipientAddress, uint256 _amount) external; -} \ No newline at end of file diff --git a/test/_helpers/deployment.js b/test/_helpers/deployment.js index 0850ff5f4..a962eda7d 100644 --- a/test/_helpers/deployment.js +++ b/test/_helpers/deployment.js @@ -1,5 +1,6 @@ /*** Dependencies ********************/ -import { RocketStorage } from '../_utils/artifacts'; +import { RocketDAOProtocolSettingsNode, RocketStorage } from '../_utils/artifacts'; +import { setDAOProtocolBootstrapSetting } from '../dao/scenario-dao-protocol-bootstrap'; const hre = require('hardhat'); const pako = require('pako'); @@ -44,21 +45,21 @@ const contracts = { rocketDepositPool: artifacts.require('RocketDepositPool.sol'), // Minipool rocketMinipoolDelegate: artifacts.require('RocketMinipoolDelegate.sol'), - rocketMinipoolManager: artifacts.require('RocketMinipoolManagerOld.sol'), + rocketMinipoolManager: artifacts.require('RocketMinipoolManager.sol'), rocketMinipoolQueue: artifacts.require('RocketMinipoolQueue.sol'), rocketMinipoolPenalty: artifacts.require('RocketMinipoolPenalty.sol'), // Network - rocketNetworkBalances: artifacts.require('RocketNetworkBalancesOld.sol'), + rocketNetworkBalances: artifacts.require('RocketNetworkBalances.sol'), rocketNetworkFees: artifacts.require('RocketNetworkFees.sol'), - rocketNetworkPrices: artifacts.require('RocketNetworkPricesOld.sol'), + rocketNetworkPrices: artifacts.require('RocketNetworkPrices.sol'), rocketNetworkPenalties: artifacts.require('RocketNetworkPenalties.sol'), // Rewards - rocketRewardsPool: artifacts.require('RocketRewardsPoolOld.sol'), - rocketClaimDAO: artifacts.require('RocketClaimDAOOld.sol'), + rocketRewardsPool: artifacts.require('RocketRewardsPool.sol'), + rocketClaimDAO: artifacts.require('RocketClaimDAO.sol'), // Node - rocketNodeDeposit: artifacts.require('RocketNodeDepositOld.sol'), - rocketNodeManager: artifacts.require('RocketNodeManagerOld.sol'), - rocketNodeStaking: artifacts.require('RocketNodeStakingOld.sol'), + rocketNodeDeposit: artifacts.require('RocketNodeDeposit.sol'), + rocketNodeManager: artifacts.require('RocketNodeManager.sol'), + rocketNodeStaking: artifacts.require('RocketNodeStaking.sol'), // DAOs rocketDAOProposal: artifacts.require('RocketDAOProposal.sol'), rocketDAONodeTrusted: artifacts.require('RocketDAONodeTrusted.sol'), @@ -68,18 +69,18 @@ const contracts = { rocketDAONodeTrustedSettingsMembers: artifacts.require('RocketDAONodeTrustedSettingsMembers.sol'), rocketDAONodeTrustedSettingsProposals: artifacts.require('RocketDAONodeTrustedSettingsProposals.sol'), rocketDAONodeTrustedSettingsMinipool: artifacts.require('RocketDAONodeTrustedSettingsMinipool.sol'), - rocketDAOProtocol: artifacts.require('RocketDAOProtocolOld.sol'), - rocketDAOProtocolProposals: artifacts.require('RocketDAOProtocolProposalsOld.sol'), + rocketDAOProtocol: artifacts.require('RocketDAOProtocol.sol'), + rocketDAOProtocolProposals: artifacts.require('RocketDAOProtocolProposals.sol'), rocketDAOProtocolActions: artifacts.require('RocketDAOProtocolActions.sol'), - rocketDAOProtocolSettingsInflation: artifacts.require('RocketDAOProtocolSettingsInflationOld.sol'), - rocketDAOProtocolSettingsRewards: artifacts.require('RocketDAOProtocolSettingsRewardsOld.sol'), - rocketDAOProtocolSettingsAuction: artifacts.require('RocketDAOProtocolSettingsAuctionOld.sol'), - rocketDAOProtocolSettingsNode: artifacts.require('RocketDAOProtocolSettingsNodeOld.sol'), - rocketDAOProtocolSettingsNetwork: artifacts.require('RocketDAOProtocolSettingsNetworkOld.sol'), - rocketDAOProtocolSettingsDeposit: artifacts.require('RocketDAOProtocolSettingsDepositOld.sol'), - rocketDAOProtocolSettingsMinipool: artifacts.require('RocketDAOProtocolSettingsMinipoolOld.sol'), + rocketDAOProtocolSettingsInflation: artifacts.require('RocketDAOProtocolSettingsInflation.sol'), + rocketDAOProtocolSettingsRewards: artifacts.require('RocketDAOProtocolSettingsRewards.sol'), + rocketDAOProtocolSettingsAuction: artifacts.require('RocketDAOProtocolSettingsAuction.sol'), + rocketDAOProtocolSettingsNode: artifacts.require('RocketDAOProtocolSettingsNode.sol'), + rocketDAOProtocolSettingsNetwork: artifacts.require('RocketDAOProtocolSettingsNetwork.sol'), + rocketDAOProtocolSettingsDeposit: artifacts.require('RocketDAOProtocolSettingsDeposit.sol'), + rocketDAOProtocolSettingsMinipool: artifacts.require('RocketDAOProtocolSettingsMinipool.sol'), // v1.1 - rocketMerkleDistributorMainnet: artifacts.require('RocketMerkleDistributorMainnetOld.sol'), + rocketMerkleDistributorMainnet: artifacts.require('RocketMerkleDistributorMainnet.sol'), rocketDAONodeTrustedSettingsRewards: artifacts.require('RocketDAONodeTrustedSettingsRewards.sol'), rocketSmoothingPool: artifacts.require('RocketSmoothingPool.sol'), rocketNodeDistributorFactory: artifacts.require('RocketNodeDistributorFactory.sol'), @@ -98,25 +99,6 @@ const contracts = { rocketDAOSecurityProposals: artifacts.require('RocketDAOSecurityProposals.sol'), rocketDAOProtocolSettingsSecurity: artifacts.require('RocketDAOProtocolSettingsSecurity.sol'), rocketDAOProtocolProposal: artifacts.require('RocketDAOProtocolProposal.sol'), - rocketDAOProtocolNew: artifacts.require('RocketDAOProtocol.sol'), - rocketDAOProtocolProposalsNew: artifacts.require('RocketDAOProtocolProposals.sol'), - rocketNetworkPricesNew: artifacts.require('RocketNetworkPrices.sol'), - rocketNodeDepositNew: artifacts.require('RocketNodeDeposit.sol'), - rocketNodeManagerNew: artifacts.require('RocketNodeManager.sol'), - rocketNodeStakingNew: artifacts.require('RocketNodeStaking.sol'), - rocketClaimDAONew: artifacts.require('RocketClaimDAO.sol'), - rocketDAOProtocolSettingsRewardsNew: artifacts.require('RocketDAOProtocolSettingsRewards.sol'), - rocketMinipoolManagerNew: artifacts.require('RocketMinipoolManager.sol'), - rocketRewardsPoolNew: artifacts.require('RocketRewardsPool.sol'), - rocketNetworkBalancesNew: artifacts.require('RocketNetworkBalances.sol'), - rocketDAOProtocolSettingsNetworkNew: artifacts.require('RocketDAOProtocolSettingsNetwork.sol'), - rocketDAOProtocolSettingsAuctionNew: artifacts.require('RocketDAOProtocolSettingsAuction.sol'), - rocketDAOProtocolSettingsDepositNew: artifacts.require('RocketDAOProtocolSettingsDeposit.sol'), - rocketDAOProtocolSettingsInflationNew: artifacts.require('RocketDAOProtocolSettingsInflation.sol'), - rocketDAOProtocolSettingsMinipoolNew: artifacts.require('RocketDAOProtocolSettingsMinipool.sol'), - rocketDAOProtocolSettingsNodeNew: artifacts.require('RocketDAOProtocolSettingsNode.sol'), - rocketMerkleDistributorMainnetNew: artifacts.require('RocketMerkleDistributorMainnet.sol'), - rocketUpgradeOneDotThree: artifacts.require('RocketUpgradeOneDotThree.sol'), // Utils addressQueueStorage: artifacts.require('AddressQueueStorage.sol'), addressSetStorage: artifacts.require('AddressSetStorage.sol'), @@ -234,7 +216,6 @@ export async function deployRocketPool() { let instance if(!contracts[contract].hasOwnProperty('precompiled')) { switch (contract) { - // New RPL contract - pass storage address & existing RPL contract address case 'rocketTokenRPL': instance = await contracts[contract].new(rocketStorageInstance.address, (await contracts.rocketTokenRPLFixedSupply.deployed()).address); @@ -249,73 +230,6 @@ export async function deployRocketPool() { contracts[contract].setAsDeployed(instance); break; - // Upgrade contract - case 'rocketUpgradeOneDotThree': - const upgrader = await contracts[contract].new(rocketStorageInstance.address); - contracts[contract].setAsDeployed(upgrader); - const args = [ - [ - (await contracts.rocketDAOProtocolNew.deployed()).address, - (await contracts.rocketDAOProtocolProposalsNew.deployed()).address, - (await contracts.rocketNetworkPricesNew.deployed()).address, - (await contracts.rocketNodeDepositNew.deployed()).address, - (await contracts.rocketNodeManagerNew.deployed()).address, - (await contracts.rocketNodeStakingNew.deployed()).address, - (await contracts.rocketClaimDAONew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsRewardsNew.deployed()).address, - (await contracts.rocketMinipoolManagerNew.deployed()).address, - (await contracts.rocketRewardsPoolNew.deployed()).address, - (await contracts.rocketNetworkBalancesNew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsNetworkNew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsAuctionNew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsDepositNew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsInflationNew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsMinipoolNew.deployed()).address, - (await contracts.rocketDAOProtocolSettingsNodeNew.deployed()).address, - (await contracts.rocketMerkleDistributorMainnetNew.deployed()).address, - (await contracts.rocketDAOProtocolVerifier.deployed()).address, - (await contracts.rocketDAOProtocolSettingsProposals.deployed()).address, - (await contracts.rocketDAOProtocolSettingsSecurity.deployed()).address, - (await contracts.rocketDAOSecurity.deployed()).address, - (await contracts.rocketDAOSecurityActions.deployed()).address, - (await contracts.rocketDAOSecurityProposals.deployed()).address, - (await contracts.rocketNetworkSnapshots.deployed()).address, - (await contracts.rocketNetworkVoting.deployed()).address, - (await contracts.rocketDAOProtocolProposal.deployed()).address, - ], - [ - compressABI(contracts.rocketDAOProtocolNew.abi), - compressABI(contracts.rocketDAOProtocolProposalsNew.abi), - compressABI(contracts.rocketNetworkPricesNew.abi), - compressABI(contracts.rocketNodeDepositNew.abi), - compressABI(contracts.rocketNodeManagerNew.abi), - compressABI(contracts.rocketNodeStakingNew.abi), - compressABI(contracts.rocketClaimDAONew.abi), - compressABI(contracts.rocketDAOProtocolSettingsRewardsNew.abi), - compressABI(contracts.rocketMinipoolManagerNew.abi), - compressABI(contracts.rocketRewardsPoolNew.abi), - compressABI(contracts.rocketNetworkBalancesNew.abi), - compressABI(contracts.rocketDAOProtocolSettingsNetworkNew.abi), - compressABI(contracts.rocketDAOProtocolSettingsAuctionNew.abi), - compressABI(contracts.rocketDAOProtocolSettingsDepositNew.abi), - compressABI(contracts.rocketDAOProtocolSettingsInflationNew.abi), - compressABI(contracts.rocketDAOProtocolSettingsMinipoolNew.abi), - compressABI(contracts.rocketDAOProtocolSettingsNodeNew.abi), - compressABI(contracts.rocketMerkleDistributorMainnetNew.abi), - compressABI(contracts.rocketDAOProtocolVerifier.abi), - compressABI(contracts.rocketDAOProtocolSettingsProposals.abi), - compressABI(contracts.rocketDAOProtocolSettingsSecurity.abi), - compressABI(contracts.rocketDAOSecurity.abi), - compressABI(contracts.rocketDAOSecurityActions.abi), - compressABI(contracts.rocketDAOSecurityProposals.abi), - compressABI(contracts.rocketNetworkSnapshots.abi), - compressABI(contracts.rocketNetworkVoting.abi), - compressABI(contracts.rocketDAOProtocolProposal.abi), - ], - ] - await upgrader.set(...args) - break; - // All other contracts - pass storage address default: instance = await contracts[contract].new(rocketStorageInstance.address); @@ -347,36 +261,9 @@ export async function deployRocketPool() { for (let contract in contracts) { if(contracts.hasOwnProperty(contract)) { switch (contract) { - // Ignore contracts that will be upgraded later - case 'rocketDAOProtocolNew': - case 'rocketDAOProtocolProposalsNew': - case 'rocketNetworkPricesNew': - case 'rocketNodeDepositNew': - case 'rocketNodeManagerNew': - case 'rocketNodeStakingNew': - case 'rocketClaimDAONew': - case 'rocketDAOProtocolSettingsRewardsNew': - case 'rocketMinipoolManagerNew': - case 'rocketRewardsPoolNew': - case 'rocketNetworkBalancesNew': - case 'rocketDAOProtocolSettingsNetworkNew': - case 'rocketDAOProtocolSettingsAuctionNew': - case 'rocketDAOProtocolSettingsDepositNew': - case 'rocketDAOProtocolSettingsInflationNew': - case 'rocketDAOProtocolSettingsMinipoolNew': - case 'rocketDAOProtocolSettingsNodeNew': - case 'rocketMerkleDistributorMainnetNew': - case 'rocketDAOProtocolVerifier': - case 'rocketDAOProtocolSettingsProposals': - case 'rocketDAOProtocolSettingsSecurity': - case 'rocketDAOSecurity': - case 'rocketDAOSecurityActions': - case 'rocketDAOSecurityProposals': - case 'rocketNetworkSnapshots': - case 'rocketNetworkVoting': - case 'rocketDAOProtocolProposal': - break; - + case 'RocketNetworkSnapshots': + break + default: const address = contract === 'casperDeposit' ? contracts[contract].address : (await contracts[contract].deployed()).address; @@ -450,12 +337,20 @@ export async function deployRocketPool() { // Store deployed block console.log('\n'); - console.log('Setting deploy.block to ' + deployBlock); + console.log('Setting `deploy.block` to ' + deployBlock); await rocketStorageInstance.setUint( $web3.utils.soliditySha3('deploy.block'), deployBlock ); + // Set protocol version + const protocolVersion = '1.3.0' + console.log('Setting `protocol.version` to ' + protocolVersion); + await rocketStorageInstance.setString( + $web3.utils.soliditySha3('protocol.version'), + protocolVersion + ); + // Disable direct access to storage now await rocketStorageInstance.setDeployedStatus(); if(await rocketStorageInstance.getDeployedStatus() !== true) throw 'Storage Access Not Locked Down!!'; @@ -473,12 +368,4 @@ export async function deployRocketPool() { instance = await rocketNodeDepositLEB4.new(rocketStorageInstance.address); rocketNodeDepositLEB4.setAsDeployed(instance); } - - // Perform upgrade if we are not running in test environment - if (network.name !== 'hardhat') { - console.log('Executing upgrade to v1.3') - const RocketUpgradeOneDotThree = artifacts.require('RocketUpgradeOneDotThree') - const rocketUpgradeOneDotThree = await RocketUpgradeOneDotThree.deployed(); - await rocketUpgradeOneDotThree.execute({ from: accounts[0] }); - } }; diff --git a/test/_helpers/minipool.js b/test/_helpers/minipool.js index 8f29508ab..c5d921654 100644 --- a/test/_helpers/minipool.js +++ b/test/_helpers/minipool.js @@ -7,11 +7,10 @@ import { RocketNodeDeposit, RocketDAOProtocolSettingsNode, RocketStorage, - RocketNodeStaking, RocketNodeDepositNew, RocketNodeStakingNew, RocketNetworkPricesNew, RocketMinipoolManagerNew, + RocketNodeStaking, } from '../_utils/artifacts'; import { getValidatorPubkey, getValidatorSignature, getDepositDataRoot } from '../_utils/beacon'; import { assertBN } from './bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Possible states that a proposal may be in export const minipoolStates = { @@ -73,14 +72,13 @@ export async function getMinipoolMinimumRPLStake() { export async function getMinipoolMaximumRPLStake() { // Load contracts - const upgraded = await upgradeExecuted(); const [ rocketDAOProtocolSettingsMinipool, rocketNetworkPrices, rocketDAOProtocolSettingsNode, ] = await Promise.all([ RocketDAOProtocolSettingsMinipool.deployed(), - (upgraded) ? RocketNetworkPricesNew.deployed() : await RocketNetworkPrices.deployed(), + RocketNetworkPrices.deployed(), RocketDAOProtocolSettingsNode.deployed(), ]); @@ -105,15 +103,14 @@ export async function createMinipool(txOptions, salt = null) { export async function createMinipoolWithBondAmount(bondAmount, txOptions, salt = null) { // Load contracts - const upgraded = await upgradeExecuted(); const [ rocketMinipoolFactory, rocketNodeDeposit, rocketNodeStaking, ] = await Promise.all([ RocketMinipoolFactory.deployed(), - (upgraded) ? RocketNodeDepositNew.deployed() : await RocketNodeDeposit.deployed(), - (upgraded) ? RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(), + RocketNodeDeposit.deployed(), + RocketNodeStaking.deployed(), ]); // Get minipool contract bytecode @@ -158,7 +155,6 @@ export async function createMinipoolWithBondAmount(bondAmount, txOptions, salt = // Create a vacant minipool export async function createVacantMinipool(bondAmount, txOptions, salt = null, currentBalance = '32'.ether, pubkey = null) { // Load contracts - const upgraded = await upgradeExecuted(); const [ rocketMinipoolFactory, rocketNodeDeposit, @@ -166,8 +162,8 @@ export async function createVacantMinipool(bondAmount, txOptions, salt = null, c rocketStorage, ] = await Promise.all([ RocketMinipoolFactory.deployed(), - (upgraded) ? RocketNodeDepositNew.deployed() : await RocketNodeDeposit.deployed(), - (upgraded) ? RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(), + RocketNodeDeposit.deployed(), + RocketNodeStaking.deployed(), RocketStorage.deployed() ]); @@ -202,7 +198,7 @@ export async function refundMinipoolNodeETH(minipool, txOptions) { export async function stakeMinipool(minipool, txOptions) { // Get contracts - const rocketMinipoolManager = (await upgradeExecuted()) ? await RocketMinipoolManagerNew.deployed() : await RocketMinipoolManager.deployed(); + const rocketMinipoolManager = await RocketMinipoolManager.deployed(); // Get minipool validator pubkey const validatorPubkey = await rocketMinipoolManager.getMinipoolPubkey(minipool.address); @@ -242,13 +238,11 @@ export async function stakeMinipool(minipool, txOptions) { // Promote a minipool to staking export async function promoteMinipool(minipool, txOptions) { await minipool.promote(txOptions); - if (await upgradeExecuted()) { - // Expect pubkey -> minipool mapping still exists - const rocketMinipoolManager = await RocketMinipoolManager.deployed(); - const actualPubKey = await rocketMinipoolManager.getMinipoolPubkey(minipool.address); - const reverseAddress = await rocketMinipoolManager.getMinipoolByPubkey(actualPubKey); - assert.equal(reverseAddress, minipool.address); - } + // Expect pubkey -> minipool mapping still exists + const rocketMinipoolManager = await RocketMinipoolManager.deployed(); + const actualPubKey = await rocketMinipoolManager.getMinipoolPubkey(minipool.address); + const reverseAddress = await rocketMinipoolManager.getMinipoolByPubkey(actualPubKey); + assert.equal(reverseAddress, minipool.address); } diff --git a/test/_helpers/network.js b/test/_helpers/network.js index a6ba07a04..f1d76c7d2 100644 --- a/test/_helpers/network.js +++ b/test/_helpers/network.js @@ -1,11 +1,9 @@ import { - RocketNetworkBalances, RocketNetworkBalancesNew, + RocketNetworkBalances, RocketNetworkFees, - RocketNetworkPrices, RocketNetworkPricesNew, + RocketNetworkPrices, RocketNetworkVoting, - RocketNetworkWithdrawal, } from '../_utils/artifacts'; -import { upgradeExecuted } from '../_utils/upgrade'; // Get the network total ETH balance @@ -34,31 +32,21 @@ export async function getETHUtilizationRate() { // Submit network balances export async function submitBalances(block, slotTimestamp, totalEth, stakingEth, rethSupply, txOptions) { - if (await upgradeExecuted()) { - const rocketNetworkBalances = await RocketNetworkBalancesNew.deployed(); - await rocketNetworkBalances.submitBalances(block, slotTimestamp, totalEth, stakingEth, rethSupply, txOptions); - } else { - const rocketNetworkBalances = await RocketNetworkBalances.deployed(); - await rocketNetworkBalances.submitBalances(block, totalEth, stakingEth, rethSupply, txOptions); - } + const rocketNetworkBalances = await RocketNetworkBalances.deployed(); + await rocketNetworkBalances.submitBalances(block, slotTimestamp, totalEth, stakingEth, rethSupply, txOptions); } // Submit network token prices export async function submitPrices(block, slotTimestamp, rplPrice, txOptions) { - if (await upgradeExecuted()) { - const rocketNetworkPrices = await RocketNetworkPricesNew.deployed(); - await rocketNetworkPrices.submitPrices(block, slotTimestamp, rplPrice, txOptions); - } else { - const rocketNetworkPrices = await RocketNetworkPrices.deployed(); - await rocketNetworkPrices.submitPrices(block, rplPrice, txOptions); - } + const rocketNetworkPrices = await RocketNetworkPrices.deployed(); + await rocketNetworkPrices.submitPrices(block, slotTimestamp, rplPrice, txOptions); } // Get network RPL price export async function getRPLPrice() { - const rocketNetworkPrices = (await upgradeExecuted()) ? await RocketNetworkPricesNew.deployed() : await RocketNetworkPrices.deployed(); + const rocketNetworkPrices = await RocketNetworkPrices.deployed(); let price = await rocketNetworkPrices.getRPLPrice.call(); return price; } diff --git a/test/_helpers/node.js b/test/_helpers/node.js index e3b81ae50..f97ca7e61 100644 --- a/test/_helpers/node.js +++ b/test/_helpers/node.js @@ -9,10 +9,7 @@ import { RocketDAONodeTrusted, RocketMinipoolFactory, RocketNetworkVoting, - RocketDAOProtocolNew, RocketDAOProtocol, - RocketNodeManagerNew, - RocketNodeStakingNew, RocketNodeDepositNew, } from '../_utils/artifacts'; import { setDaoNodeTrustedBootstrapMember } from '../dao/scenario-dao-node-trusted-bootstrap'; import { daoNodeTrustedMemberJoin } from '../dao/scenario-dao-node-trusted'; @@ -21,12 +18,11 @@ import { burnFixedRPL } from '../token/scenario-rpl-burn-fixed'; import { allowDummyRPL } from '../token/scenario-rpl-allow-fixed'; import { getDepositDataRoot, getValidatorPubkey, getValidatorSignature } from '../_utils/beacon'; import { assertBN } from './bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Get a node's RPL stake export async function getNodeRPLStake(nodeAddress) { - const rocketNodeStaking = (await upgradeExecuted()) ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); let stake = await rocketNodeStaking.getNodeRPLStake.call(nodeAddress); return stake; } @@ -34,7 +30,7 @@ export async function getNodeRPLStake(nodeAddress) { // Get a node's effective RPL stake export async function getNodeEffectiveRPLStake(nodeAddress) { - const rocketNodeStaking = (await upgradeExecuted()) ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); let effectiveStake = await rocketNodeStaking.getNodeEffectiveRPLStake.call(nodeAddress); return effectiveStake; } @@ -42,7 +38,7 @@ export async function getNodeEffectiveRPLStake(nodeAddress) { // Get a node's minipool RPL stake export async function getNodeMinimumRPLStake(nodeAddress) { - const rocketNodeStaking = (await upgradeExecuted()) ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); let minimumStake = await rocketNodeStaking.getNodeMinimumRPLStake.call(nodeAddress); return minimumStake; } @@ -50,13 +46,13 @@ export async function getNodeMinimumRPLStake(nodeAddress) { // Register a node export async function registerNode(txOptions) { - const rocketNodeManager = (await upgradeExecuted()) ? await RocketNodeManagerNew.deployed() : await RocketNodeManager.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); await rocketNodeManager.registerNode('Australia/Brisbane', txOptions); } // Get number of nodes export async function getNodeCount(txOptions) { - const rocketNodeManager = (await upgradeExecuted()) ? await RocketNodeManagerNew.deployed() : await RocketNodeManager.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); return rocketNodeManager.getNodeCount(txOptions); } @@ -120,15 +116,14 @@ export async function setNodeWithdrawalAddress(nodeAddress, withdrawalAddress, t // Set an RPL withdrawal address for a node export async function setNodeRPLWithdrawalAddress(nodeAddress, rplWithdrawalAddress, txOptions) { - assert(await upgradeExecuted()); - const rocketNodeManager = await RocketNodeManagerNew.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); await rocketNodeManager.setRPLWithdrawalAddress(nodeAddress, rplWithdrawalAddress, true, txOptions); } // Submit a node RPL stake export async function nodeStakeRPL(amount, txOptions) { const [rocketNodeStaking, rocketTokenRPL] = await Promise.all([ - (await upgradeExecuted()) ? RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(), + RocketNodeStaking.deployed(), RocketTokenRPL.deployed(), ]); await rocketTokenRPL.approve(rocketNodeStaking.address, amount, txOptions); @@ -150,7 +145,7 @@ export async function nodeSetDelegate(to, txOptions) { // Submit a node RPL stake on behalf of another node export async function nodeStakeRPLFor(nodeAddress, amount, txOptions) { const [rocketNodeStaking, rocketTokenRPL] = await Promise.all([ - (await upgradeExecuted()) ? RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(), + RocketNodeStaking.deployed(), RocketTokenRPL.deployed(), ]); await rocketTokenRPL.approve(rocketNodeStaking.address, amount, txOptions); @@ -162,9 +157,8 @@ export async function nodeStakeRPLFor(nodeAddress, amount, txOptions) { // Deposits ETH into a node operator's balance export async function nodeDepositEthFor(nodeAddress, txOptions) { - assert.isTrue(await upgradeExecuted()); const [rocketNodeDeposit] = await Promise.all([ - RocketNodeDepositNew.deployed(), + RocketNodeDeposit.deployed(), ]); const before = await rocketNodeDeposit.getNodeEthBalance(nodeAddress); await rocketNodeDeposit.depositEthFor(nodeAddress, txOptions); @@ -175,7 +169,7 @@ export async function nodeDepositEthFor(nodeAddress, txOptions) { // Sets allow state for staking on behalf export async function setStakeRPLForAllowed(caller, state, txOptions) { const [rocketNodeStaking] = await Promise.all([ - (await upgradeExecuted()) ? RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(), + RocketNodeStaking.deployed(), ]); await rocketNodeStaking.methods['setStakeRPLForAllowed(address,bool)'](caller, state, txOptions); } @@ -183,29 +177,25 @@ export async function setStakeRPLForAllowed(caller, state, txOptions) { // Sets allow state for staking on behalf export async function setStakeRPLForAllowedWithNodeAddress(nodeAddress, caller, state, txOptions) { - assert.isTrue(await upgradeExecuted()); - const rocketNodeStaking = await RocketNodeStakingNew.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); await rocketNodeStaking.methods['setStakeRPLForAllowed(address,address,bool)'](nodeAddress, caller, state, txOptions); } // Withdraw a node RPL stake export async function nodeWithdrawRPL(amount, txOptions) { - const rocketNodeStaking = (await upgradeExecuted()) ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); await rocketNodeStaking.methods['withdrawRPL(uint256)'](amount, txOptions); } // Set allow state for RPL locking export async function setRPLLockingAllowed(node, state, txOptions) { - assert.isTrue(await upgradeExecuted()); - const rocketNodeStaking = await RocketNodeStakingNew.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); await rocketNodeStaking.setRPLLockingAllowed(node, state, txOptions); } // Make a node deposit let minipoolSalt = 0; export async function nodeDeposit(txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketMinipoolFactory, @@ -213,7 +203,7 @@ export async function nodeDeposit(txOptions) { rocketStorage, ] = await Promise.all([ RocketMinipoolFactory.deployed(), - upgraded ? RocketNodeDepositNew.deployed() : RocketNodeDeposit.deployed(), + RocketNodeDeposit.deployed(), RocketStorage.deployed() ]); diff --git a/test/_utils/artifacts.js b/test/_utils/artifacts.js index 3e1588a3b..7a9e18283 100644 --- a/test/_utils/artifacts.js +++ b/test/_utils/artifacts.js @@ -1,6 +1,5 @@ export const RocketAuctionManager = artifacts.require('RocketAuctionManager.sol'); -export const RocketClaimDAO = artifacts.require('RocketClaimDAOOld.sol'); -export const RocketClaimDAONew = artifacts.require('RocketClaimDAO.sol'); +export const RocketClaimDAO = artifacts.require('RocketClaimDAO.sol'); export const RocketDAONodeTrusted = artifacts.require('RocketDAONodeTrusted.sol'); export const RocketDAONodeTrustedActions = artifacts.require('RocketDAONodeTrustedActions.sol'); export const RocketDAONodeTrustedProposals = artifacts.require('RocketDAONodeTrustedProposals.sol'); @@ -8,18 +7,15 @@ export const RocketDAONodeTrustedSettingsMembers = artifacts.require('RocketDAON export const RocketDAONodeTrustedSettingsProposals = artifacts.require('RocketDAONodeTrustedSettingsProposals.sol'); export const RocketDAONodeTrustedSettingsMinipool = artifacts.require('RocketDAONodeTrustedSettingsMinipool.sol'); export const RocketDAONodeTrustedUpgrade = artifacts.require('RocketDAONodeTrustedUpgrade.sol'); -export const RocketDAOProtocol = artifacts.require('RocketDAOProtocolOld.sol'); -export const RocketDAOProtocolNew = artifacts.require('RocketDAOProtocol.sol'); -export const RocketDAOProtocolProposals = artifacts.require('RocketDAOProtocolProposalsOld.sol'); -export const RocketDAOProtocolProposalsNew = artifacts.require('RocketDAOProtocolProposals.sol'); +export const RocketDAOProtocol = artifacts.require('RocketDAOProtocol.sol'); +export const RocketDAOProtocolProposals = artifacts.require('RocketDAOProtocolProposals.sol'); export const RocketDAOProtocolProposal = artifacts.require('RocketDAOProtocolProposal.sol'); export const RocketDAOProtocolSettingsAuction = artifacts.require('RocketDAOProtocolSettingsAuction.sol'); export const RocketDAOProtocolSettingsDeposit = artifacts.require('RocketDAOProtocolSettingsDeposit.sol'); export const RocketDAOProtocolSettingsInflation = artifacts.require('RocketDAOProtocolSettingsInflation.sol'); export const RocketDAOProtocolSettingsNetwork = artifacts.require('RocketDAOProtocolSettingsNetwork.sol'); export const RocketDAOProtocolSettingsNode = artifacts.require('RocketDAOProtocolSettingsNode.sol'); -export const RocketDAOProtocolSettingsRewards = artifacts.require('RocketDAOProtocolSettingsRewardsOld.sol'); -export const RocketDAOProtocolSettingsRewardsNew = artifacts.require('RocketDAOProtocolSettingsRewards.sol'); +export const RocketDAOProtocolSettingsRewards = artifacts.require('RocketDAOProtocolSettingsRewards.sol'); export const RocketDAOProtocolSettingsProposals = artifacts.require('RocketDAOProtocolSettingsProposals.sol'); export const RocketDAOProtocolSettingsSecurity = artifacts.require('RocketDAOProtocolSettingsSecurity.sol'); export const RocketDAOProtocolVerifier = artifacts.require('RocketDAOProtocolVerifier.sol'); @@ -28,22 +24,16 @@ export const RocketDAOSecurityActions = artifacts.require('RocketDAOSecurityActi export const RocketDAOSecurityProposals = artifacts.require('RocketDAOSecurityProposals.sol'); export const RocketDAOSecurity = artifacts.require('RocketDAOSecurity.sol'); export const RocketMinipoolPenalty = artifacts.require('RocketMinipoolPenalty.sol'); -export const RocketMinipoolManager = artifacts.require('RocketMinipoolManagerOld.sol'); -export const RocketMinipoolManagerNew = artifacts.require('RocketMinipoolManager.sol'); -export const RocketNetworkBalances = artifacts.require('RocketNetworkBalancesOld.sol'); -export const RocketNetworkBalancesNew = artifacts.require('RocketNetworkBalances.sol'); +export const RocketMinipoolManager = artifacts.require('RocketMinipoolManager.sol'); +export const RocketNetworkBalances = artifacts.require('RocketNetworkBalances.sol'); export const RocketNetworkPenalties = artifacts.require('RocketNetworkPenalties.sol'); export const RocketNetworkFees = artifacts.require('RocketNetworkFees.sol'); -export const RocketNetworkPrices = artifacts.require('RocketNetworkPricesOld.sol'); -export const RocketNetworkPricesNew = artifacts.require('RocketNetworkPrices.sol'); -export const RocketNodeManager = artifacts.require('RocketNodeManagerOld.sol'); -export const RocketNodeManagerNew = artifacts.require('RocketNodeManager.sol'); -export const RocketNodeStaking = artifacts.require('RocketNodeStakingOld.sol'); -export const RocketNodeStakingNew = artifacts.require('RocketNodeStaking.sol'); +export const RocketNetworkPrices = artifacts.require('RocketNetworkPrices.sol'); +export const RocketNodeManager = artifacts.require('RocketNodeManager.sol'); +export const RocketNodeStaking = artifacts.require('RocketNodeStaking.sol'); export const RocketNodeDistributorFactory = artifacts.require('RocketNodeDistributorFactory.sol'); export const RocketNodeDistributorDelegate = artifacts.require('RocketNodeDistributorDelegate.sol'); -export const RocketRewardsPool = artifacts.require('RocketRewardsPoolOld.sol'); -export const RocketRewardsPoolNew = artifacts.require('RocketRewardsPool.sol'); +export const RocketRewardsPool = artifacts.require('RocketRewardsPool.sol'); export const RocketMerkleDistributorMainnet = artifacts.require('RocketMerkleDistributorMainnet.sol'); export const RocketSmoothingPool = artifacts.require('RocketSmoothingPool.sol'); export const RocketStorage = artifacts.require('RocketStorage.sol'); @@ -56,14 +46,11 @@ export const PenaltyTest = artifacts.require('PenaltyTest.sol'); export const SnapshotTest = artifacts.require('SnapshotTest.sol'); export const RocketMinipoolFactory = artifacts.require('RocketMinipoolFactory.sol'); export const RocketMinipoolBase = artifacts.require('RocketMinipoolBase.sol'); -export const RocketNodeDeposit = artifacts.require('RocketNodeDepositOld.sol'); -export const RocketNodeDepositNew = artifacts.require('RocketNodeDeposit.sol'); -export const RocketMinipoolDelegate = artifacts.require('RocketMinipoolDelegate.sol'); -export const RocketDAOProtocolSettingsMinipool = artifacts.require('RocketDAOProtocolSettingsMinipoolOld.sol'); -export const RocketDAOProtocolSettingsMinipoolNew = artifacts.require('RocketDAOProtocolSettingsMinipool.sol'); export const RocketMinipoolQueue = artifacts.require('RocketMinipoolQueue.sol'); +export const RocketNodeDeposit = artifacts.require('RocketNodeDeposit.sol'); +export const RocketMinipoolDelegate = artifacts.require('RocketMinipoolDelegate.sol'); +export const RocketDAOProtocolSettingsMinipool = artifacts.require('RocketDAOProtocolSettingsMinipool.sol'); export const RocketDepositPool = artifacts.require('RocketDepositPool.sol'); export const RocketMinipoolBondReducer = artifacts.require('RocketMinipoolBondReducer.sol'); export const RocketNetworkSnapshots = artifacts.require('RocketNetworkSnapshots.sol'); export const RocketNetworkVoting = artifacts.require('RocketNetworkVoting.sol'); -export const RocketUpgradeOneDotThree = artifacts.require('RocketUpgradeOneDotThree.sol'); diff --git a/test/_utils/upgrade.js b/test/_utils/upgrade.js index 55f464858..afcdf6b50 100644 --- a/test/_utils/upgrade.js +++ b/test/_utils/upgrade.js @@ -1,11 +1,12 @@ import { RocketUpgradeOneDotThree } from './artifacts'; export async function upgradeOneDotThree(guardian) { - const rocketUpgradeOneDotThree = await RocketUpgradeOneDotThree.deployed(); - await rocketUpgradeOneDotThree.execute({ from: guardian }); + // const rocketUpgradeOneDotThree = await RocketUpgradeOneDotThree.deployed(); + // await rocketUpgradeOneDotThree.execute({ from: guardian }); } export async function upgradeExecuted() { - const rocketUpgradeOneDotThree = await RocketUpgradeOneDotThree.deployed(); - return await rocketUpgradeOneDotThree.executed(); + return true; + // const rocketUpgradeOneDotThree = await RocketUpgradeOneDotThree.deployed(); + // return await rocketUpgradeOneDotThree.executed(); } \ No newline at end of file diff --git a/test/auction/auction-tests.js b/test/auction/auction-tests.js index f06a4085a..379840349 100644 --- a/test/auction/auction-tests.js +++ b/test/auction/auction-tests.js @@ -34,6 +34,7 @@ export default function() { random2, ] = accounts; + const defaultAuctionDuration = 40320; // Setup let scrubPeriod = (60 * 60 * 24); // 24 hours @@ -107,9 +108,9 @@ export default function() { it(printTitle('auction lot', 'has correct price at block'), async () => { // Set lot settings - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 100, {from: owner}); + await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 100000, {from: owner}); await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.price.start', '1'.ether, {from: owner}); - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.price.reserve', '0'.ether, {from: owner}); + await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.price.reserve', '0.5'.ether, {from: owner}); // Set RPL price let block = await web3.eth.getBlockNumber(); @@ -125,15 +126,15 @@ export default function() { // Set expected prices at blocks const values = [ - {block: startBlock + 0, expectedPrice: '1.0000'.ether}, - {block: startBlock + 12, expectedPrice: '0.9856'.ether}, - {block: startBlock + 25, expectedPrice: '0.9375'.ether}, - {block: startBlock + 37, expectedPrice: '0.8631'.ether}, - {block: startBlock + 50, expectedPrice: '0.7500'.ether}, - {block: startBlock + 63, expectedPrice: '0.6031'.ether}, - {block: startBlock + 75, expectedPrice: '0.4375'.ether}, - {block: startBlock + 88, expectedPrice: '0.2256'.ether}, - {block: startBlock + 100, expectedPrice: '0.0000'.ether}, + {block: startBlock + 0, expectedPrice: '1.00000'.ether}, + {block: startBlock + 12000, expectedPrice: '0.99280'.ether}, + {block: startBlock + 25000, expectedPrice: '0.96875'.ether}, + {block: startBlock + 37000, expectedPrice: '0.93155'.ether}, + {block: startBlock + 50000, expectedPrice: '0.87500'.ether}, + {block: startBlock + 63000, expectedPrice: '0.80155'.ether}, + {block: startBlock + 75000, expectedPrice: '0.71875'.ether}, + {block: startBlock + 88000, expectedPrice: '0.61280'.ether}, + {block: startBlock + 100000, expectedPrice: '0.50000'.ether}, ]; // Check fees @@ -241,13 +242,13 @@ export default function() { it(printTitle('random address', 'cannot bid on a lot after the lot bidding period has concluded'), async () => { - // Set lot duration - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 0, {from: owner}); - // Create lot await withdrawValidatorBalance(minipool, '0'.ether, node, true); await auctionCreateLot({from: random1}); + // Wait for duration to end + await mineBlocks(web3, defaultAuctionDuration); + // Attempt to place bid await shouldRevert(placeBid(0, { from: random1, @@ -360,11 +361,13 @@ export default function() { it(printTitle('random address', 'can recover unclaimed RPL from a lot'), async () => { // Create closed lots - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 0, {from: owner}); await withdrawValidatorBalance(minipool, '0'.ether, node, true); await auctionCreateLot({from: random1}); await auctionCreateLot({from: random1}); + // Wait for duration to end + await mineBlocks(web3, defaultAuctionDuration); + // Recover RPL from first lot await recoverUnclaimedRPL(0, { from: random1, @@ -381,10 +384,12 @@ export default function() { it(printTitle('random address', 'cannot recover unclaimed RPL from a lot which doesn\'t exist'), async () => { // Create closed lot - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 0, {from: owner}); await withdrawValidatorBalance(minipool, '0'.ether, node, true); await auctionCreateLot({from: random1}); + // Wait for duration to end + await mineBlocks(web3, defaultAuctionDuration); + // Attempt to recover RPL await shouldRevert(recoverUnclaimedRPL(1, { from: random1, @@ -410,10 +415,12 @@ export default function() { it(printTitle('random address', 'cannot recover unclaimed RPL from a lot twice'), async () => { // Create closed lot - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 0, {from: owner}); await withdrawValidatorBalance(minipool, '0'.ether, node, true); await auctionCreateLot({from: random1}); + // Wait for duration to end + await mineBlocks(web3, defaultAuctionDuration); + // Recover RPL await recoverUnclaimedRPL(0, {from: random1}); @@ -427,16 +434,13 @@ export default function() { it(printTitle('random address', 'cannot recover unclaimed RPL from a lot which has no RPL to recover'), async () => { - // Set lot duration - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsAuction, 'auction.lot.duration', 10, {from: owner}); - // Create lot & place bid to clear await withdrawValidatorBalance(minipool, '0'.ether, node, true); await auctionCreateLot({from: random1}); await auctionPlaceBid(0, {from: random1, value: '1000'.ether}); - // Move to lot bidding period end - await mineBlocks(web3, 10); + // Wait for duration to end + await mineBlocks(web3, defaultAuctionDuration); // Attempt to recover RPL again await shouldRevert(recoverUnclaimedRPL(0, { diff --git a/test/dao/scenario-dao-protocol-bootstrap.js b/test/dao/scenario-dao-protocol-bootstrap.js index aac84ba3d..3ff448801 100644 --- a/test/dao/scenario-dao-protocol-bootstrap.js +++ b/test/dao/scenario-dao-protocol-bootstrap.js @@ -4,15 +4,9 @@ import { RocketDAOProtocolSettingsRewards, RocketDAOProtocolSettingsInflation, RocketTokenRPL, - RocketVault, - RocketDAOProtocolNew, - RocketNetworkPricesNew, - RocketNetworkPrices, - RocketDAOProtocolSettingsRewardsNew, - RocketClaimDAO, RocketClaimDAONew, + RocketVault, RocketClaimDAO, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Change a trusted node DAO setting while bootstrap mode is enabled @@ -24,7 +18,7 @@ export async function setDAOProtocolBootstrapSetting(_settingContractInstance, _ } // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); const rocketDAOProtocolSettingsContract = await _settingContractInstance.deployed(); // Get data about the tx @@ -42,11 +36,7 @@ export async function setDAOProtocolBootstrapSetting(_settingContractInstance, _ // Capture data let ds1 = await getTxData(); - // Trim "Old" off contract name let contractName = _settingContractInstance._json.contractName.lowerCaseFirstLetter(); - if (contractName.endsWith('Old')) { - contractName = contractName.substring(0, contractName.length - 3); - } // Set as a bootstrapped setting. detect type first, can be a number, string or bn object if(Web3.utils.isAddress(_value)) { @@ -75,8 +65,8 @@ export async function setDAOProtocolBootstrapSetting(_settingContractInstance, _ // Set a contract that can claim rewards export async function setDAONetworkBootstrapRewardsClaimers(_trustedNodePerc, _protocolPerc, _nodePerc, txOptions) { // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); - const rocketDAOProtocolSettingsRewards = (await upgradeExecuted()) ? await RocketDAOProtocolSettingsRewardsNew.deployed() : await RocketDAOProtocolSettingsRewards.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); + const rocketDAOProtocolSettingsRewards = await RocketDAOProtocolSettingsRewards.deployed(); // Get data about the tx function getTxData() { return Promise.all([ @@ -144,11 +134,9 @@ export async function spendRewardsClaimTreasury(_invoiceID, _recipientAddress, _ // Create a new recurring payment via bootstrap export async function bootstrapTreasuryNewContract(_contractName, _recipientAddress, _amount, _periodLength, _startTime, _numPeriods, txOptions) { - assert(await upgradeExecuted()); - // Load contracts - const rocketDAOProtocol = await RocketDAOProtocolNew.deployed(); - const rocketClaimDAO = await RocketClaimDAONew.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); + const rocketClaimDAO = await RocketClaimDAO.deployed(); // Perform tx await rocketDAOProtocol.bootstrapTreasuryNewContract(_contractName, _recipientAddress, _amount, _periodLength, _startTime, _numPeriods, txOptions); @@ -165,11 +153,9 @@ export async function bootstrapTreasuryNewContract(_contractName, _recipientAddr // Update an existing recurring payment via bootstrap export async function bootstrapTreasuryUpdateContract(_contractName, _recipientAddress, _amount, _periodLength, _numPeriods, txOptions) { - assert(await upgradeExecuted()); - // Load contracts - const rocketDAOProtocol = await RocketDAOProtocolNew.deployed(); - const rocketClaimDAO = await RocketClaimDAONew.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); + const rocketClaimDAO = await RocketClaimDAO.deployed(); // Perform tx await rocketDAOProtocol.bootstrapTreasuryUpdateContract(_contractName, _recipientAddress, _amount, _periodLength, _numPeriods, txOptions); @@ -203,7 +189,7 @@ export async function setRPLInflationStartTime(startTime, txOptions) { // Disable bootstrap mode export async function setDaoProtocolBootstrapModeDisabled(txOptions) { // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); // Get data about the tx function getTxData() { @@ -236,7 +222,7 @@ export async function setDAOProtocolBootstrapSettingMulti(_settingContractInstan } // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); const contractNames = []; @@ -307,7 +293,7 @@ export async function setDAOProtocolBootstrapSettingMulti(_settingContractInstan export async function setDAOProtocolBootstrapEnableGovernance(txOptions) { // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); // Execute enable transaction await rocketDAOProtocol.bootstrapEnableGovernance(); } @@ -317,7 +303,7 @@ export async function setDAOProtocolBootstrapEnableGovernance(txOptions) { // Use bootstrap power to invite a member to the security council export async function setDAOProtocolBootstrapSecurityInvite(_id, _memberAddress, txOptions) { // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); // Execute the invite await rocketDAOProtocol.bootstrapSecurityInvite(_id, _memberAddress, txOptions); } @@ -325,7 +311,7 @@ export async function setDAOProtocolBootstrapSecurityInvite(_id, _memberAddress, // Use bootstrap power to kick a member from the security council export async function setDAOProtocolBootstrapSecurityKick(_id, _memberAddress, txOptions) { // Load contracts - const rocketDAOProtocol = (await upgradeExecuted()) ? await RocketDAOProtocolNew.deployed() : await RocketDAOProtocol.deployed(); + const rocketDAOProtocol = await RocketDAOProtocol.deployed(); // Execute the kick await rocketDAOProtocol.bootstrapSecurityKick(_memberAddress, txOptions); } diff --git a/test/dao/scenario-dao-protocol-treasury.js b/test/dao/scenario-dao-protocol-treasury.js index 4eb8f69c2..d00a69adf 100644 --- a/test/dao/scenario-dao-protocol-treasury.js +++ b/test/dao/scenario-dao-protocol-treasury.js @@ -1,18 +1,14 @@ import Web3 from 'web3'; import { - RocketClaimDAONew, - RocketDAOProtocol, - RocketDAOProtocolNew, RocketTokenRPL, + RocketClaimDAO, + RocketTokenRPL, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; import { getCurrentTime } from '../_utils/evm'; export async function payOutContracts(_contractNames, txOptions) { - assert(await upgradeExecuted()); - // Load contracts - const rocketClaimDAO = await RocketClaimDAONew.deployed(); + const rocketClaimDAO = await RocketClaimDAO.deployed(); // Calculate expected payouts let contracts = []; @@ -66,10 +62,8 @@ export async function payOutContracts(_contractNames, txOptions) { } export async function withdrawBalance(recipient, txOptions) { - assert(await upgradeExecuted()); - // Load contracts - const rocketClaimDAO = await RocketClaimDAONew.deployed(); + const rocketClaimDAO = await RocketClaimDAO.deployed(); const rocketTokenRPL = await RocketTokenRPL.deployed(); // Get balance before withdrawal diff --git a/test/dao/scenario-dao-protocol.js b/test/dao/scenario-dao-protocol.js index 5ecd1d7f5..478fccdc2 100644 --- a/test/dao/scenario-dao-protocol.js +++ b/test/dao/scenario-dao-protocol.js @@ -2,7 +2,7 @@ import { RocketNetworkVoting, RocketDAOProtocolVerifier, RocketDAOProtocolSettingsProposals, - RocketNodeStakingNew, RocketNodeManagerNew, RocketDAOProtocolProposal, + RocketDAOProtocolProposal, RocketNodeManager, RocketNodeStaking, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; import { voteStates } from './scenario-dao-proposal'; @@ -43,7 +43,7 @@ export async function getDAOProposalVotesRequired(proposalID, txOptions) { export async function getDelegatedVotingPower(block) { // Load contracts const rocketNetworkVoting = await RocketNetworkVoting.deployed(); - const rocketNodeManager = await RocketNodeManagerNew.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); // Grab the number of nodes at the block const nodeCount = (await rocketNetworkVoting.getNodeCount(block)).toNumber(); @@ -88,7 +88,7 @@ export async function getDelegatedVotingPower(block) { export async function getPhase2VotingPower(block, nodeIndex) { // Load contracts const rocketNetworkVoting = await RocketNetworkVoting.deployed(); - const rocketNodeManager = await RocketNodeManagerNew.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); // Grab the number of nodes at the block const nodeCount = (await rocketNetworkVoting.getNodeCount(block)).toNumber(); @@ -667,7 +667,7 @@ export async function daoProtocolExecute(_proposalID, txOptions) { export async function daoProtocolFinalise(_proposalID, txOptions) { // Load contracts const rocketDAOProtocolProposal = await RocketDAOProtocolProposal.deployed(); - const rocketNodeStaking = await RocketNodeStakingNew.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); const proposer = await rocketDAOProtocolProposal.getProposer(_proposalID); const proposalBond = await getDaoProtocolProposalBond(); @@ -705,7 +705,7 @@ export async function daoProtocolFinalise(_proposalID, txOptions) { export async function daoProtocolClaimBondProposer(_proposalID, _indices, txOptions) { const rocketDAOProtocolVerifier = await RocketDAOProtocolVerifier.deployed(); - const rocketNodeStaking = await RocketNodeStakingNew.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); const lockedBalanceBefore = await rocketNodeStaking.getNodeRPLLocked(txOptions.from); const balanceBefore = await rocketNodeStaking.getNodeRPLStake(txOptions.from); @@ -723,7 +723,7 @@ export async function daoProtocolClaimBondProposer(_proposalID, _indices, txOpti export async function daoProtocolClaimBondChallenger(_proposalID, _indices, txOptions) { const rocketDAOProtocolVerifier = await RocketDAOProtocolVerifier.deployed(); - const rocketNodeStaking = await RocketNodeStakingNew.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); const lockedBalanceBefore = await rocketNodeStaking.getNodeRPLLocked(txOptions.from); const balanceBefore = await rocketNodeStaking.getNodeRPLStake(txOptions.from); diff --git a/test/minipool/minipool-vacant-tests.js b/test/minipool/minipool-vacant-tests.js index eae6cd81b..457d3f693 100644 --- a/test/minipool/minipool-vacant-tests.js +++ b/test/minipool/minipool-vacant-tests.js @@ -1,7 +1,7 @@ import { RocketDAOProtocolSettingsMinipool, RocketDAOProtocolSettingsNetwork, - RocketDAONodeTrustedSettingsMinipool, RocketNodeStaking, RocketNodeStakingNew, + RocketDAONodeTrustedSettingsMinipool, RocketNodeStaking, } from '../_utils/artifacts'; import { increaseTime } from '../_utils/evm'; import { printTitle } from '../_utils/formatting'; @@ -57,7 +57,7 @@ export default function() { // Upgrade to Houston await upgradeOneDotThree(); - rocketNodeStaking = await RocketNodeStakingNew.deployed(); + rocketNodeStaking = await RocketNodeStaking.deployed(); // Register node & set withdrawal address await registerNode({from: node}); diff --git a/test/minipool/minipool-withdrawal-tests.js b/test/minipool/minipool-withdrawal-tests.js index 492178f87..d718a2b3d 100644 --- a/test/minipool/minipool-withdrawal-tests.js +++ b/test/minipool/minipool-withdrawal-tests.js @@ -47,8 +47,8 @@ export default function() { let userDistributeLength = (60 * 60); before(async () => { - // Hard code fee to 50% - const fee = '0.5'.ether; + // Hard code fee to 10% + const fee = '0.1'.ether; await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsNetwork, 'network.node.fee.minimum', fee, {from: owner}); await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsNetwork, 'network.node.fee.target', fee, {from: owner}); await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsNetwork, 'network.node.fee.maximum', fee, {from: owner}); @@ -157,13 +157,13 @@ export default function() { it(printTitle('node operator withdrawal address', 'can process withdrawal when balance is greater than 32 ETH and not marked as withdrawable'), async () => { // Process withdraw - await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, false, '17', '19'); + await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, false, '17.8', '18.2'); }); it(printTitle('random user', 'can process withdrawal when balance is greater than 32 ETH and not marked as withdrawable'), async () => { // Process withdraw - await withdrawAndCheck(minipool, '36', random, false, '17', '19', true); + await withdrawAndCheck(minipool, '36', random, false, '17.8', '18.2', true); }); @@ -262,8 +262,8 @@ export default function() { it(printTitle('node operator withdrawal address', 'can process withdrawal and finalise pool when penalised by DAO'), async () => { // Penalise the minipool 50% of it's ETH await penaltyTestContract.setPenaltyRate(minipool.address, maxPenaltyRate); - // Process withdraw - 36 ETH would normally give node operator 19 and user 17 but with a 50% penalty, and extra 9.5 goes to the user - await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, true, '26.5', '9.5'); + // Process withdraw - 36 ETH would normally give node operator 18.2 and user 17.8 but with a 50% penalty, and extra 9.1 goes to the user + await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, true, '26.9', '9.1'); }); @@ -271,7 +271,7 @@ export default function() { // Try to penalise the minipool 75% of it's ETH (max is 50%) await penaltyTestContract.setPenaltyRate(minipool.address, web3.utils.toWei('0.75')); // Process withdraw - 36 ETH would normally give node operator 19 and user 17 but with a 50% penalty, and extra 9.5 goes to the user - await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, true, '26.5', '9.5'); + await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, true, '26.9', '9.1'); }); @@ -282,7 +282,7 @@ export default function() { // Try to penalise the minipool 50% await penaltyTestContract.setPenaltyRate(minipool.address, web3.utils.toWei('0.5')); // Process withdraw - await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, true, '17', '19'); + await withdrawAndCheck(minipool, '36', nodeWithdrawalAddress, true, '17.8', '18.2'); }); }) } diff --git a/test/minipool/scenario-close.js b/test/minipool/scenario-close.js index 811907fde..408946af3 100644 --- a/test/minipool/scenario-close.js +++ b/test/minipool/scenario-close.js @@ -1,14 +1,12 @@ -import { RocketNodeManager, RocketNodeStaking, RocketNodeStakingNew } from '../_utils/artifacts'; +import { RocketNodeManager, RocketNodeStaking } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Close a minipool export async function close(minipool, txOptions) { // Load contracts - const upgraded = await upgradeExecuted(); const rocketNodeManager = await RocketNodeManager.deployed(); - const rocketNodeStaking = upgraded ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); // Get parameters let nodeAddress = await minipool.getNodeAddress.call(); diff --git a/test/minipool/scenario-reduce-bond.js b/test/minipool/scenario-reduce-bond.js index 17dfabc3e..72c082082 100644 --- a/test/minipool/scenario-reduce-bond.js +++ b/test/minipool/scenario-reduce-bond.js @@ -1,19 +1,18 @@ import { RocketMinipoolBondReducer, - RocketMinipoolManager, RocketMinipoolManagerNew, + RocketMinipoolManager, RocketNodeDeposit, - RocketNodeStaking, RocketNodeStakingNew, + RocketNodeStaking, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Reduce bonding amount of a minipool export async function reduceBond(minipool, txOptions = null) { const rocketNodeDeposit = await RocketNodeDeposit.deployed(); - const rocketNodeStaking = (await upgradeExecuted()) ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); const rocketMinipoolBondReducer = await RocketMinipoolBondReducer.deployed(); - const rocketMinipoolManager = (await upgradeExecuted()) ? await RocketMinipoolManagerNew.deployed() : await RocketMinipoolManager.deployed(); + const rocketMinipoolManager = await RocketMinipoolManager.deployed(); const node = await minipool.getNodeAddress(); const newBond = await rocketMinipoolBondReducer.getReduceBondValue(minipool.address); diff --git a/test/minipool/scenario-scrub.js b/test/minipool/scenario-scrub.js index b9dd0584a..334fd04da 100644 --- a/test/minipool/scenario-scrub.js +++ b/test/minipool/scenario-scrub.js @@ -13,7 +13,6 @@ import { } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; import { minipoolStates } from '../_helpers/minipool'; -import { upgradeExecuted } from '../_utils/upgrade'; export async function voteScrub(minipool, txOptions) { @@ -21,7 +20,7 @@ export async function voteScrub(minipool, txOptions) { const nodeAddress = await minipool.getNodeAddress.call(); // Get contracts - const rocketNodeStaking = (await upgradeExecuted()) ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); + const rocketNodeStaking = await RocketNodeStaking.deployed(); const rocketVault = await RocketVault.deployed(); const rocketTokenRPL = await RocketTokenRPL.deployed(); const rocketDAONodeTrustedSettingsMinipool = await RocketDAONodeTrustedSettingsMinipool.deployed(); diff --git a/test/network/network-fees-tests.js b/test/network/network-fees-tests.js index 7d91b3c10..32963baca 100644 --- a/test/network/network-fees-tests.js +++ b/test/network/network-fees-tests.js @@ -16,9 +16,9 @@ export default function() { // Setup - let minNodeFee = '0.00'.ether; - let targetNodeFee = '0.50'.ether; - let maxNodeFee = '1.00'.ether; + let minNodeFee = '0.10'.ether; + let targetNodeFee = '0.15'.ether; + let maxNodeFee = '0.20'.ether; let demandRange = '1'.ether; before(async () => { @@ -36,17 +36,17 @@ export default function() { it(printTitle('network node fee', 'has correct value based on node demand'), async () => { // Set expected fees for node demand values let values = [ - {demand: '-1.25'.ether, expectedFee: '0'.ether}, - {demand: '-1.00'.ether, expectedFee: '0'.ether}, - {demand: '-0.75'.ether, expectedFee: '0.2890625'.ether}, - {demand: '-0.50'.ether, expectedFee: '0.4375'.ether}, - {demand: '-0.25'.ether, expectedFee: '0.4921875'.ether}, - {demand: '0.00'.ether, expectedFee: '0.5'.ether}, - {demand: '0.25'.ether, expectedFee: '0.5078125'.ether}, - {demand: '0.50'.ether, expectedFee: '0.5625'.ether}, - {demand: '0.75'.ether, expectedFee: '0.7109375'.ether}, - {demand: '1.00'.ether, expectedFee: '1'.ether}, - {demand: '1.25'.ether, expectedFee: '1'.ether}, + {demand: '-1.25'.ether, expectedFee: '0.1'.ether}, + {demand: '-1.00'.ether, expectedFee: '0.1'.ether}, + {demand: '-0.75'.ether, expectedFee: '0.12890625'.ether}, + {demand: '-0.50'.ether, expectedFee: '0.14375'.ether}, + {demand: '-0.25'.ether, expectedFee: '0.14921875'.ether}, + {demand: '0.00'.ether, expectedFee: '0.15'.ether}, + {demand: '0.25'.ether, expectedFee: '0.15078125'.ether}, + {demand: '0.50'.ether, expectedFee: '0.15625'.ether}, + {demand: '0.75'.ether, expectedFee: '0.17109375'.ether}, + {demand: '1.00'.ether, expectedFee: '0.2'.ether}, + {demand: '1.25'.ether, expectedFee: '0.2'.ether}, ]; // Check fees diff --git a/test/network/scenario-submit-balances.js b/test/network/scenario-submit-balances.js index 305d82a75..5b8e6287d 100644 --- a/test/network/scenario-submit-balances.js +++ b/test/network/scenario-submit-balances.js @@ -1,17 +1,13 @@ import { RocketDAONodeTrusted, RocketNetworkBalances, - RocketNetworkBalancesNew, RocketStorage, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Submit network balances export async function submitBalances(block, slotTimestamp, totalEth, stakingEth, rethSupply, txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketDAONodeTrusted, @@ -19,7 +15,7 @@ export async function submitBalances(block, slotTimestamp, totalEth, stakingEth, rocketStorage, ] = await Promise.all([ RocketDAONodeTrusted.deployed(), - upgraded ? RocketNetworkBalancesNew.deployed() : RocketNetworkBalances.deployed(), + RocketNetworkBalances.deployed(), RocketStorage.deployed(), ]); @@ -91,7 +87,7 @@ export async function submitBalances(block, slotTimestamp, totalEth, stakingEth, // Execute update network balances export async function executeUpdateBalances(block, slotTimestamp, totalEth, stakingEth, rethSupply, txOptions) { // Load contracts - const rocketNetworkBalances = (await upgradeExecuted()) ? await RocketNetworkBalancesNew.deployed() : await RocketNetworkBalances.deployed(); + const rocketNetworkBalances = await RocketNetworkBalances.deployed(); // Get balances function getBalances() { diff --git a/test/network/scenario-submit-prices.js b/test/network/scenario-submit-prices.js index 1adc388c6..1c44499a5 100644 --- a/test/network/scenario-submit-prices.js +++ b/test/network/scenario-submit-prices.js @@ -1,11 +1,9 @@ -import { RocketDAONodeTrusted, RocketNetworkPrices, RocketNetworkPricesNew, RocketStorage } from '../_utils/artifacts'; +import { RocketDAONodeTrusted, RocketNetworkPrices, RocketStorage } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Submit network prices export async function submitPrices(block, slotTimestamp, rplPrice, txOptions) { - const upgraded = await upgradeExecuted(); // Load contracts const [ rocketDAONodeTrusted, @@ -13,7 +11,7 @@ export async function submitPrices(block, slotTimestamp, rplPrice, txOptions) { rocketStorage, ] = await Promise.all([ RocketDAONodeTrusted.deployed(), - upgraded ? RocketNetworkPricesNew.deployed() : RocketNetworkPrices.deployed(), + RocketNetworkPrices.deployed(), RocketStorage.deployed(), ]); @@ -80,7 +78,7 @@ export async function submitPrices(block, slotTimestamp, rplPrice, txOptions) { // Execute price update export async function executeUpdatePrices(block, slotTimestamp, rplPrice, txOptions) { // Load contracts - const rocketNetworkPrices = (await upgradeExecuted()) ? await RocketNetworkPricesNew.deployed() : await RocketNetworkPrices.deployed(); + const rocketNetworkPrices = await RocketNetworkPrices.deployed(); // Get prices function getPrices() { diff --git a/test/node/node-distributor-tests.js b/test/node/node-distributor-tests.js index 6991f3a89..9c12692b4 100644 --- a/test/node/node-distributor-tests.js +++ b/test/node/node-distributor-tests.js @@ -2,7 +2,7 @@ import { printTitle } from '../_utils/formatting'; import { RocketNodeManager, RocketDAONodeTrustedSettingsMinipool, - RocketNodeDistributorFactory, RocketNodeManagerNew, + RocketNodeDistributorFactory, } from '../_utils/artifacts'; import { createMinipool, @@ -63,7 +63,7 @@ export default function() { await registerNode({from: node2}); await nodeStakeRPL(rplStake, {from: node2}); // Get contracts - const rocketNodeManager = await RocketNodeManagerNew.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); // Attempt to initialise await shouldRevert(rocketNodeManager.initialiseFeeDistributor({from: node2}), 'Was able to initialise again', 'Already initialised'); }); @@ -71,7 +71,7 @@ export default function() { it(printTitle('node operator', 'can not initialise fee distributor if already initialised'), async () => { // Attempt to initialise a second time - const rocketNodeManager = await RocketNodeManagerNew.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); await shouldRevert(rocketNodeManager.initialiseFeeDistributor({from: node1}), 'Was able to initialise again', 'Already initialised'); }); diff --git a/test/node/node-manager-tests.js b/test/node/node-manager-tests.js index a85e16ff4..1e520c40c 100644 --- a/test/node/node-manager-tests.js +++ b/test/node/node-manager-tests.js @@ -1,7 +1,7 @@ import { printTitle } from '../_utils/formatting'; import { shouldRevert } from '../_utils/testing'; import { registerNode } from '../_helpers/node'; -import { RocketDAOProtocolSettingsNode, RocketNodeManager, RocketNodeManagerNew } from '../_utils/artifacts'; +import { RocketDAOProtocolSettingsNode, RocketNodeManager } from '../_utils/artifacts'; import { setDAOProtocolBootstrapSetting, setRewardsClaimIntervalTime } from '../dao/scenario-dao-protocol-bootstrap'; import { register } from './scenario-register'; import { setTimezoneLocation } from './scenario-set-timezone'; @@ -245,7 +245,7 @@ export default function() { it(printTitle('random', 'can query timezone counts'), async () => { - const rocketNodeManager = await RocketNodeManagerNew.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); await rocketNodeManager.registerNode('Australia/Sydney', {from: random2}); await rocketNodeManager.registerNode('Australia/Perth', {from: random3}); diff --git a/test/node/node-staking-tests.js b/test/node/node-staking-tests.js index 2010b9ffd..ee5d3b351 100644 --- a/test/node/node-staking-tests.js +++ b/test/node/node-staking-tests.js @@ -1,6 +1,6 @@ import { RocketDAONodeTrustedSettingsMinipool, RocketDAOProtocolSettingsMinipool, RocketDAOProtocolSettingsRewards, - RocketNodeStaking, RocketNodeStakingNew, + RocketNodeStaking, } from '../_utils/artifacts'; import { printTitle } from '../_utils/formatting'; import { shouldRevert } from '../_utils/testing'; @@ -47,7 +47,7 @@ export default function() { await upgradeOneDotThree(); // Load contracts - rocketNodeStaking = await RocketNodeStakingNew.deployed(); + rocketNodeStaking = await RocketNodeStaking.deployed(); // Set settings await setDAONodeTrustedBootstrapSetting(RocketDAONodeTrustedSettingsMinipool, 'minipool.scrub.period', scrubPeriod, {from: owner}); diff --git a/test/node/scenario-deposit-v2.js b/test/node/scenario-deposit-v2.js index f29776186..25291757b 100644 --- a/test/node/scenario-deposit-v2.js +++ b/test/node/scenario-deposit-v2.js @@ -1,12 +1,11 @@ import { RocketMinipoolDelegate, RocketMinipoolFactory, RocketMinipoolManager, - RocketNodeDeposit, RocketNodeDepositNew, + RocketNodeDeposit, RocketStorage, } from '../_utils/artifacts'; import { getDepositDataRoot, getValidatorPubkey, getValidatorSignature } from '../_utils/beacon'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; let minipoolSalt = 0; @@ -22,7 +21,7 @@ export async function depositV2(minimumNodeFee, bondAmount, txOptions) { ] = await Promise.all([ RocketMinipoolManager.deployed(), RocketMinipoolFactory.deployed(), - (await upgradeExecuted()) ? RocketNodeDepositNew.deployed() : RocketNodeDeposit.deployed(), + RocketNodeDeposit.deployed(), RocketStorage.deployed() ]); diff --git a/test/node/scenario-register-smoothing-pool.js b/test/node/scenario-register-smoothing-pool.js index 0d419c7fe..87fae5b1d 100644 --- a/test/node/scenario-register-smoothing-pool.js +++ b/test/node/scenario-register-smoothing-pool.js @@ -1,11 +1,10 @@ -import { RocketNodeManager, RocketNodeManagerNew } from '../_utils/artifacts'; -import { upgradeExecuted } from '../_utils/upgrade'; +import { RocketNodeManager } from '../_utils/artifacts'; // Register a node export async function setSmoothingPoolRegistrationState(state, txOptions) { // Load contracts - const rocketNodeManager = await upgradeExecuted() ? await RocketNodeManagerNew.deployed() : await RocketNodeManager.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); // Register await rocketNodeManager.setSmoothingPoolRegistrationState(state, txOptions); diff --git a/test/node/scenario-register.js b/test/node/scenario-register.js index d5749a49f..c40d6a658 100644 --- a/test/node/scenario-register.js +++ b/test/node/scenario-register.js @@ -1,13 +1,12 @@ -import { RocketNodeManager, RocketNodeManagerNew } from '../_utils/artifacts'; +import { RocketNodeManager } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Register a node export async function register(timezoneLocation, txOptions) { // Load contracts - const rocketNodeManager = await upgradeExecuted() ? await RocketNodeManagerNew.deployed() : await RocketNodeManager.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); // Get node details function getNodeDetails(nodeAddress) { diff --git a/test/node/scenario-set-timezone.js b/test/node/scenario-set-timezone.js index 93412c5cb..78f732e03 100644 --- a/test/node/scenario-set-timezone.js +++ b/test/node/scenario-set-timezone.js @@ -1,11 +1,10 @@ -import { RocketNodeManager, RocketNodeManagerNew } from '../_utils/artifacts'; -import { upgradeExecuted } from '../_utils/upgrade'; +import { RocketNodeManager } from '../_utils/artifacts'; // Set a node's timezone location export async function setTimezoneLocation(timezoneLocation, txOptions) { // Load contracts - const rocketNodeManager = await upgradeExecuted() ? await RocketNodeManagerNew.deployed() : await RocketNodeManager.deployed(); + const rocketNodeManager = await RocketNodeManager.deployed(); // Set timezone location await rocketNodeManager.setTimezoneLocation(timezoneLocation, txOptions); diff --git a/test/node/scenario-stake-rpl.js b/test/node/scenario-stake-rpl.js index 7f5885375..a226943a6 100644 --- a/test/node/scenario-stake-rpl.js +++ b/test/node/scenario-stake-rpl.js @@ -6,16 +6,12 @@ import { RocketNodeStaking, RocketTokenRPL, RocketVault, - RocketNetworkPricesNew, RocketNodeStakingNew, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Stake RPL against the node export async function stakeRpl(amount, txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketMinipoolManager, @@ -28,9 +24,9 @@ export async function stakeRpl(amount, txOptions) { ] = await Promise.all([ RocketMinipoolManager.deployed(), RocketDAOProtocolSettingsMinipool.deployed(), - upgraded ? RocketNetworkPricesNew.deployed() : RocketNetworkPrices.deployed(), + RocketNetworkPrices.deployed(), RocketDAOProtocolSettingsNode.deployed(), - upgraded ? RocketNodeStakingNew.deployed() : RocketNodeStaking.deployed(), + RocketNodeStaking.deployed(), RocketTokenRPL.deployed(), RocketVault.deployed(), ]); diff --git a/test/node/scenario-withdraw-rpl.js b/test/node/scenario-withdraw-rpl.js index 4997073a7..36f6f756a 100644 --- a/test/node/scenario-withdraw-rpl.js +++ b/test/node/scenario-withdraw-rpl.js @@ -6,16 +6,13 @@ import { RocketNodeStaking, RocketTokenRPL, RocketVault, - RocketNetworkPricesNew, RocketNodeStakingNew, RocketNodeManager, RocketNodeManagerNew, + RocketNodeManager, } from '../_utils/artifacts'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Withdraw RPL staked against the node export async function withdrawRpl(amount, txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketMinipoolManager, @@ -29,10 +26,10 @@ export async function withdrawRpl(amount, txOptions) { ] = await Promise.all([ RocketMinipoolManager.deployed(), RocketDAOProtocolSettingsMinipool.deployed(), - upgraded ? RocketNetworkPricesNew.deployed() : RocketNetworkPrices.deployed(), + RocketNetworkPrices.deployed(), RocketDAOProtocolSettingsNode.deployed(), - upgraded ? RocketNodeManagerNew.deployed() : RocketNodeManager.deployed(), - upgraded ? RocketNodeStakingNew.deployed() : RocketNodeStaking.deployed(), + RocketNodeManager.deployed(), + RocketNodeStaking.deployed(), RocketTokenRPL.deployed(), RocketVault.deployed(), ]); @@ -49,7 +46,7 @@ export async function withdrawRpl(amount, txOptions) { rocketDAOProtocolSettingsNode.getMinimumPerMinipoolStake.call(), rocketDAOProtocolSettingsNode.getMaximumPerMinipoolStake.call(), rocketNetworkPrices.getRPLPrice.call(), - upgraded ? rocketNodeManager.getNodeRPLWithdrawalAddress(txOptions.from) : txOptions.from, + rocketNodeManager.getNodeRPLWithdrawalAddress(txOptions.from), ]); // Get token balances @@ -96,7 +93,7 @@ export async function withdrawRpl(amount, txOptions) { ]); // Withdraw RPL - await (upgraded ? rocketNodeStaking.methods['withdrawRPL(uint256)'](amount, txOptions) : rocketNodeStaking.withdrawRPL(amount, txOptions)); + await rocketNodeStaking.methods['withdrawRPL(uint256)'](amount, txOptions); // Get updated token balances, staking details & minipool counts let [balances2, details2, minipoolCounts] = await Promise.all([ diff --git a/test/rewards/scenario-claim-and-stake-rewards.js b/test/rewards/scenario-claim-and-stake-rewards.js index 561e6ef14..b711f7472 100644 --- a/test/rewards/scenario-claim-and-stake-rewards.js +++ b/test/rewards/scenario-claim-and-stake-rewards.js @@ -1,19 +1,16 @@ import { RocketMerkleDistributorMainnet, - RocketNodeManager, RocketNodeStaking, RocketNodeStakingNew, + RocketNodeManager, RocketNodeStaking, RocketRewardsPool, RocketStorage, RocketTokenRPL, } from '../_utils/artifacts'; import { parseRewardsMap } from '../_utils/merkle-tree'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Submit network prices export async function claimAndStakeRewards(nodeAddress, indices, rewards, stakeAmount, txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketRewardsPool, @@ -25,7 +22,7 @@ export async function claimAndStakeRewards(nodeAddress, indices, rewards, stakeA ] = await Promise.all([ RocketRewardsPool.deployed(), RocketNodeManager.deployed(), - upgraded ? RocketNodeStakingNew.deployed() : RocketNodeStaking.deployed(), + RocketNodeStaking.deployed(), RocketMerkleDistributorMainnet.deployed(), RocketStorage.deployed(), RocketTokenRPL.deployed(), diff --git a/test/rewards/scenario-submit-rewards.js b/test/rewards/scenario-submit-rewards.js index 8dcc66848..5acb95b0f 100644 --- a/test/rewards/scenario-submit-rewards.js +++ b/test/rewards/scenario-submit-rewards.js @@ -1,18 +1,15 @@ import { RocketClaimDAO, RocketDAONodeTrusted, - RocketRewardsPool, RocketRewardsPoolNew, + RocketRewardsPool, RocketTokenRETH, RocketTokenRPL, } from '../_utils/artifacts'; import { parseRewardsMap } from '../_utils/merkle-tree'; import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted } from '../_utils/upgrade'; // Submit rewards export async function submitRewards(index, rewards, treasuryRPL, userETH, txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketDAONodeTrusted, @@ -22,7 +19,7 @@ export async function submitRewards(index, rewards, treasuryRPL, userETH, txOpti rocketClaimDAO ] = await Promise.all([ RocketDAONodeTrusted.deployed(), - upgraded ? RocketRewardsPoolNew.deployed() : RocketRewardsPool.deployed(), + RocketRewardsPool.deployed(), RocketTokenRETH.deployed(), RocketTokenRPL.deployed(), RocketClaimDAO.deployed() @@ -145,13 +142,11 @@ export async function submitRewards(index, rewards, treasuryRPL, userETH, txOpti // Execute a reward period that already has consensus export async function executeRewards(index, rewards, treasuryRPL, userETH, txOptions) { - const upgraded = await upgradeExecuted(); - // Load contracts const [ rocketRewardsPool, ] = await Promise.all([ - upgraded ? RocketRewardsPoolNew.deployed() : RocketRewardsPool.deployed(), + RocketRewardsPool.deployed(), ]); // Construct the merkle tree diff --git a/test/rocket-pool-tests.js b/test/rocket-pool-tests.js index d93eb6b6f..d374a1048 100644 --- a/test/rocket-pool-tests.js +++ b/test/rocket-pool-tests.js @@ -30,7 +30,6 @@ import { injectBNHelpers } from './_helpers/bn'; import { checkInvariants } from './_helpers/invariants'; import networkSnapshotsTests from './network/network-snapshots-tests'; import networkVotingTests from './network/network-voting-tests'; -import upgradeTests from './upgrade/upgrade-tests'; // Header console.log('\n'); @@ -70,7 +69,6 @@ auctionTests(); depositPoolTests(); minipoolScrubTests(); minipoolTests(); -upgradeTests(); minipoolVacantTests(); minipoolStatusTests(); minipoolWithdrawalTests(); diff --git a/test/upgrade/upgrade-tests.js b/test/upgrade/upgrade-tests.js deleted file mode 100644 index 1e4277ed0..000000000 --- a/test/upgrade/upgrade-tests.js +++ /dev/null @@ -1,480 +0,0 @@ -import { - RocketDAONodeTrustedSettingsMinipool, - RocketDAOProtocolSettingsMinipool, - RocketDAOProtocolSettingsNetwork, - RocketDAOProtocolSettingsRewards, - RocketMinipoolManager, - RocketMinipoolManagerNew, - RocketNetworkVoting, - RocketNodeStaking, - RocketNodeStakingNew, RocketUpgradeOneDotThree, -} from '../_utils/artifacts'; -import { increaseTime } from '../_utils/evm'; -import { userDeposit } from '../_helpers/deposit'; -import { - createMinipool, - createVacantMinipool, - getMinipoolMinimumRPLStake, - promoteMinipool, - stakeMinipool, -} from '../_helpers/minipool'; -import { nodeStakeRPL, registerNode, setNodeTrusted } from '../_helpers/node'; -import { mintRPL } from '../_helpers/tokens'; -import { close } from '../minipool/scenario-close'; -import { setDAOProtocolBootstrapSetting } from '../dao/scenario-dao-protocol-bootstrap'; -import { setDAONodeTrustedBootstrapSetting } from '../dao/scenario-dao-node-trusted-bootstrap'; -import { assertBN } from '../_helpers/bn'; -import { upgradeExecuted, upgradeOneDotThree } from '../_utils/upgrade'; -import { voteScrub } from '../minipool/scenario-scrub'; -import { shouldRevert } from '../_utils/testing'; - -export default function() { - contract('RocketUpgrade', async (accounts) => { - - // Accounts - const [ - owner, - node1, - node2, - node3, - node4, - emptyNode, - nodeWithdrawalAddress, - trustedNode, - dummySwc, - random, - ] = accounts; - - // Setup - let launchTimeout = (60 * 60 * 72); // 72 hours - let withdrawalDelay = 20; - let scrubPeriod = (60 * 60 * 24); // 24 hours - let bondReductionWindowStart = (2 * 24 * 60 * 60); - let bondReductionWindowLength = (2 * 24 * 60 * 60); - let rewardClaimBalanceIntervals = 28; - let balanceSubmissionFrequency = (60 * 60 * 24); - let promotionScrubDelay = (60 * 60 * 24); // 24 hours - - let rocketNetworkVoting; - - before(async () => { - rocketNetworkVoting = await RocketNetworkVoting.deployed(); - - // Register trusted node - await registerNode({ from: trustedNode }); - await setNodeTrusted(trustedNode, 'saas_1', 'node@home.com', owner); - - // Set settings - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsMinipool, 'minipool.launch.timeout', launchTimeout, { from: owner }); - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsMinipool, 'minipool.withdrawal.delay', withdrawalDelay, { from: owner }); - await setDAONodeTrustedBootstrapSetting(RocketDAONodeTrustedSettingsMinipool, 'minipool.scrub.period', scrubPeriod, { from: owner }); - await setDAONodeTrustedBootstrapSetting(RocketDAONodeTrustedSettingsMinipool, 'minipool.bond.reduction.window.start', bondReductionWindowStart, { from: owner }); - await setDAONodeTrustedBootstrapSetting(RocketDAONodeTrustedSettingsMinipool, 'minipool.bond.reduction.window.length', bondReductionWindowLength, { from: owner }); - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsNetwork, 'network.submit.balances.frequency', balanceSubmissionFrequency, { from: owner }); - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsRewards, 'rewards.claimsperiods', rewardClaimBalanceIntervals, { from: owner }); - await setDAONodeTrustedBootstrapSetting(RocketDAONodeTrustedSettingsMinipool, 'minipool.promotion.scrub.period', promotionScrubDelay, {from: owner}); - - // Set rETH collateralisation target to a value high enough it won't cause excess ETH to be funneled back into deposit pool and mess with our calcs - await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsNetwork, 'network.reth.collateral.target', '50'.ether, { from: owner }); - - // Fill up deposit pool - await userDeposit({ from: random, value: '500'.ether }); - }); - - async function getData(nodeAddress) { - const upgraded = await upgradeExecuted(); - const rocketNodeStaking = upgraded ? await RocketNodeStakingNew.deployed() : await RocketNodeStaking.deployed(); - const rocketMinipoolManager = upgraded ? await RocketMinipoolManagerNew.deployed() : await RocketMinipoolManager.deployed(); - - return { - ethProvided: await rocketNodeStaking.getNodeETHProvided(nodeAddress), - ethMatched: await rocketNodeStaking.getNodeETHMatched(nodeAddress), - collatRatio: await rocketNodeStaking.getNodeETHCollateralisationRatio(nodeAddress), - effective: await rocketNodeStaking.getNodeEffectiveRPLStake(nodeAddress), - stake: await rocketNodeStaking.getNodeRPLStake(nodeAddress), - count: await rocketMinipoolManager.getNodeActiveMinipoolCount(nodeAddress), - }; - } - - function printData(data) { - console.log(`ethProvided: ` + data.ethProvided.toString()); - console.log(`ethMatched: ` + data.ethMatched.toString()); - console.log(`collatRatio: ` + data.collatRatio.toString()); - console.log(`effective: ` + data.effective.toString()); - console.log(`stake: ` + data.stake.toString()); - console.log(`count: ` + data.count.toString()); - } - - function compareData(data1, data2) { - assertBN.equal(data1.ethProvided, data2.ethProvided); - assertBN.equal(data1.ethMatched, data2.ethMatched); - assertBN.equal(data1.collatRatio, data2.collatRatio); - assertBN.equal(data1.effective, data2.effective); - assertBN.equal(data1.stake, data2.stake); - assertBN.equal(data1.count, data2.count); - } - - async function setupNode(node) { - // Register empty node - await registerNode({ from: node }); - // Stake RPL to cover minipools - let minipoolRplStake = await getMinipoolMinimumRPLStake(); - let rplStake = minipoolRplStake.mul('7'.BN); - await mintRPL(owner, node, rplStake); - await nodeStakeRPL(rplStake, { from: node }); - } - - async function distribute(minipool, node){ - await web3.eth.sendTransaction({ - from: random, - to: minipool.address, - value: '32'.ether, - }); - await minipool.distributeBalance(false, { from: node }); - } - - async function initialiseVoting(node) { - await rocketNetworkVoting.methods['initialiseVoting()']({ from: node }); - } - - async function scrub(minipool, node) { - await voteScrub(minipool, { from: trustedNode }); - await close(minipool, { from: node }); - } - - // - // Pubkey mapping fix - // - - it('should be able to fix the reverse pubkey mapping', async () => { - // Register and stake RPL for 1 node - await setupNode(node1); - - // Create a vacant minipool with current balance of 33 - let minipool1 = await createVacantMinipool('8'.ether, {from: node1}, null, '33'.ether); - let minipool2 = await createVacantMinipool('16'.ether, {from: node1}); - - // Scrub minipool2 - await voteScrub(minipool2, {from: trustedNode}); - - // Wait required scrub period - await increaseTime(hre.web3, promotionScrubDelay + 1); - - // Promote the minipool - await promoteMinipool(minipool1, {from: node1}); - - // Pubkey should be wrong due to bug in previous version - const rocketMinipoolManager = await RocketMinipoolManager.deployed(); - let actualPubKey = await rocketMinipoolManager.getMinipoolPubkey(minipool1.address); - let reverseAddress = await rocketMinipoolManager.getMinipoolByPubkey(actualPubKey); - assert.equal(reverseAddress, "0x0000000000000000000000000000000000000000"); - - // Perform upgrade - await upgradeOneDotThree(); - - // Call the fix method - const rocketUpgrade = await RocketUpgradeOneDotThree.deployed(); - await rocketUpgrade.fixPubkeys([minipool1.address]); - - // Pubkey should be correct now - actualPubKey = await rocketMinipoolManager.getMinipoolPubkey(minipool1.address); - reverseAddress = await rocketMinipoolManager.getMinipoolByPubkey(actualPubKey); - assert.equal(reverseAddress, minipool1.address); - - // Should not be able to call it on the scrubbed minipool - await shouldRevert(rocketUpgrade.fixPubkeys([minipool2.address]), "Was able to call fix on dissolved minipool", "Minipool was dissolved"); - }); - - // - // State differential tests - // - - it('creating minipools before and after upgrade', async () => { - // Register and stake RPL for 3 nodes - await setupNode(node1); - await setupNode(node2); - await setupNode(node4); - - // Create and 8 and a 16 for node2 - await createMinipool({ from: node2, value: '8'.ether }); - await createMinipool({ from: node2, value: '16'.ether }); - - const node2Data1 = await getData(node2); - - // Create an 8 for node1 - await createMinipool({ from: node1, value: '8'.ether }); - - // Perform upgrade - await upgradeOneDotThree(); - - // Create a 16 for node1 - await createMinipool({ from: node1, value: '16'.ether }); - - // Register and stake for node3 - await setupNode(node3); - - // Create and 8 and a 16 for node3 - await createMinipool({ from: node3, value: '8'.ether }); - await createMinipool({ from: node3, value: '16'.ether }); - - const node1Data1 = await getData(node1); - - // Create a 16 for node4 - await createMinipool({ from: node4, value: '16'.ether }); - - // Initialise voting for node1 - await initialiseVoting(node1); - - // Create an 8 for node4 - await createMinipool({ from: node4, value: '8'.ether }); - - const node4Data1 = await getData(node4); - const node2Data2 = await getData(node2); - - // Initialise voting for node2 and node4 - await initialiseVoting(node2); - await initialiseVoting(node4); - - // Collect data - const node1Data2 = await getData(node1); - const node2Data3 = await getData(node2); - const node3Data1 = await getData(node3); - const node4Data2 = await getData(node4); - - // All data should be identical at the times collected - compareData(node2Data1, node2Data3); - compareData(node1Data1, node1Data2); - compareData(node1Data2, node2Data3); - compareData(node1Data1, node3Data1); - compareData(node1Data1, node4Data1); - compareData(node4Data1, node4Data2); - compareData(node2Data1, node2Data2); - }); - - it('scrub across upgrade', async () => { - // Create minipool - await setupNode(node1); - const minipool1 = await createMinipool({ from: node1, value: '16'.ether }); - - const node1Data1 = await getData(node1); - - await upgradeOneDotThree(); - - // Scrub - await scrub(minipool1, node1); - - const node1Data2 = await getData(node1); - - // Same thing with a node post upgrade - await setupNode(node2); - const minipool2 = await createMinipool({ from: node2, value: '16'.ether }); - - const node2Data1 = await getData(node2); - - // Scrub - await scrub(minipool2, node2); - - const node2Data2 = await getData(node2); - - compareData(node1Data1, node2Data1); - compareData(node1Data2, node2Data2); - }); - - it('distribute across upgrade', async () => { - // Create minipool - await setupNode(node1); - const minipool1 = await createMinipool({ from: node1, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(minipool1, { from: node1 }); - - // Perform upgrade - await upgradeOneDotThree(); - - // Distribute - await distribute(minipool1, node1); - - // Same thing but post upgrade - await setupNode(node2); - const minipool2 = await createMinipool({ from: node2, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(minipool2, { from: node2 }); - - // Distribute - await distribute(minipool2, node2); - - const node1Data1 = await getData(node1); - await initialiseVoting(node1); - const node1Data2 = await getData(node1); - - const node2Data = await getData(node2); - - // Should be same outcome - compareData(node1Data1, node1Data2); - compareData(node1Data1, node2Data); - }); - - it('distribute with multiple minipools across upgrade', async () => { - // Create minipool - await setupNode(node1); - const minipool1 = await createMinipool({ from: node1, value: '16'.ether }); - await createMinipool({ from: node1, value: '8'.ether }); - await createMinipool({ from: node1, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(minipool1, { from: node1 }); - - await setupNode(node2); - await createMinipool({ from: node2, value: '8'.ether }); - - // Perform upgrade - await upgradeOneDotThree(); - - // Distribute - await distribute(minipool1, node1); - - const minipool2 = await createMinipool({ from: node2, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(minipool2, { from: node2 }); - - // Distribute - await distribute(minipool2, node2); - - await createMinipool({ from: node2, value: '16'.ether }); - - const node2Data1 = await getData(node2); - await initialiseVoting(node2); - const node2Data2 = await getData(node2); - - const node1Data1 = await getData(node1); - await initialiseVoting(node1); - const node1Data2 = await getData(node1); - - // Same thing with new node post upgrade - await setupNode(node3); - const minipool3 = await createMinipool({ from: node3, value: '16'.ether }); - await createMinipool({ from: node3, value: '8'.ether }); - await createMinipool({ from: node3, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(minipool3, { from: node3 }); - await distribute(minipool3, node3); - - const node3Data = await getData(node3); - - // Should be same outcome - compareData(node1Data1, node1Data2); - compareData(node2Data1, node2Data2); - compareData(node1Data1, node2Data1); - compareData(node1Data1, node3Data); - }); - - it('distribute and scrub across upgrade', async () => { - // Create minipool - await setupNode(node1); - const node1minipool1 = await createMinipool({ from: node1, value: '16'.ether }); - const node1minipool2 = await createMinipool({ from: node1, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(node1minipool2, { from: node1 }); - - await upgradeOneDotThree(); - - // Scrub - await scrub(node1minipool1, node1); - - // Distribute - await distribute(node1minipool2, node1); - - // Do the same thing post upgrade with a fresh node - await setupNode(node2); - const node2minipool1 = await createMinipool({ from: node2, value: '16'.ether }); - const node2minipool2 = await createMinipool({ from: node2, value: '16'.ether }); - await increaseTime(web3, scrubPeriod + 1); - await stakeMinipool(node2minipool2, { from: node2 }); - - // Scrub - await scrub(node2minipool1, node2); - - // Distribute - await distribute(node2minipool2, node2); - - // Check results match - const node1Data1 = await getData(node1); - await initialiseVoting(node1); - const node1Data2 = await getData(node1); - const node2Data = await getData(node2); - compareData(node1Data1, node1Data2); - compareData(node2Data, node1Data1); - }); - - it('scrub before and after upgrade', async () => { - // Create minipool - await setupNode(node1); - const node1minipool1 = await createMinipool({ from: node1, value: '16'.ether }); - const node1minipool2 = await createMinipool({ from: node1, value: '16'.ether }); - - // Scrub - await scrub(node1minipool1, node1); - - // Upgrade - await upgradeOneDotThree(); - - // Scrub - await scrub(node1minipool2, node1); - - // Same thing post upgrade - await setupNode(node2); - const node2minipool1 = await createMinipool({ from: node2, value: '16'.ether }); - const node2minipool2 = await createMinipool({ from: node2, value: '16'.ether }); - - // Scrub - await scrub(node2minipool1, node2); - await scrub(node2minipool2, node2); - - // Check results match - const node1Data1 = await getData(node1); - await initialiseVoting(node1); - const node1Data2 = await getData(node1); - const node2Data = await getData(node2); - compareData(node1Data1, node1Data2); - compareData(node2Data, node1Data1); - }); - - it('scrub before and after upgrade and throw in some other minipools', async () => { - // Create minipool - await setupNode(node1); - const node1minipool1 = await createMinipool({ from: node1, value: '16'.ether }); - const node1minipool2 = await createMinipool({ from: node1, value: '16'.ether }); - await createMinipool({ from: node1, value: '8'.ether }); - await createMinipool({ from: node1, value: '16'.ether }); - - // Scrub - await scrub(node1minipool1, node1); - - await upgradeOneDotThree(); - - // Scrub - await scrub(node1minipool2, node1); - - // Same thing post upgrade - await setupNode(node2); - const node2minipool1 = await createMinipool({ from: node2, value: '16'.ether }); - const node2minipool2 = await createMinipool({ from: node2, value: '16'.ether }); - - // Scrub - await scrub(node2minipool1, node2); - await scrub(node2minipool2, node2); - - // Create some new ones - await createMinipool({ from: node1, value: '8'.ether }); - await createMinipool({ from: node2, value: '8'.ether }); - await createMinipool({ from: node2, value: '8'.ether }); - await createMinipool({ from: node2, value: '16'.ether }); - - // Check results match - const node1Data1 = await getData(node1); - await initialiseVoting(node1); - const node1Data2 = await getData(node1); - const node2Data = await getData(node2); - compareData(node1Data1, node1Data2); - compareData(node2Data, node1Data1); - }); - }); -}