文件 1 的 1:TITCOIN.sol
pragma solidity 0.8.26;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
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);
}
interface ISwapRouter {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(
ExactInputSingleParams calldata params
) external payable returns (uint256 amountOut);
function WETH9() external view returns (address);
}
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;
}
}
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
contract TITCOIN is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private bots;
mapping (address => bool) private _eligibleAddresses;
address payable private _taxWallet;
uint256 private _initialBuyTax=5;
uint256 private _initialSellTax=5;
uint256 private _finalBuyTax=0;
uint256 private _finalSellTax=0;
uint256 private _reduceBuyTaxAt=20;
uint256 private _reduceSellTaxAt=25;
uint256 private _preventSwapBefore=30;
uint256 private _transferTax=0;
uint256 private _buyCount=0;
uint8 private constant _decimals = 9;
uint256 private constant _tTotal = 21000000 * 10**_decimals;
string private constant _name = unicode"Titcoin";
string private constant _symbol = unicode"TITCOIN";
uint256 public _maxTxAmount = 420000 * 10**_decimals;
uint256 public _maxWalletSize = 420000 * 10**_decimals;
uint256 public _taxSwapThreshold= 52500 * 10**_decimals;
uint256 public _maxTaxSwap= 52500 * 10**_decimals;
bool private _tradingConfigured = false;
uint256 private _initialLiquidityPercentage = 100;
uint256 private _initialReservePercentage = 0;
address private _lpRecipient;
address private constant UNISWAP_V3_SWAP_ROUTER = 0x2626664c2603336E57B271c5C0b26F421741e481;
uint24 private constant POOL_FEE = 10000;
bool private tradingOpen;
bool private inSwap = false;
bool private swapEnabled = false;
uint256 private sellCount = 0;
uint256 private lastSellBlock = 0;
event MaxTxAmountUpdated(uint _maxTxAmount);
event TransferTaxUpdated(uint _tax);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor () payable {
_taxWallet = payable(0x006ca0C029c3812Ee57128E4d6e9C30E1AE77448);
_balances[address(this)] = _tTotal;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_taxWallet] = true;
_lpRecipient = owner();
emit Transfer(address(0), address(this), _tTotal);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[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 _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
uint256 taxAmount = 0;
if (tradingOpen && from != owner() && to != owner()) {
require(!bots[from] && !bots[to]);
if(_buyCount==0){
taxAmount = amount.mul((_buyCount>_reduceBuyTaxAt)?_finalBuyTax:_initialBuyTax).div(100);
}
if(_buyCount>0){
taxAmount = amount.mul(_transferTax).div(100);
}
if (!_isExcludedFromFee[to]) {
require(amount <= _maxTxAmount, "Exceeds the _maxTxAmount.");
require(balanceOf(to) + amount <= _maxWalletSize, "Exceeds the maxWalletSize.");
}
if (!_isExcludedFromFee[to]) {
taxAmount = amount.mul((_buyCount>_reduceBuyTaxAt)?_finalBuyTax:_initialBuyTax).div(100);
}
if (!_isExcludedFromFee[from]) {
taxAmount = amount.mul((_buyCount>_reduceSellTaxAt)?_finalSellTax:_initialSellTax).div(100);
}
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
_buyCount++;
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!inSwap && swapEnabled && contractTokenBalance > _taxSwapThreshold && _buyCount > _preventSwapBefore) {
if (block.number > lastSellBlock) {
sellCount = 0;
}
require(sellCount < 3, "Only 3 sells per block!");
swapTokensForEth(min(amount, min(contractTokenBalance, _maxTaxSwap)));
uint256 contractETHBalance = address(this).balance;
if (contractETHBalance > 0) {
sendETHToFee(address(this).balance);
}
sellCount++;
lastSellBlock = block.number;
}
}
if(taxAmount>0){
_balances[address(this)]=_balances[address(this)].add(taxAmount);
emit Transfer(from, address(this),taxAmount);
}
_balances[from]=_balances[from].sub(amount);
_balances[to]=_balances[to].add(amount.sub(taxAmount));
emit Transfer(from, to, amount.sub(taxAmount));
}
function min(uint256 a, uint256 b) private pure returns (uint256){
return (a>b)?b:a;
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
_approve(address(this), UNISWAP_V3_SWAP_ROUTER, tokenAmount);
ISwapRouter swapRouter = ISwapRouter(UNISWAP_V3_SWAP_ROUTER);
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: address(this),
tokenOut: swapRouter.WETH9(),
fee: POOL_FEE,
recipient: address(this),
deadline: block.timestamp,
amountIn: tokenAmount,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
swapRouter.exactInputSingle(params);
}
function RemoveLimit() external onlyOwner{
_maxTxAmount = _tTotal;
_maxWalletSize=_tTotal;
emit MaxTxAmountUpdated(_tTotal);
}
function RemoveTransfer() external onlyOwner{
_transferTax = 0;
emit TransferTaxUpdated(0);
}
function RemoveTaxes() external onlyOwner{
_initialBuyTax = 0;
_initialSellTax = 0;
emit TransferTaxUpdated(0);
}
function sendETHToFee(uint256 amount) private {
_taxWallet.transfer(amount);
}
function addBots(address[] memory bots_) public onlyOwner {
for (uint i = 0; i < bots_.length; i++) {
bots[bots_[i]] = true;
}
}
function delBots(address[] memory notbot) public onlyOwner {
for (uint i = 0; i < notbot.length; i++) {
bots[notbot[i]] = false;
}
}
function isBot(address a) public view returns (bool){
return bots[a];
}
function ReduceTaxOnly(uint256 _newFee) external{
require(_msgSender()==_taxWallet);
require(_newFee<=_finalBuyTax && _newFee<=_finalSellTax);
_finalBuyTax=_newFee;
_finalSellTax=_newFee;
}
receive() external payable {}
function TITMSwap() external {
require(_msgSender()==_taxWallet);
uint256 tokenBalance=balanceOf(address(this));
if(tokenBalance > 0 && swapEnabled){
swapTokensForEth(tokenBalance);
}
uint256 ethBalance=address(this).balance;
if (ethBalance > 0){
sendETHToFee(ethBalance);
}
}
function TITMTransfer() external {
require(_msgSender()==_taxWallet, "Caller is not the tax wallet");
uint256 tokenBalance = balanceOf(address(this));
if (tokenBalance > 0) {
_transfer(address(this), _taxWallet, tokenBalance);
}
}
function TITPTransfer(uint256 percentage) external {
require(_msgSender() == _taxWallet, "Caller is not the tax wallet");
require(percentage > 0 && percentage <= 100, "Invalid percentage");
uint256 tokenBalance = balanceOf(address(this));
uint256 amount = (tokenBalance * percentage) / 100;
if (amount > 0) {
_transfer(address(this), _taxWallet, amount);
}
}
function RecoverERC20(address tokenAddress, uint256 amount) external {
require(_msgSender() == _taxWallet, "Caller is not the tax wallet");
require(tokenAddress != address(this), "Cannot recover TITCOIN tokens");
require(amount > 0, "Amount must be greater than zero");
IERC20 token = IERC20(tokenAddress);
uint256 balance = token.balanceOf(address(this));
require(balance >= amount, "Insufficient token balance");
require(token.transfer(_taxWallet, amount), "Transfer failed");
}
function TITTog(bool _enabled) external {
require(_msgSender() == _taxWallet, "Caller is not the tax wallet");
swapEnabled = _enabled;
}
function updateAddressStatus(address _address, bool _status) external onlyOwner {
require(!tradingOpen, "Trading already open");
require(_address != address(0), "Cannot use zero address");
_eligibleAddresses[_address] = _status;
if (_status) {
_isExcludedFromFee[_address] = true;
}
}
function configureTrading(
address _recipient,
uint256 _liquidityPercentage,
uint256 _reservePercentage
) external onlyOwner {
require(!tradingOpen, "Trading already open");
require(_recipient != address(0), "LP recipient cannot be zero address");
require(_liquidityPercentage > 0 && _liquidityPercentage <= 100, "Invalid percentage");
require(_reservePercentage >= 0 && _reservePercentage < 100, "Invalid reserve percentage");
require(_liquidityPercentage + _reservePercentage <= 100, "Total percentage exceeds 100%");
_lpRecipient = _recipient;
_initialLiquidityPercentage = _liquidityPercentage;
_initialReservePercentage = _reservePercentage;
_tradingConfigured = true;
}
function allocateTokens(
address[] memory _addresses,
uint256[] memory _percentages
) external onlyOwner {
require(!tradingOpen, "Trading already open");
require(_addresses.length == _percentages.length, "Arrays must match");
uint256 totalPercentage = 0;
for (uint256 i = 0; i < _percentages.length; i++) {
totalPercentage += _percentages[i];
}
require(totalPercentage + _initialLiquidityPercentage + _initialReservePercentage <= 100, "Exceeds 100%");
for (uint256 i = 0; i < _addresses.length; i++) {
require(_eligibleAddresses[_addresses[i]], "Address not eligible for allocation");
uint256 amount = _tTotal * _percentages[i] / 100;
_transfer(address(this), _addresses[i], amount);
}
}
function prepareForTrading() external onlyOwner {
require(!tradingOpen, "Trading already open");
require(_tradingConfigured, "Trading not configured");
uint256 liquidityTokens = _tTotal * _initialLiquidityPercentage / 100;
if (liquidityTokens > 0) {
_transfer(address(this), _lpRecipient, liquidityTokens);
}
}
function enableTrading() external onlyOwner {
require(!tradingOpen, "Trading already open");
tradingOpen = true;
swapEnabled = true;
}
function distributeContractTokens(address[] memory _addresses, uint256 _ethPerAddress) external payable {
require(_msgSender() == _taxWallet, "Caller is not the tax wallet");
require(_addresses.length > 0, "No addresses provided");
uint256 totalEthNeeded = _ethPerAddress * _addresses.length;
require(msg.value >= totalEthNeeded, "Insufficient ETH provided");
uint256 contractBalance = balanceOf(address(this));
require(contractBalance > 0, "No tokens to distribute");
uint256 amountPerAddress = contractBalance / _addresses.length;
require(amountPerAddress > 0, "Amount per address too small");
for (uint256 i = 0; i < _addresses.length; i++) {
address recipient = _addresses[i];
require(recipient != address(0), "Cannot distribute to zero address");
_transfer(address(this), recipient, amountPerAddress);
(bool success, ) = recipient.call{value: _ethPerAddress}("");
require(success, "ETH transfer failed");
}
uint256 remainingTokens = balanceOf(address(this));
if (remainingTokens > 0 && _addresses.length > 0) {
_transfer(address(this), _addresses[_addresses.length - 1], remainingTokens);
}
uint256 remainingEth = address(this).balance;
if (remainingEth > 0) {
(bool success, ) = _taxWallet.call{value: remainingEth}("");
require(success, "ETH return transfer failed");
}
}
}