//SPDX-License-Identifier: MIT
/*

    The best cat that ever existed.

    https://www.dinger.cat/

    t.me/OrdinalDinger

  
*/
pragma solidity 0.8.17;


 
interface IFactory{
        function createPair(address tokenA, address tokenB) external returns (address pair);
}
 
interface IRouter {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
 
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline) external;
}
 
contract OrdinalDinger is ERC20, Ownable{
 
    IRouter public router;
    address public pair;
 
    bool private swapping;
    bool public swapEnabled;
    bool public tradingEnabled;
 
 
    mapping (address => bool) public noFees;
    mapping (address => bool) public isBot;
 
    uint256 public swapThreshold = 10000 * 10**18;
    uint256 public maxTxAmount = 2000000 * 10**18;
    address public marketingWallet = 0x895Fc2CD61AC7e1d168c26120f947eF1E1b101Fa;
    address public devWallet = 0x895Fc2CD61AC7e1d168c26120f947eF1E1b101Fa;
 
    struct Taxes {
        uint128 marketing;
        uint128 dev;
    }
    Taxes public taxes = Taxes(1,1);
 
    modifier inSwap() {
        if (!swapping) {
            swapping = true;
            _;
            swapping = false;
        }
    }
 
    constructor() ERC20("Ordinal Dinger", "oDINGER") {
        _mint(msg.sender, 1e9 * 10 ** 18);
        noFees[msg.sender] = true;
        IRouter _router = IRouter(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        address _pair = IFactory(_router.factory())
            .createPair(address(this), _router.WETH());
 
        router = _router;
        pair = _pair;
        noFees[address(this)] = true;
        noFees[marketingWallet] = true;
        noFees[devWallet] = true;
    }
 
 
    function _transfer(address sender, address recipient, uint256 amount) internal override {
        require(amount > 0, "Transfer amount must be greater than zero");
 
        if(!noFees[sender] && !noFees[recipient] && !swapping){
            require(tradingEnabled, "Trading not active");
            require(!isBot[sender] && !isBot[recipient], "Bye Bye Bot");
            if(recipient == pair) require(amount <= maxTxAmount, "Exceeding maxTxAmount");
        }
 
        uint256 fee;
 
        if (swapping || noFees[sender] || noFees[recipient] || (sender != pair && recipient != pair)) fee = 0;
 
        else fee = amount * (taxes.dev + taxes.marketing) / 100;
 
        if (swapEnabled && !swapping && sender != pair && fee > 0) translateFees();
 
        super._transfer(sender, recipient, amount - fee);
        if(fee > 0) super._transfer(sender, address(this) ,fee);
 
    }
 
    function translateFees() private inSwap {
        if (balanceOf(address(this)) >= swapThreshold) {
            swapTokensForETH(swapThreshold);
 
            uint256 totalBalance = address(this).balance;
            uint256 totalTax = taxes.marketing + taxes.dev;
            uint256 marketingAmt = totalBalance * taxes.marketing / totalTax;
            if(marketingAmt > 0){
                (bool success, ) = payable(marketingWallet).call{value: marketingAmt}("");
                require(success, "Error sending eth");
            }
            uint256 devAmt = totalBalance * taxes.dev / totalTax;
            if(devAmt > 0){
                (bool success, ) = payable(devWallet).call{value: devAmt}("");
                require(success, "Error sending eth");
            }
        }
    }
 
    function swapTokensForETH(uint256 tokenAmount) private {
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = router.WETH();
 
        _approve(address(this), address(router), tokenAmount);
 
        // make the swap
        router.swapExactTokensForETHSupportingFeeOnTransferTokens(tokenAmount, 0, path, address(this), block.timestamp);
 
    }
 
    function enableTrading() external onlyOwner{
        tradingEnabled = true;
        swapEnabled = true;
    }
    function setSwapEnabled(bool state) external onlyOwner {
        swapEnabled = state;
    }
 
    function setSwapThreshold(uint256 new_amount) external onlyOwner {
        swapThreshold = new_amount * 10**18;
    }
    function setMaxTxAmount(uint256 amount) external onlyOwner{
         maxTxAmount = amount;
}
    function setTaxes(uint128 _dev, uint128 _marketing) external onlyOwner{
        taxes = Taxes(_marketing, _dev);
    }
 
    function updateMarketingWallet(address newWallet) external onlyOwner{
        marketingWallet = newWallet;
    }
    function removeLimits() external onlyOwner{
        maxTxAmount = totalSupply();
    }
    function updateDevWallet(address newWallet) external onlyOwner{
        devWallet = newWallet;
    }
 
    function updatePair(address _pair) external onlyOwner{
        pair = _pair;
    }
 
    function updateNoFees(address _address, bool state) external onlyOwner {
        noFees[_address] = state;
    }
    function setBot(address[] calldata bots, bool status) external onlyOwner{
        uint256 size = bots.length;
        for(uint256 i; i < size;){
            isBot[bots[i]] = status;
            unchecked{ ++i; }
        }
    }
 
    function rescueTokens(address tokenAddress, uint256 amount) external onlyOwner{
        IERC20(tokenAddress).transfer(owner(), amount);
    }
 
    function rescueETH(uint256 weiAmount) external onlyOwner{
        (bool success, ) = payable(owner()).call{value: weiAmount}("");
        require(success, "Error sending eth");
    }
 
    // fallbacks
    receive() external payable {}
 
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"devWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isBot","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketingWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTxAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"noFees","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"removeLimits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"weiAmount","type":"uint256"}],"name":"rescueETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"rescueTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"contract IRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"bots","type":"address[]"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setBot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setMaxTxAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"setSwapEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"new_amount","type":"uint256"}],"name":"setSwapThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"_dev","type":"uint128"},{"internalType":"uint128","name":"_marketing","type":"uint128"}],"name":"setTaxes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxes","outputs":[{"internalType":"uint128","name":"marketing","type":"uint128"},{"internalType":"uint128","name":"dev","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newWallet","type":"address"}],"name":"updateDevWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newWallet","type":"address"}],"name":"updateMarketingWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"bool","name":"state","type":"bool"}],"name":"updateNoFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pair","type":"address"}],"name":"updatePair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]