> For the complete documentation index, see [llms.txt](https://document.sunprotocol.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://document.sunprotocol.io/en/smart-contracts/tokenfee-contract.md).

# Tokenfee Contract

Token Fee receives SUN fees, swaps SUN through the SUN/USDT pool, and immediately distributes all resulting USDT according to its fee configuration. Normal users mainly inspect balances, quotes, slippage, and recipients; `sell()` is restricted to authorized executors.

### Token and trading configuration

| Function             | Purpose                                      |
| -------------------- | -------------------------------------------- |
| `sun()` / `usdt()`   | SUN and USDT token addresses                 |
| `pair()`             | SUN/USDT liquidity pair                      |
| `router()`           | Swap router                                  |
| `MAX_SELL_USDT()`    | Maximum target USDT value sold per execution |
| `sellSlippageBips()` | Current sell slippage protection             |
| `executors(account)` | Whether an address can call `sell()`         |
| `owner()` / `dao()`  | Owner and DAO addresses                      |

The published `MAX_SELL_USDT` is `3000 ether`. It is an on-chain smallest-unit value and should be formatted with the token returned by `usdt()`.

### Conversion reads

| Function                      | Result                                                                            |
| ----------------------------- | --------------------------------------------------------------------------------- |
| `quoteSunToUSDT(sunAmount)`   | SUN value from the current reserve ratio                                          |
| `quoteUSDTToSUN(usdtAmount)`  | SUN amount from the current reserve ratio                                         |
| `minUSDTOutForSUN(sunAmount)` | Minimum output after AMM price impact, the 0.3% pool fee, and configured slippage |

The first two quote functions use a simple reserve ratio and are useful for value and cap decisions; they are not an exact execution quote. Use `minUSDTOutForSUN` to inspect transaction protection.

### Fee distribution

`getFeeConfig()` returns aligned `recipients` and `bips` arrays. Allocation uses `DENOMINATOR() = 10,000`, so `2500` means 25%. Individual entries are available through `feeRecipients(index)` and `feeBips(index)`.

Two similarly named values use different scales:

* `feeBips` uses a denominator of `10,000`;
* `sellSlippageBips` uses `SLIPPAGE_DENOMINATOR() = 1,000,000`.

Therefore a slippage value of `30,000` means 3%, not 300%.

### How `sell()` operates

The executor-only `sell()` call:

1. Reads the contract's SUN balance.
2. Caps the SUN input when its estimated value exceeds `MAX_SELL_USDT`.
3. Swaps with the minimum output returned by `minUSDTOutForSUN`.
4. Distributes the contract's full USDT balance according to the fee configuration.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://document.sunprotocol.io/en/smart-contracts/tokenfee-contract.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
