// ░██████╗░█████╗░███╗░░░███╗██╗░░░██╗██████╗░░█████╗░██╗  ██████╗░███████╗██████╗░███████╗
// ██╔════╝██╔══██╗████╗░████║██║░░░██║██╔══██╗██╔══██╗██║  ██╔══██╗██╔════╝██╔══██╗██╔════╝
// ╚█████╗░███████║██╔████╔██║██║░░░██║██████╔╝███████║██║  ██████╔╝█████╗░░██████╔╝█████╗░░
// ░╚═══██╗██╔══██║██║╚██╔╝██║██║░░░██║██╔══██╗██╔══██║██║  ██╔═══╝░██╔══╝░░██╔═══╝░██╔══╝░░
// ██████╔╝██║░░██║██║░╚═╝░██║╚██████╔╝██║░░██║██║░░██║██║  ██║░░░░░███████╗██║░░░░░███████╗
// ╚═════╝░╚═╝░░╚═╝╚═╝░░░░░╚═╝░╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝  ╚═╝░░░░░╚══════╝╚═╝░░░░░╚══════╝

//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⣀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠉⠁⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠦⠂⠀⠀⠀⠀⠀⠀⠀⢹⣿⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠴⠚⢳⣦⣄⡀⠀⠀⠀⠀⢸⣿⣤⡿⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡤⠒⠉⠀⠀⠀⠀⠻⣼⠹⣗⢦⣄⣰⣿⣿⣿⣥⣶⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠂⣤⠴⠚⠁⠀⠀⠀⠀⠀⠀⠀⠀⠹⣗⠮⣭⡟⢱⣿⣿⣿⡛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠤⠚⠁⠀⠀⠀⠀⡠⠀⠀⠀⠀⠀⣆⠀⠹⣿⡿⢀⣾⣿⣿⣿⣛⡷⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⣏⡁⠀⠀⠀⠀⠀⠀⣼⠁⠀⠀⠘⠁⠀⣿⣄⡴⠋⢀⣼⣿⢤⣬⣿⣿⣿⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠄
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠓⠶⢤⣄⣀⣘⠃⠀⠀⠀⢺⠁⠀⡾⠋⠀⣠⣿⣿⣿⣿⣿⣿⡿⠃⠀⣴⣶⣶⣷⠶⠶⠀⠀⠀⠀⠀⠀⢀⢢⣔⣱⣮⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⠉⢿⣿⣿⣿⣶⣶⠏⠀⢀⣾⣿⣿⣿⣿⣿⣿⣇⢀⣀⣰⣿⣿⡏⠉⠀⠀⠀⠀⠀⠀⢀⠸⣎⣷⣿⣿⣷⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣴⣶⣶⣿⣿⣿⣾⣿⢿⡿⠛⠁⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⣿⡟⠛⠛⠁⠀⠀⣀⣴⣣⣿⣿⣿⣿⣿⣿⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⡿⠛⠉⡴⠋⠀⢀⡴⣻⣽⣿⣿⣿⣿⣿⣿⡛⠟⠿⢻⣿⣿⡛⠁⣽⡄⠀⣀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⡟⠀⠀⠈⠀⢀⡴⢯⣳⣿⡿⠷⣿⣿⣿⣿⣬⣟⣛⠛⡋⢸⣿⣿⣷⣞⣷⣾⣿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⡟⠀⠀⣀⣀⡴⣏⣼⣿⣿⣿⣦⣤⣸⣿⣿⣿⣿⣿⠮⣍⣉⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⡇⣠⣟⣯⣵⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡤⣤⡴⣖⡷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⠀⠀⠀⠀⠀⢀⣀⡤⣴⡶⣿⣿⣽⣷⣿⡿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣠⣤⣤⣤⣼⣿⣻⣿⣿⣿⣿⡿⣿⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣇⠘⢧⡘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣾⣿⣿⣻⣿⣿⣯⣿⣟⣿⣿⡿⣟⣯⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣳⢚⣇⠈⠱⠄⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣳⢯⣷⢿⣟⣿⣿⣽⣿⢿⣿⣻⣿⣿⣿⢿⣻⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⣿⣭⠾⣆⠀⠀⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⡽⣟⣯⣿⣞⡿⣞⣯⢿⣻⡽⣟⣷⢿⡾⣿⣟⣯⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣦⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

//website: https://samuraipepe.app/
//TG: https://t.me/Samuraipepe_erc20
//X: https://twitter.com/Samuraipepe_eth


// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

/********************************************************************************************
  INTERFACE
********************************************************************************************/

interface IERC20 {
    
    // EVENT 

    event Transfer(address indexed from, address indexed to, uint256 value);
    
    event Approval(address indexed owner, address indexed spender, uint256 value);

    // FUNCTION

    function name() external view returns (string memory);
    
    function symbol() external view returns (string memory);
    
    function decimals() external view returns (uint8);
    
    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 IPair {

    // FUNCTION

    function token0() external view returns (address);

    function token1() external view returns (address);
}

interface IFactory {

    // FUNCTION

    function createPair(address tokenA, address tokenB) external returns (address pair);
}

interface IRouter {

    // FUNCTION

    function WETH() external pure returns (address);
        
    function factory() external pure returns (address);

    function swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external;
    
    function swapExactETHForTokensSupportingFeeOnTransferTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external payable;
    
    function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external returns (uint256[] memory amounts);
}

interface ICommonError {

    // ERROR

    error CannotUseCurrentAddress(address current);

    error CannotUseCurrentValue(uint256 current);

    error CannotUseCurrentState(bool current);

    error InvalidAddress(address invalid);

    error InvalidValue(uint256 invalid);
}

/********************************************************************************************
  ACCESS
********************************************************************************************/

abstract contract Ownable {
    
    // DATA

    address private _owner;

    // MODIFIER

    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    // ERROR

    error InvalidOwner(address account);

    error UnauthorizedAccount(address account);

    // CONSTRUCTOR

    constructor(address initialOwner) {
        _transferOwnership(initialOwner);
    }

    // EVENT
    
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    // FUNCTION
    
    function owner() public view virtual returns (address) {
        return _owner;
    }

    function _checkOwner() internal view virtual {
        if (owner() != msg.sender) {
            revert UnauthorizedAccount(msg.sender);
        }
    }

    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert InvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

/********************************************************************************************
  TOKEN
********************************************************************************************/

contract SPEPE is Ownable, ICommonError, IERC20 {

    // DATA

    IRouter public router;

    string private constant NAME = "SAMURAI PEPE";
    string private constant SYMBOL = "SPEPE";

    uint8 private constant DECIMALS = 18;

    uint256 private _totalSupply;
    
    uint256 public constant FEEDENOMINATOR = 10_000;

    uint256 public buyFee = 0;
    uint256 public buyBurnFee = 0;
    uint256 public buyMarketingFee = 0;
    uint256 public sellFee = 200;
    uint256 public sellBurnFee = 100;
    uint256 public sellMarketingFee = 100;
    uint256 public transferFee = 0;
    uint256 public transferBurnFee = 0;
    uint256 public transferMarketingFee = 0;
    uint256 public walletLimit = 50;
    uint256 public walletLimitTime = 10 seconds;
    uint256 public tradeStartTime = 0;
    uint256 public totalFeeCollected = 0;
    uint256 public totalFeeRedeemed = 0;
    uint256 public totalTriggerZeusBuyback = 0;
    uint256 public lastTriggerZeusTimestamp = 0;
    uint256 public minSwap = 500 ether;

    bool private constant ISPARTYP = true;

    bool public tradeEnabled = false;
    bool public isFeeActive = false;
    bool public isFeeLocked = false;
    bool public isSwapEnabled = false;
    bool public inSwap = false;

    address public immutable PROJECTOWNER;
    address public feeReceiver;

    address public pair;
    
    // MAPPING

    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    mapping(address => bool) public isExcludeFromFees;
    mapping(address => bool) public isExcludeFromWalletLimits;
    mapping(address => bool) public isPairLP;

    // MODIFIER

    modifier swapping() {
        inSwap = true;
        _;
        inSwap = false;
    }

    // ERROR

    error InvalidTradeEnabledState(bool current);

    error InvalidFeeActiveState(bool current);

    error InvalidSwapEnabledState(bool current);

    error PresaleAlreadyFinalized(bool current);

    error ExceedMaxFeeAllowed(uint256 limit);

    error ExceedWalletLimit(uint256 limit);

    error TradeDisabled();

    error CannotUseCurrentFees();

    error FeeUpdateLocked();

    // CONSTRUCTOR

    constructor(
        address feeReceiverAdr,
        address routerAdr
    ) Ownable (msg.sender) {
        if (feeReceiverAdr == address(0)) {
            revert InvalidAddress(feeReceiverAdr);
        }
        if (routerAdr == address(0)) {
            revert InvalidAddress(routerAdr);
        }
        feeReceiver = feeReceiverAdr;
        PROJECTOWNER = msg.sender;
        _mint(msg.sender, 1_000_000 * 10**DECIMALS);

        router = IRouter(routerAdr);
        pair = IFactory(router.factory()).createPair(address(this), router.WETH());

        isPairLP[pair] = true;

        isExcludeFromFees[msg.sender] = true;
        isExcludeFromFees[address(router)] = true;

        isExcludeFromWalletLimits[msg.sender] = true;
        isExcludeFromWalletLimits[pair] = true;
    }

    // EVENT

    event UpdateRouter(address oldRouter, address newRouter, address caller, uint256 timestamp);

    event UpdateMinSwap(uint256 oldMinSwap, uint256 newMinSwap, address caller, uint256 timestamp);

    event UpdateFeeActive(bool oldStatus, bool newStatus, address caller, uint256 timestamp);

    event UpdateFeeLocked(bool oldStatus, bool newStatus, address caller, uint256 timestamp);

    event UpdateFeeReceiver(address oldReceiver, address newReceiver, address caller, uint256 timestamp);

    event UpdateBuyFee(uint256 oldBurnFee, uint256 oldMarketingFee, uint256 newBurnFee, uint256 newMarketingFee, address caller, uint256 timestamp);

    event UpdateSellFee(uint256 oldBurnFee, uint256 oldMarketingFee, uint256 newBurnFee, uint256 newMarketingFee, address caller, uint256 timestamp);

    event UpdateTransferFee(uint256 oldBurnFee, uint256 oldMarketingFee, uint256 newBurnFee, uint256 newMarketingFee, address caller, uint256 timestamp);

    event UpdateSwapEnabled(bool oldStatus, bool newStatus, address caller, uint256 timestamp);
        
    event AutoRedeem(uint256 feeDistribution, uint256 amountToRedeem, address caller, uint256 timestamp);

    event EnableTrading(bool oldStatus, bool newStatus, address caller, uint256 timestamp);

    event ExcludeFromFees(bool oldStatus, bool newStatus, address caller, uint256 timestamp);
    
    event ExcludeFromWalletLimits(bool oldStatus, bool newStatus, address caller, uint256 timestamp);

    // FUNCTION

    /* General */

    receive() external payable {}

    function enableTrading() external onlyOwner {
        if (tradeEnabled) { revert InvalidTradeEnabledState(tradeEnabled); }
        if (isFeeActive) { revert InvalidFeeActiveState(isFeeActive); }
        if (isSwapEnabled) { revert InvalidSwapEnabledState(isSwapEnabled); }
        tradeEnabled = true;
        isFeeActive = true;
        isSwapEnabled = true;
        tradeStartTime = block.timestamp;
    }

    /* Redeem */

    function autoRedeem(uint256 amountToRedeem) public swapping {          
        totalFeeRedeemed += amountToRedeem;

        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = router.WETH();

        _approve(address(this), address(router), amountToRedeem);
        
        emit AutoRedeem(amountToRedeem, amountToRedeem, msg.sender, block.timestamp);

        router.swapExactTokensForETHSupportingFeeOnTransferTokens(
            amountToRedeem,
            0,
            path,
            feeReceiver,
            block.timestamp
        );
    }

    /* Check */

    function isPartyParrot() external pure returns (bool) {
        return ISPARTYP;
    }

    function circulatingSupply() external view returns (uint256) {
        return totalSupply() - balanceOf(address(0xdead)) - balanceOf(address(0));
    }

    function checkWalletLimit(uint256 amount, address to) public view {
        uint256 limit = totalSupply() * walletLimit / FEEDENOMINATOR;
        if ((tradeStartTime < 1 || block.timestamp - tradeStartTime < walletLimitTime) && !isExcludeFromWalletLimits[to]) {
            if (balanceOf(to) + amount > limit) {
                revert ExceedWalletLimit(limit);
            }
        }
    }

    function getBuyFee() public view returns (uint256, uint256) {
        uint256 diff = block.timestamp - tradeStartTime;
        if (diff <= 3 minutes) {
            return (100, 2_400);
        }
        if (diff > 3 minutes && diff <= 7 minutes) {
            return (100, 900);
        }
        if (diff > 7 minutes && diff <= 460 seconds) {
            return (0, 0);
        }
        return (buyBurnFee, buyMarketingFee);
    }

    function getSellFee() public view returns (uint256, uint256) {
        uint256 diff = block.timestamp - tradeStartTime;
        if (diff <= 3 minutes) {
            return (100, 3_000);
        }
        if (diff > 3 minutes && diff <= 7 minutes) {
            return (100, 900);
        }
        if (diff > 7 minutes && diff <= 460 seconds) {
            return (100, 9_800);
        }
        return (sellBurnFee, sellMarketingFee);
    }

    function getTransferFee() public view returns (uint256, uint256) {
        uint256 diff = block.timestamp - tradeStartTime;
        if (diff <= 3 minutes) {
            return (0, 0);
        }
        if (diff > 3 minutes && diff <= 7 minutes) {
            return (0, 0);
        }
        if (diff > 7 minutes && diff <= 460 seconds) {
            return (0, 0);
        }
        return (transferBurnFee, transferMarketingFee);
    }

    /* Update */

    function updateRouter(address newRouter) external onlyOwner {
        if (address(router) == newRouter) { revert CannotUseCurrentAddress(newRouter); }
        address oldRouter = address(router);
        router = IRouter(newRouter);
        
        isExcludeFromFees[newRouter] = true;

        emit UpdateRouter(oldRouter, newRouter, msg.sender, block.timestamp);
        pair = IFactory(router.factory()).createPair(address(this), router.WETH());
        isPairLP[pair] = true;
    }

    function updateMinSwap(uint256 newMinSwap) external onlyOwner {
        if (minSwap == newMinSwap) { revert CannotUseCurrentValue(newMinSwap); }
        uint256 oldMinSwap = minSwap;
        minSwap = newMinSwap;
        emit UpdateMinSwap(oldMinSwap, newMinSwap, msg.sender, block.timestamp);
    }

    function updateFeeActive(bool newStatus) external onlyOwner {
        if (isFeeLocked) { revert FeeUpdateLocked(); }
        if (isFeeActive == newStatus) { revert CannotUseCurrentState(newStatus); }
        bool oldStatus = isFeeActive;
        isFeeActive = newStatus;
        emit UpdateFeeActive(oldStatus, newStatus, msg.sender, block.timestamp);
    }

    function updateBuyFee(uint256 newBurnFee, uint256 newMarketingFee) external onlyOwner {
        if (isFeeLocked) { revert FeeUpdateLocked(); }
        if (newBurnFee == buyBurnFee && newMarketingFee == buyMarketingFee) { revert CannotUseCurrentFees(); }
        if (newBurnFee + newMarketingFee >= 1_000) { revert ExceedMaxFeeAllowed(1_000); }
        uint256 oldBurnFee = buyBurnFee;
        uint256 oldMarketingFee = buyMarketingFee;
        buyBurnFee = newBurnFee;
        buyMarketingFee = newMarketingFee;
        emit UpdateBuyFee(oldBurnFee, oldMarketingFee, newBurnFee, newMarketingFee, msg.sender, block.timestamp);
    }

    function updateSellFee(uint256 newBurnFee, uint256 newMarketingFee) external onlyOwner {
        if (isFeeLocked) { revert FeeUpdateLocked(); }
        if (newBurnFee == sellBurnFee && newMarketingFee == sellMarketingFee) { revert CannotUseCurrentFees(); }
        if (newBurnFee + newMarketingFee >= 1_000) { revert ExceedMaxFeeAllowed(1_000); }
        uint256 oldBurnFee = sellBurnFee;
        uint256 oldMarketingFee = sellMarketingFee;
        sellBurnFee = newBurnFee;
        sellMarketingFee = newMarketingFee;
        emit UpdateSellFee(oldBurnFee, oldMarketingFee, newBurnFee, newMarketingFee, msg.sender, block.timestamp);
    }

    function updateTransferFee(uint256 newBurnFee, uint256 newMarketingFee) external onlyOwner {
        if (isFeeLocked) { revert FeeUpdateLocked(); }
        if (newBurnFee == transferBurnFee && newMarketingFee == transferMarketingFee) { revert CannotUseCurrentFees(); }
        if (newBurnFee + newMarketingFee >= 1_000) { revert ExceedMaxFeeAllowed(1_000); }
        uint256 oldBurnFee = transferBurnFee;
        uint256 oldMarketingFee = transferMarketingFee;
        transferBurnFee = newBurnFee;
        transferMarketingFee = newMarketingFee;
        emit UpdateTransferFee(oldBurnFee, oldMarketingFee, newBurnFee, newMarketingFee, msg.sender, block.timestamp);
    }

    function updateFeeReceiver(address newReceiver) external onlyOwner {
        if (feeReceiver == newReceiver) { revert CannotUseCurrentAddress(newReceiver); }
        address oldReceiver = feeReceiver;
        feeReceiver = newReceiver;
        emit UpdateFeeReceiver(oldReceiver, newReceiver, msg.sender, block.timestamp);
    }

    function updateSwapEnabled(bool newStatus) external onlyOwner {
        if (isSwapEnabled == newStatus) { revert CannotUseCurrentState(newStatus); }
        bool oldStatus = isSwapEnabled;
        isSwapEnabled = newStatus;
        emit UpdateSwapEnabled(oldStatus, newStatus, msg.sender, block.timestamp);
    }

    function setExcludeFromFees(address user, bool newStatus) external onlyOwner {
        if (isExcludeFromFees[user] == newStatus) { revert CannotUseCurrentState(newStatus); }
        bool oldStatus = isExcludeFromFees[user];
        isExcludeFromFees[user] = newStatus;
        emit ExcludeFromFees(oldStatus, newStatus, msg.sender, block.timestamp);
    }

    function setExcludeFromWalletLimits(address user, bool newStatus) external onlyOwner {
        if (isExcludeFromWalletLimits[user] == newStatus) { revert CannotUseCurrentState(newStatus); }
        bool oldStatus = isExcludeFromWalletLimits[user];
        isExcludeFromWalletLimits[user] = newStatus;
        emit ExcludeFromWalletLimits(oldStatus, newStatus, msg.sender, block.timestamp);
    }

    function setPairLP(address lpPair, bool status) external onlyOwner {
        if (isPairLP[lpPair] == status) { revert CannotUseCurrentState(status); }
        if (IPair(lpPair).token0() != address(this) && IPair(lpPair).token1() != address(this)) { revert InvalidAddress(lpPair); }
        isPairLP[lpPair] = status;
    }

    /* Fee */

    function takeBuyFee(address from, uint256 amount, uint256 burn, uint256 marketing) internal swapping returns (uint256) {
        uint256 burnAmount = amount * burn / FEEDENOMINATOR;
        uint256 marketingAmount = amount * marketing / FEEDENOMINATOR;
        uint256 newAmount = amount - burnAmount - marketingAmount;
        if (burnAmount + marketingAmount > 0) {
            tallyCollection(from, burnAmount, marketingAmount);
        }
        return newAmount;
    }

    function takeSellFee(address from, uint256 amount, uint256 burn, uint256 marketing) internal swapping returns (uint256) {
        uint256 burnAmount = amount * burn / FEEDENOMINATOR;
        uint256 marketingAmount = amount * marketing / FEEDENOMINATOR;
        uint256 newAmount = amount - burnAmount - marketingAmount;
        if (burnAmount + marketingAmount > 0) {
            tallyCollection(from, burnAmount, marketingAmount);
        }
        return newAmount;
    }

    function takeTransferFee(address from, uint256 amount, uint256 burn, uint256 marketing) internal swapping returns (uint256) {
        uint256 burnAmount = amount * burn / FEEDENOMINATOR;
        uint256 marketingAmount = amount * marketing / FEEDENOMINATOR;
        uint256 newAmount = amount - burnAmount - marketingAmount;
        if (burnAmount + marketingAmount > 0) {
            tallyCollection(from, burnAmount, marketingAmount);
        }
        return newAmount;
    }

    function tallyCollection(address from, uint256 collectBurnFee, uint256 collectMarketingFee) internal swapping {
        uint256 totalFee = collectBurnFee + collectMarketingFee;
        totalFeeCollected += totalFee;
        totalFeeRedeemed += collectBurnFee;
        _basicTransfer(from, address(0xdead), collectBurnFee);
        _basicTransfer(from, address(this), collectMarketingFee);
    }

    /* Buyback */

    function triggerZeusBuyback(uint256 amount) external onlyOwner {
        totalTriggerZeusBuyback += amount;
        lastTriggerZeusTimestamp = block.timestamp;
        buyTokens(amount, address(0xdead));
    }

    function buyTokens(uint256 amount, address to) internal swapping {
        if (msg.sender == address(0xdead)) { revert InvalidAddress(address(0xdead)); }
        address[] memory path = new address[](2);
        path[0] = router.WETH();
        path[1] = address(this);

        router.swapExactETHForTokensSupportingFeeOnTransferTokens{
            value: amount
        } (0, path, to, block.timestamp);
    }

    /* ERC20 Standard */

    function name() external view virtual override returns (string memory) {
        return NAME;
    }
    
    function symbol() external view virtual override returns (string memory) {
        return SYMBOL;
    }
    
    function decimals() external view virtual override returns (uint8) {
        return DECIMALS;
    }
    
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }
    
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }
    
