-
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.
* Remove bridge operator weight * Add bridge contracts * Update RoninTrustedOrganization * Slash bridge voting feature * Avoid slashing newcomers
- Loading branch information
1 parent
3eb0823
commit c380c4d
Showing
43 changed files
with
2,748 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/security/Pausable.sol"; | ||
import "../interfaces/IQuorum.sol"; | ||
import "./collections/HasProxyAdmin.sol"; | ||
|
||
abstract contract GatewayV2 is HasProxyAdmin, Pausable, IQuorum { | ||
uint256 internal _num; | ||
uint256 internal _denom; | ||
|
||
address private ______deprecated; | ||
uint256 public nonce; | ||
|
||
/** | ||
* @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[50] private ______gap; | ||
|
||
/** | ||
* @dev See {IQuorum-getThreshold}. | ||
*/ | ||
function getThreshold() external view virtual returns (uint256, uint256) { | ||
return (_num, _denom); | ||
} | ||
|
||
/** | ||
* @dev See {IQuorum-checkThreshold}. | ||
*/ | ||
function checkThreshold(uint256 _voteWeight) external view virtual returns (bool) { | ||
return _voteWeight * _denom >= _num * _getTotalWeight(); | ||
} | ||
|
||
/** | ||
* @dev See {IQuorum-setThreshold}. | ||
*/ | ||
function setThreshold(uint256 _numerator, uint256 _denominator) | ||
external | ||
virtual | ||
onlyAdmin | ||
returns (uint256, uint256) | ||
{ | ||
return _setThreshold(_numerator, _denominator); | ||
} | ||
|
||
/** | ||
* @dev Triggers paused state. | ||
*/ | ||
function pause() external onlyAdmin { | ||
_pause(); | ||
} | ||
|
||
/** | ||
* @dev Triggers unpaused state. | ||
*/ | ||
function unpause() external onlyAdmin { | ||
_unpause(); | ||
} | ||
|
||
/** | ||
* @dev See {IQuorum-minimumVoteWeight}. | ||
*/ | ||
function minimumVoteWeight() public view virtual returns (uint256) { | ||
return _minimumVoteWeight(_getTotalWeight()); | ||
} | ||
|
||
/** | ||
* @dev Sets threshold and returns the old one. | ||
* | ||
* Emits the `ThresholdUpdated` event. | ||
* | ||
*/ | ||
function _setThreshold(uint256 _numerator, uint256 _denominator) | ||
internal | ||
virtual | ||
returns (uint256 _previousNum, uint256 _previousDenom) | ||
{ | ||
require(_numerator <= _denominator, "GatewayV2: invalid threshold"); | ||
_previousNum = _num; | ||
_previousDenom = _denom; | ||
_num = _numerator; | ||
_denom = _denominator; | ||
emit ThresholdUpdated(nonce++, _numerator, _denominator, _previousNum, _previousDenom); | ||
} | ||
|
||
/** | ||
* @dev Returns minimum vote weight. | ||
*/ | ||
function _minimumVoteWeight(uint256 _totalWeight) internal view virtual returns (uint256) { | ||
return (_num * _totalWeight + _denom - 1) / _denom; | ||
} | ||
|
||
/** | ||
* @dev Returns the total weight. | ||
*/ | ||
function _getTotalWeight() internal view virtual returns (uint256); | ||
} |
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,61 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./collections/HasProxyAdmin.sol"; | ||
import "../libraries/Transfer.sol"; | ||
|
||
abstract contract MinimumWithdrawal is HasProxyAdmin { | ||
/// @dev Emitted when the minimum thresholds are updated | ||
event MinimumThresholdsUpdated(address[] tokens, uint256[] threshold); | ||
|
||
/// @dev Mapping from token address => minimum thresholds | ||
mapping(address => uint256) public minimumThreshold; | ||
|
||
/** | ||
* @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[50] private ______gap; | ||
|
||
/** | ||
* @dev Sets the minimum thresholds to withdraw. | ||
* | ||
* Requirements: | ||
* - The method caller is admin. | ||
* - The arrays have the same length and its length larger than 0. | ||
* | ||
* Emits the `MinimumThresholdsUpdated` event. | ||
* | ||
*/ | ||
function setMinimumThresholds(address[] calldata _tokens, uint256[] calldata _thresholds) external virtual onlyAdmin { | ||
require(_tokens.length > 0, "MinimumWithdrawal: invalid array length"); | ||
_setMinimumThresholds(_tokens, _thresholds); | ||
} | ||
|
||
/** | ||
* @dev Sets minimum thresholds. | ||
* | ||
* Requirements: | ||
* - The array lengths are equal. | ||
* | ||
* Emits the `MinimumThresholdsUpdated` event. | ||
* | ||
*/ | ||
function _setMinimumThresholds(address[] calldata _tokens, uint256[] calldata _thresholds) internal virtual { | ||
require(_tokens.length == _thresholds.length, "MinimumWithdrawal: invalid array length"); | ||
for (uint256 _i; _i < _tokens.length; _i++) { | ||
minimumThreshold[_tokens[_i]] = _thresholds[_i]; | ||
} | ||
emit MinimumThresholdsUpdated(_tokens, _thresholds); | ||
} | ||
|
||
/** | ||
* @dev Checks whether the request is larger than or equal to the minimum threshold. | ||
*/ | ||
function _checkWithdrawal(Transfer.Request calldata _request) internal view { | ||
require( | ||
_request.info.erc != Token.Standard.ERC20 || _request.info.quantity >= minimumThreshold[_request.tokenAddr], | ||
"MinimumWithdrawal: query for too small quantity" | ||
); | ||
} | ||
} |
Oops, something went wrong.