# Swap Module

### Architecture Overview

City Protocol's swap infrastructure delivers best-execution token exchange as part of our Neofinance as a Service layer. It is designed to route trades across hundreds of liquidity aggregating liquidity from **top decentralized exchanges** (e.g PancakeSwap, Aerodrome, Uniswap) and bridge protocols ([Li.Fi](http://Li.Fi)), in order to guarantees best-execution pricing and minimal slippage, exposed via the `@cityprotocol/core` SDK and the `CitySwapClient` interface.&#x20;

These swap modules support quote discovery, transaction building, approval orchestration, and optional one-shot execution. This modular request-then-execute workflow mirrors the order management patterns used by professional trading desks, bridging the gap between institutional-grade routing and decentralized liquidity.

> City Protocol's swap client is implemented in **TypeScript**, shipped inside the `@cityprotocol/core` package, and supports **both EVM and Solana ecosystems**. The architecture is entirely transport-agnostic and wallet-neutral.

{% hint style="info" %}
This module is natively integrated into the Vault Architecture, allowing curators to execute complex rebalancing strategies efficiently and enabling users to deposit into vaults using any supported asset, with the Swap Module handling the underlying conversion automatically.
{% endhint %}

***

### Key Components

<table><thead><tr><th width="243.06640625">Component</th><th>Description</th></tr></thead><tbody><tr><td><strong>Quote Discovery</strong></td><td>Read-only price estimates that simulate a swap against live aggregator routes before any transaction is committed.</td></tr><tr><td><strong>Transaction Building</strong></td><td>Aggregator-generated swap payloads with configurable slippage, gas preferences, and swap mode.</td></tr><tr><td><strong>Approval Management</strong></td><td>Allowance checks and ERC-20 approval calldata generation, with automatic handling of stale USDT-like approvals.</td></tr><tr><td><strong>Execution Orchestration</strong></td><td>End-to-end swap flow mediated through a developer-supplied <code>executeTransaction</code> callback.</td></tr></tbody></table>

***

### Underlying Protocols

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-type="content-ref"></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><strong>PancakeSwap</strong></td><td><a href="https://pancakeswap.finance/swap">https://pancakeswap.finance/swap</a></td><td><a href="/files/eoRer6SqWe9eyZWaTKYE">/files/eoRer6SqWe9eyZWaTKYE</a></td></tr><tr><td><strong>Aerodrome</strong></td><td><a href="https://aerodrome.finance/">https://aerodrome.finance/</a></td><td><a href="/files/udc9Wz3Spab5GPq4uDQO">/files/udc9Wz3Spab5GPq4uDQO</a></td></tr><tr><td><strong>Uniswap</strong></td><td><a href="https://app.uniswap.org/">https://app.uniswap.org/</a></td><td><a href="/files/n9kHMQCiQKr3PBNJYNHO">/files/n9kHMQCiQKr3PBNJYNHO</a></td></tr><tr><td><strong>Li.Fi</strong></td><td><a href="https://li.fi/">https://li.fi/</a></td><td><a href="/files/o21xOiQYSw2bp4yzrd00">/files/o21xOiQYSw2bp4yzrd00</a></td></tr></tbody></table>


---

# 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://city-protocol.gitbook.io/docs/neofinance-as-a-service/swap-module.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.
