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 whenNotPausedPublic payable function to deposit BTC into the contract.
Emits
Depositedevent.
withdraw(address recipient, uint256 amount)
function withdraw(address recipient, uint256 amount) external nonReentrant onlyWithdrawer whenNotPausedTransfers specified amount of BTC to a recipient.
Restricted to addresses with withdrawer role.
Emits
Withdrawnevent.
pause()
function pause() external onlyOwnerPauses the contract.
unpause()
function unpause() external onlyOwnerUnpauses the contract.
transferOwnership(address newOwner)
function transferOwnership(address newOwner) external onlyOwnerTransfers ownership to
newOwner.Emits
OwnershipTransferredevent.
transferAdminRole(address newAdmin)
function transferAdminRole(address newAdmin) external onlyOwnerAssigns new admin.
Emits
AdminRoleTransferredevent.
grantWithdrawerRole(address account)
function grantWithdrawerRole(address account) external onlyAdminGrants withdraw permission to
account.Emits
WithdrawerRoleGrantedevent.
revokeWithdrawerRole(address account)
function revokeWithdrawerRole(address account) external onlyAdminRevokes withdraw permission from
account.Emits
WithdrawerRoleRevokedevent.
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