|
1 | 1 | // SPDX-License-Identifier: GPL-3.0 |
2 | | - |
3 | 2 | pragma solidity ^0.8.27; |
4 | 3 |
|
5 | | -import { IImplementationAuthority } from "../interface/IImplementationAuthority.sol"; |
6 | | -import { Errors } from "../libraries/Errors.sol"; |
7 | | - |
8 | | -contract IdentityProxy { |
9 | | - |
10 | | - /** |
11 | | - * @dev constructor of the proxy Identity contract |
12 | | - * @param _implementationAuthority the implementation Authority contract address |
13 | | - * @param initialManagementKey the management key at deployment |
14 | | - * the proxy is going to use the logic deployed on the implementation contract |
15 | | - * deployed at an address listed in the ImplementationAuthority contract |
16 | | - */ |
17 | | - constructor(address _implementationAuthority, address initialManagementKey) { |
18 | | - require(_implementationAuthority != address(0), Errors.ZeroAddress()); |
19 | | - require(initialManagementKey != address(0), Errors.ZeroAddress()); |
20 | | - |
21 | | - // solhint-disable-next-line no-inline-assembly |
22 | | - assembly { |
23 | | - sstore(0x821f3e4d3d679f19eacc940c87acf846ea6eae24a63058ea750304437a62aafc, _implementationAuthority) |
24 | | - } |
25 | | - |
26 | | - address logic = IImplementationAuthority(_implementationAuthority).getImplementation(); |
27 | | - |
28 | | - // solhint-disable-next-line avoid-low-level-calls |
29 | | - (bool success,) = logic.delegatecall(abi.encodeWithSignature("initialize(address)", initialManagementKey)); |
30 | | - require(success, Errors.InitializationFailed()); |
31 | | - } |
| 4 | +import { BeaconProxy } from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; |
32 | 5 |
|
33 | | - /** |
34 | | - * @dev fallback proxy function used for any transaction call that is made using |
35 | | - * the Identity contract ABI and called on the proxy contract |
36 | | - * The proxy will update its local storage depending on the behaviour requested |
37 | | - * by the implementation contract given by the Implementation Authority |
38 | | - */ |
39 | | - // solhint-disable-next-line no-complex-fallback |
40 | | - fallback() external payable { |
41 | | - address logic = IImplementationAuthority(implementationAuthority()).getImplementation(); |
| 6 | +import { Identity } from "../Identity.sol"; |
42 | 7 |
|
43 | | - // solhint-disable-next-line no-inline-assembly |
44 | | - assembly { |
45 | | - calldatacopy(0x0, 0x0, calldatasize()) |
46 | | - let success := delegatecall(sub(gas(), 10000), logic, 0x0, calldatasize(), 0, 0) |
47 | | - let retSz := returndatasize() |
48 | | - returndatacopy(0, 0, retSz) |
49 | | - switch success |
50 | | - case 0 { |
51 | | - revert(0, retSz) |
52 | | - } |
53 | | - default { |
54 | | - return(0, retSz) |
55 | | - } |
56 | | - } |
57 | | - } |
| 8 | +contract IdentityProxy is BeaconProxy { |
58 | 9 |
|
59 | | - function implementationAuthority() public view returns (address) { |
60 | | - address implemAuth; |
61 | | - // solhint-disable-next-line no-inline-assembly |
62 | | - assembly { |
63 | | - implemAuth := sload(0x821f3e4d3d679f19eacc940c87acf846ea6eae24a63058ea750304437a62aafc) |
64 | | - } |
65 | | - return implemAuth; |
66 | | - } |
| 10 | + constructor(address _implementationAuthority, address _initialManagementKey) |
| 11 | + BeaconProxy(_implementationAuthority, abi.encodeCall(Identity.initialize, (_initialManagementKey))) |
| 12 | + { } |
67 | 13 |
|
68 | 14 | } |
0 commit comments