> 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/rbs-he-yue.md).

# RBS合约

RBS 根据 SUN/USDT 流动池价格判断是否达到买入或卖出条件，并在配置的金额区间内执行操作。普通用户主要使用它的报价和状态查询；`buy()` 与 `sell()` 仅允许授权执行者调用。

### 当前价格与触发线

| 函数                     | 含义                        |
| ---------------------- | ------------------------- |
| `currentPrice()`       | 当前 SUN 现货价格，精度为 `1e18`    |
| `buyTriggerPrice()`    | 买入触发价                     |
| `sellTriggerPrice()`   | 卖出触发价                     |
| `minTradeUSDTAmount()` | 单次交易目标价值下限                |
| `maxTradeUSDTAmount()` | 单次交易目标价值上限                |
| `slippageBps()`        | 执行使用的滑点参数，分母为 `1,000,000` |

`currentPrice()` 返回每个 SUN 对应的 USDT 价值，按 `1e18` 格式化。例如用 ethers.js 执行 `formatUnits(price, 18)`。

### 查询买入条件和数量区间

`quoteBuy()` 返回：

* `price`：当前价格；
* `executable`：当前是否低于买入触发价；
* `usdtBalance`：RBS 合约当前 USDT 余额；
* `minUSDTAmount` / `maxUSDTAmount`：随机买入金额所在的 USDT 区间。

只有 `price < buyTriggerPrice` 时 `executable=true`。实际执行还要求合约余额充足。

### 查询卖出条件和数量区间

`quoteSell()` 返回：

* `price`：当前价格；
* `executable`：当前是否高于卖出触发价；
* `sunBalance`：RBS 合约当前 SUN 余额；
* `minSunIn` / `maxSunIn`：按当前池子储备换算的 SUN 卖出数量区间。


---

# 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/rbs-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.
