diff --git a/docs/source/architecture/contracts.rst b/docs/source/architecture/contracts.rst index 0350cc76f..b76abedd6 100644 --- a/docs/source/architecture/contracts.rst +++ b/docs/source/architecture/contracts.rst @@ -58,8 +58,8 @@ Alice can choose stakers by herself ("handpicked") or select from the result of In order to place the fee for a policy, Alice calls the method ``PolicyManager.createPolicy(bytes16, address, uint64, address[])``\ , specifying the policy ID (off-chain generation), the policy owner (could be zero address), the end timestamp of the policy and the stakers' addresses. -Payment should be added to the transaction in ETH and the amount is ``rewardRate * periods * stakers.length``\ , where ``periods`` is ``endTimestampPeriod - currentPeriod + 1``. -The reward rate must be greater than or equal to the minimum reward for each staker in the list. +Payment should be added to the transaction in ETH and the amount is ``feeRate * periods * stakers.length``\ , where ``periods`` is ``endTimestampPeriod - currentPeriod + 1``. +The fee rate must be greater than or equal to the minimum fee for each staker in the list. Alice Revokes a Blockchain Policy ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,13 +123,13 @@ The reward is calculated separately for each stake that is active during the min The order of calling ``StakingEscrow.mint()`` by stakers (e.g. who calls first, second etc) doesn't matter. Stakers can claim their rewards by using the ``StakingEscrow.withdraw(uint256)`` method. Only non-locked tokens can be withdrawn. -Ursula Generates Policy Rewards +Ursula Generates Policy Fees ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Also the staker gets rewards for policies deployed. -Computation of a policy reward happens every time ``StakingEscrow.mint()`` is called by the ``PolicyManager.updateReward(address, uint16)`` method. -In order to take the reward, the staker needs to call method ``withdraw()`` of the contract ``PolicyManager``. -The staker can set a minimum reward rate for a policy. For that, the staker should call the ``PolicyManager.setMinRewardRate(uint256)`` method. +Also the staker gets fees for policies deployed. +Computation of a policy fee happens every time ``StakingEscrow.mint()`` is called by the ``PolicyManager.updateFee(address, uint16)`` method. +In order to take the fee, the staker needs to call method ``withdraw()`` of the contract ``PolicyManager``. +The staker can set a minimum fee rate for a policy. For that, the staker should call the ``PolicyManager.setMinFeeRate(uint256)`` method. NuCypher Partner Ursula Staking ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/source/guides/network_node/staking_guide.rst b/docs/source/guides/network_node/staking_guide.rst index 6ab268698..b4cada546 100644 --- a/docs/source/guides/network_node/staking_guide.rst +++ b/docs/source/guides/network_node/staking_guide.rst @@ -371,7 +371,7 @@ the commitment period. will result in the loss of staked tokens as described in the NuCypher slashing protocol. Keeping your Ursula node online during the staking period and successfully - producing correct re-encryption work orders will result in rewards + producing correct re-encryption work orders will result in fees paid out in ethers retro-actively and on-demand. Accept ursula node operator obligation? [y/N]: y @@ -577,16 +577,16 @@ To divide an existing stake: Collect rewards earned by the staker ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -NuCypher nodes earn two types of rewards: staking rewards (in NU) and policy rewards (i.e., service fees in ETH). -To collect these rewards use ``nucypher stake collect-reward`` with flags ``--staking-reward`` and ``--policy-reward`` +NuCypher nodes earn two types of rewards: staking rewards (in NU) and policy fees (i.e., service fees in ETH). +To collect these rewards use ``nucypher stake collect-reward`` with flags ``--staking-reward`` and ``--policy-fee`` (or even both). While staking rewards can only be collected to the original staker account, you can decide which account receives -policy rewards using the ``--withdraw-address `` flag. +policy fees using the ``--withdraw-address `` flag. .. code:: bash - (nucypher)$ nucypher stake collect-reward --staking-reward --policy-reward --staking-address 0x287A817426DD1AE78ea23e9918e2273b6733a43D --hw-wallet + (nucypher)$ nucypher stake collect-reward --staking-reward --policy-fee --staking-address 0x287A817426DD1AE78ea23e9918e2273b6733a43D --hw-wallet ____ __ __ /\ _`\ /\ \__ /\ \ @@ -604,7 +604,7 @@ policy rewards using the ``--withdraw-address `` flag. Block #1245170 | 0x63e4da39056873adaf869674db4002e016c80466f38256a4c251516a0e25e547 See https://goerli.etherscan.io/tx/0xb0625030224e228198faa3ed65d43f93247cf6067aeb62264db6f31b5bf411fa - Collecting 0.978 ETH from policy rewards... + Collecting 0.978 ETH from policy fees... OK | 0xe6d555be43263702b74727ce29dc4bcd6e32019159ccb15120791dfda0975372 (25070 gas) Block #1245171 | 0x0d8180a69213c240e2bf2045179976d5f18de56a82f17a9d59db54756b6604e4 diff --git a/docs/source/support/faq.rst b/docs/source/support/faq.rst index d92452774..095f37f09 100644 --- a/docs/source/support/faq.rst +++ b/docs/source/support/faq.rst @@ -86,7 +86,7 @@ Alice provides an upfront deposit that covers the entirety of the sharing policy Q: What currency does Ursula stake in (assuming Ursula is also the Staker)? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Ursula stakes in NU, receives policy rewards in ETH, and receives inflation rewards in NU. +Ursula stakes in NU, receives policy fees in ETH, and receives inflation rewards in NU. Q: Why do you have a mix of NU and ETH? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -137,12 +137,12 @@ NU is an implementation of the ERC20 standard deployed onto the Ethereum blockch Q: What are the two streams of income Ursula can receive? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Inflation Rewards (NU) and Policy Rewards (ETH). We will soon refer to Policy Rewards as “Fees” to avoid confusion. +Inflation Rewards (NU) and Policy Fees (ETH). -Q: How are Policy Rewards (ETH) determined? +Q: How are Policy Fees (ETH) determined? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The reward is calculated with Confirm Activity taking into account the number of policies Ursula is enforcing. +The fee is calculated with Confirm Activity taking into account the number of policies Ursula is enforcing. Q: How many Ursulas per period collect Inflation rewards (NU)? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index 703fec347..c21f46696 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -501,19 +501,19 @@ class ContractAdministrator(NucypherTokenActor): file.write(data) return filepath - def set_min_reward_rate_range(self, - minimum: int, - default: int, - maximum: int, - transaction_gas_limit: int = None) -> dict: + def set_min_fee_rate_range(self, + minimum: int, + default: int, + maximum: int, + transaction_gas_limit: int = None) -> dict: policy_manager_deployer = PolicyManagerDeployer(registry=self.registry, deployer_address=self.deployer_address, economics=self.economics) - receipt = policy_manager_deployer.set_min_reward_rate_range(minimum=minimum, - default=default, - maximum=maximum, - gas_limit=transaction_gas_limit) + receipt = policy_manager_deployer.set_min_fee_rate_range(minimum=minimum, + default=default, + maximum=maximum, + gas_limit=transaction_gas_limit) return receipt @@ -1117,24 +1117,24 @@ class Staker(NucypherTokenActor): staking_reward = self.staking_agent.calculate_staking_reward(staker_address=self.checksum_address) return staking_reward - def calculate_policy_reward(self) -> int: - policy_reward = self.policy_agent.get_reward_amount(staker_address=self.checksum_address) - return policy_reward + def calculate_policy_fee(self) -> int: + policy_fee = self.policy_agent.get_fee_amount(staker_address=self.checksum_address) + return policy_fee @only_me @save_receipt @validate_checksum_address - def collect_policy_reward(self, collector_address=None) -> dict: - """Collect rewarded ETH.""" + def collect_policy_fee(self, collector_address=None) -> dict: + """Collect fee ETH.""" if self.is_contract: if collector_address and collector_address != self.beneficiary_address: - raise ValueError("Policy rewards must be withdrawn to the beneficiary address") - self.preallocation_escrow_agent.collect_policy_reward() # TODO save receipt + raise ValueError("Policy fees must be withdrawn to the beneficiary address") + self.preallocation_escrow_agent.collect_policy_fee() # TODO save receipt receipt = self.preallocation_escrow_agent.withdraw_eth() else: withdraw_address = collector_address or self.checksum_address - receipt = self.policy_agent.collect_policy_reward(collector_address=withdraw_address, - staker_address=self.checksum_address) + receipt = self.policy_agent.collect_policy_fee(collector_address=withdraw_address, + staker_address=self.checksum_address) return receipt @only_me @@ -1190,33 +1190,33 @@ class Staker(NucypherTokenActor): @only_me @save_receipt - def set_min_reward_rate(self, min_rate: int) -> Tuple[str, str]: - """Public facing method for setting min reward rate.""" - minimum, _default, maximum = self.policy_agent.get_min_reward_rate_range() + def set_min_fee_rate(self, min_rate: int) -> Tuple[str, str]: + """Public facing method for setting min fee rate.""" + minimum, _default, maximum = self.policy_agent.get_min_fee_rate_range() if min_rate < minimum or min_rate > maximum: - raise ValueError(f"Min reward rate {min_rate} must be within range [{minimum}, {maximum}]") + raise ValueError(f"Min fee rate {min_rate} must be within range [{minimum}, {maximum}]") if self.is_contract: - receipt = self.preallocation_escrow_agent.set_min_reward_rate(min_rate=min_rate) + receipt = self.preallocation_escrow_agent.set_min_fee_rate(min_rate=min_rate) else: - receipt = self.policy_agent.set_min_reward_rate(staker_address=self.checksum_address, min_rate=min_rate) + receipt = self.policy_agent.set_min_fee_rate(staker_address=self.checksum_address, min_rate=min_rate) return receipt @property - def min_reward_rate(self) -> int: - """Minimum acceptable reward rate""" + def min_fee_rate(self) -> int: + """Minimum acceptable fee rate""" staker_address = self.checksum_address - min_rate = self.policy_agent.get_min_reward_rate(staker_address) - return min_rate + min_fee = self.policy_agent.get_min_fee_rate(staker_address) + return min_fee @property - def raw_min_reward_rate(self) -> int: - """Minimum acceptable reward rate set by staker. + def raw_min_fee_rate(self) -> int: + """Minimum acceptable fee rate set by staker. This's not applicable if this rate out of global range. - In that case default value will be used instead of raw value (see `min_reward_rate`)""" + In that case default value will be used instead of raw value (see `min_fee_rate`)""" staker_address = self.checksum_address - min_rate = self.policy_agent.get_raw_min_reward_rate(staker_address) - return min_rate + min_fee = self.policy_agent.get_raw_min_fee_rate(staker_address) + return min_fee class Worker(NucypherTokenActor): @@ -1385,7 +1385,7 @@ class BlockchainPolicyAuthor(NucypherTokenActor): @property def default_rate(self): - _minimum, default, _maximum = self.policy_agent.get_min_reward_rate_range() + _minimum, default, _maximum = self.policy_agent.get_min_fee_rate_range() return default def generate_policy_parameters(self, diff --git a/nucypher/blockchain/eth/agents.py b/nucypher/blockchain/eth/agents.py index 25d5690bc..3cdc575a4 100644 --- a/nucypher/blockchain/eth/agents.py +++ b/nucypher/blockchain/eth/agents.py @@ -785,8 +785,8 @@ class PolicyManagerAgent(EthereumContractAgent): return receipt @validate_checksum_address - def collect_policy_reward(self, collector_address: str, staker_address: str): - """Collect rewarded ETH""" + def collect_policy_fee(self, collector_address: str, staker_address: str): + """Collect fee ETH""" contract_function = self.contract.functions.withdraw(collector_address) receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=staker_address) return receipt @@ -816,27 +816,27 @@ class PolicyManagerAgent(EthereumContractAgent): return receipt @validate_checksum_address - def get_reward_amount(self, staker_address: str) -> int: - reward_amount = self.contract.functions.nodes(staker_address).call()[0] - return reward_amount + def get_fee_amount(self, staker_address: str) -> int: + fee_amount = self.contract.functions.nodes(staker_address).call()[0] + return fee_amount - def get_min_reward_rate_range(self) -> Tuple[int, int, int]: - minimum, default, maximum = self.contract.functions.minRewardRateRange().call() + def get_min_fee_rate_range(self) -> Tuple[int, int, int]: + minimum, default, maximum = self.contract.functions.minFeeRateRange().call() return minimum, default, maximum @validate_checksum_address - def get_min_reward_rate(self, staker_address: str) -> int: - min_rate = self.contract.functions.getMinRewardRate(staker_address).call() + def get_min_fee_rate(self, staker_address: str) -> int: + min_rate = self.contract.functions.getMinFeeRate(staker_address).call() return min_rate @validate_checksum_address - def get_raw_min_reward_rate(self, staker_address: str) -> int: + def get_raw_min_fee_rate(self, staker_address: str) -> int: min_rate = self.contract.functions.nodes(staker_address).call()[3] return min_rate @validate_checksum_address - def set_min_reward_rate(self, staker_address: str, min_rate: int): - contract_function = self.contract.functions.setMinRewardRate(min_rate) + def set_min_fee_rate(self, staker_address: str, min_rate: int): + contract_function = self.contract.functions.setMinFeeRate(min_rate) receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=staker_address) return receipt @@ -994,13 +994,13 @@ class PreallocationEscrowAgent(EthereumContractAgent): receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=self.__beneficiary) return receipt - def collect_policy_reward(self): - contract_function = self.__interface_agent.functions.withdrawPolicyReward() + def collect_policy_fee(self): + contract_function = self.__interface_agent.functions.withdrawPolicyFee() receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=self.__beneficiary) return receipt - def set_min_reward_rate(self, min_rate: int): - contract_function = self.__interface_agent.functions.setMinRewardRate(min_rate) + def set_min_fee_rate(self, min_rate: int): + contract_function = self.__interface_agent.functions.setMinFeeRate(min_rate) receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=self.__beneficiary) return receipt diff --git a/nucypher/blockchain/eth/deployers.py b/nucypher/blockchain/eth/deployers.py index 5b5b28a8f..6bd520a1f 100644 --- a/nucypher/blockchain/eth/deployers.py +++ b/nucypher/blockchain/eth/deployers.py @@ -805,12 +805,12 @@ class PolicyManagerDeployer(BaseContractDeployer, UpgradeableContractMixin, Owna self._contract = wrapped_contract return deployment_receipts - def set_min_reward_rate_range(self, - minimum: int, - default: int, - maximum: int, - gas_limit: int = None, - confirmations: int = 0) -> dict: + def set_min_fee_rate_range(self, + minimum: int, + default: int, + maximum: int, + gas_limit: int = None, + confirmations: int = 0) -> dict: if minimum > default or default > maximum: raise ValueError(f"Default rate ({default}) must satisfy the condition: " @@ -823,7 +823,7 @@ class PolicyManagerDeployer(BaseContractDeployer, UpgradeableContractMixin, Owna tx_args = {} if gas_limit: tx_args.update({'gas': gas_limit}) # TODO: Gas management - 842 - set_range_function = policy_manager.functions.setMinRewardRateRange(minimum, default, maximum) + set_range_function = policy_manager.functions.setMinFeeRateRange(minimum, default, maximum) set_range_receipt = self.blockchain.send_transaction(contract_function=set_range_function, sender_address=self.deployer_address, payload=tx_args, diff --git a/nucypher/blockchain/eth/sol/source/contracts/PolicyManager.sol b/nucypher/blockchain/eth/sol/source/contracts/PolicyManager.sol index f7e1fbb09..190c52fd7 100644 --- a/nucypher/blockchain/eth/sol/source/contracts/PolicyManager.sol +++ b/nucypher/blockchain/eth/sol/source/contracts/PolicyManager.sol @@ -14,7 +14,7 @@ import "contracts/proxy/Upgradeable.sol"; /** * @notice Contract holds policy data and locks fees -* @dev |v4.1.1| +* @dev |v5.1.1| */ contract PolicyManager is Upgradeable { using SafeERC20 for NuCypherToken; @@ -28,7 +28,7 @@ contract PolicyManager is Upgradeable { bytes16 indexed policyId, address indexed sponsor, address indexed owner, - uint256 rewardRate, + uint256 feeRate, uint64 startTimestamp, uint64 endTimestamp, uint256 numberOfNodes @@ -48,10 +48,10 @@ contract PolicyManager is Upgradeable { event PolicyRevoked(bytes16 indexed policyId, address indexed sender, uint256 value); event RefundForPolicy(bytes16 indexed policyId, address indexed sender, uint256 value); event NodeBrokenState(address indexed node, uint16 period); - event MinRewardRateSet(address indexed node, uint256 value); + event MinFeeRateSet(address indexed node, uint256 value); // TODO #1501 // Range range - event MinRewardRateRangeSet(address indexed sender, uint256 min, uint256 defaultValue, uint256 max); + event MinFeeRateRangeSet(address indexed sender, uint256 min, uint256 defaultValue, uint256 max); event Withdrawn(address indexed node, address indexed recipient, uint256 value); struct ArrangementInfo { @@ -65,7 +65,7 @@ contract PolicyManager is Upgradeable { address payable sponsor; address owner; - uint128 rewardRate; + uint128 feeRate; uint64 startTimestamp; uint64 endTimestamp; @@ -79,11 +79,11 @@ contract PolicyManager is Upgradeable { } struct NodeInfo { - uint128 reward; + uint128 fee; uint16 lastMinedPeriod; - uint256 rewardRate; - uint256 minRewardRate; - mapping (uint16 => int256) rewardDelta; + uint256 feeRate; + uint256 minFeeRate; + mapping (uint16 => int256) feeDelta; } struct Range { @@ -96,14 +96,14 @@ contract PolicyManager is Upgradeable { address internal constant RESERVED_NODE = address(0); uint256 internal constant MAX_BALANCE = uint256(uint128(0) - 1); // controlled overflow to get max int256 - int256 public constant DEFAULT_REWARD_DELTA = int256((uint256(0) - 1) >> 1); + int256 public constant DEFAULT_FEE_DELTA = int256((uint256(0) - 1) >> 1); StakingEscrow public immutable escrow; uint32 public immutable secondsPerPeriod; mapping (bytes16 => Policy) public policies; mapping (address => NodeInfo) public nodes; - Range public minRewardRateRange; + Range public minFeeRateRange; /** * @notice Constructor sets address of the escrow contract @@ -145,52 +145,52 @@ contract PolicyManager is Upgradeable { } /** - * @notice Set range for the minimum reward rate for all nodes + * @notice Set range for the minimum fee rate for all nodes */ // TODO # 1501 - // function setMinRewardRateRange(Range calldata _range) external onlyOwner { - function setMinRewardRateRange(uint128 _min, uint128 _default, uint128 _max) external onlyOwner { + // function setMinFeeRateRange(Range calldata _range) external onlyOwner { + function setMinFeeRateRange(uint128 _min, uint128 _default, uint128 _max) external onlyOwner { require(_min <= _default && _default <= _max); - minRewardRateRange = Range(_min, _default, _max); - emit MinRewardRateRangeSet(msg.sender, _min, _default, _max); + minFeeRateRange = Range(_min, _default, _max); + emit MinFeeRateRangeSet(msg.sender, _min, _default, _max); } /** - * @notice Set the minimum reward acceptable by node - * @dev Input value must be within `minRewardRateRange` + * @notice Set the minimum fee acceptable by node + * @dev Input value must be within `minFeeRateRange` */ - function setMinRewardRate(uint256 _minRewardRate) external { - require(_minRewardRate >= minRewardRateRange.min && - _minRewardRate <= minRewardRateRange.max, - "The min reward rate must be within permitted range"); + function setMinFeeRate(uint256 _minFeeRate) external { + require(_minFeeRate >= minFeeRateRange.min && + _minFeeRate <= minFeeRateRange.max, + "The min fee rate must be within permitted range"); NodeInfo storage nodeInfo = nodes[msg.sender]; - if (nodeInfo.minRewardRate == _minRewardRate) { + if (nodeInfo.minFeeRate == _minFeeRate) { return; } - nodeInfo.minRewardRate = _minRewardRate; - emit MinRewardRateSet(msg.sender, _minRewardRate); + nodeInfo.minFeeRate = _minFeeRate; + emit MinFeeRateSet(msg.sender, _minFeeRate); } /** - * @notice Get the minimum reward rate acceptable by node + * @notice Get the minimum fee rate acceptable by node */ - function getMinRewardRate(NodeInfo storage _nodeInfo) internal view returns (uint256) { - // if minRewardRate has not been set or is outside the acceptable range - if (_nodeInfo.minRewardRate == 0 || - _nodeInfo.minRewardRate < minRewardRateRange.min || - _nodeInfo.minRewardRate > minRewardRateRange.max) { - return minRewardRateRange.defaultValue; + function getMinFeeRate(NodeInfo storage _nodeInfo) internal view returns (uint256) { + // if minFeeRate has not been set or is outside the acceptable range + if (_nodeInfo.minFeeRate == 0 || + _nodeInfo.minFeeRate < minFeeRateRange.min || + _nodeInfo.minFeeRate > minFeeRateRange.max) { + return minFeeRateRange.defaultValue; } else { - return _nodeInfo.minRewardRate; + return _nodeInfo.minFeeRate; } } /** - * @notice Get the minimum reward rate acceptable by node + * @notice Get the minimum fee rate acceptable by node */ - function getMinRewardRate(address _node) public view returns (uint256) { + function getMinFeeRate(address _node) public view returns (uint256) { NodeInfo storage nodeInfo = nodes[_node]; - return getMinRewardRate(nodeInfo); + return getMinFeeRate(nodeInfo); } /** @@ -212,7 +212,7 @@ contract PolicyManager is Upgradeable { Policy storage policy = policies[_policyId]; require( _policyId != RESERVED_POLICY_ID && - policy.rewardRate == 0 && + policy.feeRate == 0 && !policy.disabled && _endTimestamp > block.timestamp && msg.value > 0 @@ -225,8 +225,8 @@ contract PolicyManager is Upgradeable { policy.sponsor = msg.sender; policy.startTimestamp = uint64(block.timestamp); policy.endTimestamp = _endTimestamp; - policy.rewardRate = uint128(msg.value.div(_nodes.length) / numberOfPeriods); - require(policy.rewardRate > 0 && policy.rewardRate * numberOfPeriods * _nodes.length == msg.value); + policy.feeRate = uint128(msg.value.div(_nodes.length) / numberOfPeriods); + require(policy.feeRate > 0 && policy.feeRate * numberOfPeriods * _nodes.length == msg.value); if (_policyOwner != msg.sender && _policyOwner != address(0)) { policy.owner = _policyOwner; } @@ -237,25 +237,25 @@ contract PolicyManager is Upgradeable { NodeInfo storage nodeInfo = nodes[node]; require(nodeInfo.lastMinedPeriod != 0 && nodeInfo.lastMinedPeriod < currentPeriod && - policy.rewardRate >= getMinRewardRate(nodeInfo)); - // Check default value for rewardDelta - if (nodeInfo.rewardDelta[currentPeriod] == DEFAULT_REWARD_DELTA) { - nodeInfo.rewardDelta[currentPeriod] = int256(policy.rewardRate); + policy.feeRate >= getMinFeeRate(nodeInfo)); + // Check default value for feeDelta + if (nodeInfo.feeDelta[currentPeriod] == DEFAULT_FEE_DELTA) { + nodeInfo.feeDelta[currentPeriod] = int256(policy.feeRate); } else { // Overflow protection removed, because ETH total supply less than uint255/int256 - nodeInfo.rewardDelta[currentPeriod] += int256(policy.rewardRate); + nodeInfo.feeDelta[currentPeriod] += int256(policy.feeRate); } - if (nodeInfo.rewardDelta[endPeriod] == DEFAULT_REWARD_DELTA) { - nodeInfo.rewardDelta[endPeriod] = -int256(policy.rewardRate); + if (nodeInfo.feeDelta[endPeriod] == DEFAULT_FEE_DELTA) { + nodeInfo.feeDelta[endPeriod] = -int256(policy.feeRate); } else { - nodeInfo.rewardDelta[endPeriod] -= int256(policy.rewardRate); + nodeInfo.feeDelta[endPeriod] -= int256(policy.feeRate); } // Reset to default value if needed - if (nodeInfo.rewardDelta[currentPeriod] == 0) { - nodeInfo.rewardDelta[currentPeriod] = DEFAULT_REWARD_DELTA; + if (nodeInfo.feeDelta[currentPeriod] == 0) { + nodeInfo.feeDelta[currentPeriod] = DEFAULT_FEE_DELTA; } - if (nodeInfo.rewardDelta[endPeriod] == 0) { - nodeInfo.rewardDelta[endPeriod] = DEFAULT_REWARD_DELTA; + if (nodeInfo.feeDelta[endPeriod] == 0) { + nodeInfo.feeDelta[endPeriod] = DEFAULT_FEE_DELTA; } policy.arrangements.push(ArrangementInfo(node, 0, 0)); } @@ -264,7 +264,7 @@ contract PolicyManager is Upgradeable { _policyId, msg.sender, _policyOwner == address(0) ? msg.sender : _policyOwner, - policy.rewardRate, + policy.feeRate, policy.startTimestamp, policy.endTimestamp, _nodes.length @@ -280,71 +280,71 @@ contract PolicyManager is Upgradeable { } /** - * @notice Set default `rewardDelta` value for specified period + * @notice Set default `feeDelta` value for specified period * @dev This method increases gas cost for node in trade of decreasing cost for policy sponsor * @param _node Node address * @param _period Period to set */ - function setDefaultRewardDelta(address _node, uint16 _period) external onlyEscrowContract { + function setDefaultFeeDelta(address _node, uint16 _period) external onlyEscrowContract { NodeInfo storage node = nodes[_node]; - if (node.rewardDelta[_period] == 0) { - node.rewardDelta[_period] = DEFAULT_REWARD_DELTA; + if (node.feeDelta[_period] == 0) { + node.feeDelta[_period] = DEFAULT_FEE_DELTA; } } /** - * @notice Update node reward + * @notice Update node fee * @param _node Node address * @param _period Processed period */ - function updateReward(address _node, uint16 _period) external onlyEscrowContract { + function updateFee(address _node, uint16 _period) external onlyEscrowContract { NodeInfo storage node = nodes[_node]; if (node.lastMinedPeriod == 0 || _period <= node.lastMinedPeriod) { return; } for (uint16 i = node.lastMinedPeriod + 1; i <= _period; i++) { - int256 delta = node.rewardDelta[i]; - if (delta == DEFAULT_REWARD_DELTA) { + int256 delta = node.feeDelta[i]; + if (delta == DEFAULT_FEE_DELTA) { // gas refund - node.rewardDelta[i] = 0; + node.feeDelta[i] = 0; continue; } // broken state - if (delta < 0 && uint256(-delta) > node.rewardRate) { - node.rewardDelta[i] += int256(node.rewardRate); - node.rewardRate = 0; + if (delta < 0 && uint256(-delta) > node.feeRate) { + node.feeDelta[i] += int256(node.feeRate); + node.feeRate = 0; emit NodeBrokenState(_node, _period); // good state } else { - node.rewardRate = node.rewardRate.addSigned(delta); + node.feeRate = node.feeRate.addSigned(delta); // gas refund - node.rewardDelta[i] = 0; + node.feeDelta[i] = 0; } } node.lastMinedPeriod = _period; - node.reward += uint128(node.rewardRate); + node.fee += uint128(node.feeRate); } /** - * @notice Withdraw reward by node + * @notice Withdraw fee by node */ function withdraw() external returns (uint256) { return withdraw(msg.sender); } /** - * @notice Withdraw reward by node - * @param _recipient Recipient of the reward + * @notice Withdraw fee by node + * @param _recipient Recipient of the fee */ function withdraw(address payable _recipient) public returns (uint256) { NodeInfo storage node = nodes[msg.sender]; - uint256 reward = node.reward; - require(reward != 0); - node.reward = 0; - _recipient.sendValue(reward); - emit Withdrawn(msg.sender, _recipient, reward); - return reward; + uint256 fee = node.fee; + require(fee != 0); + node.fee = 0; + _recipient.sendValue(fee); + emit Withdrawn(msg.sender, _recipient, fee); + return fee; } /** @@ -392,7 +392,7 @@ contract PolicyManager is Upgradeable { downtimePeriods += maxPeriod - AdditionalMath.max16(minPeriod - 1, lastActivePeriod); } - refundValue = _policy.rewardRate * downtimePeriods; + refundValue = _policy.feeRate * downtimePeriods; lastRefundedPeriod = maxPeriod + 1; } @@ -424,27 +424,27 @@ contract PolicyManager is Upgradeable { if (_forceRevoke) { NodeInfo storage nodeInfo = nodes[node]; - // Check default value for rewardDelta + // Check default value for feeDelta uint16 lastRefundedPeriod = arrangement.lastRefundedPeriod; - if (nodeInfo.rewardDelta[lastRefundedPeriod] == DEFAULT_REWARD_DELTA) { - nodeInfo.rewardDelta[lastRefundedPeriod] = -int256(policy.rewardRate); + if (nodeInfo.feeDelta[lastRefundedPeriod] == DEFAULT_FEE_DELTA) { + nodeInfo.feeDelta[lastRefundedPeriod] = -int256(policy.feeRate); } else { - nodeInfo.rewardDelta[lastRefundedPeriod] -= int256(policy.rewardRate); + nodeInfo.feeDelta[lastRefundedPeriod] -= int256(policy.feeRate); } - if (nodeInfo.rewardDelta[endPeriod] == DEFAULT_REWARD_DELTA) { - nodeInfo.rewardDelta[endPeriod] = -int256(policy.rewardRate); + if (nodeInfo.feeDelta[endPeriod] == DEFAULT_FEE_DELTA) { + nodeInfo.feeDelta[endPeriod] = -int256(policy.feeRate); } else { - nodeInfo.rewardDelta[endPeriod] += int256(policy.rewardRate); + nodeInfo.feeDelta[endPeriod] += int256(policy.feeRate); } // Reset to default value if needed - if (nodeInfo.rewardDelta[lastRefundedPeriod] == 0) { - nodeInfo.rewardDelta[lastRefundedPeriod] = DEFAULT_REWARD_DELTA; + if (nodeInfo.feeDelta[lastRefundedPeriod] == 0) { + nodeInfo.feeDelta[lastRefundedPeriod] = DEFAULT_FEE_DELTA; } - if (nodeInfo.rewardDelta[endPeriod] == 0) { - nodeInfo.rewardDelta[endPeriod] = DEFAULT_REWARD_DELTA; + if (nodeInfo.feeDelta[endPeriod] == 0) { + nodeInfo.feeDelta[endPeriod] = DEFAULT_FEE_DELTA; } - nodeRefundValue += uint256(endPeriod - lastRefundedPeriod) * policy.rewardRate; + nodeRefundValue += uint256(endPeriod - lastRefundedPeriod) * policy.feeRate; } if (_forceRevoke || arrangement.lastRefundedPeriod >= endPeriod) { arrangement.node = RESERVED_NODE; @@ -468,7 +468,7 @@ contract PolicyManager is Upgradeable { // gas refund policy.sponsor = address(0); policy.owner = address(0); - policy.rewardRate = 0; + policy.feeRate = 0; policy.startTimestamp = 0; policy.endTimestamp = 0; emit PolicyRevoked(_policyId, msg.sender, refundValue); @@ -625,15 +625,15 @@ contract PolicyManager is Upgradeable { } /** - * @notice Get information about node reward + * @notice Get information about node fee * @param _node Address of node - * @param _period Period to get reward delta + * @param _period Period to get fee delta */ - function getNodeRewardDelta(address _node, uint16 _period) + function getNodeFeeDelta(address _node, uint16 _period) // TODO "virtual" only for tests, probably will be removed after #1512 external view virtual returns (int256) { - return nodes[_node].rewardDelta[_period]; + return nodes[_node].feeDelta[_period]; } /** @@ -689,10 +689,10 @@ contract PolicyManager is Upgradeable { } /** - * @dev Get minRewardRateRange structure by delegatecall + * @dev Get minFeeRateRange structure by delegatecall */ - function delegateGetMinRewardRateRange(address _target) internal returns (Range memory result) { - bytes32 memoryAddress = delegateGetData(_target, this.minRewardRateRange.selector, 0, 0, 0); + function delegateGetMinFeeRateRange(address _target) internal returns (Range memory result) { + bytes32 memoryAddress = delegateGetData(_target, this.minFeeRateRange.selector, 0, 0, 0); assembly { result := memoryAddress } @@ -701,15 +701,15 @@ contract PolicyManager is Upgradeable { /// @dev the `onlyWhileUpgrading` modifier works through a call to the parent `verifyState` function verifyState(address _testTarget) public override virtual { super.verifyState(_testTarget); - Range memory rangeToCheck = delegateGetMinRewardRateRange(_testTarget); - require(minRewardRateRange.min == rangeToCheck.min && - minRewardRateRange.defaultValue == rangeToCheck.defaultValue && - minRewardRateRange.max == rangeToCheck.max); + Range memory rangeToCheck = delegateGetMinFeeRateRange(_testTarget); + require(minFeeRateRange.min == rangeToCheck.min && + minFeeRateRange.defaultValue == rangeToCheck.defaultValue && + minFeeRateRange.max == rangeToCheck.max); Policy storage policy = policies[RESERVED_POLICY_ID]; Policy memory policyToCheck = delegateGetPolicy(_testTarget, RESERVED_POLICY_ID); require(policyToCheck.sponsor == policy.sponsor && policyToCheck.owner == policy.owner && - policyToCheck.rewardRate == policy.rewardRate && + policyToCheck.feeRate == policy.feeRate && policyToCheck.startTimestamp == policy.startTimestamp && policyToCheck.endTimestamp == policy.endTimestamp && policyToCheck.disabled == policy.disabled); @@ -727,13 +727,13 @@ contract PolicyManager is Upgradeable { NodeInfo storage nodeInfo = nodes[RESERVED_NODE]; NodeInfo memory nodeInfoToCheck = delegateGetNodeInfo(_testTarget, RESERVED_NODE); - require(nodeInfoToCheck.reward == nodeInfo.reward && - nodeInfoToCheck.rewardRate == nodeInfo.rewardRate && + require(nodeInfoToCheck.fee == nodeInfo.fee && + nodeInfoToCheck.feeRate == nodeInfo.feeRate && nodeInfoToCheck.lastMinedPeriod == nodeInfo.lastMinedPeriod && - nodeInfoToCheck.minRewardRate == nodeInfo.minRewardRate); + nodeInfoToCheck.minFeeRate == nodeInfo.minFeeRate); - require(int256(delegateGet(_testTarget, this.getNodeRewardDelta.selector, - bytes32(bytes20(RESERVED_NODE)), bytes32(uint256(11)))) == nodeInfo.rewardDelta[11]); + require(int256(delegateGet(_testTarget, this.getNodeFeeDelta.selector, + bytes32(bytes20(RESERVED_NODE)), bytes32(uint256(11)))) == nodeInfo.feeDelta[11]); } /// @dev the `onlyWhileUpgrading` modifier works through a call to the parent `finishUpgrade` @@ -745,14 +745,14 @@ contract PolicyManager is Upgradeable { policy.owner = address(this); policy.startTimestamp = 1; policy.endTimestamp = 2; - policy.rewardRate = 3; + policy.feeRate = 3; policy.disabled = true; policy.arrangements.push(ArrangementInfo(RESERVED_NODE, 11, 22)); NodeInfo storage nodeInfo = nodes[RESERVED_NODE]; - nodeInfo.reward = 100; - nodeInfo.rewardRate = 33; + nodeInfo.fee = 100; + nodeInfo.feeRate = 33; nodeInfo.lastMinedPeriod = 44; - nodeInfo.rewardDelta[11] = 55; - nodeInfo.minRewardRate = 777; + nodeInfo.feeDelta[11] = 55; + nodeInfo.minFeeRate = 777; } } diff --git a/nucypher/blockchain/eth/sol/source/contracts/StakingEscrow.sol b/nucypher/blockchain/eth/sol/source/contracts/StakingEscrow.sol index aa39494bd..26c2f4175 100644 --- a/nucypher/blockchain/eth/sol/source/contracts/StakingEscrow.sol +++ b/nucypher/blockchain/eth/sol/source/contracts/StakingEscrow.sol @@ -12,9 +12,9 @@ import "zeppelin/math/SafeMath.sol"; */ interface PolicyManagerInterface { function register(address _node, uint16 _period) external; - function updateReward(address _node, uint16 _period) external; + function updateFee(address _node, uint16 _period) external; function escrow() external view returns (address); - function setDefaultRewardDelta(address _node, uint16 _period) external; + function setDefaultFeeDelta(address _node, uint16 _period) external; } @@ -37,7 +37,7 @@ interface WorkLockInterface { /** * @notice Contract holds and locks stakers tokens. * Each staker that locks their tokens will receive some compensation -* @dev |v4.2.1| +* @dev |v4.2.2| */ contract StakingEscrow is Issuer, IERC900History { @@ -947,7 +947,7 @@ contract StakingEscrow is Issuer, IERC900History { if (lastActivePeriod < currentPeriod) { info.pastDowntime.push(Downtime(lastActivePeriod + 1, currentPeriod)); } - policyManager.setDefaultRewardDelta(staker, nextPeriod); + policyManager.setDefaultFeeDelta(staker, nextPeriod); emit ActivityConfirmed(staker, nextPeriod, lockedTokens); } @@ -1059,7 +1059,7 @@ contract StakingEscrow is Issuer, IERC900History { } } } - policyManager.updateReward(_staker, _mintingPeriod); + policyManager.updateFee(_staker, _mintingPeriod); return reward; } diff --git a/nucypher/blockchain/eth/sol/source/contracts/staking_contracts/StakingInterface.sol b/nucypher/blockchain/eth/sol/source/contracts/staking_contracts/StakingInterface.sol index 05cebf4f6..794bd1a59 100644 --- a/nucypher/blockchain/eth/sol/source/contracts/staking_contracts/StakingInterface.sol +++ b/nucypher/blockchain/eth/sol/source/contracts/staking_contracts/StakingInterface.sol @@ -79,8 +79,8 @@ contract StakingInterface is BaseStakingInterface { event Locked(address indexed sender, uint256 value, uint16 periods); event Divided(address indexed sender, uint256 index, uint256 newValue, uint16 periods); event Mined(address indexed sender); - event PolicyRewardWithdrawn(address indexed sender, uint256 value); - event MinRewardRateSet(address indexed sender, uint256 value); + event PolicyFeeWithdrawn(address indexed sender, uint256 value); + event MinFeeRateSet(address indexed sender, uint256 value); event ReStakeSet(address indexed sender, bool reStake); event ReStakeLocked(address indexed sender, uint16 lockUntilPeriod); event WorkerSet(address indexed sender, address worker); @@ -193,19 +193,19 @@ contract StakingInterface is BaseStakingInterface { } /** - * @notice Withdraw available reward from the policy manager to the staking contract + * @notice Withdraw available fee from the policy manager to the staking contract */ - function withdrawPolicyReward() public onlyDelegateCall { + function withdrawPolicyFee() public onlyDelegateCall { uint256 value = policyManager.withdraw(); - emit PolicyRewardWithdrawn(msg.sender, value); + emit PolicyFeeWithdrawn(msg.sender, value); } /** - * @notice Set the minimum reward that the staker will take in the policy manager + * @notice Set the minimum fee that the staker will take in the policy manager */ - function setMinRewardRate(uint256 _minRewardRate) public onlyDelegateCall { - policyManager.setMinRewardRate(_minRewardRate); - emit MinRewardRateSet(msg.sender, _minRewardRate); + function setMinFeeRate(uint256 _minFeeRate) public onlyDelegateCall { + policyManager.setMinFeeRate(_minFeeRate); + emit MinFeeRateSet(msg.sender, _minFeeRate); } diff --git a/nucypher/cli/actions.py b/nucypher/cli/actions.py index 7d486cf30..e5c8f2772 100644 --- a/nucypher/cli/actions.py +++ b/nucypher/cli/actions.py @@ -295,7 +295,7 @@ Failure to keep your node online, or violation of re-encryption work orders will result in the loss of staked tokens as described in the NuCypher slashing protocol. Keeping your Ursula node online during the staking period and successfully -producing correct re-encryption work orders will result in rewards +producing correct re-encryption work orders will result in fees paid out in ethers retro-actively and on-demand. Accept ursula node operator obligation?""", abort=True) diff --git a/nucypher/cli/commands/deploy.py b/nucypher/cli/commands/deploy.py index bcb1422fd..5530fc155 100644 --- a/nucypher/cli/commands/deploy.py +++ b/nucypher/cli/commands/deploy.py @@ -594,7 +594,7 @@ def transfer_ownership(general_config, actor_options, target_address, gas): @click.option('--maximum', help="Maximum value for range (in wei)", type=WEI) def set_range(general_config, actor_options, minimum, default, maximum): """ - Set the allowed range for the minimum reward rate in the policy manager contract. + Set the allowed range for the minimum fee rate in the policy manager contract. """ emitter = general_config.emitter ADMINISTRATOR, _, _, _ = actor_options.create_actor(emitter) @@ -606,6 +606,6 @@ def set_range(general_config, actor_options, minimum, default, maximum): if not maximum: maximum = click.prompt("Enter new maximum value for range", type=click.IntRange(min=default)) - ADMINISTRATOR.set_min_reward_rate_range(minimum=minimum, default=default, maximum=maximum) - emitter.echo(f"The minimum reward rate was limited to the range [{minimum}, {maximum}] " + ADMINISTRATOR.set_min_fee_rate_range(minimum=minimum, default=default, maximum=maximum) + emitter.echo(f"The minimum fee rate was limited to the range [{minimum}, {maximum}] " f"with the default value {default}") diff --git a/nucypher/cli/commands/multisig.py b/nucypher/cli/commands/multisig.py index 6d33812a0..7b0b709dc 100644 --- a/nucypher/cli/commands/multisig.py +++ b/nucypher/cli/commands/multisig.py @@ -234,7 +234,7 @@ def propose(general_config, blockchain_options, multisig_options): # - Transfer ownership of contract # - Send ETH from MultiSig # - Send tokens from MultiSig - # - Change min reward rate range in PolicyManager + # - Change min fee rate range in PolicyManager # - Send raw transaction # Init diff --git a/nucypher/cli/commands/stake.py b/nucypher/cli/commands/stake.py index 192470b9b..49719ca80 100644 --- a/nucypher/cli/commands/stake.py +++ b/nucypher/cli/commands/stake.py @@ -773,12 +773,12 @@ def prolong(general_config, transacting_staker_options, config_file, force, lock @group_transacting_staker_options @option_config_file @click.option('--staking-reward/--no-staking-reward', is_flag=True, default=False) -@click.option('--policy-reward/--no-policy-reward', is_flag=True, default=False) -@click.option('--withdraw-address', help="Send reward collection to an alternate address", type=EIP55_CHECKSUM_ADDRESS) +@click.option('--policy-fee/--no-policy-fee', is_flag=True, default=False) +@click.option('--withdraw-address', help="Send fee collection to an alternate address", type=EIP55_CHECKSUM_ADDRESS) @option_force @group_general_config def collect_reward(general_config, transacting_staker_options, config_file, - staking_reward, policy_reward, withdraw_address, force): + staking_reward, policy_fee, withdraw_address, force): """ Withdraw staking reward. """ @@ -789,8 +789,8 @@ def collect_reward(general_config, transacting_staker_options, config_file, STAKEHOLDER = transacting_staker_options.create_character(emitter, config_file) blockchain = transacting_staker_options.get_blockchain() - if not staking_reward and not policy_reward: - raise click.BadArgumentUsage(f"Either --staking-reward or --policy-reward must be True to collect rewards.") + if not staking_reward and not policy_fee: + raise click.BadArgumentUsage(f"Either --staking-reward or --policy-fee must be True to collect rewards.") client_account, staking_address = handle_client_account_for_staking( emitter=emitter, @@ -811,10 +811,10 @@ def collect_reward(general_config, transacting_staker_options, config_file, chain_name=STAKEHOLDER.wallet.blockchain.client.chain_name, emitter=emitter) - if policy_reward: - reward_amount = Web3.fromWei(STAKEHOLDER.calculate_policy_reward(), 'ether') - emitter.echo(message=f'Collecting {reward_amount} ETH from policy rewards...') - policy_receipt = STAKEHOLDER.collect_policy_reward(collector_address=withdraw_address) + if policy_fee: + fee_amount = Web3.fromWei(STAKEHOLDER.calculate_policy_fee(), 'ether') + emitter.echo(message=f'Collecting {fee_amount} ETH from policy fees...') + policy_receipt = STAKEHOLDER.collect_policy_fee(collector_address=withdraw_address) paint_receipt_summary(receipt=policy_receipt, chain_name=STAKEHOLDER.wallet.blockchain.client.chain_name, emitter=emitter) @@ -916,10 +916,10 @@ def events(general_config, staker_options, config_file, event_name): @option_config_file @option_force @group_general_config -@click.option('--min-rate', help="Minimum acceptable reward rate", type=WEI) +@click.option('--min-rate', help="Minimum acceptable fee rate", type=WEI) def set_min_rate(general_config, transacting_staker_options, config_file, force, min_rate): """ - Set minimum acceptable value for the reward rate. + Set minimum acceptable value for the fee rate. """ emitter = _setup_emitter(general_config) @@ -936,19 +936,19 @@ def set_min_rate(general_config, transacting_staker_options, config_file, force, if not min_rate: painting.paint_min_rate(emitter, STAKEHOLDER.registry, STAKEHOLDER.policy_agent, staking_address) # TODO check range - min_rate = click.prompt("Enter new value for min reward rate within range", type=WEI) + min_rate = click.prompt("Enter new value for min fee rate within range", type=WEI) password = transacting_staker_options.get_password(blockchain, client_account) if not force: click.confirm(f"Commit new value {min_rate} for " - f"minimum acceptable reward rate?", abort=True) + f"minimum acceptable fee rate?", abort=True) STAKEHOLDER.assimilate(checksum_address=client_account, password=password) - receipt = STAKEHOLDER.set_min_reward_rate(min_rate=min_rate) + receipt = STAKEHOLDER.set_min_fee_rate(min_rate=min_rate) # Report Success - emitter.echo(f"\nMinimum reward rate {min_rate} successfully set by staker {staking_address}", color='green') + emitter.echo(f"\nMinimum fee rate {min_rate} successfully set by staker {staking_address}", color='green') paint_receipt_summary(emitter=emitter, receipt=receipt, chain_name=blockchain.client.chain_name, diff --git a/nucypher/cli/commands/status.py b/nucypher/cli/commands/status.py index 54ffc84eb..b5906151a 100644 --- a/nucypher/cli/commands/status.py +++ b/nucypher/cli/commands/status.py @@ -47,7 +47,7 @@ from nucypher.cli.painting import ( paint_contract_status, paint_stakers, paint_locked_tokens_status, - paint_min_reward_range + paint_min_fee_range ) from nucypher.config.constants import NUCYPHER_ENVVAR_PROVIDER_URI @@ -178,11 +178,11 @@ def events(general_config, registry_options, contract_name, from_block, to_block emitter.echo(f" - {event_record}") -@status.command(name='reward-range') +@status.command(name='fee-range') @group_registry_options @group_general_config -def reward_range(general_config, registry_options): - """Show information about the allowed range for min reward rate.""" +def fee_range(general_config, registry_options): + """Show information about the allowed range for min fee rate.""" emitter, registry, blockchain = registry_options.setup(general_config=general_config) policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=registry) - paint_min_reward_range(emitter=emitter, policy_agent=policy_agent) + paint_min_fee_range(emitter=emitter, policy_agent=policy_agent) diff --git a/nucypher/cli/painting.py b/nucypher/cli/painting.py index c1d4bac23..33463b788 100644 --- a/nucypher/cli/painting.py +++ b/nucypher/cli/painting.py @@ -348,7 +348,7 @@ Registry ................ {registry.filepath} try: policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=registry) - paint_min_reward_range(emitter, policy_agent) + paint_min_fee_range(emitter, policy_agent) emitter.echo(sep, nl=False) except BaseContractRegistry.UnknownContract: @@ -357,11 +357,11 @@ Registry ................ {registry.filepath} emitter.echo(sep, nl=False) -def paint_min_reward_range(emitter, policy_agent): - minimum, default, maximum = policy_agent.get_min_reward_rate_range() +def paint_min_fee_range(emitter, policy_agent): + minimum, default, maximum = policy_agent.get_min_fee_rate_range() range_payload = f""" -Range of the minimum reward rate: +Range of the minimum fee rate: ~ Minimum ............ {prettify_eth_amount(minimum)} ~ Default ............ {prettify_eth_amount(default)} ~ Maximum ............ {prettify_eth_amount(maximum)}""" @@ -369,12 +369,12 @@ Range of the minimum reward rate: def paint_min_rate(emitter, registry, policy_agent, staker_address): - paint_min_reward_range(emitter, policy_agent) - minimum = policy_agent.min_reward_rate(staker_address) - raw_minimum = policy_agent.raw_min_reward_rate(staker_address) + paint_min_fee_range(emitter, policy_agent) + minimum = policy_agent.min_fee_rate(staker_address) + raw_minimum = policy_agent.raw_min_fee_rate(staker_address) rate_payload = f""" -Minimum reward rate: +Minimum fee rate: ~ Previously set ....... {prettify_eth_amount(raw_minimum)} ~ Effective ............ {prettify_eth_amount(minimum)}""" emitter.echo(rate_payload) @@ -491,7 +491,7 @@ See https://docs.nucypher.com/en/latest/guides/staking_guide.html''' def paint_stakes(emitter, stakeholder, paint_inactive: bool = False, staker_address: str = None): headers = ('Idx', 'Value', 'Remaining', 'Enactment', 'Termination') - staker_headers = ('Status', 'Restaking', 'Winding Down', 'Unclaimed Fees', 'Min reward rate') + staker_headers = ('Status', 'Restaking', 'Winding Down', 'Unclaimed Fees', 'Min fee rate') stakers = stakeholder.get_stakers() if not stakers: @@ -513,11 +513,11 @@ def paint_stakes(emitter, stakeholder, paint_inactive: bool = False, staker_addr if not active_stakes: emitter.echo(f"There are no active stakes\n") - fees = staker.policy_agent.get_reward_amount(staker.checksum_address) + fees = staker.policy_agent.get_fee_amount(staker.checksum_address) pretty_fees = prettify_eth_amount(fees) last_confirmed = staker.staking_agent.get_last_active_period(staker.checksum_address) missing = staker.missing_confirmations - min_reward_rate = prettify_eth_amount(staker.min_reward_rate) + min_fee_rate = prettify_eth_amount(staker.min_fee_rate) if missing == -1: missing_info = "Never Confirmed (New Stake)" @@ -528,7 +528,7 @@ def paint_stakes(emitter, stakeholder, paint_inactive: bool = False, staker_addr f'{"Yes" if staker.is_restaking else "No"} ({"Locked" if staker.restaking_lock_enabled else "Unlocked"})', "Yes" if bool(staker.is_winding_down) else "No", pretty_fees, - min_reward_rate] + min_fee_rate] line_width = 54 if staker.registry.source: # TODO: #1580 - Registry source might be Falsy in tests. @@ -744,11 +744,11 @@ def paint_stakers(emitter, stakers: List[str], staking_agent, policy_agent) -> N else: emitter.echo(f"{worker}") - fees = prettify_eth_amount(policy_agent.get_reward_amount(staker)) + fees = prettify_eth_amount(policy_agent.get_fee_amount(staker)) emitter.echo(f"{tab} Unclaimed fees: {fees}") - min_rate = prettify_eth_amount(policy_agent.get_min_reward_rate(staker)) - emitter.echo(f"{tab} Min reward rate: {min_rate}") + min_rate = prettify_eth_amount(policy_agent.get_min_fee_rate(staker)) + emitter.echo(f"{tab} Min fee rate: {min_rate}") def paint_preallocation_status(emitter, preallocation_agent, token_agent) -> None: @@ -978,7 +978,7 @@ def paint_bidding_notice(emitter, bidder): in the NuCypher slashing protocol. - Keeping your Ursula node online during the staking period and correctly servicing - re-encryption work orders will result in rewards paid out in ethers retro-actively + re-encryption work orders will result in fees paid out in ethers retro-actively and on-demand. Accept WorkLock terms and node operator obligation?""" # TODO: Show a special message for first bidder, since there's no refund rate yet? diff --git a/nucypher/config/characters.py b/nucypher/config/characters.py index 7e37d962f..4047c75f4 100644 --- a/nucypher/config/characters.py +++ b/nucypher/config/characters.py @@ -151,7 +151,6 @@ class AliceConfiguration(CharacterConfiguration): # TODO: Best (Sane) Defaults DEFAULT_M = 2 DEFAULT_N = 3 - DEFAULT_FIRST_PERIOD_REWARD = 0 # TODO #1063 def __init__(self, m: int = None, diff --git a/nucypher/policy/policies.py b/nucypher/policy/policies.py index 9b39a4d4f..23e3585ae 100644 --- a/nucypher/policy/policies.py +++ b/nucypher/policy/policies.py @@ -533,9 +533,9 @@ class BlockchainPolicy(Policy): super().__init__(alice=alice, expiration=expiration, *args, **kwargs) self.selection_buffer = 1.5 - self.validate_reward_value() + self.validate_fee_value() - def validate_reward_value(self) -> None: + def validate_fee_value(self) -> None: rate_per_period = self.value // self.n // self.duration_periods # wei recalculated_value = self.duration_periods * rate_per_period * self.n if recalculated_value != self.value: diff --git a/tests/blockchain/eth/contracts/contracts/PolicyManagerTestSet.sol b/tests/blockchain/eth/contracts/contracts/PolicyManagerTestSet.sol index c6d2a143a..47dbf884a 100644 --- a/tests/blockchain/eth/contracts/contracts/PolicyManagerTestSet.sol +++ b/tests/blockchain/eth/contracts/contracts/PolicyManagerTestSet.sol @@ -13,7 +13,7 @@ contract PolicyManagerBad is PolicyManager { constructor(StakingEscrow _escrow) public PolicyManager(_escrow) { } - function getNodeRewardDelta(address, uint16) public view override returns (int256) {} + function getNodeFeeDelta(address, uint16) public view override returns (int256) {} } @@ -91,7 +91,7 @@ contract StakingEscrowForPolicyMock { */ function mint(address _staker, uint16 _startPeriod, uint16 _numberOfPeriods) public { for (uint16 i = 0; i < _numberOfPeriods; i++) { - policyManager.updateReward(_staker, i + _startPeriod); + policyManager.updateFee(_staker, i + _startPeriod); } } @@ -143,9 +143,9 @@ contract StakingEscrowForPolicyMock { } } - function setDefaultRewardDelta(address _node, uint16 _startPeriod, uint16 _numberOfPeriods) public { + function setDefaultFeeDelta(address _node, uint16 _startPeriod, uint16 _numberOfPeriods) public { for (uint16 i = 0; i < _numberOfPeriods; i++) { - policyManager.setDefaultRewardDelta(_node, i + _startPeriod); + policyManager.setDefaultFeeDelta(_node, i + _startPeriod); } } @@ -160,8 +160,8 @@ contract ExtendedPolicyManager is PolicyManager { constructor(StakingEscrow _escrow) public PolicyManager(_escrow) { } - function setNodeRewardDelta(address _node, uint16 _period, int256 _value) external { + function setNodeFeeDelta(address _node, uint16 _period, int256 _value) external { NodeInfo storage node = nodes[_node]; - node.rewardDelta[_period] = _value; + node.feeDelta[_period] = _value; } } diff --git a/tests/blockchain/eth/contracts/contracts/StakingContractsTestSet.sol b/tests/blockchain/eth/contracts/contracts/StakingContractsTestSet.sol index 2eff7efde..375e55cb7 100644 --- a/tests/blockchain/eth/contracts/contracts/StakingContractsTestSet.sol +++ b/tests/blockchain/eth/contracts/contracts/StakingContractsTestSet.sol @@ -95,7 +95,7 @@ contract StakingEscrowForStakingContractMock { contract PolicyManagerForStakingContractMock { uint32 public immutable secondsPerPeriod = 1; - uint256 public minRewardRate; + uint256 public minFeeRate; function withdraw() public returns (uint256) { uint256 value = address(this).balance; @@ -104,12 +104,12 @@ contract PolicyManagerForStakingContractMock { return value; } - function setMinRewardRate(uint256 _minRewardRate) public { - minRewardRate = _minRewardRate; + function setMinFeeRate(uint256 _minFeeRate) public { + minFeeRate = _minFeeRate; } - function additionalMethod(uint256 _minRewardRate) public { - minRewardRate = _minRewardRate; + function additionalMethod(uint256 _minFeeRate) public { + minFeeRate = _minFeeRate; } // TODO #1809 diff --git a/tests/blockchain/eth/contracts/contracts/StakingEscrowTestSet.sol b/tests/blockchain/eth/contracts/contracts/StakingEscrowTestSet.sol index 0a7953b55..cb8326367 100644 --- a/tests/blockchain/eth/contracts/contracts/StakingEscrowTestSet.sol +++ b/tests/blockchain/eth/contracts/contracts/StakingEscrowTestSet.sol @@ -125,11 +125,11 @@ contract PolicyManagerForStakingEscrowMock { nodes[_node].push(_period); } - function updateReward(address _node, uint16 _period) external { + function updateFee(address _node, uint16 _period) external { nodes[_node].push(_period); } - function setDefaultRewardDelta(address _node, uint16 _period) external { + function setDefaultFeeDelta(address _node, uint16 _period) external { nodes[_node].push(_period); } diff --git a/tests/blockchain/eth/contracts/integration/test_intercontract_integration.py b/tests/blockchain/eth/contracts/integration/test_intercontract_integration.py index 908d1981d..24982dd0b 100644 --- a/tests/blockchain/eth/contracts/integration/test_intercontract_integration.py +++ b/tests/blockchain/eth/contracts/integration/test_intercontract_integration.py @@ -876,7 +876,7 @@ def test_policy(testerchain, tx = escrow.functions.confirmActivity().transact({'from': staker1}) testerchain.wait_for_receipt(tx) - # Withdraw reward and refund + # Withdraw fee and refund testerchain.time_travel(hours=3) staker1_balance = testerchain.client.get_balance(staker1) tx = policy_manager.functions.withdraw().transact({'from': staker1, 'gas_price': 0}) @@ -887,7 +887,7 @@ def test_policy(testerchain, testerchain.wait_for_receipt(tx) assert staker2_balance < testerchain.client.get_balance(staker2) staker3_balance = testerchain.client.get_balance(staker3) - tx = preallocation_escrow_interface_1.functions.withdrawPolicyReward().transact({'from': staker3, 'gas_price': 0}) + tx = preallocation_escrow_interface_1.functions.withdrawPolicyFee().transact({'from': staker3, 'gas_price': 0}) testerchain.wait_for_receipt(tx) tx = preallocation_escrow_1.functions.withdrawETH().transact({'from': staker3, 'gas_price': 0}) testerchain.wait_for_receipt(tx) diff --git a/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager.py b/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager.py index dce5b1546..8a2670db8 100644 --- a/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager.py +++ b/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager.py @@ -32,10 +32,10 @@ RATE_FIELD = 3 START_TIMESTAMP_FIELD = 4 END_TIMESTAMP_FIELD = 5 -REWARD_FIELD = 0 +FEE_FIELD = 0 LAST_MINED_PERIOD_FIELD = 1 -REWARD_RATE_FIELD = 2 -MIN_REWARD_RATE_FIELD = 3 +FEE_RATE_FIELD = 2 +MIN_FEE_RATE_FIELD = 3 POLICY_ID_LENGTH = 16 @@ -57,8 +57,8 @@ def test_create_revoke(testerchain, escrow, policy_manager): arrangement_refund_log = policy_manager.events.RefundForArrangement.createFilter(fromBlock='latest') policy_refund_log = policy_manager.events.RefundForPolicy.createFilter(fromBlock='latest') warn_log = policy_manager.events.NodeBrokenState.createFilter(fromBlock='latest') - min_reward_log = policy_manager.events.MinRewardRateSet.createFilter(fromBlock='latest') - reward_range_log = policy_manager.events.MinRewardRateRangeSet.createFilter(fromBlock='latest') + min_fee_log = policy_manager.events.MinFeeRateSet.createFilter(fromBlock='latest') + fee_range_log = policy_manager.events.MinFeeRateRangeSet.createFilter(fromBlock='latest') # Only past periods is allowed in register method current_period = policy_manager.functions.getCurrentPeriod().call() @@ -135,7 +135,7 @@ def test_create_revoke(testerchain, escrow, policy_manager): assert policy_id == event_args['policyId'] assert policy_sponsor == event_args['sponsor'] assert policy_sponsor == event_args['owner'] - assert rate == event_args['rewardRate'] + assert rate == event_args['feeRate'] assert current_timestamp == event_args['startTimestamp'] assert end_timestamp == event_args['endTimestamp'] assert 1 == event_args['numberOfNodes'] @@ -184,9 +184,9 @@ def test_create_revoke(testerchain, escrow, policy_manager): # Create new policy period = escrow.functions.getCurrentPeriod().call() - tx = escrow.functions.setDefaultRewardDelta(node1, period, number_of_periods + 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, period, number_of_periods + 1).transact() testerchain.wait_for_receipt(tx) - tx = escrow.functions.setDefaultRewardDelta(node2, period, number_of_periods + 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node2, period, number_of_periods + 1).transact() testerchain.wait_for_receipt(tx) end_timestamp = current_timestamp + (number_of_periods - 1) * one_period policy_id_2 = os.urandom(POLICY_ID_LENGTH) @@ -211,7 +211,7 @@ def test_create_revoke(testerchain, escrow, policy_manager): assert policy_id_2 == event_args['policyId'] assert policy_sponsor == event_args['sponsor'] assert policy_owner == event_args['owner'] - assert 2 * rate == event_args['rewardRate'] + assert 2 * rate == event_args['feeRate'] assert current_timestamp == event_args['startTimestamp'] assert end_timestamp == event_args['endTimestamp'] assert 3 == event_args['numberOfNodes'] @@ -294,35 +294,35 @@ def test_create_revoke(testerchain, escrow, policy_manager): tx = policy_manager.functions.revokeArrangement(policy_id_2, node1).transact({'from': policy_sponsor}) testerchain.wait_for_receipt(tx) - # Can't create policy with wrong ETH value - when reward is not calculated by formula: - # numberOfNodes * rewardRate * numberOfPeriods + # Can't create policy with wrong ETH value - when fee is not calculated by formula: + # numberOfNodes * feeRate * numberOfPeriods policy_id_3 = os.urandom(POLICY_ID_LENGTH) with pytest.raises((TransactionFailed, ValueError)): tx = policy_manager.functions.createPolicy(policy_id_3, policy_sponsor, end_timestamp, [node1])\ .transact({'from': policy_sponsor, 'value': 11}) testerchain.wait_for_receipt(tx) - # Can't set minimum reward because range is [0, 0] + # Can't set minimum fee because range is [0, 0] with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setMinRewardRate(10).transact({'from': node1}) + tx = policy_manager.functions.setMinFeeRate(10).transact({'from': node1}) testerchain.wait_for_receipt(tx) # Only owner can change range with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setMinRewardRateRange(10, 20, 30).transact({'from': node1}) + tx = policy_manager.functions.setMinFeeRateRange(10, 20, 30).transact({'from': node1}) testerchain.wait_for_receipt(tx) - assert policy_manager.functions.minRewardRateRange().call() == [0, 0, 0] + assert policy_manager.functions.minFeeRateRange().call() == [0, 0, 0] - tx = policy_manager.functions.setMinRewardRate(0).transact({'from': node1}) + tx = policy_manager.functions.setMinFeeRate(0).transact({'from': node1}) testerchain.wait_for_receipt(tx) - assert policy_manager.functions.getMinRewardRate(node1).call() == 0 - assert len(min_reward_log.get_all_entries()) == 0 + assert policy_manager.functions.getMinFeeRate(node1).call() == 0 + assert len(min_fee_log.get_all_entries()) == 0 - tx = policy_manager.functions.setMinRewardRateRange(0, 0, 0).transact({'from': creator}) + tx = policy_manager.functions.setMinFeeRateRange(0, 0, 0).transact({'from': creator}) testerchain.wait_for_receipt(tx) - assert policy_manager.functions.minRewardRateRange().call() == [0, 0, 0] + assert policy_manager.functions.minFeeRateRange().call() == [0, 0, 0] - events = reward_range_log.get_all_entries() + events = fee_range_log.get_all_entries() assert len(events) == 1 event_args = events[0]['args'] assert event_args['sender'] == creator @@ -332,22 +332,22 @@ def test_create_revoke(testerchain, escrow, policy_manager): # Can't set range with inconsistent values with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setMinRewardRateRange(10, 5, 11).transact({'from': creator}) + tx = policy_manager.functions.setMinFeeRateRange(10, 5, 11).transact({'from': creator}) testerchain.wait_for_receipt(tx) with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setMinRewardRateRange(10, 15, 11).transact({'from': creator}) + tx = policy_manager.functions.setMinFeeRateRange(10, 15, 11).transact({'from': creator}) testerchain.wait_for_receipt(tx) min_rate, default_rate, max_rate = 10, 20, 30 - tx = policy_manager.functions.setMinRewardRateRange(min_rate, default_rate, max_rate).transact({'from': creator}) + tx = policy_manager.functions.setMinFeeRateRange(min_rate, default_rate, max_rate).transact({'from': creator}) testerchain.wait_for_receipt(tx) - assert policy_manager.functions.minRewardRateRange().call() == [min_rate, default_rate, max_rate] - assert policy_manager.functions.nodes(node1).call()[MIN_REWARD_RATE_FIELD] == 0 - assert policy_manager.functions.nodes(node2).call()[MIN_REWARD_RATE_FIELD] == 0 - assert policy_manager.functions.getMinRewardRate(node1).call() == default_rate - assert policy_manager.functions.getMinRewardRate(node2).call() == default_rate + assert policy_manager.functions.minFeeRateRange().call() == [min_rate, default_rate, max_rate] + assert policy_manager.functions.nodes(node1).call()[MIN_FEE_RATE_FIELD] == 0 + assert policy_manager.functions.nodes(node2).call()[MIN_FEE_RATE_FIELD] == 0 + assert policy_manager.functions.getMinFeeRate(node1).call() == default_rate + assert policy_manager.functions.getMinFeeRate(node2).call() == default_rate - events = reward_range_log.get_all_entries() + events = fee_range_log.get_all_entries() assert len(events) == 2 event_args = events[1]['args'] assert event_args['sender'] == creator @@ -355,25 +355,25 @@ def test_create_revoke(testerchain, escrow, policy_manager): assert event_args['defaultValue'] == default_rate assert event_args['max'] == max_rate - # Can't set min reward let out of range + # Can't set min fee let out of range with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setMinRewardRate(5).transact({'from': node1}) + tx = policy_manager.functions.setMinFeeRate(5).transact({'from': node1}) testerchain.wait_for_receipt(tx) with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setMinRewardRate(35).transact({'from': node1}) + tx = policy_manager.functions.setMinFeeRate(35).transact({'from': node1}) testerchain.wait_for_receipt(tx) - # Set minimum reward rate for nodes - tx = policy_manager.functions.setMinRewardRate(10).transact({'from': node1}) + # Set minimum fee rate for nodes + tx = policy_manager.functions.setMinFeeRate(10).transact({'from': node1}) testerchain.wait_for_receipt(tx) - tx = policy_manager.functions.setMinRewardRate(20).transact({'from': node2}) + tx = policy_manager.functions.setMinFeeRate(20).transact({'from': node2}) testerchain.wait_for_receipt(tx) - assert policy_manager.functions.nodes(node1).call()[MIN_REWARD_RATE_FIELD] == 10 - assert policy_manager.functions.nodes(node2).call()[MIN_REWARD_RATE_FIELD] == 20 - assert policy_manager.functions.getMinRewardRate(node1).call() == 10 - assert policy_manager.functions.getMinRewardRate(node2).call() == 20 + assert policy_manager.functions.nodes(node1).call()[MIN_FEE_RATE_FIELD] == 10 + assert policy_manager.functions.nodes(node2).call()[MIN_FEE_RATE_FIELD] == 20 + assert policy_manager.functions.getMinFeeRate(node1).call() == 10 + assert policy_manager.functions.getMinFeeRate(node2).call() == 20 - events = min_reward_log.get_all_entries() + events = min_fee_log.get_all_entries() assert len(events) == 2 event_args = events[0]['args'] assert event_args['node'] == node1 @@ -418,7 +418,7 @@ def test_create_revoke(testerchain, escrow, policy_manager): assert policy_id_3 == event_args['policyId'] assert policy_sponsor == event_args['sponsor'] assert policy_sponsor == event_args['owner'] - assert rate == event_args['rewardRate'] + assert rate == event_args['feeRate'] assert current_timestamp == event_args['startTimestamp'] assert end_timestamp == event_args['endTimestamp'] assert 2 == event_args['numberOfNodes'] @@ -481,17 +481,17 @@ def test_create_revoke(testerchain, escrow, policy_manager): assert len(warn_log.get_all_entries()) == 0 - # If min reward rate is outside of the range after changing it - then default value must be returned + # If min fee rate is outside of the range after changing it - then default value must be returned min_rate, default_rate, max_rate = 11, 15, 19 - tx = policy_manager.functions.setMinRewardRateRange(min_rate, default_rate, max_rate).transact({'from': creator}) + tx = policy_manager.functions.setMinFeeRateRange(min_rate, default_rate, max_rate).transact({'from': creator}) testerchain.wait_for_receipt(tx) - assert policy_manager.functions.minRewardRateRange().call() == [min_rate, default_rate, max_rate] - assert policy_manager.functions.nodes(node1).call()[MIN_REWARD_RATE_FIELD] == 10 - assert policy_manager.functions.nodes(node2).call()[MIN_REWARD_RATE_FIELD] == 20 - assert policy_manager.functions.getMinRewardRate(node1).call() == default_rate - assert policy_manager.functions.getMinRewardRate(node2).call() == default_rate + assert policy_manager.functions.minFeeRateRange().call() == [min_rate, default_rate, max_rate] + assert policy_manager.functions.nodes(node1).call()[MIN_FEE_RATE_FIELD] == 10 + assert policy_manager.functions.nodes(node2).call()[MIN_FEE_RATE_FIELD] == 20 + assert policy_manager.functions.getMinFeeRate(node1).call() == default_rate + assert policy_manager.functions.getMinFeeRate(node2).call() == default_rate - events = reward_range_log.get_all_entries() + events = fee_range_log.get_all_entries() assert len(events) == 3 event_args = events[2]['args'] assert event_args['sender'] == creator @@ -542,7 +542,7 @@ def test_upgrading(testerchain, deploy_contract): abi=contract_library_v2.abi, address=dispatcher.address, ContractFactoryClass=Contract) - tx = contract.functions.setMinRewardRateRange(10, 15, 20).transact({'from': creator}) + tx = contract.functions.setMinFeeRateRange(10, 15, 20).transact({'from': creator}) testerchain.wait_for_receipt(tx) # Can't call `finishUpgrade` and `verifyState` methods outside upgrade lifecycle @@ -634,30 +634,30 @@ def test_handling_wrong_state(testerchain, deploy_contract): # Prepare broken state, emulates creating policy in the same period as node was registered number_of_periods = 2 - tx = policy_manager.functions.setNodeRewardDelta(node1, initial_period, 1).transact() + tx = policy_manager.functions.setNodeFeeDelta(node1, initial_period, 1).transact() testerchain.wait_for_receipt(tx) - tx = policy_manager.functions.setNodeRewardDelta(node1, initial_period + number_of_periods, -1).transact() + tx = policy_manager.functions.setNodeFeeDelta(node1, initial_period + number_of_periods, -1).transact() testerchain.wait_for_receipt(tx) - tx = escrow.functions.setDefaultRewardDelta(node1, current_period, 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, current_period, 1).transact() testerchain.wait_for_receipt(tx) # Emulate confirm activity actions for i in range(1, number_of_periods + 2): testerchain.time_travel(hours=1) current_period = policy_manager.functions.getCurrentPeriod().call() - tx = escrow.functions.setDefaultRewardDelta(node1, current_period + 1, 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, current_period + 1, 1).transact() testerchain.wait_for_receipt(tx) tx = escrow.functions.mint(current_period - 1, 1).transact({'from': node1}) testerchain.wait_for_receipt(tx) - reward, last_mined_period, reward_rate, _min_reward_rate = policy_manager.functions.nodes(node1).call() - assert reward == 0 - assert reward_rate == 0 + fee, last_mined_period, fee_rate, _min_fee_rate = policy_manager.functions.nodes(node1).call() + assert fee == 0 + assert fee_rate == 0 assert last_mined_period == current_period - 1 - assert policy_manager.functions.getNodeRewardDelta(node1, initial_period).call() == 1 + assert policy_manager.functions.getNodeFeeDelta(node1, initial_period).call() == 1 for i in range(1, number_of_periods): - assert policy_manager.functions.getNodeRewardDelta(node1, initial_period + i).call() == 0 - assert policy_manager.functions.getNodeRewardDelta(node1, initial_period + number_of_periods).call() == -1 + assert policy_manager.functions.getNodeFeeDelta(node1, initial_period + i).call() == 0 + assert policy_manager.functions.getNodeFeeDelta(node1, initial_period + number_of_periods).call() == -1 events = warn_log.get_all_entries() assert 1 == len(events) @@ -671,36 +671,36 @@ def test_handling_wrong_state(testerchain, deploy_contract): tx = escrow.functions.register(node2, initial_period).transact() testerchain.wait_for_receipt(tx) number_of_periods = 5 - tx = escrow.functions.setDefaultRewardDelta(node2, current_period, 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node2, current_period, 1).transact() testerchain.wait_for_receipt(tx) - tx = policy_manager.functions.setNodeRewardDelta(node2, initial_period, 100).transact() + tx = policy_manager.functions.setNodeFeeDelta(node2, initial_period, 100).transact() testerchain.wait_for_receipt(tx) - tx = policy_manager.functions.setNodeRewardDelta(node2, initial_period + number_of_periods, -100).transact() + tx = policy_manager.functions.setNodeFeeDelta(node2, initial_period + number_of_periods, -100).transact() testerchain.wait_for_receipt(tx) - tx = policy_manager.functions.setNodeRewardDelta(node2, initial_period + 2, 50).transact() + tx = policy_manager.functions.setNodeFeeDelta(node2, initial_period + 2, 50).transact() testerchain.wait_for_receipt(tx) - tx = policy_manager.functions.setNodeRewardDelta(node2, initial_period + 2 + number_of_periods, -50).transact() + tx = policy_manager.functions.setNodeFeeDelta(node2, initial_period + 2 + number_of_periods, -50).transact() testerchain.wait_for_receipt(tx) # Emulate confirm activity actions for i in range(1, number_of_periods + 4): testerchain.time_travel(hours=1) current_period = policy_manager.functions.getCurrentPeriod().call() - tx = escrow.functions.setDefaultRewardDelta(node2, current_period + 1, 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node2, current_period + 1, 1).transact() testerchain.wait_for_receipt(tx) tx = escrow.functions.mint(current_period - 1, 1).transact({'from': node2}) testerchain.wait_for_receipt(tx) - reward, last_mined_period, reward_rate, _min_reward_rate = policy_manager.functions.nodes(node2).call() - assert reward == 50 * (number_of_periods - 2) - assert reward_rate == 0 + fee, last_mined_period, fee_rate, _min_fee_rate = policy_manager.functions.nodes(node2).call() + assert fee == 50 * (number_of_periods - 2) + assert fee_rate == 0 assert last_mined_period == current_period - 1 - assert policy_manager.functions.getNodeRewardDelta(node2, initial_period).call() == 100 + assert policy_manager.functions.getNodeFeeDelta(node2, initial_period).call() == 100 for i in range(1, number_of_periods - 2): - assert policy_manager.functions.getNodeRewardDelta(node2, initial_period + i).call() == 0 - assert policy_manager.functions.getNodeRewardDelta(node2, initial_period + number_of_periods).call() == -50 - assert policy_manager.functions.getNodeRewardDelta(node2, initial_period + number_of_periods + 1).call() == 0 - assert policy_manager.functions.getNodeRewardDelta(node2, initial_period + number_of_periods + 2).call() == -50 + assert policy_manager.functions.getNodeFeeDelta(node2, initial_period + i).call() == 0 + assert policy_manager.functions.getNodeFeeDelta(node2, initial_period + number_of_periods).call() == -50 + assert policy_manager.functions.getNodeFeeDelta(node2, initial_period + number_of_periods + 1).call() == 0 + assert policy_manager.functions.getNodeFeeDelta(node2, initial_period + number_of_periods + 2).call() == -50 events = warn_log.get_all_entries() assert 3 == len(events) diff --git a/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager_operations.py b/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager_operations.py index 6469c7707..ba774bab9 100644 --- a/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager_operations.py +++ b/tests/blockchain/eth/contracts/main/policy_manager/test_policy_manager_operations.py @@ -30,10 +30,10 @@ RATE_FIELD = 3 START_TIMESTAMP_FIELD = 4 END_TIMESTAMP_FIELD = 5 -REWARD_FIELD = 0 -REWARD_RATE_FIELD = 1 +FEE_FIELD = 0 +FEE_RATE_FIELD = 1 LAST_MINED_PERIOD_FIELD = 2 -MIN_REWARD_RATE_FIELD = 3 +MIN_FEE_RATE_FIELD = 3 POLICY_ID_LENGTH = 16 policy_id = os.urandom(POLICY_ID_LENGTH) @@ -46,7 +46,7 @@ value = rate * number_of_periods @pytest.mark.slow -def test_reward(testerchain, escrow, policy_manager): +def test_fee(testerchain, escrow, policy_manager): creator, policy_sponsor, bad_node, node1, node2, node3, *everyone_else = testerchain.client.accounts node_balance = testerchain.client.get_balance(node1) withdraw_log = policy_manager.events.Withdrawn.createFilter(fromBlock='latest') @@ -56,10 +56,10 @@ def test_reward(testerchain, escrow, policy_manager): period = escrow.functions.getCurrentPeriod().call() tx = escrow.functions.mint(period - 1, 1).transact({'from': node1, 'gas_price': 0}) testerchain.wait_for_receipt(tx) - assert 0 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 0 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] # Create policy - tx = escrow.functions.setDefaultRewardDelta(node1, period - 1, number_of_periods + 2).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, period - 1, number_of_periods + 2).transact() testerchain.wait_for_receipt(tx) current_timestamp = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp end_timestamp = current_timestamp + (number_of_periods - 1) * one_period @@ -72,9 +72,9 @@ def test_reward(testerchain, escrow, policy_manager): tx = policy_manager.functions.withdraw().transact({'from': node1}) testerchain.wait_for_receipt(tx) - # Can't update reward directly (only through mint method in the escrow contract) + # Can't update fee directly (only through mint method in the escrow contract) with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.updateReward(node1, period + 1).transact({'from': node1}) + tx = policy_manager.functions.updateFee(node1, period + 1).transact({'from': node1}) testerchain.wait_for_receipt(tx) # Can't register directly (only through deposit method in the escrow contract) with pytest.raises((TransactionFailed, ValueError)): @@ -82,14 +82,14 @@ def test_reward(testerchain, escrow, policy_manager): testerchain.wait_for_receipt(tx) # Can't set default value directly (only through confirmActivity method in the escrow contract) with pytest.raises((TransactionFailed, ValueError)): - tx = policy_manager.functions.setDefaultRewardDelta(bad_node, period).transact({'from': bad_node}) + tx = policy_manager.functions.setDefaultFeeDelta(bad_node, period).transact({'from': bad_node}) testerchain.wait_for_receipt(tx) - # Mint some periods for calling updateReward method + # Mint some periods for calling updateFee method tx = escrow.functions.mint(period - 1, 5).transact({'from': node1, 'gas_price': 0}) testerchain.wait_for_receipt(tx) period += 4 - assert 80 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 80 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] # Withdraw some ETH tx = policy_manager.functions.withdraw().transact({'from': node1, 'gas_price': 0}) @@ -105,15 +105,15 @@ def test_reward(testerchain, escrow, policy_manager): assert 80 == event_args['value'] # Mint more periods - tx = escrow.functions.setDefaultRewardDelta(node1, period, 6).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, period, 6).transact() testerchain.wait_for_receipt(tx) tx = escrow.functions.mint(period, 6).transact({'from': node1, 'gas_price': 0}) testerchain.wait_for_receipt(tx) period += 6 - assert 120 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 120 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] tx = escrow.functions.mint(period, 1).transact({'from': node1, 'gas_price': 0}) testerchain.wait_for_receipt(tx) - assert 120 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 120 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] # Withdraw some ETH tx = policy_manager.functions.withdraw(node1).transact({'from': node1, 'gas_price': 0}) @@ -130,7 +130,7 @@ def test_reward(testerchain, escrow, policy_manager): # Create policy period = escrow.functions.getCurrentPeriod().call() - tx = escrow.functions.setDefaultRewardDelta(node1, period, 1).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, period, 1).transact() testerchain.wait_for_receipt(tx) tx = policy_manager.functions.createPolicy(policy_id_2, policy_sponsor, end_timestamp, [node2, node3]) \ .transact({'from': policy_sponsor, 'value': int(2 * value)}) @@ -140,15 +140,15 @@ def test_reward(testerchain, escrow, policy_manager): tx = escrow.functions.mint(period, 5).transact({'from': node2, 'gas_price': 0}) testerchain.wait_for_receipt(tx) period += 5 - assert 100 == policy_manager.functions.nodes(node2).call()[REWARD_FIELD] + assert 100 == policy_manager.functions.nodes(node2).call()[FEE_FIELD] # Mint more periods tx = escrow.functions.mint(period, 6).transact({'from': node2, 'gas_price': 0}) testerchain.wait_for_receipt(tx) period += 6 - assert 200 == policy_manager.functions.nodes(node2).call()[REWARD_FIELD] + assert 200 == policy_manager.functions.nodes(node2).call()[FEE_FIELD] - # Withdraw the second node reward to the first node + # Withdraw the second node fee to the first node node_balance = testerchain.client.get_balance(node1) node_2_balance = testerchain.client.get_balance(node2) tx = policy_manager.functions.withdraw(node1).transact({'from': node2, 'gas_price': 0}) @@ -352,7 +352,7 @@ def test_refund(testerchain, escrow, policy_manager): testerchain.wait_for_receipt(tx) tx = escrow.functions.setLastActivePeriod(period + 8).transact({'from': creator}) testerchain.wait_for_receipt(tx) - assert 100 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 100 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] testerchain.time_travel(hours=10) assert 300 == policy_manager.functions.calculateRefundValue(policy_id_2).call({'from': policy_creator}) @@ -444,7 +444,7 @@ def test_refund(testerchain, escrow, policy_manager): period += 3 tx = escrow.functions.setLastActivePeriod(period).transact({'from': creator}) testerchain.wait_for_receipt(tx) - assert 160 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 160 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] # Policy owner revokes policy testerchain.time_travel(hours=4) @@ -454,7 +454,7 @@ def test_refund(testerchain, escrow, policy_manager): policy_manager_balance = testerchain.client.get_balance(policy_manager.address) creator_balance = testerchain.client.get_balance(policy_creator) period = escrow.functions.getCurrentPeriod().call() - tx = escrow.functions.setDefaultRewardDelta(node1, period + 1, number_of_periods).transact() + tx = escrow.functions.setDefaultFeeDelta(node1, period + 1, number_of_periods).transact() testerchain.wait_for_receipt(tx) tx = policy_manager.functions.revokePolicy(policy_id_3).transact({'from': policy_creator, 'gas_price': 0}) testerchain.wait_for_receipt(tx) @@ -487,7 +487,7 @@ def test_refund(testerchain, escrow, policy_manager): tx = escrow.functions.mint(period + 1, number_of_periods + 1).transact({'from': node1}) testerchain.wait_for_receipt(tx) period += 20 - assert 160 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD] + assert 160 == policy_manager.functions.nodes(node1).call()[FEE_FIELD] # Create policy again to test double call of `refund` with specific conditions testerchain.time_travel(hours=number_of_periods + 2) @@ -587,7 +587,7 @@ def test_reentrancy(testerchain, escrow, policy_manager, deploy_contract): period = escrow.functions.getCurrentPeriod().call() tx = escrow.functions.mint(contract_address, period, 1).transact({'gas_price': 0}) testerchain.wait_for_receipt(tx) - assert 2 * rate == policy_manager.functions.nodes(contract_address).call()[REWARD_FIELD] + assert 2 * rate == policy_manager.functions.nodes(contract_address).call()[FEE_FIELD] # Check protection from reentrancy in withdrawal method balance = testerchain.client.get_balance(contract_address) @@ -599,7 +599,7 @@ def test_reentrancy(testerchain, escrow, policy_manager, deploy_contract): tx = testerchain.client.send_transaction({'to': contract_address}) testerchain.wait_for_receipt(tx) assert balance == testerchain.client.get_balance(contract_address) - assert 2 * rate == policy_manager.functions.nodes(contract_address).call()[REWARD_FIELD] + assert 2 * rate == policy_manager.functions.nodes(contract_address).call()[FEE_FIELD] assert 0 == len(withdraw_log.get_all_entries()) # Prepare for refund and check reentrancy protection @@ -613,7 +613,7 @@ def test_reentrancy(testerchain, escrow, policy_manager, deploy_contract): testerchain.wait_for_receipt(tx) assert balance == testerchain.client.get_balance(contract_address) assert not policy_manager.functions.policies(policy_id).call()[DISABLED_FIELD] - assert 2 * rate == policy_manager.functions.nodes(contract_address).call()[REWARD_FIELD] + assert 2 * rate == policy_manager.functions.nodes(contract_address).call()[FEE_FIELD] assert 0 == len(arrangement_revoked_log.get_all_entries()) assert 0 == len(policy_revoked_log.get_all_entries()) assert 0 == len(arrangement_refund_log.get_all_entries()) diff --git a/tests/blockchain/eth/contracts/main/staking_contracts/test_staking_interface.py b/tests/blockchain/eth/contracts/main/staking_contracts/test_staking_interface.py index e30c59af7..b3c480980 100644 --- a/tests/blockchain/eth/contracts/main/staking_contracts/test_staking_interface.py +++ b/tests/blockchain/eth/contracts/main/staking_contracts/test_staking_interface.py @@ -260,47 +260,47 @@ def test_policy(testerchain, policy_manager, staking_contract, staking_contract_ # Nothing to withdraw with pytest.raises((TransactionFailed, ValueError)): - tx = staking_contract_interface.functions.withdrawPolicyReward().transact({'from': owner, 'gas_price': 0}) + tx = staking_contract_interface.functions.withdrawPolicyFee().transact({'from': owner, 'gas_price': 0}) testerchain.wait_for_receipt(tx) assert owner_balance == testerchain.client.get_balance(owner) assert 0 == testerchain.client.get_balance(staking_contract.address) - # Send ETH to the policy manager as a reward for the owner + # Send ETH to the policy manager as a fee for the owner tx = testerchain.client.send_transaction( {'from': testerchain.client.coinbase, 'to': policy_manager.address, 'value': 10000}) testerchain.wait_for_receipt(tx) - staker_reward = staking_contract_interface.events.PolicyRewardWithdrawn.createFilter(fromBlock='latest') + staker_fee = staking_contract_interface.events.PolicyFeeWithdrawn.createFilter(fromBlock='latest') - # Only owner can withdraw reward + # Only owner can withdraw fee with pytest.raises((TransactionFailed, ValueError)): - tx = staking_contract_interface.functions.withdrawPolicyReward().transact({'from': creator, 'gas_price': 0}) + tx = staking_contract_interface.functions.withdrawPolicyFee().transact({'from': creator, 'gas_price': 0}) testerchain.wait_for_receipt(tx) - # Owner withdraws reward - tx = staking_contract_interface.functions.withdrawPolicyReward().transact({'from': owner, 'gas_price': 0}) + # Owner withdraws fee + tx = staking_contract_interface.functions.withdrawPolicyFee().transact({'from': owner, 'gas_price': 0}) testerchain.wait_for_receipt(tx) assert 10000 == testerchain.client.get_balance(staking_contract.address) assert owner_balance == testerchain.client.get_balance(owner) assert 0 == testerchain.client.get_balance(policy_manager.address) assert 10000 == testerchain.client.get_balance(staking_contract.address) - events = staker_reward.get_all_entries() + events = staker_fee.get_all_entries() assert 1 == len(events) event_args = events[0]['args'] assert owner == event_args['sender'] assert 10000 == event_args['value'] - # Only owner can set min reward rate - min_reward_sets = staking_contract_interface.events.MinRewardRateSet.createFilter(fromBlock='latest') + # Only owner can set min fee rate + min_fee_sets = staking_contract_interface.events.MinFeeRateSet.createFilter(fromBlock='latest') with pytest.raises((TransactionFailed, ValueError)): - tx = staking_contract_interface.functions.setMinRewardRate(333).transact({'from': creator}) + tx = staking_contract_interface.functions.setMinFeeRate(333).transact({'from': creator}) testerchain.wait_for_receipt(tx) - tx = staking_contract_interface.functions.setMinRewardRate(222).transact({'from': owner}) + tx = staking_contract_interface.functions.setMinFeeRate(222).transact({'from': owner}) testerchain.wait_for_receipt(tx) - assert 222 == policy_manager.functions.minRewardRate().call() + assert 222 == policy_manager.functions.minFeeRate().call() - events = min_reward_sets.get_all_entries() + events = min_fee_sets.get_all_entries() assert 1 == len(events) event_args = events[0]['args'] assert owner == event_args['sender'] diff --git a/tests/blockchain/eth/entities/actors/test_deployer.py b/tests/blockchain/eth/entities/actors/test_deployer.py index 75b32baa4..c984f1651 100644 --- a/tests/blockchain/eth/entities/actors/test_deployer.py +++ b/tests/blockchain/eth/entities/actors/test_deployer.py @@ -80,4 +80,4 @@ def test_rapid_deployment(token_economics, test_registry, tmpdir, get_random_che administrator.batch_deposits(allocation_data_filepath=str(filepath), interactive=False) minimum, default, maximum = 10, 20, 30 - administrator.set_min_reward_rate_range(minimum, default, maximum) + administrator.set_min_fee_rate_range(minimum, default, maximum) diff --git a/tests/blockchain/eth/entities/actors/test_staker.py b/tests/blockchain/eth/entities/actors/test_staker.py index 2514f70d3..8070dc32a 100644 --- a/tests/blockchain/eth/entities/actors/test_staker.py +++ b/tests/blockchain/eth/entities/actors/test_staker.py @@ -26,7 +26,7 @@ from nucypher.crypto.powers import TransactingPower from nucypher.utilities.sandbox.blockchain import token_airdrop from nucypher.utilities.sandbox.constants import DEVELOPMENT_TOKEN_AIRDROP_AMOUNT, INSECURE_DEVELOPMENT_PASSWORD from nucypher.utilities.sandbox.ursula import make_decentralized_ursulas -from tests.fixtures import MIN_REWARD_RATE_RANGE +from tests.fixtures import MIN_FEE_RATE_RANGE @pytest.mark.slow() @@ -199,15 +199,15 @@ def test_staker_manages_winding_down(testerchain, assert staker.locked_tokens(base_duration) == 0 -def test_set_min_reward_rate(testerchain, test_registry, staker): +def test_set_min_fee_rate(testerchain, test_registry, staker): # Check before set - _minimum, default, maximum = MIN_REWARD_RATE_RANGE - assert staker.min_reward_rate == default + _minimum, default, maximum = MIN_FEE_RATE_RANGE + assert staker.min_fee_rate == default # New value must be within range with pytest.raises((TransactionFailed, ValueError)): - staker.set_min_reward_rate(maximum + 1) - receipt = staker.set_min_reward_rate(maximum - 1) + staker.set_min_fee_rate(maximum + 1) + receipt = staker.set_min_fee_rate(maximum - 1) assert receipt['status'] == 1 - assert staker.min_reward_rate == maximum - 1 + assert staker.min_fee_rate == maximum - 1 diff --git a/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py b/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py index bc78bb640..c85044a51 100644 --- a/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py +++ b/tests/blockchain/eth/entities/agents/test_policy_manager_agent.py @@ -25,7 +25,7 @@ from eth_utils import is_checksum_address, to_wei from nucypher.blockchain.eth.agents import PolicyManagerAgent, ContractAgency from nucypher.crypto.powers import TransactingPower from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD -from tests.fixtures import MIN_REWARD_RATE_RANGE +from tests.fixtures import MIN_FEE_RATE_RANGE MockPolicyMetadata = collections.namedtuple('MockPolicyMetadata', 'policy_id author addresses') @@ -137,23 +137,23 @@ def test_collect_refund(testerchain, agency, policy_meta): @pytest.mark.slow() -def test_set_min_reward_rate(testerchain, test_registry, agency, policy_meta): +def test_set_min_fee_rate(testerchain, test_registry, agency, policy_meta): policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=test_registry) # type: PolicyManagerAgent - minimum, default, maximum = MIN_REWARD_RATE_RANGE + minimum, default, maximum = MIN_FEE_RATE_RANGE staker = policy_meta.addresses[-1] - assert policy_agent.get_min_reward_rate(staker) == default + assert policy_agent.get_min_fee_rate(staker) == default with pytest.raises((TransactionFailed, ValueError)): - policy_agent.set_min_reward_rate(staker_address=staker, min_rate=minimum - 1) + policy_agent.set_min_fee_rate(staker_address=staker, min_rate=minimum - 1) - receipt = policy_agent.set_min_reward_rate(staker_address=staker, min_rate=minimum + 1) + receipt = policy_agent.set_min_fee_rate(staker_address=staker, min_rate=minimum + 1) assert receipt['status'] == 1 - assert policy_agent.get_min_reward_rate(staker) == minimum + 1 + assert policy_agent.get_min_fee_rate(staker) == minimum + 1 @pytest.mark.slow() @pytest.mark.usefixtures('blockchain_ursulas') -def test_collect_policy_reward(testerchain, agency, policy_meta, token_economics, mock_transacting_power_activation): +def test_collect_policy_fee(testerchain, agency, policy_meta, token_economics, mock_transacting_power_activation): token_agent, staking_agent, policy_agent = agency agent = policy_agent @@ -169,7 +169,7 @@ def test_collect_policy_reward(testerchain, agency, policy_meta, token_economics testerchain.time_travel(periods=1) mock_transacting_power_activation(account=staker, password=INSECURE_DEVELOPMENT_PASSWORD) - receipt = agent.collect_policy_reward(collector_address=staker, staker_address=staker) + receipt = agent.collect_policy_fee(collector_address=staker, staker_address=staker) assert receipt['status'] == 1, "Transaction Rejected" assert receipt['logs'][0]['address'] == agent.contract_address new_eth_balance = token_agent.blockchain.client.get_balance(staker) diff --git a/tests/blockchain/eth/entities/agents/test_preallocation_escrow_agent.py b/tests/blockchain/eth/entities/agents/test_preallocation_escrow_agent.py index 5ea7bb0d4..f055a0f28 100644 --- a/tests/blockchain/eth/entities/agents/test_preallocation_escrow_agent.py +++ b/tests/blockchain/eth/entities/agents/test_preallocation_escrow_agent.py @@ -206,7 +206,7 @@ def test_collect_policy_reward(testerchain, agent, agency, token_economics, mock mock_transacting_power_activation(account=agent.beneficiary, password=INSECURE_DEVELOPMENT_PASSWORD) - receipt = agent.collect_policy_reward() + receipt = agent.collect_policy_fee() assert receipt['status'] == 1, "Transaction Rejected" receipt = agent.withdraw_eth() assert receipt['status'] == 1, "Transaction Rejected" diff --git a/tests/blockchain/eth/entities/deployers/test_policy_manager_deployer.py b/tests/blockchain/eth/entities/deployers/test_policy_manager_deployer.py index 845f4b3e9..061b74aaf 100644 --- a/tests/blockchain/eth/entities/deployers/test_policy_manager_deployer.py +++ b/tests/blockchain/eth/entities/deployers/test_policy_manager_deployer.py @@ -138,11 +138,11 @@ def test_rollback(testerchain, test_registry): assert new_target == old_target -def test_set_reward_range(policy_manager_deployer, test_registry): +def test_set_fee_range(policy_manager_deployer, test_registry): policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=test_registry) # type: PolicyManagerAgent - assert policy_agent.get_min_reward_rate_range() == (0, 0, 0) + assert policy_agent.get_min_fee_rate_range() == (0, 0, 0) minimum, default, maximum = 10, 20, 30 - receipt = policy_manager_deployer.set_min_reward_rate_range(minimum, default, maximum) + receipt = policy_manager_deployer.set_min_fee_rate_range(minimum, default, maximum) assert receipt['status'] == 1 - assert policy_agent.get_min_reward_rate_range() == (minimum, default, maximum) + assert policy_agent.get_min_fee_rate_range() == (minimum, default, maximum) diff --git a/tests/cli/test_status.py b/tests/cli/test_status.py index 1af385b9e..e383d59d0 100644 --- a/tests/cli/test_status.py +++ b/tests/cli/test_status.py @@ -28,7 +28,7 @@ from nucypher.blockchain.eth.agents import ( from nucypher.blockchain.eth.token import NU from nucypher.cli.commands.status import status from nucypher.utilities.sandbox.constants import TEST_PROVIDER_URI, TEMPORARY_DOMAIN -from tests.fixtures import MIN_REWARD_RATE_RANGE +from tests.fixtures import MIN_FEE_RATE_RANGE def test_nucypher_status_network(click_runner, testerchain, agency_local_registry): @@ -91,21 +91,21 @@ def test_nucypher_status_stakers(click_runner, agency_local_registry, stakers): assert re.search(r"Worker:\s+" + some_dude.worker_address, result.output, re.MULTILINE) assert re.search(r"Owned:\s+" + str(round(owned_tokens, 2)), result.output, re.MULTILINE) assert re.search(r"Staked: " + str(round(locked_tokens, 2)), result.output, re.MULTILINE) - _minimum, default, _maximum = MIN_REWARD_RATE_RANGE - assert f"Min reward rate: {default} wei" in result.output + _minimum, default, _maximum = MIN_FEE_RATE_RANGE + assert f"Min fee rate: {default} wei" in result.output -def test_nucypher_status_reward_range(click_runner, agency_local_registry, stakers): +def test_nucypher_status_fee_range(click_runner, agency_local_registry, stakers): - # Get info about reward range - stakers_command = ('reward-range', + # Get info about fee range + stakers_command = ('fee-range', '--registry-filepath', agency_local_registry.filepath, '--provider', TEST_PROVIDER_URI, '--network', TEMPORARY_DOMAIN) result = click_runner.invoke(status, stakers_command, catch_exceptions=False) assert result.exit_code == 0 - minimum, default, maximum = MIN_REWARD_RATE_RANGE + minimum, default, maximum = MIN_FEE_RATE_RANGE assert f"{minimum} wei" in result.output assert f"{default} wei" in result.output assert f"{maximum} wei" in result.output diff --git a/tests/cli/ursula/test_stake_via_allocation_contract.py b/tests/cli/ursula/test_stake_via_allocation_contract.py index b3105cc0d..c7432bc84 100644 --- a/tests/cli/ursula/test_stake_via_allocation_contract.py +++ b/tests/cli/ursula/test_stake_via_allocation_contract.py @@ -616,10 +616,10 @@ def test_collect_rewards_integration(click_runner, # Since we are mocking the blockchain connection, manually consume the transacting power of the Beneficiary. mock_transacting_power_activation(account=beneficiary, password=INSECURE_DEVELOPMENT_PASSWORD) - # Collect Policy Reward + # Collect Policy Fee collection_args = ('stake', 'collect-reward', '--config-file', stakeholder_configuration_file_location, - '--policy-reward', + '--policy-fee', '--no-staking-reward', '--withdraw-address', beneficiary, '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, @@ -631,9 +631,9 @@ def test_collect_rewards_integration(click_runner, catch_exceptions=False) assert result.exit_code == 0 - # Policy Reward - collected_policy_reward = testerchain.client.get_balance(beneficiary) - assert collected_policy_reward > balance + # Policy Fee + collected_policy_fee = testerchain.client.get_balance(beneficiary) + assert collected_policy_fee > balance # # Collect Staking Reward @@ -643,7 +643,7 @@ def test_collect_rewards_integration(click_runner, collection_args = ('stake', 'collect-reward', '--config-file', stakeholder_configuration_file_location, - '--no-policy-reward', + '--no-policy-fee', '--staking-reward', '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, '--force') diff --git a/tests/cli/ursula/test_stakeholder_and_ursula.py b/tests/cli/ursula/test_stakeholder_and_ursula.py index f0bdef45e..fac417b70 100644 --- a/tests/cli/ursula/test_stakeholder_and_ursula.py +++ b/tests/cli/ursula/test_stakeholder_and_ursula.py @@ -39,7 +39,7 @@ from nucypher.utilities.sandbox.constants import ( select_test_port, ) from nucypher.utilities.sandbox.middleware import MockRestMiddleware -from tests.fixtures import MIN_REWARD_RATE_RANGE +from tests.fixtures import MIN_FEE_RATE_RANGE @mock.patch('nucypher.config.characters.StakeHolderConfiguration.default_filepath', return_value='/non/existent/file') @@ -139,7 +139,7 @@ def test_stake_list(click_runner, result = click_runner.invoke(nucypher_cli, stake_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 assert str(stake_value) in result.output - _minimum, default, _maximum = MIN_REWARD_RATE_RANGE + _minimum, default, _maximum = MIN_FEE_RATE_RANGE assert f"{default} wei" in result.output @@ -523,10 +523,10 @@ def test_collect_rewards_integration(click_runner, # Since we are mocking the blockchain connection, manually consume the transacting power of the Staker. mock_transacting_power_activation(account=staker_address, password=INSECURE_DEVELOPMENT_PASSWORD) - # Collect Policy Reward + # Collect Policy Fee collection_args = ('stake', 'collect-reward', '--config-file', stakeholder_configuration_file_location, - '--policy-reward', + '--policy-fee', '--no-staking-reward', '--staking-address', staker_address, '--withdraw-address', burner_wallet.address) @@ -536,10 +536,10 @@ def test_collect_rewards_integration(click_runner, catch_exceptions=False) assert result.exit_code == 0 - # Policy Reward - collected_policy_reward = testerchain.client.get_balance(burner_wallet.address) + # Policy Fee + collected_policy_fee = testerchain.client.get_balance(burner_wallet.address) expected_collection = policy_rate * 30 - assert collected_policy_reward == expected_collection + assert collected_policy_fee == expected_collection # Finish the passage of time... once and for all # Extended periods from stake division @@ -557,7 +557,7 @@ def test_collect_rewards_integration(click_runner, collection_args = ('stake', 'collect-reward', '--config-file', stakeholder_configuration_file_location, - '--no-policy-reward', + '--no-policy-fee', '--staking-reward', '--staking-address', staker_address, '--force') @@ -610,10 +610,10 @@ def test_set_min_rate(click_runner, agency_local_registry, stakeholder_configuration_file_location): - _minimum, _default, maximum = MIN_REWARD_RATE_RANGE + _minimum, _default, maximum = MIN_FEE_RATE_RANGE min_rate = maximum - 1 staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) - assert staker.raw_min_reward_rate == 0 + assert staker.raw_min_fee_rate == 0 restake_args = ('stake', 'set-min-rate', '--min-rate', min_rate, @@ -626,7 +626,7 @@ def test_set_min_rate(click_runner, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 - assert staker.raw_min_reward_rate == min_rate + assert staker.raw_min_fee_rate == min_rate assert "successfully set" in result.output stake_args = ('stake', 'list', diff --git a/tests/fixtures.py b/tests/fixtures.py index 950e4443f..3cbc0a501 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -100,7 +100,7 @@ from tests.performance_mocks import ( ) test_logger = Logger("test-logger") -MIN_REWARD_RATE_RANGE = (5, 10, 15) +MIN_FEE_RATE_RANGE = (5, 10, 15) # @@ -564,8 +564,8 @@ def _make_agency(testerchain, _worklock_agent = worklock_deployer.make_agent() # 5 Worklock # Set additional parameters - minimum, default, maximum = MIN_REWARD_RATE_RANGE - txhash = policy_agent.contract.functions.setMinRewardRateRange(minimum, default, maximum).transact() + minimum, default, maximum = MIN_FEE_RATE_RANGE + txhash = policy_agent.contract.functions.setMinFeeRateRange(minimum, default, maximum).transact() _receipt = testerchain.wait_for_receipt(txhash) # TODO: Get rid of returning these agents here. diff --git a/tests/metrics/estimate_gas.py b/tests/metrics/estimate_gas.py index 1a1c8aeaf..9729000d4 100755 --- a/tests/metrics/estimate_gas.py +++ b/tests/metrics/estimate_gas.py @@ -347,7 +347,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None: transact_and_log("Confirm activity + mint + re-stake", staker_functions.confirmActivity(), {'from': ursula2}) - transact_and_log("Confirm activity + mint + re-stake + first reward + first reward rate", + transact_and_log("Confirm activity + mint + re-stake + first fee + first fee rate", staker_functions.confirmActivity(), {'from': ursula1}) @@ -360,7 +360,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None: testerchain.time_travel(periods=2) transact(staker_functions.confirmActivity(), {'from': ursula3}) transact_and_log("Confirm activity after downtime", staker_functions.confirmActivity(), {'from': ursula2}) - transact_and_log("Confirm activity after downtime + updating reward", + transact_and_log("Confirm activity after downtime + updating fee", staker_functions.confirmActivity(), {'from': ursula1}) @@ -408,8 +408,8 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None: # testerchain.time_travel(periods=1) transact(staker_functions.mint(), {'from': ursula3}) - transact_and_log("Last mining + updating reward + updating reward rate", staker_functions.mint(), {'from': ursula1}) - transact_and_log("Last mining + first reward + first reward rate", staker_functions.mint(), {'from': ursula2}) + transact_and_log("Last mining + updating fee + updating fee rate", staker_functions.mint(), {'from': ursula1}) + transact_and_log("Last mining + first fee + first fee rate", staker_functions.mint(), {'from': ursula2}) # # Create policy again without pre-confirmed nodes @@ -443,7 +443,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None: testerchain.time_travel(periods=2) transact(staker_functions.mint(), {'from': ursula3}) - transact_and_log("Last mining after downtime + updating reward", + transact_and_log("Last mining after downtime + updating fee", staker_functions.mint(), {'from': ursula1})