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: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 addressreceiverEnd: End position of the receiver addresspathEnd: End position of the swap path
2. Component Extraction
After parsing the end positions, the message is split into its components:toToken: Destination token addressreceiver: Receiver addresswithdraw: Boolean flag for withdrawalpath: Swap pathminAmountOut: Minimum amount to receive
3. Data Types
toToken: Parsed as an Ethereum addressreceiver: Kept as raw byteswithdraw: Parsed as a booleanpath: Kept as raw bytesminAmountOut: Decoded as a uint256
Parsing Process
-
End Position Parsing
- Iterate through the message to find comma separators
- Extract the end positions for toToken, receiver, and path
-
Component Extraction
- Use the parsed end positions to slice the message and extract each component
- Convert components to appropriate data types (address, boolean, uint256)
-
Structure Population
- Populate a
CrossChainParamsstructure with the parsed data
- Populate a
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