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
endContract 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
Always check return values from external calls
Use SafeERC20 for token transfers
Implement proper access controls for administrative functions
Add circuit breakers for emergency situations
Monitor price feed staleness to prevent oracle attacks
For Users
Start with small deposits to test the system
Monitor your credit balance regularly
Be aware of price volatility affecting credit values
Keep some buffer credits for unexpected gas spikes
Use batch operations when depositing multiple tokens
Deployed Address
BSC: 0x0A4467D2D63dB133eC34162Ca0f738948d40A28c
Next Steps:
Learn about Multi-Token Support
Understand Chainlink Integration
Explore Credit Management
Related Contracts:
MetaTxGateway - Uses credits for gas payments
Overview - System architecture overview
Last updated