-
Notifications
You must be signed in to change notification settings - Fork 9
/
Recoverable.sol
39 lines (32 loc) · 1.35 KB
/
Recoverable.sol
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
/**
* Based on https://github.com/TokenMarketNet/smart-contracts/blob/master/contracts/Recoverable.sol
*/
pragma solidity ^0.5.0;
import '@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol';
/**
* Allows to recover any tokens accidentally send on the smart contract.
*
* Sending ethers on token contracts is not possible in the first place.
* as they are not payable.
*
* https://twitter.com/moo9000/status/1238514802189795331
*/
contract Recoverable is Ownable {
function initialize(address sender) public initializer {
super.initialize(sender);
}
/// @dev This will be invoked by the owner, when owner wants to rescue tokens
/// @param token Token which will we rescue to the owner from the contract
function recoverTokens(IERC20 token) public onlyOwner {
require(token.transfer(owner(), tokensToBeReturned(token)), "Transfer failed");
}
/// @dev Interface function, can be overwritten by the superclass
/// @param token Token which balance we will check and return
/// @return The amount of tokens (in smallest denominator) the contract owns
function tokensToBeReturned(IERC20 token) public view returns (uint) {
return token.balanceOf(address(this));
}
// Upgradeability - add some space
uint256[50] private ______gap;
}