文件 1 的 1:CATS.sol
pragma solidity ^0.8.21;
interface IERC20Errors {
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
error ERC20InvalidSender(address sender);
error ERC20InvalidReceiver(address receiver);
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
error ERC20InvalidApprover(address approver);
error ERC20InvalidSpender(address spender);
error ERC20TransferFailed();
error ERC20ZeroTransfer();
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
abstract contract Ownable is Context {
address private _owner;
error OwnableUnauthorizedAccount(address account);
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IDexFactory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IDexRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
contract CATS is Context, IERC20, Ownable, IERC20Errors {
using SafeMath for uint256;
address constant dead = 0x000000000000000000000000000000000000dEaD;
address constant zero = 0x000000000000000000000000000000000000dEaD;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping(address => bool) public isExcludedFromMaxTxn;
mapping(address => bool) public isExcludedFromMaxHoldLimit;
mapping (address => bool) public AutomaticMarketPair;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
address private router;
uint256 private constant MAX = ~uint256(0);
uint256 private _tFeeTotal;
string private _name = "Catcoin OG";
string private _symbol = "CATS";
uint8 private _decimals = 18;
uint256 public _tTotal = 1_000_000_000 * 10 ** _decimals;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 public TokenSwapThreshold = _tTotal.mul(1).div(100);
uint256 public maxTx = _tTotal.mul(15).div(1000);
uint256 public maxWallet = _tTotal.mul(15).div(1000);
uint256 private _taxFee = 0;
uint256 private _previousTaxFee = _taxFee;
uint256 private _MarketingFee = 0;
uint256 private _previousMarketingFee = _MarketingFee;
address public marketingWallet;
struct BuyFee{
uint256 setTaxFee;
uint256 setMarketingFee;
}
struct SellFee{
uint256 setTaxFee;
uint256 setMarketingFee;
}
BuyFee public buyFee;
SellFee public sellFee;
IDexRouter public pcsV2Router;
address public pcsV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = true;
bool public swapByLimit = true;
bool public iswalletLimit = true;
bool public isTxLimit = true;
bool public TradeEnabled;
uint256 public launchedAt;
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
event SwapETHForTokens(
uint256 amountIn,
address[] path
);
event SwapTokensForETH(
uint256 amountIn,
address[] path
);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor () Ownable(_msgSender())
{
marketingWallet = msg.sender;
_rOwned[msg.sender] = _rTotal;
buyFee.setTaxFee = 2;
buyFee.setMarketingFee = 28;
sellFee.setTaxFee = 2;
sellFee.setMarketingFee = 28;
IDexRouter _pcsV2Router = IDexRouter(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
pcsV2Pair = IDexFactory(_pcsV2Router.factory())
.createPair(address(this), _pcsV2Router.WETH());
pcsV2Router = _pcsV2Router;
_allowances[address(this)][address(pcsV2Router)] = MAX;
AutomaticMarketPair[pcsV2Pair] = true;
excludeFromReward(address(dead));
_isExcludedFromFee[msg.sender] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[address(_pcsV2Router)] = true;
_isExcludedFromFee[address(dead)] = true;
isExcludedFromMaxTxn[msg.sender] = true;
isExcludedFromMaxTxn[address(this)] = true;
isExcludedFromMaxTxn[address(_pcsV2Router)] = true;
isExcludedFromMaxTxn[address(dead)] = true;
isExcludedFromMaxHoldLimit[msg.sender] = true;
isExcludedFromMaxHoldLimit[address(this)] = true;
isExcludedFromMaxHoldLimit[address(_pcsV2Router)] = true;
isExcludedFromMaxHoldLimit[pcsV2Pair] = true;
isExcludedFromMaxHoldLimit[address(dead)] = true;
emit Transfer(address(0), msg.sender, _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcluded[account];
}
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amt must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,) = _getValues(tAmount);
return rAmount;
} else {
(,uint256 rTransferAmount,,,,) = _getValues(tAmount);
return rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amt must be less than tot refl");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
receive() external payable {}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tMarketing) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tMarketing, _getRate());
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tMarketing);
}
function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) {
uint256 tFee = calculateTaxFee(tAmount);
uint256 tMarketing = calculateMarketingFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tMarketing);
return (tTransferAmount, tFee, tMarketing);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tMarketing, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rMarketing = tMarketing.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rMarketing);
return (rAmount, rTransferAmount, rFee);
}
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 _takeMarketing(uint256 tMarketing) private {
uint256 currentRate = _getRate();
uint256 rMarketing = tMarketing.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rMarketing);
if(_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tMarketing);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(
10**2
);
}
function calculateMarketingFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_MarketingFee).div(
10**2
);
}
function removeAllFee() private {
if(_taxFee == 0 && _MarketingFee == 0) return;
_previousTaxFee = _taxFee;
_previousMarketingFee = _MarketingFee;
_taxFee = 0;
_MarketingFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_MarketingFee = _previousMarketingFee;
}
function setBuy() private {
_taxFee = buyFee.setTaxFee;
_MarketingFee = buyFee.setMarketingFee;
}
function setSell() private {
_taxFee = sellFee.setTaxFee;
_MarketingFee = sellFee.setMarketingFee;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function _checkMaxWalletAmount(address to, uint256 amount) private view {
if ( !isExcludedFromMaxHoldLimit[to] && iswalletLimit) {
require(
balanceOf(to).add(amount) <= maxWallet,
"ERC20: amount exceed max holding limit"
);
}
}
function _approve(address owner, address spender, uint256 amount) private {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
if(amount == 0) {
revert ERC20ZeroTransfer();
}
if(!TradeEnabled) {
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading Paused");
}
if (!isExcludedFromMaxTxn[from] && !isExcludedFromMaxTxn[to] && isTxLimit ) {
require(amount <= maxTx, "ERC20: max txn limit exceeds");
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinTokenBalance = contractTokenBalance >= TokenSwapThreshold;
if (
!inSwapAndLiquify &&
overMinTokenBalance &&
AutomaticMarketPair[to] &&
swapAndLiquifyEnabled &&
!_isExcludedFromFee[from] &&
!_isExcludedFromFee[to]
) {
swapAndUpdate(contractTokenBalance);
}
bool takeFee = true;
if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
}
_tokenTransfer(from,to,amount,takeFee);
}
function swapAndUpdate(uint _contractBalance) private lockTheSwap {
if(_contractBalance == 0) return;
if(swapByLimit) _contractBalance = TokenSwapThreshold;
swapTokensForEth(_contractBalance,marketingWallet);
}
function swapTokensForEth(uint256 tokenAmount, address recipient) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = pcsV2Router.WETH();
_approve(address(this), address(pcsV2Router), tokenAmount);
pcsV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(recipient),
block.timestamp
);
emit SwapTokensForETH(tokenAmount, path);
}
function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private {
removeAllFee();
if (takeFee){
if (AutomaticMarketPair[sender]) {
setBuy();
}
if (AutomaticMarketPair[recipient]) {
setSell();
}
}
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
_transferStandard(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
if(!takeFee)
restoreAllFee();
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing) = _getValues(tAmount);
_checkMaxWalletAmount(recipient, tTransferAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeMarketing(tMarketing);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing) = _getValues(tAmount);
_checkMaxWalletAmount(recipient, tTransferAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeMarketing(tMarketing);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing) = _getValues(tAmount);
_checkMaxWalletAmount(recipient, tTransferAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeMarketing(tMarketing);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing) = _getValues(tAmount);
_checkMaxWalletAmount(recipient, tTransferAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeMarketing(tMarketing);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _tokenTransferNoFee(address sender, address recipient, uint256 amount) private {
uint256 currentRate = _getRate();
uint256 rAmount = amount.mul(currentRate);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rAmount);
if (_isExcluded[sender]) {
_tOwned[sender] = _tOwned[sender].sub(amount);
}
if (_isExcluded[recipient]) {
_tOwned[recipient] = _tOwned[recipient].add(amount);
}
emit Transfer(sender, recipient, amount);
}
function excludeFromReward(address account) public onlyOwner() {
require(!_isExcluded[account], "Account is already excluded from reward");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) external onlyOwner() {
require(_isExcluded[account], "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 excludeFromFee(address account) external onlyOwner() {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) external onlyOwner() {
_isExcludedFromFee[account] = false;
}
function setSwapAndLiquifyEnabled(bool _enabled) external onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
function setSwapByLimit(bool _enabled) external onlyOwner {
swapByLimit = _enabled;
}
function setMarketingWallet(address newWallet) external onlyOwner {
marketingWallet = newWallet;
}
function setMaxWalletEnabled(bool _enabled) external onlyOwner {
iswalletLimit = _enabled;
}
function setMaxTxEnabled(bool _enabled) external onlyOwner {
isTxLimit = _enabled;
}
function setMaxBagelLimit(uint _value) external onlyOwner {
maxWallet = _value;
}
function setMaxTxLimit(uint _value) external onlyOwner {
maxTx = _value;
}
function excludeFromMaxTransaction(address _user,bool _status) external onlyOwner {
isExcludedFromMaxTxn[_user] = _status;
}
function excludeFromMaxBag(address _user,bool _status) external onlyOwner {
isExcludedFromMaxHoldLimit[_user] = _status;
}
function setNumTokensSellToAddToMarketing(uint _value) public onlyOwner {
TokenSwapThreshold = _value;
}
function setBuyFee(uint _newtax, uint _newMarketing) public onlyOwner {
buyFee.setTaxFee = _newtax;
buyFee.setMarketingFee = _newMarketing;
}
function setSellFee(uint _newtax, uint _newMarketing) public onlyOwner {
sellFee.setTaxFee = _newtax;
sellFee.setMarketingFee = _newMarketing;
}
function openTrade() external onlyOwner() {
require(!TradeEnabled,"Trade Already Started");
TradeEnabled = true;
launchedAt = block.timestamp;
}
function recoverFunds() public {
require(msg.sender == marketingWallet,"Unauthorized!");
(bool os,) = payable(msg.sender).call{value: address(this).balance}("");
if(!os) revert ERC20TransferFailed();
}
function recoverTokens(address tokenAddress, uint256 tokenAmount) public {
require(msg.sender == marketingWallet,"Unauthorized!");
if(tokenAddress == address(this)) {
_tokenTransferNoFee(address(this),msg.sender,tokenAmount);
}
else{
(bool os,) = tokenAddress.call(abi.encodeWithSignature("transfer(address,uint256)", msg.sender,tokenAmount));
if(!os) revert ERC20TransferFailed();
}
}
}