# BitcoinRedeemer

This contract facilitates redemption of stBTC tokens to Bitcoin through tBTC redemption process.

## tbtcToken

```solidity
contract ITBTCToken tbtcToken
```

Interface for tBTC token contract.

## stbtc

```solidity
contract stBTC stbtc
```

stBTC token contract.

## tbtcVault

```solidity
address tbtcVault
```

Address of the TBTCVault contract.

## TbtcVaultUpdated

```solidity
event TbtcVaultUpdated(address oldTbtcVault, address newTbtcVault)
```

Emitted when the TBTCVault contract address is updated.

### Parameters

| Name         | Type    | Description                            |
| ------------ | ------- | -------------------------------------- |
| oldTbtcVault | address | Address of the old TBTCVault contract. |
| newTbtcVault | address | Address of the new TBTCVault contract. |

## RedemptionRequested

```solidity
event RedemptionRequested(address owner, uint256 shares, uint256 tbtcAmount)
```

Emitted when redemption is requested.

### Parameters

| Name       | Type    | Description             |
| ---------- | ------- | ----------------------- |
| owner      | address | Owner of stBTC tokens.  |
| shares     | uint256 | Number of stBTC tokens. |
| tbtcAmount | uint256 | Number of tBTC tokens.  |

## TbtcTokenZeroAddress

```solidity
error TbtcTokenZeroAddress()
```

Reverts if the tBTC Token address is zero.

## StbtcZeroAddress

```solidity
error StbtcZeroAddress()
```

Reverts if the stBTC address is zero.

## TbtcVaultZeroAddress

```solidity
error TbtcVaultZeroAddress()
```

Reverts if the TBTCVault address is zero.

## CallerNotAllowed

```solidity
error CallerNotAllowed(address caller)
```

Attempted to call receiveApproval by supported token.

## EmptyExtraData

```solidity
error EmptyExtraData()
```

Attempted to call receiveApproval with empty data.

## UnexpectedTbtcTokenOwner

```solidity
error UnexpectedTbtcTokenOwner()
```

Attempted to call \_redeemSharesAndUnmint with unexpected tBTC token owner.

## RedeemerNotOwner

```solidity
error RedeemerNotOwner(address redeemer, address owner)
```

Reverts if the redeemer is not the deposit owner.

## ApproveAndCallFailed

```solidity
error ApproveAndCallFailed()
```

Reverts when approveAndCall to tBTC contract fails.

## NotTbtcTokenOwner

```solidity
error NotTbtcTokenOwner()
```

Reverts if the new TBTCVault contract is not tBTC token owner.

## constructor

```solidity
constructor() public
```

## initialize

```solidity
function initialize(address _tbtcToken, address _stbtc, address _tbtcVault) public
```

Initializes the contract with tBTC token and stBTC token addresses.

### Parameters

| Name        | Type    | Description                              |
| ----------- | ------- | ---------------------------------------- |
| \_tbtcToken | address | The address of the tBTC token contract.  |
| \_stbtc     | address | The address of the stBTC token contract. |
| \_tbtcVault | address | The address of the TBTCVault contract.   |

## receiveApproval

```solidity
function receiveApproval(address from, uint256 amount, address, bytes extraData) external
```

Redeems shares for tBTC and requests bridging to Bitcoin.

### Parameters

| Name      | Type    | Description                                                                                                         |
| --------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| from      | address | Shares token holder executing redemption.                                                                           |
| amount    | uint256 | Amount of shares to redeem.                                                                                         |
|           | address |                                                                                                                     |
| extraData | bytes   | Redemption data in a format expected from `redemptionData` parameter of Bridge's `receiveBalanceApproval` function. |

## updateTbtcVault

```solidity
function updateTbtcVault(address newTbtcVault) external
```

Updates TBTCVault contract address.

### Parameters

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| newTbtcVault | address | New TBTCVault contract address. |

## \_redeemSharesAndUnmint

```solidity
function _redeemSharesAndUnmint(address owner, uint256 shares, bytes tbtcRedemptionData) internal
```

Initiates the redemption process by exchanging stBTC tokens for tBTC tokens and requesting bridging to Bitcoin.

*Redeems stBTC shares to receive tBTC and requests redemption of tBTC to Bitcoin via tBTC Bridge. Redemption data in a format expected from `redemptionData` parameter of Bridge's `receiveBalanceApproval`. It uses tBTC token owner which is the TBTCVault contract as spender of tBTC requested for redemption. tBTC Bridge redemption process has a path where request can timeout. It is a scenario that is unlikely to happen with the current Bridge setup. This contract remains upgradable to have flexibility to handle adjustments to tBTC Bridge changes. Redemption data should include a `redeemer` address matching the address of the deposit owner who is redeeming the shares. In case anything goes wrong during the tBTC unminting process, the redeemer will be able to claim the tBTC tokens back from the tBTC Bank contract.*

### Parameters

| Name               | Type    | Description                                                                                                                          |
| ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| owner              | address | The owner of the stBTC tokens.                                                                                                       |
| shares             | uint256 | The number of stBTC tokens to redeem.                                                                                                |
| tbtcRedemptionData | bytes   | Additional data required for the tBTC redemption. See `redemptionData` parameter description of `Bridge.requestRedemption` function. |


---

# 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.acre.fi/api/bitcoinredeemer.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.
