Vault

Overview

IBVMVault is a secure IBVM Bitcoin vault contract that allows users to deposit BTC and enables authorized roles to perform withdrawals. It incorporates safety mechanisms like pausing and reentrancy protection, and utilizes a role-based access system.

Inheritance

  • Pausable: Allows the contract to be paused and unpaused by the owner.

  • ReentrancyGuard: Protects against reentrancy attacks.

Events

  • Deposited(address sender, uint256 amount): Emitted when BTC is deposited.

  • Withdrawn(address recipient, uint256 amount): Emitted when BTC is withdrawn.

  • OwnershipTransferred(address previousOwner, address newOwner): Emitted when the owner changes.

  • AdminRoleTransferred(address previousAdmin, address newAdmin): Emitted when the admin changes.

  • WithdrawerRoleGranted(address account): Emitted when an address is given the withdrawer role.

  • WithdrawerRoleRevoked(address account): Emitted when an address has the withdrawer role revoked.

State Variables

  • owner (address): Current contract owner.

  • admin (address): Address with administrative capabilities.

  • hasWithdrawerRole (mapping): Tracks which addresses are authorized to withdraw BTC.

Constructor

  • Assigns the deployer as owner, admin, and a withdrawer.

Modifiers

  • onlyOwner: Restricts access to the owner.

  • onlyAdmin: Restricts access to the admin.

  • onlyWithdrawer: Restricts access to addresses with the withdrawer role.

Functions

deposit()

function deposit() external payable whenNotPaused
  • Public payable function to deposit BTC into the contract.

  • Emits Deposited event.

withdraw(address recipient, uint256 amount)

function withdraw(address recipient, uint256 amount) external nonReentrant onlyWithdrawer whenNotPaused
  • Transfers specified amount of BTC to a recipient.

  • Restricted to addresses with withdrawer role.

  • Emits Withdrawn event.

pause()

function pause() external onlyOwner
  • Pauses the contract.

unpause()

function unpause() external onlyOwner
  • Unpauses the contract.

transferOwnership(address newOwner)

function transferOwnership(address newOwner) external onlyOwner
  • Transfers ownership to newOwner.

  • Emits OwnershipTransferred event.

transferAdminRole(address newAdmin)

function transferAdminRole(address newAdmin) external onlyOwner
  • Assigns new admin.

  • Emits AdminRoleTransferred event.

grantWithdrawerRole(address account)

function grantWithdrawerRole(address account) external onlyAdmin
  • Grants withdraw permission to account.

  • Emits WithdrawerRoleGranted event.

revokeWithdrawerRole(address account)

function revokeWithdrawerRole(address account) external onlyAdmin
  • Revokes withdraw permission from account.

  • Emits WithdrawerRoleRevoked event.

Security Features

  • Role-based access control: Owner and admin can delegate or revoke access.

  • Pausable operations: Emergency pause/unpause.

  • Reentrancy guard: Ensures secure withdrawals.

Usage Example

vault.deposit{value: 1 ether}();
vault.withdraw(0xRecipient, 1 ether);

Notes

  • This contract only handles BTC (native currency).

  • Ensure that only trusted addresses are granted withdrawer roles.

Last updated