Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.8 kB
0
Indexable
Never
/**
 *Submitted for verification at Etherscan.io on 2024-04-13
*/

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IERC20 {
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address recipient, uint256 amount) external returns (bool);
}

contract PreSale {
    address public admin;
    IERC20 public preSaleToken;
    IERC20 public usdtToken;

    uint256 public totalSold;

    uint256 public constant TOKEN_PRICE = 0.0982 *10**18;

    mapping(address => uint256) public buyAmount;
    event TokensPurchased(address indexed buyer, uint256 amount, uint256 totalPrice);

    constructor() {
        admin = msg.sender;
        preSaleToken = IERC20(0x5aeD4C2E109D1EfD0AAbde02cB16C6e8bD7823c3);
        usdtToken = IERC20(0xF5e96a117A83c7913a2EAEC06567c9968b452068);
    }

    modifier onlyAdmin() {
        require(msg.sender == admin, "Only admin can call this function");
        _;
    }

    function buyTokensWithUSDT(uint256 usdtAmount) external {
        uint256 numberOfTokens = (usdtAmount * 10**18) / TOKEN_PRICE;
        
        require(
            usdtToken.transferFrom(msg.sender, admin, usdtAmount),
            "Token transfer failed"
        );
        buyAmount[msg.sender] += numberOfTokens;
        totalSold += numberOfTokens;
        require(preSaleToken.transfer(msg.sender, numberOfTokens), "Claim token failed");
        emit TokensPurchased(msg.sender, numberOfTokens, usdtAmount);
    }

    function withdrawFundsUSD() external onlyAdmin {
        uint256 contractBalance = preSaleToken.balanceOf(address(this));
        require(preSaleToken.transfer(admin, contractBalance), "Funds withdrawal failed");
    }
}
Leave a Comment