-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathImmutableBeaconProxy.sol
More file actions
36 lines (29 loc) · 1.39 KB
/
ImmutableBeaconProxy.sol
File metadata and controls
36 lines (29 loc) · 1.39 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IBeacon} from './interfaces/IBeacon.sol';
import {Proxy} from '../oz-common/Proxy.sol';
import {Address} from '../oz-common/Address.sol';
/**
* @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
* The beacon address is immutable. The purpose of it, is to be able to access this proxy via delegatecall
* !!! IMPORTANT CONSIDERATION !!!
* We expect that the implementation will not have any storage associated,
* because it when accessed via delegatecall, will not work as expected creating dangerous side-effects. Preferable, the implementation should be declared as a library
*/
contract ImmutableBeaconProxy is Proxy {
address internal immutable _beacon;
event ImmutableBeaconSet(address indexed beacon);
constructor(address beacon) {
require(Address.isContract(beacon), 'INVALID_BEACON');
require(Address.isContract(IBeacon(beacon).implementation()), 'INVALID_IMPLEMENTATION');
// there is no initialization call, because we expect that implementation should have no storage
_beacon = beacon;
emit ImmutableBeaconSet(beacon);
}
/**
* @dev Returns the current implementation address of the associated beacon.
*/
function _implementation() internal view virtual override returns (address) {
return IBeacon(_beacon).implementation();
}
}