Aggregator Initialization
When the Aggregator contract is deployed, the user who initializes it becomes the protocol administrator. During initialization, compatible underlying protocols are registered in the contract’s storage, as shown in Figure 1.
Figure 1: Aggregator initialize function operations diagram.
Token Swap Process
The Aggregator facilitates token swaps through two primary functions:swap_exact_tokens_for_tokens (when you want to have an exact input)swap_tokens_for_exact_tokens (when you want ot have an exact output)
- The input token (
token_in). - The output token (
token_out). - The amounts involved.
- A distribution vector (
DexDistribution).

Figure 2: Aggregator swap functions operations diagram.
Distribution Calculation
To calculate the amounts to be swapped in each protocol, thecalculate_distribution_amounts function is used. The mathematical formula applied is:
This formula calculates the amount to be swapped for each protocol (i), where:
total_amountis the total amount to be swapped.total_partsis the sum of all parts specified inDexDistribution.
Administrative Functions
The Aggregator includes administrative functions that allow management of the contract, such as:- Initializing the contract.
- Registering, pausing, and removing protocols.
- Modifying the administrator address.
Adapter Interface and Protocols
The Aggregator communicates with protocols via adapters, which implement theSoroswapAggregatorAdapterTrait interface. This interface defines standard functions such as:
initialize: Sets up the adapter with necessary information.swap_exact_tokens_for_tokens: Executes swaps specifying the minimum token amounts.swap_tokens_for_exact_tokens: Executes swaps specifying the maximum input tokens.

Figure 3: Adapter swap functions and data fetchers diagram.