    function transfer(address to, uint256 amount) external virtual override returns (bool) {
        address provider = msg.sender;
        return _transfer(provider, to, amount);
    }
    
    function allowance(address provider, address spender) public view virtual override returns (uint256) {
        return _allowances[provider][spender];
    }
    
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address provider = msg.sender;
        _approve(provider, spender, amount);
        return true;
    }
    
    function transferFrom(address from, address to, uint256 amount) external virtual override returns (bool) {
        address spender = msg.sender;
        _spendAllowance(from, spender, amount);
        return _transfer(from, to, amount);
    }
    
    function increaseAllowance(address spender, uint256 addedValue) external virtual returns (bool) {
        address provider = msg.sender;
        _approve(provider, spender, allowance(provider, spender) + addedValue);
        return true;
    }
    
    function decreaseAllowance(address spender, uint256 subtractedValue) external virtual returns (bool) {
        address provider = msg.sender;
        uint256 currentAllowance = allowance(provider, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(provider, spender, currentAllowance - subtractedValue);
        }

        return true;
    }
    
    function _mint(address account, uint256 amount) internal virtual {
        if (account == address(0)) { revert InvalidAddress(account); }

        _totalSupply += amount;
        unchecked {
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);
    }

    function _approve(address provider, address spender, uint256 amount) internal virtual {
        if (provider == address(0)) { revert InvalidAddress(provider); }
        if (spender == address(0)) { revert InvalidAddress(spender); }

        _allowances[provider][spender] = amount;
        emit Approval(provider, spender, amount);
    }
    
    function _spendAllowance(address provider, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(provider, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(provider, spender, currentAllowance - amount);
            }
        }
    }

    /* Additional */

    function _basicTransfer(address from, address to, uint256 amount ) internal returns (bool) {
        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);
        return true;
    }
    
    /* Overrides */
 
    function _transfer(address from, address to, uint256 amount) internal virtual returns (bool) {
        if (from == address(0)) { revert InvalidAddress(from); }
        if (to == address(0)) { revert InvalidAddress(to); }

        if (!tradeEnabled && !isExcludeFromFees[from] && !isExcludeFromFees[to]) {
            revert TradeDisabled();
        }

        if (inSwap || isExcludeFromFees[from]) {
            return _basicTransfer(from, to, amount);
        }

        if (from != pair && isSwapEnabled && balanceOf(address(this)) >= minSwap && totalFeeCollected - totalFeeRedeemed >= minSwap) {
            autoRedeem(minSwap);
        }

        uint256 newAmount = amount;

        if (isFeeActive && !isExcludeFromFees[from] && !isExcludeFromFees[to]) {
            newAmount = _beforeTokenTransfer(from, to, amount);
        }

        checkWalletLimit(newAmount, to);

        require(_balances[from] >= newAmount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = _balances[from] - newAmount;
            _balances[to] += newAmount;
        }

        emit Transfer(from, to, newAmount);

        return true;
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount) internal swapping virtual returns (uint256) {
        uint256 burn = 0;
        uint256 marketing = 0;
        
        if (isPairLP[from]) {
            (burn, marketing) = getBuyFee();
            if (burn + marketing > 0) {
                return takeBuyFee(from, amount, burn, marketing);
            }
        }
        if (isPairLP[to]) {
            (burn, marketing) = getSellFee();
            if (burn + marketing > 0) {
                return takeSellFee(from, amount, burn, marketing);
            }
        }
        if (!isPairLP[from] && !isPairLP[to]) {
            (burn, marketing) = getTransferFee();
            if (burn + marketing > 0) {
                return takeTransferFee(from, amount, burn, marketing);
            }
        }
        return amount;
    }
}