S Price: $0.747694 (-1.93%)

Contract Diff Checker

Contract Name:
EGGNOG

Contract Source Code:

File 1 of 1 : EGGNOG

// SPDX-License-Identifier: MIT

pragma solidity 0.8.17;

interface IDEXV2Router0201 {
    function factory() external pure returns (address);

    function WETH() external pure returns (address);

    struct route {
        /// @dev token from
        address from;
        /// @dev token to
        address to;
        /// @dev is stable route
        bool stable;
    }

    function getReserves(
        address tokenA,
        address tokenB,
        bool stable
    ) external view returns (uint256 reserveA, uint256 reserveB);

    function getAmountsOut(uint256 amountIn, route[] memory routes)
        external
        view
        returns (uint256[] memory amounts);

    function getAmountsIn(uint256 amountOut, route[] memory routes)
        external
        view
        returns (uint256[] memory amounts);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (
            uint256 amountToken,
            uint256 amountETH,
            uint256 liquidity
        );

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);



    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);
}

interface IDEXV2ROUTER02 is IDEXV2Router0201 {
    

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        route[] calldata routes,
        address to,
        uint256 deadline
    ) external;

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}

interface IDEXV2Pair {
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event Transfer(address indexed from, address indexed to, uint256 value);

    function name() external pure returns (string memory);

    function symbol() external pure returns (string memory);

    function decimals() external pure returns (uint8);

    function totalSupply() external view returns (uint256);

    function balanceOf(address owner) external view returns (uint256);

    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    function approve(address spender, uint256 value) external returns (bool);

    function transfer(address to, uint256 value) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint256 value
    ) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function PERMIT_TYPEHASH() external pure returns (bytes32);

    function nonces(address owner) external view returns (uint256);

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    event Mint(address indexed sender, uint256 amount0, uint256 amount1);
    event Burn(
        address indexed sender,
        uint256 amount0,
        uint256 amount1,
        address indexed to
    );
    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint256);

    function factory() external view returns (address);

    function token0() external view returns (address);

    function token1() external view returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 reserve0,
            uint112 reserve1,
            uint32 blockTimestampLast
        );

    function price0CumulativeLast() external view returns (uint256);

    function price1CumulativeLast() external view returns (uint256);

    function kLast() external view returns (uint256);

    function mint(address to) external returns (uint256 liquidity);

    function burn(address to)
        external
        returns (uint256 amount0, uint256 amount1);

    function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external;

    function skim(address to) external;

    function sync() external;

    function initialize(address, address) external;
}

interface IDEXV2Factory {
    event PairCreated(
        address indexed token0,
        address indexed token1,
        address pair,
        uint256
    );

    function feeTo() external view returns (address);

    function feeToSetter() external view returns (address);

    function getPair(
        address tokenA,
        address tokenB,
        bool stable
    ) external view returns (address _pair);

    function allPairs(uint256) external view returns (address pair);

    function allPairsLength() external view returns (uint256);

    function createPair(
        address tokenA,
        address tokenB,
        bool stable
    ) external returns (address pair);

    function setFeeTo(address) external;

    function setFeeToSetter(address) external;
}

library SafeMath {
    function tryAdd(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    function trySub(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    function tryMul(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    function tryDiv(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    function tryMod(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

library TransferHelper {
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0x095ea7b3, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper: APPROVE_FAILED"
        );
    }

    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0xa9059cbb, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper: TRANSFER_FAILED"
        );
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0x23b872dd, from, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper: TRANSFER_FROM_FAILED"
        );
    }

    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, "TransferHelper: ETH_TRANSFER_FAILED");
    }
}

interface IERC20 {
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event Transfer(address indexed from, address indexed to, uint256 value);

    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 owner) external view returns (uint256);

    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    function approve(address spender, uint256 value) external returns (bool);

    function transfer(address to, uint256 value) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint256 value
    ) external returns (bool);
}

interface ISTAKE {
    

    function swap(
        address _router,
        address swaptoken,
        address print
    ) external;

    function stake(uint256 value) external;

    function withdraw(uint256 value, address receiver) external;

    function claimReward(address _printer) external;

    function setPortion(uint256 _treasery, uint256 _printing) external;

    function setStake(
        uint256 _minimum,
        uint256 _tax,
        bool _on
    ) external;

    function SafeTransferToken(
        address _tokenAdd,
        address to,
        bool _transferETH
    ) external returns (bool);
}

