Skip to content
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

chore: test fixes #1005

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions contracts/Core/BlockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,7 @@ contract BlockManager is Initializable, BlockStorage, StateManager, BlockManager
* @param biggestStake biggest Stake that was revealed
* @return isAdded : whether the block was added to the array
*/
function _insertAppropriately(
uint32 epoch,
uint32 blockId,
uint256 iteration,
uint256 biggestStake
) internal returns (bool isAdded) {
function _insertAppropriately(uint32 epoch, uint32 blockId, uint256 iteration, uint256 biggestStake) internal returns (bool isAdded) {
uint8 sortedProposedBlockslength = uint8(sortedProposedBlockIds[epoch].length);

if (sortedProposedBlockslength == 0) {
Expand Down Expand Up @@ -570,11 +565,7 @@ contract BlockManager is Initializable, BlockStorage, StateManager, BlockManager
* @param blockIndex index of the block that is disputed
* @param blockId id of the block being disputed
*/
function _executeDispute(
uint32 epoch,
uint8 blockIndex,
uint32 blockId
) internal {
function _executeDispute(uint32 epoch, uint8 blockIndex, uint32 blockId) internal {
proposedBlocks[epoch][blockId].valid = false;

uint8 sortedProposedBlocksLength = uint8(sortedProposedBlockIds[epoch].length);
Expand Down Expand Up @@ -627,12 +618,12 @@ contract BlockManager is Initializable, BlockStorage, StateManager, BlockManager
// stake * 2^32 < prng * 2^32 * biggestStake
// multiplying by 2^32 since seed2 is bytes32 so rand2 goes from 0 to 2^32
bytes32 seed2 = Random.prngHash(salt, keccak256(abi.encode(stakerId, iteration)));
uint256 rand2 = Random.prng(2**32, seed2);
uint256 rand2 = Random.prng(2 ** 32, seed2);

uint256 biggestStake = voteManager.getStakeSnapshot(epoch, biggestStakerId);
uint256 stake = voteManager.getStakeSnapshot(epoch, stakerId);
// Below line can't be tested since it can't be assured if it returns true or false
if (rand2 * (biggestStake) > stake * (2**32)) return (false);
if (rand2 * (biggestStake) > stake * (2 ** 32)) return (false);
return true;
}
}
10 changes: 4 additions & 6 deletions contracts/Core/CollectionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ contract CollectionManager is Initializable, CollectionStorage, StateManager, Co
* @param assetStatus the status that needs to be set for the collection
* @param id the collection id for which the status needs to change
*/
function setCollectionStatus(bool assetStatus, uint16 id)
external
initialized
onlyRole(COLLECTION_MODIFIER_ROLE)
checkState(State.Confirm, buffer)
{
function setCollectionStatus(
bool assetStatus,
uint16 id
) external initialized onlyRole(COLLECTION_MODIFIER_ROLE) checkState(State.Confirm, buffer) {
require(id != 0, "ID cannot be 0");
require(id <= numCollections, "ID does not exist");

Expand Down
6 changes: 1 addition & 5 deletions contracts/Core/RewardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ contract RewardManager is Initializable, Constants, RewardManagerParams, IReward
* @param stakeValue The Stake that staker had in last epoch
* @param ageValue The age that staker had in last epoch
*/
function _calculateInactivityPenalties(
uint32 epochs,
uint256 stakeValue,
uint32 ageValue
) internal view returns (uint256, uint32) {
function _calculateInactivityPenalties(uint32 epochs, uint256 stakeValue, uint32 ageValue) internal view returns (uint256, uint32) {
uint256 penalty = ((epochs) * (stakeValue * penaltyNotRevealNum)) / BASE_DENOMINATOR;
uint256 newStake = penalty < stakeValue ? stakeValue - penalty : 0;
uint256 penaltyAge = (uint256(epochs) * (uint256(ageValue) * uint256(penaltyAgeNotRevealNum))) / BASE_DENOMINATOR;
Expand Down
33 changes: 5 additions & 28 deletions contracts/Core/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake
}

/// @inheritdoc IStakeManager
function srzrTransfer(
address from,
address to,
uint256 amount,
uint32 stakerId
) external override initialized onlyRole(STOKEN_ROLE) {
function srzrTransfer(address from, address to, uint256 amount, uint32 stakerId) external override initialized onlyRole(STOKEN_ROLE) {
emit SrzrTransfer(from, to, amount, stakerId);
}

Expand Down Expand Up @@ -513,11 +508,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake
}

/// @inheritdoc IStakeManager
function slash(
uint32 epoch,
uint32 stakerId,
address bountyHunter
) external override initialized onlyRole(STAKE_MODIFIER_ROLE) {
function slash(uint32 epoch, uint32 stakerId, address bountyHunter) external override initialized onlyRole(STAKE_MODIFIER_ROLE) {
uint256 _stake = stakers[stakerId].stake;

uint256 bounty;
Expand Down Expand Up @@ -631,13 +622,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake
* @param _id of the staker
* @param _stake the amount of Razor tokens staked
*/
function _setStakerStake(
uint32 _epoch,
uint32 _id,
Constants.StakeChanged reason,
uint256 _prevStake,
uint256 _stake
) internal {
function _setStakerStake(uint32 _epoch, uint32 _id, Constants.StakeChanged reason, uint256 _prevStake, uint256 _stake) internal {
stakers[_id].stake = _stake;
emit StakeChange(_epoch, _id, reason, _prevStake, _stake, block.timestamp);
}
Expand Down Expand Up @@ -667,11 +652,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake
* @param _sAmount The Amount in sRZR
* @param _currentStake The cuurent stake of associated staker
*/
function _convertSRZRToRZR(
uint256 _sAmount,
uint256 _currentStake,
uint256 _totalSupply
) internal pure returns (uint256) {
function _convertSRZRToRZR(uint256 _sAmount, uint256 _currentStake, uint256 _totalSupply) internal pure returns (uint256) {
return ((_sAmount * _currentStake) / _totalSupply);
}

Expand All @@ -681,11 +662,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake
* @param _currentStake The cuurent stake of associated staker
* @param _totalSupply The totalSupply of sRZR
*/
function _convertRZRtoSRZR(
uint256 _amount,
uint256 _currentStake,
uint256 _totalSupply
) internal pure returns (uint256) {
function _convertRZRtoSRZR(uint256 _amount, uint256 _currentStake, uint256 _totalSupply) internal pure returns (uint256) {
// Follwoing require is included to cover case where
// CurrentStake Becomes zero beacues of penalties,
//this is likely scenario when staker stakes is slashed to 0 for invalid block.
Expand Down
6 changes: 1 addition & 5 deletions contracts/Core/StateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ contract StateManager is Constants {
/** @notice a check to ensure the epoch value sent in the function is of the currect epoch
* and was called in the state specified
*/
modifier checkEpochAndState(
State state,
uint32 epoch,
uint8 buffer
) {
modifier checkEpochAndState(State state, uint32 epoch, uint8 buffer) {
// slither-disable-next-line incorrect-equality
require(epoch == _getEpoch(), "incorrect epoch");
// slither-disable-next-line incorrect-equality
Expand Down
12 changes: 2 additions & 10 deletions contracts/Core/VoteManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,13 @@ contract VoteManager is Initializable, VoteStorage, StateManager, VoteManagerPar
}

/// @inheritdoc IVoteManager
function getVoteValue(
uint32 epoch,
uint32 stakerId,
uint16 leafId
) external view override returns (uint256) {
function getVoteValue(uint32 epoch, uint32 stakerId, uint16 leafId) external view override returns (uint256) {
//epoch -> stakerid -> asserId
return votes[epoch][stakerId][leafId];
}

/// @inheritdoc IVoteManager
function getVoteWeight(
uint32 epoch,
uint16 leafId,
uint256 voteValue
) external view override returns (uint256) {
function getVoteWeight(uint32 epoch, uint16 leafId, uint256 voteValue) external view override returns (uint256) {
//epoch -> leafId -> voteValue -> weight
return (voteWeights[epoch][leafId][voteValue]);
}
Expand Down
28 changes: 4 additions & 24 deletions contracts/Core/interface/IStakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ interface IStakeManager {
* @param prevStake previous stake of the staker
* @param _stake updated stake of the staker
*/
function setStakerStake(
uint32 _epoch,
uint32 _id,
Constants.StakeChanged reason,
uint256 prevStake,
uint256 _stake
) external;
function setStakerStake(uint32 _epoch, uint32 _id, Constants.StakeChanged reason, uint256 prevStake, uint256 _stake) external;

/**
* @notice The function is used by the Votemanager reveal function and BlockManager FinalizeDispute
Expand All @@ -29,11 +23,7 @@ interface IStakeManager {
* @param stakerId The ID of the staker who is penalised
* @param bountyHunter The address of the bounty hunter
*/
function slash(
uint32 epoch,
uint32 stakerId,
address bountyHunter
) external;
function slash(uint32 epoch, uint32 stakerId, address bountyHunter) external;

/**
* @notice External function for setting staker age of the staker
Expand All @@ -43,12 +33,7 @@ interface IStakeManager {
* @param _age the updated new age
* @param reason the reason for age change
*/
function setStakerAge(
uint32 _epoch,
uint32 _id,
uint32 _age,
Constants.AgeChanged reason
) external;
function setStakerAge(uint32 _epoch, uint32 _id, uint32 _age, Constants.AgeChanged reason) external;

/**
* @notice External function for setting stakerReward of the staker
Expand Down Expand Up @@ -86,12 +71,7 @@ interface IStakeManager {
* @param amount srzr amount being transferred
* @param stakerId of the staker
*/
function srzrTransfer(
address from,
address to,
uint256 amount,
uint32 stakerId
) external;
function srzrTransfer(address from, address to, uint256 amount, uint32 stakerId) external;

/**
* @param _address Address of the staker
Expand Down
12 changes: 2 additions & 10 deletions contracts/Core/interface/IVoteManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ interface IVoteManager {
* @param leafId seq position of collection in merkle tree
* @return vote value
*/
function getVoteValue(
uint32 epoch,
uint32 stakerId,
uint16 leafId
) external view returns (uint256);
function getVoteValue(uint32 epoch, uint32 stakerId, uint16 leafId) external view returns (uint256);

/**
* @notice returns vote weight of the value of the collection reported
Expand All @@ -37,11 +33,7 @@ interface IVoteManager {
* @param voteValue one of the values of the collection being reported
* @return vote weight of the vote
*/
function getVoteWeight(
uint32 epoch,
uint16 leafId,
uint256 voteValue
) external view returns (uint256);
function getVoteWeight(uint32 epoch, uint16 leafId, uint256 voteValue) external view returns (uint256);

/**
* @notice returns snapshot of influence of the staker when they revealed
Expand Down
6 changes: 1 addition & 5 deletions contracts/Core/parameters/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ contract Governance is Initializable, ACL, Constants {
* @param _burn updated percent value to be set for burn
* @param _keep updated percent value to be set for keep
*/
function setSlashParams(
uint32 _bounty,
uint32 _burn,
uint32 _keep
) external initialized onlyRole(GOVERNER_ROLE) {
function setSlashParams(uint32 _bounty, uint32 _burn, uint32 _keep) external initialized onlyRole(GOVERNER_ROLE) {
require(_bounty + _burn + _keep <= BASE_DENOMINATOR, "Slash nums addtion exceeds 10mil");
emit ParameterChanged(msg.sender, "bountySlashNum", _bounty, block.timestamp);
emit ParameterChanged(msg.sender, "burnSlashNum", _burn, block.timestamp);
Expand Down
4 changes: 2 additions & 2 deletions contracts/Core/parameters/child/BlockManagerParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ abstract contract BlockManagerParams is ACL, IBlockManagerParams, Constants {
uint8 public maxAltBlocks = 5;
uint8 public buffer = 5;
/// @notice reward given to staker whose block is confirmed
uint256 public blockReward = 100 * (10**18);
uint256 public blockReward = 100 * (10 ** 18);
/// @notice minimum amount of stake required to participate
uint256 public minStake = 20000 * (10**18);
uint256 public minStake = 20000 * (10 ** 18);

/// @inheritdoc IBlockManagerParams
function setMaxAltBlocks(uint8 _maxAltBlocks) external override onlyRole(GOVERNANCE_ROLE) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/Core/parameters/child/RewardManagerParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract contract RewardManagerParams is ACL, IRewardManagerParams, Constants {
/// @notice maximum age a staker can have
uint32 public maxAge = 100 * 10000;
/// @notice reward given to staker whose block is confirmed
uint256 public blockReward = 100 * (10**18);
uint256 public blockReward = 100 * (10 ** 18);
/// @notice maximum percentage deviation allowed from medians for all collections
uint32 public maxTolerance = 1_000_000;
/// @notice maximum commission stakers can charge from delegators on their profits
Expand Down
10 changes: 3 additions & 7 deletions contracts/Core/parameters/child/StakeManagerParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ abstract contract StakeManagerParams is ACL, IStakeManagerParams, Constants {
/// @notice slashing params being used if staker is slashed. Slash Penalty = bounty + burned + kept == 100%
SlashNums public slashNums = SlashNums(500_000, 9_500_000, 0);
/// @notice minimum amount of stake required to participate
uint256 public minStake = 20000 * (10**18);
uint256 public minStake = 20000 * (10 ** 18);
/// @notice minimum amount of stake required to become a staker
uint256 public minSafeRazor = 10000 * (10**18);
uint256 public minSafeRazor = 10000 * (10 ** 18);

/// @inheritdoc IStakeManagerParams
function setSlashParams(
uint32 _bounty,
uint32 _burn,
uint32 _keep
) external override onlyRole(GOVERNANCE_ROLE) {
function setSlashParams(uint32 _bounty, uint32 _burn, uint32 _keep) external override onlyRole(GOVERNANCE_ROLE) {
require(_bounty + _burn + _keep <= BASE_DENOMINATOR, "params sum exceeds denominator");
// slither-disable-next-line events-maths
slashNums = SlashNums(_bounty, _burn, _keep);
Expand Down
2 changes: 1 addition & 1 deletion contracts/Core/parameters/child/VoteManagerParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract contract VoteManagerParams is ACL, IVoteManagerParams, Constants {
/// @notice maximum number of collections that can be assigned to the staker
uint16 public toAssign = 3;
/// @notice minimum amount of stake required to participate
uint256 public minStake = 20000 * (10**18);
uint256 public minStake = 20000 * (10 ** 18);

/// @inheritdoc IVoteManagerParams
function setMinStake(uint256 _minStake) external override onlyRole(GOVERNANCE_ROLE) {
Expand Down
6 changes: 1 addition & 5 deletions contracts/Core/parameters/interfaces/IStakeManagerParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ interface IStakeManagerParams {
* @param _burn updated percent value to be set for burn
* @param _keep updated percent value to be set for keep
*/
function setSlashParams(
uint32 _bounty,
uint32 _burn,
uint32 _keep
) external;
function setSlashParams(uint32 _bounty, uint32 _burn, uint32 _keep) external;

/**
* @notice changing the number of epochs for which the RAZORs are locked after initiating withdraw
Expand Down
6 changes: 1 addition & 5 deletions contracts/tokenization/IStakedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ interface IStakedToken is IERC20 {
*
* - `account` cannot be the zero address.
*/
function mint(
address account,
uint256 amount,
uint256 razorDeposited
) external returns (bool);
function mint(address account, uint256 amount, uint256 razorDeposited) external returns (bool);

/**
* @dev Destroys `amount` tokens from `account`, reducing the
Expand Down
12 changes: 2 additions & 10 deletions contracts/tokenization/StakedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ contract StakedToken is ERC20, IStakedToken {
}

/// @inheritdoc IStakedToken
function mint(
address account,
uint256 amount,
uint256 _razorDeposited
) external override onlyOwner returns (bool) {
function mint(address account, uint256 amount, uint256 _razorDeposited) external override onlyOwner returns (bool) {
razorDeposited[account] = razorDeposited[account] + _razorDeposited;
_mint(account, amount);
return true;
Expand All @@ -65,11 +61,7 @@ contract StakedToken is ERC20, IStakedToken {
* @param to address where sRZR is being transferred to
* @param amount amount sRZR being transferred
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
//mint : addition, would happen in case of delegate or stake
//burn : subtraction, would happeen when staker calls withdraw
//transfer : add and sub
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@razor-network/contracts",
"version": "2.0.0",
"version": "2.0.1",
"description": "These are the contracts for Razor network testnet",
"author": "Razor Network",
"private": false,
Expand Down
Loading
Loading