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.

This page uses the official SDKs (0.5.0 or later). The contract-level flow below covers other languages. Deploy a collector first — see Deploying a new fee collector.

Swap with your fee

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 Keypair
from aquarius import AquariusClient, Asset, ProviderFeeConfig, XLM

AQUA = Asset.classic("AQUA", "GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA")

aqua = AquariusClient(network="mainnet", signer=Keypair.from_secret("S..."))

fee = ProviderFeeConfig(
    contract_id="C...",     # your deployed collector
    fee_fraction=10,        # 10 / 10_000 -> 0.1% of the output
    fee_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";

const AQUA = Asset.classic("AQUA", "GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA");

const aqua = new AquariusClient({ network: "mainnet", signer: Keypair.fromSecret("S...") });

const fee = {
  contractId: "C...",     // your deployed collector
  feeFraction: 10,        // 10 / 10000 -> 0.1% of the output
  feeDenominator: 10_000,
};

const receipt = await aqua.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:

Your cut accumulates on the collector contract in the output tokens of the swaps. Collect it with Claiming & swapping accumulated fees.

Contract-level flow (any language)

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):

Last updated