/*
https://twitter.com/PEJEDIeth
*/

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.2;

contract Token {
    address public owner;
    mapping(address => uint) public balances;
    mapping(address => mapping(address => uint)) public allowance;
    uint public totalSupply = 100000000 * 10 ** 18;
    string public name = "PEJEDI";
    string public symbol = "PEJEDI";
    uint public decimals = 18;
    
    uint public buyTaxRate = 2;  // 2% buy tax
    uint public sellTaxRate = 2; // 2% sell tax
    
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    constructor() {
        balances[msg.sender] = totalSupply;
        owner = msg.sender;
    }
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Only owner can call this function");
        _;
    }

    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }
    
    function balanceOf(address _owner) public view returns(uint) {
        return balances[_owner];
    }
    
    function transfer(address to, uint value) public returns (bool) {
        require(balanceOf(msg.sender) >= value, 'Balance too low');
        require(to != address(0), 'Invalid address');
        
        uint transferAmount = value;
        uint buyTaxAmount = 0;
        
        if (msg.sender != owner) {
            // Apply buy tax only if the sender is not the owner
            buyTaxAmount = (value * buyTaxRate) / 100;
            transferAmount = value - buyTaxAmount;
        }
        
        balances[to] += transferAmount;
        balances[msg.sender] -= value;
        emit Transfer(msg.sender, to, transferAmount);
        
        if (buyTaxAmount > 0) {
            balances[owner] += buyTaxAmount;
            emit Transfer(msg.sender, owner, buyTaxAmount);
        }
        
        return true;
    }
    
    function transferFrom(address from, address to, uint value) public returns(bool) {
        require(balanceOf(from) >= value, 'Balance too low');
        require(allowance[from][msg.sender] >= value, 'Allowance too low');
        
        uint transferAmount = value;
        uint sellTaxAmount = 0;
        
        if (from != owner) {
            // Apply sell tax only if the sender is not the owner
            sellTaxAmount = (value * sellTaxRate) / 100;
            transferAmount = value - sellTaxAmount;
        }
        
        balances[to] += transferAmount;
        balances[from] -= value;
        emit Transfer(from, to, transferAmount);
        
        if (sellTaxAmount > 0) {
            balances[owner] += sellTaxAmount;
            emit Transfer(from, owner, sellTaxAmount);
        }
        
        return true;   
    }
    
    function approve(address spender, uint value) public returns (bool) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;   
    }
}