账户
0x9c...ce26
0x9C...ce26

0x9C...ce26

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.17+commit.8df45f5f
语言
Solidity
合同源代码
文件 1 的 7:Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
合同源代码
文件 2 的 7:IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
合同源代码
文件 3 的 7:Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
合同源代码
文件 4 的 7:Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
合同源代码
文件 5 的 7:ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}
合同源代码
文件 6 的 7:SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}
合同源代码
文件 7 的 7:ktoverter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

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

// Interface for the Uniswap V2 Router
interface IUniswapV2Router02 {
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function WETH() external pure returns (address);
    
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

/**
 * @title KTOverter - Token Exchange Contract
 * @dev This contract allows users to buy and sell KTO tokens using the Uniswap V2 Router.
 * @dev This contract also allows direct sale of KTO tokens from/to contract balance.
 */
contract KTOverter is Ownable, Pausable, ReentrancyGuard{
    using SafeMath for uint256;

    uint256 public minAmount = 1 * (10**9);
    uint256 public maxAmount = 1000000000 * (10**9); // 1 billion
    address public feeReceiver;
    IERC20 public theToken;
    uint256 public feeAmount;
    bool public ktoSellEnabled = false;
    uint256 public maxSellAmount;

    enum Fee {
        Disabled,
        Enabled
    }
    Fee public feeState;
    IUniswapV2Router02 public uniswapRouter;

    /**
     * @dev Initializes the KTOverter contract.
     * @param _tokenAddress The address of the KTO token contract.
     * @param _uniswapRouterAddress The address of the Uniswap V2 Router contract.
     */
    constructor(address _tokenAddress, address _uniswapRouterAddress) {
        theToken = IERC20(_tokenAddress);
        uniswapRouter = IUniswapV2Router02(_uniswapRouterAddress);
        feeState = Fee.Disabled;
    }

    /**
     * @dev Executes the fee calculation for a given input amount.
     * @param _amountIn The input amount to calculate the fee for.
     * @return _totalAfterFee The total amount after deducting the fee.
     */
    function enactFee(uint256 _amountIn) internal view returns(uint256 _totalAfterFee)
    {
        require(_amountIn > 0, "Amount must be greater than 0");
        uint256 divisor = 10_000;
        uint256 amountOutAfterFee = (_amountIn * (divisor - feeAmount)) / divisor;
        return amountOutAfterFee;
    }

    /**
     * @dev Returns the amount of output tokens for a given input amount of Ether.
     * @param _amountIn The input amount of Ether.
     * @param _tokenOut The address of the output token.
     * @return The amount of output tokens.
     */
    function getAmountOutFromEth(uint256 _amountIn, address _tokenOut) public view returns (uint256)
    {
        require(_amountIn > 0, "Value must be greater than 0 to get amount");
        require(_tokenOut != address(0), "Fatal error");

        address[] memory path = new address[](2);
        path[0] = uniswapRouter.WETH();
        path[1] = _tokenOut;

        uint[] memory amounts = uniswapRouter.getAmountsOut(_amountIn, path);
        
        return amounts[1];
    }
    /**  
    * @dev gets the conversion rate from token to weth
    * @param _amountKTOin the input amount of KTO
     */
    function tokenAmountInToEth(uint256 _amountKTOin) public view returns (uint256 _ethOut)
    {
        address[] memory path = new address[](2);
        path[0] = address(theToken);
        path[1] = uniswapRouter.WETH();

        uint[] memory amounts = uniswapRouter.getAmountsOut(_amountKTOin, path);

        return amounts[1];
    }
    /**
    * @dev allows users to sell KTO back to the verter
    * @param _amountOfKTO the amount of kto without decimals the user would like to sell
     */
    function sellKtoToConverter(uint _amountOfKTO) public
    {
        require(ktoSellEnabled, "selling through converter is currently disabled");
        require(maxSellAmount > 0, "max sell amount not set");
        require(address(this).balance > 0, "no eth to give for KTO-sell transaction");

        uint256 ethBalance = address(this).balance;
        uint256 prelimEth = tokenAmountInToEth(_amountOfKTO);
        uint256 finalEth;
        if(feeState == Fee.Enabled){
            finalEth = enactFee(prelimEth);
        } else {
            finalEth = prelimEth;
        }

        require(ethBalance >= finalEth, "not enough eth in contract for trade");

        require(_amountOfKTO <= maxSellAmount, "cannot sell over limit");

        bool transfer = theToken.transferFrom(msg.sender, address(this), _amountOfKTO);
        
        require(transfer, "token transfer failed");
        payable(msg.sender).transfer(finalEth);
        emit KTOSold(msg.sender, _amountOfKTO, block.timestamp);
        
    }
    function setSellActiveForVerterPool() public onlyOwner
    {
        ktoSellEnabled = !ktoSellEnabled;
    }
    function setMaxAmountForSelltoVerter(uint256 _newLimit) public onlyOwner
    {
        uint256 _newLimitWithDecimals = (_newLimit * 10 ** 9); 
        maxSellAmount = _newLimitWithDecimals;
    }

    /**
     * @dev Allows users to buy KTO tokens by sending Ether.
     */
    function buyWithWei() public payable whenNotPaused nonReentrant
    {
        uint amountOut = getAmountOutFromEth(msg.value, address(theToken));
        uint256 balToken = theToken.balanceOf(address(this));

        require(amountOut <= balToken, "Contract does not have enough balance");
        require(amountOut >= minAmount, "Below min");
        require(amountOut <= maxAmount, "Above max");
        
        uint256 eventAmount;

        if(feeState == Fee.Enabled){
            uint totalAmountOut = enactFee(amountOut);
            eventAmount = totalAmountOut;
        }else{
            eventAmount = amountOut;
        }

        require(theToken.transfer(msg.sender, eventAmount), "Transfer failed");
        emit KTOPurchase(msg.sender, eventAmount, block.timestamp);
    }

    /* Utility Functions */

    /**
     * @dev Sets the receiver address for the fee.
     * @param _receiver The address to receive the fee.
     */
    function setFeeReceiver(address _receiver) public onlyOwner
    {
        require(_receiver != address(0), "Cannot set receiver to burn");
        feeReceiver = _receiver;
    }

    /**
     * @dev Sets the fee amount.
     * @param _newFee The new fee amount.
     */
    function setFeeAmountForAll(uint256 _newFee) public onlyOwner
    {
        require(_newFee <= 1000 && _newFee >= 100, "Not permitted to raise fee over 10% of 10_000 or can't set below 1% of 10_000");
        feeAmount = _newFee;
    }

    /**
     * @dev Adds funds to the contract.
     * @param _amount The amount of tokens to add.
     * @notice only enter whole tokens. decimal calc is done already
     */
    function addFunds(uint256 _amount) public onlyOwner nonReentrant
    {
        uint totalAmount = _amount * 10 ** 9;

        require(theToken.transferFrom(msg.sender, address(this), totalAmount), "Transfer failed");
        emit AddFunds(msg.sender, _amount);
    }

    /**
     * @dev Sets the minimum amount of KTO tokens that can be bought.
     * @param _newMinAmount The new minimum amount. enter whole tokens
     */
    function setMinAmountBuy(uint256 _newMinAmount) public onlyOwner
    {
        minAmount = _newMinAmount * 10 ** 9;
    }

    /**
     * @dev Sets the maximum amount of KTO tokens that can be bought.
     * @param _newMaxAmount The new maximum amount.
     */
    function setMaxAmountBuy(uint256 _newMaxAmount) public onlyOwner
    {
        maxAmount = _newMaxAmount * 10 ** 9;
    }

    /**
     * @dev Toggles the fee state between enabled and disabled.
     */
    function toggleFee() public onlyOwner
    {
        if(feeState == Fee.Disabled){
            feeState = Fee.Enabled;
        } else if(feeState == Fee.Enabled){
            feeState = Fee.Disabled;
        }
    }

    /**
     * @dev Pauses the contract.
     */
    function pause() public onlyOwner
    {
        _pause();
    }

    /**
     * @dev Unpauses the contract.
     */
    function unpause() public onlyOwner
    {
        _unpause();
    }

    /**
     * @dev Allows the owner to withdraw ETH from the contract.
     */
    function withdrawETH() public onlyOwner nonReentrant
    {
        uint256 ethBalance = address(this).balance;
        payable(feeReceiver).transfer(ethBalance);
        emit Withdraw(feeReceiver, ethBalance);
    }

    /**
     * @dev Allows the owner to withdraw the base ERC-20 token from the contract's balance.
     */
    function withdrawKTO() public onlyOwner nonReentrant
    {
        uint256 balance = theToken.balanceOf(address(this));
        require(balance > 0, "Not enough balance");
        require(theToken.transfer(feeReceiver, balance), "Transfer failed");
        emit WithdrawTokens(feeReceiver, theToken, balance);
    }

    /**
     * @dev Updates the address of the Uniswap V2 Router contract.
     * @param _newPool The new address of the Uniswap V2 Router contract.
     */
    function updateRouterAddress(address _newPool) public onlyOwner nonReentrant
    {
        uniswapRouter = IUniswapV2Router02(_newPool);
    }

    /**
     * @dev Updates the address of the KTO token contract.
     * @param _tokenAddress The new address of the KTO token contract.
     */
    function updateTokenAddress(address _tokenAddress) public onlyOwner nonReentrant
    {
        theToken = IERC20(_tokenAddress);
    }

    /* Uniswap Pool Interaction */

    /**
     * @dev Buys KTO tokens with Ether. KTO stored in contract balance
     */
    function buyKTOforContract() public nonReentrant payable onlyOwner
    {
        uint256 ethBalance = address(this).balance;
        require(ethBalance > 0, "no eth to exchange");

        // Generate the Uniswap pair path of WETH -> transferTaxToken
        address[] memory path = new address[](2);
        path[0] = uniswapRouter.WETH();
        path[1] = address(theToken);

        // Make the swap
        uniswapRouter.swapExactETHForTokensSupportingFeeOnTransferTokens{ value: ethBalance }(
            0,  // Accept any amount of Ether
            path,
            address(this),
            block.timestamp
        );
    }

    /* Events */
    event Withdraw(address indexed user, uint256 amount);
    event WithdrawTokens(address indexed user, IERC20 indexed token, uint256 amount);
    event TokenExchanged(address indexed user, uint256 amountTokens, uint256 amountEth);
    event AddFunds(address indexed user, uint256 amount);
    event KTOPurchase(address indexed user, uint256 KTOamount, uint256 time);
    event KTOSold(address indexed user, uint256 KTOamount, uint256 time);
}
设置
{
  "compilationTarget": {
    "contracts/ktoverter.sol": "KTOverter"
  },
  "evmVersion": "london",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_uniswapRouterAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AddFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"KTOamount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"time","type":"uint256"}],"name":"KTOPurchase","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"KTOamount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"time","type":"uint256"}],"name":"KTOSold","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":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountTokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountEth","type":"uint256"}],"name":"TokenExchanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawTokens","type":"event"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"addFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"buyKTOforContract","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"buyWithWei","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"feeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeState","outputs":[{"internalType":"enum KTOverter.Fee","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"address","name":"_tokenOut","type":"address"}],"name":"getAmountOutFromEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ktoSellEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSellAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountOfKTO","type":"uint256"}],"name":"sellKtoToConverter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newFee","type":"uint256"}],"name":"setFeeAmountForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_receiver","type":"address"}],"name":"setFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newMaxAmount","type":"uint256"}],"name":"setMaxAmountBuy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newLimit","type":"uint256"}],"name":"setMaxAmountForSelltoVerter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newMinAmount","type":"uint256"}],"name":"setMinAmountBuy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setSellActiveForVerterPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"theToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountKTOin","type":"uint256"}],"name":"tokenAmountInToEth","outputs":[{"internalType":"uint256","name":"_ethOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"uniswapRouter","outputs":[{"internalType":"contract IUniswapV2Router02","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newPool","type":"address"}],"name":"updateRouterAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"updateTokenAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawKTO","outputs":[],"stateMutability":"nonpayable","type":"function"}]