Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xBA75798CFEaeF055449084c81Ce9Aa8bb39869c0
Balance 0 ETH
Nonce 1
Code Size 4074 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

4074 bytes
0x608060405234801561000f575f80fd5b50600436106100fb575f3560e01c8063715018a611610093578063bbe4fd5011610063578063bbe4fd501461021e578063bc8bcdce1461022e578063d953a86714610243578063f2fde38b1461024c575f80fd5b8063715018a6146101d55780638456cb59146101dd5780638da5cb5b146101e5578063964614bb146101fa575f80fd5b80635c975abb116100ce5780635c975abb146101425780635d3eea911461015c5780635fbe4d1d1461016f57806364e5e2231461019a575f80fd5b806310087fb1146100ff5780632e1a7d4d146101145780633f4ba83a146101275780634eb665af1461012f575b5f80fd5b61011261010d366004610d58565b61025f565b005b610112610122366004610d82565b610426565b6101126105d0565b61011261013d366004610d82565b6105e2565b5f5460ff1660405190151581526020015b60405180910390f35b61011261016a366004610d82565b610625565b600154610182906001600160a01b031681565b6040516001600160a01b039091168152602001610153565b6101c06101a8366004610d99565b60026020525f90815260409020805460019091015482565b60408051928352602083019190915201610153565b6101126107eb565b6101126107fc565b5f5461010090046001600160a01b0316610182565b61020d610208366004610dc8565b61080c565b604051610153959493929190610e24565b425b604051908152602001610153565b61023661085a565b6040516101539190610e59565b61022060045481565b61011261025a366004610ed3565b61092a565b610267610967565b3361028d5760405162461bcd60e51b815260040161028490610eec565b60405180910390fd5b670de0b6b3a76400008210156102e55760405162461bcd60e51b815260206004820152601d60248201527f43616e2774207374616b65206c657373207468616e203120746f6b656e0000006044820152606401610284565b6001546102fd906001600160a01b03163330856109ac565b5f6040518060a001604052808481526020014281526020015f815260200183600381111561032d5761032d610df0565b815260016020918201819052335f9081526003808452604080832080548086018255908452928590208651600490940201928355938501518284015592840151600282015560608401518184018054959650869592949193909260ff191691849081111561039d5761039d610df0565b0217905550608091909101516003918201805460ff9092166101000261ff00199092169190911790558151335f8181526020939093526040909220547f1449c6dd7851abc30abf37f57715f492010519147cc2652fbc38202c18a6ee90919061040890600190610f2f565b604080519283526020830191909152015b60405180910390a2505050565b336104435760405162461bcd60e51b815260040161028490610eec565b335f90815260036020526040812080548390811061046357610463610f42565b905f5260205f20906004020190505f816002015411801561048f5750600381810154610100900460ff16145b6104ef5760405162461bcd60e51b815260206004820152602b60248201527f77697468647261773a5468697320756e7374616b652068616420616c7265616460448201526a3c903bb4ba34323930bb9760a91b6064820152608401610284565b4260045482600201546105029190610f56565b11156105625760405162461bcd60e51b815260206004820152602960248201527f77697468647261773a5468697320756e7374616b6520706572696f64206e6f74604482015268081bdd995c881e595d60ba1b6064820152608401610284565b805460015461057e916001600160a01b03909116903390610a19565b60038101805461ff0019166105001790558054604080519182526020820184905233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a25050565b6105d8610a4f565b6105e0610a81565b565b6105ea610a4f565b60048190556040518181527f3e062f634a950eae456fa5f8fb53a4f59f55039983bd73df7a34a313b75443d49060200160405180910390a150565b336106425760405162461bcd60e51b815260040161028490610eec565b335f90815260036020526040812080548390811061066257610662610f42565b5f91825260208220600360049092020181810154909350600291839160ff169081111561069157610691610df0565b60038111156106a2576106a2610df0565b81526020019081526020015f205f015482600101546106c19190610f56565b90504281111561071f5760405162461bcd60e51b8152602060048201526024808201527f756e5374616b653a207374616b652074696d65206973206e6f742074696d65206044820152637965742160e01b6064820152608401610284565b600282015415801561073e5750600382015460ff610100909104166001145b61079a5760405162461bcd60e51b815260206004820152602760248201527f756e5374616b653a54686973207374616b652068616420616c726561647920756044820152663739ba30b5b29760c91b6064820152608401610284565b60038201805461ff0019166103001790554260028301558154604080519182526020820185905233917ff26c0304cc83daf500e1dc22ab2e3cf954b3d506d62e34d70cc054255079e3979101610419565b6107f3610a4f565b6105e05f610ad2565b610804610a4f565b6105e0610b2a565b6003602052815f5260405f208181548110610825575f80fd5b5f9182526020909120600490910201805460018201546002830154600390930154919450925060ff8082169161010090041685565b335f908152600360209081526040808320805482518185028101850190935280835260609492939192909184015b82821015610921578382905f5260205f2090600402016040518060a00160405290815f82015481526020016001820154815260200160028201548152602001600382015f9054906101000a900460ff1660038111156108e9576108e9610df0565b60038111156108fa576108fa610df0565b815260039190910154610100900460ff166020918201529082526001929092019101610888565b50505050905090565b610932610a4f565b6001600160a01b03811661095b57604051631e4fbdf760e01b81525f6004820152602401610284565b61096481610ad2565b50565b5f5460ff16156105e05760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610284565b6040516001600160a01b038481166024830152838116604483015260648201839052610a139186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050610b66565b50505050565b6040516001600160a01b03838116602483015260448201839052610a4a91859182169063a9059cbb906064016109e1565b505050565b5f546001600160a01b036101009091041633146105e05760405163118cdaa760e01b8152336004820152602401610284565b610a89610bc7565b5f805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b5f80546001600160a01b03838116610100818102610100600160a81b0319851617855560405193049190911692909183917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a35050565b610b32610967565b5f805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610ab53390565b5f610b7a6001600160a01b03841683610c0f565b905080515f14158015610b9e575080806020019051810190610b9c9190610f69565b155b15610a4a57604051635274afe760e01b81526001600160a01b0384166004820152602401610284565b5f5460ff166105e05760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610284565b6060610c1c83835f610c25565b90505b92915050565b606081471015610c4a5760405163cd78605960e01b8152306004820152602401610284565b5f80856001600160a01b03168486604051610c659190610f88565b5f6040518083038185875af1925050503d805f8114610c9f576040519150601f19603f3d011682016040523d82523d5f602084013e610ca4565b606091505b5091509150610cb4868383610cc0565b925050505b9392505050565b606082610cd557610cd082610d1c565b610cb9565b8151158015610cec57506001600160a01b0384163b155b15610d1557604051639996b31560e01b81526001600160a01b0385166004820152602401610284565b5080610cb9565b805115610d2c5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b803560048110610d53575f80fd5b919050565b5f8060408385031215610d69575f80fd5b82359150610d7960208401610d45565b90509250929050565b5f60208284031215610d92575f80fd5b5035919050565b5f60208284031215610da9575f80fd5b610c1c82610d45565b80356001600160a01b0381168114610d53575f80fd5b5f8060408385031215610dd9575f80fd5b610de283610db2565b946020939093013593505050565b634e487b7160e01b5f52602160045260245ffd5b60048110610e2057634e487b7160e01b5f52602160045260245ffd5b9052565b858152602081018590526040810184905260a08101610e466060830185610e04565b60ff831660808301529695505050505050565b602080825282518282018190525f919060409081850190868401855b82811015610ec65781518051855286810151878601528581015186860152606080820151610ea582880182610e04565b505060809081015160ff169085015260a09093019290850190600101610e75565b5091979650505050505050565b5f60208284031215610ee3575f80fd5b610c1c82610db2565b6020808252601590820152741059191c995cdcc81e995c9bc819195d1958dd1959605a1b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610c1f57610c1f610f1b565b634e487b7160e01b5f52603260045260245ffd5b80820180821115610c1f57610c1f610f1b565b5f60208284031215610f79575f80fd5b81518015158114610cb9575f80fd5b5f82515f5b81811015610fa75760208186018101518583015201610f8d565b505f92019182525091905056fea264697066735822122021cac37174b663dae46b47795e3f6ccd6b425305d377b2dd23875066cefe81a464736f6c63430008160033

