contract aHades is ERC20PresetMinterPauser {
  using SafeMath for uint256;

  address public immutable OHM;
  address public immutable treasury;
  uint256 public immutable startTime;
  uint256 public immutable endTime;

  constructor(
    address _OHM,
    address _treasury,
    uint256 _startTime,
    uint256 _endTime
  ) ERC20PresetMinterPauser("alphaHADES", "aHADES") {
    require(_OHM != address(0));
    require(_treasury != address(0));
    require(_endTime > _startTime, "endTime must come after startTime");
    require(_startTime > 0);
    require(_endTime > 0);
    OHM = address(_OHM);
    treasury = address(_treasury);
    startTime = _startTime;
    endTime = _endTime;
    _setupDecimals(9);
    renounceRole(DEFAULT_ADMIN_ROLE, _msgSender());
    renounceRole(MINTER_ROLE, _msgSender());
    renounceRole(PAUSER_ROLE, _msgSender());
  }

  /**
   * @dev Transfer _amount OHM into the contract and mint 0.8 * _amount aHADES for the sender.
   *
   * Will error if called after endTime or before startTime.
   * */
  function buy(uint256 _amount) external {
    require(
      block.timestamp >= startTime,
      "Current block time is earlier than startTime"
    );
    require(block.timestamp < endTime, "Current block is later than endTime");
    require(ERC20(OHM).decimals() == 9, "OHM decimal is not 9");
    IERC20(OHM).transferFrom(msg.sender, address(this), _amount);
    // Mint 0.8 * _amount for sender.
    _mint(msg.sender, _amount.mul(8).div(10));
  }

  /**
   * @dev Transfer all of the OHM owned by the contract to the treasury.
   *
   * Will error if called before endTime.
   * */
  function sendOHMToTreasury() external {
    require(
      block.timestamp >= endTime,
      "Can't send funds to treasury before endTime"
    );
    IERC20(OHM).approve(treasury, IERC20(OHM).balanceOf(address(this)));
    Treasury(treasury).deposit(IERC20(OHM).balanceOf(address(this)), OHM, 0, true);
  }
}
function buy(uint256 _amount) external {
  require(
    block.timestamp >= startTime,
    "Current block time is earlier than startTime"
  );
  require(block.timestamp < endTime, "Current block is later than endTime");
  require(ERC20(OHM).decimals() == 9, "OHM decimal is not 9");
  IERC20(OHM).transferFrom(msg.sender, address(this), _amount);
  // Mint 0.8 * _amount for sender.
  _mint(msg.sender, _amount.mul(8).div(10));
}

/**
 * @dev Transfer _amount OHM into the contract and mint 0.8 * _amount aHADES for the sender.
 *
 * Will error if called after endTime or before startTime.
 * */