contract Stake is ISTAKE {
    ///////// using libraries \\\\\\\\\
    using SafeMath for uint256;

    event Staked(address _stacker, uint256 amount);
    event Printed(address _printer, uint256 Amount);
    event Withdraw(address _stackers, uint256 amount, bool out);
    event DistributeReward(
        address _rewardToken,
        uint256 amount,
        uint256 totalStackers
    );
    event Claim(address _stacker, address _rewardToken, uint256 amount);


    address public Owner;
    address public immutable _callerToken; // authority contract which can regulate this
    address public nativeCoin; // native Wrraped coin address
    address public BURNED_ADDRESS = address(0xdead);

    bool stakeOn;
    uint256 claimTax;
    uint256 MINIMUM_STAKE_AMOUNT = 100000000000000000000; //100 Eggnog
    uint256 public totalStacked;

    uint256 printingPortion = 400000000000000000; //40%
    uint256 burningPortion = 600000000000000000; //60%

    struct ClaimInfo {
        uint256 totalCollectedClaim;
        uint256 pendingClaim;
    }

    bool permission = true; //permission will false when printing reward
    bool isEntered; //re-entrancy block
    mapping(address => mapping(address => ClaimInfo)) public claim;
    mapping(address => bool) public IsStacker;
    mapping(address => uint256) public stacked;
    mapping(address => uint256) indexByAdd;
    mapping(address => uint256) reseaveReward;
    address[] public stackers;

    modifier onlyToken() {
        require(msg.sender == _callerToken);
        permission = false;
        _;
        permission = true;
    }

    modifier onlyOwner() {
        require(msg.sender == Owner, "Only owner can call");
        _;
    }

    modifier reentrancyGurd() {
        require(!isEntered);
        isEntered = true;
        _;
        isEntered = false;
    }

    constructor(address _nativeCoin, address _owner) {
        require(_nativeCoin != address(0), "invalid nativeCoin address");
        nativeCoin = _nativeCoin;
        _callerToken = msg.sender;
        Owner = _owner;
    }

    receive() external payable {}

    event swapPrintedToken(uint256 _printAmount);

    function setBurningWallet(address _burned) external onlyOwner {
        require(_burned != address(0) && _burned != BURNED_ADDRESS);
        BURNED_ADDRESS = _burned;
    }

    function setPortion(uint256 _treasery, uint256 _printing)
        external
        onlyOwner
    {
        burningPortion = _treasery;
        printingPortion = _printing;
    }

    function setStake(
        uint256 _minimum,
        uint256 _tax,
        bool _on
    ) external onlyOwner {
        claimTax = _tax;
        stakeOn = _on;
        MINIMUM_STAKE_AMOUNT = _minimum;
    }

    function swap(
        address _router,
        address swaptoken,
        address printToken
    ) external onlyToken {
        uint256 finalAmount;
        if (swaptoken == printToken) {
            finalAmount = (IERC20(swaptoken).balanceOf(address(this))).sub(
                reseaveReward[swaptoken]
            );
        } else {
            uint256 initBal = IERC20(printToken).balanceOf(address(this));
            uint256 _amount = IERC20(swaptoken).balanceOf(address(this)).sub(
                reseaveReward[swaptoken]
            );
            TransferHelper.safeApprove(swaptoken, _router, _amount);

            IDEXV2Router0201.route[] memory pathroutes;
            if (swaptoken == nativeCoin || printToken == nativeCoin) {
                pathroutes = new IDEXV2Router0201.route[](1); //native swap
                pathroutes[0] = IDEXV2Router0201.route({
                    from: swaptoken,
                    to: printToken,
                    stable: false
                });
            } else {
                //token to token swap
                pathroutes = new IDEXV2Router0201.route[](2); //native swap
                pathroutes[0] = IDEXV2Router0201.route({
                    from: swaptoken,
                    to: nativeCoin,
                    stable: false
                });
                pathroutes[1] = IDEXV2Router0201.route({
                    from: nativeCoin,
                    to: printToken,
                    stable: false
                });
            }
            uint256[] memory amounts = IDEXV2ROUTER02(_router).getAmountsOut(
                _amount,
                pathroutes
            );
            if (amounts[1] > 100) {
                IDEXV2ROUTER02(_router)
                    .swapExactTokensForTokensSupportingFeeOnTransferTokens(
                        _amount,
                        0,
                        pathroutes,
                        address(this),
                        block.timestamp
                    );
                finalAmount = (IERC20(printToken).balanceOf(address(this))).sub(
                    initBal
                );
                emit Printed(printToken, finalAmount);
            }
        }
        if (finalAmount > 0) {
            uint256 burningAmount = (finalAmount.mul(burningPortion)).div(
                burningPortion.add(printingPortion)
            );
            if (burningAmount > 0) {
                TransferHelper.safeTransfer(
                    printToken,
                    BURNED_ADDRESS,
                    burningAmount
                );
            }
            uint256 _distribute = finalAmount.sub(burningAmount);
            if (_distribute > 0) _distributeReward(printToken, _distribute);
        }
    }

    function _distributeReward(address _printerAdd, uint256 amount) private {
        uint256 _td;
        uint256 returnAmount;
        uint256 _totalstaker = stackers.length;
        if (stakeOn && _totalstaker > 0) {
            for (uint256 i = 0; i < _totalstaker; i++) {
                uint256 _rA = ((stacked[stackers[i]]).mul(amount)).div(
                    totalStacked
                );
                claim[stackers[i]][_printerAdd].pendingClaim += _rA;
                _td = _td.add(_rA);
            }
            reseaveReward[_printerAdd] += _td;
            returnAmount = amount.sub(_td);
            emit DistributeReward(_printerAdd, _td, _totalstaker);
        } else {
            returnAmount = amount;
        }
        if (returnAmount > 0) {
            TransferHelper.safeTransfer(
                _printerAdd,
                _callerToken,
                returnAmount
            );
        }
    }

    function stake(uint256 value) external {
        require(
            value >= MINIMUM_STAKE_AMOUNT && permission /*re-entrancy when printing permission*/
        );
        TransferHelper.safeTransferFrom(
            _callerToken,
            msg.sender,
            address(this),
            value
        );
        stacked[msg.sender] = stacked[msg.sender].add(value);
        totalStacked = totalStacked.add(value);
        if (!IsStacker[msg.sender]) {
            IsStacker[msg.sender] = true;
            indexByAdd[msg.sender] = stackers.length;
            stackers.push(msg.sender);
        }
        emit Staked(msg.sender, value);
    }

    function withdraw(uint256 value, address receiver) external reentrancyGurd {
        require(
            IsStacker[msg.sender] && value <= stacked[msg.sender] && permission /*re-entrancy when printing permission*/
        );
        stacked[msg.sender] = stacked[msg.sender].sub(value);
        totalStacked = totalStacked.sub(value);
        TransferHelper.safeTransfer(_callerToken, receiver, value);
        if (stacked[msg.sender] == 0) {
            IsStacker[msg.sender] = false;
            stackers[indexByAdd[msg.sender]] = stackers[stackers.length - 1];
            stackers.pop();
            emit Withdraw(msg.sender, value, true);
        } else {
            emit Withdraw(msg.sender, value, false);
        }
    }

    function claimReward(address _printer) external reentrancyGurd {
        uint256 _claim = claim[msg.sender][_printer].pendingClaim;
        require(
            _claim > 0 && reseaveReward[_printer] >= _claim && permission, /*re-entrancy when printing permission*/
            "INSUFFICIENT RESERVE REWARD"
        );
        claim[msg.sender][_printer].pendingClaim -= _claim;
        claim[msg.sender][_printer].totalCollectedClaim += _claim;
        reseaveReward[_printer] -= _claim;
        uint256 ct = (_claim.mul(claimTax)).div(1000000000000000000);
        if (ct > 0) {
            TransferHelper.safeTransfer(_printer, BURNED_ADDRESS, ct);
        }
        TransferHelper.safeTransfer(_printer, msg.sender, _claim.sub(ct));
        emit Claim(msg.sender, _printer, _claim.sub(ct));
    }

    function SafeTransferToken(
        address _tokenAdd,
        address to,
        bool _transferETH
    ) external onlyOwner returns (bool) {
        require(to != address(0), "ERC20: transfer to the zero address");
        uint256 _surplasAmount = _transferETH
            ? address(this).balance
            : (IERC20(_tokenAdd).balanceOf(address(this))).sub(
                reseaveReward[_tokenAdd]
            );
        require(
            _surplasAmount > 0,
            "Transfer amount must be greater than zero"
        );
        if (_transferETH) {
            TransferHelper.safeTransferETH(to, _surplasAmount);
        } else TransferHelper.safeTransfer(_tokenAdd, to, _surplasAmount);
        return true;
    }

    function transferOwnership(address _owner) external onlyOwner {
        require(_owner != address(0), "INVALID ADD");
        Owner = _owner;
    }
}

