# App fees

> Charge your own fee on the swaps you route, and track the volume you bring.

This page is part of the DEX Aggregator docs. The aggregator is at `https://router.intear.tech`, with live quotes at `wss://router.intear.tech/route/subscribe`, on NEAR mainnet only. https://docs.intear.tech/dex-aggregator/llms-full.txt has all of its pages in one file, and https://docs.intear.tech/llms.txt lists every page of the Intear docs.

There are two parameters, and you can use either or both:

- `fees` charges your own fee on the swap, split between up to 4 accounts.
- `referrer_id` passes your account to DEXs that track referrals or pay a share of their own fees. Without it, the aggregator's own account `dex-aggregator.intear.near` is used.

## Your own fee

Add `fees` to your requests: a JSON object of the accounts to pay and the fee each one charges, as a fraction of the swap, where `0.005` is 0.5%. URL-encode it:

```
https://router.intear.tech/route?token_in=near&token_out=nep141:usdt.tether-token.near&amount_in=1000000000000000000000000&slippage_type=Fixed&slippage=0.01&fees=%7B%22alice.near%22%3A0.005%2C%22bob.near%22%3A0.001%7D
```

That's `{"alice.near":0.005,"bob.near":0.001}`: 0.5% to `alice.near` and 0.1% to `bob.near`.

- Up to 4 accounts, charging up to 5% together, each fee in steps of 0.000001 (0.0001%). Requests over the limits are rejected with a [`400` error](https://docs.intear.tech/dex-aggregator/reference/errors.md). A fee of 0 charges nothing.
- The fee is charged once, on the input, on every DEX.
- Each account gets 80% of its fee, and 20% goes to the aggregator (`dex-aggregator.intear.near`).
- The fee is set per request, so each app or user can pay a different one. Nothing is stored, and there's nothing to set up first.
- Routes register the accounts to receive the input token where they need it, and the trader pays for that storage, in the quote's `storage_deposits`. So the first swap of a token that pays an account can cost a little more.

Where the fee goes depends on the DEX:

| DEX | How it's charged | Paid to | What the route registers |
| --- | --- | --- | --- |
| IntearDex, Plach | Intear DEX takes it out of the swap's [input](https://docs.intear.tech/intear-dex/guides/referral-fees.md), before the DEX gets the rest | The account's [Intear DEX inner balance](https://docs.intear.tech/intear-dex/guides/inner-balances.md) of the input token, which it [withdraws](https://docs.intear.tech/intear-dex/guides/inner-balances.md#withdraw) to its wallet | The input token on Intear DEX, with `register_assets`. Only with `trader_account_id`: without it, an account that doesn't have the token registered isn't paid, and the trader keeps its fee |
| Rhea, Rhea DCL | An `ft_transfer` of the input token in a fee transaction after the swap | The account's wallet, NEAR as wNEAR | Storage on the token contract (`wrap.near` for NEAR), in the fee transaction |
| Rhea, from and to Rhea balances (`rhea-nep141:`) | An `mft_transfer` in the same transaction as the swap | The account's Rhea inner balance | Storage on Rhea for the token, in the same transaction |
| Wrap | Not charged | — | — |

On IntearDex and Plach, the fee is in the swap's input token, NEAR included. On Rhea and Rhea DCL, NEAR is wrapped whole, so its fee is paid in wNEAR. [dex.intea.rs/developers](https://dex.intea.rs/developers) shows what an account collected on each DEX, and withdraws it to its wallet.

On Rhea and Rhea DCL, the fees go out in [fee transactions](https://docs.intear.tech/dex-aggregator/guides/executing-routes.md#fee-transactions), marked with `is_fee_transaction: true`, at the end of the route. A failed swap still lets its transaction succeed, so send them only if [`/route/outcome`](https://docs.intear.tech/dex-aggregator/reference/outcome.md) of the transactions before them says `charge_fee: true`. The swap is done at that point, so your app can show it as complete right away. The Rhea route from and to Rhea balances is the exception: its `mft_transfer`s are in the swap's own transaction, so they're paid only if the swap succeeds. IntearDex and Plach routes have no fee transactions: Intear DEX pays the fees in the swap itself, and lists them in its [`swap` event](https://docs.intear.tech/intear-dex/reference/events.md#swap).

Every fee transfer, `ft_transfer` and `mft_transfer`, carries the memo `Trading fee (<referrer_id>)`, with the request's `referrer_id`, or `dex-aggregator.intear.near` without one. Explorers show it along with the transfer.

:::note
Quotes include your fee: `estimated_amount` and `worst_case_amount` already have it taken out, so you can show them as they are. The fee comes off the input before the swap. For an exact-out request, it's added on top of the estimated input, so `amount_in` includes it. Routes are compared with your fee included. Trader's $TEAR [fee discount](https://docs.intear.tech/dex-aggregator/guides/amounts.md#fee-discounts) doesn't reduce your fee.
:::

## Referral tracking

`referrer_id=<your account>` is passed to all DEXs and can be tracked with [trade-indexer](https://github.com/INTEARnear/trade-indexer) or [Developers page](https://dex.intea.rs/developers) on Intear DEX (tracks all DEXs, not only Intear DEX).
