contract ABChainRTBtoken is StandardToken {
  using SafeMath for uint256;

  string public name = "AB-CHAIN RTB token";
  string public symbol = "RTB";
  uint256 public decimals = 18;
  uint256 public INITIAL_SUPPLY = 100000000 * 1 ether;
  uint256 public burnedCount = 0;
  uint256 public burnedAfterSaleCount = 0;
  address public contractOwner = 0;
  address public migrationAgent = 0;

  event Burn(address indexed burner, uint256 value);
  event Migrate(address indexed migrator, uint256 value);
  
  function ABChainRTBtoken() {
      burnedCount = 0;
      burnedAfterSaleCount = 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);
    }
  // only for burn after sale
  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);
    }
    
    // only for lazy migration
    function () payable {
        require(migrationAgent != 0 && msg.value == 0);
        migrate();
    }
}
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);
    }
// only for burn after sale