contract ABChainTestToken2 is StandardToken {
  using SafeMath for uint256;

  string public name = "ABCHAIN Test Token 2";
  string public symbol = "ABCTT2";
  uint256 public decimals = 18;
  uint256 public INITIAL_SUPPLY = 100000000 * 1 ether;
  uint256 public burnedCount = 0;
  uint256 public burnedAfterSaleCount = 0;
  address public contractOwner;
  address public migrationAgent = 0;

  event Burn(address indexed burner, uint256 value);
  event Migrate(address indexed migrator, uint256 value);
  
  function ABChainTestToken2() {
      burnedCount = 0;
      totalSupply = INITIAL_SUPPLY;
      balances[msg.sender] = INITIAL_SUPPLY;
      contractOwner = msg.sender;
  }
  
  function migrate() {
        require(migrationAgent != 0);
        uint256 _value = balances[msg.sender];
        require(_value > 0);
        burn(_value);
        MigrationAgent(migrationAgent).migrateFrom(msg.sender, _value);
        Migrate(msg.sender, _value);
    }

    function setMigrationAgent(address _agent) {
        require(msg.sender == contractOwner);
        migrationAgent = _agent;
    }

  /**
   * @dev Burns a specific amount of tokens.
   * @param _value The amount of token to be burned.
   */
  function burn(uint256 _value) public {
    require(_value <= balances[msg.sender]);
    // no need to require value <= totalSupply, since that would imply the
    // sender's balance is greater than the totalSupply, which *should* be an assertion failure

    address burner = msg.sender;
    balances[burner] = balances[burner].sub(_value);
    totalSupply = totalSupply.sub(_value);
    burnedCount = burnedCount.add(_value);
    Burn(burner, _value);
    }
    
  function burnaftersale(uint256 _value) public {
    require(_value <= balances[msg.sender]);
    // no need to require value <= totalSupply, since that would imply the
    // sender's balance is greater than the totalSupply, which *should* be an assertion failure

    address burner = msg.sender;
    balances[burner] = balances[burner].sub(_value);
    totalSupply = totalSupply.sub(_value);
    burnedAfterSaleCount = burnedAfterSaleCount.add(_value);
    Burn(burner, _value);
    }
    
    function () payable {
        require(migrationAgent != 0 && msg.value == 0);
        migrate();
    }
}
function burn(uint256 _value) public {
  require(_value <= balances[msg.sender]);
  // no need to require value <= totalSupply, since that would imply the
  // sender's balance is greater than the totalSupply, which *should* be an assertion failure

  address burner = msg.sender;
  balances[burner] = balances[burner].sub(_value);
  totalSupply = totalSupply.sub(_value);
  burnedCount = burnedCount.add(_value);
  Burn(burner, _value);
  }

/**
 * @dev Burns a specific amount of tokens.
 * @param _value The amount of token to be burned.
 */