Swap tokens

Overview

This guide walks through how to exchange tokens in a Saros DLMM pool from your frontend interface. The steps are:

  1. Define swap parameters

  2. Invoke the on-chain swap instruction

Swap Types

There are two types of swaps available:

  1. Exact Input: You specify the exact amount of tokens you want to swap in, and receive the corresponding amount of tokens out

  2. Exact Output: You specify the exact amount of tokens you want to receive, and provide the corresponding amount of tokens in

Swap Direction

Swaps can be performed in two directions:

  1. Swap for Y: Swap token X for token Y

  2. Swap for X: Swap token Y for token X

Example Code

Exact Input Swap

Exact Output Swap

How the Swap Executes

When you perform a swap, the following happens:

  1. Tokens are transferred from user to the pool's vault

  2. The swap is executed across one or more bins, starting from the active bin

  3. If the swap cannot be completed in a single bin, the active bin is moved and the swap continues

  4. Tokens are transferred from the pool's vault to user

  5. Protocol fees are collected and stored in the pair account

Last updated