Contract Diff Checker

Contract Name:
PicklesPresale

Contract Source Code:

File 1 of 1 : PicklesPresale

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

interface IPicklesToken {
    function transfer(address recipient, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

contract PicklesPresale {
    address public owner;
    address public tokenAddress;
    uint256 public tokensPerEther = 4; // 4 tokens per 1 native currency (e.g., ETH)
    uint256 public totalTokensForSale = 200_000_000 * 10**18; // 200 million tokens
    uint256 public tokensSold;
    uint256 public minPurchase = 10 ether; // Minimum purchase: 10 native currency (e.g., ETH)
    uint256 public maxPurchase = 5000 ether; // Maximum purchase: 5000 native currency (e.g., ETH)
    bool public saleActive = false; // Initially, presale is inactive

    // Events
    event TokensPurchased(address indexed buyer, uint256 amount);
    event SaleEnded(address indexed owner, uint256 unsoldTokens);
    event FundsWithdrawn(address indexed owner, uint256 amount);

    modifier onlyOwner() {
        require(msg.sender == owner, "Not the contract owner");
        _;
    }

    constructor(address _tokenAddress) {
        require(_tokenAddress != address(0), "Invalid token address");
        owner = msg.sender;
        tokenAddress = _tokenAddress;
    }

    // Start the presale
    function startPresale() external onlyOwner {
        require(!saleActive, "Presale is already active");
        saleActive = true;
    }

    // End the presale
    function endPresale() external onlyOwner {
        require(saleActive, "Presale already ended");

        saleActive = false;

        uint256 unsoldTokens = totalTokensForSale - tokensSold;
        if (unsoldTokens > 0) {
            bool success = IPicklesToken(tokenAddress).transfer(owner, unsoldTokens);
            require(success, "Returning unsold tokens failed");
        }

        emit SaleEnded(owner, unsoldTokens);
    }

    // Buy tokens during presale
    function buyTokens() external payable {
        require(saleActive, "Presale is not active");
        require(msg.value >= minPurchase, "Minimum purchase not met");
        require(msg.value <= maxPurchase, "Maximum purchase exceeded");

        uint256 tokensToBuy = (msg.value * tokensPerEther) / 1 ether;

        require(tokensSold + tokensToBuy <= totalTokensForSale, "Not enough tokens left for sale");

        bool success = IPicklesToken(tokenAddress).transfer(msg.sender, tokensToBuy);
        require(success, "Token transfer failed");

        tokensSold += tokensToBuy;

        emit TokensPurchased(msg.sender, tokensToBuy);
    }

    // Withdraw Ether from the contract
    function withdrawFunds() external onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "No funds to withdraw");

        payable(owner).transfer(balance);

        emit FundsWithdrawn(owner, balance);
    }

    // Update tokens per native currency
    function updateTokensPerEther(uint256 _tokensPerEther) external onlyOwner {
        require(_tokensPerEther > 0, "Tokens per ether must be greater than zero");
        tokensPerEther = _tokensPerEther;
    }

    // Update purchase limits
    function updatePurchaseLimits(uint256 _minPurchase, uint256 _maxPurchase) external onlyOwner {
        require(_minPurchase > 0 && _maxPurchase > _minPurchase, "Invalid purchase limits");
        minPurchase = _minPurchase;
        maxPurchase = _maxPurchase;
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):