Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xf48415039913DBdF17e337e681de922A9cb04010
Balance 0 ETH
Nonce 1
Code Size 6294 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6294 bytes
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c80638da5cb5b116100ad578063ccc8362c11610071578063ccc8362c146102a4578063d45dc3b6146102ad578063e3a9db1a146102c0578063f2fde38b146102e0578063fad1126f146102f357600080fd5b80638da5cb5b146102455780639130fc77146102565780639ad60b8e14610269578063bbd0949d1461027c578063be9a65551461029c57600080fd5b80632cb75a30116100f45780632cb75a30146101e7578063372500ab146101ef57806343c8c943146101f75780636d2698b214610222578063715018a61461023d57600080fd5b806304e806be1461013157806307da68f51461016f57806312df892a14610179578063150b7a021461018c5780631f2698ab146101c3575b600080fd5b61015c61013f366004611233565b600360209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b61017761030e565b005b610177610187366004611263565b610379565b6101aa61019a3660046112ae565b630a85bd0160e11b949350505050565b6040516001600160e01b03199091168152602001610166565b6001546101d790600160a01b900460ff1681565b6040519015158152602001610166565b61015c601281565b6101776103df565b60015461020a906001600160a01b031681565b6040516001600160a01b039091168152602001610166565b61020a73a5ae87b40076745895bb7387011ca8de5fde37e081565b6101776105a4565b6000546001600160a01b031661020a565b61017761026436600461138a565b6105da565b6101776102773660046113f1565b610652565b61028f61028a36600461145d565b6108e0565b60405161016691906114de565b6101776109aa565b61015c60045481565b6101776102bb3660046113f1565b610a12565b6102d36102ce36600461138a565b610c83565b6040516101669190611522565b6101776102ee36600461138a565b610e0e565b61020a7386e9c5ad3d4b5519da2d2c19f5c71baa5ef4093381565b6000546001600160a01b031633146103415760405162461bcd60e51b815260040161033890611597565b60405180910390fd5b6001805460ff60a01b191690556040517f7acc84e34091ae817647a4c49116f5cc07f319078ba80f8f5fde37ea7e25cbd690600090a1565b6000546001600160a01b031633146103a35760405162461bcd60e51b815260040161033890611597565b60048190556040518181527fa108be85db8eaa102cd3c727dc21fa14deaac87ce9d9dba8a8b9019936c0530a906020015b60405180910390a150565b336000805b60028160ff16101561054c5760008160ff166001811115610407576104076115cc565b905060005b6001600160a01b038516600090815260026020526040812061045e9184600181111561043a5761043a6115cc565b600181111561044b5761044b6115cc565b8152602001908152602001600020610ea9565b811015610537576001600160a01b03851660009081526002602052604081206104c390839083866001811115610496576104966115cc565b60018111156104a7576104a76115cc565b8152602001908152602001600020610eb990919063ffffffff16565b905060006104d2878387610ecc565b9050801561052d576104e481876115f8565b955043600360008660018111156104fd576104fd6115cc565b600181111561050e5761050e6115cc565b8152602080820192909252604090810160009081208682529092529020555b505060010161040c565b5050808061054490611610565b9150506103e4565b5080156105a05761055d8282610fb6565b604080516001600160a01b0384168152602081018390527f106f923f993c2149d49b4255ff723acafa1f2d94393f561d3eda32ae348f7241910160405180910390a15b5050565b6000546001600160a01b031633146105ce5760405162461bcd60e51b815260040161033890611597565b6105d86000611020565b565b6000546001600160a01b031633146106045760405162461bcd60e51b815260040161033890611597565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527fba2cc6bd7fef6b0ef35edd4e2196952ce904fd3e4c720b6afe2d5c098a2d6453906020016103d4565b600154600160a01b900460ff1661067c57604051636f312cbd60e01b815260040160405180910390fd5b3360005b8481101561089957600086868381811061069c5761069c61162f565b90506020020135905060008585848181106106b9576106b961162f565b90506020020160208101906106ce9190611656565b60ff1660018111156106e2576106e26115cc565b90506000808260018111156106f9576106f96115cc565b03610719575073a5ae87b40076745895bb7387011ca8de5fde37e0610766565b600182600181111561072d5761072d6115cc565b0361074d57507386e9c5ad3d4b5519da2d2c19f5c71baa5ef40933610766565b604051631a96fe1360e21b815260040160405180910390fd5b604051635c46a7ef60e11b81526001600160a01b03868116600483015230602483015260448201859052608060648301526000608483015282169063b88d4fde9060a401600060405180830381600087803b1580156107c457600080fd5b505af11580156107d8573d6000803e3d6000fd5b5050506001600160a01b03861660009081526002602052604081206108399250859185600181111561080c5761080c6115cc565b600181111561081d5761081d6115cc565b815260200190815260200160002061107090919063ffffffff16565b504360036000846001811115610851576108516115cc565b6001811115610862576108626115cc565b81526020019081526020016000206000858152602001908152602001600020819055505050506108928160010190565b9050610680565b507fb0d73e0a4e730eeba8bb4067e242393a6f043d0ee10c44f73e7cf56d7a057c5e81868686866040516108d1959493929190611671565b60405180910390a15050505050565b60608367ffffffffffffffff8111156108fb576108fb611298565b604051908082528060200260200182016040528015610924578160200160208202803683370190505b50905060005b848110156109a05761097b878787848181106109485761094861162f565b905060200201358686858181106109615761096161162f565b90506020020160208101906109769190611656565b610ecc565b82828151811061098d5761098d61162f565b602090810291909101015260010161092a565b5095945050505050565b6000546001600160a01b031633146109d45760405162461bcd60e51b815260040161033890611597565b6001805460ff60a01b1916600160a01b1790556040517fd8cea0ecd56872ff072e771658b5682ffe4de16d752947f79597d600ea56f7a990600090a1565b610a1a6103df565b3360005b84811015610c4b576000868683818110610a3a57610a3a61162f565b9050602002013590506000858584818110610a5757610a5761162f565b9050602002016020810190610a6c9190611656565b60ff166001811115610a8057610a806115cc565b6001600160a01b0385166000908152600260205260408120919250610ae0918491846001811115610ab357610ab36115cc565b6001811115610ac457610ac46115cc565b815260200190815260200160002061107c90919063ffffffff16565b610afd57604051639dda579960e01b815260040160405180910390fd5b6001600160a01b0384166000908152600260205260408120610b5b91849190846001811115610b2e57610b2e6115cc565b6001811115610b3f57610b3f6115cc565b815260200190815260200160002061109490919063ffffffff16565b50600080826001811115610b7157610b716115cc565b03610b91575073a5ae87b40076745895bb7387011ca8de5fde37e0610bc1565b6001826001811115610ba557610ba56115cc565b0361074d57507386e9c5ad3d4b5519da2d2c19f5c71baa5ef409335b604051635c46a7ef60e11b81523060048201526001600160a01b03868116602483015260448201859052608060648301526000608483015282169063b88d4fde9060a401600060405180830381600087803b158015610c1f57600080fd5b505af1158015610c33573d6000803e3d6000fd5b50505050505050610c448160010190565b9050610a1e565b507f638e9ac99b5041be01aa18e8bbd4420963ac9ce354d4ef9ebe4d088e9f0fb68e81868686866040516108d1959493929190611671565b610c8b61120c565b6001600160a01b0382166000908152600260209081526040808320838052909152812090610cb882610ea9565b67ffffffffffffffff811115610cd057610cd0611298565b604051908082528060200260200182016040528015610cf9578160200160208202803683370190505b50905060005b610d0883610ea9565b811015610d3e57610d198382610eb9565b828281518110610d2b57610d2b61162f565b6020908102919091010152600101610cff565b506001600160a01b038416600090815260026020908152604080832060018452909152812090610d6d82610ea9565b67ffffffffffffffff811115610d8557610d85611298565b604051908082528060200260200182016040528015610dae578160200160208202803683370190505b50905060005b610dbd83610ea9565b811015610df357610dce8382610eb9565b828281518110610de057610de061162f565b6020908102919091010152600101610db4565b50604080518082019091529283526020830152509392505050565b6000546001600160a01b03163314610e385760405162461bcd60e51b815260040161033890611597565b6001600160a01b038116610e9d5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610338565b610ea681611020565b50565b6000610eb3825490565b92915050565b6000610ec583836110a0565b9392505050565b6000808260ff166001811115610ee457610ee46115cc565b6001600160a01b0386166000908152600260205260408120919250610f17918691846001811115610ab357610ab36115cc565b610f25576000915050610ec5565b600060036000836001811115610f3d57610f3d6115cc565b6001811115610f4e57610f4e6115cc565b8152602080820192909252604090810160009081208882529092528120549150611c20610f7b8343611702565b610f859190611719565b9050610f936012600a61181f565b81600454610fa1919061182b565b610fab919061182b565b979650505050505050565b6001546040516340c10f1960e01b81526001600160a01b03848116600483015260248201849052909116906340c10f1990604401600060405180830381600087803b15801561100457600080fd5b505af1158015611018573d6000803e3d6000fd5b505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000610ec583836110ca565b60008181526001830160205260408120541515610ec5565b6000610ec58383611119565b60008260000182815481106110b7576110b761162f565b9060005260206000200154905092915050565b600081815260018301602052604081205461111157508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610eb3565b506000610eb3565b6000818152600183016020526040812054801561120257600061113d600183611702565b855490915060009061115190600190611702565b90508181146111b65760008660000182815481106111715761117161162f565b90600052602060002001549050808760000184815481106111945761119461162f565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806111c7576111c761184a565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610eb3565b6000915050610eb3565b60405180604001604052806002905b606081526020019060019003908161121b5790505090565b6000806040838503121561124657600080fd5b82356002811061125557600080fd5b946020939093013593505050565b60006020828403121561127557600080fd5b5035919050565b80356001600160a01b038116811461129357600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600080600080608085870312156112c457600080fd5b6112cd8561127c565b93506112db6020860161127c565b925060408501359150606085013567ffffffffffffffff808211156112ff57600080fd5b818701915087601f83011261131357600080fd5b81358181111561132557611325611298565b604051601f8201601f19908116603f0116810190838211818310171561134d5761134d611298565b816040528281528a602084870101111561136657600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60006020828403121561139c57600080fd5b610ec58261127c565b60008083601f8401126113b757600080fd5b50813567ffffffffffffffff8111156113cf57600080fd5b6020830191508360208260051b85010111156113ea57600080fd5b9250929050565b6000806000806040858703121561140757600080fd5b843567ffffffffffffffff8082111561141f57600080fd5b61142b888389016113a5565b9096509450602087013591508082111561144457600080fd5b50611451878288016113a5565b95989497509550505050565b60008060008060006060868803121561147557600080fd5b61147e8661127c565b9450602086013567ffffffffffffffff8082111561149b57600080fd5b6114a789838a016113a5565b909650945060408801359150808211156114c057600080fd5b506114cd888289016113a5565b969995985093965092949392505050565b6020808252825182820181905260009190848201906040850190845b81811015611516578351835292840192918401916001016114fa565b50909695505050505050565b6020808252600090606083018382018584805b600281101561158a57878503601f19018452825180518087529087019087870190845b8181101561157457835183529289019291890191600101611558565b5090965050509285019291850191600101611535565b5092979650505050505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000821982111561160b5761160b6115e2565b500190565b600060ff821660ff8103611626576116266115e2565b60010192915050565b634e487b7160e01b600052603260045260246000fd5b803560ff8116811461129357600080fd5b60006020828403121561166857600080fd5b610ec582611645565b6001600160a01b0386168152606060208083018290529082018590526000906001600160fb1b038611156116a457600080fd5b8560051b808860808601378301838103608090810160408601528101859052859060009060a0015b868210156116f45760ff6116df84611645565b168152918301916001919091019083016116cc565b9a9950505050505050505050565b600082821015611714576117146115e2565b500390565b60008261173657634e487b7160e01b600052601260045260246000fd5b500490565b600181815b8085111561177657816000190482111561175c5761175c6115e2565b8085161561176957918102915b93841c9390800290611740565b509250929050565b60008261178d57506001610eb3565b8161179a57506000610eb3565b81600181146117b057600281146117ba576117d6565b6001915050610eb3565b60ff8411156117cb576117cb6115e2565b50506001821b610eb3565b5060208310610133831016604e8410600b84101617156117f9575081810a610eb3565b611803838361173b565b8060001904821115611817576118176115e2565b029392505050565b6000610ec5838361177e565b6000816000190483118215151615611845576118456115e2565b500290565b634e487b7160e01b600052603160045260246000fdfea264697066735822122030ae058962df2043f5e4f1f2e9930a1b9ccad8c6ca74add7ff1a2606f0bdd19f64736f6c634300080d0033

