Skip to content

Commit

Permalink
Merge pull request #79 from Kwenta/RescueERC20()-Fix
Browse files Browse the repository at this point in the history
馃棏 Remove rescueERC20()
  • Loading branch information
JaredBorders committed Oct 7, 2022
2 parents 30bc18d + 84fe92d commit 8fede78
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 48 deletions.
14 changes: 0 additions & 14 deletions contracts/MarginBase.sol
Expand Up @@ -954,18 +954,4 @@ contract MarginBase is MinimalProxyable, IMarginBase, OpsReady {
function _abs(int256 x) internal pure returns (uint256) {
return uint256(x < 0 ? -x : x);
}

/// @notice added to support recovering trapped erc20 tokens
/// @param tokenAddress: address of token to be recovered
/// @param tokenAmount: amount of token to be recovered
function rescueERC20(address tokenAddress, uint256 tokenAmount)
external
onlyOwner
{
if (tokenAddress == address(marginAsset)) {
revert CannotRescueMarginAsset();
}
IERC20(tokenAddress).transfer(owner(), tokenAmount);
emit Rescued(tokenAddress, tokenAmount);
}
}
3 changes: 0 additions & 3 deletions contracts/interfaces/IMarginBase.sol
Expand Up @@ -69,7 +69,4 @@ interface IMarginBase is IMarginBaseTypes {
external
view
returns (bool canExec, bytes memory execPayload);

// Utility
function rescueERC20(address tokenAddress, uint256 tokenAmount) external;
}
31 changes: 0 additions & 31 deletions test/contracts/MarginBase.t.sol
Expand Up @@ -842,37 +842,6 @@ contract MarginBaseTest is DSTest {
account.depositAndDistribute(1 ether, newPositions);
}

/********************************************************************
* rescueERC20()
********************************************************************/
function testCanRescueToken() public {
MintableERC20 token = new MintableERC20(address(this), 1 ether);
token.transfer(address(account), 1 ether);
assertEq(token.balanceOf(address(this)), 0);
account.rescueERC20(address(token), 1 ether);
assertEq(token.balanceOf(address(this)), 1 ether);
}

function testCantRescueMarginAssetToken() public {
marginAsset.mint(address(this), 1 ether);
marginAsset.transfer(address(account), 1 ether);
assertEq(marginAsset.balanceOf(address(this)), 0);
cheats.expectRevert(
abi.encodeWithSelector(MarginBase.CannotRescueMarginAsset.selector)
);
account.rescueERC20(address(marginAsset), 1 ether);
}

function testCantRescueTokenIfNotOwner() public {
MintableERC20 token = new MintableERC20(address(this), 1 ether);
token.transfer(address(account), 1 ether);
cheats.expectRevert(
abi.encodePacked("Ownable: caller is not the owner")
);
cheats.prank(nonOwnerEOA); // non-owner calling rescueERC20()
account.rescueERC20(address(token), 1 ether);
}

/********************************************************************
* Advanced Orders Logic
********************************************************************/
Expand Down

0 comments on commit 8fede78

Please sign in to comment.