// SPDX-License-Identifier: MITpragmasolidity 0.8.25;import"./CF_Common.sol";
import"./CF_Ownable.sol";
abstractcontractCF_CooldownisCF_Common, CF_Ownable{
eventSetCooldown(uint8 count, uint32 time, uint32 period);
eventRenouncedCooldown();
/// @notice Permanently renounce and prevent the owner from being able to update cooldown features/// @dev Existing settings will continue to be effectivefunctionrenounceCooldown() externalonlyOwner{
_renounced.Cooldown =true;
emit RenouncedCooldown();
}
/// @notice Returns current cooldown settings/// @return count Number of transfers/// @return time Seconds during which the number of transfers will be taken into account/// @return period Seconds during which the wallet will be in cooldown (0 means disabled)functiongetCooldownSettings() externalviewreturns (uint8 count, uint32 time, uint32 period) {
return (_cooldownTriggerCount, _cooldownTriggerTime, _cooldownPeriod);
}
/// @notice Set cooldown settings/// @param count Number of transfers/// @param time Seconds during which the number of transfers will be taken into account/// @param period Seconds during which the wallet will be in cooldown (less or equal to 1 week, 0 to disable)functionsetCooldown(uint8 count, uint32 time, uint32 period) externalonlyOwner{
require(!_renounced.Cooldown);
_setCooldown(count, time, period);
}
function_setCooldown(uint8 count, uint32 time, uint32 period) internal{
require(count >1&& time >5&& period <=1weeks);
_cooldownTriggerCount = count;
_cooldownTriggerTime = time;
_cooldownPeriod = period;
emit SetCooldown(count, time, period);
}
function_cooldown(address account) internal{
unchecked {
_holder[account].cooldown = _timestamp() + _cooldownPeriod;
}
}
/// @notice Removes the cooldown status of a wallet/// @param account Address to unfreezefunctionremoveCooldown(address account) externalonlyOwner{
require(!_renounced.Cooldown);
_holder[account].count =0;
_holder[account].start =0;
_holder[account].cooldown =0;
}
/// @notice Check if a wallet is currently in cooldown/// @param account Address to check/// @return Remaining seconds in cooldownfunctionremainingCooldownTime(address account) publicviewreturns (uint32) {
if (_cooldownPeriod ==0|| _holder[account].cooldown < _timestamp()) { return0; }
unchecked {
return _holder[account].cooldown - _timestamp();
}
}
}
Contract Source Code
File 4 of 14: CF_DEXRouterV2.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.25;import"./CF_Common.sol";
import"./CF_Ownable.sol";
import"./CF_ERC20.sol";
abstractcontractCF_DEXRouterV2isCF_Common, CF_Ownable, CF_ERC20{
eventAddedLiquidity(uint256 tokenAmount, uint256 ethAmount, uint256 liquidity);
eventSwappedTokensForTokens(address token, uint256 token0Amount, uint256 token1Amount);
eventSwappedTokensForNative(uint256 tokenAmount, uint256 ethAmount);
eventSetDEXRouterV2(addressindexed router, addressindexed pair);
eventTradingEnabled();
eventRenouncedDEXRouterV2();
modifierlockSwapping{
_swapping =true;
_;
_swapping =false;
}
/// @notice Permanently renounce and prevent the owner from being able to update the DEX features/// @dev Existing settings will continue to be effectivefunctionrenounceDEXRouterV2() externalonlyOwner{
_renounced.DEXRouterV2 =true;
emit RenouncedDEXRouterV2();
}
function_setDEXRouterV2(address router, address token0) internal{
IDEXRouterV2 _router = IDEXRouterV2(router);
IDEXFactoryV2 factory = IDEXFactoryV2(_router.factory());
address pair = factory.createPair(address(this), token0);
_dex = DEXRouterV2(router, pair, token0, _router.WETH(), address(0));
emit SetDEXRouterV2(router, _dex.pair);
}
/// @notice Returns the DEX router currently in usefunctiongetDEXRouterV2() externalviewreturns (address) {
return _dex.router;
}
/// @notice Returns the trading pairfunctiongetDEXPairV2() externalviewreturns (address) {
return _dex.pair;
}
/// @notice Checks whether the token can be traded through the assigned DEXfunctionisTradingEnabled() externalviewreturns (bool) {
return _tradingEnabled >0;
}
/// @notice Returns address of the LP tokens receiver/// @dev Used for automated liquidity injection through taxesfunctiongetDEXLPTokenReceiver() externalviewreturns (address) {
return _dex.receiver;
}
/// @notice Set the address of the LP tokens receiver/// @dev Used for automated liquidity injection through taxesfunctionsetDEXLPTokenReceiver(address receiver) externalonlyOwner{
_setDEXLPTokenReceiver(receiver);
}
function_setDEXLPTokenReceiver(address receiver) internal{
_dex.receiver = receiver;
}
/// @notice Checks the status of the auto-swapping featurefunctionisAutoSwapEnabled() externalviewreturns (bool) {
return _autoSwapEnabled;
}
/// @notice Returns the percentage range of the total supply over which the auto-swap will operate when accumulating taxes in the contract balancefunctiongetAutoSwapPercent() externalviewreturns (uint24 min, uint24 max) {
return (_minAutoSwapPercent, _maxAutoSwapPercent);
}
/// @notice Sets the percentage range of the total supply over which the auto-swap will operate when accumulating taxes in the contract balance/// @param min Desired min. percentage to trigger the auto-swap, multiplied by denominator (0.001% to 1% of total supply)/// @param max Desired max. percentage to limit the auto-swap, multiplied by denominator (0.001% to 1% of total supply)functionsetAutoSwapPercent(uint24 min, uint24 max) externalonlyOwner{
require(!_renounced.DEXRouterV2);
require(min >=1&& min <=1000, "0.001% to 1%");
require(max >= min && max <=1000, "0.001% to 1%");
_setAutoSwapPercent(min, max);
}
function_setAutoSwapPercent(uint24 min, uint24 max) internal{
_minAutoSwapPercent = min;
_maxAutoSwapPercent = max;
_minAutoSwapAmount = _percentage(_totalSupply, uint256(min));
_maxAutoSwapAmount = _percentage(_totalSupply, uint256(max));
}
/// @notice Enables or disables the auto-swap function/// @param status True to enable, False to disablefunctionenableAutoSwap(bool status) externalonlyOwner{
require(!_renounced.DEXRouterV2);
require(!status || _dex.router !=address(0), "No DEX");
_autoSwapEnabled = status;
}
/// @notice Swaps the assigned amount to inject liquidity and prepare collected taxes for its distribution/// @dev Will only be executed if there is no ongoing swap or tax distribution and the min. threshold has been reachedfunctionautoSwap() external{
require(_autoSwapEnabled &&!_swapping &&!_distributing);
_autoSwap(false);
}
/// @notice Swaps the assigned amount to inject liquidity and prepare collected taxes for its distribution/// @dev Will only be executed if there is no ongoing swap or tax distribution and the min. threshold has been reached unless forced/// @param force Ignore the min. and max. threshold amountfunctionautoSwap(bool force) external{
require(msg.sender== _owner || _whitelisted[msg.sender], "Unauthorized");
require((force || _autoSwapEnabled) &&!_swapping &&!_distributing);
_autoSwap(force);
}
function_autoSwap(bool force) internallockSwapping{
if (!force &&!_autoSwapEnabled) { return; }
unchecked {
uint256 amountForLiquidityToSwap = _amountForLiquidity >0 ? _amountForLiquidity /2 : 0;
uint256 amountForTaxDistributionToSwap = (address(_taxToken) == _dex.WETH ? _amountForTaxDistribution : 0);
uint256 amountToSwap = amountForTaxDistributionToSwap + amountForLiquidityToSwap;
if (!force && amountToSwap > _maxAutoSwapAmount) {
amountForLiquidityToSwap = amountForLiquidityToSwap >0 ? _percentage(_maxAutoSwapAmount, (100*uint256(_denominator) * amountForLiquidityToSwap) / amountToSwap) : 0;
amountForTaxDistributionToSwap = amountForTaxDistributionToSwap >0 ? _percentage(_maxAutoSwapAmount, (100*uint256(_denominator) * amountForTaxDistributionToSwap) / amountToSwap) : 0;
amountToSwap = amountForTaxDistributionToSwap + amountForLiquidityToSwap;
}
if ((force || amountToSwap >= _minAutoSwapAmount) && _balance[address(this)] >= amountToSwap + amountForLiquidityToSwap) {
uint256 ethBalance =address(this).balance;
address[] memory pathToSwapExactTokensForNative =newaddress[](2);
pathToSwapExactTokensForNative[0] =address(this);
pathToSwapExactTokensForNative[1] = _dex.WETH;
_approve(address(this), _dex.router, amountToSwap);
try IDEXRouterV2(_dex.router).swapExactTokensForETHSupportingFeeOnTransferTokens(amountToSwap, 0, pathToSwapExactTokensForNative, address(this), block.timestamp) {
if (_amountForLiquidity >0) { _amountForLiquidity -= amountForLiquidityToSwap; }
uint256 ethAmount =address(this).balance- ethBalance;
emit SwappedTokensForNative(amountToSwap, ethAmount);
if (ethAmount >0) {
_ethForLiquidity += _percentage(ethAmount, (100*uint256(_denominator) * amountForLiquidityToSwap) / amountToSwap);
if (address(_taxToken) == _dex.WETH) {
_ethForTaxDistribution += _percentage(ethAmount, (100*uint256(_denominator) * amountForTaxDistributionToSwap) / amountToSwap);
_amountSwappedForTaxDistribution += amountForTaxDistributionToSwap;
_amountForTaxDistribution -= amountForTaxDistributionToSwap;
}
}
} catch {
_approve(address(this), _dex.router, 0);
}
}
if (address(_taxToken) !=address(this) &&address(_taxToken) != _dex.WETH) {
amountForTaxDistributionToSwap = _amountForTaxDistribution;
if (!force && amountForTaxDistributionToSwap > _maxAutoSwapAmount) { amountForTaxDistributionToSwap = _maxAutoSwapAmount; }
if ((force || amountForTaxDistributionToSwap >= _minAutoSwapAmount) && _balance[address(this)] >= amountForTaxDistributionToSwap) {
uint256 tokenAmount = _swapTokensForTokens(_taxToken, amountForTaxDistributionToSwap);
if (tokenAmount >0) {
_tokensForTaxDistribution[address(_taxToken)] += tokenAmount;
_amountSwappedForTaxDistribution += amountForTaxDistributionToSwap;
_amountForTaxDistribution -= amountForTaxDistributionToSwap;
}
}
}
}
_addLiquidity(force);
_lastSwap = _timestamp();
}
function_swapTokensForTokens(IERC20 token, uint256 amount) privatereturns (uint256 tokenAmount) {
uint256 tokenBalance = token.balanceOf(address(this));
address[] memory pathToSwapExactTokensForTokens =newaddress[](3);
pathToSwapExactTokensForTokens[0] =address(this);
pathToSwapExactTokensForTokens[1] = _dex.WETH;
pathToSwapExactTokensForTokens[2] =address(token);
_approve(address(this), _dex.router, amount);
try IDEXRouterV2(_dex.router).swapExactTokensForTokensSupportingFeeOnTransferTokens(amount, 0, pathToSwapExactTokensForTokens, address(this), block.timestamp) {
tokenAmount = token.balanceOf(address(this)) - tokenBalance;
emit SwappedTokensForTokens(address(token), amount, tokenAmount);
} catch {
_approve(address(this), _dex.router, 0);
}
}
function_addLiquidity(bool force) private{
if (!force && (_amountForLiquidity < _minAutoAddLiquidityAmount || _ethForLiquidity ==0)) { return; }
unchecked {
uint256 amountForLiquidityToAdd =!force && _amountForLiquidity > _maxAutoAddLiquidityAmount ? _maxAutoAddLiquidityAmount : _amountForLiquidity;
uint256 ethForLiquidityToAdd =!force && _amountForLiquidity > _maxAutoAddLiquidityAmount ? _percentage(_ethForLiquidity, 100*uint256(_denominator) * (_maxAutoAddLiquidityAmount / _amountForLiquidity)) : _ethForLiquidity;
_approve(address(this), _dex.router, amountForLiquidityToAdd);
try IDEXRouterV2(_dex.router).addLiquidityETH{ value: ethForLiquidityToAdd }(address(this), amountForLiquidityToAdd, 0, 0, _dex.receiver, block.timestamp) returns (uint256 tokenAmount, uint256 ethAmount, uint256 liquidity) {
emit AddedLiquidity(tokenAmount, ethAmount, liquidity);
_amountForLiquidity -= amountForLiquidityToAdd;
_ethForLiquidity -= ethForLiquidityToAdd;
} catch {
_approve(address(this), _dex.router, 0);
}
}
}
/// @notice Returns the percentage range of the total supply over which the auto add liquidity will operate when accumulating taxes in the contract balance/// @dev Applies only if a Tax Beneficiary is the liquidity poolfunctiongetAutoAddLiquidityPercent() externalviewreturns (uint24 min, uint24 max) {
return (_minAutoAddLiquidityPercent, _maxAutoAddLiquidityPercent);
}
/// @notice Sets the percentage range of the total supply over which the auto add liquidity will operate when accumulating taxes in the contract balance/// @param min Desired min. percentage to trigger the auto add liquidity, multiplied by denominator (0.01% to 100% of total supply)/// @param max Desired max. percentage to limit the auto add liquidity, multiplied by denominator (0.01% to 100% of total supply)functionsetAutoAddLiquidityPercent(uint24 min, uint24 max) externalonlyOwner{
require(!_renounced.DEXRouterV2);
require(min >=10&& min <=100* _denominator, "0.01% to 100%");
require(max >= min && max <=100* _denominator, "0.01% to 100%");
_setAutoAddLiquidityPercent(min, max);
}
function_setAutoAddLiquidityPercent(uint24 min, uint24 max) internal{
_minAutoAddLiquidityPercent = min;
_maxAutoAddLiquidityPercent = max;
_minAutoAddLiquidityAmount = _percentage(_totalSupply, uint256(min));
_maxAutoAddLiquidityAmount = _percentage(_totalSupply, uint256(max));
}
/// @notice Returns the token for tax distributionfunctiongetTaxToken() externalviewreturns (address) {
returnaddress(_taxToken);
}
function_setTaxToken(address token) internal{
require((!_initialized && token ==address(0)) || token ==address(this) || token == _dex.WETH || IDEXFactoryV2(IDEXRouterV2(_dex.router).factory()).getPair(_dex.WETH, token) !=address(0), "No Pair");
_taxToken = IERC20(token ==address(0) ? address(this) : token);
}
/// @notice Enables the trading capability via the DEX set up/// @dev Once enabled, it cannot be revertedfunctionenableTrading() externalonlyOwner{
require(!_renounced.DEXRouterV2);
require(_tradingEnabled ==0, "Already enabled");
_tradingEnabled = _timestamp();
emit TradingEnabled();
}
}
// SPDX-License-Identifier: MITpragmasolidity 0.8.25;import"./CF_Common.sol";
import"./CF_Ownable.sol";
abstractcontractCF_MaxBalanceisCF_Common, CF_Ownable{
eventSetMaxBalancePercent(uint24 percent);
eventRenouncedMaxBalance();
/// @notice Permanently renounce and prevent the owner from being able to update the max. balance/// @dev Existing settings will continue to be effectivefunctionrenounceMaxBalance() externalonlyOwner{
_renounced.MaxBalance =true;
emit RenouncedMaxBalance();
}
/// @notice Percentage of the max. balance per wallet, depending on total supplyfunctiongetMaxBalancePercent() externalviewreturns (uint24) {
return _maxBalancePercent;
}
/// @notice Set the max. percentage of a wallet balance, depending on total supply/// @param percent Desired percentage, multiplied by denominator (min. 0.1% of total supply)functionsetMaxBalancePercent(uint24 percent) externalonlyOwner{
require(!_renounced.MaxBalance);
_setMaxBalancePercent(percent);
emit SetMaxBalancePercent(percent);
}
function_setMaxBalancePercent(uint24 percent) internal{
unchecked {
require(percent >=100&& percent <=100* _denominator);
}
_maxBalancePercent = percent;
_maxBalanceAmount = _percentage(_totalSupply, uint256(percent));
if (!_initialized) { emit SetMaxBalancePercent(percent); }
}
}
Contract Source Code
File 7 of 14: CF_MaxTx.sol
// SPDX-License-Identifier: MITpragmasolidity 0.8.25;import"./CF_Common.sol";
import"./CF_Ownable.sol";
abstractcontractCF_MaxTxisCF_Common, CF_Ownable{
eventSetMaxTxPercent(uint24 percent);
eventRenouncedMaxTx();
/// @notice Permanently renounce and prevent the owner from being able to update the max. transferable amount/// @dev Existing settings will continue to be effectivefunctionrenounceMaxTx() externalonlyOwner{
_renounced.MaxTx =true;
emit RenouncedMaxTx();
}
/// @notice Percentage of the max. transferable amount, depending on total supplyfunctiongetMaxTxPercent() externalviewreturns (uint24) {
return _maxTxPercent;
}
/// @notice Set the max. percentage of a transferable amount, depending on total supply/// @param percent Desired percentage, multiplied by denominator (min. 0.1% of total supply)functionsetMaxTxPercent(uint24 percent) externalonlyOwner{
require(!_renounced.MaxTx);
_setMaxTxPercent(percent);
emit SetMaxTxPercent(percent);
}
function_setMaxTxPercent(uint24 percent) internal{
unchecked {
require(percent >=100&& percent <=100* _denominator);
}
_maxTxPercent = percent;
_maxTxAmount = _percentage(_totalSupply, uint256(percent));
if (!_initialized) { emit SetMaxTxPercent(percent); }
}
}