Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xa9226F99c36AAb51E924C187E75bEf554b29A55F
Balance 0 ETH
Nonce 1
Code Size 5273 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5273 bytes
0x60406080815260048036101561001457600080fd5b600090813560e01c806306cd3af1146110d85780630d567f3814610fa357806314f5cd1714610e9557806318c4110714610e6a5780633333dcc514610e29578063355274ea14610dee578063379607f514610bcf57806361d027b314610b8b5780636cd799be14610b49578063715018a614610aef57806378cf19e9146109385780637b292a4a14610900578063879f9c96146108d75780638da5cb5b146108af57806395a01d06146108905780639601497b1461086a5780639de5f92c1461084b578063a04476621461076e578063aab006d5146106a7578063af38d75714610682578063b14a1e871461061f578063b569ef8c14610581578063c4098ed814610545578063d085835a1461051c578063e834a834146104f3578063f2fde38b14610465578063fc0c546a146104215763ffbbfe4b1461015457600080fd5b3461041d578160031936011261041d5780546001600160a01b039061017c9082163314611161565b6101d36101ac6002547f00000000000000000000000000000000000000000000000000000000013c68009061110b565b7f0000000000000000000000000000000000000000000000000000000001da9c009061110b565b4211156103da5783516370a0823160e01b81523081840152602092907f0000000000000000000000004bdfa27ce379d7601da1d15bd637a1cf895ff8fb8316908481602481855afa80156103d057869061039c575b6102369150600354906112c2565b928315610335578591604486928951948593849263a9059cbb60e01b84527f00000000000000000000000098f71f3c272092896f4134ea27b39365ef96696516888401528860248401525af190811561032b5785916102fe575b50156102c257507f59957b5aed3f2262ac2e0f685c87e00666e87cbe08d2b0820ed96078c54ab712929351908152a180f35b845162461bcd60e51b815290810183905260166024820152753bb4ba34323930bb9030b6b7bab73a399032b93937b960511b6044820152606490fd5b61031e9150843d8611610324575b610316818361120f565b8101906112cf565b38610290565b503d61030c565b86513d87823e3d90fd5b608483888781519262461bcd60e51b845283015260248201527f746865726520617265206e6f20756e72656465656d65642066756e6473206c6560448201527f6674206f6e2074686520736d61727420636f6e7472616374206163636f756e746064820152fd5b508481813d83116103c9575b6103b2818361120f565b810103126103c4576102369051610228565b600080fd5b503d6103a8565b87513d88823e3d90fd5b835162461bcd60e51b8152602081840152601a60248201527f726f756e6420686173206e6f742066696e6973686564207965740000000000006044820152606490fd5b5080fd5b82843461041d578160031936011261041d57517f0000000000000000000000004bdfa27ce379d7601da1d15bd637a1cf895ff8fb6001600160a01b03168152602090f35b508290346104ef5760203660031901126104ef576104816110f5565b9061048a61131e565b6001600160a01b039182169283156104d95750506000548260018060a01b0319821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b51631e4fbdf760e01b8152908101849052602490fd5b8280fd5b82843461041d578160031936011261041d57600281602093338152600585522001549051908152f35b508290346104ef57826003193601126104ef575490516001600160a01b03909116815260209150f35b82843461041d57602036600319011261041d5760209160019082906001600160a01b036105706110f5565b168152600585522001549051908152f35b5081923461061b578260031936011261061b5780516001624401b560e01b03196020820152828152916105b3836111d7565b80546001600160a01b031692833b15610617576105e893859283855180978195829463134008d360e01b8452309084016112e7565b03925af190811561060e57506105fb5750f35b610604906111ad565b61060b5780f35b80fd5b513d84823e3d90fd5b8480fd5b5050fd5b5081923461061b578060031936011261061b57610674916105b36106416110f5565b83516378cf19e960e01b60208201526001600160a01b039091166024808301919091523560448201529384906064820190565b03601f19810185528461120f565b82843461041d578160031936011261041d576020906106a03361134a565b9051908152f35b5081923461061b578060031936011261061b57610674916106d16106c96110f5565b61064161131e565b8054825163793d064960e11b8152906001600160a01b03166020828481845afa91821561076457869261072d575b50803b15610729576105e89486809486519788958694859362ea831560e11b855230908501611284565b8580fd5b955090506020853d60201161075c575b8161074a6020938361120f565b810103126103c45785945190386106ff565b3d915061073d565b84513d88823e3d90fd5b5081923461061b57602091826003193601126108465761078c61131e565b8151926301aacfe760e31b8185015281356024850152602484526107af846111f3565b8154835163793d064960e11b81526001600160a01b039091169082818581855afa92831561083c578793610809575b5050803b15610729576105e89486809486519788958694859362ea831560e11b855230908501611284565b819750809293503d8311610835575b610822818361120f565b810103126103c4578594519038806107de565b503d610818565b85513d89823e3d90fd5b505050fd5b82843461041d578160031936011261041d576020906002549051908152f35b82843461041d57602036600319011261041d576020906106a061088b6110f5565b61134a565b82843461041d578160031936011261041d576020906003549051908152f35b82843461041d578160031936011261041d57905490516001600160a01b039091168152602090f35b82843461041d578160031936011261041d57600181602093338152600585522001549051908152f35b5081923461061b57602036600319011261061b578051916301aacfe760e31b602084015280356024840152602483526105b3836111f3565b508290346104ef57816003193601126104ef576109536110f5565b8154602435926001600160a01b0392916109709084163314611161565b6109a06101ac6002547f00000000000000000000000000000000000000000000000000000000013c68009061110b565b421015610abb57600354906109b5858361110b565b7f000000000000000000000000000000000000000000000000000eebe0b40e800010610a895750918391610a0c7f059b47189b97a25d79b2e8a4a5af2bbb0e875b59ce5057302a77e2c6c9e2d5039560209561110b565b600355169384865260058352600181872001610a2983825461110b565b90556002544210610a3d575b51908152a280f35b84865260058352612710610a78600183892001547f00000000000000000000000000000000000000000000000000000000000000c890611231565b048587526005845281872055610a35565b606490602087519162461bcd60e51b8352820152600c60248201526b18d85c08195e18d95959195960a21b6044820152fd5b606490602086519162461bcd60e51b8352820152600e60248201526d1c9bdd5b9908199a5b9a5cda195960921b6044820152fd5b823461060b578060031936011261060b57610b0861131e565b600080546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b82843461041d578160031936011261041d576020906106a06002547f00000000000000000000000000000000000000000000000000000000013c68009061110b565b82843461041d578160031936011261041d57517f00000000000000000000000098f71f3c272092896f4134ea27b39365ef9669656001600160a01b03168152602090f35b5082346104ef5760209081600319360112610dea578235928315610db357600260015414610da5576002600155338552600583526001828620015415610d645783610c193361134a565b10610d2e5733855260058352600282862001610c3685825461110b565b9055815163a9059cbb60e01b815233828201908152602081018690528490829081906040010381897f0000000000000000000000004bdfa27ce379d7601da1d15bd637a1cf895ff8fb6001600160a01b03165af1908115610d24578691610d07575b5015610cd05750907fe42df0d9493dfd0d7f69902c895b94c190a53e8c27876a86f45e7c997d9d8f7c91519283523392a26001805580f35b82606492519162461bcd60e51b8352820152601360248201527231b630b4b69030b6b7bab73a399032b93937b960691b6044820152fd5b610d1e9150843d861161032457610316818361120f565b86610c98565b83513d88823e3d90fd5b82606492519162461bcd60e51b83528201526012602482015271696e73756666696369656e742066756e647360701b6044820152fd5b82606492519162461bcd60e51b8352820152601a60248201527f6163636f756e74206973206e6f742062656e65666963696172790000000000006044820152fd5b9051633ee5aeb560e01b8152fd5b82606492519162461bcd60e51b8352820152601360248201527276616c75652063616e2774206265207a65726f60681b6044820152fd5b8380fd5b82843461041d578160031936011261041d57602090517f000000000000000000000000000000000000000000000000000eebe0b40e80008152f35b82843461041d578160031936011261041d576020906106a06003547f000000000000000000000000000000000000000000000000000eebe0b40e80006112c2565b82843461041d57602036600319011261041d5760209160029082906001600160a01b036105706110f5565b5082346104ef57826003193601126104ef57610eaf61131e565b80516001624401b560e01b03196020820152828152610ecd816111d7565b8254825163793d064960e11b8152916001600160a01b03909116906020838681855afa928315610764578693610f6f575b508260021b92808404861490151715610f5c5790859291813b15610dea5783610f3c9686519788958694859362ea831560e11b855230908501611284565b03925af190811561060e5750610f50575080f35b610f59906111ad565b80f35b634e487b7160e01b865260118552602486fd5b9092506020813d602011610f9b575b81610f8b6020938361120f565b8101031261072957519186610efe565b3d9150610f7e565b5082346104ef5760203660031901126104ef57813591610fcd60018060a01b038254163314611161565b60025442101561106657428311156110115750816020917fc74a4546b71f3059f55db2df5106f31a5135e8be09e24949201458a94dad14309360025551908152a180f35b6020608492519162461bcd60e51b8352820152602a60248201527f737461727420726f756e642074696d657374616d702063616e277420626520696044820152691b881d1a19481c185cdd60b21b6064820152fd5b602060a492519162461bcd60e51b8352820152604160248201527f737461727420726f756e642074696d657374616d702063616e2774206265206560448201527f64697465642061667465722074686520726f756e6420686173207374617274656064820152601960fa1b6084820152fd5b82843461041d578160031936011261041d576020906106a061112e565b600435906001600160a01b03821682036103c457565b9190820180921161111857565b634e487b7160e01b600052601160045260246000fd5b61115e6101ac6002547f00000000000000000000000000000000000000000000000000000000013c68009061110b565b90565b1561116857565b60405162461bcd60e51b815260206004820152601e60248201527f43616e206f6e6c792062652063616c6c65642062792054696d654c6f636b00006044820152606490fd5b67ffffffffffffffff81116111c157604052565b634e487b7160e01b600052604160045260246000fd5b6040810190811067ffffffffffffffff8211176111c157604052565b6060810190811067ffffffffffffffff8211176111c157604052565b90601f8019910116810190811067ffffffffffffffff8211176111c157604052565b8181029291811591840414171561111857565b919082519283825260005b848110611270575050826000602080949584010152601f8019910116010190565b60208183018101518483018201520161124f565b9392916112af9060a092600180851b031686526000602087015260c0604087015260c0860190611244565b9360006060820152600060808201520152565b9190820391821161111857565b908160209103126103c4575180151581036103c45790565b929161131360809160009360018060a01b0316865283602087015260a0604087015260a0860190611244565b938260608201520152565b6000546001600160a01b0316330361133257565b60405163118cdaa760e01b8152336004820152602490fd5b6001600160a01b03166000908152600560205260408120600181015491821561145d5760028254920154926002548042106114555761138761112e565b42101561144757906113e791847f00000000000000000000000000000000000000000000000000000000013c68006113bf818461110b565b42111561143a576113d66113dc916113e29461110b565b426112c2565b926112c2565b611231565b7f0000000000000000000000000000000000000000000000000000000001da9c009182156114265750916114219161115e9493049061110b565b6112c2565b634e487b7160e01b81526012600452602490fd5b506113e2915084926112c2565b50905061115e9291506112c2565b505091505090565b9150509056fea2646970667358221220b527248798991d42e7c86627565cc71ee25b5851b9ca1267cb4f828ce88209c564736f6c63430008180033

