Skip to content

0x7s0lt1/GasTank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⛽GasTank

A simple smart contract for managing user-funded gas balances.

Features

  • Users can deposit and withdraw native tokens (e.g. ETH)
  • Authorized addresses (“facilities” and “pipes”) can transfer or burn user balances
  • Owner-controlled access and pausable
  • EOAs only — contracts cannot deposit/withdraw

Use Case

Useful for bots or services that execute transactions on behalf of users using pre-funded gas.

Usage

import {GasTank} from "./GasTank.sol";

contract MyFactory {
    
    GastTank private immutable gasTank;

    constructor() {
        
        address owner = msg.sender;
        address factory = address(this);
        
        // Initialize GasTank
        gasTank = new GasTank(owner);
        
        // Allow the factory to set pipes
        gasTank.addFacility(factory);
        
        // Allow the factory to transfer ETH from the tank
        gasTank.addPipe(factory);
        
    }

    function doSomething() public {
        uint256 startGas = gasLeft();

        // do something

        uint256 cost = ( startGas - gasLeft() ) * tx.gasprice;
        
        // Burn the cost for the service
        gasTank.burn(msg.sender, cost);
        
    }
}

Build

$ forge build

Test

$ forge test

About

Smart contract for managing user-funded gas balances.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published