contract StrategyETH {
    using SafeERC20 for IERC20;
    using Address for address;
    using SafeMath for uint256;

    address constant public unirouter = address(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
    address constant public weth = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
	address constant public bti = address(0x76c5449F4950f6338A393F53CdA8b53B0cd3Ca3a);

    address constant public want = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);  //weth

    address constant public ethpool = address(0x67B66C99D3Eb37Fa76Aa3Ed1ff33E8e39F0b9c7A);

    address public governance;
    address public controller;
    uint256 public redeliverynum = 100 * 1e18;

    uint public withdrawalFee = 0;
    uint constant public withdrawalMax = 10000;

    address[] public swap2BTIRouting;

    constructor() public {
        governance = tx.origin;
        controller = 0x03D2079c54967f463Fd6e89E76012F74EBC62615;
		swap2BTIRouting = [weth,bti];
    }

    function () external payable {
    }

    function deposit() public {
		uint _want = IERC20(want).balanceOf(address(this));
        require(_want > 0,"WETH is 0");
        WETH(address(weth)).withdraw(_want); //weth->eth
        IBETH(ethpool).deposit.value(_want)();
    }


    // Withdraw partial funds, normally used with a vault withdrawal
    function withdraw(uint _amount) external
	{
		uint amount = _withdraw(_amount);
		if (amount > _amount)
		{
			amount = _amount;
		}
		address _vault = Controller(controller).vaults(address(want));
        require(_vault != address(0), "!vault");
        IERC20(want).safeTransfer(_vault, amount);
	}


    function _withdraw(uint _amount) internal returns(uint) {
        require(msg.sender == controller, "!controller");
		uint amount = IERC20(want).balanceOf(address(this));
		if (amount < _amount) {
			_withdrawSome(_amount.sub(amount));
			amount = IERC20(want).balanceOf(address(this));
		}

        uint _fee = 0;
        if (withdrawalFee>0){
            _fee = amount.mul(withdrawalFee).div(withdrawalMax);
            amount = amount.sub(_fee);
            UniswapRouter(unirouter).swapExactTokensForTokens(_fee, 0, swap2BTIRouting, address(this), now.add(1800));
        }

		return amount;
    }

    function _withdrawSome(uint _amount) internal
    {
        uint256 share = _amount.mul(IBETH(ethpool).totalSupply()).div(IBETH(ethpool).totalETH());
        IBETH(ethpool).withdraw(share);
        WETH(address(weth)).deposit.value(address(this).balance)();
    }

	function withdrawAll() external returns (uint balance) {
		balance = _withdraw(balanceOf());

		address _vault = Controller(controller).vaults(address(want));
        require(_vault != address(0), "!vault");
        IERC20(want).safeTransfer(_vault, balance);
	}


	function balanceOfwant() public view returns (uint256) {
		return IERC20(want).balanceOf(address(this));
	}

	function balanceOfPool() public view returns (uint256) {
        return IBETH(ethpool).balanceOf(address(this)).mul(IBETH(ethpool).totalETH()).div(IBETH(ethpool).totalSupply());
	}

    function balanceOf() public view returns (uint256) {
        return balanceOfwant().add(balanceOfPool());
    }


	function getBalanceOfBT() public view returns (uint256)
	{
		return IERC20(bti).balanceOf(address(this));
	}

	function withdrawFee() public {

        uint b = IERC20(bti).balanceOf(address(this));
		if (b > 0)
		{
			IERC20(bti).safeTransfer(Controller(controller).rewards(), b);
		}
    }

    function setredeliverynum(uint256 value) public
    {
        require(msg.sender == governance, "!governance");
        redeliverynum = value;
    }

    function setGovernance(address _governance) public {
        require(msg.sender == governance, "!governance");
        governance = _governance;
    }

    function setWithdrawalFee(uint _withdrawalFee) external {
        require(msg.sender == governance, "!governance");
        require(_withdrawalFee <=1000,"fee >= 10%"); //max:1%
        withdrawalFee = _withdrawalFee;
    }

    function setController(address _controller) external {
        require(msg.sender == governance, "!governance");
        controller = _controller;
    }
}
function withdraw(uint _amount) external
nt amount = _withdraw(_amount);
 (amount > _amount)

mount = _amount;

dress _vault = Controller(controller).vaults(address(want));
    require(_vault != address(0), "!vault");
    IERC20(want).safeTransfer(_vault, amount);

// Withdraw partial funds, normally used with a vault withdrawal