Skip to content
Verified contractExactMIT

EthVault

Address0x09efb3b9f5c088907698d36d190852e9a82d30b3
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
No
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,448,492
Creation transaction
0x8342f10523…f982931790

src/EthVault.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IPriceFeed {
    function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80);
}

/// @notice Time/price-locked ETH vault. Unlocks when the FIRST of these happens:
///         1) Chainlink ETH/USD >= $4000
///         2) Oracle is dead (not updated for 7 days, or reverts)
///         3) 90 days have passed since deployment
///         Funds can ONLY ever be sent to `owner`. `operator` may trigger the withdrawal but cannot redirect funds.
contract EthVault {
    IPriceFeed public constant PRICE_FEED = IPriceFeed(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); // Chainlink ETH/USD
    int256  public constant TARGET_PRICE  = 4000e8;  // $4000 (8 decimals)
    uint256 public constant STALE_AFTER   = 7 days;
    uint256 public constant LOCK_DURATION = 90 days;

    address public immutable owner;    // the only recipient of funds
    address public immutable operator; // may trigger withdraw, funds still go to owner
    uint256 public immutable unlockTime;

    event Deposited(address indexed from, uint256 amount);
    event Withdrawn(address indexed by, uint256 amount);

    constructor(address _owner, address _operator) payable {
        require(_owner != address(0), "zero owner");
        owner = _owner;
        operator = _operator;
        unlockTime = block.timestamp + LOCK_DURATION;
    }

    receive() external payable {
        emit Deposited(msg.sender, msg.value);
    }

    function isUnlocked() public view returns (bool) {
        if (block.timestamp >= unlockTime) return true;
        try PRICE_FEED.latestRoundData() returns (uint80, int256 price, uint256, uint256 updatedAt, uint80) {
            if (block.timestamp - updatedAt > STALE_AFTER) return true; // oracle dead
            return price >= TARGET_PRICE;
        } catch {
            return true; // oracle reverts -> dead
        }
    }

    /// @notice Sends the entire balance to `owner`.
    function withdraw() external {
        require(msg.sender == owner || msg.sender == operator, "not authorized");
        require(isUnlocked(), "locked");
        uint256 amount = address(this).balance;
        (bool ok,) = payable(owner).call{value: amount}("");
        require(ok, "transfer failed");
        emit Withdrawn(msg.sender, amount);
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.