Timelock

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/Timelock.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/// @title TimeLock
/// @notice A timelock contract that allows the owner to deposit and lock ETH for a specified period
/// @dev The owner can deposit funds, extend the lock period, and withdraw after the unlock time
///

contract Timelock {
    address public immutable OWNER;
    uint256 public unlockTime;

    bool private _entered;
        
    uint256 public constant MAX_INITIAL_LOCK = 100 days;    
    
    event Deposited(address indexed from, uint256 amount, uint256 unlockTime);
    event Withdrawn(address indexed to, uint256 amount);
    
    modifier onlyOwner() {
        _onlyOwner();
        _;
    }
    function _onlyOwner() internal view {
        require(msg.sender == OWNER, "not owner");
    }

    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() internal {
        require(!_entered, "reentrant");
        _entered = true;
    }
    
    function _nonReentrantAfter() internal {
        _entered = false;
    }

    /// @param lockDays Number of days to lock funds initially (≤ 300)
    constructor(uint256 lockDays) {
        require(lockDays > 0, "must lock > 0 days");
        require(lockDays <= MAX_INITIAL_LOCK, "max days");

        OWNER = msg.sender;        
        unlockTime = block.timestamp + (lockDays * 1 days);
    }

    function depositEth() external payable onlyOwner {
        require(msg.value > 0, "zero value");
        emit Deposited(msg.sender, msg.value, unlockTime);
    }

    function withdrawEth() external onlyOwner nonReentrant {
        require(block.timestamp >= unlockTime, "still locked");

        uint256 amt = address(this).balance;
        require(amt > 0, "nothing to withdraw");

        (bool ok, ) = OWNER.call{value: amt}("");
        require(ok, "transfer failed");
        emit Withdrawn(OWNER, amt);
    }

    receive() external payable {
        revert("use depositEth()");
    }

    fallback() external payable {
        revert("invalid");
    }
}
"
    }
  },
  "settings": {
    "remappings": [
      "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
      "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
      "forge-std/=lib/forge-std/src/",
      "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
      "openzeppelin-contracts/=lib/openzeppelin-contracts/"
    ],
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "ipfs",
      "appendCBOR": true
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "prague",
    "viaIR": false
  }
}}

Tags:
Factory|addr:0x7b33a100417aaf44adbd7c8aed5dc8f0fde3b3e0|verified:true|block:23676172|tx:0x201be1e456b10abfd6d5d8aa6e63f4f7537d54a3cd7f6ec6e3b2aa001abbf4d2|first_check:1761661172

Submitted on: 2025-10-28 15:19:34

Comments

Log in to comment.

No comments yet.