import IERC20 from ERC20 section:5 #98
-
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/*
* This contract represents a vault for ERC20 tokens.
*
* INVARIANT: Users must always be able to withdraw the exact balance amout.
*/
contract HandlerStatefulFuzzCatches {
error HandlerStatefulFuzzCatches__UnsupportedToken();
using SafeERC20 for IERC20;
mapping(IERC20 => bool) public tokenIsSupported;
mapping(address user => mapping(IERC20 token => uint256 balance)) public tokenBalances;
modifier requireSupportedToken(IERC20 token) {
if (!tokenIsSupported[token]) revert HandlerStatefulFuzzCatches__UnsupportedToken();
_;
}
constructor(IERC20[] memory _supportedTokens) {
for (uint256 i; i < _supportedTokens.length; i++) {
tokenIsSupported[_supportedTokens[i]] = true;
}
}
function depositToken(IERC20 token, uint256 amount) external requireSupportedToken(token) {
tokenBalances[msg.sender][token] += amount;
token.safeTransferFrom(msg.sender, address(this), amount);
}
function withdrawToken(IERC20 token) external requireSupportedToken(token) {
uint256 currentBalance = tokenBalances[msg.sender][token];
tokenBalances[msg.sender][token] = 0;
token.safeTransfer(msg.sender, currentBalance);
}
} this is the handler contract from sc-exploits |
Beta Was this translation helpful? Give feedback.
Answered by
PatrickAlphaC
Jan 31, 2024
Replies: 1 comment 2 replies
-
You can import a contract from any contract that has the contract. For example, the ...although, for simplicity it would be better to import from |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
PatrickAlphaC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can import a contract from any contract that has the contract.
For example, the
ERC20.sol
contract importsIERC20.sol
, so we can pulled theIERC20.sol
from theERC20.sol
....although, for simplicity it would be better to import from
IERC20.sol
...