|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +/** |
| 4 | + * Authors: Moonstream Engineering (engineering@moonstream.to) |
| 5 | + * GitHub: https://github.com/bugout-dev/dao |
| 6 | + * |
| 7 | + */ |
| 8 | +pragma solidity ^0.8.9; |
| 9 | + |
| 10 | +import "@openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol"; |
| 11 | +import "@openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol"; |
| 12 | +import "@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; |
| 13 | +import "@openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol"; |
| 14 | + |
| 15 | +import "../diamond/libraries/LibDiamond.sol"; |
| 16 | + |
| 17 | +contract TokenDrainerFacet { |
| 18 | + function drainERC20(address tokenAddress, address receiverAddress) |
| 19 | + external |
| 20 | + { |
| 21 | + uint256 balance = IERC20(tokenAddress).balanceOf(address(this)); |
| 22 | + withdrawERC20(tokenAddress, balance, receiverAddress); |
| 23 | + } |
| 24 | + |
| 25 | + function withdrawERC20( |
| 26 | + address tokenAddress, |
| 27 | + uint256 amount, |
| 28 | + address receiverAddress |
| 29 | + ) public { |
| 30 | + LibDiamond.enforceIsContractOwner(); |
| 31 | + IERC20 token = IERC20(tokenAddress); |
| 32 | + token.transfer(receiverAddress, amount); |
| 33 | + } |
| 34 | + |
| 35 | + function drainERC1155( |
| 36 | + address tokenAddress, |
| 37 | + uint256 tokenId, |
| 38 | + address receiverAddress |
| 39 | + ) external { |
| 40 | + uint256 balance = IERC1155(tokenAddress).balanceOf( |
| 41 | + address(this), |
| 42 | + tokenId |
| 43 | + ); |
| 44 | + withdrawERC1155(tokenAddress, tokenId, balance, receiverAddress); |
| 45 | + } |
| 46 | + |
| 47 | + function withdrawERC1155( |
| 48 | + address tokenAddress, |
| 49 | + uint256 tokenId, |
| 50 | + uint256 amount, |
| 51 | + address receiverAddress |
| 52 | + ) public { |
| 53 | + LibDiamond.enforceIsContractOwner(); |
| 54 | + IERC1155 token = IERC1155(tokenAddress); |
| 55 | + token.safeTransferFrom( |
| 56 | + address(this), |
| 57 | + receiverAddress, |
| 58 | + tokenId, |
| 59 | + amount, |
| 60 | + "" |
| 61 | + ); |
| 62 | + } |
| 63 | +} |
0 commit comments