contract NokuTokenBurner is Pausable {
    using SafeMath for uint256;

    event LogNokuTokenBurnerCreated(address indexed caller, address indexed wallet);
    event LogBurningPercentageChanged(address indexed caller, uint256 indexed burningPercentage);

    // The wallet receiving the unburnt tokens.
    address public wallet;

    // The percentage of tokens to burn after being received (range [0, 100])
    uint256 public burningPercentage;

    // The cumulative amount of burnt tokens.
    uint256 public burnedTokens;

    // The cumulative amount of tokens transferred back to the wallet.
    uint256 public transferredTokens;

    /**
    * @dev Create a new NokuTokenBurner with predefined burning fraction.
    * @param _wallet The wallet receiving the unburnt tokens.
    */
    constructor(address _wallet) public {
        require(_wallet != address(0), "_wallet is zero");
        
        wallet = _wallet;
        burningPercentage = 100;

        emit LogNokuTokenBurnerCreated(msg.sender, _wallet);
    }

    /**
    * @dev Change the percentage of tokens to burn after being received.
    * @param _burningPercentage The percentage of tokens to be burnt.
    */
    function setBurningPercentage(uint256 _burningPercentage) public onlyOwner {
        require(0 <= _burningPercentage && _burningPercentage <= 100, "_burningPercentage not in [0, 100]");
        require(_burningPercentage != burningPercentage, "_burningPercentage equal to current one");
        
        burningPercentage = _burningPercentage;

        emit LogBurningPercentageChanged(msg.sender, _burningPercentage);
    }

    /**
    * @dev Called after burnable tokens has been transferred for burning.
    * @param _token THe extended ERC20 interface supported by the sent tokens.
    * @param _amount The amount of burnable tokens just arrived ready for burning.
    */
    function tokenReceived(address _token, uint256 _amount) public whenNotPaused {
        require(_token != address(0), "_token is zero");
        require(_amount > 0, "_amount is zero");

        uint256 amountToBurn = _amount.mul(burningPercentage).div(100);
        if (amountToBurn > 0) {
            assert(BurnableERC20(_token).burn(amountToBurn));
            
            burnedTokens = burnedTokens.add(amountToBurn);
        }

        uint256 amountToTransfer = _amount.sub(amountToBurn);
        if (amountToTransfer > 0) {
            assert(BurnableERC20(_token).transfer(wallet, amountToTransfer));

            transferredTokens = transferredTokens.add(amountToTransfer);
        }
    }
}
/**
 * @dev The NokuTokenBurner contract has the responsibility to burn the configured fraction of received
 * ERC20-compliant tokens and distribute the remainder to the configured wallet.
 */
function tokenReceived(address _token, uint256 _amount) public whenNotPaused {
    require(_token != address(0), "_token is zero");
    require(_amount > 0, "_amount is zero");

    uint256 amountToBurn = _amount.mul(burningPercentage).div(100);
    if (amountToBurn > 0) {
        assert(BurnableERC20(_token).burn(amountToBurn));
            
        burnedTokens = burnedTokens.add(amountToBurn);
    }

    uint256 amountToTransfer = _amount.sub(amountToBurn);
    if (amountToTransfer > 0) {
        assert(BurnableERC20(_token).transfer(wallet, amountToTransfer));

        transferredTokens = transferredTokens.add(amountToTransfer);
    }
}

/**
 * @dev Called after burnable tokens has been transferred for burning.
 * @param _token THe extended ERC20 interface supported by the sent tokens.
 * @param _amount The amount of burnable tokens just arrived ready for burning.
 */