|
| 1 | +pragma solidity 0.8.10; |
| 2 | +import "./RecoveryForwarder.sol"; |
| 3 | +import "./CloneFactory.sol"; |
| 4 | +/** |
| 5 | + * |
| 6 | + * RecoveryWallet |
| 7 | + * ============ |
| 8 | + * |
| 9 | + * Basic singleSig wallet designed to recover funds. |
| 10 | + * |
| 11 | + */ |
| 12 | +contract RecoveryWallet is CloneFactory { |
| 13 | + |
| 14 | + // Public fields |
| 15 | + address public immutable signer; |
| 16 | + address public immutable forwarderImplementationAddress; |
| 17 | + |
| 18 | + constructor (address _signer, address _forwarderImplementationAddress) { |
| 19 | + signer = _signer; |
| 20 | + forwarderImplementationAddress = _forwarderImplementationAddress; |
| 21 | + } |
| 22 | + /** |
| 23 | + * Modifier that will execute internal code block only if the sender is an authorized signer on this wallet |
| 24 | + */ |
| 25 | + modifier onlySigner { |
| 26 | + require( signer == msg.sender, 'Non-signer in onlySigner method'); |
| 27 | + _; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Gets called when a transaction is received with ether and no data |
| 32 | + */ |
| 33 | + receive() external payable { |
| 34 | + } |
| 35 | + /** |
| 36 | + * Default function; Gets called when data is sent but does not match any other function |
| 37 | + */ |
| 38 | + fallback() external payable { |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Creates new forwarder contract controlled by signer in batches |
| 43 | + */ |
| 44 | +function createRecoveryForwarder(uint8 value) external { |
| 45 | + require(value > 0 && value < 150 , 'value must be greater than 0 and less than 150'); |
| 46 | + for ( uint8 i = 0; i < value; ++i) { |
| 47 | + address payable clone = createClone(forwarderImplementationAddress); |
| 48 | + RecoveryForwarder(clone).init(signer); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Execute a transaction from this wallet using the signer. |
| 54 | + * |
| 55 | + * @param toAddress the destination address to send an outgoing transaction |
| 56 | + * @param value the amount in Wei to be sent |
| 57 | + * @param data the data to send to the toAddress when invoking the transaction |
| 58 | + */ |
| 59 | + function sendFunds( |
| 60 | + address toAddress, |
| 61 | + uint256 value, |
| 62 | + bytes calldata data |
| 63 | + ) external onlySigner { |
| 64 | + |
| 65 | + // Success, send the transaction |
| 66 | + (bool success, ) = toAddress.call{ value: value }(data); |
| 67 | + require(success, 'Call execution failed'); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments