-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProxy.sol
More file actions
52 lines (44 loc) · 1.66 KB
/
Proxy.sol
File metadata and controls
52 lines (44 loc) · 1.66 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
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './Implementations.sol';
import './utils/LibRegister.sol';
contract Proxy is Implementations {
/**
* @dev Get function selector of calldata
* @param selector The function selector.
*/
function getSelector() private pure returns (bytes4 selector) {
require(msg.data.length >= 4, 'InvalidByteOperation');
assembly {
selector := calldataload(0x0)
selector := and(
selector,
0xFFFFFFFF00000000000000000000000000000000000000000000000000000000
)
}
return selector;
}
/**
* @dev Call target contract register functions
* @param target The target contract address
*/
function bootstrap(address target) public onlyOwner {
address owner = getOwnableStorage().owner;
// Set the owner to ourselves to allow bootstrap to call `setFunctionImplementation()`.
getOwnableStorage().owner = address(this);
LibRegister.delegatecallRegisterFunction(target);
getOwnableStorage().owner = owner;
}
/// @dev Forwards calls to the appropriate implementation contract.
fallback() external payable {
bytes4 selector = getSelector();
address impl = getFunctionImplementation(selector);
require(impl != address(0), 'NotImplementedError');
(bool success, bytes memory resultData) = impl.delegatecall(msg.data);
require(success, string(resultData));
}
// solhint-disable no-empty-blocks
/// @dev Fallback for just receiving ether.
receive() external payable {}
// solhint-enable no-empty-blocks
}