-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecureUpgradableVault.sol
More file actions
68 lines (50 loc) · 1.52 KB
/
SecureUpgradableVault.sol
File metadata and controls
68 lines (50 loc) · 1.52 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
63
64
65
66
67
68
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract SecureUV{
//Storage
address private owner;
mapping(address => uint256) private balances;
bool private initialized;
bool private locked;
//UUPS storage slot forimplementation
address private implementation;
//Modifiers
modifier initializer(){
require(!initialized, "Already initialized");
_;
}
modifier onlyOwner(){
require(msg.sender == owner, "Fraudster");
_;
}
modifier noReentrant() {
require(!locked, "Reentrant call");
locked = true;
_;
locked = false;
}
//Initializer
function initialize(address _owner) public initializer{
owner = _owner;
initialized = true;
}
//Core logic
function deposit() public payable {
require(msg.value > 0, "Deposit something chat");
balances[msg.sender] += msg.value;
}
function withdraw(uint256 amount) public payable noReentrant onlyOwner {
require(balances[msg.sender] >= amount, "Insufficient fund");
balances[msg.sender] -= amount;
(bool success,) = payable(msg.sender).call{value: amount}("");
require(success, "Transaction failed");
}
//UUPS upgrade function
function upgradeTo(address newImplementation) external onlyOwner {
require(newImplementation != address(0), "Invalid address");
implementation = newImplementation;
}
function getImplementation() public view returns (address) {
return implementation;
}
}