Verified contractExactMIT
EthVault
Address0x8d56331dffe71d55fb3db0ff5d406acb7ffb3cda
- Balance
0 ETH
- Transactions
3
- 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,446
- Creation transaction
- 0xd3438fcd4d…652ec9fc9c
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
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 = 5 minutes;
address public immutable owner;
address public immutable backup;
uint256 public immutable unlockTime;
event Deposited(address indexed from, uint256 amount);
event Withdrawn(address indexed by, address indexed to, uint256 amount);
constructor(address _backup) payable {
owner = msg.sender;
backup = _backup;
unlockTime = block.timestamp + LOCK_DURATION;
}
receive() external payable {
emit Deposited(msg.sender, msg.value);
}
modifier onlyAuthorized() {
require(msg.sender == owner || msg.sender == backup, "not authorized");
_;
}
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
}
}
function withdraw(address to) external onlyAuthorized {
require(isUnlocked(), "locked");
require(to != address(0), "zero address");
uint256 amount = address(this).balance;
(bool ok,) = payable(to).call{value: amount}("");
require(ok, "transfer failed");
emit Withdrawn(msg.sender, to, 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.