Add method to claim erc20 tokens locked in the contract
Closed this issue · 0 comments
patitonar commented
Let's add a method to claim any erc20 token transferred to the smart contract that could be sent accidentally by other users to its address. It will help also in case the owner transfers his KNC tokens accidentally using transfer
method instead of using the approve
and transferFrom
pattern.
Since this contract will only hold native eth coins and not any erc20 for the pool members distribution, no funds will be compromised with this method.
The method could look something like this:
function claimErc20Tokens(address _token, address _to) external onlyOwner {
IERC20 token = IERC20(_token);
uint256 balance = token.balanceOf(this);
SafeERC20.safeTransfer(_token, _to, balance);
}
SafeERC20.safeTransfer
can be imported from OpenZeppelin contracts
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/61973af29f469e62dadf9df239699175d5bee95e/contracts/token/ERC20/SafeERC20.sol#L20-L22