MetaTxGateway
The MetaTxGateway is the core contract responsible for executing gasless meta-transactions with built-in native token support and automatic refund mechanisms.
This protocol also includes the DI Token, Token Presale, and Token Staking contracts, providing a complete tokenomics suite.
Overview
MetaTxGateway v1.0.0-native-token-support enables secure, gasless meta-transactions with native token (ETH/BNB) support, batch execution, and relayer authorization.
Key Features
🔒 Native Token Validation
Ensures exact native token amounts are provided for meta-transactions that require ETH/BNB transfers.
🔄 Automatic Refunds
Returns unused native tokens to users when transactions fail, preventing fund loss.
📦 Batch Processing
Execute multiple transactions in a single call, reducing gas costs and improving efficiency.
🖋️ EIP-712 Signatures
Cryptographically secure meta-transaction authorization with structured data signing.
🔧 UUPS Upgradeable
Safe upgrade patterns for future enhancements without disrupting existing functionality.
⏸️ Pausable
Owner can pause/unpause contract with a reason.
Contract Interface
Core Functions
executeMetaTransactions
Purpose: Execute a batch of meta-transactions on behalf of a user.
Parameters:
from: The user's address (signature signer)metaTxs: Array of MetaTransaction structssignature: EIP-712 signature from the usernonce: User's current nonce for replay protectiondeadline: Transaction expiration timestamp
Returns: Array of boolean values indicating success/failure for each transaction
Key Validations:
Relayer authorization check
Signature verification using EIP-712
Nonce validation for replay protection
Native token amount validation
Deadline enforcement
calculateRequiredValue
Purpose: Calculate the total native token value required for a batch of meta-transactions.
Use Case: Frontend applications can use this to determine how much ETH/BNB to include with the relayer transaction.
setRelayerAuthorization
Purpose: Authorize or deauthorize a relayer address.
pauseWithReason
Purpose: Pause the contract with a reason.
unpause
Purpose: Unpause the contract.
View Functions
getNonce
Purpose: Get the current nonce for a user address.
isRelayerAuthorized
Purpose: Check if a relayer is authorized.
getDomainSeparator
Purpose: Get the EIP-712 domain separator for signature verification.
getMetaTransactionTypehash
Purpose: Get the MetaTransaction struct typehash for EIP-712.
getMainTypehash
Purpose: Get the main typehash for batch meta-transactions.
getSigningDigest
Purpose: Helper for frontend to generate the EIP-712 digest for signing.
getTotalBatchCount
Purpose: Get the total number of batch transactions processed.
getVersion
Returns: "v1.0.0-native-token-support"
Data Structures
MetaTransaction
Events
RelayerAuthorized
Emitted: When relayer authorization status changes.
MetaTransactionExecuted
Emitted: For each individual meta-transaction execution.
NativeTokenUsed
Emitted: When native tokens are used in meta-transactions, showing usage and refund details.
PausedWithReason
Emitted: When the contract is paused with a reason.
TokenRescued
Emitted: When tokens are rescued by the owner.
EIP-712 Implementation
Domain Separator
MetaTransaction Type
Batch MetaTransactions Type
Signature Generation (Frontend)
Security Considerations
All addresses are validated for zero address.
Signature recovery is performed safely.
Uses OpenZeppelin's ReentrancyGuard and Pausable.
Only owner can authorize relayers and upgrades.
Refunds unused native tokens to users.
Integration Examples
Basic Meta-Transaction
Native Token Meta-Transaction
Deployed Contracts
MetaTxGateway (deployed) Chains: Mainnet, BSC, Base, Polygon, Optimism, Arbitrum, Avalanche Address: 0xbee9591415128F7d52279C8df327614d8fD8a9b2
GasCreditVault (BSC) Address: 0x0A4467D2D63dB133eC34162Ca0f738948d40A28c
Next Steps
Native Token Handling - Deep dive into value validation
Batch Processing - Optimize with batches
EIP-712 Signatures - Signature implementation
API Reference - Complete function reference
DI Token - Token details and governance
Token Presale - Presale participation guide
Token Staking - Staking and rewards
Vesting schedule (optional)
Funds forwarding to treasury
Contract Interface
Token Staking
The Token Staking contract allows users to lock DI tokens and earn rewards. Staking supports flexible or fixed terms, with rewards distributed in DI tokens.
Key Features
Stake/unstake at any time (or after lock period)
Reward calculation based on staked amount and duration
Penalty for early withdrawal (optional)
View functions for user and pool stats
Contract Interface
Next Steps
Native Token Handling - Deep dive into value validation
Batch Processing - Optimize with batches
EIP-712 Signatures - Signature implementation
API Reference - Complete function reference
DI Token - Token details and governance
Token Presale - Presale participation guide
Token Staking - Staking and rewards
Last updated

