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


    //function designed to be called automatically by zeta observers
    function onCall(
        zContext calldata context,
        address fromToken,
        uint256 amount,
        bytes calldata message
    ) external virtual;

    //functions to be called by eoa wallets to leave zetachain
    function fromZetaCrosschain(
        address fromToken,
        address toToken,
        bytes calldata path,
        uint256 inputAmount,
        uint256 minAmountOut,
        bytes calldata receiver
    ) external virtual;

    function fromZetaNativeCrosschain(
        address wzeta,
        address toToken,
        bytes calldata path,
        uint256 inputAmount,
        uint256 minAmountOut,
        bytes calldata receiver
    ) external virtual payable;

Message Structure

The cross-chain messages follow a specific structure parsed by the MessageParserLib:

{
  toToken: string // Destination token address
  receiver: bytes // Recipient address bytes
  path: bytes // Swap path for routing
  withdraw: boolean // Whether to withdraw from ZetaChain
  minAmountOut: uint256 // Minimum amount to receive
}

Security Features

  1. Token Blacklisting

    • Contract maintains a blacklist of tokens
    • Owner can update blacklist entries
    • Prevents swaps with malicious tokens
  2. Slippage Protection

    • Enforces minimum output amounts
    • Handles gas token swaps with 4% slippage tolerance
  3. 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

if (params.withdraw && params.toToken != gasZRC20) {
    // Gas token swap logic
    address[] memory path = UniswapV2Library.getUniswapV2Path(
        params.toToken,
        gasZRC20,
        wzeta
    );
    uint256[] memory amountsQuote = UniswapV2Library.getAmountsIn(
        gasFee,
        path
    );
    uint256 amountInMax = amountsQuote[0] + amountsQuote[0] / 25;
}

Best Practices

  1. Gas Optimization

    • Use direct pool swaps when possible
    • Optimize path encoding for Bitcoin transactions
    • Batch operations where feasible
  2. Error Handling

    • Implement comprehensive revert messages
    • Handle edge cases for token transfers
    • Validate input parameters
  3. Security Considerations

    • Always verify token approvals
    • Check pool existence before swaps
    • Validate recipient addresses

Maintenance

Owner Functions

  1. Token Management
function updateBlacklist(address contractAddress, bool flag) public onlyOwner
function sweepToken(address receiver, address token) public onlyOwner

Emergency Procedures

  1. Token Recovery
    • Owner can sweep stuck tokens
    • Requires valid token and receiver addresses
    • Verifies transfer success

Considerations

  1. Cross-Chain Testing

    • Test with various source chains
    • Verify message parsing
    • Validate gas fee calculations
  2. Pool Integration

    • Test direct vs multi-hop swaps
    • Verify pool existence checks
    • Validate slippage protection
  3. Edge Cases

    • Zero amount transfers
    • Invalid token addresses
    • Insufficient gas token amounts