Verified Source Code Partial Match

Compiler: v0.8.22+commit.4fc1097e EVM: shanghai Optimization: Yes (200 runs)
DmailStaking.sol 813 lines
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol


// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol


// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

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

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


// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

// File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol


// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;




/**
 * @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 An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, 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);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @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.encodeCall(token.approve, (spender, value));

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

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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(token).code.length > 0;
    }
}

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


// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

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


// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;


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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: @openzeppelin/contracts/security/Pausable.sol


// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;


/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

// File: contracts/DmailStake.sol

pragma solidity ^0.8.22;





contract DmailStaking is Pausable, Ownable {

    using SafeERC20 for IERC20;

    event LockDurationUpdated(uint256 _timePeriodInSeconds);
    event Staked(address indexed staker,  uint256  amount,  uint256 index);
    event UnStaked(address indexed staker,  uint256  amount,  uint256 index);
    event Withdrawn(address indexed staker, uint256  amount,  uint256 index);

     struct StakeInfo{
        uint256 index;
        PoolType poolType;
    }

    struct Pool {
        uint256 duration;
        uint256 multiplier;
    }

    struct Staker {
        uint256 stakeAmount;
        uint256 stakeStartTime;
        uint256 unstakeTime;
        PoolType poolType;
        uint8 stakeRecordStatus;
    }
    address public tokenAddr;
    
    mapping(PoolType => Pool) public poolKV;
    mapping(address => Staker[]) public stakerKV;

    enum PoolType {Flex,D7,D30,D90}
    uint256 public lockTimePeriod = 3 days;
    constructor(address _Address) Ownable(msg.sender)  {
        tokenAddr = _Address;
        poolKV[PoolType.Flex] = Pool(0, 80);
        poolKV[PoolType.D7] = Pool(7 days,240);
        poolKV[PoolType.D30] = Pool(30 days,800);
        poolKV[PoolType.D90] = Pool(90 days,1200);
    }


    /* ============ Method ============ */
    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function setLockDuration(uint256 _timePeriodInSeconds) public onlyOwner  {
        lockTimePeriod = _timePeriodInSeconds;
        emit LockDurationUpdated(_timePeriodInSeconds);
    }
    
    function getStakeByAddress() public view returns (Staker[] memory)   {
        return stakerKV[msg.sender];
    }

    function getNow () public view returns (uint256) {
        return block.timestamp;
    }
    
    function stake(uint256 _amount,PoolType poolType) public whenNotPaused {
        require(msg.sender != address(0), "Address zero detected");
        require(_amount >= 1 * 1e18, "Can't stake less than 1 token");
        
        // status 
        IERC20(tokenAddr).safeTransferFrom(msg.sender, address(this), _amount);
        Staker memory staker = Staker({
            stakeAmount: _amount,
            stakeStartTime: block.timestamp,
            poolType: poolType,
            unstakeTime:0,
            stakeRecordStatus:1
        });
        stakerKV[msg.sender].push(staker);
     
        emit Staked(msg.sender,staker.stakeAmount, stakerKV[msg.sender].length - 1);
    }


    function unStake(uint256 index) public  {
        require(msg.sender != address(0), "Address zero detected");
        Staker storage staker =  stakerKV[msg.sender][index];
        uint256 stakeTime = staker.stakeStartTime + poolKV[staker.poolType].duration;
        require(stakeTime <= block.timestamp, "unStake: stake time is not time yet!");
        require(staker.unstakeTime == 0 && staker.stakeRecordStatus == 1, "unStake:This stake had already unstake.");

        // status
        staker.stakeRecordStatus = 3;
        staker.unstakeTime = block.timestamp;
        emit UnStaked(msg.sender, staker.stakeAmount, index);
    }

    function withdraw(uint256 index) public  {
        require(msg.sender != address(0), "Address zero detected");
        Staker storage staker =  stakerKV[msg.sender][index];
        require(staker.unstakeTime > 0  && staker.stakeRecordStatus == 3, "withdraw:This unstake had already withdraw.");
        require(staker.unstakeTime + lockTimePeriod <= block.timestamp, "withdraw:This unstake period not over yet");

        // status
        IERC20(tokenAddr).safeTransfer(msg.sender, staker.stakeAmount);
        staker.stakeRecordStatus = 5;
        emit Withdrawn(msg.sender, staker.stakeAmount, index);
    }
}

Read Contract

getNow 0xbbe4fd50 → uint256
getStakeByAddress 0xbc8bcdce → tuple[]
lockTimePeriod 0xd953a867 → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
poolKV 0x64e5e223 → uint256, uint256
stakerKV 0x964614bb → uint256, uint256, uint256, uint8, uint8
tokenAddr 0x5fbe4d1d → address

Write Contract 8 functions

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

pause 0x8456cb59
No parameters
renounceOwnership 0x715018a6
No parameters
setLockDuration 0x4eb665af
uint256 _timePeriodInSeconds
stake 0x10087fb1
uint256 _amount
uint8 poolType
transferOwnership 0xf2fde38b
address newOwner
unStake 0x5d3eea91
uint256 index
unpause 0x3f4ba83a
No parameters
withdraw 0x2e1a7d4d
uint256 index

Recent Transactions

No transactions found for this address