Skip to content

Commit 8d2fbd4

Browse files
committed
Store complement of skill, allow mining reward scaling
1 parent 7671757 commit 8d2fbd4

File tree

12 files changed

+218
-19
lines changed

12 files changed

+218
-19
lines changed

contracts/colony/Colony.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ contract Colony is BasicMetaTransaction, Multicall, ColonyStorage, PatriciaTreeP
209209
IColonyNetwork(colonyNetworkAddress).setReputationMiningCycleReward(_amount);
210210
}
211211

212+
function setReputationMiningCycle(uint256 _amount) public
213+
stoppable
214+
auth
215+
{
216+
IColonyNetwork(colonyNetworkAddress).setReputationMiningCycleReward(_amount);
217+
}
218+
219+
212220
function addNetworkColonyVersion(uint256 _version, address _resolver) public
213221
stoppable
214222
auth
@@ -334,6 +342,9 @@ contract Colony is BasicMetaTransaction, Multicall, ColonyStorage, PatriciaTreeP
334342

335343
sig = bytes4(keccak256("setReputationDecayRate(uint256,uint256)"));
336344
colonyAuthority.setRoleCapability(uint8(ColonyRole.Root), address(this), sig, true);
345+
346+
sig = bytes4(keccak256("setReputationMiningCycleRewardReputationScaling(uint256)"));
347+
colonyAuthority.setRoleCapability(uint8(ColonyRole.Root), address(this), sig, true);
337348
}
338349

339350
function setTokenReputationRate(address _token, uint256 _rate) public stoppable {
@@ -423,4 +434,9 @@ contract Colony is BasicMetaTransaction, Multicall, ColonyStorage, PatriciaTreeP
423434
return tokenApprovalTotals[_token];
424435
}
425436

437+
function setReputationMiningCycleRewardReputationScaling(uint256 _factor) public stoppable auth {
438+
require(_factor <= WAD, "colony-invalid-scale-factor");
439+
IColonyNetwork(colonyNetworkAddress).setReputationMiningCycleRewardReputationScaling(_factor);
440+
emit MiningReputationScalingSet(_factor);
441+
}
426442
}

contracts/colony/ColonyAuthority.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ contract ColonyAuthority is CommonAuthority {
133133
// Added in colony v xxxxx
134134
addRoleCapability(ROOT_ROLE, "setDomainReputationScaling(uint256,bool,uint256)");
135135
addRoleCapability(ROOT_ROLE, "setReputationDecayRate(uint256,uint256)");
136+
addRoleCapability(ROOT_ROLE, "setReputationMiningCycleRewardReputationScaling(uint256)");
136137

137138
}
138139

