-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathProxy.sol
37 lines (32 loc) · 1.13 KB
/
Proxy.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
// SPDX-License-Identifier: Beta Software
pragma solidity ^0.8;
import "./LibRawResult.sol";
import "./Implementation.sol";
/// @notice Base class for all proxy contracts.
contract Proxy {
using LibRawResult for bytes;
/// @notice The address of the implementation contract used by this proxy.
Implementation public immutable IMPL;
// Made `payable` to allow initialized crowdfunds to receive ETH as an
// initial contribution.
constructor(Implementation impl, bytes memory initCallData) payable {
IMPL = impl;
(bool s, bytes memory r) = address(impl).delegatecall(initCallData);
if (!s) {
r.rawRevert();
}
}
// Forward all calls to the implementation.
fallback() external payable {
Implementation impl = IMPL;
assembly {
calldatacopy(0x00, 0x00, calldatasize())
let s := delegatecall(gas(), impl, 0x00, calldatasize(), 0x00, 0)
returndatacopy(0x00, 0x00, returndatasize())
if iszero(s) {
revert(0x00, returndatasize())
}
return(0x00, returndatasize())
}
}
}