Skip to content

Commit 6a20911

Browse files
committed
rewards: confusing, error-prone interest rates management
- Add validation for the minimum issuance rate - Initialize the minimum issuance rate in the constructor - Add natspec to describe the intuition behind the issuance rate parameter - Add tests for setting under minimum issuance rate
1 parent ee63a7b commit 6a20911

File tree

2 files changed

+458
-429
lines changed

2 files changed

+458
-429
lines changed

contracts/rewards/RewardsManager.sol

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
1212
using SafeMath for uint256;
1313

1414
uint256 private constant TOKEN_DECIMALS = 1e18;
15+
uint256 private constant MIN_ISSUANCE_RATE = 1e18;
1516

1617
// -- Events --
1718

@@ -50,6 +51,7 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
5051
*/
5152
function initialize(address _controller) external onlyImpl {
5253
Managed._initialize(_controller);
54+
_setIssuanceRate(MIN_ISSUANCE_RATE);
5355
}
5456

5557
/**
@@ -67,7 +69,11 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
6769

6870
/**
6971
* @dev Sets the issuance rate.
70-
* @param _issuanceRate Issuance rate
72+
* The issuance rate is defined as a percentage increase of the total supply per block.
73+
* This means that it needs to be greater than 1.0, any number under 1.0 is not
74+
* allowed and an issuance rate of 1.0 means no issuance.
75+
* To accomodate a high precision the issuance rate is expressed in wei.
76+
* @param _issuanceRate Issuance rate expressed in wei
7177
*/
7278
function setIssuanceRate(uint256 _issuanceRate) public override onlyGovernor {
7379
_setIssuanceRate(_issuanceRate);
@@ -78,6 +84,8 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
7884
* @param _issuanceRate Issuance rate
7985
*/
8086
function _setIssuanceRate(uint256 _issuanceRate) internal {
87+
require(_issuanceRate >= MIN_ISSUANCE_RATE, "Issuance rate under minimun allowed");
88+
8189
// Called since `issuance rate` will change
8290
updateAccRewardsPerSignal();
8391

@@ -165,21 +173,20 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
165173
* @return newly accrued rewards per signal since last update
166174
*/
167175
function getNewRewardsPerSignal() public override view returns (uint256) {
168-
IGraphToken graphToken = graphToken();
169-
170176
// Calculate time steps
171177
uint256 t = block.number.sub(accRewardsPerSignalLastBlockUpdated);
172178
// Optimization to skip calculations if zero time steps elapsed
173179
if (t == 0) {
174180
return 0;
175181
}
176182

177-
// Zero issuance
178-
if (issuanceRate == 0) {
183+
// Zero issuance under a rate of 1.0
184+
if (issuanceRate <= MIN_ISSUANCE_RATE) {
179185
return 0;
180186
}
181187

182188
// Zero issuance if no signalled tokens
189+
IGraphToken graphToken = graphToken();
183190
uint256 signalledTokens = graphToken.balanceOf(address(curation()));
184191
if (signalledTokens == 0) {
185192
return 0;

0 commit comments

Comments
 (0)