Verified Source Code Full Match

Compiler: v0.8.24+commit.e11b9ed9 EVM: paris Optimization: Yes (100 runs)
Vesting.sol 404 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/governance/TimelockController.sol";

contract Vesting is Ownable, ReentrancyGuard {
    // events
    event StartRoundTsChanged(uint256 value);
    event TokenReserved(address indexed beneficiary, uint256 value);
    event TokenClaimed(address indexed beneficiary, uint256 value);
    event FundsWithdrawal(uint256 value);
    // PV
    // start round unix timestamp
    uint256 private _startRound;
    // lock-up period (duration, sec)
    uint256 private immutable _cliffPeriod;
    // vesting period (duration, sec)
    uint256 private immutable _vestingPeriod;

    // pre-cliff ration
    // share of funds unlocked for TGE
    uint256 private immutable _tgep;

    // full round amounts
    uint256 private immutable _cap;

    // amount purchased
    uint256 private _purchased;
    // the token being sold
    IERC20 private immutable _token;
    // treasury address
    address payable private immutable _treasury;

    TimelockController public timeLock;

    /**
     * @dev ico wallet structure for collecting benefeciary purchased/claimed amounts
     */
    struct VestingWallet {
        uint256 initiallyUnlocked;
        uint256 purchased;
        uint256 claimed;
    }

    mapping(address => VestingWallet) private _balances;

    // modifiers

    /**
     * @dev checking value not zero
     */
    modifier valueNotZero(uint256 val) {
        require(val != 0, "value can't be zero");
        _;
    }

    constructor(
        address initialOwner,
        uint256 startRound_,
        uint256 cliffDuration_,
        uint256 vestingDuration_,
        uint256 tgep_, // % in basis points (parts per 10,000)
        uint256 cap_,
        address token_,
        address payable treasury_,
        TimelockController timeLock_
    ) Ownable(initialOwner) {
        require(
            block.timestamp < startRound_,
            "start round timestamp can't be in the past"
        );
        require(vestingDuration_ > 0, "invalid vesting period duration");
        require(cliffDuration_ > 0, "invalid cliff period duration");
        require(cap_ > 0, "invalid cap amount");
        require((tgep_ <= 10_000), "invalid rate");
        require(token_ != address(0), "invalid token address");
        require(treasury_ != address(0), "invalid treasury address");
        require(address(timeLock_) != address(0), "invalid timelock address");

        _token = IERC20(token_);

        _startRound = startRound_;
        _cliffPeriod = cliffDuration_;
        _vestingPeriod = vestingDuration_;

        _tgep = tgep_;
        _cap = cap_;

        _treasury = treasury_;
        timeLock = timeLock_;
    }

    modifier onlyTimeLock() {
        require(
            msg.sender == address(timeLock),
            "Can only be called by TimeLock"
        );
        _;
    }

    /**
     * @dev getting start round timestamp
     * @return start round timestamp
     */
    function startRoundTimestamp() public view returns (uint) {
        return _startRound;
    }

    /**
     * @dev getting vesting timestamp
     * @return vesting timestamp
     */
    function vestingTimestamp() public view returns (uint) {
        return _startRound + _cliffPeriod;
    }

    /**
     * @dev getting finish round timestamp
     * @return finish round timestamp
     */
    function finishRoundTimestamp() public view returns (uint) {
        return vestingTimestamp() + _vestingPeriod;
    }

    /**
     * @return address of the token being sold.
     */
    function token() public view returns (address) {
        return address(_token);
    }

    /**
     * @return treasury address.
     */
    function treasury() public view returns (address payable) {
        return _treasury;
    }

    /**
     * @return amount of purchased.
     */
    function allPurchased() public view returns (uint256) {
        return _purchased;
    }

    /**
     * @return full round cap
     */
    function cap() public view returns (uint256) {
        return _cap;
    }

    /**
     * @return available for purchase amounts.
     */
    function availableForPurchase() public view returns (uint256) {
        return _cap - _purchased;
    }

    /**
     * @dev admin method getting users claimed amounts
     * @return the amount claimed by user.
     */
    function claimedByUser(address beneficiary) public view returns (uint256) {
        return _balances[beneficiary].claimed;
    }

    /**
     * @dev public method getting users claimed amounts
     * @return the amount claimed by user.
     */
    function claimed() public view returns (uint256) {
        return _balances[msg.sender].claimed;
    }

    /**
     * @dev manager method getting users purchased amounts
     * @return the amount purchased by user.
     */
    function purchasedByUser(
        address beneficiary
    ) public view returns (uint256) {
        return _balances[beneficiary].purchased;
    }

    /**
     * @dev public method getting users purchased amounts
     * @return the amount purchased by user.
     */
    function purchased() public view returns (uint256) {
        return _balances[msg.sender].purchased;
    }

    /**
     * @dev manager method getting beneficiary amounts value available for claim
     * @return amount available for claim.
     */
    function claimableForUser(
        address beneficiary
    ) public view returns (uint256) {
        return _claimable(beneficiary);
    }

    /**
     * @dev getting beneficiary amounts value available for claim
     * @return amount available for claim.
     */
    function claimable() public view returns (uint256) {
        return _claimable(msg.sender);
    }

    /**
     * @dev private method getting beneficiary amounts value available for claim
     * @return amount available for claim.
     */
    function _claimable(address beneficiary) private view returns (uint256) {
        if (_balances[beneficiary].purchased == 0) {
            return 0;
        }

        uint256 initiallyUnlocked = _balances[beneficiary].initiallyUnlocked;
        uint256 claimedBalance = _balances[beneficiary].claimed;
        uint256 purchasedBalance = _balances[beneficiary].purchased;
        uint256 currentTime = block.timestamp;

        // round not started
        if (currentTime < startRoundTimestamp()) {
            return 0;
        }

        // round finished
        if (currentTime >= finishRoundTimestamp()) {
            return purchasedBalance - claimedBalance;
        }

        uint256 period = currentTime > vestingTimestamp()
            ? currentTime - vestingTimestamp()
            : 0;
        uint256 unlocked = ((purchasedBalance - initiallyUnlocked) * period) /
            _vestingPeriod;
        return initiallyUnlocked + unlocked - claimedBalance;
    }

    /**
     * @dev change start round timestamp
     */
    function setStartRound(uint256 startRound) public onlyTimeLock {
        require(
            _startRound > block.timestamp,
            "start round timestamp can't be edited after the round has started"
        );
        require(
            startRound > block.timestamp,
            "start round timestamp can't be in the past"
        );
        _startRound = startRound;
        emit StartRoundTsChanged(_startRound);
    }

    /**
     * @dev schedule change start round timestamp
     */
    function scheduleSetStartRound(uint256 startRound) public onlyOwner {
       bytes memory data = abi.encodeWithSignature(
            "setStartRound(uint256)",
            startRound
        );
        timeLock.schedule(
            address(this),
            0,
            data,
            bytes32(0),
            bytes32(0),
            timeLock.getMinDelay()
        );
    }

    /**
     * @dev execute change start round timestamp
     */
    function executeSetStartRound(
        uint256 startRound
    ) external {
        bytes memory data = abi.encodeWithSignature(
            "setStartRound(uint256)",
            startRound
        );
        timeLock.execute(address(this), 0, data, bytes32(0), bytes32(0));
    }

    /**
     * @dev claim funds
     */
    function claim(uint256 amount) public valueNotZero(amount) nonReentrant {
        require(
            _balances[msg.sender].purchased > 0,
            "account is not beneficiary"
        );
        require(_claimable(msg.sender) >= amount, "insufficient funds");
        _balances[msg.sender].claimed += amount;
        bool res = _token.transfer(msg.sender, amount);
        require(res, "claim amounts error");
        emit TokenClaimed(msg.sender, amount);
    }

    /**
     * @dev reserve tokens
     */
    function reserveTokens(
        address beneficiary,
        uint256 amount
    ) public onlyTimeLock {
        require(
            block.timestamp < (vestingTimestamp() + _vestingPeriod),
            "round finished"
        );
        require((allPurchased() + amount) <= cap(), "cap exceeded");
        _purchased += amount;
        _balances[beneficiary].purchased += amount;
        if (block.timestamp < _startRound) {
            _balances[beneficiary].initiallyUnlocked =
                (_balances[beneficiary].purchased * _tgep) /
                10_000;
        }
        emit TokenReserved(beneficiary, amount);
    }

    /**
     * @dev withdraw unpurchased funds
     */
    function withdrawUnpurchasedFunds() public onlyTimeLock {
        require(
            block.timestamp > (vestingTimestamp() + _vestingPeriod),
            "round has not finished yet"
        );
        uint256 amount = _token.balanceOf(address(this)) - _purchased;
        require(
            amount != 0,
            "there are no unredeemed funds left on the smart contract account"
        );

        bool res = _token.transfer(_treasury, amount);
        if (!res) {
            revert("withdraw amounts error");
        }

        emit FundsWithdrawal(amount);
    }

    function scheduleReserveTokens(
        address beneficiary,
        uint256 amount
    ) external onlyOwner {
        bytes memory data = abi.encodeWithSignature(
            "reserveTokens(address,uint256)",
            beneficiary,
            amount
        );
        timeLock.schedule(
            address(this),
            0,
            data,
            bytes32(0),
            bytes32(0),
            timeLock.getMinDelay()
        );
    }

    function executeReserveTokens(
        address beneficiary,
        uint256 amount
    ) external {
        bytes memory data = abi.encodeWithSignature(
            "reserveTokens(address,uint256)",
            beneficiary,
            amount
        );
        timeLock.execute(address(this), 0, data, bytes32(0), bytes32(0));
    }

    function scheduleWithdrawUnpurchasedFunds() external onlyOwner {
        bytes memory data = abi.encodeWithSignature(
            "withdrawUnpurchasedFunds()"
        );
        timeLock.schedule(
            address(this),
            0,
            data,
            bytes32(0),
            bytes32(0),
            timeLock.getMinDelay() * 4
        );
    }

    function executeWithdrawUnpurchasedFunds() external {
        bytes memory data = abi.encodeWithSignature(
            "withdrawUnpurchasedFunds()"
        );
        timeLock.execute(address(this), 0, data, bytes32(0), bytes32(0));
    }
}
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.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 AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @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);
        _;
    }

    /**
     * @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) {
        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) {
        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 {
        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) {
        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) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
IAccessControl.sol 98 lines
// 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;
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
TimelockController.sol 472 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/TimelockController.sol)

pragma solidity ^0.8.20;

import {AccessControl} from "../access/AccessControl.sol";
import {ERC721Holder} from "../token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "../token/ERC1155/utils/ERC1155Holder.sol";
import {Address} from "../utils/Address.sol";

/**
 * @dev Contract module which acts as a timelocked controller. When set as the
 * owner of an `Ownable` smart contract, it enforces a timelock on all
 * `onlyOwner` maintenance operations. This gives time for users of the
 * controlled contract to exit before a potentially dangerous maintenance
 * operation is applied.
 *
 * By default, this contract is self administered, meaning administration tasks
 * have to go through the timelock process. The proposer (resp executor) role
 * is in charge of proposing (resp executing) operations. A common use case is
 * to position this {TimelockController} as the owner of a smart contract, with
 * a multisig or a DAO as the sole proposer.
 */
contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
    bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
    bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
    bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
    uint256 internal constant _DONE_TIMESTAMP = uint256(1);

    mapping(bytes32 id => uint256) private _timestamps;
    uint256 private _minDelay;

    enum OperationState {
        Unset,
        Waiting,
        Ready,
        Done
    }

    /**
     * @dev Mismatch between the parameters length for an operation call.
     */
    error TimelockInvalidOperationLength(uint256 targets, uint256 payloads, uint256 values);

    /**
     * @dev The schedule operation doesn't meet the minimum delay.
     */
    error TimelockInsufficientDelay(uint256 delay, uint256 minDelay);

    /**
     * @dev The current state of an operation is not as required.
     * The `expectedStates` is a bitmap with the bits enabled for each OperationState enum position
     * counting from right to left.
     *
     * See {_encodeStateBitmap}.
     */
    error TimelockUnexpectedOperationState(bytes32 operationId, bytes32 expectedStates);

    /**
     * @dev The predecessor to an operation not yet done.
     */
    error TimelockUnexecutedPredecessor(bytes32 predecessorId);

    /**
     * @dev The caller account is not authorized.
     */
    error TimelockUnauthorizedCaller(address caller);

    /**
     * @dev Emitted when a call is scheduled as part of operation `id`.
     */
    event CallScheduled(
        bytes32 indexed id,
        uint256 indexed index,
        address target,
        uint256 value,
        bytes data,
        bytes32 predecessor,
        uint256 delay
    );

    /**
     * @dev Emitted when a call is performed as part of operation `id`.
     */
    event CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data);

    /**
     * @dev Emitted when new proposal is scheduled with non-zero salt.
     */
    event CallSalt(bytes32 indexed id, bytes32 salt);

    /**
     * @dev Emitted when operation `id` is cancelled.
     */
    event Cancelled(bytes32 indexed id);

    /**
     * @dev Emitted when the minimum delay for future operations is modified.
     */
    event MinDelayChange(uint256 oldDuration, uint256 newDuration);

    /**
     * @dev Initializes the contract with the following parameters:
     *
     * - `minDelay`: initial minimum delay in seconds for operations
     * - `proposers`: accounts to be granted proposer and canceller roles
     * - `executors`: accounts to be granted executor role
     * - `admin`: optional account to be granted admin role; disable with zero address
     *
     * IMPORTANT: The optional admin can aid with initial configuration of roles after deployment
     * without being subject to delay, but this role should be subsequently renounced in favor of
     * administration through timelocked proposals. Previous versions of this contract would assign
     * this admin to the deployer automatically and should be renounced as well.
     */
    constructor(uint256 minDelay, address[] memory proposers, address[] memory executors, address admin) {
        // self administration
        _grantRole(DEFAULT_ADMIN_ROLE, address(this));

        // optional admin
        if (admin != address(0)) {
            _grantRole(DEFAULT_ADMIN_ROLE, admin);
        }

        // register proposers and cancellers
        for (uint256 i = 0; i < proposers.length; ++i) {
            _grantRole(PROPOSER_ROLE, proposers[i]);
            _grantRole(CANCELLER_ROLE, proposers[i]);
        }

        // register executors
        for (uint256 i = 0; i < executors.length; ++i) {
            _grantRole(EXECUTOR_ROLE, executors[i]);
        }

        _minDelay = minDelay;
        emit MinDelayChange(0, minDelay);
    }

    /**
     * @dev Modifier to make a function callable only by a certain role. In
     * addition to checking the sender's role, `address(0)` 's role is also
     * considered. Granting a role to `address(0)` is equivalent to enabling
     * this role for everyone.
     */
    modifier onlyRoleOrOpenRole(bytes32 role) {
        if (!hasRole(role, address(0))) {
            _checkRole(role, _msgSender());
        }
        _;
    }

    /**
     * @dev Contract might receive/hold ETH as part of the maintenance process.
     */
    receive() external payable {}

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(AccessControl, ERC1155Holder) returns (bool) {
        return super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns whether an id corresponds to a registered operation. This
     * includes both Waiting, Ready, and Done operations.
     */
    function isOperation(bytes32 id) public view returns (bool) {
        return getOperationState(id) != OperationState.Unset;
    }

    /**
     * @dev Returns whether an operation is pending or not. Note that a "pending" operation may also be "ready".
     */
    function isOperationPending(bytes32 id) public view returns (bool) {
        OperationState state = getOperationState(id);
        return state == OperationState.Waiting || state == OperationState.Ready;
    }

    /**
     * @dev Returns whether an operation is ready for execution. Note that a "ready" operation is also "pending".
     */
    function isOperationReady(bytes32 id) public view returns (bool) {
        return getOperationState(id) == OperationState.Ready;
    }

    /**
     * @dev Returns whether an operation is done or not.
     */
    function isOperationDone(bytes32 id) public view returns (bool) {
        return getOperationState(id) == OperationState.Done;
    }

    /**
     * @dev Returns the timestamp at which an operation becomes ready (0 for
     * unset operations, 1 for done operations).
     */
    function getTimestamp(bytes32 id) public view virtual returns (uint256) {
        return _timestamps[id];
    }

    /**
     * @dev Returns operation state.
     */
    function getOperationState(bytes32 id) public view virtual returns (OperationState) {
        uint256 timestamp = getTimestamp(id);
        if (timestamp == 0) {
            return OperationState.Unset;
        } else if (timestamp == _DONE_TIMESTAMP) {
            return OperationState.Done;
        } else if (timestamp > block.timestamp) {
            return OperationState.Waiting;
        } else {
            return OperationState.Ready;
        }
    }

    /**
     * @dev Returns the minimum delay in seconds for an operation to become valid.
     *
     * This value can be changed by executing an operation that calls `updateDelay`.
     */
    function getMinDelay() public view virtual returns (uint256) {
        return _minDelay;
    }

    /**
     * @dev Returns the identifier of an operation containing a single
     * transaction.
     */
    function hashOperation(
        address target,
        uint256 value,
        bytes calldata data,
        bytes32 predecessor,
        bytes32 salt
    ) public pure virtual returns (bytes32) {
        return keccak256(abi.encode(target, value, data, predecessor, salt));
    }

    /**
     * @dev Returns the identifier of an operation containing a batch of
     * transactions.
     */
    function hashOperationBatch(
        address[] calldata targets,
        uint256[] calldata values,
        bytes[] calldata payloads,
        bytes32 predecessor,
        bytes32 salt
    ) public pure virtual returns (bytes32) {
        return keccak256(abi.encode(targets, values, payloads, predecessor, salt));
    }

    /**
     * @dev Schedule an operation containing a single transaction.
     *
     * Emits {CallSalt} if salt is nonzero, and {CallScheduled}.
     *
     * Requirements:
     *
     * - the caller must have the 'proposer' role.
     */
    function schedule(
        address target,
        uint256 value,
        bytes calldata data,
        bytes32 predecessor,
        bytes32 salt,
        uint256 delay
    ) public virtual onlyRole(PROPOSER_ROLE) {
        bytes32 id = hashOperation(target, value, data, predecessor, salt);
        _schedule(id, delay);
        emit CallScheduled(id, 0, target, value, data, predecessor, delay);
        if (salt != bytes32(0)) {
            emit CallSalt(id, salt);
        }
    }

    /**
     * @dev Schedule an operation containing a batch of transactions.
     *
     * Emits {CallSalt} if salt is nonzero, and one {CallScheduled} event per transaction in the batch.
     *
     * Requirements:
     *
     * - the caller must have the 'proposer' role.
     */
    function scheduleBatch(
        address[] calldata targets,
        uint256[] calldata values,
        bytes[] calldata payloads,
        bytes32 predecessor,
        bytes32 salt,
        uint256 delay
    ) public virtual onlyRole(PROPOSER_ROLE) {
        if (targets.length != values.length || targets.length != payloads.length) {
            revert TimelockInvalidOperationLength(targets.length, payloads.length, values.length);
        }

        bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt);
        _schedule(id, delay);
        for (uint256 i = 0; i < targets.length; ++i) {
            emit CallScheduled(id, i, targets[i], values[i], payloads[i], predecessor, delay);
        }
        if (salt != bytes32(0)) {
            emit CallSalt(id, salt);
        }
    }

    /**
     * @dev Schedule an operation that is to become valid after a given delay.
     */
    function _schedule(bytes32 id, uint256 delay) private {
        if (isOperation(id)) {
            revert TimelockUnexpectedOperationState(id, _encodeStateBitmap(OperationState.Unset));
        }
        uint256 minDelay = getMinDelay();
        if (delay < minDelay) {
            revert TimelockInsufficientDelay(delay, minDelay);
        }
        _timestamps[id] = block.timestamp + delay;
    }

    /**
     * @dev Cancel an operation.
     *
     * Requirements:
     *
     * - the caller must have the 'canceller' role.
     */
    function cancel(bytes32 id) public virtual onlyRole(CANCELLER_ROLE) {
        if (!isOperationPending(id)) {
            revert TimelockUnexpectedOperationState(
                id,
                _encodeStateBitmap(OperationState.Waiting) | _encodeStateBitmap(OperationState.Ready)
            );
        }
        delete _timestamps[id];

        emit Cancelled(id);
    }

    /**
     * @dev Execute an (ready) operation containing a single transaction.
     *
     * Emits a {CallExecuted} event.
     *
     * Requirements:
     *
     * - the caller must have the 'executor' role.
     */
    // This function can reenter, but it doesn't pose a risk because _afterCall checks that the proposal is pending,
    // thus any modifications to the operation during reentrancy should be caught.
    // slither-disable-next-line reentrancy-eth
    function execute(
        address target,
        uint256 value,
        bytes calldata payload,
        bytes32 predecessor,
        bytes32 salt
    ) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
        bytes32 id = hashOperation(target, value, payload, predecessor, salt);

        _beforeCall(id, predecessor);
        _execute(target, value, payload);
        emit CallExecuted(id, 0, target, value, payload);
        _afterCall(id);
    }

    /**
     * @dev Execute an (ready) operation containing a batch of transactions.
     *
     * Emits one {CallExecuted} event per transaction in the batch.
     *
     * Requirements:
     *
     * - the caller must have the 'executor' role.
     */
    // This function can reenter, but it doesn't pose a risk because _afterCall checks that the proposal is pending,
    // thus any modifications to the operation during reentrancy should be caught.
    // slither-disable-next-line reentrancy-eth
    function executeBatch(
        address[] calldata targets,
        uint256[] calldata values,
        bytes[] calldata payloads,
        bytes32 predecessor,
        bytes32 salt
    ) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
        if (targets.length != values.length || targets.length != payloads.length) {
            revert TimelockInvalidOperationLength(targets.length, payloads.length, values.length);
        }

        bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt);

        _beforeCall(id, predecessor);
        for (uint256 i = 0; i < targets.length; ++i) {
            address target = targets[i];
            uint256 value = values[i];
            bytes calldata payload = payloads[i];
            _execute(target, value, payload);
            emit CallExecuted(id, i, target, value, payload);
        }
        _afterCall(id);
    }

    /**
     * @dev Execute an operation's call.
     */
    function _execute(address target, uint256 value, bytes calldata data) internal virtual {
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        Address.verifyCallResult(success, returndata);
    }

    /**
     * @dev Checks before execution of an operation's calls.
     */
    function _beforeCall(bytes32 id, bytes32 predecessor) private view {
        if (!isOperationReady(id)) {
            revert TimelockUnexpectedOperationState(id, _encodeStateBitmap(OperationState.Ready));
        }
        if (predecessor != bytes32(0) && !isOperationDone(predecessor)) {
            revert TimelockUnexecutedPredecessor(predecessor);
        }
    }

    /**
     * @dev Checks after execution of an operation's calls.
     */
    function _afterCall(bytes32 id) private {
        if (!isOperationReady(id)) {
            revert TimelockUnexpectedOperationState(id, _encodeStateBitmap(OperationState.Ready));
        }
        _timestamps[id] = _DONE_TIMESTAMP;
    }

    /**
     * @dev Changes the minimum timelock duration for future operations.
     *
     * Emits a {MinDelayChange} event.
     *
     * Requirements:
     *
     * - the caller must be the timelock itself. This can only be achieved by scheduling and later executing
     * an operation where the timelock is the target and the data is the ABI-encoded call to this function.
     */
    function updateDelay(uint256 newDelay) external virtual {
        address sender = _msgSender();
        if (sender != address(this)) {
            revert TimelockUnauthorizedCaller(sender);
        }
        emit MinDelayChange(_minDelay, newDelay);
        _minDelay = newDelay;
    }

    /**
     * @dev Encodes a `OperationState` into a `bytes32` representation where each bit enabled corresponds to
     * the underlying position in the `OperationState` enum. For example:
     *
     * 0x000...1000
     *   ^^^^^^----- ...
     *         ^---- Done
     *          ^--- Ready
     *           ^-- Waiting
     *            ^- Unset
     */
    function _encodeStateBitmap(OperationState operationState) internal pure returns (bytes32) {
        return bytes32(1 << uint8(operationState));
    }
}
IERC1155Receiver.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Interface that must be implemented by smart contracts in order to receive
 * ERC-1155 token transfers.
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}
ERC1155Holder.sol 42 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/utils/ERC1155Holder.sol)

