Skip to content

Commit

Permalink
Merge 'dev' to main branch (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ducthotran2010 authored Dec 6, 2022
2 parents d9b52c0 + 04de1b5 commit cab9010
Show file tree
Hide file tree
Showing 62 changed files with 2,046 additions and 953 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
test:
uses: axieinfinity/workflows-samples/.github/workflows/testing-node.yml@main
with:
node_version: v14.18.1
node_version: v14.18.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ The validators will be slashed when they do not provide good service for Ronin n

| Properties | Explanation |
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| `gainCreditScore` | The max gained number of credit score per period. |
| `gainCreditScore` | The score to gain per period. |
| `maxCreditScore` | The max number of credit score that a validator can hold. |
| `bailOutCostMultiplier` | The number that will be multiplied with the remaining jailed time to get the cost of bailing out. |
| `cutOffPercentageAfterBailout` | The percentage of reward that the block producer will be cut off from until the end of the period after bailing out. |
Expand Down
8 changes: 4 additions & 4 deletions contracts/extensions/GatewayV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ abstract contract GatewayV2 is HasProxyAdmin, Pausable, IQuorum {
uint256[50] private ______gap;

/**
* @dev See {IQuorum-getThreshold}.
* @inheritdoc IQuorum
*/
function getThreshold() external view virtual returns (uint256, uint256) {
return (_num, _denom);
}

/**
* @dev See {IQuorum-checkThreshold}.
* @inheritdoc IQuorum
*/
function checkThreshold(uint256 _voteWeight) external view virtual returns (bool) {
return _voteWeight * _denom >= _num * _getTotalWeight();
}

/**
* @dev See {IQuorum-setThreshold}.
* @inheritdoc IQuorum
*/
function setThreshold(uint256 _numerator, uint256 _denominator)
external
Expand All @@ -59,7 +59,7 @@ abstract contract GatewayV2 is HasProxyAdmin, Pausable, IQuorum {
}

/**
* @dev See {IQuorum-minimumVoteWeight}.
* @inheritdoc IQuorum
*/
function minimumVoteWeight() public view virtual returns (uint256) {
return _minimumVoteWeight(_getTotalWeight());
Expand Down
4 changes: 2 additions & 2 deletions contracts/extensions/GovernanceAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract GovernanceAdmin is CoreGovernance, HasRoninTrustedOrganizationContract,
}

/**
* @dev Override {CoreGovernance-_getMinimumVoteWeight}.
* @dev Override `CoreGovernance-_getMinimumVoteWeight`.
*/
function _getMinimumVoteWeight() internal view virtual override returns (uint256) {
(bool _success, bytes memory _returndata) = roninTrustedOrganizationContract().staticcall(
Expand All @@ -106,7 +106,7 @@ contract GovernanceAdmin is CoreGovernance, HasRoninTrustedOrganizationContract,
}

/**
* @dev Override {CoreGovernance-_getTotalWeights}.
* @dev Override `CoreGovernance-_getTotalWeights`.
*/
function _getTotalWeights() internal view virtual override returns (uint256) {
(bool _success, bytes memory _returndata) = roninTrustedOrganizationContract().staticcall(
Expand Down
2 changes: 1 addition & 1 deletion contracts/extensions/WithdrawalLimitation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract contract WithdrawalLimitation is GatewayV2 {
uint256[50] private ______gap;

/**
* @dev Override {GatewayV2-setThreshold}.
* @dev Override `GatewayV2-setThreshold`.
*
* Requirements:
* - The high-tier vote weight threshold must equal to or larger than the normal threshold.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IBridgeTracking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface IBridgeTracking {
/**
* @dev Returns the total number of ballots of bridge operators at the specific period `_period`.
*/
function bulkTotalBallotsOf(uint256 _period, address[] calldata _bridgeOperators)
function getManyTotalBallots(uint256 _period, address[] calldata _bridgeOperators)
external
view
returns (uint256[] memory);
Expand Down
42 changes: 21 additions & 21 deletions contracts/interfaces/IMaintenance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ interface IMaintenance {
);

/**
* @dev Returns whether the validator `_consensusAddr` is maintaining at the block number `_block`.
* @dev Returns whether the validator `_consensusAddr` maintained at the block number `_block`.
*/
function maintaining(address _consensusAddr, uint256 _block) external view returns (bool);
function checkMaintained(address _consensusAddr, uint256 _block) external view returns (bool);

/**
* @dev Returns whether the validator `_consensusAddr` was maintaining in the inclusive range [`_fromBlock`, `_toBlock`] of blocks.
* @dev Returns whether the validator `_consensusAddr` maintained in the inclusive range [`_fromBlock`, `_toBlock`] of blocks.
*/
function maintainingInBlockRange(
function checkMaintainedInBlockRange(
address _consensusAddr,
uint256 _fromBlock,
uint256 _toBlock
) external view returns (bool);

/**
* @dev Returns the bool array indicating the validator is maintaining or not.
* @dev Returns the bool array indicating the validators maintained at block number `_block` or not.
*/
function bulkMaintaining(address[] calldata _addrList, uint256 _block) external view returns (bool[] memory);
function checkManyMaintained(address[] calldata _addrList, uint256 _block) external view returns (bool[] memory);

/**
* @dev Returns a bool array indicating the validator was maintaining in the inclusive range [`_fromBlock`, `_toBlock`] of blocks or not.
* @dev Returns a bool array indicating the validators maintained in the inclusive range [`_fromBlock`, `_toBlock`] of blocks or not.
*/
function bulkMaintainingInBlockRange(
function checkManyMaintainedInBlockRange(
address[] calldata _addrList,
uint256 _fromBlock,
uint256 _toBlock
Expand All @@ -51,22 +51,17 @@ interface IMaintenance {
/**
* @dev Returns whether the validator `_consensusAddr` has scheduled.
*/
function scheduled(address _consensusAddr) external view returns (bool);
function checkScheduled(address _consensusAddr) external view returns (bool);

/**
* @dev Returns the detailed schedule of the validator `_consensusAddr`.
*/
function getSchedule(address _consensusAddr) external view returns (Schedule memory);

/**
* @dev Returns the min duration for maintenance in block.
*/
function minMaintenanceDurationInBlock() external view returns (uint256);

/**
* @dev Returns the max duration for maintenance in block.
* @dev Returns the total of current schedules.
*/
function maxMaintenanceDurationInBlock() external view returns (uint256);
function totalSchedules() external view returns (uint256 _count);

/**
* @dev Sets the duration restriction, start time restriction, and max allowed for maintenance.
Expand All @@ -87,6 +82,16 @@ interface IMaintenance {
uint256 _maxSchedules
) external;

/**
* @dev Returns the min duration for maintenance in block.
*/
function minMaintenanceDurationInBlock() external view returns (uint256);

/**
* @dev Returns the max duration for maintenance in block.
*/
function maxMaintenanceDurationInBlock() external view returns (uint256);

/**
* @dev The offset to the min block number that the schedule can start
*/
Expand All @@ -102,11 +107,6 @@ interface IMaintenance {
*/
function maxSchedules() external view returns (uint256);

/**
* @dev Returns the total of current schedules.
*/
function totalSchedules() external view returns (uint256 _count);

/**
* @dev Schedules for maintenance from `_startedAtBlock` to `_startedAtBlock`.
*
Expand Down
24 changes: 12 additions & 12 deletions contracts/interfaces/slash-indicator/ICreditScore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ICreditScore {
* Emits the event `CreditScoresUpdated`.
*
*/
function updateCreditScore(address[] calldata _validators, uint256 _period) external;
function updateCreditScores(address[] calldata _validators, uint256 _period) external;

/**
* @dev A slashed validator use this method to get out of jail.
Expand All @@ -47,23 +47,23 @@ interface ICreditScore {
*
* Emits the event `CreditScoreConfigsUpdated`.
*
* @param _gainCreditScore The max gained number of credit score per period.
* @param _maxCreditScore The max number of credit score that a validator can hold.
* @param _bailOutCostMultiplier The number that will be multiplied with the remaining jailed time to get the cost of bailing out.
* @param _cutOffPercentageAfterBailout The percentage of reward that the block producer will be cut off from until the end of the period after bailing out.
* @param _gainScore The score to gain per period.
* @param _maxScore The max number of credit score that a validator can hold.
* @param _bailOutMultiplier The number that will be multiplied with the remaining jailed time to get the cost of bailing out.
* @param _cutOffPercentage The percentage of reward that the block producer will be cut off from until the end of the period after bailing out.
*
*/
function setCreditScoreConfigs(
uint256 _gainCreditScore,
uint256 _maxCreditScore,
uint256 _bailOutCostMultiplier,
uint256 _cutOffPercentageAfterBailout
uint256 _gainScore,
uint256 _maxScore,
uint256 _bailOutMultiplier,
uint256 _cutOffPercentage
) external;

/**
* @dev Returns the configs related to credit score.
*
* @return _gainCreditScore The max gained number of credit score per period.
* @return _gainCreditScore The score to gain per period.
* @return _maxCreditScore The max number of credit score that a validator can hold.
* @return _bailOutCostMultiplier The number that will be multiplied with the remaining jailed time to get the cost of bailing out.
* @return _cutOffPercentageAfterBailout The percentage of reward that the block producer will be cut off from until the end of the period after bailing out.
Expand All @@ -87,10 +87,10 @@ interface ICreditScore {
/**
* @dev Returns the current credit score of a list of validators.
*/
function getBulkCreditScore(address[] calldata _validators) external view returns (uint256[] memory _resultList);
function getManyCreditScores(address[] calldata _validators) external view returns (uint256[] memory _resultList);

/**
* @dev Returns the whether the `_validator` has been bailed out at the `_period`.
*/
function bailedOutAtPeriod(address _validator, uint256 _period) external view returns (bool);
function checkBailedOutAtPeriod(address _validator, uint256 _period) external view returns (bool);
}
13 changes: 10 additions & 3 deletions contracts/interfaces/slash-indicator/ISlashBridgeOperator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface ISlashBridgeOperator {
event BridgeOperatorSlashingConfigsUpdated(
uint256 missingVotesRatioTier1,
uint256 missingVotesRatioTier2,
uint256 jailDurationForMissingVotesRatioTier2
uint256 jailDurationForMissingVotesRatioTier2,
uint256 skipBridgeOperatorSlashingThreshold
);

/**
Expand All @@ -21,6 +22,8 @@ interface ISlashBridgeOperator {
* block producer will be put in jail if (s)he misses more than this ratio.
* @return _jailDurationForMissingVotesRatioTier2 The number of blocks to jail the corresponding block producer when
* its bridge operator is slashed tier-2.
* @return _skipBridgeOperatorSlashingThreshold The threshold to skip slashing the bridge operator in case the total
* number of votes in the bridge is too small.
*
*/
function getBridgeOperatorSlashingConfigs()
Expand All @@ -29,7 +32,8 @@ interface ISlashBridgeOperator {
returns (
uint256 _missingVotesRatioTier1,
uint256 _missingVotesRatioTier2,
uint256 _jailDurationForMissingVotesRatioTier2
uint256 _jailDurationForMissingVotesRatioTier2,
uint256 _skipBridgeOperatorSlashingThreshold
);

/**
Expand All @@ -46,11 +50,14 @@ interface ISlashBridgeOperator {
* be put in jail if (s)he misses more than this ratio. Values 0-10,000 map to 0%-100%.
* @param _jailDurationTier2 The number of blocks to jail the corresponding block producer when its bridge operator is
* slashed tier-2.
* @param _skipSlashingThreshold The threshold to skip slashing the bridge operator in case the total number of votes
* in the bridge is too small.
*
*/
function setBridgeOperatorSlashingConfigs(
uint256 _ratioTier1,
uint256 _ratioTier2,
uint256 _jailDurationTier2
uint256 _jailDurationTier2,
uint256 _skipSlashingThreshold
) external;
}
26 changes: 26 additions & 0 deletions contracts/interfaces/staking/ICandidateStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ interface ICandidateStaking is IRewardPool {
uint256 amount,
uint256 contractBalance
);
/// @dev Emitted when the staking amount deducted failed, e.g. when the validator gets slashed.
event StakingAmountDeductFailed(
address indexed validator,
address indexed recipient,
uint256 amount,
uint256 contractBalance
);

/**
* @dev Returns the minimum threshold for being a validator candidate.
Expand Down Expand Up @@ -100,6 +107,25 @@ interface ICandidateStaking is IRewardPool {
*/
function unstake(address _consensusAddr, uint256 _amount) external;

/**
* @dev Pool admin requests update validator commission rate. The request will be forwarded to the candidate manager
* contract, and the value is getting updated in {ICandidateManager-execRequestUpdateCommissionRate}.
*
* Requirements:
* - The consensus address is a validator candidate.
* - The method caller is the pool admin.
* - The `_effectiveDaysOnwards` must be equal to or larger than the {CandidateManager-_minEffectiveDaysOnwards}.
* - The `_rate` must be in range of [0_00; 100_00].
*
* Emits the event `CommissionRateUpdated`.
*
*/
function requestUpdateCommissionRate(
address _consensusAddr,
uint256 _effectiveDaysOnwards,
uint256 _commissionRate
) external;

/**
* @dev Renounces being a validator candidate and takes back the delegating/staking amount.
*
Expand Down
8 changes: 4 additions & 4 deletions contracts/interfaces/staking/IRewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ interface IRewardPool is PeriodWrapperConsumer {
/**
* @dev Returns the staking amount of an user.
*/
function stakingAmountOf(address _poolAddr, address _user) external view returns (uint256);
function getStakingAmount(address _poolAddr, address _user) external view returns (uint256);

/**
* @dev Returns the staking amounts of the users.
*/
function bulkStakingAmountOf(address[] calldata _poolAddrs, address[] calldata _userList)
function getManyStakingAmounts(address[] calldata _poolAddrs, address[] calldata _userList)
external
view
returns (uint256[] memory);

/**
* @dev Returns the total staking amount of all users for a pool.
*/
function stakingTotal(address _poolAddr) external view returns (uint256);
function getStakingTotal(address _poolAddr) external view returns (uint256);

/**
* @dev Returns the total staking amounts of all users for the pools `_poolAddrs`.
*/
function bulkStakingTotal(address[] calldata _poolAddrs) external view returns (uint256[] memory);
function getManyStakingTotals(address[] calldata _poolAddrs) external view returns (uint256[] memory);
}
6 changes: 4 additions & 2 deletions contracts/interfaces/staking/IStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ interface IStaking is IRewardPool, IBaseStaking, ICandidateStaking, IDelegatorSt
* Emits the event `Unstaked`.
*
*/
function deductStakingAmount(address _consensusAddr, uint256 _amount) external;
function deductStakingAmount(address _consensusAddr, uint256 _amount)
external
returns (uint256 _actualDeductingAmount);

/**
* @dev Returns the staking pool detail.
Expand All @@ -52,5 +54,5 @@ interface IStaking is IRewardPool, IBaseStaking, ICandidateStaking, IDelegatorSt
/**
* @dev Returns the self-staking amounts of the pools.
*/
function bulkSelfStaking(address[] calldata) external view returns (uint256[] memory);
function getManySelfStakings(address[] calldata) external view returns (uint256[] memory);
}
Loading

0 comments on commit cab9010

Please sign in to comment.