For the complete documentation index, see llms.txt. This page is also available as Markdown.
Executing swaps with provider fees
Execute swaps through your fee collector, charging your provider fee on each one.
Route a swap through your deployed fee collector and keep a fraction of the output. Pass a ProviderFeeConfig to any quote or swap: the SDK keeps the fee arithmetic exact (ceiling rounding, both amount modes), targets the collector with client-built authorization, and the collector pulls the tokens, takes your cut from the output, and drives the router itself.
The fee is fee_fraction / fee_denominator of the swap's output: with the denominator 10,000, fee_fraction=10 is 0.1% and fee_fraction=30 is 0.3%. The denominator must match the value your collector was deployed with, and fee_fraction must stay at or below its max_swap_fee_fraction:
from stellar_sdk import Keypairfrom aquarius import AquariusClient, Asset, ProviderFeeConfig,XLMAQUA= Asset.classic("AQUA","GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA")aqua =AquariusClient(network="mainnet",signer=Keypair.from_secret("S..."))fee =ProviderFeeConfig(contract_id="C...",# your deployed collectorfee_fraction=10,# 10 / 10_000 -> 0.1% of the outputfee_denominator=10_000,)receipt = aqua.swap(XLM,AQUA,amount_in=10_0000000,provider_fee=fee,retries=3)print(f"user received: {receipt.amount_out}")# net of your fee
import{Keypair}from"@stellar/stellar-sdk";import{AquariusClient,Asset,XLM}from"@aquariusdefi/sdk";constAQUA=Asset.classic("AQUA","GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA");constaqua=newAquariusClient({network:"mainnet",signer:Keypair.fromSecret("S...") });constfee={contractId:"C...",// your deployed collectorfeeFraction:10,// 10 / 10000 -> 0.1% of the outputfeeDenominator:10_000,};constreceipt=awaitaqua.swap({from:XLM,to:AQUA,amountIn:10_0000000n,providerFee:fee,retries:3});console.log(`user received: ${receipt.amountOut}`);// net of your fee
Both amount modes work. With amount_out the SDK quotes the gross amount the route must produce so the user still receives exactly the requested output after your fee.
If you attached to the collector with aqua.fee_collector(...), fee_config() builds the same configuration with the contract id filled in — see Claiming & swapping accumulated fees.
Send the output to a third party
Set recipient to deliver the net output to another address — it does not sign anything. If the recipient lacks a trustline for the output asset, the error names the recipient, not your signer:
The complete flow against the collector contract directly — request a route from the Find Path API, build the transaction, and call the collector's swap_chained (or swap_chained_to with a recipient):