// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IUniswapV2Router02 {
    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
    );
}

interface IERC20 {
    function approve(address spender, uint amount) external returns (bool);
}

contract FOMOARMY {
    string public name = "FOMOARMY";
    string public symbol = "FOM";
    uint8 public decimals = 18;
    uint256 public totalSupply = 21000000000 * 10**18;
    address public owner;
    address public ownerWallet = 0xAFBe3989fEf4482f71697082ca499D453fccac35; // Owner wallet address
    mapping(address => uint256) public balances;
    mapping(address => mapping(address => uint256)) public allowed;
    uint256 public lastActionBlock;
    uint256 public constant DELAY_BLOCKS = 20; // Adjust the delay as needed
    uint256 public priceMultiplier = 100000001;
    uint256 public tokensSold;
    uint256 public tokensBought;
    uint256 public tokensPerStep = 1_000_000_000; // Number of tokens per price increase

    modifier onlyOwner() {
        require(msg.sender == owner, "Only the owner can call this function");
        _;
    }

    modifier onlyAfterDelay() {
        require(block.number >= lastActionBlock + DELAY_BLOCKS, "Delay not elapsed");
        _;
    }

    constructor() {
        owner = msg.sender;
        balances[owner] = totalSupply;
    }

    function balanceOf(address tokenOwner) external view returns (uint256 balance) {
        return balances[tokenOwner];
    }

    function changeOwner(address newOwner) public onlyOwner {
        require(newOwner != address(0), "Invalid new owner address");
        owner = newOwner;
    }

    function addLiquidityToUniswap(
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        uint deadline
    ) external onlyAfterDelay {
        IUniswapV2Router02 uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        IERC20 usdc = IERC20(0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc);
        IERC20 usdt = IERC20(0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852);
        
        require(usdc.approve(0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc, amountADesired), "Failed to approve USDC");
        require(usdt.approve(0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852, amountBDesired), "Failed to approve USDT");

        (uint amountA, uint amountB, uint liquidity) = uniswapRouter.addLiquidity(
            0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc,
            0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852,
            amountADesired,
            amountBDesired,
            amountAMin,
            amountBMin,
            msg.sender,
            deadline
        );

        require(amountA > 0 && amountB > 0 && liquidity > 0, "Liquidity addition failed");
    }

    function myFunction() public onlyOwner onlyAfterDelay {
        lastActionBlock = block.number;
    }

    function adjustPrice(uint256 _tokensBought, uint256 _tokensSold) internal {
        tokensBought += _tokensBought;
        tokensSold += _tokensSold;

        uint256 tokensCount = tokensBought + tokensSold;

        if (tokensCount >= tokensPerStep) {
            uint256 steps = tokensCount / tokensPerStep;
            priceMultiplier = priceMultiplier ** steps;

            // Update tokensBought and tokensSold based on completed steps
            tokensBought = tokensCount % tokensPerStep;
            tokensSold = 0;
        }
    }
}