> 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/bond-contract.md).

# Bond Contract

This contract handles Bond purchases, single-token SUN staking, order settlement, management fees, principal claims, and personal reward claims. Use BondInfo for normal order queries because it combines raw fields with live claimable values.

### Find a user's order IDs

| Function                      | Purpose                              |
| ----------------------------- | ------------------------------------ |
| `userBondOrderCount(user)`    | Number of Bond orders                |
| `userBondOrders(user,index)`  | Bond order ID at a zero-based index  |
| `userStakeOrderCount(user)`   | Number of single-stake orders        |
| `userStakeOrders(user,index)` | Stake order ID at a zero-based index |

Bond and stake orders share one globally increasing `orderId`, so IDs are not necessarily contiguous for one user or order kind.

Raw details are exposed by `orderBase(orderId)`, `orderAmounts(orderId)`, and `orderIndexes(orderId)`. `kind=1` is Bond and `kind=2` is single-token staking. `status=1` is normal and `status=2` is collateralized. Only the current `holder` may claim.

### Claim personal rewards

```
claimReward(orderId, amount)
```

`amount` is in SUN's smallest unit. An exact amount makes a partial claim. The maximum `uint256` value means all currently claimable rewards. The call settles the order and credits **Turbine `claimableReward`**; it does not transfer SUN directly to the wallet.

```
115792089237316195423570985008687907853269984665640564039457584007913129639935
```

### Claim principal

```
claimPrincipal(orderId, amount)
```

This transfers linearly released principal directly to the current holder. The amount must not exceed the live `claimablePrincipal`; maximum `uint256` means all principal currently available.

Before writing, call `BondInfo.getOrder(orderId)` and inspect `holder`, `status`, `claimableReward`, and `claimablePrincipal`.

### Other user actions

| Function                                 | Purpose                                                                                             |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `buyBond(typeId,usdtAmount)`             | Buy a Bond; requires USDT approval                                                                  |
| `stake(typeId,sunAmount)`                | Create a single-token stake; requires SUN approval and USDT approval for the initial management fee |
| `payManagementFee(orderId,periods)`      | Extend management-fee coverage                                                                      |
| `settleOrder(orderId)`                   | Settle one order without claiming                                                                   |
| `transferOrderHolder(orderId,newHolder)` | Transfer order-holder rights; use with care                                                         |

<figure><img src="https://67272133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQwq1LDgDnycI1FCz8mLz%2Fuploads%2F6hY3ZKhh9gXeKT5A9MGV%2Fuserinfo.png?alt=media&amp;token=4f99fc8b-2dfc-49a0-9ac0-cdd8dc041a02" alt=""><figcaption></figcaption></figure>

<figure><img src="https://67272133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQwq1LDgDnycI1FCz8mLz%2Fuploads%2FnedwbrX4jkf4CEWwa1Kp%2Fclaim.png?alt=media&amp;token=8521a1de-d2d9-493f-bcaa-e3922885a0bc" alt=""><figcaption></figcaption></figure>


---

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