pragma solidity ^0.8.20;

import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";

/**
 * @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
 *
 * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
 * stuck.
 */
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
    }

    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155BatchReceived.selector;
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
IERC721Receiver.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be
     * reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
ERC721Holder.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.20;

import {IERC721Receiver} from "../IERC721Receiver.sol";

/**
 * @dev Implementation of the {IERC721Receiver} interface.
 *
 * Accepts all token transfers.
 * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
 * {IERC721-setApprovalForAll}.
 */
abstract contract ERC721Holder is IERC721Receiver {
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
        return this.onERC721Received.selector;
    }
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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 Context {
    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;
    }
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @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 ReentrancyGuard {
    // 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;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _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 {
        // 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 {
        // 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) {
        return _status == ENTERED;
    }
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./IERC165.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 ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// 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);
}

Read Contract

allPurchased 0x95a01d06 → uint256
availableForPurchase 0x3333dcc5 → uint256
cap 0x355274ea → uint256
claimable 0xaf38d757 → uint256
claimableForUser 0x9601497b → uint256
claimed 0xe834a834 → uint256
claimedByUser 0x18c41107 → uint256
finishRoundTimestamp 0x06cd3af1 → uint256
owner 0x8da5cb5b → address
purchased 0x879f9c96 → uint256
purchasedByUser 0xc4098ed8 → uint256
startRoundTimestamp 0x9de5f92c → uint256
timeLock 0xd085835a → address
token 0xfc0c546a → address
treasury 0x61d027b3 → address
vestingTimestamp 0x6cd799be → uint256

Write Contract 12 functions

These functions modify contract state and require a wallet transaction to execute.

claim 0x379607f5
uint256 amount
executeReserveTokens 0xb14a1e87
address beneficiary
uint256 amount
executeSetStartRound 0x7b292a4a
uint256 startRound
executeWithdrawUnpurchasedFunds 0xb569ef8c
No parameters
renounceOwnership 0x715018a6
No parameters
reserveTokens 0x78cf19e9
address beneficiary
uint256 amount
scheduleReserveTokens 0xaab006d5
address beneficiary
uint256 amount
scheduleSetStartRound 0xa0447662
uint256 startRound
scheduleWithdrawUnpurchasedFunds 0x14f5cd17
No parameters
setStartRound 0x0d567f38
uint256 startRound
transferOwnership 0xf2fde38b
address newOwner
withdrawUnpurchasedFunds 0xffbbfe4b
No parameters

Recent Transactions

No transactions found for this address