Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x70C7af7a78B5453E4A09376eB2b506CE4E4140E5
Balance 0 ETH
Nonce 1
Code Size 5941 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5941 bytes
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c80638da5cb5b1161008c578063cbfd469011610066578063cbfd4690146101d3578063e295ddca146101e6578063f2fde38b146101f9578063fe058c4f1461020c57600080fd5b80638da5cb5b146101855780638da7be7b146101a057806394b6e751146101b357600080fd5b8063150b7a02146100d45780631526fe271461011057806332a9caba146101425780634ecb98e31461015757806351cecc801461016a578063715018a61461017d575b600080fd5b6100f26100e23660046113ec565b630a85bd0160e11b949350505050565b6040516001600160e01b031990911681526020015b60405180910390f35b61012361011e3660046114b0565b610234565b604080516001600160a01b039093168352602083019190915201610107565b6101556101503660046114c9565b610279565b005b6101556101653660046114f5565b6102fd565b6101556101783660046114f5565b610562565b610155610831565b6000546040516001600160a01b039091168152602001610107565b6101556101ae366004611517565b610845565b6101c66101c13660046114c9565b610b37565b60405161010791906115c3565b6101556101e13660046114f5565b610c50565b6101556101f4366004611517565b610c88565b610155610207366004611607565b611071565b61021f61021a3660046114f5565b6110ea565b60408051928352602083019190915201610107565b60008060006001848154811061024c5761024c611624565b6000918252602090912060059091020180546001909101546001600160a01b039091169590945092505050565b610281611145565b6001805480820182556000919091526005027fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6810180546001600160a01b039094166001600160a01b0319909416939093179092557fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf790910155565b60006001828154811061031257610312611624565b90600052602060002090600502019050806003016000848152602001908152602001600020600101544210156103995760405162461bcd60e51b815260206004820152602160248201527f796f7572206e6674206973206c6f636b656420666f72207769746864726177616044820152601b60fa1b60648201526084015b60405180910390fd5b3360009081526002808301602052604090912001546103f45760405162461bcd60e51b81526020600482015260176024820152761e5bdd481a185d99481b9bc81b999d1cc81cdd185ad959604a1b6044820152606401610390565b60008381526004820160205260409020546001600160a01b0316331461045c5760405162461bcd60e51b815260206004820152601960248201527f796f7520646f6e2774206f776e207468697320746f6b656e21000000000000006044820152606401610390565b33600090815260028083016020526040822001805460019290610480908490611650565b90915550506000838152600482016020908152604080832080546001600160a01b03191690553383526002840190915290206104bc818561119f565b5081546040516323b872dd60e01b81526001600160a01b03909116906323b872dd906104f090309033908990600401611663565b600060405180830381600087803b15801561050a57600080fd5b505af115801561051e573d6000803e3d6000fd5b5050604080518781524260208201523393507ff960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb28092500160405180910390a250505050565b60006001828154811061057757610577611624565b6000918252602090912060059091020180546040516370a0823160e01b81523360048201529192506001916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156105d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f89190611687565b10156106425760405162461bcd60e51b8152602060048201526019602482015278796f7520646f6e74206861766520656e6f756768206e66747360381b6044820152606401610390565b80546040516331a9108f60e11b81526004810185905233916001600160a01b031690636352211e90602401602060405180830381865afa15801561068a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ae91906116a0565b6001600160a01b0316146106fe5760405162461bcd60e51b8152602060048201526017602482015276796f7520646f6e2774206f776e2074686973206e66742160481b6044820152606401610390565b336000908152600280830160205260408220018054600192906107229084906116bd565b9091555050336000908152600282016020526040902061074290846111b2565b50600181015461075290426116bd565b6000848152600383016020908152604080832060018101949094554290935560048085019091529082902080546001600160a01b03191633908117909155835492516323b872dd60e01b81526001600160a01b0393909316926323b872dd926107c092913091899101611663565b600060405180830381600087803b1580156107da57600080fd5b505af11580156107ee573d6000803e3d6000fd5b5050604080518681524260208201523393507f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b692500160405180910390a2505050565b610839611145565b61084360006111be565b565b60006001828154811061085a5761085a611624565b600091825260208083203384526002600590930201828101909152604090922001549091506108c55760405162461bcd60e51b81526020600482015260176024820152761e5bdd481a185d99481b9bc81b999d1cc81cdd185ad959604a1b6044820152606401610390565b60005b8351811015610b3157336001600160a01b03168260040160008684815181106108f3576108f3611624565b6020908102919091018101518252810191909152604001600020546001600160a01b0316148015610955575081600301600085838151811061093757610937611624565b60200260200101518152602001908152602001600020600101544210155b15610b1f573360009081526002808401602052604082200180546001929061097e908490611650565b92505081905550600082600401600086848151811061099f5761099f611624565b6020026020010151815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055506000826002016000336001600160a01b03166001600160a01b031681526020019081526020016000209050610a33858381518110610a1957610a19611624565b60200260200101518260000161119f90919063ffffffff16565b50825485516001600160a01b03909116906323b872dd9030903390899087908110610a6057610a60611624565b60200260200101516040518463ffffffff1660e01b8152600401610a8693929190611663565b600060405180830381600087803b158015610aa057600080fd5b505af1158015610ab4573d6000803e3d6000fd5b50505050336001600160a01b03167ff960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb280868481518110610af557610af5611624565b602002602001015142604051610b15929190918252602082015260400190565b60405180910390a2505b80610b29816116d0565b9150506108c8565b50505050565b6060600060018381548110610b4e57610b4e611624565b600091825260208083206001600160a01b03881684526002600590930201918201905260408220909250610b819061120e565b67ffffffffffffffff811115610b9957610b996113a5565b604051908082528060200260200182016040528015610bc2578160200160208202803683370190505b50905060005b6001600160a01b03861660009081526002840160205260409020610beb9061120e565b811015610c45576001600160a01b03861660009081526002840160205260409020610c169082611218565b828281518110610c2857610c28611624565b602090810291909101015280610c3d816116d0565b915050610bc8565b509150505b92915050565b610c58611145565b600060018381548110610c6d57610c6d611624565b60009182526020909120600160059092020101919091555050565b600060018281548110610c9d57610c9d611624565b6000918252602090912060059091020180546040516370a0823160e01b81523360048201529192506001916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610cfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1e9190611687565b1015610d685760405162461bcd60e51b8152602060048201526019602482015278796f7520646f6e74206861766520656e6f756768206e66747360381b6044820152606401610390565b60005b8351811015610b31578154845133916001600160a01b031690636352211e90879085908110610d9c57610d9c611624565b60200260200101516040518263ffffffff1660e01b8152600401610dc291815260200190565b602060405180830381865afa158015610ddf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0391906116a0565b6001600160a01b031614610e535760405162461bcd60e51b8152602060048201526017602482015276796f7520646f6e2774206f776e2074686973206e66742160481b6044820152606401610390565b33600090815260028084016020526040822001805460019290610e779084906116bd565b92505081905550610eb7848281518110610e9357610e93611624565b602090810291909101810151336000908152600286019092526040909120906111b2565b506001820154610ec790426116bd565b826003016000868481518110610edf57610edf611624565b602002602001015181526020019081526020016000206001018190555042826003016000868481518110610f1557610f15611624565b602002602001015181526020019081526020016000206000018190555033826004016000868481518110610f4b57610f4b611624565b602090810291909101810151825281019190915260400160002080546001600160a01b0319166001600160a01b03928316179055825485519116906323b872dd9033903090889086908110610fa257610fa2611624565b60200260200101516040518463ffffffff1660e01b8152600401610fc893929190611663565b600060405180830381600087803b158015610fe257600080fd5b505af1158015610ff6573d6000803e3d6000fd5b50505050336001600160a01b03167f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b685838151811061103757611037611624565b602002602001015142604051611057929190918252602082015260400190565b60405180910390a280611069816116d0565b915050610d6b565b611079611145565b6001600160a01b0381166110de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610390565b6110e7816111be565b50565b60008060006001848154811061110257611102611624565b6000918252602080832097835260059190910290960160030186526040908190208151808301909252805480835260019091015491909601819052959350505050565b6000546001600160a01b031633146108435760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610390565b60006111ab8383611224565b9392505050565b60006111ab8383611317565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000610c4a825490565b60006111ab8383611366565b6000818152600183016020526040812054801561130d576000611248600183611650565b855490915060009061125c90600190611650565b90508181146112c157600086600001828154811061127c5761127c611624565b906000526020600020015490508087600001848154811061129f5761129f611624565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806112d2576112d26116e9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610c4a565b6000915050610c4a565b600081815260018301602052604081205461135e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610c4a565b506000610c4a565b600082600001828154811061137d5761137d611624565b9060005260206000200154905092915050565b6001600160a01b03811681146110e757600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156113e4576113e46113a5565b604052919050565b6000806000806080858703121561140257600080fd5b843561140d81611390565b935060208581013561141e81611390565b935060408601359250606086013567ffffffffffffffff8082111561144257600080fd5b818801915088601f83011261145657600080fd5b813581811115611468576114686113a5565b61147a601f8201601f191685016113bb565b9150808252898482850101111561149057600080fd5b808484018584013760008482840101525080935050505092959194509250565b6000602082840312156114c257600080fd5b5035919050565b600080604083850312156114dc57600080fd5b82356114e781611390565b946020939093013593505050565b6000806040838503121561150857600080fd5b50508035926020909101359150565b6000806040838503121561152a57600080fd5b823567ffffffffffffffff8082111561154257600080fd5b818501915085601f83011261155657600080fd5b813560208282111561156a5761156a6113a5565b8160051b925061157b8184016113bb565b828152928401810192818101908985111561159557600080fd5b948201945b848610156115b35785358252948201949082019061159a565b9997909101359750505050505050565b6020808252825182820181905260009190848201906040850190845b818110156115fb578351835292840192918401916001016115df565b50909695505050505050565b60006020828403121561161957600080fd5b81356111ab81611390565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b81810381811115610c4a57610c4a61163a565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60006020828403121561169957600080fd5b5051919050565b6000602082840312156116b257600080fd5b81516111ab81611390565b80820180821115610c4a57610c4a61163a565b6000600182016116e2576116e261163a565b5060010190565b634e487b7160e01b600052603160045260246000fdfea264697066735822122006c3fc1ba439f83f8ded1afc434d2b53bd30534c3723c28708574e65cfc427df64736f6c63430008100033

