Interchain Swap
Sequence diagram and description of the interchain (cross-chain) swap.
Last updated
Sequence diagram and description of the interchain (cross-chain) swap.
Last updated
Description of the interchain (cross-chain) swap.
Initiation:
The User initiates an interchain swap through the Frontend interface.
The Frontend constructs the swap transaction and requests the User to sign it.
The User signs the transaction and returns it to the Frontend.
Network 1 Processing:
The Frontend broadcasts the signed transaction to the Network 1 and Executor contract is called.
The Executor validates the transaction.
If the assets are not already in stablecoin form:
The Executor requests the Swap Protocol on Network 1 to convert the assets to stablecoin.
The Swap Protocol executes the conversion and returns the result.
The Executor transfers the stablecoin and LP fee to the Vault on Network 1.
The Executor transfers out the protocol fee.
The Vault confirms the transfer to the Executor.
Cross-Chain Message Transmission:
The Executor on Network 1 sends a cross-chain message to the Gateway on Network 1.
The Gateway emits an Event that is monitored by the Messaging and Swap Service.
The Messaging and Swap Service collects and processes the messages.
Network 2 Message Handling:
The Messaging and Swap Service submits the processed messages to the Gateway on Network 2.
The Gateway on Network 2 forwards these messages to the Executor on Network 2 for storage.
The Executor on Network 2 confirms the storage of messages.
The Gateway on Network 2 acknowledges the message submission to the Messaging and Swap Service.
Swap Execution on Network 2:
The Messaging and Swap Service forms a swap transaction for Network 2.
It sends this transaction to the Executor on Network 2 for execution.
The Executor on Network 2 requests funds from the Vault on Network 2, limited to the amount specified in the stored message.
The Vault provides the requested funds to the Executor.
The Executor sends a request to the Swap Protocol on Network 2 to execute the swap.
The Swap Protocol performs the swap and returns the result to the Executor.
The Executor updates its state and the message status to reflect the completed swap.
The Executor confirms the swap execution to the Messaging and Swap Service.
Status Monitoring and User Update:
The Frontend periodically checks the message status on the Executor of Network 2.
Based on the returned status, the Frontend updates the User:
If the swap is completed, it displays a success message.
If the swap is still pending, it shows a pending status.
If the swap has failed or timed out, it displays an appropriate error message.
This checking process continues until the swap is completed or a timeout occurs.
Error Handling:
If the initial transaction is invalid, the Executor on Network 1 returns an error to the Frontend, which then informs the User.
If any step in the process fails, the appropriate error is propagated back through the system to be reflected in the message status, which the Frontend will detect during its status checks.