# Aggregator Engine

### **What Is an Aggregator Engine?**

A DEX aggregator is a smart routing system that scans multiple decentralized exchanges simultaneously to find the most efficient trading route for your swap.\
Instead of relying on a single DEX’s liquidity pool, SpurSwap’s Aggregator Engine connects to **multiple DEXs and liquidity sources** at once, optimizing for price, speed, and cost.

When you initiate a swap, the engine:

1. Analyzes token prices across connected DEXs.
2. Splits or routes your trade through one or more exchanges.
3. Automatically selects the path that gives you the **best overall return**.

***

### **How It Works**

SpurSwap’s Aggregator Engine follows a multi-step optimization process:

1. **Token Pair Discovery**\
   The engine identifies all available trading pairs for the selected tokens on each connected DEX.
2. **Price and Liquidity Analysis**\
   It then queries each source for:
   * Token reserves
   * Liquidity depth
   * Current market price
   * Estimated gas costs
3. **Route Optimization**\
   Using an internal algorithm, SpurSwap simulates every possible swap path, including split routes and determines the most profitable and stable option for you.
4. **Execution Layer**\
   The engine executes the optimized route through smart contracts or API calls, ensuring your transaction finalizes securely and transparently on-chain.

***

### **Supported Liquidity Sources**

SpurSwap currently integrates with top decentralized exchanges and liquidity hubs, including:

* **PancakeSwap (BSC)**
* **ApeSwap (BSC)**
* **Uniswap V3 (Ethereum & Base)**
* **SushiSwap (Multichain)**
* **QuickSwap (Polygon)**
* **BaseSwap (Base Chain)**

The Aggregator Engine continuously evolves, new DEXs are added as the ecosystem grows to maintain optimal liquidity coverage.

***

### **Dynamic Price Routing**

Instead of using static APIs or hardcoded pairs, the Aggregator Engine dynamically queries live DEX data every time a swap request is made.\
This ensures that prices reflect **real-time market conditions**, not cached or outdated data.

The routing algorithm considers:

* Best token-to-token rate
* Gas efficiency
* Liquidity depth
* Historical volatility
* Potential price impact

This makes every swap decision **data-driven**, not guesswork.

***

### **Fail-Safe & Recovery Logic**

In the event that a preferred DEX route becomes unavailable during execution (for example, if liquidity temporarily drops), the Aggregator Engine automatically retries using the **next-best available route** without user intervention, minimizing swap failures and improving transaction reliability.

***

### **Why It Matters**

Traditional DEX users often overpay without realizing it, simply because they trade on a single platform.\
SpurSwap eliminates this inefficiency by letting users **access the entire DeFi liquidity network from one interface**, automatically choosing the most profitable route.

This means:

* No manual comparison between DEXs
* No need to understand complex routing logic
* Always getting the **best execution price**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://spurprotocol.gitbook.io/spurswap-whitepapper/aggregator-engine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
