> ## Documentation Index
> Fetch the complete documentation index at: https://docs.soroswap.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Swap (all-in-one)

> 
Quotes, builds and simulates a swap in a **single call**: the equivalent of calling /quote and then /quote/build.

Send the same parameters as /quote plus the wallet address (`from`, a G account or C contract). The response always includes the quote, plus an `action` field telling you what to do next:

- **SIGN_TRANSACTION** — `xdr` is the simulated swap transaction, ready to be signed and sent to /send or your own rpc.
- **CREATE_TRUSTLINE** — the account is missing a trustline for the output asset. `xdr` is a changeTrust transaction: sign it, submit it, then call this endpoint again to get the swap XDR. Details (signer, assetCode, assetIssuer) come in `actionData`.
- Other actions (e.g. **RESTORE_BALANCE**) follow the same pattern: `xdr` is the transaction that resolves the action.

#### 📦 Inline prerequisites
Pass `inlinePrerequisites: true` to always receive the swap XDR in a single call, even when a trustline is missing. Instead of a **CREATE_TRUSTLINE** action, the trustline transaction comes in a `prerequisites` array: sign and submit each prerequisite in order, then handle the swap XDR according to `simulated`:

- `simulated: true` (SDEX routes) — the swap XDR is complete; sign it and send it.
- `simulated: false` (Soroban routes) — simulation cannot succeed until the trustline exists, so the swap XDR has no footprint, resource fees or auth entries. Re-simulate and assemble it (footprint, resources and auth entries are regenerated automatically), or override sequence and Soroban resources yourself, before signing and sending. Submitting it as-is will fail.

The swap XDR's sequence number already accounts for the prerequisite transactions when they share the same source account. Only the missing-trustline case becomes a prerequisite; other actions (e.g. **RESTORE_BALANCE**) keep the action flow described above.

#### ⚡ Gasless Trustline
Pass `gaslessTrustline: "create"` together with a `sponsor` address to get a single SDEX transaction that opens the trustline and swaps. The returned XDR must be signed by **both** the user and the sponsor.

> **Note:** The two-step Soroban sponsored flow (user signature + fee bump) is not supported here — use /quote and /quote/build for that.

#### 💰 Fees
`feeBps` and `referralId` are accepted for compatibility and ignored: the fee comes from your authenticated principal's partner rate, and fee destinations are no longer caller-supplied. The values you send are recorded so Soroswap can seed your profile and propose your payout address. The quote includes `platformFee` only when a partner rate applies.




## OpenAPI

