Skip to content
Verified contractExactUNLICENSED

BlinkSolver

Address0x60331ba0c6aed38041aff15e4ccf034fc7c10fd9
Balance

0 ETH

 

Transactions

201

 

Compiler

solc 0.8.24

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 800 runs
EVM version
cancun
Via IR
yes
License
UNLICENSED
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,371,583
Creation transaction
0x70794a21a0…0e51a4bcd7

src/BlinkSolver.sol

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

interface IERC20 {
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    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 IBlinkEscrow {
    function release(address token, uint256 amount) external;
}

address constant NATIVE = address(0);

contract BlinkSolver {
    address public owner;
    address public pendingOwner;
    address public pauser;
    IBlinkEscrow public escrow;
    address public feeManager;
    bool public paused;
    bool private entered;

    mapping(address => bool) public executors;

    event Fulfilled(
        bytes32 indexed quoteHash, address indexed recipient, address dstToken, uint256 amountOut, uint256 gasDrop
    );
    event ExecutorSet(address indexed executor, bool allowed);
    event EscrowSet(address indexed escrow);
    event FeeManagerSet(address indexed feeManager);
    event PauserSet(address indexed pauser);
    event Paused(address indexed account);
    event Unpaused(address indexed account);
    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    error TransferFailed();
    error NativeForwardFailed();
    error Unauthorized();
    error GasDropNotAllowed();
    error NotOwner();
    error NotPauser();
    error EnforcedPause();
    error Reentrancy();
    error InsufficientOutput();
    error EscrowAlreadySet();
    error VoucherShareExceedsRelease();

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

    modifier onlyPauser() {
        if (msg.sender != pauser) revert NotPauser();
        _;
    }

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

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

    modifier nonReentrant() {
        if (entered) revert Reentrancy();
        entered = true;
        _;
        entered = false;
    }

    constructor(address _owner) {
        owner = _owner;
    }

    receive() external payable {}

    function setPauser(address _pauser) external onlyOwner {
        pauser = _pauser;
        emit PauserSet(_pauser);
    }

    function pause() external onlyPauser {
        paused = true;
        emit Paused(msg.sender);
    }

    function unpause() external onlyOwner {
        paused = false;
        emit Unpaused(msg.sender);
    }

    function transferOwnership(address newOwner) external onlyOwner {
        pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner, newOwner);
    }

    function acceptOwnership() external {
        if (msg.sender != pendingOwner) revert NotOwner();
        emit OwnershipTransferred(owner, msg.sender);
        owner = msg.sender;
        pendingOwner = address(0);
    }

    function setEscrow(address _escrow) external onlyOwner {
        if (address(escrow) != address(0)) revert EscrowAlreadySet();
        escrow = IBlinkEscrow(_escrow);
        emit EscrowSet(_escrow);
    }

    function setFeeManager(address _feeManager) external onlyOwner {
        feeManager = _feeManager;
        emit FeeManagerSet(_feeManager);
    }

    function setExecutor(address executor, bool allowed) external onlyOwner {
        executors[executor] = allowed;
        emit ExecutorSet(executor, allowed);
    }

    function withdraw(address token, address to, uint256 amount) external onlyOwner nonReentrant {
        if (token == NATIVE) {
            _sendNative(to, amount);
        } else {
            _safeTransfer(token, to, amount);
        }
    }

    function pullFromEscrow(address token, uint256 amount, uint256 voucherAmount)
        external
        onlyExecutor
        nonReentrant
        whenNotPaused
    {
        if (voucherAmount > amount) revert VoucherShareExceedsRelease();
        escrow.release(token, amount);
        if (voucherAmount == 0) {
            return;
        }
        if (token == NATIVE) {
            _sendNative(feeManager, voucherAmount);
        } else {
            _safeTransfer(token, feeManager, voucherAmount);
        }
    }

    function fulfillToken(
        bytes32 quoteHash,
        address token,
        address recipient,
        uint256 amount,
        uint256 minAmountOut,
        uint256 gasDrop
    ) external onlyExecutor nonReentrant whenNotPaused {
        if (token == NATIVE) {
            if (gasDrop != 0) revert GasDropNotAllowed();
            if (amount < minAmountOut) revert InsufficientOutput();
            _sendNative(recipient, amount);
            emit Fulfilled(quoteHash, recipient, NATIVE, amount, 0);
            return;
        }
        uint256 balanceBefore = IERC20(token).balanceOf(recipient);
        _safeTransfer(token, recipient, amount);
        uint256 delivered = IERC20(token).balanceOf(recipient) - balanceBefore;
        if (delivered < minAmountOut) revert InsufficientOutput();
        if (gasDrop != 0) {
            _sendNative(recipient, gasDrop);
        }
        emit Fulfilled(quoteHash, recipient, token, delivered, gasDrop);
    }

    function payToken(address token, address recipient, uint256 amount)
        external
        onlyExecutor
        nonReentrant
        whenNotPaused
    {
        if (token == NATIVE) {
            _sendNative(recipient, amount);
            return;
        }
        _safeTransfer(token, recipient, amount);
    }

    function _sendNative(address to, uint256 amount) internal {
        (bool ok,) = to.call{value: amount}("");
        if (!ok) revert NativeForwardFailed();
    }

    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();
    }
}
Compiler settingsShow
{
  "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/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.