contracts/colony/ColonyDataTypes.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ interface ColonyDataTypes {
351351

352352
event DomainReputationScalingSet(uint256 domainId, bool enabled, uint256 factor);
353353

354+
event MiningReputationScalingSet(uint256 factor);
355+
354356
struct RewardPayoutCycle {
355357
// Reputation root hash at the time of reward payout creation
356358
bytes32 reputationState;

contracts/colony/IMetaColony.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ interface IMetaColony is IColony {
5858
/// @param _amount The CLNY awarded per mining cycle to the miners
5959
function setReputationMiningCycleReward(uint256 _amount) external;
6060

61+
/// @notice Called to set the total per-cycle reputation scaling factor for the tokens paid out
62+
/// @dev Calls the corresponding function on the ColonyNetwork.
63+
/// @param _factor The scale factor to apply to reputation mining rewards
64+
function setReputationMiningCycleRewardReputationScaling(uint256 _factor) external;
65+
6166
/// @notice Add a new extension/version to the Extensions repository.
6267
/// @dev Calls `IColonyNetwork.addExtensionToNetwork`.
6368
/// @dev The extension version is queried from the resolver itself.

contracts/colonyNetwork/ColonyNetwork.sol

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,25 @@ contract ColonyNetwork is ColonyDataTypes, BasicMetaTransaction, ColonyNetworkSt
282282
{
283283
require(_factor <= WAD, "colony-network-invalid-reputation-scale-factor");
284284
uint256 skillId = IColony(msgSender()).getDomain(_domainId).skillId;
285-
skills[skillId].earnedReputationScaling = _enabled;
286-
skills[skillId].reputationScalingFactor = _factor;
285+
skills[skillId].reputationScalingFactorComplement = WAD - _factor;
287286
}
288287

289288
function getSkillReputationScaling(uint256 _skillId) public view returns (uint256) {
290289
uint256 factor;
291290
Skill storage s = skills[_skillId];
292-
factor = s.earnedReputationScaling ? s.reputationScalingFactor : WAD;
291+
factor = WAD - s.reputationScalingFactorComplement;
293292

294293
while (s.nParents > 0) {
295294
s = skills[s.parents[0]];
296295
// If reputation scaling is in effect for this skill, then take the value for this skill in to
297296
// account. Otherwise, no effect and continue walking up the tree
298-
if (s.earnedReputationScaling) {
299-
if (s.reputationScalingFactor == 0){
300-
// If scaling is in effect and is 0, we can short circuit - regardless of the rest of the tree
297+
if (s.reputationScalingFactorComplement > 0) {
298+
if (s.reputationScalingFactorComplement == 1){
299+
// If scaling is in effect and is 0 (because factor = 1 - complement), we can short circuit - regardless of the rest of the tree
301300
// the scaling factor will be 0
302301
return 0;
303302
} else {
304-
factor = wmul(factor, s.reputationScalingFactor);
303+
factor = wmul(factor, WAD - s.reputationScalingFactorComplement);
305304
}
306305
}
307306
}

contracts/colonyNetwork/ColonyNetworkDataTypes.sol

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,8 @@ interface ColonyNetworkDataTypes {
166166
bool globalSkill;
167167
// `true` for a global skill that is deprecated
168168
bool deprecated;
169-
// `true` if global scaling is in effect
170-
bool earnedReputationScaling;
171-
// NB extra storage space available here for more booleans etc
172-
// scaling in effect for reputation earned in this skill
173-
uint256 reputationScalingFactor;
169+
// This is the complement of the reputaiton scaling factor. So the scaling factor is WAD-reputationScalingFactorComplement
170+
uint256 reputationScalingFactorComplement;
174171
}
175172

176173
struct ENSRecord {

contracts/colonyNetwork/ColonyNetworkMining.sol

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ pragma experimental "ABIEncoderV2";
2121
import "./../common/ERC20Extended.sol";
2222
import "./../common/EtherRouter.sol";
2323
import "./../common/MultiChain.sol";
24+
import "./../common/ScaleReputation.sol";
2425
import "./../reputationMiningCycle/IReputationMiningCycle.sol";
2526
import "./../tokenLocking/ITokenLocking.sol";
2627
import "./ColonyNetworkStorage.sol";
2728

2829

29-
contract ColonyNetworkMining is ColonyNetworkStorage, MultiChain {
30+
contract ColonyNetworkMining is ColonyNetworkStorage, MultiChain, ScaleReputation {
3031
// TODO: Can we handle a dispute regarding the very first hash that should be set?
3132

3233
modifier onlyReputationMiningCycle () {
@@ -201,7 +202,8 @@ contract ColonyNetworkMining is ColonyNetworkStorage, MultiChain {
201202
stakers,
202203
minerWeights,
203204
metaColony,
204-
totalMinerRewardPerCycle,
205+
// totalMinerRewardPerCycle,
206+
uint256(scaleReputation(int256(totalMinerRewardPerCycle), WAD - skills[reputationMiningSkillId].reputationScalingFactorComplement)),
205207
reputationMiningSkillId
206208
);
207209
}
@@ -275,6 +277,7 @@ contract ColonyNetworkMining is ColonyNetworkStorage, MultiChain {
275277
}
276278

277279
function setReputationMiningCycleReward(uint256 _amount) public stoppable calledByMetaColony {
280+
require(_amount < uint256(type(int256).max), "colony-network-too-large-reward");
278281
totalMinerRewardPerCycle = _amount;
279282

280283
emit ReputationMiningRewardSet(_amount);
@@ -284,6 +287,12 @@ contract ColonyNetworkMining is ColonyNetworkStorage, MultiChain {
284287
return totalMinerRewardPerCycle;
285288
}
286289

290+
function setReputationMiningCycleRewardReputationScaling(uint256 _factor) public calledByMetaColony stoppable
291+
{
292+
require(_factor <= WAD, "colony-network-invalid-reputation-scale-factor");
293+
skills[reputationMiningSkillId].reputationScalingFactorComplement = WAD - _factor;
294+
}
295+
287296
uint256 constant UINT192_MAX = 2**192 - 1; // Used for updating the stake timestamp
288297

289298
function getNewTimestamp(uint256 _prevWeight, uint256 _currWeight, uint256 _prevTime, uint256 _currTime) internal pure returns (uint256) {

contracts/colonyNetwork/IColonyNetwork.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,9 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery, IBasicMetaTransac
487487
/// @return numerator The numerator of the fraction reputation does down by every reputation cycle
488488
/// @return denominator The denominator of the fraction reputation does down by every reputation cycle
489489
function getColonyReputationDecayRate(address _colony) external view returns (uint256 numerator, uint256 denominator);
490+
491+
/// @notice Called to set the total per-cycle reputation scaling factor for the tokens paid out
492+
/// @dev Calls the corresponding function on the ColonyNetwork.
493+
/// @param _factor The scale factor to apply to reputation mining rewards
494+
function setReputationMiningCycleRewardReputationScaling(uint256 _factor) external;
490495
}

docs/interfaces/icolonynetwork.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,19 @@ Called to set the total per-cycle reputation reward, which will be split between
10141014
|_amount|uint256|The CLNY awarded per mining cycle to the miners
10151015

10161016

1017+
### `setReputationMiningCycleRewardReputationScaling(uint256 _factor)`
1018+
1019+
Called to set the total per-cycle reputation scaling factor for the tokens paid out
1020+
1021+
*Note: Calls the corresponding function on the ColonyNetwork.*
1022+
1023+
**Parameters**
1024+
1025+
|Name|Type|Description|
1026+
|---|---|---|
1027+
|_factor|uint256|The scale factor to apply to reputation mining rewards
1028+
1029+
10171030
### `setReputationRootHash(bytes32 _newHash, uint256 _newNLeaves, address[] memory _stakers)`
10181031

10191032
Set a new Reputation root hash and starts a new mining cycle. Can only be called by the ReputationMiningCycle contract.

docs/interfaces/imetacolony.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,17 @@ Called to set the total per-cycle reputation reward, which will be split between
109109

110110
|Name|Type|Description|
111111
|---|---|---|
112-
|_amount|uint256|The CLNY awarded per mining cycle to the miners
112+
|_amount|uint256|The CLNY awarded per mining cycle to the miners
113+
114+
115+
### `setReputationMiningCycleRewardReputationScaling(uint256 _factor)`
116+
117+
Called to set the total per-cycle reputation scaling factor for the tokens paid out
118+
119+
*Note: Calls the corresponding function on the ColonyNetwork.*
120+
121+
**Parameters**
122+
123+
|Name|Type|Description|
124+
|---|---|---|
125+
|_factor|uint256|The scale factor to apply to reputation mining rewards

0 commit comments

Comments
 (0)