# sBTC 代币

## 概述

这个 [sBTC 代币合约](https://github.com/stacks-network/sbtc/blob/main/contracts/contracts/sbtc-token.clar) (`sbtc-token.clar`) 实现了 sBTC 的同质化代币功能。它同时管理未锁定和已锁定的 sBTC 代币，并提供铸造、销毁、转账以及查询代币信息的函数。sBTC 是一种 SIP-010 标准的同质化代币。

## 常量

* `ERR_NOT_OWNER` (u4)：当发送方尝试移动其不拥有的代币时出现的错误。
* `ERR_NOT_AUTH` (u5)：当调用者不是被授权的协议调用者时出现的错误。
* `token-decimals` (u8)：代币的小数位数。

## 同质化代币

* `sbtc-token`: sBTC 的主要同质化代币。
* `sbtc-token-locked`: 表示已锁定的 sBTC 代币。

## 数据变量

* `token-name`: 代币名称（默认值："sBTC"）。
* `token-symbol`: 代币符号（默认值："sBTC"）。
* `token-uri`: 代币元数据的可选 URI。

## 协议函数

这些函数只能由已授权的协议合约调用：

### protocol-transfer

* 参数： `amount: uint`, `sender: principal`, `recipient: principal`
* 返回： `(response bool uint)`

### protocol-lock

* 参数： `amount: uint`, `owner: principal`
* 返回： `(response bool uint)`

### protocol-unlock

* 参数： `amount: uint`, `owner: principal`
* 返回： `(response bool uint)`

### protocol-mint

* 参数： `amount: uint`, `recipient: principal`
* 返回： `(response bool uint)`

### protocol-burn

* 参数： `amount: uint`, `owner: principal`
* 返回： `(response bool uint)`

### protocol-burn-locked

* 参数： `amount: uint`, `owner: principal`
* 返回： `(response bool uint)`

### protocol-set-name

* 参数： `new-name: (string-ascii 32)`
* 返回： `(response bool uint)`

### protocol-set-symbol

* 参数： `new-symbol: (string-ascii 10)`
* 返回： `(response bool uint)`

### protocol-set-token-uri

* 参数： `new-uri: (optional (string-utf8 256))`
* 返回： `(response bool uint)`

### protocol-mint-many

* 参数： `recipients: (list 200 {amount: uint, recipient: principal})`
* 返回： `(response (list 200 (response bool uint)) uint)`

## 公开函数（SIP-010 特性）

### transfer

* 参数： `amount: uint`, `sender: principal`, `recipient: principal`, `memo: (optional (buff 34))`
* 返回： `(response bool uint)`

### get-name

* 返回： `(response (string-ascii 32) uint)`

### get-symbol

* 返回： `(response (string-ascii 10) uint)`

### get-decimals

* 返回： `(response uint uint)`

### get-balance

返回某个主体的总余额（已锁定 + 未锁定）。

* 参数： `who: principal`
* 返回： `(response uint uint)`

### get-balance-available

返回某个主体可用（未锁定）的余额。

* 参数： `who: principal`
* 返回： `(response uint uint)`

### get-balance-locked

返回某个主体已锁定的余额。

* 参数： `who: principal`
* 返回： `(response uint uint)`

### get-total-supply

* 返回： `(response uint uint)`

### get-token-uri

* 返回： `(response (optional (string-utf8 256)) uint)`

## 私有函数

### protocol-mint-many-iter

* 用于向多个接收者铸造代币的辅助函数。
* 参数： `item: {amount: uint, recipient: principal}`
* 返回： `(response bool uint)`

## 安全考虑

{% stepper %}
{% step %}
**访问控制**

协议函数只能由已授权合约调用，并通过以下方式强制执行： `sbtc-registry` 合约。
{% endstep %}

{% step %}
**所有权验证**

这个 `transfer` 函数检查发送方是否拥有要转移的代币。
{% endstep %}

{% step %}
**独立的代币跟踪**

该合约分别跟踪已锁定和未锁定的代币，以确保正确记账。
{% endstep %}
{% endstepper %}

## 与其他合约的交互

* `.sbtc-registry`: 用于验证协议调用者是否可执行特权操作。


---

# 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://docs.stacks.co/learn/zh/sbtc/clarity-contracts/sbtc-token.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.
