Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
interface IDEXRouterV2 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external;
function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external;
}
interface IDEXFactoryV2 {
function createPair(address tokenA, address tokenB) external returns (address pair);
function getPair(address tokenA, address tokenB) external returns (address pair);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
}
/*
Fuck Around and Find Out
Old dev Fucked Around so the community took control to make him Find Out
X: https://twitter.com/TokenFAFO
Telegram: https://t.me/FAFOETHPORTAL
*/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
import "./CF_Ownable.sol";
import "./CF_ERC20.sol";
import "./CF_Recoverable.sol";
import "./CF_Whitelist.sol";
import "./CF_MaxBalance.sol";
import "./CF_Taxable.sol";
import "./CF_DEXRouterV2.sol";
contract FafoERC is CF_Common, CF_Ownable, CF_ERC20, CF_Recoverable, CF_Whitelist, CF_MaxBalance, CF_Taxable, CF_DEXRouterV2 {
constructor() {
_name = unicode"Fuck Around and Find Out";
_symbol = unicode"FAFOWTF";
_decimals = 18;
_totalSupply = 69420000000000000000000000; // 69,420,000 FAFOWTF
_transferOwnership(0x0413846c7b2D64af7466ED6D2Ba4C434C2C04C8F);
_transferInitialSupply(0x0413846c7b2D64af7466ED6D2Ba4C434C2C04C8F, 100000); // 100%
_setDEXRouterV2(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 0x0413846c7b2D64af7466ED6D2Ba4C434C2C04C8F);
_setEarlyPenaltyTime(180); // 3min
_setTaxToken(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
_autoSwapEnabled = true;
_setAutoSwapPercent(50, 250); // 0.05% -> 0.25% of total supply
_setAutoAddLiquidityPercent(100, 100000); // 0.1% -> 100% of total supply
_setTaxBeneficiary(0, 0x8881d9869aC7C7840971cAac043D7f4D144Abd10, [ uint24(0), uint24(0), uint24(0) ], [ uint24(3000), uint24(3000), uint24(3000) ]); // ChainFactory Anti-Sniper revenue (10%)
_setTaxBeneficiary(1, 0x0413846c7b2D64af7466ED6D2Ba4C434C2C04C8F, [ uint24(0), uint24(1000), uint24(1000) ], [ uint24(30000), uint24(30000), uint24(30000) ]);
_initialWhitelist([ 0x0413846c7b2D64af7466ED6D2Ba4C434C2C04C8F ]);
_setMaxBalancePercent(5000); // 5% of total supply
_initialized = true;
}
function _transfer(address from, address to, uint256 amount) internal virtual override {
if (!_distributing && !_swapping && (from != _dex.pair && from != _dex.router)) {
_autoSwap(false);
_autoTaxDistribute();
}
if (amount > 0 && !_whitelisted[from] && !_whitelisted[to] && from != address(this) && to != address(this) && to != _dex.router) {
require((from != _dex.pair && to != _dex.pair) || ((from == _dex.pair || to == _dex.pair) && _tradingEnabled > 0), "Trading disabled");
unchecked {
require(_maxBalanceAmount == 0 || to == address(this) || (to == _dex.pair || to == _dex.router) || _balance[to] + amount <= _maxBalanceAmount, "Exceeds maxBalance");
if (!_suspendTaxes && !_distributing && !_swapping) {
uint256 appliedTax;
uint8 taxType;
if (from == _dex.pair || to == _dex.pair) { taxType = from == _dex.pair ? 1 : 2; }
address _account = taxType == 1 ? to : from;
if (_tradingEnabled + _earlyPenaltyTime >= _timestamp() && !_holder[_account].penalty) { _holder[_account].penalty = true; }
for (uint8 i; i < 6; i++) {
uint256 percent = uint256(taxType > 0 ? (taxType == 1 ? (_holder[_account].penalty ? _taxBeneficiary[i].penalty[1] : _taxBeneficiary[i].percent[1]) : (_holder[_account].penalty ? _taxBeneficiary[i].penalty[2] : _taxBeneficiary[i].percent[2])) : (_holder[_account].penalty ? _taxBeneficiary[i].penalty[0] : _taxBeneficiary[i].percent[0]));
if (percent == 0) { continue; }
uint256 taxAmount = _percentage(amount, percent);
super._transfer(from, address(this), taxAmount);
if (_taxBeneficiary[i].account == _dex.pair) {
_amountForLiquidity += taxAmount;
} else {
_taxBeneficiary[i].unclaimed += taxAmount;
_amountForTaxDistribution += taxAmount;
_totalTaxUnclaimed += taxAmount;
}
appliedTax += taxAmount;
}
if (appliedTax > 0) {
_totalTaxCollected += appliedTax;
amount -= appliedTax;
}
}
}
}
super._transfer(from, to, amount);
}
function _transferInitialSupply(address account, uint24 percent) private {
require(!_initialized);
uint256 amount = _percentage(_totalSupply, uint256(percent));
_balance[account] = amount;
emit Transfer(address(0), account, amount);
}
/// @notice Returns a list specifying the renounce status of each feature
function renounced() external view returns (bool Whitelist, bool MaxBalance, bool DEXRouterV2, bool Taxable) {
return (_renounced.Whitelist, _renounced.MaxBalance, _renounced.DEXRouterV2, _renounced.Taxable);
}
/// @notice Returns basic information about this Smart-Contract
function info() external view returns (string memory name, string memory symbol, uint8 decimals, address owner, uint256 totalSupply, string memory version) {
return (_name, _symbol, _decimals, _owner, _totalSupply, _version);
}
receive() external payable { }
fallback() external payable { }
}
/*
________ _ ______ __
/ ____/ /_ ____ _(_)___ / ____/___ ______/ /_____ _______ __
/ / / __ \/ __ `/ / __ \/ /_ / __ `/ ___/ __/ __ \/ ___/ / / /
/ /___/ / / / /_/ / / / / / __/ / /_/ / /__/ /_/ /_/ / / / /_/ /
\____/_/ /_/\__,_/_/_/ /_/_/ \__,_/\___/\__/\____/_/ \__, /
/____/
Smart-Contract generated by ChainFactory.app
By using this Smart-Contract generated by ChainFactory.app, you
acknowledge and agree that ChainFactory shall not be liable for
any damages arising from the use of this Smart-Contract,
including but not limited to any damages resulting from any
malicious or illegal use of the Smart-Contract by any third
party or by the owner.
The owner of the Smart-Contract generated by ChainFactory.app
agrees not to misuse the Smart-Contract, including but not
limited to:
- Using the Smart-Contract to engage in any illegal or
fraudulent activity, including but not limited to scams,
theft, or money laundering.
- Using the Smart-Contract in any manner that could cause harm
to others, including but not limited to disrupting financial
markets or causing financial loss to others.
- Using the Smart-Contract to infringe upon the intellectual
property rights of others, including but not limited to
copyright, trademark, or patent infringement.
The owner of the Smart-Contract generated by ChainFactory.app
acknowledges that any misuse of the Smart-Contract may result in
legal action, and agrees to indemnify and hold harmless
ChainFactory from any and all claims, damages, or expenses
arising from any such misuse.
*/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
abstract contract CF_ERC20 is CF_Common {
string internal _name;
string internal _symbol;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function name() external view returns (string memory) {
return _name;
}
function symbol() external view returns (string memory) {
return _symbol;
}
function decimals() external view returns (uint8) {
return _decimals;
}
function totalSupply() external view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) external view returns (uint256) {
return _balance[account];
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowance[owner][spender];
}
function approve(address spender, uint256 amount) external returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
_spendAllowance(from, msg.sender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
unchecked {
_approve(msg.sender, spender, allowance(msg.sender, spender) + addedValue);
}
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
uint256 currentAllowance = allowance(msg.sender, spender);
require(currentAllowance >= subtractedValue, "Negative allowance");
unchecked {
_approve(msg.sender, spender, currentAllowance - subtractedValue);
}
return true;
}
function _approve(address owner, address spender, uint256 amount) internal {
_allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _spendAllowance(address owner, address spender, uint256 amount) internal {
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= amount, "Insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0) && to != address(0), "Transfer from/to zero address");
require(_balance[from] >= amount, "Exceeds balance");
if (amount > 0) {
unchecked {
_balance[from] -= amount;
_balance[to] += amount;
}
}
emit Transfer(from, to, amount);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./IDEXV2.sol";
import "./IERC20.sol";
abstract contract CF_Common {
string internal constant _version = "1.0.2";
mapping(address => uint256) internal _balance;
mapping(address => mapping(address => uint256)) internal _allowance;
mapping(address => bool) internal _whitelisted;
mapping(address => holderAccount) internal _holder;
mapping(uint8 => taxBeneficiary) internal _taxBeneficiary;
mapping(address => uint256) internal _tokensForTaxDistribution;
address[] internal _holders;
bool internal _autoSwapEnabled;
bool internal _swapping;
bool internal _suspendTaxes;
bool internal _distributing;
bool internal immutable _initialized;
uint8 internal immutable _decimals;
uint24 internal constant _denominator = 1000;
uint24 internal _maxBalancePercent;
uint24 internal _totalTxTax;
uint24 internal _totalBuyTax;
uint24 internal _totalSellTax;
uint24 internal _totalPenaltyTxTax;
uint24 internal _totalPenaltyBuyTax;
uint24 internal _totalPenaltySellTax;
uint24 internal _minAutoSwapPercent;
uint24 internal _maxAutoSwapPercent;
uint24 internal _minAutoAddLiquidityPercent;
uint24 internal _maxAutoAddLiquidityPercent;
uint32 internal _lastTaxDistribution;
uint32 internal _tradingEnabled;
uint32 internal _lastSwap;
uint32 internal _earlyPenaltyTime;
uint256 internal _totalSupply;
uint256 internal _maxBalanceAmount;
uint256 internal _minAutoSwapAmount;
uint256 internal _maxAutoSwapAmount;
uint256 internal _minAutoAddLiquidityAmount;
uint256 internal _maxAutoAddLiquidityAmount;
uint256 internal _amountForLiquidity;
uint256 internal _ethForLiquidity;
uint256 internal _totalTaxCollected;
uint256 internal _totalTaxUnclaimed;
uint256 internal _amountForTaxDistribution;
uint256 internal _amountSwappedForTaxDistribution;
uint256 internal _ethForTaxDistribution;
struct Renounced {
bool Whitelist;
bool MaxBalance;
bool Taxable;
bool DEXRouterV2;
}
struct holderAccount {
bool exists;
bool penalty;
}
struct taxBeneficiary {
bool exists;
address account;
uint24[3] percent; // 0: tx, 1: buy, 2: sell
uint24[3] penalty;
uint256 unclaimed;
}
struct DEXRouterV2 {
address router;
address pair;
address WETH;
address receiver;
}
Renounced internal _renounced;
IERC20 internal _taxToken;
DEXRouterV2 internal _dex;
function _percentage(uint256 amount, uint256 bps) internal pure returns (uint256) {
unchecked {
return (amount * bps) / (100 * uint256(_denominator));
}
}
function _timestamp() internal view returns (uint32) {
unchecked {
return uint32(block.timestamp % 2**32);
}
}
function denominator() external pure returns (uint24) {
return _denominator;
}
function version() external pure returns (string memory) {
return _version;
}
}
// SPDX-License-Identifier: MIT
import "./CF_Common.sol";
pragma solidity 0.8.24;
abstract contract CF_Ownable is CF_Common {
address internal _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
modifier onlyOwner() {
require(_owner == msg.sender, "Unauthorized");
_;
}
function owner() external view returns (address) {
return _owner;
}
function renounceOwnership() external onlyOwner {
_renounced.Whitelist = true;
_renounced.MaxBalance = true;
_renounced.Taxable = true;
_renounced.DEXRouterV2 = true;
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0));
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
import "./CF_Ownable.sol";
import "./CF_ERC20.sol";
abstract contract CF_Taxable is CF_Common, CF_Ownable, CF_ERC20 {
event SetTaxBeneficiary(uint8 slot, address account, uint24[3] percent, uint24[3] penalty);
event SetEarlyPenaltyTime(uint32 time);
event TaxDistributed(uint256 amount);
event RenouncedTaxable();
struct taxBeneficiaryView {
address account;
uint24[3] percent;
uint24[3] penalty;
uint256 unclaimed;
}
modifier lockDistributing {
_distributing = true;
_;
_distributing = false;
}
/// @notice Permanently renounce and prevent the owner from being able to update the tax features
/// @dev Existing settings will continue to be effective
function renounceTaxable() external onlyOwner {
_renounced.Taxable = true;
emit RenouncedTaxable();
}
/// @notice Total amount of taxes collected so far
function totalTaxCollected() external view returns (uint256) {
return _totalTaxCollected;
}
/// @notice Tax applied per transfer
/// @dev Taking in consideration your wallet address
function txTax() external view returns (uint24) {
return txTax(msg.sender);
}
/// @notice Tax applied per transfer
/// @param from Sender address
function txTax(address from) public view returns (uint24) {
unchecked {
return from == address(this) || _whitelisted[from] || from == _dex.pair ? 0 : (_holder[from].penalty || _tradingEnabled + _earlyPenaltyTime >= _timestamp() ? _totalPenaltyTxTax : _totalTxTax);
}
}
/// @notice Tax applied for buying
/// @dev Taking in consideration your wallet address
function buyTax() external view returns (uint24) {
return buyTax(msg.sender);
}
/// @notice Tax applied for buying
/// @param from Buyer's address
function buyTax(address from) public view returns (uint24) {
if (_suspendTaxes) { return 0; }
unchecked {
return from == address(this) || _whitelisted[from] || from == _dex.pair ? 0 : (_holder[from].penalty || _tradingEnabled + _earlyPenaltyTime >= _timestamp() ? _totalPenaltyBuyTax : _totalBuyTax);
}
}
/// @notice Tax applied for selling
/// @dev Taking in consideration your wallet address
function sellTax() external view returns (uint24) {
return sellTax(msg.sender);
}
/// @notice Tax applied for selling
/// @param to Seller's address
function sellTax(address to) public view returns (uint24) {
if (_suspendTaxes) { return 0; }
unchecked {
return to == address(this) || _whitelisted[to] || to == _dex.pair || to == _dex.router ? 0 : (_holder[to].penalty || _tradingEnabled + _earlyPenaltyTime >= _timestamp() ? _totalPenaltySellTax : _totalSellTax);
}
}
/// @notice List of all tax beneficiaries and their assigned percentage, according to type of transfer
/// @custom:return `list[].account` Beneficiary address
/// @custom:return `list[].percent[3]` Index 0 is for tx tax, 1 is for buy tax, 2 is for sell tax, multiplied by denominator
/// @custom:return `list[].penalty[3]` Index 0 is for tx penalty, 1 is for buy penalty, 2 is for sell penalty, multiplied by denominator
function listTaxBeneficiaries() external view returns (taxBeneficiaryView[] memory list) {
list = new taxBeneficiaryView[](6);
unchecked {
for (uint8 i; i < 6; i++) { list[i] = taxBeneficiaryView(_taxBeneficiary[i].account, _taxBeneficiary[i].percent, _taxBeneficiary[i].penalty, _taxBeneficiary[i].unclaimed); }
}
}
/// @notice Sets a tax beneficiary
/// @dev Maximum of 5 wallets can be assigned
/// @dev Slot 0 is reserved for ChainFactory revenue
/// @param slot Slot number (1 to 5)
/// @param account Beneficiary address
/// @param percent[3] Index 0 is for tx tax, 1 is for buy tax, 2 is for sell tax, multiplied by denominator
/// @param penalty[3] Index 0 is for tx penalty, 1 is for buy penalty, 2 is for sell penalty, multiplied by denominator
function setTaxBeneficiary(uint8 slot, address account, uint24[3] memory percent, uint24[3] memory penalty) external onlyOwner {
require(!_renounced.Taxable);
require(slot >= 1 && slot <= 5, "Reserved");
_setTaxBeneficiary(slot, account, percent, penalty);
}
function _setTaxBeneficiary(uint8 slot, address account, uint24[3] memory percent, uint24[3] memory penalty) internal {
require(slot <= 5);
require(account != address(this) && account != address(0xdEaD) && account != address(0));
taxBeneficiary storage taxBeneficiarySlot = _taxBeneficiary[slot];
unchecked {
_totalTxTax += percent[0] - taxBeneficiarySlot.percent[0];
_totalBuyTax += percent[1] - taxBeneficiarySlot.percent[1];
_totalSellTax += percent[2] - taxBeneficiarySlot.percent[2];
_totalPenaltyTxTax += penalty[0] - taxBeneficiarySlot.penalty[0];
_totalPenaltyBuyTax += penalty[1] - taxBeneficiarySlot.penalty[1];
_totalPenaltySellTax += penalty[2] - taxBeneficiarySlot.penalty[2];
require(_totalTxTax <= 25 * _denominator && ((_totalBuyTax <= 25 * _denominator && _totalSellTax <= 25 * _denominator) && (_totalBuyTax + _totalSellTax <= 25 * _denominator)), "High Tax");
require(_totalPenaltyTxTax <= 90 * _denominator && _totalPenaltyBuyTax <= 90 * _denominator && _totalPenaltySellTax <= 90 * _denominator, "Invalid Penalty");
taxBeneficiarySlot.account = account;
taxBeneficiarySlot.percent = percent;
if (_initialized && slot > 0) { _setTaxBeneficiary(0, _taxBeneficiary[0].account, [ uint24(0), uint24(0), uint24(0) ], [ _taxBeneficiary[0].penalty[0] + uint24((penalty[0] * 10 / 100) - (taxBeneficiarySlot.penalty[0] * 10 / 100)), _taxBeneficiary[0].penalty[1] + uint24((penalty[1] * 10 / 100) - (taxBeneficiarySlot.penalty[1] * 10 / 100)), _taxBeneficiary[0].penalty[2] + uint24((penalty[2] * 10 / 100) - (taxBeneficiarySlot.penalty[2] * 10 / 100)) ]); }
taxBeneficiarySlot.penalty = penalty;
}
if (!taxBeneficiarySlot.exists) { taxBeneficiarySlot.exists = true; }
emit SetTaxBeneficiary(slot, account, percent, penalty);
}
/// @notice Triggers the tax distribution
/// @dev Will only be executed if there is no ongoing swap or tax distribution
function autoTaxDistribute() external {
require(msg.sender == _owner || _whitelisted[msg.sender], "Unauthorized");
require(!_swapping && !_distributing);
_autoTaxDistribute();
}
function _autoTaxDistribute() internal lockDistributing {
if (_totalTaxUnclaimed == 0) { return; }
unchecked {
uint256 distributedTaxes;
for (uint8 i; i < 6; i++) {
taxBeneficiary storage taxBeneficiarySlot = _taxBeneficiary[i];
address account = taxBeneficiarySlot.account;
if (taxBeneficiarySlot.unclaimed == 0 || account == _dex.pair) { continue; }
uint256 unclaimed = _percentage(address(_taxToken) == address(this) ? _amountForTaxDistribution : _amountSwappedForTaxDistribution, (100 * uint256(_denominator) * taxBeneficiarySlot.unclaimed) / _totalTaxUnclaimed);
uint256 _distributedTaxes = _distribute(account, unclaimed);
if (_distributedTaxes > 0) {
taxBeneficiarySlot.unclaimed -= _distributedTaxes;
distributedTaxes += _distributedTaxes;
}
}
_lastTaxDistribution = _timestamp();
if (distributedTaxes > 0) {
_totalTaxUnclaimed -= distributedTaxes;
emit TaxDistributed(distributedTaxes);
}
}
}
function _distribute(address account, uint256 unclaimed) private returns (uint256) {
if (unclaimed == 0) { return 0; }
unchecked {
if (address(_taxToken) == address(this)) {
if (_maxBalanceAmount > 0 && _balance[account] + unclaimed > _maxBalanceAmount && !_whitelisted[account]) {
unclaimed = _maxBalanceAmount > _balance[account] ? _maxBalanceAmount - _balance[account] : 0;
if (unclaimed == 0) { return 0; }
}
super._transfer(address(this), account, unclaimed);
_amountForTaxDistribution -= unclaimed;
} else {
uint256 percent = (100 * uint256(_denominator) * unclaimed) / _amountSwappedForTaxDistribution;
uint256 amount;
if (address(_taxToken) == _dex.WETH) {
amount = _percentage(_ethForTaxDistribution, percent);
(bool success, ) = payable(account).call{ value: amount, gas: 30000 }("");
if (!success) { return 0; }
_ethForTaxDistribution -= amount;
} else {
amount = _percentage(_tokensForTaxDistribution[address(_taxToken)], percent);
try _taxToken.transfer(account, amount) { _tokensForTaxDistribution[address(_taxToken)] -= amount; } catch { return 0; }
}
_amountSwappedForTaxDistribution -= unclaimed;
}
}
return unclaimed;
}
/// @notice Suspend or reinstate tax collection
/// @dev Also applies to early penalties
/// @param status True to suspend, False to reinstate existent taxes
function suspendTaxes(bool status) external onlyOwner {
require(!_renounced.Taxable);
_suspendTaxes = status;
}
/// @notice Checks if tax collection is currently suspended
function taxesSuspended() external view returns (bool) {
return _suspendTaxes;
}
/// @notice Removes the penalty status of a wallet
/// @param account Address to depenalize
function removePenalty(address account) external onlyOwner {
require(!_renounced.Taxable);
_holder[account].penalty = false;
}
/// @notice Check if a wallet is penalized due to an early transaction
/// @param account Address to check
function isPenalized(address account) external view returns (bool) {
return _holder[account].penalty;
}
/// @notice Returns the period of time during which early buyers will be penalized from the time trading was enabled
function getEarlyPenaltyTime() external view returns (uint32) {
return _earlyPenaltyTime;
}
/// @notice Defines the period of time during which early buyers will be penalized from the time trading was enabled
/// @dev Must be less or equal to 1 hour
/// @param time Time, in seconds
function setEarlyPenaltyTime(uint32 time) external onlyOwner {
require(!_renounced.Taxable);
require(time <= 600);
_setEarlyPenaltyTime(time);
}
function _setEarlyPenaltyTime(uint32 time) internal {
_earlyPenaltyTime = time;
emit SetEarlyPenaltyTime(time);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
import "./CF_Ownable.sol";
abstract contract CF_Whitelist is CF_Common, CF_Ownable {
event Whitelisted(address indexed account, bool status);
event RenouncedWhitelist();
/// @notice Permanently renounce and prevent the owner from being able to update the whitelist
/// @dev Existing entries will continue to be effective
function renounceWhitelist() external onlyOwner {
_renounced.Whitelist = true;
emit RenouncedWhitelist();
}
/// @notice Check if an address is whitelisted
/// @param account Address to check
function isWhitelisted(address account) external view returns (bool) {
return _whitelisted[account];
}
/// @notice Add or remove an address from the whitelist
/// @param status True for adding, False for removing
function whitelist(address account, bool status) public onlyOwner {
_whitelist(account, status);
}
function _whitelist(address account, bool status) internal {
require(!_renounced.Whitelist);
require(account != address(0));
require(account != _dex.router && account != _dex.pair, "DEX router and pair are privileged");
_whitelisted[account] = status;
emit Whitelisted(account, status);
}
/// @notice Add or remove multiple addresses from the whitelist
/// @param status True for adding, False for removing
function whitelist(address[] calldata accounts, bool status) external onlyOwner {
unchecked {
uint256 cnt = accounts.length;
for (uint256 i; i < cnt; i++) { _whitelist(accounts[i], status); }
}
}
function _initialWhitelist(address[1] memory accounts) internal {
require(!_initialized);
unchecked {
for (uint256 i; i < 1; i++) { _whitelist(accounts[i], true); }
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
import "./CF_Ownable.sol";
abstract contract CF_MaxBalance is CF_Common, CF_Ownable {
event SetMaxBalancePercent(uint24 percent);
event RenouncedMaxBalance();
/// @notice Permanently renounce and prevent the owner from being able to update the max. balance
/// @dev Existing settings will continue to be effective
function renounceMaxBalance() external onlyOwner {
_renounced.MaxBalance = true;
emit RenouncedMaxBalance();
}
/// @notice Percentage of the max. balance per wallet, depending on total supply
function getMaxBalancePercent() external view returns (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, 0 to disable)
function setMaxBalancePercent(uint24 percent) external onlyOwner {
require(!_renounced.MaxBalance);
unchecked {
require(percent == 0 || (percent >= 100 && percent <= 100 * _denominator));
}
_setMaxBalancePercent(percent);
emit SetMaxBalancePercent(percent);
}
function _setMaxBalancePercent(uint24 percent) internal {
_maxBalancePercent = percent;
_maxBalanceAmount = percent > 0 ? _percentage(_totalSupply, uint256(percent)) : 0;
if (!_initialized) { emit SetMaxBalancePercent(percent); }
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
import "./CF_Ownable.sol";
import "./CF_ERC20.sol";
abstract contract CF_DEXRouterV2 is CF_Common, CF_Ownable, CF_ERC20 {
event AddedLiquidity(uint256 tokenAmount, uint256 ethAmount, uint256 liquidity);
event SwappedTokensForNative(uint256 tokenAmount, uint256 ethAmount);
event SwappedTokensForTokens(address token, uint256 token0Amount, uint256 token1Amount);
event SetDEXRouterV2(address indexed router, address indexed pair, address receiver);
event TradingEnabled();
event RenouncedDEXRouterV2();
modifier lockSwapping {
_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 effective
function renounceDEXRouterV2() external onlyOwner {
_renounced.DEXRouterV2 = true;
emit RenouncedDEXRouterV2();
}
function _setDEXRouterV2(address router, address receiver) internal returns (address) {
require(router != address(0));
if (_dex.router != router) {
IDEXRouterV2 _router = IDEXRouterV2(router);
IDEXFactoryV2 factory = IDEXFactoryV2(_router.factory());
address WETH = _router.WETH();
address pair = factory.getPair(address(this), WETH);
if (pair == address(0)) { pair = factory.createPair(address(this), WETH); }
_dex = DEXRouterV2(router, pair, WETH, receiver);
}
if (receiver != _dex.receiver) { _dex.receiver = receiver; }
emit SetDEXRouterV2(router, _dex.pair, receiver);
return _dex.pair;
}
/// @notice Returns the DEX router currently in use
function getDEXRouterV2() external view returns (address) {
return _dex.router;
}
/// @notice Returns the trading pair
function getDEXPairV2() external view returns (address) {
return _dex.pair;
}
/// @notice Returns address of the LP tokens receiver
function getLPTokensReceiver() external view returns (address) {
return _dex.receiver;
}
/// @notice Checks whether the token can be traded through the assigned DEX
function isTradingEnabled() external view returns (bool) {
return _tradingEnabled > 0;
}
/// @notice Checks the status of the auto-swapping feature
function isAutoSwapEnabled() external view returns (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 balance
function getAutoSwapPercent() external view returns (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)
function setAutoSwapPercent(uint24 min, uint24 max) external onlyOwner {
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 disable
function enableAutoSwap(bool status) external onlyOwner {
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 reached
function autoSwap() 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 amount
function autoSwap(bool force) external {
require(msg.sender == _owner || _whitelisted[msg.sender], "Unauthorized");
require((force || _autoSwapEnabled) && !_swapping && !_distributing);
_autoSwap(force);
}
function _autoSwap(bool force) internal lockSwapping {
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 = new address[](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) private returns (uint256 tokenAmount) {
uint256 tokenBalance = token.balanceOf(address(this));
address[] memory pathToSwapExactTokensForTokens = new address[](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 amountToken, uint256 amountETH, uint256 liquidity) {
emit AddedLiquidity(amountToken, amountETH, 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 pool
function getAutoAddLiquidityPercent() external view returns (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)
function setAutoAddLiquidityPercent(uint24 min, uint24 max) external onlyOwner {
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 distribution
function getTaxToken() external view returns (address) {
return address(_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 reverted
function enableTrading() external onlyOwner {
require(!_renounced.DEXRouterV2);
require(_tradingEnabled == 0, "Already enabled");
_tradingEnabled = _timestamp();
emit TradingEnabled();
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./CF_Common.sol";
import "./CF_Ownable.sol";
abstract contract CF_Recoverable is CF_Common, CF_Ownable {
/// @notice Recovers a misplaced amount of an ERC-20 token sitting in the contract balance
/// @dev Beware of scam tokens!
/// @dev Note that if the token of this contract is specified, amounts allocated for tax distribution and liquidity are reserved
/// @param token Address of the ERC-20 token
/// @param to Recipient
/// @param amount Amount to be transferred
function recoverERC20(address token, address to, uint256 amount) external onlyOwner {
unchecked {
uint256 balance = IERC20(token).balanceOf(address(this));
uint256 allocated = token == address(this) ? _amountForTaxDistribution + _amountForLiquidity : (address(_taxToken) == token ? _tokensForTaxDistribution[address(_taxToken)] : 0);
require(balance - (allocated >= balance ? balance : allocated) >= amount, "Exceeds balance");
}
IERC20(token).transfer(to, amount);
}
/// @notice Recovers a misplaced amount of native tokens sitting in the contract balance
/// @dev Note that if the reflection token is the wrapped native, amounts allocated for tax distribution and/or liquidity are reserved
/// @param to Recipient
/// @param amount Amount of native tokens to be transferred
function recoverNative(address payable to, uint256 amount) external onlyOwner {
unchecked {
uint256 balance = address(this).balance;
uint256 allocated = address(_taxToken) == _dex.WETH ? _ethForTaxDistribution : 0;
require(balance - (allocated >= balance ? balance : allocated) >= amount, "Exceeds balance");
}
(bool success, ) = to.call{ value: amount }("");
require(success);
}
}