CjHare / Separate-Staking-Reward-ERC4626-Vault

A ERC4626 Vault that hands out rewards in the vein of Masterchef V2
Apache License 2.0
3 stars 0 forks source link

[Feature] ERC20 Recovery #14

Open CjHare opened 1 year ago

CjHare commented 1 year ago

Feature Description

ERC20 Token sweeper; a mechanism for recovering tokens that have been transferred to the contract.

Restriction: the asset may only be recovered when there are no shares remaining.

Security: contract to have a owner (Ownable) with the recovery function being guarded byisOwner` modifier.

Additional Information

tempe-techie commented 1 year ago

Do you mean recovering reward tokens, or some other erc-20 tokens that were mistakenly sent to the contract's address?

This is something I use in my smart contracts to recover tokens:

/// @notice Recover any ERC-20 token mistakenly sent to this contract address
  function recoverERC20(address tokenAddress_, uint256 tokenAmount_, address recipient_) external onlyOwner {
    IERC20(tokenAddress_).transfer(recipient_, tokenAmount_);
  }

  /// @notice Recover any ERC-721 token mistakenly sent to this contract address
  function recoverERC721(address tokenAddress_, uint256 tokenId_, address recipient_) external onlyOwner {
    IERC721(tokenAddress_).transferFrom(address(this), recipient_, tokenId_);
  }

  /// @notice Recover any ERC-1155 token mistakenly sent to this contract address
  function recoverERC1155(address tokenAddress_, uint256 tokenId_, address recipient_, uint256 _amount) external onlyOwner {
    IERC1155(tokenAddress_).safeTransferFrom(address(this), recipient_, tokenId_, _amount, "");
  }

But in your case the reward and staking tokens should be excluded from recoverERC20(). Their recovery can be handled by a different function with its own rules.

CjHare commented 1 year ago

Sweeping random tokens sent to the contract (strangely that actually does happen 🤷).

Certain tokens merit exclusion or special handling (such as the asset and share(, but yes, as you say.