Skip to content

Commit

Permalink
v0.5.1 (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxqbao authored May 17, 2023
2 parents 620a28f + 8134c49 commit 63f1b56
Show file tree
Hide file tree
Showing 67 changed files with 4,884 additions and 1,305 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ refs/
.vscode
remix-compiler.config.js
foundry
.npmrc
14 changes: 7 additions & 7 deletions contracts/interfaces/staking/ICandidateStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import "./IRewardPool.sol";
interface ICandidateStaking is IRewardPool {
/// @dev Emitted when the minimum staking amount for being a validator is updated.
event MinValidatorStakingAmountUpdated(uint256 threshold);
/// @dev Emitted when the max commission rate is updated.
event MaxCommissionRateUpdated(uint256 maxRate);
/// @dev Emitted when the commission rate range is updated.
event CommissionRateRangeUpdated(uint256 minRate, uint256 maxRate);

/// @dev Emitted when the pool admin staked for themself.
event Staked(address indexed consensuAddr, uint256 amount);
Expand Down Expand Up @@ -57,9 +57,9 @@ interface ICandidateStaking is IRewardPool {
function minValidatorStakingAmount() external view returns (uint256);

/**
* @dev Returns the max commission rate that the candidate can set.
* @dev Returns the commission rate range that the candidate can set.
*/
function maxCommissionRate() external view returns (uint256);
function getCommissionRateRange() external view returns (uint256 _minRange, uint256 _maxRange);

/**
* @dev Sets the minimum threshold for being a validator candidate.
Expand All @@ -73,15 +73,15 @@ interface ICandidateStaking is IRewardPool {
function setMinValidatorStakingAmount(uint256) external;

/**
* @dev Sets the max commission rate that a candidate can set.
* @dev Sets the commission rate range that a candidate can set.
*
* Requirements:
* - The method caller is admin.
*
* Emits the `MaxCommissionRateUpdated` event.
* Emits the `CommissionRateRangeUpdated` event.
*
*/
function setMaxCommissionRate(uint256 _maxRate) external;
function setCommissionRateRange(uint256 _minRate, uint256 _maxRate) external;

/**
* @dev Proposes a candidate to become a validator.
Expand Down
4 changes: 2 additions & 2 deletions contracts/ronin/Maintenance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ contract Maintenance is IMaintenance, HasValidatorContract, Initializable {
"Maintenance: start block is out of offset"
);
require(_startedAtBlock < _endedAtBlock, "Maintenance: start block must be less than end block");
uint256 _blockPeriod = _endedAtBlock - _startedAtBlock;
uint256 _maintenanceElapsed = _endedAtBlock - _startedAtBlock + 1;
require(
_blockPeriod.inRange(minMaintenanceDurationInBlock, maxMaintenanceDurationInBlock),
_maintenanceElapsed.inRange(minMaintenanceDurationInBlock, maxMaintenanceDurationInBlock),
"Maintenance: invalid maintenance duration"
);
require(_validator.epochEndingAt(_startedAtBlock - 1), "Maintenance: start block is not at the start of an epoch");
Expand Down
11 changes: 0 additions & 11 deletions contracts/ronin/gateway/PauseEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ contract PauseEnforcer is AccessControlEnumerable {
emit EmergencyUnpaused(msg.sender);
}

/**
* @dev Helper function to reset emergency status.
*/
function resetEmergency() external {
require(
hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(SENTRY_ROLE, msg.sender),
"PauseEnforcer: Unauthorized reset"
);
emergency = false;
}

/**
* @dev Setter for `target`.
*
Expand Down
25 changes: 13 additions & 12 deletions contracts/ronin/staking/CandidateStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf

/// @dev The max commission rate that the validator can set (in range of [0;100_00] means [0-100%])
uint256 internal _maxCommissionRate;
/// @dev The min commission rate that the validator can set (in range of [0;100_00] means [0-100%])
uint256 internal _minCommissionRate;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
*/
uint256[49] ______gap;
uint256[48] ______gap;

/**
* @inheritdoc ICandidateStaking
Expand All @@ -31,8 +33,8 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf
/**
* @inheritdoc ICandidateStaking
*/
function maxCommissionRate() external view override returns (uint256) {
return _maxCommissionRate;
function getCommissionRateRange() external view override returns (uint256, uint256) {
return (_minCommissionRate, _maxCommissionRate);
}

/**
Expand All @@ -45,8 +47,8 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf
/**
* @inheritdoc ICandidateStaking
*/
function setMaxCommissionRate(uint256 _maxRate) external override onlyAdmin {
_setMaxCommissionRate(_maxRate);
function setCommissionRateRange(uint256 _minRate, uint256 _maxRate) external override onlyAdmin {
_setCommissionRateRange(_minRate, _maxRate);
}

/**
Expand All @@ -60,7 +62,7 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf
uint256 _commissionRate
) external payable override nonReentrant {
if (isAdminOfActivePool(msg.sender)) revert ErrAdminOfAnyActivePoolForbidden(msg.sender);
if (_commissionRate > _maxCommissionRate) revert ErrInvalidCommissionRate();
if (_commissionRate > _maxCommissionRate || _commissionRate < _minCommissionRate) revert ErrInvalidCommissionRate();

uint256 _amount = msg.value;
address payable _poolAdmin = payable(msg.sender);
Expand Down Expand Up @@ -91,7 +93,7 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf
uint256 _effectiveDaysOnwards,
uint256 _commissionRate
) external override poolIsActive(_consensusAddr) onlyPoolAdmin(_stakingPool[_consensusAddr], msg.sender) {
if (_commissionRate > _maxCommissionRate) revert ErrInvalidCommissionRate();
if (_commissionRate > _maxCommissionRate || _commissionRate < _minCommissionRate) revert ErrInvalidCommissionRate();
_validatorContract.execRequestUpdateCommissionRate(_consensusAddr, _effectiveDaysOnwards, _commissionRate);
}

Expand Down Expand Up @@ -192,8 +194,6 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf
if (!_unsafeSendRON(_poolAdmin, 0)) revert ErrCannotInitTransferRON(_poolAdmin, "pool admin");
if (!_unsafeSendRON(_treasuryAddr, 0)) revert ErrCannotInitTransferRON(_treasuryAddr, "treasury");
if (_amount < _minValidatorStakingAmount) revert ErrInsufficientStakingAmount();
if (_commissionRate > _maxCommissionRate) revert ErrInvalidCommissionRate();

if (_poolAdmin != _candidateAdmin || _candidateAdmin != _treasuryAddr) revert ErrThreeInteractionAddrsNotEqual();

address[] memory _diffAddrs = new address[](3);
Expand Down Expand Up @@ -269,9 +269,10 @@ abstract contract CandidateStaking is BaseStaking, ICandidateStaking, GlobalConf
* Emits the `MaxCommissionRateUpdated` event.
*
*/
function _setMaxCommissionRate(uint256 _maxRate) internal {
if (_maxRate > _MAX_PERCENTAGE) revert ErrInvalidCommissionRate();
function _setCommissionRateRange(uint256 _minRate, uint256 _maxRate) internal {
if (_maxRate > _MAX_PERCENTAGE || _minRate > _maxRate) revert ErrInvalidCommissionRate();
_maxCommissionRate = _maxRate;
emit MaxCommissionRateUpdated(_maxRate);
_minCommissionRate = _minRate;
emit CommissionRateRangeUpdated(_minRate, _maxRate);
}
}
9 changes: 6 additions & 3 deletions contracts/ronin/staking/DelegatorStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ abstract contract DelegatorStaking is BaseStaking, IDelegatorStaking {
) private notPoolAdmin(_pool, _delegator) {
if (_amount == 0) revert ErrUndelegateZeroAmount();
if (_pool.delegatingAmount[_delegator] < _amount) revert ErrInsufficientDelegatingAmount();
if (_pool.lastDelegatingTimestamp[_delegator] + _cooldownSecsToUndelegate >= block.timestamp) {
revert ErrUndelegateTooEarly();
}

if (
_validatorContract.isValidatorCandidate(_pool.addr) &&
_validatorContract.getCandidateInfo(_pool.addr).revokingTimestamp == 0 && // if candidate is not on renunciation
_pool.lastDelegatingTimestamp[_delegator] + _cooldownSecsToUndelegate >= block.timestamp // delegator is still in cooldown
) revert ErrUndelegateTooEarly();

_changeDelegatingAmount(
_pool,
Expand Down
2 changes: 1 addition & 1 deletion contracts/ronin/staking/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract Staking is IStaking, CandidateStaking, DelegatorStaking, Initializable
) external initializer {
_setValidatorContract(__validatorContract);
_setMinValidatorStakingAmount(__minValidatorStakingAmount);
_setMaxCommissionRate(__maxCommissionRate);
_setCommissionRateRange(0, __maxCommissionRate);
_setCooldownSecsToUndelegate(__cooldownSecsToUndelegate);
_setWaitingSecsToRevoke(__waitingSecsToRevoke);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/ronin/validator/CoinbaseExecution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ abstract contract CoinbaseExecution is
}

_reward -= _cutOffReward;
uint256 _maxRate = _stakingContract.maxCommissionRate();
uint256 _rate = Math.min(_candidateInfo[msg.sender].commissionRate, _maxRate);
(uint256 _minRate, uint256 _maxRate) = _stakingContract.getCommissionRateRange();
uint256 _rate = Math.max(Math.min(_candidateInfo[msg.sender].commissionRate, _maxRate), _minRate);
uint256 _miningAmount = (_rate * _reward) / _MAX_PERCENTAGE;
_miningReward[msg.sender] += _miningAmount;

Expand Down
62 changes: 31 additions & 31 deletions deployments/ronin-mainnet/MaintenanceLogic.json

Large diffs are not rendered by default.

72 changes: 31 additions & 41 deletions deployments/ronin-mainnet/RoninGatewayPauseEnforcer.json

Large diffs are not rendered by default.

176 changes: 88 additions & 88 deletions deployments/ronin-mainnet/RoninValidatorSetLogic.json

Large diffs are not rendered by default.

210 changes: 120 additions & 90 deletions deployments/ronin-mainnet/StakingLogic.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

164 changes: 82 additions & 82 deletions deployments/ronin-testnet/BridgeTrackingLogic.json

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions deployments/ronin-testnet/BridgeTrackingProxy.json

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions deployments/ronin-testnet/MaintenanceLogic.json

Large diffs are not rendered by default.

Loading

0 comments on commit 63f1b56

Please sign in to comment.