Contracts
ZetaChain Gateway Router
Understanding the ZetaChain Gateway Router implementation for cross-chain swaps
Key Features
- Cross-chain message parsing
- Multi-DEX integration (Algebra & UniswapV2)
- Native token wrapping/unwrapping
- Gas fee management for cross-chain transactions
- Blacklist protection
Architecture Overview
Core Functions
Message Structure
The cross-chain messages follow a specific structure parsed by the MessageParserLib:
Security Features
-
Token Blacklisting
- Contract maintains a blacklist of tokens
- Owner can update blacklist entries
- Prevents swaps with malicious tokens
-
Slippage Protection
- Enforces minimum output amounts
- Handles gas token swaps with 4% slippage tolerance
-
Deadline Checks
- All swaps expire after 600 seconds
- Prevents pending transactions from executing at unfavorable rates
Integration Points
1. DEX Integration
The router integrates with two types of DEXes:
- Algebra (concentrated liquidity)
- UniswapV2 (constant product)
2. Token Standards
Supports multiple token types:
- Native ZetaChain token (ZETA)
- Wrapped ZETA (WZETA)
- ZRC20 tokens
- Cross-chain assets
3. Gas Management
To ensure we always have the necessary liquidity required for the bridge token we leverage uniswap v2 style pools offered by zetachain
Best Practices
-
Gas Optimization
- Use direct pool swaps when possible
- Optimize path encoding for Bitcoin transactions
- Batch operations where feasible
-
Error Handling
- Implement comprehensive revert messages
- Handle edge cases for token transfers
- Validate input parameters
-
Security Considerations
- Always verify token approvals
- Check pool existence before swaps
- Validate recipient addresses
Maintenance
Owner Functions
- Token Management
Emergency Procedures
- Token Recovery
- Owner can sweep stuck tokens
- Requires valid token and receiver addresses
- Verifies transfer success
Considerations
-
Cross-Chain Testing
- Test with various source chains
- Verify message parsing
- Validate gas fee calculations
-
Pool Integration
- Test direct vs multi-hop swaps
- Verify pool existence checks
- Validate slippage protection
-
Edge Cases
- Zero amount transfers
- Invalid token addresses
- Insufficient gas token amounts