Split ERC20Votes and ERC20VotesComp (#2706)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -29,7 +29,7 @@ library SafeCast {
|
||||
* - input must fit into 224 bits
|
||||
*/
|
||||
function toUint224(uint256 value) internal pure returns (uint224) {
|
||||
require(value < 2**224, "SafeCast: value doesn\'t fit in 224 bits");
|
||||
require(value <= type(uint224).max, "SafeCast: value doesn\'t fit in 224 bits");
|
||||
return uint224(value);
|
||||
}
|
||||
|
||||
@ -44,10 +44,25 @@ library SafeCast {
|
||||
* - input must fit into 128 bits
|
||||
*/
|
||||
function toUint128(uint256 value) internal pure returns (uint128) {
|
||||
require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
|
||||
require(value <= type(uint128).max, "SafeCast: value doesn\'t fit in 128 bits");
|
||||
return uint128(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the downcasted uint96 from uint256, reverting on
|
||||
* overflow (when the input is greater than largest uint96).
|
||||
*
|
||||
* Counterpart to Solidity's `uint96` operator.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - input must fit into 96 bits
|
||||
*/
|
||||
function toUint96(uint256 value) internal pure returns (uint96) {
|
||||
require(value <= type(uint96).max, "SafeCast: value doesn\'t fit in 96 bits");
|
||||
return uint96(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the downcasted uint64 from uint256, reverting on
|
||||
* overflow (when the input is greater than largest uint64).
|
||||
@ -59,7 +74,7 @@ library SafeCast {
|
||||
* - input must fit into 64 bits
|
||||
*/
|
||||
function toUint64(uint256 value) internal pure returns (uint64) {
|
||||
require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits");
|
||||
require(value <= type(uint64).max, "SafeCast: value doesn\'t fit in 64 bits");
|
||||
return uint64(value);
|
||||
}
|
||||
|
||||
@ -74,7 +89,7 @@ library SafeCast {
|
||||
* - input must fit into 32 bits
|
||||
*/
|
||||
function toUint32(uint256 value) internal pure returns (uint32) {
|
||||
require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits");
|
||||
require(value <= type(uint32).max, "SafeCast: value doesn\'t fit in 32 bits");
|
||||
return uint32(value);
|
||||
}
|
||||
|
||||
@ -89,7 +104,7 @@ library SafeCast {
|
||||
* - input must fit into 16 bits
|
||||
*/
|
||||
function toUint16(uint256 value) internal pure returns (uint16) {
|
||||
require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits");
|
||||
require(value <= type(uint16).max, "SafeCast: value doesn\'t fit in 16 bits");
|
||||
return uint16(value);
|
||||
}
|
||||
|
||||
@ -104,7 +119,7 @@ library SafeCast {
|
||||
* - input must fit into 8 bits.
|
||||
*/
|
||||
function toUint8(uint256 value) internal pure returns (uint8) {
|
||||
require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits");
|
||||
require(value <= type(uint8).max, "SafeCast: value doesn\'t fit in 8 bits");
|
||||
return uint8(value);
|
||||
}
|
||||
|
||||
@ -134,7 +149,7 @@ library SafeCast {
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function toInt128(int256 value) internal pure returns (int128) {
|
||||
require(value >= -2**127 && value < 2**127, "SafeCast: value doesn\'t fit in 128 bits");
|
||||
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn\'t fit in 128 bits");
|
||||
return int128(value);
|
||||
}
|
||||
|
||||
@ -152,7 +167,7 @@ library SafeCast {
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function toInt64(int256 value) internal pure returns (int64) {
|
||||
require(value >= -2**63 && value < 2**63, "SafeCast: value doesn\'t fit in 64 bits");
|
||||
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn\'t fit in 64 bits");
|
||||
return int64(value);
|
||||
}
|
||||
|
||||
@ -170,7 +185,7 @@ library SafeCast {
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function toInt32(int256 value) internal pure returns (int32) {
|
||||
require(value >= -2**31 && value < 2**31, "SafeCast: value doesn\'t fit in 32 bits");
|
||||
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn\'t fit in 32 bits");
|
||||
return int32(value);
|
||||
}
|
||||
|
||||
@ -188,7 +203,7 @@ library SafeCast {
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function toInt16(int256 value) internal pure returns (int16) {
|
||||
require(value >= -2**15 && value < 2**15, "SafeCast: value doesn\'t fit in 16 bits");
|
||||
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn\'t fit in 16 bits");
|
||||
return int16(value);
|
||||
}
|
||||
|
||||
@ -206,7 +221,7 @@ library SafeCast {
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function toInt8(int256 value) internal pure returns (int8) {
|
||||
require(value >= -2**7 && value < 2**7, "SafeCast: value doesn\'t fit in 8 bits");
|
||||
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn\'t fit in 8 bits");
|
||||
return int8(value);
|
||||
}
|
||||
|
||||
@ -218,7 +233,8 @@ library SafeCast {
|
||||
* - input must be less than or equal to maxInt256.
|
||||
*/
|
||||
function toInt256(uint256 value) internal pure returns (int256) {
|
||||
require(value < 2**255, "SafeCast: value doesn't fit in an int256");
|
||||
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
|
||||
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
|
||||
return int256(value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user