Withdraw from ERC20 Vaults

This section outlines the operational steps for initiating and completing a withdrawal from an ERC20-based Byzantine Vault.

0. Preview the Withdrawal

Estimate how many shares are needed or what amount you’ll receive using:

function previewWithdraw(uint256 assets) external view returns (uint256 shares);
function previewRedeem(uint256 shares) external view returns (uint256 assets);

This step helps avoid errors and ensures correct share approvals.

1. Call withdraw() or redeem()

This function initiates the withdrawal and locks the shares in the vault while the protocol processes the request.

You can call 2 functions :

  • withdraw() is used when the user specifies the amount of assets they want to withdraw, and the contract calculates the corresponding number of shares to redeem.

  • redeem() is used when the user specifies the number of shares they want to redeem, and the contract calculates the amount of assets they will receive. In both cases, the function locks the shares in the vault while the protocol processes the request.

function withdraw(
    uint256 assets,
    address receiver,
    address owner
) external returns (uint256 shares);

function redeem(
    uint256 shares,
    address receiver,
    address owner
) external returns (uint256 assets);
  • assets / shares: Amount you wish to withdraw/redeem

  • receiver: Address to receive the tokens once the withdrawal is completed

  • owner: Owner of the vault shares

Shares are transferred from the owner to the vault but not burned at this stage.

const VAULT_ADDRESS = "0x40aba78dbb81dbef26d892b6bef4e5fc23736bf5";

// Withdraw 0.2 $wstETH
const withdrawTx = await client.withdrawFromVault(VAULT_ADDRESS, 200000000000000000); 

// Redeem 0.2 $byzShare
const redeemTx = await client.redeemSharesFromVault(VAULT_ADDRESS, 200000000000000000); 

2. Wait for the Withdrawal Delay

Withdrawals require a waiting period, usually determined by the underlying restaking protocol. Slashing may occur during this time.

3. Call completeWithdrawal()

After the delay, finalize your withdrawal:

function completeWithdrawal(uint256 requestId) external;

This transfers the tokens to the receiver. The vault burns the shares at this point.

const VAULT_ADDRESS = "0x40aba78dbb81dbef26d892b6bef4e5fc23736bf5";
const REQUEST_ID = "0xBBB5C00413D3D0541A8B48189AA3652F4F3A2AAA820FD9ED044F9B83503F4A1B";

// Check if the requestId is claimable
const claimable = await client.isClaimable(VAULT_ADDRESS, REQUEST_ID);

// If yes, you can claim it
const tx = await client.completeWithdrawal(VAULT_ADDRESS, REQUEST_ID);
await tx.wait();

Last updated