-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERC-1967.sol
71 lines (52 loc) · 1.48 KB
/
ERC-1967.sol
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
69
70
71
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/utils/StorageSlot.sol";
contract StorageProxy {
uint public num;
uint public num2;
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(address _implementation) {
setImplementation(_implementation);
}
fallback() external {
(bool success, ) = getImplementation().delegatecall(msg.data);
if (!success) {
revert();
}
}
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
function setImplementation(address _implementation) public {
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = _implementation;
}
}
contract ImplementationV1 {
uint public num;
address implementation; // 1919191919191
uint public num2;
function setNum(uint _num) public {
num = _num;
}
}
contract ImplementationV2 {
uint public num;
function setNum(uint _num) public {
num = _num;
}
function putNum(uint _num) public {
num = 2 * _num;
}
}
contract ImplementationV3 {
uint public num;
function setNum(uint _num) public {
num = _num;
}
function putNum(uint _num) public {
num = 2 * _num;
}
function deleteNum(uint _num) public {
num = 2 * _num;
}
}