ImmediateAutoRefunder

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.19;

contract ImmediateAutoRefunder {
    address public owner;
    uint256 public gasEstimate = 21000; // Standard ETH transfer gas
    uint256 public gasBufferWei = 200000000; // 0.3 gwei in wei
    
    event Deposit(address indexed from, uint256 amount, uint256 refunded, uint256 gasCost);
    event GasSettingsUpdated(uint256 gasEstimate, uint256 gasBuffer);
    
    constructor() {
        owner = msg.sender;
    }
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not the owner");
        _;
    }
    
    receive() external payable {
        
        uint256 adjustedGasPrice = tx.gasprice + gasBufferWei; // Add 0.3 gwei buffer
        uint256 estimatedGasCost = gasEstimate * adjustedGasPrice;
        
        require(msg.value > estimatedGasCost, "Amount too small to cover gas");
        
        
        uint256 refundAmount = msg.value - estimatedGasCost;
        
        // refund
        payable(msg.sender).transfer(refundAmount);
        
        emit Deposit(msg.sender, msg.value, refundAmount, estimatedGasCost);
    }
    
    // Update gas settings (only owner)
    function updateGasSettings(uint256 _gasEstimate, uint256 _gasBufferWei) external onlyOwner {
        gasEstimate = _gasEstimate;
        gasBufferWei = _gasBufferWei;
        emit GasSettingsUpdated(_gasEstimate, _gasBufferWei);
    }
    
    // Get current gas calculation
    function getGasCalculation() external view returns (
        uint256 currentGasPrice, 
        uint256 adjustedGasPrice, 
        uint256 estimatedCost
    ) {
        currentGasPrice = tx.gasprice;
        adjustedGasPrice = tx.gasprice + gasBufferWei;
        estimatedCost = gasEstimate * adjustedGasPrice;
    }
    
    // Preview what refund would be for a given amount
    function previewRefund(uint256 amount) external view returns (uint256 refundAmount, uint256 gasCost) {
        uint256 adjustedGasPrice = tx.gasprice + gasBufferWei;
        gasCost = gasEstimate * adjustedGasPrice;
        
        if (amount > gasCost) {
            refundAmount = amount - gasCost;
        } else {
            refundAmount = 0;
        }
    }
    
    function execute(address payable recipient, uint256 amount) external onlyOwner {
        require(address(this).balance >= amount, "Insufficient balance");
        recipient.transfer(amount);
    }
    
    // Get contract balance
    function getBalance() external view returns (uint256) {
        return address(this).balance;
    }
    
    // Emergency withdraw
    function withdrawAll() external onlyOwner {
        payable(owner).transfer(address(this).balance);
    }
}

Tags:
addr:0x4c49542c95fb3317a43d92d68b979751543a39fe|verified:true|block:23663532|tx:0x67a39f9d50e0f7cfb186cc4b7c6c755aeda7d54a7c31d95fd446b332f5e1e092|first_check:1761505034

Submitted on: 2025-10-26 19:57:15

Comments

Log in to comment.

No comments yet.