-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleVaultContractV2.sol
More file actions
62 lines (46 loc) · 1.44 KB
/
SimpleVaultContractV2.sol
File metadata and controls
62 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
//Gas optimization
contract SimpleVaultContractV2{
receive() external payable { }
fallback() external payable { }
enum Role {Member, Admin}
address public immutable owner;
mapping(address => uint256) public balance;
mapping(address => Role) public roles;
error InvalidAmount(uint balance, uint amount);
error TransactionFailed();
error NotAnAdmin();
error Fraudster(address attempter);
constructor(){
owner = msg.sender;
}
modifier OnlyOwner(){
if(msg.sender != owner){
revert Fraudster(msg.sender);
}
_;
}
function Deposit() public payable{
if(msg.value <= 0){
revert InvalidAmount(address(this).balance, msg.value);
}
balance[msg.sender] += msg.value;
}
function setRole(address user, Role _role) public OnlyOwner{
roles[user] = _role;
}
function Withdraw(uint256 amount) public payable OnlyOwner{
if(amount <= 0){
revert InvalidAmount(address(this).balance, amount);
}
if(roles[msg.sender] != Role.Admin){
revert NotAnAdmin();
}
balance[msg.sender] -= amount;
(bool success, ) = payable(msg.sender).call{value: amount}("");
if(!success){
revert TransactionFailed();
}
}
}