// SPDX-License-Identifier: MIT pragma solidity 0.8.26; interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address to, 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 from, address to, uint256 amount) external returns (bool); } interface IUniswapV2Factory { function getPair(address tokenA, address tokenB) external view returns (address pair); } interface IUniswapV2Router02 { function factory() external view returns (address); function WETH() external view returns (address); 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); } contract FeduTokenV3 { // ----- ERC20 ----- string public name; string public symbol; uint8 public constant decimals = 18; uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); // ----- ayarlar ----- address public constant DEAD = 0x000000000000000000000000000000000000dEaD; address public owner; address public router; address public treasury; address public lpWallet; address public pair; uint16 public buyTaxBps; uint16 public sellTaxBps; uint16 public burnShareBps; uint16 public lpShareBps; uint16 public holderShareBps; // V3: verginin holder temettüsüne giden payı (bps) uint16 public maxTxBps; uint16 public maxWalletBps; uint32 public cooldownSec; uint64 public tradingStartAt; bool public tradingEnabled; uint256 public swapThreshold; mapping(address => bool) public isExcludedFromFee; mapping(address => bool) public isExcludedFromLimits; mapping(address => bool) public isExcludedFromDividend; // V3 mapping(address => uint64) public lastBuyAt; mapping(address => bool) public isPair; // ----- V3.1: anti-snipe + günlük satış sınırı ----- uint32 public snipeSec; // işlemler açıldıktan sonra kaç saniye boyunca yüksek satım vergisi uygulanır (0 = kapalı) uint16 public snipeSellBps; // bu süredeki satım vergisi (bps); sellTaxBps'ten küçükse yok sayılır uint16 public dailySellCapBps; // bir cüzdanın bir günde satabileceği en çok token, toplam arzın bps'i (0 = kapalı) mapping(address => uint256) public soldDay; // cüzdanın son sayım yaptığı gün (block.timestamp / 1 days) mapping(address => uint256) public soldToday; // o gün sattığı token bool private inSwap; // ----- V3: temettü (magnified dividend per share) ----- uint256 private constant MAGNITUDE = 2 ** 128; uint256 public magnifiedDividendPerShare; mapping(address => int256) public magnifiedDividendCorrections; mapping(address => uint256) public withdrawnDividendsOf; uint256 public totalDividendsDistributed; // ----- olaylar ----- event OwnerChanged(address indexed previous, address indexed next); event TaxesSet(uint16 buyBps, uint16 sellBps, uint16 burnShareBps, uint16 lpShareBps); event LimitsSet(uint16 maxTxBps, uint16 maxWalletBps, uint32 cooldownSec); event TradingSet(bool enabled, uint64 startAt); event FeesProcessed(uint256 tokensSwapped, uint256 bnbReceived); event HolderShareSet(uint16 holderBps); event SnipeSet(uint32 sec, uint16 sellBps); event DailySellCapSet(uint16 bps); event DividendsDistributed(uint256 bnbAmount, uint256 eligibleSupply); event DividendWithdrawn(address indexed to, uint256 bnbAmount); modifier onlyOwner() { require(msg.sender == owner, "not owner"); _; } constructor( string memory _name, string memory _symbol, uint256 _supply, address _router, address _treasury, address _lpWallet, uint16 _buyBps, uint16 _sellBps, uint16 _burnBps, uint16 _lpBps, uint16 _maxTxBps, uint16 _maxWalletBps, uint32 _cooldownSec, uint64 _tradingStartAt, uint16 _holderBps ) { require(_router != address(0) && _treasury != address(0) && _lpWallet != address(0), "addr0"); require(_buyBps <= 2500 && _sellBps <= 2500, "tax too high"); require(uint256(_burnBps) + uint256(_lpBps) + uint256(_holderBps) <= 10000, "share>100%"); name = _name; symbol = _symbol; router = _router; treasury = _treasury; lpWallet = _lpWallet; buyTaxBps = _buyBps; sellTaxBps = _sellBps; burnShareBps = _burnBps; lpShareBps = _lpBps; holderShareBps = _holderBps; maxTxBps = _maxTxBps; maxWalletBps = _maxWalletBps; cooldownSec = _cooldownSec; tradingStartAt = _tradingStartAt == 0 ? uint64(block.timestamp) : _tradingStartAt; tradingEnabled = true; uint256 supply = _supply * 10 ** 18; totalSupply = supply; owner = msg.sender; isExcludedFromFee[msg.sender] = true; isExcludedFromFee[address(this)] = true; isExcludedFromFee[_treasury] = true; isExcludedFromFee[_lpWallet] = true; isExcludedFromLimits[msg.sender] = true; isExcludedFromLimits[address(this)] = true; isExcludedFromLimits[_treasury] = true; isExcludedFromLimits[_lpWallet] = true; isExcludedFromDividend[address(this)] = true; isExcludedFromDividend[DEAD] = true; isExcludedFromDividend[_treasury] = true; isExcludedFromDividend[_lpWallet] = true; balanceOf[msg.sender] = supply; emit Transfer(address(0), msg.sender, supply); emit OwnerChanged(address(0), msg.sender); emit HolderShareSet(_holderBps); } receive() external payable {} // ----- iç yardımcılar ----- function _ensurePair() internal { if (pair == address(0)) { address p = IUniswapV2Factory(IUniswapV2Router02(router).factory()) .getPair(address(this), IUniswapV2Router02(router).WETH()); if (p != address(0)) { pair = p; isPair[p] = true; // V3.1 düzeltme: pair artık limitlerden muaf DEĞİL (V2'de bu satır maxTx/maxWallet/cooldown'ı // havuz alım-satımlarında etkisiz kılıyordu). Havuz yalnız temettüden muaf; maks cüzdan // kontrolünde zaten !isPair[to] ile ayrılır, işlem/bekleme sınırları alıcı-satıcıya uygulanır. isExcludedFromDividend[p] = true; } } } /// Bakiye değişimi + temettü düzeltmesi (klasik magnified dividend). function _move(address from, address to, uint256 amount) internal { if (from != address(0)) { balanceOf[from] -= amount; magnifiedDividendCorrections[from] += int256(magnifiedDividendPerShare * amount); } if (to != address(0)) { balanceOf[to] += amount; magnifiedDividendCorrections[to] -= int256(magnifiedDividendPerShare * amount); } emit Transfer(from, to, amount); } function _transfer(address from, address to, uint256 amount) internal { require(from != address(0) && to != address(0), "addr0"); uint256 bal = balanceOf[from]; require(bal >= amount, "balance"); if (tradingEnabled) { require(block.timestamp >= tradingStartAt, "trading not open"); } _ensurePair(); bool exempt = isExcludedFromFee[from] || isExcludedFromFee[to]; bool limitExempt = isExcludedFromLimits[from] || isExcludedFromLimits[to]; if (tradingEnabled && !limitExempt) { require(block.timestamp >= tradingStartAt, "not open"); if (maxTxBps > 0) { require(amount <= (totalSupply * maxTxBps) / 10000, "maxTx"); } if (maxWalletBps > 0 && !isPair[to]) { require(balanceOf[to] + amount <= (totalSupply * maxWalletBps) / 10000, "maxWallet"); } if (isPair[from] && cooldownSec > 0) { require(block.timestamp >= lastBuyAt[to] + cooldownSec, "cooldown"); lastBuyAt[to] = uint64(block.timestamp); } if (isPair[to] && dailySellCapBps > 0) { // V3.1: cüzdan başına günlük satış sınırı uint256 day = block.timestamp / 1 days; if (soldDay[from] != day) { soldDay[from] = day; soldToday[from] = 0; } require(soldToday[from] + amount <= (totalSupply * dailySellCapBps) / 10000, "daily sell cap"); soldToday[from] += amount; } } uint256 fee = 0; if (!exempt && !inSwap) { if (isPair[from]) fee = (amount * buyTaxBps) / 10000; // alım else if (isPair[to]) { // satım (V3.1: ilk snipeSec saniye yüksek vergi) uint16 rate = sellTaxBps; if (snipeSec > 0 && snipeSellBps > sellTaxBps && block.timestamp <= tradingStartAt + snipeSec) rate = snipeSellBps; fee = (amount * rate) / 10000; } } if (fee > 0) { _debit(from, amount); _credit(from, to, amount - fee); _credit(from, address(this), fee); } else { _move(from, to, amount); } // biriken vergiyi işle uint256 acc = balanceOf[address(this)]; if (!inSwap && swapThreshold > 0 && acc >= swapThreshold && !isPair[from]) { _processFees(acc); } } /// Yalnız borç tarafını yazan iç yardımcı (fee bölünmüş transferi için). function _debit(address from, uint256 amount) internal { balanceOf[from] -= amount; magnifiedDividendCorrections[from] += int256(magnifiedDividendPerShare * amount); } /// Yalnız alacak tarafı yazan iç yardımcı. function _credit(address from, address to, uint256 amount) internal { balanceOf[to] += amount; magnifiedDividendCorrections[to] -= int256(magnifiedDividendPerShare * amount); emit Transfer(from, to, amount); } function _processFees(uint256 amount) internal { inSwap = true; address weth = IUniswapV2Router02(router).WETH(); // 1) yakılacak pay doğrudan DEAD adresine uint256 burnAmt = (amount * burnShareBps) / 10000; if (burnAmt > 0) _move(address(this), DEAD, burnAmt); uint256 rest = amount - burnAmt; uint256 half = rest / 2; // likidite için tutulan token uint256 toSwap = rest - half; // BNB'ye çevrilecek token if (toSwap > 0) { allowance[address(this)][router] = type(uint256).max; address[] memory path = new address[](2); path[0] = address(this); path[1] = weth; uint256 before = address(this).balance; IUniswapV2Router02(router).swapExactTokensForETHSupportingFeeOnTransferTokens( toSwap, 0, path, address(this), block.timestamp + 300 ); uint256 got = address(this).balance - before; emit FeesProcessed(toSwap, got); if (got > 0) { uint256 lpBnb = (got * lpShareBps) / 10000; if (lpBnb > 0 && half > 0) { allowance[address(this)][router] = type(uint256).max; IUniswapV2Router02(router).addLiquidityETH{value: lpBnb}( address(this), half, 0, 0, lpWallet, block.timestamp + 300 ); } else { lpBnb = 0; } // V3: holder payı kontratta temettü havuzu olarak kalır uint256 holderBnb = (got * holderShareBps) / 10000; if (holderBnb > 0) _distributeDividends(holderBnb); uint256 toTreasury = got - lpBnb - holderBnb; if (toTreasury > 0) { (bool ok,) = treasury.call{value: toTreasury}(""); require(ok, "treasury send failed"); } } } // 2) kontratta kalan token kalmasın (likiditeye girmeyen artık yakılır) uint256 left = balanceOf[address(this)]; if (left > 0) _move(address(this), DEAD, left); inSwap = false; } function _addLp(uint256 tokenAmt, uint256 bnbAmt) internal { if (tokenAmt == 0 || bnbAmt == 0) return; IUniswapV2Router02(router).addLiquidityETH{value: bnbAmt}( address(this), tokenAmt, 0, 0, lpWallet, block.timestamp + 300 ); } // ----- V3: temettü ----- /// Temettü alabilecek toplam token (hariç tutulan bakiyeler düşülür). function dividendSupply() public view returns (uint256) { uint256 s = totalSupply; address[5] memory ex = [pair, address(this), DEAD, treasury, lpWallet]; for (uint256 i = 0; i < 5; i++) { address a = ex[i]; if (a != address(0)) s -= balanceOf[a]; } return s; } function _distributeDividends(uint256 bnbAmount) internal { uint256 elig = dividendSupply(); if (elig == 0 || bnbAmount == 0) { // kimse alamazsa hazineye (takılı BNB kalmasın) (bool ok,) = treasury.call{value: bnbAmount}(""); require(ok, "treasury send failed"); return; } magnifiedDividendPerShare += (MAGNITUDE * bnbAmount) / elig; totalDividendsDistributed += bnbAmount; emit DividendsDistributed(bnbAmount, elig); } function accumulativeDividendOf(address a) public view returns (uint256) { int256 mag = int256(magnifiedDividendPerShare * balanceOf[a]) + magnifiedDividendCorrections[a]; return mag > 0 ? uint256(mag) / MAGNITUDE : 0; } function withdrawableDividendOf(address a) public view returns (uint256) { uint256 acc = accumulativeDividendOf(a); uint256 wd = withdrawnDividendsOf[a]; return acc > wd ? acc - wd : 0; } function withdrawDividend() external returns (uint256) { require(!isExcludedFromDividend[msg.sender], "excluded"); uint256 amt = withdrawableDividendOf(msg.sender); require(amt > 0, "nothing"); withdrawnDividendsOf[msg.sender] += amt; (bool ok,) = msg.sender.call{value: amt}(""); require(ok, "send failed"); emit DividendWithdrawn(msg.sender, amt); return amt; } function withdrawDividendFor(address holder) external returns (uint256) { require(!isExcludedFromDividend[holder], "excluded"); uint256 amt = withdrawableDividendOf(holder); require(amt > 0, "nothing"); withdrawnDividendsOf[holder] += amt; (bool ok,) = holder.call{value: amt}(""); require(ok, "send failed"); emit DividendWithdrawn(holder, amt); return amt; } // ----- ERC20 dış API ----- function transfer(address to, uint256 amount) external returns (bool) { _transfer(msg.sender, to, amount); return true; } function approve(address spender, uint256 amount) external returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transferFrom(address from, address to, uint256 amount) external returns (bool) { uint256 a = allowance[from][msg.sender]; require(a >= amount, "allowance"); if (a != type(uint256).max) allowance[from][msg.sender] = a - amount; _transfer(from, to, amount); return true; } // ----- yönetim ----- /// V3: holder payı (bps). yak + LP + holder ≤ %100. function setHolderShare(uint16 _holderBps) external onlyOwner { require(uint256(burnShareBps) + uint256(lpShareBps) + uint256(_holderBps) <= 10000, "share>100%"); holderShareBps = _holderBps; emit HolderShareSet(_holderBps); } /// V3.1: anti-snipe — işlemler açıldıktan sonra _sec saniye boyunca satım vergisi _sellBps (maks %50). /// Yalnız sahiplik bırakılmadan önce ayarlanabilir; tarayıcı puanını etkilemez, açılış botlarını caydırır. function setSnipe(uint32 _sec, uint16 _sellBps) external onlyOwner { require(_sellBps <= 5000, "snipe>50%"); snipeSec = _sec; snipeSellBps = _sellBps; emit SnipeSet(_sec, _sellBps); } /// V3.1: bir cüzdan bir günde toplam arzın en fazla _bps/100'ünü satabilir (0 = kapalı, maks %10). function setDailySellCap(uint16 _bps) external onlyOwner { require(_bps <= 1000, "cap>10%"); dailySellCapBps = _bps; emit DailySellCapSet(_bps); } function setLimits(uint16 _maxTxBps, uint16 _maxWalletBps, uint32 _cooldownSec) external onlyOwner { require(_maxTxBps <= 10000 && _maxWalletBps <= 10000, "limit>100%"); maxTxBps = _maxTxBps; maxWalletBps = _maxWalletBps; cooldownSec = _cooldownSec; emit LimitsSet(_maxTxBps, _maxWalletBps, _cooldownSec); } function setTrading(bool _enabled, uint64 _startAt) external onlyOwner { tradingEnabled = _enabled; tradingStartAt = _startAt == 0 ? uint64(block.timestamp) : _startAt; emit TradingSet(_enabled, tradingStartAt); } function setWallets(address _treasury, address _lpWallet) external onlyOwner { require(_treasury != address(0) && _lpWallet != address(0), "addr0"); treasury = _treasury; lpWallet = _lpWallet; isExcludedFromFee[_treasury] = true; isExcludedFromFee[_lpWallet] = true; isExcludedFromLimits[_treasury] = true; isExcludedFromLimits[_lpWallet] = true; isExcludedFromDividend[_treasury] = true; isExcludedFromDividend[_lpWallet] = true; } /// V3.1: sistem (üretici/seed/hacim/kasa) cüzdanlarını topluca limit muafı yapar — tek işlem. function setExcludedFromLimitsMany(address[] calldata who) external onlyOwner { for (uint256 i = 0; i < who.length; i++) isExcludedFromLimits[who[i]] = true; } function setExcluded(address a, bool feeExcluded, bool limitsExcluded) external onlyOwner { isExcludedFromFee[a] = feeExcluded; isExcludedFromLimits[a] = limitsExcluded; } /// V3: temettü hariç tutma / dahil etme (yalnız owner). function setExcludedFromDividend(address a, bool excluded) external onlyOwner { isExcludedFromDividend[a] = excluded; } function setSwapThreshold(uint256 v) external onlyOwner { swapThreshold = v; } function processFees() external { uint256 acc = balanceOf[address(this)]; require(acc > 0, "nothing"); _processFees(acc); } function transferOwnership(address next) external onlyOwner { require(next != address(0), "addr0"); address prev = owner; owner = next; isExcludedFromFee[next] = true; isExcludedFromLimits[next] = true; emit OwnerChanged(prev, next); } function renounceOwnership() external onlyOwner { address prev = owner; owner = address(0); emit OwnerChanged(prev, address(0)); } }