Description:
Decentralized Finance (DeFi) protocol contract providing Swap, Liquidity, Factory functionality.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"Base Contract new Format.sol": {
"content": "// SPDX-License-Identifier: MIT\r
pragma solidity 0.8.20;\r
\r
interface IERC20 {\r
function totalSupply() external view returns (uint256);\r
function balanceOf(address account) external view returns (uint256);\r
function transfer(address recipient, uint256 amount) external returns (bool);\r
function allowance(address owner, address spender) external view returns (uint256);\r
function approve(address spender, uint256 amount) external returns (bool);\r
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\r
event Transfer(address indexed from, address indexed to, uint256 value);\r
event Approval(address indexed owner, address indexed spender, uint256 value);\r
}\r
\r
interface IUniswapV2Factory {\r
function createPair(address tokenA, address tokenB) external returns (address pair);\r
}\r
\r
interface IUniswapV2Router02 {\r
function swapExactTokensForETHSupportingFeeOnTransferTokens(\r
uint amountIn,\r
uint amountOutMin,\r
address[] calldata path,\r
address to,\r
uint deadline\r
) external;\r
function factory() external pure returns (address);\r
function WETH() external pure returns (address);\r
function addLiquidityETH(\r
address token,\r
uint amountTokenDesired,\r
uint amountTokenMin,\r
uint amountETHMin,\r
address to,\r
uint deadline\r
) external payable returns (uint amountToken, uint amountETH, uint liquidity);\r
}\r
\r
/**\r
* @title SecureToken - Korrigierte Version\r
* @notice ERC20 Token mit korrigierten Konflikten\r
*/\r
contract SecureToken is IERC20 {\r
// Storage optimization\r
mapping(address => uint256) private _balances;\r
mapping(address => mapping(address => uint256)) private _allowances;\r
mapping(address => bool) private _isExcludedFromFee;\r
mapping(address => bool) private _bots;\r
\r
address payable private immutable _taxWallet;\r
address private immutable _owner;\r
IUniswapV2Router02 private immutable _uniswapV2Router;\r
address private _uniswapV2Pair;\r
\r
// Packed storage\r
uint64 private _buyCount;\r
uint16 private _initialBuyTax = 10;\r
uint16 private _initialSellTax = 10;\r
uint16 private _finalBuyTax = 0;\r
uint16 private _finalSellTax = 0;\r
uint16 private _reduceBuyTaxAt = 50;\r
uint16 private _reduceSellTaxAt = 50;\r
uint16 private _preventSwapBefore = 12;\r
bool private _tradingOpen;\r
bool private _inSwap;\r
bool private _swapEnabled;\r
bool private _limitsRemoved;\r
\r
// Constants\r
uint8 private constant DECIMALS = 9;\r
uint256 private constant TOTAL_SUPPLY = 100_000_000 * 10**DECIMALS;\r
uint256 private constant PERCENT_DIVISOR = 100;\r
uint256 private constant MAX_TAX = 10;\r
string private constant NAME = "Red Bean";\r
string private constant SYMBOL = "RDBN";\r
\r
uint256 public _maxTxAmount = 1_500_000 * 10**DECIMALS;\r
uint256 public _maxWalletSize = 1_500_000 * 10**DECIMALS;\r
uint256 public _taxSwapThreshold = 750_000 * 10**DECIMALS;\r
uint256 public _maxTaxSwap = 1_000_000 * 10**DECIMALS;\r
\r
// Emergency pause\r
bool public paused;\r
uint256 public pausedUntil;\r
\r
event MaxTxAmountUpdated(uint256 maxTxAmount);\r
event FeesReduced(uint256 newFee);\r
event TradingOpened();\r
event BotAdded(address indexed bot);\r
event BotRemoved(address indexed bot);\r
event EmergencyPause(uint256 pausedUntil);\r
event Unpaused();\r
event LimitsRemoved();\r
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r
\r
error TransferFromZeroAddress();\r
error TransferToZeroAddress();\r
error TransferAmountZero();\r
error ExceedsMaxTx();\r
error ExceedsMaxWallet();\r
error BotDetected();\r
error TradingNotOpen();\r
error TradingAlreadyOpen();\r
error Unauthorized();\r
error ContractPaused();\r
error FeeTooHigh();\r
error LimitsAlreadyRemoved();\r
\r
modifier onlyOwner() {\r
require(msg.sender == _owner, "Not owner");\r
_;\r
}\r
\r
modifier lockTheSwap {\r
_inSwap = true;\r
_;\r
_inSwap = false;\r
}\r
\r
// ✅ FIX 1: Modifier ohne Zustandsänderung\r
modifier whenNotPaused() {\r
_checkPauseStatus();\r
_;\r
}\r
\r
constructor(\r
address owner_,\r
address routerAddress,\r
address payable taxWallet\r
) {\r
require(owner_ != address(0), "Invalid owner");\r
require(taxWallet != address(0), "Invalid tax wallet");\r
\r
_owner = owner_;\r
_taxWallet = taxWallet;\r
_uniswapV2Router = IUniswapV2Router02(routerAddress);\r
\r
_balances[owner_] = TOTAL_SUPPLY;\r
_isExcludedFromFee[owner_] = true;\r
_isExcludedFromFee[address(this)] = true;\r
_isExcludedFromFee[taxWallet] = true;\r
\r
emit Transfer(address(0), owner_, TOTAL_SUPPLY);\r
}\r
\r
// ========== ERC20 Functions ==========\r
\r
function name() public pure returns (string memory) {\r
return NAME;\r
}\r
\r
function symbol() public pure returns (string memory) {\r
return SYMBOL;\r
}\r
\r
function decimals() public pure returns (uint8) {\r
return DECIMALS;\r
}\r
\r
function totalSupply() public pure override returns (uint256) {\r
return TOTAL_SUPPLY;\r
}\r
\r
function balanceOf(address account) public view override returns (uint256) {\r
return _balances[account];\r
}\r
\r
function transfer(address recipient, uint256 amount) public override whenNotPaused returns (bool) {\r
_transfer(msg.sender, recipient, amount);\r
return true;\r
}\r
\r
function allowance(address tokenOwner, address spender) public view override returns (uint256) {\r
return _allowances[tokenOwner][spender];\r
}\r
\r
function approve(address spender, uint256 amount) public override returns (bool) {\r
_approve(msg.sender, spender, amount);\r
return true;\r
}\r
\r
function transferFrom(address sender, address recipient, uint256 amount) public override whenNotPaused returns (bool) {\r
uint256 currentAllowance = _allowances[sender][msg.sender];\r
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");\r
\r
_transfer(sender, recipient, amount);\r
unchecked {\r
_approve(sender, msg.sender, currentAllowance - amount);\r
}\r
return true;\r
}\r
\r
function _approve(address tokenOwner, address spender, uint256 amount) private {\r
if (tokenOwner == address(0)) revert TransferFromZeroAddress();\r
if (spender == address(0)) revert TransferToZeroAddress();\r
\r
_allowances[tokenOwner][spender] = amount;\r
emit Approval(tokenOwner, spender, amount);\r
}\r
\r
// ✅ FIX 2: Separate Funktion für Pause-Status-Prüfung\r
function _checkPauseStatus() private view {\r
if (paused) {\r
if (block.timestamp < pausedUntil) {\r
revert ContractPaused();\r
}\r
// Wenn Pause abgelaufen ist, wird sie beim nächsten unpause() Call entfernt\r
}\r
}\r
\r
function _transfer(address from, address to, uint256 amount) private {\r
if (from == address(0)) revert TransferFromZeroAddress();\r
if (to == address(0)) revert TransferToZeroAddress();\r
if (amount == 0) revert TransferAmountZero();\r
\r
uint256 taxAmount = 0;\r
bool isOwnerTx = (from == _owner || to == _owner);\r
\r
// ✅ FIX 3: Trading-Status-Prüfung hinzugefügt\r
if (!isOwnerTx && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {\r
if (!_tradingOpen) revert TradingNotOpen();\r
}\r
\r
if (!isOwnerTx) {\r
if (_bots[from] || _bots[to]) revert BotDetected();\r
\r
uint64 buyCount = _buyCount;\r
address pair = _uniswapV2Pair;\r
\r
// Buy transaction\r
if (from == pair && to != address(_uniswapV2Router) && !_isExcludedFromFee[to]) {\r
if (!_limitsRemoved && amount > _maxTxAmount) revert ExceedsMaxTx();\r
if (!_limitsRemoved && _balances[to] + amount > _maxWalletSize) revert ExceedsMaxWallet();\r
\r
taxAmount = (amount * (buyCount > _reduceBuyTaxAt ? _finalBuyTax : _initialBuyTax)) / PERCENT_DIVISOR;\r
unchecked { _buyCount++; }\r
}\r
// Sell transaction\r
else if (to == pair && from != address(this)) {\r
taxAmount = (amount * (buyCount > _reduceSellTaxAt ? _finalSellTax : _initialSellTax)) / PERCENT_DIVISOR;\r
}\r
\r
// Swap and liquify\r
uint256 contractBalance = _balances[address(this)];\r
if (!_inSwap && to == pair && _swapEnabled && \r
contractBalance > _taxSwapThreshold && buyCount > _preventSwapBefore) {\r
\r
uint256 swapAmount = amount < contractBalance ? amount : contractBalance;\r
swapAmount = swapAmount < _maxTaxSwap ? swapAmount : _maxTaxSwap;\r
\r
swapTokensForEth(swapAmount);\r
\r
uint256 ethBalance = address(this).balance;\r
if (ethBalance > 0) {\r
sendETHToFee(ethBalance);\r
}\r
}\r
}\r
\r
// Update balances\r
if (taxAmount > 0) {\r
unchecked {\r
_balances[address(this)] += taxAmount;\r
}\r
emit Transfer(from, address(this), taxAmount);\r
}\r
\r
unchecked {\r
_balances[from] -= amount;\r
_balances[to] += amount - taxAmount;\r
}\r
\r
emit Transfer(from, to, amount - taxAmount);\r
}\r
\r
// ========== Internal Functions ==========\r
\r
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {\r
address[] memory path = new address[](2);\r
path[0] = address(this);\r
path[1] = _uniswapV2Router.WETH();\r
\r
_approve(address(this), address(_uniswapV2Router), tokenAmount);\r
_uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(\r
tokenAmount,\r
0,\r
path,\r
address(this),\r
block.timestamp\r
);\r
}\r
\r
function sendETHToFee(uint256 amount) private {\r
(bool success, ) = _taxWallet.call{value: amount}("");\r
require(success, "ETH transfer failed");\r
}\r
\r
// ========== Owner Functions ==========\r
\r
function removeLimits() external onlyOwner {\r
if (_limitsRemoved) revert LimitsAlreadyRemoved();\r
\r
_maxTxAmount = TOTAL_SUPPLY;\r
_maxWalletSize = TOTAL_SUPPLY;\r
_limitsRemoved = true;\r
\r
emit LimitsRemoved();\r
emit MaxTxAmountUpdated(TOTAL_SUPPLY);\r
}\r
\r
function openTrading() external onlyOwner {\r
if (_tradingOpen) revert TradingAlreadyOpen();\r
\r
_approve(address(this), address(_uniswapV2Router), TOTAL_SUPPLY);\r
_uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())\r
.createPair(address(this), _uniswapV2Router.WETH());\r
\r
_uniswapV2Router.addLiquidityETH{value: address(this).balance}(\r
address(this),\r
balanceOf(address(this)),\r
0,\r
0,\r
_owner,\r
block.timestamp\r
);\r
\r
IERC20(_uniswapV2Pair).approve(address(_uniswapV2Router), type(uint).max);\r
_swapEnabled = true;\r
_tradingOpen = true;\r
\r
emit TradingOpened();\r
}\r
\r
function reduceFee(uint256 newFee) external onlyOwner {\r
if (newFee > MAX_TAX) revert FeeTooHigh();\r
require(newFee <= _finalBuyTax && newFee <= _finalSellTax, "Cannot increase fees");\r
\r
_finalBuyTax = uint16(newFee);\r
_finalSellTax = uint16(newFee);\r
\r
emit FeesReduced(newFee);\r
}\r
\r
function addBot(address bot) external onlyOwner {\r
require(bot != address(_uniswapV2Router), "Cannot blacklist router");\r
require(bot != _uniswapV2Pair, "Cannot blacklist pair");\r
\r
_bots[bot] = true;\r
emit BotAdded(bot);\r
}\r
\r
function removeBot(address bot) external onlyOwner {\r
_bots[bot] = false;\r
emit BotRemoved(bot);\r
}\r
\r
function emergencyPause(uint256 duration) external onlyOwner {\r
require(duration <= 7 days, "Max pause 7 days");\r
\r
paused = true;\r
pausedUntil = block.timestamp + duration;\r
\r
emit EmergencyPause(pausedUntil);\r
}\r
\r
// ✅ FIX 4: Unpause prüft jetzt auch abgelaufene Pausen\r
function unpause() external onlyOwner {\r
require(paused, "Not paused");\r
paused = false;\r
pausedUntil = 0;\r
\r
emit Unpaused();\r
}\r
\r
// ========== Tax Wallet Functions ==========\r
\r
function manualSwap() external {\r
require(msg.sender == _taxWallet, "Only tax wallet");\r
\r
uint256 tokenBalance = _balances[address(this)];\r
if (tokenBalance > 0) {\r
swapTokensForEth(tokenBalance);\r
}\r
\r
uint256 ethBalance = address(this).balance;\r
if (ethBalance > 0) {\r
sendETHToFee(ethBalance);\r
}\r
}\r
\r
// ========== View Functions ==========\r
\r
function owner() public view returns (address) {\r
return _owner;\r
}\r
\r
function isBot(address account) external view returns (bool) {\r
return _bots[account];\r
}\r
\r
function getTaxInfo() external view returns (\r
uint256 initialBuyTax,\r
uint256 initialSellTax,\r
uint256 finalBuyTax,\r
uint256 finalSellTax,\r
uint256 buyCount\r
) {\r
return (_initialBuyTax, _initialSellTax, _finalBuyTax, _finalSellTax, _buyCount);\r
}\r
\r
receive() external payable {}\r
}"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-11-05 14:57:01
Comments
Log in to comment.
No comments yet.