ValidatorPPEP

Description:

Smart contract deployed on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

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

interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

contract ValidatorPPEP {
    struct Phase {
        string name;
        uint256 priceUSD;
    }

    address public constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
    IERC20 public constant PPEP = IERC20(0xA6b7C832a4B7722A4a46C221Fdd3332A2E1e4736);
    
    address public secureWallet;
    address public owner;
    
    Phase[12] public phases;
    uint256 public currentPhase;
    uint256 public constant MIN_PURCHASE_USD = 5 * 1e6;
    bool public paused;
    
    event PaymentValidated(address indexed user, address indexed tokenIn, uint256 amountIn, uint256 ppepAmount, uint256 phaseIndex, string phaseName, uint256 priceUSD);
    event PhaseChanged(uint256 indexed oldPhase, uint256 indexed newPhase, string newPhaseName);
    event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
    event SecureWalletUpdated(address indexed oldWallet, address indexed newWallet);
    event Paused(bool status);
    event EmergencyWithdraw(address indexed token, uint256 amount);
    event PPEPDeposited(uint256 amount, uint256 newBalance);
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }
    
    modifier whenNotPaused() {
        require(!paused, "Contract paused");
        _;
    }
    
    constructor(address _secureWallet) {
        require(_secureWallet != address(0), "Invalid wallet");
        owner = msg.sender;
        secureWallet = _secureWallet;
        phases[0]  = Phase("Fase 1",  1000);
        phases[1]  = Phase("Fase 2",  2000);
        phases[2]  = Phase("Fase 3",  4000);
        phases[3]  = Phase("Fase 4",  6000);
        phases[4]  = Phase("Fase 5",  8000);
        phases[5]  = Phase("Fase 6",  11000);
        phases[6]  = Phase("Fase 7",  14000);
        phases[7]  = Phase("Fase 8",  17000);
        phases[8]  = Phase("Fase 9",  21000);
        phases[9]  = Phase("Fase 10", 25000);
        phases[10] = Phase("Fase 11", 29000);
        phases[11] = Phase("Fase 12", 33000);
        currentPhase = 0;
    }
    
    function payWithETH(uint256 ethPriceUSD) external payable whenNotPaused {
        require(msg.value > 0, "No ETH sent");
        require(ethPriceUSD > 0, "Invalid ETH price");
        uint256 amountInUSD = (msg.value * ethPriceUSD) / 1e18;
        uint256 ppepAmount = _processPurchase(amountInUSD);
        (bool ok, ) = payable(secureWallet).call{value: msg.value}("");
        require(ok, "ETH transfer failed");
        require(PPEP.transfer(msg.sender, ppepAmount), "PPEP transfer failed");
        Phase memory phase = phases[currentPhase];
        emit PaymentValidated(msg.sender, address(0), msg.value, ppepAmount, currentPhase, phase.name, phase.priceUSD);
    }
    
    function payWithToken(address tokenIn, uint256 amountIn) external whenNotPaused {
        require(tokenIn == USDT || tokenIn == USDC, "Invalid token");
        require(amountIn > 0, "Invalid amount");
        uint256 ppepAmount = _processPurchase(amountIn);
        require(IERC20(tokenIn).transferFrom(msg.sender, secureWallet, amountIn), "Token transfer failed");
        require(PPEP.transfer(msg.sender, ppepAmount), "PPEP transfer failed");
        Phase memory phase = phases[currentPhase];
        emit PaymentValidated(msg.sender, tokenIn, amountIn, ppepAmount, currentPhase, phase.name, phase.priceUSD);
    }
    
    function _processPurchase(uint256 amountInUSD) internal returns (uint256 ppepAmount) {
        require(amountInUSD >= MIN_PURCHASE_USD, "Below minimum");
        Phase storage phase = phases[currentPhase];
        require(phase.priceUSD > 0, "Invalid phase price");
        ppepAmount = (amountInUSD * 1e18) / phase.priceUSD;
        require(PPEP.balanceOf(address(this)) >= ppepAmount, "Insufficient PPEP in contract");
        return ppepAmount;
    }

    function getCurrentPhase() external view returns (uint256 phaseNumber, string memory name, uint256 priceUSD) {
        Phase memory phase = phases[currentPhase];
        return (currentPhase + 1, phase.name, phase.priceUSD);
    }
    
    function setPhase(uint256 phaseIndex) external onlyOwner {
        require(phaseIndex < 12, "Invalid phase");
        uint256 oldPhase = currentPhase;
        currentPhase = phaseIndex;
        emit PhaseChanged(oldPhase, phaseIndex, phases[phaseIndex].name);
    }
    
    function nextPhase() external onlyOwner {
        require(currentPhase < 11, "Already at final phase");
        uint256 oldPhase = currentPhase;
        currentPhase++;
        emit PhaseChanged(oldPhase, currentPhase, phases[currentPhase].name);
    }
    
    function previousPhase() external onlyOwner {
        require(currentPhase > 0, "Already at first phase");
        uint256 oldPhase = currentPhase;
        currentPhase--;
        emit PhaseChanged(oldPhase, currentPhase, phases[currentPhase].name);
    }
    
    function setPaused(bool _paused) external onlyOwner {
        paused = _paused;
        emit Paused(_paused);
    }
    
    function depositPPEP(uint256 amount) external onlyOwner {
        require(PPEP.transferFrom(msg.sender, address(this), amount), "Deposit failed");
        emit PPEPDeposited(amount, PPEP.balanceOf(address(this)));
    }
    
    function emergencyWithdraw(address token, uint256 amount) external onlyOwner {
        if (token == address(0)) {
            (bool ok, ) = payable(owner).call{value: amount}("");
            require(ok, "ETH withdraw failed");
        } else {
            require(IERC20(token).transfer(owner, amount), "Token withdraw failed");
        }
        emit EmergencyWithdraw(token, amount);
    }
    
    function setSecureWallet(address _secureWallet) external onlyOwner {
        require(_secureWallet != address(0), "Invalid wallet");
        emit SecureWalletUpdated(secureWallet, _secureWallet);
        secureWallet = _secureWallet;
    }
    
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Zero address");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }
    
    receive() external payable {
        revert("Use payWithETH()");
    }
}

Tags:
addr:0xa6bb45921dbd23f402444c3658e059fab2e6ada5|verified:true|block:23536323|tx:0x6bcfb2493cb8bd64f365ab99b97e99c85562a1eed1a4ddbc5f8e6892bd049a8b|first_check:1759995320

Submitted on: 2025-10-09 09:35:20

Comments

Log in to comment.

No comments yet.