|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity 0.8.10; |
| 3 | +import '../IForwarder.sol'; |
| 4 | + |
| 5 | +/** ERC721, ERC1155 imports */ |
| 6 | +import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol'; |
| 7 | +import '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol'; |
| 8 | + |
| 9 | +/** |
| 10 | + * |
| 11 | + * RecoveryWallet |
| 12 | + * ============ |
| 13 | + * |
| 14 | + * Basic singleSig wallet designed to recover funds. |
| 15 | + * |
| 16 | + */ |
| 17 | +contract RecoveryWalletSimple is IERC721Receiver, ERC1155Receiver { |
| 18 | + // Public fields |
| 19 | + address public signer; |
| 20 | + bool public initialized = false; // True if the contract has been initialized |
| 21 | + |
| 22 | + function init(address _signer) external onlyUninitialized { |
| 23 | + signer = _signer; |
| 24 | + initialized = true; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Modifier that will execute internal code block only if the sender is an authorized signer on this wallet |
| 29 | + */ |
| 30 | + modifier onlySigner() { |
| 31 | + require(signer == msg.sender, 'Non-signer in onlySigner method'); |
| 32 | + _; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Modifier that will execute internal code block only if the contract has not been initialized yet |
| 37 | + */ |
| 38 | + modifier onlyUninitialized() { |
| 39 | + require(!initialized, 'Contract already initialized'); |
| 40 | + _; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Gets called when a transaction is received with data that does not match any other method |
| 45 | + */ |
| 46 | + fallback() external payable {} |
| 47 | + |
| 48 | + /** |
| 49 | + * Gets called when a transaction is received with ether and no data |
| 50 | + */ |
| 51 | + receive() external payable {} |
| 52 | + |
| 53 | + /** |
| 54 | + * Execute a transaction from this wallet using the signer. |
| 55 | + * |
| 56 | + * @param toAddress the destination address to send an outgoing transaction |
| 57 | + * @param value the amount in Wei to be sent |
| 58 | + * @param data the data to send to the toAddress when invoking the transaction |
| 59 | + */ |
| 60 | + function sendFunds( |
| 61 | + address toAddress, |
| 62 | + uint256 value, |
| 63 | + bytes calldata data |
| 64 | + ) external onlySigner { |
| 65 | + // Success, send the transaction |
| 66 | + (bool success, ) = toAddress.call{ value: value }(data); |
| 67 | + require(success, 'Call execution failed'); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Execute a token flush from one of the forwarder addresses. This transfer can be done by any external address |
| 72 | + * |
| 73 | + * @param forwarderAddress the address of the forwarder address to flush the tokens from |
| 74 | + * @param tokenContractAddress the address of the erc20 token contract |
| 75 | + */ |
| 76 | + function flushForwarderTokens( |
| 77 | + address payable forwarderAddress, |
| 78 | + address tokenContractAddress |
| 79 | + ) external { |
| 80 | + IForwarder forwarder = IForwarder(forwarderAddress); |
| 81 | + forwarder.flushTokens(tokenContractAddress); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Execute a ERC721 token flush from one of the forwarder addresses. This transfer can be done by any external address |
| 86 | + * |
| 87 | + * @param forwarderAddress the address of the forwarder address to flush the tokens from |
| 88 | + * @param tokenContractAddress the address of the erc20 token contract |
| 89 | + */ |
| 90 | + function flushERC721ForwarderTokens( |
| 91 | + address payable forwarderAddress, |
| 92 | + address tokenContractAddress, |
| 93 | + uint256 tokenId |
| 94 | + ) external { |
| 95 | + IForwarder forwarder = IForwarder(forwarderAddress); |
| 96 | + forwarder.flushERC721Token(tokenContractAddress, tokenId); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Execute a ERC1155 batch token flush from one of the forwarder addresses. |
| 101 | + * This transfer can be done by any external address. |
| 102 | + * |
| 103 | + * @param forwarderAddress the address of the forwarder address to flush the tokens from |
| 104 | + * @param tokenContractAddress the address of the erc1155 token contract |
| 105 | + */ |
| 106 | + function batchFlushERC1155ForwarderTokens( |
| 107 | + address payable forwarderAddress, |
| 108 | + address tokenContractAddress, |
| 109 | + uint256[] calldata tokenIds |
| 110 | + ) external { |
| 111 | + IForwarder forwarder = IForwarder(forwarderAddress); |
| 112 | + forwarder.batchFlushERC1155Tokens(tokenContractAddress, tokenIds); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Execute a ERC1155 token flush from one of the forwarder addresses. |
| 117 | + * This transfer can be done by any external address. |
| 118 | + * |
| 119 | + * @param forwarderAddress the address of the forwarder address to flush the tokens from |
| 120 | + * @param tokenContractAddress the address of the erc1155 token contract |
| 121 | + * @param tokenId the token id associated with the ERC1155 |
| 122 | + */ |
| 123 | + function flushERC1155ForwarderTokens( |
| 124 | + address payable forwarderAddress, |
| 125 | + address tokenContractAddress, |
| 126 | + uint256 tokenId |
| 127 | + ) external { |
| 128 | + IForwarder forwarder = IForwarder(forwarderAddress); |
| 129 | + forwarder.flushERC1155Tokens(tokenContractAddress, tokenId); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Sets the autoflush 721 parameter on the forwarder. |
| 134 | + * |
| 135 | + * @param forwarderAddress the address of the forwarder to toggle. |
| 136 | + * @param autoFlush whether to autoflush erc721 tokens |
| 137 | + */ |
| 138 | + function setAutoFlush721(address forwarderAddress, bool autoFlush) |
| 139 | + external |
| 140 | + onlySigner |
| 141 | + { |
| 142 | + IForwarder forwarder = IForwarder(forwarderAddress); |
| 143 | + forwarder.setAutoFlush721(autoFlush); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Sets the autoflush 721 parameter on the forwarder. |
| 148 | + * |
| 149 | + * @param forwarderAddress the address of the forwarder to toggle. |
| 150 | + * @param autoFlush whether to autoflush erc1155 tokens |
| 151 | + */ |
| 152 | + function setAutoFlush1155(address forwarderAddress, bool autoFlush) |
| 153 | + external |
| 154 | + onlySigner |
| 155 | + { |
| 156 | + IForwarder forwarder = IForwarder(forwarderAddress); |
| 157 | + forwarder.setAutoFlush1155(autoFlush); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * ERC721 standard callback function for when a ERC721 is transfered. |
| 162 | + * |
| 163 | + * @param _operator The address of the nft contract |
| 164 | + * @param _from The address of the sender |
| 165 | + * @param _tokenId The token id of the nft |
| 166 | + * @param _data Additional data with no specified format, sent in call to `_to` |
| 167 | + */ |
| 168 | + function onERC721Received( |
| 169 | + address _operator, |
| 170 | + address _from, |
| 171 | + uint256 _tokenId, |
| 172 | + bytes memory _data |
| 173 | + ) external virtual override returns (bytes4) { |
| 174 | + return this.onERC721Received.selector; |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @inheritdoc IERC1155Receiver |
| 179 | + */ |
| 180 | + function onERC1155Received( |
| 181 | + address _operator, |
| 182 | + address _from, |
| 183 | + uint256 id, |
| 184 | + uint256 value, |
| 185 | + bytes calldata data |
| 186 | + ) external virtual override returns (bytes4) { |
| 187 | + return this.onERC1155Received.selector; |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * @inheritdoc IERC1155Receiver |
| 192 | + */ |
| 193 | + function onERC1155BatchReceived( |
| 194 | + address _operator, |
| 195 | + address _from, |
| 196 | + uint256[] calldata ids, |
| 197 | + uint256[] calldata values, |
| 198 | + bytes calldata data |
| 199 | + ) external virtual override returns (bytes4) { |
| 200 | + return this.onERC1155BatchReceived.selector; |
| 201 | + } |
| 202 | +} |
0 commit comments