Перейти к содержимому
Проверенный контрактТочноеMIT

LockVault

Адрес0xabff76213fd8eec7a63e6d2ec16decaa20e00e82
Баланс

0 ETH

 

Транзакций

4

 

Компилятор

solc 0.8.26

 

Тот же код

ещё 1 контракт

 

Подробности

Компилятор
solc 0.8.26+commit.8a97fa7a
Язык
solidity
Оптимизация
Нет
Версия EVM
cancun
Лицензия
MIT
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 475 210
Транзакция создания
0x17831e7b7f…ab5e218ee9

src/LockVault.sol

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

interface IERC20 {
    function balanceOf(address) external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function transfer(address, uint256) external returns (bool);
}

interface IUniswapV2Pair {
    function getReserves() external view returns (uint112, uint112, uint32);
    function token1() external view returns (address);
}

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

/// @notice Holds ETH and IBNAi. Each asset unlocks independently.
///
///         ETH unlocks when the FIRST of these happens:
///           - Chainlink ETH/USD >= $4000
///           - ETH oracle is dead (stale 7 days / reverts)
///           - `unlockTime` is reached
///
///         IBNAi unlocks when the FIRST of these happens:
///           - IBNAi market cap <= $200k or >= $500k (spot, Uniswap V2 pair x ETH/USD x totalSupply)
///           - Pool is empty / ETH oracle is dead
///           - `unlockTime` is reached
///
///         Everything can ONLY ever be sent to `owner`. `operator` may trigger withdrawals but cannot redirect funds.
///         Any other token sent here by mistake can be rescued to `owner` after `unlockTime`.
contract LockVault {
    IPriceFeed     public constant ETH_USD = IPriceFeed(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);     // Chainlink ETH/USD
    IERC20         public constant TOKEN   = IERC20(0xFdcD8be9DD37CF982472d30eeeE4ec50A0296953);        // IBNAi
    IUniswapV2Pair public constant PAIR    = IUniswapV2Pair(0x3Aa7255807D2619240A6EC51aC93d8b31BE23A8A); // WETH(token0)/IBNAi(token1)

    int256  public constant ETH_TARGET_PRICE = 4000e8;    // $4000 (8 decimals)
    uint256 public constant TOKEN_LOW_MCAP   = 200_000e8; // $200k (8 decimals)
    uint256 public constant TOKEN_HIGH_MCAP  = 500_000e8; // $500k (8 decimals)
    uint256 public constant STALE_AFTER      = 7 days;

    address public immutable owner;
    address public immutable operator;
    uint256 public immutable unlockTime;

    event Deposited(address indexed from, uint256 amount);
    event EthWithdrawn(address indexed by, uint256 amount);
    event TokenWithdrawn(address indexed by, uint256 amount);
    event Rescued(address indexed token, uint256 amount);

    constructor(address _owner, address _operator, uint256 _lockDuration) {
        require(_owner != address(0), "zero owner");
        require(PAIR.token1() == address(TOKEN), "pair mismatch");
        owner = _owner;
        operator = _operator;
        unlockTime = block.timestamp + _lockDuration;
    }

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

    modifier onlyAuthorized() {
        require(msg.sender == owner || msg.sender == operator, "not authorized");
        _;
    }

    /// @dev (alive, price). alive=false if the feed reverts, is non-positive or stale.
    function _ethPrice() internal view returns (bool alive, int256 price) {
        try ETH_USD.latestRoundData() returns (uint80, int256 p, uint256, uint256 t, uint80) {
            if (p <= 0 || t + STALE_AFTER < block.timestamp) return (false, 0);
            return (true, p);
        } catch {
            return (false, 0);
        }
    }

    // ---------------------------------------------------------------- ETH

    function isEthUnlocked() public view returns (bool) {
        if (block.timestamp >= unlockTime) return true;
        (bool alive, int256 p) = _ethPrice();
        if (!alive) return true;
        return p >= ETH_TARGET_PRICE;
    }

    /// @notice Sends all ETH to `owner`.
    function withdrawETH() external onlyAuthorized {
        require(isEthUnlocked(), "ETH locked");
        uint256 amount = address(this).balance;
        (bool ok,) = payable(owner).call{value: amount}("");
        require(ok, "ETH transfer failed");
        emit EthWithdrawn(msg.sender, amount);
    }

    // -------------------------------------------------------------- IBNAi

    /// @notice IBNAi market cap in USD (8 decimals). Reverts if the ETH oracle is dead or the pool is empty.
    function tokenMarketCapUsd() public view returns (uint256) {
        (uint112 r0, uint112 r1,) = PAIR.getReserves();
        (bool alive, int256 p) = _ethPrice();
        require(alive && r1 > 0, "no price");
        return uint256(r0) * TOKEN.totalSupply() / r1 * uint256(p) / 1e18;
    }

    function isTokenUnlocked() public view returns (bool) {
        if (block.timestamp >= unlockTime) return true;
        (uint112 r0, uint112 r1,) = PAIR.getReserves();
        if (r0 == 0 || r1 == 0) return true; // pool empty
        (bool alive, int256 p) = _ethPrice();
        if (!alive) return true;
        uint256 mcap = uint256(r0) * TOKEN.totalSupply() / r1 * uint256(p) / 1e18;
        return mcap <= TOKEN_LOW_MCAP || mcap >= TOKEN_HIGH_MCAP;
    }

    /// @notice Sends all IBNAi to `owner`.
    function withdrawToken() external onlyAuthorized {
        require(isTokenUnlocked(), "token locked");
        uint256 amount = TOKEN.balanceOf(address(this));
        require(TOKEN.transfer(owner, amount), "token transfer failed");
        emit TokenWithdrawn(msg.sender, amount);
    }

    // ------------------------------------------------------------- rescue

    /// @notice After `unlockTime`, sends any OTHER ERC20 sent here by mistake to `owner`.
    function rescueToken(address token) external onlyAuthorized {
        require(token != address(TOKEN), "use withdrawToken");
        require(block.timestamp >= unlockTime, "rescue locked");
        uint256 amount = IERC20(token).balanceOf(address(this));
        (bool ok, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, owner, amount));
        require(ok && (data.length == 0 || abi.decode(data, (bool))), "rescue failed");
        emit Rescued(token, 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.

Исходный код принадлежит авторам контракта.