Skip to main content
The aggregator is a normal Soroban contract, so another contract can call it the same way the aggregator calls its own adapters: generate a client from the WASM and invoke it.

Import the client

Call a swap

The return is Vec<Vec<i128>>: one inner vector of step amounts per protocol the trade was split across, in the same order as distribution.

You have to supply the distribution

This is the part that differs from calling the router. The aggregator does not decide how to split the trade, the caller does, by passing Vec<DexDistribution>:
parts is a weight, not a percentage. Each entry receives amount * parts / total_parts. A distribution may hold at most MAX_DISTRIBUTION_LENGTH (15) entries. See Aggregator Operation for the exact arithmetic.
Computing a good distribution on chain is expensive and needs reserve data from every protocol. In practice callers get the distribution off chain, from the Soroswap API, and pass it in. A contract that builds its own distribution is responsible for the routing quality of the result.

Authorization

As with the router, the receiving address authorizes the swap. Your contract can only swap for a user inside an invocation that user authorized, or for itself.

Read-only calls

get_adapters tells you which protocols are registered, and get_paused whether a given one is currently closed to new swaps. Both are cheap, and checking get_paused before including a protocol in a distribution avoids a failed swap. Full interface on the SoroswapAggregator page.