> For the complete documentation index, see [llms.txt](https://terplayer-1.gitbook.io/terplayer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://terplayer-1.gitbook.io/terplayer/terplayer-berabtc/operating-mechanism-of-berabtc.md).

# Operating Mechanism of beraBTC

## 1. System Overview

#### System Architecture Diagram

<figure><img src="https://3164221739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqmz8b1Xn8Ts4iju0Z5Ox%2Fuploads%2FdOAVIMJe0WTxsORdAlCN%2Fimage.png?alt=media&amp;token=f01c5ebd-9d93-4ae7-9d39-df2c45f75665" alt=""><figcaption></figcaption></figure>

***

## 2. Core Function Modules

### **2.1 mint**

Enter the amount of beraBTC to mint, obtain the BTC price through the Pyth oracle, and stake HONEY to mint beraBTC.

```
//     function openPosition(uint256 amount) external {}
```

### **2.2 burn**

Enter the NFT ID of the beraBTC to be minted, burn the beraBTC to redeem HONEY.

```
//     function closePosition(uint256 tokenId) external {}
```

### **2.3 Settlement**

Enter the NFT ID of the beraBTC to be settled. Settle beraBTC by using the pledged honey to purchase an equivalent amount of BTC through Atomic swap using the Pyth oracle, and return the remaining HONEY.

```
//     function deliveryPosition(uint256 tokenId) external {}
```

### **2.4 Passive Delivery Triggered by Price**

When the BTC price exceeds the delivery price of beraBTC, passive delivery is triggered. Using the Pyth oracle, the pledged HONEY is used to purchase an equivalent amount of BTC through Atomic swap, and the remaining HONEY is returned.

{% code overflow="wrap" %}

```
//    function liquidateDeliveryPosition(uint256[] memory tokenIdList) external{}
    
    function liquidatePosition(uint256[] memory tokenIdList,address redeemer, bytes32 secretHash,bytes memory receiveBtcAddr) external{}
		
		function liquidatePositionFinish(uint256[] memory tokenIdList,bytes32 deliverySecretHash) external{}
```

{% endcode %}

***

## 3. Frontend-Backend Contract Interaction

### **3.1 Mint** beraBTC

Frontend calls the beraBTC trading contract, inputs the amount of beraBTC to mint and deposits 120% of the current equivalent beraBTC value in HONEY to the berachain beraBTC contract.Contract mints beraBTC and a beraBTC NFT.

### **3.2 Burn** beraBTC

Frontend calls the beraBTC trading contract, inputs the NFT ID of the beraBTC to burn and authorizes the corresponding mint amount of beraBTC, sends the transaction to the beraBTC contract.Contract burns the corresponding beraBTC and returns the staked HONEY.

### **3.3 Delivery** beraBTC

Frontend calls the beraBTC trading contract, inputs the NFT ID of the beraBtc to be delivered and sends the transaction to the beraBTC contract.Uses Atomic swap to purchase the corresponding mint amount of beraBTC, deducts 1% fee and returns the remaining HONEY to the user's address.

### **3.4 Platform Delivery** beraBTC

Backend calls when BTC price exceeds the delivery price of minted beraBTC, triggering platform delivery.Uses Atomic swap to purchase the corresponding mint amount of beraBTC, deducts 1% fee and returns the remaining HONEY to the user's address.
