Swap
The following example demonstrates how InterSwap's cross-chain liquidity transfer works:
To describe how cross-chain swaps work, let's use an example:
User wants to exchange 5 ETH to equivalent amount of BNB.
User calls swap() function on ChildCommunicator.sol on source chain (Ethereum) with the following parameters
messageObj, lzGasObj
:
2. swap() function locks ETH, then sends LayerZero message to MasterCommunicator.sol on masterchain with the following payload:
3. MasterCommunicator.sol receives payload, gets Pool.sol by poolID and calls Pool.swap(). It changes reserves of the pool, adds amountOut to the payload and sends second chained LayerZero message to destination chain (Binance Smart Chain).
4. ChildCommunicator.sol receives a message, get the address of Lock.sol contract and calls unlock() function to unlock BNB
Slippage Control
Undesirable slippage is the only possible reason why order execution can fail. Before swap execution, InterSwap UI queries current expected amountOut from MasterCommunicator.sol and adjust amountOutMin value according to slippage settings %.
Refund
Undesirable slippage will trigger a refund message from masterchain to the source chain to unlock user's assets. If a "refund transaction" will fail because lack of gas - user will be able to re-execute it from his end.
InterSwap provides explorer UI to enable control over all transaction history and refunds.
Last updated