|
1 | 1 | pragma solidity 0.8.10; |
2 | | - |
| 2 | +import './TransferHelper.sol'; |
| 3 | +import './ERC20Interface.sol'; |
3 | 4 | /** |
4 | | - * Basic singleSig contract designed to send funds controlled by signer. |
| 5 | + * Contract that will forward any incoming Ether to the creator of the contract |
5 | 6 | */ |
6 | 7 | contract RecoveryForwarder { |
7 | | - // Address which can move funds from this contract |
8 | | - address public signer; |
| 8 | + // Address to which any funds sent to this contract will be forwarded |
| 9 | + address public parentAddress; |
9 | 10 | /** |
10 | | - * Initialize the signer |
| 11 | + * Initialize the parent |
11 | 12 | */ |
12 | | - function init(address _signer) external onlyUninitialized { |
13 | | - signer = _signer; |
| 13 | + function init(address _parentAddress) external onlyUninitialized { |
| 14 | + parentAddress = _parentAddress; |
14 | 15 | } |
15 | 16 |
|
16 | | - /** |
17 | | - * Modifier that will execute internal code block only if the sender is an authorized signer on this wallet |
18 | | - */ |
19 | | - modifier onlySigner { |
20 | | - require( signer == msg.sender, 'Non-signer in onlySigner method'); |
| 17 | + /** |
| 18 | + * Modifier that will execute internal code block only if the sender is the parent address |
| 19 | + */ |
| 20 | + modifier onlyParent { |
| 21 | + require( parentAddress == msg.sender, 'Non-parent in onlyParent method'); |
21 | 22 | _; |
22 | 23 | } |
23 | 24 |
|
24 | 25 | /** |
25 | 26 | * Modifier that will execute internal code block only if the contract has not been initialized yet |
26 | 27 | */ |
27 | 28 | modifier onlyUninitialized { |
28 | | - require(signer == address(0x0), 'Already initialized'); |
| 29 | + require(parentAddress == address(0x0), 'Already initialized'); |
29 | 30 | _; |
30 | 31 | } |
31 | 32 |
|
32 | | - /** |
33 | | - * Default function; Gets called when Ether is deposited |
34 | | - */ |
35 | | - receive() external payable { |
| 33 | + /** |
| 34 | + * Default function; Gets called when Ether is deposited |
| 35 | + */ |
| 36 | + receive() external payable { |
| 37 | + flush(); |
36 | 38 | } |
37 | 39 |
|
38 | 40 | /** |
39 | 41 | * Default function; Gets called when data is sent but does not match any other function |
40 | 42 | */ |
41 | 43 | fallback() external payable { |
| 44 | + flush(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Execute a token transfer of the full balance from the forwarder token to the parent address |
| 49 | + * @param tokenContractAddress the address of the erc20 token contract |
| 50 | + */ |
| 51 | + function flushTokens(address tokenContractAddress) external onlyParent { |
| 52 | + ERC20Interface instance = ERC20Interface(tokenContractAddress); |
| 53 | + address forwarderAddress = address(this); |
| 54 | + uint256 forwarderBalance = instance.balanceOf(forwarderAddress); |
| 55 | + TransferHelper.safeTransfer( |
| 56 | + tokenContractAddress, |
| 57 | + parentAddress, |
| 58 | + forwarderBalance |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * A fallback function which can used to transfer funds controlled by parent. |
| 64 | + */ |
| 65 | + function callFromParent( |
| 66 | + address target, |
| 67 | + uint256 value, |
| 68 | + bytes calldata data |
| 69 | + ) external onlyParent { |
| 70 | + (bool success, ) = target.call{ value: value }( |
| 71 | + data |
| 72 | + ); |
| 73 | + require(success, 'Parent call execution failed'); |
42 | 74 | } |
43 | 75 |
|
44 | 76 | /** |
45 | | - * Execute a transaction from this contract using the signer. |
46 | | - * |
47 | | - * @param toAddress the destination address to send an outgoing transaction |
48 | | - * @param value the amount in Wei to be sent |
49 | | - * @param data the data to send to the toAddress when invoking the transaction |
| 77 | + * Flush the entire balance of the contract to the parent address. |
50 | 78 | */ |
51 | | - function sendFunds( |
52 | | - address toAddress, |
53 | | - uint256 value, |
54 | | - bytes calldata data |
55 | | - ) external onlySigner { |
56 | | - // Success, send the transaction |
57 | | - (bool success, ) = toAddress.call{ value: value }(data); |
58 | | - require(success, 'Call execution failed'); |
| 79 | + function flush() public { |
| 80 | + uint256 value = address(this).balance; |
| 81 | + (bool success, ) = parentAddress.call{ value: value }(''); |
| 82 | + require(success, 'Flush failed'); |
59 | 83 | } |
60 | 84 | } |
0 commit comments