Swap

TorchSwapFlow

Torch’s Stable Swap mechanism effectively reduces slippage during swaps, providing a more cost-efficient trading experience. Below is a detailed breakdown of the swap process:

  1. Asset Transfer to Vault

    • Users transfer the asset they wish to swap (swap in asset) to the corresponding Vault contract.

  2. Vault Notifies Pool

    • Once the Vault receives the asset, it sends an op::swap_internal message to the Pool contract, initiating the swap calculation.

  3. Pool Calculates and Notifies Vault

    • After the calculation, the Pool determines the amount of the swap out asset and sends an op::payout message to the Vault responsible for the swap out asset.

    • The Vault then transfers the swapped asset to the user’s designated address as instructed.

  4. Cross-Pool Swap Operations

    • If the swap involves cross-pool operations, the Pool includes swap details and sends an op::swap_between or op::withdraw_between message to the next Pool to continue the swap process.

    • A detailed explanation of cross-pool operations will be provided in the following sections.

Last updated