-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow a specified address to disable/enable rewards distribution #1828
Changes from all commits
3a0acc5
3df4d2c
1af99f0
ac428da
e466053
e9639a1
644441e
a90e692
8ba374a
51f61b6
a3fdf21
d71a75b
a6d0b69
51da099
8e8f18a
21588db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ pragma solidity ^0.5.3; | |
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
|
||
import "../baklava/Freezable.sol"; | ||
import "../common/FixidityLib.sol"; | ||
import "../common/Initializable.sol"; | ||
import "../common/UsingRegistry.sol"; | ||
|
@@ -11,7 +12,7 @@ import "../common/UsingPrecompiles.sol"; | |
/** | ||
* @title Contract for calculating epoch rewards. | ||
*/ | ||
contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry { | ||
contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry, Freezable { | ||
using FixidityLib for FixidityLib.Fraction; | ||
using SafeMath for uint256; | ||
|
||
|
@@ -82,6 +83,7 @@ contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry | |
*/ | ||
function initialize( | ||
address registryAddress, | ||
address _freezer, | ||
uint256 targetVotingYieldInitial, | ||
uint256 targetVotingYieldMax, | ||
uint256 targetVotingYieldAdjustmentFactor, | ||
|
@@ -92,6 +94,7 @@ contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry | |
uint256 _targetValidatorEpochPayment | ||
) external initializer { | ||
_transferOwnership(msg.sender); | ||
setFreezer(_freezer); | ||
setRegistry(registryAddress); | ||
setTargetVotingYieldParameters(targetVotingYieldMax, targetVotingYieldAdjustmentFactor); | ||
setRewardsMultiplierParameters( | ||
|
@@ -127,6 +130,10 @@ contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry | |
); | ||
} | ||
|
||
function setFreezer(address freezer) public onlyOwner { | ||
_setFreezer(freezer); | ||
} | ||
|
||
/** | ||
* @notice Sets the target voting Gold fraction. | ||
* @param value The percentage of floating Gold voting to target. | ||
|
@@ -362,7 +369,7 @@ contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry | |
* voting Gold fraction. | ||
* @dev Only called directly by the protocol. | ||
*/ | ||
function updateTargetVotingYield() external { | ||
function updateTargetVotingYield() external onlyWhenNotFrozen { | ||
m-chrzan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require(msg.sender == address(0)); | ||
_updateTargetVotingYield(); | ||
} | ||
|
@@ -372,6 +379,10 @@ contract EpochRewards is Ownable, Initializable, UsingPrecompiles, UsingRegistry | |
* @return The per validator epoch payment and the total rewards to voters. | ||
*/ | ||
function calculateTargetEpochPaymentAndRewards() external view returns (uint256, uint256) { | ||
if (frozen) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This shouldn't strictly be necessary, since if one epoch rewards action fails we won't execute any of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. @nategraf recommended this change for robustness. One nice thing about how this is implemented is that after Baklava we can just delete the |
||
return (0, 0); | ||
} | ||
|
||
uint256 targetEpochRewards = getTargetEpochRewards(); | ||
uint256 targetTotalEpochPaymentsInGold = getTargetTotalEpochPaymentsInGold(); | ||
uint256 targetGoldSupplyIncrease = targetEpochRewards.add(targetTotalEpochPaymentsInGold); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,13 @@ import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' | |
import { config } from '@celo/protocol/migrationsConfig' | ||
import { toFixed } from '@celo/utils/lib/fixidity' | ||
import { EpochRewardsInstance } from 'types' | ||
const truffle = require('@celo/protocol/truffle-config.js') | ||
|
||
const initializeArgs = async (): Promise<any[]> => { | ||
const initializeArgs = async (networkName: string): Promise<any[]> => { | ||
const network: any = truffle.networks[networkName] | ||
return [ | ||
config.registry.predeployedProxyAddress, | ||
network.from, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any ideas what else this could be? validator-0 is fairly convenient as that has been the address we use in our tooling to manage test networks (throughout celotool, I believe that's the address that has faucet balances), but agree that we might need to think differently about baklava. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be any key, including one generated on the fly. You could generate it from the same mnemonic and might create a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we currently set other things to? I.e. the approver, reserve spender, etc.? I agree validator 0 isn't the most robust choice, but I believe it's currently the standard choice |
||
toFixed(config.epochRewards.targetVotingYieldParameters.initial).toFixed(), | ||
toFixed(config.epochRewards.targetVotingYieldParameters.max).toFixed(), | ||
toFixed(config.epochRewards.targetVotingYieldParameters.adjustmentFactor).toFixed(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning this up!