How Swapping Works
At a high level, the process can be described with the following steps:
- Initiating a swap: This first step can be done through the Swapping app (opens in a new tab) (frontend), the Javascript SDK, or directly using the Chainflip CLI client. There are two primary methods to start a Chainflip Swap:
- Generating a Deposit Address: This method involves creating a unique deposit address where the user can send the funds. Once the deposit is made, the swap process is automatically triggered. See Request Deposit Address method.
- Direct call to the Vault Smart Contract (EVM chains only): This method involves calling the
swap()
function in Chainflip Vault contracts. It offers a higher degree of control, making it suitable for advanced users (like DEX Aggregators). See Execute Swap / Call method. For more details on the smart contract implementation see EVM integration.
- Witnessing the deposit: The Validator network will monitor open Deposit Channels for incoming transactions and Vault Contracts for swap calls. Upon seeing a deposit for a Swap, it will be witnessed and registered on the State Chain.
There's a delay between the deposit transaction and its confirmation on the State Chain. On Ethereum, is 7 blocks (~84 seconds), whereas Bitcoin is 3 blocks (~30 minutes).
At this point, you can use the Block Explorer (opens in a new tab) to see the swap 'in progress'.
- Processing the swap: Once the swap is Witnessed it is ready to be swapped in the Just-In-Time AMM protocol. Swaps are automatically bundled and processed so that LPs can bid on swaps in the same block where they occur.
For swap routes that require more than one pool, i.e. BTC -> ETH, each swap is conducted sequentially, usually in the same block: BTC -> USDC, and then USDC -> ETH.
The swap input is first denominated in USD during the swapping process as a function of Chainflip's $USDC Denominated Pools.
- Broadcasting the swap output: Swapped assets on the State Chain are now listed as Pending Egress Transactions before being paid out to the user's destination address. These transactions are processed in a batch with estimated gas fees deducted to compensate the network for the Broadcast.