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

BlinkBridger

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

0 ETH

 

Транзакций

13

 

Компилятор

solc 0.8.24

 

Тот же код

Только этот контракт

 

Подробности

Компилятор
solc 0.8.24+commit.e11b9ed9
Язык
solidity
Оптимизация
Да, 800 прогонов
Версия EVM
cancun
Через IR
да
Лицензия
UNLICENSED
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 371 583
Транзакция создания
0x8dd306843e…c5213b6a3f

src/BlinkBridger.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool);
    function approve(address spender, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

interface IBlinkInventory {
    function payToken(address token, address recipient, uint256 amount) external;
    function owner() external view returns (address);
    function paused() external view returns (bool);
}

address constant NATIVE = address(0);

contract BlinkBridger {
    IBlinkInventory public immutable inventory;

    mapping(address => bool) public callers;
    mapping(address => bool) public targets;

    event CallerSet(address indexed caller, bool allowed);
    event TargetSet(address indexed target, bool allowed);
    event BridgedOut(address indexed target, address indexed token, uint256 amount, uint256 nativeValue);

    error NotOwner();
    error Unauthorized();
    error ApproveFailed();
    error TransferFailed();
    error BridgeCallFailed();
    error EnforcedPause();

    modifier onlyOwner() {
        if (msg.sender != inventory.owner()) revert NotOwner();
        _;
    }

    modifier onlyCaller() {
        if (!callers[msg.sender]) revert Unauthorized();
        _;
    }

    modifier whenNotPaused() {
        if (inventory.paused()) revert EnforcedPause();
        _;
    }

    constructor(address _inventory) {
        inventory = IBlinkInventory(_inventory);
    }

    receive() external payable {}

    function setCaller(address caller, bool allowed) external onlyOwner {
        callers[caller] = allowed;
        emit CallerSet(caller, allowed);
    }

    function setTarget(address target, bool allowed) external onlyOwner {
        targets[target] = allowed;
        emit TargetSet(target, allowed);
    }

    function bridgeOut(address target, address token, uint256 amount, uint256 nativeValue, bytes calldata data)
        external
        onlyCaller
        whenNotPaused
    {
        if (!targets[target]) revert Unauthorized();

        inventory.payToken(token, address(this), amount);
        if (nativeValue != 0) {
            inventory.payToken(NATIVE, address(this), nativeValue);
        }

        _safeApprove(token, target, amount);
        (bool ok,) = target.call{value: nativeValue}(data);
        if (!ok) revert BridgeCallFailed();
        _safeApprove(token, target, 0);

        emit BridgedOut(target, token, amount, nativeValue);
    }

    function withdraw(address token, address to, uint256 amount) external onlyOwner {
        if (token == NATIVE) {
            (bool ok,) = to.call{value: amount}("");
            if (!ok) revert TransferFailed();
            return;
        }
        _safeTransfer(token, to, amount);
    }

    function _safeTransfer(address token, address to, uint256 amount) internal {
        if (token.code.length == 0) revert TransferFailed();
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, amount));
        if (!success) revert TransferFailed();
        if (data.length != 0 && !abi.decode(data, (bool))) revert TransferFailed();
    }

    function _safeApprove(address token, address spender, uint256 amount) internal {
        if (token.code.length == 0) revert ApproveFailed();
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, spender, amount));
        if (!success) revert ApproveFailed();
        if (data.length != 0 && !abi.decode(data, (bool))) revert ApproveFailed();
    }
}
Настройки компилятораПоказать
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 800,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Исходный код и метаданные: Sourcify.

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