> For the complete documentation index, see [llms.txt](https://docs.aqua.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aqua.network/developers/code-examples/add-fees-to-swap/deploying-a-new-fee-collector.md). Agents can also search and read this documentation through its [MCP server](https://docs.aqua.network/~gitbook/mcp).

# Deploying a new fee collector

Deploy your own fee collector contract and configure its fee parameters.

To receive fees from swaps, deploy your own fee collector instance through the Provider Swap Fee Factory. With the SDK it is one call — the signer becomes the collector's `operator`:

{% hint style="info" %}
This page uses the [official SDKs](https://docs.aqua.network/developers/integrating-with-aquarius.md#official-sdks) (0.6.0 or later). The factory address lives in [Addresses and networks](https://docs.aqua.network/developers/reference/addresses-and-networks.md); the [complete code examples](#complete-code-examples) deploy and verify a collector in one script, and the [contract-level flow](#contract-level-flow-any-language) below covers other languages. On testnet the SDKs have no built-in factory: pass the testnet factory address as `factory`.
{% endhint %}

{% tabs %}
{% tab title="Python" %}

```python
from stellar_sdk import Keypair
from aquarius import AquariusClient

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

collector = aqua.deploy_fee_collector(
    max_fee_fraction=100,        # per-swap fee_fraction cap: 100 / 10_000 -> up to 1%
    fee_denominator=10_000,      # basis points; raise for finer fee resolution
    fee_destination="G...",      # optional — defaults to the operator (the signer)
)
print(f"collector deployed: {collector.address}")
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Keypair } from "@stellar/stellar-sdk";
import { AquariusClient } from "@aquariusdefi/sdk";

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

const collector = await aqua.deployFeeCollector({
  maxFeeFraction: 100,        // per-swap feeFraction cap: 100 / 10000 -> up to 1%
  feeDenominator: 10_000,     // basis points; raise for finer fee resolution
  feeDestination: "G...",     // optional — defaults to the operator (the signer)
});
console.log(`collector deployed: ${collector.address}`);
```

{% endtab %}
{% endtabs %}

Parameters, fixed at deploy time:

| Parameter          | Description                                                                                                                                                                                                                                                                                                |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `operator`         | The signer. The only address that can [claim fees](https://docs.aqua.network/developers/code-examples/add-fees-to-swap/claiming-and-swapping-accumulated-fees.md).                                                                                                                                         |
| `fee_destination`  | Where every claim pays out. Cannot be changed later — not even by the operator.                                                                                                                                                                                                                            |
| `max_fee_fraction` | Upper bound for the per-swap `fee_fraction` this collector accepts. At most 20% of `fee_denominator` (2,000 with a denominator of 10,000); a higher value fails the deployment with [`FeeFractionTooHigh`](https://docs.aqua.network/developers/reference/error-codes.md#provider-fee-collector-specific). |
| `fee_denominator`  | The fraction's denominator. 10,000 (basis points) works well; record it — the contract has no getter, and every `ProviderFeeConfig` must match it.                                                                                                                                                         |

A collector is never upgraded: it keeps the methods it was deployed with, so [support for output recipients](https://docs.aqua.network/developers/code-examples/add-fees-to-swap/executing-swaps-with-provider-fees.md#send-the-output-to-a-third-party) depends on when you deployed it.

The operator and the fee destination can be the same address; separate addresses are safer. The destination needs trustlines for any asset the operator claims raw — or convert claims into one asset with [`claim_and_swap`](https://docs.aqua.network/developers/code-examples/add-fees-to-swap/claiming-and-swapping-accumulated-fees.md).

Verify the deployment with the collector's read methods:

{% tabs %}
{% tab title="Python" %}

```python
print(collector.fee_destination())
print(collector.max_fee_fraction())
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
console.log(await collector.feeDestination());
console.log(await collector.maxFeeFraction());
```

{% endtab %}
{% endtabs %}

Charge fees on swaps with `collector.fee_config(fee_fraction)` — see [Executing swaps with provider fees](https://docs.aqua.network/developers/code-examples/add-fees-to-swap/executing-swaps-with-provider-fees.md).

### Complete code examples

This code deploys a fee collector on the Stellar mainnet that accepts fees of up to 1% with the denominator 10,000, then reads its configuration back from the new contract.

To execute the code, provide the secret key of the account that becomes the operator and pays for the deployment, and the address that receives the claimed fees. Save the JavaScript version as a `.mjs` file: it uses top-level `await`.

{% tabs %}
{% tab title="Python" %}

```python
from stellar_sdk import Keypair
from aquarius import AquariusClient

# =========================================
# Configuration & Setup
# =========================================

# Operator account: becomes the collector's operator and pays for the deployment
operator_secret_key = "S..."

# Address to receive the claimed fees
fee_destination_address = "G..."

# Maximum per-swap fee fraction the collector accepts, over the denominator
# (100 with the denominator 10,000 is a fee of up to 1%)
max_fee_fraction = 100
fee_denominator = 10_000

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

# =========================================
# Entry Point
# =========================================

# 1. Deploy the collector through the Provider Swap Fee Factory
print("Deploying the fee collector...")
collector = aqua.deploy_fee_collector(
    max_fee_fraction=max_fee_fraction,
    fee_denominator=fee_denominator,
    fee_destination=fee_destination_address,
)
print(f"Deployed address: {collector.address}")

# 2. Read the configuration back from the new contract
print(f"Fee destination: {collector.fee_destination()}")
print(f"Max fee fraction: {collector.max_fee_fraction()} / {fee_denominator}")
print(f"Router: {collector.router()}")
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Keypair } from "@stellar/stellar-sdk";
import { AquariusClient } from "@aquariusdefi/sdk";

// =========================================
// Configuration & Setup
// =========================================

// Operator account: becomes the collector's operator and pays for the deployment
const operatorSecretKey = "S...";

// Address to receive the claimed fees
const feeDestinationAddress = "G...";

// Maximum per-swap fee fraction the collector accepts, over the denominator
// (100 with the denominator 10,000 is a fee of up to 1%)
const maxFeeFraction = 100;
const feeDenominator = 10_000;

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

// =========================================
// Entry Point
// =========================================

// 1. Deploy the collector through the Provider Swap Fee Factory
console.log("Deploying the fee collector...");
const collector = await aqua.deployFeeCollector({
  maxFeeFraction,
  feeDenominator,
  feeDestination: feeDestinationAddress,
});
console.log(`Deployed address: ${collector.address}`);

// 2. Read the configuration back from the new contract
console.log(`Fee destination: ${await collector.feeDestination()}`);
console.log(`Max fee fraction: ${await collector.maxFeeFraction()} / ${feeDenominator}`);
console.log(`Router: ${await collector.router()}`);
```

{% endtab %}
{% endtabs %}

### Contract-level flow (any language)

The factory function behind `deploy_fee_collector`:

* **Function:**\
  `deploy_swap_fee_contract(operator: Address, fee_destination: Address, max_swap_fee_fraction: u32, swap_fee_fraction_denominator: u32) -> Address`
* **Returns:**\
  Address of the newly deployed **ProviderSwapFeeCollector**.

The parameters are described in [Provider fee contracts](https://docs.aqua.network/developers/reference/router-and-pool-contracts.md#provider-fee-contracts). The call needs the operator's authorization for the root call only, as listed in [Contract authorization](https://docs.aqua.network/developers/reference/contract-authorization.md#authorization-trees).
