-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Staking/Validator] Refine structures & fix TODO (#18)
### Description - Refine structures - Adopt `RONTransferHelper` and has contracts - Move `validatorCandidates` storage to Ronin Validator contract - Distribute reward for delegator at the ending of a period - Remove insufficient candidates at the end of an epoch - Reset unavailability indicator
- Loading branch information
Showing
47 changed files
with
995 additions
and
1,035 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/utils/StorageSlot.sol"; | ||
|
||
abstract contract HasProxyAdmin { | ||
// bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1)); | ||
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; | ||
|
||
modifier onlyAdmin() { | ||
require(msg.sender == _getAdmin(), "HasProxyAdmin: unauthorized sender"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Returns proxy admin. | ||
*/ | ||
function _getAdmin() internal view returns (address) { | ||
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./HasProxyAdmin.sol"; | ||
import "../interfaces/collections/IHasSlashIndicatorContract.sol"; | ||
import "../interfaces/ISlashIndicator.sol"; | ||
|
||
contract HasSlashIndicatorContract is IHasSlashIndicatorContract, HasProxyAdmin { | ||
ISlashIndicator internal _slashIndicatorContract; | ||
|
||
modifier onlySlashIndicatorContract() { | ||
require( | ||
slashIndicatorContract() == msg.sender, | ||
"HasSlashIndicatorContract: method caller must be slash indicator contract" | ||
); | ||
_; | ||
} | ||
|
||
/** | ||
* @inheritdoc IHasSlashIndicatorContract | ||
*/ | ||
function slashIndicatorContract() public view override returns (address) { | ||
return address(_slashIndicatorContract); | ||
} | ||
|
||
/** | ||
* @inheritdoc IHasSlashIndicatorContract | ||
*/ | ||
function setSlashIndicatorContract(address _addr) external override onlyAdmin { | ||
_setSlashIndicatorContract(_addr); | ||
} | ||
|
||
/** | ||
* @dev Sets the slash indicator contract. | ||
* | ||
* Requirements: | ||
* - The new address is a contract. | ||
* | ||
* Emits the event `SlashIndicatorContractUpdated`. | ||
* | ||
*/ | ||
function _setSlashIndicatorContract(address _addr) internal { | ||
_slashIndicatorContract = ISlashIndicator(_addr); | ||
emit SlashIndicatorContractUpdated(_addr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./HasProxyAdmin.sol"; | ||
import "../interfaces/collections/IHasStakingContract.sol"; | ||
import "../interfaces/IStaking.sol"; | ||
|
||
contract HasStakingContract is IHasStakingContract, HasProxyAdmin { | ||
IStaking internal _stakingContract; | ||
|
||
modifier onlyStakingContract() { | ||
require(stakingContract() == msg.sender, "HasStakingManager: method caller must be staking contract"); | ||
_; | ||
} | ||
|
||
/** | ||
* @inheritdoc IHasStakingContract | ||
*/ | ||
function stakingContract() public view override returns (address) { | ||
return address(_stakingContract); | ||
} | ||
|
||
/** | ||
* @inheritdoc IHasStakingContract | ||
*/ | ||
function setStakingContract(address _addr) external override onlyAdmin { | ||
_setStakingContract(_addr); | ||
} | ||
|
||
/** | ||
* @dev Sets the staking contract. | ||
* | ||
* Requirements: | ||
* - The new address is a contract. | ||
* | ||
* Emits the event `StakingContractUpdated`. | ||
* | ||
*/ | ||
function _setStakingContract(address _addr) internal { | ||
_stakingContract = IStaking(_addr); | ||
emit StakingContractUpdated(_addr); | ||
} | ||
} |
Oops, something went wrong.