diff --git a/contracts/core/HodlERC20.sol b/contracts/core/HodlERC20.sol index b7ab80b..1f3e7b7 100644 --- a/contracts/core/HodlERC20.sol +++ b/contracts/core/HodlERC20.sol @@ -235,6 +235,16 @@ contract HodlERC20 is ERC20PermitUpgradeable { } } + /** + * @dev sweep additional erc20 tokens into feeRecipient's address + * @param _token token address, cannot be bonus token or main token + * @param _amount amount of token to send out. + */ + function sweep(address _token, uint256 _amount) external { + require(_token != address(token) && _token != address(bonusToken), "INVALID_TOKEN_TO_SWEEP"); + IERC20WithDetail(_token).transfer(feeRecipient, _amount); + } + /********************** * private Functions * **********************/ @@ -262,7 +272,6 @@ contract HodlERC20 is ERC20PermitUpgradeable { _burn(msg.sender, _amount); (uint256 payout, uint256 reward, uint256 fee) = _calculateExitPayout(_amount); - (_amount); // increase total in reward pool totalReward = totalReward.add(reward); diff --git a/test/HodlERC20.ts b/test/HodlERC20.ts index 99da1ab..aeae8f9 100644 --- a/test/HodlERC20.ts +++ b/test/HodlERC20.ts @@ -2,7 +2,6 @@ import { ethers, waffle } from "hardhat"; import { expect } from "chai"; import { HodlERC20, MockERC20 } from "../typechain"; import { BigNumber, utils } from "ethers"; -// import { calculateShares } from './utils'; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; describe("HodlERC20 Tests", function () { @@ -12,6 +11,8 @@ describe("HodlERC20 Tests", function () { let hodl: HodlERC20; let token: MockERC20; let bonusToken: MockERC20; + let randomToken: MockERC20; + let totalTime: BigNumber; let accounts: SignerWithAddress[] = []; @@ -58,12 +59,15 @@ describe("HodlERC20 Tests", function () { const ERC20 = await ethers.getContractFactory("MockERC20"); const erc20 = await ERC20.deploy(); const bonusErc20 = await ERC20.deploy(); + const randomErc20 = await ERC20.deploy(); token = erc20 as MockERC20; bonusToken = bonusErc20 as MockERC20; + randomToken = randomErc20 as MockERC20; + await token.init("WETH", "WETH", 18); await bonusToken.init("BONUS", "BONUS", 18); + await randomToken.init("COMP", "COMP", 18); - // mint 100 WETH to account 0, 1 , 2, 3 // every depositor got 10 weth const mintAmount = utils.parseUnits("10", "ether"); await token.mint(depositor1.address, mintAmount); @@ -395,6 +399,33 @@ describe("HodlERC20 Tests", function () { expect(bonusBalanceAfter.gt(0.0)).to.be.true; }); }); + describe("#donations", () => { + it("should revert if trying to sweep bonus token", async () => { + await expect(hodl.sweep(bonusToken.address, 0)).to.be.revertedWith("INVALID_TOKEN_TO_SWEEP"); + }); + it("should revert if trying to sweep main token", async () => { + await expect(hodl.sweep(token.address, 0)).to.be.revertedWith("INVALID_TOKEN_TO_SWEEP"); + }); + it("should be able to sweep token out of the contract", async function () { + const tokenAmount = 2000000; + await randomToken.mint(hodl.address, tokenAmount); + + const feeRecipientBalanceBefore = await randomToken.balanceOf(feeRecipient.address); + const hodlContractBalanceBefore = await randomToken.balanceOf(hodl.address); + + await hodl.sweep(randomToken.address, tokenAmount); + + const feeRecipientBalanceAfter = await randomToken.balanceOf(feeRecipient.address); + const hodlContractBalanceAfter = await randomToken.balanceOf(hodl.address); + + expect( + hodlContractBalanceBefore + .sub(hodlContractBalanceAfter) + .eq(feeRecipientBalanceAfter.sub(feeRecipientBalanceBefore)) + ).to.be.true; + expect(hodlContractBalanceBefore.sub(hodlContractBalanceAfter).eq(tokenAmount)).to.be.true; + }); + }); }); describe("lock period", () => {