contract EGGNOG is IERC20 {
    using SafeMath for uint256;
    address public Owner;

    string constant _name = "EGGNOG";
    string constant _symbol = "Eggnog";
    uint8 constant _decimals = 18;
    uint256 public totalSupply = 10000000 * (10**_decimals); // 200M Initial supply
    uint256 constant maxSupply = 69420000000 * (10**_decimals); // 69B 420M Max Supply;

    uint256 public BLAST_THRESHOLD = 65000000000 * (10**_decimals); //65B threshold for regular mode
    uint256 BLAST_THRESHOLD_INCREASING_RATE = 20000000000000000; //2%

    event SwapBackSuccess(
        uint256 tokenAmount,
        uint256 ETHAmountReceived,
        bool success
    );

    event Tx(
        uint256 amount,
        uint256 newAmount,
        uint256 mintAmount,
        uint256 contractAmount
    );
    event StakeContractChanges(address Address);
    event UpgradedMode(
        string _mode,
        uint256 ActivateAt,
        uint256 activatePriceAt
    );

    uint256 public BURNING_FEE = 300000000000000000; // 20% treasury fee
    uint256 public PRINTING_FEE = 300000000000000000; // 20% treasury fee

    address public PRINTER_TOKEN = 0xf26Ff70573ddc8a90Bd7865AF8d7d70B8Ff019bC; //egg
    address PEG_TOKEN_ADDRESS;

    ISTAKE public eggnog_stake;

    IDEXV2ROUTER02 public DEXV2Router =
        IDEXV2ROUTER02(0x1D368773735ee1E678950B7A97bcA2CafB330CDc); //shadow router02
    IDEXV2Pair public DEXV2Pair;

    struct balanceInfo {
        uint256 balance;
        uint256 update;
    }

    mapping(address => balanceInfo) _balances;
    mapping(address => mapping(address => uint256)) _allowances;
    mapping(address => bool) public IsExcludeFromFee;
    mapping(address => bool) public IsExcludeFromMaxTx;
    mapping(address => bool) public IsLiquidityProvider;
    mapping(address => bool) public AMMPair;

    bool IsEntered;

    uint256 public immutable buyFees =  50000000000000000; //5%
    uint256 public immutable sellFees = 30000000000000000; //3%

    uint256 immutable Blast_Fee = 8000000000000000; //0.8%

    bool public BLAST_MODE;
    bool STABLE_MODE;
    bool public HATCH_MODE;
    bool VOLUME_MODE;
    bool public APY_MODE;
    bool public PRINTING_ENABLE = true;

    uint256 constant pegDenominator = 10**(_decimals); // Peg calculation denominator according to decimal number

    //For APY
    uint256 public APY_UPDATED_AT;
    uint256 public Expedted_price;
    uint256 public APY_PERIOD;
    uint256 public APY_RATE_PER_PERIOD;

    //For HFT trading
    bool HFT; // HFT => High frequency Trading Mode (Demotivate Holder to early sell with high tax)
    uint256 HFTFee = 20000000000000000; //2%
    uint256 QuickSellFee = 10000000000000000; //1%
    uint256 HFTTimingThreshold = 60 * 60; // HFT within an Hour
    uint256 QuickSellTimingThreshold = 7 * 24 * 60 * 60; // QuickSell with in a week;

    //For Jump Mode
    uint256 public Hatch_THRESHOLD = 500000000 * (10**_decimals); //amount of peg token in lp pool
    uint256 public Reserve_flactuate_rate = 200000000000000000; //on 4x of lp growth
    uint256 public peg_flactuate_rate = 20000000000000000; //10% of peg balance
    uint256 public RESERVE_PEG_LP;
    uint256 public LAST_RESERVE_PEG_LP;

    //For swap back
    uint256 public RESERVE_FOR_PRINT;
    uint256 MINIMUM_SWAPBACK = 10000000000000000000; //10 eggnog

    //Limited TX mode (LTM)
    bool LTM = true;
    uint256 immutable GSL = 100000000000000000; // General sell limit (GSL) => 10% of peg $eggnog amount can sell at a time On LLS mode.

    //For price appreciation and depreciation
    bool public Buy_Appreciation_Mode;
    bool public Sell_Depreciation_Mode;
    uint256 public Sell_Depreciation_Rate;
    uint256 public Buy_Appreciation_Rate;
    uint256 public HigherThreshold;
    uint256 public LowerThreshold;
    uint256 public App_Rate;
    uint256 BuyAppTxLimit;
    uint256 SellDepTxLimit;

    bool init;
    uint256 initialPrice;

    struct route {
        /// @dev token from
        address from;
        /// @dev token to
        address to;
        /// @dev is stable route
        bool stable;
    }

    modifier onlyOwner() {
        require(msg.sender == Owner, "Caller isn't owner");
        _;
    }

    modifier reentrancyGurd() {
        require(IsEntered == false);
        IsEntered = true;
        _;
        IsEntered = false;
    }

    constructor() {
        Owner = msg.sender;
        IsLiquidityProvider[msg.sender] = true;
        eggnog_stake = new Stake(DEXV2Router.WETH(), msg.sender);
        IsExcludeFromMaxTx[address(this)] = true;
        IsExcludeFromMaxTx[address(eggnog_stake)] = true;
        _balances[msg.sender].balance = totalSupply;
    }

    receive() external payable {}

    function name() public view virtual returns (string memory) {
        return _name;
    }

    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account].balance;
    }

    function transfer(address to, uint256 value) public virtual returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    function allowance(address owner, address spender)
        public
        view
        virtual
        returns (uint256)
    {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 value)
        public
        virtual
        returns (bool)
    {
        require(spender != address(0), "INVALID ZERO ADD");
        _allowances[msg.sender][spender] += value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 value
    ) public virtual returns (bool) {
        address spender = msg.sender;
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    //////////////////////////////////// internal functions \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

    function _spendAllowance(
        address owner,
        address spender,
        uint256 value
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= value, "Exceed Allowance");
            unchecked {
                _allowances[owner][spender] = currentAllowance - value;
            }
        }
    }

    function _mint(address account, uint256 value) private {
        require(account != address(0), "INVALID MINTER ADDRESS");
        if (totalSupply < maxSupply) {
            if (totalSupply.add(value) > maxSupply) {
                uint256 _r = maxSupply.sub(totalSupply); //shouldn't exceed max supply
                totalSupply += _r;
                _balances[account].balance = (_balances[account].balance).add(
                    _r
                );
            } else {
                _balances[account].balance = (_balances[account].balance).add(
                    value
                );
                totalSupply += value;
            }
        }
        if (totalSupply >= BLAST_THRESHOLD && BLAST_THRESHOLD != maxSupply) {
            BLAST_MODE = true;
            BLAST_THRESHOLD = totalSupply == maxSupply
                ? maxSupply
                : (BLAST_THRESHOLD.mul(BLAST_THRESHOLD_INCREASING_RATE)).div(
                    pegDenominator
                );
            BURNING_FEE = PRINTING_FEE = 500000000000000000;
            emit UpgradedMode("Blast", block.timestamp, Expedted_price);
        }
        emit Transfer(address(0), account, value);
    }

    function swapTokensForPegToken(uint256 tokenAmount)
        private
        returns (uint256 swaped)
    {
        // generate the DEX pair path of token -> wETH

        IDEXV2Router0201.route[]
            memory pathroutes = new IDEXV2Router0201.route[](1);
        pathroutes[0] = IDEXV2Router0201.route({
            from: address(this),
            to: PEG_TOKEN_ADDRESS,
            stable: false
        });

        _allowances[address(this)][address(DEXV2Router)] += tokenAmount;
        uint256 _preBal = IERC20(PEG_TOKEN_ADDRESS).balanceOf(
            address(eggnog_stake)
        );
        // execute the swap
        DEXV2Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
            tokenAmount,
            0, // accept any amount of ETH
            pathroutes,
            address(eggnog_stake),
            block.timestamp
        );
        return
            (IERC20(PEG_TOKEN_ADDRESS).balanceOf(address(eggnog_stake))).sub(
                _preBal
            );
    }

    function swapBack() private {
        uint256 contractBalance = _balances[address(this)].balance;
        if (RESERVE_FOR_PRINT < MINIMUM_SWAPBACK) {
            return;
        }
        if (contractBalance >= RESERVE_FOR_PRINT) {
            uint256 AMountToSwapForPegToken = RESERVE_FOR_PRINT;
            uint256 _maxSwap = LTM
                ? MaximumTxOnLTM()
                : (totalSupply.mul(2)).div(100); //max amount for swapback
            if (RESERVE_FOR_PRINT > _maxSwap)
                AMountToSwapForPegToken = _maxSwap;
            swapTokensForPegToken(AMountToSwapForPegToken);
            eggnog_stake.swap(
                address(DEXV2Router),
                PEG_TOKEN_ADDRESS,
                PRINTER_TOKEN
            );
            RESERVE_FOR_PRINT = RESERVE_FOR_PRINT.sub(AMountToSwapForPegToken);
        }
    }

    function _transfer(
        address from,
        address to,
        uint256 amount
    ) private returns (bool) {
        require(from != address(0) && !AMMPair[to], "INVALID SENDER WALLET");
        require(
            from == address(this) ? true : IsEntered == false,
            "Reentrancy Err"
        );
        IsEntered = true;
        uint256 feeAmount;
        //updating sender balance
        uint256 fromBalance = _balances[from].balance;
        require(fromBalance >= amount, "INSUFFICIENT SENDER BALANCE");
        unchecked {
            // Overflow not possible: value <= fromBalance <= totalSupply.
            _balances[from].balance = fromBalance - amount;
        }

        //ON BUY
        if (
            from == address(DEXV2Pair) &&
            !IsLiquidityProvider[to] &&
            !BLAST_MODE
        ) {
            feeAmount = !IsExcludeFromFee[to]
                ? (amount.mul(buyFees)).div(pegDenominator)
                : 0;
            _brebase(amount);
            _update(from, to, amount.sub(feeAmount)); //update receiver balance
            _balances[to].update = block.timestamp; // update buy timestamp For HFT trading
        }
        //ON SELL
        else if (
            to == address(DEXV2Pair) &&
            !IsLiquidityProvider[from] &&
            !BLAST_MODE
        ) {
            uint256 _sellAmount = MaximumTxOnLTM();
            require(
                !IsExcludeFromMaxTx[from] && LTM ? amount <= _sellAmount : true,
                "EXCEED LTM SELL LIMIT"
            );
            feeAmount = !IsExcludeFromFee[from] && Sell_Depreciation_Mode
                ? (amount.mul(sellFees)).div(pegDenominator)
                : 0; //No sell taxes in hard peg stable mode;

            if (HFT && !IsExcludeFromFee[from]) {
                uint256 HFTaxAmount = (block.timestamp).sub(
                    _balances[from].update
                ) <= HFTTimingThreshold
                    ? (amount.mul(HFTFee)).div(pegDenominator)
                    : (block.timestamp).sub(_balances[from].update) <=
                        QuickSellTimingThreshold
                    ? (amount.mul(QuickSellFee.mul(10))).div(pegDenominator)
                    : 0;
                feeAmount = feeAmount.add(HFTaxAmount);
            }

            if (
                from != address(this) &&
                from != address(eggnog_stake) &&
                !IsExcludeFromFee[from] &&
                PRINTING_ENABLE
            ) swapBack();
            _srebase(from, amount.sub(feeAmount), feeAmount);
        }
        //if(isTransfer || IsLiquidityProvider[from] || IsLiquidityProvider[to] || BLAST_MODE)
        else {
            if (BLAST_MODE) {
                if (from == address(DEXV2Pair) && !IsExcludeFromFee[to])
                    feeAmount = (amount.mul(Blast_Fee)).div(pegDenominator);
                if (to == address(DEXV2Pair) && !IsExcludeFromFee[from]) {
                    uint256 _price;
                    feeAmount = (amount.mul(Blast_Fee)).div(pegDenominator);
                    if (PRINTING_ENABLE && from != address(this)) swapBack();
                    (uint256 reserve0, uint256 reserve1, ) = DEXV2Pair
                        .getReserves();
                    uint256 amountWithoutFee = amount.sub(feeAmount);
                    IDEXV2Router0201.route[] memory pathroutes = new IDEXV2Router0201.route[](1);
                     pathroutes[0] = IDEXV2Router0201.route({
                        from: address(this),
                        to: PEG_TOKEN_ADDRESS,
                        stable: false
                      });
                    uint _amountOut = DEXV2Router.getAmountsOut(amountWithoutFee, pathroutes)[1];
                    if (DEXV2Pair.token0() == address(this)) {
                        
                        _price = ((reserve1.sub(_amountOut)).mul(pegDenominator))
                            .div(reserve0.add(amountWithoutFee));
                        RESERVE_PEG_LP = reserve1.sub(_amountOut);
                    } else {
                        _price = ((reserve0.sub(_amountOut)).mul(pegDenominator))
                            .div(reserve1.add(amountWithoutFee));
                        RESERVE_PEG_LP = reserve0.sub(_amountOut);
                    }
                    if (_price <= Expedted_price) {
                        BLAST_MODE = false;
                        Expedted_price = _price;
                        BURNING_FEE = PRINTING_FEE = 300000000000000000;
                        _upgradeApp(
                            App_Rate,
                            Buy_Appreciation_Mode,
                            Sell_Depreciation_Mode,
                            VOLUME_MODE,
                            BuyAppTxLimit,
                            SellDepTxLimit
                        ); //Fix app and dep according to new price
                        LAST_RESERVE_PEG_LP = RESERVE_PEG_LP;
                    }
                }
            } else {
                if (from != address(DEXV2Pair) && to != address(DEXV2Pair))
                    DISTRIBUTE();

                if (IsLiquidityProvider[from] || IsLiquidityProvider[to]) {
                    IsLiquidityProvider[from] = false;
                    IsLiquidityProvider[to] = false;
                }
            }
            _update(from, to, amount.sub(feeAmount)); //update receiver balances
        }

        if (feeAmount > 0) {
            if (PRINTING_ENABLE) {
                uint256 printingAmount = (
                    feeAmount.mul(PRINTING_FEE.add(BURNING_FEE))
                ).div(pegDenominator);
                RESERVE_FOR_PRINT += printingAmount;
            }
            _update(from, address(this), feeAmount);
        }
        IsEntered = false;
        return true;
    }

    function _update(
        address from,
        address to,
        uint256 value
    ) internal {
        require(to != address(0), "INVALID RECEIVER WALLET");
        unchecked {
            // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
            _balances[to].balance += value;
        }
        emit Transfer(from, to, value);
    }

    function _brebase(uint256 amount) private {
        uint256 newAmount;
        uint256 mintAmount;
        uint256 contractAmount;
        uint256 pairEggnogBal = _balances[address(DEXV2Pair)].balance;
        //uint256 pairPegBal = IERC20(PEG_TOKEN_ADDRESS).balanceOf(address(DEXV2Pair));
        //_apy(); // APY rising

        (uint256 reserve0, uint256 reserve1, ) = DEXV2Pair.getReserves();

        IDEXV2Router0201.route[]
            memory pathroutes = new IDEXV2Router0201.route[](1);
        pathroutes[0] = IDEXV2Router0201.route({
            from: PEG_TOKEN_ADDRESS,
            to: address(this),
            stable: false
        });
        uint256[] memory amounts = DEXV2Router.getAmountsIn(amount, pathroutes);
        if (DEXV2Pair.token0() == address(this)) 
            RESERVE_PEG_LP = reserve1.add(amounts[0]);
         else 
            RESERVE_PEG_LP = reserve0.add(amounts[0]);
        
        

        newAmount = (pegDenominator.mul(RESERVE_PEG_LP)).div(Expedted_price); //expected new pair LADDER balance for repeg price

        if (Buy_Appreciation_Mode) {
            //On Buy appreciation
            uint256 newPrice = VOLUME_MODE
                ? Expedted_price.add(
                    (amount.mul(HigherThreshold.sub(Expedted_price))).div(
                        pairEggnogBal
                    )
                )
                : Expedted_price.add(Buy_Appreciation_Rate);
            uint256 price = (pegDenominator.mul(RESERVE_PEG_LP)).div(
                pairEggnogBal.add(amount)
            );
            if (price > newPrice && newPrice > 0 && newPrice > Expedted_price) {
                newAmount = (pegDenominator.mul(RESERVE_PEG_LP)).div(newPrice);
                Expedted_price = newPrice;
            }
        }

        if (newAmount > pairEggnogBal) {
            uint256 supplyAmount = newAmount.sub(pairEggnogBal); //require amount to repeg with added more vlue in pair
            uint256 _rb = (_balances[address(this)].balance).sub(
                RESERVE_FOR_PRINT
            ); //contract available balance without printing reserve to repeg
            if (_rb > supplyAmount) {
                //is contract reserve is enough for repeg
                _balances[address(this)].balance = (
                    _balances[address(this)].balance
                ).sub(supplyAmount);
                _update(address(this), address(DEXV2Pair), supplyAmount);
            } else {
                mintAmount = supplyAmount.sub(_rb); //need to mint new token to repeg
                if (_rb > 0) {
                    _balances[address(this)].balance = (
                        _balances[address(this)].balance
                    ).sub(_rb);
                    _update(address(this), address(DEXV2Pair), _rb);
                }
                if (mintAmount > 0) {
                    _mint(address(DEXV2Pair), mintAmount);
                }
            }
        } else {
            //adjust the balance to repeg if pair has exceed amount then require
            contractAmount = pairEggnogBal.sub(newAmount);
            //transfer extra funds to contract from pair
            _balances[address(DEXV2Pair)].balance = (
                _balances[address(DEXV2Pair)].balance
            ).sub(contractAmount);
            _update(address(DEXV2Pair), address(this), contractAmount);
        }
        emit Tx(amount, newAmount, mintAmount, contractAmount);
    }

    function _srebase(
        address sender,
        uint256 _amount,
        uint256 _fee
    ) private {
        uint256 contractAmount;
        uint256 newAmount;
        uint256 mintAmount;
        (uint256 reserve0, uint256 reserve1, ) = DEXV2Pair.getReserves();
        uint256 pairEggnogBal = _balances[address(DEXV2Pair)].balance;
        uint256 pairPegTokenBal = IERC20(PEG_TOKEN_ADDRESS).balanceOf(
            address(DEXV2Pair)
        );
        if (msg.sender == address(DEXV2Router)) {
            uint256 optimalAmount = ((_amount.add(_fee)).mul(pairPegTokenBal))
                .div(pairEggnogBal);
            require(
                address(DEXV2Router).balance < optimalAmount &&
                    IERC20(PEG_TOKEN_ADDRESS).allowance(
                        sender,
                        address(DEXV2Router)
                    ) <
                    optimalAmount,
                "Only LiquidityAdder can addLiquidity or remove WNATIVE allowance in router to sell"
            );
        }

        IDEXV2Router0201.route[]
            memory pathroutes = new IDEXV2Router0201.route[](1);
        pathroutes[0] = IDEXV2Router0201.route({
            from: address(this),
            to: PEG_TOKEN_ADDRESS,
            stable: false
        });


        if(DEXV2Pair.token0() == address(this))
                RESERVE_PEG_LP = reserve1.sub(DEXV2Router.getAmountsOut(_amount, pathroutes)[1]); 
            else
               RESERVE_PEG_LP = reserve0.sub(DEXV2Router.getAmountsOut(_amount, pathroutes)[1]);       
            


        if (sender != address(this)) {
            //if contract is selling for printing, peg will remain stable

            if (pairPegTokenBal >= Hatch_THRESHOLD && !HATCH_MODE) {
                HATCH_MODE = true;
                LAST_RESERVE_PEG_LP = RESERVE_PEG_LP;
                emit UpgradedMode("HATCH", block.timestamp, Expedted_price);
            }

            if (
                (HATCH_MODE &&
                    RESERVE_PEG_LP >
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.add(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator)) ||
                (HATCH_MODE &&
                    RESERVE_PEG_LP <
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.sub(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator))
            ) {
                if (
                    RESERVE_PEG_LP >
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.add(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator)
                ) {
                    Expedted_price = Expedted_price.add(
                        (Expedted_price.mul(peg_flactuate_rate)).div(
                            pegDenominator
                        )
                    );
                }
                if (
                    RESERVE_PEG_LP <
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.sub(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator)
                ) {
                    Expedted_price = Expedted_price.sub(
                        (Expedted_price.mul(peg_flactuate_rate)).div(
                            pegDenominator
                        )
                    );
                }

                newAmount = (pegDenominator.mul(RESERVE_PEG_LP)).div(
                    Expedted_price
                );
                if (Buy_Appreciation_Mode || Sell_Depreciation_Mode)
                    _upgradeApp(
                        App_Rate,
                        Buy_Appreciation_Mode,
                        Sell_Depreciation_Mode,
                        VOLUME_MODE,
                        BuyAppTxLimit,
                        SellDepTxLimit
                    ); //Fix app and dep threshold according to new price
                LAST_RESERVE_PEG_LP = RESERVE_PEG_LP;
                emit UpgradedMode("HATCH", block.timestamp, Expedted_price);
            } else _apy();

            if (
                Sell_Depreciation_Mode &&
                sender != address(this) &&
                Expedted_price.sub(LowerThreshold) > 100
            ) {
                uint256 newPrice = VOLUME_MODE
                    ? Expedted_price.sub(
                        (_amount.mul(Expedted_price.sub(LowerThreshold))).div(
                            pairEggnogBal
                        )
                    )
                    : Expedted_price.sub(Sell_Depreciation_Rate);
                newAmount = (pegDenominator.mul(RESERVE_PEG_LP)).div(newPrice);
                uint256 _price = (pegDenominator.mul(RESERVE_PEG_LP)).div(
                    pairEggnogBal
                );
                if (_price > LowerThreshold && newPrice > LowerThreshold) {
                    newAmount = (pegDenominator.mul(RESERVE_PEG_LP)).div(
                        Expedted_price
                    );
                    Expedted_price = newPrice;
                }
            }
        }

        newAmount = (pegDenominator.mul(RESERVE_PEG_LP)).div(Expedted_price);

        if (newAmount > pairEggnogBal) {
            uint256 supplyAmount = newAmount.sub(pairEggnogBal); //require amount to repeg with added more value in pair
            if (_amount > supplyAmount) {
                //if selling amount is enough
                _balances[address(DEXV2Pair)].balance = (
                    _balances[address(DEXV2Pair)].balance
                ).add(supplyAmount);
                contractAmount = _amount.sub(supplyAmount);
                _balances[address(this)].balance = (
                    _balances[address(this)].balance
                ).add(contractAmount);
            } else {
                _balances[address(DEXV2Pair)].balance = (
                    _balances[address(DEXV2Pair)].balance
                ).add(_amount);
                uint256 surplasAmount = supplyAmount.sub(_amount);
                uint256 _rb = (_balances[address(this)].balance).sub(
                    RESERVE_FOR_PRINT
                );
                if (_rb > surplasAmount) {
                    //is selling and contract reserve is enough
                    _balances[address(this)].balance = (
                        _balances[address(this)].balance
                    ).sub(surplasAmount);
                    _balances[address(DEXV2Pair)].balance = (
                        _balances[address(DEXV2Pair)].balance
                    ).add(surplasAmount);
                    emit Transfer(
                        address(this),
                        address(DEXV2Pair),
                        surplasAmount
                    );
                } else {
                    mintAmount = surplasAmount.sub(_rb); //if need to mint new token
                    if (_rb > 0) {
                        _balances[address(this)].balance = (
                            _balances[address(this)].balance
                        ).sub(_rb);
                        _balances[address(DEXV2Pair)].balance = (
                            _balances[address(DEXV2Pair)].balance
                        ).add(_rb);
                        emit Transfer(address(this), address(DEXV2Pair), _rb);
                    }
                    if (mintAmount > 0) {
                        _mint(address(DEXV2Pair), mintAmount);
                    }
                }
            }
        } else {
            //adjust the balance to repeg if pair has exceed amount then require
            uint256 expectedDiff = pairEggnogBal.sub(newAmount);
            uint256 expectedPairAmount = pairEggnogBal.sub(expectedDiff);
            _balances[address(DEXV2Pair)].balance = expectedPairAmount.sub(
                _amount.add(_fee)
            );
            contractAmount = _amount.add(expectedDiff);
            DEXV2Pair.sync(); //external syncing  reserve to insure expected return for seller inspite repeging
            _balances[address(DEXV2Pair)].balance = expectedPairAmount; //then assign expected balance for repeg
            //transfer extra funds to contract from pair
            _balances[address(this)].balance = (
                _balances[address(this)].balance
            ).add(contractAmount);
            emit Transfer(address(DEXV2Pair), address(this), contractAmount);
        }

        emit Transfer(sender, address(DEXV2Pair), _amount);
        emit Tx(_amount, newAmount, mintAmount, contractAmount);
    }

    function setAPY(
        uint256 _apy_rate_per_period,
        uint256 _upgradingPeriod,
        bool _apy_mode
    ) external onlyOwner {
        APY_PERIOD = _upgradingPeriod;
        if (_upgradingPeriod > 0) {
            APY_RATE_PER_PERIOD = _apy_rate_per_period.add(pegDenominator);
            APY_UPDATED_AT = block.timestamp;
            APY_MODE = _apy_mode;
            if (_apy_mode)
                emit UpgradedMode("APY", block.timestamp, Expedted_price);
        }
    }

    function _apy() private returns (bool) {
        if (APY_MODE) {
            uint256 _periods = ((block.timestamp).sub(APY_UPDATED_AT)).div(
                APY_PERIOD
            ); //how many period over since last peg rise by apy
            if (_periods > 0) {
                uint256 newPrice = Expedted_price;
                for (uint256 i = 0; i < _periods; i++) {
                    uint256 updatePrice = (newPrice.mul(APY_RATE_PER_PERIOD))
                        .div(pegDenominator);
                    newPrice = updatePrice;
                }
                APY_UPDATED_AT += (APY_PERIOD.mul(_periods)); //last period updated timestamp
                Expedted_price = newPrice;
                if (Buy_Appreciation_Mode)
                    _upgradeApp(
                        App_Rate,
                        Buy_Appreciation_Mode,
                        Sell_Depreciation_Mode,
                        VOLUME_MODE,
                        BuyAppTxLimit,
                        SellDepTxLimit
                    ); //Fix app and dep according to new price
            }
        }
        return true;
    }

    function DISTRIBUTE() public {
        if ((APY_MODE && BLAST_MODE) || (HATCH_MODE && BLAST_MODE)) {
            uint256 _prePrice = Expedted_price;
            _apy(); //APY BPEGV RISING

            if (
                (HATCH_MODE &&
                    RESERVE_PEG_LP >
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.add(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator)) ||
                (HATCH_MODE &&
                    RESERVE_PEG_LP <
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.sub(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator))
            ) {
                if (
                    RESERVE_PEG_LP >
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.add(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator)
                ) {
                    Expedted_price = Expedted_price.add(
                        (Expedted_price.mul(peg_flactuate_rate)).div(
                            pegDenominator
                        )
                    );
                }
                if (
                    RESERVE_PEG_LP <
                    (
                        LAST_RESERVE_PEG_LP.mul(
                            pegDenominator.sub(Reserve_flactuate_rate)
                        )
                    ).div(pegDenominator)
                ) {
                    Expedted_price = Expedted_price.sub(
                        (Expedted_price.mul(peg_flactuate_rate)).div(
                            pegDenominator
                        )
                    );
                }
                _upgradeApp(
                    App_Rate,
                    Buy_Appreciation_Mode,
                    Sell_Depreciation_Mode,
                    VOLUME_MODE,
                    BuyAppTxLimit,
                    SellDepTxLimit
                ); //Fix app and dep according to new price
                LAST_RESERVE_PEG_LP = RESERVE_PEG_LP;
                emit UpgradedMode("HATCH", block.timestamp, Expedted_price);
            }
            if (_prePrice != Expedted_price) _recover(Expedted_price);
        }
    }

    function HARD_UPGRADE(uint256 _price, bool _recoveringToInitialPhase)
        external
        onlyOwner
    {
        //  if(init == false){
        //     init = true;
        //     initialPrice = priceNow();
        //  }
        _recover(_price);
        if (_recoveringToInitialPhase) {
            STABLE_MODE = true;
            Buy_Appreciation_Mode = false;
            Sell_Depreciation_Mode = false;
            HATCH_MODE = false;
            APY_MODE = false;
            emit UpgradedMode("HardPeg", block.timestamp, Expedted_price);
        }
    }

    function _recover(uint256 _basePrice) private {
        uint256 supplyAmount;
        uint256 newAmount;
        (uint256 reserve0, uint256 reserve1, ) = DEXV2Pair.getReserves();
        uint256 pairEggnogBal = _balances[address(DEXV2Pair)].balance;
        if (DEXV2Pair.token0() == address(this)) {
            newAmount = (pegDenominator.mul(reserve1)).div(_basePrice);
        } else {
            newAmount = (pegDenominator.mul(reserve0)).div(_basePrice);
        }
        if (pairEggnogBal > newAmount) {
            //transfer surplas amount to contract for peg repeg
            uint256 contractAmount = pairEggnogBal.sub(newAmount);
            _balances[address(DEXV2Pair)].balance = (
                _balances[address(DEXV2Pair)].balance
            ).sub(contractAmount);
            _update(address(DEXV2Pair), address(this), contractAmount);
        } else {
            supplyAmount = newAmount.sub(pairEggnogBal);
            uint256 contractReserve = (_balances[address(this)].balance).sub(
                RESERVE_FOR_PRINT
            );
            if (contractReserve >= supplyAmount) {
                _balances[address(this)].balance = (
                    _balances[address(this)].balance
                ).sub(supplyAmount);
                _update(address(this), address(DEXV2Pair), supplyAmount);
            } else {
                if (contractReserve > 0) {
                    _balances[address(this)].balance = (
                        _balances[address(this)].balance
                    ).sub(contractReserve);
                    _update(address(this), address(DEXV2Pair), contractReserve);
                }
                uint256 mintAmount = supplyAmount.sub(contractReserve);
                if (mintAmount > 0) {
                    _mint(address(DEXV2Pair), mintAmount);
                }
            }
        }
        //force syncing to get wanted reserve
        DEXV2Pair.sync();
        Expedted_price = _basePrice;
    }

    function _upgradeApp(
        uint256 _appRate,
        bool _ba,
        bool _sd,
        bool _volumeMode,
        uint256 _buyTxLimit,
        uint256 _sellTxLimit
    ) private {
        uint256 _app = (Expedted_price.mul(_appRate)).div(pegDenominator);
        HigherThreshold = Expedted_price.add(_app);
        LowerThreshold = Expedted_price.sub(_app);
        App_Rate = _appRate;
        STABLE_MODE = !(_ba || _sd); //  price stability will false on app or dep turn on.
        if (!_volumeMode) {
            // Peg App. and Dep. will count according to Number Of Txs
            if (_ba) {
                Buy_Appreciation_Mode = _ba;
                Buy_Appreciation_Rate = _app.div(_buyTxLimit);
                BuyAppTxLimit = _buyTxLimit;
            }
            if (_sd) {
                Sell_Depreciation_Mode = _sd;
                Sell_Depreciation_Rate = _app.div(_sellTxLimit);
                SellDepTxLimit = _sellTxLimit;
            }
        } else {
            // Peg App. and Dep. will count according to volume Of Txs
            Buy_Appreciation_Mode = _ba;
            Sell_Depreciation_Mode = _sd;
        }
        VOLUME_MODE = _volumeMode;
        if (!STABLE_MODE)
            emit UpgradedMode("App", block.timestamp, Expedted_price);
    }

    function upgradeAppreciationAndDepreciation(
        uint256 _appRate,
        bool _ba,
        bool _sd,
        bool _volumeMode,
        uint256 _buyTxLimit,
        uint256 _sellTxLimit
    ) external onlyOwner {
        _upgradeApp(_appRate, _ba, _sd, _volumeMode, _buyTxLimit, _sellTxLimit);
    }

    function MaximumTxOnLTM() public view returns (uint256 sellAmount) {
        uint256 _pegBal = _balances[address(DEXV2Pair)].balance;
        sellAmount = (_pegBal.mul(GSL)).div(pegDenominator);
    }

    function priceNow() public view returns (uint256 _pegPriceWithDecimal) {
        (uint256 reserve0, uint256 reserve1, ) = DEXV2Pair.getReserves();
        if (DEXV2Pair.token0() == address(this)) {
            _pegPriceWithDecimal = (reserve1.mul(pegDenominator)).div(reserve0);
        } else {
            _pegPriceWithDecimal = (reserve0.mul(pegDenominator)).div(reserve1);
        }
    }

    ///////////// settings /////////////////////
    function setBlastMode(
        uint256 _theshold,
        uint256 _rate,
        bool _execute
    ) external onlyOwner {
        BLAST_MODE = _execute;
        BLAST_THRESHOLD = _theshold;
        BLAST_THRESHOLD_INCREASING_RATE = _rate.add(pegDenominator);
    }

    function setAMMPair(
        address[] calldata pairAdds,
        address _peg_token_address,
        bool _setPeg,
        bool _isBlock
    ) external onlyOwner {
        if(_setPeg){
            require(pairAdds.length == 1, "only One pair");
            DEXV2Pair = IDEXV2Pair(pairAdds[0]);
            PEG_TOKEN_ADDRESS = _peg_token_address;
            IsExcludeFromMaxTx[pairAdds[0]] = true;
        }else{
            for(uint i ; i < pairAdds.length; i++){
                AMMPair[pairAdds[i]] = _isBlock;
            }
        }
    }

    function transferOwnership(address _owner) external onlyOwner {
        require(_owner != address(0), "INVALID ADD");
        Owner = _owner;
    }

    function setRouter(address _routerAdd, bool _stable) external onlyOwner {
        DEXV2Router = IDEXV2ROUTER02(_routerAdd);
        if (PEG_TOKEN_ADDRESS != address(0)) {
            address _pairAdd = IDEXV2Factory(DEXV2Router.factory()).getPair(
                PEG_TOKEN_ADDRESS,
                address(this),
                _stable
            );
            if (_pairAdd == address(0)) {
                _pairAdd = IDEXV2Factory(DEXV2Router.factory()).createPair(
                    PEG_TOKEN_ADDRESS,
                    address(this),
                    _stable
                );
            }
            DEXV2Pair = IDEXV2Pair(_pairAdd);
            IsExcludeFromMaxTx[_pairAdd] = true;
        }
    }

    function setHatching(
        uint256 _reserve_rate,
        uint256 _peg_rate,
        uint256 _hatchThreshold,
        bool execute
    ) external onlyOwner {
        Reserve_flactuate_rate = _reserve_rate;
        peg_flactuate_rate = _peg_rate;
        LAST_RESERVE_PEG_LP = IERC20(PEG_TOKEN_ADDRESS).balanceOf(
            address(DEXV2Pair)
        );
        Hatch_THRESHOLD = _hatchThreshold;
        HATCH_MODE = execute;
    }

    function setPrinting(
        address _printer,
        uint256 _minimum_swapback,
        bool _printing
    ) external onlyOwner {
        require(_printer != address(0));
        PRINTING_ENABLE = _printing;
        PRINTER_TOKEN = _printer;
        MINIMUM_SWAPBACK = _minimum_swapback;
    }

    function setLiquidityProvider(address account, bool execute)
        external
        onlyOwner
    {
        require(account != address(0));
        IsLiquidityProvider[account] = execute;
    }

    function setExempt(
        address[] calldata _exempters,
        bool _execute,
        uint256 _pos
    ) external onlyOwner {
        for (uint256 i = 0; i < _exempters.length; i++) {
            require(_exempters[i] != address(0));
            if (_pos == 1) IsExcludeFromFee[_exempters[i]] = _execute;
            else if (_pos == 2) IsExcludeFromMaxTx[_exempters[i]] = _execute;
            else {
                IsExcludeFromFee[_exempters[i]] = _execute;
                IsExcludeFromMaxTx[_exempters[i]] = _execute;
            }
        }
    }

    function setHFT(
        uint256 _hft,
        uint256 _quicksellfee,
        uint256 _hftThreshole,
        uint256 _qsThreshole,
        bool execute
    ) external onlyOwner {
        HFTFee = _hft;
        QuickSellFee = _quicksellfee;
        HFTTimingThreshold = _hftThreshole;
        QuickSellTimingThreshold = _qsThreshole;
        HFT = execute;
    }

    function SafeTransferToken(
        address _tokenAdd,
        address to,
        uint256 amount,
        bool _transferETH
    ) public reentrancyGurd onlyOwner {
        require(to != address(0), "ERC20: transfer to the zero address");
        uint256 _contractBal = _transferETH
            ? address(this).balance
            : IERC20(_tokenAdd).balanceOf(address(this));
        require(
            amount > 0 && amount <= _contractBal,
            "Transfer amount must be greater than zero or lower than reserve"
        );
        if (_transferETH) {
            TransferHelper.safeTransferETH(to, amount);
        } else TransferHelper.safeTransfer(_tokenAdd, to, amount);
    }

    function airDrop(address[] memory to, uint256[] memory amount)
        public
        reentrancyGurd
        onlyOwner
    {
        require(to.length == amount.length);
        for (uint256 i = 0; i < to.length; i++) {
            require(to[i] != address(0), "ERC20: transfer to the zero address");
            require(
                amount[i] > 0 &&
                    amount[i] <=
                    (_balances[address(this)].balance).sub(RESERVE_FOR_PRINT),
                "Transfer amount must be greater than zero or Lower than reserve"
            );
            bool success = _transfer(address(this), to[i], amount[i]);
            require(success, "ERC20 token transfer failed");
        }
    }

    function setStakeContract(address _add) external onlyOwner {
        require(
            _add != address(0) && _add != address(eggnog_stake),
            "Invalid Add"
        );
        eggnog_stake = ISTAKE(_add);
        emit StakeContractChanges(_add);
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):