Cross-Chain Message Parsing for ZetaChain

Overview

Our system integrates with ZetaChain to enable cross-chain functionality, particularly for messages originating from Bitcoin/Evms (with plans to include Solana in the future). This document explains the pattern used to parse these cross-chain messages.

Message Structure

The cross-chain messages follow a specific structure:

${toTokenEnd},${receiverEnd},${pathEnd}-${toToken}${receiver}${withdraw}${path}${minAmountOut}

This structure allows for efficient parsing and extraction of key parameters.

Parsing Pattern

1. End Position Parsing

The message begins with three numbers separated by commas, indicating the end positions of key components:

  • toTokenEnd: End position of the destination token address
  • receiverEnd: End position of the receiver address
  • pathEnd: End position of the swap path

2. Component Extraction

After parsing the end positions, the message is split into its components:

  • toToken: Destination token address
  • receiver: Receiver address
  • withdraw: Boolean flag for withdrawal
  • path: Swap path
  • minAmountOut: Minimum amount to receive

3. Data Types

  • toToken: Parsed as an Ethereum address
  • receiver: Kept as raw bytes
  • withdraw: Parsed as a boolean
  • path: Kept as raw bytes
  • minAmountOut: Decoded as a uint256

Parsing Process

  1. End Position Parsing

    • Iterate through the message to find comma separators
    • Extract the end positions for toToken, receiver, and path
  2. Component Extraction

    • Use the parsed end positions to slice the message and extract each component
    • Convert components to appropriate data types (address, boolean, uint256)
  3. Structure Population

    • Populate a CrossChainParams structure with the parsed data

Key Considerations

  • Flexibility: The structure allows for variable-length components, particularly useful for multi-hop swap paths

Future Enhancements

  • Solana/Cosmos Integration: The parsing pattern is designed to be adaptable for future integration with any blockchain
  • Extended Functionality: The structure allows for potential usage on other topics (lp management) with just a different string pattern