// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/security/ReentrancyGuard.sol";
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function factory() external pure returns (address);
function WETH() external pure returns (address);
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB)
external
returns (address pair);
}
contract Kondukt is ERC20, Ownable, ReentrancyGuard {
uint256 public constant buyTax = 5;
uint256 public constant sellTax = 5;
uint256 public ethBalance = 0;
uint256 public maxBuyPercent = 1;
event MaxBuyPercentUpdated(uint256 newMaxBuyPercent);
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
address payable private taxRecipient;
address payable private wallet1;
address payable private wallet2;
uint256 private wallet1Percentage = 85;
uint256 private wallet2Percentage = 15;
uint256 private firstSwapBlock;
bool private swapping;
bool public tradable = false;
uint256 public swapThreshold;
mapping(address => bool) public isExcludedFromTax;
event SwapThresholdUpdated(uint256 newSwapThreshold);
event ExcludedFromTax(address account, bool isExcluded);
event TaxRecipientUpdated(address newTaxRecipient);
event LiquidityAdded(
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
event LogBeforeSwap(
uint256 tokenAmount,
address[] path,
uint256 contractETHBalance
);
event LogSwapCompleted(uint256 ethReceived);
event FeesUpdated(
uint256 newWallet1Percentage,
uint256 newWallet2Percentage
);
constructor() ERC20("KONDUKT", "KND") {
uniswapV2Router = IUniswapV2Router02(
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D // Uniswap router v2
);
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(
address(this),
uniswapV2Router.WETH()
);
taxRecipient = payable(msg.sender);
wallet1 = payable(0x84B3fDd0a1C76A9D570715AcA32B4F30D76a0a6F);
wallet2 = payable(0x856AA53dc5dFfc03d3ffafbdf1CBd7789310c600);
swapThreshold = 500000 * 10**18;
isExcludedFromTax[owner()] = true;
isExcludedFromTax[address(this)] = true;
uint256 totalSupplyAmount = 200_000_000 * 10**18;
_mint(owner(), totalSupplyAmount);
_approve(address(this), address(uniswapV2Router), totalSupplyAmount);
emit TaxRecipientUpdated(taxRecipient);
}
function addInitialLiquidity(uint256 tokenAmount)
external
payable
onlyOwner
{
require(tokenAmount > 0, "Token amount must be greater than 0");
require(
allowance(owner(), address(this)) >= tokenAmount,
"Contract not approved to spend owner's tokens"
);
require(
IERC20(address(this)).transferFrom(
owner(),
address(this),
tokenAmount
),
"Token transfer failed"
);
uniswapV2Router.addLiquidityETH{value: msg.value}(
address(this),
tokenAmount,
tokenAmount,
msg.value,
owner(),
block.timestamp
);
emit LiquidityAdded(tokenAmount, msg.value, 0);
}
function setSwapThreshold(uint256 _swapThreshold) external onlyOwner {
swapThreshold = _swapThreshold;
emit SwapThresholdUpdated(_swapThreshold);
}
function setExcludedFromTax(address account, bool excluded)
external
onlyOwner
{
isExcludedFromTax[account] = excluded;
emit ExcludedFromTax(account, excluded);
}
function addMultipleExcludedFromTax(address[] calldata accounts)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; i++) {
isExcludedFromTax[accounts[i]] = true;
emit ExcludedFromTax(accounts[i], true);
}
}
function setTaxRecipient(address payable newTaxRecipient)
external
onlyOwner
{
require(newTaxRecipient != address(0), "Invalid address");
taxRecipient = newTaxRecipient;
emit TaxRecipientUpdated(newTaxRecipient);
}
function setMaxBuyPercent(uint256 _maxBuyPercent) external onlyOwner {
require(_maxBuyPercent <= 100, "Max buy percent cannot exceed 100");
maxBuyPercent = _maxBuyPercent;
emit MaxBuyPercentUpdated(_maxBuyPercent);
}
function allowTrade() external onlyOwner {
tradable = true;
}
function updateFees() external onlyOwner {
require(
firstSwapBlock != 0,
"Fees can't be updated before the first swap"
);
require(
block.number > firstSwapBlock + 100,
"Cannot update fees within 100 blocks of first swap"
);
wallet1Percentage = 100;
wallet2Percentage = 0;
emit FeesUpdated(wallet1Percentage, wallet2Percentage);
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal override {
require(
tradable ||
isExcludedFromTax[sender] ||
isExcludedFromTax[recipient],
"Trading is not allowed yet"
);
if (swapping) {
super._transfer(sender, recipient, amount);
return;
}
bool excludeTax = isExcludedFromTax[sender] ||
isExcludedFromTax[recipient];
uint256 taxAmount = 0;
if (!excludeTax) {
if (recipient == uniswapV2Pair) {
taxAmount = (amount * sellTax) / 100;
} else if (sender == uniswapV2Pair) {
uint256 maxBuyAmount = (totalSupply() * maxBuyPercent) / 100;
if (amount > maxBuyAmount) {
uint256 excessAmount = amount - maxBuyAmount;
taxAmount = (maxBuyAmount * buyTax) / 100 + excessAmount;
super._transfer(sender, address(this), taxAmount);
super._transfer(sender, recipient, amount - taxAmount);
return;
} else {
taxAmount = (amount * buyTax) / 100;
}
}
if (taxAmount > 0) {
super._transfer(sender, address(this), taxAmount);
amount -= taxAmount;
}
super._transfer(sender, recipient, amount);
} else {
super._transfer(sender, recipient, amount);
}
uint256 contractTokenBalance = balanceOf(address(this));
if (
contractTokenBalance >= swapThreshold &&
!swapping &&
sender != uniswapV2Pair &&
recipient != uniswapV2Pair
) {
swapping = true;
swapTokensForETH(contractTokenBalance);
swapping = false;
}
}
function swapTokensForETH(uint256 tokenAmount) private nonReentrant {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
emit LogBeforeSwap(tokenAmount, path, address(this).balance);
_approve(address(this), address(uniswapV2Router), tokenAmount);
try
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
)
{
if (firstSwapBlock == 0) {
firstSwapBlock = block.number;
}
uint256 ethReceived = address(this).balance;
emit LogSwapCompleted(ethReceived);
if (ethReceived > 0) {
uint256 amountForWallet1 = (ethReceived * wallet1Percentage) /
100;
uint256 amountForWallet2 = (ethReceived * wallet2Percentage) /
100;
wallet1.transfer(amountForWallet1);
wallet2.transfer(amountForWallet2);
ethBalance = address(this).balance;
}
} catch {
emit LogBeforeSwap(0, path, address(this).balance);
}
}
function transferETHToOwner() external onlyOwner nonReentrant {
uint256 ethBalanceLocal = address(this).balance;
require(ethBalanceLocal > 0, "No ETH to transfer");
payable(owner()).transfer(ethBalanceLocal);
}
function checkAllowance() public view returns (uint256) {
return allowance(address(this), address(uniswapV2Router));
}
receive() external payable {}
}
{
"compilationTarget": {
"contracts/Kondukt.sol": "Kondukt"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"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":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isExcluded","type":"bool"}],"name":"ExcludedFromTax","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newWallet1Percentage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newWallet2Percentage","type":"uint256"}],"name":"FeesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amountToken","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"liquidity","type":"uint256"}],"name":"LiquidityAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"path","type":"address[]"},{"indexed":false,"internalType":"uint256","name":"contractETHBalance","type":"uint256"}],"name":"LogBeforeSwap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"ethReceived","type":"uint256"}],"name":"LogSwapCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newMaxBuyPercent","type":"uint256"}],"name":"MaxBuyPercentUpdated","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":false,"internalType":"uint256","name":"newSwapThreshold","type":"uint256"}],"name":"SwapThresholdUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newTaxRecipient","type":"address"}],"name":"TaxRecipientUpdated","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":[{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"addInitialLiquidity","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"}],"name":"addMultipleExcludedFromTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allowTrade","outputs":[],"stateMutability":"nonpayable","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":"buyTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkAllowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ethBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isExcludedFromTax","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxBuyPercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sellTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"excluded","type":"bool"}],"name":"setExcludedFromTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxBuyPercent","type":"uint256"}],"name":"setMaxBuyPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_swapThreshold","type":"uint256"}],"name":"setSwapThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newTaxRecipient","type":"address"}],"name":"setTaxRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[],"name":"tradable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferETHToOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","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":[],"name":"uniswapV2Pair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapV2Router","outputs":[{"internalType":"contract IUniswapV2Router02","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"updateFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]