For the complete documentation index, see llms.txt. This page is also available as Markdown.
Executing swaps through specific pool
Pin a swap to one known pool with the official SDK — quote through the router's own estimator and execute without the path-finding API.
Swap against one pool you choose, bypassing path-finding entirely. pool.quote() asks the router's on-chain estimate_swap for that pool's hash, and execute() submits the router's single-pool swap with a minimum-out guard derived from the quote. The only network dependency is the RPC — for your own routing, a single-market integration, or isolation from other pools.
This page uses the official SDKs (0.4.0 or later). The contract-level flow below covers other languages and contract sub-invocations.
Make sure the account has an established trustline for the asset to receive — otherwise the swap will fail until the trustline is created. See the Stellar documentation on trustlines.
1. Set up the client and pick the pool
A pair can have several pools — different types and fee tiers. Pick the exact one you trust:
from stellar_sdk import Keypairfrom aquarius import AquariusClient, Asset,XLMAQUA= Asset.classic("AQUA","GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA")aqua =AquariusClient(network="mainnet",signer=Keypair.from_secret("S..."))pools = aqua.pools_for_pair(XLM,AQUA)pool =next(p for p in pools if p.type =="volatile"and p.fee_bps ==30)
The quote runs the router's estimate_swap for this pool's hash — no signer required, no path-finding API involved:
quote = pool.quote(XLM,AQUA,amount_in=1000000,slippage=0.01)# 0.1 XLM in stroopsprint(f"estimated out: {quote.amount_out}")# base unitsprint(f"guaranteed minimum: {quote.guard}")# estimate reduced by slippage
constquote=awaitpool.quote({from:XLM,to:AQUA,amountIn:1000000n,slippage:0.01});// 0.1 XLM in stroopsconsole.log(`estimated out: ${quote.amountOut}`);// base unitsconsole.log(`guaranteed minimum: ${quote.guard}`);// estimate reduced by slippage
3. Execute
execute() submits the router's single-pool swap pinned to this pool, with the quote's guard as the on-chain minimum. If the pool moves past the guard between quote and inclusion, the transaction fails with a SlippageError whose requote() re-reads the same pool. For bots, pool.swap() combines quote, execute, and retries:
Single-pool swaps are exact-input only: the router has no single-pool strict-receive. For an exact output amount, use the routed path described in Executing swaps through optimal path.
Contract-level flow (any language)
The SDK methods above wrap the router's single-pool entry points. The steps below call the pool contract directly — useful from other languages and for contract sub-invocations, where a direct pool call costs fewer resources than a chained swap.
To perform a swap, you need to follow these steps:
1. Identify pool address: This part was covered earlier, please check corresponding article.
2. Specify user secret key, pool address, amount in, input and output token indices: You need to specify pool address, the amount of the input token you want to swap in stroops and swap direction by in and out tokens.
3. Calculate minimum amount of token to receive: This can be achieved by simulating estimate_swap pool method.
4. Perform swap operation by submitting corresponding transaction.
Complete code examples
This code swaps 0.1 XLM to AQUA with Aquarius AMM on mainnet.
To successfully execute the code, provide the secret key of a Stellar account with at least 3 XLM and an established trustline for AQUA.
Copy the full code PythonCopy the full code JavaScript