Проверенный контрактТочноеMIT
EthVault
Адрес0x09efb3b9f5c088907698d36d190852e9a82d30b3
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.26
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.26+commit.8a97fa7a
- Язык
- solidity
- Оптимизация
- Нет
- Версия EVM
- cancun
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 448 492
- Транзакция создания
- 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);
}
}
Настройки компилятораПоказать
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.