文件 1 的 1:Coin.sol
pragma solidity ^0.8.9;
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);
}
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 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;
}
interface IUniswapV2Pair {
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
function burn(address to) external returns (uint amount0, uint amount1);
function transferFrom(address from, address to, uint value) external returns (bool);
function balanceOf(address owner) external view returns (uint);
function totalSupply() external view returns (uint256);
}
interface IERC20Metadata is IERC20 {
function name() external view returns(string memory);
function symbol() external view returns(string memory);
function decimals() external view returns(uint8);
}
abstract contract Context {
function _msgSender() internal view virtual returns(address) {
return msg.sender;
}
}
contract ERC20 is Context, IERC20, IERC20Metadata {
using SafeMath for uint256;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string public _name;
string public _symbol;
uint8 public _decimals;
constructor(string memory name_, string memory symbol_, uint8 decimals_) {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
}
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 _decimals;
}
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 recipient, uint256 amount) public virtual override returns(bool) {
_transfer(_msgSender(), recipient, 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) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns(bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns(bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns(bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased cannot be below zero"));
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns(uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns(uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns(uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns(uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns(uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns(uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns(address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() internal virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) internal virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
library SafeMathInt {
int256 private constant MIN_INT256 = int256(1) << 255;
int256 private constant MAX_INT256 = ~(int256(1) << 255);
function mul(int256 a, int256 b) internal pure returns(int256) {
int256 c = a * b;
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
}
function div(int256 a, int256 b) internal pure returns(int256) {
require(b != -1 || a != MIN_INT256);
return a / b;
}
function sub(int256 a, int256 b) internal pure returns(int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a));
return c;
}
function add(int256 a, int256 b) internal pure returns(int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
}
function abs(int256 a) internal pure returns(int256) {
require(a != MIN_INT256);
return a < 0 ? -a : a;
}
function toUint256Safe(int256 a) internal pure returns(uint256) {
require(a >= 0);
return uint256(a);
}
}
library SafeMathUint {
function toInt256Safe(uint256 a) internal pure returns(int256) {
int256 b = int256(a);
require(b >= 0);
return b;
}
}
interface FactoryContract {
function devWallet() external view returns(address);
function feeAmount() external view returns(uint256);
function owner() external view returns(address);
}
contract Coin is ERC20, Ownable {
using SafeMath for uint256;
address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;
address public constant ROUTER_ADDRESS = 0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24;
string public _description;
address payable public devWallet;
string public logoUrl;
string public bannerUrl;
string website;
string telegram;
string discord;
string twitter;
uint256 public lpETHAmount;
bool public lpCreated;
uint256 public lpBurnAmount;
address public poolAddress;
bool public renounced;
bool basic;
bool silver;
bool gold;
bool platinum;
FactoryContract public factoryContract;
event renouncedOwnership(address indexed token);
event lpCreatedEvent(address indexed token);
event lpBurnedEvent(address indexed token);
constructor(
address wallet,
string [] memory tokenDatas,
uint256 supply,
uint8 decimals,
address factoryAddress
) ERC20(tokenDatas[0], tokenDatas[1], decimals) {
transferOwnership(wallet);
_name = tokenDatas[0];
_symbol = tokenDatas[1];
_description = tokenDatas[2];
logoUrl = tokenDatas[3];
bannerUrl = tokenDatas[4];
website = tokenDatas[5];
telegram = tokenDatas[6];
discord = tokenDatas[7];
twitter = tokenDatas[8];
uint256 totalSupply = supply * (10 ** decimals);
_mint(wallet, totalSupply);
factoryContract = FactoryContract(factoryAddress);
}
receive() external payable {
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal override {
if (amount == 0) {
super._transfer(sender, recipient, 0);
return;
}
super._transfer(sender, recipient, amount);
}
function _renounceOwnership() public payable onlyOwner {
uint256 feeAmount = FactoryContract(factoryContract).feeAmount();
address feeAddress = FactoryContract(factoryContract).devWallet();
require(msg.value == feeAmount, "You should send ETH for this method");
payable(feeAddress).transfer(msg.value);
renounceOwnership();
emit renouncedOwnership(address(this));
renounced = true;
}
function createLp(uint256 _tokenAmount) external payable returns(bool) {
uint256 feeAmount = FactoryContract(factoryContract).feeAmount();
address feeAddress = FactoryContract(factoryContract).devWallet();
require(msg.value > feeAmount && renounced == true, "You should send fee for this method");
payable(feeAddress).transfer(feeAmount);
poolAddress = IUniswapV2Factory(IUniswapV2Router02(ROUTER_ADDRESS).factory()).getPair(IUniswapV2Router02(ROUTER_ADDRESS).WETH(), address(this));
if(poolAddress == address(0x0)){
poolAddress = IUniswapV2Factory(IUniswapV2Router02(ROUTER_ADDRESS).factory()).createPair(address(this), IUniswapV2Router02(ROUTER_ADDRESS).WETH());
}
IUniswapV2Router02 uniswapV2Router = IUniswapV2Router02(ROUTER_ADDRESS);
uint256 ethAmount = msg.value - (feeAmount);
lpETHAmount += ethAmount;
super._transfer(msg.sender, address(this), _tokenAmount);
_approve(address(this), address(uniswapV2Router), _tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
_tokenAmount,
0,
0,
address(msg.sender),
block.timestamp + 400
);
emit lpCreatedEvent(address(this));
lpCreated = true;
return true;
}
function LpBurn() external payable returns(bool) {
uint256 feeAmount = FactoryContract(factoryContract).feeAmount();
address feeAddress = FactoryContract(factoryContract).devWallet();
require(msg.value == feeAmount && lpCreated == true && IUniswapV2Pair(poolAddress).balanceOf(msg.sender) > 0 && renounced == true, "You should send some ETH for this method");
payable(feeAddress).transfer(feeAmount);
uint256 totalLpAmount = IUniswapV2Pair(poolAddress).totalSupply();
uint256 burnedAmount = IUniswapV2Pair(poolAddress).balanceOf(msg.sender);
IUniswapV2Pair(poolAddress).transferFrom(msg.sender, address(0xdead), burnedAmount);
lpBurnAmount += burnedAmount * 10000 / totalLpAmount;
emit lpBurnedEvent(address(this));
return true;
}
function _transferOwnership(address newOwner) public virtual onlyOwner {
transferOwnership(newOwner);
}
function updateInfo(string [] memory datas) external onlyOwner {
website = datas[0];
telegram = datas[1];
discord = datas[2];
twitter = datas[3];
}
function updateImageData(string[] memory strings) external {
address owner = FactoryContract(factoryContract).owner();
require(msg.sender == owner, "Only factory owner address can set this urls");
logoUrl = strings[0];
bannerUrl = strings[1];
}
function updateMarketingData(bool[] memory datas) external {
address owner = FactoryContract(factoryContract).owner();
require(msg.sender == owner, "Only factory owner address can set this urls");
basic = datas[0];
silver = datas[1];
gold = datas[2];
platinum = datas[3];
}
function getCoinInfo() external view returns(string memory, string memory, uint256, uint8, uint256, string memory, string memory, bool, uint256, address, string [4] memory){
string [4] memory datas;
datas[0] = website;
datas[1] = telegram;
datas[2] = discord;
datas[3] = twitter;
return (name(), symbol(), totalSupply(), decimals(), lpETHAmount, logoUrl, bannerUrl, lpCreated, lpBurnAmount, address(this), datas);
}
function getMarketinInfo() external view returns(bool, bool, bool, bool){
return (basic, silver, gold, platinum);
}
}
contract Factory {
address[] public allCoins;
address payable public devWallet;
address public Owner;
mapping(address => address[]) public tokenLists;
mapping(address => bool) public whitelists;
uint256 public feeAmount = 0.01 ether;
constructor(address payable _devWallet) {
devWallet = _devWallet;
Owner = msg.sender;
}
event tokenCreation(address indexed token);
receive() external payable {
}
function createCoin(
address wallet,
string [] memory tokenDatas,
uint256 supply,
uint8 decimals
) external payable returns (address) {
Coin coin = new Coin(wallet, tokenDatas, supply, decimals, address(this));
address coinAddr = address(coin);
allCoins.push(coinAddr);
tokenLists[wallet].push(coinAddr);
if(whitelists[msg.sender] == false){
require(msg.value == feeAmount, "You should send some fee for this method");
devWallet.transfer(msg.value);
}
emit tokenCreation(coinAddr);
return coinAddr;
}
function allCoinsLength() public view returns (uint256){
return allCoins.length;
}
function coinListLength(address _user) public view returns (uint256){
return tokenLists[_user].length;
}
function updateDevwallet(address payable _newDev) external payable returns (address){
require(msg.sender == Owner, "Only owner can set this dev wallet");
devWallet = _newDev;
return devWallet;
}
function updateOwnerWallet(address _newOwner) external returns (address){
require(msg.sender == Owner, "Only owner can set this dev wallet");
Owner = _newOwner;
return Owner;
}
function tokenUserLists(address _user) public view returns (address [] memory){
return (tokenLists[_user]);
}
function allLists() public view returns (address [] memory){
return (allCoins);
}
function updateWhitelist(address _newAddress, bool _whitelisted) public{
require(msg.sender == Owner, "Only owner can set this dev wallet");
whitelists[_newAddress] = _whitelisted;
}
function updateFeeAmount(uint256 _newFee) public{
require(msg.sender == Owner, "Only owner can set this dev wallet");
feeAmount = _newFee;
}
}