// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: contracts/interfaces/IUniswapV2Router02.sol
pragma solidity ^0.8.4;
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
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);
}
// File: contracts/interfaces/IUniswapV2Factory.sol
pragma solidity ^0.8.4;
interface IUniswapV2Factory {
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
}
// File: contracts/CoinLauncherERC20.sol
pragma solidity 0.8.23;
contract LaunchpadERC20New is IERC20, Ownable {
string private _name = "NAME";
string private _symbol = "SYMBOL";
uint8 private _decimals = 18;
uint256 private _totalSupply = 10_000_000_000e18;
uint256 private _twoPercent = _totalSupply / 100 * 2;
uint256 private _minSwap = _totalSupply / 1000;
uint256 private _taxPercentage = 10;
address payable _taxDestination;
bool private _openTrade = false;
bool private _inSwapAndLiquify = false;
uint256 public _maxTxAmount = 2**256 - 1;
mapping(address => bool) private _isExcludedWallet;
mapping(address => uint256) private _balance;
mapping(address => mapping(address => uint256)) private _allowances;
IUniswapV2Router02 immutable uniswapV2Router02; // Uniswap Router
address immutable uniswapV2Pair; // Pair address
address immutable WETH;
/**
* constructor of contract
* @param name_ name of token
* @param symbol_ symbol of token
* @param decimals_ decimals of token
* @param totalSupply_ total supply
* @param maxTxAmount_ maximum transaction token amount
* @param uniswapV2Router02_ address of uniswapV2Router02 based on network
*/
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 totalSupply_,
uint256 maxTxAmount_,
address uniswapV2Router02_
) {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
_taxDestination = payable(msg.sender);
_totalSupply = totalSupply_;
_twoPercent = totalSupply_ / 100 * 2; // 2%
_minSwap = totalSupply_ / 1000; // 0.001%
_maxTxAmount = maxTxAmount_;
uniswapV2Router02 = IUniswapV2Router02(
uniswapV2Router02_
);
WETH = uniswapV2Router02.WETH();
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router02.factory()).createPair(
address(this),
WETH
);
_isExcludedWallet[msg.sender] = true;
_isExcludedWallet[address(this)] = true;
_balance[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
/**
*
* PUBLIC
*
* **/
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
return _balance[account];
}
function allowance(address owner,address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()] - amount
);
return true;
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
*
* ONLYOWNER
*
*/
function setTaxDestination(address taxDestination) external onlyOwner {
_taxDestination = payable(taxDestination);
_isExcludedWallet[_taxDestination] = true;
_approve(_taxDestination, address(uniswapV2Router02), 2**256 - 1);
}
function updateTax(uint newTaxPercentage) external onlyOwner { // Function updates the tax amount if in allowable range.
require(newTaxPercentage <= 5, "Taxable: tax is too high"); // Throws the call if the new tax is above the maximum tax.
require(newTaxPercentage >= 0, "Taxable: tax is too low"); // Throws the call if the new tax is below the minimum tax.
_taxPercentage = newTaxPercentage; // Sets the tax amount integer to the new value, updating the tax amount.
}
function setMinSwap(uint newMinSwap) external onlyOwner {
_minSwap = newMinSwap;
}
function openTrading() external onlyOwner {
_openTrade = true;
}
function removeLimits() external onlyOwner {
_maxTxAmount = _totalSupply;
}
/**
*
* PRIVATE
*
*/
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");
if (!_isExcludedWallet[from] && !_isExcludedWallet[to]) {
require(_openTrade, "Trade not enabled");
require(amount <= _maxTxAmount, "Exceed maxTxAmount");
}
uint256 _taxTransfer;
if (_inSwapAndLiquify) {
// No tax transfer
_balance[from] -= amount;
_balance[to] += amount;
emit Transfer(from, to, amount);
return;
}
if (from == uniswapV2Pair && !_isExcludedWallet[to]) { // From Uniswap To Receiver
_taxTransfer = _taxPercentage;
} else if (to == uniswapV2Pair && !_isExcludedWallet[from]) { // From Sender To Uniswap
uint256 tokensToSwap = balanceOf(address(this));
if (tokensToSwap > _minSwap && !_inSwapAndLiquify) {
if (tokensToSwap > _twoPercent) {
tokensToSwap = _twoPercent;
}
_inSwapAndLiquify = true;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WETH;
uniswapV2Router02.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokensToSwap,
0,
path,
_taxDestination,
block.timestamp
);
_inSwapAndLiquify = false;
}
_taxTransfer = _taxPercentage;
} else {
_taxTransfer = 0;
}
// Is there tax for sender|receiver?
if (_taxTransfer != 0) {
// Tax transfer
uint256 taxTokens = amount * (_taxTransfer / 100);
uint256 transferAmount = amount - taxTokens;
_balance[from] -= amount;
_balance[address(this)] += taxTokens;
_balance[to] += transferAmount;
emit Transfer(from, address(this), taxTokens);
emit Transfer(from, to, transferAmount);
} else {
// No tax transfer
_balance[from] -= amount;
_balance[to] += amount;
emit Transfer(from, to, amount);
}
}
/**
* EXTERNAL PAYABLE
*/
function addLiquidity(uint256 tokenAmount) external payable onlyOwner {
uint256 ethAmount = msg.value;
// Ensure the contract has received enough ETH
require(ethAmount > 0, "ETH amount must be greater than zero");
// Ensure the contract has received enough Token
require(tokenAmount > 0, "Token amount must be greater than zero");
// Ensure the contract has enough tokens
require(balanceOf(msg.sender) >= tokenAmount, "Not enough tokens in contract");
// Approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router02), 2**256 - 1);
// Transfer
_transfer(msg.sender, address(this), tokenAmount);
uniswapV2Router02.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0,
0,
owner(),
block.timestamp
);
IERC20(uniswapV2Pair).approve(address(uniswapV2Router02), 2**256 - 1);
}
receive() external payable {}
}
{
"compilationTarget": {
"LaunchpadERC20New.sol": "LaunchpadERC20New"
},
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"uint8","name":"decimals_","type":"uint8"},{"internalType":"uint256","name":"totalSupply_","type":"uint256"},{"internalType":"uint256","name":"maxTxAmount_","type":"uint256"},{"internalType":"address","name":"uniswapV2Router02_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"_maxTxAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"addLiquidity","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"openTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"removeLimits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMinSwap","type":"uint256"}],"name":"setMinSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"taxDestination","type":"address"}],"name":"setTaxDestination","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newTaxPercentage","type":"uint256"}],"name":"updateTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]