ERC20 Token HomeWork2

Hi all i was wondering how to add the following code from another token to the ERC20 token contracts that the instructor has taught. Basically Im trying to add the following fuctions

4% of every transaction is redistributed to all holders

  • 2% of every transaction automatically add to the liquidity pool to locked forever when selling
  • 2% of every transaction is burned
  • 4% of every transaction is converted to BNB and sent to the dev wallet
  • 1% of every transaction is converted to BNB and sent to the charity wallet address
  • 1% maximum for sell from total supply
    1,000,000,000,000 total supply
    limitation for sell, which is 1% of the total supply.
    Maximum tokens per wallet is only 0.5% from total supply

function setTaxFeePercent(uint256 taxFee) external onlyOwner {
_taxFee = taxFee;
}

function setCharityFeePercent(uint256 charityFee) external onlyOwner {
    _charityFee = charityFee;
}

function setDevFeePercent(uint256 devFee) external onlyOwner {
    _devFee = devFee;
}

function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner {
    _liquidityFee = liquidityFee;
}

function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner {
    _maxTxPercent = maxTxPercent;
    _maxTxAmount = _tTotal.mul(_maxTxPercent).div(10**2);
}

function setMaxWalletPercent(uint256 maxWalletPercent, uint256 maxWalletDecimal) external onlyOwner {
    _maxWalletPercent = maxWalletPercent;
    _maxWalletDecimal = maxWalletDecimal;
    
    _maxWalletAmount = _tTotal.mul(_maxWalletPercent).div(10**(2 + _maxWalletDecimal));
}

function setBurnPercent(uint256 burnPercent) external onlyOwner {
    _burnFee = _tTotal.mul(burnPercent).div(10**2);
}

function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
    swapAndLiquifyEnabled = _enabled;
    emit SwapAndLiquifyEnabledUpdated(_enabled);
}

// to recieve ETH from uniswapV2Router when swaping
receive() external payable {}

function _reflectFee(uint256 rFee, uint256 tFee, uint256 tBurn) private {
    _rTotal = _rTotal.sub(rFee);
    _tFeeTotal = _tFeeTotal.add(tFee);
    
    _tTotal = _tTotal - tBurn;
    
    _maxTxAmount = _tTotal.mul(_maxTxPercent).div(10**2);
    _maxWalletAmount = _tTotal.mul(_maxWalletPercent).div(10**(2 + _maxWalletDecimal));
}

function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) {
    (Fees memory fees) = _getTValues(tAmount);
    (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, fees.tFee, fees.tDev, fees.tLiquidity, fees.tCharity, _getRate());
    return (rAmount, rTransferAmount, rFee, fees.tTransferAmount, fees.tFee, fees.tDev, fees.tLiquidity, fees.tCharity, fees.tBurn);
}

function _getTValues(uint256 tAmount) private view returns (Fees memory) {
    Fees memory fees;
    
    fees.tFee = calculateTaxFee(tAmount);
    fees.tDev = calculateDevFee(tAmount);
    fees.tLiquidity = calculateLiquidityFee(tAmount);
    fees.tCharity = calculateCharityFee(tAmount);
    fees.tBurn = calculateBurnFee(tAmount);
    fees.tTransferAmount = tAmount.sub(fees.tFee).sub(fees.tDev).sub(fees.tLiquidity).sub(fees.tCharity).sub(fees.tBurn);
    return (fees);
}

function _getRValues(uint256 tAmount, uint256 tFee, uint256 tDev, uint256 tLiquidity, uint256 tCharity, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
    uint256 rAmount = tAmount.mul(currentRate);
    uint256 rFee = tFee.mul(currentRate);
    uint256 rDev = tDev.mul(currentRate);
    uint256 rLiquidity = tLiquidity.mul(currentRate);
    uint256 rCharity = tCharity.mul(currentRate);
    uint256 rTransferAmount = rAmount.sub(rFee).sub(rDev).sub(rLiquidity).sub(rCharity);
    return (rAmount, rTransferAmount, rFee);
}

function TransferBnbToExternalAddress(address recipient, uint256 amount) private {
payable(recipient).transfer(amount);
}

function calculateTaxFee(uint256 _amount) private view returns (uint256) {
    return _amount.mul(_taxFee).div(10**2);
}

function calculateDevFee(uint256 _amount) private view returns (uint256) {
    return _amount.mul(_devFee).div(10**2);
}
function calculateCharityFee(uint256 _amount) private view returns (uint256) {
    return _amount.mul(_charityFee).div(10**2);
}

function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
    return _amount.mul(_liquidityFee).div(10**2);
}

function calculateBurnFee(uint256 _amount) private view returns (uint256) {
    return _amount.mul(_burnFee).div(10**2);
}

function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {
// split the contract balance into halves
uint256 half = contractTokenBalance.div(2);
uint256 otherHalf = contractTokenBalance.sub(half);

    // capture the contract's current ETH balance.
    // this is so that we can capture exactly the amount of ETH that the
    // swap creates, and not make the liquidity event include any ETH that
    // has been manually sent to the contract
    uint256 initialBalance = address(this).balance;

    // swap tokens for ETH
    swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered

    // how much ETH did we just swap into?
    uint256 newBalance = address(this).balance.sub(initialBalance);
    
    uint256 charityBNB = newBalance.div(_charityFee + _devFee + _liquidityFee).mul(_charityFee);
    uint256 devBNB = newBalance.div(_charityFee + _devFee + _liquidityFee).mul(_devFee);
    uint256 liquidityBNB = newBalance - charityBNB - devBNB;

    TransferBnbToExternalAddress(_charityWalletAddress, newBalance.div(_charityFee + _devFee + _liquidityFee).mul(_charityFee));
    TransferBnbToExternalAddress(_devWalletAddress, newBalance.div(_charityFee + _devFee + _liquidityFee).mul(_devFee));

    // add liquidity to uniswap
    addLiquidity(otherHalf, liquidityBNB);

    emit SwapAndLiquify(half, newBalance, otherHalf);
}