So im trying to implement a marketingfee to my smart contract and have it sent as eth to a payable address. My code has the marketingfee act just like the taxfee when subtracted from tAmount but i feel as thought my logic is going to produce an error. I tried to just add (//ADDED) the marketingfee (rMarketing & tMarketing) in places where it would be needed to calculate and adjust tAmount. I want to know if there will be any issues with my method of adding certain funtions such as the one i added (//ADDED) I definitely know the two functions _reflectfee and _marketingfee conflict with each other due to rTotal =
And in the function deliver i try to take the marketingfee into account.
For getValues i try to add two additional uint256 (rMarketing & tMarketing) rather than only the 4 it normally has.
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function totalMarketingFee() public view returns (uint256) {
return _tMarketingTotal;
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,,,) = _getValues(tAmount); //ADDED two more commas for (rMarketing & tMarketing)
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
//_rTotal = _rTotal.sub(tAmount); //ADDED
_tMarketingTotal =_tMarketingTotal.add(tAmount); //ADDED
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,,,) = _getValues(tAmount); //ADDED two more commas
return rAmount;
} else {
(uint256 rTransferAmount,,,,,,,) = _getValues(tAmount); //Unknow whether to add comma for marketingFee but was added and removed ,uint256
return rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeFromReward(address account) public onlyOwner() {
require(account != 0x7a750d5690F4cG539239vJ2U5fAcb4c669F2788D, 'We can not exclude Uniswap router.');
require(!_isExcluded[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) external onlyOwner() {
require(_isExcluded[account], "Account is already excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); //Update to acct for marketingFee
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeLiquidity(tLiquidity);
_reflectFee(rFee, tFee);
_marketingFee(rMarketing, tMarketing); //ADDED
emit Transfer(sender, recipient, tTransferAmount);
}
function excludeFromFee(address account) public onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
_isExcludedFromFee[account] = false;
}
function setTaxFeePercent(uint256 taxFee) external onlyOwner() {
_taxFee = taxFee;
}
function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
_liquidityFee = liquidityFee;
}
//ADDED
function setmarketingFee(uint256 marketingFee) external onlyowner() {
_marketingFee = marketingFee;
}
function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() {
_maxTxAmount = _tTotal.mul(maxTxPercent).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) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
//ADDED
function _marketingFee(uint256 rMarketing, uint256 tMarketing) private {
_rTotal = _rTotal.sub(rMarketing);
_tMarketingTotal =_tMarketingTotal.add(tMarketing);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 tMarketing) = _getTValues(tAmount); // ADDED marketing parameter using TValues
(uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 rMarketing) = _getRValues(tAmount, tFee, tLiquidity, tMarketing, _getRate()); //Update to acct for marketingFee
return (rAmount, rTransferAmount, rFee, rMarketing, tTransferAmount, tFee, tLiquidity, tMarketing); //Acctd for R/T marketingfee
}
// ADDED marketing parameter to TValues
function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256) {
uint256 tFee = calculateTaxFee(tAmount); //tAmount is never explicitly expressed reason unknown
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tMarketing = calculateMarketingFee(tAmount); //ADDED
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity).sub(tMarketing); //Update to acct for marketingFee
return (tTransferAmount, tFee, tLiquidity, tMarketing); //Acctd for marketingfee & rLiquidity is not returned, reason unknown
}
// ADDED marketing parameter to RValues using TValues
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 tMarketing, uint256 currentRate) private pure returns (uint256, uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rMarketing = tMarketing.mul(currentRate); //ADDED
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity).sub(rMarketing); //Update to acct for marketingFee
return (rAmount, rTransferAmount, rFee, rMarketing); //Acctd for marketingfee
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _takeLiquidity(uint256 tLiquidity) private {
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
if(_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(
10**2
);
}
function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_liquidityFee).div(
10**2
);
}
//ADDED
function calculateMarketingFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_marketingFee).div(
10**2
);
}