Multi-Token Support
The GasCreditVault contract supports multiple ERC-20 tokens as collateral for gas credits, enabling users to pay for transaction fees using their preferred tokens. This flexible system integrates with Chainlink price feeds to ensure fair and accurate conversion rates across different tokens.
Overview
Multi-token support in GasCreditVault provides:
Flexible token options for gas credit deposits
Real-time price conversion using Chainlink oracles
Secure token management with proper validation
Dynamic token addition/removal by administrators
Per-token configuration for limits and parameters
Architecture
Token Configuration
Supported Token Structure
struct TokenInfo {
AggregatorV3Interface priceFeed;
bool isStablecoin;
}
// Storage mapping
mapping(address => TokenInfo) public tokenInfo;
mapping(address => uint256) public credits;
function isTokenWhitelisted(address token) external view returns (bool);
Price Conversion Logic
function getCreditValue(address token, uint256 amount) external view returns (uint256);
function getTokenValue(address token, uint256 creditAmount) external view returns (uint256);
Deposit Management
Multi-Token Deposits
function deposit(address token, uint256 amount) external;
Withdrawal Management
Token-Specific Withdrawals
function withdraw(address token, uint256 creditAmount) external;
Transfer Credits
function transferCredit(address receiver, uint256 credit) external
Administrative Functions
Token Management
function whitelistToken(address token, address priceFeed, bool isStablecoin) external onlyOwner;
function removeToken(address token) external onlyOwner;
Emergency Functions
function emergencyWithdraw() external onlyOwner;
View Functions
Token Information
function getWhitelistedTokens() external view returns (address[] memory);
function getWhitelistedRelayers() external view returns (address[] memory);
function isTokenWhitelisted(address token) external view returns (bool);
function isRelayerWhitelisted(address relayer) external view returns (bool);
User Balances
mapping(address => uint256) public credits;
Events
event TokenWhitelisted(address indexed token, address priceFeed);
event TokenRemoved(address indexed token);
event Deposited(address indexed user, address indexed token, uint256 amount, uint256 credited);
event Withdrawn(address indexed user, address indexed token, uint256 amount, uint256 credited);
event CreditsConsumed(address indexed user, uint256 usdValue, uint256 creditCost);
event CreditTransfer(address indexed sender, address indexed receiver, uint256 creditAmount);
event OwnerWithdrawn(address indexed token, uint256 amount, uint256 creditedConsumed);
event RelayerAdded(address indexed relayer);
event RelayerRemoved(address indexed relayer);
event EmergencyWithdrawn(address indexed to, uint256 amount);
event Paused();
event Unpaused();
Best Practices
For Administrators
Validate price feeds thoroughly before adding tokens
Set appropriate limits based on token volatility
Monitor daily deposits for unusual activity
Keep fallback oracles for critical tokens
Regular security audits of token contracts
For Users
Check token prices before large deposits
Understand conversion fees for each token
Monitor price staleness indicators
Use batch deposits for multiple tokens
Keep diversified token holdings for flexibility
For Developers
Handle price feed failures gracefully
Implement proper slippage protection
Cache token information for better UX
Monitor gas costs for multi-token operations
Test with various token configurations
Related Topics:
Chainlink Integration - Price feed implementation
Credit Management - Credit lifecycle management
GasCreditVault Overview - Main contract documentation
Last updated