> ## 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.

# Routing through SDEX

> When the API quotes the Stellar classic DEX, what an SDEX quote looks like, and how to execute it next to aggregator routes.

The Soroswap API can route a swap through the Stellar classic DEX (SDEX, the order book and
classic liquidity pools) as well as through the Soroban venues the
[aggregator](/aggregator/supported-amms) executes. SDEX works differently from the other venues
in three ways, and an integration has to handle all three.

1. **SDEX is opt-in.** It is quoted only when `"sdex"` is in `protocols`.
2. **An SDEX quote is not an aggregator call.** It comes back with `"platform": "sdex"` and is
   executed as a classic path payment.
3. **A contract cannot execute it.** A path payment is a classic operation signed by a `G...`
   account. It cannot run inside a Soroban contract call.

## SDEX is quoted only when you ask for it

`/quote` looks at the venues listed in `protocols` and nothing else. If `"sdex"` is not in the
list, the API never asks SDEX for a price, and no quote will ever come back with
`"platform": "sdex"`.

```json theme={null}
{
  "assetIn": "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA",
  "assetOut": "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75",
  "amount": "149625000",
  "tradeType": "EXACT_IN",
  "protocols": ["soroswap", "aqua", "sushi", "comet", "sdex"]
}
```

When `"sdex"` is present together with Soroban venues, the API prices both in parallel and
returns **one** of them: the one with the higher `amountOut` for `EXACT_IN`, or the lower
`amountIn` for `EXACT_OUT`. A single quote never mixes SDEX and Soroban hops. To compare them
yourself, send two quotes, one with `["sdex"]` and one without it.

`GET /protocols?network=mainnet` returns every value `protocols` accepts.

> [!NOTE]
>
> SDEX trades classic Stellar assets only. A token that exists only as a Soroban contract, with no
> classic issuer behind it, has no SDEX market, and a quote with `["sdex"]` alone returns 400 for
> it. Keep the Soroban venues in `protocols` so those pairs still route.

## Read `platform` before you execute

Every quote carries `platform`, and `rawTrade` has a different shape on each.

| `platform` | What `rawTrade` holds | How it is executed |
| - | - | - |
| `aggregator` | `distribution`: routes and hops with pool ids, in stroops | An [aggregator v3](/aggregator/technical-reference/contracts/aggregator-v3) `swap_exact_in` / `swap_exact_out` call |
| `router` | A Soroswap AMM path | A Soroswap router call |
| `sdex` | A Horizon path record: `source_amount`, `destination_amount`, `path`, `min_destination_amount` (or `max_source_amount` for `EXACT_OUT`), in decimal units | A classic `path_payment_strict_send` (or `strict_receive`) operation |

An SDEX quote looks like this:

```json theme={null}
{
  "amountIn": "149625000",
  "amountOut": "26834267",
  "otherAmountThreshold": "26700096",
  "tradeType": "EXACT_IN",
  "platform": "sdex",
  "rawTrade": {
    "source_asset_type": "native",
    "source_amount": "14.9475375",
    "destination_asset_type": "credit_alphanum4",
    "destination_asset_code": "USDC",
    "destination_asset_issuer": "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
    "destination_amount": "2.6834267",
    "path": [],
    "min_destination_amount": "2.6700096"
  },
  "routePlan": [
    { "swapInfo": { "protocol": "sdex", "path": ["CAS3J7...", "CCW67T..."] }, "percent": "100" }
  ]
}
```

The top-level `amountIn` and `amountOut` are stroops, as on every quote. The amounts inside an
SDEX `rawTrade` are decimal strings, the way Horizon returns them. `source_amount` is already
net of the fee, which is charged on the input asset.

An SDEX `rawTrade` has no `distribution`, so code that expects one will fail on it.

## Executing an SDEX quote

Send the quote to `/quote/build` with a `G...` account as `from`. The API returns a classic
transaction XDR with the path payment and, on mainnet, one extra `payment` operation carrying
the fee. Sign it with `from` and submit it to the Stellar network.

```bash theme={null}
curl -X POST "https://api.soroswap.finance/quote/build?network=mainnet" \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"quote": <THE_SDEX_QUOTE>, "from": "G...", "to": "G..."}'
```

SDEX swaps pay the same fee as aggregated swaps, partner fee included. See
[Fees and revenue share](/api/fees). Building the SDEX transaction through `/quote/build` is
what puts the fee operation in it.

## If your integration calls the aggregator from a contract

Integrations that take `rawTrade.distribution` from `/quote` and pass it to the aggregator from
their own router contract, or that swap for a smart wallet (`C...` address), can only execute
`aggregator` quotes. You have two options:

* **Leave `"sdex"` out of `protocols`.** Every quote is then a Soroban route your contract can
  run. You lose the pairs where SDEX gives the better price.
* **Ask for `"sdex"` and branch on `platform`.** When the quote is `sdex`, execute it as a
  separate classic transaction from a `G...` account through `/quote/build`, outside your
  contract. When it is `aggregator`, keep your current path.

`/quote/build` and `/swap` drop `sdex` automatically when `from` or `to` is a contract address,
and return 400 if no other venue is left.

## Checklist when you never see SDEX routes

* `"sdex"` is in the `protocols` you send to `/quote`.
* You read `platform` on the response, not only `rawTrade.distribution`.
* Both assets are classic Stellar assets.
* The `from` and `to` you pass to `/quote/build` are `G...` accounts.


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