Verified Source Code Partial Match

Compiler: v0.8.13+commit.abaa5c0e EVM: london Optimization: Yes (200 runs)
Staking.sol 953 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)



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



/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

/**
 * @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 Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        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);
    }
}// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)



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



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

/**
 * @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`, 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 be 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 Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

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

    /**
     * @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;
}// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)



// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)



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

/**
 * @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;
    }
}// OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol)



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

        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;

        assembly {
            result := store
        }

        return result;
    }
}
interface IGum {
    function mint(address, uint256) external;

    function decimals() external returns (uint8);
}

error NotStarted();
error TokenNotDeposited();
error UnknownBGContract();

/**
 * @notice Accept deposits of Bubblegum Kid and Bubblegum Puppy NFTs
 * ("staking") in exchange for GUM token rewards. Thanks to the Sappy Seals team,
 * this contract is largely based on their work
 * @dev Contract defines a "day" as 7200 ethereum blocks.
 */
contract Staking is ERC721Holder, Ownable {
    using EnumerableSet for EnumerableSet.UintSet;

    address public constant BGK = 0xa5ae87B40076745895BB7387011ca8DE5fde37E0;
    address public constant BGP = 0x86e9C5ad3D4b5519DA2D2C19F5c71bAa5Ef40933;
    enum BGContract {
        BGK,
        BGP
    }

    uint256 public constant GUM_TOKEN_DECIMALS = 18;

    address public gumToken;

    bool public started;

    mapping(address => mapping(BGContract => EnumerableSet.UintSet))
        private _deposits;
    mapping(BGContract => mapping(uint256 => uint256)) public depositBlocks;
    uint256 public stakeRewardRate;

    event GumTokenUpdated(address _gumToken);
    event Started();
    event Stopped();
    event Deposited(address from, uint256[] tokenIds, uint8[] bgContracts);
    event Withdrawn(address to, uint256[] tokenIds, uint8[] bgContracts);
    event StakeRewardRateUpdated(uint256 _stakeRewardRate);
    event RewardClaimed(address to, uint256 amount);

    constructor(address _gumToken) {
        gumToken = _gumToken;
        stakeRewardRate = 1;
        started = false;
    }

    modifier onlyStarted() {
        if (!started) revert NotStarted();
        _;
    }

    function start() public onlyOwner {
        started = true;
        emit Started();
    }

    function stop() public onlyOwner {
        started = false;
        emit Stopped();
    }

    function unsafe_inc(uint256 x) private pure returns (uint256) {
        unchecked {
            return x + 1;
        }
    }

    /**
     * @dev Change the address of the reward token contract (must
     * support ERC20 functions named in IGum interface and conform
     * to hardcoded GUM_TOKEN_DECIMALS constant).
     */
    function updateGumToken(address _gumToken) public onlyOwner {
        gumToken = _gumToken;
        emit GumTokenUpdated(_gumToken);
    }

    function updateStakeRewardRate(uint256 _stakeRewardRate) public onlyOwner {
        stakeRewardRate = _stakeRewardRate;
        emit StakeRewardRateUpdated(_stakeRewardRate);
    }

    /**
     * @dev Mint GUM token rewards
     * @param to The recipient's ethereum address
     * @param amount The amount to mint
     */
    function _reward(address to, uint256 amount) internal {
        IGum(gumToken).mint(to, amount);
    }

    /**
     * @dev Calculate accrued GUM token rewards for a given
     * BGK or BGP NFT
     * @param account The user's ethereum address
     * @param tokenId The NFT's id
     * @param _bgContract Kids (0) or Puppies (1)
     * @return rewards
     */
    function getRewardsForToken(
        address account,
        uint256 tokenId,
        uint8 _bgContract
    ) internal view returns (uint256) {
        BGContract bgContract = BGContract(_bgContract);
        // the user has not staked this nft
        if (!_deposits[account][bgContract].contains(tokenId)) {
            return 0;
        }
        // when was the NFT deposited?
        uint256 depositBlock = depositBlocks[bgContract][tokenId];
        // how many days have elapsed since the NFT was deposited or
        // rewards were claimed?
        uint256 depositDaysElapsed = (block.number - depositBlock) / 7200;
        return stakeRewardRate * depositDaysElapsed * 10**GUM_TOKEN_DECIMALS;
    }

    /**
     * @dev Calculate accrued GUM token rewards for a set
     * of BGK and BGP NFTs
     * @param account The user's ethereum address
     * @param tokenIds The NFTs' ids
     * @param bgContracts The NFTs' contracts -- Kids (0)
     * or Puppies (1) -- with indices corresponding to those
     * of `tokenIds`
     * @return rewards
     */
    function calculateRewards(
        address account,
        uint256[] calldata tokenIds,
        uint8[] calldata bgContracts
    ) public view returns (uint256[] memory rewards) {
        rewards = new uint256[](tokenIds.length);
        for (uint256 i; i < tokenIds.length; i = unsafe_inc(i)) {
            rewards[i] = getRewardsForToken(
                account,
                tokenIds[i],
                bgContracts[i]
            );
        }
    }

    /**
     * @dev Claim accrued GUM token rewards for all
     * staked BGK and BGP NFTs -- if caller's rewards are
     * greater than 0, balance will be transferred to
     * caller's address
     */
    function claimRewards() public {
        address account = msg.sender;
        uint256 amount;
        for (uint8 i; i < 2; i++) {
            BGContract bgContract = BGContract(i);
            for (
                uint256 j;
                j < _deposits[account][bgContract].length();
                j = unsafe_inc(j)
            ) {
                uint256 tokenId = _deposits[account][bgContract].at(j);
                uint256 thisAmount = (getRewardsForToken(account, tokenId, i));
                if (thisAmount > 0) {
                    amount += thisAmount;
                    depositBlocks[bgContract][tokenId] = block.number;
                }
            }
        }
        if (amount > 0) {
            _reward(account, amount);
            emit RewardClaimed(account, amount);
        }
    }

    /**
     * @dev Deposit ("stake") a set of BGK and BGP NFTs. Caller
     * must be the owner of the NFTs supplied as arguments.
     * @param tokenIds The NFTs' ids
     * @param bgContracts The NFTs' contracts -- Kids (0)
     * or Puppies (1) -- with indices corresponding to those
     * of `tokenIds`
     */
    function deposit(uint256[] calldata tokenIds, uint8[] calldata bgContracts)
        external
        onlyStarted
    {
        address account = msg.sender;
        for (uint256 i; i < tokenIds.length; i = unsafe_inc(i)) {
            uint256 tokenId = tokenIds[i];
            BGContract bgContract = BGContract(bgContracts[i]);
            address bgContractAddress;
            if (bgContract == BGContract.BGK) {
                bgContractAddress = BGK;
            } else if (bgContract == BGContract.BGP) {
                bgContractAddress = BGP;
            } else {
                revert UnknownBGContract();
            }
            IERC721(bgContractAddress).safeTransferFrom(
                account,
                address(this),
                tokenId,
                ""
            );
            _deposits[account][bgContract].add(tokenId);
            depositBlocks[bgContract][tokenId] = block.number;
        }
        emit Deposited(account, tokenIds, bgContracts);
    }

    /**
     * @dev Withdraw ("unstake") a set of deposited BGK and BGP
     * NFTs. Calling `withdraw` automatically claims accrued
     * rewards on the NFTs supplied as arguments. Caller must
     * have deposited the NFTs.
     * @param tokenIds The NFTs' ids
     * @param bgContracts The NFTs' contracts -- Kids (0)
     * or Puppies (1) -- with indices corresponding to those
     * of `tokenIds`
     */
    function withdraw(uint256[] calldata tokenIds, uint8[] calldata bgContracts)
        external
    {
        claimRewards();
        address account = msg.sender;
        for (uint256 i; i < tokenIds.length; i = unsafe_inc(i)) {
            uint256 tokenId = tokenIds[i];
            BGContract bgContract = BGContract(bgContracts[i]);
            if (!_deposits[account][bgContract].contains(tokenId)) {
                revert TokenNotDeposited();
            }
            _deposits[account][bgContract].remove(tokenId);
            address nftAddress;
            if (bgContract == BGContract.BGK) {
                nftAddress = BGK;
            } else if (bgContract == BGContract.BGP) {
                nftAddress = BGP;
            } else {
                revert UnknownBGContract();
            }
            IERC721(nftAddress).safeTransferFrom(
                address(this),
                account,
                tokenId,
                ""
            );
        }
        emit Withdrawn(account, tokenIds, bgContracts);
    }

    /**
     * @dev Get the ids of Kid and Puppy NFTs staked by the
     * user supplied in the `account` argument
     * @param account The depositor's ethereum address
     * @return bgContracts The ids of the deposited NFTs,
     * as an array: the first item is an array of Kid ids,
     * the second an array of Pup ids
     */
    function depositsOf(address account)
        external
        view
        returns (uint256[][2] memory)
    {
        EnumerableSet.UintSet storage bgkDepositSet = _deposits[account][
            BGContract.BGK
        ];
        uint256[] memory bgkIds = new uint256[](bgkDepositSet.length());
        for (uint256 i; i < bgkDepositSet.length(); i = unsafe_inc(i)) {
            bgkIds[i] = bgkDepositSet.at(i);
        }
        EnumerableSet.UintSet storage bgpDepositSet = _deposits[account][
            BGContract.BGP
        ];
        uint256[] memory bgpIds = new uint256[](bgpDepositSet.length());
        for (uint256 i; i < bgpDepositSet.length(); i = unsafe_inc(i)) {
            bgpIds[i] = bgpDepositSet.at(i);
        }
        return [bgkIds, bgpIds];
    }
}

Read Contract

BGK 0x6d2698b2 → address
BGP 0xfad1126f → address
GUM_TOKEN_DECIMALS 0x2cb75a30 → uint256
calculateRewards 0xbbd0949d → uint256[]
depositBlocks 0x04e806be → uint256
depositsOf 0xe3a9db1a → uint256[][2]
gumToken 0x43c8c943 → address
owner 0x8da5cb5b → address
stakeRewardRate 0xccc8362c → uint256
started 0x1f2698ab → bool

Write Contract 10 functions

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

claimRewards 0x372500ab
No parameters
deposit 0x9ad60b8e
uint256[] tokenIds
uint8[] bgContracts
onERC721Received 0x150b7a02
address
address
uint256
bytes
returns: bytes4
renounceOwnership 0x715018a6
No parameters
start 0xbe9a6555
No parameters
stop 0x07da68f5
No parameters
transferOwnership 0xf2fde38b
address newOwner
updateGumToken 0x9130fc77
address _gumToken
updateStakeRewardRate 0x12df892a
uint256 _stakeRewardRate
withdraw 0xd45dc3b6
uint256[] tokenIds
uint8[] bgContracts

Recent Transactions

No transactions found for this address