# Exchange rate calculations

The relationship between stBTC and BTC is governed by a dynamic exchange rate that reflects accumulated yield. Understanding this mechanism is crucial for users of Bitcoin Yield.

## The stBTC/BTC Exchange Rate

The exchange rate between stBTC and BTC is determined by:

```
Exchange Rate = Total BTC in Protocol / Total stBTC Supply
```

This simple but powerful formula ensures that as more BTC enters the protocol (through transaction fees), each stBTC becomes worth more BTC.

## Example Calculation

Let's walk through a simplified example:

1. **Initial State**:
   * Total BTC in protocol: 100 BTC
   * Total stBTC supply: 100 stBTC
   * Exchange rate: 100/100 = 1 BTC per stBTC
2. **After Fee Collection**:
   * Transaction fees add 5 BTC to the protocol
   * Total BTC in protocol: 105 BTC
   * Total stBTC supply: still 100 stBTC (no new minting)
   * New exchange rate: 105/100 = 1.05 BTC per stBTC
3. **For an Individual User**:
   * If you hold 10 stBTC, initially worth 10 BTC
   * After fee collection, your 10 stBTC is now worth 10 × 1.05 = 10.5 BTC
   * Effective yield: 5% increase

## Technical Implementation

The exchange rate is implemented through the EIP-4626 tokenized vault standard:

* **Share Accounting**: stBTC tokens represent shares of the total pool of BTC
* **Asset-to-Share Conversion**: When depositing, the protocol calculates how many stBTC shares your BTC assets are worth
* **Share-to-Asset Conversion**: When withdrawing, the protocol calculates how many BTC assets your stBTC shares are worth

## Exchange Rate Updates

* The exchange rate is updated with every interaction with the protocol:
  * Deposits
  * Withdrawals
  * Fee distribution events
* The smart contract automatically recalculates the exchange rate based on:
  * Current BTC balance in the protocol
  * Current stBTC token supply

## Handling Intermediate Token (pegged BTC)

The protocol uses pegged BTC (pBTC) as an intermediate token:

1. When depositing: BTC → pBTC (1:1) → stBTC (at current exchange rate)
2. When withdrawing: stBTC → pBTC (at current exchange rate) → BTC (1:1)

This two-token system enables the protocol to maintain a clean separation between the pegged asset (pBTC) and the yield-bearing token (stBTC).


---

# 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.botanixlabs.com/bitcoin-yield/technical-details/exchange-rate-calculations.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.
