Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.1 kB
33
Indexable
Never
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/v4.3.0/contracts/token/ERC20/IERC20.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/v4.3.0/contracts/token/ERC20/ERC20.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/v4.3.0/contracts/access/Ownable.sol";

contract SafeMoneyUp is ERC20, Ownable {
    uint256 private constant PRECISION = 1e18;
    uint256 private constant FIXED_SUPPLY = 400 * 1e12 * PRECISION;

    mapping(address => bool) public excludedFromFees;
    mapping(address => bool) public isBlacklisted;

    uint256 public adminFee = 50; // 0.5% (50/10000)

    constructor() ERC20("SafeMoney Up", "SMU") {
        _mint(address(this), FIXED_SUPPLY);
        excludedFromFees[owner()] = true;
    }

    function buyTokens() public payable {
        require(!isBlacklisted[msg.sender], "Address is blacklisted");
        require(msg.value > 0, "Amount must be greater than 0");

        uint256 supplyWithoutContractAndBurn = totalSupply() - balanceOf(address(this)) - balanceOf(address(0));
        uint256 ethAmount = msg.value;
        uint256 tokensToBuy = (ethAmount * supplyWithoutContractAndBurn) / address(this).balance;

        uint256 fee = (ethAmount * adminFee) / 10000;
        uint256 tokensWithFee = (tokensToBuy * 98) / 100; // 2% fee

        if (!excludedFromFees[msg.sender]) {
            tokensToBuy = tokensWithFee;
            ethAmount -= fee;
        }

        _transfer(address(this), msg.sender, tokensToBuy);
    }

    function sellTokens(uint256 tokensToSell) public {
        require(!isBlacklisted[msg.sender], "Address is blacklisted");
        require(tokensToSell > 0, "Amount must be greater than 0");

        uint256 supplyWithoutContractAndBurn = totalSupply() - balanceOf(address(this)) - balanceOf(address(0));
        uint256 ethAmount = (tokensToSell * address(this).balance) / supplyWithoutContractAndBurn;

        uint256 fee = (ethAmount * adminFee) / 10000;
        uint256 ethWithFee = (ethAmount * 98) / 100; // 2% fee

        if (!excludedFromFees[msg.sender]) {
            ethAmount = ethWithFee;
        } else {
            ethAmount -= fee;
        }

        _transfer(msg.sender, address(this), tokensToSell);
        payable(msg.sender).transfer(ethAmount);
    }

    function setAdminFee(uint256 newAdminFee) public onlyOwner {
        require(newAdminFee >= 0 && newAdminFee <= 10000, "Invalid fee value");
        adminFee = newAdminFee;
    }

    function excludeFromFees(address account, bool excluded) public onlyOwner {
        excludedFromFees[account] = excluded;
    }

        function setBlacklistStatus(address account, bool blacklisted) public onlyOwner {
        isBlacklisted[account] = blacklisted;
    }

    function claimFees() public onlyOwner {
        uint256 feesToClaim = address(this).balance;
        require(feesToClaim > 0, "No fees to claim");
        payable(owner()).transfer(feesToClaim);
    }

    function withdrawToken(address tokenAddress, uint256 amount) public onlyOwner {
        require(tokenAddress != address(0), "Invalid token address");
        IERC20 token = IERC20(tokenAddress);
        uint256 tokenBalance = token.balanceOf(address(this));
        require(amount <= tokenBalance, "Not enough tokens in contract");
        token.transfer(owner(), amount);
    }

    function withdrawETH(uint256 amount) public onlyOwner {
        uint256 ethBalance = address(this).balance;
        require(amount <= ethBalance, "Not enough Ether in contract");
        payable(owner()).transfer(amount);
    }

    receive() external payable {
        require(msg.sender != owner(), "Owner cannot send Ether directly");
    }

    function transferAnyERC20Token(address tokenAddress, uint256 amount) public onlyOwner {
        IERC20 token = IERC20(tokenAddress);
        token.transfer(owner(), amount);
    }
}