Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x21d6D6d6FFD8b68e94bf5159Bb029635Af540aE8
Balance 0 ETH
Nonce 1
Code Size 4300 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

4300 bytes
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c80638456cb59116100ad578063b6b55f2511610071578063b6b55f251461020c578063ba7bd2aa1461021f578063c713aa9414610232578063cddb3e7b14610245578063f2fde38b146102aa57600080fd5b80638456cb59146101ba5780638da5cb5b146101c257806399a03316146101dd578063a1003b29146101e6578063ae04d45d146101f957600080fd5b80633eecea51116100f45780633eecea51146101715780633f4ba83a1461017a5780635c975abb14610182578063715018a61461019f57806379ee54f7146101a757600080fd5b8063083c6323146101315780630d6680871461014d57806329d0fa3e146101565780632be11ae21461015f5780633ccfd60b14610169575b600080fd5b61013a60075481565b6040519081526020015b60405180910390f35b61013a60065481565b61013a60055481565b6101676102bd565b005b6101676102f4565b61013a60025481565b6101676104e0565b60095461018f9060ff1681565b6040519015158152602001610144565b610167610574565b61013a6101b5366004610ef0565b610586565b61016761069e565b6000546040516001600160a01b039091168152602001610144565b61013a60015481565b6101676101f4366004610f20565b6106f6565b610167610207366004610f20565b610703565b61016761021a366004610f20565b610710565b61016761022d366004610f39565b6108a9565b610167610240366004610f20565b6108fb565b610282610253366004610ef0565b600860205260009081526040902080546001820154600283015460038401546004909401549293919290919085565b604080519586526020860194909452928401919091526060830152608082015260a001610144565b6101676102b8366004610ef0565b610908565b60095460ff16156102e95760405162461bcd60e51b81526004016102e090610f5b565b60405180910390fd5b6102f233610981565b565b60095460ff16156103175760405162461bcd60e51b81526004016102e090610f5b565b33600090815260086020908152604091829020825160a0810184528154808252600183015493820193909352600282015493810193909352600381015460608401526004015460808301526007544310158061038457504260065483602001516103819190610f9c565b11155b6103eb5760405162461bcd60e51b815260206004820152603260248201527f596f7520617265206e6f7420616c6c6f77656420746f207769746864726177206044820152716265666f7265206c6f636b65642074696d6560701b60648201526084016102e0565b6000811161043b5760405162461bcd60e51b815260206004820152601d60248201527f576974686472617720616d6f756e742063616e2774206265207a65726f00000060448201526064016102e0565b6104436102bd565b3360009081526008602052604081208181556001808201839055600282018390556003820183905560049091018290558054839290610483908490610fb5565b909155505060405181815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a26104dc7325b4f5d4c314bcd5d7962734936c957b947cb7cf3383610aa3565b5050565b60095460ff1661052a5760405162461bcd60e51b815260206004820152601560248201527414dd185ada5b99c81a5cc81b9bdd081c185d5cd959605a1b60448201526064016102e0565b6009805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b61057c610b06565b6102f26000610b60565b600060015460000361059a57506000919050565b600060075443116105b7576003546105b29043610fb5565b6105c7565b6003546007546105c79190610fb5565b90506000600554826105d99190610fc8565b9050600060015469d3c21bcecceda1000000836105f69190610fc8565b6106009190610fdf565b60045461060d9190610f9c565b6001600160a01b038616600090815260086020908152604091829020825160a081018452815480825260018301549382019390935260028201549381019390935260038101546060840152600401546080830181905292935090919069d3c21bcecceda100000090610680908590610fc8565b61068a9190610fdf565b6106949190610fb5565b9695505050505050565b60095460ff16156106c15760405162461bcd60e51b81526004016102e090610f5b565b6009805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586105573390565b6106fe610b06565b600555565b61070b610b06565b600655565b60095460ff16156107335760405162461bcd60e51b81526004016102e090610f5b565b60075443106107785760405162461bcd60e51b815260206004820152601160248201527014dd185ada5b99c81a185cc8195b991959607a1b60448201526064016102e0565b600081116107c85760405162461bcd60e51b815260206004820152601c60248201527f4465706f73697420616d6f756e742063616e2774206265207a65726f0000000060448201526064016102e0565b3360009081526008602052604090206107df6102bd565b818160000160008282546107f39190610f9c565b9091555050600454815469d3c21bcecceda10000009161081291610fc8565b61081c9190610fdf565b60048201556001810154600003610834574260018201555b438160020181905550816001600082825461084f9190610f9c565b909155505060405182815233907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9060200160405180910390a26104dc7325b4f5d4c314bcd5d7962734936c957b947cb7cf333085610bb0565b6108b1610b06565b81156108d6576108d67325b4f5d4c314bcd5d7962734936c957b947cb7cf3384610aa3565b80156104dc576104dc73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb483383610aa3565b610903610b06565b600755565b610910610b06565b6001600160a01b0381166109755760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016102e0565b61097e81610b60565b50565b610989610bee565b6001600160a01b03811660009081526008602052604081206004808201549054825492939269d3c21bcecceda1000000916109c391610fc8565b6109cd9190610fdf565b6109d79190610fb5565b9050806000036109e657505050565b80600260008282546109f89190610f9c565b9250508190555080826003016000828254610a139190610f9c565b9091555050600454825469d3c21bcecceda100000091610a3291610fc8565b610a3c9190610fdf565b60048301556040518181526001600160a01b038416907fdaaebb9609cb2f719c59c9d334be287bf4def107ad3dec4a6f90d8abaa94c73c9060200160405180910390a2610a9e73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb488483610aa3565b505050565b6040516001600160a01b038316602482015260448101829052610a9e90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610c8b565b6000546001600160a01b031633146102f25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016102e0565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b0380851660248301528316604482015260648101829052610be89085906323b872dd60e01b90608401610acf565b50505050565b600154600003610bfe5743600355565b60006007544311610c1b57600354610c169043610fb5565b610c2b565b600354600754610c2b9190610fb5565b9050600060055482610c3d9190610fc8565b600154909150610c5769d3c21bcecceda100000083610fc8565b610c619190610fdf565b600454610c6e9190610f9c565b6004556007544311610c805743610c84565b6007545b6003555050565b6000610ce0826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610d609092919063ffffffff16565b9050805160001480610d01575080806020019051810190610d019190611001565b610a9e5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016102e0565b6060610d6f8484600085610d77565b949350505050565b606082471015610dd85760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016102e0565b600080866001600160a01b03168587604051610df49190611047565b60006040518083038185875af1925050503d8060008114610e31576040519150601f19603f3d011682016040523d82523d6000602084013e610e36565b606091505b5091509150610e4787838387610e52565b979650505050505050565b60608315610ec1578251600003610eba576001600160a01b0385163b610eba5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102e0565b5081610d6f565b610d6f8383815115610ed65781518083602001fd5b8060405162461bcd60e51b81526004016102e09190611063565b600060208284031215610f0257600080fd5b81356001600160a01b0381168114610f1957600080fd5b9392505050565b600060208284031215610f3257600080fd5b5035919050565b60008060408385031215610f4c57600080fd5b50508035926020909101359150565b60208082526011908201527014dd185ada5b99c81a5cc81c185d5cd959607a1b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b80820180821115610faf57610faf610f86565b92915050565b81810381811115610faf57610faf610f86565b8082028115828204841417610faf57610faf610f86565b600082610ffc57634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561101357600080fd5b81518015158114610f1957600080fd5b60005b8381101561103e578181015183820152602001611026565b50506000910152565b60008251611059818460208701611023565b9190910192915050565b6020815260008251806020840152611082816040850160208701611023565b601f01601f1916919091016040019291505056fea2646970667358221220de59362dd0493d85d17901d83b57f1cbf452eab38649a4740fc113c73237701864736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: paris Optimization: Yes (200 runs)
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../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.
 *
 * 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. 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 {
        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);
    }
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount) external returns (bool);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
StakingManagerV1.sol 258 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract StakingManagerV1 is Ownable {
    using SafeERC20 for IERC20;

    IERC20 private constant USDC =
        IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
    IERC20 private constant stakeToken =
        IERC20(0x25B4f5D4C314bCD5d7962734936C957B947cb7CF);

    uint256 public tokensStaked;
    uint256 public harvestedRewards;

    uint256 private lastRewardedBlock;
    uint256 private accumulatedRewardsPerShare;
    uint256 public rewardTokensPerBlock;

    uint256 private constant REWARDS_PRECISION = 1e24;

    uint256 public lockTime;
    uint256 public endBlock;

    struct PoolStaker {
        uint256 amount;
        uint256 stakedTime;
        uint256 lastUpdatedBlock;
        uint256 harvestedRewards;
        uint256 rewardDebt;
    }

    mapping(address => PoolStaker) public poolStakers;

    bool public paused;

    event Deposit(address indexed user, uint256 amount);
    event Withdraw(address indexed user, uint256 amount);
    event HarvestRewards(address indexed user, uint256 amount);
    event Paused(address account);
    event Unpaused(address account);

    /**
     * @dev Constructor
     * @param _rewardTokensPerBlock The number of reward tokens per block
     * @param _lockTime The lock time in seconds
     * @param _endBlock The block number when the staking ends
     */
    constructor(
        uint256 _rewardTokensPerBlock,
        uint256 _lockTime,
        uint256 _endBlock
    ) {
        rewardTokensPerBlock = _rewardTokensPerBlock;
        lockTime = _lockTime;
        endBlock = _endBlock;
    }

    /**
     * @dev This modifier is used to prevent certain functions from being called when the contract is paused
     */
    modifier whenNotPaused() {
        require(!paused, "Staking is paused");
        _;
    }

    /**
     * @dev This modifier is used to allow certain functions to be called only when the contract is paused
     */
    modifier whenPaused() {
        require(paused, "Staking is not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     */
    function pause() external whenNotPaused {
        paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     */
    function unpause() external whenPaused {
        paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * @dev Deposit tokens to the pool
     * @param _amount The amount of tokens to deposit
     */
    function deposit(uint256 _amount) external whenNotPaused {
        require(block.number < endBlock, "Staking has ended");
        require(_amount > 0, "Deposit amount can't be zero");

        PoolStaker storage staker = poolStakers[msg.sender];

        // Update pool stakers
        harvestRewards();

        // Update current staker
        staker.amount += _amount;
        staker.rewardDebt =
            (staker.amount * accumulatedRewardsPerShare) /
            REWARDS_PRECISION;
        if (staker.stakedTime == 0) {
            staker.stakedTime = block.timestamp;
        }
        staker.lastUpdatedBlock = block.number;

        // Update pool
        tokensStaked += _amount;

        // Deposit tokens
        emit Deposit(msg.sender, _amount);
        stakeToken.safeTransferFrom(msg.sender, address(this), _amount);
    }

    /**
     * @dev Withdraw all tokens from existing pool
     */
    function withdraw() external whenNotPaused {
        PoolStaker memory staker = poolStakers[msg.sender];
        uint256 amount = staker.amount;
        require(
            block.number >= endBlock ||
                staker.stakedTime + lockTime <= block.timestamp,
            "You are not allowed to withdraw before locked time"
        );
        require(amount > 0, "Withdraw amount can't be zero");

        // Pay rewards
        harvestRewards();

        // Delete staker
        delete poolStakers[msg.sender];

        // Update pool
        tokensStaked -= amount;

        // Withdraw tokens
        emit Withdraw(msg.sender, amount);
        stakeToken.safeTransfer(msg.sender, amount);
    }

    /**
     * @dev Harvest user rewards
     */
    function harvestRewards() public whenNotPaused {
        _harvestRewards(msg.sender);
    }

    /**
     * @dev Harvest user rewards
     * @param _user The address of the user
     */
    function _harvestRewards(address _user) private {
        updatePoolRewards();
        PoolStaker storage staker = poolStakers[_user];
        uint256 rewardsToHarvest = ((staker.amount *
            accumulatedRewardsPerShare) / REWARDS_PRECISION) -
            staker.rewardDebt;
        if (rewardsToHarvest == 0) {
            return;
        }

        harvestedRewards += rewardsToHarvest;
        staker.harvestedRewards += rewardsToHarvest;
        staker.rewardDebt =
            (staker.amount * accumulatedRewardsPerShare) /
            REWARDS_PRECISION;
        emit HarvestRewards(_user, rewardsToHarvest);
        USDC.safeTransfer(_user, rewardsToHarvest);
    }

    /**
     * @dev Update pool's accumulatedRewardsPerShare and lastRewardedBlock
     */
    function updatePoolRewards() private {
        if (tokensStaked == 0) {
            lastRewardedBlock = block.number;
            return;
        }
        uint256 blocksSinceLastReward = block.number > endBlock
            ? endBlock - lastRewardedBlock
            : block.number - lastRewardedBlock;
        uint256 rewards = blocksSinceLastReward * rewardTokensPerBlock;
        accumulatedRewardsPerShare =
            accumulatedRewardsPerShare +
            ((rewards * REWARDS_PRECISION) / tokensStaked);
        lastRewardedBlock = block.number > endBlock ? endBlock : block.number;
    }

    /**
     * @dev To get the number of rewards that user can get
     * @param _user The address of the user
     */
    function getRewards(address _user) public view returns (uint256) {
        if (tokensStaked == 0) {
            return 0;
        }
        uint256 blocksSinceLastReward = block.number > endBlock
            ? endBlock - lastRewardedBlock
            : block.number - lastRewardedBlock;
        uint256 rewards = blocksSinceLastReward * rewardTokensPerBlock;
        uint256 accCalc = accumulatedRewardsPerShare +
            ((rewards * REWARDS_PRECISION) / tokensStaked);
        PoolStaker memory staker = poolStakers[_user];
        return
            ((staker.amount * accCalc) / REWARDS_PRECISION) - staker.rewardDebt;
    }

    /**
     * @dev To set the lock time
     * @param _lockTime The lock time in seconds
     */
    function setLockTime(uint256 _lockTime) public onlyOwner {
        lockTime = _lockTime;
    }

    /**
     * @dev To set the end block
     * @param _endBlock The block number when the staking ends
     */
    function setEndBlock(uint256 _endBlock) public onlyOwner {
        endBlock = _endBlock;
    }

    /**
     * @dev To set the number of reward tokens per block
     * @param _rewardTokensPerBlock The number of reward tokens per block
     */
    function setRewardsPerBlock(
        uint256 _rewardTokensPerBlock
    ) public onlyOwner {
        rewardTokensPerBlock = _rewardTokensPerBlock;
    }

    /**
     * @dev To withdraw tokens from the contract
     * @param _amountStakeToken The amount of stake token to withdraw
     * @param _amountUSDC The amount of USDC to withdraw
     */
    function withdrawTokens(
        uint256 _amountStakeToken,
        uint256 _amountUSDC
    ) public onlyOwner {
        if (_amountStakeToken > 0)
            stakeToken.safeTransfer(msg.sender, _amountStakeToken);
        if (_amountUSDC > 0) USDC.safeTransfer(msg.sender, _amountUSDC);
    }
}

Read Contract

endBlock 0x083c6323 → uint256
getRewards 0x79ee54f7 → uint256
harvestedRewards 0x3eecea51 → uint256
lockTime 0x0d668087 → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
poolStakers 0xcddb3e7b → uint256, uint256, uint256, uint256, uint256
rewardTokensPerBlock 0x29d0fa3e → uint256
tokensStaked 0x99a03316 → uint256

Write Contract 11 functions

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

deposit 0xb6b55f25
uint256 _amount
harvestRewards 0x2be11ae2
No parameters
pause 0x8456cb59
No parameters
renounceOwnership 0x715018a6
No parameters
setEndBlock 0xc713aa94
uint256 _endBlock
setLockTime 0xae04d45d
uint256 _lockTime
setRewardsPerBlock 0xa1003b29
uint256 _rewardTokensPerBlock
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
withdraw 0x3ccfd60b
No parameters
withdrawTokens 0xba7bd2aa
uint256 _amountStakeToken
uint256 _amountUSDC

Recent Transactions

No transactions found for this address