@layerzerolabs/proxy-v5-6-evm-contracts 1.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +270 -0
- package/.turbo/turbo-lint.log +98 -0
- package/.turbo/turbo-test.log +124 -0
- package/LICENSE +23 -0
- package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.json +85 -0
- package/artifacts/@openzeppelin/contracts/access/Ownable2Step.sol/Ownable2Step.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/Ownable2Step.sol/Ownable2Step.json +124 -0
- package/artifacts/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.json +56 -0
- package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +81 -0
- package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol/ERC1967Utils.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol/ERC1967Utils.json +49 -0
- package/artifacts/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.json +15 -0
- package/artifacts/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.json +24 -0
- package/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +132 -0
- package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json +74 -0
- package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +121 -0
- package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.json +22 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Errors.sol/Errors.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Errors.sol/Errors.json +48 -0
- package/artifacts/@openzeppelin/contracts/utils/LowLevelCall.sol/LowLevelCall.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/LowLevelCall.sol/LowLevelCall.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.json +10 -0
- package/artifacts/build-info/eb640ccbdf084d1d111d9ebf9250fdca.json +1 -0
- package/artifacts/contracts/ProxyAdmin2Step.sol/ProxyAdmin2Step.dbg.json +4 -0
- package/artifacts/contracts/ProxyAdmin2Step.sol/ProxyAdmin2Step.json +176 -0
- package/artifacts/contracts/TransparentUpgradeableProxy2Step.sol/TransparentUpgradeableProxy2Step.dbg.json +4 -0
- package/artifacts/contracts/TransparentUpgradeableProxy2Step.sol/TransparentUpgradeableProxy2Step.json +121 -0
- package/artifacts/contracts/interfaces/IProxyAdmin2Step.sol/IProxyAdmin2Step.dbg.json +4 -0
- package/artifacts/contracts/interfaces/IProxyAdmin2Step.sol/IProxyAdmin2Step.json +16 -0
- package/artifacts-flattened-contracts/contracts/ProxyAdmin2Step.flattened.sol +922 -0
- package/artifacts-flattened-contracts/contracts/TransparentUpgradeableProxy2Step.flattened.sol +1017 -0
- package/artifacts-tron/@openzeppelin/contracts/access/Ownable.sol/Ownable.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/access/Ownable.sol/Ownable.json +85 -0
- package/artifacts-tron/@openzeppelin/contracts/access/Ownable2Step.sol/Ownable2Step.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/access/Ownable2Step.sol/Ownable2Step.json +124 -0
- package/artifacts-tron/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.json +56 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +81 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol/ERC1967Utils.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol/ERC1967Utils.json +49 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.json +15 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.json +24 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +132 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json +74 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +121 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/Address.sol/Address.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/Address.sol/Address.json +22 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/Errors.sol/Errors.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/Errors.sol/Errors.json +48 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/LowLevelCall.sol/LowLevelCall.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/LowLevelCall.sol/LowLevelCall.json +10 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.dbg.json +4 -0
- package/artifacts-tron/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.json +10 -0
- package/artifacts-tron/build-info/33e2b07450318007b249bcb542a1e222.json +1 -0
- package/artifacts-tron/contracts/ProxyAdmin2Step.sol/ProxyAdmin2Step.dbg.json +4 -0
- package/artifacts-tron/contracts/ProxyAdmin2Step.sol/ProxyAdmin2Step.json +176 -0
- package/artifacts-tron/contracts/TransparentUpgradeableProxy2Step.sol/TransparentUpgradeableProxy2Step.dbg.json +4 -0
- package/artifacts-tron/contracts/TransparentUpgradeableProxy2Step.sol/TransparentUpgradeableProxy2Step.json +121 -0
- package/artifacts-tron/contracts/interfaces/IProxyAdmin2Step.sol/IProxyAdmin2Step.dbg.json +4 -0
- package/artifacts-tron/contracts/interfaces/IProxyAdmin2Step.sol/IProxyAdmin2Step.json +16 -0
- package/artifacts-zk/@openzeppelin/contracts/access/Ownable.sol/Ownable.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/access/Ownable.sol/Ownable.json +86 -0
- package/artifacts-zk/@openzeppelin/contracts/access/Ownable2Step.sol/Ownable2Step.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/access/Ownable2Step.sol/Ownable2Step.json +125 -0
- package/artifacts-zk/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.json +57 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +82 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol/ERC1967Utils.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol/ERC1967Utils.json +50 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.json +16 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.json +25 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +133 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json +75 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +124 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/Address.sol/Address.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/Address.sol/Address.json +23 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/Context.sol/Context.json +11 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/Errors.sol/Errors.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/Errors.sol/Errors.json +49 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/LowLevelCall.sol/LowLevelCall.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/LowLevelCall.sol/LowLevelCall.json +11 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.dbg.json +4 -0
- package/artifacts-zk/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.json +11 -0
- package/artifacts-zk/build-info/9069f70cfc4c7329462d894dfdd2740c.json +1 -0
- package/artifacts-zk/contracts/ProxyAdmin2Step.sol/ProxyAdmin2Step.dbg.json +4 -0
- package/artifacts-zk/contracts/ProxyAdmin2Step.sol/ProxyAdmin2Step.json +177 -0
- package/artifacts-zk/contracts/TransparentUpgradeableProxy2Step.sol/TransparentUpgradeableProxy2Step.dbg.json +4 -0
- package/artifacts-zk/contracts/TransparentUpgradeableProxy2Step.sol/TransparentUpgradeableProxy2Step.json +124 -0
- package/artifacts-zk/contracts/interfaces/IProxyAdmin2Step.sol/IProxyAdmin2Step.dbg.json +4 -0
- package/artifacts-zk/contracts/interfaces/IProxyAdmin2Step.sol/IProxyAdmin2Step.json +17 -0
- package/contracts/ProxyAdmin2Step.sol +39 -0
- package/contracts/TransparentUpgradeableProxy2Step.sol +109 -0
- package/contracts/interfaces/IProxyAdmin2Step.sol +15 -0
- package/foundry.toml +23 -0
- package/hardhat.config.js +58 -0
- package/package.json +42 -0
- package/solhint.config.js +3 -0
- package/test/TransparentUpgradeableProxy2Step.t.sol +276 -0
- package/turbo-snapshot.lock.json +454 -0
package/artifacts-flattened-contracts/contracts/TransparentUpgradeableProxy2Step.flattened.sol
ADDED
|
@@ -0,0 +1,1017 @@
|
|
|
1
|
+
pragma solidity ^0.8.22;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
abstract contract Proxy {
|
|
5
|
+
/**
|
|
6
|
+
* @dev Delegates the current call to `implementation`.
|
|
7
|
+
*
|
|
8
|
+
* This function does not return to its internal call site, it will return directly to the external caller.
|
|
9
|
+
*/
|
|
10
|
+
function _delegate(address implementation) internal virtual {
|
|
11
|
+
assembly {
|
|
12
|
+
// Copy msg.data. We take full control of memory in this inline assembly
|
|
13
|
+
// block because it will not return to Solidity code. We overwrite the
|
|
14
|
+
// Solidity scratch pad at memory position 0.
|
|
15
|
+
calldatacopy(0x00, 0x00, calldatasize())
|
|
16
|
+
|
|
17
|
+
// Call the implementation.
|
|
18
|
+
// out and outsize are 0 because we don't know the size yet.
|
|
19
|
+
let result := delegatecall(gas(), implementation, 0x00, calldatasize(), 0x00, 0x00)
|
|
20
|
+
|
|
21
|
+
// Copy the returned data.
|
|
22
|
+
returndatacopy(0x00, 0x00, returndatasize())
|
|
23
|
+
|
|
24
|
+
switch result
|
|
25
|
+
// delegatecall returns 0 on error.
|
|
26
|
+
case 0 {
|
|
27
|
+
revert(0x00, returndatasize())
|
|
28
|
+
}
|
|
29
|
+
default {
|
|
30
|
+
return(0x00, returndatasize())
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback
|
|
37
|
+
* function and {_fallback} should delegate.
|
|
38
|
+
*/
|
|
39
|
+
function _implementation() internal view virtual returns (address);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @dev Delegates the current call to the address returned by `_implementation()`.
|
|
43
|
+
*
|
|
44
|
+
* This function does not return to its internal call site, it will return directly to the external caller.
|
|
45
|
+
*/
|
|
46
|
+
function _fallback() internal virtual {
|
|
47
|
+
_delegate(_implementation());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
|
|
52
|
+
* function in the contract matches the call data.
|
|
53
|
+
*/
|
|
54
|
+
fallback() external payable virtual {
|
|
55
|
+
_fallback();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface IBeacon {
|
|
60
|
+
/**
|
|
61
|
+
* @dev Must return an address that can be used as a delegate call target.
|
|
62
|
+
*
|
|
63
|
+
* {UpgradeableBeacon} will check that this address is a contract.
|
|
64
|
+
*/
|
|
65
|
+
function implementation() external view returns (address);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface IERC1967 {
|
|
69
|
+
/**
|
|
70
|
+
* @dev Emitted when the implementation is upgraded.
|
|
71
|
+
*/
|
|
72
|
+
event Upgraded(address indexed implementation);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @dev Emitted when the admin account has changed.
|
|
76
|
+
*/
|
|
77
|
+
event AdminChanged(address previousAdmin, address newAdmin);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @dev Emitted when the beacon is changed.
|
|
81
|
+
*/
|
|
82
|
+
event BeaconUpgraded(address indexed beacon);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
library Errors {
|
|
86
|
+
/**
|
|
87
|
+
* @dev The ETH balance of the account is not enough to perform the operation.
|
|
88
|
+
*/
|
|
89
|
+
error InsufficientBalance(uint256 balance, uint256 needed);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @dev A call to an address target failed. The target may have reverted.
|
|
93
|
+
*/
|
|
94
|
+
error FailedCall();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @dev The deployment failed.
|
|
98
|
+
*/
|
|
99
|
+
error FailedDeployment();
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @dev A necessary precompile is missing.
|
|
103
|
+
*/
|
|
104
|
+
error MissingPrecompile(address);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
library LowLevelCall {
|
|
108
|
+
/// @dev Performs a Solidity function call using a low level `call` and ignoring the return data.
|
|
109
|
+
function callNoReturn(address target, bytes memory data) internal returns (bool success) {
|
|
110
|
+
return callNoReturn(target, 0, data);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// @dev Same as {callNoReturn-address-bytes}, but allows specifying the value to be sent in the call.
|
|
114
|
+
function callNoReturn(address target, uint256 value, bytes memory data) internal returns (bool success) {
|
|
115
|
+
assembly ("memory-safe") {
|
|
116
|
+
success := call(gas(), target, value, add(data, 0x20), mload(data), 0x00, 0x00)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// @dev Performs a Solidity function call using a low level `call` and returns the first 64 bytes of the result
|
|
121
|
+
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
|
|
122
|
+
///
|
|
123
|
+
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
|
|
124
|
+
/// and this function doesn't zero it out.
|
|
125
|
+
function callReturn64Bytes(
|
|
126
|
+
address target,
|
|
127
|
+
bytes memory data
|
|
128
|
+
) internal returns (bool success, bytes32 result1, bytes32 result2) {
|
|
129
|
+
return callReturn64Bytes(target, 0, data);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// @dev Same as {callReturn64Bytes-address-bytes}, but allows specifying the value to be sent in the call.
|
|
133
|
+
function callReturn64Bytes(
|
|
134
|
+
address target,
|
|
135
|
+
uint256 value,
|
|
136
|
+
bytes memory data
|
|
137
|
+
) internal returns (bool success, bytes32 result1, bytes32 result2) {
|
|
138
|
+
assembly ("memory-safe") {
|
|
139
|
+
success := call(gas(), target, value, add(data, 0x20), mload(data), 0x00, 0x40)
|
|
140
|
+
result1 := mload(0x00)
|
|
141
|
+
result2 := mload(0x20)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/// @dev Performs a Solidity function call using a low level `staticcall` and ignoring the return data.
|
|
146
|
+
function staticcallNoReturn(address target, bytes memory data) internal view returns (bool success) {
|
|
147
|
+
assembly ("memory-safe") {
|
|
148
|
+
success := staticcall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x00)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// @dev Performs a Solidity function call using a low level `staticcall` and returns the first 64 bytes of the result
|
|
153
|
+
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
|
|
154
|
+
///
|
|
155
|
+
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
|
|
156
|
+
/// and this function doesn't zero it out.
|
|
157
|
+
function staticcallReturn64Bytes(
|
|
158
|
+
address target,
|
|
159
|
+
bytes memory data
|
|
160
|
+
) internal view returns (bool success, bytes32 result1, bytes32 result2) {
|
|
161
|
+
assembly ("memory-safe") {
|
|
162
|
+
success := staticcall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x40)
|
|
163
|
+
result1 := mload(0x00)
|
|
164
|
+
result2 := mload(0x20)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// @dev Performs a Solidity function call using a low level `delegatecall` and ignoring the return data.
|
|
169
|
+
function delegatecallNoReturn(address target, bytes memory data) internal returns (bool success) {
|
|
170
|
+
assembly ("memory-safe") {
|
|
171
|
+
success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x00)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// @dev Performs a Solidity function call using a low level `delegatecall` and returns the first 64 bytes of the result
|
|
176
|
+
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
|
|
177
|
+
///
|
|
178
|
+
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
|
|
179
|
+
/// and this function doesn't zero it out.
|
|
180
|
+
function delegatecallReturn64Bytes(
|
|
181
|
+
address target,
|
|
182
|
+
bytes memory data
|
|
183
|
+
) internal returns (bool success, bytes32 result1, bytes32 result2) {
|
|
184
|
+
assembly ("memory-safe") {
|
|
185
|
+
success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x40)
|
|
186
|
+
result1 := mload(0x00)
|
|
187
|
+
result2 := mload(0x20)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// @dev Returns the size of the return data buffer.
|
|
192
|
+
function returnDataSize() internal pure returns (uint256 size) {
|
|
193
|
+
assembly ("memory-safe") {
|
|
194
|
+
size := returndatasize()
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// @dev Returns a buffer containing the return data from the last call.
|
|
199
|
+
function returnData() internal pure returns (bytes memory result) {
|
|
200
|
+
assembly ("memory-safe") {
|
|
201
|
+
result := mload(0x40)
|
|
202
|
+
mstore(result, returndatasize())
|
|
203
|
+
returndatacopy(add(result, 0x20), 0x00, returndatasize())
|
|
204
|
+
mstore(0x40, add(result, add(0x20, returndatasize())))
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/// @dev Revert with the return data from the last call.
|
|
209
|
+
function bubbleRevert() internal pure {
|
|
210
|
+
assembly ("memory-safe") {
|
|
211
|
+
let fmp := mload(0x40)
|
|
212
|
+
returndatacopy(fmp, 0x00, returndatasize())
|
|
213
|
+
revert(fmp, returndatasize())
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function bubbleRevert(bytes memory returndata) internal pure {
|
|
218
|
+
assembly ("memory-safe") {
|
|
219
|
+
revert(add(returndata, 0x20), mload(returndata))
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
library Address {
|
|
225
|
+
/**
|
|
226
|
+
* @dev There's no code at `target` (it is not a contract).
|
|
227
|
+
*/
|
|
228
|
+
error AddressEmptyCode(address target);
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
|
|
232
|
+
* `recipient`, forwarding all available gas and reverting on errors.
|
|
233
|
+
*
|
|
234
|
+
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
|
|
235
|
+
* of certain opcodes, possibly making contracts go over the 2300 gas limit
|
|
236
|
+
* imposed by `transfer`, making them unable to receive funds via
|
|
237
|
+
* `transfer`. {sendValue} removes this limitation.
|
|
238
|
+
*
|
|
239
|
+
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
|
|
240
|
+
*
|
|
241
|
+
* IMPORTANT: because control is transferred to `recipient`, care must be
|
|
242
|
+
* taken to not create reentrancy vulnerabilities. Consider using
|
|
243
|
+
* {ReentrancyGuard} or the
|
|
244
|
+
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
|
|
245
|
+
*/
|
|
246
|
+
function sendValue(address payable recipient, uint256 amount) internal {
|
|
247
|
+
if (address(this).balance < amount) {
|
|
248
|
+
revert Errors.InsufficientBalance(address(this).balance, amount);
|
|
249
|
+
}
|
|
250
|
+
if (LowLevelCall.callNoReturn(recipient, amount, "")) {
|
|
251
|
+
// call successful, nothing to do
|
|
252
|
+
return;
|
|
253
|
+
} else if (LowLevelCall.returnDataSize() > 0) {
|
|
254
|
+
LowLevelCall.bubbleRevert();
|
|
255
|
+
} else {
|
|
256
|
+
revert Errors.FailedCall();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @dev Performs a Solidity function call using a low level `call`. A
|
|
262
|
+
* plain `call` is an unsafe replacement for a function call: use this
|
|
263
|
+
* function instead.
|
|
264
|
+
*
|
|
265
|
+
* If `target` reverts with a revert reason or custom error, it is bubbled
|
|
266
|
+
* up by this function (like regular Solidity function calls). However, if
|
|
267
|
+
* the call reverted with no returned reason, this function reverts with a
|
|
268
|
+
* {Errors.FailedCall} error.
|
|
269
|
+
*
|
|
270
|
+
* Returns the raw returned data. To convert to the expected return value,
|
|
271
|
+
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
|
|
272
|
+
*
|
|
273
|
+
* Requirements:
|
|
274
|
+
*
|
|
275
|
+
* - `target` must be a contract.
|
|
276
|
+
* - calling `target` with `data` must not revert.
|
|
277
|
+
*/
|
|
278
|
+
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
|
|
279
|
+
return functionCallWithValue(target, data, 0);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
|
284
|
+
* but also transferring `value` wei to `target`.
|
|
285
|
+
*
|
|
286
|
+
* Requirements:
|
|
287
|
+
*
|
|
288
|
+
* - the calling contract must have an ETH balance of at least `value`.
|
|
289
|
+
* - the called Solidity function must be `payable`.
|
|
290
|
+
*/
|
|
291
|
+
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
|
|
292
|
+
if (address(this).balance < value) {
|
|
293
|
+
revert Errors.InsufficientBalance(address(this).balance, value);
|
|
294
|
+
}
|
|
295
|
+
bool success = LowLevelCall.callNoReturn(target, value, data);
|
|
296
|
+
if (success && (LowLevelCall.returnDataSize() > 0 || target.code.length > 0)) {
|
|
297
|
+
return LowLevelCall.returnData();
|
|
298
|
+
} else if (success) {
|
|
299
|
+
revert AddressEmptyCode(target);
|
|
300
|
+
} else if (LowLevelCall.returnDataSize() > 0) {
|
|
301
|
+
LowLevelCall.bubbleRevert();
|
|
302
|
+
} else {
|
|
303
|
+
revert Errors.FailedCall();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
|
309
|
+
* but performing a static call.
|
|
310
|
+
*/
|
|
311
|
+
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
|
|
312
|
+
bool success = LowLevelCall.staticcallNoReturn(target, data);
|
|
313
|
+
if (success && (LowLevelCall.returnDataSize() > 0 || target.code.length > 0)) {
|
|
314
|
+
return LowLevelCall.returnData();
|
|
315
|
+
} else if (success) {
|
|
316
|
+
revert AddressEmptyCode(target);
|
|
317
|
+
} else if (LowLevelCall.returnDataSize() > 0) {
|
|
318
|
+
LowLevelCall.bubbleRevert();
|
|
319
|
+
} else {
|
|
320
|
+
revert Errors.FailedCall();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
|
326
|
+
* but performing a delegate call.
|
|
327
|
+
*/
|
|
328
|
+
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
|
|
329
|
+
bool success = LowLevelCall.delegatecallNoReturn(target, data);
|
|
330
|
+
if (success && (LowLevelCall.returnDataSize() > 0 || target.code.length > 0)) {
|
|
331
|
+
return LowLevelCall.returnData();
|
|
332
|
+
} else if (success) {
|
|
333
|
+
revert AddressEmptyCode(target);
|
|
334
|
+
} else if (LowLevelCall.returnDataSize() > 0) {
|
|
335
|
+
LowLevelCall.bubbleRevert();
|
|
336
|
+
} else {
|
|
337
|
+
revert Errors.FailedCall();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
|
|
343
|
+
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
|
|
344
|
+
* of an unsuccessful call.
|
|
345
|
+
*
|
|
346
|
+
* NOTE: This function is DEPRECATED and may be removed in the next major release.
|
|
347
|
+
*/
|
|
348
|
+
function verifyCallResultFromTarget(
|
|
349
|
+
address target,
|
|
350
|
+
bool success,
|
|
351
|
+
bytes memory returndata
|
|
352
|
+
) internal view returns (bytes memory) {
|
|
353
|
+
// only check if target is a contract if the call was successful and the return data is empty
|
|
354
|
+
// otherwise we already know that it was a contract
|
|
355
|
+
if (success && (returndata.length > 0 || target.code.length > 0)) {
|
|
356
|
+
return returndata;
|
|
357
|
+
} else if (success) {
|
|
358
|
+
revert AddressEmptyCode(target);
|
|
359
|
+
} else if (returndata.length > 0) {
|
|
360
|
+
LowLevelCall.bubbleRevert(returndata);
|
|
361
|
+
} else {
|
|
362
|
+
revert Errors.FailedCall();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
|
|
368
|
+
* revert reason or with a default {Errors.FailedCall} error.
|
|
369
|
+
*/
|
|
370
|
+
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
|
|
371
|
+
if (success) {
|
|
372
|
+
return returndata;
|
|
373
|
+
} else if (returndata.length > 0) {
|
|
374
|
+
LowLevelCall.bubbleRevert(returndata);
|
|
375
|
+
} else {
|
|
376
|
+
revert Errors.FailedCall();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
library StorageSlot {
|
|
382
|
+
struct AddressSlot {
|
|
383
|
+
address value;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
struct BooleanSlot {
|
|
387
|
+
bool value;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
struct Bytes32Slot {
|
|
391
|
+
bytes32 value;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
struct Uint256Slot {
|
|
395
|
+
uint256 value;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
struct Int256Slot {
|
|
399
|
+
int256 value;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
struct StringSlot {
|
|
403
|
+
string value;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
struct BytesSlot {
|
|
407
|
+
bytes value;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
|
|
412
|
+
*/
|
|
413
|
+
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
|
|
414
|
+
assembly ("memory-safe") {
|
|
415
|
+
r.slot := slot
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
|
|
421
|
+
*/
|
|
422
|
+
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
|
|
423
|
+
assembly ("memory-safe") {
|
|
424
|
+
r.slot := slot
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
|
|
430
|
+
*/
|
|
431
|
+
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
|
|
432
|
+
assembly ("memory-safe") {
|
|
433
|
+
r.slot := slot
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
|
|
439
|
+
*/
|
|
440
|
+
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
|
|
441
|
+
assembly ("memory-safe") {
|
|
442
|
+
r.slot := slot
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
|
|
448
|
+
*/
|
|
449
|
+
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
|
|
450
|
+
assembly ("memory-safe") {
|
|
451
|
+
r.slot := slot
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* @dev Returns a `StringSlot` with member `value` located at `slot`.
|
|
457
|
+
*/
|
|
458
|
+
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
|
|
459
|
+
assembly ("memory-safe") {
|
|
460
|
+
r.slot := slot
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
|
|
466
|
+
*/
|
|
467
|
+
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
|
|
468
|
+
assembly ("memory-safe") {
|
|
469
|
+
r.slot := store.slot
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
|
|
475
|
+
*/
|
|
476
|
+
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
|
|
477
|
+
assembly ("memory-safe") {
|
|
478
|
+
r.slot := slot
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
|
|
484
|
+
*/
|
|
485
|
+
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
|
|
486
|
+
assembly ("memory-safe") {
|
|
487
|
+
r.slot := store.slot
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
library ERC1967Utils {
|
|
493
|
+
/**
|
|
494
|
+
* @dev Storage slot with the address of the current implementation.
|
|
495
|
+
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
|
|
496
|
+
*/
|
|
497
|
+
// solhint-disable-next-line private-vars-leading-underscore
|
|
498
|
+
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* @dev The `implementation` of the proxy is invalid.
|
|
502
|
+
*/
|
|
503
|
+
error ERC1967InvalidImplementation(address implementation);
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* @dev The `admin` of the proxy is invalid.
|
|
507
|
+
*/
|
|
508
|
+
error ERC1967InvalidAdmin(address admin);
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @dev The `beacon` of the proxy is invalid.
|
|
512
|
+
*/
|
|
513
|
+
error ERC1967InvalidBeacon(address beacon);
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* @dev An upgrade function sees `msg.value > 0` that may be lost.
|
|
517
|
+
*/
|
|
518
|
+
error ERC1967NonPayable();
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* @dev Returns the current implementation address.
|
|
522
|
+
*/
|
|
523
|
+
function getImplementation() internal view returns (address) {
|
|
524
|
+
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* @dev Stores a new address in the ERC-1967 implementation slot.
|
|
529
|
+
*/
|
|
530
|
+
function _setImplementation(address newImplementation) private {
|
|
531
|
+
if (newImplementation.code.length == 0) {
|
|
532
|
+
revert ERC1967InvalidImplementation(newImplementation);
|
|
533
|
+
}
|
|
534
|
+
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
|
|
539
|
+
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
|
|
540
|
+
* to avoid stuck value in the contract.
|
|
541
|
+
*
|
|
542
|
+
* Emits an {IERC1967-Upgraded} event.
|
|
543
|
+
*/
|
|
544
|
+
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
|
|
545
|
+
_setImplementation(newImplementation);
|
|
546
|
+
emit IERC1967.Upgraded(newImplementation);
|
|
547
|
+
|
|
548
|
+
if (data.length > 0) {
|
|
549
|
+
Address.functionDelegateCall(newImplementation, data);
|
|
550
|
+
} else {
|
|
551
|
+
_checkNonPayable();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* @dev Storage slot with the admin of the contract.
|
|
557
|
+
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
|
|
558
|
+
*/
|
|
559
|
+
// solhint-disable-next-line private-vars-leading-underscore
|
|
560
|
+
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @dev Returns the current admin.
|
|
564
|
+
*
|
|
565
|
+
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
|
|
566
|
+
* the https://ethereum.org/developers/docs/apis/json-rpc/#eth_getstorageat[`eth_getStorageAt`] RPC call.
|
|
567
|
+
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
|
|
568
|
+
*/
|
|
569
|
+
function getAdmin() internal view returns (address) {
|
|
570
|
+
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* @dev Stores a new address in the ERC-1967 admin slot.
|
|
575
|
+
*/
|
|
576
|
+
function _setAdmin(address newAdmin) private {
|
|
577
|
+
if (newAdmin == address(0)) {
|
|
578
|
+
revert ERC1967InvalidAdmin(address(0));
|
|
579
|
+
}
|
|
580
|
+
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @dev Changes the admin of the proxy.
|
|
585
|
+
*
|
|
586
|
+
* Emits an {IERC1967-AdminChanged} event.
|
|
587
|
+
*/
|
|
588
|
+
function changeAdmin(address newAdmin) internal {
|
|
589
|
+
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
|
|
590
|
+
_setAdmin(newAdmin);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
|
|
595
|
+
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
|
|
596
|
+
*/
|
|
597
|
+
// solhint-disable-next-line private-vars-leading-underscore
|
|
598
|
+
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* @dev Returns the current beacon.
|
|
602
|
+
*/
|
|
603
|
+
function getBeacon() internal view returns (address) {
|
|
604
|
+
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* @dev Stores a new beacon in the ERC-1967 beacon slot.
|
|
609
|
+
*/
|
|
610
|
+
function _setBeacon(address newBeacon) private {
|
|
611
|
+
if (newBeacon.code.length == 0) {
|
|
612
|
+
revert ERC1967InvalidBeacon(newBeacon);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
|
|
616
|
+
|
|
617
|
+
address beaconImplementation = IBeacon(newBeacon).implementation();
|
|
618
|
+
if (beaconImplementation.code.length == 0) {
|
|
619
|
+
revert ERC1967InvalidImplementation(beaconImplementation);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* @dev Change the beacon and trigger a setup call if data is nonempty.
|
|
625
|
+
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
|
|
626
|
+
* to avoid stuck value in the contract.
|
|
627
|
+
*
|
|
628
|
+
* Emits an {IERC1967-BeaconUpgraded} event.
|
|
629
|
+
*
|
|
630
|
+
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
|
|
631
|
+
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
|
|
632
|
+
* efficiency.
|
|
633
|
+
*/
|
|
634
|
+
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
|
|
635
|
+
_setBeacon(newBeacon);
|
|
636
|
+
emit IERC1967.BeaconUpgraded(newBeacon);
|
|
637
|
+
|
|
638
|
+
if (data.length > 0) {
|
|
639
|
+
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
|
|
640
|
+
} else {
|
|
641
|
+
_checkNonPayable();
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
|
|
647
|
+
* if an upgrade doesn't perform an initialization call.
|
|
648
|
+
*/
|
|
649
|
+
function _checkNonPayable() private {
|
|
650
|
+
if (msg.value > 0) {
|
|
651
|
+
revert ERC1967NonPayable();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
contract ERC1967Proxy is Proxy {
|
|
657
|
+
/**
|
|
658
|
+
* @dev The proxy is left uninitialized.
|
|
659
|
+
*/
|
|
660
|
+
error ERC1967ProxyUninitialized();
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation`.
|
|
664
|
+
*
|
|
665
|
+
* Provided `_data` is passed in a delegate call to `implementation`. This will typically be an encoded function
|
|
666
|
+
* call, and allows initializing the storage of the proxy like a Solidity constructor. By default construction
|
|
667
|
+
* will fail if `_data` is empty. This behavior can be overridden using a custom {_unsafeAllowUninitialized} that
|
|
668
|
+
* returns true. In that case, empty `_data` is ignored and no delegate call to the implementation is performed
|
|
669
|
+
* during construction.
|
|
670
|
+
*
|
|
671
|
+
* Requirements:
|
|
672
|
+
*
|
|
673
|
+
* - If `data` is empty, `msg.value` must be zero.
|
|
674
|
+
*/
|
|
675
|
+
constructor(address implementation, bytes memory _data) payable {
|
|
676
|
+
if (!_unsafeAllowUninitialized() && _data.length == 0) {
|
|
677
|
+
revert ERC1967ProxyUninitialized();
|
|
678
|
+
}
|
|
679
|
+
ERC1967Utils.upgradeToAndCall(implementation, _data);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* @dev Returns the current implementation address.
|
|
684
|
+
*
|
|
685
|
+
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
|
|
686
|
+
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
|
|
687
|
+
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
|
|
688
|
+
*/
|
|
689
|
+
function _implementation() internal view virtual override returns (address) {
|
|
690
|
+
return ERC1967Utils.getImplementation();
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* @dev Returns whether the proxy can be left uninitialized.
|
|
695
|
+
*
|
|
696
|
+
* NOTE: Override this function to allow the proxy to be left uninitialized.
|
|
697
|
+
* Consider uninitialized proxies might be susceptible to man-in-the-middle threats
|
|
698
|
+
* where the proxy is replaced with a malicious one.
|
|
699
|
+
*/
|
|
700
|
+
function _unsafeAllowUninitialized() internal pure virtual returns (bool) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
interface ITransparentUpgradeableProxy is IERC1967 {
|
|
706
|
+
/// @dev See {UUPSUpgradeable-upgradeToAndCall}
|
|
707
|
+
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
abstract contract Context {
|
|
711
|
+
function _msgSender() internal view virtual returns (address) {
|
|
712
|
+
return msg.sender;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function _msgData() internal view virtual returns (bytes calldata) {
|
|
716
|
+
return msg.data;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function _contextSuffixLength() internal view virtual returns (uint256) {
|
|
720
|
+
return 0;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
abstract contract Ownable is Context {
|
|
725
|
+
address private _owner;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* @dev The caller account is not authorized to perform an operation.
|
|
729
|
+
*/
|
|
730
|
+
error OwnableUnauthorizedAccount(address account);
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @dev The owner is not a valid owner account. (eg. `address(0)`)
|
|
734
|
+
*/
|
|
735
|
+
error OwnableInvalidOwner(address owner);
|
|
736
|
+
|
|
737
|
+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
|
|
741
|
+
*/
|
|
742
|
+
constructor(address initialOwner) {
|
|
743
|
+
if (initialOwner == address(0)) {
|
|
744
|
+
revert OwnableInvalidOwner(address(0));
|
|
745
|
+
}
|
|
746
|
+
_transferOwnership(initialOwner);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* @dev Throws if called by any account other than the owner.
|
|
751
|
+
*/
|
|
752
|
+
modifier onlyOwner() {
|
|
753
|
+
_checkOwner();
|
|
754
|
+
_;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* @dev Returns the address of the current owner.
|
|
759
|
+
*/
|
|
760
|
+
function owner() public view virtual returns (address) {
|
|
761
|
+
return _owner;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* @dev Throws if the sender is not the owner.
|
|
766
|
+
*/
|
|
767
|
+
function _checkOwner() internal view virtual {
|
|
768
|
+
if (owner() != _msgSender()) {
|
|
769
|
+
revert OwnableUnauthorizedAccount(_msgSender());
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* @dev Leaves the contract without owner. It will not be possible to call
|
|
775
|
+
* `onlyOwner` functions. Can only be called by the current owner.
|
|
776
|
+
*
|
|
777
|
+
* NOTE: Renouncing ownership will leave the contract without an owner,
|
|
778
|
+
* thereby disabling any functionality that is only available to the owner.
|
|
779
|
+
*/
|
|
780
|
+
function renounceOwnership() public virtual onlyOwner {
|
|
781
|
+
_transferOwnership(address(0));
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
|
786
|
+
* Can only be called by the current owner.
|
|
787
|
+
*/
|
|
788
|
+
function transferOwnership(address newOwner) public virtual onlyOwner {
|
|
789
|
+
if (newOwner == address(0)) {
|
|
790
|
+
revert OwnableInvalidOwner(address(0));
|
|
791
|
+
}
|
|
792
|
+
_transferOwnership(newOwner);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
|
797
|
+
* Internal function without access restriction.
|
|
798
|
+
*/
|
|
799
|
+
function _transferOwnership(address newOwner) internal virtual {
|
|
800
|
+
address oldOwner = _owner;
|
|
801
|
+
_owner = newOwner;
|
|
802
|
+
emit OwnershipTransferred(oldOwner, newOwner);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
contract ProxyAdmin is Ownable {
|
|
807
|
+
/**
|
|
808
|
+
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgrade(address,address)`
|
|
809
|
+
* and `upgradeAndCall(address,address,bytes)` are present, and `upgrade` must be used if no function should be called,
|
|
810
|
+
* while `upgradeAndCall` will invoke the `receive` function if the third argument is the empty byte string.
|
|
811
|
+
* If the getter returns `"5.0.0"`, only `upgradeAndCall(address,address,bytes)` is present, and the third argument must
|
|
812
|
+
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
|
|
813
|
+
* during an upgrade.
|
|
814
|
+
*/
|
|
815
|
+
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* @dev Sets the initial owner who can perform upgrades.
|
|
819
|
+
*/
|
|
820
|
+
constructor(address initialOwner) Ownable(initialOwner) {}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation.
|
|
824
|
+
* See {TransparentUpgradeableProxy-_dispatchUpgradeToAndCall}.
|
|
825
|
+
*
|
|
826
|
+
* Requirements:
|
|
827
|
+
*
|
|
828
|
+
* - This contract must be the admin of `proxy`.
|
|
829
|
+
* - If `data` is empty, `msg.value` must be zero.
|
|
830
|
+
*/
|
|
831
|
+
function upgradeAndCall(
|
|
832
|
+
ITransparentUpgradeableProxy proxy,
|
|
833
|
+
address implementation,
|
|
834
|
+
bytes memory data
|
|
835
|
+
) public payable virtual onlyOwner {
|
|
836
|
+
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
abstract contract Ownable2Step is Ownable {
|
|
841
|
+
address private _pendingOwner;
|
|
842
|
+
|
|
843
|
+
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* @dev Returns the address of the pending owner.
|
|
847
|
+
*/
|
|
848
|
+
function pendingOwner() public view virtual returns (address) {
|
|
849
|
+
return _pendingOwner;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
|
|
854
|
+
* Can only be called by the current owner.
|
|
855
|
+
*
|
|
856
|
+
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
|
|
857
|
+
*/
|
|
858
|
+
function transferOwnership(address newOwner) public virtual override onlyOwner {
|
|
859
|
+
_pendingOwner = newOwner;
|
|
860
|
+
emit OwnershipTransferStarted(owner(), newOwner);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
|
|
865
|
+
* Internal function without access restriction.
|
|
866
|
+
*/
|
|
867
|
+
function _transferOwnership(address newOwner) internal virtual override {
|
|
868
|
+
delete _pendingOwner;
|
|
869
|
+
super._transferOwnership(newOwner);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* @dev The new owner accepts the ownership transfer.
|
|
874
|
+
*/
|
|
875
|
+
function acceptOwnership() public virtual {
|
|
876
|
+
address sender = _msgSender();
|
|
877
|
+
if (pendingOwner() != sender) {
|
|
878
|
+
revert OwnableUnauthorizedAccount(sender);
|
|
879
|
+
}
|
|
880
|
+
_transferOwnership(sender);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
interface IProxyAdmin2Step {
|
|
885
|
+
/**
|
|
886
|
+
* @notice Thrown when trying to renounce ownership.
|
|
887
|
+
*/
|
|
888
|
+
error CannotRenounceOwnership();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
contract ProxyAdmin2Step is IProxyAdmin2Step, ProxyAdmin, Ownable2Step {
|
|
892
|
+
constructor(address _initialOwner) ProxyAdmin(_initialOwner) {}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* @inheritdoc Ownable2Step
|
|
896
|
+
*/
|
|
897
|
+
function transferOwnership(address _newOwner) public virtual override(Ownable, Ownable2Step) {
|
|
898
|
+
Ownable2Step.transferOwnership(_newOwner);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* @inheritdoc Ownable2Step
|
|
903
|
+
*/
|
|
904
|
+
function _transferOwnership(address _newOwner) internal virtual override(Ownable, Ownable2Step) {
|
|
905
|
+
Ownable2Step._transferOwnership(_newOwner);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* @dev Override to prevent renouncing ownership.
|
|
910
|
+
* @inheritdoc Ownable
|
|
911
|
+
*/
|
|
912
|
+
function renounceOwnership() public virtual override {
|
|
913
|
+
revert CannotRenounceOwnership();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// SPDX-License-Identifier: MIT
|
|
918
|
+
// OpenZeppelin Contracts (last updated v5.5.0) (proxy/transparent/TransparentUpgradeableProxy.sol)
|
|
919
|
+
/**
|
|
920
|
+
* @dev This contract implements a proxy that is upgradeable through an associated {ProxyAdmin2Step} instance.
|
|
921
|
+
*
|
|
922
|
+
* To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
|
|
923
|
+
* clashing], which can potentially be used in an attack, this contract uses the
|
|
924
|
+
* https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
|
|
925
|
+
* things that go hand in hand:
|
|
926
|
+
*
|
|
927
|
+
* 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
|
|
928
|
+
* that call matches the {ITransparentUpgradeableProxy-upgradeToAndCall} function exposed by the proxy itself.
|
|
929
|
+
* 2. If the admin calls the proxy, it can call the `upgradeToAndCall` function, but any other call won't be forwarded to
|
|
930
|
+
* the implementation. If the admin tries to call a function on the implementation it will fail with an error indicating
|
|
931
|
+
* the proxy admin cannot fallback to the target implementation.
|
|
932
|
+
*
|
|
933
|
+
* These properties mean that the admin account can only be used for upgrading the proxy, so it's best if it's a
|
|
934
|
+
* dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to
|
|
935
|
+
* call a function from the proxy implementation. For this reason, the proxy deploys an instance of {ProxyAdmin2Step} and
|
|
936
|
+
* allows upgrades only if they come through it. You should think of the `ProxyAdmin2Step` instance as the administrative
|
|
937
|
+
* interface of the proxy, including the ability to change who can trigger upgrades by transferring ownership.
|
|
938
|
+
*
|
|
939
|
+
* NOTE: The real interface of this proxy is that defined in `ITransparentUpgradeableProxy`. This contract does not
|
|
940
|
+
* inherit from that interface, and instead `upgradeToAndCall` is implicitly implemented using a custom dispatch
|
|
941
|
+
* mechanism in `_fallback`. Consequently, the compiler will not produce an ABI for this contract. This is necessary to
|
|
942
|
+
* fully implement transparency without decoding reverts caused by selector clashes between the proxy and the
|
|
943
|
+
* implementation.
|
|
944
|
+
*
|
|
945
|
+
* NOTE: This proxy does not inherit from {Context} deliberately. The {ProxyAdmin2Step} of this contract won't send a
|
|
946
|
+
* meta-transaction in any way, and any other meta-transaction setup should be made in the implementation contract.
|
|
947
|
+
*
|
|
948
|
+
* IMPORTANT: This contract avoids unnecessary storage reads by setting the admin only during construction as an
|
|
949
|
+
* immutable variable, preventing any changes thereafter. However, the admin slot defined in ERC-1967 can still be
|
|
950
|
+
* overwritten by the implementation logic pointed to by this proxy. In such cases, the contract may end up in an
|
|
951
|
+
* undesirable state where the admin slot is different from the actual admin. Relying on the value of the admin slot
|
|
952
|
+
* is generally fine if the implementation is trusted.
|
|
953
|
+
*
|
|
954
|
+
* WARNING: It is not recommended to extend this contract to add additional external functions. If you do so, the
|
|
955
|
+
* compiler will not check that there are no selector conflicts, due to the note above. A selector clash between any new
|
|
956
|
+
* function and the functions declared in {ITransparentUpgradeableProxy} will be resolved in favor of the new one. This
|
|
957
|
+
* could render the `upgradeToAndCall` function inaccessible, preventing upgradeability and compromising transparency.
|
|
958
|
+
*
|
|
959
|
+
* @dev Differs from OZ's `TransparentUpgradeableProxy` by deploying `ProxyAdmin2Step` instead of `ProxyAdmin`.
|
|
960
|
+
*/
|
|
961
|
+
contract TransparentUpgradeableProxy2Step is ERC1967Proxy {
|
|
962
|
+
// An immutable address for the admin to avoid unnecessary SLOADs before each call
|
|
963
|
+
// at the expense of removing the ability to change the admin once it's set.
|
|
964
|
+
// This is acceptable if the admin is always a ProxyAdmin2Step instance or similar contract
|
|
965
|
+
// with its own ability to transfer the permissions to another account.
|
|
966
|
+
address private immutable _admin;
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* @dev The proxy caller is the current admin, and can't fallback to the proxy target.
|
|
970
|
+
*/
|
|
971
|
+
error ProxyDeniedAdminAccess();
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* @dev Initializes an upgradeable proxy managed by an instance of a {ProxyAdmin2Step} with an `initialOwner`,
|
|
975
|
+
* backed by the implementation at `_logic`, and optionally initialized with `_data` as explained in
|
|
976
|
+
* {ERC1967Proxy-constructor}.
|
|
977
|
+
*/
|
|
978
|
+
constructor(address _logic, address initialOwner, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
|
|
979
|
+
_admin = address(new ProxyAdmin2Step(initialOwner));
|
|
980
|
+
// Set the storage value and emit an event for ERC-1967 compatibility
|
|
981
|
+
ERC1967Utils.changeAdmin(_proxyAdmin());
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* @dev Returns the admin of this proxy.
|
|
986
|
+
*/
|
|
987
|
+
function _proxyAdmin() internal view virtual returns (address) {
|
|
988
|
+
return _admin;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* @dev If caller is the admin process the call internally, otherwise transparently fallback to the proxy behavior.
|
|
993
|
+
*/
|
|
994
|
+
function _fallback() internal virtual override {
|
|
995
|
+
if (msg.sender == _proxyAdmin()) {
|
|
996
|
+
if (msg.sig != ITransparentUpgradeableProxy.upgradeToAndCall.selector) {
|
|
997
|
+
revert ProxyDeniedAdminAccess();
|
|
998
|
+
} else {
|
|
999
|
+
_dispatchUpgradeToAndCall();
|
|
1000
|
+
}
|
|
1001
|
+
} else {
|
|
1002
|
+
super._fallback();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* @dev Upgrade the implementation of the proxy. See {ERC1967Utils-upgradeToAndCall}.
|
|
1008
|
+
*
|
|
1009
|
+
* Requirements:
|
|
1010
|
+
*
|
|
1011
|
+
* - If `data` is empty, `msg.value` must be zero.
|
|
1012
|
+
*/
|
|
1013
|
+
function _dispatchUpgradeToAndCall() private {
|
|
1014
|
+
(address newImplementation, bytes memory data) = abi.decode(msg.data[4:], (address, bytes));
|
|
1015
|
+
ERC1967Utils.upgradeToAndCall(newImplementation, data);
|
|
1016
|
+
}
|
|
1017
|
+
}
|