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