Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Claiming & swapping accumulated fees

Claim the fees your integration has accumulated, or convert them into one target asset.

Your fee accumulates on the collector as plain token balances — the fee comes out of each swap's output token, so a collector serving many pairs holds many tokens. Claims are per token, only the collector's operator can call them, and every claim pays out to the fee_destination fixed at deploy time.

This page uses the official SDKs (0.6.0 or later). The complete code examples run each claim in one script, and the contract-level flow below covers other languages.

Read what has accrued

Reads need no signer. balance returns 0 for a token the collector has never held:

from aquarius import AquariusClient, Asset, XLM

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

reader = AquariusClient(network="mainnet")
fees = reader.fee_collector("C...")   # your deployed collector

print(fees.fee_destination())         # where claims pay out
print(fees.balance(AQUA))             # accrued fees in AQUA, base units
import { AquariusClient, Asset, XLM } from "@aquariusdefi/sdk";

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

const reader = new AquariusClient({ network: "mainnet" });
const fees = reader.feeCollector("C...");   // your deployed collector

console.log(await fees.feeDestination());   // where claims pay out
console.log(await fees.balance(AQUA));      // accrued fees in AQUA, base units

Claim and convert into one asset

claim_and_swap claims a token's entire accrued balance, swaps it through the router along a fresh quoted route, and sends the output token to the fee destination. The minimum-out guard comes from the quote, so a moving market fails the claim instead of underdelivering. The signer must be the operator:

from stellar_sdk import Keypair

USDC = Asset.classic("USDC", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN")

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

claimed = collector.claim_and_swap(AQUA, USDC, slippage=0.01)
print(f"claimed {claimed.amount_in} AQUA -> {claimed.amount_out} USDC")
print(f"transaction: {claimed.tx_hash}")
import { Keypair } from "@stellar/stellar-sdk";

const USDC = Asset.classic("USDC", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN");

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

const claimed = await collector.claimAndSwap(AQUA, USDC, { slippage: 0.01 });
console.log(`claimed ${claimed.amountIn} AQUA -> ${claimed.amountOut} USDC`);
console.log(`transaction: ${claimed.txHash}`);

Claim raw

claim sweeps one token's balance to the fee destination without conversion. For classic assets the destination needs a trustline for that token:

Complete code examples

The scripts below claim from your collector on the Stellar mainnet. To execute them, provide the secret key of the collector's operator and the address of your collector. Save the JavaScript versions as .mjs files: they use top-level await.

Claim AQUA and swap it into XLM

This script reads the collector's accrued AQUA, claims all of it, swaps it into XLM along a freshly quoted route with 0.5% slippage, and pays the XLM out to the fee destination.

Claim XLM raw

This script reads the collector's accrued XLM and transfers all of it to the fee destination without conversion.

Contract-level flow (any language)

The collector functions behind claim_and_swap and claim, called directly. Both are listed in Provider fee contracts; they need the operator's authorization for the root call only, as listed in Contract authorization.

Claim and immediately swap

  • Function: claim_fees_and_swap(e, operator: Address, swaps_chain: Vec<(Vec<Address>, BytesN<32>, Address)>, token: Address, out_min: u128) -> u128

  • Effect:

    1. Claims all of token.

    2. Swaps via your router along swaps_chain.

    3. Sends resulting tokens to fee_destination.

  • Returns: Final output amount in the target asset.

claim_and_swap requests swaps_chain from the Find Path API for the collector's current balance of token, and passes the quote's guard as out_min.

Claim raw fees

  • Function: claim_fees(e, operator: Address, token: Address) -> u128

  • Effect: Transfers entire token balance from the contract to fee_destination.

  • Returns: The amount transferred.

Last updated