Skip to content

Commit

Permalink
Release/v0.7.0-testnet: Profile contract and change addresses (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxqbao authored Nov 27, 2023
2 parents 0568342 + b2b0be0 commit 4e0465e
Show file tree
Hide file tree
Showing 127 changed files with 10,507 additions and 3,761 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ on:
- "release/**"
pull_request:
branches:
- main
- mainnet
- testnet
- "release/**"
- "feat/**"

permissions:
packages: read
Expand Down
34 changes: 17 additions & 17 deletions contracts/extensions/forwarder/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ contract Forwarder is AccessControlEnumerable {
/**
* @dev Initializes the forwarder with an initial target address and a contract admin.
*/
constructor(address[] memory _targets, address _admin, address _moderator) payable {
for (uint _i = 0; _i < _targets.length; ) {
_setupRole(TARGET_ROLE, _targets[_i]);
constructor(address[] memory targets, address admin, address moderator) payable {
for (uint i = 0; i < targets.length; ) {
_setupRole(TARGET_ROLE, targets[i]);

unchecked {
++_i;
++i;
}
}
_setupRole(DEFAULT_ADMIN_ROLE, _admin);
_setupRole(MODERATOR_ROLE, _moderator);
_setupRole(DEFAULT_ADMIN_ROLE, admin);
_setupRole(MODERATOR_ROLE, moderator);
}

modifier validTarget(address _target) {
_checkRole(TARGET_ROLE, _target);
modifier validTarget(address target) {
_checkRole(TARGET_ROLE, target);
_;
}

Expand All @@ -61,21 +61,21 @@ contract Forwarder is AccessControlEnumerable {
* - Only user with {MODERATOR_ROLE} can call this method.
*/
function functionCall(
address _target,
bytes memory _data,
uint256 _val
) external payable validTarget(_target) onlyRole(MODERATOR_ROLE) {
if (_val > address(this).balance) revert ErrInvalidForwardValue();
_call(_target, _data, _val);
address target,
bytes memory data,
uint256 val
) external payable validTarget(target) onlyRole(MODERATOR_ROLE) {
if (val > address(this).balance) revert ErrInvalidForwardValue();
_call(target, data, val);
}

/**
* @dev Forwards the current call to `target`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _call(address _target, bytes memory _data, uint256 _value) internal {
(bool _success, bytes memory _res) = _target.call{ value: _value }(_data);
_success.handleRevert(bytes4(_data), _res);
function _call(address target, bytes memory data, uint256 value) internal {
(bool success, bytes memory res) = target.call{ value: value }(data);
success.handleRevert(bytes4(data), res);
}
}
90 changes: 58 additions & 32 deletions contracts/interfaces/IMaintenance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity ^0.8.9;

import { TConsensus } from "../udvts/Types.sol";

interface IMaintenance {
/**
* @dev Error thrown when attempting to schedule an already scheduled event.
Expand Down Expand Up @@ -61,9 +63,9 @@ interface IMaintenance {
}

/// @dev Emitted when a maintenance is scheduled.
event MaintenanceScheduled(address indexed consensusAddr, Schedule);
event MaintenanceScheduled(TConsensus indexed consensusAddr, Schedule);
/// @dev Emitted when a schedule of maintenance is cancelled.
event MaintenanceScheduleCancelled(address indexed consensusAddr);
event MaintenanceScheduleCancelled(TConsensus indexed consensusAddr);
/// @dev Emitted when the maintenance config is updated.
event MaintenanceConfigUpdated(
uint256 minMaintenanceDurationInBlock,
Expand All @@ -75,52 +77,76 @@ interface IMaintenance {
);

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

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

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

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

function checkManyMaintainedById(
address[] calldata candidateIdList,
uint256 atBlock
) external view returns (bool[] memory);

/**
* @dev Returns a bool array indicating the validators maintained in the inclusive range [`_fromBlock`, `_toBlock`] of blocks or not.
*/
function checkManyMaintainedInBlockRange(
address[] calldata _addrList,
TConsensus[] calldata _consensusAddrList,
uint256 _fromBlock,
uint256 _toBlock
) external view returns (bool[] memory);

function checkManyMaintainedInBlockRangeById(
address[] calldata idList,
uint256 fromBlock,
uint256 toBlock
) external view returns (bool[] memory);

/**
* @dev Returns whether the validator `_consensusAddr` has scheduled.
* @dev Returns whether the validator `consensusAddr` has finished cooldown.
*/
function checkScheduled(address _consensusAddr) external view returns (bool);
function checkCooldownEnded(TConsensus consensusAddr) external view returns (bool);

/**
* @dev Returns whether the validator `_consensusAddr`
* @dev Returns whether the validator `consensusAddr` has schedule.
*/
function checkCooldownEnded(address _consensusAddr) external view returns (bool);
function checkScheduled(TConsensus consensusAddr) external view returns (bool);

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

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

/**
* @dev Returns the cooldown to maintain in seconds.
*/
function cooldownSecsToMaintain() external view returns (uint256);

/**
* @dev Sets the duration restriction, start time restriction, and max allowed for maintenance.
Expand All @@ -134,12 +160,12 @@ interface IMaintenance {
*
*/
function setMaintenanceConfig(
uint256 _minMaintenanceDurationInBlock,
uint256 _maxMaintenanceDurationInBlock,
uint256 _minOffsetToStartSchedule,
uint256 _maxOffsetToStartSchedule,
uint256 _maxSchedules,
uint256 _cooldownSecsToMaintain
uint256 minMaintenanceDurationInBlock_,
uint256 maxMaintenanceDurationInBlock_,
uint256 minOffsetToStartSchedule_,
uint256 maxOffsetToStartSchedule_,
uint256 maxSchedules_,
uint256 cooldownSecsToMaintain_
) external;

/**
Expand Down Expand Up @@ -168,12 +194,12 @@ interface IMaintenance {
function maxSchedule() external view returns (uint256);

/**
* @dev Schedules for maintenance from `_startedAtBlock` to `_startedAtBlock`.
* @dev Schedules for maintenance from `startedAtBlock` to `endedAtBlock`.
*
* Requirements:
* - The candidate `_consensusAddr` is the block producer.
* - The method caller is candidate admin of the candidate `_consensusAddr`.
* - The candidate `_consensusAddr` has no schedule yet or the previous is done.
* - The candidate `consensusAddr` is the block producer.
* - The method caller is candidate admin of the candidate `consensusAddr`.
* - The candidate `consensusAddr` has no schedule yet or the previous is done.
* - The total number of schedules is not larger than `maxSchedules()`.
* - The start block must be at least `minOffsetToStartSchedule()` and at most `maxOffsetToStartSchedule()` blocks from the current block.
* - The end block is larger than the start block.
Expand All @@ -184,17 +210,17 @@ interface IMaintenance {
* Emits the event `MaintenanceScheduled`.
*
*/
function schedule(address _consensusAddr, uint256 _startedAtBlock, uint256 _endedAtBlock) external;
function schedule(TConsensus consensusAddr, uint256 startedAtBlock, uint256 endedAtBlock) external;

/**
* @dev Cancel the schedule of maintenance for the `_consensusAddr`.
* @dev Cancel the schedule of maintenance for the `consensusAddr`.
*
* Requirements:
* - The candidate `_consensusAddr` is the block producer.
* - The method caller is candidate admin of the candidate `_consensusAddr`.
* - A schedule for the `_consensusAddr` must be existent and not executed yet.
* - The candidate `consensusAddr` is the block producer.
* - The method caller is candidate admin of the candidate `consensusAddr`.
* - A schedule for the `consensusAddr` must be existent and not executed yet.
*
* Emits the event `MaintenanceScheduleCancelled`.
*/
function cancelSchedule(address _consensusAddr) external;
function cancelSchedule(TConsensus consensusAddr) external;
}
44 changes: 37 additions & 7 deletions contracts/interfaces/IProfile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pragma solidity ^0.8.9;

import { TPoolId, TConsensus } from "../udvts/Types.sol";
import "../utils/RoleAccess.sol";

interface IProfile {
Expand All @@ -15,13 +16,13 @@ interface IProfile {
*/
address id;
/// @dev Consensus address.
address consensus;
TConsensus consensus;
/// @dev Pool admin address.
address admin;
/// @dev Treasury address.
address payable treasury;
/// @dev Address to voting proposal.
address governor;
address __reservedGovernor;
/// @dev Public key for fast finality.
bytes pubkey;
}
Expand Down Expand Up @@ -51,6 +52,15 @@ interface IProfile {
/// @dev Getter to query full `profile` from `id` address.
function getId2Profile(address id) external view returns (CandidateProfile memory profile);

/// @dev Getter to batch query from `id` to `consensus`, return address(0) if the profile not exist.
function getManyId2Consensus(address[] calldata idList) external view returns (TConsensus[] memory consensusList);

/// @dev Getter to backward query from `consensus` address to `id` address.
function getConsensus2Id(TConsensus consensus) external view returns (address id);

/// @dev Getter to backward batch query from `consensus` address to `id` address.
function getManyConsensus2Id(TConsensus[] memory consensus) external view returns (address[] memory);

/**
* @notice Add a new profile.
*
Expand All @@ -61,14 +71,34 @@ interface IProfile {
function addNewProfile(CandidateProfile memory profile) external;

/**
* @notice The candidate admin registers a new profile.
* @dev Cross-contract function to add/update new profile of a validator candidate when they
* applying for candidate role.
*
* @dev Requirements:
* - The profile must not be existent before.
* - Only user with candidate admin role can call this method.
* Requirements:
* - Only `stakingContract` can call this method.
*/
function execApplyValidatorCandidate(address admin, address id, address treasury, bytes calldata pubkey) external;

function registerProfile(CandidateProfile memory profile) external;
/**
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
*
* Emit an {ProfileAddressChanged}.
*/
function requestChangeAdminAddress(address id, address newAdminAddr) external;

/**
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
*
* Emit an {ProfileAddressChanged}.
*/
function requestChangeConsensusAddr(address id, TConsensus newConsensusAddr) external;

/**
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
*
* Emit an {ProfileAddressChanged}.
*/
function requestChangeTreasuryAddr(address id, address payable newTreasury) external;

/**
* @notice The candidate admin changes the public key.
Expand Down
24 changes: 12 additions & 12 deletions contracts/interfaces/IRoninGovernanceAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import "../utils/CommonErrors.sol";
interface IRoninGovernanceAdmin {
/// @dev Emitted when an emergency exit poll is created.
event EmergencyExitPollCreated(
bytes32 _voteHash,
address _consensusAddr,
address _recipientAfterUnlockedFund,
uint256 _requestedAt,
uint256 _expiredAt
bytes32 voteHash,
address validatorId,
address recipientAfterUnlockedFund,
uint256 requestedAt,
uint256 expiredAt
);
/// @dev Emitted when an emergency exit poll is approved.
event EmergencyExitPollApproved(bytes32 _voteHash);
event EmergencyExitPollApproved(bytes32 voteHash);
/// @dev Emitted when an emergency exit poll is expired.
event EmergencyExitPollExpired(bytes32 _voteHash);
event EmergencyExitPollExpired(bytes32 voteHash);
/// @dev Emitted when an emergency exit poll is voted.
event EmergencyExitPollVoted(bytes32 indexed _voteHash, address indexed _voter);
event EmergencyExitPollVoted(bytes32 indexed voteHash, address indexed voter);

/**
* @dev Create a vote to agree that an emergency exit is valid and should return the locked funds back.a
Expand All @@ -27,9 +27,9 @@ interface IRoninGovernanceAdmin {
*
*/
function createEmergencyExitPoll(
address _consensusAddr,
address _recipientAfterUnlockedFund,
uint256 _requestedAt,
uint256 _expiredAt
address validatorId,
address recipientAfterUnlockedFund,
uint256 requestedAt,
uint256 expiredAt
) external;
}
Loading

0 comments on commit 4e0465e

Please sign in to comment.