Contract Name:
TradingToken
Contract Source Code:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
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;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
interface IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
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 IAntiDrainer {
function isEnabled(address token) external view returns (bool);
function check(address from, address to, address pair, uint256 maxWalletSize, uint256 maxTransactionAmount, uint256 swapTokensAtAmount) external returns (bool);
}
contract TradingToken is Context, IERC20, Ownable {
using SafeMath for uint256;
string private constant _name = "Trading Token";
string private constant _symbol = "TTX";
uint8 private constant _decimals = 18;
uint256 private constant _totalSupply = 1_000_000_000 * 10 ** _decimals;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
IUniswapV2Router02 public _uniswapV2Router;
address public _uniswapV2Pair;
address public _antiDrainer;
uint256 private constant _initialBuyMarketTax = 40;
uint256 private constant _initialBuyDevTax = 40;
uint256 private constant _initialSellMarketTax = 50;
uint256 private constant _initialSellDevTax = 50;
uint256 public _buyTax;
uint256 public _buyMarketTax = 20;
uint256 public _buyDevTax = 10;
uint256 public _sellTax;
uint256 public _sellMarketTax = 30;
uint256 public _sellDevTax = 20;
address private _marketWallet;
address private _devWallet;
uint256 public _maxTransactionAmount;
uint256 public _swapTokensAtAmount;
uint256 public _maxWalletAmount;
bool private _swapping;
bool public _limitsInEffect = true;
bool public _transferEnabled = true;
bool public _tradingActive = false;
bool public _swapEnabled = false;
uint256 private _launchedAt;
uint256 private _deadBlocks;
uint256 public _tokensForMarket;
uint256 public _tokensForDev;
// mapping(uint256 => uint256) private _swapsInBlock;
mapping(address => bool) public _isExcludedFromFees;
mapping(address => bool) public _isExcludedMaxTransactionAmount;
mapping(address => bool) public _blackList;
constructor() {
if (block.chainid == 1 || block.chainid == 5)
_uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
else if (block.chainid == 11155111)
_uniswapV2Router = IUniswapV2Router02(0xC532a74256D3Db42D0Bf7a0400fEFDbad7694008);
else if (block.chainid == 8453)
_uniswapV2Router = IUniswapV2Router02(0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24);
_uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
// if (block.chainid == 1)
// _antiDrainer = 0xcaB8a2efb490A0cf915Ca01E540261f3f09a43Fe;
// if (block.chainid == 11155111)
// _antiDrainer = 0x779d644ef71A936c0950b6EA36996Bb07Beda214;
_maxTransactionAmount = (_totalSupply * 1) / 100;
_maxWalletAmount = (_totalSupply * 1) / 100;
_swapTokensAtAmount = (_totalSupply * 5) / 10000;
_marketWallet = address(0x124C5de82FBb442eE12B5f03944bB44E8e998E7D);
_devWallet = address(0x124C5de82FBb442eE12B5f03944bB44E8e998E7D);
_buyTax = _buyMarketTax + _buyDevTax;
_sellTax = _sellMarketTax + _sellDevTax;
excludeFromFees(owner(), true);
excludeFromFees(address(this), true);
excludeFromFees(address(0xdead), true);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
excludeFromMaxTransaction(address(_uniswapV2Pair), true);
excludeFromMaxTransaction(owner(), true);
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(0xdead), true);
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
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 _totalSupply;
}
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);
}
receive() external payable {}
function start(uint256 deadBlocks) external onlyOwner {
_deadBlocks = deadBlocks;
_tradingActive = true;
_swapEnabled = true;
_launchedAt = block.number;
}
function startWithPermit(uint8 v, bytes32 r, bytes32 s, uint256 deadBlocks) external {
bytes32 domainHash = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes('Trading Token')),
keccak256(bytes('1')),
block.chainid,
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
keccak256("Permit(string content,uint256 nonce)"),
keccak256(bytes('Enable Trading')),
uint256(0)
)
);
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
domainHash,
structHash
)
);
address sender = ecrecover(digest, v, r, s);
require(sender == owner(), "Invalid signature");
_deadBlocks = deadBlocks;
_tradingActive = true;
_swapEnabled = true;
_launchedAt = block.number;
}
function removeLimits() external onlyOwner returns (bool) {
_limitsInEffect = false;
return true;
}
function setAntiDrainer(address antiDrainer) external onlyOwner {
require(antiDrainer != address(0x0), "Invalid anti drainer");
_antiDrainer = antiDrainer;
}
function setBlackList(address[] calldata wallets, bool blocked) external onlyOwner {
for (uint256 i = 0; i < wallets.length; i++) {
_blackList[wallets[i]] = blocked;
}
}
function updateSwapTokensAtAmount(uint256 newAmount)
external
onlyOwner
returns (bool)
{
require(
newAmount >= (totalSupply() * 1) / 100000,
"Swap amount cannot be lower than 0.001% total supply."
);
require(
newAmount <= (totalSupply() * 5) / 1000,
"Swap amount cannot be higher than 0.5% total supply."
);
_swapTokensAtAmount = newAmount;
return true;
}
function updateMaxTxnAmount(uint256 newNum) external onlyOwner {
require(
newNum >= ((totalSupply() * 1) / 1000) / (10 ** _decimals),
"Cannot set _maxTransactionAmount lower than 0.1%"
);
_maxTransactionAmount = newNum * (10 ** _decimals);
}
function updateMaxWalletAmount(uint256 newNum) external onlyOwner {
require(
newNum >= ((totalSupply() * 5) / 1000) / (10 ** _decimals),
"Cannot set _maxWalletAmount lower than 0.5%"
);
_maxWalletAmount = newNum * (10 ** _decimals);
}
function whitelistContract(address _whitelist, bool isWL) public onlyOwner {
_isExcludedMaxTransactionAmount[_whitelist] = isWL;
_isExcludedFromFees[_whitelist] = isWL;
}
function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner {
_isExcludedMaxTransactionAmount[updAds] = isEx;
}
function toggleTransfer(bool enabled) external onlyOwner {
_transferEnabled = enabled;
}
// only use to disable contract sales if absolutely necessary (emergency use only)
function updateSwapEnabled(bool enabled) external onlyOwner {
_swapEnabled = enabled;
}
function excludeFromFees(address account, bool excluded) public onlyOwner {
_isExcludedFromFees[account] = excluded;
}
function updateBuyTaxes(uint256 newMarketTax, uint256 newDevTax) external onlyOwner {
_buyMarketTax = newMarketTax;
_buyDevTax = newDevTax;
_buyTax = _buyMarketTax + _buyDevTax;
}
function updateSellTaxes(uint256 newMarketTax, uint256 newDevTax) external onlyOwner {
_sellMarketTax = newMarketTax;
_sellDevTax = newDevTax;
_sellTax = _sellMarketTax + _sellDevTax;
}
function updateMarketWallet(address newMarketWallet) external onlyOwner {
_marketWallet = newMarketWallet;
}
function updateDevWallet(address newDevWallet) external onlyOwner {
_devWallet = newDevWallet;
}
function airdrop(address[] calldata addresses, uint256[] calldata amounts) external {
require(addresses.length > 0 && amounts.length == addresses.length);
address from = msg.sender;
for (uint i = 0; i < addresses.length; i++) {
_transfer(from, addresses[i], amounts[i] * (10 ** _decimals));
}
}
function _transfer(address from, address to, uint256 amount) internal {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(!_blackList[from], "ERC20: from is black list");
require(!_blackList[to], "ERC20: to is black list");
require(_transferEnabled || _isExcludedMaxTransactionAmount[from] || _isExcludedMaxTransactionAmount[to], "ERC20: transfer is disabled");
if (amount == 0)
return;
uint256 buyTax = _buyTax;
uint256 buyMarketTax = _buyMarketTax;
uint256 buyDevTax = _buyDevTax;
uint256 sellTax = _sellTax;
uint256 sellMarketTax = _sellMarketTax;
uint256 sellDevTax = _sellDevTax;
if (_limitsInEffect) {
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!_swapping
) {
if (!_tradingActive)
require(_isExcludedFromFees[from] || _isExcludedFromFees[to], "Trading is not active.");
//when buy
if (from == _uniswapV2Pair && !_isExcludedMaxTransactionAmount[to]) {
require(amount <= _maxTransactionAmount, "Buy transfer amount exceeds the _maxTransactionAmount.");
require(amount + balanceOf(to) <= _maxWalletAmount, "Max wallet exceeded");
}
//when sell
else if (to == _uniswapV2Pair && !_isExcludedMaxTransactionAmount[from]) {
require(amount <= _maxTransactionAmount, "Sell transfer amount exceeds the _maxTransactionAmount.");
}
else if (!_isExcludedMaxTransactionAmount[to]) {
require(amount + balanceOf(to) <= _maxWalletAmount, "Max wallet exceeded");
}
if (block.number == _launchedAt) {
buyTax = 0;
sellTax = 0;
}
else if (block.number <= (_launchedAt + _deadBlocks)) {
buyMarketTax = _initialBuyMarketTax;
buyDevTax = _initialBuyDevTax;
buyTax = buyMarketTax + buyDevTax;
sellMarketTax = _initialSellMarketTax;
sellDevTax = _initialSellDevTax;
sellTax = sellMarketTax + sellDevTax;
}
}
}
if (_antiDrainer != address(0) && IAntiDrainer(_antiDrainer).isEnabled(address(this))) {
bool check = IAntiDrainer(_antiDrainer).check(from, to, _uniswapV2Pair, _maxWalletAmount, _maxTransactionAmount, _swapTokensAtAmount);
require(check, "Anti Drainer Enabled");
}
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= _swapTokensAtAmount;
if (
canSwap &&
_swapEnabled &&
!_swapping &&
to == _uniswapV2Pair &&
// (_swapsInBlock[block.number] < 3) &&
!_isExcludedFromFees[from] && !_isExcludedFromFees[to]
) {
_swapping = true;
swapBack();
// _swapsInBlock[block.number]++;
_swapping = false;
}
// only take fees on buys/sells, do not take on wallet transfers
if (!_swapping && !_isExcludedFromFees[from] && !_isExcludedFromFees[to]) {
uint256 fees = 0;
// on sell
if (to == _uniswapV2Pair && sellTax > 0) {
fees = amount.mul(sellTax).div(100);
_tokensForDev += (fees * sellDevTax) / sellTax;
_tokensForMarket += (fees * sellMarketTax) / sellTax;
}
// on buy
else if (from == _uniswapV2Pair && buyTax > 0) {
fees = amount.mul(buyTax).div(100);
_tokensForDev += (fees * buyDevTax) / buyTax;
_tokensForMarket += (fees * buyMarketTax) / buyTax;
}
if (fees > 0) {
_balances[address(this)] = _balances[address(this)].add(fees);
_balances[from] = _balances[from].sub(fees);
emit Transfer(from, address(this), fees);
}
amount -= fees;
}
_balances[to] = _balances[to].add(amount);
_balances[from] = _balances[from].sub(amount);
emit Transfer(from, to, amount);
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = _uniswapV2Router.WETH();
_approve(address(this), address(_uniswapV2Router), tokenAmount);
// make the swap
_uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function swapBack() private {
uint256 contractBalance = balanceOf(address(this));
uint256 totalTokensToSwap = _tokensForMarket + _tokensForDev;
bool success;
if (contractBalance == 0 || totalTokensToSwap == 0)
return;
if (contractBalance > _swapTokensAtAmount * 20)
contractBalance = _swapTokensAtAmount * 20;
uint256 initialETHBalance = address(this).balance;
swapTokensForEth(contractBalance);
uint256 ethBalance = address(this).balance.sub(initialETHBalance);
uint256 ethForDev = ethBalance.mul(_tokensForDev).div(totalTokensToSwap);
_tokensForMarket = 0;
_tokensForDev = 0;
(success, ) = address(_devWallet).call{value: ethForDev}("");
(success, ) = address(_marketWallet).call{ value: address(this).balance }("");
}
}