Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"viaIR": true,
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
},
"sources": {
"Basyn.sol": {
"content": "// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\r
\r
pragma solidity ^0.8.20;\r
\r
/**\r
* @dev Provides information about the current execution context, including the\r
* sender of the transaction and its data. While these are generally available\r
* via msg.sender and msg.data, they should not be accessed in such a direct\r
* manner, since when dealing with meta-transactions the account sending and\r
* paying for execution may not be the actual sender (as far as an application\r
* is concerned).\r
*\r
* This contract is only required for intermediate, library-like contracts.\r
*/\r
abstract contract Context {\r
function _msgSender() internal view virtual returns (address) {\r
return msg.sender;\r
}\r
\r
function _msgData() internal view virtual returns (bytes calldata) {\r
return msg.data;\r
}\r
\r
function _contextSuffixLength() internal view virtual returns (uint256) {\r
return 0;\r
}\r
}\r
pragma solidity >=0.8.4;\r
\r
/**\r
* @dev Standard ERC-20 Errors\r
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\r
*/\r
interface IERC20Errors {\r
/**\r
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\r
* @param sender Address whose tokens are being transferred.\r
* @param balance Current balance for the interacting account.\r
* @param needed Minimum amount required to perform a transfer.\r
*/\r
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\r
\r
/**\r
* @dev Indicates a failure with the token `sender`. Used in transfers.\r
* @param sender Address whose tokens are being transferred.\r
*/\r
error ERC20InvalidSender(address sender);\r
\r
/**\r
* @dev Indicates a failure with the token `receiver`. Used in transfers.\r
* @param receiver Address to which tokens are being transferred.\r
*/\r
error ERC20InvalidReceiver(address receiver);\r
\r
/**\r
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\r
* @param spender Address that may be allowed to operate on tokens without being their owner.\r
* @param allowance Amount of tokens a `spender` is allowed to operate with.\r
* @param needed Minimum amount required to perform a transfer.\r
*/\r
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\r
\r
/**\r
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r
* @param approver Address initiating an approval operation.\r
*/\r
error ERC20InvalidApprover(address approver);\r
\r
/**\r
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.\r
* @param spender Address that may be allowed to operate on tokens without being their owner.\r
*/\r
error ERC20InvalidSpender(address spender);\r
}\r
\r
/**\r
* @dev Standard ERC-721 Errors\r
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\r
*/\r
interface IERC721Errors {\r
/**\r
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\r
* Used in balance queries.\r
* @param owner Address of the current owner of a token.\r
*/\r
error ERC721InvalidOwner(address owner);\r
\r
/**\r
* @dev Indicates a `tokenId` whose `owner` is the zero address.\r
* @param tokenId Identifier number of a token.\r
*/\r
error ERC721NonexistentToken(uint256 tokenId);\r
\r
/**\r
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.\r
* @param sender Address whose tokens are being transferred.\r
* @param tokenId Identifier number of a token.\r
* @param owner Address of the current owner of a token.\r
*/\r
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\r
\r
/**\r
* @dev Indicates a failure with the token `sender`. Used in transfers.\r
* @param sender Address whose tokens are being transferred.\r
*/\r
error ERC721InvalidSender(address sender);\r
\r
/**\r
* @dev Indicates a failure with the token `receiver`. Used in transfers.\r
* @param receiver Address to which tokens are being transferred.\r
*/\r
error ERC721InvalidReceiver(address receiver);\r
\r
/**\r
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.\r
* @param operator Address that may be allowed to operate on tokens without being their owner.\r
* @param tokenId Identifier number of a token.\r
*/\r
error ERC721InsufficientApproval(address operator, uint256 tokenId);\r
\r
/**\r
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r
* @param approver Address initiating an approval operation.\r
*/\r
error ERC721InvalidApprover(address approver);\r
\r
/**\r
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.\r
* @param operator Address that may be allowed to operate on tokens without being their owner.\r
*/\r
error ERC721InvalidOperator(address operator);\r
}\r
\r
/**\r
* @dev Standard ERC-1155 Errors\r
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\r
*/\r
interface IERC1155Errors {\r
/**\r
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\r
* @param sender Address whose tokens are being transferred.\r
* @param balance Current balance for the interacting account.\r
* @param needed Minimum amount required to perform a transfer.\r
* @param tokenId Identifier number of a token.\r
*/\r
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\r
\r
/**\r
* @dev Indicates a failure with the token `sender`. Used in transfers.\r
* @param sender Address whose tokens are being transferred.\r
*/\r
error ERC1155InvalidSender(address sender);\r
\r
/**\r
* @dev Indicates a failure with the token `receiver`. Used in transfers.\r
* @param receiver Address to which tokens are being transferred.\r
*/\r
error ERC1155InvalidReceiver(address receiver);\r
\r
/**\r
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.\r
* @param operator Address that may be allowed to operate on tokens without being their owner.\r
* @param owner Address of the current owner of a token.\r
*/\r
error ERC1155MissingApprovalForAll(address operator, address owner);\r
\r
/**\r
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r
* @param approver Address initiating an approval operation.\r
*/\r
error ERC1155InvalidApprover(address approver);\r
\r
/**\r
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.\r
* @param operator Address that may be allowed to operate on tokens without being their owner.\r
*/\r
error ERC1155InvalidOperator(address operator);\r
\r
/**\r
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\r
* Used in batch transfers.\r
* @param idsLength Length of the array of token identifiers\r
* @param valuesLength Length of the array of token amounts\r
*/\r
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\r
}\r
pragma solidity >=0.4.16;\r
\r
interface IERC5267 {\r
/**\r
* @dev MAY be emitted to signal that the domain could have changed.\r
*/\r
event EIP712DomainChanged();\r
\r
/**\r
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\r
* signature.\r
*/\r
function eip712Domain()\r
external\r
view\r
returns (\r
bytes1 fields,\r
string memory name,\r
string memory version,\r
uint256 chainId,\r
address verifyingContract,\r
bytes32 salt,\r
uint256[] memory extensions\r
);\r
}\r
pragma solidity >=0.4.16;\r
\r
/**\r
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in\r
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].\r
*\r
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by\r
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\r
* need to send a transaction, and thus is not required to hold Ether at all.\r
*\r
* ==== Security Considerations\r
*\r
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\r
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\r
* considered as an intention to spend the allowance in any specific way. The second is that because permits have\r
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\r
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\r
* generally recommended is:\r
*\r
* ```solidity\r
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\r
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\r
* doThing(..., value);\r
* }\r
*\r
* function doThing(..., uint256 value) public {\r
* token.safeTransferFrom(msg.sender, address(this), value);\r
* ...\r
* }\r
* ```\r
*\r
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\r
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\r
* {SafeERC20-safeTransferFrom}).\r
*\r
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\r
* contracts should have entry points that don't rely on permit.\r
*/\r
interface IERC20Permit {\r
/**\r
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\r
* given ``owner``'s signed approval.\r
*\r
* IMPORTANT: The same issues {IERC20-approve} has related to transaction\r
* ordering also apply here.\r
*\r
* Emits an {Approval} event.\r
*\r
* Requirements:\r
*\r
* - `spender` cannot be the zero address.\r
* - `deadline` must be a timestamp in the future.\r
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\r
* over the EIP712-formatted function arguments.\r
* - the signature must use ``owner``'s current nonce (see {nonces}).\r
*\r
* For more information on the signature format, see the\r
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\r
* section].\r
*\r
* CAUTION: See Security Considerations above.\r
*/\r
function permit(\r
address owner,\r
address spender,\r
uint256 value,\r
uint256 deadline,\r
uint8 v,\r
bytes32 r,\r
bytes32 s\r
) external;\r
\r
/**\r
* @dev Returns the current nonce for `owner`. This value must be\r
* included whenever a signature is generated for {permit}.\r
*\r
* Every successful call to {permit} increases ``owner``'s nonce by one. This\r
* prevents a signature from being used multiple times.\r
*/\r
function nonces(address owner) external view returns (uint256);\r
\r
/**\r
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\r
*/\r
// solhint-disable-next-line func-name-mixedcase\r
function DOMAIN_SEPARATOR() external view returns (bytes32);\r
}\r
pragma solidity >=0.4.16;\r
\r
/**\r
* @dev Interface of the ERC-20 standard as defined in the ERC.\r
*/\r
interface IERC20 {\r
/**\r
* @dev Emitted when `value` tokens are moved from one account (`from`) to\r
* another (`to`).\r
*\r
* Note that `value` may be zero.\r
*/\r
event Transfer(address indexed from, address indexed to, uint256 value);\r
\r
/**\r
* @dev Emitted when the allowance of a `spender` for an `owner` is set by\r
* a call to {approve}. `value` is the new allowance.\r
*/\r
event Approval(address indexed owner, address indexed spender, uint256 value);\r
\r
/**\r
* @dev Returns the value of tokens in existence.\r
*/\r
function totalSupply() external view returns (uint256);\r
\r
/**\r
* @dev Returns the value of tokens owned by `account`.\r
*/\r
function balanceOf(address account) external view returns (uint256);\r
\r
/**\r
* @dev Moves a `value` amount of tokens from the caller's account to `to`.\r
*\r
* Returns a boolean value indicating whether the operation succeeded.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function transfer(address to, uint256 value) external returns (bool);\r
\r
/**\r
* @dev Returns the remaining number of tokens that `spender` will be\r
* allowed to spend on behalf of `owner` through {transferFrom}. This is\r
* zero by default.\r
*\r
* This value changes when {approve} or {transferFrom} are called.\r
*/\r
function allowance(address owner, address spender) external view returns (uint256);\r
\r
/**\r
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the\r
* caller's tokens.\r
*\r
* Returns a boolean value indicating whether the operation succeeded.\r
*\r
* IMPORTANT: Beware that changing an allowance with this method brings the risk\r
* that someone may use both the old and the new allowance by unfortunate\r
* transaction ordering. One possible solution to mitigate this race\r
* condition is to first reduce the spender's allowance to 0 and set the\r
* desired value afterwards:\r
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r
*\r
* Emits an {Approval} event.\r
*/\r
function approve(address spender, uint256 value) external returns (bool);\r
\r
/**\r
* @dev Moves a `value` amount of tokens from `from` to `to` using the\r
* allowance mechanism. `value` is then deducted from the caller's\r
* allowance.\r
*\r
* Returns a boolean value indicating whether the operation succeeded.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function transferFrom(address from, address to, uint256 value) external returns (bool);\r
}\r
pragma solidity ^0.8.20;\r
\r
/**\r
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\r
*\r
* These functions can be used to verify that a message was signed by the holder\r
* of the private keys of a given address.\r
*/\r
library ECDSA {\r
enum RecoverError {\r
NoError,\r
InvalidSignature,\r
InvalidSignatureLength,\r
InvalidSignatureS\r
}\r
\r
/**\r
* @dev The signature derives the `address(0)`.\r
*/\r
error ECDSAInvalidSignature();\r
\r
/**\r
* @dev The signature has an invalid length.\r
*/\r
error ECDSAInvalidSignatureLength(uint256 length);\r
\r
/**\r
* @dev The signature has an S value that is in the upper half order.\r
*/\r
error ECDSAInvalidSignatureS(bytes32 s);\r
\r
/**\r
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\r
* return address(0) without also returning an error description. Errors are documented using an enum (error type)\r
* and a bytes32 providing additional information about the error.\r
*\r
* If no error is returned, then the address can be used for verification purposes.\r
*\r
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\r
* this function rejects them by requiring the `s` value to be in the lower\r
* half order, and the `v` value to be either 27 or 28.\r
*\r
* IMPORTANT: `hash` _must_ be the result of a hash operation for the\r
* verification to be secure: it is possible to craft signatures that\r
* recover to arbitrary addresses for non-hashed data. A safe way to ensure\r
* this is by receiving a hash of the original message (which may otherwise\r
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\r
*\r
* Documentation for signature generation:\r
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\r
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\r
*/\r
function tryRecover(\r
bytes32 hash,\r
bytes memory signature\r
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\r
if (signature.length == 65) {\r
bytes32 r;\r
bytes32 s;\r
uint8 v;\r
// ecrecover takes the signature parameters, and the only way to get them\r
// currently is to use assembly.\r
assembly ("memory-safe") {\r
r := mload(add(signature, 0x20))\r
s := mload(add(signature, 0x40))\r
v := byte(0, mload(add(signature, 0x60)))\r
}\r
return tryRecover(hash, v, r, s);\r
} else {\r
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\r
}\r
}\r
\r
/**\r
* @dev Returns the address that signed a hashed message (`hash`) with\r
* `signature`. This address can then be used for verification purposes.\r
*\r
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\r
* this function rejects them by requiring the `s` value to be in the lower\r
* half order, and the `v` value to be either 27 or 28.\r
*\r
* IMPORTANT: `hash` _must_ be the result of a hash operation for the\r
* verification to be secure: it is possible to craft signatures that\r
* recover to arbitrary addresses for non-hashed data. A safe way to ensure\r
* this is by receiving a hash of the original message (which may otherwise\r
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\r
*/\r
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\r
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\r
_throwError(error, errorArg);\r
return recovered;\r
}\r
\r
/**\r
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\r
*\r
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\r
*/\r
function tryRecover(\r
bytes32 hash,\r
bytes32 r,\r
bytes32 vs\r
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\r
unchecked {\r
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\r
// We do not check for an overflow here since the shift operation results in 0 or 1.\r
uint8 v = uint8((uint256(vs) >> 255) + 27);\r
return tryRecover(hash, v, r, s);\r
}\r
}\r
\r
/**\r
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\r
*/\r
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\r
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\r
_throwError(error, errorArg);\r
return recovered;\r
}\r
\r
/**\r
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,\r
* `r` and `s` signature fields separately.\r
*/\r
function tryRecover(\r
bytes32 hash,\r
uint8 v,\r
bytes32 r,\r
bytes32 s\r
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\r
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\r
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\r
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\r
// signatures from current libraries generate a unique signature with an s-value in the lower half order.\r
//\r
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\r
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\r
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\r
// these malleable signatures as well.\r
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\r
return (address(0), RecoverError.InvalidSignatureS, s);\r
}\r
\r
// If the signature is valid (and not malleable), return the signer address\r
address signer = ecrecover(hash, v, r, s);\r
if (signer == address(0)) {\r
return (address(0), RecoverError.InvalidSignature, bytes32(0));\r
}\r
\r
return (signer, RecoverError.NoError, bytes32(0));\r
}\r
\r
/**\r
* @dev Overload of {ECDSA-recover} that receives the `v`,\r
* `r` and `s` signature fields separately.\r
*/\r
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\r
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\r
_throwError(error, errorArg);\r
return recovered;\r
}\r
\r
/**\r
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\r
*/\r
function _throwError(RecoverError error, bytes32 errorArg) private pure {\r
if (error == RecoverError.NoError) {\r
return; // no error: do nothing\r
} else if (error == RecoverError.InvalidSignature) {\r
revert ECDSAInvalidSignature();\r
} else if (error == RecoverError.InvalidSignatureLength) {\r
revert ECDSAInvalidSignatureLength(uint256(errorArg));\r
} else if (error == RecoverError.InvalidSignatureS) {\r
revert ECDSAInvalidSignatureS(errorArg);\r
}\r
}\r
}\r
pragma solidity ^0.8.20;\r
\r
/**\r
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\r
* checks.\r
*\r
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\r
* easily result in undesired exploitation or bugs, since developers usually\r
* assume that overflows raise errors. `SafeCast` restores this intuition by\r
* reverting the transaction when such an operation overflows.\r
*\r
* Using this library instead of the unchecked operations eliminates an entire\r
* class of bugs, so it's recommended to use it always.\r
*/\r
library SafeCast {\r
/**\r
* @dev Value doesn't fit in an uint of `bits` size.\r
*/\r
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\r
\r
/**\r
* @dev An int value doesn't fit in an uint of `bits` size.\r
*/\r
error SafeCastOverflowedIntToUint(int256 value);\r
\r
/**\r
* @dev Value doesn't fit in an int of `bits` size.\r
*/\r
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\r
\r
/**\r
* @dev An uint value doesn't fit in an int of `bits` size.\r
*/\r
error SafeCastOverflowedUintToInt(uint256 value);\r
\r
/**\r
* @dev Returns the downcasted uint248 from uint256, reverting on\r
* overflow (when the input is greater than largest uint248).\r
*\r
* Counterpart to Solidity's `uint248` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 248 bits\r
*/\r
function toUint248(uint256 value) internal pure returns (uint248) {\r
if (value > type(uint248).max) {\r
revert SafeCastOverflowedUintDowncast(248, value);\r
}\r
return uint248(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint240 from uint256, reverting on\r
* overflow (when the input is greater than largest uint240).\r
*\r
* Counterpart to Solidity's `uint240` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 240 bits\r
*/\r
function toUint240(uint256 value) internal pure returns (uint240) {\r
if (value > type(uint240).max) {\r
revert SafeCastOverflowedUintDowncast(240, value);\r
}\r
return uint240(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint232 from uint256, reverting on\r
* overflow (when the input is greater than largest uint232).\r
*\r
* Counterpart to Solidity's `uint232` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 232 bits\r
*/\r
function toUint232(uint256 value) internal pure returns (uint232) {\r
if (value > type(uint232).max) {\r
revert SafeCastOverflowedUintDowncast(232, value);\r
}\r
return uint232(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint224 from uint256, reverting on\r
* overflow (when the input is greater than largest uint224).\r
*\r
* Counterpart to Solidity's `uint224` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 224 bits\r
*/\r
function toUint224(uint256 value) internal pure returns (uint224) {\r
if (value > type(uint224).max) {\r
revert SafeCastOverflowedUintDowncast(224, value);\r
}\r
return uint224(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint216 from uint256, reverting on\r
* overflow (when the input is greater than largest uint216).\r
*\r
* Counterpart to Solidity's `uint216` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 216 bits\r
*/\r
function toUint216(uint256 value) internal pure returns (uint216) {\r
if (value > type(uint216).max) {\r
revert SafeCastOverflowedUintDowncast(216, value);\r
}\r
return uint216(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint208 from uint256, reverting on\r
* overflow (when the input is greater than largest uint208).\r
*\r
* Counterpart to Solidity's `uint208` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 208 bits\r
*/\r
function toUint208(uint256 value) internal pure returns (uint208) {\r
if (value > type(uint208).max) {\r
revert SafeCastOverflowedUintDowncast(208, value);\r
}\r
return uint208(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint200 from uint256, reverting on\r
* overflow (when the input is greater than largest uint200).\r
*\r
* Counterpart to Solidity's `uint200` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 200 bits\r
*/\r
function toUint200(uint256 value) internal pure returns (uint200) {\r
if (value > type(uint200).max) {\r
revert SafeCastOverflowedUintDowncast(200, value);\r
}\r
return uint200(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint192 from uint256, reverting on\r
* overflow (when the input is greater than largest uint192).\r
*\r
* Counterpart to Solidity's `uint192` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 192 bits\r
*/\r
function toUint192(uint256 value) internal pure returns (uint192) {\r
if (value > type(uint192).max) {\r
revert SafeCastOverflowedUintDowncast(192, value);\r
}\r
return uint192(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint184 from uint256, reverting on\r
* overflow (when the input is greater than largest uint184).\r
*\r
* Counterpart to Solidity's `uint184` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 184 bits\r
*/\r
function toUint184(uint256 value) internal pure returns (uint184) {\r
if (value > type(uint184).max) {\r
revert SafeCastOverflowedUintDowncast(184, value);\r
}\r
return uint184(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint176 from uint256, reverting on\r
* overflow (when the input is greater than largest uint176).\r
*\r
* Counterpart to Solidity's `uint176` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 176 bits\r
*/\r
function toUint176(uint256 value) internal pure returns (uint176) {\r
if (value > type(uint176).max) {\r
revert SafeCastOverflowedUintDowncast(176, value);\r
}\r
return uint176(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint168 from uint256, reverting on\r
* overflow (when the input is greater than largest uint168).\r
*\r
* Counterpart to Solidity's `uint168` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 168 bits\r
*/\r
function toUint168(uint256 value) internal pure returns (uint168) {\r
if (value > type(uint168).max) {\r
revert SafeCastOverflowedUintDowncast(168, value);\r
}\r
return uint168(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint160 from uint256, reverting on\r
* overflow (when the input is greater than largest uint160).\r
*\r
* Counterpart to Solidity's `uint160` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 160 bits\r
*/\r
function toUint160(uint256 value) internal pure returns (uint160) {\r
if (value > type(uint160).max) {\r
revert SafeCastOverflowedUintDowncast(160, value);\r
}\r
return uint160(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint152 from uint256, reverting on\r
* overflow (when the input is greater than largest uint152).\r
*\r
* Counterpart to Solidity's `uint152` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 152 bits\r
*/\r
function toUint152(uint256 value) internal pure returns (uint152) {\r
if (value > type(uint152).max) {\r
revert SafeCastOverflowedUintDowncast(152, value);\r
}\r
return uint152(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint144 from uint256, reverting on\r
* overflow (when the input is greater than largest uint144).\r
*\r
* Counterpart to Solidity's `uint144` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 144 bits\r
*/\r
function toUint144(uint256 value) internal pure returns (uint144) {\r
if (value > type(uint144).max) {\r
revert SafeCastOverflowedUintDowncast(144, value);\r
}\r
return uint144(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint136 from uint256, reverting on\r
* overflow (when the input is greater than largest uint136).\r
*\r
* Counterpart to Solidity's `uint136` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 136 bits\r
*/\r
function toUint136(uint256 value) internal pure returns (uint136) {\r
if (value > type(uint136).max) {\r
revert SafeCastOverflowedUintDowncast(136, value);\r
}\r
return uint136(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint128 from uint256, reverting on\r
* overflow (when the input is greater than largest uint128).\r
*\r
* Counterpart to Solidity's `uint128` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 128 bits\r
*/\r
function toUint128(uint256 value) internal pure returns (uint128) {\r
if (value > type(uint128).max) {\r
revert SafeCastOverflowedUintDowncast(128, value);\r
}\r
return uint128(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint120 from uint256, reverting on\r
* overflow (when the input is greater than largest uint120).\r
*\r
* Counterpart to Solidity's `uint120` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 120 bits\r
*/\r
function toUint120(uint256 value) internal pure returns (uint120) {\r
if (value > type(uint120).max) {\r
revert SafeCastOverflowedUintDowncast(120, value);\r
}\r
return uint120(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint112 from uint256, reverting on\r
* overflow (when the input is greater than largest uint112).\r
*\r
* Counterpart to Solidity's `uint112` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 112 bits\r
*/\r
function toUint112(uint256 value) internal pure returns (uint112) {\r
if (value > type(uint112).max) {\r
revert SafeCastOverflowedUintDowncast(112, value);\r
}\r
return uint112(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint104 from uint256, reverting on\r
* overflow (when the input is greater than largest uint104).\r
*\r
* Counterpart to Solidity's `uint104` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 104 bits\r
*/\r
function toUint104(uint256 value) internal pure returns (uint104) {\r
if (value > type(uint104).max) {\r
revert SafeCastOverflowedUintDowncast(104, value);\r
}\r
return uint104(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint96 from uint256, reverting on\r
* overflow (when the input is greater than largest uint96).\r
*\r
* Counterpart to Solidity's `uint96` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 96 bits\r
*/\r
function toUint96(uint256 value) internal pure returns (uint96) {\r
if (value > type(uint96).max) {\r
revert SafeCastOverflowedUintDowncast(96, value);\r
}\r
return uint96(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint88 from uint256, reverting on\r
* overflow (when the input is greater than largest uint88).\r
*\r
* Counterpart to Solidity's `uint88` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 88 bits\r
*/\r
function toUint88(uint256 value) internal pure returns (uint88) {\r
if (value > type(uint88).max) {\r
revert SafeCastOverflowedUintDowncast(88, value);\r
}\r
return uint88(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint80 from uint256, reverting on\r
* overflow (when the input is greater than largest uint80).\r
*\r
* Counterpart to Solidity's `uint80` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 80 bits\r
*/\r
function toUint80(uint256 value) internal pure returns (uint80) {\r
if (value > type(uint80).max) {\r
revert SafeCastOverflowedUintDowncast(80, value);\r
}\r
return uint80(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint72 from uint256, reverting on\r
* overflow (when the input is greater than largest uint72).\r
*\r
* Counterpart to Solidity's `uint72` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 72 bits\r
*/\r
function toUint72(uint256 value) internal pure returns (uint72) {\r
if (value > type(uint72).max) {\r
revert SafeCastOverflowedUintDowncast(72, value);\r
}\r
return uint72(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint64 from uint256, reverting on\r
* overflow (when the input is greater than largest uint64).\r
*\r
* Counterpart to Solidity's `uint64` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 64 bits\r
*/\r
function toUint64(uint256 value) internal pure returns (uint64) {\r
if (value > type(uint64).max) {\r
revert SafeCastOverflowedUintDowncast(64, value);\r
}\r
return uint64(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint56 from uint256, reverting on\r
* overflow (when the input is greater than largest uint56).\r
*\r
* Counterpart to Solidity's `uint56` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 56 bits\r
*/\r
function toUint56(uint256 value) internal pure returns (uint56) {\r
if (value > type(uint56).max) {\r
revert SafeCastOverflowedUintDowncast(56, value);\r
}\r
return uint56(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint48 from uint256, reverting on\r
* overflow (when the input is greater than largest uint48).\r
*\r
* Counterpart to Solidity's `uint48` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 48 bits\r
*/\r
function toUint48(uint256 value) internal pure returns (uint48) {\r
if (value > type(uint48).max) {\r
revert SafeCastOverflowedUintDowncast(48, value);\r
}\r
return uint48(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint40 from uint256, reverting on\r
* overflow (when the input is greater than largest uint40).\r
*\r
* Counterpart to Solidity's `uint40` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 40 bits\r
*/\r
function toUint40(uint256 value) internal pure returns (uint40) {\r
if (value > type(uint40).max) {\r
revert SafeCastOverflowedUintDowncast(40, value);\r
}\r
return uint40(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint32 from uint256, reverting on\r
* overflow (when the input is greater than largest uint32).\r
*\r
* Counterpart to Solidity's `uint32` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 32 bits\r
*/\r
function toUint32(uint256 value) internal pure returns (uint32) {\r
if (value > type(uint32).max) {\r
revert SafeCastOverflowedUintDowncast(32, value);\r
}\r
return uint32(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint24 from uint256, reverting on\r
* overflow (when the input is greater than largest uint24).\r
*\r
* Counterpart to Solidity's `uint24` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 24 bits\r
*/\r
function toUint24(uint256 value) internal pure returns (uint24) {\r
if (value > type(uint24).max) {\r
revert SafeCastOverflowedUintDowncast(24, value);\r
}\r
return uint24(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint16 from uint256, reverting on\r
* overflow (when the input is greater than largest uint16).\r
*\r
* Counterpart to Solidity's `uint16` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 16 bits\r
*/\r
function toUint16(uint256 value) internal pure returns (uint16) {\r
if (value > type(uint16).max) {\r
revert SafeCastOverflowedUintDowncast(16, value);\r
}\r
return uint16(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted uint8 from uint256, reverting on\r
* overflow (when the input is greater than largest uint8).\r
*\r
* Counterpart to Solidity's `uint8` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 8 bits\r
*/\r
function toUint8(uint256 value) internal pure returns (uint8) {\r
if (value > type(uint8).max) {\r
revert SafeCastOverflowedUintDowncast(8, value);\r
}\r
return uint8(value);\r
}\r
\r
/**\r
* @dev Converts a signed int256 into an unsigned uint256.\r
*\r
* Requirements:\r
*\r
* - input must be greater than or equal to 0.\r
*/\r
function toUint256(int256 value) internal pure returns (uint256) {\r
if (value < 0) {\r
revert SafeCastOverflowedIntToUint(value);\r
}\r
return uint256(value);\r
}\r
\r
/**\r
* @dev Returns the downcasted int248 from int256, reverting on\r
* overflow (when the input is less than smallest int248 or\r
* greater than largest int248).\r
*\r
* Counterpart to Solidity's `int248` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 248 bits\r
*/\r
function toInt248(int256 value) internal pure returns (int248 downcasted) {\r
downcasted = int248(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(248, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int240 from int256, reverting on\r
* overflow (when the input is less than smallest int240 or\r
* greater than largest int240).\r
*\r
* Counterpart to Solidity's `int240` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 240 bits\r
*/\r
function toInt240(int256 value) internal pure returns (int240 downcasted) {\r
downcasted = int240(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(240, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int232 from int256, reverting on\r
* overflow (when the input is less than smallest int232 or\r
* greater than largest int232).\r
*\r
* Counterpart to Solidity's `int232` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 232 bits\r
*/\r
function toInt232(int256 value) internal pure returns (int232 downcasted) {\r
downcasted = int232(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(232, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int224 from int256, reverting on\r
* overflow (when the input is less than smallest int224 or\r
* greater than largest int224).\r
*\r
* Counterpart to Solidity's `int224` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 224 bits\r
*/\r
function toInt224(int256 value) internal pure returns (int224 downcasted) {\r
downcasted = int224(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(224, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int216 from int256, reverting on\r
* overflow (when the input is less than smallest int216 or\r
* greater than largest int216).\r
*\r
* Counterpart to Solidity's `int216` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 216 bits\r
*/\r
function toInt216(int256 value) internal pure returns (int216 downcasted) {\r
downcasted = int216(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(216, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int208 from int256, reverting on\r
* overflow (when the input is less than smallest int208 or\r
* greater than largest int208).\r
*\r
* Counterpart to Solidity's `int208` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 208 bits\r
*/\r
function toInt208(int256 value) internal pure returns (int208 downcasted) {\r
downcasted = int208(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(208, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int200 from int256, reverting on\r
* overflow (when the input is less than smallest int200 or\r
* greater than largest int200).\r
*\r
* Counterpart to Solidity's `int200` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 200 bits\r
*/\r
function toInt200(int256 value) internal pure returns (int200 downcasted) {\r
downcasted = int200(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(200, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int192 from int256, reverting on\r
* overflow (when the input is less than smallest int192 or\r
* greater than largest int192).\r
*\r
* Counterpart to Solidity's `int192` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 192 bits\r
*/\r
function toInt192(int256 value) internal pure returns (int192 downcasted) {\r
downcasted = int192(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(192, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int184 from int256, reverting on\r
* overflow (when the input is less than smallest int184 or\r
* greater than largest int184).\r
*\r
* Counterpart to Solidity's `int184` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 184 bits\r
*/\r
function toInt184(int256 value) internal pure returns (int184 downcasted) {\r
downcasted = int184(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(184, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int176 from int256, reverting on\r
* overflow (when the input is less than smallest int176 or\r
* greater than largest int176).\r
*\r
* Counterpart to Solidity's `int176` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 176 bits\r
*/\r
function toInt176(int256 value) internal pure returns (int176 downcasted) {\r
downcasted = int176(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(176, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int168 from int256, reverting on\r
* overflow (when the input is less than smallest int168 or\r
* greater than largest int168).\r
*\r
* Counterpart to Solidity's `int168` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 168 bits\r
*/\r
function toInt168(int256 value) internal pure returns (int168 downcasted) {\r
downcasted = int168(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(168, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int160 from int256, reverting on\r
* overflow (when the input is less than smallest int160 or\r
* greater than largest int160).\r
*\r
* Counterpart to Solidity's `int160` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 160 bits\r
*/\r
function toInt160(int256 value) internal pure returns (int160 downcasted) {\r
downcasted = int160(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(160, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int152 from int256, reverting on\r
* overflow (when the input is less than smallest int152 or\r
* greater than largest int152).\r
*\r
* Counterpart to Solidity's `int152` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 152 bits\r
*/\r
function toInt152(int256 value) internal pure returns (int152 downcasted) {\r
downcasted = int152(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(152, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int144 from int256, reverting on\r
* overflow (when the input is less than smallest int144 or\r
* greater than largest int144).\r
*\r
* Counterpart to Solidity's `int144` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 144 bits\r
*/\r
function toInt144(int256 value) internal pure returns (int144 downcasted) {\r
downcasted = int144(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(144, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int136 from int256, reverting on\r
* overflow (when the input is less than smallest int136 or\r
* greater than largest int136).\r
*\r
* Counterpart to Solidity's `int136` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 136 bits\r
*/\r
function toInt136(int256 value) internal pure returns (int136 downcasted) {\r
downcasted = int136(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(136, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int128 from int256, reverting on\r
* overflow (when the input is less than smallest int128 or\r
* greater than largest int128).\r
*\r
* Counterpart to Solidity's `int128` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 128 bits\r
*/\r
function toInt128(int256 value) internal pure returns (int128 downcasted) {\r
downcasted = int128(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(128, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int120 from int256, reverting on\r
* overflow (when the input is less than smallest int120 or\r
* greater than largest int120).\r
*\r
* Counterpart to Solidity's `int120` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 120 bits\r
*/\r
function toInt120(int256 value) internal pure returns (int120 downcasted) {\r
downcasted = int120(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(120, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int112 from int256, reverting on\r
* overflow (when the input is less than smallest int112 or\r
* greater than largest int112).\r
*\r
* Counterpart to Solidity's `int112` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 112 bits\r
*/\r
function toInt112(int256 value) internal pure returns (int112 downcasted) {\r
downcasted = int112(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(112, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int104 from int256, reverting on\r
* overflow (when the input is less than smallest int104 or\r
* greater than largest int104).\r
*\r
* Counterpart to Solidity's `int104` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 104 bits\r
*/\r
function toInt104(int256 value) internal pure returns (int104 downcasted) {\r
downcasted = int104(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(104, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int96 from int256, reverting on\r
* overflow (when the input is less than smallest int96 or\r
* greater than largest int96).\r
*\r
* Counterpart to Solidity's `int96` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 96 bits\r
*/\r
function toInt96(int256 value) internal pure returns (int96 downcasted) {\r
downcasted = int96(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(96, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int88 from int256, reverting on\r
* overflow (when the input is less than smallest int88 or\r
* greater than largest int88).\r
*\r
* Counterpart to Solidity's `int88` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 88 bits\r
*/\r
function toInt88(int256 value) internal pure returns (int88 downcasted) {\r
downcasted = int88(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(88, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int80 from int256, reverting on\r
* overflow (when the input is less than smallest int80 or\r
* greater than largest int80).\r
*\r
* Counterpart to Solidity's `int80` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 80 bits\r
*/\r
function toInt80(int256 value) internal pure returns (int80 downcasted) {\r
downcasted = int80(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(80, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int72 from int256, reverting on\r
* overflow (when the input is less than smallest int72 or\r
* greater than largest int72).\r
*\r
* Counterpart to Solidity's `int72` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 72 bits\r
*/\r
function toInt72(int256 value) internal pure returns (int72 downcasted) {\r
downcasted = int72(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(72, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int64 from int256, reverting on\r
* overflow (when the input is less than smallest int64 or\r
* greater than largest int64).\r
*\r
* Counterpart to Solidity's `int64` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 64 bits\r
*/\r
function toInt64(int256 value) internal pure returns (int64 downcasted) {\r
downcasted = int64(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(64, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int56 from int256, reverting on\r
* overflow (when the input is less than smallest int56 or\r
* greater than largest int56).\r
*\r
* Counterpart to Solidity's `int56` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 56 bits\r
*/\r
function toInt56(int256 value) internal pure returns (int56 downcasted) {\r
downcasted = int56(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(56, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int48 from int256, reverting on\r
* overflow (when the input is less than smallest int48 or\r
* greater than largest int48).\r
*\r
* Counterpart to Solidity's `int48` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 48 bits\r
*/\r
function toInt48(int256 value) internal pure returns (int48 downcasted) {\r
downcasted = int48(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(48, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int40 from int256, reverting on\r
* overflow (when the input is less than smallest int40 or\r
* greater than largest int40).\r
*\r
* Counterpart to Solidity's `int40` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 40 bits\r
*/\r
function toInt40(int256 value) internal pure returns (int40 downcasted) {\r
downcasted = int40(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(40, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int32 from int256, reverting on\r
* overflow (when the input is less than smallest int32 or\r
* greater than largest int32).\r
*\r
* Counterpart to Solidity's `int32` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 32 bits\r
*/\r
function toInt32(int256 value) internal pure returns (int32 downcasted) {\r
downcasted = int32(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(32, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int24 from int256, reverting on\r
* overflow (when the input is less than smallest int24 or\r
* greater than largest int24).\r
*\r
* Counterpart to Solidity's `int24` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 24 bits\r
*/\r
function toInt24(int256 value) internal pure returns (int24 downcasted) {\r
downcasted = int24(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(24, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int16 from int256, reverting on\r
* overflow (when the input is less than smallest int16 or\r
* greater than largest int16).\r
*\r
* Counterpart to Solidity's `int16` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 16 bits\r
*/\r
function toInt16(int256 value) internal pure returns (int16 downcasted) {\r
downcasted = int16(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(16, value);\r
}\r
}\r
\r
/**\r
* @dev Returns the downcasted int8 from int256, reverting on\r
* overflow (when the input is less than smallest int8 or\r
* greater than largest int8).\r
*\r
* Counterpart to Solidity's `int8` operator.\r
*\r
* Requirements:\r
*\r
* - input must fit into 8 bits\r
*/\r
function toInt8(int256 value) internal pure returns (int8 downcasted) {\r
downcasted = int8(value);\r
if (downcasted != value) {\r
revert SafeCastOverflowedIntDowncast(8, value);\r
}\r
}\r
\r
/**\r
* @dev Converts an unsigned uint256 into a signed int256.\r
*\r
* Requirements:\r
*\r
* - input must be less than or equal to maxInt256.\r
*/\r
function toInt256(uint256 value) internal pure returns (int256) {\r
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\r
if (value > uint256(type(int256).max)) {\r
revert SafeCastOverflowedUintToInt(value);\r
}\r
return int256(value);\r
}\r
\r
/**\r
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\r
*/\r
function toUint(bool b) internal pure returns (uint256 u) {\r
assembly ("memory-safe") {\r
u := iszero(iszero(b))\r
}\r
}\r
}\r
pragma solidity ^0.8.20;\r
\r
/**\r
* @dev Provides tracking nonces for addresses. Nonces will only increment.\r
*/\r
abstract contract Nonces {\r
/**\r
* @dev The nonce used for an `account` is not the expected current nonce.\r
*/\r
error InvalidAccountNonce(address account, uint256 currentNonce);\r
\r
mapping(address account => uint256) private _nonces;\r
\r
/**\r
* @dev Returns the next unused nonce for an address.\r
*/\r
function nonces(address owner) public view virtual returns (uint256) {\r
return _nonces[owner];\r
}\r
\r
/**\r
* @dev Consumes a nonce.\r
*\r
* Returns the current value and increments nonce.\r
*/\r
function _useNonce(address owner) internal virtual returns (uint256) {\r
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be\r
// decremented or reset. This guarantees that the nonce never overflows.\r
unchecked {\r
// It is important to do x++ and not ++x here.\r
return _nonces[owner]++;\r
}\r
}\r
\r
/**\r
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.\r
*/\r
function _useCheckedNonce(address owner, uint256 nonce) internal virtual {\r
uint256 current = _useNonce(owner);\r
if (nonce != current) {\r
revert InvalidAccountNonce(owner, current);\r
}\r
}\r
}\r
pragma solidity ^0.8.20;\r
\r
/**\r
* @dev Helper library for emitting standardized panic codes.\r
*\r
* ```solidity\r
* contract Example {\r
* using Panic for uint256;\r
*\r
* // Use any of the declared internal constants\r
* function foo() { Panic.GENERIC.panic(); }\r
*\r
* // Alternatively\r
* function foo() { Panic.panic(Panic.GENERIC); }\r
* }\r
* ```\r
*\r
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\r
*\r
* _Available since v5.1._\r
*/\r
// slither-disable-next-line unused-state\r
library Panic {\r
/// @dev generic / unspecified error\r
uint256 internal constant GENERIC = 0x00;\r
/// @dev used by the assert() builtin\r
uint256 internal constant ASSERT = 0x01;\r
/// @dev arithmetic underflow or overflow\r
uint256 internal constant UNDER_OVERFLOW = 0x11;\r
/// @dev division or modulo by zero\r
uint256 internal constant DIVISION_BY_ZERO = 0x12;\r
/// @dev enum conversion error\r
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\r
/// @dev invalid encoding in storage\r
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\r
/// @dev empty array pop\r
uint256 internal constant EMPTY_ARRAY_POP = 0x31;\r
/// @dev array out of bounds access\r
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\r
/// @dev resource error (too large allocation or too large array)\r
uint256 internal constant RESOURCE_ERROR = 0x41;\r
/// @dev calling invalid
Submitted on: 2025-11-02 19:04:58
Comments
Log in to comment.
No comments yet.