// File: src/Yeet.sol



/*                                                                                                                                                                          
                                                                                                                                                                                                                                                                                            |   |                                                  
░░    ░░ ░░░░░░░ ░░░░░░░ ░░░░░░░░     ░░░░░░      ░░░░░░  
 ▒▒  ▒▒  ▒▒      ▒▒         ▒▒             ▒▒    ▒▒  ▒▒▒▒ 
  ▒▒▒▒   ▒▒▒▒▒   ▒▒▒▒▒      ▒▒         ▒▒▒▒▒     ▒▒ ▒▒ ▒▒ 
   ▓▓    ▓▓      ▓▓         ▓▓        ▓▓         ▓▓▓▓  ▓▓ 
   ██    ███████ ███████    ██        ███████ ██  ██████  


It's time to go up only.

Website: https://yeetzejeet.com
Docs: https://docs.yeetzejeet.com
Telegram: https://t.me/YeetZeJeet
Twitter: https://twitter.com/YeetZeJeet

*/

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import "lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol";
import "lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol";
import "interfaces/IUniswapV2Router02.sol";
import "interfaces/IUniswapV2Pair.sol";
import "interfaces/IUniswapV2Factory.sol";

contract Yeet is IERC20, Ownable, ReentrancyGuard {
    string public name = "Yeet ze Jeet 2.0";
    string public symbol = "YEET";
    uint8 public decimals = 18;
    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) private _allowances;
    mapping(address => bool) public isExcludedFromTax;

    bool public isTimeToYeet;
    bool public tradingOpen;
    bool public dynamicTaxOn = true;

    uint256 public baseSellTax = 10e12; // 10%
    uint256 public maxWallet;

    uint256 public floorYeetReserve;
    uint256 public floorEthReserve;
    uint256 public yeetCooldown = 24 hours;
    uint256 public lastYeetTimestamp;

    IUniswapV2Pair public immutable uniswapV2Pair;
    IUniswapV2Router02 public immutable uniswapV2Router;
    address payable public devWallet;
    address payable public marketingWallet;

    constructor() {
        totalSupply = 2_000_000e18;
        balanceOf[msg.sender] = totalSupply;

        uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        uniswapV2Pair = IUniswapV2Pair(
            IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH())
        );

        devWallet = payable(0x4783c30AEa0A1a467aD4662a2e19e742d00865D9);
        marketingWallet = payable(0xCc3E3C5044e461ECe6cC6D0577c146998D3eD37A);

        maxWallet = totalSupply / 50; // 2%

        isExcludedFromTax[owner()] = true;
        isExcludedFromTax[address(this)] = true;
        isExcludedFromTax[devWallet] = true;
        isExcludedFromTax[marketingWallet] = true;
        isExcludedFromTax[0xAbc1508B730c7Edd3811e31591f66616d71271Ea] = true; // Presale addr
        isExcludedFromTax[0x2c952eE289BbDB3aEbA329a4c41AE4C836bcc231] = true; // Wentokens addr
    }

    event Yeeted(
        uint256 prevYeetReserve,
        uint256 prevEthReserve,
        uint256 newYeetReserve,
        uint256 newEthReserve,
        uint256 prevPrice,
        uint256 newPrice,
        uint256 yeetBurned
    );
    event NewFloorSet(uint256 prevFloorPrice, uint256 newFloorPrice);
    event JeetDetected(address who, uint256 amountSold, uint256 taxPaid);

    bool inSwap = false;

    modifier lockTheSwap() {
        inSwap = true;
        _;
        inSwap = false;
    }

    receive() external payable {}

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

    function approve(address spender, uint256 amount) public override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function _approve(address owner, address spender, uint256 amount) private {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");
        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    function _spendAllowance(address owner, address spender, uint256 amount) private {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    function transfer(address recipient, uint256 amount) external returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        emit Transfer(msg.sender, recipient, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) {
        _spendAllowance(sender, _msgSender(), amount);
        _transfer(sender, recipient, amount);
        emit Transfer(sender, recipient, amount);
        return true;
    }

    function _transfer(address from, address to, uint256 amount) private {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");
        require(amount > 0, "Transfer amount must be greater than zero");

        if (!tradingOpen) {
            require(isExcludedFromTax[from], "Can't trade yet");
        }

        uint256 taxAmount = 0;

        if (isTimeToYeet && !isExcludedFromTax[from] && !isExcludedFromTax[to]) {
            if (from == address(uniswapV2Pair) && to != address(uniswapV2Router)) {
                require(balanceOf[to] + amount <= maxWallet, "Max wallet exceeded");
            }

            if (to == address(uniswapV2Pair) && from != address(this)) {
                taxAmount = getTaxAmount(amount);
                emit JeetDetected(from, amount, taxAmount);
            }

            if (taxAmount > 0) {
                balanceOf[address(this)] += taxAmount;
                emit Transfer(from, address(this), taxAmount);
            }

            uint256 contractTokenBalance = balanceOf[address(this)];
            bool canSwap = contractTokenBalance > 0;

            if (canSwap && !inSwap && to == address(uniswapV2Pair)) {
                swapAndBurn(contractTokenBalance);
            }
        }

        balanceOf[from] -= amount;
        balanceOf[to] += amount - taxAmount;
    }

    function swapAndBurn(uint256 tokenAmount) private lockTheSwap {
        (uint256 toSwap, uint256 toBurn) = getSwapAndBurnAmounts(tokenAmount);
        burnFrom(address(this), toBurn);
        swapTokensForEth(toSwap);
    }

    function burnFrom(address account, uint256 amount) private {
        address deadAddress = 0x000000000000000000000000000000000000dEaD;
        balanceOf[account] -= amount;
        balanceOf[deadAddress] += amount;
        emit Transfer(account, deadAddress, amount);
    }

    function swapTokensForEth(uint256 tokenAmount) private {
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = uniswapV2Router.WETH();

        _approve(address(this), address(uniswapV2Router), tokenAmount);
        uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount, 0, path, address(this), block.timestamp
        );

        uint256 contractEth = address(this).balance;
        uint256 ethToDev = (contractEth * 70) / 100;
        uint256 ethToMarketing = contractEth - ethToDev;

        (bool success1,) = devWallet.call{value: ethToDev}("");
        require(success1);

        (bool success2,) = marketingWallet.call{value: ethToMarketing}("");
        require(success2);
    }

    function manualSwap() external {
        require(_msgSender() == devWallet, "Not authorized");
        uint256 tokenBalance = balanceOf[address(this)];
        if (tokenBalance > 0) {
            swapAndBurn(tokenBalance);
        }
    }

    /**
     * This function both sets new floor and maintains it by yeeting
     */
    function yeet() public nonReentrant {
        require(isTimeToYeet, "Yeet machine broke");
        require(getTimeLeft() == 0, "Yeet cooldown not met");

        // Sync first in case pair is disbalanced
        uniswapV2Pair.sync();

        // Get $yeet price
        uint256 currentPrice = getCurrentPrice();
        uint256 floorPrice = getFloorPrice();

        // Get LP reserves
        (uint112 prevYeetReserve, uint112 prevEthReserve) = getReserves();

        // If we dump below floor, proceed with yeeting
        if (floorPrice > currentPrice) {
            // Burn $yeet from lp
            uint256 toBurn = getBurnAmount();
            burnFrom(address(uniswapV2Pair), toBurn);

            // Sync again
            uniswapV2Pair.sync();

            // Get reserves after burn
            (uint112 newYeetReserve, uint112 newEthReserve) = getReserves();

            // Let everyone know
            emit Yeeted(
                prevYeetReserve, prevEthReserve, newYeetReserve, newEthReserve, currentPrice, getCurrentPrice(), toBurn
            );
        } else {
            // Set new floor
            floorYeetReserve = prevYeetReserve;
            floorEthReserve = prevEthReserve;

            // Let everyone know
            emit NewFloorSet(floorPrice, currentPrice);
        }

        // Reset cooldown
        lastYeetTimestamp = block.timestamp;
    }

    /**
     * VIEW FUNCS
     */

    /**
     * Returns amount to swap and burn
     * When dynamic tax is on, we want to keep swap amount at fixed
     * 5% rate and burn the rest
     */
    function getSwapAndBurnAmounts(uint256 tokenAmount) public view returns (uint256, uint256) {
        uint256 sellTax = getSellTax();
        uint256 toSwap;
        uint256 toBurn;
        if (sellTax > baseSellTax) {
            toSwap = ((tokenAmount * ((baseSellTax * 1e12) / sellTax)) / 1e12) / 2;
            toBurn = tokenAmount - toSwap;
        } else {
            toSwap = tokenAmount / 2;
            toBurn = tokenAmount - toSwap;
        }
        return (toSwap, toBurn);
    }

    /**
     * A helper function that returns exact amount to tax
     */
    function getTaxAmount(uint256 amount) public view returns (uint256 taxAmount) {
        uint256 sellTax = getSellTax();
        return (amount * sellTax) / 100e12;
    }

    /**
     * Dynamic tax mechanism
     * If price dumps further than 10% under floor sell tax will be equal
     * to exact % of the dump percent value
     * Returns percent value of tax (divide by 1e12)
     */
    function getSellTax() public view returns (uint256 actualSellTax) {
        if (dynamicTaxOn) {
            uint256 dumpAmount = getDumpAmount();
            if (dumpAmount > baseSellTax) {
                return dumpAmount;
            } else {
                return baseSellTax;
            }
        } else {
            return baseSellTax;
        }
    }

    /**
     * Returns the percent value of how much price is down below floor
     * for use in dynamic tax calculation. Divide output by 1e12
     */
    function getDumpAmount() public view returns (uint256 pumpAmount) {
        uint256 currentPrice = getCurrentPrice();
        uint256 floorPrice = getFloorPrice();
        if (floorPrice > currentPrice) {
            return (100 * 1e12) - (((currentPrice * 1e12) / floorPrice) * 100);
        } else {
            return 0;
        }
    }

    /**
     * Returns the percent difference between current price and floor
     * Purely for front end purposes. Divide output by 1e12
     */
    function getPumpAmount() public view returns (uint256 pumpAmount) {
        uint256 currentPrice = getCurrentPrice();
        uint256 floorPrice = getFloorPrice();
        if (floorPrice > currentPrice) {
            return (((floorPrice * 1e12) / currentPrice) - 1e12) * 100;
        } else {
            return 0;
        }
    }

    /**
     * Returns exact amount of YEET to burn to bring price back up
     */
    function getBurnAmount() public view returns (uint256 toBurn) {
        (uint112 currentYeetReserve, uint112 currentEthReserve) = getReserves();
        uint256 targetYeetReserve = (currentEthReserve * 1e12) / getFloorPrice();
        if (currentYeetReserve > targetYeetReserve) {
            return currentYeetReserve - targetYeetReserve;
        } else {
            return 0;
        }
    }

    /**
     * Returns floor price in ETH
     * Divide the output by 1e12 and multiply by ETH price to get USD price
     */
    function getFloorPrice() public view returns (uint256 floorPrice) {
        return (floorEthReserve * 1e12) / floorYeetReserve;
    }

    /**
     * Returns current price in ETH
     * Divide the output by 1e12 and multiply by ETH price to get USD price
     */
    function getCurrentPrice() public view returns (uint256 currentPrice) {
        (uint112 currentYeetReserve, uint112 currentEthReserve) = getReserves();
        return (currentEthReserve * 1e12) / currentYeetReserve;
    }

    /**
     * Debug only, this should always be equal to floor price
     * Divide the output by 1e12 and multiply by ETH price to get USD price
     */
    function getPriceAfterYeet() public view returns (uint256 currentPrice) {
        (uint112 currentYeetReserve, uint112 currentEthReserve) = getReserves();
        uint256 toBurn = getBurnAmount();
        return (currentEthReserve * 1e12) / (currentYeetReserve - toBurn);
    }

    /**
     * Returns time left in seconds until yeet button becomes available
     */
    function getTimeLeft() public view returns (uint256 timeLeft) {
        if (lastYeetTimestamp + yeetCooldown > block.timestamp) {
            return (lastYeetTimestamp + yeetCooldown) - block.timestamp;
        } else {
            return 0;
        }
    }

    /**
     *  This function always returns currentYeetReserve at first slot of the tuple,
     *  which is not always the case with calling pair for reserves
     */
    function getReserves() public view returns (uint112, uint112) {
        (uint112 reserve0, uint112 reserve1,) = uniswapV2Pair.getReserves();
        bool isYeetReserve = address(this) < uniswapV2Router.WETH();
        uint112 yeetReserve = isYeetReserve ? reserve0 : reserve1;
        uint112 ethReserve = !isYeetReserve ? reserve0 : reserve1;
        return (yeetReserve, ethReserve);
    }

    /**
     * OWNER FUNCS
     */

    /**
     * Sets initial floor price at launch
     */
    function setFloorPrice() public onlyOwner {
        (uint112 yeetReserve, uint112 ethReserve) = getReserves();
        floorYeetReserve = yeetReserve;
        floorEthReserve = ethReserve;
        if (lastYeetTimestamp == 0) {
            lastYeetTimestamp = block.timestamp;
        }
    }

    /**
     * Emergency only, toggles dynamic tax system on/off
     */
    function toggleDynamicTax() public onlyOwner {
        dynamicTaxOn = !dynamicTaxOn;
    }

    /**
     * Start the protocol
     */
    function timeToYeet(bool isIt) public onlyOwner {
        isTimeToYeet = isIt;
    }

    /**
     * Add liquidity
     */
    function addLiquidity(uint256 tokenAmount) public payable onlyOwner {
        this.transferFrom(owner(), address(this), tokenAmount);
        this.approve(address(uniswapV2Router), tokenAmount);
        uniswapV2Router.addLiquidityETH{value: msg.value}(address(this), tokenAmount, 0, 0, owner(), block.timestamp);
        setFloorPrice();
    }

    /**
     * Open trading on Uniswap
     * Can never be disabled once called
     */
    function openTrading() public payable onlyOwner {
        tradingOpen = true;
    }

    function setDevWallet(address _devWallet) public onlyOwner {
        devWallet = payable(_devWallet);
    }

    function setMarketingWallet(address _marketingWallet) public onlyOwner {
        marketingWallet = payable(_marketingWallet);
    }

    function setMaxWallet(uint256 _maxWallet) public onlyOwner {
        maxWallet = _maxWallet;
    }

    function addExcludedFromTax(address toBeExcluded) public payable onlyOwner {
        isExcludedFromTax[toBeExcluded] = true;
    }

    function removeExcludedFromTax(address toBeRemoved) public payable onlyOwner {
        isExcludedFromTax[toBeRemoved] = false;
    }

    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }
}

// File: lib/openzeppelin-contracts/contracts/access/Ownable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

// File: lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";

// File: interfaces/IUniswapV2Router02.sol



pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

// File: interfaces/IUniswapV2Pair.sol



pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint 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 (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint 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 (uint);

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

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

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    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 (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
// File: interfaces/IUniswapV2Factory.sol



pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

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

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}
// File: lib/openzeppelin-contracts/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

// File: lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

// File: interfaces/IUniswapV2Router01.sol



pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}