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

> ## Agent Instructions
> Soroswap Aggregator API: base URL https://api.soroswap.finance, pick the network with ?network=mainnet or ?network=testnet (omitted means mainnet).
> Auth: Authorization: Bearer sk_... on every call. Get a key at https://console.soroswap.finance/register. A missing or invalid key returns 401 with code and registerUrl (POST /send returns 403 instead); an expired JWT or a missing role returns 403. Free plan 1 request/s; see https://docs.soroswap.finance/api/plans.md.
> Flow: POST /quote (assetIn, assetOut as C... contract addresses, amount as an integer string in the smallest unit, tradeType, protocols) -> POST /quote/build with the unchanged quote and from -> the user signs the XDR -> POST /send. Build right after quoting: a Soroban XDR is valid for 180 seconds. Submit it as is, never re-simulate it.
> Partner id: every account has one (9 hex chars, permanent). Read partnerId from GET /partner, or in the console at https://console.soroswap.finance under Fees & payouts. The partner fee itself is switched on by Soroswap; see https://docs.soroswap.finance/api/fees.md.
> AI tools: docs MCP at https://docs.soroswap.finance/mcp (claude mcp add --transport http soroswap-docs https://docs.soroswap.finance/mcp), skill with npx skills add https://docs.soroswap.finance. Other clients: https://docs.soroswap.finance/api/build-with-ai.md.
> Units and Stellar pitfalls: https://docs.soroswap.finance/api/stellar-gotchas.md. Errors and retries: https://docs.soroswap.finance/api/errors.md.

# Smart contracts

> Map of Soroswap core and periphery contracts: factory, pairs, library, and router.

Soroswap is a smart contract system. [Core](https://docs.soroswap.finance/amm/technical-reference/contracts#core) contracts provide fundamental safety guarantees for all parties interacting with Soroswap. [Periphery](https://docs.soroswap.finance/amm/technical-reference/contracts#periphery) contracts interact with one or more core contracts but are not themselves part of the core.

## Core

[Source code](https://github.com/soroswap/core)

The core consists of a singleton [factory](https://docs.soroswap.finance/amm/technical-reference/contracts#factory) and many [pairs](https://docs.soroswap.finance/amm/technical-reference/contracts#pairs), which the factory is responsible for creating and indexing. These contracts are quite minimal, even brutalist. The simple rationale for this is that contracts with a smaller surface area are easier to reason about, less bug-prone, and more functionally elegant. Perhaps the biggest upside of this design is that many desired properties of the system can be asserted directly in the code, leaving little room for error. One downside, however, is that core contracts are somewhat user-unfriendly. In fact, interacting directly with these contracts is not recommended for most use cases. Instead, a periphery contract should be used.

### SoroswapFactory:

[Reference documentation](https://docs.soroswap.finance/amm/technical-reference/contracts/soroswap-factory.md)

The factory holds the generic bytecode responsible for powering pairs. Its primary job is to create one and only one smart contract per unique token pair. It also contains logic to turn on the protocol charge.

### SoroswapPairs:

[Reference documentation](https://docs.soroswap.finance/amm/technical-reference/contracts/soroswap-pair.md)

Pairs have two primary purposes: serving as automated market makers and keeping track of pool token balances. They also expose data which can be used to build decentralized price oracles.

## Periphery:

[Source code](https://github.com/soroswap/core/tree/main/contracts)

The periphery is a constellation of smart contracts designed to support domain-specific interactions with the core. Because of Soroswap's permissionless nature, the contracts described below have no special privileges, and are in fact only a small subset of the universe of possible periphery-like contracts. However, they are useful examples of how to safely and efficiently interact with the Soroswap Protocol.

### SoroswapLibrary:

[Reference documentation](https://docs.soroswap.finance/amm/technical-reference/contracts/soroswap-library.md)

The library provides a variety of convenience functions for fetching data and pricing.

### SoroswapRouter:

[Reference documentation](https://docs.soroswap.finance/amm/technical-reference/contracts/soroswap-router.md)

The router, which uses the library, fully supports all the basic requirements of a front-end offering trading and liquidity management functionality.


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