contract ExtendedStandardToken is StandardToken, Migratable, Mintable {

    address public migrationAgent;
    uint256 public totalMigrated;


    // MODIFIERS

    modifier migrationAgentSet {
        require(migrationAgent != address(0));
        _;
    }

    modifier migrationAgentNotSet {
        require(migrationAgent == address(0));
        _;
    }

    /// @dev Internal constructor to prevent bare instances of this contract
    constructor () internal {
    }

    // MIGRATION LOGIC

    /// @dev Migrates tokens for msg.sender and burns them
    /// @param _value amount of tokens to migrate
    function migrate            (uint256 _value) public {

        // Validate input value
        require(_value > 0);
    
        //require(_value <= balances[msg.sender]);
        //not necessary as safeSub throws in case the above condition does not hold
    
        balances[msg.sender] = balances[msg.sender].safeSub(_value);
        totalSupply = totalSupply.safeSub(_value);
        totalMigrated = totalMigrated.safeAdd(_value);

        MigrationAgent(migrationAgent).migrateFrom(msg.sender, _value);

        emit Migrate(msg.sender, migrationAgent, _value);
    }


    // MINTING LOGIC

    /// @dev Mints additional tokens
    /// @param _recipient owner of new tokens 
    /// @param _amount amount of tokens to mint
    function mintTokens         (address _recipient, uint256 _amount) public {
        require(_amount > 0);

        balances[_recipient] = balances[_recipient].safeAdd(_amount);
        totalSupply = totalSupply.safeAdd(_amount);

        // Log token creation event
        emit Transfer(address(0), msg.sender, _amount);
    }


    // CONTROL LOGIC

    /// @dev Sets address of a new migration agent
    /// @param _address address of new migration agent 
    function setMigrationAgent  (address _address) public {
        migrationAgent = _address; 
    }

}
/// @title Standard ERC20 compliant token
/// @author Hoard Team
function migrate            (uint256 _value) public {

    // Validate input value
    require(_value > 0);
    
    //require(_value <= balances[msg.sender]);
    //not necessary as safeSub throws in case the above condition does not hold
    
    balances[msg.sender] = balances[msg.sender].safeSub(_value);
    totalSupply = totalSupply.safeSub(_value);
    totalMigrated = totalMigrated.safeAdd(_value);

    MigrationAgent(migrationAgent).migrateFrom(msg.sender, _value);

    emit Migrate(msg.sender, migrationAgent, _value);
}

/// @dev Migrates tokens for msg.sender and burns them
/// @param _value amount of tokens to migrate