// SPDX-License-Identifier: MIT
// Your Personalized, Sovereign AI in the Web 3.0 Era https://tgpt.guru

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";


contract TruthGPT is ERC20, Ownable {
    using SafeMath for uint256;

    // treasury wallet
    address payable public treasury;

    // maximum transaction amount
    uint256 public maxTxAmount;

    string public _1_x;
    string public _2_telegram;
    string public _3_website;

    constructor() ERC20("TruthGPT", "TGPT") {
        // Set the treasury wallet to the contract owner
        treasury = payable(msg.sender);

        uint256 initialSupply = 69420000000 * (10 ** uint256(decimals()));
        _mint(msg.sender, initialSupply);
    }

    function setTreasury(address payable _treasury) public onlyOwner {
        require(_treasury != address(0), "Treasury cannot be the zero address");
        require(address(this)!= _treasury, "Treasury wallet cannot be the contract address");
        treasury = _treasury;
    }

    function set_1_x(string memory _1_x_) public onlyOwner {
        _1_x = _1_x_;
    }

    function set_2_telegram(string memory _2_telegram_) public onlyOwner {
        _2_telegram = _2_telegram_;
    }

    function set_3_website(string memory _3_website_) public onlyOwner {
        _3_website = _3_website_;
    }


    function setMaxTxAmount(uint256 _maxTxAmount) public onlyOwner {
        maxTxAmount = _maxTxAmount;
    }


    function _transfer(address sender, address recipient, uint256 amount) internal virtual override {

        if (sender != treasury && recipient != treasury) {
            require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
        }


        super._transfer(sender, recipient, amount);

        // The implementation of a 1% treasury minting on large transactions (those amounting to 6942000 or more) is a purposeful and strategic financial decision designed to safeguard the project's sustainability and foster long-term growth. This automatic funding mechanism provides a steady stream of resources for the treasury, enabling reinvestment into crucial areas such as project development, marketing, and community incentives.
        // Additionally, the 1% minting policy serves as a deterrent against excessively large transactions that could destabilize the token price or leave the system vulnerable to market manipulation. In this way, we align the interests of all stakeholders, ensuring the project's stability and fostering an environment conducive to continual innovation and improvement. This is not merely a measure to increase funds; it's a strategy for ensuring the project's resilience, longevity, and success in the dynamic and competitive landscape of blockchain technologies.
        if (amount >= 6942000 * (10 ** uint256(decimals()))) {
            uint256 mintAmount = amount.div(100);  // 1%
            _mint(treasury, mintAmount);
        }
    }

    // Emergency function to withdraw all ETH from the contract
    function emergencyETHWithdraw() external {
        require(msg.sender == treasury, "Only the treasury can withdraw ETH");
        treasury.transfer(address(this).balance);
    }

    // Emergency function to withdraw any ERC20 token from the contract
    function emergencyERC20Withdraw(IERC20 token) external {
        require(msg.sender == treasury, "Only the treasury can withdraw ERC20 tokens");
        uint256 balance = token.balanceOf(address(this));
        token.transfer(treasury, balance);
    }
}
[{"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":[],"name":"_1_x","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_2_telegram","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_3_website","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"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":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"emergencyERC20Withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyETHWithdraw","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":[],"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":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxTxAmount","type":"uint256"}],"name":"setMaxTxAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_treasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_1_x_","type":"string"}],"name":"set_1_x","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_2_telegram_","type":"string"}],"name":"set_2_telegram","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_3_website_","type":"string"}],"name":"set_3_website","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":[],"name":"treasury","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"}]