|
1 | 1 | pragma solidity >=0.5.0 <0.7.0; |
2 | 2 |
|
3 | | -import { Enum } from "@gnosis.pm/safe-contracts/contracts/common/Enum.sol"; |
4 | | -import { Proxy } from "@gnosis.pm/safe-contracts/contracts/proxies/Proxy.sol"; |
| 3 | +import { GnosisSafeProxy } from "@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxy.sol"; |
5 | 4 | import { GnosisSafe } from "@gnosis.pm/safe-contracts/contracts/GnosisSafe.sol"; |
6 | 5 |
|
| 6 | +import { ProxyImplSetter } from "./ProxyImplSetter.sol"; |
| 7 | + |
7 | 8 | contract CPKFactory { |
8 | | - event ProxyCreation(Proxy proxy); |
| 9 | + //keccak256( |
| 10 | + // "EIP712Domain(address verifyingContract)" |
| 11 | + //); |
| 12 | + bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; |
| 13 | + |
| 14 | + //keccak256( |
| 15 | + // "SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)" |
| 16 | + //); |
| 17 | + bytes32 private constant SAFE_TX_TYPEHASH = 0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8; |
| 18 | + |
| 19 | + ProxyImplSetter public proxyImplSetter; |
| 20 | + |
| 21 | + constructor() public { |
| 22 | + proxyImplSetter = new ProxyImplSetter(); |
| 23 | + } |
| 24 | + |
| 25 | + event ProxyCreation(GnosisSafeProxy proxy); |
9 | 26 |
|
10 | 27 | function proxyCreationCode() external pure returns (bytes memory) { |
11 | | - return type(Proxy).creationCode; |
| 28 | + return type(GnosisSafeProxy).creationCode; |
12 | 29 | } |
13 | 30 |
|
14 | 31 | function createProxyAndExecTransaction( |
15 | | - address masterCopy, |
| 32 | + address owner, |
| 33 | + address safeVersion, |
16 | 34 | uint256 saltNonce, |
17 | 35 | address fallbackHandler, |
18 | | - address to, |
19 | | - uint256 value, |
20 | | - bytes calldata data, |
21 | | - Enum.Operation operation |
| 36 | + bytes calldata execTxCalldata |
22 | 37 | ) |
23 | 38 | external |
| 39 | + payable |
24 | 40 | returns (bool execTransactionSuccess) |
25 | 41 | { |
26 | | - GnosisSafe proxy; |
27 | | - bytes memory deploymentData = abi.encodePacked(type(Proxy).creationCode, abi.encode(masterCopy)); |
28 | | - bytes32 salt = keccak256(abi.encode(msg.sender, saltNonce)); |
29 | | - // solium-disable-next-line security/no-inline-assembly |
30 | | - assembly { |
31 | | - proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt) |
| 42 | + bytes32 salt = keccak256(abi.encode(owner, saltNonce)); |
| 43 | + |
| 44 | + address payable proxy; |
| 45 | + { |
| 46 | + bytes memory deploymentData = abi.encodePacked( |
| 47 | + type(GnosisSafeProxy).creationCode, |
| 48 | + abi.encode(proxyImplSetter) |
| 49 | + ); |
| 50 | + // solium-disable-next-line security/no-inline-assembly |
| 51 | + assembly { |
| 52 | + proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt) |
| 53 | + } |
| 54 | + require(proxy != address(0), "create2 call failed"); |
32 | 55 | } |
33 | | - require(address(proxy) != address(0), "create2 call failed"); |
| 56 | + |
| 57 | + ProxyImplSetter(proxy).setImplementation(safeVersion); |
34 | 58 |
|
35 | 59 | { |
36 | 60 | address[] memory tmp = new address[](1); |
37 | | - tmp[0] = address(this); |
38 | | - proxy.setup(tmp, 1, address(0), "", fallbackHandler, address(0), 0, address(0)); |
| 61 | + tmp[0] = address(owner); |
| 62 | + GnosisSafe(proxy).setup(tmp, 1, address(0), "", fallbackHandler, address(0), 0, address(0)); |
39 | 63 | } |
40 | 64 |
|
41 | | - execTransactionSuccess = proxy.execTransaction(to, value, data, operation, 0, 0, 0, address(0), address(0), |
42 | | - abi.encodePacked(uint(address(this)), uint(0), uint8(1))); |
| 65 | + proxy.call.value(msg.value)(execTxCalldata); |
43 | 66 |
|
44 | | - proxy.execTransaction( |
45 | | - address(proxy), 0, |
46 | | - abi.encodeWithSignature("swapOwner(address,address,address)", address(1), address(this), msg.sender), |
47 | | - Enum.Operation.Call, |
48 | | - 0, 0, 0, address(0), address(0), |
49 | | - abi.encodePacked(uint(address(this)), uint(0), uint8(1)) |
50 | | - ); |
51 | | - |
52 | | - emit ProxyCreation(Proxy(address(proxy))); |
53 | | - } |
| 67 | + emit ProxyCreation(GnosisSafeProxy(proxy)); |
| 68 | + } |
54 | 69 | } |
0 commit comments