-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTokenDrainerFacet.sol
More file actions
74 lines (67 loc) · 2.19 KB
/
Copy pathTokenDrainerFacet.sol
File metadata and controls
74 lines (67 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: Apache-2.0
/**
* Authors: Moonstream Engineering (engineering@moonstream.to)
* GitHub: https://github.com/bugout-dev/dao
*
*/
pragma solidity ^0.8.9;
import "@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol";
import {LibDiamondMoonstream as LibDiamond} from "./diamond/libraries/LibDiamondMoonstream.sol";
contract TokenDrainerFacet {
function drainERC20(
address tokenAddress,
address receiverAddress
) external {
uint256 balance = IERC20(tokenAddress).balanceOf(address(this));
withdrawERC20(tokenAddress, balance, receiverAddress);
}
function withdrawERC20(
address tokenAddress,
uint256 amount,
address receiverAddress
) public {
LibDiamond.enforceIsContractOwner();
IERC20 token = IERC20(tokenAddress);
token.transfer(receiverAddress, amount);
}
function drainERC1155(
address tokenAddress,
uint256 tokenId,
address receiverAddress
) external {
uint256 balance = IERC1155(tokenAddress).balanceOf(
address(this),
tokenId
);
withdrawERC1155(tokenAddress, tokenId, balance, receiverAddress);
}
function withdrawERC1155(
address tokenAddress,
uint256 tokenId,
uint256 amount,
address receiverAddress
) public {
LibDiamond.enforceIsContractOwner();
IERC1155 token = IERC1155(tokenAddress);
token.safeTransferFrom(
address(this),
receiverAddress,
tokenId,
amount,
""
);
}
function withdrawERC721(
address tokenAddress,
uint256 tokenId,
address receiverAddress
) public {
LibDiamond.enforceIsContractOwner();
IERC721 token = IERC721(tokenAddress);
token.safeTransferFrom(address(this), receiverAddress, tokenId, "");
}
}