SecureSaleETH

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * 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;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    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
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // 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;
    }
}
"
    },
    "contracts/SecureSaleETH.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @title SecureSaleETH
 * @dev Processa vendas aceitando apenas ETH.
 * O contrato não mantém saldo intencionalmente: os fundos vão direto para o vendedor.
 * Inclui função de resgate caso ETH seja enviado por engano ao contrato.
 */
contract SecureSaleETH is ReentrancyGuard {
    // Endereço da carteira do vendedor
    address payable public immutable vendedorWallet;

    // Evento para registrar vendas
    event VendaRealizada(address indexed comprador, uint256 valor, uint256 timestamp);

    error EnderecoVendedorInvalido();
    error ValorInvalido();

    constructor(address payable _vendedorWallet) {
        if (_vendedorWallet == address(0)) revert EnderecoVendedorInvalido();
        vendedorWallet = _vendedorWallet;
    }

    /**
     * @notice Processa a venda em ETH.
     * @dev O comprador deve enviar o valor junto com a transação.
     */
    function processarVenda() external payable nonReentrant {
        if (msg.value == 0) revert ValorInvalido();

        // Transfere ETH diretamente para o vendedor
        (bool ok, ) = vendedorWallet.call{value: msg.value}("");
        require(ok, "Falha ao enviar ETH");

        emit VendaRealizada(msg.sender, msg.value, block.timestamp);
    }

    /**
     * @notice Permite ao vendedor recuperar ETH que, por algum motivo, fique no contrato.
     * @dev Só o vendedor pode chamar.
     */
    function resgatarETHAcidental() external nonReentrant {
        require(msg.sender == vendedorWallet, "Apenas vendedor");
        uint256 bal = address(this).balance;
        if (bal > 0) {
            (bool ok, ) = vendedorWallet.call{value: bal}("");
            require(ok, "Falha ao enviar ETH");
        }
    }

    // Rejeita envios diretos sem usar `processarVenda`
    receive() external payable {
        revert("Use processarVenda()");
    }

    fallback() external payable {
        revert("Nao aceita chamadas inesperadas");
    }
}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Factory|addr:0xeaf0adf382aa3c480d94a8277d5c2c350d675060|verified:true|block:23428769|tx:0x95c05c0bf75972e9093912a07269635c1cfdcb75ae1bb94318e3148629671eaf|first_check:1758729335

Submitted on: 2025-09-24 17:55:39

Comments

Log in to comment.

No comments yet.