> 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/zhi-neng-he-yue/tokenfee-he-yue.md).

# Tokenfee合约

Token Fee 接收 SUN 费用，把 SUN 通过 SUN/USDT 流动池兑换为 USDT，然后立即按照费用配置分配全部 USDT。普通用户主要查询合约余额、兑换估值、滑点参数和分配地址；`sell()` 仅允许授权执行者调用。

### 查询代币与交易配置

| 函数                   | 用途                    |
| -------------------- | --------------------- |
| `sun()` / `usdt()`   | SUN 和 USDT 代币地址       |
| `pair()`             | SUN/USDT 流动池地址        |
| `router()`           | 使用的交易路由地址             |
| `MAX_SELL_USDT()`    | 单次执行允许卖出的最大目标 USDT 价值 |
| `sellSlippageBips()` | 当前卖出滑点保护              |
| `executors(account)` | 地址是否有权执行 `sell()`     |
| `owner()` / `dao()`  | 管理地址和 DAO 地址          |

当前源码的 `MAX_SELL_USDT` 为 `3000 ether`。它是链上最小单位数值，展示时仍应根据 `usdt()` 代币的 `decimals()` 格式化。

### 查询兑换估值

| 函数                            | 返回                                     |
| ----------------------------- | -------------------------------------- |
| `quoteSunToUSDT(sunAmount)`   | 按当前池子储备比例计算的 SUN 对应 USDT 价值            |
| `quoteUSDTToSUN(usdtAmount)`  | 按当前池子储备比例计算的 USDT 对应 SUN 数量            |
| `minUSDTOutForSUN(sunAmount)` | 考虑 AMM 价格影响、0.3% 池手续费和当前滑点后的最小 USDT 输出 |

前两个 `quote...` 使用简单储备比例，适合价值和上限判断，不等同于真实成交输出。展示交易保护值时应使用 `minUSDTOutForSUN`。

### 查询费用分配

`getFeeConfig()` 返回 `recipients` 和 `bips` 两个等长数组。分配比例使用 `DENOMINATOR() = 10,000`：`2500` 表示 25%。还可以用 `feeConfigLength()`、`feeRecipients(index)` 和 `feeBips(index)` 分项读取。

注意两个名称相似但精度不同的参数：

* `feeBips` 分母是 `10,000`；
* `sellSlippageBips` 分母是 `SLIPPAGE_DENOMINATOR() = 1,000,000`。

因此滑点值 `30,000` 表示 3%，不是 300%。

### `sell()` 的执行逻辑

`sell()` 仅允许授权执行者调用。每次执行时：

1. 读取 Token Fee 当前 SUN 余额；
2. 若全部 SUN 的估值超过 `MAX_SELL_USDT`，只卖出约等于该上限的 SUN；
3. 按 `minUSDTOutForSUN` 设置最小输出并兑换；
4. 把合约当前全部 USDT 按费用配置分配。


---

# 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/zhi-neng-he-yue/tokenfee-he-yue.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.
