How DCA Swaps Work on Chainflip

How DCA Swaps Work on Chainflip

Dollar Cost Averaging (DCA) swaps represent a new pricing strategy from Chainflip, designed to reduce the risks associated with market volatility by spreading a large swap over several smaller transactions.

This automated process allows users to swap at significantly better pricing. Lets explore two scenarios on how DCA works in practice.

Example 1: Successful DCA Swap

1. Starting the Swap: A user initiates a swap, depositing 5 BTC to exchange for USDC. The user sets a minimum accepted price of 50,000 USDC per BTC. To manage the risk of market fluctuations, Chainflip suggests splitting the swap into 5 equal parts, with each swap separated by 2 state chain blocks.

2. Swap Scheduling: The deposit is confirmed at block 100. The first chunk, consisting of 1 BTC, is scheduled for execution at block 102, allowing 2 blocks for liquidity providers (LPs) to update their orders.

3. First Swap Execution: At block 102, the first swap is executed, resulting in 50,100 USDC. Since this is above the minimum accepted price, the swap is successful. The second chunk is then scheduled for block 104.

4. Handling a Below-Minimum Price: At block 104, the second swap receives a price of 49,900 USDC, which is below the minimum set by the user. Instead of executing at a suboptimal price, the swap is rescheduled to allow for a price recovery. It will be retried based on the swap deadline before initiating a refund.

5. Retrying the Swap: At block 109, the second chunk is retried, and this time it executes successfully at 50,070 USDC, meeting the user’s criteria.

6. Completing the Remaining Chunks: The remaining three chunks are executed at blocks 111, 113, and 115, yielding 50,020 USDC, 50,010 USDC, and 50,000 USDC respectively.

7. Total Output: After all chunks are executed, the user receives a total of 250,200 USDC in their wallet. The outcome illustrates how DCA swaps can help capture better prices over time.

Example 2: DCA with Partial Refund

In some cases, not all chunks may be executed within the desired parameters. Here’s how a partial refund works when some swaps fail to meet the minimum price requirements.

1. Starting the Swap: A user again initiates a swap by depositing 5 BTC with a minimum accepted price of 50,000 USDC per BTC. The swap is split into 5 parts, spaced by 2 state chain blocks.

2. Executing the First Chunk: At block 102, the first swap is executed successfully with an output of 50,100 USDC.

3. Dealing with a Failed Chunk: As in the previous example, the second chunk scheduled for block 104 fails to meet the minimum price and is rescheduled for later execution.

4. Swap Deadline Reached: At block 109, after multiple retries, the swap is still unable to execute within the swap deadline. As a result, the process is aborted, and the remaining 4 BTC is refunded to the user’s BTC wallet.

5. Partial Refund Completion: The user receives 50,100 USDC from the successfully executed first chunk, while the unexecuted amount (4 BTC) is returned to the original BTC wallet address.

Why Use DCA Swaps?

DCA swaps are ideal for swapper looking to avoid large price swings during high-volume trades. By spreading out the swaps into chunks, users can benefit from improved average pricing and reduced exposure to sudden market movements.

Learn More About DCA Swaps on Chainflip

For a deeper dive into the technical details behind DCA swaps, check out our documentation on DCA implementation.