GasCreditVault

The GasCreditVault is a core component of the MetaTx-Contracts system that manages gas credits backed by ERC-20 tokens. It allows users to deposit supported tokens and receive credits that can be used to pay for meta-transaction fees, eliminating the need to hold native tokens for gas.

Overview

The GasCreditVault contract serves as a secure vault for managing user deposits and converting them into gas credits that can be used across the MetaTx ecosystem. It integrates with Chainlink price feeds to ensure fair and accurate conversion rates between different tokens and gas costs.

Key Features

  • Multi-Token Support: Accept multiple ERC-20 tokens as collateral

  • Chainlink Integration: Real-time price feeds for accurate conversions

  • Credit Management: Flexible credit allocation, transfer, and usage tracking

  • Security: Comprehensive access controls and safety mechanisms

  • Upgradeable: UUPS proxy pattern for future improvements

Architecture

flowchart TB
    subgraph "GasCreditVault"
        A[Token Deposits] --> B[Price Conversion]
        B --> C[Credit Allocation]
        C --> D[Credit Management]
        D --> E[Usage Tracking]
    end
    
    subgraph "External Dependencies"
        F[Chainlink Oracles] --> B
        G[ERC-20 Tokens] --> A
        H[MetaTxGateway] --> D
    end
    
    subgraph "User Operations"
        I[Deposit Tokens] --> A
        J[Transfer Credits] --> D
        K[Withdraw Tokens] --> A
        L[Check Balance] --> E
    end

Contract Interface

Core Functions

Token Support

Supported Tokens

The vault supports multiple ERC-20 tokens with Chainlink price feeds:

Adding New Tokens

Only administrators can add new supported tokens:

Credit Conversion

Price Calculation

Credits are calculated based on real-time token prices from Chainlink:

Price Staleness Protection

Deposit Operations

Basic Deposit

Deposit for Another User

Credit Management

Credit Transfer

Credit Usage

Withdrawal Operations

Token Withdrawal

Emergency Withdrawal

Security Features

Access Control

Circuit Breaker

Reentrancy Protection

Events

Error Handling

Gas Optimization

Batch Operations

Storage Optimization

Integration Examples

Frontend Integration

Best Practices

For Developers

  1. Always check return values from external calls

  2. Use SafeERC20 for token transfers

  3. Implement proper access controls for administrative functions

  4. Add circuit breakers for emergency situations

  5. Monitor price feed staleness to prevent oracle attacks

For Users

  1. Start with small deposits to test the system

  2. Monitor your credit balance regularly

  3. Be aware of price volatility affecting credit values

  4. Keep some buffer credits for unexpected gas spikes

  5. Use batch operations when depositing multiple tokens

Deployed Address

  • BSC: 0x0A4467D2D63dB133eC34162Ca0f738948d40A28c


Next Steps:

Related Contracts:

Last updated