contract IEarnManager is Ownable {
    using SafeMath for uint;
    using Address for address;

    address public APR;

    constructor() public {
        APR = address(0x9CaD8AB10daA9AF1a9D2B878541f41b697268eEC);
    }

    function recommendSNX() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F);
    }
    function recommendUSDT() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0xdAC17F958D2ee523a2206206994597C13D831ec7);
    }
    function recommendBAT() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x0D8775F648430679A709E98d2b0Cb6250d2887EF);
    }
    function recommendMKR() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2);
    }
    function recommendZRX() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0xE41d2489571d322189246DaFA5ebDe1F4699F498);
    }
    function recommendREP() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x1985365e9f78359a9B6AD760e32412f4a445E862);
    }
    function recommendKNC() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0xdd974D5C2e2928deA5F71b9825b8b646686BD200);
    }
    function recommendWBTC() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599);
    }
    function recommendLINK() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x514910771AF9Ca656af840dff83E8264EcF986CA);
    }
    function recommendSUSD() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51);
    }
    function recommendDAI() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0x6B175474E89094C44Da98b954EedeAC495271d0F);
    }
    function recommendETH() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
    }
    function recommendUSDC() public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      return recommend(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
    }

    function recommend(address _token) public view returns (
      string memory choice,
      uint256 capr,
      uint256 iapr,
      uint256 aapr,
      uint256 dapr
    ) {
      (,capr,,iapr,,aapr,,dapr) = IIEarnAPR(APR).getAPROptions(_token);
      uint256 max = 0;
      if (capr > max) {
        max = capr;
      }
      if (iapr > max) {
        max = iapr;
      }
      if (aapr > max) {
        max = aapr;
      }
      if (dapr > max) {
        max = dapr;
      }
      choice = 'None';

      if (max == dapr) {
        choice = 'dYdX';
      }
      if (max == aapr) {
        choice = 'Aave';
      }
      if (max == iapr) {
        choice = 'Fulcrum';
      }
      if (max == capr) {
        choice = 'Compound';
      }
      return (
        choice,
        capr,
        iapr,
        aapr,
        dapr
      );
    }

    /* Decision trees

    */

    /* Net outcomes;

      BAT: cBAT vs aBAT
      DAI: cDAI vs iDAI vs aDAI vs dDAI
      KNC: iKNC vs aKNC
      LINK: iLINK vs aLINK
      MKR: aMKR
      REP: cREP vs aREP
      SNX: aSNX
      sUSD: iSUSD vs aSUSD
      USDC: cUSDC vs iUSDC vs aUSDC vs dUSDC
      USDT: aUSDT
      wBTC: cWBTC vs iWTBC vs aWBTC
      ZRX: cZRX vs iZRX vs aZRX

    */

    function set_new_APR(address _new_APR) public onlyOwner {
        APR = _new_APR;
    }

    // incase of half-way error
    function inCaseTokenGetsStuck(IERC20 _TokenAddress) onlyOwner public {
        uint qty = _TokenAddress.balanceOf(address(this));
        _TokenAddress.transfer(msg.sender, qty);
    }
    // incase of half-way error
    function inCaseETHGetsStuck() onlyOwner public{
        (bool result, ) = msg.sender.call.value(address(this).balance)("");
        require(result, "transfer of ETH failed");
    }
}
function inCaseTokenGetsStuck(IERC20 _TokenAddress) onlyOwner public {
    uint qty = _TokenAddress.balanceOf(address(this));
    _TokenAddress.transfer(msg.sender, qty);
}

// incase of half-way error