````yaml POST /swap
openapi: 3.0.0
info:
  title: Soroswap API
  description: >+

    # 🚀 Soroswap API


    **Soroswap.Finance** is both an **Automated Market Maker (AMM)** and a **DEX
    Aggregator** on the Stellar blockchain.


    It aggregates liquidity from Soroban DEXes (**Soroswap, Phoenix, Aqua and
    Comet(TBA)**), and the **Stellar Classic DEX** — giving you **the best trade
    routes, liquidity tools, and real-time market data**.


    ---


    ## 📋 What You Can Do


    - 🔄 **Quote** – Get the best trade route between two assets with
    split-routing logic across AMMs and SDEX.  

    - 🧱 **Build** – Generate and simulate unsigned transactions (XDR) for swaps
    or liquidity actions.  

    - 🚀 **Send** – Submit signed transactions via Soroban RPC or Horizon.

    - ⚡ **Gasless Trustlines** – Use `gaslessTrustline` in `/quote` to open
    trustlines for users without requiring them to hold XLM or deal with
    trustline setup themselves.

    - 💰 **Platform Fees** – Add your own fee to user swaps with
    `platformFee`.  

    - 💧 **Liquidity** – Create LPs, add liquidity, remove liquidity.  

    - 💲 **Price** – Get real-time token prices.  

    - 🧠 **Pools** – View detailed pool information for Soroswap AMM.


    📮 **[Downnload the Postman Collection
    here](https://drive.google.com/drive/folders/1G-LQYE2EojPWP1CSuuS_tDb9vjYbFR6E?usp=drive_link)**

  version: '1.0'
  contact: {}
  x-logo:
    url: https://links.paltalabs.io/soroswap-full.svg
    backgroundColor: '#0e0e0e'
    altText: Soroswap Logo
    href: https://soroswap.finance
servers: []
security: []
tags: []
paths:
  /swap:
    post:
      tags:
        - Quote
      summary: Swap (all-in-one)
      description: >

        Quotes, builds and simulates a swap in a **single call**: the equivalent
        of calling /quote and then /quote/build.


        Send the same parameters as /quote plus the wallet address (`from`, a G
        account or C contract). The response always includes the quote, plus an
        `action` field telling you what to do next:


        - **SIGN_TRANSACTION** — `xdr` is the simulated swap transaction, ready
        to be signed and sent to /send or your own rpc.

        - **CREATE_TRUSTLINE** — the account is missing a trustline for the
        output asset. `xdr` is a changeTrust transaction: sign it, submit it,
        then call this endpoint again to get the swap XDR. Details (signer,
        assetCode, assetIssuer) come in `actionData`.

        - Other actions (e.g. **RESTORE_BALANCE**) follow the same pattern:
        `xdr` is the transaction that resolves the action.


        #### 📦 Inline prerequisites

        Pass `inlinePrerequisites: true` to always receive the swap XDR in a
        single call, even when a trustline is missing. Instead of a
        **CREATE_TRUSTLINE** action, the trustline transaction comes in a
        `prerequisites` array: sign and submit each prerequisite in order, then
        handle the swap XDR according to `simulated`:


        - `simulated: true` (SDEX routes) — the swap XDR is complete; sign it
        and send it.

        - `simulated: false` (Soroban routes) — simulation cannot succeed until
        the trustline exists, so the swap XDR has no footprint, resource fees or
        auth entries. Re-simulate and assemble it (footprint, resources and auth
        entries are regenerated automatically), or override sequence and Soroban
        resources yourself, before signing and sending. Submitting it as-is will
        fail.


        The swap XDR's sequence number already accounts for the prerequisite
        transactions when they share the same source account. Only the
        missing-trustline case becomes a prerequisite; other actions (e.g.
        **RESTORE_BALANCE**) keep the action flow described above.


        #### ⚡ Gasless Trustline

        Pass `gaslessTrustline: "create"` together with a `sponsor` address to
        get a single SDEX transaction that opens the trustline and swaps. The
        returned XDR must be signed by **both** the user and the sponsor.


        > **Note:** The two-step Soroban sponsored flow (user signature + fee
        bump) is not supported here — use /quote and /quote/build for that.


        #### 💰 Fees

        `feeBps` and `referralId` are accepted for compatibility and ignored:
        the fee comes from your authenticated principal's partner rate, and fee
        destinations are no longer caller-supplied. The values you send are
        recorded so Soroswap can seed your profile and propose your payout
        address. The quote includes `platformFee` only when a partner rate
        applies.
      operationId: SwapController_swap
      parameters:
        - name: network
          required: false
          in: query
          description: Network on which the operation will be performed
          schema:
            enum:
              - testnet
              - mainnet
            type: string
      requestBody:
        required: true
        description: Data required to quote and build the swap
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapDto'
            examples:
              exactIn:
                value:
                  assetIn: CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA
                  assetOut: CDTKPWPLOURQA2SGTKTUQOWRCBZEORB4BWBOMJ3D3ZTQQSGE5F6JBQLV
                  amount: '10000000'
                  tradeType: EXACT_IN
                  protocols:
                    - soroswap
                    - aqua
                    - sdex
                  slippageBps: '50'
                  from: GBQJ4HBCQHJQKSKNT3JRKC5VKA3QJUXBVFWIVSMHKPQSJ7XP2IXTCAAK
                summary: 'One-call EXACT_IN swap: quote + ready-to-sign XDR'
              withPlatformFee:
                value:
                  assetIn: CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA
                  assetOut: CDTKPWPLOURQA2SGTKTUQOWRCBZEORB4BWBOMJ3D3ZTQQSGE5F6JBQLV
                  amount: '10000000'
                  tradeType: EXACT_IN
                  protocols:
                    - soroswap
                    - aqua
                  slippageBps: '50'
                  from: GBQJ4HBCQHJQKSKNT3JRKC5VKA3QJUXBVFWIVSMHKPQSJ7XP2IXTCAAK
                summary: >-
                  Swap for a caller with a partner rate: the platform fee is
                  resolved from the profile, not the body
              gaslessTrustline:
                value:
                  assetIn: CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA
                  assetOut: CDTKPWPLOURQA2SGTKTUQOWRCBZEORB4BWBOMJ3D3ZTQQSGE5F6JBQLV
                  amount: '10000000'
                  tradeType: EXACT_IN
                  protocols:
                    - sdex
                  slippageBps: '50'
                  gaslessTrustline: create
                  from: GBQJ4HBCQHJQKSKNT3JRKC5VKA3QJUXBVFWIVSMHKPQSJ7XP2IXTCAAK
                  sponsor: GDFRQKZH2F6QPZDW7YNWCV3H6FGUQZ3XAJS7XEZQVYZSQYB4SVPQXVYB
                summary: 'Gasless trustline swap: single XDR signed by user and sponsor'
              inlinePrerequisites:
                value:
                  assetIn: CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA
                  assetOut: CDTKPWPLOURQA2SGTKTUQOWRCBZEORB4BWBOMJ3D3ZTQQSGE5F6JBQLV
                  amount: '10000000'
                  tradeType: EXACT_IN
                  protocols:
                    - soroswap
                    - aqua
                    - sdex
                  slippageBps: '50'
                  from: GBQJ4HBCQHJQKSKNT3JRKC5VKA3QJUXBVFWIVSMHKPQSJ7XP2IXTCAAK
                  inlinePrerequisites: true
                summary: >-
                  Always get the swap XDR: a missing trustline is returned in
                  prerequisites instead of replacing the swap
      responses:
        '200':
          description: Quote and transaction (or required action) returned successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  quote:
                    type: object
                    description: The quote for the swap, same schema as the /quote response
                  xdr:
                    type: string
                    example: >-
                      AAAAAgAAAAB8shYDi1JO9x2/3jMeVzK2IGtrsFVWLCL4uHRJf+YPyAAAA+gCzi7H...
                    description: >-
                      Unsigned transaction XDR: the swap when action is
                      SIGN_TRANSACTION, or the transaction that resolves the
                      required action (e.g. a changeTrust for CREATE_TRUSTLINE)
                  action:
                    type: string
                    enum:
                      - SIGN_TRANSACTION
                      - CREATE_TRUSTLINE
                      - RESTORE_BALANCE
                      - RESTORE_CONTRACT
                    example: SIGN_TRANSACTION
                    description: What to do next with the returned XDR
                  message:
                    type: string
                    example: >-
                      Sign the transaction with the user wallet and send the
                      signed XDR to /send endpoint or your own rpc
                    description: Human-readable explanation of the required action
                  actionData:
                    type: object
                    description: >-
                      Extra details when action is not SIGN_TRANSACTION (e.g.
                      signer, assetCode, assetIssuer for CREATE_TRUSTLINE)
                  simulated:
                    type: boolean
                    example: false
                    description: >-
                      Only present in inline-prerequisites mode. false means the
                      swap XDR was built without simulation (no footprint,
                      resource fees or auth entries) and must be re-simulated
                      and assembled before submission
                  prerequisites:
                    type: array
                    description: >-
                      Only present in inline-prerequisites mode: transactions to
                      sign and submit, in order, before the swap XDR
                    items:
                      type: object
                      properties:
                        action:
                          type: string
                          example: CREATE_TRUSTLINE
                        xdr:
                          type: string
                          example: AAAAAgAAAABiSu3MsKtQvDuQO5i2b...
                          description: Unsigned transaction XDR for this prerequisite
                        signer:
                          type: string
                          example: >-
                            GBQJ4HBCQHJQKSKNT3JRKC5VKA3QJUXBVFWIVSMHKPQSJ7XP2IXTCAAK
                          description: >-
                            The account that must sign and submit this
                            transaction
                        assetCode:
                          type: string
                          example: USDC
                        assetIssuer:
                          type: string
                          example: >-
                            GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN
                        description:
                          type: string
        '400':
          description: Error in input parameters, route not found, or simulation failed
        '409':
          description: The fee rate changed since the quote was issued; request a new quote
components:
  schemas:
    SwapDto:
      type: object
      properties:
        assetIn:
          type: string
          example: CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA
          description: Input asset contract address
        assetOut:
          type: string
          example: CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75
          description: Output asset contract address
        amount:
          format: int64
          type: integer
          example: '10000000'
          description: Expected input amount in stroops
        tradeType:
          type: string
          example: EXACT_IN
          enum:
            - EXACT_IN
            - EXACT_OUT
          description: 'Type of trade: EXACT_IN = input fixed; EXACT_OUT = output fixed'
        protocols:
          example:
            - soroswap
            - aqua
          description: Array of protocols to aggregate liquidity from
          type: array
          items:
            type: array
        parts:
          type: number
          example: 10
          description: >-
            Number of route splits for optimization. Higher values improve price
            discovery but increase latency. Max: 1000..
        slippageBps:
          type: number
          example: '50'
          description: >-
            Slippage tolerance in basis points (bps). 10000 = 100%, 100 = 1%, 50
            = 0.5%. Default is 50 bps (0.5%)
        maxHops:
          type: number
          example: 2
          description: Maximum number of hops to aggregate liquidity from
        assetList:
          example:
            - SOROSWAP
            - STELLAR_EXPERT
            - AQUA
            - LOBSTR
          description: >-
            Restricts intermediate tokens to a specific list. Only useful for
            Soroban transactions (Router and Aggregator). Not useful for SDEX.
          type: array
          items:
            type: string
        feeBps:
          type: number
          example: 50
          description: >-
            Ignored. Your fee rate lives in your partner profile (see GET
            /partner). Kept for wire compatibility; the value you send is
            recorded so Soroswap can seed your profile.
        gaslessTrustline:
          type: string
          example: true
          description: >-
            Whether to use gasless trustline swap. Only use this if you are sure
            that the user does not have a trustline for the output asset and if
            you have an sponsor account.
        from:
          type: string
          example: GBQJ4HBCQHJQKSKNT3JRKC5VKA3QJUXBVFWIVSMHKPQSJ7XP2IXTCAAK
          description: >-
            The wallet address (G account or C contract) that will send the
            funds and sign the transaction
        to:
          type: string
          description: >-
            The wallet address that will receive the funds. Defaults to the from
            address. Must equal from when gaslessTrustline is enabled
        referralId:
          type: string
          description: >-
            Ignored. Fee destinations are no longer caller-supplied; the value
            you send is recorded so Soroswap can propose your payout address.
        sponsor:
          type: string
          description: >-
            The wallet address that will sponsor the trustline. Only supported
            for the Gasless Trustline (SDEX) flow
        inlinePrerequisites:
          type: boolean
          example: true
          description: >-
            When true and a trustline is missing, the response still contains
            the swap XDR: the trustline transaction is returned in a
            `prerequisites` array instead of replacing the swap. Prerequisites
            must be signed and submitted in order first. For Soroban routes the
            swap XDR is returned unsimulated (`simulated: false`) since
            simulation cannot succeed until the trustline exists — re-simulate
            it (or override sequence and Soroban resources) before submitting
      required:
        - assetIn
        - assetOut
        - amount
        - tradeType
        - protocols
        - from

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.