# Affiliate Fee Integration

Partners can earn a commission on swap transactions by passing affiliate fee parameters in API calls.

## How it works

The affiliate fee is deducted from `amountIn` **before** the swap calculation. The pool receives the remainder.

```
affiliateFeeAmount = floor((amountIn × partnerFeeBps) / 1,000,000)
poolAmountIn = amountIn - affiliateFeeAmount
```

## Request example

```json
{
  "type": "SWAP",
  "params": {
    "tokens": ["2584333:39", "0:0"],
    "amountIn": "1000000",
    "amountOut": "100000",
    "feeRates": [3000],
    "isExactIn": true,
    "partnerFeeBps": 10000,
    "partnerFeeRecipient": "bc1q..."
  }
}
```

## Rules

* `partnerFeeBps` and `partnerFeeRecipient` must always be provided together
* **RUNE → BTC swaps:** affiliate receives RUNE. Minimum fee: 1 RUNE
* **BTC → RUNE swaps:** affiliate receives BTC. Minimum fee: 546 sats (auto-adjusted if lower)
* `partnerFeeRecipient` cannot be the pool address or the user's trading address

## Fee calculation examples

**1% fee on a RUNE → BTC swap:**

```
amountIn = 1,000,000 RUNE
affiliateFeeAmount = floor((1,000,000 × 10,000) / 1,000,000) = 10,000 RUNE
poolAmountIn = 990,000 RUNE
```

**0.5% fee on a BTC → RUNE swap:**

```
amountIn = 1,000,000 sats
affiliateFeeAmount = floor((1,000,000 × 5,000) / 1,000,000) = 5,000 sats
poolAmountIn = 995,000 sats
```

## Common errors

| Error             | Cause                                                  | Fix                                    |
| ----------------- | ------------------------------------------------------ | -------------------------------------- |
| Missing recipient | `partnerFeeBps` provided without `partnerFeeRecipient` | Always provide both together           |
| Invalid recipient | Recipient is pool or user address                      | Use a different recipient address      |
| Fee too small     | Calculated fee < 1 RUNE                                | Increase `partnerFeeBps` or `amountIn` |
| Fee too large     | `poolAmountIn` would be 0                              | Reduce `partnerFeeBps`                 |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bound-1.gitbook.io/bound-docs/developer-guide/affiliate-fee-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
