/*                                                                       
________  .__      ___.   .__           ._______   ____
\______ \ |__|____ \_ |__ |  |   ____   |   \   \ /   /
 |    |  \|  \__  \ | __ \|  |  /  _ \  |   |\   Y   / 
 |    `   \  |/ __ \| \_\ \  |_(  <_> ) |   | \     /  
/_______  /__(____  /___  /____/\____/  |___|  \___/   
        \/        \/    \/                             
                                                                                                                                               
                    
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract IVToken {
    string public name;
    string public symbol;
    uint8 public decimals;
    uint256 public totalSupply;
    address public taxAddress;
    uint256 public taxRate;

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor() {
        name = "Diablo IV";
        symbol = "IV";
        decimals = 18;
        totalSupply = 10000000000000 * 10**uint256(decimals);
        taxAddress = 0xC6082521Bc568C1a5E3cB7474452671a7764D5e2;
        taxRate = 2;
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address to, uint256 value) public returns (bool) {
        uint256 taxAmount = (value * taxRate) / 100;
        uint256 taxedValue = value - taxAmount;

        require(to != address(0), "Invalid address");
        require(balanceOf[msg.sender] >= value, "Insufficient balance");

        balanceOf[msg.sender] -= value;
        balanceOf[taxAddress] += taxAmount;
        balanceOf[to] += taxedValue;

        emit Transfer(msg.sender, to, taxedValue);
        emit Transfer(msg.sender, taxAddress, taxAmount);
        return true;
    }

    function approve(address spender, uint256 value) public returns (bool) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) public returns (bool) {
        uint256 taxAmount = (value * taxRate) / 100;
        uint256 taxedValue = value - taxAmount;

        require(from != address(0), "Invalid address");
        require(to != address(0), "Invalid address");
        require(balanceOf[from] >= value, "Insufficient balance");
        require(allowance[from][msg.sender] >= value, "Allowance exceeded");

        balanceOf[from] -= value;
        balanceOf[taxAddress] += taxAmount;
        balanceOf[to] += taxedValue;
        allowance[from][msg.sender] -= value;

        emit Transfer(from, to, taxedValue);
        emit Transfer(from, taxAddress, taxAmount);
        return true;
    }
}