Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
MonPresale
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
//SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {AccessControlDefaultAdminRulesUpgradeable} from "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol"; import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {IDelegateRegistryV1} from "./interfaces/IDelegateRegistryV1.sol"; import {IDelegateRegistryV2} from "./interfaces/IDelegateRegistryV2.sol"; /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ /$$ /$$ /$$ /$$$$$$ /$$ /$$ /$$$$$$ | $$$ /$$$ /$$__ $$| $$$ | $$ /$$__ $$| $$$$ /$$$$| $$ \ $$| $$$$| $$ | $$ \__/| $$ $$/$$ $$| $$ | $$| $$ $$ $$ | $$$$$$ | $$ $$$| $$| $$ | $$| $$ $$$$ \____ $$| $$\ $ | $$| $$ | $$| $$\ $$$ /$$ \ $$| $$ \/ | $$| $$$$$$/| $$ \ $$ | $$$$$$/|__/ |__/ \______/ |__/ \__/ \_ $$_/ \__/ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ @title MonPresale @author 0xBuooy $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ contract MonPresale is Initializable, ReentrancyGuardUpgradeable, AccessControlDefaultAdminRulesUpgradeable, PausableUpgradeable { using ECDSA for bytes32; enum State { NOT_STARTED, PRESALE_STARTED, PRESALE_ENDED, REFUND_STARTED, REFUND_ENDED } struct Reservation { uint16 guaranteedLots; uint16 waitlistLots; } State public state; IDelegateRegistryV1 private delegateRegistryV1; IDelegateRegistryV2 private delegateRegistryV2; uint256 public pricePerLot; bytes32 public constant DEVELOPER_ROLE = keccak256("DEVELOPER"); address public financeWalletAddress; address public signer; mapping(address wallet => Reservation reservation) private reservations; mapping(address wallet => bool isRefunded) private isWalletRefunded; address[] private refunders; address[] private reservers; // ============================================================ // Events // ============================================================ event EventReserved( address indexed wallet, uint16 guaranteedLots, uint16 waitlistLots ); event EventRefunded(address indexed wallet, uint256 amount); // ============================================================ // Errors // ============================================================ error AlreadyRefunded(); error InvalidAddress(); error InvalidFunds(); error InvalidSignature(); error InvalidState(); error MustReserveAtLeastOneLot(); error NoRefundNeeded(); error PriceNotSet(); error ReserveTooManyLots(); error UnsetFinanceWallet(); error WithdrawFailed(); error InvalidDelegate(); // ============================================================ // Constructor/Initialiser // ============================================================ /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } function initialize( address _initialOwner, address _signer, address _financeWalletAddress, address[] calldata _developers, uint256 _pricePerLot, address _delegateRegistryV1, address _delegateRegistryV2 ) public initializer { // Initialise the access controls AccessControlDefaultAdminRulesUpgradeable .__AccessControlDefaultAdminRules_init(1 days, _initialOwner); // Initialise reentrancy guard ReentrancyGuardUpgradeable.__ReentrancyGuard_init(); // Initialise Pausable PausableUpgradeable.__Pausable_init(); // grant admin and developer roles _grantRole(DEVELOPER_ROLE, _initialOwner); for (uint256 i; i < _developers.length; ) { _grantRole(DEVELOPER_ROLE, _developers[i]); unchecked { ++i; } } if (_financeWalletAddress == address(0) || _signer == address(0)) { revert InvalidAddress(); } // Set basic constraints financeWalletAddress = _financeWalletAddress; signer = _signer; pricePerLot = _pricePerLot; delegateRegistryV1 = IDelegateRegistryV1(_delegateRegistryV1); delegateRegistryV2 = IDelegateRegistryV2(_delegateRegistryV2); } // ============================================================ // Reserve Management // ============================================================ function reserve( uint16 _guaranteedLots, uint16 _waitlistLots, uint16 _lotsToReserve, bytes calldata _salt, bytes calldata _signature, address _coldWallet ) external payable nonReentrant whenNotPaused { address reserveAddress = _getReserveWallet(_coldWallet); // Validates all necessary requirements // Specifically, it checks if the guaranteedlots and waitlist lots are valid _presaleChecker( reserveAddress, _guaranteedLots, _waitlistLots, _lotsToReserve, _salt, _signature ); uint16 availableGuaranteedLots = _guaranteedLots - reservations[reserveAddress].guaranteedLots; uint16 guaranteedLots = _lotsToReserve > availableGuaranteedLots ? availableGuaranteedLots : _lotsToReserve; uint16 waitlistLots = _lotsToReserve > availableGuaranteedLots ? _lotsToReserve - availableGuaranteedLots : 0; if ( reservations[reserveAddress].guaranteedLots == 0 && reservations[reserveAddress].waitlistLots == 0 ) { // Add new reserver and reservation is new reservers.push(reserveAddress); reservations[reserveAddress] = Reservation( guaranteedLots, waitlistLots ); } else { // Update reservation if reserver already exists reservations[reserveAddress].guaranteedLots = reservations[reserveAddress].guaranteedLots + guaranteedLots; reservations[reserveAddress].waitlistLots = reservations[reserveAddress].waitlistLots + waitlistLots; } emit EventReserved(reserveAddress, _guaranteedLots, _waitlistLots); } /// @dev checks the sender's reservation status /// @return guaranteed reserved details /// @return waitlist reserved details function getReservation( address _userAddress ) external view returns (uint256 guaranteed, uint256 waitlist) { return ( reservations[_userAddress].guaranteedLots, reservations[_userAddress].waitlistLots ); } /// @dev returns all reservations /// @return reserversList reservers list /// @return guaranteedList guaranteed list /// @return waitlistList waitlist list function getAllReservations() external view onlyRole(DEVELOPER_ROLE) returns ( address[] memory reserversList, uint256[] memory guaranteedList, uint256[] memory waitlistList ) { uint256[] memory _guaranteedList = new uint256[](reservers.length); uint256[] memory _waitlistList = new uint256[](reservers.length); for (uint256 i; i < reservers.length; ) { _guaranteedList[i] = reservations[reservers[i]].guaranteedLots; _waitlistList[i] = reservations[reservers[i]].waitlistLots; unchecked { ++i; } } return (reservers, _guaranteedList, _waitlistList); } // ============================================================ // Financial Management // ============================================================ /// @dev allows wallet to refund to their wallet /// @param _successfulWaitlistCount number of waitlist lots that were successful /// @param _signature signature of the successful waitlist count function refund( uint16 _successfulWaitlistCount, address _coldWallet, bytes calldata _salt, bytes calldata _signature ) external nonReentrant whenNotPaused { // Check if the refund is ongoing if (state != State.REFUND_STARTED) { revert InvalidState(); } address reserveAddress = _getReserveWallet(_coldWallet); // Check if the wallet has already refunded if (isWalletRefunded[reserveAddress]) { revert AlreadyRefunded(); } // Check if the number of successful waitlist lots is more than the number of waitlist lots reserved if ( _successfulWaitlistCount >= reservations[reserveAddress].waitlistLots ) { revert NoRefundNeeded(); } // checks if signature is valid bytes32 messagehash = keccak256( abi.encodePacked(_salt, _successfulWaitlistCount, reserveAddress) ); if ( signer != MessageHashUtils.toEthSignedMessageHash(messagehash).recover( _signature ) ) { revert InvalidSignature(); } uint256 totalRefundAmount = (reservations[reserveAddress].waitlistLots - _successfulWaitlistCount) * pricePerLot; isWalletRefunded[reserveAddress] = true; refunders.push(reserveAddress); (bool success, ) = reserveAddress.call{value: totalRefundAmount}(""); if (!success) { revert WithdrawFailed(); } emit EventRefunded(reserveAddress, totalRefundAmount); } /// @dev withdraw all proceeds to the finance wallet function withdrawAll() external onlyRole(DEFAULT_ADMIN_ROLE) whenNotPaused { if (financeWalletAddress == address(0)) { revert UnsetFinanceWallet(); } if (state != State.REFUND_ENDED) { revert InvalidState(); } (bool success, ) = financeWalletAddress.call{ value: address(this).balance }(""); if (!success) { revert WithdrawFailed(); } } /// @dev withdraw secured lots to the finance wallet function withdrawFunds( uint256 _securedLots ) external onlyRole(DEFAULT_ADMIN_ROLE) whenNotPaused { if (financeWalletAddress == address(0)) { revert UnsetFinanceWallet(); } if (state == State.NOT_STARTED || state == State.PRESALE_STARTED) { revert InvalidState(); } (bool success, ) = financeWalletAddress.call{ value: _securedLots * pricePerLot }(""); if (!success) { revert WithdrawFailed(); } } /// @dev sets the finance wallet address /// @param _financeWalletAddress address of the finance wallet function setFinanceWalletAddress( address _financeWalletAddress ) external payable onlyRole(DEFAULT_ADMIN_ROLE) whenNotPaused { if (_financeWalletAddress == address(0)) { revert InvalidAddress(); } financeWalletAddress = _financeWalletAddress; } // ============================================================ // Refund Management // ============================================================ function getRefundStatus( address _userAddress ) external view returns (bool isRefunded) { return isWalletRefunded[_userAddress]; } function getAllRefundStatus() external view returns (address[] memory wallets, bool[] memory status) { bool[] memory _isWalletRefunded = new bool[](refunders.length); for (uint256 i; i < refunders.length; ) { _isWalletRefunded[i] = isWalletRefunded[refunders[i]]; unchecked { ++i; } } return (refunders, _isWalletRefunded); } // ============================================================ // Waitlist Checker // ============================================================ /// @dev sets the signer address /// @param _signer address of the signer function setSigner( address _signer ) external payable onlyRole(DEVELOPER_ROLE) whenNotPaused { if (_signer == address(0)) { revert InvalidAddress(); } signer = _signer; } /// @dev check if cold wallet is used and is valid in the delegate registry /// @param _coldWallet : delegate registry wallet (for non-delegate -> address(0) ) /// returns : replace hot wallet with cold wallet if delegate function _getReserveWallet( address _coldWallet ) internal view returns (address reserveWallet) { if (_coldWallet == address(0)) return _msgSender(); bool isDelegateValid = delegateRegistryV2.checkDelegateForContract( _msgSender(), _coldWallet, address(this), "" ); if (isDelegateValid) return _coldWallet; isDelegateValid = delegateRegistryV1.checkDelegateForContract( _msgSender(), _coldWallet, address(this) ); if (!isDelegateValid) revert InvalidDelegate(); return _coldWallet; } /// @dev checks if the mint is valid /// @param _guaranteedLots number of guaranteed lots /// @param _waitlistLots number of waitlist lots /// @param _lotsToReserve number of lots to reserve function _presaleChecker( address _checkAgainst, uint16 _guaranteedLots, uint16 _waitlistLots, uint16 _lotsToReserve, bytes calldata _salt, bytes calldata _signature ) internal { if (state != State.PRESALE_STARTED) { revert InvalidState(); } // ========================================================================= // Quantity Checks // ========================================================================= if (_lotsToReserve == 0) { revert MustReserveAtLeastOneLot(); } if ( uint32(_lotsToReserve) + uint32(reservations[_checkAgainst].guaranteedLots) + uint32(reservations[_checkAgainst].waitlistLots) > uint32(_guaranteedLots) + uint32(_waitlistLots) ) { revert ReserveTooManyLots(); } // ========================================================================= // Finance Checks // ========================================================================= // checks that the pricePerLot is set if (pricePerLot == 0) { revert PriceNotSet(); } // checks if sufficient eth is sent if (msg.value != _lotsToReserve * pricePerLot) { revert InvalidFunds(); } // ========================================================================= // Signature Checks // ========================================================================= // checks if signature is valid bytes32 messagehash = keccak256( abi.encodePacked( _salt, _guaranteedLots, _waitlistLots, _checkAgainst ) ); if ( signer != MessageHashUtils.toEthSignedMessageHash(messagehash).recover( _signature ) ) { revert InvalidSignature(); } } // ============================================================ // Administrative Function // ============================================================ /// @dev sets the state /// @param _state state to set function setState(State _state) external payable onlyRole(DEVELOPER_ROLE) { state = _state; } /// @dev sets the price per lot /// @param _pricePerLot price of each lot function setPricePerLot( uint256 _pricePerLot ) external payable onlyRole(DEVELOPER_ROLE) whenNotPaused { if (state != State.NOT_STARTED) { revert InvalidState(); } pricePerLot = _pricePerLot; } // ============================================================ // Emergency Functions // ============================================================ /// @dev pauses the contract function pause() external onlyRole(DEVELOPER_ROLE) { _pause(); } /// @dev unpauses the contract function unpause() external onlyRole(DEVELOPER_ROLE) { _unpause(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol) pragma solidity ^0.8.20; import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable { struct RoleData { mapping(address account => bool) hasRole; bytes32 adminRole; } bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl struct AccessControlStorage { mapping(bytes32 role => RoleData) _roles; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800; function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) { assembly { $.slot := AccessControlStorageLocation } } /** * @dev Modifier that checks that an account has a specific role. Reverts * with an {AccessControlUnauthorizedAccount} error including the required role. */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual returns (bool) { AccessControlStorage storage $ = _getAccessControlStorage(); return $._roles[role].hasRole[account]; } /** * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()` * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier. */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account` * is missing `role`. */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert AccessControlUnauthorizedAccount(account, role); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) { AccessControlStorage storage $ = _getAccessControlStorage(); return $._roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `callerConfirmation`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address callerConfirmation) public virtual { if (callerConfirmation != _msgSender()) { revert AccessControlBadConfirmation(); } _revokeRole(role, callerConfirmation); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { AccessControlStorage storage $ = _getAccessControlStorage(); bytes32 previousAdminRole = getRoleAdmin(role); $._roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual returns (bool) { AccessControlStorage storage $ = _getAccessControlStorage(); if (!hasRole(role, account)) { $._roles[role].hasRole[account] = true; emit RoleGranted(role, account, _msgSender()); return true; } else { return false; } } /** * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual returns (bool) { AccessControlStorage storage $ = _getAccessControlStorage(); if (hasRole(role, account)) { $._roles[role].hasRole[account] = false; emit RoleRevoked(role, account, _msgSender()); return true; } else { return false; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlDefaultAdminRules.sol) pragma solidity ^0.8.20; import {IAccessControlDefaultAdminRules} from "@openzeppelin/contracts/access/extensions/IAccessControlDefaultAdminRules.sol"; import {AccessControlUpgradeable} from "../AccessControlUpgradeable.sol"; import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {IERC5313} from "@openzeppelin/contracts/interfaces/IERC5313.sol"; import {Initializable} from "../../proxy/utils/Initializable.sol"; /** * @dev Extension of {AccessControl} that allows specifying special rules to manage * the `DEFAULT_ADMIN_ROLE` holder, which is a sensitive role with special permissions * over other roles that may potentially have privileged rights in the system. * * If a specific role doesn't have an admin role assigned, the holder of the * `DEFAULT_ADMIN_ROLE` will have the ability to grant it and revoke it. * * This contract implements the following risk mitigations on top of {AccessControl}: * * * Only one account holds the `DEFAULT_ADMIN_ROLE` since deployment until it's potentially renounced. * * Enforces a 2-step process to transfer the `DEFAULT_ADMIN_ROLE` to another account. * * Enforces a configurable delay between the two steps, with the ability to cancel before the transfer is accepted. * * The delay can be changed by scheduling, see {changeDefaultAdminDelay}. * * It is not possible to use another role to manage the `DEFAULT_ADMIN_ROLE`. * * Example usage: * * ```solidity * contract MyToken is AccessControlDefaultAdminRules { * constructor() AccessControlDefaultAdminRules( * 3 days, * msg.sender // Explicit initial `DEFAULT_ADMIN_ROLE` holder * ) {} * } * ``` */ abstract contract AccessControlDefaultAdminRulesUpgradeable is Initializable, IAccessControlDefaultAdminRules, IERC5313, AccessControlUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.AccessControlDefaultAdminRules struct AccessControlDefaultAdminRulesStorage { // pending admin pair read/written together frequently address _pendingDefaultAdmin; uint48 _pendingDefaultAdminSchedule; // 0 == unset uint48 _currentDelay; address _currentDefaultAdmin; // pending delay pair read/written together frequently uint48 _pendingDelay; uint48 _pendingDelaySchedule; // 0 == unset } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControlDefaultAdminRules")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant AccessControlDefaultAdminRulesStorageLocation = 0xeef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698400; function _getAccessControlDefaultAdminRulesStorage() private pure returns (AccessControlDefaultAdminRulesStorage storage $) { assembly { $.slot := AccessControlDefaultAdminRulesStorageLocation } } /** * @dev Sets the initial values for {defaultAdminDelay} and {defaultAdmin} address. */ function __AccessControlDefaultAdminRules_init(uint48 initialDelay, address initialDefaultAdmin) internal onlyInitializing { __AccessControlDefaultAdminRules_init_unchained(initialDelay, initialDefaultAdmin); } function __AccessControlDefaultAdminRules_init_unchained(uint48 initialDelay, address initialDefaultAdmin) internal onlyInitializing { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); if (initialDefaultAdmin == address(0)) { revert AccessControlInvalidDefaultAdmin(address(0)); } $._currentDelay = initialDelay; _grantRole(DEFAULT_ADMIN_ROLE, initialDefaultAdmin); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlDefaultAdminRules).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC5313-owner}. */ function owner() public view virtual returns (address) { return defaultAdmin(); } /// /// Override AccessControl role management /// /** * @dev See {AccessControl-grantRole}. Reverts for `DEFAULT_ADMIN_ROLE`. */ function grantRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControl) { if (role == DEFAULT_ADMIN_ROLE) { revert AccessControlEnforcedDefaultAdminRules(); } super.grantRole(role, account); } /** * @dev See {AccessControl-revokeRole}. Reverts for `DEFAULT_ADMIN_ROLE`. */ function revokeRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControl) { if (role == DEFAULT_ADMIN_ROLE) { revert AccessControlEnforcedDefaultAdminRules(); } super.revokeRole(role, account); } /** * @dev See {AccessControl-renounceRole}. * * For the `DEFAULT_ADMIN_ROLE`, it only allows renouncing in two steps by first calling * {beginDefaultAdminTransfer} to the `address(0)`, so it's required that the {pendingDefaultAdmin} schedule * has also passed when calling this function. * * After its execution, it will not be possible to call `onlyRole(DEFAULT_ADMIN_ROLE)` functions. * * NOTE: Renouncing `DEFAULT_ADMIN_ROLE` will leave the contract without a {defaultAdmin}, * thereby disabling any functionality that is only available for it, and the possibility of reassigning a * non-administrated role. */ function renounceRole(bytes32 role, address account) public virtual override(AccessControlUpgradeable, IAccessControl) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) { (address newDefaultAdmin, uint48 schedule) = pendingDefaultAdmin(); if (newDefaultAdmin != address(0) || !_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) { revert AccessControlEnforcedDefaultAdminDelay(schedule); } delete $._pendingDefaultAdminSchedule; } super.renounceRole(role, account); } /** * @dev See {AccessControl-_grantRole}. * * For `DEFAULT_ADMIN_ROLE`, it only allows granting if there isn't already a {defaultAdmin} or if the * role has been previously renounced. * * NOTE: Exposing this function through another mechanism may make the `DEFAULT_ADMIN_ROLE` * assignable again. Make sure to guarantee this is the expected behavior in your implementation. */ function _grantRole(bytes32 role, address account) internal virtual override returns (bool) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); if (role == DEFAULT_ADMIN_ROLE) { if (defaultAdmin() != address(0)) { revert AccessControlEnforcedDefaultAdminRules(); } $._currentDefaultAdmin = account; } return super._grantRole(role, account); } /** * @dev See {AccessControl-_revokeRole}. */ function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) { delete $._currentDefaultAdmin; } return super._revokeRole(role, account); } /** * @dev See {AccessControl-_setRoleAdmin}. Reverts for `DEFAULT_ADMIN_ROLE`. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual override { if (role == DEFAULT_ADMIN_ROLE) { revert AccessControlEnforcedDefaultAdminRules(); } super._setRoleAdmin(role, adminRole); } /// /// AccessControlDefaultAdminRules accessors /// /** * @inheritdoc IAccessControlDefaultAdminRules */ function defaultAdmin() public view virtual returns (address) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); return $._currentDefaultAdmin; } /** * @inheritdoc IAccessControlDefaultAdminRules */ function pendingDefaultAdmin() public view virtual returns (address newAdmin, uint48 schedule) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); return ($._pendingDefaultAdmin, $._pendingDefaultAdminSchedule); } /** * @inheritdoc IAccessControlDefaultAdminRules */ function defaultAdminDelay() public view virtual returns (uint48) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); uint48 schedule = $._pendingDelaySchedule; return (_isScheduleSet(schedule) && _hasSchedulePassed(schedule)) ? $._pendingDelay : $._currentDelay; } /** * @inheritdoc IAccessControlDefaultAdminRules */ function pendingDefaultAdminDelay() public view virtual returns (uint48 newDelay, uint48 schedule) { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); schedule = $._pendingDelaySchedule; return (_isScheduleSet(schedule) && !_hasSchedulePassed(schedule)) ? ($._pendingDelay, schedule) : (0, 0); } /** * @inheritdoc IAccessControlDefaultAdminRules */ function defaultAdminDelayIncreaseWait() public view virtual returns (uint48) { return 5 days; } /// /// AccessControlDefaultAdminRules public and internal setters for defaultAdmin/pendingDefaultAdmin /// /** * @inheritdoc IAccessControlDefaultAdminRules */ function beginDefaultAdminTransfer(address newAdmin) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _beginDefaultAdminTransfer(newAdmin); } /** * @dev See {beginDefaultAdminTransfer}. * * Internal function without access restriction. */ function _beginDefaultAdminTransfer(address newAdmin) internal virtual { uint48 newSchedule = SafeCast.toUint48(block.timestamp) + defaultAdminDelay(); _setPendingDefaultAdmin(newAdmin, newSchedule); emit DefaultAdminTransferScheduled(newAdmin, newSchedule); } /** * @inheritdoc IAccessControlDefaultAdminRules */ function cancelDefaultAdminTransfer() public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _cancelDefaultAdminTransfer(); } /** * @dev See {cancelDefaultAdminTransfer}. * * Internal function without access restriction. */ function _cancelDefaultAdminTransfer() internal virtual { _setPendingDefaultAdmin(address(0), 0); } /** * @inheritdoc IAccessControlDefaultAdminRules */ function acceptDefaultAdminTransfer() public virtual { (address newDefaultAdmin, ) = pendingDefaultAdmin(); if (_msgSender() != newDefaultAdmin) { // Enforce newDefaultAdmin explicit acceptance. revert AccessControlInvalidDefaultAdmin(_msgSender()); } _acceptDefaultAdminTransfer(); } /** * @dev See {acceptDefaultAdminTransfer}. * * Internal function without access restriction. */ function _acceptDefaultAdminTransfer() internal virtual { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); (address newAdmin, uint48 schedule) = pendingDefaultAdmin(); if (!_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) { revert AccessControlEnforcedDefaultAdminDelay(schedule); } _revokeRole(DEFAULT_ADMIN_ROLE, defaultAdmin()); _grantRole(DEFAULT_ADMIN_ROLE, newAdmin); delete $._pendingDefaultAdmin; delete $._pendingDefaultAdminSchedule; } /// /// AccessControlDefaultAdminRules public and internal setters for defaultAdminDelay/pendingDefaultAdminDelay /// /** * @inheritdoc IAccessControlDefaultAdminRules */ function changeDefaultAdminDelay(uint48 newDelay) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _changeDefaultAdminDelay(newDelay); } /** * @dev See {changeDefaultAdminDelay}. * * Internal function without access restriction. */ function _changeDefaultAdminDelay(uint48 newDelay) internal virtual { uint48 newSchedule = SafeCast.toUint48(block.timestamp) + _delayChangeWait(newDelay); _setPendingDelay(newDelay, newSchedule); emit DefaultAdminDelayChangeScheduled(newDelay, newSchedule); } /** * @inheritdoc IAccessControlDefaultAdminRules */ function rollbackDefaultAdminDelay() public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _rollbackDefaultAdminDelay(); } /** * @dev See {rollbackDefaultAdminDelay}. * * Internal function without access restriction. */ function _rollbackDefaultAdminDelay() internal virtual { _setPendingDelay(0, 0); } /** * @dev Returns the amount of seconds to wait after the `newDelay` will * become the new {defaultAdminDelay}. * * The value returned guarantees that if the delay is reduced, it will go into effect * after a wait that honors the previously set delay. * * See {defaultAdminDelayIncreaseWait}. */ function _delayChangeWait(uint48 newDelay) internal view virtual returns (uint48) { uint48 currentDelay = defaultAdminDelay(); // When increasing the delay, we schedule the delay change to occur after a period of "new delay" has passed, up // to a maximum given by defaultAdminDelayIncreaseWait, by default 5 days. For example, if increasing from 1 day // to 3 days, the new delay will come into effect after 3 days. If increasing from 1 day to 10 days, the new // delay will come into effect after 5 days. The 5 day wait period is intended to be able to fix an error like // using milliseconds instead of seconds. // // When decreasing the delay, we wait the difference between "current delay" and "new delay". This guarantees // that an admin transfer cannot be made faster than "current delay" at the time the delay change is scheduled. // For example, if decreasing from 10 days to 3 days, the new delay will come into effect after 7 days. return newDelay > currentDelay ? uint48(Math.min(newDelay, defaultAdminDelayIncreaseWait())) // no need to safecast, both inputs are uint48 : currentDelay - newDelay; } /// /// Private setters /// /** * @dev Setter of the tuple for pending admin and its schedule. * * May emit a DefaultAdminTransferCanceled event. */ function _setPendingDefaultAdmin(address newAdmin, uint48 newSchedule) private { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); (, uint48 oldSchedule) = pendingDefaultAdmin(); $._pendingDefaultAdmin = newAdmin; $._pendingDefaultAdminSchedule = newSchedule; // An `oldSchedule` from `pendingDefaultAdmin()` is only set if it hasn't been accepted. if (_isScheduleSet(oldSchedule)) { // Emit for implicit cancellations when another default admin was scheduled. emit DefaultAdminTransferCanceled(); } } /** * @dev Setter of the tuple for pending delay and its schedule. * * May emit a DefaultAdminDelayChangeCanceled event. */ function _setPendingDelay(uint48 newDelay, uint48 newSchedule) private { AccessControlDefaultAdminRulesStorage storage $ = _getAccessControlDefaultAdminRulesStorage(); uint48 oldSchedule = $._pendingDelaySchedule; if (_isScheduleSet(oldSchedule)) { if (_hasSchedulePassed(oldSchedule)) { // Materialize a virtual delay $._currentDelay = $._pendingDelay; } else { // Emit for implicit cancellations when another delay was scheduled. emit DefaultAdminDelayChangeCanceled(); } } $._pendingDelay = newDelay; $._pendingDelaySchedule = newSchedule; } /// /// Private helpers /// /** * @dev Defines if an `schedule` is considered set. For consistency purposes. */ function _isScheduleSet(uint48 schedule) private pure returns (bool) { return schedule != 0; } /** * @dev Defines if an `schedule` is considered passed. For consistency purposes. */ function _hasSchedulePassed(uint48 schedule) private view returns (bool) { return schedule < block.timestamp; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.20; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Storage of the initializable contract. * * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions * when using with upgradeable contracts. * * @custom:storage-location erc7201:openzeppelin.storage.Initializable */ struct InitializableStorage { /** * @dev Indicates that the contract has been initialized. */ uint64 _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool _initializing; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00; /** * @dev The contract is already initialized. */ error InvalidInitialization(); /** * @dev The contract is not initializing. */ error NotInitializing(); /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint64 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in * production. * * Emits an {Initialized} event. */ modifier initializer() { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); // Cache values to avoid duplicated sloads bool isTopLevelCall = !$._initializing; uint64 initialized = $._initialized; // Allowed calls: // - initialSetup: the contract is not in the initializing state and no previous version was // initialized // - construction: the contract is initialized at version 1 (no reininitialization) and the // current contract is just being deployed bool initialSetup = initialized == 0 && isTopLevelCall; bool construction = initialized == 1 && address(this).code.length == 0; if (!initialSetup && !construction) { revert InvalidInitialization(); } $._initialized = 1; if (isTopLevelCall) { $._initializing = true; } _; if (isTopLevelCall) { $._initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint64 version) { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing || $._initialized >= version) { revert InvalidInitialization(); } $._initialized = version; $._initializing = true; _; $._initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { _checkInitializing(); _; } /** * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}. */ function _checkInitializing() internal view virtual { if (!_isInitializing()) { revert NotInitializing(); } } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing) { revert InvalidInitialization(); } if ($._initialized != type(uint64).max) { $._initialized = type(uint64).max; emit Initialized(type(uint64).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint64) { return _getInitializableStorage()._initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _getInitializableStorage()._initializing; } /** * @dev Returns a pointer to the storage namespace. */ // solhint-disable-next-line var-name-mixedcase function _getInitializableStorage() private pure returns (InitializableStorage storage $) { assembly { $.slot := INITIALIZABLE_STORAGE } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {Initializable} from "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` */ abstract contract ERC165Upgradeable is Initializable, IERC165 { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol) pragma solidity ^0.8.20; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.Pausable struct PausableStorage { bool _paused; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300; function _getPausableStorage() private pure returns (PausableStorage storage $) { assembly { $.slot := PausableStorageLocation } } /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); /** * @dev The operation failed because the contract is paused. */ error EnforcedPause(); /** * @dev The operation failed because the contract is not paused. */ error ExpectedPause(); /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { PausableStorage storage $ = _getPausableStorage(); $._paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { PausableStorage storage $ = _getPausableStorage(); return $._paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { if (paused()) { revert EnforcedPause(); } } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { if (!paused()) { revert ExpectedPause(); } } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant NOT_ENTERED = 1; uint256 private constant ENTERED = 2; /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard struct ReentrancyGuardStorage { uint256 _status; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00; function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) { assembly { $.slot := ReentrancyGuardStorageLocation } } /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); $._status = NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); // On the first call to nonReentrant, _status will be NOT_ENTERED if ($._status == ENTERED) { revert ReentrancyGuardReentrantCall(); } // Any calls to nonReentrant after this point will fail $._status = ENTERED; } function _nonReentrantAfter() private { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) $._status = NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); return $._status == ENTERED; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlDefaultAdminRules.sol) pragma solidity ^0.8.20; import {IAccessControl} from "../IAccessControl.sol"; /** * @dev External interface of AccessControlDefaultAdminRules declared to support ERC165 detection. */ interface IAccessControlDefaultAdminRules is IAccessControl { /** * @dev The new default admin is not a valid default admin. */ error AccessControlInvalidDefaultAdmin(address defaultAdmin); /** * @dev At least one of the following rules was violated: * * - The `DEFAULT_ADMIN_ROLE` must only be managed by itself. * - The `DEFAULT_ADMIN_ROLE` must only be held by one account at the time. * - Any `DEFAULT_ADMIN_ROLE` transfer must be in two delayed steps. */ error AccessControlEnforcedDefaultAdminRules(); /** * @dev The delay for transferring the default admin delay is enforced and * the operation must wait until `schedule`. * * NOTE: `schedule` can be 0 indicating there's no transfer scheduled. */ error AccessControlEnforcedDefaultAdminDelay(uint48 schedule); /** * @dev Emitted when a {defaultAdmin} transfer is started, setting `newAdmin` as the next * address to become the {defaultAdmin} by calling {acceptDefaultAdminTransfer} only after `acceptSchedule` * passes. */ event DefaultAdminTransferScheduled(address indexed newAdmin, uint48 acceptSchedule); /** * @dev Emitted when a {pendingDefaultAdmin} is reset if it was never accepted, regardless of its schedule. */ event DefaultAdminTransferCanceled(); /** * @dev Emitted when a {defaultAdminDelay} change is started, setting `newDelay` as the next * delay to be applied between default admin transfer after `effectSchedule` has passed. */ event DefaultAdminDelayChangeScheduled(uint48 newDelay, uint48 effectSchedule); /** * @dev Emitted when a {pendingDefaultAdminDelay} is reset if its schedule didn't pass. */ event DefaultAdminDelayChangeCanceled(); /** * @dev Returns the address of the current `DEFAULT_ADMIN_ROLE` holder. */ function defaultAdmin() external view returns (address); /** * @dev Returns a tuple of a `newAdmin` and an accept schedule. * * After the `schedule` passes, the `newAdmin` will be able to accept the {defaultAdmin} role * by calling {acceptDefaultAdminTransfer}, completing the role transfer. * * A zero value only in `acceptSchedule` indicates no pending admin transfer. * * NOTE: A zero address `newAdmin` means that {defaultAdmin} is being renounced. */ function pendingDefaultAdmin() external view returns (address newAdmin, uint48 acceptSchedule); /** * @dev Returns the delay required to schedule the acceptance of a {defaultAdmin} transfer started. * * This delay will be added to the current timestamp when calling {beginDefaultAdminTransfer} to set * the acceptance schedule. * * NOTE: If a delay change has been scheduled, it will take effect as soon as the schedule passes, making this * function returns the new delay. See {changeDefaultAdminDelay}. */ function defaultAdminDelay() external view returns (uint48); /** * @dev Returns a tuple of `newDelay` and an effect schedule. * * After the `schedule` passes, the `newDelay` will get into effect immediately for every * new {defaultAdmin} transfer started with {beginDefaultAdminTransfer}. * * A zero value only in `effectSchedule` indicates no pending delay change. * * NOTE: A zero value only for `newDelay` means that the next {defaultAdminDelay} * will be zero after the effect schedule. */ function pendingDefaultAdminDelay() external view returns (uint48 newDelay, uint48 effectSchedule); /** * @dev Starts a {defaultAdmin} transfer by setting a {pendingDefaultAdmin} scheduled for acceptance * after the current timestamp plus a {defaultAdminDelay}. * * Requirements: * * - Only can be called by the current {defaultAdmin}. * * Emits a DefaultAdminRoleChangeStarted event. */ function beginDefaultAdminTransfer(address newAdmin) external; /** * @dev Cancels a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}. * * A {pendingDefaultAdmin} not yet accepted can also be cancelled with this function. * * Requirements: * * - Only can be called by the current {defaultAdmin}. * * May emit a DefaultAdminTransferCanceled event. */ function cancelDefaultAdminTransfer() external; /** * @dev Completes a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}. * * After calling the function: * * - `DEFAULT_ADMIN_ROLE` should be granted to the caller. * - `DEFAULT_ADMIN_ROLE` should be revoked from the previous holder. * - {pendingDefaultAdmin} should be reset to zero values. * * Requirements: * * - Only can be called by the {pendingDefaultAdmin}'s `newAdmin`. * - The {pendingDefaultAdmin}'s `acceptSchedule` should've passed. */ function acceptDefaultAdminTransfer() external; /** * @dev Initiates a {defaultAdminDelay} update by setting a {pendingDefaultAdminDelay} scheduled for getting * into effect after the current timestamp plus a {defaultAdminDelay}. * * This function guarantees that any call to {beginDefaultAdminTransfer} done between the timestamp this * method is called and the {pendingDefaultAdminDelay} effect schedule will use the current {defaultAdminDelay} * set before calling. * * The {pendingDefaultAdminDelay}'s effect schedule is defined in a way that waiting until the schedule and then * calling {beginDefaultAdminTransfer} with the new delay will take at least the same as another {defaultAdmin} * complete transfer (including acceptance). * * The schedule is designed for two scenarios: * * - When the delay is changed for a larger one the schedule is `block.timestamp + newDelay` capped by * {defaultAdminDelayIncreaseWait}. * - When the delay is changed for a shorter one, the schedule is `block.timestamp + (current delay - new delay)`. * * A {pendingDefaultAdminDelay} that never got into effect will be canceled in favor of a new scheduled change. * * Requirements: * * - Only can be called by the current {defaultAdmin}. * * Emits a DefaultAdminDelayChangeScheduled event and may emit a DefaultAdminDelayChangeCanceled event. */ function changeDefaultAdminDelay(uint48 newDelay) external; /** * @dev Cancels a scheduled {defaultAdminDelay} change. * * Requirements: * * - Only can be called by the current {defaultAdmin}. * * May emit a DefaultAdminDelayChangeCanceled event. */ function rollbackDefaultAdminDelay() external; /** * @dev Maximum time in seconds for an increase to {defaultAdminDelay} (that is scheduled using {changeDefaultAdminDelay}) * to take effect. Default to 5 days. * * When the {defaultAdminDelay} is scheduled to be increased, it goes into effect after the new delay has passed with * the purpose of giving enough time for reverting any accidental change (i.e. using milliseconds instead of seconds) * that may lock the contract. However, to avoid excessive schedules, the wait is capped by this function and it can * be overrode for a custom {defaultAdminDelay} increase scheduling. * * IMPORTANT: Make sure to add a reasonable amount of time while overriding this value, otherwise, * there's a risk of setting a high new delay that goes into effect almost immediately without the * possibility of human intervention in the case of an input error (eg. set milliseconds instead of seconds). */ function defaultAdminDelayIncreaseWait() external view returns (uint48); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol) pragma solidity ^0.8.20; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev The `account` is missing a role. */ error AccessControlUnauthorizedAccount(address account, bytes32 neededRole); /** * @dev The caller of a function is not the expected one. * * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}. */ error AccessControlBadConfirmation(); /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `callerConfirmation`. */ function renounceRole(bytes32 role, address callerConfirmation) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5313.sol) pragma solidity ^0.8.20; /** * @dev Interface for the Light Contract Ownership Standard. * * A standardized minimal interface required to identify an account that controls a contract */ interface IERC5313 { /** * @dev Gets the address of the owner. */ function owner() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.20; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS } /** * @dev The signature derives the `address(0)`. */ error ECDSAInvalidSignature(); /** * @dev The signature has an invalid length. */ error ECDSAInvalidSignatureLength(uint256 length); /** * @dev The signature has an S value that is in the upper half order. */ error ECDSAInvalidSignatureS(bytes32 s); /** * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not * return address(0) without also returning an error description. Errors are documented using an enum (error type) * and a bytes32 providing additional information about the error. * * If no error is returned, then the address can be used for verification purposes. * * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length)); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature); _throwError(error, errorArg); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] */ function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) { unchecked { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); // We do not check for an overflow here since the shift operation results in 0 or 1. uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. */ function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs); _throwError(error, errorArg); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError, bytes32) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS, s); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature, bytes32(0)); } return (signer, RecoverError.NoError, bytes32(0)); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s); _throwError(error, errorArg); return recovered; } /** * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided. */ function _throwError(RecoverError error, bytes32 errorArg) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert ECDSAInvalidSignature(); } else if (error == RecoverError.InvalidSignatureLength) { revert ECDSAInvalidSignatureLength(uint256(errorArg)); } else if (error == RecoverError.InvalidSignatureS) { revert ECDSAInvalidSignatureS(errorArg); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol) pragma solidity ^0.8.20; import {Strings} from "../Strings.sol"; /** * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing. * * The library provides methods for generating a hash of a message that conforms to the * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712] * specifications. */ library MessageHashUtils { /** * @dev Returns the keccak256 digest of an EIP-191 signed data with version * `0x45` (`personal_sign` messages). * * The digest is calculated by prefixing a bytes32 `messageHash` with * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method. * * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with * keccak256, although any bytes32 value can be safely used because the final digest will * be re-hashed. * * See {ECDSA-recover}. */ function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) { /// @solidity memory-safe-assembly assembly { mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20) } } /** * @dev Returns the keccak256 digest of an EIP-191 signed data with version * `0x45` (`personal_sign` messages). * * The digest is calculated by prefixing an arbitrary `message` with * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method. * * See {ECDSA-recover}. */ function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) { return keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message)); } /** * @dev Returns the keccak256 digest of an EIP-191 signed data with version * `0x00` (data with intended validator). * * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended * `validator` address. Then hashing the result. * * See {ECDSA-recover}. */ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { return keccak256(abi.encodePacked(hex"19_00", validator, data)); } /** * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`). * * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with * `\x19\x01` and hashing the result. It corresponds to the hash signed by the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712. * * See {ECDSA-recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, hex"19_01") mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) digest := keccak256(ptr, 0x42) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol) pragma solidity ^0.8.20; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Muldiv operation overflow. */ error MathOverflowedMulDiv(); enum Rounding { Floor, // Toward negative infinity Ceil, // Toward positive infinity Trunc, // Toward zero Expand // Away from zero } /** * @dev Returns the addition of two unsigned integers, with an overflow flag. */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds towards infinity instead * of rounding towards zero. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { // Guarantee the same behavior as in a regular Solidity division. return a / b; } // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or * denominator == 0. * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by * Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. if (denominator <= prod1) { revert MathOverflowedMulDiv(); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. // Always >= 1. See https://cs.stackexchange.com/q/138556/92363. uint256 twos = denominator & (0 - denominator); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also // works in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded * towards zero. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256 of a positive value rounded towards zero. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0); } } /** * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. */ function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) { return uint8(rounding) % 2 == 1; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.20; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeCast { /** * @dev Value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value); /** * @dev An int value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedIntToUint(int256 value); /** * @dev Value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedIntDowncast(uint8 bits, int256 value); /** * @dev An uint value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedUintToInt(uint256 value); /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits */ function toUint248(uint256 value) internal pure returns (uint248) { if (value > type(uint248).max) { revert SafeCastOverflowedUintDowncast(248, value); } return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits */ function toUint240(uint256 value) internal pure returns (uint240) { if (value > type(uint240).max) { revert SafeCastOverflowedUintDowncast(240, value); } return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits */ function toUint232(uint256 value) internal pure returns (uint232) { if (value > type(uint232).max) { revert SafeCastOverflowedUintDowncast(232, value); } return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { if (value > type(uint224).max) { revert SafeCastOverflowedUintDowncast(224, value); } return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits */ function toUint216(uint256 value) internal pure returns (uint216) { if (value > type(uint216).max) { revert SafeCastOverflowedUintDowncast(216, value); } return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits */ function toUint208(uint256 value) internal pure returns (uint208) { if (value > type(uint208).max) { revert SafeCastOverflowedUintDowncast(208, value); } return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits */ function toUint200(uint256 value) internal pure returns (uint200) { if (value > type(uint200).max) { revert SafeCastOverflowedUintDowncast(200, value); } return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits */ function toUint192(uint256 value) internal pure returns (uint192) { if (value > type(uint192).max) { revert SafeCastOverflowedUintDowncast(192, value); } return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits */ function toUint184(uint256 value) internal pure returns (uint184) { if (value > type(uint184).max) { revert SafeCastOverflowedUintDowncast(184, value); } return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits */ function toUint176(uint256 value) internal pure returns (uint176) { if (value > type(uint176).max) { revert SafeCastOverflowedUintDowncast(176, value); } return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits */ function toUint168(uint256 value) internal pure returns (uint168) { if (value > type(uint168).max) { revert SafeCastOverflowedUintDowncast(168, value); } return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits */ function toUint160(uint256 value) internal pure returns (uint160) { if (value > type(uint160).max) { revert SafeCastOverflowedUintDowncast(160, value); } return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits */ function toUint152(uint256 value) internal pure returns (uint152) { if (value > type(uint152).max) { revert SafeCastOverflowedUintDowncast(152, value); } return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits */ function toUint144(uint256 value) internal pure returns (uint144) { if (value > type(uint144).max) { revert SafeCastOverflowedUintDowncast(144, value); } return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits */ function toUint136(uint256 value) internal pure returns (uint136) { if (value > type(uint136).max) { revert SafeCastOverflowedUintDowncast(136, value); } return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { if (value > type(uint128).max) { revert SafeCastOverflowedUintDowncast(128, value); } return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits */ function toUint120(uint256 value) internal pure returns (uint120) { if (value > type(uint120).max) { revert SafeCastOverflowedUintDowncast(120, value); } return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits */ function toUint112(uint256 value) internal pure returns (uint112) { if (value > type(uint112).max) { revert SafeCastOverflowedUintDowncast(112, value); } return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits */ function toUint104(uint256 value) internal pure returns (uint104) { if (value > type(uint104).max) { revert SafeCastOverflowedUintDowncast(104, value); } return uint104(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) { if (value > type(uint96).max) { revert SafeCastOverflowedUintDowncast(96, value); } return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits */ function toUint88(uint256 value) internal pure returns (uint88) { if (value > type(uint88).max) { revert SafeCastOverflowedUintDowncast(88, value); } return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits */ function toUint80(uint256 value) internal pure returns (uint80) { if (value > type(uint80).max) { revert SafeCastOverflowedUintDowncast(80, value); } return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits */ function toUint72(uint256 value) internal pure returns (uint72) { if (value > type(uint72).max) { revert SafeCastOverflowedUintDowncast(72, value); } return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { if (value > type(uint64).max) { revert SafeCastOverflowedUintDowncast(64, value); } return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits */ function toUint56(uint256 value) internal pure returns (uint56) { if (value > type(uint56).max) { revert SafeCastOverflowedUintDowncast(56, value); } return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits */ function toUint48(uint256 value) internal pure returns (uint48) { if (value > type(uint48).max) { revert SafeCastOverflowedUintDowncast(48, value); } return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits */ function toUint40(uint256 value) internal pure returns (uint40) { if (value > type(uint40).max) { revert SafeCastOverflowedUintDowncast(40, value); } return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { if (value > type(uint32).max) { revert SafeCastOverflowedUintDowncast(32, value); } return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits */ function toUint24(uint256 value) internal pure returns (uint24) { if (value > type(uint24).max) { revert SafeCastOverflowedUintDowncast(24, value); } return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { if (value > type(uint16).max) { revert SafeCastOverflowedUintDowncast(16, value); } return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits */ function toUint8(uint256 value) internal pure returns (uint8) { if (value > type(uint8).max) { revert SafeCastOverflowedUintDowncast(8, value); } return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { if (value < 0) { revert SafeCastOverflowedIntToUint(value); } return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(248, value); } } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(240, value); } } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(232, value); } } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(224, value); } } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(216, value); } } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(208, value); } } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(200, value); } } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(192, value); } } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(184, value); } } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(176, value); } } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(168, value); } } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(160, value); } } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(152, value); } } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(144, value); } } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(136, value); } } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(128, value); } } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(120, value); } } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(112, value); } } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(104, value); } } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(96, value); } } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(88, value); } } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(80, value); } } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(72, value); } } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(64, value); } } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(56, value); } } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(48, value); } } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(40, value); } } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(32, value); } } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(24, value); } } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(16, value); } } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(8, value); } } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive if (value > uint256(type(int256).max)) { revert SafeCastOverflowedUintToInt(value); } return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.20; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant HEX_DIGITS = "0123456789abcdef"; uint8 private constant ADDRESS_LENGTH = 20; /** * @dev The `value` string doesn't fit in the specified `length`. */ error StringsInsufficientHexLength(uint256 value, uint256 length); /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), HEX_DIGITS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toStringSigned(int256 value) internal pure returns (string memory) { return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { uint256 localValue = value; bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = HEX_DIGITS[localValue & 0xf]; localValue >>= 4; } if (localValue != 0) { revert StringsInsufficientHexLength(value, length); } return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal * representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: CC0-1.0 pragma solidity ^0.8.17; /** * @title An immutable registry contract to be deployed as a standalone primitive * @dev See EIP-5639, new project launches can read previous cold wallet -> hot wallet delegations * from here and integrate those permissions into their flow */ interface IDelegateRegistryV1 { /// @notice Delegation type enum DelegationType { NONE, ALL, CONTRACT, TOKEN } /// @notice Info about a single delegation, used for onchain enumeration struct DelegationInfo { DelegationType type_; address vault; address delegate; address contract_; uint256 tokenId; } /// @notice Info about a single contract-level delegation struct ContractDelegation { address contract_; address delegate; } /// @notice Info about a single token-level delegation struct TokenDelegation { address contract_; uint256 tokenId; address delegate; } /// @notice Emitted when a user delegates their entire wallet event DelegateForAll(address vault, address delegate, bool value); /// @notice Emitted when a user delegates a specific contract event DelegateForContract( address vault, address delegate, address contract_, bool value ); /// @notice Emitted when a user delegates a specific token event DelegateForToken( address vault, address delegate, address contract_, uint256 tokenId, bool value ); /// @notice Emitted when a user revokes all delegations event RevokeAllDelegates(address vault); /// @notice Emitted when a user revoes all delegations for a given delegate event RevokeDelegate(address vault, address delegate); /** * ----------- WRITE ----------- */ /** * @notice Allow the delegate to act on your behalf for all contracts * @param delegate The hotwallet to act on your behalf * @param value Whether to enable or disable delegation for this address, true for setting and false for revoking */ function delegateForAll(address delegate, bool value) external; /** * @notice Allow the delegate to act on your behalf for a specific contract * @param delegate The hotwallet to act on your behalf * @param contract_ The address for the contract you're delegating * @param value Whether to enable or disable delegation for this address, true for setting and false for revoking */ function delegateForContract( address delegate, address contract_, bool value ) external; /** * @notice Allow the delegate to act on your behalf for a specific token * @param delegate The hotwallet to act on your behalf * @param contract_ The address for the contract you're delegating * @param tokenId The token id for the token you're delegating * @param value Whether to enable or disable delegation for this address, true for setting and false for revoking */ function delegateForToken( address delegate, address contract_, uint256 tokenId, bool value ) external; /** * @notice Revoke all delegates */ function revokeAllDelegates() external; /** * @notice Revoke a specific delegate for all their permissions * @param delegate The hotwallet to revoke */ function revokeDelegate(address delegate) external; /** * @notice Remove yourself as a delegate for a specific vault * @param vault The vault which delegated to the msg.sender, and should be removed */ function revokeSelf(address vault) external; /** * ----------- READ ----------- */ /** * @notice Returns all active delegations a given delegate is able to claim on behalf of * @param delegate The delegate that you would like to retrieve delegations for * @return info Array of DelegationInfo structs */ function getDelegationsByDelegate( address delegate ) external view returns (DelegationInfo[] memory); /** * @notice Returns an array of wallet-level delegates for a given vault * @param vault The cold wallet who issued the delegation * @return addresses Array of wallet-level delegates for a given vault */ function getDelegatesForAll( address vault ) external view returns (address[] memory); /** * @notice Returns an array of contract-level delegates for a given vault and contract * @param vault The cold wallet who issued the delegation * @param contract_ The address for the contract you're delegating * @return addresses Array of contract-level delegates for a given vault and contract */ function getDelegatesForContract( address vault, address contract_ ) external view returns (address[] memory); /** * @notice Returns an array of contract-level delegates for a given vault's token * @param vault The cold wallet who issued the delegation * @param contract_ The address for the contract holding the token * @param tokenId The token id for the token you're delegating * @return addresses Array of contract-level delegates for a given vault's token */ function getDelegatesForToken( address vault, address contract_, uint256 tokenId ) external view returns (address[] memory); /** * @notice Returns all contract-level delegations for a given vault * @param vault The cold wallet who issued the delegations * @return delegations Array of ContractDelegation structs */ function getContractLevelDelegations( address vault ) external view returns (ContractDelegation[] memory delegations); /** * @notice Returns all token-level delegations for a given vault * @param vault The cold wallet who issued the delegations * @return delegations Array of TokenDelegation structs */ function getTokenLevelDelegations( address vault ) external view returns (TokenDelegation[] memory delegations); /** * @notice Returns true if the address is delegated to act on the entire vault * @param delegate The hotwallet to act on your behalf * @param vault The cold wallet who issued the delegation */ function checkDelegateForAll( address delegate, address vault ) external view returns (bool); /** * @notice Returns true if the address is delegated to act on your behalf for a token contract or an entire vault * @param delegate The hotwallet to act on your behalf * @param contract_ The address for the contract you're delegating * @param vault The cold wallet who issued the delegation */ function checkDelegateForContract( address delegate, address vault, address contract_ ) external view returns (bool); /** * @notice Returns true if the address is delegated to act on your behalf for a specific token, the token's contract or an entire vault * @param delegate The hotwallet to act on your behalf * @param contract_ The address for the contract you're delegating * @param tokenId The token id for the token you're delegating * @param vault The cold wallet who issued the delegation */ function checkDelegateForToken( address delegate, address vault, address contract_, uint256 tokenId ) external view returns (bool); }
// SPDX-License-Identifier: CC0-1.0 pragma solidity >=0.8.13; /** * @title IDelegateRegistry * @custom:version 2.0 * @custom:author foobar (0xfoobar) * @notice A standalone immutable registry storing delegated permissions from one address to another */ interface IDelegateRegistryV2 { /// @notice Delegation type, NONE is used when a delegation does not exist or is revoked enum DelegationType { NONE, ALL, CONTRACT, ERC721, ERC20, ERC1155 } /// @notice Struct for returning delegations struct Delegation { DelegationType type_; address to; address from; bytes32 rights; address contract_; uint256 tokenId; uint256 amount; } /// @notice Emitted when an address delegates or revokes rights for their entire wallet event DelegateAll( address indexed from, address indexed to, bytes32 rights, bool enable ); /// @notice Emitted when an address delegates or revokes rights for a contract address event DelegateContract( address indexed from, address indexed to, address indexed contract_, bytes32 rights, bool enable ); /// @notice Emitted when an address delegates or revokes rights for an ERC721 tokenId event DelegateERC721( address indexed from, address indexed to, address indexed contract_, uint256 tokenId, bytes32 rights, bool enable ); /// @notice Emitted when an address delegates or revokes rights for an amount of ERC20 tokens event DelegateERC20( address indexed from, address indexed to, address indexed contract_, bytes32 rights, uint256 amount ); /// @notice Emitted when an address delegates or revokes rights for an amount of an ERC1155 tokenId event DelegateERC1155( address indexed from, address indexed to, address indexed contract_, uint256 tokenId, bytes32 rights, uint256 amount ); /// @notice Thrown if multicall calldata is malformed error MulticallFailed(); /** * ----------- WRITE ----------- */ /** * @notice Call multiple functions in the current contract and return the data from all of them if they all succeed * @param data The encoded function data for each of the calls to make to this contract * @return results The results from each of the calls passed in via data */ function multicall( bytes[] calldata data ) external payable returns (bytes[] memory results); /** * @notice Allow the delegate to act on behalf of `msg.sender` for all contracts * @param to The address to act as delegate * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights * @param enable Whether to enable or disable this delegation, true delegates and false revokes * @return delegationHash The unique identifier of the delegation */ function delegateAll( address to, bytes32 rights, bool enable ) external payable returns (bytes32 delegationHash); /** * @notice Allow the delegate to act on behalf of `msg.sender` for a specific contract * @param to The address to act as delegate * @param contract_ The contract whose rights are being delegated * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights * @param enable Whether to enable or disable this delegation, true delegates and false revokes * @return delegationHash The unique identifier of the delegation */ function delegateContract( address to, address contract_, bytes32 rights, bool enable ) external payable returns (bytes32 delegationHash); /** * @notice Allow the delegate to act on behalf of `msg.sender` for a specific ERC721 token * @param to The address to act as delegate * @param contract_ The contract whose rights are being delegated * @param tokenId The token id to delegate * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights * @param enable Whether to enable or disable this delegation, true delegates and false revokes * @return delegationHash The unique identifier of the delegation */ function delegateERC721( address to, address contract_, uint256 tokenId, bytes32 rights, bool enable ) external payable returns (bytes32 delegationHash); /** * @notice Allow the delegate to act on behalf of `msg.sender` for a specific amount of ERC20 tokens * @dev The actual amount is not encoded in the hash, just the existence of a amount (since it is an upper bound) * @param to The address to act as delegate * @param contract_ The address for the fungible token contract * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights * @param amount The amount to delegate, > 0 delegates and 0 revokes * @return delegationHash The unique identifier of the delegation */ function delegateERC20( address to, address contract_, bytes32 rights, uint256 amount ) external payable returns (bytes32 delegationHash); /** * @notice Allow the delegate to act on behalf of `msg.sender` for a specific amount of ERC1155 tokens * @dev The actual amount is not encoded in the hash, just the existence of a amount (since it is an upper bound) * @param to The address to act as delegate * @param contract_ The address of the contract that holds the token * @param tokenId The token id to delegate * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights * @param amount The amount of that token id to delegate, > 0 delegates and 0 revokes * @return delegationHash The unique identifier of the delegation */ function delegateERC1155( address to, address contract_, uint256 tokenId, bytes32 rights, uint256 amount ) external payable returns (bytes32 delegationHash); /** * ----------- CHECKS ----------- */ /** * @notice Check if `to` is a delegate of `from` for the entire wallet * @param to The potential delegate address * @param from The potential address who delegated rights * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only * @return valid Whether delegate is granted to act on the from's behalf */ function checkDelegateForAll( address to, address from, bytes32 rights ) external view returns (bool); /** * @notice Check if `to` is a delegate of `from` for the specified `contract_` or the entire wallet * @param to The delegated address to check * @param contract_ The specific contract address being checked * @param from The cold wallet who issued the delegation * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only * @return valid Whether delegate is granted to act on from's behalf for entire wallet or that specific contract */ function checkDelegateForContract( address to, address from, address contract_, bytes32 rights ) external view returns (bool); /** * @notice Check if `to` is a delegate of `from` for the specific `contract` and `tokenId`, the entire `contract_`, or the entire wallet * @param to The delegated address to check * @param contract_ The specific contract address being checked * @param tokenId The token id for the token to delegating * @param from The wallet that issued the delegation * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only * @return valid Whether delegate is granted to act on from's behalf for entire wallet, that contract, or that specific tokenId */ function checkDelegateForERC721( address to, address from, address contract_, uint256 tokenId, bytes32 rights ) external view returns (bool); /** * @notice Returns the amount of ERC20 tokens the delegate is granted rights to act on the behalf of * @param to The delegated address to check * @param contract_ The address of the token contract * @param from The cold wallet who issued the delegation * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only * @return balance The delegated balance, which will be 0 if the delegation does not exist */ function checkDelegateForERC20( address to, address from, address contract_, bytes32 rights ) external view returns (uint256); /** * @notice Returns the amount of a ERC1155 tokens the delegate is granted rights to act on the behalf of * @param to The delegated address to check * @param contract_ The address of the token contract * @param tokenId The token id to check the delegated amount of * @param from The cold wallet who issued the delegation * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only * @return balance The delegated balance, which will be 0 if the delegation does not exist */ function checkDelegateForERC1155( address to, address from, address contract_, uint256 tokenId, bytes32 rights ) external view returns (uint256); /** * ----------- ENUMERATIONS ----------- */ /** * @notice Returns all enabled delegations a given delegate has received * @param to The address to retrieve delegations for * @return delegations Array of Delegation structs */ function getIncomingDelegations( address to ) external view returns (Delegation[] memory delegations); /** * @notice Returns all enabled delegations an address has given out * @param from The address to retrieve delegations for * @return delegations Array of Delegation structs */ function getOutgoingDelegations( address from ) external view returns (Delegation[] memory delegations); /** * @notice Returns all hashes associated with enabled delegations an address has received * @param to The address to retrieve incoming delegation hashes for * @return delegationHashes Array of delegation hashes */ function getIncomingDelegationHashes( address to ) external view returns (bytes32[] memory delegationHashes); /** * @notice Returns all hashes associated with enabled delegations an address has given out * @param from The address to retrieve outgoing delegation hashes for * @return delegationHashes Array of delegation hashes */ function getOutgoingDelegationHashes( address from ) external view returns (bytes32[] memory delegationHashes); /** * @notice Returns the delegations for a given array of delegation hashes * @param delegationHashes is an array of hashes that correspond to delegations * @return delegations Array of Delegation structs, return empty structs for nonexistent or revoked delegations */ function getDelegationsFromHashes( bytes32[] calldata delegationHashes ) external view returns (Delegation[] memory delegations); /** * ----------- STORAGE ACCESS ----------- */ /** * @notice Allows external contracts to read arbitrary storage slots */ function readSlot(bytes32 location) external view returns (bytes32); /** * @notice Allows external contracts to read an arbitrary array of storage slots */ function readSlots( bytes32[] calldata locations ) external view returns (bytes32[] memory); }
{ "optimizer": { "enabled": true, "runs": 200 }, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"uint48","name":"schedule","type":"uint48"}],"name":"AccessControlEnforcedDefaultAdminDelay","type":"error"},{"inputs":[],"name":"AccessControlEnforcedDefaultAdminRules","type":"error"},{"inputs":[{"internalType":"address","name":"defaultAdmin","type":"address"}],"name":"AccessControlInvalidDefaultAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[],"name":"AlreadyRefunded","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidFunds","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidState","type":"error"},{"inputs":[],"name":"MustReserveAtLeastOneLot","type":"error"},{"inputs":[],"name":"NoRefundNeeded","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"PriceNotSet","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"ReserveTooManyLots","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[],"name":"UnsetFinanceWallet","type":"error"},{"inputs":[],"name":"WithdrawFailed","type":"error"},{"anonymous":false,"inputs":[],"name":"DefaultAdminDelayChangeCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"newDelay","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"effectSchedule","type":"uint48"}],"name":"DefaultAdminDelayChangeScheduled","type":"event"},{"anonymous":false,"inputs":[],"name":"DefaultAdminTransferCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"},{"indexed":false,"internalType":"uint48","name":"acceptSchedule","type":"uint48"}],"name":"DefaultAdminTransferScheduled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EventRefunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint16","name":"guaranteedLots","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"waitlistLots","type":"uint16"}],"name":"EventReserved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEVELOPER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"beginDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"}],"name":"changeDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelay","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelayIncreaseWait","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"financeWalletAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllRefundStatus","outputs":[{"internalType":"address[]","name":"wallets","type":"address[]"},{"internalType":"bool[]","name":"status","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllReservations","outputs":[{"internalType":"address[]","name":"reserversList","type":"address[]"},{"internalType":"uint256[]","name":"guaranteedList","type":"uint256[]"},{"internalType":"uint256[]","name":"waitlistList","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"getRefundStatus","outputs":[{"internalType":"bool","name":"isRefunded","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"getReservation","outputs":[{"internalType":"uint256","name":"guaranteed","type":"uint256"},{"internalType":"uint256","name":"waitlist","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_initialOwner","type":"address"},{"internalType":"address","name":"_signer","type":"address"},{"internalType":"address","name":"_financeWalletAddress","type":"address"},{"internalType":"address[]","name":"_developers","type":"address[]"},{"internalType":"uint256","name":"_pricePerLot","type":"uint256"},{"internalType":"address","name":"_delegateRegistryV1","type":"address"},{"internalType":"address","name":"_delegateRegistryV2","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdmin","outputs":[{"internalType":"address","name":"newAdmin","type":"address"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdminDelay","outputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pricePerLot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_successfulWaitlistCount","type":"uint16"},{"internalType":"address","name":"_coldWallet","type":"address"},{"internalType":"bytes","name":"_salt","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"refund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_guaranteedLots","type":"uint16"},{"internalType":"uint16","name":"_waitlistLots","type":"uint16"},{"internalType":"uint16","name":"_lotsToReserve","type":"uint16"},{"internalType":"bytes","name":"_salt","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"},{"internalType":"address","name":"_coldWallet","type":"address"}],"name":"reserve","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rollbackDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_financeWalletAddress","type":"address"}],"name":"setFinanceWalletAddress","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pricePerLot","type":"uint256"}],"name":"setPricePerLot","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"enum MonPresale.State","name":"_state","type":"uint8"}],"name":"setState","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"signer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"state","outputs":[{"internalType":"enum MonPresale.State","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_securedLots","type":"uint256"}],"name":"withdrawFunds","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b506200001c62000022565b620000d6565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff1615620000735760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b0390811614620000d35780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b612ea380620000e66000396000f3fe6080604052600436106102305760003560e01c80636c19e7831161012e578063b2066f80116100ab578063cf6eefb71161006f578063cf6eefb714610685578063d547741f146106c0578063d602b9fd146106e0578063e63723fa146106f5578063fbc628331461071557600080fd5b8063b2066f80146105b7578063b75663c814610611578063c19d93fb14610634578063cc8463c81461065b578063cefc14291461067057600080fd5b80639103a0e0116100f25780639103a0e01461051957806391d148541461053b578063a1eda53c1461055b578063a217fddf1461058f578063b1a47064146105a457600080fd5b80636c19e783146104b25780638456cb59146104c557806384ef8ffc146104da578063853828b6146104ef5780638da5cb5b1461050457600080fd5b80633edf4fd6116101bc5780635c975abb116101805780635c975abb14610401578063634e93da14610426578063639c9a2d14610446578063649a5ec71461045957806365c2944e1461047957600080fd5b80633edf4fd6146103905780633f4ba83a146103b057806356181bac146103c557806356de96db146103db5780635c6c09e9146103ee57600080fd5b8063238ac93311610203578063238ac933146102ca578063248a9ca3146103025780632f2ff15d14610330578063343039d51461035057806336568abe1461037057600080fd5b806301ffc9a714610235578063022d63fb1461026a5780630aa6220b14610293578063155dd5ee146102aa575b600080fd5b34801561024157600080fd5b5061025561025036600461277f565b610739565b60405190151581526020015b60405180910390f35b34801561027657600080fd5b50620697805b60405165ffffffffffff9091168152602001610261565b34801561029f57600080fd5b506102a8610764565b005b3480156102b657600080fd5b506102a86102c53660046127a9565b61077a565b3480156102d657600080fd5b506004546102ea906001600160a01b031681565b6040516001600160a01b039091168152602001610261565b34801561030e57600080fd5b5061032261031d3660046127a9565b610893565b604051908152602001610261565b34801561033c57600080fd5b506102a861034b3660046127de565b6108b5565b34801561035c57600080fd5b506003546102ea906001600160a01b031681565b34801561037c57600080fd5b506102a861038b3660046127de565b6108e1565b34801561039c57600080fd5b506102a86103ab366004612865565b6109a5565b3480156103bc57600080fd5b506102a8610c96565b3480156103d157600080fd5b5061032260025481565b6102a86103e93660046128f6565b610cb6565b6102a86103fc366004612917565b610cf6565b34801561040d57600080fd5b50600080516020612e0e8339815191525460ff16610255565b34801561043257600080fd5b506102a8610441366004612917565b610d53565b6102a86104543660046127a9565b610d67565b34801561046557600080fd5b506102a8610474366004612932565b610dc3565b34801561048557600080fd5b50610255610494366004612917565b6001600160a01b031660009081526006602052604090205460ff1690565b6102a86104c0366004612917565b610dd7565b3480156104d157600080fd5b506102a8610e41565b3480156104e657600080fd5b506102ea610e61565b3480156104fb57600080fd5b506102a8610e7d565b34801561051057600080fd5b506102ea610f64565b34801561052557600080fd5b50610322600080516020612dae83398151915281565b34801561054757600080fd5b506102556105563660046127de565b610f73565b34801561056757600080fd5b50610570610fab565b6040805165ffffffffffff938416815292909116602083015201610261565b34801561059b57600080fd5b50610322600081565b6102a86105b236600461295a565b61101e565b3480156105c357600080fd5b506105fc6105d2366004612917565b6001600160a01b031660009081526005602052604090205461ffff80821692620100009092041690565b60408051928352602083019190915201610261565b34801561061d57600080fd5b506106266112a2565b604051610261929190612a50565b34801561064057600080fd5b5060005461064e9060ff1681565b6040516102619190612abf565b34801561066757600080fd5b5061027c6113d5565b34801561067c57600080fd5b506102a8611453565b34801561069157600080fd5b5061069a611493565b604080516001600160a01b03909316835265ffffffffffff909116602083015201610261565b3480156106cc57600080fd5b506102a86106db3660046127de565b6114c1565b3480156106ec57600080fd5b506102a86114e9565b34801561070157600080fd5b506102a8610710366004612ae7565b6114fc565b34801561072157600080fd5b5061072a61172a565b60405161026193929190612bda565b60006001600160e01b031982166318a4c3c360e11b148061075e575061075e8261192b565b92915050565b600061076f81611960565b61077761196a565b50565b600061078581611960565b61078d611977565b6003546001600160a01b03166107b657604051636be25ca360e01b815260040160405180910390fd5b6000805460ff1660048111156107ce576107ce612aa9565b14806107f05750600160005460ff1660048111156107ee576107ee612aa9565b145b1561080e5760405163baf3f0f760e01b815260040160405180910390fd5b6003546002546000916001600160a01b03169061082b9085612c33565b604051600081818185875af1925050503d8060008114610867576040519150601f19603f3d011682016040523d82523d6000602084013e61086c565b606091505b505090508061088e57604051631d42c86760e21b815260040160405180910390fd5b505050565b6000908152600080516020612dee833981519152602052604090206001015490565b816108d357604051631fe1e13d60e11b815260040160405180910390fd5b6108dd82826119a8565b5050565b600080516020612dce833981519152821580156109165750610901610e61565b6001600160a01b0316826001600160a01b0316145b1561099b57600080610926611493565b90925090506001600160a01b038216151580610948575065ffffffffffff8116155b8061095b57504265ffffffffffff821610155b15610988576040516319ca5ebb60e01b815265ffffffffffff821660048201526024015b60405180910390fd5b5050805465ffffffffffff60a01b191681555b61088e83836119ca565b6109ad6119fd565b6109b5611977565b600360005460ff1660048111156109ce576109ce612aa9565b146109ec5760405163baf3f0f760e01b815260040160405180910390fd5b60006109f786611a35565b6001600160a01b03811660009081526006602052604090205490915060ff1615610a345760405163542f378d60e11b815260040160405180910390fd5b6001600160a01b03811660009081526005602052604090205461ffff62010000909104811690881610610a7a5760405163ebb4ee0760e01b815260040160405180910390fd5b600085858984604051602001610a939493929190612c4a565b604051602081830303815290604052805190602001209050610af684848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610af09250859150611ba09050565b90611bd3565b6004546001600160a01b03908116911614610b2457604051638baa579f60e01b815260040160405180910390fd5b6002546001600160a01b038316600090815260056020526040812054909190610b58908b9062010000900461ffff16612c87565b61ffff16610b669190612c33565b6001600160a01b038416600081815260066020526040808220805460ff1916600190811790915560078054918201815583527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c6880180546001600160a01b03191684179055519293509183908381818185875af1925050503d8060008114610c09576040519150601f19603f3d011682016040523d82523d6000602084013e610c0e565b606091505b5050905080610c3057604051631d42c86760e21b815260040160405180910390fd5b836001600160a01b03167f63f0c6828e5ca4c6c9759e55ab66061d99ca532380fd9306da9edc5f297d522783604051610c6b91815260200190565b60405180910390a250505050610c8e6001600080516020612e2e83398151915255565b505050505050565b600080516020612dae833981519152610cae81611960565b610777611c11565b600080516020612dae833981519152610cce81611960565b6000805483919060ff19166001836004811115610ced57610ced612aa9565b02179055505050565b6000610d0181611960565b610d09611977565b6001600160a01b038216610d305760405163e6c4247b60e01b815260040160405180910390fd5b50600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000610d5e81611960565b6108dd82611c71565b600080516020612dae833981519152610d7f81611960565b610d87611977565b6000805460ff166004811115610d9f57610d9f612aa9565b14610dbd5760405163baf3f0f760e01b815260040160405180910390fd5b50600255565b6000610dce81611960565b6108dd82611ce4565b600080516020612dae833981519152610def81611960565b610df7611977565b6001600160a01b038216610e1e5760405163e6c4247b60e01b815260040160405180910390fd5b50600480546001600160a01b0319166001600160a01b0392909216919091179055565b600080516020612dae833981519152610e5981611960565b610777611d54565b600080516020612e4e833981519152546001600160a01b031690565b6000610e8881611960565b610e90611977565b6003546001600160a01b0316610eb957604051636be25ca360e01b815260040160405180910390fd5b600460005460ff166004811115610ed257610ed2612aa9565b14610ef05760405163baf3f0f760e01b815260040160405180910390fd5b6003546040516000916001600160a01b03169047908381818185875af1925050503d8060008114610f3d576040519150601f19603f3d011682016040523d82523d6000602084013e610f42565b606091505b50509050806108dd57604051631d42c86760e21b815260040160405180910390fd5b6000610f6e610e61565b905090565b6000918252600080516020612dee833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600080516020612e4e83398151915254600090600160d01b900465ffffffffffff16600080516020612dce8339815191528115801590610ff357504265ffffffffffff831610155b610fff57600080611015565b6001810154600160a01b900465ffffffffffff16825b92509250509091565b6110266119fd565b61102e611977565b600061103982611a35565b905061104b818a8a8a8a8a8a8a611d9d565b6001600160a01b0381166000908152600560205260408120546110729061ffff168b612c87565b905060008161ffff168961ffff161161108b578861108d565b815b905060008261ffff168a61ffff16116110a75760006110b1565b6110b1838b612c87565b6001600160a01b03851660009081526005602052604090205490915061ffff161580156110fe57506001600160a01b03841660009081526005602052604090205462010000900461ffff16155b1561119a5760088054600181019091557ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0386166001600160a01b0319909116811790915560408051808201825261ffff80861682528481166020838101918252600095865260059052929093209051815492518416620100000263ffffffff19909316931692909217179055611234565b6001600160a01b0384166000908152600560205260409020546111c290839061ffff16612ca2565b6001600160a01b0385166000908152600560205260409020805461ffff191661ffff92831617908190556111fe91839162010000900416612ca2565b6001600160a01b0385166000908152600560205260409020805461ffff92909216620100000263ffff0000199092169190911790555b6040805161ffff808f1682528d1660208201526001600160a01b038616917fee291955cc75edc853c7af08c8c88b7040846622baff2403443608bca44f92fc910160405180910390a2505050506112986001600080516020612e2e83398151915255565b5050505050505050565b606080600060078054905067ffffffffffffffff8111156112c5576112c5612cbd565b6040519080825280602002602001820160405280156112ee578160200160208202803683370190505b50905060005b60075481101561136c57600660006007838154811061131557611315612cd3565b60009182526020808320909101546001600160a01b03168352820192909252604001902054825160ff9091169083908390811061135457611354612cd3565b911515602092830291909101909101526001016112f4565b50600781818054806020026020016040519081016040528092919081815260200182805480156113c557602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116113a7575b5050505050915092509250509091565b600080516020612e4e83398151915254600090600080516020612dce83398151915290600160d01b900465ffffffffffff16801580159061141d57504265ffffffffffff8216105b611437578154600160d01b900465ffffffffffff1661144c565b6001820154600160a01b900465ffffffffffff165b9250505090565b600061145d611493565b509050336001600160a01b0382161461148b57604051636116401160e11b815233600482015260240161097f565b610777611f7b565b600080516020612dce833981519152546001600160a01b03811691600160a01b90910465ffffffffffff1690565b816114df57604051631fe1e13d60e11b815260040160405180910390fd5b6108dd8282612018565b60006114f481611960565b610777612034565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff166000811580156115425750825b905060008267ffffffffffffffff16600114801561155f5750303b155b90508115801561156d575080155b1561158b5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff1916600117855583156115b557845460ff60401b1916600160401b1785555b6115c2620151808e61203f565b6115ca612051565b6115d2612061565b6115ea600080516020612dae8339815191528e612071565b5060005b8981101561163d57611634600080516020612dae8339815191528c8c8481811061161a5761161a612cd3565b905060200201602081019061162f9190612917565b612071565b506001016115ee565b506001600160a01b038b16158061165b57506001600160a01b038c16155b156116795760405163e6c4247b60e01b815260040160405180910390fd5b600380546001600160a01b03199081166001600160a01b038e8116919091179092556004805482168f841617905560028a905560008054610100600160a81b0319166101008b85160217905560018054909116918816919091179055831561171b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050505050505050565b6060806060600080516020612dae83398151915261174781611960565b60085460009067ffffffffffffffff81111561176557611765612cbd565b60405190808252806020026020018201604052801561178e578160200160208202803683370190505b5060085490915060009067ffffffffffffffff8111156117b0576117b0612cbd565b6040519080825280602002602001820160405280156117d9578160200160208202803683370190505b50905060005b6008548110156118bc57600560006008838154811061180057611800612cd3565b60009182526020808320909101546001600160a01b03168352820192909252604001902054835161ffff9091169084908390811061184057611840612cd3565b602002602001018181525050600560006008838154811061186357611863612cd3565b6000918252602080832091909101546001600160a01b0316835282019290925260400190205482516201000090910461ffff16908390839081106118a9576118a9612cd3565b60209081029190910101526001016117df565b50600882828280548060200260200160405190810160405280929190818152602001828054801561191657602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116118f8575b50505050509250955095509550505050909192565b60006001600160e01b03198216637965db0b60e01b148061075e57506301ffc9a760e01b6001600160e01b031983161461075e565b61077781336120e8565b611975600080612121565b565b600080516020612e0e8339815191525460ff16156119755760405163d93c066560e01b815260040160405180910390fd5b6119b182610893565b6119ba81611960565b6119c48383612071565b50505050565b6001600160a01b03811633146119f35760405163334bd91960e11b815260040160405180910390fd5b61088e82826121fc565b600080516020612e2e833981519152805460011901611a2f57604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b60006001600160a01b038216611a4b573361075e565b6001546000906001600160a01b0316638988eea9336040516001600160e01b031960e084901b1681526001600160a01b039182166004820152908616602482015230604482015260006064820152608401602060405180830381865afa158015611ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611add9190612ce9565b90508015611aec575090919050565b60005461010090046001600160a01b03166390c9a2d0336040516001600160e01b031960e084901b1681526001600160a01b0391821660048201529086166024820152306044820152606401602060405180830381865afa158015611b55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b799190612ce9565b905080611b9957604051632d618d8160e21b815260040160405180910390fd5b5090919050565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b600080600080611be38686612255565b925092509250611bf382826122a2565b5090949350505050565b6001600080516020612e2e83398151915255565b611c1961235b565b600080516020612e0e833981519152805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b6000611c7b6113d5565b611c844261238b565b611c8e9190612d0b565b9050611c9a82826123c2565b60405165ffffffffffff821681526001600160a01b038316907f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed69060200160405180910390a25050565b6000611cef8261244f565b611cf84261238b565b611d029190612d0b565b9050611d0e8282612121565b6040805165ffffffffffff8085168252831660208201527ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b910160405180910390a15050565b611d5c611977565b600080516020612e0e833981519152805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611c53565b600160005460ff166004811115611db657611db6612aa9565b14611dd45760405163baf3f0f760e01b815260040160405180910390fd5b8461ffff16600003611df957604051630d3e758f60e31b815260040160405180910390fd5b611e0a61ffff808816908916612d2a565b6001600160a01b03891660009081526005602052604090205463ffffffff919091169061ffff620100008204811691611e4891908116908916612d2a565b611e529190612d2a565b63ffffffff161115611e775760405163019f02c360e31b815260040160405180910390fd5b600254600003611e9a576040516313a8ad7d60e11b815260040160405180910390fd5b600254611eab9061ffff8716612c33565b3414611eca576040516394b5970f60e01b815260040160405180910390fd5b6000848489898c604051602001611ee5959493929190612d47565b604051602081830303815290604052805190602001209050611f4283838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610af09250859150611ba09050565b6004546001600160a01b03908116911614611f7057604051638baa579f60e01b815260040160405180910390fd5b505050505050505050565b600080516020612dce833981519152600080611f95611493565b91509150611faa8165ffffffffffff16151590565b1580611fbe57504265ffffffffffff821610155b15611fe6576040516319ca5ebb60e01b815265ffffffffffff8216600482015260240161097f565b611ff86000611ff3610e61565b6121fc565b50612004600083612071565b505081546001600160d01b03191690915550565b61202182610893565b61202a81611960565b6119c483836121fc565b6119756000806123c2565b61204761249e565b6108dd82826124e7565b61205961249e565b611975612550565b61206961249e565b611975612558565b6000600080516020612dce833981519152836120d6576000612091610e61565b6001600160a01b0316146120b857604051631fe1e13d60e11b815260040160405180910390fd5b6001810180546001600160a01b0319166001600160a01b0385161790555b6120e08484612579565b949350505050565b6120f28282610f73565b6108dd5760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161097f565b600080516020612e4e83398151915254600080516020612dce83398151915290600160d01b900465ffffffffffff1680156121be574265ffffffffffff8216101561219457600182015482546001600160d01b0316600160a01b90910465ffffffffffff16600160d01b021782556121be565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec590600090a15b5060010180546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b6000600080516020612dce83398151915283158015612233575061221e610e61565b6001600160a01b0316836001600160a01b0316145b1561224b576001810180546001600160a01b03191690555b6120e08484612625565b6000806000835160410361228f5760208401516040850151606086015160001a612281888285856126a1565b95509550955050505061229b565b50508151600091506002905b9250925092565b60008260038111156122b6576122b6612aa9565b036122bf575050565b60018260038111156122d3576122d3612aa9565b036122f15760405163f645eedf60e01b815260040160405180910390fd5b600282600381111561230557612305612aa9565b036123265760405163fce698f760e01b81526004810182905260240161097f565b600382600381111561233a5761233a612aa9565b036108dd576040516335e2f38360e21b81526004810182905260240161097f565b600080516020612e0e8339815191525460ff1661197557604051638dfc202b60e01b815260040160405180910390fd5b600065ffffffffffff8211156123be576040516306dfcc6560e41b8152603060048201526024810183905260440161097f565b5090565b600080516020612dce83398151915260006123db611493565b835465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b03881617178455915061241b90508165ffffffffffff16151590565b156119c4576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510990600090a150505050565b60008061245a6113d5565b90508065ffffffffffff168365ffffffffffff16116124825761247d8382612d8e565b612497565b61249765ffffffffffff841662069780612770565b9392505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661197557604051631afcd79f60e31b815260040160405180910390fd5b6124ef61249e565b600080516020612dce8339815191526001600160a01b03821661252857604051636116401160e11b81526000600482015260240161097f565b80546001600160d01b0316600160d01b65ffffffffffff8516021781556119c4600083612071565b611bfd61249e565b61256061249e565b600080516020612e0e833981519152805460ff19169055565b6000600080516020612dee8339815191526125948484610f73565b612614576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556125ca3390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4600191505061075e565b600091505061075e565b5092915050565b6000600080516020612dee8339815191526126408484610f73565b15612614576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4600191505061075e565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411156126dc5750600091506003905082612766565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015612730573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661275c57506000925060019150829050612766565b9250600091508190505b9450945094915050565b6000818310611b995781612497565b60006020828403121561279157600080fd5b81356001600160e01b03198116811461249757600080fd5b6000602082840312156127bb57600080fd5b5035919050565b80356001600160a01b03811681146127d957600080fd5b919050565b600080604083850312156127f157600080fd5b82359150612801602084016127c2565b90509250929050565b803561ffff811681146127d957600080fd5b60008083601f84011261282e57600080fd5b50813567ffffffffffffffff81111561284657600080fd5b60208301915083602082850101111561285e57600080fd5b9250929050565b6000806000806000806080878903121561287e57600080fd5b6128878761280a565b9550612895602088016127c2565b9450604087013567ffffffffffffffff808211156128b257600080fd5b6128be8a838b0161281c565b909650945060608901359150808211156128d757600080fd5b506128e489828a0161281c565b979a9699509497509295939492505050565b60006020828403121561290857600080fd5b81356005811061249757600080fd5b60006020828403121561292957600080fd5b612497826127c2565b60006020828403121561294457600080fd5b813565ffffffffffff8116811461249757600080fd5b60008060008060008060008060c0898b03121561297657600080fd5b61297f8961280a565b975061298d60208a0161280a565b965061299b60408a0161280a565b9550606089013567ffffffffffffffff808211156129b857600080fd5b6129c48c838d0161281c565b909750955060808b01359150808211156129dd57600080fd5b506129ea8b828c0161281c565b90945092506129fd905060a08a016127c2565b90509295985092959890939650565b600081518084526020808501945080840160005b83811015612a455781516001600160a01b031687529582019590820190600101612a20565b509495945050505050565b604081526000612a636040830185612a0c565b82810360208481019190915284518083528582019282019060005b81811015612a9c578451151583529383019391830191600101612a7e565b5090979650505050505050565b634e487b7160e01b600052602160045260246000fd5b6020810160058310612ae157634e487b7160e01b600052602160045260246000fd5b91905290565b60008060008060008060008060e0898b031215612b0357600080fd5b612b0c896127c2565b9750612b1a60208a016127c2565b9650612b2860408a016127c2565b9550606089013567ffffffffffffffff80821115612b4557600080fd5b818b0191508b601f830112612b5957600080fd5b813581811115612b6857600080fd5b8c60208260051b8501011115612b7d57600080fd5b60208301975080965050505060808901359250612b9c60a08a016127c2565b91506129fd60c08a016127c2565b600081518084526020808501945080840160005b83811015612a4557815187529582019590820190600101612bbe565b606081526000612bed6060830186612a0c565b8281036020840152612bff8186612baa565b90508281036040840152612c138185612baa565b9695505050505050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761075e5761075e612c1d565b8385823760f09290921b6001600160f01b0319169190920190815260609190911b6bffffffffffffffffffffffff19166002820152601601919050565b61ffff82811682821603908082111561261e5761261e612c1d565b61ffff81811683821601908082111561261e5761261e612c1d565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060208284031215612cfb57600080fd5b8151801515811461249757600080fd5b65ffffffffffff81811683821601908082111561261e5761261e612c1d565b63ffffffff81811683821601908082111561261e5761261e612c1d565b8486823760f093841b6001600160f01b0319908116919095019081529190921b909216600283015260601b6bffffffffffffffffffffffff19166004820152601801919050565b65ffffffffffff82811682821603908082111561261e5761261e612c1d56fe2714cbbaddbb71bcae9366d8bf7770636ec7ae63227b573986d2f54fffacb39deef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d869840002dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00eef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698401a26469706673582212202c78d6605de2e42eda1afe594d9384829afcb82d68d9e1b22ef5d3ae543ec2e064736f6c63430008140033
Deployed Bytecode
0x6080604052600436106102305760003560e01c80636c19e7831161012e578063b2066f80116100ab578063cf6eefb71161006f578063cf6eefb714610685578063d547741f146106c0578063d602b9fd146106e0578063e63723fa146106f5578063fbc628331461071557600080fd5b8063b2066f80146105b7578063b75663c814610611578063c19d93fb14610634578063cc8463c81461065b578063cefc14291461067057600080fd5b80639103a0e0116100f25780639103a0e01461051957806391d148541461053b578063a1eda53c1461055b578063a217fddf1461058f578063b1a47064146105a457600080fd5b80636c19e783146104b25780638456cb59146104c557806384ef8ffc146104da578063853828b6146104ef5780638da5cb5b1461050457600080fd5b80633edf4fd6116101bc5780635c975abb116101805780635c975abb14610401578063634e93da14610426578063639c9a2d14610446578063649a5ec71461045957806365c2944e1461047957600080fd5b80633edf4fd6146103905780633f4ba83a146103b057806356181bac146103c557806356de96db146103db5780635c6c09e9146103ee57600080fd5b8063238ac93311610203578063238ac933146102ca578063248a9ca3146103025780632f2ff15d14610330578063343039d51461035057806336568abe1461037057600080fd5b806301ffc9a714610235578063022d63fb1461026a5780630aa6220b14610293578063155dd5ee146102aa575b600080fd5b34801561024157600080fd5b5061025561025036600461277f565b610739565b60405190151581526020015b60405180910390f35b34801561027657600080fd5b50620697805b60405165ffffffffffff9091168152602001610261565b34801561029f57600080fd5b506102a8610764565b005b3480156102b657600080fd5b506102a86102c53660046127a9565b61077a565b3480156102d657600080fd5b506004546102ea906001600160a01b031681565b6040516001600160a01b039091168152602001610261565b34801561030e57600080fd5b5061032261031d3660046127a9565b610893565b604051908152602001610261565b34801561033c57600080fd5b506102a861034b3660046127de565b6108b5565b34801561035c57600080fd5b506003546102ea906001600160a01b031681565b34801561037c57600080fd5b506102a861038b3660046127de565b6108e1565b34801561039c57600080fd5b506102a86103ab366004612865565b6109a5565b3480156103bc57600080fd5b506102a8610c96565b3480156103d157600080fd5b5061032260025481565b6102a86103e93660046128f6565b610cb6565b6102a86103fc366004612917565b610cf6565b34801561040d57600080fd5b50600080516020612e0e8339815191525460ff16610255565b34801561043257600080fd5b506102a8610441366004612917565b610d53565b6102a86104543660046127a9565b610d67565b34801561046557600080fd5b506102a8610474366004612932565b610dc3565b34801561048557600080fd5b50610255610494366004612917565b6001600160a01b031660009081526006602052604090205460ff1690565b6102a86104c0366004612917565b610dd7565b3480156104d157600080fd5b506102a8610e41565b3480156104e657600080fd5b506102ea610e61565b3480156104fb57600080fd5b506102a8610e7d565b34801561051057600080fd5b506102ea610f64565b34801561052557600080fd5b50610322600080516020612dae83398151915281565b34801561054757600080fd5b506102556105563660046127de565b610f73565b34801561056757600080fd5b50610570610fab565b6040805165ffffffffffff938416815292909116602083015201610261565b34801561059b57600080fd5b50610322600081565b6102a86105b236600461295a565b61101e565b3480156105c357600080fd5b506105fc6105d2366004612917565b6001600160a01b031660009081526005602052604090205461ffff80821692620100009092041690565b60408051928352602083019190915201610261565b34801561061d57600080fd5b506106266112a2565b604051610261929190612a50565b34801561064057600080fd5b5060005461064e9060ff1681565b6040516102619190612abf565b34801561066757600080fd5b5061027c6113d5565b34801561067c57600080fd5b506102a8611453565b34801561069157600080fd5b5061069a611493565b604080516001600160a01b03909316835265ffffffffffff909116602083015201610261565b3480156106cc57600080fd5b506102a86106db3660046127de565b6114c1565b3480156106ec57600080fd5b506102a86114e9565b34801561070157600080fd5b506102a8610710366004612ae7565b6114fc565b34801561072157600080fd5b5061072a61172a565b60405161026193929190612bda565b60006001600160e01b031982166318a4c3c360e11b148061075e575061075e8261192b565b92915050565b600061076f81611960565b61077761196a565b50565b600061078581611960565b61078d611977565b6003546001600160a01b03166107b657604051636be25ca360e01b815260040160405180910390fd5b6000805460ff1660048111156107ce576107ce612aa9565b14806107f05750600160005460ff1660048111156107ee576107ee612aa9565b145b1561080e5760405163baf3f0f760e01b815260040160405180910390fd5b6003546002546000916001600160a01b03169061082b9085612c33565b604051600081818185875af1925050503d8060008114610867576040519150601f19603f3d011682016040523d82523d6000602084013e61086c565b606091505b505090508061088e57604051631d42c86760e21b815260040160405180910390fd5b505050565b6000908152600080516020612dee833981519152602052604090206001015490565b816108d357604051631fe1e13d60e11b815260040160405180910390fd5b6108dd82826119a8565b5050565b600080516020612dce833981519152821580156109165750610901610e61565b6001600160a01b0316826001600160a01b0316145b1561099b57600080610926611493565b90925090506001600160a01b038216151580610948575065ffffffffffff8116155b8061095b57504265ffffffffffff821610155b15610988576040516319ca5ebb60e01b815265ffffffffffff821660048201526024015b60405180910390fd5b5050805465ffffffffffff60a01b191681555b61088e83836119ca565b6109ad6119fd565b6109b5611977565b600360005460ff1660048111156109ce576109ce612aa9565b146109ec5760405163baf3f0f760e01b815260040160405180910390fd5b60006109f786611a35565b6001600160a01b03811660009081526006602052604090205490915060ff1615610a345760405163542f378d60e11b815260040160405180910390fd5b6001600160a01b03811660009081526005602052604090205461ffff62010000909104811690881610610a7a5760405163ebb4ee0760e01b815260040160405180910390fd5b600085858984604051602001610a939493929190612c4a565b604051602081830303815290604052805190602001209050610af684848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610af09250859150611ba09050565b90611bd3565b6004546001600160a01b03908116911614610b2457604051638baa579f60e01b815260040160405180910390fd5b6002546001600160a01b038316600090815260056020526040812054909190610b58908b9062010000900461ffff16612c87565b61ffff16610b669190612c33565b6001600160a01b038416600081815260066020526040808220805460ff1916600190811790915560078054918201815583527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c6880180546001600160a01b03191684179055519293509183908381818185875af1925050503d8060008114610c09576040519150601f19603f3d011682016040523d82523d6000602084013e610c0e565b606091505b5050905080610c3057604051631d42c86760e21b815260040160405180910390fd5b836001600160a01b03167f63f0c6828e5ca4c6c9759e55ab66061d99ca532380fd9306da9edc5f297d522783604051610c6b91815260200190565b60405180910390a250505050610c8e6001600080516020612e2e83398151915255565b505050505050565b600080516020612dae833981519152610cae81611960565b610777611c11565b600080516020612dae833981519152610cce81611960565b6000805483919060ff19166001836004811115610ced57610ced612aa9565b02179055505050565b6000610d0181611960565b610d09611977565b6001600160a01b038216610d305760405163e6c4247b60e01b815260040160405180910390fd5b50600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000610d5e81611960565b6108dd82611c71565b600080516020612dae833981519152610d7f81611960565b610d87611977565b6000805460ff166004811115610d9f57610d9f612aa9565b14610dbd5760405163baf3f0f760e01b815260040160405180910390fd5b50600255565b6000610dce81611960565b6108dd82611ce4565b600080516020612dae833981519152610def81611960565b610df7611977565b6001600160a01b038216610e1e5760405163e6c4247b60e01b815260040160405180910390fd5b50600480546001600160a01b0319166001600160a01b0392909216919091179055565b600080516020612dae833981519152610e5981611960565b610777611d54565b600080516020612e4e833981519152546001600160a01b031690565b6000610e8881611960565b610e90611977565b6003546001600160a01b0316610eb957604051636be25ca360e01b815260040160405180910390fd5b600460005460ff166004811115610ed257610ed2612aa9565b14610ef05760405163baf3f0f760e01b815260040160405180910390fd5b6003546040516000916001600160a01b03169047908381818185875af1925050503d8060008114610f3d576040519150601f19603f3d011682016040523d82523d6000602084013e610f42565b606091505b50509050806108dd57604051631d42c86760e21b815260040160405180910390fd5b6000610f6e610e61565b905090565b6000918252600080516020612dee833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600080516020612e4e83398151915254600090600160d01b900465ffffffffffff16600080516020612dce8339815191528115801590610ff357504265ffffffffffff831610155b610fff57600080611015565b6001810154600160a01b900465ffffffffffff16825b92509250509091565b6110266119fd565b61102e611977565b600061103982611a35565b905061104b818a8a8a8a8a8a8a611d9d565b6001600160a01b0381166000908152600560205260408120546110729061ffff168b612c87565b905060008161ffff168961ffff161161108b578861108d565b815b905060008261ffff168a61ffff16116110a75760006110b1565b6110b1838b612c87565b6001600160a01b03851660009081526005602052604090205490915061ffff161580156110fe57506001600160a01b03841660009081526005602052604090205462010000900461ffff16155b1561119a5760088054600181019091557ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0386166001600160a01b0319909116811790915560408051808201825261ffff80861682528481166020838101918252600095865260059052929093209051815492518416620100000263ffffffff19909316931692909217179055611234565b6001600160a01b0384166000908152600560205260409020546111c290839061ffff16612ca2565b6001600160a01b0385166000908152600560205260409020805461ffff191661ffff92831617908190556111fe91839162010000900416612ca2565b6001600160a01b0385166000908152600560205260409020805461ffff92909216620100000263ffff0000199092169190911790555b6040805161ffff808f1682528d1660208201526001600160a01b038616917fee291955cc75edc853c7af08c8c88b7040846622baff2403443608bca44f92fc910160405180910390a2505050506112986001600080516020612e2e83398151915255565b5050505050505050565b606080600060078054905067ffffffffffffffff8111156112c5576112c5612cbd565b6040519080825280602002602001820160405280156112ee578160200160208202803683370190505b50905060005b60075481101561136c57600660006007838154811061131557611315612cd3565b60009182526020808320909101546001600160a01b03168352820192909252604001902054825160ff9091169083908390811061135457611354612cd3565b911515602092830291909101909101526001016112f4565b50600781818054806020026020016040519081016040528092919081815260200182805480156113c557602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116113a7575b5050505050915092509250509091565b600080516020612e4e83398151915254600090600080516020612dce83398151915290600160d01b900465ffffffffffff16801580159061141d57504265ffffffffffff8216105b611437578154600160d01b900465ffffffffffff1661144c565b6001820154600160a01b900465ffffffffffff165b9250505090565b600061145d611493565b509050336001600160a01b0382161461148b57604051636116401160e11b815233600482015260240161097f565b610777611f7b565b600080516020612dce833981519152546001600160a01b03811691600160a01b90910465ffffffffffff1690565b816114df57604051631fe1e13d60e11b815260040160405180910390fd5b6108dd8282612018565b60006114f481611960565b610777612034565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff166000811580156115425750825b905060008267ffffffffffffffff16600114801561155f5750303b155b90508115801561156d575080155b1561158b5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff1916600117855583156115b557845460ff60401b1916600160401b1785555b6115c2620151808e61203f565b6115ca612051565b6115d2612061565b6115ea600080516020612dae8339815191528e612071565b5060005b8981101561163d57611634600080516020612dae8339815191528c8c8481811061161a5761161a612cd3565b905060200201602081019061162f9190612917565b612071565b506001016115ee565b506001600160a01b038b16158061165b57506001600160a01b038c16155b156116795760405163e6c4247b60e01b815260040160405180910390fd5b600380546001600160a01b03199081166001600160a01b038e8116919091179092556004805482168f841617905560028a905560008054610100600160a81b0319166101008b85160217905560018054909116918816919091179055831561171b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050505050505050565b6060806060600080516020612dae83398151915261174781611960565b60085460009067ffffffffffffffff81111561176557611765612cbd565b60405190808252806020026020018201604052801561178e578160200160208202803683370190505b5060085490915060009067ffffffffffffffff8111156117b0576117b0612cbd565b6040519080825280602002602001820160405280156117d9578160200160208202803683370190505b50905060005b6008548110156118bc57600560006008838154811061180057611800612cd3565b60009182526020808320909101546001600160a01b03168352820192909252604001902054835161ffff9091169084908390811061184057611840612cd3565b602002602001018181525050600560006008838154811061186357611863612cd3565b6000918252602080832091909101546001600160a01b0316835282019290925260400190205482516201000090910461ffff16908390839081106118a9576118a9612cd3565b60209081029190910101526001016117df565b50600882828280548060200260200160405190810160405280929190818152602001828054801561191657602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116118f8575b50505050509250955095509550505050909192565b60006001600160e01b03198216637965db0b60e01b148061075e57506301ffc9a760e01b6001600160e01b031983161461075e565b61077781336120e8565b611975600080612121565b565b600080516020612e0e8339815191525460ff16156119755760405163d93c066560e01b815260040160405180910390fd5b6119b182610893565b6119ba81611960565b6119c48383612071565b50505050565b6001600160a01b03811633146119f35760405163334bd91960e11b815260040160405180910390fd5b61088e82826121fc565b600080516020612e2e833981519152805460011901611a2f57604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b60006001600160a01b038216611a4b573361075e565b6001546000906001600160a01b0316638988eea9336040516001600160e01b031960e084901b1681526001600160a01b039182166004820152908616602482015230604482015260006064820152608401602060405180830381865afa158015611ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611add9190612ce9565b90508015611aec575090919050565b60005461010090046001600160a01b03166390c9a2d0336040516001600160e01b031960e084901b1681526001600160a01b0391821660048201529086166024820152306044820152606401602060405180830381865afa158015611b55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b799190612ce9565b905080611b9957604051632d618d8160e21b815260040160405180910390fd5b5090919050565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b600080600080611be38686612255565b925092509250611bf382826122a2565b5090949350505050565b6001600080516020612e2e83398151915255565b611c1961235b565b600080516020612e0e833981519152805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b6000611c7b6113d5565b611c844261238b565b611c8e9190612d0b565b9050611c9a82826123c2565b60405165ffffffffffff821681526001600160a01b038316907f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed69060200160405180910390a25050565b6000611cef8261244f565b611cf84261238b565b611d029190612d0b565b9050611d0e8282612121565b6040805165ffffffffffff8085168252831660208201527ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b910160405180910390a15050565b611d5c611977565b600080516020612e0e833981519152805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611c53565b600160005460ff166004811115611db657611db6612aa9565b14611dd45760405163baf3f0f760e01b815260040160405180910390fd5b8461ffff16600003611df957604051630d3e758f60e31b815260040160405180910390fd5b611e0a61ffff808816908916612d2a565b6001600160a01b03891660009081526005602052604090205463ffffffff919091169061ffff620100008204811691611e4891908116908916612d2a565b611e529190612d2a565b63ffffffff161115611e775760405163019f02c360e31b815260040160405180910390fd5b600254600003611e9a576040516313a8ad7d60e11b815260040160405180910390fd5b600254611eab9061ffff8716612c33565b3414611eca576040516394b5970f60e01b815260040160405180910390fd5b6000848489898c604051602001611ee5959493929190612d47565b604051602081830303815290604052805190602001209050611f4283838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610af09250859150611ba09050565b6004546001600160a01b03908116911614611f7057604051638baa579f60e01b815260040160405180910390fd5b505050505050505050565b600080516020612dce833981519152600080611f95611493565b91509150611faa8165ffffffffffff16151590565b1580611fbe57504265ffffffffffff821610155b15611fe6576040516319ca5ebb60e01b815265ffffffffffff8216600482015260240161097f565b611ff86000611ff3610e61565b6121fc565b50612004600083612071565b505081546001600160d01b03191690915550565b61202182610893565b61202a81611960565b6119c483836121fc565b6119756000806123c2565b61204761249e565b6108dd82826124e7565b61205961249e565b611975612550565b61206961249e565b611975612558565b6000600080516020612dce833981519152836120d6576000612091610e61565b6001600160a01b0316146120b857604051631fe1e13d60e11b815260040160405180910390fd5b6001810180546001600160a01b0319166001600160a01b0385161790555b6120e08484612579565b949350505050565b6120f28282610f73565b6108dd5760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161097f565b600080516020612e4e83398151915254600080516020612dce83398151915290600160d01b900465ffffffffffff1680156121be574265ffffffffffff8216101561219457600182015482546001600160d01b0316600160a01b90910465ffffffffffff16600160d01b021782556121be565b6040517f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec590600090a15b5060010180546001600160a01b0316600160a01b65ffffffffffff948516026001600160d01b031617600160d01b9290931691909102919091179055565b6000600080516020612dce83398151915283158015612233575061221e610e61565b6001600160a01b0316836001600160a01b0316145b1561224b576001810180546001600160a01b03191690555b6120e08484612625565b6000806000835160410361228f5760208401516040850151606086015160001a612281888285856126a1565b95509550955050505061229b565b50508151600091506002905b9250925092565b60008260038111156122b6576122b6612aa9565b036122bf575050565b60018260038111156122d3576122d3612aa9565b036122f15760405163f645eedf60e01b815260040160405180910390fd5b600282600381111561230557612305612aa9565b036123265760405163fce698f760e01b81526004810182905260240161097f565b600382600381111561233a5761233a612aa9565b036108dd576040516335e2f38360e21b81526004810182905260240161097f565b600080516020612e0e8339815191525460ff1661197557604051638dfc202b60e01b815260040160405180910390fd5b600065ffffffffffff8211156123be576040516306dfcc6560e41b8152603060048201526024810183905260440161097f565b5090565b600080516020612dce83398151915260006123db611493565b835465ffffffffffff8616600160a01b026001600160d01b03199091166001600160a01b03881617178455915061241b90508165ffffffffffff16151590565b156119c4576040517f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510990600090a150505050565b60008061245a6113d5565b90508065ffffffffffff168365ffffffffffff16116124825761247d8382612d8e565b612497565b61249765ffffffffffff841662069780612770565b9392505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661197557604051631afcd79f60e31b815260040160405180910390fd5b6124ef61249e565b600080516020612dce8339815191526001600160a01b03821661252857604051636116401160e11b81526000600482015260240161097f565b80546001600160d01b0316600160d01b65ffffffffffff8516021781556119c4600083612071565b611bfd61249e565b61256061249e565b600080516020612e0e833981519152805460ff19169055565b6000600080516020612dee8339815191526125948484610f73565b612614576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556125ca3390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4600191505061075e565b600091505061075e565b5092915050565b6000600080516020612dee8339815191526126408484610f73565b15612614576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4600191505061075e565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411156126dc5750600091506003905082612766565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015612730573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661275c57506000925060019150829050612766565b9250600091508190505b9450945094915050565b6000818310611b995781612497565b60006020828403121561279157600080fd5b81356001600160e01b03198116811461249757600080fd5b6000602082840312156127bb57600080fd5b5035919050565b80356001600160a01b03811681146127d957600080fd5b919050565b600080604083850312156127f157600080fd5b82359150612801602084016127c2565b90509250929050565b803561ffff811681146127d957600080fd5b60008083601f84011261282e57600080fd5b50813567ffffffffffffffff81111561284657600080fd5b60208301915083602082850101111561285e57600080fd5b9250929050565b6000806000806000806080878903121561287e57600080fd5b6128878761280a565b9550612895602088016127c2565b9450604087013567ffffffffffffffff808211156128b257600080fd5b6128be8a838b0161281c565b909650945060608901359150808211156128d757600080fd5b506128e489828a0161281c565b979a9699509497509295939492505050565b60006020828403121561290857600080fd5b81356005811061249757600080fd5b60006020828403121561292957600080fd5b612497826127c2565b60006020828403121561294457600080fd5b813565ffffffffffff8116811461249757600080fd5b60008060008060008060008060c0898b03121561297657600080fd5b61297f8961280a565b975061298d60208a0161280a565b965061299b60408a0161280a565b9550606089013567ffffffffffffffff808211156129b857600080fd5b6129c48c838d0161281c565b909750955060808b01359150808211156129dd57600080fd5b506129ea8b828c0161281c565b90945092506129fd905060a08a016127c2565b90509295985092959890939650565b600081518084526020808501945080840160005b83811015612a455781516001600160a01b031687529582019590820190600101612a20565b509495945050505050565b604081526000612a636040830185612a0c565b82810360208481019190915284518083528582019282019060005b81811015612a9c578451151583529383019391830191600101612a7e565b5090979650505050505050565b634e487b7160e01b600052602160045260246000fd5b6020810160058310612ae157634e487b7160e01b600052602160045260246000fd5b91905290565b60008060008060008060008060e0898b031215612b0357600080fd5b612b0c896127c2565b9750612b1a60208a016127c2565b9650612b2860408a016127c2565b9550606089013567ffffffffffffffff80821115612b4557600080fd5b818b0191508b601f830112612b5957600080fd5b813581811115612b6857600080fd5b8c60208260051b8501011115612b7d57600080fd5b60208301975080965050505060808901359250612b9c60a08a016127c2565b91506129fd60c08a016127c2565b600081518084526020808501945080840160005b83811015612a4557815187529582019590820190600101612bbe565b606081526000612bed6060830186612a0c565b8281036020840152612bff8186612baa565b90508281036040840152612c138185612baa565b9695505050505050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761075e5761075e612c1d565b8385823760f09290921b6001600160f01b0319169190920190815260609190911b6bffffffffffffffffffffffff19166002820152601601919050565b61ffff82811682821603908082111561261e5761261e612c1d565b61ffff81811683821601908082111561261e5761261e612c1d565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060208284031215612cfb57600080fd5b8151801515811461249757600080fd5b65ffffffffffff81811683821601908082111561261e5761261e612c1d565b63ffffffff81811683821601908082111561261e5761261e612c1d565b8486823760f093841b6001600160f01b0319908116919095019081529190921b909216600283015260601b6bffffffffffffffffffffffff19166004820152601801919050565b65ffffffffffff82811682821603908082111561261e5761261e612c1d56fe2714cbbaddbb71bcae9366d8bf7770636ec7ae63227b573986d2f54fffacb39deef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d869840002dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00eef3dac4538c82c8ace4063ab0acd2d15cdb5883aa1dff7c2673abb3d8698401a26469706673582212202c78d6605de2e42eda1afe594d9384829afcb82d68d9e1b22ef5d3ae543ec2e064736f6c63430008140033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.