> ## Documentation Index
> Fetch the complete documentation index at: https://partner.tren.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# Partner Fees

> Charge your own fee on any trade with partnerFeeBps, paid to a wallet you register with Trench in the same transaction as the trade.

You can take a cut of every trade your integration executes by sending a `partnerFeeBps` field with a buy or a sell. The fee is paid to a wallet you register with Trench, as a plain SOL transfer included in the same transaction as the trade.

Because the transfer rides in the trade transaction, the two settle together. A trade that fails moves no fee.

<Note>
  Charging a fee requires the Partner tier. Apps on the free Basic tier cannot charge one, and a non-zero `partnerFeeBps` from such an app is rejected outright. See [Tiers](/concepts/registration#tiers).
</Note>

## Setting the Rate

The rate is expressed in basis points, so `100` is 1% and `50` is 0.5%. It is sent per request, and Trench never stores it.

```json theme={null}
{
  "mint": "…",
  "maxSolIn": "100000000",
  "minTokensOut": "…",
  "partnerFeeBps": 100,
  "priorityFeeLamports": "20000",
  "tipLamports": "1000000"
}
```

| Field           | Type                     | Required | Constraint             |
| --------------- | ------------------------ | -------- | ---------------------- |
| `partnerFeeBps` | number or numeric string | No       | Integer from 0 to 9999 |

Omitting the field, or sending `0`, charges nothing. Trench never applies a rate you did not send.

The upper bound of 9999 is arithmetic rather than a policy ceiling, since a rate of 10000 basis points would leave nothing to spend on the trade.

<Tip>
  Because the rate travels with each request, per-user tiering is entirely yours to design. Store each user's rate in your own database and pass it with their trades.
</Tip>

## What the Fee Is Charged On

The basis differs between buys and sells, and rounding is always down so you never over-collect.

| Endpoint               | Basis       | Notes                                                                                                                                |
| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `trades/buy`           | `maxSolIn`  | Taken out of `maxSolIn` rather than added on top, so the user's total debit is still `maxSolIn` and the venue receives the remainder |
| `trades/buy-exact-out` | `maxSolIn`  | The same basis, whether you supplied the value or the quote produced it. A loose cap produces a larger fee than the fill warrants    |
| `trades/sell`          | `minSolOut` | Charged on the guaranteed floor and forwarded after the sell completes                                                               |

<Warning>
  On a sell, the fee is calculated from `minSolOut` rather than from the actual proceeds, which means a `minSolOut` of `"0"` earns you nothing. This is worth checking if you are computing sell bounds loosely.
</Warning>

## Fees and Slippage

On a buy, the fee is deducted before the remainder reaches the trading venue.

In [slippage mode](/api-reference/trades#request-modes) this is handled for you. Trench takes the quote after deducting the fee, so the derived bound already accounts for it. If you charge a fee, this is the main practical reason to prefer that mode.

In explicit mode the deduction is yours to account for, which means `minTokensOut` has to be quoted against the post-fee amount rather than against `maxSolIn`.

```javascript theme={null}
const maxSolIn = 100_000_000n;      // 0.1 SOL
const partnerFeeBps = 100;          // 1%

// The venue only ever sees what is left after the fee.
const fee = (maxSolIn * BigInt(partnerFeeBps)) / 10_000n;
const spendable = maxSolIn - fee;   // 99,000,000 lamports

// Quote against `spendable`, then apply your own slippage tolerance.
const quoted = await quoteTokensOut(mint, spendable);
const minTokensOut = ((quoted * 99n) / 100n).toString();
```

<Warning>
  In explicit mode, quoting against `maxSolIn` while a fee is set will cause a correctly priced trade to trip your own slippage guard and fail with `slippage_exceeded`.
</Warning>

## Registering Fee Wallets

Fee wallets are granted with the Partner tier. Send the Trench team one or more addresses to register against your app, each of which has to meet three conditions.

1. It must already exist on-chain.
2. It must be a plain system account rather than a program-owned one.
3. It must already be rent-exempt.

A transfer into an unfunded or program-owned account fails, and because the fee rides in the trade transaction, that failure takes the whole trade with it.

If you register several wallets, one is chosen at random for each trade, so you can spread volume across wallets without coordinating with Trench.

Sending a non-zero `partnerFeeBps` without an eligible tier or a registered wallet returns `partner_fee_not_configured`. The `message` field distinguishes the two cases.

## Disclosure

Trench imposes no ceiling on `partnerFeeBps` and does not tell your users what you charge. The consent screen indicates only that your app charges a fee, not the rate.

<Warning>
  Telling your users what they are being charged, and complying with whatever rules apply to you for doing so, is your responsibility.
</Warning>

## Errors

| Status | Error                        | Cause                                                        |
| ------ | ---------------------------- | ------------------------------------------------------------ |
| `400`  | `invalid_partner_fee`        | `partnerFeeBps` is not an integer between 0 and 9999         |
| `400`  | `partner_fee_not_configured` | Your tier cannot charge fees, or no fee wallet is registered |