Verified Source Code Partial Match

Compiler: v0.8.16+commit.07a7930e EVM: london Optimization: Yes (200 runs)
Staking.sol 867 lines
// SPDX-License-Identifier: GPL-3.0

// File: @openzeppelin/contracts/utils/structs/EnumerableSet.sol


// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol


// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

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

// File: @openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol


// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.0;


/**
 * @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}.
 */
contract ERC721Holder is IERC721Receiver {
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address,
        address,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC721Received.selector;
    }
}

// File: @openzeppelin/contracts/utils/introspection/IERC165.sol


// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

// File: @openzeppelin/contracts/token/ERC721/IERC721.sol


// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;


/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

// File: @openzeppelin/contracts/utils/Context.sol


// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

// File: @openzeppelin/contracts/access/Ownable.sol


// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;


/**
 * @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.
 *
 * By default, the owner account will be the one that deploys the contract. 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;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @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 {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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 {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _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);
    }
}

// File: contracts/Staking.sol



pragma solidity ^0.8.11;





contract Staking is ERC721Holder, Ownable {

    using EnumerableSet for EnumerableSet.UintSet;

    struct Staker {
        EnumerableSet.UintSet tokenIds; // set of token ids
        uint256 amount;
    }

    struct StakedNft {
        uint256 stakedTime;
        uint256 lockedTime;
    }

    struct Collection {
        IERC721 NFT;
        uint256 lockTime;
        mapping(address => Staker) Stakers;
        mapping(uint256 => StakedNft) StakedNfts;
        mapping(uint256 => address) StakerAddresses;
    }

    Collection[] nftPools;

    constructor() {
    }

    event Stake(address indexed owner, uint256 id, uint256 time);
    event Unstake(address indexed owner, uint256 id, uint256 time);

    function stakeNFT(uint256 _tokenId, uint256 _poolId) public {
        Collection storage pool = nftPools[_poolId];
        require(pool.NFT.balanceOf(msg.sender) >= 1, "you dont have enough nfts");
        require(
            pool.NFT.ownerOf(_tokenId) == msg.sender,
            "you don't own this nft!"
        );
        pool.Stakers[msg.sender].amount += 1;
        pool.Stakers[msg.sender].tokenIds.add(_tokenId);
        pool.StakedNfts[_tokenId].lockedTime = block.timestamp + pool.lockTime;
        pool.StakedNfts[_tokenId].stakedTime = block.timestamp;
        pool.StakerAddresses[_tokenId] = msg.sender;
        pool.NFT.transferFrom(msg.sender, address(this), _tokenId);
        emit Stake (msg.sender, _tokenId, block.timestamp);
    }

    function batchStakeNFT(uint256[] memory _tokenIds, uint256 _poolId) public {
        Collection storage pool = nftPools[_poolId];
        require(pool.NFT.balanceOf(msg.sender) >= 1, "you dont have enough nfts");
        
        for (uint i = 0; i < _tokenIds.length; i++) {
            require(
                pool.NFT.ownerOf(_tokenIds[i]) == msg.sender,
                "you don't own this nft!"
            );
            pool.Stakers[msg.sender].amount += 1;
            pool.Stakers[msg.sender].tokenIds.add(_tokenIds[i]);
            pool.StakedNfts[_tokenIds[i]].lockedTime = block.timestamp + pool.lockTime;
            pool.StakedNfts[_tokenIds[i]].stakedTime = block.timestamp;
            pool.StakerAddresses[_tokenIds[i]] = msg.sender;
            pool.NFT.transferFrom(msg.sender, address(this), _tokenIds[i]);
            emit Stake (msg.sender, _tokenIds[i], block.timestamp);
        }
    }

    function unstakeNFT(uint256 _tokenId, uint256 _poolId) public {
        Collection storage pool = nftPools[_poolId];
        require(block.timestamp >= pool.StakedNfts[_tokenId].lockedTime, "your nft is locked for withdrawal");
        require(
            pool.Stakers[msg.sender].amount > 0,
            "you have no nfts staked"
        );
        require(pool.StakerAddresses[_tokenId] == msg.sender, "you don't own this token!");
        pool.Stakers[msg.sender].amount -= 1;
        pool.StakerAddresses[_tokenId] = address(0);

        Staker storage u = pool.Stakers[msg.sender];
        u.tokenIds.remove(_tokenId);

        pool.NFT.transferFrom(address(this), msg.sender, _tokenId);

        emit Unstake(msg.sender, _tokenId, block.timestamp);
    }

    function batchUnstakeNFT(uint256[] memory _tokenIds, uint256 _poolId) public {
        Collection storage pool = nftPools[_poolId];
        require(
            pool.Stakers[msg.sender].amount > 0,
            "you have no nfts staked"
        );

        for (uint i = 0; i < _tokenIds.length; i++) {
            if(pool.StakerAddresses[_tokenIds[i]] == msg.sender && block.timestamp >= pool.StakedNfts[_tokenIds[i]].lockedTime) {
                pool.Stakers[msg.sender].amount -= 1;
                pool.StakerAddresses[_tokenIds[i]] = address(0);

                Staker storage u = pool.Stakers[msg.sender];
                u.tokenIds.remove(_tokenIds[i]);

                pool.NFT.transferFrom(address(this), msg.sender, _tokenIds[i]);

                emit Unstake(msg.sender, _tokenIds[i], block.timestamp);
            }
        }
    }

    function addPool(address _nftAddress, uint256 _lockTime) external onlyOwner {
        Collection storage newCollection = nftPools.push();
        newCollection.NFT = IERC721(_nftAddress);
        newCollection.lockTime = _lockTime;
    }

    function poolInfo(uint256 _poolId) external view returns(IERC721, uint256) {
        Collection storage pool = nftPools[_poolId];
        
        return (pool.NFT, pool.lockTime);
    }

    function updatePoolLocktime(uint256 _poolId, uint256 _lockTime) external onlyOwner {
        Collection storage pool = nftPools[_poolId];
        pool.lockTime = _lockTime;
    }

    function stakedNftInfo(uint256 _tokenId, uint256 _poolId) external view returns(uint256, uint256) {
        Collection storage pool = nftPools[_poolId];
        StakedNft memory stakeInfo = pool.StakedNfts[_tokenId];
        
        return (stakeInfo.lockedTime, stakeInfo.stakedTime);
    }

    function stakedNfts(address _owner, uint256 _poolId) external view returns(uint256[] memory) {
        Collection storage pool = nftPools[_poolId];
        uint256[] memory tempArr = new uint256[](pool.Stakers[_owner].tokenIds.length());
        for(uint i = 0; i < pool.Stakers[_owner].tokenIds.length(); i++) {
            tempArr[i] = pool.Stakers[_owner].tokenIds.at(i);
        }
        return tempArr;
    }

}

Read Contract

owner 0x8da5cb5b → address
poolInfo 0x1526fe27 → address, uint256
stakedNftInfo 0xfe058c4f → uint256, uint256
stakedNfts 0x94b6e751 → uint256[]

Write Contract 9 functions

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

addPool 0x32a9caba
address _nftAddress
uint256 _lockTime
batchStakeNFT 0xe295ddca
uint256[] _tokenIds
uint256 _poolId
batchUnstakeNFT 0x8da7be7b
uint256[] _tokenIds
uint256 _poolId
onERC721Received 0x150b7a02
address
address
uint256
bytes
returns: bytes4
renounceOwnership 0x715018a6
No parameters
stakeNFT 0x51cecc80
uint256 _tokenId
uint256 _poolId
transferOwnership 0xf2fde38b
address newOwner
unstakeNFT 0x4ecb98e3
uint256 _tokenId
uint256 _poolId
updatePoolLocktime 0xcbfd4690
uint256 _poolId
uint256 _lockTime

Recent Transactions

No transactions found for this address