Skip to content

Commit

Permalink
Safe age limit and required added (#694)
Browse files Browse the repository at this point in the history
* Safe age limit and required added

* array length added

* Tests fix
  • Loading branch information
SamAg19 committed Feb 17, 2022
1 parent 64cff77 commit c8e3cea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contracts/Core/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake
return stakers[stakerId].epochFirstStakedOrLastPenalized;
}

function maturitiesLength() external view override returns (uint32) {
return uint32(maturities.length);
}

/// @notice Internal function for setting stake of the staker
/// @param _id of the staker
/// @param _stake the amount of Razor tokens staked
Expand Down
2 changes: 2 additions & 0 deletions contracts/Core/interface/IStakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ interface IStakeManager {
function getStake(uint32 stakerId) external view returns (uint256);

function getEpochFirstStakedOrLastPenalized(uint32 stakerId) external view returns (uint32);

function maturitiesLength() external view returns (uint32);
}
4 changes: 4 additions & 0 deletions contracts/Core/parameters/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./interfaces/IRewardManagerParams.sol";
import "./interfaces/IStakeManagerParams.sol";
import "./interfaces/IVoteManagerParams.sol";
import "./interfaces/ICollectionManagerParams.sol";
import "./../interface/IStakeManager.sol";
import "../storage/Constants.sol";
import "./ACL.sol";

Expand All @@ -19,6 +20,7 @@ contract Governance is Initializable, ACL, Constants {
IStakeManagerParams public stakeManagerParams;
IVoteManagerParams public voteManagerParams;
ICollectionManagerParams public collectionManagerParams;
IStakeManager public stakeManager;

bytes32 public constant GOVERNER_ROLE = 0x704c992d358ec8f6051d88e5bd9f92457afedcbc3e2d110fcd019b5eda48e52e;

Expand All @@ -37,6 +39,7 @@ contract Governance is Initializable, ACL, Constants {
stakeManagerParams = IStakeManagerParams(stakeManagerAddress);
voteManagerParams = IVoteManagerParams(voteManagerAddress);
collectionManagerParams = ICollectionManagerParams(collectionManagerAddress);
stakeManager = IStakeManager(stakeManagerAddress);
}

function setPenaltyNotRevealNum(uint16 _penaltyNotRevealNumerator) external initialized onlyRole(GOVERNER_ROLE) {
Expand Down Expand Up @@ -106,6 +109,7 @@ contract Governance is Initializable, ACL, Constants {
}

function setMaxAge(uint32 _maxAge) external initialized onlyRole(GOVERNER_ROLE) {
require(_maxAge <= stakeManager.maturitiesLength() * 10000, "Invalid Max Age Update");
emit ParameterChanged(msg.sender, "maxAge", _maxAge, block.timestamp);
rewardManagerParams.setMaxAge(_maxAge);
}
Expand Down
3 changes: 3 additions & 0 deletions test/Governance.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ describe('Governance contract Test', async () => {
let tx = governance.setMaxCommission(toBigNumber('101'));
await assertRevert(tx, 'Invalid Max Commission Update');

tx = governance.setMaxAge(toBigNumber('1010001'));
await assertRevert(tx, 'Invalid Max Age Update');

tx = governance.setSlashParams(toBigNumber('5000000'), toBigNumber('4000000'), toBigNumber('3000000'));
await assertRevert(tx, 'Slash nums addtion exceeds 10mil');

Expand Down

0 comments on commit c8e3cea

Please sign in to comment.