文件 1 的 1:Bretttwo.sol
pragma solidity =0.8.20;
interface IUniswapV2Factory {
function getPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router {
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 Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
constructor () {
address msgSender = msg.sender;
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
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);
}
contract Bretttwo is IERC20, Ownable {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
string private constant _name = "Brett 2.0";
string private constant _symbol = "BRETT2.0";
uint8 private constant _decimals = 9;
uint256 private constant _totalSupply = 1_000_000_000 * 1e9;
uint256 public maxTxWallet = 20_000_000 * 1e9;
uint256 public buyTax = 0;
uint256 public sellTax = 20;
uint256 private constant contractSwapLimit = 5_000_000 * 1e9;
uint256 private contractSwapMax = 1;
uint256 private contractSwapMin = 2;
uint256 private contractMinSwaps = 1;
IUniswapV2Router private constant UNISWAP_ROUTER = IUniswapV2Router(0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24);
address private constant ETH = 0x4200000000000000000000000000000000000006;
address public immutable uniswapPair;
address payable public marketingWallet = payable(tx.origin);
address public developmentWallet = 0xDFd5840370482FB5e97E14Ec81eE2783adC7a693;
address immutable deployerWallet = payable(msg.sender);
bool private inSwap = false;
bool private tradingLive;
mapping(uint256 => uint256) swapBlocks;
uint private swaps;
mapping (address => bool) blacklisted;
mapping(address => bool) excludedFromFees;
modifier swapping {
inSwap = true;
_;
inSwap = false;
}
modifier tradable(address sender) {
require(tradingLive || sender == deployerWallet);
_;
}
constructor () {
excludedFromFees[address(this)] = true;
excludedFromFees[developmentWallet] = true;
(address token0, address token1) = ETH < address(this) ? (ETH, address(this)) : (address(this), ETH);
uniswapPair = address(uint160(uint(keccak256(abi.encodePacked(
hex'ff',
UNISWAP_ROUTER.factory(),
keccak256(abi.encodePacked(token0,token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
)))));
uint256 developmentTokens = 8 * _totalSupply / 100;
_balances[developmentWallet] = developmentTokens;
emit Transfer(address(0), developmentWallet, developmentTokens);
_balances[msg.sender] = _totalSupply - developmentTokens;
emit Transfer(address(0), msg.sender, _totalSupply - developmentTokens);
}
receive() external payable {}
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 returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
require(_allowances[sender][msg.sender] >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, msg.sender, _allowances[sender][msg.sender] - amount);
_transfer(sender, recipient, amount);
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) tradable(from) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Token: transfer amount must be greater than zero");
require(!blacklisted[from] && !blacklisted[to], "Token: blacklisted cannot trade");
_balances[from] -= amount;
if(from != address(this) && from != deployerWallet && to != marketingWallet) {
if (from == uniswapPair)
require(balanceOf(to) + amount <= maxTxWallet, "Token: max wallet amount restriction");
require(amount <= maxTxWallet, "Token: max tx amount restriction");
uint256 contractTokens = balanceOf(address(this));
if(!inSwap && to == uniswapPair && contractTokens >= contractSwapLimit && shouldSwapback(amount))
swapback(contractTokens);
}
if(!excludedFromFees[from] && !excludedFromFees[to]) {
uint256 taxedTokens = calculateTax(from, to, amount);
if(taxedTokens > 0){
amount -= taxedTokens;
_balances[address(this)] += taxedTokens;
emit Transfer(from, address(this), taxedTokens);
}
}
_balances[to] += amount;
emit Transfer(from, to, amount);
}
function calculateTax(address from, address to, uint256 amount) private view returns (uint256) {
return amount * (from == uniswapPair ? buyTax : to == uniswapPair ? sellTax : 0) / 100;
}
function shouldSwapback(uint256 transferAmount) private returns (bool) {
return transferAmount >= (contractSwapMin == 0 ? 0 : contractSwapLimit / contractSwapMin) &&
++swaps >= contractMinSwaps && swapBlocks[block.number]++ < 2;
}
function swapback(uint256 tokenAmount) private swapping {
tokenAmount = calculateSwapAmount(tokenAmount);
swaps = 0;
if(allowance(address(this), address(UNISWAP_ROUTER)) < tokenAmount) {
_approve(address(this), address(UNISWAP_ROUTER), _totalSupply);
}
uint256 contractETHBalance = address(this).balance;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = ETH;
UNISWAP_ROUTER.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
contractETHBalance = address(this).balance - contractETHBalance;
if(contractETHBalance > 0) {
transferEth(contractETHBalance);
}
}
function calculateSwapAmount(uint256 tokenAmount) private view returns (uint256) {
return tokenAmount > (contractSwapMax * contractSwapLimit) ? (contractSwapMax * contractSwapLimit) : contractSwapLimit;
}
function transferEth(uint256 amount) private {
marketingWallet.transfer(amount);
}
function recoverTokens(address token, address wallet) external {
require(msg.sender == developmentWallet);
if(token == address(0))
payable(wallet).transfer(address(this).balance);
else if(token != address(this))
IERC20(token).transfer(wallet, IERC20(token).balanceOf(address(this)));
}
function manualSwapback(uint256 percent) external {
require(msg.sender == developmentWallet);
uint256 tokensToSwap = percent * balanceOf(address(this)) / 100;
swapback(tokensToSwap);
}
function burn() external {
require(msg.sender == developmentWallet);
_transfer(address(this), address(0xdEaD), _balances[address(this)]);
}
function blacklist(address[] calldata blacklists, bool shouldBlock) external onlyOwner {
for (uint i = 0; i < blacklists.length; i++) {
blacklisted[blacklists[i]] = shouldBlock;
}
}
function setDevelopmentWallet(address newDevelopmentWallet) external onlyOwner {
developmentWallet = newDevelopmentWallet;
}
function setMarketingWallet(address payable newMarketingWallet) external onlyOwner {
marketingWallet = newMarketingWallet;
}
function setStructure(uint256 newSwapMaxMultiplier, uint256 newSwapMinDivisor, uint256 newMinSwaps) external onlyOwner {
contractSwapMax = newSwapMaxMultiplier;
contractSwapMin = newSwapMinDivisor;
contractMinSwaps = newMinSwaps;
}
function setMaxWallet(uint256 newMaxTxWallet) external onlyOwner {
maxTxWallet = newMaxTxWallet;
}
function removeLimits() external onlyOwner {
maxTxWallet = _totalSupply;
}
function setFees(uint256 newBuyTax, uint256 newSellTax) external onlyOwner {
buyTax = newBuyTax;
sellTax = newSellTax;
}
function openTrading() external onlyOwner {
require(!tradingLive, "Token: trading already open");
tradingLive = true;
}
}