Unstake bfBTC

Preview Withdrawal

function previewWithdraw(uint256 share, bool native) public view returns (uint256 underlyingAmount, uint256 fee)

Description: Preview the amount of underlying asset (BTC/BTCB/hemiBTC) you will receive when withdrawing bfBTC, including fee calculations.

Parameters:

  • share: Amount of bfBTC to withdraw

  • native: true = withdraw to Bitcoin network; false = withdraw to EVM network. This parameter (bool) is currently unused on Bitlayer.

Returns:

  • underlyingAmount: Amount of underlying asset you will receive

  • fee: Total fee to be paid (percentage + fixed)

Notes:

  • Fees are calculated based on current fee configuration

  • If total fee exceeds withdrawal amount, returns (0, fee)

  • Actual received amount may vary due to ratio changes between preview and actual withdrawal

Request Withdrawal

function requestWithdraw(uint256 amount) external

Description: Initiate a withdrawal request by locking specified amount of bfBTC in the contract, awaiting administrator approval.

Parameters:

  • amount: Amount of bfBTC to withdraw

Notes:

  • Amount must exceed minWithdrawBfbtcAmount

  • Transaction reverts if calculated fees exceed withdrawal amount

  • Initial status: WITHDRAWAL_STATUS_PENDING

  • bfBTC is transferred to contract but not burned yet

Approve Withdrawal

function approveWithdraw(uint256 epoch, uint256[] calldata withdrawIds) external

Description: Administrator function to approve multiple withdrawal requests, updating their status to claimable (or approved in modeP002).

Parameters:

  • epoch: Historical epoch number for exchange rate calculation (must be less than current epoch)

  • withdrawIds: Array of withdrawal request IDs to approve

Notes:

  • Only callable by multisig manager address

  • Requests must be in WITHDRAWAL_STATUS_PENDING state

  • Must satisfy cooldown period requirement

  • In modeP002: Emits UnboundRequired event instead of setting status to claimable on Bitlayer only.

Claim Withdrawal

function claim(uint256[] calldata withdrawIds) external

Description: Claim approved withdrawals, receiving underlying assets (BTC, BTCB, hemiBTC) to user's address.

Parameters:

  • withdrawIds: Array of withdrawal request IDs to claim

Notes:

  • Only original requestor can claim

  • Requests must be in WITHDRAWAL_STATUS_CLAIMABLE state

  • Status changes to WITHDRAWAL_STATUS_CLAIMED after successful claim

  • Actual received amount calculated based on withdrawal epoch's ratio

Withdrawal Process Flow

Status Transitions

Standard Flow:

Pending -> Approved -> Claimed

Bitlayer Specific Flow (modeP002 enabled):

Pending -> Approved -> Unbound -> Claimed

Notes:

  • On Bitlayer, after approval, funds must be transferred via bridge before status changes to Unbound

  • Withdrawal approval timing varies based on Ceffu's processing speed

Withdrawal Amount Calculation

For WBTC withdrawals on Ethereum, actual amount is calculated using Oracle price:

Recv=WithdrawAmountmax(1,OraclePrice1e6)1e8RatioRecv = \text{WithdrawAmount} * \max\left(1, \frac{\text{OraclePrice}}{1e6}\right) * \frac{\text{1e8}}{Ratio}

Where:

  • Recv: Amount of WBTC received (8 decimals)

  • WithdrawAmount: Amount of bfBTC withdrawn (8 decimals)

  • OraclePrice: WBTC/BTC price from oracle

  • Ratio: Exchange ratio between BTC and bfBTC

Additional Information

  • Use claimable(withdrawId) to check available amount before claiming

  • Preview withdrawal amount using previewWithdraw() before initiating request

  • Consider fee implications when planning withdrawal amount

  • Monitor ratio changes between request and claim for potential amount variations

Important Notes

  • Stakes and Unstakes must be made while the contract is not paused.

  • Unstake require a cooldown period. (1 epoch)

  • The actual amount of BTC received depends on the current epoch's ratio and price.

  • The displayed receive amount may differ.

  • Unstake approval time may vary depending on Ceffu's processing speed. BitFi aims to process unstake request within 5 epochs.

Last updated