|
| 1 | +pragma solidity >=0.5.0 <0.7.0; |
| 2 | + |
| 3 | +import { Enum } from "@gnosis.pm/safe-contracts/contracts/common/Enum.sol"; |
| 4 | +import { GnosisSafeProxy } from "@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxy.sol"; |
| 5 | +import { GnosisSafe } from "@gnosis.pm/safe-contracts/contracts/GnosisSafe.sol"; |
| 6 | + |
| 7 | +contract CPKFactoryV1 { |
| 8 | + event ProxyCreation(GnosisSafeProxy proxy); |
| 9 | + |
| 10 | + function proxyCreationCode() external pure returns (bytes memory) { |
| 11 | + return type(GnosisSafeProxy).creationCode; |
| 12 | + } |
| 13 | + |
| 14 | + function createProxyAndExecTransaction( |
| 15 | + address masterCopy, |
| 16 | + uint256 saltNonce, |
| 17 | + address fallbackHandler, |
| 18 | + address to, |
| 19 | + uint256 value, |
| 20 | + bytes calldata data, |
| 21 | + Enum.Operation operation |
| 22 | + ) |
| 23 | + external |
| 24 | + returns (bool execTransactionSuccess) |
| 25 | + { |
| 26 | + GnosisSafe proxy; |
| 27 | + bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).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) |
| 32 | + } |
| 33 | + require(address(proxy) != address(0), "create2 call failed"); |
| 34 | + |
| 35 | + { |
| 36 | + address[] memory tmp = new address[](1); |
| 37 | + tmp[0] = address(this); |
| 38 | + proxy.setup(tmp, 1, address(0), "", fallbackHandler, address(0), 0, address(0)); |
| 39 | + } |
| 40 | + |
| 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))); |
| 43 | + |
| 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(GnosisSafeProxy(address(proxy))); |
| 53 | + } |
| 54 | +} |
0 commit comments